multimediacommscontroller/mmccavcpayloadformat/src/rfc3984encode.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    AVC Payloadization class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // ============================ INCLUDES =======================================
       
    22 
       
    23 #include"rfc3984encode.h"
       
    24 #include "mccinternalcodecs.h"
       
    25 #include <es_sock.h>
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CRFC3984Encode::CRFC3984Encode()
       
    31 // Default Constructor
       
    32 // (other items were commented in a header).
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CRFC3984Encode::CRFC3984Encode()
       
    36     {
       
    37 	iBufferIndex = 0;
       
    38 	iToPayloadizeCount = 0;
       
    39 	iNalCount = 0;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CRFC3984Encode::~CRFC3984Encode()
       
    44 // Default Destructor
       
    45 // (other items were commented in a header).
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CRFC3984Encode::~CRFC3984Encode()
       
    49     {
       
    50 	ClearNalBuffers();
       
    51 	iToPayloadizeBuffer.Reset( );
       
    52 	iToPayloadizeSizeBuffer.Reset( );	
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CRFC3984Encode::NewL()
       
    57 // First stage constructor
       
    58 // (other items were commented in a header).
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 
       
    62 CRFC3984Encode * CRFC3984Encode::NewL()
       
    63     {
       
    64 	CRFC3984Encode * self = new(ELeave) CRFC3984Encode;
       
    65 	CleanupStack::PushL( self );
       
    66     CleanupStack::Pop();
       
    67     return self;		
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CRFC3984Encode::SetMTUSize()
       
    73 // Purpose     : 
       
    74 // Parameters  : 
       
    75 // Return Value: 
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 
       
    79 void CRFC3984Encode::SetMTUSize( TUint32 aMtuSize )
       
    80     {
       
    81 	iMaxPacketSize = aMtuSize;	
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CRFC3984Encode::SetFrameRate()
       
    87 // Purpose     : 
       
    88 // Parameters  : 
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 
       
    92 void CRFC3984Encode::SetFrameRate( TInt aFrameRate )
       
    93     {
       
    94 	iFrameRate = aFrameRate;	
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CRFC3984Encode::PayloadizeFrameL()
       
    99 // Purpose     : This function receives the encoded frame and payloadizes it based 
       
   100 //               on the packetization_mode value
       
   101 // Parameters  : aBuffer - Buffer containing the encoded frame
       
   102 //				 aTimeStamp - Timestamp to go into RTP
       
   103 // 				 aMarkerBit - Marker Bit indication (this function sets it for key frames)
       
   104 // 				 aNalCount - Reference to return the number of NAL units payloadized
       
   105 // Return Value: none, leaves if an error occured
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 
       
   109 void CRFC3984Encode::PayloadizeFrameL(
       
   110     TDes8 & aBuffer, 
       
   111     TUint32 aTimeStamp, 
       
   112     TUint32 & aMarkerBit, 
       
   113     TInt &aNalCount )
       
   114     {
       
   115 	TInt error = KErrNone;
       
   116 	
       
   117 	if ( iPacketizationMode == AVC_MODE_SNALU )
       
   118 	    {
       
   119 		TRAP( error, 
       
   120 		PayloadizeFrameSingleNALModeL( aBuffer, aTimeStamp, aMarkerBit, aNalCount ) );
       
   121 	    }
       
   122 	else if ( iPacketizationMode == AVC_MODE_NONINTERLEAVED )
       
   123 	    {
       
   124 		TRAP( error, 
       
   125 		PayloadizeFrameNonInterleavedModeL( aBuffer, aTimeStamp, aMarkerBit, aNalCount ) );
       
   126     	}
       
   127 	else if ( iPacketizationMode == AVC_MODE_INTERLEAVED )
       
   128 	    {
       
   129 		User::Leave( KErrNotSupported );
       
   130 	    }
       
   131 	
       
   132 	if ( KErrNone != error )
       
   133 	    {
       
   134 		ClearNalBuffers();
       
   135 		iToPayloadizeBuffer.Reset();
       
   136     	iToPayloadizeSizeBuffer.Reset();
       
   137     	iToPayloadizeCount = 0;
       
   138     	User::Leave( error );
       
   139         }
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CRFC3984Encode::PayloadizeFrameSingleNALModeL()
       
   144 // Purpose     : This function receives the encoded frame and payloadizes it
       
   145 //               according to the SNALU mode
       
   146 // Parameters  : aBuffer - Buffer containing the encoded frame
       
   147 //				 aTimeStamp - Timestamp to go into RTP
       
   148 // 				 aMarkerBit - Marker Bit indication (this function sets it for key frames)
       
   149 //				 aNalCount - This function returns the number of packetized NAL
       
   150 //               units through this variable.
       
   151 // Return Value: none, leaves if an error occured
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 
       
   155 void CRFC3984Encode::PayloadizeFrameSingleNALModeL(
       
   156     TDes8& aBuffer, 
       
   157     TUint32 /*aTimeStamp*/, 
       
   158     TUint32& /*aMarkerBit*/, 
       
   159     TInt& aNalCount )
       
   160     {
       
   161 	// This implementation assumes the NAL units for one frame are seperated
       
   162 	// by 0x001 or 0x0001 start codes 
       
   163     
       
   164     // Resetting iBufferIndex for this new frame, always do this for new frame
       
   165     // because this is used to find start codes within one frame
       
   166     iBufferIndex = 0; 	
       
   167     
       
   168     TInt startIndex = 0;	// holds first byte-index of NALU
       
   169     TInt endIndex = 0;		// hold byte-index of next to last byte of NALU
       
   170     TInt size = 0;
       
   171     HBufC8 * pBuffer = 0;
       
   172     
       
   173     // loop to find and packetize all NAL Units in the frame
       
   174 	while ( ETrue )
       
   175 	    {
       
   176 		startIndex = TMccCodecInfo::FindAvcNaluStart( iBufferIndex, aBuffer );
       
   177 		if ( KErrNotFound == startIndex )
       
   178 		    {
       
   179 			break;
       
   180 		    }
       
   181 		
       
   182 		endIndex = TMccCodecInfo::FindAvcNaluEnd( iBufferIndex, aBuffer );
       
   183 		if ( KErrNotFound == endIndex )
       
   184 		    {
       
   185 			break;
       
   186 		    }
       
   187 		
       
   188 		if ( startIndex == endIndex )
       
   189 		    {
       
   190 			break;
       
   191 		    }
       
   192 				
       
   193 		// finding size of the NAL unit
       
   194 		size = endIndex - startIndex;
       
   195 		
       
   196 		__ASSERT_ALWAYS( size > 0, User::Leave( KErrGeneral ) ); // some flaw in logic
       
   197 		
       
   198 		pBuffer = HBufC8::NewLC( size );
       
   199 		
       
   200 		TPtr8 aPtr = pBuffer->Des();
       
   201 		// Now the size and start Index is known, copying the data
       
   202 		
       
   203 		aPtr.Copy( aBuffer.Mid( startIndex, size ) );
       
   204 		
       
   205 		// Now inserting pointer
       
   206 		iPayloadizedBuffers.InsertL( pBuffer, iNalCount );
       
   207 		CleanupStack::Pop( pBuffer );
       
   208 		pBuffer = NULL;	// ownership transferred
       
   209 		iNalCount++;
       
   210 	    }
       
   211     
       
   212     aNalCount = iNalCount;
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CRFC3984Encode::PayloadizeFrameNonInterleavedModeL()
       
   217 // Purpose     : This function receives the encoded frame and payloadizes it
       
   218 //               according to the Non-Interleaved Mode
       
   219 // Parameters  : aBuffer - Buffer containing the encoded frame
       
   220 //				 aTimeStamp - Timestamp to go into RTP
       
   221 // 				 aMarkerBit - Marker Bit indication (this function sets it for key frames)
       
   222 //				 aNalCount - This function returns the number of packetized
       
   223 //               NAL units through this variable.
       
   224 // Return Value: none, leaves if an error occured
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 
       
   228 void CRFC3984Encode::PayloadizeFrameNonInterleavedModeL(
       
   229     TDes8& aBuffer, 
       
   230     TUint32 aTimeStamp, 
       
   231     TUint32& aMarkerBit, 
       
   232     TInt& aNalCount )
       
   233     {
       
   234 	iNalCount = 0;
       
   235 	aNalCount = 0; // resetting value coming from above
       
   236 	iBufferIndex = 0;
       
   237 	
       
   238 	TInt startIndex = 0;
       
   239 	TInt endIndex = 0;
       
   240 	TInt size = 0;
       
   241 	TInt count = 0; // variable to keep track of the size of aggregated packet.
       
   242 	
       
   243 	aNalCount = 0;
       
   244 	
       
   245 	// loop to find and packetize all NAL Units in the frame
       
   246 	while( ETrue )
       
   247 	    {
       
   248 		startIndex = TMccCodecInfo::FindAvcNaluStart( iBufferIndex, aBuffer );
       
   249 		if ( startIndex == KErrNotFound )
       
   250 		    {
       
   251 			break;
       
   252 		    }
       
   253 		
       
   254 		endIndex = TMccCodecInfo::FindAvcNaluEnd( iBufferIndex, aBuffer );
       
   255 		if ( endIndex == KErrNotFound )
       
   256 		    {
       
   257 			break;
       
   258 		    }
       
   259 		
       
   260 		if ( startIndex == endIndex )
       
   261 		    {
       
   262 			break;
       
   263 		    }
       
   264 		    
       
   265 		// finding size of the NAL unit
       
   266 		size = endIndex - startIndex;
       
   267 		
       
   268 		__ASSERT_ALWAYS( size > 0, User::Leave( KErrGeneral ) ); // some flaw in logic
       
   269 		
       
   270 		// Now startIndex and size of this NAL Unit are known
       
   271 		// decide if SNALU packetization or STAP or FU-A is required
       
   272 		if ( size > iMaxPacketSize )
       
   273 		    {
       
   274 		    // if any NALU there for aggregation or SNALU, payloadize it first
       
   275 			if ( iToPayloadizeCount > 0 )  
       
   276 			    {
       
   277 				PayloadizeNaluL( aBuffer, aTimeStamp, aMarkerBit, aNalCount );
       
   278 				
       
   279 				count = 0; // resetting count of bytes for aggregation packets
       
   280 				iToPayloadizeCount = 0;	
       
   281 			    }
       
   282 			
       
   283 			FragmentNaluL( aBuffer, aTimeStamp, aMarkerBit, aNalCount, startIndex, size, 0 );
       
   284 		    }
       
   285 		else if ( size <= iMaxPacketSize )
       
   286 		    {
       
   287 			if( size + count > iMaxPacketSize )
       
   288 			    {
       
   289 				// make STAP-A or SNALU based on number of elements in the buffer
       
   290 				PayloadizeNaluL( aBuffer, aTimeStamp, aMarkerBit, aNalCount );
       
   291 				
       
   292 				count = 0;   // resetting count of bytes for aggregation packets
       
   293 				iToPayloadizeCount = 0;
       
   294 			    }	
       
   295 			// Insert current NALU into the Buffer.
       
   296 			iToPayloadizeBuffer.InsertL( startIndex, iToPayloadizeCount );
       
   297 			iToPayloadizeSizeBuffer.InsertL( size, iToPayloadizeCount );
       
   298 			iToPayloadizeCount++;
       
   299 			count += size;
       
   300 		    }
       
   301 	    } // end while()
       
   302 	
       
   303 	// packetizing any last NALUs left in the buffer
       
   304 	if ( iToPayloadizeCount > 0 )
       
   305 	    {
       
   306 	 	PayloadizeNaluL( aBuffer, aTimeStamp, aMarkerBit, aNalCount );
       
   307 	 	count = 0;
       
   308 	 	iToPayloadizeCount = 0;
       
   309 	    }
       
   310     }
       
   311 
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CRFC3984Encode::PayloadizeNaluL()
       
   315 // Purpose     : This function makes a SNALU packet or STAP-A packet based on the
       
   316 //               number of NALUs in the array iToPayloadizeBuffer.
       
   317 // Parameters  : aBuffer - Buffer containing the encoded frame
       
   318 //				 aTimeStamp - Timestamp to go into RTP
       
   319 // 				 aMarkerBit - Marker Bit indication (this function sets it for key frames)
       
   320 //				 aNalCount - This function returns the number of packetized
       
   321 //               NAL units through this variable.
       
   322 //				 aStartIndex - Index to the starting of the NALU
       
   323 // Return Value: none, leaves if an error occured
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 
       
   327 void CRFC3984Encode::PayloadizeNaluL(
       
   328     TDes8 & aBuffer, 
       
   329     TUint32 /*aTimeStamp*/, 
       
   330     TUint32& /*aMarkerBit*/, 
       
   331     TInt & aNalCount )
       
   332     {
       
   333 	TInt startIndex = 0;
       
   334 	TInt size = 0;
       
   335 	
       
   336 	__ASSERT_ALWAYS( iToPayloadizeCount > 0, User::Leave( KErrArgument ) );
       
   337 	
       
   338 	__ASSERT_ALWAYS( iToPayloadizeBuffer.Count() == iToPayloadizeSizeBuffer.Count(), 
       
   339 	                 User::Leave( KErrArgument ) );
       
   340 		
       
   341 	if ( iToPayloadizeCount == 1 ) // SNALU packet
       
   342 	    {
       
   343 		startIndex = iToPayloadizeBuffer[0];
       
   344 		size = iToPayloadizeSizeBuffer[0];	
       
   345 		TPtr8 start = aBuffer.MidTPtr( startIndex );
       
   346 		AddSnaluPacketL( start, size );
       
   347     	}
       
   348 	else // payloadize STAP-A packet
       
   349 	    {
       
   350 		TInt count = 0;
       
   351 		TInt totalSize = 0;
       
   352 		TUint8 headerByte = 0;
       
   353 		
       
   354 		for ( count = 0; count < iToPayloadizeCount; count++ )
       
   355 		    {
       
   356 		    // finding total size of all the NALU's to aggregate
       
   357 			totalSize += iToPayloadizeSizeBuffer[count]; 
       
   358 		    }
       
   359 		
       
   360 		// addding the total size fields and STAP-A header size	
       
   361 		totalSize += ( iToPayloadizeCount*2 + 1 ); 
       
   362 		
       
   363 		count = 0;
       
   364 		
       
   365 		// allocating memory for the total buffer size		
       
   366 		HBufC8* pBuffer = HBufC8::NewLC( totalSize );
       
   367 		
       
   368 		TUint16 value = 0;
       
   369 		TPtr8 pDes1 = pBuffer->Des();
       
   370 		
       
   371 		headerByte = PACKET_STAP_A | ( aBuffer[iToPayloadizeBuffer[count]] & ( 0x7 << 5 ) ); 
       
   372 		pDes1.Append( &headerByte, 1 );
       
   373 		
       
   374 		 // Pps and sps are handled as SNALUs, 
       
   375 		 // if there's nothing else to packetize, stap-a packet is not created
       
   376 		TBool stapPacketCreated( EFalse );
       
   377 		for( count = 0; count < iToPayloadizeCount; count++ )
       
   378 		    {
       
   379 			startIndex = iToPayloadizeBuffer[count];
       
   380 			size = iToPayloadizeSizeBuffer[count];
       
   381 			TPtr8 pStart = aBuffer.MidTPtr( startIndex ); // getting start index
       
   382 			
       
   383 			if ( TMccCodecInfo::IsAvcPpsOrSpsData( pStart, ETrue ) )
       
   384 			    {
       
   385 			    AddSnaluPacketL( pStart, size );
       
   386 			    }
       
   387 			else
       
   388 			    {
       
   389     			// convert to network byte order
       
   390     			value = ByteOrder::Swap16( static_cast<TUint16>( size ) ); 
       
   391     			TUint8* ptrByte = reinterpret_cast<TUint8*>( &value );
       
   392     			pDes1.Append( ptrByte, 2 );
       
   393     			pDes1.Append( pStart.Ptr(), size );
       
   394     			stapPacketCreated = ETrue;
       
   395 			    }
       
   396 		    }
       
   397 		
       
   398 		if ( stapPacketCreated )
       
   399 		    {
       
   400     		// inserting stap-a packet into the payloadized NAL unit buffer for retrieval
       
   401         	iPayloadizedBuffers.InsertL( pBuffer, iNalCount );
       
   402         	iNalCount++;
       
   403         	CleanupStack::Pop(pBuffer);
       
   404 		    }
       
   405 		else
       
   406 		    {
       
   407 		    // stap-a packet not created
       
   408 		    CleanupStack::PopAndDestroy(pBuffer);
       
   409 		    }
       
   410 	    }
       
   411 	
       
   412     //Now cleaning up the buffer
       
   413     iToPayloadizeBuffer.Reset();
       
   414     iToPayloadizeSizeBuffer.Reset();
       
   415     iToPayloadizeCount = 0;
       
   416     	
       
   417 	aNalCount = iNalCount;
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CRFC3984Encode::FragmentNaluL()
       
   422 // Purpose     : This function receives the starting index of a NALU in a buffer and
       
   423 //               fragments the NAL unit
       
   424 // Parameters  : aBuffer - Buffer containing the encoded frame
       
   425 //				 aTimeStamp - Timestamp to go into RTP
       
   426 // 				 aMarkerBit - Marker Bit indication (this function sets it for key frames)
       
   427 //				 aNalCount - This function returns the number of packetized NAL units
       
   428 //               through this variable.
       
   429 //				 aStartIndex - Index to the starting of the NALU
       
   430 // 				 aSize - Size of the NALU
       
   431 //				 aDon - valeu of Decoding order number , 16 bit value
       
   432 // Return Value: none, leaves if an error occured
       
   433 // -----------------------------------------------------------------------------
       
   434 //
       
   435 
       
   436 void CRFC3984Encode::FragmentNaluL(
       
   437     TDes8 & aBuffer, 
       
   438     TUint32 /*aTimeStamp*/, 
       
   439     TUint32 & aMarkerBit, 
       
   440     TInt & aNalCount, 
       
   441     TInt aStartIndex, 
       
   442     TInt aSize, 
       
   443     TUint16 aDON )
       
   444     {
       
   445 	TInt index = 0;
       
   446 	TInt fragsPacketized = 0;
       
   447 	TUint8 headerByte = 0; // FU-A packet header byte (contains F, NRI, Type Fields) 
       
   448 	TUint8 fragHeaderByte = 0;
       
   449 	TInt length = 0;
       
   450 	// maximum size of fragment, 4 is to cater for DON field in FU-B
       
   451 	TInt fragMaxSize = iMaxPacketSize - 4; 
       
   452 	TInt fragSize = 0; // size of fragment
       
   453 	HBufC8 * pBuffer = NULL;
       
   454 	
       
   455 	// index keeps track of indexes in the buffer
       
   456 	index = aStartIndex; 
       
   457 	// length of data packetized, the code decrements this after each fragment is made
       
   458 	length = aSize;	
       
   459 	
       
   460 	while ( length > 0 )
       
   461 	    {
       
   462 	     // Actually should be based on (PacketizationMode == INTERLEAVED && fragsPacketized == 0)
       
   463 		TBool fuB = EFalse;
       
   464 		
       
   465 		headerByte = aBuffer[aStartIndex]  & ( 0x07 << 5 ); // Extracting F and NRI bits
       
   466 		
       
   467 		// taking lower 5 type bits and putting into fragHeader
       
   468 		fragHeaderByte = aBuffer[aStartIndex] & 0x1f; 
       
   469 			
       
   470 		if ( fragsPacketized == 0 )
       
   471 		    {
       
   472 		    fragHeaderByte |= (0x1 << 7); // setting start bit
       
   473 		    }
       
   474 		    
       
   475 		if ( length <= fragMaxSize )
       
   476 		    {
       
   477 			fragHeaderByte |= ( 0x1 << 6 );	// setting end byte
       
   478 			aMarkerBit = 1;	
       
   479 		    }
       
   480 		else
       
   481 		    {
       
   482 			aMarkerBit = 0;
       
   483 		    }
       
   484 		
       
   485 		if ( fragsPacketized == 0 )	// skipping payload header byte for FU packets 
       
   486 		    {	
       
   487 		    index += 1;
       
   488 			length -= 1;	
       
   489 		    }
       
   490 	    
       
   491 	    fragSize = ( length > fragMaxSize ) ? fragMaxSize+2 : length+2; // 2 bytes for headers
       
   492 		
       
   493 		if( !fuB )
       
   494 		    {
       
   495 			headerByte |= PACKET_FU_A;	
       
   496 		    }
       
   497 		else
       
   498 		    {
       
   499 			fragSize += 2; // for additional DON field
       
   500 			headerByte |= PACKET_FU_B;
       
   501 		    }
       
   502 		
       
   503 		// allocating memory for fragmented NAL unit
       
   504 	    pBuffer = HBufC8::NewLC(fragSize);
       
   505 	     	
       
   506  		TPtr8 pDes = pBuffer->Des(); //new (ELeave) TBuf8<size>;
       
   507 		pDes.Append( &headerByte, 1 ); // appending FU-A packet header byte
       
   508 		pDes.Append( &fragHeaderByte, 1 ); // appending Fragment header
       
   509 		
       
   510 		if ( fuB )
       
   511 		    {  
       
   512 		    // writing DON in network byte order
       
   513 			TUint16 val = ByteOrder::Swap16( aDON );
       
   514 			TUint8* ptrByte = reinterpret_cast<TUint8*>( &val );
       
   515 			pDes.Append( ptrByte, 2 );
       
   516 		    }
       
   517 		
       
   518 		TPtr8 pStart = aBuffer.MidTPtr( index ); // pStart contains the data pointer    		
       
   519     	
       
   520     	if ( !fuB )
       
   521     	    {
       
   522     		pDes.Append( pStart.Ptr(), fragSize-2 ); // copying data	
       
   523     		index += Min( length, fragMaxSize );    	
       
   524     		length -= ( fragSize-2 );
       
   525         	}
       
   526     	else
       
   527     	    {
       
   528     	    // copying data, subtracting DON and header size from total size to copy
       
   529     		pDes.Append( pStart.Ptr( ), fragSize-4 );
       
   530 			index += Min( length, fragMaxSize );
       
   531 			length -= ( fragSize-4 );    		
       
   532     	    }
       
   533     
       
   534     	
       
   535     	// inserting into the payloadized NAL unit buffer for retreival
       
   536     	iPayloadizedBuffers.InsertL( pBuffer, iNalCount );
       
   537     	iNalCount++;
       
   538     	CleanupStack::Pop( pBuffer );
       
   539     	pBuffer = NULL; // ownership transferred
       
   540     	
       
   541     	fragsPacketized++; // to count the number of fragments
       
   542 	
       
   543 	    } // end while()
       
   544 	
       
   545 	aNalCount = iNalCount;
       
   546     }
       
   547 
       
   548 
       
   549 HBufC8 * CRFC3984Encode::GetNalUnitsInOrder( TInt & aIndex )
       
   550     {
       
   551 	HBufC8 *pBuffer;
       
   552 	if ( aIndex < iNalCount )
       
   553 	    {
       
   554 		pBuffer = iPayloadizedBuffers[aIndex];
       
   555 		return (pBuffer);
       
   556 	    }
       
   557 	else
       
   558 	    {
       
   559 		return NULL;
       
   560 	    }
       
   561 	
       
   562     }
       
   563 
       
   564 void CRFC3984Encode::ClearNalBuffers()
       
   565     {
       
   566 	TInt count = 0;
       
   567 	HBufC8 * pBuffer = NULL;
       
   568 	
       
   569 	for ( count = 0; count < iPayloadizedBuffers.Count(); count++ )
       
   570 	    {
       
   571 		pBuffer = iPayloadizedBuffers[count];
       
   572 		delete pBuffer;
       
   573 		pBuffer = NULL;
       
   574 		iPayloadizedBuffers[count] = NULL;
       
   575 	    }
       
   576 	
       
   577 	iPayloadizedBuffers.Reset();
       
   578 	iNalCount = 0; 
       
   579     }
       
   580 
       
   581 void CRFC3984Encode::AddSnaluPacketL( TPtr8 aStart, TInt aSize )
       
   582     {
       
   583     HBufC8* pBuffer = HBufC8::NewLC( aSize );
       
   584 	
       
   585 	TPtr8 pPtr = pBuffer->Des();
       
   586 	pPtr.Copy( aStart.Ptr(), aSize );
       
   587 	
       
   588 	// inserting into the payloadized NAL unit buffer for retreival
       
   589 	iPayloadizedBuffers.InsertL( pBuffer, iNalCount );
       
   590 	iNalCount++;
       
   591 	CleanupStack::Pop( pBuffer );
       
   592     }
       
   593     	
       
   594 // End of file
       
   595