// ----------------------------------------------------------------------------- // CExprUDPMsg::HandleReceivedDataL() // ----------------------------------------------------------------------------- // TBool CExprUDPMsg::HandleRecievedMsgL( TDes8& aData, TInt& aStartPos, TInt& aLength ) { // Check if the prefix matches aStartPos = aData.Find( KUDPPrefix ); if ( aStartPos != KErrNotFound ) { // Found a matching prefix // Let the observer know iObserver->FrameStarted(); TPtr8 dataToParse( aData.MidTPtr( aStartPos ) ); TInt err = TryParsingL( dataToParse, aLength ); if ( err != KErrNone ) { // corrupted data in the frame iObserver->ProtocolErrorL( err, aData ); // delete the corrupted data aData.SetLength( 0 ); } return ETrue; } else { return EFalse; } }
/** Implementation of pure virtual function. @see MWTCacheInterface::ReadL() */ void CDynamicDirCache::ReadL(TInt64 aPos, TInt aLength, TDes8& aDes) { #ifdef _DEBUG if(iCacheDisabled) { // cache is disabled for debug purposes __PRINT(_L("CDynamicDirCache disabled")); User::LeaveIfError(iDrive.ReadNonCritical(aPos, aLength, aDes)); return; } #endif //_DEBUG aDes.Zero(); const TUint32 PageSz = iPageSizeInBytes;//-- cache page size TInt64 pageStartMedPos = CalcPageStartPos(aPos); const TUint32 bytesToPageEnd = (TUint32)(pageStartMedPos + PageSz - aPos); //-- number of bytes from aPos to the end of the page // __PRINT5(_L("CDynamicDirCache::ReadL: aPos=%lx, aLength=%x, page:%lx, pageSz:%x, bytesToPageEnd=%x"), aPos, aLength, pageStartMedPos, PageSz, bytesToPageEnd); // if all data needed is on a single page if((TUint32)aLength <= bytesToPageEnd) { ReadDataFromSinglePageL(aPos, aLength, aDes); } // or data to be read cross cache page boundary or probably we have more than 1 page to read else { __PRINT(_L("CDynamicDirCache::ReadL() CROSS PAGE!")); TUint32 dataLen(aLength); //-- current data length TInt64 currMediaPos(aPos); //-- current media position //-- 1. read data that are already in the current page ReadDataFromSinglePageL(currMediaPos, bytesToPageEnd, aDes); dataLen -= bytesToPageEnd; currMediaPos += bytesToPageEnd; TPtr8 dataNext = aDes.MidTPtr(aDes.Length()); //-- 2. read whole pages of data while (dataLen >= PageSz) { //-- find out if currMediaPos is in cache. If not, find a spare page and read data there ReadDataFromSinglePageL(currMediaPos, PageSz, dataNext); currMediaPos += PageSz; dataLen -= PageSz; dataNext = dataNext.MidTPtr(dataNext.Length()); } //-- 3. read the rest of the data if(dataLen > 0) { ReadDataFromSinglePageL(currMediaPos, dataLen, dataNext); } } //else((TUint32)aLength <= bytesToPageEnd) }
/** Sets the MTP dataset buffer to be managed. @param aBuffer The MTP dataset buffer to be managed. */ EXPORT_C void TMTPTypeFlatBase::SetBuffer(const TDes8& aBuffer) { iBuffer.Set(aBuffer.MidTPtr(0)); iBuffer.SetLength(iBuffer.MaxLength()); }
EXPORT_C void TMTPTypeNull::SetBuffer(const TDes8& aBuffer) { iNullBuffer.Set(aBuffer.MidTPtr(0)); }
void CRFC3984Encode::FragmentNaluL( TDes8 & aBuffer, TUint32 /*aTimeStamp*/, TUint32 & aMarkerBit, TInt & aNalCount, TInt aStartIndex, TInt aSize, TUint16 aDON ) { TInt index = 0; TInt fragsPacketized = 0; TUint8 headerByte = 0; // FU-A packet header byte (contains F, NRI, Type Fields) TUint8 fragHeaderByte = 0; TInt length = 0; // maximum size of fragment, 4 is to cater for DON field in FU-B TInt fragMaxSize = iMaxPacketSize - 4; TInt fragSize = 0; // size of fragment HBufC8 * pBuffer = NULL; // index keeps track of indexes in the buffer index = aStartIndex; // length of data packetized, the code decrements this after each fragment is made length = aSize; while ( length > 0 ) { // Actually should be based on (PacketizationMode == INTERLEAVED && fragsPacketized == 0) TBool fuB = EFalse; headerByte = aBuffer[aStartIndex] & ( 0x07 << 5 ); // Extracting F and NRI bits // taking lower 5 type bits and putting into fragHeader fragHeaderByte = aBuffer[aStartIndex] & 0x1f; if ( fragsPacketized == 0 ) { fragHeaderByte |= (0x1 << 7); // setting start bit } if ( length <= fragMaxSize ) { fragHeaderByte |= ( 0x1 << 6 ); // setting end byte aMarkerBit = 1; } else { aMarkerBit = 0; } if ( fragsPacketized == 0 ) // skipping payload header byte for FU packets { index += 1; length -= 1; } fragSize = ( length > fragMaxSize ) ? fragMaxSize+2 : length+2; // 2 bytes for headers if( !fuB ) { headerByte |= PACKET_FU_A; } else { fragSize += 2; // for additional DON field headerByte |= PACKET_FU_B; } // allocating memory for fragmented NAL unit pBuffer = HBufC8::NewLC(fragSize); TPtr8 pDes = pBuffer->Des(); //new (ELeave) TBuf8<size>; pDes.Append( &headerByte, 1 ); // appending FU-A packet header byte pDes.Append( &fragHeaderByte, 1 ); // appending Fragment header if ( fuB ) { // writing DON in network byte order TUint16 val = ByteOrder::Swap16( aDON ); TUint8* ptrByte = reinterpret_cast<TUint8*>( &val ); pDes.Append( ptrByte, 2 ); } TPtr8 pStart = aBuffer.MidTPtr( index ); // pStart contains the data pointer if ( !fuB ) { pDes.Append( pStart.Ptr(), fragSize-2 ); // copying data index += Min( length, fragMaxSize ); length -= ( fragSize-2 ); } else { // copying data, subtracting DON and header size from total size to copy pDes.Append( pStart.Ptr( ), fragSize-4 ); index += Min( length, fragMaxSize ); length -= ( fragSize-4 ); } // inserting into the payloadized NAL unit buffer for retreival iPayloadizedBuffers.InsertL( pBuffer, iNalCount ); iNalCount++; CleanupStack::Pop( pBuffer ); pBuffer = NULL; // ownership transferred fragsPacketized++; // to count the number of fragments } // end while() aNalCount = iNalCount; }
void CRFC3984Encode::PayloadizeNaluL( TDes8 & aBuffer, TUint32 /*aTimeStamp*/, TUint32& /*aMarkerBit*/, TInt & aNalCount ) { TInt startIndex = 0; TInt size = 0; __ASSERT_ALWAYS( iToPayloadizeCount > 0, User::Leave( KErrArgument ) ); __ASSERT_ALWAYS( iToPayloadizeBuffer.Count() == iToPayloadizeSizeBuffer.Count(), User::Leave( KErrArgument ) ); if ( iToPayloadizeCount == 1 ) // SNALU packet { startIndex = iToPayloadizeBuffer[0]; size = iToPayloadizeSizeBuffer[0]; TPtr8 start = aBuffer.MidTPtr( startIndex ); AddSnaluPacketL( start, size ); } else // payloadize STAP-A packet { TInt count = 0; TInt totalSize = 0; TUint8 headerByte = 0; for ( count = 0; count < iToPayloadizeCount; count++ ) { // finding total size of all the NALU's to aggregate totalSize += iToPayloadizeSizeBuffer[count]; } // addding the total size fields and STAP-A header size totalSize += ( iToPayloadizeCount*2 + 1 ); count = 0; // allocating memory for the total buffer size HBufC8* pBuffer = HBufC8::NewLC( totalSize ); TUint16 value = 0; TPtr8 pDes1 = pBuffer->Des(); headerByte = PACKET_STAP_A | ( aBuffer[iToPayloadizeBuffer[count]] & ( 0x7 << 5 ) ); pDes1.Append( &headerByte, 1 ); // Pps and sps are handled as SNALUs, // if there's nothing else to packetize, stap-a packet is not created TBool stapPacketCreated( EFalse ); for( count = 0; count < iToPayloadizeCount; count++ ) { startIndex = iToPayloadizeBuffer[count]; size = iToPayloadizeSizeBuffer[count]; TPtr8 pStart = aBuffer.MidTPtr( startIndex ); // getting start index if ( TMccCodecInfo::IsAvcPpsOrSpsData( pStart, ETrue ) ) { AddSnaluPacketL( pStart, size ); } else { // convert to network byte order value = ByteOrder::Swap16( static_cast<TUint16>( size ) ); TUint8* ptrByte = reinterpret_cast<TUint8*>( &value ); pDes1.Append( ptrByte, 2 ); pDes1.Append( pStart.Ptr(), size ); stapPacketCreated = ETrue; } } if ( stapPacketCreated ) { // inserting stap-a packet into the payloadized NAL unit buffer for retrieval iPayloadizedBuffers.InsertL( pBuffer, iNalCount ); iNalCount++; CleanupStack::Pop(pBuffer); } else { // stap-a packet not created CleanupStack::PopAndDestroy(pBuffer); } } //Now cleaning up the buffer iToPayloadizeBuffer.Reset(); iToPayloadizeSizeBuffer.Reset(); iToPayloadizeCount = 0; aNalCount = iNalCount; }
TInt ParseMixedBinaryAsciiDataL(TDes8& aTextToConvert) /** Parses aTextToConvert based on the following rules: '\\' (double backslash) is used to denote a single '\' (single backslash) '\xnn' denote a byte of binary data where nn is in hex-decimal. The '\xnn' in aTextToConvert is replaced by the binary byte that it represents. For example: If aTextToConvert contains "abc\\def\xFF", after parsing, it will contain "abc\def?" where ? = 0xFF. @param aTextToConvert Modifiable buffer which will be parsed. @return KErrNone if aTextToConvert is in valid EAdditionalParamDataFormatMixedBinaryAndAscii format. KErrArgument if aTextToConvert is in an incorrect format. @panic KErrNoMemory if there is not enough memory to do the parsing. */ { // Pointer to unparsed portion of additionalParamDataBuffer HBufC8* resultBuffer = HBufC8::NewLC(aTextToConvert.Length()); __ASSERT_ALWAYS(resultBuffer, PanicClient(KErrNoMemory)); TPtr8 result(resultBuffer->Des()); // Position of backslash TInt pos = 0; while ((pos = aTextToConvert.Locate('\\')) != KErrNotFound) { // Check that the backslash is followed by at least one more character if ((pos+1) >= aTextToConvert.Length()) { return KErrArgument; } TUint8 modifier = aTextToConvert[pos+1]; // Parse depending on character after the backslash switch (modifier) { case '\\': // Next character after the '\' is another '\'. // Replace it with a single '\' and move // on. result.Append(aTextToConvert.Left(pos+1)); aTextToConvert.Delete(0, pos+2); break; case 'x': // Next character is an 'x' so check that there are three // characters after the backslash (one for the x and two // characters of HEX. if ((pos+3) >= aTextToConvert.Length()) { return KErrArgument; } // Convert those to HEX and replace '\xNN' with this. result.Append(aTextToConvert.Left(pos)); TUint8 hexAsInt; if (AsciiHexToNum(aTextToConvert.MidTPtr(pos+2,2), hexAsInt) != KErrNone) { return KErrArgument; } // Append the raw byte to the result result.SetLength(result.Length()+1); result[result.Length()-1] = hexAsInt; aTextToConvert.Delete(0, pos+4); break; } } // End while aTextToConvert.Insert(0, result); CleanupStack::PopAndDestroy(resultBuffer); return KErrNone; }