multimediacommscontroller/mmccavcpayloadformat/src/avcpayloadformatwrite.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 Payload Format Write .. Payloadizes incoming frames into RTP packets
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <e32base.h>
       
    25 #include <mmf/common/mmffourcc.h>
       
    26 #include <sysutil.h>
       
    27 #include "avcpayloadformatwrite.h"
       
    28 #include "mccrtpdatasink.h"
       
    29 #include "mccinternaldef.h"
       
    30 #include "mmcccodecavc.h"
       
    31 #include "avcpayloadformatlogs.h"
       
    32 
       
    33 
       
    34 // ============================= LOCAL FUNCTIONS ===============================
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CAvcPayloadFormatWrite::CAvcPayloadFormatWrite
       
    41 //
       
    42 // CAvcPayloadFormatWrite default constructor, can NOT contain any code,
       
    43 // that might leave
       
    44 // Phase #1 of 2-phase constructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CAvcPayloadFormatWrite::CAvcPayloadFormatWrite ( )
       
    48     {
       
    49     iFrameTimeInterval = 0;
       
    50     iSourceBuffer = NULL;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CAvcPayloadFormatWrite::NewL
       
    55 //
       
    56 // Two-phased constructor.
       
    57 // Static function for creating and constructing an instance of the AVC formatter.
       
    58 //
       
    59 // Returns:  CAvcPayloadFormatWrite* : pointer to created instance
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CAvcPayloadFormatWrite* CAvcPayloadFormatWrite::NewL( MDataSink* aSink )
       
    63     {
       
    64     CAvcPayloadFormatWrite* self = new ( ELeave ) CAvcPayloadFormatWrite;
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL( aSink );
       
    67     CleanupStack::Pop();
       
    68     return self;
       
    69     }
       
    70     
       
    71 // -----------------------------------------------------------------------------
       
    72 // CAvcPayloadFormatWrite::ConstructL
       
    73 //
       
    74 // Symbian 2nd phase constructor can leave.
       
    75 // Phase #2 of 2-phase constructor
       
    76 // Initializes the Encoder State Machine and Encoder
       
    77 // Parameters:
       
    78 //  aSink				:	data sink
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 void CAvcPayloadFormatWrite::ConstructL( MDataSink* aSink )
       
    82     {
       
    83     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::ConstructL")
       
    84     
       
    85     __ASSERT_ALWAYS( aSink, User::Leave ( KErrArgument ) );
       
    86     
       
    87 	// Set data sink
       
    88     iClip = aSink;
       
    89       
       
    90     iIsRtpSink = ( KMccRtpSinkUid == iClip->DataSinkType() );
       
    91 
       
    92     // Initialize state machine
       
    93     iStateMachine = CFormatEncodeStateMachine::NewL( this );
       
    94     iStateMachine->ChangeState( EEncodeIdle );
       
    95     iCurDataSink = aSink;
       
    96     
       
    97     iEncoder = CRFC3984Encode::NewL();
       
    98     
       
    99     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::ConstructL, exit")
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CAvcPayloadFormatWrite::~CAvcPayloadFormatWrite
       
   105 //
       
   106 // Destructor.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CAvcPayloadFormatWrite::~CAvcPayloadFormatWrite ( )
       
   110     {
       
   111     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::~CAvcPayloadFormatWrite")
       
   112     
       
   113     delete iSourceBuffer;
       
   114     delete iSinkBuffer;
       
   115     delete iStateMachine;
       
   116     delete iEncoder;
       
   117     
       
   118     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::~CAvcPayloadFormatWrite, exit")
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CAvcPayloadFormatWrite::SetPayloadType
       
   123 // Set PayloadType
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CAvcPayloadFormatWrite::SetPayloadType( TUint8 aPayloadType )
       
   127     {
       
   128 	iCInfo.iPayloadType = aPayloadType;
       
   129     }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CAvcPayloadFormatWrite::FrameTimeInterval
       
   134 //
       
   135 // Return the frame time interval for the given media
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TTimeIntervalMicroSeconds CAvcPayloadFormatWrite::FrameTimeInterval( TMediaId aMediaId ) const
       
   139     {
       
   140     if ( aMediaId.iMediaType == KUidMediaTypeVideo )
       
   141         {
       
   142         return iFrameTimeInterval;
       
   143         }
       
   144     else
       
   145         {
       
   146         return TTimeIntervalMicroSeconds( 0 );
       
   147         }
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CAvcPayloadFormatWrite::CreateSinkBufferL
       
   152 //
       
   153 // Create a source buffer for the given media and indicate in aReference if buffer
       
   154 // is created.
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 CMMFBuffer* CAvcPayloadFormatWrite::CreateSinkBufferL( TMediaId aMediaId, 
       
   158                                                        TBool &aReference )
       
   159     {
       
   160   
       
   161     if ( aMediaId.iMediaType != KUidMediaTypeVideo )
       
   162         {
       
   163         User::Leave( KErrNotSupported );
       
   164         }
       
   165 	
       
   166     aReference = ETrue;
       
   167    	return CreateSinkBufferOfSizeL( iCInfo.iFrameSize );
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CAvcPayloadFormatWrite::CreateSinkBufferOfSizeL
       
   172 //
       
   173 // Create a sink buffer of the given size.
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 CMMFDataBuffer* CAvcPayloadFormatWrite::CreateSinkBufferOfSizeL( TUint aSize )
       
   177     {
       
   178 	// the buffer is created once and the component retains ownership in order to delete the resource
       
   179 
       
   180 	if(NULL == iSourceBuffer)
       
   181 	    {
       
   182 		//needs to create source buffer
       
   183 		iSourceBuffer = CMMFDataBuffer::NewL( aSize );
       
   184 		iSourceBuffer->Data().FillZ( aSize );
       
   185 		iSourceBuffer->SetRequestSizeL( aSize );
       
   186 	    }
       
   187 	
       
   188     return iSourceBuffer;
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CAvcPayloadFormatWrite::SinkDataTypeCode
       
   193 //
       
   194 // Return the sink data type ( four CC code ) for the given media
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 TFourCC CAvcPayloadFormatWrite::SinkDataTypeCode( TMediaId aMediaId )
       
   198     {
       
   199     if ( aMediaId.iMediaType == KUidMediaTypeVideo ) 
       
   200         {
       
   201         return iCInfo.iFourCC;
       
   202         }
       
   203     else 
       
   204         {
       
   205         return TFourCC( ); //defaults to 'NULL' fourCC
       
   206         }
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CAvcPayloadFormatWrite::SetSinkDataTypeCode
       
   211 //
       
   212 // Set the sink data type to the given four CC code for the given media
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 TInt CAvcPayloadFormatWrite::SetSinkDataTypeCode( TFourCC aSinkFourCC, 
       
   216                                                   TMediaId aMediaId )
       
   217     {
       
   218     if ( aMediaId.iMediaType != KUidMediaTypeVideo )
       
   219         {
       
   220         return KErrNotSupported;
       
   221         }
       
   222     else 
       
   223         {
       
   224         iCInfo.iFourCC = aSinkFourCC;
       
   225         }
       
   226 
       
   227     return KErrNone;
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CAvcPayloadFormatWrite::SinkThreadLogon
       
   232 //
       
   233 // Passes the logon command to the sink clip
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 TInt CAvcPayloadFormatWrite::SinkThreadLogon( MAsyncEventHandler& aEventHandler )
       
   237     {
       
   238     iCurDataSink->SinkThreadLogon( aEventHandler );
       
   239     return KErrNone;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CAvcPayloadFormatWrite::SinkThreadLogoff
       
   244 //
       
   245 // Log out of the sink thread.
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void CAvcPayloadFormatWrite::SinkThreadLogoff ( )
       
   249     {
       
   250     iCurDataSink->SinkThreadLogoff( );
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CAvcPayloadFormatWrite::ProcessFramesL
       
   255 //
       
   256 // Packetize the AVC frames received from AVC codec and deliver the packets.
       
   257 // The AVC frames are stored in "iSourceBuffer".
       
   258 // return value - Current talk spurt finished, ETrue. Otherwise, EFalse
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 TBool CAvcPayloadFormatWrite::ProcessFramesL( )
       
   262     {
       
   263     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::ProcessFramesL")
       
   264     
       
   265     __ASSERT_ALWAYS( iSourceBuffer, User::Leave( KErrNotReady ) );
       
   266     
       
   267 	TInt nalCount = 0;
       
   268     TUint32 markerBit = 0;
       
   269     TDes8& srcDes = iSourceBuffer->Data();
       
   270     HBufC8* bufPtr = NULL;
       
   271     TInt count = 0;
       
   272     TBool retVal = EFalse;
       
   273     
       
   274     if ( !iSinkBuffer )
       
   275         {
       
   276         __AVCPLFORMAT_CONTROLL(
       
   277             "CAvcPayloadFormatWrite::ProcessFramesL, sink not ready, exit")
       
   278         return retVal;
       
   279         }	
       
   280     
       
   281     // Get timestamp to RTP header. conversion to 90kHz clock
       
   282 	iRtpSendHeader.iTimestamp = iSourceBuffer->TimeToPlay().Int64() / 100 * 9; 
       
   283     
       
   284     iEncoder->PayloadizeFrameL( srcDes, iRtpSendHeader.iTimestamp, markerBit, nalCount );
       
   285         
       
   286    	for ( count = 0; count < nalCount; count++ )
       
   287    	    {
       
   288    	    __AVCPLFORMAT_CONTROLL("looping")
       
   289    	    
       
   290    		// getting data
       
   291    		bufPtr = iEncoder->GetNalUnitsInOrder( count );
       
   292    		User::LeaveIfNull( bufPtr );
       
   293    		TPtr8 ptr = bufPtr->Des();
       
   294    		
       
   295    		// copying data to sink
       
   296    		TDes8& dataDes = iSinkBuffer->Data();
       
   297    		
       
   298    		dataDes.Copy( ptr.Ptr(), ptr.Length() );
       
   299    		
       
   300 		// filling RTP Header structure
       
   301 		
       
   302 		iSinkBuffer->SetFrameNumber( iSourceBuffer->FrameNumber() + iSeqNumIncrementer );
       
   303 
       
   304 		// Setting marker bit only for last packet if more than one NAL unit
       
   305 		// for same ts, marker bit is never set for sps or pps
       
   306 		if ( nalCount > 1 && ( count != nalCount-1 ) )
       
   307 		    {
       
   308 		    iRtpSendHeader.iMarker = 0;
       
   309 		    
       
   310 		    // If frame is divided in several packets, sequence numbers of following
       
   311 	        // packets have to be modified
       
   312 		    iSeqNumIncrementer++;
       
   313 		    }
       
   314 		else if ( TMccCodecInfo::IsAvcPpsOrSpsData( ptr, ETrue ) )
       
   315 		    {
       
   316 		    iRtpSendHeader.iMarker = 0;
       
   317 		    }
       
   318 	    else
       
   319 	        {
       
   320 	        iRtpSendHeader.iMarker = 1;
       
   321 	        }
       
   322 	        
       
   323 		iRtpSendHeader.iPayloadType = iCInfo.iPayloadType; // as per configured
       
   324    		
       
   325    		if ( iIsRtpSink )
       
   326     	    {
       
   327         	CMccRtpDataSink* rtpSink = static_cast<CMccRtpDataSink*>( iCurDataSink );
       
   328     	    rtpSink->EmptyBufferL( iSinkBuffer, this, iMediaId, iRtpSendHeader );
       
   329     	    }
       
   330     	else
       
   331     	    {
       
   332     	    iSinkBuffer->SetTimeToPlay( iRtpSendHeader.iTimestamp );
       
   333 		    iSinkBuffer->SetLastBuffer( iRtpSendHeader.iMarker );
       
   334     	    iCurDataSink->EmptyBufferL( iSinkBuffer, this, iMediaId );
       
   335     	    }
       
   336 	    }
       
   337    	
       
   338    	// this clears the buffers in the encoder filled with data, necessary to do this
       
   339    	iEncoder->ClearNalBuffers();	
       
   340     
       
   341     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::ProcessFramesL, exit")
       
   342     // probably it always returns false because in TRUE case, S/M goes IDLE,
       
   343     // which is not desired in video
       
   344     return retVal;
       
   345     }
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 // CAvcPayloadFormatWrite::EmptyBufferL
       
   349 //
       
   350 // Empty the given source buffer by formatting the AVC frames into RTP payload.
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 void CAvcPayloadFormatWrite::EmptyBufferL( CMMFBuffer* aBuffer, 
       
   354                                            MDataSource* aSupplier, 
       
   355                                            TMediaId aMediaId )
       
   356     {
       
   357  
       
   358     if ( aMediaId.iMediaType != KUidMediaTypeVideo )
       
   359         {
       
   360         User::Leave( KErrNotSupported );
       
   361         }
       
   362     
       
   363     // MMF buffer must never be NULL
       
   364     __ASSERT_ALWAYS (aBuffer, User::Leave(KErrArgument));
       
   365     
       
   366     // Make sure that the very buffer is passed on, which we created once...
       
   367     // This is necessary to avoid double-deletion problems etc.
       
   368     __ASSERT_ALWAYS (aBuffer == iSourceBuffer, User::Leave(KErrArgument));
       
   369     
       
   370     // if same buffer is passed then no need to save the pointer; we already have it
       
   371 
       
   372     // Save source buffer parameters and change the state.
       
   373     iDataPath = aSupplier;
       
   374     iMediaId = aMediaId;
       
   375     
       
   376     // we request S/M to call our EmptySourceBufferL() function
       
   377     iStateMachine->ChangeState( EEmptySourceBuffer );
       
   378 
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CAvcPayloadFormatWrite::EmptySourceBufferL
       
   383 //
       
   384 // Empty the given source buffer by formatting the AMR frames into RTP payload.
       
   385 // Source buffer is given in "iSourceBuffer".
       
   386 // Called by the state machine.
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 void CAvcPayloadFormatWrite::EmptySourceBufferL( )
       
   390     {
       
   391   
       
   392     if ( this->ProcessFramesL( ) )
       
   393         {
       
   394         // Current talk spurt is finished. Either last buffer
       
   395         iStateMachine->ChangeState( EEncodeIdle );
       
   396         }
       
   397     else
       
   398         {
       
   399         // Just one step in a talk spurt
       
   400         iStateMachine->ChangeState( ESourceBufferEmptied );
       
   401         }
       
   402     }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // CAvcPayloadFormatWrite::SourceBufferEmptiedL
       
   406 //
       
   407 // Hanlde the event that source buffer has been emptied.
       
   408 // Source buffer is given in "iSourceBuffer".
       
   409 // Called by the state machine.
       
   410 // -----------------------------------------------------------------------------
       
   411 //
       
   412 void CAvcPayloadFormatWrite::SourceBufferEmptiedL( )
       
   413     {
       
   414     __ASSERT_ALWAYS( iDataPath, User::Leave( KErrNotReady ) );
       
   415     iDataPath->BufferEmptiedL( iSourceBuffer );
       
   416     }
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CAvcPayloadFormatWrite::BufferEmptiedL
       
   420 //
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 void CAvcPayloadFormatWrite::BufferEmptiedL( CMMFBuffer* /*aBuffer*/ )
       
   424     {
       
   425     // We're using synchronous EmptyBufferL( aBuffer ) function call to RTP Sink.
       
   426     // The aBuffer is ready to be used again when the EmptyBufferL returns back.
       
   427     // So BufferEmptiedL( aBuffer ) is not really used.
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CAvcPayloadFormatWrite::Duration
       
   432 //
       
   433 // Return the clip duration for the given media. Returns a big value, 
       
   434 // which is not usable since this function is not being used for video.
       
   435 // The return value should be ignored.
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 TTimeIntervalMicroSeconds CAvcPayloadFormatWrite::Duration( TMediaId /*aMediaType*/ ) const
       
   439     {
       
   440     return TTimeIntervalMicroSeconds( 1000000000 );
       
   441     }
       
   442 
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // CAvcPayloadFormatWrite::CancelUlRequest
       
   446 // Cancel UL Request
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 void CAvcPayloadFormatWrite::CancelUlRequest( )
       
   450     {
       
   451     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::CancelUlRequest")
       
   452      
       
   453     iStateMachine->Cancel( );
       
   454     iStateMachine->ChangeState( EEncodeIdle );
       
   455 
       
   456      // Reset the payload buffer
       
   457     if ( iSinkBuffer )
       
   458         {
       
   459         TDes8& dataDes = iSinkBuffer->Data();
       
   460         dataDes.SetLength( 0 );
       
   461         }
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CAvcPayloadFormatWrite::SinkPrimeL( )
       
   466 // Primes sink
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 void CAvcPayloadFormatWrite::SinkPrimeL( )
       
   470     {
       
   471     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkPrimeL")
       
   472     
       
   473     iCurDataSink->SinkPrimeL();
       
   474     
       
   475     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkPrimeL, exit")
       
   476     }
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CAvcPayloadFormatWrite::SinkPlayL( )
       
   480 // Plays sink
       
   481 // -----------------------------------------------------------------------------
       
   482 //
       
   483 void CAvcPayloadFormatWrite::SinkPlayL( )
       
   484     {
       
   485     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkPlayL")
       
   486     
       
   487     // Allocate buffer for data transfer between 
       
   488     // FormatWrite - MDataSink AND FormatWrite - redundancy payload encoder
       
   489 	
       
   490     delete iSinkBuffer;
       
   491     iSinkBuffer = NULL;
       
   492     iSinkBuffer = CMMFDataBuffer::NewL( iCInfo.iFrameSize );
       
   493 
       
   494     // Initialize payload encoder
       
   495     TDes8& dataDes = iSinkBuffer->Data();
       
   496     dataDes.SetLength( 0 );   // for first packet length
       
   497     
       
   498     iSinkBuffer->SetLastBuffer( EFalse );
       
   499     
       
   500     iCurDataSink->SinkPlayL();
       
   501     
       
   502     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkPlayL, exit")
       
   503     }
       
   504 
       
   505 // -----------------------------------------------------------------------------
       
   506 // CAvcPayloadFormatWrite::SinkPauseL( )
       
   507 // Pauses sink
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 void CAvcPayloadFormatWrite::SinkPauseL( )
       
   511     {
       
   512     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkPauseL")
       
   513     
       
   514     iCurDataSink->SinkPauseL( );
       
   515     
       
   516     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkPauseL, exit")
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CAvcPayloadFormatWrite::SinkStopL( )
       
   521 // Stops sink
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 void CAvcPayloadFormatWrite::SinkStopL( )
       
   525     {
       
   526     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkStopL")
       
   527      
       
   528     if ( EEmptySourceBuffer == iStateMachine->CurrentState( ) )
       
   529         {
       
   530         return;
       
   531         }
       
   532 
       
   533     // Stop state machine
       
   534     CancelUlRequest( );
       
   535 
       
   536     iCurDataSink->SinkStopL( );
       
   537     
       
   538     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::SinkStopL, exit")
       
   539     }
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CAvcPayloadFormatWrite::ConfigurePayloadFormatL
       
   543 // Configure payload encoding parameters.
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 void CAvcPayloadFormatWrite::ConfigurePayloadFormatL(
       
   547     const TDesC8& aConfigParams,
       
   548     CMccRtpMediaClock& /*aClock*/ )
       
   549     {
       
   550 	__AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::ConfigurePayloadFormatL")
       
   551 	
       
   552 	if ( aConfigParams.Size() == sizeof( TMccCodecInfo ) )
       
   553         {
       
   554         TMccCodecInfoBuffer infoBuffer;
       
   555         infoBuffer.Copy( aConfigParams );
       
   556         iCInfo = infoBuffer();
       
   557         
       
   558         // use values passed in to set parameter variables
       
   559         __AVCPLFORMAT_CONTROLL_INT1( "packetization mode:", iCInfo.iCodecMode )
       
   560         __ASSERT_ALWAYS( iCInfo.iCodecMode == KAvcFormatModeSingleNal || 
       
   561                          iCInfo.iCodecMode == KAvcFormatModeNonInterleaved,
       
   562                          User::Leave( KErrNotSupported ) );
       
   563         
       
   564         __ASSERT_ALWAYS( iCInfo.iPayloadType < KMccPayloadTypeMax, 
       
   565                          User::Leave( KErrArgument ) );
       
   566         
       
   567         __ASSERT_ALWAYS( iCInfo.iFrameSize > 0, User::Leave( KErrArgument ) );
       
   568         __ASSERT_ALWAYS( iCInfo.iMTUSize > 0, User::Leave( KErrArgument ) );
       
   569         
       
   570         iEncoder->SetPacketizationMode( iCInfo.iCodecMode );
       
   571 
       
   572         iEncoder->SetFrameRate( static_cast<TInt>( iCInfo.iFramerate ) );
       
   573 
       
   574         iEncoder->SetMTUSize( iCInfo.iMTUSize );
       
   575         }
       
   576     else
       
   577         {
       
   578         User::Leave( KErrArgument );
       
   579     	}
       
   580     	
       
   581     __AVCPLFORMAT_CONTROLL("CAvcPayloadFormatWrite::ConfigurePayloadFormatL, exit")
       
   582     }
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585