os/mm/mdfdevvideoextensions/nga_mdf_postprocessor/src/NGAPostProcHwDevice.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 
    19 #include "NGAPostProcHwDevice.h"
    20 #include "NGAPostProcSessionManager.h"
    21 #include "NGAPostProcSurfaceHandler.h"
    22 
    23 // post-processor info
    24 const TUid KUidVideoPostProcHwDevice = {KUidNGAPostProcHwDeviceImplUid};
    25 _LIT(KManufacturer, "Nokia Inc.");
    26 _LIT(KIdentifier, "Nokia S60 Video Post Processor Hardware Device Plugin");
    27 
    28 // --- Constants ---
    29 const TInt KMaxVBMBuffers      			= 4;
    30 const TInt KMinVBMInputWidth   			= 32; 
    31 const TInt KMinVBMInputHeight  			= 32;
    32 const TInt KMaxVBMInputWidth   			= 1280; 
    33 const TInt KMaxVBMInputHeight  			= 720;
    34 const TInt KRenderAhead 	     		= 50000;     
    35 const TInt KMaxRenderDelay     			= 50000;
    36 const TInt KPostingOfset       			= 0;    
    37 const TInt KColorConversionBuffers  	= 3;
    38 const TInt KMaxBuffersGceCanHold    	= 3;
    39 const TInt KDefPlayRate					= 100;
    40 const TInt KMaxAllowedSkipInNFrames 	= 40;
    41 #ifdef __cplusplus
    42 extern "C"
    43 {
    44 #endif
    45 
    46 int32 gColorConvYUVtoYUV422Int (tBaseVideoFrame *yuv420Frame, tBaseVideoFrame* yuv422Frame,
    47 							   uint8 outClrFmt, int16 stride); 
    48 
    49 int32 Emz_VDec_gColorConv_YUVtoRGB ( 
    50 	  tBaseVideoFrame *srcImage, uint8 *dstImage, tWndParam *srcWindow, 
    51 	  tWndParam *dstWindow, uint8 srcImageFormat, uint8 dstImageFormat,
    52 	  uint8 colorConvScheme);
    53 		 	  
    54 #ifdef __cplusplus
    55 }
    56 #endif
    57 
    58 //**************************************************
    59 
    60 CMMFVideoPostProcHwDevice* CNGAPostProcHwDevice::NewL() 
    61 { 
    62    PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() ++"));
    63 
    64     CNGAPostProcHwDevice* self = new (ELeave) CNGAPostProcHwDevice; 
    65     CleanupStack::PushL(self);
    66     self->ConstructL(); 
    67     CleanupStack::Pop();
    68 
    69    PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() --"));
    70     return (CMMFVideoPostProcHwDevice*)self; 
    71 }
    72 
    73 void CNGAPostProcHwDevice::ConstructL() 
    74 { 
    75    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() ++"), this);
    76     
    77     // support for VBM buffer interface
    78     iVBMBufferOptions.iNumInputBuffers  = KMaxVBMBuffers; 
    79     iVBMBufferOptions.iBufferSize = TSize(KMaxVBMInputWidth, KMaxVBMInputHeight);
    80     iPostingTimer = CNGAPostProcTimer::NewL(*this);
    81     iWsSession.Connect();
    82    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() --"), this);
    83 }
    84 
    85 CNGAPostProcHwDevice::CNGAPostProcHwDevice() 
    86         :   iProxy(NULL), 
    87             iInputDecoderDevice(NULL),
    88             iCurrentPlaybackPosition(TTimeIntervalMicroSeconds(0)),
    89             iPPState(EInitializing),
    90             iSurfaceHandler(NULL),
    91             iSessionManager(NULL),
    92             iIsInputEnded(EFalse),
    93             iPostingTimer(NULL),
    94             iFirstPictureUpdated(EFalse),
    95             iUsingExternalSurface(EFalse),
    96             iIsColorConversionNeeded(EFalse),
    97             iSurfaceCreatedEventPublished(EFalse),
    98             iOverflowPictureCounter(0),
    99             iVideoFrameBufSize(0),
   100             iResourceLost(EFalse),
   101             iRedrawDone(EFalse),
   102 			iRedrawSurfaceInUse(EFalse),
   103             iVBMObserver(NULL),
   104             count(0),
   105             iSurfaceMask(surfaceHints::EAllowAllExternals),
   106             iSurfaceKey(TUid::Uid(surfaceHints::KSurfaceProtection)),
   107             iVideoSurfaceObserver(NULL),
   108             iVPObserver(NULL),
   109             iPicSize(0,0),
   110 			iAspectRatioNum(1),
   111 			iAspectRatioDenom(1),
   112             iStepFrameCount(0),
   113             iPlayRate(KDefPlayRate),
   114             iKeyFrameMode(EFalse),
   115             iFPObserver(NULL)
   116 {
   117 	iSurfaceId 		 = TSurfaceId::CreateNullId();
   118 	iAttributes().iPixelFormat    = EUidPixelFormatYUV_422Interleaved;
   119 }
   120 
   121 CNGAPostProcHwDevice::~CNGAPostProcHwDevice()
   122 {
   123    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::~CNGAPostProcHwDevice() ++"), this);
   124    	if (iSessionManager)
   125     {
   126         iSessionManager->CancelUpdate();
   127         delete iSessionManager;
   128         iSessionManager = NULL;
   129     }
   130    	
   131    	while (iSupportedInputFormats.Count()>0)
   132     {
   133 		iSupportedInputFormats.Remove(0);
   134     }
   135     
   136    	while (iProcessQ.Count()>0)
   137     {
   138 		iProcessQ.Remove(0);
   139     }
   140 
   141    	if(iPostingTimer)
   142     {
   143     	iPostingTimer->Cancel();
   144         delete iPostingTimer;
   145         iPostingTimer = NULL;
   146     }
   147     
   148     while (iVBMBufferReferenceQ.Count()>0)
   149     {
   150         TVideoPicture* pic = iVBMBufferReferenceQ[0];
   151         iVBMBufferReferenceQ.Remove(0);
   152         if (iColorConversionQ.Count()>0)
   153     	{
   154 	        iColorConversionQ.Remove(0);
   155 	    }
   156 
   157         if (pic->iHeader) delete pic->iHeader;
   158         delete pic->iData.iRawData;
   159         delete pic;
   160     }
   161     
   162     iSupportedInputFormats.Reset();
   163     iSupportedInputFormats.Close();
   164     
   165     iVBMBufferReferenceQ.Reset();
   166     iVBMBufferReferenceQ.Close();
   167     
   168     iColorConversionQ.Reset();
   169     iColorConversionQ.Close();
   170     
   171     iVBMBufferQ.Reset();
   172     iVBMBufferQ.Close();
   173     
   174     iProcessQ.Reset();
   175     iProcessQ.Close();
   176         
   177     iInputQ.Reset();
   178     iInputQ.Close();
   179     
   180     if (iSurfaceHandler)
   181     {
   182     	if(!iSurfaceId.IsNull())
   183     	{
   184     		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::UnregisterSurface"), this);
   185 			TInt numScreens = iWsSession.NumberOfScreens();
   186     		for(TInt i=0;i < numScreens;i++)
   187     		{
   188     			iWsSession.UnregisterSurface(i, iSurfaceId);
   189     		}
   190     		iWsSession.Flush();
   191         	iSurfaceHandler->DestroySurface(iSurfaceId);
   192     	}
   193         delete iSurfaceHandler;
   194         iSurfaceHandler = NULL;
   195     }
   196     
   197     iWsSession.Close();
   198     iChunk.Close();
   199     RDebug::Printf("------ Statistics of Post Processor ------");
   200     RDebug::Printf("    Pictures Received : %d", iPictureCounters.iTotalPictures);
   201     RDebug::Printf("    Pictures Displayed: %d", iPictureCounters.iPicturesDisplayed);
   202     RDebug::Printf("    Pictures Skipped  : %d", iPictureCounters.iPicturesSkipped);
   203     RDebug::Printf("    Pictures overflow : %d", iOverflowPictureCounter);
   204     RDebug::Printf("------------------------------------------");
   205     
   206    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:~() --"), this);
   207 }
   208 
   209 void CNGAPostProcHwDevice::SetInputFormatL(const TUncompressedVideoFormat&  aFormat) 
   210 { 
   211    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() Pattern= %x ++"), this, aFormat.iYuvFormat.iPattern);
   212     if (iPPState != EInitializing)
   213     {
   214 				PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() FAILED: Unexpected state"), this);
   215         User::Leave(KErrNotReady);
   216 	  }
   217 
   218 		iVideoFormat = aFormat; 
   219 		if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
   220 			(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
   221     		(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))
   222 		{
   223 			iVideoFormat.iYuvFormat.iCoefficients  	     = EYuvBt709Range1;
   224     		iVideoFormat.iYuvFormat.iPattern       	     = EYuv422Chroma1;
   225     		iVideoFormat.iYuvFormat.iDataLayout          = EYuvDataInterleavedBE;
   226 			
   227 #if defined __WINSCW__				
   228 				iIsColorConversionNeeded = ETrue; 
   229 #else
   230 				iAttributes().iPixelFormat = EUidPixelFormatYUV_420Planar;
   231 #endif //__WINSCW__
   232 		}	
   233 
   234    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() WARNING: -- Not Found!"), this);
   235 }
   236 
   237 
   238 void CNGAPostProcHwDevice::SetInputDevice(CMMFVideoDecodeHwDevice* aDevice) 
   239 { 
   240    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() ++"), this);
   241 
   242     if (iPPState != EInitializing)
   243     {
   244 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() FAILED: unexpected state"), this);
   245         return;
   246 	}
   247 
   248     iInputDecoderDevice = aDevice;
   249 
   250    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() --"), this);
   251 }
   252 
   253 void CNGAPostProcHwDevice::GetOutputFormatListL(RArray<TUncompressedVideoFormat>& ) 
   254 { 
   255    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetOutputFormatListL() ++"), this);
   256 
   257 
   258 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetOutputFormatListL() --"), this);
   259 }
   260 
   261 void CNGAPostProcHwDevice::SetOutputFormatL(const TUncompressedVideoFormat&  ) 
   262 {
   263    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputFormatL() ++"), this);
   264 
   265 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputFormatL() --"), this);
   266 }
   267 
   268 void CNGAPostProcHwDevice::SetClockSource(MMMFClockSource* aClock) 
   269 { 
   270    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() ++"), this);
   271     
   272     if (iPPState != EInitializing)
   273     {
   274 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() FAILED: Unexpected state"), this);
   275         return;
   276 	}
   277     iClockSource = aClock;
   278 
   279    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() --"), this);
   280 }
   281 
   282 void CNGAPostProcHwDevice::SetVideoDestScreenL(TBool /*aScreen*/) 
   283 { 
   284    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetVideoDestScreenL() ++"), this);
   285 
   286    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetVideoDestScreenL() --"), this);
   287 }
   288 
   289 void CNGAPostProcHwDevice::SetProxy(MMMFDevVideoPlayProxy& aProxy) 
   290 { 
   291    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() ++"), this);
   292 
   293     if (iPPState != EInitializing)
   294     {
   295 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() FAILED: Unexpected state"), this);
   296         return;
   297 	}
   298 
   299     iProxy = &aProxy;
   300 
   301    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() --"), this);
   302 }
   303 
   304 void CNGAPostProcHwDevice::Initialize() 
   305 {
   306    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize ++"));
   307 	TInt err = KErrNone;
   308 
   309     if (iPPState != EInitializing)
   310     {
   311 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize() FAILED: Unexpected state"), this);
   312         return;
   313 	}
   314 	if (!iSurfaceHandler)
   315     {
   316     	TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
   317     	if (err != KErrNone)
   318     	{
   319     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create SurfaceHandler."), this);
   320     	    return;
   321     	}
   322     }
   323     if (!iSessionManager)
   324     {
   325     	TRAP(err, iSessionManager = CNGAPostProcSessionManager::NewL());
   326     	if (err != KErrNone)
   327     	{
   328     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create SessionManager."), this);
   329     	    return;
   330     	}
   331     	iSessionManager->SetObserver(*this);
   332     }
   333 
   334   	if (iInputDecoderDevice)
   335 	{
   336 		MMmfVideoResourceHandler* handler = NULL;
   337 		handler = (MMmfVideoResourceHandler*)iInputDecoderDevice->CustomInterface(KUidMmfVideoResourceManagement);
   338 		if (handler)
   339 		{
   340 			handler->MmvrhSetObserver((MMmfVideoResourceObserver*)this);
   341 		}
   342 		else
   343 		{
   344 			PP_DEBUG(_L("ppHwDev[%x]:Initialize() decoder yet to implement MMmfVideoResourceHandler CI"), this);
   345 		}
   346 		
   347 		MMmfVideoPropertiesNotifier* VPHandler = NULL;
   348 		VPHandler = (MMmfVideoPropertiesNotifier*)iInputDecoderDevice->CustomInterface(KUidMmfVideoPropertiesManagement);
   349 		if (VPHandler)
   350 		{
   351 			PP_DEBUG(_L("ppHwDev[%x]:Initialize() Register for video property changes"), this);
   352 			VPHandler->MmvpnSetObserver((MMmfVideoPropertiesObserver*)this);
   353 		}
   354 		else
   355 		{
   356 			PP_DEBUG(_L("ppHwDev[%x]:Initialize() decoder yet to implement MMmfVideoPropertiesNotifier CI"), this);
   357 		}
   358 	}
   359 		
   360     // Initialize picture counters
   361 	iPictureCounters.iPicturesSkipped 	= 0;
   362 	iPictureCounters.iPicturesDisplayed = 0;
   363 	iPictureCounters.iTotalPictures = 0;
   364 	iOverflowPictureCounter = 0;
   365 	if (iProxy)
   366 	{
   367 		iProxy->MdvppInitializeComplete(this, err);
   368 	}
   369 	iPPState = EInitialized;	
   370    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize --"), this);
   371 }
   372 
   373 void CNGAPostProcHwDevice::WritePictureL(TVideoPicture* aPicture) 
   374 { 
   375 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture bufId = %d"), this,GetID(aPicture));
   376 	TVideoPicture* pic;
   377 	if (iPPState==EInitializing || iPPState==EStopped || iIsInputEnded)
   378     {
   379 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Unexpected state"), this);
   380         User::Leave(KErrNotReady);
   381 	}
   382 
   383     if(!aPicture)
   384     {
   385 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Invalid argument"), this);
   386 		User::Leave(KErrArgument);
   387 	}
   388 	pic = aPicture;	
   389 	iPictureCounters.iTotalPictures++;
   390 	if((iPPState != EPlaying) && (iFirstPictureUpdated))
   391 	{
   392 		AddToQ(pic);
   393 	}
   394 	else if( iInputQ.Count() > 0 )
   395 	{
   396 		AddToQ(pic);
   397 		AttemptToPost();
   398 	}
   399 	else
   400 	{
   401 		TInt64 delta = 0;
   402 		TTimeToPost iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
   403 		if(!IsGceReady())
   404 	    {  
   405 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL GCE not ready"), this );
   406 			if(iTimeToPost == EPostIt)
   407 			{
   408 					iTimeToPost = EDelayIt;
   409 			}
   410 	    }
   411 	    if (delta > 0x7FFFFFFF)
   412 	    {
   413 	         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL Too large delta .. skipping"), this ); 
   414 	         iTimeToPost = ESkipIt;
   415 	    }
   416 		if(!iFirstPictureUpdated)
   417 		{
   418             if(iTimeToPost == EDelayIt)
   419             {
   420                 iTimeToPost = EPostIt;
   421             }
   422 		}
   423 		switch(iTimeToPost)
   424 		{
   425 			case EDelayIt:
   426 			{
   427 				if(AddToQ(pic) != 0)
   428 				{
   429 					break;
   430 				}
   431 				iPostingTimer->Cancel();
   432 				SetTimer(delta);
   433 			}
   434 			break;
   435 			case EPostIt:
   436 			{
   437 		
   438 				if(iIsColorConversionNeeded)
   439 				{
   440 					TVideoPicture* ccPic;				
   441 	    			ccPic = DoColorConvert(pic); // output will be in ccPic
   442 	    			pic = ccPic;			   
   443 				}
   444 				iProcessQ.Append(pic);
   445 						
   446 				#ifdef _DUMP_YUV_FRAMES
   447 				captureYuv(pic);
   448 				#endif
   449 				iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue);	
   450 				iCurrentPlaybackPosition = pic->iTimestamp;			
   451 			
   452 				if(!iFirstPictureUpdated)
   453 				{
   454 					iFirstPictureUpdated = ETrue;
   455                     if(!iSurfaceCreatedEventPublished)
   456                     {
   457                         PublishSurfaceCreated();
   458                     }
   459 				}
   460 			}
   461 			break;
   462 			case ESkipIt:
   463 			{
   464 				ReleasePicture(pic); 
   465 				PicturesSkipped();
   466 			}
   467 			break;
   468 		}
   469     }
   470 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture --"), this);
   471 }
   472 
   473 
   474 CPostProcessorInfo* 
   475 CNGAPostProcHwDevice::PostProcessorInfoLC() 
   476 {
   477    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PostProcessorInfoLC() ++"), this);
   478     TUncompressedVideoFormat yuvFormat;
   479     RArray<TUint32>                     SupportedPostProcess;
   480     TBool                               SupportedHwAcceleration = ETrue;   //Non-Accelerated ETrue, 
   481     TYuvToRgbCapabilities               SupportedYuvToRgbCapab; 
   482     TInt32                              SupportedRotations = ERotateNone; // no rotation supported
   483     
   484     TBool                               SupportedArbitraryScaling = EFalse; // no scaling supported
   485     RArray<TScaleFactor>                SupportedScaleFactors;
   486     TBool                               SupportedAntiAliasing = EFalse;
   487     
   488     //default
   489     yuvFormat.iDataFormat                     = EYuvRawData;
   490     yuvFormat.iYuvFormat.iYuv2RgbMatrix       = 0;
   491     yuvFormat.iYuvFormat.iRgb2YuvMatrix       = 0;
   492     yuvFormat.iYuvFormat.iAspectRatioNum      = 1;
   493     yuvFormat.iYuvFormat.iAspectRatioDenom    = 1;
   494     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range1;
   495     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   496     yuvFormat.iYuvFormat.iDataLayout          = EYuvDataInterleavedBE;
   497     
   498     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   499     
   500     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   501     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   502     
   503     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range0;
   504     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   505     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedBE;
   506     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   507     
   508     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   509     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   510     
   511     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range0;
   512     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   513     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   514     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   515             
   516 	yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   517     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   518 
   519     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range1;
   520     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   521     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   522     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   523     
   524     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   525     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   526             
   527     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range0;
   528     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   529     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedBE;
   530     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   531     
   532     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   533     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   534 
   535     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range1;
   536     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   537     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedBE;
   538     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   539     
   540     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   541     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   542             
   543     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range0;
   544     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   545     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   546     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   547     
   548     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   549     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   550 
   551     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range1;
   552     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   553     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   554     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   555     
   556     yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   557     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   558     
   559     //YUV 420 planar
   560     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range1;
   561     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   562     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   563     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   564 
   565     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   566     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   567 
   568     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   569     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   570 
   571     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range0;
   572     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   573     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   574     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   575 
   576     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   577     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   578 
   579     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   580     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   581 
   582     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range1;
   583     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   584     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   585     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   586 
   587     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   588     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   589 
   590     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   591     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   592 
   593     yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range0;
   594     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   595     yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   596     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   597 
   598     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   599     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   600 
   601     yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   602     User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   603             
   604     CPostProcessorInfo* postProcessorInfo = CPostProcessorInfo::NewL( 
   605                 KUidVideoPostProcHwDevice, 
   606                 KManufacturer, 
   607                 KIdentifier, 
   608                 TVersion(1, 0, 0), 
   609                 iSupportedInputFormats.Array(),
   610                 SupportedPostProcess.Array(), 
   611                 SupportedHwAcceleration,   
   612                 ETrue,      //Direct Display
   613                 SupportedYuvToRgbCapab, 
   614                 SupportedRotations, 
   615                 SupportedArbitraryScaling,
   616                 SupportedScaleFactors.Array(), 
   617                 SupportedAntiAliasing);
   618                 
   619     CleanupStack::PushL(postProcessorInfo);            
   620    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PostProcessorInfoLC() --"), this);
   621     return postProcessorInfo;
   622 }
   623 
   624 void CNGAPostProcHwDevice::MmvprcGetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCap)
   625 {       
   626     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcGetPlayRateCapabilitiesL ++"), this);       
   627      aCap.iPlayForward = ETrue;       
   628      aCap.iPlayBackward = ETrue;       
   629      aCap.iStepForward = ETrue;       
   630      aCap.iStepBackward = ETrue;       
   631     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcGetPlayRateCapabilitiesL --"), this);       
   632 }       
   633 
   634 void CNGAPostProcHwDevice::MmvprcSetPlayRateL(const TInt aRate)
   635 {       
   636     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetPlayRateL ++"), this);       
   637      iPlayRate = aRate;
   638      if (iPlayRate<0)        
   639      {       
   640          iKeyFrameMode = ETrue;    
   641      }       
   642      else        
   643      {       
   644          iKeyFrameMode = EFalse;   
   645          ResetCountingBuffer();       
   646      }       
   647      //In fast forward go direct to key frame mode if speed >4X =     
   648     if (iPlayRate>KDefPlayRate*4)
   649      {       
   650          if (iFPObserver)        
   651          {       
   652              iFPObserver->MmvproKeyFrameModeRequest();       
   653              iKeyFrameMode=ETrue;       
   654          }       
   655      }       
   656     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetPlayRateL=%d --"), this, aRate);       
   657 }       
   658 
   659 TInt CNGAPostProcHwDevice::MmvprcPlayRateL()
   660 {       
   661    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcPlayRateL= ++"), this);       
   662    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcPlayRateL= --"), this);       
   663     return iPlayRate;       
   664 }       
   665 
   666 void CNGAPostProcHwDevice::MmvprcStepFrameL(const TInt aStep)
   667 {       
   668    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcStepFrameL= ++"), this);       
   669     iStepFrameCount = aStep;       
   670    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcStepFrameL=%d --"), this, aStep);       
   671 }       
   672 
   673 void CNGAPostProcHwDevice::MmvprcSetObserver(MMmfVideoPlayRateObserver& aObserver)
   674 {       
   675    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetObserver ++"), this);       
   676     iFPObserver  = &aObserver;
   677    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetObserver --"), this);
   678 } 
   679 
   680 void CNGAPostProcHwDevice::MmvsoSetSecureOutputL(TBool aSecure)
   681 {
   682 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL aSecure = %d++"), this, aSecure);     
   683 	TInt err = KErrNone;  
   684     if(aSecure)
   685 	{
   686 		iSurfaceMask = surfaceHints::EAllowInternalOnly;
   687 	}
   688 	else
   689 	{
   690 		iSurfaceMask = surfaceHints::EAllowAllExternals;
   691 	}
   692 	if(!iSurfaceId.IsNull())
   693 	{
   694 		err = AddHints();
   695 		if(err != KErrNone)
   696 		{
   697 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvsoSetSecureOutputL -- leaving err = %d"), this, err);
   698 			User::Leave(err);
   699 		}
   700 	}
   701     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL --"), this);
   702 }
   703 
   704 void CNGAPostProcHwDevice::MmavsoSetAllowedOutputL(TUint aAllowedOutputMask)
   705 {
   706    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL aAllowedOutputMask=0x%08x ++"), this,aAllowedOutputMask);  
   707    TInt err = KErrNone;
   708    iSurfaceMask = surfaceHints::EAllowInternalOnly;
   709     if (aAllowedOutputMask == EVideoAllowAll)
   710     {
   711         iSurfaceMask = surfaceHints::EAllowAllExternals;
   712     }
   713     else if (aAllowedOutputMask == EVideoAllowInternalOnly)
   714     {
   715         iSurfaceMask = surfaceHints::EAllowInternalOnly;
   716     }
   717     else 
   718     {
   719         // we hope to find some valid output prefs
   720         if (aAllowedOutputMask & EVideoAllowAnalog)
   721         {
   722             iSurfaceMask |= surfaceHints::EAllowAnalog;
   723         }
   724         if (aAllowedOutputMask & EVideoAllowMacroVision)
   725         {
   726             iSurfaceMask |= surfaceHints::EAllowAnalogProtectionRequired;
   727         }
   728         if (aAllowedOutputMask & EVideoAllowHDMI)
   729         {
   730             iSurfaceMask |= surfaceHints::EAllowDigital;
   731         }
   732         if (aAllowedOutputMask & EVideoAllowHdmiHdcpRequested)
   733         {
   734             iSurfaceMask |= surfaceHints::EAllowDigitalProtectionRequested;
   735         }
   736         if (aAllowedOutputMask & EVideoAllowHdmiHdcpRequired)
   737         {
   738             iSurfaceMask |= surfaceHints::EAllowDigitalProtectionRequired;
   739         }
   740     }
   741     
   742 	if((!iSurfaceId.IsNull()))
   743 	{
   744 		err = AddHints();
   745 		if(err != KErrNone)
   746 		{
   747 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmavsoSetAllowedOutputL -- leaving err = %d"), this, err);
   748 			User::Leave(err);
   749 		}
   750 	}
   751     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL --"), this);
   752 }	
   753 
   754 void CNGAPostProcHwDevice::SetPostProcessTypesL(TUint32 /*aCombination*/) 
   755 { 
   756 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPostProcessTypesL ++"), this);
   757 	
   758    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPostProcessTypesL --"), this);
   759 }
   760 
   761 void CNGAPostProcHwDevice::SetInputCropOptionsL(const TRect& /*aRect*/) 
   762 { 
   763 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputCropOptionsL ++"), this);
   764    
   765 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputCropOptionsL --"), this);
   766 }    
   767 
   768 void CNGAPostProcHwDevice::SetYuvToRgbOptionsL( const TYuvToRgbOptions&  /*aOptions*/, const TYuvFormat& /*aYuvFormat*/, TRgbFormat /*aRgbFormat*/) 
   769 { 
   770 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL ++"), this);
   771 
   772 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL --"), this);
   773 }
   774 
   775 void CNGAPostProcHwDevice::SetYuvToRgbOptionsL(const TYuvToRgbOptions& /*aOptions*/)
   776 {
   777 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL ++"), this);
   778 
   779 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL --"), this);
   780 }
   781 
   782 void CNGAPostProcHwDevice::SetRotateOptionsL(TRotationType ) 
   783 { 
   784 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetRotateOptionsL ++"), this);
   785     
   786 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetRotateOptionsL --"));
   787 }
   788 
   789 void CNGAPostProcHwDevice::SetScaleOptionsL(const TSize& /*aTargetSize*/, TBool /*aAntiAliasFiltering*/) 
   790 { 
   791 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScaleOptionsL ++"), this);
   792     
   793    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScaleOptionsL --"), this);
   794 }
   795 
   796 void CNGAPostProcHwDevice::SetOutputCropOptionsL(const TRect& /*aRect*/) 
   797 { 
   798 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputCropOptionsL ++"), this);
   799     
   800 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputCropOptionsL --"), this);
   801 }
   802 
   803 void CNGAPostProcHwDevice::SetPostProcSpecificOptionsL(const TDesC8& ) 
   804 { 
   805     //ignore 
   806 }
   807 
   808 void CNGAPostProcHwDevice::CommitL() 
   809 { 
   810 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CommitL ++"), this);
   811 
   812    	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CommitL --"), this);
   813 }
   814 
   815 void CNGAPostProcHwDevice::Revert() 
   816 {
   817 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Revert ++"), this);
   818     
   819 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Revert --"), this);
   820 }
   821 
   822 void CNGAPostProcHwDevice::StartDirectScreenAccessL( const TRect& /*aVideoRect*/, CFbsScreenDevice& /*aScreenDevice*/, const TRegion& /*aClipRegion*/) 
   823 { 
   824    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:StartDSA ++"), this);
   825     
   826    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:StartDSA --"), this);
   827 }
   828 
   829 void CNGAPostProcHwDevice::AbortDirectScreenAccess() 
   830 { 
   831    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AbortDSA ++"), this);
   832 
   833    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AbortDSA --"), this);
   834 }
   835 
   836 void CNGAPostProcHwDevice::SetScreenClipRegion(const TRegion& /*aRegion*/) 
   837 { 
   838    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScreenClipRegion ++"), this);
   839     
   840     
   841    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScreenClipRegion --"), this);
   842 }		    
   843 
   844 void CNGAPostProcHwDevice::SetPauseOnClipFail(TBool ) 
   845 { 
   846     //ignore. Post Processor will always behave as aPause==False. 
   847 }
   848 
   849 TBool CNGAPostProcHwDevice::IsPlaying()
   850 {
   851 	if( iPPState == EPlaying)
   852 	{
   853     	return ETrue; 
   854     }
   855     else
   856     {
   857     	return EFalse;
   858     }
   859 }
   860 
   861 void CNGAPostProcHwDevice::Redraw() 
   862 { 
   863 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw ++"), this);
   864 	TInt err = KErrNone;
   865 	if(iRedrawSurfaceInUse && !iRedrawDone)
   866 	{
   867         err = AddHints();
   868         if (err != KErrNone)
   869         {
   870             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to AddHints %d"), 
   871                          this, err);
   872             iProxy->MdvppFatalError(this, err);	
   873             return;   
   874         }
   875         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface"), this);
   876 		err = RegisterSurface(iSurfaceId);
   877 		if (err != KErrNone)
   878 		{
   879 		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to Register Surface %d"), 
   880 		   				this, err);
   881 		   	iSurfaceHandler->DestroySurface(iSurfaceId);
   882 	   		iSurfaceId = TSurfaceId::CreateNullId();
   883 			iProxy->MdvppFatalError(this, err);	
   884 			return;   				
   885 		}
   886 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface done"), this);
   887         iSessionManager->PostPicture(iSurfaceId, 0, 1, EFalse);
   888         PublishSurfaceCreated();
   889         iRedrawDone = ETrue;
   890     }
   891     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw --"), this);
   892 }
   893 
   894 void CNGAPostProcHwDevice::Start() 
   895 {  
   896 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start ++"), this);
   897 	iPPState = EPlaying;
   898 	AttemptToPost();
   899 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start --"), this);
   900 }
   901 
   902 void CNGAPostProcHwDevice::Stop() 
   903 { 
   904 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Stop ++"), this);
   905     iPPState = EStopped;
   906 	iPostingTimer->Cancel();
   907 	ReleaseInputQ();
   908 	
   909 	RDebug::Printf("------ Statistics of Post Processor ------");
   910     RDebug::Printf("    Pictures Received : %d", iPictureCounters.iTotalPictures);
   911     RDebug::Printf("    Pictures Displayed: %d", iPictureCounters.iPicturesDisplayed);
   912     RDebug::Printf("    Pictures Skipped  : %d", iPictureCounters.iPicturesSkipped);
   913     RDebug::Printf("------------------------------------------");
   914     
   915 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Stop --"), this);
   916 }
   917 
   918 void CNGAPostProcHwDevice::Pause()
   919 {
   920 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Pause ++"), this);
   921 	iPPState = EPaused;
   922     iPostingTimer->Cancel();
   923    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Pause --"), this);
   924 }
   925 
   926 void CNGAPostProcHwDevice::Resume()
   927 {
   928 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Resume ++"), this);
   929 	iPPState = EPlaying;
   930 	AttemptToPost();
   931    	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Resume --"), this);
   932 }
   933 
   934 void CNGAPostProcHwDevice::SetPosition(const TTimeIntervalMicroSeconds& aPlaybackPosition) 
   935 {
   936    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition ++"), this);
   937     
   938     if (iPPState == EInitializing)
   939     { 
   940 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition FAILED: Unexpected state"), this);
   941         return;
   942     }
   943     if (iPPState == EPaused)
   944     {	
   945         iFirstPictureUpdated = EFalse;
   946     }
   947     iCurrentPlaybackPosition = aPlaybackPosition;  
   948     
   949     ReleaseInputQ();
   950 
   951    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition --"), this);
   952 }
   953 
   954 void CNGAPostProcHwDevice::FreezePicture(const TTimeIntervalMicroSeconds& ) 
   955 { 
   956     //TODO:
   957 }
   958 
   959 void CNGAPostProcHwDevice::ReleaseFreeze(const TTimeIntervalMicroSeconds&  ) 
   960 { 
   961     //TODO:
   962 }
   963 
   964 TTimeIntervalMicroSeconds 
   965 CNGAPostProcHwDevice::PlaybackPosition() 
   966 { 
   967 	if (iPPState == EInitializing)
   968     {
   969         return TTimeIntervalMicroSeconds(0);
   970     }
   971     
   972     return iCurrentPlaybackPosition; 
   973 }
   974 
   975 TUint CNGAPostProcHwDevice::PictureBufferBytes() 
   976 {   //TODO 
   977     return 0; 
   978 }
   979 
   980 void CNGAPostProcHwDevice::GetPictureCounters( CMMFDevVideoPlay::TPictureCounters&  aCounters) 
   981 { 
   982 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetPictureCounters ++"), this);
   983 	
   984 	if (iPPState == EInitializing)
   985 		return;
   986 	aCounters = iPictureCounters;
   987 	
   988    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetPictureCounters --"), this);
   989 }
   990 
   991 void CNGAPostProcHwDevice::SetComplexityLevel(TUint ) 
   992 { 
   993     //not required 
   994 }
   995 
   996 TUint CNGAPostProcHwDevice::NumComplexityLevels() 
   997 { 
   998     //not required 
   999     return 1; 
  1000 }
  1001 
  1002 void CNGAPostProcHwDevice::GetComplexityLevelInfo(TUint , CMMFDevVideoPlay::TComplexityLevelInfo& ) 
  1003 { 
  1004     //not required 
  1005 }
  1006 
  1007 void CNGAPostProcHwDevice::ReturnPicture(TVideoPicture* ) 
  1008 { 
  1009 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicture +-"), this);
  1010     //not required for direct rendering 
  1011 }
  1012 
  1013 TBool CNGAPostProcHwDevice::GetSnapshotL(TPictureData& aPictureData, const TUncompressedVideoFormat& /*aFormat*/)
  1014 { 
  1015 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL %d %d ++"), this, iVBMEnabled, iProcessQ.Count());
  1016 	TVideoPicture* 		pic = NULL;
  1017 	TInt 				err = KErrNone;
  1018 	TBool				frameAvailable =EFalse;
  1019 	tWndParam			inputCropWindow;
  1020 	tWndParam			outputCropWindow;
  1021 	tBaseVideoFrame		inputFrame;
  1022 	inputFrame.lum 		= NULL; 
  1023 	
  1024 	if(aPictureData.iDataFormat == ERgbFbsBitmap)
  1025 	{	
  1026 		if(iProcessQ.Count())
  1027 		{
  1028 			pic = iProcessQ[0]; //frame already submitted for display
  1029 		}
  1030 		else if(iInputQ.Count())
  1031 		{
  1032 			pic = iInputQ[0]; //frame yet to be displayed
  1033 		}
  1034 		if(pic) 
  1035 		{
  1036 			if (iVBMEnabled)
  1037 		    {
  1038 				inputFrame.lum	= (TUint8*)pic->iData.iRawData->Ptr();
  1039 			}
  1040 			else
  1041 			{
  1042 				if (iInputDecoderDevice)
  1043 				{
  1044 					MMmfVideoFetchFrame* VFHandler = NULL;
  1045 					VFHandler = (MMmfVideoFetchFrame*)iInputDecoderDevice->CustomInterface(KUidMMFVideoFetchFrame);
  1046 					if (VFHandler)
  1047 					{
  1048 						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() fetch frame"), this);
  1049 						inputFrame.lum = (TUint8*)VFHandler->MmvffGetFrame(GetID(pic));
  1050 					}
  1051 					else
  1052 					{
  1053 						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() decoder yet to implement MMmfVideoFetchFrame CI"), this);
  1054 					}
  1055 				}
  1056 			}
  1057 		}
  1058 		if(inputFrame.lum)
  1059 		{
  1060 			inputFrame.cb	= inputFrame.lum + iPicSize.iWidth * iPicSize.iHeight;
  1061 			
  1062 			if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
  1063 				(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
  1064 	    		(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))						
  1065 			{
  1066 				inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*5)/4;
  1067 			}
  1068 			else
  1069 			{
  1070 				inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*3)/2;
  1071 			}
  1072 			
  1073 			inputFrame.width	= (unsigned short)iPicSize.iWidth;
  1074 			inputFrame.height	= (unsigned short)iPicSize.iHeight;
  1075 			
  1076 			outputCropWindow.wndHeight  = iPicSize.iHeight;	
  1077 			outputCropWindow.wndWidth	= iPicSize.iWidth; 	
  1078 			outputCropWindow.xOffset	= 0;
  1079 			outputCropWindow.yOffset	= 0;
  1080 			
  1081 			inputCropWindow.wndHeight  = iPicSize.iHeight;	
  1082 			inputCropWindow.wndWidth	= iPicSize.iWidth; 	
  1083 			inputCropWindow.xOffset	= 0;
  1084 			inputCropWindow.yOffset	= 0;
  1085 			
  1086 			RFbsSession fbs;
  1087 			fbs.Connect();
  1088 			CFbsBitmap* iOutBitmap = aPictureData.iRgbBitmap;
  1089 			TInt status = iOutBitmap->Resize(iPicSize);
  1090 			if (status == KErrNone)
  1091 			{
  1092 				// Lock the heap to prevent the FBS server from invalidating the address
  1093 		        iOutBitmap->LockHeap();
  1094 		        TUint8* dataAddress = (TUint8*)iOutBitmap->DataAddress();
  1095 				err = ColorConvert(&inputFrame, dataAddress, &inputCropWindow, &outputCropWindow);
  1096 				iOutBitmap->UnlockHeap();
  1097 				frameAvailable = ETrue;
  1098 			}
  1099 			fbs.Disconnect();
  1100 		}
  1101 	}
  1102 	else
  1103 	{
  1104 		err = KErrNotSupported;
  1105 	}
  1106 	if(err != KErrNone)
  1107 	{
  1108 		User::Leave(err);
  1109 	}
  1110 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL --"), this);
  1111 	return(frameAvailable);
  1112 }
  1113 
  1114 void CNGAPostProcHwDevice::InputEnd() 
  1115 { 
  1116    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd ++"), this);
  1117     
  1118 	if (iPPState!=EPlaying && iPPState!=EPaused)
  1119     {
  1120 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd FAILED: Unexpected state"), this);
  1121         return;
  1122 	}
  1123     iIsInputEnded = ETrue;
  1124     
  1125   if( (iProcessQ.Count() == 1) && (iInputQ.Count() == 0))
  1126 	{
  1127 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd() Stream end"), this);
  1128 		iProxy->MdvppStreamEnd();
  1129 	}
  1130     
  1131    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd --"), this);
  1132 }
  1133 
  1134 TAny* CNGAPostProcHwDevice::CustomInterface(TUid aInterface)
  1135 {
  1136    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CustomInterface UID = %d ++"), this, aInterface.iUid);
  1137 	
  1138 	if (aInterface == KUidMmfVideoBufferManagement)
  1139     {
  1140       return (MMmfVideoBufferManagement *)this;
  1141     }
  1142 	if (aInterface == KUidMMFVideoSurfaceSupport)
  1143 	{
  1144       return (MMMFVideoSurfaceSupport *)this;
  1145     }
  1146 	if (aInterface == KUidMMFVideoSurfaceHandleControl)
  1147 	{
  1148     	return (MMmfVideoSurfaceHandleControl *)this;
  1149   }    
  1150     if (aInterface == KUidMmfVideoPlayRateControl)
  1151     {
  1152       return (MMmfVideoPlayRateControl *)this;
  1153     } 
  1154     if (aInterface == KMmfVideoAdvancedSecureOutputUid)
  1155     {
  1156       return (MMmfAdvancedVideoSecureOutput *)this;
  1157     }
  1158     if (aInterface == KUidMmfVideoResourceManagement)
  1159     {
  1160       return (MMmfVideoResourceObserver *)this;
  1161     } 
  1162    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CustomInterface --"), this);
  1163     return NULL;
  1164 }
  1165 
  1166 void CNGAPostProcHwDevice::BufferAvailable(TInt aBufId, TInt aStatus)
  1167 { 
  1168    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CNGAPostProcHwDevice::BufferAvailable aStatus = %d aBufId = %d++"), this, aStatus, aBufId);
  1169     TVideoPicture* pic = NULL;
  1170     if((aStatus != KErrNone) && (aStatus != KErrOverflow) && (aStatus != KErrNotVisible))
  1171 	{
  1172 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:BufferAvailable FAILED: aStatus = %d"), this, aStatus);
  1173 		iProxy->MdvppFatalError(this, aStatus);
  1174 	}
  1175 
  1176 	if(aStatus == KErrOverflow)
  1177 	{
  1178 		iOverflowPictureCounter++;
  1179 		PicturesSkipped();
  1180 	}
  1181     	
  1182     if (iVBMEnabled)
  1183     {
  1184 		for(TInt i=0; i < iProcessQ.Count(); i++)
  1185 		{
  1186 			if(iVBMBufferReferenceQ[aBufId] == iProcessQ[i])
  1187 			{
  1188 				pic = iProcessQ[i];
  1189 				iProcessQ.Remove(i);				
  1190 				ReturnPicToDecoder(pic);
  1191 				if (iIsColorConversionNeeded)
  1192 				{
  1193 				    AddPictureToColorConversionQ(pic);
  1194 				}
  1195 				else
  1196 				{
  1197 				    AddPictureToVBMQ(pic);
  1198 				}
  1199 				break;
  1200 			}
  1201 		} 
  1202 	}
  1203 	else if (iUsingExternalSurface)
  1204 	{
  1205 	    for(TInt i=0; i < iProcessQ.Count(); i++)
  1206 		{
  1207 			if (aBufId == GetExternalBufferID(iProcessQ[i]))
  1208 			{
  1209 				pic = iProcessQ[i];
  1210 				iProcessQ.Remove(i);
  1211 				ReturnPicToDecoder(pic);
  1212 				break;
  1213 			}
  1214 		} 
  1215 	}
  1216 	
  1217 	if(aStatus == KErrNone)
  1218 	{
  1219 		if (!iKeyFrameMode && iPlayRate>KDefPlayRate)     
  1220 		{   
  1221 		 	if (iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer]==1)        
  1222 		 	{       
  1223 		 		iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer] = 0;       
  1224 		 		iSkippedFramesInLast64Frames--;       
  1225 		 	}       
  1226 		 	iCurrentPosInFramesCountingBuffer = ++iCurrentPosInFramesCountingBuffer%64;       
  1227 		} 
  1228 		iPictureCounters.iPicturesDisplayed++;
  1229 		if (iStepFrameCount != 0)
  1230         {       
  1231         	iStepFrameCount > 0 ? iStepFrameCount-- : iStepFrameCount++;		            	      
  1232             if (iStepFrameCount==0 && iFPObserver)        
  1233             {       
  1234             	iFPObserver->MmvproStepFrameComplete(pic->iTimestamp);       
  1235             }       
  1236         }
  1237 	}
  1238 	
  1239 	if(iPPState == EPlaying)
  1240 	{
  1241 		AttemptToPost();
  1242 	}
  1243 
  1244 	if( iIsInputEnded && (iProcessQ.Count() == 1)  && (iInputQ.Count() == 0))
  1245 	{
  1246 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:BufferAvailable() Stream end"), this);
  1247 		iProxy->MdvppStreamEnd();
  1248 	}
  1249 	
  1250    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CNGAPostProcHwDevice::BufferAvailable --"), this);
  1251 }
  1252 
  1253 //=== MMmfVideoBufferManagement ===
  1254 void CNGAPostProcHwDevice::MmvbmSetObserver(MMmfVideoBufferManagementObserver* aObserver)
  1255 {
  1256    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver() ++"), this);
  1257 
  1258     if (iPPState != EInitializing)
  1259     {
  1260 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver FAILED: Unexpected state"), this);
  1261         iProxy->MdvppFatalError(this, KErrNotReady);
  1262 	}
  1263 
  1264     iVBMObserver  = aObserver;
  1265 
  1266    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver() --"), this);
  1267 }
  1268     
  1269 
  1270 void CNGAPostProcHwDevice::MmvbmEnable(TBool aEnable)
  1271 {
  1272     if (iPPState != EInitializing)
  1273     {
  1274 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmEnable FAILED: Unexpected state"), this);
  1275         iProxy->MdvppFatalError(this, KErrNotReady);
  1276 	}
  1277 
  1278     iVBMEnabled = aEnable;
  1279 }
  1280     
  1281 void CNGAPostProcHwDevice::MmvbmSetBufferOptionsL(const TBufferOptions& aOptions)
  1282 {
  1283    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL ++"), this);
  1284 
  1285     if (iPPState != EInitializing)
  1286     {
  1287 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Unexpected state"), this);
  1288         User::Leave(KErrNotReady);
  1289 	}
  1290 
  1291     if (aOptions.iNumInputBuffers > KMaxVBMBuffers 
  1292         || aOptions.iNumInputBuffers <= 1)          //at least two buffers
  1293     {
  1294 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Input buffer count limit"), this);
  1295         User::Leave(KErrNotSupported);
  1296 	}
  1297 
  1298     if (aOptions.iNumInputBuffers == 0 
  1299         || aOptions.iBufferSize.iWidth <= KMinVBMInputWidth 
  1300         || aOptions.iBufferSize.iHeight <= KMinVBMInputHeight  
  1301         || aOptions.iBufferSize.iWidth > KMaxVBMInputWidth 
  1302         || aOptions.iBufferSize.iHeight > KMaxVBMInputHeight)
  1303     {
  1304 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Unexpected buffer size"), this);
  1305         User::Leave(KErrArgument);
  1306 	}
  1307 
  1308     iVBMBufferOptions.iNumInputBuffers  = aOptions.iNumInputBuffers;
  1309     iVBMBufferOptions.iBufferSize       = aOptions.iBufferSize;
  1310 
  1311    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL --"), this);
  1312 }
  1313 
  1314 void CNGAPostProcHwDevice::MmvbmGetBufferOptions(TBufferOptions& aOptions)
  1315 {
  1316     if (iPPState == EInitializing)
  1317     {
  1318     	aOptions = iVBMBufferOptions;
  1319     }
  1320     else
  1321     {
  1322 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferOptions FAILED: Unexpected state"), this);
  1323         iProxy->MdvppFatalError(this, KErrNotReady);
  1324 	}
  1325 }
  1326     
  1327 TVideoPicture* CNGAPostProcHwDevice::MmvbmGetBufferL(const TSize& aSize)
  1328     {
  1329    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() ++"), this);
  1330     
  1331     TInt err = KErrNone;
  1332     TVideoPicture* lPic = NULL;
  1333 
  1334     if (iPPState == EInitializing)
  1335     {
  1336 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() FAILED: Unexpected state"), this);
  1337         User::Leave(KErrNotReady);
  1338 	  }
  1339 
  1340     if (aSize.iWidth < KMinVBMInputWidth 
  1341         || aSize.iHeight < KMinVBMInputHeight
  1342         || aSize.iWidth > iVBMBufferOptions.iBufferSize.iWidth 
  1343         || aSize.iHeight > iVBMBufferOptions.iBufferSize.iHeight)
  1344   	{
  1345 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() FAILED: Unexpected buffer size w=%d h=%d "), this,aSize.iWidth,aSize.iHeight );
  1346         User::Leave(KErrNotSupported);
  1347 		}
  1348 		
  1349 		if(iVBMBufferReferenceQ.Count() == 0)
  1350 		{
  1351 			iPicSize = aSize;
  1352 			err = SetupSurface(aSize);
  1353 			if(err)
  1354 			{
  1355 					PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() Surface Setup Failed %d"), this, err);
  1356 					User::Leave(err);
  1357 			}
  1358 		}
  1359 		
  1360     if(!iVBMBufferQ.Count())
  1361     {
  1362        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() WARNING: Queue buffer count zero"), this);
  1363         return NULL;
  1364     }
  1365 
  1366     lPic    = iVBMBufferQ[0];
  1367     iVBMBufferQ.Remove(0);
  1368 
  1369    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() -- %d"), this, lPic);
  1370     return lPic;
  1371 }
  1372     
  1373 void CNGAPostProcHwDevice::MmvbmReleaseBuffer(TVideoPicture* aBuffer)
  1374 {
  1375    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() ++"), this);
  1376 
  1377     if(!aBuffer)
  1378     {
  1379 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() FAILED: Invalid buffer ptr"), this);
  1380     	iProxy->MdvppFatalError(this, KErrArgument);
  1381 	}
  1382 
  1383     TInt err = iVBMBufferQ.Append(aBuffer);
  1384     if (err)
  1385     {
  1386 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() FAILED: Failed to append"), this);
  1387 		iProxy->MdvppFatalError(this, err);
  1388 	}
  1389 
  1390    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() --"), this);
  1391 }
  1392 
  1393 //=== MMMFVideoSurfaceSupport ===
  1394 
  1395 void CNGAPostProcHwDevice::MmvssUseSurfaces()
  1396 {
  1397 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssUseSurfaces() ++"), this);
  1398 	// do nothing
  1399 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssUseSurfaces() --"), this);
  1400 }
  1401 
  1402 void CNGAPostProcHwDevice::MmvssSetObserver(MMMFVideoSurfaceObserver& aObserver)
  1403 {
  1404 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSetObserver() ++"), this);
  1405 	iVideoSurfaceObserver = &aObserver;
  1406 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSetObserver() --"), this);
  1407 }
  1408 
  1409 void CNGAPostProcHwDevice::MmvssGetSurfaceParametersL(TSurfaceId& aSurfaceId, 
  1410 						TRect& aCropRect, TVideoAspectRatio& aPixelAspectRatio)
  1411 {
  1412 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() ++"), this);
  1413 
  1414 	iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1415 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() \
  1416 		surfaceWidth = %d surfaceHeight = %d SurfaceId = 0x%x --"), 
  1417 		this, iInfo().iSize.iWidth, iInfo().iSize.iHeight, iSurfaceId);
  1418 	aSurfaceId = iSurfaceId;
  1419 		aCropRect = TRect(0, 0, iInfo().iSize.iWidth, iInfo().iSize.iHeight);
  1420 		if((iPicSize.iWidth > 0) && (iPicSize.iHeight > 0))
  1421 		{
  1422 			aCropRect.Intersection( iPicSize);
  1423 		}
  1424 	aPixelAspectRatio = TVideoAspectRatio(iAspectRatioNum,iAspectRatioDenom);
  1425 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL()  \
  1426 		cropRectWidth = %d cropRectHeight = %d"), this, aCropRect.Width(), aCropRect.Height());
  1427 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL()  \
  1428 		PAR Num = %d PAR Denom = %d"), this, aPixelAspectRatio.iNumerator, aPixelAspectRatio.iDenominator);
  1429 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() --"), this);
  1430 }
  1431 
  1432 void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
  1433 {
  1434 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
  1435 	if(!aSurfaceId.IsNull())
  1436 	{
  1437 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
  1438 		TInt numScreens = iWsSession.NumberOfScreens();
  1439 		for(TInt i=0;i < numScreens;i++)
  1440 		{
  1441 			iWsSession.UnregisterSurface(i, aSurfaceId);
  1442 		}
  1443 		iWsSession.Flush();
  1444 		iSurfaceHandler->DestroySurface(aSurfaceId);
  1445 		if(iSurfaceId == aSurfaceId)
  1446 		{
  1447 			iSurfaceCreatedEventPublished = EFalse;
  1448 			iSurfaceId = TSurfaceId::CreateNullId();
  1449 			iChunk.Close();
  1450 		}
  1451 	}
  1452 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
  1453 }
  1454 
  1455 // === MMmfVideoPropertiesObserver ===
  1456     
  1457 void CNGAPostProcHwDevice::MmvpoUpdateVideoProperties(const TYuvFormat& aYuvFormat, const TSize& aPictureSize)
  1458 {
  1459 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties ++"), this);
  1460 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties PAR \
  1461 		iAspectRatioNum = %d, iAspectRatioDenom = %d"), this,
  1462 					 aYuvFormat.iAspectRatioNum,aYuvFormat.iAspectRatioDenom);
  1463 	iPicSize = aPictureSize;
  1464 	iAspectRatioNum = aYuvFormat.iAspectRatioNum;
  1465 	iAspectRatioDenom = aYuvFormat.iAspectRatioDenom;
  1466 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties Picture Size \
  1467 		iWidth = %d, iHeight = %d, iSurfaceCreatedEventPublished = %d"), 
  1468 		this, iPicSize.iWidth,iPicSize.iHeight, iSurfaceCreatedEventPublished?1:0);
  1469 			 
  1470 	if(iVPObserver)
  1471 	{
  1472 		iVPObserver->MmvpoUpdateVideoProperties(aYuvFormat, aPictureSize);
  1473 	} 
  1474 	if(iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1475 	{
  1476     	iVideoSurfaceObserver->MmvsoSurfaceParametersChanged(); 
  1477     }
  1478 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties --"), this);
  1479 }
  1480 
  1481 // === MMmfVideoResourceObserver ===
  1482 
  1483 void CNGAPostProcHwDevice::MmvroResourcesLost(TUid )
  1484 {
  1485     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ++"), this);
  1486     if(!iResourceLost)
  1487     {
  1488 		iResourceLost = ETrue;
  1489 		iRedrawDone = EFalse;
  1490 		Pause();
  1491 		ReleaseInputQ();
  1492 		iSessionManager->CancelUpdate();
  1493 		ReleaseProcessQ();
  1494 		if(iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1495 		{
  1496 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost - Telling client to remove surface"), this);
  1497 			iVideoSurfaceObserver->MmvsoRemoveSurface();
  1498 			iSurfaceCreatedEventPublished = EFalse;
  1499 		}
  1500 	}
  1501 	else if(iResourceLost && iRedrawDone)
  1502 	{
  1503 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ResourceLost happening \
  1504 					while Postprocessor is already in ResourceLoss state"), 
  1505 	   				this);
  1506 		iProxy->MdvppFatalError(this, KErrHardwareNotAvailable);	   				
  1507 	    return;		
  1508 	}
  1509 	else
  1510 	{
  1511 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost Ignoring the \
  1512 					duplicate ResourceLoss call"), 
  1513 	   				this);
  1514 	}
  1515     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost --"), this);
  1516 }
  1517 
  1518 // === MMmfVideoPropertiesNotifier ===
  1519     
  1520 void CNGAPostProcHwDevice::MmvpnSetObserver(MMmfVideoPropertiesObserver* aObserver)
  1521 {
  1522 	PP_DEBUG(_L("ppHwDev[%x]::MmvpnSetObserver ++"), this);
  1523 	iVPObserver = aObserver;
  1524 	PP_DEBUG(_L("ppHwDev[%x]::MmvpnSetObserver --"), this);
  1525 }
  1526 
  1527 void CNGAPostProcHwDevice::MmvroResourcesRestored(TUid )
  1528 {
  1529    	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesRestored ++"), this);
  1530 	iFirstPictureUpdated = EFalse;
  1531 	iResourceLost = EFalse;
  1532    	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesRestored state=%d --"), 
  1533    			this, iPPState);
  1534 }
  1535 
  1536 void CNGAPostProcHwDevice::MmvshcSetSurfaceHandle(const TSurfaceId &aSurfaceID)
  1537 {
  1538     
  1539     SetupExternalSurface(aSurfaceID);
  1540     
  1541 }
  1542 
  1543 void CNGAPostProcHwDevice::MmvshcRedrawBufferToSurface(TPtrC8& aRedrawBuffer)
  1544 {
  1545     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface ++"), this);
  1546 	
  1547     TUint8*         lPtr;
  1548     TInt 			offset;
  1549 
  1550     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface -- Creating %d x %d surface"), this, iPicSize.iWidth, iPicSize.iHeight);
  1551 
  1552    	TInt err = KErrNone;
  1553 	SetSurfaceAttributes(iPicSize, 1); 
  1554 	
  1555   	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1556   	if (err != KErrNone)
  1557 	{
  1558 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to create Surface %d"), 
  1559 	   				this, err);
  1560 		iProxy->MdvppFatalError(this, err);	   				
  1561 	    return;
  1562 	}
  1563 
  1564 	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1565 	if (err != KErrNone)
  1566 	{
  1567 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to get Surface info %d"), 
  1568 	   				this, err);
  1569 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1570 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1571 		iProxy->MdvppFatalError(this, err);	   				
  1572 	    return;
  1573 	}
  1574 
  1575 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface() \
  1576 		surfaceWidth = %d surfaceHeight = %d surfaceStride = %d"), this, iInfo().iSize.iWidth, iInfo().iSize.iHeight, iInfo().iStride);
  1577 
  1578 	TInt redrawBufferSize = aRedrawBuffer.Size();
  1579 	TInt surfaceSize = iInfo().iStride * iInfo().iSize.iHeight;
  1580 
  1581     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface RedrawBuffer size= %d Surface size = %d"), this, redrawBufferSize, surfaceSize);
  1582 
  1583 	// Check whether redraw buffer will fit onto the surface.
  1584 	// If this check fails then we won't raise a fatal error - We just won't create the redraw surface
  1585 	if (redrawBufferSize > surfaceSize)
  1586 	{
  1587     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface Redraw buffer size larger than surface size"), this);
  1588     	iSurfaceHandler->DestroySurface(iSurfaceId);
  1589 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1590     	return;
  1591 	}
  1592 
  1593 	err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
  1594 	if (err != KErrNone)
  1595 	{
  1596 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to map Surface %d"), 
  1597 	   				this, err);
  1598 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1599 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1600 		iProxy->MdvppFatalError(this, err);	   				
  1601 	    return;
  1602 	}
  1603 
  1604     if((err = iSurfaceHandler->GetBufferOffset(iSurfaceId, 0, offset)) != KErrNone)
  1605     {
  1606     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset query failed %d"), this, err);
  1607     	iSurfaceHandler->DestroySurface(iSurfaceId);
  1608 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1609 		iChunk.Close();
  1610     	iProxy->MdvppFatalError(this, err);
  1611     	return;
  1612     }
  1613 
  1614     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset = %d"), this, offset);
  1615 
  1616 	lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
  1617 	memcpy((TAny *)lPtr, (TAny *)aRedrawBuffer.Ptr(), redrawBufferSize);
  1618 
  1619 	iRedrawSurfaceInUse = ETrue;
  1620 
  1621 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface(): New surface = 0x%x"), this, iSurfaceId);
  1622 
  1623     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface error = %d --"), this, err);
  1624 }
  1625 
  1626 TInt CNGAPostProcHwDevice::SetupExternalSurface(const TSurfaceId &aSurfaceID)
  1627 {
  1628 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface(): aSurfaceID = 0x%x"), this, aSurfaceID );
  1629 
  1630     TInt err = KErrNone;
  1631     
  1632     if(!iSurfaceId.IsNull())
  1633     {
  1634 		if (iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1635 		{
  1636 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Telling client to remove old surface"), this);
  1637 			iVideoSurfaceObserver->MmvsoRemoveSurface();
  1638 			iSurfaceCreatedEventPublished = EFalse;
  1639 		}
  1640 		else
  1641 		{
  1642 			// We never told the client about the surface, so we must destroy it ourselves
  1643 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Destroying old surface"), this);
  1644 			TInt numScreens = iWsSession.NumberOfScreens();
  1645     		for(TInt i=0;i < numScreens;i++)
  1646     		{
  1647     			iWsSession.UnregisterSurface(i, iSurfaceId);
  1648     		}
  1649    			iWsSession.Flush();
  1650 			iSurfaceHandler->DestroySurface(iSurfaceId);
  1651 		}
  1652 
  1653 		iChunk.Close();
  1654 	}
  1655     
  1656     iSurfaceId            = aSurfaceID;
  1657     iUsingExternalSurface = ETrue;
  1658     iRedrawSurfaceInUse = EFalse;
  1659 
  1660     // Create the surface handler if it doesn't exist.
  1661     if (!iSurfaceHandler)
  1662     {
  1663         TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
  1664         if (err != KErrNone)
  1665         {
  1666            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to create SurfaceHandler."), this);
  1667             return err;
  1668         }
  1669     }
  1670     
  1671     err = iSurfaceHandler->OpenSurface(iSurfaceId);
  1672     if (err != KErrNone)
  1673 	{
  1674 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed OpenSurface %d"), 
  1675 	   				this, err);
  1676 	    return err;
  1677 	}
  1678     err = AddHints();
  1679     if (err != KErrNone)
  1680     {
  1681         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to AddHints %d"), 
  1682                     this, err);
  1683         return err;
  1684     }
  1685 	err = RegisterSurface(iSurfaceId);
  1686 	if (err != KErrNone)
  1687 	{
  1688 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed RegisterSurface %d"), 
  1689 	   				this, err);
  1690 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1691 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1692 	    return err;
  1693 	}
  1694 
  1695     err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1696     if (err != KErrNone)
  1697     {
  1698         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to get Surface info %d"), 
  1699                      this, err);
  1700         return err;
  1701     }
  1702  
  1703   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface err=%d"), this, err);
  1704    return err;
  1705 }
  1706 
  1707 //=== Internal ===
  1708 TVideoPicture* CNGAPostProcHwDevice::CreateBuffersL(TInt aBufId)
  1709 {
  1710 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL ++"), this);
  1711 	
  1712 	TVideoPicture*          lVideoPicture = NULL;
  1713     TUint8*                 lPtr;
  1714     TPtr8*                  lTemp;
  1715     TInt 					offset;
  1716     
  1717 	lVideoPicture = new (ELeave) TVideoPicture;
  1718     CleanupStack::PushL(lVideoPicture);
  1719     if(TInt err = iSurfaceHandler->GetBufferOffset(iSurfaceId, aBufId, offset) != KErrNone)
  1720     {
  1721     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL offset query failed %d"), this, err);
  1722     }
  1723     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL offset = %d id =%d --"), this, offset, aBufId);
  1724     
  1725 	lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
  1726 
  1727     lTemp = new (ELeave) TPtr8(lPtr, 0, (iVideoFrameBufSize ));
  1728     CleanupStack::PushL(lTemp);
  1729 
  1730     lVideoPicture->iData.iRawData   = lTemp;
  1731     lVideoPicture->iHeader = NULL ;
  1732     lVideoPicture->iLayerBitRates = NULL ;
  1733     
  1734     CleanupStack::Pop(2);
  1735     
  1736    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL --"), this);
  1737     return lVideoPicture;
  1738 }
  1739 
  1740 void CNGAPostProcHwDevice::CreateVBMBuffersL()
  1741 {
  1742 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL ++"), this);
  1743     
  1744     TInt err = KErrNone;
  1745     TVideoPicture* pic = NULL;
  1746     iVBMBufferReferenceQ.Reset();
  1747     iVBMBufferQ.Reset();
  1748     iColorConversionQ.Reset();
  1749 
  1750     for(TInt i = 0; i < iVBMBufferOptions.iNumInputBuffers; i++)
  1751     {
  1752         TRAP(err, pic = CreateBuffersL(i));
  1753 	    	if (err != KErrNone)
  1754 	    	{
  1755 	    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  1756 	    	    User::Leave(err);
  1757 	    	}
  1758 
  1759         // This will hold the references which will be used in destructor
  1760         User::LeaveIfError(iVBMBufferReferenceQ.Append(pic));
  1761         User::LeaveIfError(iVBMBufferQ.Append(pic));
  1762     }
  1763     if(iIsColorConversionNeeded)
  1764     {
  1765 		    for(TInt i = iVBMBufferOptions.iNumInputBuffers ; 
  1766 		    				 i < (iVBMBufferOptions.iNumInputBuffers + KColorConversionBuffers ); i++)
  1767 		    {
  1768 		        TRAP(err, pic = CreateBuffersL(i));
  1769 			    	if (err != KErrNone)
  1770 			    	{
  1771 			    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  1772 			    	    User::Leave(err);
  1773 			    	}
  1774 		
  1775 		        // This will hold the references which will be used in destructor
  1776 		        User::LeaveIfError(iVBMBufferReferenceQ.Append(pic));
  1777 		        User::LeaveIfError(iColorConversionQ.Append(pic));
  1778 		    }
  1779 		}
  1780 	    
  1781 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL --"), this);
  1782 }
  1783 
  1784 void CNGAPostProcHwDevice::ReturnPicToDecoder(TVideoPicture* aPic)
  1785 {
  1786    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicToDecoder ++"), this);
  1787 	if (aPic == NULL)
  1788 	{
  1789 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture FAILED: Invalid pic ptr."), this);
  1790 		return;
  1791 	}
  1792 	
  1793    	if (iInputDecoderDevice)
  1794     {
  1795        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture .. before return picture. 2"), this);
  1796         iInputDecoderDevice->ReturnPicture(aPic);
  1797     }
  1798 	
  1799 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicToDecoder --"), this);
  1800 }
  1801 
  1802 TInt CNGAPostProcHwDevice::AttemptToPost()
  1803 {
  1804    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost ++ Q:%d"), this, iInputQ.Count());
  1805    if (iPPState == EPaused)
  1806    {
  1807         return KErrNone;
  1808    }
  1809 
  1810     TInt err = KErrNotReady;
  1811     TInt count = iInputQ.Count();
  1812     TBool bDone = EFalse;
  1813     TVideoPicture* pic = PeekQ();   		
  1814   	while(pic && !bDone)
  1815   	{
  1816 	    if(!IsGceReady())
  1817 		{  
  1818 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost GCE not ready"), this );
  1819 			return err; //no need to catch this error
  1820 		}
  1821 		TInt64 delta = 0;
  1822 		TTimeToPost	iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
  1823 		switch(iTimeToPost)
  1824 		{
  1825 			case EDelayIt:
  1826 			{
  1827 				iPostingTimer->Cancel();
  1828 				SetTimer(delta);
  1829 				bDone = ETrue;
  1830 			}
  1831 			break;
  1832 			case EPostIt:
  1833 			{
  1834 				RemoveFromQ(); // remove the pic that was returned by PeekQ				
  1835 				if(iIsColorConversionNeeded)
  1836 				{
  1837 				    TVideoPicture* ccPic;
  1838     				ccPic = DoColorConvert(pic); // output will be in ccPic
  1839     				pic = ccPic;
  1840 			    }
  1841 				iProcessQ.Append(pic);
  1842                 #ifdef _DUMP_YUV_FRAMES
  1843                     captureYuv(pic);
  1844                 #endif
  1845 				iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue); 
  1846 				iCurrentPlaybackPosition = pic->iTimestamp;						 					
  1847 				if(!iFirstPictureUpdated)
  1848 				{
  1849 					iFirstPictureUpdated = ETrue;
  1850                     if(!iSurfaceCreatedEventPublished)
  1851                     {
  1852                         PublishSurfaceCreated();
  1853                     }
  1854 				}	
  1855 			}	// end of postit
  1856 			break;
  1857 			case ESkipIt: 
  1858 			{
  1859 				RemoveFromQ();
  1860 				ReleasePicture(pic);
  1861 				PicturesSkipped();				
  1862 			}
  1863 			break;
  1864 		} // end of switch
  1865 		
  1866 		// get the next picture
  1867 		pic = PeekQ();	
  1868     } // end of while
  1869     
  1870    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost --"), this);
  1871  	return err;
  1872 }
  1873 
  1874 TInt CNGAPostProcHwDevice::IsTimeToPost(TVideoPicture* frame, TInt64& delta)
  1875 {
  1876    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost ++"), this);
  1877 
  1878     if (!frame)
  1879     {
  1880 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost FAILED: Invalid frame ptr."), this);
  1881 		return KErrGeneral;
  1882 	}
  1883 
  1884     TInt resp = EPostIt;
  1885     // Frame presentation time
  1886     TInt64 uPresTime = frame->iTimestamp.Int64();
  1887       
  1888     // Check if this is an out of order frame in case of forward playback
  1889     if((iCurrentPlaybackPosition.Int64() > uPresTime) && (iPlayRate > 0))    
  1890     {      
  1891          PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (forward playback) Tfm=%d"), this,(TInt)uPresTime);
  1892          resp = ESkipIt;  //drop      
  1893     }      // Check if this is an out of order frame in case of backward playback
  1894     else if((iCurrentPlaybackPosition.Int64() < uPresTime) && (iPlayRate < 0))    
  1895     {      
  1896         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (backward playback) Tfm=%d"), this,(TInt)uPresTime);
  1897         resp = ESkipIt;  //drop      
  1898     }
  1899     else if (iClockSource)
  1900     {
  1901         // The time to sync with.
  1902         TInt64 uSyncTime = iClockSource->Time().Int64();
  1903         
  1904         delta = uPresTime - uSyncTime;
  1905         if (( delta > KRenderAhead ) &&  (iPlayRate > 0))	// Delay condition not checked for 
  1906         {													// backward playback
  1907         	resp = EDelayIt;  //wait
  1908         }
  1909         else if ( (delta < (-KMaxRenderDelay) && (iPlayRate > 0))
  1910           		||  ((delta > KMaxRenderDelay) && (iPlayRate < 0)))
  1911         {
  1912             resp = ESkipIt;  //drop
  1913         }
  1914        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost .. Tfm=%d, Tcs=%d, delta=%d"), this, (TInt)uPresTime, (TInt)uSyncTime, (TInt)delta);
  1915     }       
  1916    
  1917    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost -- %d BufID = %d"), this, resp, GetID(frame));
  1918     return resp;
  1919 }
  1920 
  1921 void CNGAPostProcHwDevice::ReleaseInputQ()
  1922 {
  1923 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputQ ++ Q = %d"), this, iInputQ.Count());
  1924     while (iInputQ.Count()>0)
  1925     {
  1926     	ReleasePicture(iInputQ[0]);
  1927         iInputQ.Remove(0);
  1928     }
  1929    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputQ --"), this);
  1930 }
  1931 
  1932 void CNGAPostProcHwDevice::ReleaseProcessQ()
  1933 {
  1934 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseProcessQ ++ Q = %d"), this, iProcessQ.Count() );
  1935 	TVideoPicture* pic = NULL;
  1936 	
  1937     while (iProcessQ.Count()>0)
  1938     {
  1939 		pic = iProcessQ[0];
  1940 		iProcessQ.Remove(0);
  1941 		ReturnPicToDecoder(pic);
  1942     }
  1943    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseProcessQ --"), this);
  1944 }
  1945 
  1946 void CNGAPostProcHwDevice::ReleasePicture(TVideoPicture *pic)
  1947 {
  1948    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleasePicture ++"), this);
  1949 	if (pic == NULL)
  1950 	{
  1951 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture FAILED: Invalid pic ptr."), this);
  1952 		return;
  1953 	}
  1954 	
  1955    	if (iInputDecoderDevice)
  1956     {
  1957        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture .. before return picture. 2"), this);
  1958         iInputDecoderDevice->ReturnPicture(pic);
  1959     }
  1960 	if (iVBMEnabled)
  1961     {
  1962         iVBMBufferQ.Append(pic);
  1963 
  1964         if ( !iIsInputEnded && iPPState != EStopped )
  1965         {
  1966             iVBMObserver->MmvbmoNewBuffers();
  1967         }
  1968 	}
  1969 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleasePicture --"), this);
  1970 }
  1971 
  1972 void CNGAPostProcHwDevice::PublishSurfaceCreated()
  1973 {
  1974 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PublishSurfaceCreated ++"), this);   
  1975 	if(iVideoSurfaceObserver)
  1976 	{
  1977 		iVideoSurfaceObserver->MmvsoSurfaceCreated();
  1978 		iSurfaceCreatedEventPublished = ETrue;
  1979 	}
  1980     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PublishSurfaceCreated --"), this);
  1981 }
  1982 
  1983 TInt CNGAPostProcHwDevice::SetupSurface(const TSize& aSize)
  1984 {
  1985 	TInt err = KErrNone;
  1986 	if(iVBMEnabled && iVBMObserver)
  1987     {
  1988     	SetSurfaceAttributes(aSize, KMaxVBMBuffers);
  1989 	    iVBMBufferOptions.iNumInputBuffers    = KMaxVBMBuffers;
  1990 	    
  1991 	    //Decoder needs the buffer size to fit in yuv422 decoded output.
  1992 	    iVBMBufferOptions.iBufferSize = aSize;
  1993     	
  1994 	  	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1995 	  	if (err != KErrNone)
  1996     	{
  1997     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create Surface %d"), this, err);
  1998     	    return err;
  1999     	}
  2000     	err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
  2001     	if (err != KErrNone)
  2002     	{
  2003     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to map Surface %d"), this, err);
  2004     	  	iSurfaceHandler->DestroySurface(iSurfaceId);
  2005 	   		iSurfaceId = TSurfaceId::CreateNullId();
  2006     	    return err;
  2007     	}
  2008     	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  2009     	if (err != KErrNone)
  2010     	{
  2011     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to get Surface info %d"), this, err);
  2012     	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  2013 	   		iSurfaceId = TSurfaceId::CreateNullId();
  2014     	    return err;
  2015     	}
  2016     	TRAP(err, CreateVBMBuffersL());
  2017     	if (err != KErrNone)
  2018     	{
  2019     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  2020     	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  2021 	   		iSurfaceId = TSurfaceId::CreateNullId();
  2022     	    return err;
  2023     	}
  2024         err = AddHints();
  2025         if (err != KErrNone)
  2026         {
  2027             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to AddHints %d"), this, err);
  2028             return err;
  2029         }
  2030         err = RegisterSurface(iSurfaceId);
  2031         if (err != KErrNone)
  2032         {
  2033             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to RegisterSurface %d"), this, err);
  2034             iSurfaceHandler->DestroySurface(iSurfaceId);
  2035             iSurfaceId = TSurfaceId::CreateNullId();
  2036             return err;
  2037         }
  2038 
  2039     }
  2040     return err;
  2041 } 
  2042 
  2043 void CNGAPostProcHwDevice::SetSurfaceAttributes(const TSize& aSize, TInt aNumBuf)
  2044 {
  2045 	iAttributes().iSize                   = aSize; // size of the video frame
  2046     iAttributes().iBuffers            	  = aNumBuf;
  2047     
  2048     /* The stride needs to be calculated for the surface manager to know
  2049     how much memory to allocate */
  2050     
  2051     if(iAttributes().iPixelFormat == EUidPixelFormatYUV_420Planar)
  2052     	{
  2053     		iAttributes().iStride       = aSize.iWidth * 3/2;
  2054     		iVideoFrameBufSize			= aSize.iWidth * aSize.iHeight * 3/2;
  2055     	}
  2056     	else
  2057     	{
  2058     		iAttributes().iStride       = aSize.iWidth * 2;
  2059     		iVideoFrameBufSize			= aSize.iWidth * aSize.iHeight * 2;
  2060     	}
  2061     		
  2062     if(iIsColorConversionNeeded)
  2063     {
  2064     	iAttributes().iBuffers            = aNumBuf + KColorConversionBuffers;
  2065     }
  2066     else
  2067     {
  2068     	iAttributes().iBuffers            = aNumBuf;	
  2069     }
  2070     
  2071     iAttributes().iOffsetToFirstBuffer    = 0;
  2072     iAttributes().iAlignment              = 4;
  2073     iAttributes().iContiguous             = ETrue;
  2074     iAttributes().iHintCount              = 0;
  2075     iAttributes().iMappable               = ETrue;
  2076 }
  2077 
  2078 TInt CNGAPostProcHwDevice::GetID(TVideoPicture *aPicture)
  2079 {
  2080     if (iUsingExternalSurface)
  2081     {
  2082 	    return GetExternalBufferID(aPicture);
  2083     }
  2084     else
  2085     {
  2086         TUint8* aPtr = (TUint8*) aPicture->iData.iRawData->Ptr();
  2087         return( (TInt) ((aPtr - iChunk.Base() - iAttributes().iOffsetToFirstBuffer) / 
  2088 			(iVideoFrameBufSize )));
  2089     }
  2090 }
  2091 
  2092 TInt CNGAPostProcHwDevice::GetExternalBufferID(TVideoPicture *aPicture)
  2093 {
  2094     // currently type cast the pointer as buffer ID.
  2095     // FIXME once the new data structure is available.
  2096     return( (TInt) aPicture->iData.iRawData->Ptr());
  2097 }
  2098 
  2099 TInt CNGAPostProcHwDevice::RegisterSurface(const TSurfaceId& aSurfaceId)
  2100 {
  2101 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:RegisterSurface(): RegisterSurface ID = 0x%x"), this, aSurfaceId);
  2102 	TInt err = KErrNone;
  2103 	TInt numScreens = iWsSession.NumberOfScreens();
  2104 	for(TInt i=0; (i < numScreens && err == KErrNone); i++)
  2105 	{
  2106 		err = iWsSession.RegisterSurface(i, aSurfaceId);
  2107 	}	
  2108 	return(err);
  2109 }
  2110 
  2111 TInt CNGAPostProcHwDevice::IsGceReady()
  2112 {
  2113     if(iProcessQ.Count() >= KMaxBuffersGceCanHold)
  2114     {
  2115     		return EFalse;
  2116     }
  2117     return ETrue;
  2118 }
  2119 
  2120 void CNGAPostProcHwDevice::SetTimer(TInt64 aDelta)
  2121 {
  2122 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetTimer .. aDelta=%d"), this, (TInt)aDelta);
  2123 	if(aDelta <= KRenderAhead)
  2124 	{
  2125 		if(aDelta < 0)
  2126 		{
  2127 			iPostingTimer->After(aDelta * -1);
  2128 		}
  2129 		else
  2130 		{
  2131 			iPostingTimer->After((aDelta - KRenderAhead) * -1);
  2132 		}
  2133 	}
  2134 	else
  2135 	{
  2136 		iPostingTimer->After(aDelta - KRenderAhead - KPostingOfset);
  2137 	}
  2138 }
  2139 //
  2140 // Convert YUV420 to YUV422InterLeaved.
  2141 //
  2142 TInt CNGAPostProcHwDevice::ConvertPostProcBuffer(TVideoPicture* pSrc, TVideoPicture* pDest)
  2143 {
  2144     PP_DEBUG(_L("CMdfPostingSurfaceProxy::ConvertPostProcBuffer ++"));
  2145     TInt err = KErrNone;
  2146     if (!pDest && !pSrc)
  2147 	{
  2148 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ConvertPostProcBuffer FAILED: Invalid pic pSrc %x pDest %x."), this, pSrc, pDest);
  2149 		return KErrArgument;
  2150 	}
  2151     
  2152     // --- Prepare wrappers ---
  2153     tBaseVideoFrame tFrame420, tFrame422;
  2154     TInt    frameSize = pSrc->iData.iDataSize.iWidth * pSrc->iData.iDataSize.iHeight;
  2155 
  2156    PP_DEBUG(_L("CMdfPostingSurfaceProxy::ConvertPostProcBuffer .. w=%d, h=%d"), pSrc->iData.iDataSize.iWidth, pSrc->iData.iDataSize.iHeight);
  2157 
  2158     tFrame420.width = pSrc->iData.iDataSize.iWidth;
  2159     tFrame420.height= pSrc->iData.iDataSize.iHeight;
  2160     tFrame420.lum   = (TUint8*)pSrc->iData.iRawData->Ptr();
  2161     tFrame420.cb    = (TUint8*)tFrame420.lum + frameSize;
  2162     tFrame420.cr    = (TUint8*)tFrame420.lum + (frameSize*5)/4;
  2163     
  2164     tFrame422.width = pSrc->iData.iDataSize.iWidth;
  2165     tFrame422.height= pSrc->iData.iDataSize.iHeight;
  2166     tFrame422.lum   = (TUint8*)pDest->iData.iRawData->Ptr();
  2167     tFrame422.cb    = 0;
  2168     tFrame422.cr    = 0;
  2169     
  2170     // --- Convertion to posting buffer ---
  2171     TInt stride     = pSrc->iData.iDataSize.iWidth * 2;
  2172     EBufferLayout422 layout = YUV422INT_BE;
  2173         
  2174     err = gColorConvYUVtoYUV422Int(&tFrame420, &tFrame422, layout, stride);
  2175     if(err != KErrNone)
  2176     {
  2177     		PP_DEBUG(_L("CNGAPostProcHwDevice::ConvertPostProcBuffer .. err= %d."), err);
  2178     }
  2179 	return err;
  2180 }   
  2181 
  2182 void CNGAPostProcHwDevice::AddPictureToVBMQ(TVideoPicture *pic)
  2183 {
  2184    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToVBMQ ++"), this);
  2185     iVBMBufferQ.Append(pic);
  2186 
  2187     if ( !iIsInputEnded && iPPState != EStopped )
  2188     {
  2189         iVBMObserver->MmvbmoNewBuffers();
  2190     }
  2191 	
  2192 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToVBMQ --"), this);
  2193 }
  2194 
  2195 void CNGAPostProcHwDevice::AddPictureToColorConversionQ(TVideoPicture *pic)
  2196 {
  2197 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToColorConversionQ ++"), this);
  2198     iColorConversionQ.Append(pic);
  2199    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToColorConversionQ --"), this);
  2200 }
  2201 
  2202 #ifdef _DUMP_YUV_FRAMES
  2203 void CNGAPostProcHwDevice::captureYuv(TVideoPicture* aPicture)
  2204 {
  2205 	char buf[128];              
  2206 	sprintf(buf, "c:\\fb%d.yuv", count++);          
  2207 	FILE *fp = ::fopen(buf, "w");
  2208 	TInt size = aPicture->iData.iRawData->Size();
  2209 	//{FILE* f1 = fopen(MY_LOG_FILE_NAME, "a+"));if(f1){fprintf(f1, "Size  %d \n"), size );fclose(f1); }}
  2210 
  2211 	::fwrite(aPicture->iData.iRawData->Ptr(), 1, size, fp);
  2212 	::fclose(fp);    	
  2213 }
  2214 #endif
  2215 
  2216 void CNGAPostProcHwDevice::ResetCountingBuffer()
  2217 {       
  2218 	memset(iSkippedFramesCountingBuffer,0,sizeof(iSkippedFramesCountingBuffer));
  2219     iSkippedFramesInLast64Frames = 0;       
  2220     iCurrentPosInFramesCountingBuffer = 0;       
  2221 } 
  2222 
  2223 void CNGAPostProcHwDevice::PicturesSkipped()
  2224 {       
  2225 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PicturesSkipped ++"), this);
  2226 	iPictureCounters.iPicturesSkipped++;
  2227 	if (!iKeyFrameMode && iPlayRate>KDefPlayRate)
  2228     {       
  2229     	if (iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer]==0)        
  2230         {       
  2231         	iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer] = 1;       
  2232             iSkippedFramesInLast64Frames++;       
  2233             if (iSkippedFramesInLast64Frames>KMaxAllowedSkipInNFrames && iFPObserver )       
  2234             {       
  2235             	iFPObserver->MmvproKeyFrameModeRequest();       
  2236                 iKeyFrameMode=ETrue;       
  2237                 ResetCountingBuffer();       
  2238             }       
  2239         }       
  2240         iCurrentPosInFramesCountingBuffer = ++iCurrentPosInFramesCountingBuffer%64;       
  2241     }
  2242     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PicturesSkipped --"), this);   
  2243 }
  2244 
  2245 TVideoPicture* CNGAPostProcHwDevice::DoColorConvert(TVideoPicture* aPicture)
  2246 {
  2247     TVideoPicture *pOutPicture  = aPicture;
  2248     					    		
  2249 	if(iColorConversionQ.Count())
  2250     {
  2251 	    pOutPicture    = iColorConversionQ[0];
  2252 	    iColorConversionQ.Remove(0);
  2253 	    ConvertPostProcBuffer(aPicture, pOutPicture);
  2254 	   	pOutPicture->iTimestamp = aPicture->iTimestamp;
  2255 	    ReleasePicture(aPicture);    	    
  2256     }				    
  2257     else
  2258     {
  2259        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: color conversion"), this);
  2260     }
  2261 
  2262 	return pOutPicture;
  2263 }
  2264 
  2265 TInt CNGAPostProcHwDevice::AddToQ(TVideoPicture* aPicture)
  2266 {
  2267 	TVideoPicture* pic = aPicture;
  2268 	TInt pos = -1;
  2269 	if(iInputQ.Count() == 0)
  2270 	{
  2271 		iInputQ.Append(pic);
  2272 	}
  2273 	else
  2274 	{
  2275 		pos = iInputQ.Count()-1;
  2276 		for(; pos >= 0; pos--)
  2277 		{
  2278 			if(pic->iTimestamp.Int64() > iInputQ[pos]->iTimestamp.Int64())
  2279 			{
  2280 				break;
  2281 			}
  2282 		} 
  2283 		if(iInputQ.Count() == pos+1)
  2284 		{
  2285 			iInputQ.Append(pic);
  2286 		}
  2287 		else
  2288 		{
  2289 			iInputQ.Insert(pic, pos+1);
  2290 		}
  2291 	}
  2292 	return pos+1;
  2293 }
  2294 
  2295 void CNGAPostProcHwDevice::RemoveFromQ()
  2296 {
  2297 	if(iInputQ.Count())
  2298 	{
  2299 		if(iPlayRate > 0)
  2300 		{
  2301 			iInputQ.Remove(0);
  2302 		}
  2303 		else
  2304 		{
  2305 			iInputQ.Remove(iInputQ.Count()-1);
  2306 		}
  2307 	}
  2308 }
  2309 
  2310 TVideoPicture* CNGAPostProcHwDevice::PeekQ()
  2311 {	
  2312 	TVideoPicture *pic = NULL;
  2313 	if(iInputQ.Count())
  2314 	{
  2315 		if(iPlayRate > 0)
  2316 		{			
  2317 			pic = iInputQ[0];
  2318 		}
  2319 		else
  2320 		{			
  2321 			pic = iInputQ[iInputQ.Count()-1];
  2322 		}	
  2323 	}
  2324 	return pic;
  2325 }
  2326 
  2327 TInt CNGAPostProcHwDevice::AddHints()
  2328 {
  2329    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints iSurfaceMask 0x%08x ++"), this, iSurfaceMask);
  2330    TInt err = KErrNone;
  2331    iHint.Set(iSurfaceKey,iSurfaceMask,ETrue);
  2332    err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
  2333    if(err == KErrAlreadyExists)
  2334    {
  2335 		err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
  2336    }
  2337    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
  2338    iHint.iKey.iUid = surfaceHints::KSurfaceContent;
  2339    iHint.iValue = surfaceHints::EVideoPlayback;
  2340    iHint.iMutable = ETrue;
  2341    err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
  2342    if(err == KErrAlreadyExists)
  2343    {
  2344 		err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
  2345    }
  2346    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
  2347    if(iUsingExternalSurface)
  2348    {
  2349    		iHint.iKey.iUid = surfaceHints::KSurfaceCharacteristics;
  2350    		iHint.iValue = surfaceHints::ENotPersistable;
  2351    		iHint.iMutable = ETrue;
  2352 	    err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
  2353 	    if(err == KErrAlreadyExists)
  2354 	    {
  2355 			err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
  2356 	    }
  2357 	    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
  2358 	}
  2359    return err;
  2360 }
  2361 
  2362 TInt CNGAPostProcHwDevice::ColorConvert(tBaseVideoFrame* aInputFrame, TUint8* aDestPtr, tWndParam* aInputCropWindow, tWndParam* aOutputCropWindow)
  2363 {
  2364 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert ++"), this);
  2365 	__ASSERT_ALWAYS(aDestPtr, User::Invariant());
  2366 	TInt				lError = E_SUCCESS;
  2367 	TInt				err = KErrNone;
  2368 	
  2369 	err = SetSourceFormat();
  2370 	if(err == KErrNone)
  2371 	{
  2372     	err = SetSourceRange();
  2373     	if(err == KErrNone)
  2374     	{
  2375 						
  2376 			lError = Emz_VDec_gColorConv_YUVtoRGB(aInputFrame,aDestPtr, 
  2377 						aInputCropWindow, aOutputCropWindow, iSourceFormat,
  2378 						EBitmapColor16MU, iSourceRange);
  2379 
  2380 			if(lError)
  2381 			{
  2382 				if(lError == E_OUT_OF_MEMORY)
  2383 					{
  2384 					err = KErrNoMemory;
  2385 					}
  2386 				else if(lError == E_FAILURE)
  2387 					{
  2388 					err = KErrNotSupported;
  2389 					}
  2390 				else
  2391 					{
  2392 					err = KErrGeneral;
  2393 					}
  2394 			}
  2395 		}
  2396 	}
  2397 	
  2398 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert --"), this);
  2399 	return err;
  2400 }
  2401 
  2402 TInt CNGAPostProcHwDevice::SetSourceFormat()
  2403 {
  2404 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL ++"), this);
  2405 	TInt err = KErrNone;
  2406 	switch (iVideoFormat.iYuvFormat.iPattern)
  2407 	{
  2408 	    case EYuv420Chroma1:
  2409     		iSourceFormat = EYuv420Chroma1_Planar;
  2410     		break;
  2411         case EYuv420Chroma2:
  2412     		iSourceFormat = EYuv420Chroma2_Planar;
  2413     		break;
  2414         case EYuv420Chroma3:
  2415     		iSourceFormat = EYuv420Chroma3_Planar;
  2416     		break;
  2417 	    case EYuv422Chroma1:
  2418 			if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
  2419     			iSourceFormat = EYuv422Chroma1_LE;
  2420 	    	else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
  2421 				iSourceFormat = EYuv422Chroma1_BE;
  2422 			else
  2423 			    err = KErrArgument;
  2424 			break;
  2425     	case EYuv422Chroma2:
  2426     		if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
  2427 	    		iSourceFormat = EYuv422Chroma2_LE;
  2428     		else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
  2429     			iSourceFormat = EYuv422Chroma2_BE;
  2430 			else
  2431 			    err = KErrArgument;
  2432 			break;
  2433       default:
  2434     		err = KErrNotSupported;
  2435 	}
  2436 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL --"), this);
  2437 	return err;
  2438 }
  2439 
  2440 
  2441 TInt CNGAPostProcHwDevice::SetSourceRange()
  2442 {
  2443 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL ++"), this);
  2444 	TInt err = KErrNone;
  2445 	switch (iVideoFormat.iYuvFormat.iCoefficients)
  2446 	{
  2447 	    case EYuvBt601Range0:
  2448 			iSourceRange = EITU601_5_REDUCEDRANGE;
  2449             break;
  2450         case EYuvBt601Range1:
  2451 			iSourceRange = EITU601_5_FULLRANGE;
  2452 			break;
  2453         case EYuvBt709Range0:
  2454 			iSourceRange = EB709_REDUCEDRANGE;
  2455 			break;
  2456         case EYuvBt709Range1:
  2457 			iSourceRange = EB709_FULLRANGE;
  2458             break;
  2459 	    default:
  2460 		    err = KErrNotSupported;
  2461     }
  2462     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL --"), this);
  2463     return err;
  2464 }
  2465 
  2466 CNGAPostProcTimer::CNGAPostProcTimer( CNGAPostProcHwDevice& aParent )
  2467 :CTimer(EPriorityHigh),iParent(aParent)
  2468 {
  2469 	CActiveScheduler::Add(this);
  2470 }
  2471 
  2472 CNGAPostProcTimer::~CNGAPostProcTimer()
  2473 {
  2474 	PP_DEBUG(_L("CNGAPostProcTimer[%x]:~CNGAPostProcTimer ++"), this);
  2475 	Cancel();
  2476 	PP_DEBUG(_L("CNGAPostProcTimer[%x]:~CNGAPostProcTimer --"), this);
  2477 }
  2478 
  2479 CNGAPostProcTimer* CNGAPostProcTimer::NewL( CNGAPostProcHwDevice& aParent )
  2480 {
  2481 	CNGAPostProcTimer* self = new (ELeave)CNGAPostProcTimer(aParent);
  2482 	CleanupStack::PushL( self );
  2483 	self->ConstructL();
  2484 	CleanupStack::Pop( self );
  2485 	return self;
  2486 }
  2487 
  2488 void CNGAPostProcTimer::ConstructL()
  2489 {
  2490 	CTimer::ConstructL();
  2491 }
  2492 
  2493 void CNGAPostProcTimer::RunL()
  2494 {
  2495 	PP_DEBUG(_L("CNGAPostProcTimer[%x]:RunL ++"), this);
  2496 	if (iStatus ==KErrCancel)
  2497 	{
  2498 		PP_DEBUG(_L("CNGAPostProcNotifier[%x]:CNGAPostProcNotifier:RunL State canceled"), this);
  2499 		return;
  2500 	}
  2501 	iParent.AttemptToPost();
  2502 	PP_DEBUG(_L("CNGAPostProcTimer[%x]:RunL --"), this);
  2503 }
  2504