mp4sp_enc/arimp4spenchwdevice/src/arimp4spenchwdeviceimpl.cpp
changeset 0 bb31fbe78861
equal deleted inserted replaced
-1:000000000000 0:bb31fbe78861
       
     1 /*
       
     2 * Copyright (c) 2009 Aricent and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Aricent - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Implementation of member functions of Mpeg4SP/H263 encoder plugin class -
       
    16 * CAriMp4spencHwDeviceImpl.
       
    17 *
       
    18 */
       
    19 
       
    20 //Includes
       
    21 #include "arimp4spenchwdeviceimpl.h"
       
    22 #include "arimp4sphwdeviceconstants.h"
       
    23 #include "aricommon.h"
       
    24 
       
    25 #include <E32base.h>
       
    26 #include <AVC.h>
       
    27 #include <H263.h>
       
    28 #include <Implementationproxy.h>
       
    29 
       
    30 //---------------------------------------------------------------------------
       
    31 //  Maps the num/denom from the MDF to the aspect_ratio_idc value supported
       
    32 //---------------------------------------------------------------------------
       
    33 //
       
    34 
       
    35 TInt32 MapAspectRatio( TUint32 aNumerator, TUint32 aDenominator )
       
    36 	{
       
    37 	PRINT_ENTRY;
       
    38 
       
    39 	TInt32 aspectratio = -1;
       
    40 	switch ( aDenominator )
       
    41 		{
       
    42 		case 1:
       
    43 			if ( aNumerator == 1 )
       
    44 				{
       
    45 				aspectratio = 1;
       
    46 				}
       
    47 			break;
       
    48 		case 11:
       
    49 			switch ( aNumerator )
       
    50 				{
       
    51 				case 12:
       
    52 					aspectratio = 2;
       
    53 					break;
       
    54 				case 10:
       
    55 					aspectratio = 3;
       
    56 					break;
       
    57 				case 16:
       
    58 					aspectratio = 4;
       
    59 					break;
       
    60 				case 24:
       
    61 					aspectratio = 6;
       
    62 					break;
       
    63 				case 20:
       
    64 					aspectratio = 7;
       
    65 					break;
       
    66 				case 32:
       
    67 					aspectratio = 8;
       
    68 					break;
       
    69 				case 18:
       
    70 					aspectratio = 10;
       
    71 					break;
       
    72 				case 15:
       
    73 					aspectratio = 11;
       
    74 					break;
       
    75 				default:
       
    76 					break;
       
    77 				}
       
    78 			break;
       
    79 		case 33:
       
    80 			switch ( aNumerator )
       
    81 				{
       
    82 				case 40:
       
    83 					aspectratio = 5;
       
    84 					break;
       
    85 				case 80:
       
    86 					aspectratio = 9;
       
    87 					break;
       
    88 				case 64:
       
    89 					aspectratio = 12;
       
    90 					break;
       
    91 				default:
       
    92 					break;
       
    93 				}
       
    94 			break;
       
    95 		case 99:
       
    96 			if ( aNumerator == 160 )
       
    97 				{
       
    98 				aspectratio = 13;
       
    99 				}
       
   100 
       
   101 			break;
       
   102 		default:
       
   103 			break;
       
   104 		}
       
   105 
       
   106 	PRINT_EXIT;
       
   107 	return aspectratio;
       
   108 	}
       
   109 
       
   110 //---------------------------------------------------------------------------
       
   111 //  Two phase constructor for an object of CAriMp4spencHwDeviceImpl
       
   112 //---------------------------------------------------------------------------
       
   113 //
       
   114 CAriMp4spencHwDeviceImpl* CAriMp4spencHwDeviceImpl::NewL()
       
   115 	{
       
   116 	PRINT_ENTRY;
       
   117 
       
   118 	CAriMp4spencHwDeviceImpl* self =
       
   119 			new ( ELeave ) CAriMp4spencHwDeviceImpl();
       
   120 	CleanupStack::PushL( self );
       
   121 	self->ConstructL();
       
   122 	CleanupStack::Pop( self );
       
   123 	PRINT_EXIT;
       
   124 	return self;
       
   125 	}
       
   126 
       
   127 //---------------------------------------------------------------------------
       
   128 //  Default constructor
       
   129 //---------------------------------------------------------------------------
       
   130 //
       
   131 CAriMp4spencHwDeviceImpl::CAriMp4spencHwDeviceImpl() :
       
   132 			iMMFDevVideoRecordProxy( NULL ),
       
   133 			iInputDevice( NULL ),
       
   134 			iClockSource( NULL ),
       
   135 			iInputBufReturnToPreProc( EFalse ),
       
   136 			iPeriodicTimer( NULL ),
       
   137 			iClockTimeWhenPaused( 0 ),
       
   138 			//100 milli seconds
       
   139 			iPollingInterval( TTimeIntervalMicroSeconds32( 100000 ) ),
       
   140 			iCodec( NULL ), iEngine( NULL ), iOutputBuffers( NULL ),
       
   141 			iOutputBufferSize( 0 ), iPauseOffset( 0 ), iTotalTime( 0 ),
       
   142 			iLastEncodedPictureTimestamp( 0 ), iPictureLoss( EFalse ),
       
   143 			iInputEndCalled( EFalse ), iFrozen( EFalse ),
       
   144 			iTotalLengthFilledSoFarInPacketMode( 0 ),
       
   145 			iTotalOutputBufferLengthInPacketMode( 0 ),
       
   146 			iPacketOffSetCurrentPosition( NULL ),
       
   147 			iPacketOffSetAndLengthInfoBuffers( NULL ),
       
   148 			iInternalOutputBuffers( NULL ), iPacketsPending( EFalse )
       
   149 
       
   150 	{
       
   151 	PRINT_ENTRY;
       
   152 
       
   153 	iSupportedDataUnitTypes = EDuCodedPicture | EDuVideoSegment;
       
   154 	iSupportedDataUnitEncapsulations = EDuElementaryStream;
       
   155 
       
   156 	// Default values for Init params - full range
       
   157 	TUncompressedVideoFormat inputFormat;
       
   158 	inputFormat.iDataFormat = EYuvRawData;
       
   159 	inputFormat.iYuvFormat.iCoefficients = EYuvBt709Range0;
       
   160 	inputFormat.iYuvFormat.iPattern = EYuv420Chroma1;
       
   161 	inputFormat.iYuvFormat.iDataLayout = EYuvDataPlanar;
       
   162 	inputFormat.iYuvFormat.iYuv2RgbMatrix = NULL;
       
   163 	inputFormat.iYuvFormat.iRgb2YuvMatrix = NULL;
       
   164 	inputFormat.iYuvFormat.iAspectRatioNum = 1;
       
   165 	inputFormat.iYuvFormat.iAspectRatioDenom = 1;
       
   166 
       
   167 	iSetMpeg4H263HWParams.iInputFormat = inputFormat;
       
   168 	iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_UNKNOWN;
       
   169 	iSetMpeg4H263HWParams.iAfterInitialize = 0;
       
   170 	iSetMpeg4H263HWParams.iOutputFormat = EH263;
       
   171 	iSetMpeg4H263HWParams.iMinNumOutputBuffers
       
   172 			= KMPEG4H263ENCIMPL_MAXNUM_OUTPUTBUFFERS;
       
   173 
       
   174 	iSetMpeg4H263HWParams.iPacketSize = KMPEG4H263ENCIMPL_DEFAULT_SEGMENTSIZE;
       
   175 	iSetMpeg4H263HWParams.iMaxPictureRate
       
   176 			= KMPEG4H263ENCIMPL_DEFAULT_PICTURERATE;
       
   177 
       
   178 	// initialize picture counters
       
   179 	iPictureCounters.iPicturesSkippedBufferOverflow = 0;
       
   180 	iPictureCounters.iPicturesSkippedProcPower = 0;
       
   181 	iPictureCounters.iPicturesSkippedRateControl = 0;
       
   182 	iPictureCounters.iPicturesProcessed = 0;
       
   183 	iPictureCounters.iInputPictures = 0;
       
   184 	iSetMpeg4H263HWParams.iDataEncapsulation = EDuElementaryStream;
       
   185 
       
   186 	// default packet mode is off
       
   187 	iSetMpeg4H263HWParams.iDataUnitType = EDuCodedPicture;
       
   188 
       
   189 	iSetMpeg4H263HWParams.iBitRate = KH263ENCIMPL_DEFAULT_BITRATE;
       
   190 	iSetMpeg4H263HWParams.iTargetPictureRate
       
   191 			= KMPEG4H263ENCIMPL_DEFAULT_PICTURERATE;
       
   192 	iSetMpeg4H263HWParams.iRandomAccessRate
       
   193 			= KMPEG4H263ENCIMPL_DEFAULT_RANDOMACCESSRATE;
       
   194 	 // scene detection is ON
       
   195 	iSetMpeg4H263HWParams.iSceneCutDetection = 1;
       
   196 	//preprocessing disabled by default
       
   197 	iSetMpeg4H263HWParams.iPreprocessing = 0;
       
   198 	iSetMpeg4H263HWParams.iRCModel = CBR;
       
   199 	iSetMpeg4H263HWParams.iComplexityLevel = HIGH;
       
   200 	iSetMpeg4H263HWParams.iSearchRange = 31;
       
   201 
       
   202 	PRINT_EXIT;
       
   203 	}
       
   204 
       
   205 //---------------------------------------------------------------------------
       
   206 //  Destructor
       
   207 //---------------------------------------------------------------------------
       
   208 //
       
   209 CAriMp4spencHwDeviceImpl::~CAriMp4spencHwDeviceImpl()
       
   210 	{
       
   211 	PRINT_ENTRY;
       
   212 
       
   213 	PRINT_MSG( LEVEL_LOW, ( "this is %x", this ) );
       
   214 	iSupportedInputFormats.Close();
       
   215 	iLevels.Close();
       
   216 
       
   217 	//allocated formats should be deleted before closing
       
   218 	while ( iSupportedOutputFormats.Count() > 0 )
       
   219 		{
       
   220 		CCompressedVideoFormat* lCompFormat = iSupportedOutputFormats[0];
       
   221 		iSupportedOutputFormats.Remove( 0 );
       
   222 		delete lCompFormat;
       
   223 		}
       
   224 	iSupportedOutputFormats.Close();
       
   225 
       
   226 	// Stop processing
       
   227 	if ( !iEncStateMac->IsStopped() && ( !iEncStateMac->IsInDeadState() ) )
       
   228 		{
       
   229 		if ( iEncStateMac->IsInitialized() )
       
   230 			{
       
   231 			Stop();
       
   232 			}
       
   233 		}
       
   234 
       
   235 	if ( iEngine )
       
   236 		{
       
   237 		iEngine->Reset();
       
   238 		delete iEngine;
       
   239 		iEngine = NULL;
       
   240 		}
       
   241 
       
   242 	if ( iCodec )
       
   243 		{
       
   244 		delete iCodec;
       
   245 		iCodec = NULL;
       
   246 		}
       
   247 
       
   248 	//delete output buffers
       
   249 	iOutputFreeBufferQueue.Reset();
       
   250 	iOutputFreeBufferQueue.Close();
       
   251 
       
   252 	if ( iOutputBuffers )
       
   253 		{
       
   254 		if ( iSetMpeg4H263HWParams.iMinNumOutputBuffers )
       
   255 			{
       
   256 			for ( TInt i = 0; i < iSetMpeg4H263HWParams.iMinNumOutputBuffers;
       
   257 				 i++ )
       
   258 				{
       
   259 				if ( iOutputBuffers[i].iData.Ptr() )
       
   260 					{
       
   261 					delete ( TUint8* ) iOutputBuffers[i].iData.Ptr();
       
   262 					}
       
   263 				}
       
   264 			}
       
   265 
       
   266 		delete[] iOutputBuffers;
       
   267 		iOutputBuffers = NULL;
       
   268 		}
       
   269 
       
   270 	if ( iPeriodicTimer )
       
   271 		{
       
   272 		delete iPeriodicTimer;
       
   273 		iPeriodicTimer = NULL;
       
   274 		}
       
   275 
       
   276 	if ( iPacketOffSetAndLengthInfoBuffers )
       
   277 		{
       
   278 		for ( TInt i = 0; i < KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS;
       
   279 			 i++ )
       
   280 			{
       
   281 			delete[] ( TUint8* ) iPacketOffSetAndLengthInfoBuffers[i];
       
   282 			}
       
   283 		delete[] ( TUint* ) iPacketOffSetAndLengthInfoBuffers;
       
   284 		iPacketOffSetAndLengthInfoBuffers = NULL;
       
   285 		}
       
   286 
       
   287 	//delete temp output buffers
       
   288 	iInternalOutputBufferQueue.Reset();
       
   289 	iInternalOutputBufferQueue.Close();
       
   290 
       
   291 	if ( iInternalOutputBuffers )
       
   292 		{
       
   293 		for ( TInt i = 0; i < KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS;
       
   294 			i++ )
       
   295 			{
       
   296 			if ( iInternalOutputBuffers[i].iData.Ptr() )
       
   297 				{
       
   298 				delete ( TUint8* ) iInternalOutputBuffers[i].iData.Ptr();
       
   299 				}
       
   300 			}
       
   301 		delete[] iInternalOutputBuffers;
       
   302 		iInternalOutputBuffers = NULL;
       
   303 		}
       
   304 
       
   305 	iFreeBufferQueueForPacketOffsetInfo.Reset();
       
   306 	iFilledBufferQueueForPacketOffsetInfo.Reset();
       
   307 
       
   308 	if ( iConfigData )
       
   309 		{
       
   310 		delete iConfigData;
       
   311 		iConfigData = NULL;
       
   312 		}
       
   313 
       
   314 	if ( iPacketOffsetBuf )
       
   315 		{
       
   316 		delete iPacketOffsetBuf;
       
   317 		iPacketOffsetBuf = NULL;
       
   318 		}
       
   319 
       
   320 	if ( iEncStateMac )
       
   321 		{
       
   322 		delete iEncStateMac;
       
   323 		iEncStateMac = NULL;
       
   324 		}
       
   325 
       
   326 	PRINT_EXIT;
       
   327 	}
       
   328 
       
   329 //---------------------------------------------------------------------------
       
   330 //  Custom Interface supported by the HwDevice plugin
       
   331 //---------------------------------------------------------------------------
       
   332 //
       
   333 TAny* CAriMp4spencHwDeviceImpl::CustomInterface( TUid /* aInterface */ )
       
   334 	{
       
   335 	PRINT_ENTRY;
       
   336 	PRINT_EXIT;
       
   337 	return NULL;
       
   338 	}
       
   339 
       
   340 //---------------------------------------------------------------------------
       
   341 //  Returns information about this Encoder HW Device
       
   342 //---------------------------------------------------------------------------
       
   343 //
       
   344 CVideoEncoderInfo* CAriMp4spencHwDeviceImpl::VideoEncoderInfoLC()
       
   345 	{
       
   346 	PRINT_ENTRY;
       
   347 
       
   348 	TSize maxPictureSize = TSize( KMPEG4H263ENCIMPL_720P_WIDTH,
       
   349 			KMPEG4H263ENCIMPL_720P_HEIGHT );
       
   350 
       
   351 	TUint32 maxBitRate = KMaxSupportedBitRate;
       
   352 	RArray<TPictureRateAndSize> maxPictureRatesAndSizes;
       
   353 	CleanupClosePushL( maxPictureRatesAndSizes );
       
   354 	TPictureRateAndSize pictureRateAndSize;
       
   355 	TInt error = KErrNone;
       
   356 
       
   357 	// Max frame rate in mpeg4 sp encoding for any resolution is 15 fps.
       
   358 	// 30 fps is supported only in H263 encoding for SQCIF, QCIF, CIF only.
       
   359 
       
   360 	pictureRateAndSize.iPictureRate = KPictureRate30;
       
   361 	pictureRateAndSize.iPictureSize = TSize( KMPEG4H263ENCIMPL_SQCIF_WIDTH,
       
   362 											KMPEG4H263ENCIMPL_SQCIF_HEIGHT );
       
   363 
       
   364 	error = maxPictureRatesAndSizes.Append( pictureRateAndSize );
       
   365 	if  ( error != KErrNone )
       
   366 		{
       
   367 		User::Leave( error );
       
   368 		}
       
   369 	pictureRateAndSize.iPictureRate = KPictureRate30;
       
   370 	pictureRateAndSize.iPictureSize = TSize( KMPEG4H263ENCIMPL_QCIF_WIDTH,
       
   371 											KMPEG4H263ENCIMPL_QCIF_HEIGHT );
       
   372 
       
   373 	error = maxPictureRatesAndSizes.Append( pictureRateAndSize );
       
   374 	if  ( error != KErrNone )
       
   375 		{
       
   376 		User::Leave( error );
       
   377 		}
       
   378 
       
   379 	pictureRateAndSize.iPictureRate = KPictureRate30;
       
   380 	pictureRateAndSize.iPictureSize = TSize( KMPEG4H263ENCIMPL_CIF_WIDTH,
       
   381 			KMPEG4H263ENCIMPL_CIF_HEIGHT );
       
   382 
       
   383 	error = maxPictureRatesAndSizes.Append( pictureRateAndSize );
       
   384 	if  ( error != KErrNone )
       
   385 		{
       
   386 		User::Leave( error );
       
   387 		}
       
   388 
       
   389 	pictureRateAndSize.iPictureRate = KPictureRate15;
       
   390 	pictureRateAndSize.iPictureSize = TSize( KMPEG4H263ENCIMPL_QVGA_WIDTH,
       
   391 											KMPEG4H263ENCIMPL_QVGA_HEIGHT );
       
   392 
       
   393 	error = maxPictureRatesAndSizes.Append( pictureRateAndSize );
       
   394 	if  ( error != KErrNone )
       
   395 		{
       
   396 			User::Leave( error );
       
   397 		}
       
   398 
       
   399 	pictureRateAndSize.iPictureRate = KPictureRate15;
       
   400 	pictureRateAndSize.iPictureSize = TSize( KMPEG4H263ENCIMPL_VGA_WIDTH,
       
   401 											KMPEG4H263ENCIMPL_VGA_HEIGHT );
       
   402 
       
   403 	error = maxPictureRatesAndSizes.Append( pictureRateAndSize );
       
   404 	if  ( error != KErrNone )
       
   405 		{
       
   406 			User::Leave( error );
       
   407 		}
       
   408 
       
   409 	pictureRateAndSize.iPictureRate = KPictureRate15;
       
   410 	pictureRateAndSize.iPictureSize = TSize( KMPEG4H263ENCIMPL_720P_WIDTH,
       
   411 											KMPEG4H263ENCIMPL_720P_HEIGHT );
       
   412 
       
   413 	error = maxPictureRatesAndSizes.Append( pictureRateAndSize );
       
   414 	if  ( error != KErrNone )
       
   415 		{
       
   416 		User::Leave( error );
       
   417 		}
       
   418 
       
   419 	TUint32 lSupportedPictureOptions = TVideoPicture::ETimestamp
       
   420 			| TVideoPicture::EReqInstantRefresh | TVideoPicture::ESceneCut;
       
   421 
       
   422 	TUint32 supportedDataUnitEncapsulations = EDuElementaryStream;
       
   423 	TUint32 supportedDataUnitTypes = EDuCodedPicture | EDuVideoSegment;
       
   424 	CVideoEncoderInfo* videoEncoderInfo = CVideoEncoderInfo::NewL( TUid::Uid(
       
   425 								KUidMpeg4H263EncoderHwDeviceImplUid ),
       
   426 								KMPEG4H263EncManufacturer,
       
   427 								KMPEG4H263EncIdentifier,
       
   428 								TVersion( KMPEG4H263ENCIMPL_MAJOR_VERSION,
       
   429 										  KMPEG4H263ENCIMPL_MINOR_VERSION,
       
   430 										  KMPEG4H263ENCIMPL_BUILD_VERSION ),
       
   431 								// Accelerated
       
   432 								EFalse,
       
   433 								// Enc doesnt support direct capture
       
   434 								EFalse,
       
   435 								iSupportedInputFormats.Array(),
       
   436 								iSupportedOutputFormats.Array(),
       
   437 								maxPictureSize,
       
   438 								supportedDataUnitTypes,
       
   439 								// Max bitrate layers
       
   440 								supportedDataUnitEncapsulations, 1,
       
   441 								//aSupportsSupplementalEnhancementInfo
       
   442 								EFalse,
       
   443 								//aMaxUnequalErrorProtectionLevels
       
   444 								1,
       
   445 								maxBitRate, maxPictureRatesAndSizes.Array(),
       
   446 								1,
       
   447 								//aSupportsPictureLoss
       
   448 								lSupportedPictureOptions,
       
   449 								ETrue,
       
   450 								//aSupportsSliceLoss
       
   451 								ETrue,
       
   452 								//aCodingStandardSpecificInfo
       
   453 								KNullDesC8,
       
   454 								//aImplementationSpecificInfo
       
   455 								KNullDesC8 );
       
   456 
       
   457 	CleanupStack::PopAndDestroy();
       
   458 	CleanupStack::PushL( videoEncoderInfo );
       
   459 
       
   460 	PRINT_EXIT;
       
   461 	return videoEncoderInfo;
       
   462 	}
       
   463 
       
   464 //---------------------------------------------------------------------------
       
   465 //  Sets the encoder output format
       
   466 //---------------------------------------------------------------------------
       
   467 //
       
   468 void CAriMp4spencHwDeviceImpl::SetOutputFormatL(
       
   469 		const CCompressedVideoFormat& aFormat,
       
   470 		TVideoDataUnitType aDataUnitType,
       
   471 		TVideoDataUnitEncapsulation aDataEncapsulation,
       
   472 		TBool aSegmentationAllowed )
       
   473 	{
       
   474 	PRINT_ENTRY;
       
   475 
       
   476 	if ( iEncStateMac->IsInitialized() )
       
   477 		{
       
   478 		PRINT_ERR( "SetOutputFormatL () called before Initialize ()" );
       
   479 		User::Leave( KErrPermissionDenied );
       
   480 		}
       
   481 
       
   482 	TInt error = KErrNotFound;
       
   483 	TPtrC8 mimeType( aFormat.MimeType() );
       
   484 	TInt i;
       
   485 	for ( i = 0; i < iSupportedOutputFormats.Count(); i++ )
       
   486 		{
       
   487 		CCompressedVideoFormat* format = iSupportedOutputFormats[i];
       
   488 		if ( mimeType.CompareF( format->MimeType() ) == 0 )
       
   489 			{
       
   490 			iSetMpeg4H263HWParams.iLevel = iLevels[i];
       
   491 			error = KErrNone;
       
   492 			break;
       
   493 			}
       
   494 		}
       
   495 
       
   496 	if ( error == KErrNotFound )
       
   497 		{
       
   498 		PRINT_ERR( "CAriMp4spencHwDeviceImpl::SetOutputFormatL() Leaving"
       
   499 				   " because of unsupported output mimetype" );
       
   500 		User::Leave( KErrNotSupported );
       
   501 		return;
       
   502 		}
       
   503 
       
   504 	// Index values 0 - 10 contain MPEG4 mime types and 11-17 contain
       
   505 	// H263 mime types
       
   506 	if ( i >= 0 && i <= KMPEG4SUPPMIMEARRAYMAXINDEXVALUE )
       
   507 		{
       
   508 		iSetMpeg4H263HWParams.iOutputFormat = EMpeg4;
       
   509 		}
       
   510 
       
   511 	else if ( i >= KMPEG4SUPPMIMEARRAYMAXINDEXVALUE + 1 && i
       
   512 			<= KH263SUPPMIMEARRAYMAXINDEXVALUE )
       
   513 		{
       
   514 		iSetMpeg4H263HWParams.iOutputFormat = EH263;
       
   515 		}
       
   516 
       
   517 		PRINT_MSG( LEVEL_HIGH, ( "level is set to %d"
       
   518 						,(TInt)iSetMpeg4H263HWParams.iLevel ) );
       
   519 
       
   520 	if ( ( ( aDataUnitType != EDuCodedPicture ) && ( aDataUnitType
       
   521 		!= EDuVideoSegment) ) || ( aDataEncapsulation
       
   522 		!= EDuElementaryStream ) || (aSegmentationAllowed ) )
       
   523 
       
   524 		{
       
   525 		PRINT_ERR( "CAriMp4spencHwDeviceImpl::SetOutputFormatL() Leaving"
       
   526 			" because of unsupported data unit type or data unit"
       
   527 			" encapsulation" );
       
   528 		User::Leave( KErrNotSupported );
       
   529 		}
       
   530 
       
   531 	if ( aDataUnitType == EDuCodedPicture )
       
   532 		{
       
   533 		iSetMpeg4H263HWParams.iPacketmode = EFalse;
       
   534 		iSetMpeg4H263HWParams.iNumOfGOBHdrs = 0;
       
   535 			PRINT_MSG( LEVEL_HIGH, ( "CAriMp4spencHwDeviceImpl::"
       
   536 							"SetOutputFormatL() Packet mode is OFF " ) );
       
   537 		}
       
   538 	else
       
   539 		{
       
   540 		iSetMpeg4H263HWParams.iPacketmode = ETrue;
       
   541 		if ( iSetMpeg4H263HWParams.iOutputFormat == EH263 )
       
   542 			{
       
   543 			iSetMpeg4H263HWParams.iNumOfGOBHdrs = 1;
       
   544 			}
       
   545 			PRINT_MSG( LEVEL_HIGH, ( "CAriMp4spencHwDeviceImpl::"
       
   546 							"SetOutputFormatL() Packet mode is ON " ) );
       
   547 
       
   548 		// must be calculated from and levels set by the client
       
   549 		iSetMpeg4H263HWParams.iMinNumOutputBuffers
       
   550 				= KMPEG4H263ENCIMPL_MAXNUM_SEGMENTBUFFERS;
       
   551 		}
       
   552 
       
   553 	iSetMpeg4H263HWParams.iDataUnitType = aDataUnitType;
       
   554 	iSetMpeg4H263HWParams.iDataEncapsulation = aDataEncapsulation;
       
   555 	iSetMpeg4H263HWParams.iSegmentationAllowed = aSegmentationAllowed;
       
   556 	iSetMpeg4H263HWParams.iBeforeInitialize |= EEncOutputFormat;
       
   557 
       
   558 	PRINT_EXIT;
       
   559 	}
       
   560 
       
   561 //---------------------------------------------------------------------------
       
   562 //  Sets the pre-processor device that will write data to this encoder
       
   563 //---------------------------------------------------------------------------
       
   564 //
       
   565 void CAriMp4spencHwDeviceImpl::SetInputDevice(
       
   566 		CMMFVideoPreProcHwDevice* aDevice )
       
   567 	{
       
   568 	PRINT_ENTRY;
       
   569 
       
   570 	if ( iEncStateMac->IsInitialized() )
       
   571 		{
       
   572 		ClientFatalError( KErrPermissionDenied );
       
   573 		return;
       
   574 		}
       
   575 
       
   576 	if ( !aDevice )
       
   577 		{
       
   578 		ClientFatalError( KErrArgument );
       
   579 		return;
       
   580 		}
       
   581 
       
   582 	iInputDevice = aDevice;
       
   583 	iSetMpeg4H263HWParams.iBeforeInitialize |= EEncInputDevice;
       
   584 	iInputBufReturnToPreProc = ETrue;
       
   585 	PRINT_EXIT;
       
   586 	}
       
   587 
       
   588 //---------------------------------------------------------------------------
       
   589 //  Sets the number of bit-rate scalability layers to use
       
   590 //---------------------------------------------------------------------------
       
   591 //
       
   592 void CAriMp4spencHwDeviceImpl::SetNumBitrateLayersL( TUint aNumLayers )
       
   593 	{
       
   594 	PRINT_ENTRY;
       
   595 
       
   596 	if ( iEncStateMac->IsInitialized() )
       
   597 		{
       
   598 		PRINT_ERR( "SetNumBitrateLayersL () called before Initialize"
       
   599 				"..leaving" );
       
   600 		User::Leave( KErrPermissionDenied );
       
   601 		}
       
   602 
       
   603 	if (aNumLayers != 1)
       
   604 		{
       
   605 		PRINT_ERR( "Wrong value passed for aNumLayers... Leaving" );
       
   606 		User::Leave( KErrNotSupported );
       
   607 		}
       
   608 
       
   609 	PRINT_EXIT;
       
   610 	}
       
   611 
       
   612 //---------------------------------------------------------------------------
       
   613 //  Sets the scalability type for a bit-rate scalability layer. Currently not
       
   614 //  supported
       
   615 //---------------------------------------------------------------------------
       
   616 //
       
   617 void CAriMp4spencHwDeviceImpl::SetScalabilityLayerTypeL( TUint /*aLayer*/,
       
   618 		TScalabilityType /*aScalabilityType*/ )
       
   619 	{
       
   620 	PRINT_ENTRY;
       
   621 
       
   622 	if ( iEncStateMac->IsInitialized() )
       
   623 		{
       
   624 		PRINT_ERR( "SetScalabilityLayerTypeL() called before Initialize"
       
   625 				"..leaving" );
       
   626 		User::Leave( KErrPermissionDenied );
       
   627 		}
       
   628 
       
   629     PRINT_ERR( "SetScalabilityLayerTypeL() not supported...Leaving with "
       
   630     		"KErrNotSupported" );
       
   631 	User::Leave( KErrNotSupported );
       
   632 
       
   633 	PRINT_EXIT;
       
   634 	}
       
   635 
       
   636 //---------------------------------------------------------------------------
       
   637 //  Sets the reference picture options to be used for all scalability layers
       
   638 //---------------------------------------------------------------------------
       
   639 //
       
   640 
       
   641 void CAriMp4spencHwDeviceImpl::SetGlobalReferenceOptions(
       
   642 		TUint aMaxReferencePictures, TUint aMaxPictureOrderDelay )
       
   643 	{
       
   644 	PRINT_ENTRY;
       
   645 
       
   646 	if ( iEncStateMac->IsInitialized() )
       
   647 		{
       
   648 		ClientFatalError( KErrPermissionDenied );
       
   649 		return;
       
   650 		}
       
   651 
       
   652 	if ( aMaxPictureOrderDelay != 0 || aMaxReferencePictures
       
   653 			> KMPEG4H263ENCIMPL_MAXNUM_REFERENCEPICTURES )
       
   654 		{
       
   655 		ClientFatalError( KErrNotSupported );
       
   656 		return;
       
   657 		}
       
   658 
       
   659 	iSetMpeg4H263HWParams.iLayerReferenceOptions[0].iMaxReferencePictures
       
   660 			= aMaxReferencePictures;
       
   661 
       
   662 	iSetMpeg4H263HWParams.iLayerReferenceOptions[0].iMaxPictureOrderDelay
       
   663 			= aMaxPictureOrderDelay;
       
   664 
       
   665 	iSetMpeg4H263HWParams.iBeforeInitialize |= EEncGlobalRefOptions;
       
   666 
       
   667 	PRINT_EXIT;
       
   668 	}
       
   669 
       
   670 //---------------------------------------------------------------------------
       
   671 // Sets the reference picture options to be used for a single scalability
       
   672 // layer
       
   673 //---------------------------------------------------------------------------
       
   674 //
       
   675 void CAriMp4spencHwDeviceImpl::SetLayerReferenceOptions( TUint /*aLayer*/,
       
   676 		TUint /*aMaxReferencePictures*/, TUint /*aMaxPictureOrderDelay*/ )
       
   677 	{
       
   678 	PRINT_ENTRY;
       
   679 
       
   680 	if ( iEncStateMac->IsInitialized() )
       
   681 		{
       
   682 		ClientFatalError( KErrPermissionDenied );
       
   683 		return;
       
   684 		}
       
   685 	ClientFatalError( KErrNotSupported );
       
   686 
       
   687 	PRINT_EXIT;
       
   688 	}
       
   689 
       
   690 //---------------------------------------------------------------------------
       
   691 // Sets encoder buffering options
       
   692 //---------------------------------------------------------------------------
       
   693 //
       
   694 void CAriMp4spencHwDeviceImpl::SetBufferOptionsL(
       
   695 		const TEncoderBufferOptions& aOptions )
       
   696 	{
       
   697 	PRINT_ENTRY;
       
   698 
       
   699 	if ( iEncStateMac->IsInitialized() )
       
   700 		{
       
   701 		PRINT_ERR( "SetBufferOptionsL () called before Initialize ()" );
       
   702 		User::Leave( KErrPermissionDenied );
       
   703 		}
       
   704 
       
   705 	PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SetBufferOptionsL() "
       
   706     		"iMaxPreEncoderBufferPictures = %d" ,
       
   707     		(TInt)aOptions.iMaxPreEncoderBufferPictures ) );
       
   708     PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SetBufferOptionsL() "
       
   709     		"iMaxOutputBufferSize = %d",
       
   710     		( TInt ) aOptions.iMaxOutputBufferSize ) );
       
   711     PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SetBufferOptionsL() "
       
   712     		"iMaxCodedPictureSize = %d" ,
       
   713     		( TInt )aOptions.iMaxCodedPictureSize ) );
       
   714     PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SetBufferOptionsL() "
       
   715     		"iHrdVbvSpec = %x", ( TInt ) aOptions.iHrdVbvSpec ) );
       
   716     PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SetBufferOptionsL() "
       
   717     		"iMinNumOutputBuffers = %d" ,
       
   718     		( TInt ) aOptions.iMinNumOutputBuffers ) );
       
   719     PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SetBufferOptionsL() "
       
   720     		"iMaxCodedSegmentSize = %d" ,
       
   721 			( TInt ) aOptions.iMaxCodedSegmentSize ) );
       
   722 
       
   723 	if ( ( aOptions.iMaxPreEncoderBufferPictures == 0 )
       
   724 			|| ( aOptions.iMaxOutputBufferSize == 0 )
       
   725 			|| ( aOptions.iMinNumOutputBuffers == 0 )
       
   726 			|| ( aOptions.iHrdVbvSpec == EHrdVbv3GPP ) )
       
   727 		{
       
   728 		PRINT_ERR( "SetBufferOptionsL () - incorrect parameter passed ..."
       
   729 				"leaving with KErrNotSupported" );
       
   730 		User::Leave( KErrNotSupported );
       
   731 		return;
       
   732 		}
       
   733 
       
   734 	iSetMpeg4H263HWParams.iMaxPreEncoderBufferPictures
       
   735 			= aOptions.iMaxPreEncoderBufferPictures;
       
   736 	iSetMpeg4H263HWParams.iMaxOutputBufferSize
       
   737 			= aOptions.iMaxOutputBufferSize;
       
   738 	iSetMpeg4H263HWParams.iMaxCodedPictureSize
       
   739 			= aOptions.iMaxCodedPictureSize;
       
   740 	iSetMpeg4H263HWParams.iPacketSize = aOptions.iMaxCodedSegmentSize;
       
   741 	iSetMpeg4H263HWParams.iMinNumOutputBuffers
       
   742 			= aOptions.iMinNumOutputBuffers;
       
   743 	iSetMpeg4H263HWParams.iBeforeInitialize |= EEncBufferOptions;
       
   744 
       
   745 	PRINT_EXIT;
       
   746 	}
       
   747 
       
   748 //---------------------------------------------------------------------------
       
   749 // Sets the encoder output rectangle
       
   750 //---------------------------------------------------------------------------
       
   751 //
       
   752 
       
   753 void CAriMp4spencHwDeviceImpl::SetOutputRectL( const TRect& aRect )
       
   754 	{
       
   755 	PRINT_ENTRY;
       
   756 
       
   757 	if ( ( aRect.iTl.iX >= aRect.iBr.iX )
       
   758 			|| ( aRect.iTl.iY >= aRect.iBr.iY ) )
       
   759 		{
       
   760 		PRINT_ERR( " Invalid parameteres passed..Leaving " );
       
   761 		User::Leave( KErrNotSupported );
       
   762 		return;
       
   763 		}
       
   764 
       
   765 	iSetMpeg4H263HWParams.iOutputRect = aRect;
       
   766 	iSetMpeg4H263HWParams.iBeforeInitialize |= EEncOutputRectSize;
       
   767 
       
   768 	PRINT_EXIT;
       
   769 	}
       
   770 
       
   771 //---------------------------------------------------------------------------
       
   772 // Sets whether bit errors or packets losses can be expected in the video
       
   773 // transmission
       
   774 //---------------------------------------------------------------------------
       
   775 //
       
   776 
       
   777 void CAriMp4spencHwDeviceImpl::SetErrorsExpected( TBool aBitErrors,
       
   778 		TBool aPacketLosses )
       
   779 	{
       
   780 	PRINT_ENTRY;
       
   781 
       
   782 	// This can bel called before and after initialize
       
   783 	 PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SetErrorsExpected()"
       
   784 			 " BitErrors is set to [ %d ]", aBitErrors ) );
       
   785 	 PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::SetErrorsExpected() "
       
   786 			 "iPacketLosses is set to [ %d ]", aPacketLosses ) );
       
   787 
       
   788 	if ( iEncStateMac->IsInitialized() )
       
   789 		{
       
   790 		iCurSetMpeg4H263HWParams.iBitErrors = aBitErrors;
       
   791 		iCurSetMpeg4H263HWParams.iPacketLosses = aPacketLosses;
       
   792 		iCurSetMpeg4H263HWParams.iAfterInitialize |= EEncErrorsExpected;
       
   793 		}
       
   794 	else
       
   795 		{
       
   796 		iSetMpeg4H263HWParams.iBitErrors = aBitErrors;
       
   797 		iSetMpeg4H263HWParams.iPacketLosses = aPacketLosses;
       
   798 		iSetMpeg4H263HWParams.iBeforeInitialize |= EEncErrorsExpected;
       
   799 		}
       
   800 
       
   801 	PRINT_EXIT;
       
   802 	}
       
   803 
       
   804 //---------------------------------------------------------------------------
       
   805 // Sets the minimum frequency (in time) for instantaneous random access points
       
   806 // in the bitstream
       
   807 //---------------------------------------------------------------------------
       
   808 //
       
   809 
       
   810 void CAriMp4spencHwDeviceImpl::SetMinRandomAccessRate( TReal aRate )
       
   811 	{
       
   812 	PRINT_ENTRY;
       
   813 
       
   814 	if ( iEncStateMac->IsInitialized() )
       
   815 		{
       
   816 		// simply return no further action is taken
       
   817 		if ( aRate <= 0.0 )
       
   818 			{
       
   819 			return;
       
   820 			}
       
   821 		iCurSetMpeg4H263HWParams.iRandomAccessRate = aRate;
       
   822 		PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl"
       
   823 				"::SetMinRandomAccessRate() iRandomAccessRate is %f" ,
       
   824 				( TReal )iSetMpeg4H263HWParams.iRandomAccessRate ) );
       
   825 		iCurSetMpeg4H263HWParams.iAfterInitialize |= EEncRandomAccessRate;
       
   826 		}
       
   827 	else
       
   828 		{
       
   829 		if ( aRate <= 0.0 )
       
   830 			{
       
   831 			ClientFatalError( KErrNotSupported );
       
   832 			return;
       
   833 			}
       
   834 		iSetMpeg4H263HWParams.iRandomAccessRate = aRate;
       
   835 
       
   836 		iSetMpeg4H263HWParams.iBeforeInitialize |= EEncRandomAccessRate;
       
   837 		}
       
   838 
       
   839 	PRINT_EXIT;
       
   840 	}
       
   841 
       
   842 //---------------------------------------------------------------------------
       
   843 //  Sets coding-standard specific encoder options.
       
   844 //---------------------------------------------------------------------------
       
   845 //
       
   846 
       
   847 void CAriMp4spencHwDeviceImpl::SetCodingStandardSpecificOptionsL(
       
   848 		const TDesC8& /*aOptions*/ )
       
   849 	{
       
   850 	PRINT_ENTRY;
       
   851 	User::Leave( KErrNotSupported );
       
   852 	PRINT_EXIT;
       
   853 	}
       
   854 
       
   855 //---------------------------------------------------------------------------
       
   856 //  Sets coding-standard specific encoder options.
       
   857 //---------------------------------------------------------------------------
       
   858 //
       
   859 
       
   860 void CAriMp4spencHwDeviceImpl::SetImplementationSpecificEncoderOptionsL(
       
   861 		const TDesC8& /*aOptions*/ )
       
   862 	{
       
   863 	PRINT_ENTRY;
       
   864 
       
   865 	//This API can be called at any point of time
       
   866 	User::Leave( KErrNotSupported );
       
   867 
       
   868 	PRINT_EXIT;
       
   869 	}
       
   870 
       
   871 //---------------------------------------------------------------------------
       
   872 //  Returns coding-standard specific initialization output from the encoder
       
   873 //---------------------------------------------------------------------------
       
   874 //
       
   875 
       
   876 HBufC8* CAriMp4spencHwDeviceImpl::CodingStandardSpecificInitOutputLC()
       
   877 	{
       
   878 	PRINT_ENTRY;
       
   879 
       
   880 	if ( !iEncStateMac->IsInitialized() )
       
   881 		{
       
   882     	PRINT_ERR( "CodingStandardSpecificInitOutputLC () called before "
       
   883     			"Initialize ()" );
       
   884 		User::Leave( KErrNotReady );
       
   885 		}
       
   886 
       
   887 	TUint configLength;
       
   888 	TUint err = iCodec->GetParam( CONTROL_CMD_GET_CONFIGDATALENGTH,
       
   889 			&configLength );
       
   890 	if ( err )
       
   891 		{
       
   892 		User::Leave( err );
       
   893 		}
       
   894 
       
   895 	iConfigData = HBufC8::NewL( configLength );
       
   896 	err = iCodec->GetParam( CONTROL_CMD_GET_CONFIGDATA, iConfigData );
       
   897 
       
   898 	if ( err )
       
   899 		{
       
   900     	PRINT_ERR("GetParam failure");
       
   901 		User::Leave( err );
       
   902 		}
       
   903 
       
   904 	PRINT_EXIT;
       
   905 	return iConfigData;
       
   906 	}
       
   907 
       
   908 //---------------------------------------------------------------------------
       
   909 //  Returns coding-standard specific initialization output from the encoder
       
   910 //---------------------------------------------------------------------------
       
   911 //
       
   912 
       
   913 HBufC8* CAriMp4spencHwDeviceImpl::ImplementationSpecificInitOutputLC()
       
   914 	{
       
   915 	PRINT_ENTRY;
       
   916 
       
   917 	if ( !iEncStateMac->IsInitialized() )
       
   918 		{
       
   919     	PRINT_ERR( "ImplementationSpecificInitOutputLC () called before "
       
   920     			"Initialize ()" );
       
   921 		User::Leave( KErrNotReady );
       
   922 		return NULL;
       
   923 		}
       
   924 
       
   925 	PRINT_ERR( "ImplementationSpecificInitOutputLC () not supported...leaving"
       
   926 			"with KErrNotSupported" );
       
   927 	User::Leave( KErrNotSupported );
       
   928 
       
   929 	PRINT_EXIT;
       
   930 	return NULL;
       
   931 	}
       
   932 
       
   933 //---------------------------------------------------------------------------
       
   934 // Sets the number of unequal error protection levels
       
   935 //---------------------------------------------------------------------------
       
   936 //
       
   937 void CAriMp4spencHwDeviceImpl::SetErrorProtectionLevelsL(
       
   938 		TUint /*aNumLevels*/, TBool /*aSeparateBuffers*/ )
       
   939 	{
       
   940 	PRINT_ENTRY;
       
   941 
       
   942 	if ( !iEncStateMac->IsInitialized() )
       
   943 		{
       
   944     	PRINT_ERR( "SetErrorProtectionLevelsL () called before "
       
   945     	    			"Initialize ()" );
       
   946 		User::Leave( KErrNotReady );
       
   947 		}
       
   948 
       
   949 	PRINT_ERR( "SetErrorProtectionLevelsL() not supported...leaving"
       
   950 			"with KErrNotSupported" );
       
   951 	User::Leave( KErrNotSupported );
       
   952 
       
   953 	PRINT_EXIT;
       
   954 	}
       
   955 
       
   956 //---------------------------------------------------------------------------
       
   957 // Sets the number of unequal error protection levels
       
   958 //---------------------------------------------------------------------------
       
   959 //
       
   960 void CAriMp4spencHwDeviceImpl::SetErrorProtectionLevelL(TUint /*aLevel*/,
       
   961 		TUint /*aBitrate*/, TUint /*aStrength*/)
       
   962 	{
       
   963 	PRINT_ENTRY;
       
   964 
       
   965 	if ( !iEncStateMac->IsInitialized() )
       
   966 		{
       
   967     	PRINT_ERR( "SetErrorProtectionLevelsL () called before "
       
   968     	    			"Initialize ()" );
       
   969 		User::Leave( KErrNotReady );
       
   970 		}
       
   971 
       
   972 	PRINT_ERR( "SetErrorProtectionLevelsL() not supported...leaving"
       
   973 			"with KErrNotSupported" );
       
   974 	User::Leave( KErrNotSupported );
       
   975 
       
   976 	PRINT_EXIT;
       
   977 	}
       
   978 
       
   979 //---------------------------------------------------------------------------
       
   980 //  Sets the expected or prevailing channel conditions for an unequal
       
   981 //  error protection level, in terms of expected packet loss rate
       
   982 //---------------------------------------------------------------------------
       
   983 //
       
   984 void CAriMp4spencHwDeviceImpl::SetChannelPacketLossRate(TUint /*aLevel*/,
       
   985 		TReal /*aLossRate*/, TTimeIntervalMicroSeconds32 /*aLossBurstLength*/)
       
   986 	{
       
   987 	PRINT_ENTRY;
       
   988 
       
   989 	if ( !iEncStateMac->IsInitialized() )
       
   990 		{
       
   991 		ClientFatalError( KErrNotReady );
       
   992         return;
       
   993 		}
       
   994 
       
   995 	PRINT_EXIT;
       
   996 	ClientFatalError( KErrNotSupported );
       
   997 
       
   998 	}
       
   999 
       
  1000 //---------------------------------------------------------------------------
       
  1001 // Sets the expected or prevailing channel conditions for an unequal error
       
  1002 // protection level, in terms of expected bit error rate
       
  1003 //---------------------------------------------------------------------------
       
  1004 //
       
  1005 void CAriMp4spencHwDeviceImpl::SetChannelBitErrorRate(TUint /*aLevel*/,
       
  1006 		TReal aErrorRate, TReal /*aStdDeviation*/)
       
  1007 	{
       
  1008 	PRINT_ENTRY;
       
  1009 
       
  1010 	if ( !iEncStateMac->IsInitialized() )
       
  1011 		{
       
  1012 		ClientFatalError( KErrNotReady );
       
  1013 		return;
       
  1014 		}
       
  1015 
       
  1016 	// ignore the negative and 0 error rate values - #AANV-6QSC9N
       
  1017 	if ( aErrorRate < 0.0 )
       
  1018 		{
       
  1019 		return;
       
  1020 		}
       
  1021 
       
  1022 	TReal* bitErrorRate = NULL;
       
  1023 	TRAPD ( error , bitErrorRate = new ( ELeave ) TReal );
       
  1024 	if ( error != KErrNone )
       
  1025 		{
       
  1026 		ClientFatalError( error );
       
  1027 		return;
       
  1028 		}
       
  1029 
       
  1030 	*bitErrorRate = aErrorRate;
       
  1031 	TRAP ( error, iEngine->AddCommandL( CBaseEngine::EHighPriority,
       
  1032 					CONTROL_CMD_SET_CHANNEL_BIT_ERROR_RATE, bitErrorRate ) );
       
  1033 
       
  1034 	if ( error != KErrNone )
       
  1035 		{
       
  1036 		delete bitErrorRate;
       
  1037 		ClientFatalError( error );
       
  1038 		return;
       
  1039 		}
       
  1040 
       
  1041 	PRINT_EXIT;
       
  1042 	}
       
  1043 
       
  1044 //---------------------------------------------------------------------------
       
  1045 //  Sets the target size of each coded video segment
       
  1046 //---------------------------------------------------------------------------
       
  1047 //
       
  1048 void CAriMp4spencHwDeviceImpl::SetSegmentTargetSize( TUint aLayer,
       
  1049 		TUint aSizeBytes, TUint /*aSizeMacroblocks*/ )
       
  1050 	{
       
  1051 	PRINT_ENTRY;
       
  1052 
       
  1053 	if ( !iEncStateMac->IsInitialized() )
       
  1054 		{
       
  1055 		ClientFatalError( KErrNotReady );
       
  1056 		return;
       
  1057 		}
       
  1058 
       
  1059 	if ( iSetMpeg4H263HWParams.iDataUnitType != EDuVideoSegment )
       
  1060 		{
       
  1061 		return;
       
  1062 		}
       
  1063 
       
  1064 	// aLayer should be zero since layered bit-rate scalability is not used.
       
  1065 	if ( aLayer != 0 )
       
  1066 		{
       
  1067 		return;
       
  1068 		}
       
  1069 
       
  1070 	TUint calculatedSegmentSize = 0;
       
  1071 	// if value < 0 or > iMaxOutputBufferSize the adjust this value
       
  1072 	if ( aSizeBytes < KMPEG4H263ENCIMPL_MIN_SEGMENTSIZE )
       
  1073 		{
       
  1074 		calculatedSegmentSize = KMPEG4H263ENCIMPL_MIN_SEGMENTSIZE;
       
  1075 		}
       
  1076 	else
       
  1077 		{
       
  1078 		if ( iSetMpeg4H263HWParams.iMaxOutputBufferSize
       
  1079 				> KMPEG4H263ENCIMPL_MAX_SEGMENTSIZE )
       
  1080 			{
       
  1081 			if ( aSizeBytes < KMPEG4H263ENCIMPL_MAX_SEGMENTSIZE )
       
  1082 				{
       
  1083 				calculatedSegmentSize = aSizeBytes;
       
  1084 				}
       
  1085 			else
       
  1086 				{
       
  1087 				calculatedSegmentSize = KMPEG4H263ENCIMPL_MAX_SEGMENTSIZE;
       
  1088 				}
       
  1089 			}
       
  1090 		else
       
  1091 			{
       
  1092 			if ( aSizeBytes < iSetMpeg4H263HWParams.iMaxOutputBufferSize )
       
  1093 				{
       
  1094 				calculatedSegmentSize = aSizeBytes;
       
  1095 				}
       
  1096 			else
       
  1097 				{
       
  1098 				calculatedSegmentSize
       
  1099 						= iSetMpeg4H263HWParams.iMaxOutputBufferSize;
       
  1100 				}
       
  1101 			}
       
  1102 		}
       
  1103 
       
  1104 	// Set the target size on codec
       
  1105 
       
  1106 	TInt error = iCodec->SetParam( CONTROL_CMD_SET_PACKETSIZE,
       
  1107 			&calculatedSegmentSize );
       
  1108 
       
  1109 	if ( error != KErrNone )
       
  1110 		{
       
  1111 		ClientFatalError( error );
       
  1112 		return;
       
  1113 		}
       
  1114 	iSetMpeg4H263HWParams.iPacketSize = calculatedSegmentSize;
       
  1115 
       
  1116 	PRINT_EXIT;
       
  1117 	}
       
  1118 
       
  1119 //---------------------------------------------------------------------------
       
  1120 // Sets the bit-rate control options for a layer
       
  1121 //---------------------------------------------------------------------------
       
  1122 //
       
  1123 void CAriMp4spencHwDeviceImpl::SetRateControlOptions( TUint aLayer,
       
  1124 		const TRateControlOptions& aOptions )
       
  1125 	{
       
  1126 	PRINT_ENTRY;
       
  1127 
       
  1128 	if ( !iEncStateMac->IsInitialized() )
       
  1129 		{
       
  1130 		ClientFatalError( KErrNotReady );
       
  1131 		return;
       
  1132 		}
       
  1133 
       
  1134 	// Since layered bit-rate scalability is not used, options are set for the
       
  1135 	//entire stream
       
  1136 
       
  1137 	if ( aLayer != 0 )
       
  1138 		{
       
  1139 		return;
       
  1140 		}
       
  1141 
       
  1142 	if ( ( aOptions.iPictureRate <= 0 ) ||
       
  1143 			( aOptions.iControl & EBrControlPicture ) )
       
  1144 		{
       
  1145 		return;
       
  1146 		}
       
  1147 
       
  1148 	if ( aOptions.iControl & EBrControlStream )
       
  1149 		{
       
  1150 		if ( ( aOptions.iQualityTemporalTradeoff < 0 )
       
  1151 				|| ( aOptions.iQualityTemporalTradeoff > 1 )
       
  1152 				|| ( aOptions.iLatencyQualityTradeoff < 0 )
       
  1153 				|| ( aOptions.iLatencyQualityTradeoff > 1 )
       
  1154 				|| ( aOptions.iBitrate == 0 ) )
       
  1155 			{
       
  1156 			return;
       
  1157 			}
       
  1158 		}
       
  1159 
       
  1160 	TRateControlOptions* rateControlOptions = NULL;
       
  1161 	TRAPD ( error, rateControlOptions = new ( ELeave ) TRateControlOptions );
       
  1162 
       
  1163 	if ( error != KErrNone )
       
  1164 		{
       
  1165 		ClientFatalError( error );
       
  1166 		return;
       
  1167 		}
       
  1168 
       
  1169 	rateControlOptions->iControl = aOptions.iControl;
       
  1170 	// default bit rate used
       
  1171 	if ( aOptions.iControl & EBrControlNone )
       
  1172 		{
       
  1173 		rateControlOptions->iBitrate = iSetMpeg4H263HWParams.iBitRate;
       
  1174 		}
       
  1175 	else
       
  1176 		{
       
  1177 		rateControlOptions->iBitrate = ( aOptions.iBitrate
       
  1178 				<= iSetMpeg4H263HWParams.iBitRate ) ? ( aOptions.iBitrate )
       
  1179 				: ( iSetMpeg4H263HWParams.iBitRate );
       
  1180 		}
       
  1181 
       
  1182 	rateControlOptions->iPictureQuality = aOptions.iPictureQuality;
       
  1183 	rateControlOptions->iPictureRate = aOptions.iPictureRate;
       
  1184 	rateControlOptions->iQualityTemporalTradeoff
       
  1185 			= aOptions.iQualityTemporalTradeoff;
       
  1186 	rateControlOptions->iLatencyQualityTradeoff
       
  1187 			= aOptions.iLatencyQualityTradeoff;
       
  1188 
       
  1189 	TRAP ( error, iEngine->AddCommandL( CBaseEngine::EHighPriority,
       
  1190 				CONTROL_CMD_SET_RATE_CONTROL_OPTIONS, rateControlOptions ) );
       
  1191 
       
  1192 	if ( error != KErrNone )
       
  1193 		{
       
  1194 		delete rateControlOptions;
       
  1195 		ClientFatalError( error );
       
  1196 		return;
       
  1197 		}
       
  1198 
       
  1199 	PRINT_MSG( LEVEL_LOW,( "CAriMp4spencHwDeviceImpl::SetRateControlOptions"
       
  1200 			"iBitrate is %d", ( TInt )aOptions.iBitrate ) );
       
  1201 
       
  1202 	PRINT_MSG( LEVEL_LOW,( "CAriMp4spencHwDeviceImpl::SetRateControlOptions"
       
  1203 			"iPictureQuality is %d" , ( TInt )aOptions.iPictureQuality ) );
       
  1204 
       
  1205 	PRINT_MSG( LEVEL_LOW,( "CAriMp4spencHwDeviceImpl::SetRateControlOptions"
       
  1206 			" iPictureRate is %f", ( TReal )aOptions.iPictureRate ) );
       
  1207 
       
  1208 	PRINT_MSG( LEVEL_LOW,( "CAriMp4spencHwDeviceImpl::SetRateControlOptions"
       
  1209 			"iQualityTemporalTradeoff is %f" ,
       
  1210 			( TReal )aOptions.iQualityTemporalTradeoff ) );
       
  1211 
       
  1212 	PRINT_MSG( LEVEL_LOW,( "CAriMp4spencHwDeviceImpl::SetRateControlOptions"
       
  1213 			" iLatencyQualityTradeoff is %f " ,
       
  1214 			( TReal ) aOptions.iLatencyQualityTradeoff ) );
       
  1215 
       
  1216 	PRINT_MSG( LEVEL_LOW,( "CAriMp4spencHwDeviceImpl::SetRateControlOptions"
       
  1217 			"iControl is %x" , ( TInt ) aOptions.iControl ) );
       
  1218 
       
  1219 	PRINT_EXIT;
       
  1220 	}
       
  1221 
       
  1222 //---------------------------------------------------------------------------
       
  1223 // Sets in-layer scalability options for a layer
       
  1224 //---------------------------------------------------------------------------
       
  1225 //
       
  1226 void CAriMp4spencHwDeviceImpl::SetInLayerScalabilityL( TUint /*aLayer*/,
       
  1227 		TUint /*aNumSteps*/, TInLayerScalabilityType /*aScalabilityType*/,
       
  1228 		const TArray<TUint>& /*aBitrateShare*/,
       
  1229 		const TArray<TUint>& /*aPictureShare*/ )
       
  1230 	{
       
  1231 	PRINT_ENTRY;
       
  1232 
       
  1233 	if ( !iEncStateMac->IsInitialized() )
       
  1234 		{
       
  1235     	PRINT_ERR( "SetInLayerScalabilityL () called before "
       
  1236     	    			"Initialize ()" );
       
  1237 		User::Leave( KErrNotReady );
       
  1238 		}
       
  1239 
       
  1240 	PRINT_ERR( "SetInLayerScalabilityL () not supported..leaving with "
       
  1241 	    			"KErrNotSupported" );
       
  1242 	User::Leave( KErrNotSupported );
       
  1243 
       
  1244 	PRINT_EXIT;
       
  1245 	}
       
  1246 
       
  1247 //---------------------------------------------------------------------------
       
  1248 // Sets the period for layer promotions points for a scalability layer
       
  1249 //---------------------------------------------------------------------------
       
  1250 //
       
  1251 void CAriMp4spencHwDeviceImpl::SetLayerPromotionPointPeriod(
       
  1252 		TUint /*aLayer*/,
       
  1253 		TUint /*aPeriod*/ )
       
  1254 	{
       
  1255 	PRINT_ENTRY;
       
  1256 
       
  1257 	if ( !iEncStateMac->IsInitialized() )
       
  1258 		{
       
  1259 		ClientFatalError( KErrNotReady );
       
  1260 		return;
       
  1261 		}
       
  1262 	ClientFatalError( KErrNotSupported );
       
  1263 
       
  1264 	PRINT_EXIT;
       
  1265 	}
       
  1266 
       
  1267 //---------------------------------------------------------------------------
       
  1268 // Returns coding-standard specific settings output from the encoder
       
  1269 //---------------------------------------------------------------------------
       
  1270 //
       
  1271 HBufC8* CAriMp4spencHwDeviceImpl::CodingStandardSpecificSettingsOutputLC()
       
  1272 	{
       
  1273 	PRINT_ENTRY;
       
  1274 
       
  1275 	if ( !iEncStateMac->IsInitialized() )
       
  1276 		{
       
  1277     	PRINT_ERR( "CodingStandardSpecificSettingsOutputLC () called before "
       
  1278     	    			"Initialize ()" );
       
  1279 		User::Leave( KErrNotReady );
       
  1280 		}
       
  1281 	PRINT_ERR( "CodingStandardSpecificSettingsOutputLC () not supported.."
       
  1282 			"leaving with KErrNotSupported" );
       
  1283 	User::Leave( KErrNotSupported );
       
  1284 
       
  1285 	PRINT_EXIT;
       
  1286 	return NULL;
       
  1287 	}
       
  1288 
       
  1289 //---------------------------------------------------------------------------
       
  1290 // Returns implementation-specific settings output from the encoder
       
  1291 //---------------------------------------------------------------------------
       
  1292 //
       
  1293 HBufC8* CAriMp4spencHwDeviceImpl::ImplementationSpecificSettingsOutputLC()
       
  1294 	{
       
  1295 	PRINT_ENTRY;
       
  1296 
       
  1297 	if ( !iEncStateMac->IsInitialized() )
       
  1298 		{
       
  1299     	PRINT_ERR( "ImplementationSpecificSettingsOutputLC () called before "
       
  1300     	    	    			"Initialize ()" );
       
  1301 		User::Leave( KErrNotReady );
       
  1302 		}
       
  1303 
       
  1304 	PRINT_ERR( "ImplementationSpecificSettingsOutputLC () not supported.."
       
  1305 			"leaving with KErrNotSupported" );
       
  1306 	User::Leave( KErrNotSupported );
       
  1307 
       
  1308 	PRINT_EXIT;
       
  1309 	return NULL;
       
  1310 	}
       
  1311 
       
  1312 //---------------------------------------------------------------------------
       
  1313 // Requests the encoder to sends supplemental information in the bitstream
       
  1314 //---------------------------------------------------------------------------
       
  1315 //
       
  1316 void CAriMp4spencHwDeviceImpl::SendSupplementalInfoL(
       
  1317 													const TDesC8& /*aData*/)
       
  1318 	{
       
  1319 	PRINT_ENTRY;
       
  1320 
       
  1321 	if ( !iEncStateMac->IsInitialized() )
       
  1322 		{
       
  1323     	PRINT_ERR( "SendSupplementalInfoL () called before "
       
  1324     	    	    			"Initialize ()" );
       
  1325 		User::Leave( KErrNotReady );
       
  1326 		}
       
  1327 
       
  1328 	PRINT_ERR( "SendSupplementalInfoL () not supported.."
       
  1329 			"leaving with KErrNotSupported" );
       
  1330 	User::Leave( KErrNotSupported );
       
  1331 
       
  1332 	PRINT_EXIT;
       
  1333 	}
       
  1334 
       
  1335 //---------------------------------------------------------------------------
       
  1336 // Requests the encoder to sends supplemental information in the bitstream
       
  1337 //---------------------------------------------------------------------------
       
  1338 //
       
  1339 void CAriMp4spencHwDeviceImpl::SendSupplementalInfoL(
       
  1340 							const TDesC8& /*aData*/,
       
  1341 							const TTimeIntervalMicroSeconds& /*aTimestamp*/)
       
  1342 	{
       
  1343 	PRINT_ENTRY;
       
  1344 
       
  1345 	if ( !iEncStateMac->IsInitialized() )
       
  1346 		{
       
  1347     	PRINT_ERR( "SendSupplementalInfoL () called before "
       
  1348     	    	    			"Initialize ()" );
       
  1349 		User::Leave( KErrNotReady );
       
  1350 		}
       
  1351 
       
  1352 	PRINT_ERR( "SendSupplementalInfoL () not supported.."
       
  1353 			"leaving with KErrNotSupported" );
       
  1354 	User::Leave( KErrNotSupported );
       
  1355 
       
  1356     PRINT_EXIT;
       
  1357 	}
       
  1358 
       
  1359 //---------------------------------------------------------------------------
       
  1360 // Cancels the current supplemental information send request
       
  1361 //---------------------------------------------------------------------------
       
  1362 //
       
  1363 void CAriMp4spencHwDeviceImpl::CancelSupplementalInfo()
       
  1364 	{
       
  1365 	PRINT_ENTRY;
       
  1366 
       
  1367 	if ( !iEncStateMac->IsInitialized() )
       
  1368 		{
       
  1369 		ClientFatalError( KErrNotReady );
       
  1370 		return;
       
  1371 		}
       
  1372     ClientFatalError( KErrNotSupported );
       
  1373 
       
  1374 	PRINT_EXIT;
       
  1375 	}
       
  1376 
       
  1377 //---------------------------------------------------------------------------
       
  1378 // Gets the current output buffer status. The information includes
       
  1379 // the number of free output buffers and the total size of free buffers in
       
  1380 // bytes.
       
  1381 //---------------------------------------------------------------------------
       
  1382 //
       
  1383 void CAriMp4spencHwDeviceImpl::GetOutputBufferStatus(
       
  1384 													TUint& aNumFreeBuffers,
       
  1385 													TUint& aTotalFreeBytes )
       
  1386 	{
       
  1387 	PRINT_ENTRY;
       
  1388 
       
  1389 	if ( !iEncStateMac->IsInitialized() )
       
  1390 		{
       
  1391 		ClientFatalError( KErrNotReady );
       
  1392 		return;
       
  1393 		}
       
  1394 
       
  1395 	aNumFreeBuffers = iEngine->NumOutputBuffers()
       
  1396 			+ iOutputFreeBufferQueue.Count();
       
  1397 	aTotalFreeBytes = aNumFreeBuffers * iOutputBufferSize;
       
  1398 
       
  1399 	PRINT_EXIT;
       
  1400 	}
       
  1401 
       
  1402 //---------------------------------------------------------------------------
       
  1403 // Returns a used output buffer back to the encoder
       
  1404 //---------------------------------------------------------------------------
       
  1405 //
       
  1406 void CAriMp4spencHwDeviceImpl::ReturnBuffer( TVideoOutputBuffer* aBuffer )
       
  1407 	{
       
  1408 	PRINT_ENTRY;
       
  1409 
       
  1410 	if ( !iEncStateMac->IsInitialized() )
       
  1411 		{
       
  1412 		ClientFatalError( KErrNotReady );
       
  1413 		return;
       
  1414 		}
       
  1415 
       
  1416 	if (iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment)
       
  1417 		{
       
  1418 		TInt error = KErrNone;
       
  1419 		error = iOutputFreeBufferQueue.Append( aBuffer );
       
  1420 
       
  1421 		if ( error != KErrNone )
       
  1422 			{
       
  1423 			ClientFatalError( error );
       
  1424 			return;
       
  1425 			}
       
  1426 
       
  1427 		if ( !iPacketsPending )
       
  1428 			{
       
  1429 			return;
       
  1430 			}
       
  1431 
       
  1432 		// still has packets in temporary buffer
       
  1433 		if ( iTotalLengthFilledSoFarInPacketMode
       
  1434 				< iTotalOutputBufferLengthInPacketMode )
       
  1435 			{
       
  1436 			TVideoOutputBuffer *outBuf = iOutputFreeBufferQueue[0];
       
  1437 			FillVideoSegment( outBuf, iInternalOutputBufferQueue[0] );
       
  1438 			iOutputFreeBufferQueue.Remove( 0 );
       
  1439 			iMMFDevVideoRecordProxy->MdvrpNewBuffer( outBuf );
       
  1440 			}
       
  1441 		}
       
  1442 	else
       
  1443 		{
       
  1444 
       
  1445 		aBuffer->iData.Set( ( TUint8* ) aBuffer->iData.Ptr()
       
  1446 						, iOutputBufferSize );
       
  1447 
       
  1448 		// add the buffer back to queue or process engine
       
  1449 		if ( ( !iEncStateMac->IsInputEndPending() )
       
  1450 				&& ( !iEncStateMac->IsStopped() ) )
       
  1451 			{
       
  1452 			iEngine->AddOutput( ( TAny* ) aBuffer );
       
  1453 			}
       
  1454 		else
       
  1455 			{
       
  1456 			TInt error = iOutputFreeBufferQueue.Append( aBuffer );
       
  1457 			if ( error != KErrNone )
       
  1458 				{
       
  1459 				ClientFatalError( error );
       
  1460 				return;
       
  1461 				}
       
  1462 			}
       
  1463 		}
       
  1464 
       
  1465 	PRINT_EXIT;
       
  1466 	}
       
  1467 
       
  1468 //---------------------------------------------------------------------------
       
  1469 // Indicates a picture loss to the encoder, without specifying the lost
       
  1470 // picture
       
  1471 //---------------------------------------------------------------------------
       
  1472 //
       
  1473 void CAriMp4spencHwDeviceImpl::PictureLoss()
       
  1474 	{
       
  1475 	PRINT_ENTRY;
       
  1476 
       
  1477 	if ( !iEncStateMac->IsInitialized() )
       
  1478 		{
       
  1479 		ClientFatalError( KErrNotReady );
       
  1480 		return;
       
  1481 		}
       
  1482 	iPictureLoss = ETrue;
       
  1483 
       
  1484 	PRINT_EXIT;
       
  1485 	}
       
  1486 
       
  1487 //---------------------------------------------------------------------------
       
  1488 // Indicates to the encoder the pictures that have been lost
       
  1489 //---------------------------------------------------------------------------
       
  1490 //
       
  1491 void CAriMp4spencHwDeviceImpl::PictureLoss(
       
  1492 						const TArray<TPictureId>& /*aPictures*/ )
       
  1493 	{
       
  1494 	PRINT_ENTRY;
       
  1495 
       
  1496 	if ( !iEncStateMac->IsInitialized() )
       
  1497 		{
       
  1498 		ClientFatalError( KErrNotReady );
       
  1499 		return;
       
  1500 		}
       
  1501 	iPictureLoss = ETrue;
       
  1502 
       
  1503 	PRINT_EXIT;
       
  1504 	}
       
  1505 
       
  1506 //---------------------------------------------------------------------------
       
  1507 // Indicates a slice loss to the encoder.
       
  1508 //---------------------------------------------------------------------------
       
  1509 //
       
  1510 
       
  1511 void CAriMp4spencHwDeviceImpl::SliceLoss( TUint aFirstMacroblock,
       
  1512 		TUint aNumMacroblocks, const TPictureId& /*aPicture*/ )
       
  1513 	{
       
  1514 	PRINT_ENTRY;
       
  1515 
       
  1516 	if ( !iEncStateMac->IsInitialized() )
       
  1517 		{
       
  1518 		ClientFatalError( KErrNotReady );
       
  1519 		return;
       
  1520 		}
       
  1521 
       
  1522 	if ( ( aFirstMacroblock == 0 ) || ( aNumMacroblocks == 0 ) )
       
  1523 		{
       
  1524     	PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::SliceLoss() "
       
  1525     			"aNumMacroblocks or aFirstMacroblock = 0 return" ) );
       
  1526 		return;
       
  1527 		}
       
  1528 
       
  1529 	TMPEG4H263EncSliceLoss* sliceLossParams = NULL;
       
  1530 	TRAPD ( error, sliceLossParams = new( ELeave ) TMPEG4H263EncSliceLoss );
       
  1531 
       
  1532 	if ( error != KErrNone )
       
  1533 		{
       
  1534 		ClientFatalError( error );
       
  1535 		return;
       
  1536 		}
       
  1537 
       
  1538 	sliceLossParams->iFirstMacroblock = aFirstMacroblock;
       
  1539 	sliceLossParams->iNumMacroblocks = aNumMacroblocks;
       
  1540 
       
  1541 	TRAP ( error, iEngine->AddCommandL( CBaseEngine::ENormalPriority
       
  1542 						, CONTROL_CMD_SET_SLICELOSS, sliceLossParams ) );
       
  1543 
       
  1544 	if ( error != KErrNone )
       
  1545 		{
       
  1546 		delete sliceLossParams;
       
  1547 		ClientFatalError( error );
       
  1548 		return;
       
  1549 		}
       
  1550 
       
  1551 	PRINT_EXIT;
       
  1552 	}
       
  1553 
       
  1554 //---------------------------------------------------------------------------
       
  1555 // Sends a reference picture selection request to the encoder
       
  1556 //---------------------------------------------------------------------------
       
  1557 //
       
  1558 
       
  1559 void CAriMp4spencHwDeviceImpl::ReferencePictureSelection(
       
  1560 											const TDesC8& /*aSelectionData*/)
       
  1561 	{
       
  1562 	PRINT_ENTRY;
       
  1563 
       
  1564 	if (!iEncStateMac->IsInitialized() )
       
  1565 		{
       
  1566 		ClientFatalError( KErrNotReady );
       
  1567 		return;
       
  1568 		}
       
  1569     ClientFatalError( KErrNotSupported );
       
  1570 
       
  1571 	PRINT_EXIT;
       
  1572 	}
       
  1573 
       
  1574 //---------------------------------------------------------------------------
       
  1575 // Initializes the device, and reserves hardware resources
       
  1576 //---------------------------------------------------------------------------
       
  1577 //
       
  1578 
       
  1579 void CAriMp4spencHwDeviceImpl::Initialize()
       
  1580 	{
       
  1581 	PRINT_ENTRY;
       
  1582 
       
  1583 	//Device should be in unintialized state
       
  1584 	if ( !iEncStateMac->IsTransitionValid(
       
  1585 								CStateMachine::EInitializingCommand ) )
       
  1586 		{
       
  1587 		iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this,
       
  1588 				KErrPermissionDenied );
       
  1589 		return;
       
  1590 		}
       
  1591 
       
  1592 	// check for input and output formats set by the client
       
  1593 	if ( !( iSetMpeg4H263HWParams.iBeforeInitialize & EEncInputFormat ) )
       
  1594 		{
       
  1595 		PRINT_MSG( LEVEL_CRITICAL, ("CAriMp4spencHwDeviceImpl::Initialize() "
       
  1596 				"- SetInputFormat not called" ) );
       
  1597 		iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this
       
  1598 														, KErrNotSupported );
       
  1599 		return;
       
  1600 		}
       
  1601 
       
  1602 	// check for buffer sizes
       
  1603 	if ( iSetMpeg4H263HWParams.iBeforeInitialize & EEncBufferOptions )
       
  1604 		{
       
  1605 		if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  1606 			{
       
  1607 			// Buffer size related checks
       
  1608 			if ( ( iSetMpeg4H263HWParams.iPacketSize
       
  1609 					> KMPEG4H263ENCIMPL_MAX_SEGMENTSIZE )
       
  1610 					|| ( iSetMpeg4H263HWParams.iPacketSize
       
  1611 							> iSetMpeg4H263HWParams.iMaxOutputBufferSize )
       
  1612 					|| ( iSetMpeg4H263HWParams.iPacketSize == 0 ) )
       
  1613 				{
       
  1614 				iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this,
       
  1615 						KErrNotSupported );
       
  1616 				return;
       
  1617 				}
       
  1618 			}
       
  1619 
       
  1620 		else if ( iSetMpeg4H263HWParams.iDataUnitType == EDuCodedPicture )
       
  1621 			{
       
  1622 			if ( ( iSetMpeg4H263HWParams.iMaxCodedPictureSize
       
  1623 					> iSetMpeg4H263HWParams.iMaxOutputBufferSize )
       
  1624 					|| ( iSetMpeg4H263HWParams.iMaxCodedPictureSize == 0 ) )
       
  1625 				{
       
  1626 				iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this,
       
  1627 						KErrNotSupported );
       
  1628 				return;
       
  1629 				}
       
  1630 			}
       
  1631 		}
       
  1632 	else
       
  1633 		{
       
  1634 		if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  1635 			{
       
  1636 			iSetMpeg4H263HWParams.iMinNumOutputBuffers
       
  1637 					= KMPEG4H263ENCIMPL_MAXNUM_SEGMENTBUFFERS;
       
  1638 			iSetMpeg4H263HWParams.iPacketSize
       
  1639 					= KMPEG4H263ENCIMPL_DEFAULT_SEGMENTSIZE;
       
  1640 			iSetMpeg4H263HWParams.iMaxOutputBufferSize
       
  1641 					= KMPEG4H263ENCIMPL_MAX_SEGMENTSIZE;
       
  1642 			}
       
  1643 		else
       
  1644 			{
       
  1645 			iSetMpeg4H263HWParams.iMinNumOutputBuffers
       
  1646 					= KMPEG4H263ENCIMPL_MAXNUM_OUTPUTBUFFERS;
       
  1647 			}
       
  1648 		}
       
  1649 
       
  1650 	if ( iSetMpeg4H263HWParams.iOutputFormat == EMpeg4 )
       
  1651 		{
       
  1652 		if ( iSetMpeg4H263HWParams.iLevel == KMPEG4_LEVEL_UNKNOWN )
       
  1653 			{
       
  1654 
       
  1655 			if ( ( ( iSetMpeg4H263HWParams.iLevel == KMPEG4_LEVEL_UNKNOWN )
       
  1656 					&& ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1657 					== KMPEG4H263ENCIMPL_QCIF_WIDTH
       
  1658 					&& iSetMpeg4H263HWParams.iPictureSize.iHeight
       
  1659 					== KMPEG4H263ENCIMPL_QCIF_HEIGHT ) )
       
  1660 					|| ( iSetMpeg4H263HWParams.iLevel == KMPEG4_LEVEL_0 ) )
       
  1661 				{
       
  1662 				iSetMpeg4H263HWParams.iBitRate
       
  1663 					= KMPEG4ENCIMPL_BITRATE_LEVEL_0;
       
  1664 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1665 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_0;
       
  1666 				}
       
  1667 
       
  1668 			else if ( ( ( iSetMpeg4H263HWParams.iLevel
       
  1669 					== KMPEG4_LEVEL_UNKNOWN )
       
  1670 					&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1671 					* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1672 					<= 99 ) ) || ( iSetMpeg4H263HWParams.iLevel
       
  1673 					== KMPEG4_LEVEL_1 ) )
       
  1674 				{
       
  1675 				iSetMpeg4H263HWParams.iBitRate
       
  1676 					= KMPEG4ENCIMPL_BITRATE_LEVEL_1;
       
  1677 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1678 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_1;
       
  1679 				}
       
  1680 
       
  1681 			else if ( ( ( iSetMpeg4H263HWParams.iLevel
       
  1682 					== KMPEG4_LEVEL_UNKNOWN)
       
  1683 					&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1684 					* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1685 					<= 396 ) ) || ( iSetMpeg4H263HWParams.iLevel
       
  1686 					== KMPEG4_LEVEL_3 ) )
       
  1687 				{
       
  1688 				iSetMpeg4H263HWParams.iBitRate
       
  1689 					= KMPEG4ENCIMPL_BITRATE_LEVEL_3;
       
  1690 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1691 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_3;
       
  1692 				}
       
  1693 
       
  1694 			else if ( ( ( iSetMpeg4H263HWParams.iLevel
       
  1695 					== KMPEG4_LEVEL_UNKNOWN )
       
  1696 					&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1697 					* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1698 					<= 1200 ) ) || ( iSetMpeg4H263HWParams.iLevel
       
  1699 					== KMPEG4_LEVEL_4 ) )
       
  1700 				{
       
  1701 				iSetMpeg4H263HWParams.iBitRate
       
  1702 					= KMPEG4ENCIMPL_BITRATE_LEVEL_4A;
       
  1703 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1704 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_4;
       
  1705 				}
       
  1706 
       
  1707 			else if ( ( ( iSetMpeg4H263HWParams.iLevel
       
  1708 					== KMPEG4_LEVEL_UNKNOWN)
       
  1709 					&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1710 					* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1711 					<= 1620 ) ) || ( iSetMpeg4H263HWParams.iLevel
       
  1712 					== KMPEG4_LEVEL_5 ) )
       
  1713 				{
       
  1714 				iSetMpeg4H263HWParams.iBitRate
       
  1715 					= KMPEG4ENCIMPL_BITRATE_LEVEL_5;
       
  1716 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1717 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_5;
       
  1718 				}
       
  1719 
       
  1720 			else if ( ( (iSetMpeg4H263HWParams.iLevel
       
  1721 					== KMPEG4_LEVEL_UNKNOWN )
       
  1722 					&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1723 					* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1724 					<= 3600 ) ) || ( iSetMpeg4H263HWParams.iLevel
       
  1725 					== KMPEG4_LEVEL_6 ) )
       
  1726 				{
       
  1727 				iSetMpeg4H263HWParams.iBitRate
       
  1728 					= KMPEG4ENCIMPL_BITRATE_LEVEL_6;
       
  1729 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1730 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_6;
       
  1731 				}
       
  1732 
       
  1733 			else if ( ( ( iSetMpeg4H263HWParams.iLevel
       
  1734 					== KMPEG4_LEVEL_UNKNOWN )
       
  1735 					&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1736 					* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1737 					<= 8160 ) ) || (iSetMpeg4H263HWParams.iLevel
       
  1738 					== KMPEG4_LEVEL_7 ) )
       
  1739 				{
       
  1740 				iSetMpeg4H263HWParams.iBitRate
       
  1741 					= KMPEG4ENCIMPL_BITRATE_LEVEL_7;
       
  1742 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1743 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_7;
       
  1744 				}
       
  1745 
       
  1746 			else if ( iSetMpeg4H263HWParams.iLevel == KMPEG4_LEVEL_0B )
       
  1747 				{
       
  1748 				iSetMpeg4H263HWParams.iBitRate
       
  1749 					= KMPEG4ENCIMPL_BITRATE_LEVEL_0B;
       
  1750 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1751 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_0B;
       
  1752 				}
       
  1753 
       
  1754 			else if (iSetMpeg4H263HWParams.iLevel == KMPEG4_LEVEL_2)
       
  1755 				{
       
  1756 				iSetMpeg4H263HWParams.iBitRate
       
  1757 					= KMPEG4ENCIMPL_BITRATE_LEVEL_2;
       
  1758 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1759 				iSetMpeg4H263HWParams.iLevel = KMPEG4_LEVEL_2;
       
  1760 				}
       
  1761 			}
       
  1762 
       
  1763 		}
       
  1764 	else if ( iSetMpeg4H263HWParams.iOutputFormat == EH263 )
       
  1765 		{
       
  1766 		if ( ( ( iSetMpeg4H263HWParams.iLevel == KH263_LEVEL_UNKNOWN)
       
  1767 			&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1768 			* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1769 			<= 99 ) ) || ( iSetMpeg4H263HWParams.iLevel == KH263_LEVEL_10 ) )
       
  1770 			{
       
  1771 			iSetMpeg4H263HWParams.iBitRate = KH263ENCIMPL_BITRATE_LEVEL_10;
       
  1772 			iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1773 			iSetMpeg4H263HWParams.iLevel = KH263_LEVEL_10;
       
  1774 			}
       
  1775 
       
  1776 		else if ( ( ( iSetMpeg4H263HWParams.iLevel == KH263_LEVEL_UNKNOWN )
       
  1777 				&& ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1778 				* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256
       
  1779 				<= 396 ) ) || ( iSetMpeg4H263HWParams.iLevel
       
  1780 				== KH263_LEVEL_30 ) )
       
  1781 			{
       
  1782 			iSetMpeg4H263HWParams.iBitRate = KH263ENCIMPL_BITRATE_LEVEL_30;
       
  1783 			iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate30;
       
  1784 			iSetMpeg4H263HWParams.iLevel = KH263_LEVEL_30;
       
  1785 			}
       
  1786 
       
  1787 		else if ( iSetMpeg4H263HWParams.iLevel == KH263_LEVEL_20 )
       
  1788 			{
       
  1789 			iSetMpeg4H263HWParams.iBitRate = KH263ENCIMPL_BITRATE_LEVEL_20;
       
  1790 			iSetMpeg4H263HWParams.iLevel = KH263ENCIMPL_LEVEL20;
       
  1791 			if ( ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1792 				* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256) <= 396 )
       
  1793 				{
       
  1794 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate15;
       
  1795 				}
       
  1796 			else if ( ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  1797 				* iSetMpeg4H263HWParams.iPictureSize.iHeight ) / 256) <= 99 )
       
  1798 				{
       
  1799 				iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate30;
       
  1800 				}
       
  1801 			}
       
  1802 
       
  1803 		else if ( iSetMpeg4H263HWParams.iLevel == KH263_LEVEL_40 )
       
  1804 			{
       
  1805 			iSetMpeg4H263HWParams.iBitRate = KH263ENCIMPL_BITRATE_LEVEL_40;
       
  1806 			iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate30;
       
  1807 			iSetMpeg4H263HWParams.iLevel = KH263ENCIMPL_LEVEL40;
       
  1808 			}
       
  1809 
       
  1810 		else if ( iSetMpeg4H263HWParams.iLevel == KH263_LEVEL_45 )
       
  1811 			{
       
  1812 			iSetMpeg4H263HWParams.iBitRate = KH263ENCIMPL_BITRATE_LEVEL_45;
       
  1813 			iSetMpeg4H263HWParams.iTargetPictureRate = KPictureRate30;
       
  1814 			iSetMpeg4H263HWParams.iLevel = KH263ENCIMPL_LEVEL45;
       
  1815 			}
       
  1816 		}
       
  1817 
       
  1818 	if ( iSetMpeg4H263HWParams.iOutputFormat == EH263 )
       
  1819 		{
       
  1820 		iSetMpeg4H263HWParams.iTimerResolution = KDefaultTimerResolution;
       
  1821 		iSetMpeg4H263HWParams.iReversibleVLC = E_ON;
       
  1822 		iSetMpeg4H263HWParams.iDataPartitioning = E_ON;
       
  1823 		iSetMpeg4H263HWParams.iMAPS = E_ON;
       
  1824 		}
       
  1825 	else
       
  1826 		{
       
  1827 		iSetMpeg4H263HWParams.iTimerResolution = KDefaultTimerResolution;
       
  1828 		iSetMpeg4H263HWParams.iReversibleVLC = E_OFF;
       
  1829 		iSetMpeg4H263HWParams.iDataPartitioning = E_OFF;
       
  1830 		iSetMpeg4H263HWParams.iMAPS = E_OFF;
       
  1831 		}
       
  1832 
       
  1833 	TUint maxNumOfPackets;
       
  1834 	// create codec
       
  1835 	TRAPD ( error, iCodec
       
  1836 			= CAriMp4spencWrapper::NewL ( iSetMpeg4H263HWParams ) );
       
  1837 
       
  1838 	if ( error != KErrNone )
       
  1839 		{
       
  1840 		// init complete with error message
       
  1841 		iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1842 		return;
       
  1843 		}
       
  1844 
       
  1845 	// set the sync options to the codec
       
  1846 	if ( iClockSource )
       
  1847 		{
       
  1848 		TInt error = iCodec->SetSyncOptions( iClockSource );
       
  1849 		if ( error != KErrNone )
       
  1850 			{
       
  1851 			iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1852 			return;
       
  1853 			}
       
  1854 		}
       
  1855 
       
  1856 		//create engine
       
  1857 		TRAP ( error, iEngine
       
  1858 				= CBaseEngine::NewL( this, ( MBaseCodec* )iCodec, EFalse ) );
       
  1859 
       
  1860 	if ( error != KErrNone )
       
  1861 		{
       
  1862 		//init complete with error message
       
  1863 		iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1864 		return;
       
  1865 		}
       
  1866 	//get the max buffer length from the codec
       
  1867 	TUint maxOutputBufferSize = 0;
       
  1868 	error = iCodec->GetParam( CONTROL_CMD_GET_MAXBUFFERLENGTH,
       
  1869 			&maxOutputBufferSize );
       
  1870 
       
  1871 	if ( error != KErrNone )
       
  1872 		{
       
  1873 		//init complete with error message
       
  1874 		iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1875 		return;
       
  1876 		}
       
  1877 
       
  1878 	// if EduCodedPicture mode then check for buffer size passed
       
  1879 	if ( iSetMpeg4H263HWParams.iDataUnitType == EDuCodedPicture )
       
  1880 		{
       
  1881 		if ( iSetMpeg4H263HWParams.iBeforeInitialize & EEncBufferOptions )
       
  1882 			{
       
  1883 			if ( maxOutputBufferSize
       
  1884 					> iSetMpeg4H263HWParams.iMaxCodedPictureSize )
       
  1885 				{
       
  1886 				//init complete with error message
       
  1887 				iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this,
       
  1888 						KErrNotSupported );
       
  1889 				return;
       
  1890 				}
       
  1891 			}
       
  1892 		else
       
  1893 			{
       
  1894 			iSetMpeg4H263HWParams.iMaxOutputBufferSize = maxOutputBufferSize;
       
  1895 			iSetMpeg4H263HWParams.iMaxCodedPictureSize = maxOutputBufferSize;
       
  1896 			}
       
  1897 		}
       
  1898 
       
  1899 	// if packet mode is on then allocate memory for NAL information
       
  1900 	iMaxNumOfPackets = 0;
       
  1901 	if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  1902 		{
       
  1903 		error = iCodec->GetParam( CONTROL_CMD_GET_MAXNUMOFPACKETS,
       
  1904 				&iMaxNumOfPackets );
       
  1905 		if ( error != KErrNone )
       
  1906 			{
       
  1907 			iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1908 			return;
       
  1909 			}
       
  1910 		maxNumOfPackets = iMaxNumOfPackets * KDoubleWordLength;
       
  1911 		}
       
  1912 
       
  1913 	if ( iSetMpeg4H263HWParams.iDataUnitType != EDuVideoSegment )
       
  1914 		{
       
  1915 			TRAP ( error,CreateCodedOutputBuffersL( (
       
  1916 													maxOutputBufferSize ) ) );
       
  1917 		}
       
  1918 
       
  1919 	else
       
  1920 		{
       
  1921 		// Allocate sufficient segment mode buffers
       
  1922 		iSetMpeg4H263HWParams.iMinNumOutputBuffers = ( maxOutputBufferSize
       
  1923 				/ iSetMpeg4H263HWParams.iPacketSize )
       
  1924 				* KMPEG4H263ENCIMPL_MAXNUM_OUTPUTBUFFERS;
       
  1925 
       
  1926 		TRAP ( error, CreateInternalOutputBuffersL( maxOutputBufferSize ) );
       
  1927 		if ( error != KErrNone )
       
  1928 			{
       
  1929 			iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1930 			return;
       
  1931 			}
       
  1932 			TRAP( error, CreatePacketOffsetLengthInfoBuffersL(
       
  1933 														maxNumOfPackets ) );
       
  1934 		if ( error != KErrNone )
       
  1935 			{
       
  1936 			iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1937 			return;
       
  1938 			}
       
  1939 
       
  1940 		TUint* ptr = iFreeBufferQueueForPacketOffsetInfo[0];
       
  1941 		TRAPD ( err, iPacketOffsetBuf = new( ELeave ) TPtr8( ( TUint8* ) ptr,
       
  1942 						maxNumOfPackets, maxNumOfPackets ) );
       
  1943 		if ( err )
       
  1944 			{
       
  1945 			ClientFatalError( KErrNoMemory );
       
  1946 			}
       
  1947 
       
  1948 		//segment size  will be the max segment size
       
  1949 		TUint segmentSize = iSetMpeg4H263HWParams.iPacketSize;
       
  1950 		TRAP ( error, CreateCodedOutputBuffersL( segmentSize ) );
       
  1951 		if ( error != KErrNone )
       
  1952 			{
       
  1953 			iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1954 			return;
       
  1955 			}
       
  1956 		}
       
  1957 
       
  1958 	if ( error != KErrNone )
       
  1959 		{
       
  1960 		iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, error );
       
  1961 		return;
       
  1962 		}
       
  1963 
       
  1964 	//reset the picture counters
       
  1965 	iPictureCounters.iInputPictures = 0;
       
  1966 	iPictureCounters.iPicturesSkippedRateControl = 0;
       
  1967 	iPictureCounters.iPicturesProcessed = 0;
       
  1968 	// reset the options set by client
       
  1969 	iSetMpeg4H263HWParams.iBeforeInitialize = 0;
       
  1970 	iCurSetMpeg4H263HWParams = iSetMpeg4H263HWParams;
       
  1971 	iEncStateMac->Transit( CStateMachine::EInitializingCommand );
       
  1972 	iEncStateMac->Transit( CStateMachine::EInitializeCommand );
       
  1973 	iMMFDevVideoRecordProxy->MdvrpInitializeComplete( this, KErrNone );
       
  1974 
       
  1975 	PRINT_EXIT;
       
  1976 	}
       
  1977 
       
  1978 //---------------------------------------------------------------------------
       
  1979 // Commit all changes since the last CommitL(), Revert() or Initialize()
       
  1980 // to the Hw device
       
  1981 //---------------------------------------------------------------------------
       
  1982 //
       
  1983 
       
  1984 void CAriMp4spencHwDeviceImpl::CommitL()
       
  1985 	{
       
  1986 	PRINT_ENTRY;
       
  1987 
       
  1988 	// This method can only be called after Initialize
       
  1989 	if ( !iEncStateMac->IsInitialized() )
       
  1990 		{
       
  1991     	PRINT_ERR( "CommitL () called before Initialize ()" );
       
  1992 		User::Leave( KErrNotReady );
       
  1993 		}
       
  1994 
       
  1995 	// Methods that will be affected by CommitL in our case:
       
  1996 	// SetOutputRectL
       
  1997 	// SetCodingStandardSpecificOptionsL
       
  1998 	// SetErrorsExpected
       
  1999 	// SetMinRandomAccessRate
       
  2000 
       
  2001 	TMpeg4H263EncoderInitParams *currentParams =
       
  2002 			new ( ELeave ) TMpeg4H263EncoderInitParams;
       
  2003 
       
  2004 	CleanupStack::PushL( currentParams );
       
  2005 	*currentParams = iCurSetMpeg4H263HWParams;
       
  2006 
       
  2007 	// Add command apply commit settings to the codec
       
  2008 	iEngine->AddCommandL( CBaseEngine::ENormalPriority,
       
  2009 			CONTROL_CMD_SET_COMMIT_OPTIONS, currentParams );
       
  2010 
       
  2011 	iCurSetMpeg4H263HWParams.iAfterInitialize = 0;
       
  2012 	iSetMpeg4H263HWParams = iCurSetMpeg4H263HWParams;
       
  2013 	CleanupStack::Pop( currentParams );
       
  2014 
       
  2015 	PRINT_EXIT;
       
  2016 	}
       
  2017 
       
  2018 //---------------------------------------------------------------------------
       
  2019 // Revert all changes since the last CommitL(), Revert() or Initialize()
       
  2020 // back to their previous settings
       
  2021 //---------------------------------------------------------------------------
       
  2022 //
       
  2023 
       
  2024 void CAriMp4spencHwDeviceImpl::Revert()
       
  2025 	{
       
  2026 	PRINT_ENTRY;
       
  2027 
       
  2028 	// This method can only be called after Initialize
       
  2029 	if ( !iEncStateMac->IsInitialized() )
       
  2030 		{
       
  2031 		ClientFatalError( KErrNotReady );
       
  2032 		return;
       
  2033 		}
       
  2034 
       
  2035 	// Methods that will be affected by Revert in our case:
       
  2036 	// SetOutputRectL
       
  2037 	// SetCodingStandardSpecificOptionsL
       
  2038 	// SetErrorsExpected
       
  2039 	// SetMinRandomAccessRate
       
  2040 	iCurSetMpeg4H263HWParams = iSetMpeg4H263HWParams;
       
  2041 	iCurSetMpeg4H263HWParams.iAfterInitialize = 0;
       
  2042 
       
  2043 	PRINT_EXIT;
       
  2044 	}
       
  2045 
       
  2046 //---------------------------------------------------------------------------
       
  2047 // This method is called only in case of client memory buffers
       
  2048 //---------------------------------------------------------------------------
       
  2049 //
       
  2050 
       
  2051 void CAriMp4spencHwDeviceImpl::WritePictureL( TVideoPicture* aPicture )
       
  2052 	{
       
  2053 	PRINT_ENTRY;
       
  2054 
       
  2055 	// This method should only be called only in following states
       
  2056 	if ( !iEncStateMac->IsInitialized() )
       
  2057 		{
       
  2058     	PRINT_ERR( "WritePictureL () called before Initialize ()" );
       
  2059 		User::Leave( KErrNotReady );
       
  2060 		}
       
  2061 
       
  2062 	if ( iEncStateMac->IsInputEndPending() )
       
  2063 		{
       
  2064     	PRINT_ERR( "Input end is pending.. leaving with KErrEof" );
       
  2065 		User::Leave( KErrEof );
       
  2066 		}
       
  2067 
       
  2068 	if ( !aPicture || ( aPicture->iData.iRawData->Length() == 0 )
       
  2069 		|| ( aPicture->iData.iRawData->Length()
       
  2070 		!= ( ( iSetMpeg4H263HWParams.iPictureSize.iWidth
       
  2071 		* iSetMpeg4H263HWParams.iPictureSize.iHeight * 3 ) / 2 ) )
       
  2072 		|| ( aPicture->iData.iDataFormat != EYuvRawData ) )
       
  2073 		{
       
  2074 		PRINT_ERR( "Incorrect parameter passed" );
       
  2075 		User::Leave( KErrArgument );
       
  2076 		return;
       
  2077 		}
       
  2078 
       
  2079 	// Added a check to return the input picture if application tries to add
       
  2080 	// pictures after calling InputEnd() or Stop() and before calling
       
  2081 	// Start() again.
       
  2082 	if ( iEncStateMac->IsStopped() )
       
  2083 		{
       
  2084 		SkipInputPicture( aPicture );
       
  2085 		return;
       
  2086 		}
       
  2087 
       
  2088 	// counter to represent the num of input pictures received
       
  2089 	iPictureCounters.iInputPictures++;
       
  2090 	if ( IsForcedIFrameRequired( aPicture ) )
       
  2091 		{
       
  2092 		iEngine->AddCommandL( CBaseEngine::ENormalPriority,
       
  2093 				CONTROL_CMD_SET_FORCED_I_FRAME, NULL );
       
  2094 		iPictureLoss = EFalse;
       
  2095 		}
       
  2096 
       
  2097 	//Check if clock source is enabled skip logic
       
  2098 	if ( iClockSource )
       
  2099 		{
       
  2100 		if ( ( !CanEncode( aPicture ) ) || iFrozen )
       
  2101 			{
       
  2102 			SkipInputPicture( aPicture );
       
  2103 			return;
       
  2104 			}
       
  2105 		}
       
  2106 
       
  2107     TInt error = iEngine->AddInput( aPicture );
       
  2108 	if ( error != KErrNone )
       
  2109 		{
       
  2110 		PRINT_ERR( "CAriMp4spencHwDeviceImpl::WritePictureL()"
       
  2111 				" AddInput() failed" );
       
  2112 		User::Leave( error );
       
  2113 		return;
       
  2114 		}
       
  2115 
       
  2116 	//If output buffer is available for encoding immedietly, only then send it
       
  2117 	// for encoding
       
  2118 	if ( this->iSetMpeg4H263HWParams.iProcessRealtime )
       
  2119 		{
       
  2120 		if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  2121 			{
       
  2122 			TInt perPictureSegmentBuffers =
       
  2123 					iSetMpeg4H263HWParams.iMinNumOutputBuffers
       
  2124 							/ KMPEG4H263ENCIMPL_MAXNUM_OUTPUTBUFFERS;
       
  2125 			TInt queueCount = iOutputFreeBufferQueue.Count();
       
  2126 			//  Check for availability of segment buffers
       
  2127 			if ( queueCount < perPictureSegmentBuffers )
       
  2128 				{
       
  2129 				// Sufficient number of segment buffers are not present
       
  2130     			PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl"
       
  2131     			"::WritePictureL() Input returned EDuVideoSegment " ) );
       
  2132 				/* Return the earlier input picture added to the queue. */
       
  2133 				iEngine->ReturnInput();
       
  2134 				return;
       
  2135 				}
       
  2136 			}
       
  2137 		else
       
  2138 			{
       
  2139 			//  Check for availability of buffers
       
  2140 			if ( iEngine->NumOutputBuffers() == 0 )
       
  2141 				{
       
  2142 				// Return the earlier input picture added to the queue
       
  2143     			PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl"
       
  2144     			"::WritePictureL() Input returned EDuCodedPicture " ) );
       
  2145 				iEngine->ReturnInput();
       
  2146 				return;
       
  2147 				}
       
  2148 			}
       
  2149 		}
       
  2150 
       
  2151 	PRINT_EXIT;
       
  2152 	}
       
  2153 
       
  2154 //---------------------------------------------------------------------------
       
  2155 // Notifies the hardware device that the end of input data has been reached
       
  2156 // and no more input pictures will be written
       
  2157 //---------------------------------------------------------------------------
       
  2158 //
       
  2159 
       
  2160 void CAriMp4spencHwDeviceImpl::InputEnd()
       
  2161 	{
       
  2162 	PRINT_ENTRY;
       
  2163 
       
  2164 	if ( !iEncStateMac->IsTransitionValid( CStateMachine::EInputEndCommand ) )
       
  2165 		{
       
  2166 		ClientFatalError( KErrPermissionDenied );
       
  2167 		return;
       
  2168 		}
       
  2169 
       
  2170 	if ( iEngine->NumInputBuffers() == 0 )
       
  2171 		{
       
  2172     	PRINT_MSG( LEVEL_HIGH, ("CAriMp4spencHwDeviceImpl::InputEnds()" ) );
       
  2173 		Stop();
       
  2174 		iMMFDevVideoRecordProxy->MdvrpStreamEnd();
       
  2175 		return;
       
  2176 		}
       
  2177 	else
       
  2178 		{
       
  2179 		iInputEndCalled = ETrue;
       
  2180 		}
       
  2181 	iEncStateMac->Transit( CStateMachine::EInputEndCommand );
       
  2182 
       
  2183 	PRINT_EXIT;
       
  2184 	}
       
  2185 
       
  2186 //---------------------------------------------------------------------------
       
  2187 // Starts recording video
       
  2188 //---------------------------------------------------------------------------
       
  2189 //
       
  2190 
       
  2191 void CAriMp4spencHwDeviceImpl::Start()
       
  2192 	{
       
  2193 	PRINT_ENTRY;
       
  2194 
       
  2195 	if ( iEncStateMac->IsPlaying() && !iEncStateMac->IsPaused() )
       
  2196 		{
       
  2197     	PRINT_MSG( LEVEL_LOW, ( "CAriMp4spencHwDeviceImpl::Start()-already "
       
  2198     			"in started state, So ignore" ) );
       
  2199 		return;
       
  2200 		}
       
  2201 
       
  2202 	if ( !iEncStateMac->IsTransitionValid( CStateMachine::EStartCommand ) )
       
  2203 		{
       
  2204 		ClientFatalError( KErrPermissionDenied );
       
  2205 		return;
       
  2206 		}
       
  2207 
       
  2208 	if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  2209 		{
       
  2210 		// Enable flag which indicates that all picture params and sequence
       
  2211 		// params are put into 1st buffer
       
  2212 		for ( TInt i = 0; i <= iInternalOutputBufferQueue.Count(); i++ )
       
  2213 			{
       
  2214 			TVideoOutputBuffer *outputBuffer = iInternalOutputBufferQueue[0];
       
  2215 			iEngine->AddOutput( ( TAny* ) outputBuffer );
       
  2216 			iInternalOutputBufferQueue.Remove( 0 );
       
  2217 			}
       
  2218 		}
       
  2219 	else
       
  2220 		{
       
  2221 		// add all output buffers to engine
       
  2222 		for ( TInt i = 0; i <= iOutputFreeBufferQueue.Count(); i++ )
       
  2223 			{
       
  2224 			TVideoOutputBuffer *outputBuffer = iOutputFreeBufferQueue[0];
       
  2225 			iEngine->AddOutput( ( TAny* ) outputBuffer );
       
  2226 			iOutputFreeBufferQueue.Remove( 0 );
       
  2227 			}
       
  2228 		}
       
  2229 
       
  2230 	if ( iClockSource )
       
  2231 		{
       
  2232 		TTime lSystemTime;
       
  2233 		lSystemTime.UniversalTime();
       
  2234 		UpdateTime();
       
  2235 		iPeriodicTimer->Start( iPollingInterval, iPollingInterval, TCallBack(
       
  2236 				CAriMp4spencHwDeviceImpl::TimerCallBack, ( TAny* ) this ) );
       
  2237 		}
       
  2238 
       
  2239 	iEngine->Start();
       
  2240     PRINT_MSG( LEVEL_LOW,("CAriMp4spencHwDeviceImpl::Start()Change to start"
       
  2241     		"state**") ) ;
       
  2242 	iEncStateMac->Transit( CStateMachine::EStartCommand );
       
  2243 
       
  2244 	PRINT_EXIT;
       
  2245 	}
       
  2246 
       
  2247 //---------------------------------------------------------------------------
       
  2248 // Callback function to CPeriodicTimer object
       
  2249 //---------------------------------------------------------------------------
       
  2250 //
       
  2251 TInt CAriMp4spencHwDeviceImpl::TimerCallBack( TAny* aPtr )
       
  2252 	{
       
  2253 	PRINT_ENTRY;
       
  2254 
       
  2255 	if ( !aPtr )
       
  2256 		{
       
  2257 		( ( CAriMp4spencHwDeviceImpl* ) aPtr )->ClientFatalError(
       
  2258 															KErrArgument );
       
  2259         return KErrNone;
       
  2260 		}
       
  2261 
       
  2262 	PRINT_EXIT;
       
  2263 	return ( ( CAriMp4spencHwDeviceImpl* ) aPtr )->UpdateTime();
       
  2264 	}
       
  2265 
       
  2266 //---------------------------------------------------------------------------
       
  2267 // Stops recording video.
       
  2268 //---------------------------------------------------------------------------
       
  2269 //
       
  2270 void CAriMp4spencHwDeviceImpl::Stop()
       
  2271 	{
       
  2272 	PRINT_ENTRY;
       
  2273 
       
  2274 	if ( iEncStateMac->IsStopped() )
       
  2275 		{
       
  2276     	PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::Stop() -> already"
       
  2277     			"stop state, so ignore" ) );
       
  2278 		return;
       
  2279 		}
       
  2280 
       
  2281 	if ( !iEncStateMac->IsTransitionValid( CStateMachine::EStopCommand ) )
       
  2282 		{
       
  2283     	PRINT_MSG( LEVEL_CRITICAL, ("CAriMp4spencHwDeviceImpl::Stop() -> "
       
  2284     			"fatalerror because Stop called in invalid state" ) );
       
  2285 		ClientFatalError( KErrPermissionDenied );
       
  2286 		return;
       
  2287 		}
       
  2288 
       
  2289 	iInputEndCalled = EFalse;
       
  2290 	if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  2291 		{
       
  2292 		iTotalOutputBufferLengthInPacketMode = 0;
       
  2293 		iTotalLengthFilledSoFarInPacketMode = 0;
       
  2294 		iPacketsPending = EFalse;
       
  2295 		}
       
  2296 
       
  2297 	iEngine->Stop();
       
  2298 	iEngine->Reset();
       
  2299 	iFrozen = EFalse;
       
  2300 	if ( iPeriodicTimer )
       
  2301 		{
       
  2302 		iPeriodicTimer->Cancel();
       
  2303 		}
       
  2304 	iEncStateMac->Transit( CStateMachine::EStopCommand );
       
  2305 
       
  2306 	PRINT_EXIT;
       
  2307 	}
       
  2308 
       
  2309 //---------------------------------------------------------------------------
       
  2310 // Pauses video recording
       
  2311 //---------------------------------------------------------------------------
       
  2312 //
       
  2313 void CAriMp4spencHwDeviceImpl::Pause()
       
  2314 	{
       
  2315 	PRINT_ENTRY;
       
  2316 
       
  2317 	if ( iEncStateMac->IsPaused() )
       
  2318 		{
       
  2319     	PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::Pause()-> already "
       
  2320     			" Paused state, so ignore" ) );
       
  2321 		return;
       
  2322 		}
       
  2323 
       
  2324 	if ( !iEncStateMac->IsTransitionValid( CStateMachine::EPauseCommand ) )
       
  2325 		{
       
  2326     	PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::Pause() Pause "
       
  2327     			"called in invalid state" ) );
       
  2328 		ClientFatalError( KErrPermissionDenied );
       
  2329 		return;
       
  2330 		}
       
  2331 
       
  2332 	if ( iClockSource )
       
  2333 		{
       
  2334 		iPeriodicTimer->Cancel();
       
  2335 		//Note down the clock when paued
       
  2336 		iClockTimeWhenPaused = iClockSource->Time().Int64();
       
  2337 		}
       
  2338 
       
  2339 	// Stop the engine
       
  2340 	iEngine->Stop();
       
  2341 
       
  2342 	//Change the state of the encoder
       
  2343 	iEncStateMac->Transit( CStateMachine::EPauseCommand );
       
  2344 
       
  2345 	PRINT_EXIT;
       
  2346 	}
       
  2347 
       
  2348 //---------------------------------------------------------------------------
       
  2349 // Resumes video recording
       
  2350 //---------------------------------------------------------------------------
       
  2351 //
       
  2352 void CAriMp4spencHwDeviceImpl::Resume()
       
  2353 	{
       
  2354 	PRINT_ENTRY;
       
  2355 
       
  2356 	// doing it before transitionvalid check because initialize->resume is
       
  2357 	// not added
       
  2358 	if ( iEncStateMac->IsInInitializedState() )
       
  2359 		{
       
  2360     	PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::Resume()->Got "
       
  2361     			"resume in initialized state. So go to start()" ) );
       
  2362 		Start();
       
  2363 		return;
       
  2364 		}
       
  2365 
       
  2366 	if ( iEncStateMac->IsPlaying() && !iEncStateMac->IsPaused() )
       
  2367 		{
       
  2368     	PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::Resume()->already "
       
  2369     			"in playing-not-paused state, so ignore" ) );
       
  2370 		return;
       
  2371 		}
       
  2372 
       
  2373 	if ( !iEncStateMac->IsTransitionValid( CStateMachine::EResumeCommand ) )
       
  2374 		{
       
  2375     	PRINT_MSG( LEVEL_CRITICAL, ("Resume called in invalid state" ) );
       
  2376 		ClientFatalError( KErrPermissionDenied );
       
  2377 		return;
       
  2378 		}
       
  2379 
       
  2380 	// No arguments to be passed in Resume
       
  2381 	if ( iClockSource )
       
  2382 		{
       
  2383 		//Clock may or may not be paused, when HWDevice is paused, so
       
  2384 		//add the paused duration to clock
       
  2385 		iPauseOffset = iClockSource->Time().Int64();
       
  2386 		iPauseOffset -= iClockTimeWhenPaused;
       
  2387 
       
  2388 		//calculate the total time and deviation
       
  2389 		iTotalTime += iPauseOffset;
       
  2390 		TTime lSystemTime;
       
  2391 		lSystemTime.UniversalTime();
       
  2392 
       
  2393 		// Send Update time before sending Resume command, so that clock source
       
  2394 		// is set before
       
  2395 		UpdateTime();
       
  2396 		iPeriodicTimer->Start( iPollingInterval, iPollingInterval, TCallBack(
       
  2397 				CAriMp4spencHwDeviceImpl::TimerCallBack, ( TAny* ) this ) );
       
  2398 		}
       
  2399 
       
  2400 	// Start the engine
       
  2401 	iEngine->Start();
       
  2402 	if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  2403 		{
       
  2404 		// send the remaining pending packets to client
       
  2405 		while ( iOutputFreeBufferQueue.Count() && iPacketsPending )
       
  2406 			{
       
  2407 			TVideoOutputBuffer *outBuf = iOutputFreeBufferQueue[0];
       
  2408 			FillVideoSegment( outBuf, iInternalOutputBufferQueue[0] );
       
  2409 			iOutputFreeBufferQueue.Remove( 0 );
       
  2410 			iMMFDevVideoRecordProxy->MdvrpNewBuffer( outBuf );
       
  2411 			}
       
  2412 		}
       
  2413 
       
  2414 	//Change the state of the encoder
       
  2415 	PRINT_EXIT;
       
  2416 	iEncStateMac->Transit( CStateMachine::EResumeCommand );
       
  2417 	}
       
  2418 
       
  2419 //---------------------------------------------------------------------------
       
  2420 // Freezes the input picture
       
  2421 //---------------------------------------------------------------------------
       
  2422 //
       
  2423 
       
  2424 void CAriMp4spencHwDeviceImpl::Freeze()
       
  2425 	{
       
  2426 	PRINT_ENTRY;
       
  2427 
       
  2428 	if ( !iEncStateMac->IsInitialized() )
       
  2429 		{
       
  2430     	PRINT_MSG( LEVEL_CRITICAL,("CAriMp4spencHwDeviceImpl::Freeze() Freeze"
       
  2431     			" called in invalid state" ) );
       
  2432 		ClientFatalError( KErrNotReady );
       
  2433 		return;
       
  2434 		}
       
  2435 	iFrozen = ETrue;
       
  2436 
       
  2437 	PRINT_EXIT;
       
  2438 	}
       
  2439 
       
  2440 //---------------------------------------------------------------------------
       
  2441 // Releases a frozen input picture
       
  2442 //---------------------------------------------------------------------------
       
  2443 //
       
  2444 
       
  2445 void CAriMp4spencHwDeviceImpl::ReleaseFreeze()
       
  2446 	{
       
  2447 
       
  2448 	PRINT_ENTRY;
       
  2449 
       
  2450 	if ( !iEncStateMac->IsInitialized() )
       
  2451 		{
       
  2452     	PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::ReleaseFreeze() "
       
  2453     			"called in invalid state" ) );
       
  2454 		ClientFatalError( KErrNotReady );
       
  2455 		return;
       
  2456 		}
       
  2457 	iFrozen = EFalse;
       
  2458 
       
  2459 	PRINT_EXIT;
       
  2460 	}
       
  2461 
       
  2462 //---------------------------------------------------------------------------
       
  2463 // Returns the current recording position
       
  2464 //---------------------------------------------------------------------------
       
  2465 //
       
  2466 TTimeIntervalMicroSeconds CAriMp4spencHwDeviceImpl::RecordingPosition()
       
  2467 	{
       
  2468 	PRINT_ENTRY;
       
  2469 
       
  2470 	if ( !iEncStateMac->IsInitialized() )
       
  2471 		{
       
  2472     	PRINT_MSG( LEVEL_HIGH, ("CAriMp4spencHwDeviceImpl::"
       
  2473     			"RecordingPosition() called in invalid state" ) );
       
  2474 		ClientFatalError( KErrNotReady );
       
  2475 		return TTimeIntervalMicroSeconds( 0 );
       
  2476 		}
       
  2477 
       
  2478 	PRINT_EXIT;
       
  2479 	return TTimeIntervalMicroSeconds( iLastEncodedPictureTimestamp );
       
  2480 	}
       
  2481 
       
  2482 //---------------------------------------------------------------------------
       
  2483 // Reads various counters related to processed video pictures
       
  2484 //---------------------------------------------------------------------------
       
  2485 //
       
  2486 void CAriMp4spencHwDeviceImpl::GetPictureCounters(
       
  2487 		CMMFDevVideoRecord::TPictureCounters& aCounters )
       
  2488 	{
       
  2489 	PRINT_ENTRY;
       
  2490 
       
  2491 	if ( !iEncStateMac->IsInitialized() )
       
  2492 		{
       
  2493 		ClientFatalError( KErrNotReady );
       
  2494 		return;
       
  2495 		}
       
  2496 
       
  2497 	TUint numofpacktsskipped;
       
  2498 	TUint err = iCodec->GetParam( CONTROL_CMD_GET_NUMOFPICTSKIPPED,
       
  2499 			&numofpacktsskipped );
       
  2500 	iPictureCounters.iPicturesSkippedRateControl
       
  2501 		= iPictureCounters.iPicturesSkippedRateControl + numofpacktsskipped;
       
  2502 	iPictureCounters.iPicturesProcessed = iPictureCounters.iInputPictures
       
  2503 			- iPictureCounters.iPicturesSkippedRateControl;
       
  2504 
       
  2505 	aCounters = iPictureCounters;
       
  2506 	//reset the counters
       
  2507 	iPictureCounters.iInputPictures = 0;
       
  2508 	iPictureCounters.iPicturesSkippedRateControl = 0;
       
  2509 	iPictureCounters.iPicturesProcessed = 0;
       
  2510 
       
  2511 	PRINT_EXIT;
       
  2512 	}
       
  2513 
       
  2514 //---------------------------------------------------------------------------
       
  2515 // Reads the frame stabilisation output picture position.
       
  2516 //---------------------------------------------------------------------------
       
  2517 //
       
  2518 void CAriMp4spencHwDeviceImpl::GetFrameStabilisationOutput(
       
  2519 												TRect&/* aRect*/)
       
  2520 	{
       
  2521 	PRINT_ENTRY;
       
  2522 	PRINT_EXIT;
       
  2523 	ClientFatalError( KErrNotSupported );
       
  2524 	}
       
  2525 
       
  2526 //---------------------------------------------------------------------------
       
  2527 // Retrieves the number of complexity control levels available for this
       
  2528 // hardware device
       
  2529 //---------------------------------------------------------------------------
       
  2530 //
       
  2531 TUint CAriMp4spencHwDeviceImpl::NumComplexityLevels()
       
  2532 	{
       
  2533 
       
  2534 	PRINT_ENTRY;
       
  2535 
       
  2536 	if ( !iEncStateMac->IsInitialized() )
       
  2537 		{
       
  2538 		ClientFatalError( KErrNotReady );
       
  2539 		return 0;
       
  2540 		}
       
  2541 
       
  2542 	PRINT_EXIT;
       
  2543 	return ( KMPEG4H263ENCIMPL_NUM_COMPLEXITYLEVELS );
       
  2544 	}
       
  2545 
       
  2546 //---------------------------------------------------------------------------
       
  2547 // Sets the complexity level to use for video processing in a hardware device
       
  2548 //---------------------------------------------------------------------------
       
  2549 //
       
  2550 void CAriMp4spencHwDeviceImpl::SetComplexityLevel( TUint aLevel )
       
  2551 	{
       
  2552 	PRINT_ENTRY;
       
  2553 
       
  2554 	if ( !iEncStateMac->IsInitialized() )
       
  2555 		{
       
  2556 		ClientFatalError( KErrNotReady );
       
  2557 		return;
       
  2558 		}
       
  2559 
       
  2560 	if ( aLevel >= KMPEG4H263ENCIMPL_NUM_COMPLEXITYLEVELS )
       
  2561 		{
       
  2562     	PRINT_MSG( LEVEL_CRITICAL, ("CAriMp4spencHwDeviceImpl"
       
  2563     			"::SetComplexityLevel() Unsupported level Passed" ) );
       
  2564 		ClientFatalError( KErrArgument );
       
  2565 		}
       
  2566 
       
  2567 	iSetMpeg4H263HWParams.iComplexityLevel = aLevel;
       
  2568 	TMpeg4H263EncoderInitParams *currentParams = NULL;
       
  2569 	TRAPD ( error, currentParams
       
  2570 			= new ( ELeave ) TMpeg4H263EncoderInitParams );
       
  2571 
       
  2572 	*currentParams = iSetMpeg4H263HWParams;
       
  2573 
       
  2574 	// Add command apply commit settings to the codec
       
  2575 	TRAP ( error, iEngine->AddCommandL( CBaseEngine::ENormalPriority,
       
  2576 					CONTROL_CMD_SET_COMPLEXITY_LEVEL, currentParams ) );
       
  2577 
       
  2578 	if ( error != KErrNone )
       
  2579 		{
       
  2580 		delete currentParams;
       
  2581 		ClientFatalError( error );
       
  2582 		return;
       
  2583 		}
       
  2584 
       
  2585 	PRINT_EXIT;
       
  2586 	}
       
  2587 
       
  2588 //---------------------------------------------------------------------------
       
  2589 // Retrieves information about the pre-processing capabilities of this
       
  2590 // hardware device.
       
  2591 //---------------------------------------------------------------------------
       
  2592 //
       
  2593 CPreProcessorInfo* CAriMp4spencHwDeviceImpl::PreProcessorInfoLC()
       
  2594 	{
       
  2595 	PRINT_ENTRY;
       
  2596 
       
  2597 	TInt cleanupStackPushCount = 0;
       
  2598 	if ( iEncStateMac->IsInitialized() )
       
  2599 		{
       
  2600     	PRINT_ERR( "SetErrorProtectionLevelsL () called after Initialize()"
       
  2601     			"..leaving" );
       
  2602 		User::Leave( KErrPermissionDenied );
       
  2603 		}
       
  2604 	_LIT( KManufacturer, "" );
       
  2605 	_LIT( KIdentifier, "" );
       
  2606 
       
  2607 	TPtrC8 implementationSpecificInfo( NULL, 0 );
       
  2608 	RArray<TUncompressedVideoFormat> inputFormats;
       
  2609 	CleanupClosePushL( inputFormats );
       
  2610 	cleanupStackPushCount++;
       
  2611 	inputFormats.Reset();
       
  2612 
       
  2613 	RArray<TUncompressedVideoFormat> outputFormats;
       
  2614 	CleanupClosePushL( outputFormats );
       
  2615 	cleanupStackPushCount++;
       
  2616 	outputFormats.Reset();
       
  2617 
       
  2618 	RArray<TUint32> supportedCombinations;
       
  2619 	CleanupClosePushL( supportedCombinations );
       
  2620 	cleanupStackPushCount++;
       
  2621 	supportedCombinations.Reset();
       
  2622 
       
  2623 	RArray<TScaleFactor> supportedScaleFactors;
       
  2624 	CleanupClosePushL( supportedScaleFactors );
       
  2625 	cleanupStackPushCount++;
       
  2626 	supportedScaleFactors.Reset();
       
  2627 
       
  2628 	TYuvToYuvCapabilities yuvToYuvCapabilities;
       
  2629 	TUid uid;
       
  2630 	CPreProcessorInfo *preProcessorInfo = CPreProcessorInfo::NewL( uid.Null(),
       
  2631 			KManufacturer, KIdentifier, TVersion( 0, 0, 0 ), EFalse, EFalse,
       
  2632 			inputFormats.Array(), outputFormats.Array(),
       
  2633 			supportedCombinations.Array(), EFalse, EFalse,
       
  2634 			supportedScaleFactors.Array(), yuvToYuvCapabilities, 0, 0,
       
  2635 			implementationSpecificInfo );
       
  2636 
       
  2637 	CleanupStack::PushL( preProcessorInfo );
       
  2638 	CleanupStack::Pop( cleanupStackPushCount );
       
  2639 
       
  2640 	PRINT_EXIT;
       
  2641 	return preProcessorInfo;
       
  2642 	}
       
  2643 
       
  2644 //---------------------------------------------------------------------------
       
  2645 // Sets the hardware device input format
       
  2646 //---------------------------------------------------------------------------
       
  2647 //
       
  2648 
       
  2649 void CAriMp4spencHwDeviceImpl::SetInputFormatL(
       
  2650 		const TUncompressedVideoFormat& aFormat, const TSize& aPictureSize )
       
  2651 	{
       
  2652 	PRINT_ENTRY;
       
  2653 
       
  2654 	if ( iEncStateMac->IsInitialized() )
       
  2655 		{
       
  2656     	PRINT_ERR( "SetInputFormatL () called after Initialize()..leaving" );
       
  2657 		User::Leave( KErrPermissionDenied );
       
  2658 		}
       
  2659 
       
  2660 	if ( !CheckInputFormat( aFormat ) )
       
  2661 		{
       
  2662     	PRINT_ERR("CAriMp4spencHwDeviceImpl"
       
  2663     	"::SetInputFormatL() Leaving because of not support input format" );
       
  2664 		User::Leave( KErrNotSupported );
       
  2665 		}
       
  2666 
       
  2667 	TInt32 aspectRatio = ::MapAspectRatio(
       
  2668 									aFormat.iYuvFormat.iAspectRatioNum,
       
  2669 									aFormat.iYuvFormat.iAspectRatioDenom );
       
  2670 	if ( aspectRatio == -1 )
       
  2671 		{
       
  2672 		User::Leave( KErrNotSupported );
       
  2673 		}
       
  2674 
       
  2675 	iSetMpeg4H263HWParams.iAspectRatio = aspectRatio;
       
  2676 	iSetMpeg4H263HWParams.iInputFormat = aFormat;
       
  2677 	iSetMpeg4H263HWParams.iPictureSize = aPictureSize;
       
  2678 	TInt height = iSetMpeg4H263HWParams.iPictureSize.iHeight;
       
  2679 	TInt width = iSetMpeg4H263HWParams.iPictureSize.iWidth;
       
  2680 
       
  2681 	if ( height > KMPEG4H263ENCIMPL_720P_HEIGHT ||
       
  2682 			width > KMPEG4H263ENCIMPL_720P_WIDTH )
       
  2683 		{
       
  2684 		User::Leave( KErrNotSupported );
       
  2685 		}
       
  2686 	iSetMpeg4H263HWParams.iBeforeInitialize |= EEncInputFormat;
       
  2687 
       
  2688 	PRINT_EXIT;
       
  2689 	}
       
  2690 
       
  2691 //---------------------------------------------------------------------------
       
  2692 // Sets the data source to be a camera, and sets the device to use direct .
       
  2693 // capture for input
       
  2694 //---------------------------------------------------------------------------
       
  2695 //
       
  2696 
       
  2697 void CAriMp4spencHwDeviceImpl::SetSourceCameraL( TInt /*aCameraHandle*/
       
  2698 , TReal /*aPictureRate*/ )
       
  2699 	{
       
  2700 	PRINT_ENTRY;
       
  2701 
       
  2702 	if ( iEncStateMac->IsInitialized() )
       
  2703 		{
       
  2704     	PRINT_ERR( "SetSourceCameraL() called after Initialize()..leaving" );
       
  2705 		User::Leave( KErrPermissionDenied );
       
  2706 		return;
       
  2707 		}
       
  2708 	User::Leave( KErrNotSupported );
       
  2709 
       
  2710 	PRINT_EXIT;
       
  2711 	}
       
  2712 
       
  2713 //---------------------------------------------------------------------------
       
  2714 // Sets the data source to be memory buffers.
       
  2715 //---------------------------------------------------------------------------
       
  2716 //
       
  2717 
       
  2718 void CAriMp4spencHwDeviceImpl::SetSourceMemoryL( TReal aMaxPictureRate,
       
  2719 		TBool aConstantPictureRate, TBool aProcessRealtime )
       
  2720 	{
       
  2721 	PRINT_ENTRY;
       
  2722 
       
  2723 	if ( iEncStateMac->IsInitialized() )
       
  2724 		{
       
  2725 		User::Leave( KErrPermissionDenied );
       
  2726 		return;
       
  2727 		}
       
  2728 
       
  2729 	if ( ( aMaxPictureRate <= 0 ) || ( aMaxPictureRate
       
  2730 			> KMPEG4H263ENCIMPL_MAX_PICTURERATE ) )
       
  2731 		{
       
  2732     	PRINT_ERR( "Incorrect value of max picture rate..leaving" );
       
  2733 		User::Leave( KErrNotSupported );
       
  2734 		return;
       
  2735 		}
       
  2736 
       
  2737 	// Check for the picture rates supported
       
  2738     PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::SetSourceMemoryL() "
       
  2739     		"Memory Picture rate is set as %f", aMaxPictureRate ) );
       
  2740 	iSetMpeg4H263HWParams.iMaxPictureRate = aMaxPictureRate;
       
  2741 	iSetMpeg4H263HWParams.iConstantPictureRate = aConstantPictureRate;
       
  2742 	iSetMpeg4H263HWParams.iProcessRealtime = aProcessRealtime;
       
  2743 	iSetMpeg4H263HWParams.iBeforeInitialize |= EEncSourceMemory;
       
  2744 
       
  2745 	PRINT_EXIT;
       
  2746 	}
       
  2747 
       
  2748 //---------------------------------------------------------------------------
       
  2749 // Sets the clock source to use for video timing. If no clock
       
  2750 // source is set. video encoding will not be synchronized, but
       
  2751 // will proceed as fast as possible, depending on input data and
       
  2752 // output buffer availability.
       
  2753 //---------------------------------------------------------------------------
       
  2754 //
       
  2755 
       
  2756 void CAriMp4spencHwDeviceImpl::SetClockSource( MMMFClockSource* aClock )
       
  2757 	{
       
  2758 	PRINT_ENTRY;
       
  2759 
       
  2760 	if ( iEncStateMac->IsInitialized() )
       
  2761 		{
       
  2762 		ClientFatalError( KErrPermissionDenied );
       
  2763 		return;
       
  2764 		}
       
  2765 
       
  2766 	if ( !aClock )
       
  2767 		{
       
  2768 		ClientFatalError( KErrArgument );
       
  2769 		return;
       
  2770 		}
       
  2771 
       
  2772     PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::SetClockSource() "
       
  2773     		"Encoder ClockSource is %x", ( TInt ) aClock ) );
       
  2774 	iClockSource = aClock;
       
  2775 
       
  2776 	PRINT_EXIT;
       
  2777 	}
       
  2778 
       
  2779 //---------------------------------------------------------------------------
       
  2780 // Sets pre-processing options for RGB to YUV color space conversion
       
  2781 //---------------------------------------------------------------------------
       
  2782 //
       
  2783 
       
  2784 void CAriMp4spencHwDeviceImpl::SetRgbToYuvOptionsL( TRgbRange /*aRange*/,
       
  2785 		const TYuvFormat& /*aOutputFormat*/ )
       
  2786 	{
       
  2787 	PRINT_ENTRY;
       
  2788 	PRINT_EXIT;
       
  2789 	User::Leave( KErrNotSupported );
       
  2790 	}
       
  2791 
       
  2792 //----------------------------------------------------------------------------
       
  2793 // Sets pre-processing options for YUV to YUV data format conversion
       
  2794 //---------------------------------------------------------------------------
       
  2795 //
       
  2796 
       
  2797 
       
  2798 void CAriMp4spencHwDeviceImpl::SetYuvToYuvOptionsL(
       
  2799 									const TYuvFormat& /*aInputFormat*/,
       
  2800 									const TYuvFormat& /*aOutputFormat*/ )
       
  2801 	{
       
  2802 	PRINT_ENTRY;
       
  2803 	PRINT_ERR( "SetYuvToYuvOptionsL not supported...leaving \n" );
       
  2804 	PRINT_EXIT;
       
  2805 	User::Leave( KErrNotSupported );
       
  2806 	}
       
  2807 
       
  2808 //---------------------------------------------------------------------------
       
  2809 // Sets the pre-processing types to be used in a hardware device
       
  2810 //---------------------------------------------------------------------------
       
  2811 //
       
  2812 
       
  2813 void CAriMp4spencHwDeviceImpl::SetPreProcessTypesL(
       
  2814 												TUint32 /*aPreProcessTypes*/ )
       
  2815 	{
       
  2816 	PRINT_ENTRY;
       
  2817 	PRINT_ERR( "SetPreProcessTypesL not supported...leaving \n" );
       
  2818 	PRINT_EXIT;
       
  2819 	User::Leave( KErrNotSupported );
       
  2820 	}
       
  2821 
       
  2822 //---------------------------------------------------------------------------
       
  2823 // Sets pre-processing options for rotation
       
  2824 //---------------------------------------------------------------------------
       
  2825 //
       
  2826 
       
  2827 void CAriMp4spencHwDeviceImpl::SetRotateOptionsL(
       
  2828 											TRotationType /*aRotationType*/ )
       
  2829 	{
       
  2830 	PRINT_ENTRY;
       
  2831 	PRINT_ERR( "SetRotateOptionsL not supported...leaving \n" );
       
  2832 	PRINT_EXIT;
       
  2833 	User::Leave( KErrNotSupported );
       
  2834 	}
       
  2835 
       
  2836 //---------------------------------------------------------------------------
       
  2837 // Sets pre-processing options for scaling
       
  2838 //---------------------------------------------------------------------------
       
  2839 //
       
  2840 
       
  2841 void CAriMp4spencHwDeviceImpl::SetScaleOptionsL(
       
  2842 										const TSize& /*aTargetSize*/,
       
  2843 										TBool /*aAntiAliasFiltering*/ )
       
  2844 	{
       
  2845 	PRINT_ENTRY;
       
  2846 	PRINT_ERR( "SetScaleOptionsL not supported...leaving \n" );
       
  2847 	PRINT_EXIT;
       
  2848 	User::Leave( KErrNotSupported );
       
  2849 	}
       
  2850 
       
  2851 //---------------------------------------------------------------------------
       
  2852 // Sets pre-processing options for input cropping
       
  2853 //---------------------------------------------------------------------------
       
  2854 //
       
  2855 
       
  2856 void CAriMp4spencHwDeviceImpl::SetInputCropOptionsL(
       
  2857 												const TRect& /*aRect*/ )
       
  2858 	{
       
  2859 	PRINT_ENTRY;
       
  2860 	PRINT_ERR( "SetInputCropOptionsL not supported...leaving \n" );
       
  2861 	PRINT_EXIT;
       
  2862 	User::Leave( KErrNotSupported );
       
  2863 	}
       
  2864 
       
  2865 //---------------------------------------------------------------------------
       
  2866 // Sets pre-processing options for output cropping
       
  2867 //---------------------------------------------------------------------------
       
  2868 //
       
  2869 
       
  2870 void CAriMp4spencHwDeviceImpl::SetOutputCropOptionsL(
       
  2871 											const TRect& /*aRect*/)
       
  2872 	{
       
  2873 	PRINT_ENTRY;
       
  2874 	PRINT_ERR( "SetOutputCropOptionsL not supported...leaving \n" );
       
  2875 	PRINT_EXIT;
       
  2876 	User::Leave( KErrNotSupported );
       
  2877 	}
       
  2878 
       
  2879 //---------------------------------------------------------------------------
       
  2880 // Sets pre-processing options for output padding
       
  2881 //---------------------------------------------------------------------------
       
  2882 //
       
  2883 
       
  2884 void CAriMp4spencHwDeviceImpl::SetOutputPadOptionsL(
       
  2885 		const TSize& /*aOutputSize*/, const TPoint& /*aPicturePos*/ )
       
  2886 	{
       
  2887 	PRINT_ENTRY;
       
  2888 	PRINT_ERR( "SetOutputPadOptionsL not supported...leaving \n" );
       
  2889 	PRINT_EXIT;
       
  2890 	User::Leave( KErrNotSupported );
       
  2891 	}
       
  2892 
       
  2893 //---------------------------------------------------------------------------
       
  2894 // Sets color enhancement pre-processing options
       
  2895 //---------------------------------------------------------------------------
       
  2896 //
       
  2897 
       
  2898 void CAriMp4spencHwDeviceImpl::SetColorEnhancementOptionsL(
       
  2899 		const TColorEnhancementOptions& /*aOptions*/)
       
  2900 	{
       
  2901 	PRINT_ENTRY;
       
  2902 	PRINT_ERR( "SetColorEnhancementOptionsL not supported...leaving \n" );
       
  2903 	PRINT_EXIT;
       
  2904 	User::Leave( KErrNotSupported );
       
  2905 	}
       
  2906 
       
  2907 //---------------------------------------------------------------------------
       
  2908 // Sets frame stabilisation options
       
  2909 //---------------------------------------------------------------------------
       
  2910 //
       
  2911 
       
  2912 void CAriMp4spencHwDeviceImpl::SetFrameStabilisationOptionsL(
       
  2913 		const TSize& /*aOutputSize*/, TBool /*aFrameStabilisation*/ )
       
  2914 	{
       
  2915 	PRINT_ENTRY;
       
  2916 	PRINT_ERR( "SetFrameStabilisationOptionsL not supported...leaving \n" );
       
  2917 	PRINT_EXIT;
       
  2918 	User::Leave( KErrNotSupported );
       
  2919 	}
       
  2920 
       
  2921 //---------------------------------------------------------------------------
       
  2922 // Sets custom implementation-specific pre-processing options.
       
  2923 //---------------------------------------------------------------------------
       
  2924 //
       
  2925 //---------------------------------------------------------------------------
       
  2926 //
       
  2927 
       
  2928 void CAriMp4spencHwDeviceImpl::SetCustomPreProcessOptionsL(
       
  2929 												const TDesC8& /*aOptions*/)
       
  2930 	{
       
  2931 	PRINT_ENTRY;
       
  2932 	PRINT_ERR( "SetCustomPreProcessOptionsL not supported...leaving \n" );
       
  2933 	PRINT_EXIT;
       
  2934 	User::Leave( KErrNotSupported );
       
  2935 	}
       
  2936 
       
  2937 //---------------------------------------------------------------------------
       
  2938 //  Proxy which recieves callbacks from Hw Device
       
  2939 //---------------------------------------------------------------------------
       
  2940 //
       
  2941 
       
  2942 void CAriMp4spencHwDeviceImpl::SetProxy( MMMFDevVideoRecordProxy& aProxy )
       
  2943 	{
       
  2944 	PRINT_ENTRY;
       
  2945 
       
  2946 	if ( iEncStateMac->IsInitialized() 	)
       
  2947 		{
       
  2948 		ClientFatalError( KErrPermissionDenied );
       
  2949 		return;
       
  2950 		}
       
  2951 	iMMFDevVideoRecordProxy = &aProxy;
       
  2952 
       
  2953 	PRINT_EXIT;
       
  2954 	}
       
  2955 
       
  2956 //---------------------------------------------------------------------------
       
  2957 // Callback to indicate the input buffer is consumed
       
  2958 //---------------------------------------------------------------------------
       
  2959 //
       
  2960 
       
  2961 TInt CAriMp4spencHwDeviceImpl::InputBufferConsumed( TAny* aInp,
       
  2962 														TInt aError )
       
  2963 	{
       
  2964 	PRINT_ENTRY;
       
  2965 
       
  2966 	if ( !aInp )
       
  2967 		{
       
  2968 		return KErrArgument;
       
  2969 		}
       
  2970 
       
  2971 	TVideoPicture *picture = (TVideoPicture *) aInp;
       
  2972 	if ( ( picture->iOptions & TVideoPicture::ETimestamp ) && aError
       
  2973 			!= ( KErrCancel ) )
       
  2974 		{
       
  2975 		iLastEncodedPictureTimestamp = picture->iTimestamp.Int64();
       
  2976 		}
       
  2977 
       
  2978 	// if custom buffer emabled then add it to queue else return the picture
       
  2979 	// to client
       
  2980 	if ( !iInputBufReturnToPreProc )
       
  2981 		{
       
  2982 		PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl"
       
  2983 		"::InputBufferConsumed()-return picture back to client" ) );
       
  2984 
       
  2985 		iMMFDevVideoRecordProxy->MdvrpReturnPicture( picture );
       
  2986 		}
       
  2987 	else
       
  2988 		{
       
  2989 		PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl"
       
  2990 		"::InputBufferConsumed()-return picture back to Input Device" ) );
       
  2991 		iInputDevice->ReturnPicture( picture );
       
  2992 		}
       
  2993 
       
  2994 	if ( iInputEndCalled && ( iEngine->NumInputBuffers() == 0 )
       
  2995 			&& ( iCodec->IsCurrentPictureSkipped() ) )
       
  2996 		{
       
  2997     	PRINT_MSG( LEVEL_HIGH, ("CAriMp4spencHwDeviceImpl"
       
  2998     			"::InputBufferConsumed()::Calling stream end " ) );
       
  2999 
       
  3000 		Stop();
       
  3001 		iMMFDevVideoRecordProxy->MdvrpStreamEnd();
       
  3002 		return ( KErrNone );
       
  3003 		}
       
  3004 
       
  3005 	PRINT_EXIT;
       
  3006 	return KErrNone;
       
  3007 	}
       
  3008 
       
  3009 //---------------------------------------------------------------------------
       
  3010 // Callback to indicate the output buffer is ready
       
  3011 //---------------------------------------------------------------------------
       
  3012 //
       
  3013 
       
  3014 TInt CAriMp4spencHwDeviceImpl::OutputBufferReady( TAny* aOup, TInt aError )
       
  3015 	{
       
  3016 	PRINT_ENTRY;
       
  3017 
       
  3018 	TVideoOutputBuffer *outputBuf = ( TVideoOutputBuffer* ) aOup;
       
  3019 	TInt error = KErrNone;
       
  3020 	if ( iFrozen )
       
  3021 		{
       
  3022 		PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::OutputBufferReady()"
       
  3023 				"Frozen state, so drop output picture" ) );
       
  3024 
       
  3025 		outputBuf->iData.Set( ( TUint8* ) outputBuf->iData.Ptr(),
       
  3026 				iOutputBufferSize );
       
  3027 
       
  3028 		iEngine->AddOutput( outputBuf );
       
  3029 		return KErrNone;
       
  3030 		}
       
  3031 
       
  3032 	if ( aError == KErrNone )
       
  3033 		{
       
  3034 		if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  3035 			{
       
  3036 			error = iInternalOutputBufferQueue.Append( outputBuf );
       
  3037 			if ( error != KErrNone )
       
  3038 				{
       
  3039 				ClientFatalError( error );
       
  3040 				return KErrNone;
       
  3041 				}
       
  3042 
       
  3043 			// get the packet offset infor
       
  3044 			TUint* ptr = iFreeBufferQueueForPacketOffsetInfo[0];
       
  3045 			iPacketOffsetBuf->Set( ( TUint8* ) ptr, iMaxNumOfPackets
       
  3046 				* KDoubleWordLength, iMaxNumOfPackets * KDoubleWordLength);
       
  3047 
       
  3048 			error = iCodec->GetParam( CONTROL_CMD_GET_PACKETBOUNDARYDATA,
       
  3049 					iPacketOffsetBuf );
       
  3050 			if ( error != KErrNone )
       
  3051 				{
       
  3052 				ClientFatalError( error );
       
  3053 				return KErrNone;
       
  3054 				}
       
  3055 
       
  3056 			//remove the first element and add it to filled Queue
       
  3057 			TUint* filledOffsetLengthInfoBuffer =
       
  3058 					iFreeBufferQueueForPacketOffsetInfo[0];
       
  3059 			iFreeBufferQueueForPacketOffsetInfo.Remove( 0 );
       
  3060 			error = iFilledBufferQueueForPacketOffsetInfo.Append(
       
  3061 					filledOffsetLengthInfoBuffer );
       
  3062 			if ( error != KErrNone )
       
  3063 				{
       
  3064 				ClientFatalError( error );
       
  3065 				return KErrNone;
       
  3066 				}
       
  3067 
       
  3068 			if ( !iTotalLengthFilledSoFarInPacketMode )
       
  3069 				{
       
  3070 				iTotalOutputBufferLengthInPacketMode
       
  3071 						= iInternalOutputBufferQueue[0]->iData.Length();
       
  3072 				if ( iTotalOutputBufferLengthInPacketMode != 0 )
       
  3073 					{
       
  3074 					iPacketOffSetCurrentPosition
       
  3075 							= iFilledBufferQueueForPacketOffsetInfo[0];
       
  3076 
       
  3077 					iPacketsPending = ETrue;
       
  3078 					while ( iOutputFreeBufferQueue.Count()
       
  3079 							&& iPacketsPending )
       
  3080 						{
       
  3081 						TVideoOutputBuffer *outBuf
       
  3082 							= iOutputFreeBufferQueue[0];
       
  3083 
       
  3084 						FillVideoSegment( outBuf,
       
  3085 								iInternalOutputBufferQueue[0] );
       
  3086 
       
  3087 						iOutputFreeBufferQueue.Remove( 0 );
       
  3088 						iMMFDevVideoRecordProxy->MdvrpNewBuffer( outBuf );
       
  3089 						}
       
  3090 					}
       
  3091 				else
       
  3092 					{
       
  3093 					iPacketsPending = EFalse;
       
  3094 
       
  3095 					// remove packet offset info buffer from filled Q and
       
  3096 					// add it to free Q
       
  3097 					TUint* freeOffsetLengthInfoBuffer =
       
  3098 							iFilledBufferQueueForPacketOffsetInfo[0];
       
  3099 					iFilledBufferQueueForPacketOffsetInfo.Remove( 0 );
       
  3100 
       
  3101 					TInt error = iFreeBufferQueueForPacketOffsetInfo .Append(
       
  3102 							freeOffsetLengthInfoBuffer );
       
  3103 
       
  3104 					if ( error != KErrNone )
       
  3105 						{
       
  3106 						ClientFatalError( error );
       
  3107 						return KErrNone;
       
  3108 						}
       
  3109 
       
  3110 					// Remove the internal buffer and add it back to process
       
  3111 					// engine
       
  3112 					if ( iInternalOutputBufferQueue.Count() )
       
  3113 						{
       
  3114 						TVideoOutputBuffer* outBuf =
       
  3115 								iInternalOutputBufferQueue[0];
       
  3116 						iInternalOutputBufferQueue.Remove( 0 );
       
  3117 
       
  3118 						outBuf->iData.Set( ( TUint8* )outBuf->iData.Ptr(),
       
  3119 								iOutputBufferSize );
       
  3120 
       
  3121 						//  Add the Buffer back to the Process Engine
       
  3122 						if ( ( !iEncStateMac->IsInputEndPending() )
       
  3123 								&& ( !iEncStateMac->IsStopped() ) )
       
  3124 							{
       
  3125 							iEngine->AddOutput( ( TAny* )outBuf );
       
  3126 							}
       
  3127 						}
       
  3128 					}
       
  3129 				}
       
  3130 			}
       
  3131 		else
       
  3132 			{
       
  3133 			// inform devvideo record that the new encoded buffer is avaibable
       
  3134 			iMMFDevVideoRecordProxy->MdvrpNewBuffer( outputBuf );
       
  3135 			}
       
  3136 		}
       
  3137 
       
  3138 	else if ( aError == KErrCancel )
       
  3139 		{
       
  3140 		// add the buffer back  to outputQueue
       
  3141 		outputBuf->iData.Set( ( TUint8* )outputBuf->iData.Ptr(),
       
  3142 				iOutputBufferSize );
       
  3143 
       
  3144 		if ( iSetMpeg4H263HWParams.iDataUnitType == EDuVideoSegment )
       
  3145 			{
       
  3146 			error = iInternalOutputBufferQueue.Append( outputBuf );
       
  3147 			if ( error != KErrNone )
       
  3148 				{
       
  3149 				ClientFatalError( error );
       
  3150 				return KErrNone;
       
  3151 				}
       
  3152 			}
       
  3153 		else
       
  3154 			{
       
  3155 			error = iOutputFreeBufferQueue.Append( outputBuf );
       
  3156 			if ( error != KErrNone )
       
  3157 				{
       
  3158 				ClientFatalError( error );
       
  3159 				return KErrNone;
       
  3160 				}
       
  3161 			}
       
  3162 
       
  3163 		if ( error != KErrNone )
       
  3164 			{
       
  3165 			ClientFatalError( error );
       
  3166 			return KErrNone;
       
  3167 			}
       
  3168 		}
       
  3169 	else
       
  3170 		{
       
  3171 		ClientFatalError( aError );
       
  3172 		return KErrNone;
       
  3173 		}
       
  3174 
       
  3175 	if ( iInputEndCalled && ( iEngine->NumInputBuffers() == 0 ) )
       
  3176 		{
       
  3177     	PRINT_MSG( LEVEL_HIGH, ("CAriMp4spencHwDeviceImpl"
       
  3178     			"::OutputBufferReady()::Calling stream end " ) );
       
  3179 		Stop();
       
  3180 		iMMFDevVideoRecordProxy->MdvrpStreamEnd();
       
  3181 		return ( KErrNone );
       
  3182 		}
       
  3183 
       
  3184 	PRINT_EXIT;
       
  3185 	return KErrNone;
       
  3186 	}
       
  3187 
       
  3188 //---------------------------------------------------------------------------
       
  3189 // Callback to indicate the command has been processed
       
  3190 //---------------------------------------------------------------------------
       
  3191 //
       
  3192 
       
  3193 void CAriMp4spencHwDeviceImpl::CommandProcessed( TInt aCmd, TAny* aCmdData,
       
  3194 													TInt aError )
       
  3195 	{
       
  3196 	PRINT_ENTRY;
       
  3197 
       
  3198 	switch ( aCmd )
       
  3199 		{
       
  3200 		case CONTROL_CMD_SET_RATE_CONTROL_OPTIONS:
       
  3201 			{
       
  3202 			TRateControlOptions *options = ( TRateControlOptions* ) aCmdData;
       
  3203 			delete options;
       
  3204 			}
       
  3205 			break;
       
  3206 
       
  3207 		case CONTROL_CMD_SET_FORCED_I_FRAME:
       
  3208 			{
       
  3209 			}
       
  3210 			break;
       
  3211 
       
  3212 		case CONTROL_CMD_SET_COMMIT_OPTIONS:
       
  3213 			{
       
  3214 			TMpeg4H263EncoderInitParams *currentParams =
       
  3215 					( TMpeg4H263EncoderInitParams* ) aCmdData;
       
  3216 
       
  3217 			if ( ( aError != KErrNone ) || ( aError != KErrCancel ) )
       
  3218 				{
       
  3219 				delete currentParams;
       
  3220 				return;
       
  3221 				}
       
  3222 			else
       
  3223 				{
       
  3224 				iSetMpeg4H263HWParams.iBitErrors = currentParams->iBitErrors;
       
  3225 				iSetMpeg4H263HWParams.iPacketLosses
       
  3226 						= currentParams->iPacketLosses;
       
  3227 				iSetMpeg4H263HWParams.iRandomAccessRate
       
  3228 						= currentParams->iRandomAccessRate;
       
  3229 				delete currentParams;
       
  3230 				}
       
  3231 			}
       
  3232 			break;
       
  3233 
       
  3234 		case CONTROL_CMD_SET_COMPLEXITY_LEVEL:
       
  3235 			{
       
  3236 			TMpeg4H263EncoderInitParams *currentParams =
       
  3237 					( TMpeg4H263EncoderInitParams* ) aCmdData;
       
  3238 			delete currentParams;
       
  3239 			}
       
  3240 			break;
       
  3241 
       
  3242 		case CONTROL_CMD_SET_CHANNEL_BIT_ERROR_RATE:
       
  3243 			{
       
  3244 			TReal* currentParams = ( TReal* ) aCmdData;
       
  3245 			delete currentParams;
       
  3246 			}
       
  3247 			break;
       
  3248 
       
  3249 		case CONTROL_CMD_SET_SLICELOSS:
       
  3250 			{
       
  3251 			TMPEG4H263EncSliceLoss* currentParams =
       
  3252 					( TMPEG4H263EncSliceLoss* ) aCmdData;
       
  3253 			delete currentParams;
       
  3254 			}
       
  3255 			break;
       
  3256 
       
  3257 		default:
       
  3258 			break;
       
  3259 		}
       
  3260 	PRINT_EXIT;
       
  3261 
       
  3262 	return;
       
  3263 	}
       
  3264 
       
  3265 //----------------------------------------------------------------------------
       
  3266 // Called when a fatal error occurs in process engine
       
  3267 //----------------------------------------------------------------------------
       
  3268 //
       
  3269 
       
  3270 void CAriMp4spencHwDeviceImpl::FatalErrorFromProcessEngine( TInt aError )
       
  3271 	{
       
  3272 	PRINT_ENTRY;
       
  3273 	ClientFatalError( aError );
       
  3274     PRINT_EXIT;
       
  3275 	}
       
  3276 
       
  3277 //---------------------------------------------------------------------------
       
  3278 //  2 phase constructor
       
  3279 //---------------------------------------------------------------------------
       
  3280 //
       
  3281 
       
  3282 void CAriMp4spencHwDeviceImpl::ConstructL()
       
  3283 	{
       
  3284 	PRINT_ENTRY;
       
  3285 
       
  3286 	TInt index = 0;
       
  3287 	TInt error = KErrNone;
       
  3288 
       
  3289 	// Create Array of Supported Input Formats
       
  3290 	TUncompressedVideoFormat inputFormat;
       
  3291 	inputFormat.iDataFormat = EYuvRawData;
       
  3292 	inputFormat.iYuvFormat.iCoefficients = EYuvBt709Range0;
       
  3293 	inputFormat.iYuvFormat.iPattern = EYuv420Chroma1;
       
  3294 	inputFormat.iYuvFormat.iDataLayout = EYuvDataPlanar;
       
  3295 	inputFormat.iYuvFormat.iYuv2RgbMatrix = NULL;
       
  3296 	inputFormat.iYuvFormat.iRgb2YuvMatrix = NULL;
       
  3297 	inputFormat.iYuvFormat.iAspectRatioNum = 1;
       
  3298 	inputFormat.iYuvFormat.iAspectRatioDenom = 1;
       
  3299 
       
  3300 	error = iSupportedInputFormats.Append( inputFormat );
       
  3301 	if ( error != KErrNone )
       
  3302 		{
       
  3303 		User::Leave( error );
       
  3304 		}
       
  3305 
       
  3306 	inputFormat.iYuvFormat.iCoefficients = EYuvBt601Range0;
       
  3307 	error = iSupportedInputFormats.Append( inputFormat );
       
  3308 	if ( error != KErrNone )
       
  3309 		{
       
  3310 		User::Leave( error );
       
  3311 		}
       
  3312 
       
  3313 	inputFormat.iYuvFormat.iPattern = EYuv420Chroma2;
       
  3314 	error = iSupportedInputFormats.Append( inputFormat );
       
  3315 	if ( error != KErrNone )
       
  3316 		{
       
  3317 		User::Leave( error );
       
  3318 		}
       
  3319 
       
  3320 	inputFormat.iYuvFormat.iCoefficients = EYuvBt709Range0;
       
  3321 	error = iSupportedInputFormats.Append( inputFormat );
       
  3322 	if ( error != KErrNone )
       
  3323 		{
       
  3324 		User::Leave( error );
       
  3325 		}
       
  3326 
       
  3327 	inputFormat.iYuvFormat.iCoefficients = EYuvBt709Range1;
       
  3328 	error = iSupportedInputFormats.Append( inputFormat );
       
  3329 	if ( error != KErrNone )
       
  3330 		{
       
  3331 		User::Leave( error );
       
  3332 		}
       
  3333 
       
  3334 	inputFormat.iYuvFormat.iCoefficients = EYuvBt601Range1;
       
  3335 	error = iSupportedInputFormats.Append( inputFormat );
       
  3336 	if ( error != KErrNone )
       
  3337 		{
       
  3338 		User::Leave( error );
       
  3339 		}
       
  3340 
       
  3341 	// Create Array of Supported Output Formats
       
  3342 	CCompressedVideoFormat* compressedVideoFormat[18];
       
  3343 
       
  3344 	//Adding mime types for all supported MPEG4 levels.
       
  3345 	compressedVideoFormat[index]
       
  3346 	                       = CCompressedVideoFormat::NewL( KMPEG4MimeType );
       
  3347 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3348 	index++;
       
  3349 	error = iLevels.Append( KMPEG4_LEVEL_UNKNOWN );
       
  3350 	if ( error != KErrNone )
       
  3351 		{
       
  3352 		User::Leave( error );
       
  3353 		}
       
  3354 
       
  3355 	compressedVideoFormat[index]
       
  3356 	                       = CCompressedVideoFormat::NewL( KMPEG4VTMimeType );
       
  3357 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3358 	index++;
       
  3359 
       
  3360 	error = iLevels.Append( KMPEG4_LEVEL_UNKNOWN );
       
  3361 	if ( error != KErrNone )
       
  3362 		{
       
  3363 		User::Leave( error );
       
  3364 		}
       
  3365 
       
  3366 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3367 			KMPEG4MimeTypeLevel0  );
       
  3368 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3369 	index++;
       
  3370 
       
  3371 	error = iLevels.Append( KMPEG4_LEVEL_0 );
       
  3372 	if ( error != KErrNone )
       
  3373 		{
       
  3374 		User::Leave( error );
       
  3375 		}
       
  3376 
       
  3377 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3378 			KMPEG4MimeTypeLevel0B );
       
  3379 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3380 	index++;
       
  3381 
       
  3382 	error = iLevels.Append( KMPEG4_LEVEL_0B );
       
  3383 	if ( error != KErrNone )
       
  3384 		{
       
  3385 		User::Leave( error );
       
  3386 		}
       
  3387 
       
  3388 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3389 			KMPEG4MimeTypeLevel1 );
       
  3390 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3391 	index++;
       
  3392 
       
  3393 	error = iLevels.Append( KMPEG4_LEVEL_1 );
       
  3394 	if ( error != KErrNone )
       
  3395 		{
       
  3396 		User::Leave( error );
       
  3397 		}
       
  3398 
       
  3399 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3400 			KMPEG4MimeTypeLevel2 );
       
  3401 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3402 	index++;
       
  3403 
       
  3404 	error = iLevels.Append( KMPEG4_LEVEL_2 );
       
  3405 	if ( error != KErrNone )
       
  3406 		{
       
  3407 		User::Leave( error );
       
  3408 		}
       
  3409 
       
  3410 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3411 			KMPEG4MimeTypeLevel3 );
       
  3412 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3413 	index++;
       
  3414 
       
  3415 	error = iLevels.Append( KMPEG4_LEVEL_3 );
       
  3416 	if ( error != KErrNone )
       
  3417 		{
       
  3418 		User::Leave( error );
       
  3419 		}
       
  3420 
       
  3421 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3422 			KMPEG4MimeTypeLevel4 );
       
  3423 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3424 	index++;
       
  3425 
       
  3426 	error = iLevels.Append( KMPEG4_LEVEL_4 );
       
  3427 	if ( error != KErrNone )
       
  3428 		{
       
  3429 		User::Leave( error );
       
  3430 		}
       
  3431 
       
  3432 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3433 			KMPEG4MimeTypeLevel5 );
       
  3434 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3435 	index++;
       
  3436 
       
  3437 	error = iLevels.Append( KMPEG4_LEVEL_5 );
       
  3438 	if ( error != KErrNone )
       
  3439 		{
       
  3440 		User::Leave( error );
       
  3441 		}
       
  3442 
       
  3443 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3444 			KMPEG4MimeTypeLevel6 );
       
  3445 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3446 	index++;
       
  3447 
       
  3448 	error = iLevels.Append( KMPEG4_LEVEL_6 );
       
  3449 	if ( error != KErrNone )
       
  3450 		{
       
  3451 		User::Leave( error );
       
  3452 		}
       
  3453 
       
  3454 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3455 			KMPEG4MimeTypeLevel7 );
       
  3456 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3457 	index++;
       
  3458 
       
  3459 	error = iLevels.Append( KMPEG4_LEVEL_7 );
       
  3460 	if ( error != KErrNone )
       
  3461 		{
       
  3462 		User::Leave( error );
       
  3463 		}
       
  3464 
       
  3465 	//Adding mime types for all supported H263 levels.
       
  3466 	compressedVideoFormat[index]
       
  3467 	                       = CCompressedVideoFormat::NewL( KH263MimeType );
       
  3468 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3469 	index++;
       
  3470 
       
  3471 	error = iLevels.Append( KH263_LEVEL_UNKNOWN );
       
  3472 	if ( error != KErrNone )
       
  3473 		{
       
  3474 		User::Leave( error );
       
  3475 		}
       
  3476 
       
  3477 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3478 			KH263MimeTypeProfile0 );
       
  3479 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3480 	index++;
       
  3481 
       
  3482 	error = iLevels.Append( KMPEG4_LEVEL_7 );
       
  3483 	if ( error != KErrNone )
       
  3484 		{
       
  3485 		User::Leave( error );
       
  3486 		}
       
  3487 
       
  3488 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3489 			KH263MimeTypeLevel10 );
       
  3490 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3491 	index++;
       
  3492 
       
  3493 	error = iLevels.Append( KH263_LEVEL_10 );
       
  3494 	if ( error != KErrNone )
       
  3495 		{
       
  3496 		User::Leave( error );
       
  3497 		}
       
  3498 
       
  3499 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3500 			KH263MimeTypeLevel20 );
       
  3501 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3502 	index++;
       
  3503 
       
  3504 	error = iLevels.Append( KH263_LEVEL_20 );
       
  3505 	if ( error != KErrNone )
       
  3506 		{
       
  3507 		User::Leave( error );
       
  3508 		}
       
  3509 
       
  3510 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3511 			KH263MimeTypeLevel30 );
       
  3512 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3513 	index++;
       
  3514 
       
  3515 	error = iLevels.Append( KH263_LEVEL_30 );
       
  3516 	if ( error != KErrNone )
       
  3517 		{
       
  3518 		User::Leave( error );
       
  3519 		}
       
  3520 
       
  3521 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3522 			KH263MimeTypeLevel40 );
       
  3523 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3524 	index++;
       
  3525 
       
  3526 	error = iLevels.Append( KH263_LEVEL_40 );
       
  3527 	if ( error != KErrNone )
       
  3528 		{
       
  3529 		User::Leave( error );
       
  3530 		}
       
  3531 
       
  3532 	compressedVideoFormat[index] = CCompressedVideoFormat::NewL(
       
  3533 			KH263MimeTypeLevel45 );
       
  3534 	CleanupStack::PushL( compressedVideoFormat[index] );
       
  3535 	index++;
       
  3536 
       
  3537 	error = iLevels.Append( KH263_LEVEL_45 );
       
  3538 	if ( error != KErrNone )
       
  3539 		{
       
  3540 		User::Leave( error );
       
  3541 		}
       
  3542 
       
  3543 	//Append all the formats to the array
       
  3544 	for ( TInt i = 0; i < index; i++ )
       
  3545 		{
       
  3546 		error = iSupportedOutputFormats.Append( compressedVideoFormat[i] );
       
  3547 		if ( error != KErrNone )
       
  3548 			{
       
  3549 			User::Leave( error );
       
  3550 			}
       
  3551 		}
       
  3552 
       
  3553 	iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityIdle );
       
  3554 	iOutputFreeBufferQueue.Reset();
       
  3555 	iInternalOutputBufferQueue.Reset();
       
  3556 	iEncStateMac = CStateMachine::NewL();
       
  3557 
       
  3558 	// pop all the pushed items from cleanup stack.
       
  3559 	CleanupStack::Pop( index );
       
  3560 
       
  3561 	PRINT_EXIT;
       
  3562 	}
       
  3563 
       
  3564 //---------------------------------------------------------------------------
       
  3565 // Sends the updated time to the codec
       
  3566 //---------------------------------------------------------------------------
       
  3567 //
       
  3568 
       
  3569 TInt CAriMp4spencHwDeviceImpl::UpdateTime()
       
  3570 	{
       
  3571 	PRINT_ENTRY;
       
  3572 
       
  3573 	if ( !iClockSource )
       
  3574 		{
       
  3575 		ClientFatalError( KErrBadHandle  );
       
  3576 		return -1;
       
  3577 		}
       
  3578 	// send the time values to the codec
       
  3579 	iCodec->SetUpdatedRefernceTime( iTotalTime );
       
  3580 
       
  3581 	PRINT_EXIT;
       
  3582 	return 1;
       
  3583 	}
       
  3584 
       
  3585 //---------------------------------------------------------------------------
       
  3586 // Create the output buffers in Coded picture mode
       
  3587 //---------------------------------------------------------------------------
       
  3588 //
       
  3589 
       
  3590 void CAriMp4spencHwDeviceImpl::CreateCodedOutputBuffersL( TUint aSize )
       
  3591 	{
       
  3592 	PRINT_ENTRY;
       
  3593 
       
  3594 	if ( iSetMpeg4H263HWParams.iDataUnitType != EDuVideoSegment )
       
  3595 		{
       
  3596 		iOutputBufferSize = aSize;
       
  3597 		}
       
  3598 
       
  3599 	// Allocate memory for TVideoOutputBuffer
       
  3600 	iOutputBuffers
       
  3601 	= new ( ELeave ) TVideoOutputBuffer[
       
  3602 	                             iSetMpeg4H263HWParams.iMinNumOutputBuffers];
       
  3603 
       
  3604 	for ( TInt i = 0; i < iSetMpeg4H263HWParams.iMinNumOutputBuffers; i++ )
       
  3605 		{
       
  3606 		iOutputBuffers[i].iData.Set( NULL, 0 );
       
  3607 		}
       
  3608 
       
  3609 	// Create the Buffer and add it to Queue
       
  3610 	for ( TInt i = 0; i < iSetMpeg4H263HWParams.iMinNumOutputBuffers; i++ )
       
  3611 		{
       
  3612 		TUint8* ptr = new ( ELeave ) TUint8[aSize];
       
  3613 		CleanupStack::PushL( ptr );
       
  3614 		iOutputBuffers[i].iData.Set( ptr, aSize );
       
  3615 		CleanupStack::Pop();
       
  3616 		InitializeOuputCodedBuffer( iOutputBuffers[i] );
       
  3617 		TInt error = iOutputFreeBufferQueue.Append( iOutputBuffers + i );
       
  3618 		if ( error != KErrNone )
       
  3619 			{
       
  3620 			User::Leave( error );
       
  3621 			return;
       
  3622 			}
       
  3623 		}
       
  3624 
       
  3625 	PRINT_EXIT;
       
  3626 	}
       
  3627 
       
  3628 //---------------------------------------------------------------------------
       
  3629 // Creates the temporary output buffers
       
  3630 //---------------------------------------------------------------------------
       
  3631 //
       
  3632 void CAriMp4spencHwDeviceImpl::CreateInternalOutputBuffersL(
       
  3633 														TUint aBufferSize )
       
  3634 	{
       
  3635 	PRINT_ENTRY;
       
  3636 
       
  3637 	iOutputBufferSize = aBufferSize;
       
  3638 
       
  3639 	// Allocate memory for TVideoOutputBuffer
       
  3640 	iInternalOutputBuffers
       
  3641 			= new ( ELeave ) TVideoOutputBuffer
       
  3642 					[KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS];
       
  3643 
       
  3644 	for ( TInt i = 0; i < KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ )
       
  3645 		{
       
  3646 		iInternalOutputBuffers[i].iData.Set( NULL, 0 );
       
  3647 		}
       
  3648 
       
  3649 	// Create the Buffer and add it to Queue
       
  3650 	for ( TInt i = 0; i < KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ )
       
  3651 		{
       
  3652 		TUint8* ptr = new ( ELeave ) TUint8[aBufferSize];
       
  3653 		CleanupStack::PushL( ptr );
       
  3654 		iInternalOutputBuffers[i].iData.Set( ptr, aBufferSize );
       
  3655 		CleanupStack::Pop();
       
  3656 		InitializeOuputCodedBuffer( iInternalOutputBuffers[i] );
       
  3657 		TInt error = iInternalOutputBufferQueue.Append(
       
  3658 				iInternalOutputBuffers + i );
       
  3659 
       
  3660 		if ( error != KErrNone )
       
  3661 			{
       
  3662 			ClientFatalError( error );
       
  3663 			return;
       
  3664 			}
       
  3665 		}
       
  3666 
       
  3667 	PRINT_EXIT;
       
  3668 	}
       
  3669 
       
  3670 //---------------------------------------------------------------------------
       
  3671 // Creates the buffers required to store length and offset
       
  3672 // info of packets
       
  3673 //---------------------------------------------------------------------------
       
  3674 //
       
  3675 
       
  3676 
       
  3677 void CAriMp4spencHwDeviceImpl::CreatePacketOffsetLengthInfoBuffersL(
       
  3678 		TUint aNumOfPackets )
       
  3679 	{
       
  3680 	PRINT_ENTRY;
       
  3681 	iPacketOffSetAndLengthInfoBuffers
       
  3682 		= new ( ELeave ) (TUint*[KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS]);
       
  3683 
       
  3684 	for ( TInt i = 0; i < KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ )
       
  3685 		{
       
  3686 		iPacketOffSetAndLengthInfoBuffers[i] = NULL;
       
  3687 		}
       
  3688 
       
  3689 	for ( TInt i = 0; i < KMPEG4H263ENCIMPL_MAXNUM_TEMPOUTPUTBUFFERS; i++ )
       
  3690 		{
       
  3691 		iPacketOffSetAndLengthInfoBuffers[i]
       
  3692 				= ( TUint* ) ( new ( ELeave ) TUint8[aNumOfPackets] );
       
  3693 		TInt error = iFreeBufferQueueForPacketOffsetInfo.Append(
       
  3694 				iPacketOffSetAndLengthInfoBuffers[i] );
       
  3695 		if ( error != KErrNone )
       
  3696 			{
       
  3697 			User::Leave( error );
       
  3698 			}
       
  3699 		}
       
  3700 
       
  3701 	PRINT_EXIT;
       
  3702 	}
       
  3703 
       
  3704 //---------------------------------------------------------------------------
       
  3705 // decides whether picture can be encoded or not
       
  3706 //---------------------------------------------------------------------------
       
  3707 //
       
  3708 
       
  3709 TBool CAriMp4spencHwDeviceImpl::CanEncode( TVideoPicture *aPicture )
       
  3710 	{
       
  3711 	PRINT_ENTRY;
       
  3712 
       
  3713 	// check with the lastly encoded picture  and decide whether it can be
       
  3714 	//	processed or skipped
       
  3715 	if ( aPicture->iTimestamp.Int64() < iLastEncodedPictureTimestamp )
       
  3716 		{
       
  3717 		return EFalse;
       
  3718 		}
       
  3719 
       
  3720 	// check with current clock
       
  3721 	if ( ( aPicture->iTimestamp.Int64() ) < ( ( iClockSource->Time().Int64()
       
  3722 			- iTotalTime ) ) )
       
  3723 		{
       
  3724 		return EFalse;
       
  3725 		}
       
  3726 
       
  3727 	PRINT_EXIT;
       
  3728 	return ETrue;
       
  3729 	}
       
  3730 
       
  3731 //---------------------------------------------------------------------------
       
  3732 //  Skips the Input Picture
       
  3733 //---------------------------------------------------------------------------
       
  3734 //
       
  3735 
       
  3736 void CAriMp4spencHwDeviceImpl::SkipInputPicture( TVideoPicture *aPicture )
       
  3737 	{
       
  3738 	PRINT_ENTRY;
       
  3739 
       
  3740 	// add the buffer back to queue
       
  3741 	if ( !iInputBufReturnToPreProc )
       
  3742 		{
       
  3743 		PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::SkipInputPicture()"
       
  3744 				"-return picture back to client" ) );
       
  3745 		iMMFDevVideoRecordProxy->MdvrpReturnPicture( aPicture );
       
  3746 		}
       
  3747 	else
       
  3748 		{
       
  3749 		PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::SkipInputPicture()-"
       
  3750 				"return picture back to Input Device" ) );
       
  3751 		iInputDevice->ReturnPicture( aPicture );
       
  3752 		}
       
  3753 
       
  3754 	if ( !iFrozen )
       
  3755 		{
       
  3756 		iPictureCounters.iPicturesSkippedRateControl++;
       
  3757 		}
       
  3758 
       
  3759 	PRINT_EXIT;
       
  3760 	}
       
  3761 
       
  3762 //---------------------------------------------------------------------------
       
  3763 // Indicates whether the next frame is to be encoded as an I frame
       
  3764 //---------------------------------------------------------------------------
       
  3765 //
       
  3766 TBool CAriMp4spencHwDeviceImpl::IsForcedIFrameRequired(
       
  3767 		TVideoPicture* aPicture )
       
  3768 	{
       
  3769 	PRINT_ENTRY;
       
  3770 
       
  3771 	if ( ( aPicture->iOptions & TVideoPicture::EReqInstantRefresh )
       
  3772 			|| iPictureLoss )
       
  3773 		{
       
  3774 		PRINT_MSG( LEVEL_HIGH, ("CAriMp4spencHwDeviceImpl"
       
  3775 				"::IsForcedIFrameRequired() ETrue 1--" ) );
       
  3776 		return ETrue;
       
  3777 		}
       
  3778 
       
  3779 	PRINT_EXIT;
       
  3780 	return EFalse;
       
  3781 	}
       
  3782 
       
  3783 //---------------------------------------------------------------------------
       
  3784 //  Extracts 1 packet from a frame and fills output buffer with the same
       
  3785 //---------------------------------------------------------------------------
       
  3786 //
       
  3787 void CAriMp4spencHwDeviceImpl::FillVideoSegment(
       
  3788 		TVideoOutputBuffer* aOutputBuf, TVideoOutputBuffer* aSrcOutputBuf )
       
  3789 	{
       
  3790 	PRINT_ENTRY;
       
  3791 
       
  3792 	TUint currentPacketLength = *( iPacketOffSetCurrentPosition );
       
  3793 	PRINT_MSG( LEVEL_LOW, ("CAriMp4spencHwDeviceImpl::FillVideoSegment()"
       
  3794 				" currentPacketLength is %d", ( TInt )currentPacketLength ) );
       
  3795 
       
  3796 	if ( iTotalLengthFilledSoFarInPacketMode
       
  3797 			< iTotalOutputBufferLengthInPacketMode )
       
  3798 		{
       
  3799 		Mem::Copy( ( TUint8* ) ( aOutputBuf->iData.Ptr() ),
       
  3800 			( TUint8* ) ( aSrcOutputBuf->iData.Ptr()
       
  3801 			+ iTotalLengthFilledSoFarInPacketMode ), currentPacketLength );
       
  3802 
       
  3803 		aOutputBuf->iData.Set( aOutputBuf->iData.Ptr(), currentPacketLength );
       
  3804 
       
  3805 		iTotalLengthFilledSoFarInPacketMode
       
  3806 				= iTotalLengthFilledSoFarInPacketMode + currentPacketLength;
       
  3807 
       
  3808 		if ( iTotalLengthFilledSoFarInPacketMode
       
  3809 				== iTotalOutputBufferLengthInPacketMode )
       
  3810 			{
       
  3811 			iTotalLengthFilledSoFarInPacketMode = 0;
       
  3812 			iPacketsPending = EFalse;
       
  3813 
       
  3814 			// remove packet offset info buffer from filled Q and add it
       
  3815 			// to free Q
       
  3816 			TUint* freeOffsetLengthInfoBuffer =
       
  3817 					iFilledBufferQueueForPacketOffsetInfo[0];
       
  3818 			iFilledBufferQueueForPacketOffsetInfo.Remove( 0 );
       
  3819 			TInt error = iFreeBufferQueueForPacketOffsetInfo.Append(
       
  3820 					freeOffsetLengthInfoBuffer );
       
  3821 			if ( error != KErrNone )
       
  3822 				{
       
  3823 				ClientFatalError( error );
       
  3824 				return;
       
  3825 				}
       
  3826 
       
  3827 			// Remove the internal buffer and add it back to process engine
       
  3828 			if ( iInternalOutputBufferQueue.Count() )
       
  3829 				{
       
  3830 				TVideoOutputBuffer* outBuf = iInternalOutputBufferQueue[0];
       
  3831 				iInternalOutputBufferQueue.Remove( 0 );
       
  3832 				outBuf->iData.Set( ( TUint8* )outBuf->iData.Ptr(),
       
  3833 						iOutputBufferSize );
       
  3834 
       
  3835 				//  Add the Buffer back to the Process Engine
       
  3836 				if ( ( !iEncStateMac->IsInputEndPending() )
       
  3837 						&& ( !iEncStateMac->IsStopped() ) )
       
  3838 					{
       
  3839 					iEngine->AddOutput( ( TAny* )outBuf );
       
  3840 					}
       
  3841 				}
       
  3842 
       
  3843 			// Still more encoded packets are available
       
  3844 			if ( iInternalOutputBufferQueue.Count() )
       
  3845 				{
       
  3846 				iPacketsPending = ETrue;
       
  3847 				iTotalOutputBufferLengthInPacketMode
       
  3848 						= iInternalOutputBufferQueue[0]->iData.Length();
       
  3849 
       
  3850 				// Get the packet offset info buffer
       
  3851 				// is this check required - will be valid always
       
  3852 				if ( iFilledBufferQueueForPacketOffsetInfo.Count() )
       
  3853 					{
       
  3854 					iPacketOffSetCurrentPosition
       
  3855 							= iFilledBufferQueueForPacketOffsetInfo[0];
       
  3856 					}
       
  3857 				}
       
  3858 			}
       
  3859 		else
       
  3860 			{
       
  3861 			++iPacketOffSetCurrentPosition;
       
  3862 			}
       
  3863 		}
       
  3864 
       
  3865 	// Update the specific members of the output buffer
       
  3866 	aOutputBuf->iRequiredSeveralPictures
       
  3867 			= aSrcOutputBuf->iRequiredSeveralPictures;
       
  3868 	aOutputBuf->iRandomAccessPoint = aSrcOutputBuf->iRandomAccessPoint;
       
  3869 	aOutputBuf->iCaptureTimestamp = aSrcOutputBuf->iCaptureTimestamp;
       
  3870 
       
  3871 	PRINT_EXIT;
       
  3872 	}
       
  3873 
       
  3874 //---------------------------------------------------------------------------
       
  3875 //  Initializes the members of the output coded buffers created
       
  3876 //---------------------------------------------------------------------------
       
  3877 //
       
  3878 
       
  3879 void CAriMp4spencHwDeviceImpl::InitializeOuputCodedBuffer(
       
  3880 		TVideoOutputBuffer& aOutputBuffer )
       
  3881 	{
       
  3882 	PRINT_ENTRY;
       
  3883 	aOutputBuffer.iOrderNumber = 0;
       
  3884 	aOutputBuffer.iMinErrorProtectionLevel = 1;
       
  3885 	aOutputBuffer.iMaxErrorProtectionLevel = 1;
       
  3886 	aOutputBuffer.iRequiredThisPicture = EFalse;
       
  3887 	aOutputBuffer.iLayer = 0;
       
  3888 	aOutputBuffer.iInLayerScalabilityStep = 0;
       
  3889 	aOutputBuffer.iDataPartitionNumber = 0;
       
  3890 	aOutputBuffer.iHrdVbvParams.Set( NULL, 0 );
       
  3891 	aOutputBuffer.iCodingStandardSpecificData.Set( NULL, 0 );
       
  3892 	aOutputBuffer.iImplementationSpecificData.Set( NULL, 0 );
       
  3893 
       
  3894 	// The following members will be modified later during execution
       
  3895 	aOutputBuffer.iRequiredSeveralPictures = EFalse;
       
  3896 	aOutputBuffer.iRandomAccessPoint = EFalse;
       
  3897 	aOutputBuffer.iCaptureTimestamp = 0;
       
  3898 	PRINT_EXIT;
       
  3899 	}
       
  3900 
       
  3901 //---------------------------------------------------------------------------
       
  3902 //  Checks if the specified input format is supported or not
       
  3903 //---------------------------------------------------------------------------
       
  3904 //
       
  3905 
       
  3906 TBool CAriMp4spencHwDeviceImpl::CheckInputFormat(
       
  3907 		const TUncompressedVideoFormat& aFormat )
       
  3908 	{
       
  3909 	PRINT_ENTRY;
       
  3910 
       
  3911 	TInt i = 0;
       
  3912 	for ( TInt i = 0; i < iSupportedInputFormats.Count(); i++ )
       
  3913 		{
       
  3914 		TUncompressedVideoFormat inputFormat = iSupportedInputFormats[i];
       
  3915 		if ( inputFormat == aFormat )
       
  3916 			return ETrue;
       
  3917 		}
       
  3918 	PRINT_EXIT;
       
  3919 
       
  3920 	return EFalse;
       
  3921 	}
       
  3922 
       
  3923 //---------------------------------------------------------------------------
       
  3924 //  Nofities the client that the fatal error happend in Hw device
       
  3925 //---------------------------------------------------------------------------
       
  3926 //
       
  3927 
       
  3928 void CAriMp4spencHwDeviceImpl::ClientFatalError( TInt aError )
       
  3929 	{
       
  3930 	PRINT_ENTRY;
       
  3931 
       
  3932 	PRINT_MSG( LEVEL_CRITICAL, ("CAriMp4spencHwDeviceImpl::ClientFatalError()"
       
  3933 			" Error is %d", aError ) );
       
  3934 	if ( iClockSource )
       
  3935 		{
       
  3936 		iPeriodicTimer->Cancel();
       
  3937 		}
       
  3938 
       
  3939 	// Stop processing
       
  3940 	if ( !iEncStateMac->IsStopped() )
       
  3941 		{
       
  3942 		if ( iEncStateMac->IsInitialized() )
       
  3943 			{
       
  3944 			Stop();
       
  3945 			}
       
  3946 		}
       
  3947 	iEncStateMac->Transit( CStateMachine::EDeadStateCommand );
       
  3948 	iMMFDevVideoRecordProxy->MdvrpFatalError( this, aError );
       
  3949 
       
  3950 	PRINT_EXIT;
       
  3951 	}
       
  3952 
       
  3953 //----------------------------------------------------------------------------
       
  3954 // The implementation table entry which indicates the 1st function
       
  3955 // to call when Mpeg4-h263 encoder hwdevice plugin is selected
       
  3956 //----------------------------------------------------------------------------
       
  3957 //
       
  3958 const TImplementationProxy ImplementationTable[] =
       
  3959     {
       
  3960 	{ KUidMpeg4H263EncoderHwDeviceImplUid,
       
  3961 				( TProxyNewLPtr )( CAriMp4spencHwDeviceImpl::NewL ) }
       
  3962     };
       
  3963 
       
  3964 //----------------------------------------------------------------------------
       
  3965 // Returns the implementation table
       
  3966 //----------------------------------------------------------------------------
       
  3967 //
       
  3968 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(
       
  3969 												TInt& aTableCount )
       
  3970 {
       
  3971 	aTableCount = sizeof( ImplementationTable ) /
       
  3972 						sizeof( TImplementationProxy );
       
  3973 	return ImplementationTable;
       
  3974 }