Exemplo n.º 1
0
void
FrameBuffer::appendData(const unsigned char* data, const unsigned int size)
{
    lock_guard<recursive_mutex> scopedLock(syncMutex_);
    //fwrite(frame.getFrameData(),1,frame.getDataBlockSize(),fp);

    ptr_lib::shared_ptr<DataBlock> dataBlockSlot;

    int segNum = ceil( (double)size / (double)maxNdnPktSize_ );
    unsigned int lastSegSize = size % maxNdnPktSize_;
    if( 0 == lastSegSize )
        lastSegSize = maxNdnPktSize_;

    uint8_t nalHead = data[4];
    if( nalHead == 0x67)
        lastSeqNo_ = lastPkgNo_+1;

    int currentBlockSize;
    for( int i = 0; i < segNum; ++i )
    {
        currentBlockSize = (i==segNum-1) ? lastSegSize : maxNdnPktSize_;
        dataBlockSlot = getFreeSlot();
        if( !dataBlockSlot.get() )
            LOG(ERROR) << "[FrameBuffer] RecvFrame: getFreeSlot error" << endl;


//        cout <<"Segme: " << i
//             << " size=" << currentBlockSize
//             << " data: " << (void*)frame.getBuf()+(i*maxSegBlockSize_)
//             << " ~ " << (void*)(frame.getBuf()+currentBlockSize)
//             << endl << endl;

        dataBlockSlot->fillData(data+(i*maxNdnPktSize_),currentBlockSize);

//        cout << "Block" << i
//             << " size=" << dataBlock->size()
//             << " data: " << (void*)dataBlock->dataPtr()
//             << " ~ " << (void*)(dataBlock->dataPtr()+dataBlock->size())
//             << endl << endl;
//        cout << "Rcev frame size = " << dataBlock->size()
//             << " data: " << (void*)dataBlock->dataPtr()
//             << " ~ " << (void*)(dataBlock->dataPtr()+dataBlock->size())
//             << endl << endl << endl;
//        for( int i = 0; i< dataBlock->size(); ++i )
//            cout << hex << dataBlock->dataPtr()[i] << " " ;

        ndn::Name dataPrefix(basePrefix_);
        dataPrefix.append(NdnUtils::componentFromInt(++lastPkgNo_));
        dataPrefix.append(NameComponents::NameComponentNalMetainfo);
        std::vector<uint8_t> value;
        value.push_back(nalHead);
        dataPrefix.append(value);
        activeSlots_[dataPrefix] = dataBlockSlot;

        LOG_IF(ERROR, dataBlockSlot->size()<=0)
                << "[FrameBuffer] Cached ERROR " << dataPrefix.toUri()
                << " seg:"<< i << " Num:" << segNum
                << " ( Size = " << dec << currentBlockSize<<" of " << size << " )" << endl;

        LOG(INFO) << "[FrameBuffer] Cached " << dataPrefix.toUri()
                  << " (" << i << "-" << segNum
                  << ") [" << dec << dataBlockSlot->size()<<"-" << size << "]" << endl;
        //NdnUtils::printMem("cache",dataBlock->dataPtr(),20);
    }
}
Exemplo n.º 2
0
const String dataPrefix (const CtrlrMidiMessage &data, const int prefixLength)
{
	return (dataPrefix (data.getData(), prefixLength));
}