os/mm/mdfdevvideoextensions/nga_mdf_postprocessor_shai/src/NGAPostProcHwDevice.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mdfdevvideoextensions/nga_mdf_postprocessor_shai/src/NGAPostProcHwDevice.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2689 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "NGAPostProcHwDevice.h"
    1.23 +#include "NGAPostProcSessionManager.h"
    1.24 +#include "NGAPostProcSurfaceHandler.h"
    1.25 +
    1.26 +//currently this uid only used if not under WINSCW environment since the only hw to use is bridge
    1.27 +#define EStUidPixelFormatYUV_420MB  0x2001FBC1
    1.28 +// post-processor info
    1.29 +const TUid KUidVideoPostProcHwDevice = {KUidNGAPostProcHwDeviceImplUid};
    1.30 +_LIT(KManufacturer, "Nokia Inc.");
    1.31 +_LIT(KIdentifier, "Nokia S60 Video Post Processor Hardware Device Plugin");
    1.32 +
    1.33 +// --- Constants ---
    1.34 +const TInt KMaxVBMBuffers      			= 4;
    1.35 +const TInt KMinVBMInputWidth   			= 32; 
    1.36 +const TInt KMinVBMInputHeight  			= 32;
    1.37 +const TInt KMaxVBMInputWidth   			= 1280; 
    1.38 +const TInt KMaxVBMInputHeight  			= 720;
    1.39 +const TInt KRenderAhead 	     		= 50000;     
    1.40 +const TInt KMaxRenderDelay     			= 50000;
    1.41 +const TInt KPostingOfset       			= 0;    
    1.42 +const TInt KColorConversionBuffers  	= 3;
    1.43 +const TInt KMaxBuffersGceCanHold    	= 3;
    1.44 +const TInt KDefPlayRate					= 100;
    1.45 +const TInt KMaxAllowedSkipInNFrames 	= 40;
    1.46 +#ifdef __cplusplus
    1.47 +extern "C"
    1.48 +{
    1.49 +#endif
    1.50 +
    1.51 +int32 gColorConvYUVtoYUV422Int (tBaseVideoFrame *yuv420Frame, tBaseVideoFrame* yuv422Frame,
    1.52 +							   uint8 outClrFmt, int16 stride); 
    1.53 +
    1.54 +int32 Emz_VDec_gColorConv_YUVtoRGB ( 
    1.55 +	  tBaseVideoFrame *srcImage, uint8 *dstImage, tWndParam *srcWindow, 
    1.56 +	  tWndParam *dstWindow, uint8 srcImageFormat, uint8 dstImageFormat,
    1.57 +	  uint8 colorConvScheme);
    1.58 +		 	  
    1.59 +#ifdef __cplusplus
    1.60 +}
    1.61 +#endif
    1.62 +
    1.63 +//**************************************************
    1.64 +
    1.65 +CMMFVideoPostProcHwDevice* CNGAPostProcHwDevice::NewL() 
    1.66 +{ 
    1.67 +   PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() ++"));
    1.68 +
    1.69 +    CNGAPostProcHwDevice* self = new (ELeave) CNGAPostProcHwDevice; 
    1.70 +    CleanupStack::PushL(self);
    1.71 +    self->ConstructL(); 
    1.72 +    CleanupStack::Pop();
    1.73 +
    1.74 +   PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() --"));
    1.75 +    return (CMMFVideoPostProcHwDevice*)self; 
    1.76 +}
    1.77 +
    1.78 +void CNGAPostProcHwDevice::ConstructL() 
    1.79 +{ 
    1.80 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() ++"), this);
    1.81 +    
    1.82 +    // support for VBM buffer interface
    1.83 +    iVBMBufferOptions.iNumInputBuffers  = KMaxVBMBuffers; 
    1.84 +    iVBMBufferOptions.iBufferSize = TSize(KMaxVBMInputWidth, KMaxVBMInputHeight);
    1.85 +    iPostingTimer = CNGAPostProcTimer::NewL(*this);
    1.86 +    User::LeaveIfError(iWsSession.Connect());
    1.87 +    
    1.88 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() --"), this);
    1.89 +}
    1.90 +
    1.91 +CNGAPostProcHwDevice::CNGAPostProcHwDevice() 
    1.92 +        :   iProxy(NULL), 
    1.93 +            iInputDecoderDevice(NULL),
    1.94 +            iCurrentPlaybackPosition(TTimeIntervalMicroSeconds(0)),
    1.95 +            iPPState(EInitializing),
    1.96 +            iSurfaceHandler(NULL),
    1.97 +            iSessionManager(NULL),
    1.98 +            iIsInputEnded(EFalse),
    1.99 +            iPostingTimer(NULL),
   1.100 +            iFirstPictureUpdated(EFalse),
   1.101 +            iUsingExternalSurface(EFalse),
   1.102 +            iIsColorConversionNeeded(EFalse),
   1.103 +            iSurfaceCreatedEventPublished(EFalse),
   1.104 +            iOverflowPictureCounter(0),
   1.105 +            iVideoFrameBufSize(0),
   1.106 +            iResourceLost(EFalse),
   1.107 +            iRedrawDone(EFalse),
   1.108 +			iRedrawSurfaceInUse(EFalse),
   1.109 +            iVBMObserver(NULL),
   1.110 +            iVBMEnabled(EFalse),        
   1.111 +            count(0),
   1.112 +            iSurfaceMask(surfaceHints::EAllowAllExternals),
   1.113 +            iSurfaceKey(TUid::Uid(surfaceHints::KSurfaceProtection)),
   1.114 +            iVideoSurfaceObserver(NULL),
   1.115 +            iVPObserver(NULL),
   1.116 +            iPicSize(0,0),
   1.117 +			iAspectRatioNum(1),
   1.118 +			iAspectRatioDenom(1),
   1.119 +            iStepFrameCount(0),
   1.120 +            iPlayRate(KDefPlayRate),
   1.121 +            iKeyFrameMode(EFalse),
   1.122 +            iFPObserver(NULL),
   1.123 +            iIsExternalChunk(EFalse)
   1.124 +{
   1.125 +	iSurfaceId 		 = TSurfaceId::CreateNullId();
   1.126 +
   1.127 +#if defined __WINSCW__ 
   1.128 +	iAttributes().iPixelFormat    = EUidPixelFormatYUV_422Interleaved;
   1.129 +#else    
   1.130 +	iAttributes().iPixelFormat    = (TUidPixelFormat) EStUidPixelFormatYUV_420MB;
   1.131 +#endif
   1.132 +}
   1.133 +
   1.134 +CNGAPostProcHwDevice::~CNGAPostProcHwDevice()
   1.135 +{
   1.136 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::~CNGAPostProcHwDevice() ++"), this);
   1.137 +   	if (iSessionManager)
   1.138 +    {
   1.139 +        iSessionManager->CancelNotifiers();
   1.140 +        delete iSessionManager;
   1.141 +        iSessionManager = NULL;
   1.142 +    }
   1.143 +   	
   1.144 +   	while (iSupportedInputFormats.Count()>0)
   1.145 +    {
   1.146 +		iSupportedInputFormats.Remove(0);
   1.147 +    }
   1.148 +    
   1.149 +   	while (iProcessQ.Count()>0)
   1.150 +    {
   1.151 +		iProcessQ.Remove(0);
   1.152 +    }
   1.153 +
   1.154 +   	if(iPostingTimer)
   1.155 +    {
   1.156 +    	iPostingTimer->Cancel();
   1.157 +        delete iPostingTimer;
   1.158 +        iPostingTimer = NULL;
   1.159 +    }
   1.160 +    
   1.161 +    while (iVBMBufferReferenceQ.Count()>0)
   1.162 +    {
   1.163 +        TVideoPicture* pic = iVBMBufferReferenceQ[0];
   1.164 +        iVBMBufferReferenceQ.Remove(0);
   1.165 +        if (iColorConversionQ.Count()>0)
   1.166 +    	{
   1.167 +	        iColorConversionQ.Remove(0);
   1.168 +	    }
   1.169 +
   1.170 +        if (pic->iHeader) delete pic->iHeader;
   1.171 +        delete pic->iData.iRawData;
   1.172 +        delete pic;
   1.173 +    }
   1.174 +    
   1.175 +    iSupportedInputFormats.Reset();
   1.176 +    iSupportedInputFormats.Close();
   1.177 +    
   1.178 +    iVBMBufferReferenceQ.Reset();
   1.179 +    iVBMBufferReferenceQ.Close();
   1.180 +    
   1.181 +    iColorConversionQ.Reset();
   1.182 +    iColorConversionQ.Close();
   1.183 +    
   1.184 +    iVBMBufferQ.Reset();
   1.185 +    iVBMBufferQ.Close();
   1.186 +    
   1.187 +    iProcessQ.Reset();
   1.188 +    iProcessQ.Close();
   1.189 +        
   1.190 +    iInputQ.Reset();
   1.191 +    iInputQ.Close();
   1.192 +    
   1.193 +    if (iSurfaceHandler)
   1.194 +    {
   1.195 +    	if(!iSurfaceId.IsNull())
   1.196 +    	{
   1.197 +    		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::UnregisterSurface"), this);
   1.198 +			TInt numScreens = iWsSession.NumberOfScreens();
   1.199 +    		for(TInt i=0;i < numScreens;i++)
   1.200 +    		{
   1.201 +    			iWsSession.UnregisterSurface(i, iSurfaceId);
   1.202 +    		}
   1.203 +    		iWsSession.Flush();
   1.204 +        	TInt err = iSurfaceHandler->DestroySurface(iSurfaceId);
   1.205 +    	}
   1.206 +        delete iSurfaceHandler;
   1.207 +        iSurfaceHandler = NULL;
   1.208 +    }
   1.209 +    
   1.210 +    iWsSession.Close();
   1.211 +    if(!iIsExternalChunk)
   1.212 +    {
   1.213 +        iChunk.Close();
   1.214 +    }
   1.215 +    
   1.216 +    RDebug::Printf("------ Statistics of Post Processor ------");
   1.217 +    RDebug::Printf("    Pictures Received : %d", iPictureCounters.iTotalPictures);
   1.218 +    RDebug::Printf("    Pictures Displayed: %d", iPictureCounters.iPicturesDisplayed);
   1.219 +    RDebug::Printf("    Pictures Skipped  : %d", iPictureCounters.iPicturesSkipped);
   1.220 +    RDebug::Printf("    Pictures overflow : %d", iOverflowPictureCounter);
   1.221 +    RDebug::Printf("------------------------------------------");
   1.222 +    
   1.223 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:~() --"), this);
   1.224 +}
   1.225 +
   1.226 +void CNGAPostProcHwDevice::SetInputFormatL(const TUncompressedVideoFormat&  aFormat) 
   1.227 +{ 
   1.228 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() Pattern= %x ++"), this, aFormat.iYuvFormat.iPattern);
   1.229 +    if (iPPState != EInitializing)
   1.230 +    {
   1.231 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() FAILED: Unexpected state"), this);
   1.232 +        User::Leave(KErrNotReady);
   1.233 +    }
   1.234 +
   1.235 +		iVideoFormat = aFormat; 
   1.236 +		if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
   1.237 +			(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
   1.238 +    		(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))
   1.239 +		{
   1.240 +			iVideoFormat.iYuvFormat.iCoefficients  	     = EYuvBt709Range1;
   1.241 +    		iVideoFormat.iYuvFormat.iPattern       	     = EYuv422Chroma1;
   1.242 +    		iVideoFormat.iYuvFormat.iDataLayout          = EYuvDataInterleavedBE;
   1.243 +			
   1.244 +#if defined __WINSCW__				
   1.245 +				iIsColorConversionNeeded = ETrue; 
   1.246 +#else
   1.247 +				iAttributes().iPixelFormat = (TUidPixelFormat) EStUidPixelFormatYUV_420MB;
   1.248 +#endif
   1.249 +		}	
   1.250 +
   1.251 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() WARNING: -- Not Found!"), this);
   1.252 +}
   1.253 +
   1.254 +
   1.255 +void CNGAPostProcHwDevice::SetInputDevice(CMMFVideoDecodeHwDevice* aDevice) 
   1.256 +{ 
   1.257 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() ++"), this);
   1.258 +
   1.259 +    if (iPPState != EInitializing)
   1.260 +    {
   1.261 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() FAILED: unexpected state"), this);
   1.262 +        return;
   1.263 +	}
   1.264 +
   1.265 +    iInputDecoderDevice = aDevice;
   1.266 +
   1.267 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() --"), this);
   1.268 +}
   1.269 +
   1.270 +void CNGAPostProcHwDevice::GetOutputFormatListL(RArray<TUncompressedVideoFormat>& ) 
   1.271 +{ 
   1.272 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetOutputFormatListL() ++"), this);
   1.273 +
   1.274 +
   1.275 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetOutputFormatListL() --"), this);
   1.276 +}
   1.277 +
   1.278 +void CNGAPostProcHwDevice::SetOutputFormatL(const TUncompressedVideoFormat&  ) 
   1.279 +{
   1.280 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputFormatL() ++"), this);
   1.281 +
   1.282 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputFormatL() --"), this);
   1.283 +}
   1.284 +
   1.285 +void CNGAPostProcHwDevice::SetClockSource(MMMFClockSource* aClock) 
   1.286 +{ 
   1.287 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() ++"), this);
   1.288 +    
   1.289 +    if (iPPState != EInitializing)
   1.290 +    {
   1.291 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() FAILED: Unexpected state"), this);
   1.292 +        return;
   1.293 +	}
   1.294 +    iClockSource = aClock;
   1.295 +
   1.296 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() --"), this);
   1.297 +}
   1.298 +
   1.299 +void CNGAPostProcHwDevice::SetVideoDestScreenL(TBool /*aScreen*/) 
   1.300 +{ 
   1.301 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetVideoDestScreenL() ++"), this);
   1.302 +
   1.303 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetVideoDestScreenL() --"), this);
   1.304 +}
   1.305 +
   1.306 +void CNGAPostProcHwDevice::SetProxy(MMMFDevVideoPlayProxy& aProxy) 
   1.307 +{ 
   1.308 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() ++"), this);
   1.309 +
   1.310 +    if (iPPState != EInitializing)
   1.311 +    {
   1.312 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() FAILED: Unexpected state"), this);
   1.313 +        return;
   1.314 +	}
   1.315 +
   1.316 +    iProxy = &aProxy;
   1.317 +
   1.318 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() --"), this);
   1.319 +}
   1.320 +
   1.321 +void CNGAPostProcHwDevice::Initialize() 
   1.322 +{
   1.323 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize ++"));
   1.324 +	TInt err = KErrNone;
   1.325 +
   1.326 +    if (iPPState != EInitializing)
   1.327 +    {
   1.328 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize() FAILED: Unexpected state"), this);
   1.329 +        if (iProxy)
   1.330 +		{
   1.331 +			iProxy->MdvppInitializeComplete(this, KErrNotReady);
   1.332 +		}
   1.333 +		return;
   1.334 +	}
   1.335 +	if (!iSurfaceHandler)
   1.336 +    {
   1.337 +    	TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
   1.338 +    	if (err != KErrNone)
   1.339 +    	{
   1.340 +    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create SurfaceHandler."), this);
   1.341 +    	    if (iProxy)
   1.342 +			{
   1.343 +				iProxy->MdvppInitializeComplete(this, err);
   1.344 +			}
   1.345 +			return;
   1.346 +    	}
   1.347 +    }
   1.348 +    if (!iSessionManager)
   1.349 +    {
   1.350 +    	TRAP(err, iSessionManager = CNGAPostProcSessionManager::NewL());
   1.351 +    	if (err != KErrNone)
   1.352 +    	{
   1.353 +    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create SessionManager."), this);
   1.354 +    	    if (iProxy)
   1.355 +			{
   1.356 +				iProxy->MdvppInitializeComplete(this, err);
   1.357 +			}
   1.358 +			return;
   1.359 +    	}
   1.360 +    	iSessionManager->SetObserver(*this);
   1.361 +    }
   1.362 +
   1.363 +  	if (iInputDecoderDevice)
   1.364 +	{
   1.365 +		MMmfVideoResourceHandler* handler = NULL;
   1.366 +		handler = (MMmfVideoResourceHandler*)iInputDecoderDevice->CustomInterface(KUidMmfVideoResourceManagement);
   1.367 +		if (handler)
   1.368 +		{
   1.369 +			handler->MmvrhSetObserver((MMmfVideoResourceObserver*)this);
   1.370 +		}
   1.371 +		else
   1.372 +		{
   1.373 +			PP_DEBUG(_L("ppHwDev[%x]:Initialize() decoder yet to implement MMmfVideoResourceHandler CI"), this);
   1.374 +		}
   1.375 +		
   1.376 +		MMmfVideoPropertiesNotifier* VPHandler = NULL;
   1.377 +		VPHandler = (MMmfVideoPropertiesNotifier*)iInputDecoderDevice->CustomInterface(KUidMmfVideoPropertiesManagement);
   1.378 +		if (VPHandler)
   1.379 +		{
   1.380 +			PP_DEBUG(_L("ppHwDev[%x]:Initialize() Register for video property changes"), this);
   1.381 +			VPHandler->MmvpnSetObserver((MMmfVideoPropertiesObserver*)this);
   1.382 +		}
   1.383 +		else
   1.384 +		{
   1.385 +			PP_DEBUG(_L("ppHwDev[%x]:Initialize() decoder yet to implement MMmfVideoPropertiesNotifier CI"), this);
   1.386 +		}
   1.387 +	}
   1.388 +		
   1.389 +    // Initialize picture counters
   1.390 +	iPictureCounters.iPicturesSkipped 	= 0;
   1.391 +	iPictureCounters.iPicturesDisplayed = 0;
   1.392 +	iPictureCounters.iTotalPictures = 0;
   1.393 +	iOverflowPictureCounter = 0;
   1.394 +	
   1.395 +	iPPState = EInitialized;
   1.396 +	if(iPostInitializeResponse)
   1.397 +	{
   1.398 +		
   1.399 +		TRAP(err, iPostInitializeResponse->MmpirPostInitializeResponseL());
   1.400 +	}
   1.401 +	
   1.402 +	if(!err)
   1.403 +	{
   1.404 +		TRAP(err, iSessionManager->CreateNotifierL(iInfo().iBuffers));
   1.405 +	}
   1.406 +	else
   1.407 +	{
   1.408 +		iPPState = EInitializing;
   1.409 +	}
   1.410 +	
   1.411 +	if (iProxy)
   1.412 +	{
   1.413 +		iProxy->MdvppInitializeComplete(this, err);
   1.414 +	}
   1.415 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize --"), this);
   1.416 +}
   1.417 +
   1.418 +void CNGAPostProcHwDevice::WritePictureL(TVideoPicture* aPicture) 
   1.419 +{ 
   1.420 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture bufId = %d"), this,GetID(aPicture));
   1.421 +	TVideoPicture* pic;
   1.422 +	if (iPPState==EInitializing || iPPState==EStopped || iIsInputEnded)
   1.423 +    {
   1.424 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Unexpected state"), this);
   1.425 +        User::Leave(KErrNotReady);
   1.426 +	}
   1.427 +
   1.428 +    if(!aPicture)
   1.429 +    {
   1.430 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Invalid argument"), this);
   1.431 +		User::Leave(KErrArgument);
   1.432 +	}
   1.433 +	pic = aPicture;	
   1.434 +	iPictureCounters.iTotalPictures++;
   1.435 +	if((iPPState != EPlaying) && (iFirstPictureUpdated))
   1.436 +	{
   1.437 +	//If decoder is fast enough, it can happen between Initialize->Start time gap between 
   1.438 +	//DecodeHwDevice and PostProc_HwDevice. OR between Pause->Resume time gap as well.
   1.439 +		AddToQ(pic);
   1.440 +	}
   1.441 +	else if( iInputQ.Count() > 0 )
   1.442 +	{
   1.443 +		AddToQ(pic);
   1.444 +		AttemptToPost();
   1.445 +	}
   1.446 +	else
   1.447 +	{
   1.448 +		TTimeToPost timeToPost = EPostIt;
   1.449 +		TInt64 delta = 0;
   1.450 +	    if(iFirstPictureUpdated)
   1.451 +		{
   1.452 +			timeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
   1.453 +			if(!IsGceReady())
   1.454 +		    {  
   1.455 +				PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL GCE not ready"), this );
   1.456 +				if(timeToPost == EPostIt)
   1.457 +				{
   1.458 +                    timeToPost = EDelayIt;
   1.459 +				}
   1.460 +		    }
   1.461 +		    if (delta > 0x7FFFFFFF)
   1.462 +		    {
   1.463 +		         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL Too large delta .. skipping"), this ); 
   1.464 +		         timeToPost = ESkipIt;
   1.465 +		    }
   1.466 +		}
   1.467 +		else
   1.468 +		{
   1.469 +			if(!iSurfaceCreatedEventPublished)
   1.470 +                {
   1.471 +                    PublishSurfaceCreated();
   1.472 +                }
   1.473 +			iFirstPictureUpdated = ETrue;
   1.474 +		}
   1.475 +		
   1.476 +
   1.477 +		switch(timeToPost)
   1.478 +		{
   1.479 +			case EDelayIt:
   1.480 +			{
   1.481 +				if(AddToQ(pic) != 0)
   1.482 +				{
   1.483 +					break;
   1.484 +				}
   1.485 +				iPostingTimer->Cancel();
   1.486 +				SetTimer(delta);
   1.487 +			}
   1.488 +			break;
   1.489 +			case EPostIt:
   1.490 +			{
   1.491 +		
   1.492 +				if(iIsColorConversionNeeded)
   1.493 +				{
   1.494 +					TVideoPicture* ccPic;				
   1.495 +	    			ccPic = DoColorConvert(pic); // output will be in ccPic
   1.496 +	    			pic = ccPic;			   
   1.497 +				}
   1.498 +						
   1.499 +				#ifdef _DUMP_YUV_FRAMES
   1.500 +				captureYuv(pic);
   1.501 +				#endif
   1.502 +				TInt err = iSessionManager->PostPicture(iSurfaceId, GetID(pic), ETrue); 
   1.503 +				if(err == KErrNone)
   1.504 +				{
   1.505 +				    iProcessQ.Append(pic);
   1.506 +					iCurrentPlaybackPosition = pic->iTimestamp;
   1.507 +				}
   1.508 +				else
   1.509 +				{
   1.510 +					ReleasePicture(pic);
   1.511 +				}
   1.512 +			}
   1.513 +			break;
   1.514 +			case ESkipIt:
   1.515 +			{
   1.516 +				ReleasePicture(pic); 
   1.517 +				PicturesSkipped();
   1.518 +			}
   1.519 +			break;
   1.520 +		}
   1.521 +    }
   1.522 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture --"), this);
   1.523 +}
   1.524 +
   1.525 +
   1.526 +CPostProcessorInfo* 
   1.527 +CNGAPostProcHwDevice::PostProcessorInfoLC() 
   1.528 +{
   1.529 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PostProcessorInfoLC() ++"), this);
   1.530 +    TUncompressedVideoFormat yuvFormat;
   1.531 +    RArray<TUint32>                     SupportedPostProcess;
   1.532 +    TBool                               SupportedHwAcceleration = ETrue;   //Non-Accelerated ETrue, 
   1.533 +    TYuvToRgbCapabilities               SupportedYuvToRgbCapab; 
   1.534 +    TInt32                              SupportedRotations = ERotateNone; // no rotation supported
   1.535 +    
   1.536 +    TBool                               SupportedArbitraryScaling = EFalse; // no scaling supported
   1.537 +    RArray<TScaleFactor>                SupportedScaleFactors;
   1.538 +    TBool                               SupportedAntiAliasing = EFalse;
   1.539 +    
   1.540 +    //default
   1.541 +    yuvFormat.iDataFormat                     = EYuvRawData;
   1.542 +    yuvFormat.iYuvFormat.iYuv2RgbMatrix       = 0;
   1.543 +    yuvFormat.iYuvFormat.iRgb2YuvMatrix       = 0;
   1.544 +    yuvFormat.iYuvFormat.iAspectRatioNum      = 1;
   1.545 +    yuvFormat.iYuvFormat.iAspectRatioDenom    = 1;
   1.546 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range1;
   1.547 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.548 +    yuvFormat.iYuvFormat.iDataLayout          = EYuvDataInterleavedBE;
   1.549 +    
   1.550 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.551 +    
   1.552 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.553 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.554 +    
   1.555 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range0;
   1.556 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.557 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedBE;
   1.558 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.559 +    
   1.560 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.561 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.562 +    
   1.563 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range0;
   1.564 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.565 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   1.566 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.567 +            
   1.568 +	yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.569 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.570 +
   1.571 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range1;
   1.572 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.573 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   1.574 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.575 +    
   1.576 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.577 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.578 +            
   1.579 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range0;
   1.580 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.581 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedBE;
   1.582 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.583 +    
   1.584 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.585 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.586 +
   1.587 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range1;
   1.588 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.589 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedBE;
   1.590 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.591 +    
   1.592 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.593 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.594 +            
   1.595 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range0;
   1.596 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.597 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   1.598 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.599 +    
   1.600 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.601 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.602 +
   1.603 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range1;
   1.604 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma1;
   1.605 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataInterleavedLE;
   1.606 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.607 +    
   1.608 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv422Chroma2;
   1.609 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.610 +    
   1.611 +    //YUV 420 planar
   1.612 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range1;
   1.613 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   1.614 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   1.615 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.616 +
   1.617 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   1.618 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.619 +
   1.620 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   1.621 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.622 +
   1.623 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt709Range0;
   1.624 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   1.625 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   1.626 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.627 +
   1.628 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   1.629 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.630 +
   1.631 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   1.632 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.633 +
   1.634 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range1;
   1.635 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   1.636 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   1.637 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.638 +
   1.639 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   1.640 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.641 +
   1.642 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   1.643 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.644 +
   1.645 +    yuvFormat.iYuvFormat.iCoefficients  	  = EYuvBt601Range0;
   1.646 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma1;
   1.647 +    yuvFormat.iYuvFormat.iDataLayout    	  = EYuvDataPlanar;
   1.648 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.649 +
   1.650 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma2;
   1.651 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.652 +
   1.653 +    yuvFormat.iYuvFormat.iPattern       	  = EYuv420Chroma3;
   1.654 +    User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
   1.655 +            
   1.656 +    CPostProcessorInfo* postProcessorInfo = CPostProcessorInfo::NewL( 
   1.657 +                KUidVideoPostProcHwDevice, 
   1.658 +                KManufacturer, 
   1.659 +                KIdentifier, 
   1.660 +                TVersion(1, 0, 0), 
   1.661 +                iSupportedInputFormats.Array(),
   1.662 +                SupportedPostProcess.Array(), 
   1.663 +                SupportedHwAcceleration,   
   1.664 +                ETrue,      //Direct Display
   1.665 +                SupportedYuvToRgbCapab, 
   1.666 +                SupportedRotations, 
   1.667 +                SupportedArbitraryScaling,
   1.668 +                SupportedScaleFactors.Array(), 
   1.669 +                SupportedAntiAliasing);
   1.670 +                
   1.671 +    CleanupStack::PushL(postProcessorInfo);            
   1.672 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PostProcessorInfoLC() --"), this);
   1.673 +    return postProcessorInfo;
   1.674 +}
   1.675 +
   1.676 +void CNGAPostProcHwDevice::MmvprcGetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCap)
   1.677 +{       
   1.678 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcGetPlayRateCapabilitiesL ++"), this);       
   1.679 +     aCap.iPlayForward = ETrue;       
   1.680 +     aCap.iPlayBackward = ETrue;       
   1.681 +     aCap.iStepForward = ETrue;       
   1.682 +     aCap.iStepBackward = ETrue;       
   1.683 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcGetPlayRateCapabilitiesL --"), this);       
   1.684 +}       
   1.685 +
   1.686 +void CNGAPostProcHwDevice::MmvprcSetPlayRateL(const TInt aRate)
   1.687 +{       
   1.688 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetPlayRateL ++"), this);       
   1.689 +     iPlayRate = aRate;
   1.690 +     if (iPlayRate<0)        
   1.691 +     {       
   1.692 +         iKeyFrameMode = ETrue;    
   1.693 +     }       
   1.694 +     else        
   1.695 +     {       
   1.696 +         iKeyFrameMode = EFalse;   
   1.697 +         ResetCountingBuffer();       
   1.698 +     }       
   1.699 +     //In fast forward go direct to key frame mode if speed >4X =     
   1.700 +    if (iPlayRate>KDefPlayRate*4)
   1.701 +     {       
   1.702 +         if (iFPObserver)        
   1.703 +         {       
   1.704 +             iFPObserver->MmvproKeyFrameModeRequest();       
   1.705 +             iKeyFrameMode=ETrue;       
   1.706 +         }       
   1.707 +     }       
   1.708 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetPlayRateL=%d --"), this, aRate);       
   1.709 +}       
   1.710 +
   1.711 +TInt CNGAPostProcHwDevice::MmvprcPlayRateL()
   1.712 +{       
   1.713 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcPlayRateL= ++"), this);       
   1.714 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcPlayRateL= --"), this);       
   1.715 +    return iPlayRate;       
   1.716 +}       
   1.717 +
   1.718 +void CNGAPostProcHwDevice::MmvprcStepFrameL(const TInt aStep)
   1.719 +{       
   1.720 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcStepFrameL= ++"), this);       
   1.721 +    iStepFrameCount = aStep;       
   1.722 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcStepFrameL=%d --"), this, aStep);       
   1.723 +}       
   1.724 +
   1.725 +void CNGAPostProcHwDevice::MmvprcSetObserver(MMmfVideoPlayRateObserver& aObserver)
   1.726 +{       
   1.727 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetObserver ++"), this);       
   1.728 +    iFPObserver  = &aObserver;
   1.729 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetObserver --"), this);
   1.730 +} 
   1.731 +
   1.732 +void CNGAPostProcHwDevice::MmvsoSetSecureOutputL(TBool aSecure)
   1.733 +{
   1.734 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL aSecure = %d++"), this, aSecure);     
   1.735 +	TInt err = KErrNone;  
   1.736 +    if(aSecure)
   1.737 +	{
   1.738 +		iSurfaceMask = surfaceHints::EAllowInternalOnly;
   1.739 +	}
   1.740 +	else
   1.741 +	{
   1.742 +		iSurfaceMask = surfaceHints::EAllowAllExternals;
   1.743 +	}
   1.744 +	if(!iSurfaceId.IsNull())
   1.745 +	{
   1.746 +		err = AddHints();
   1.747 +		if(err != KErrNone)
   1.748 +		{
   1.749 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvsoSetSecureOutputL -- leaving err = %d"), this, err);
   1.750 +			User::Leave(err);
   1.751 +		}
   1.752 +	}
   1.753 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL --"), this);
   1.754 +}
   1.755 +
   1.756 +void CNGAPostProcHwDevice::MmavsoSetAllowedOutputL(TUint aAllowedOutputMask)
   1.757 +{
   1.758 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL aAllowedOutputMask=0x%08x ++"), this,aAllowedOutputMask);  
   1.759 +   TInt err = KErrNone;
   1.760 +   iSurfaceMask = surfaceHints::EAllowInternalOnly;
   1.761 +    if (aAllowedOutputMask == EVideoAllowAll)
   1.762 +    {
   1.763 +        iSurfaceMask = surfaceHints::EAllowAllExternals;
   1.764 +    }
   1.765 +    else if (aAllowedOutputMask == EVideoAllowInternalOnly)
   1.766 +    {
   1.767 +        iSurfaceMask = surfaceHints::EAllowInternalOnly;
   1.768 +    }
   1.769 +    else 
   1.770 +    {
   1.771 +        // we hope to find some valid output prefs
   1.772 +        if (aAllowedOutputMask & EVideoAllowAnalog)
   1.773 +        {
   1.774 +            iSurfaceMask |= surfaceHints::EAllowAnalog;
   1.775 +        }
   1.776 +        if (aAllowedOutputMask & EVideoAllowMacroVision)
   1.777 +        {
   1.778 +            iSurfaceMask |= surfaceHints::EAllowAnalogProtectionRequired;
   1.779 +        }
   1.780 +        if (aAllowedOutputMask & EVideoAllowHDMI)
   1.781 +        {
   1.782 +            iSurfaceMask |= surfaceHints::EAllowDigital;
   1.783 +        }
   1.784 +        if (aAllowedOutputMask & EVideoAllowHdmiHdcpRequested)
   1.785 +        {
   1.786 +            iSurfaceMask |= surfaceHints::EAllowDigitalProtectionRequested;
   1.787 +        }
   1.788 +        if (aAllowedOutputMask & EVideoAllowHdmiHdcpRequired)
   1.789 +        {
   1.790 +            iSurfaceMask |= surfaceHints::EAllowDigitalProtectionRequired;
   1.791 +        }
   1.792 +    }
   1.793 +    
   1.794 +	if((!iSurfaceId.IsNull()))
   1.795 +	{
   1.796 +		err = AddHints();
   1.797 +		if(err != KErrNone)
   1.798 +		{
   1.799 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmavsoSetAllowedOutputL -- leaving err = %d"), this, err);
   1.800 +			User::Leave(err);
   1.801 +		}
   1.802 +	}
   1.803 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL --"), this);
   1.804 +}	
   1.805 +
   1.806 +void CNGAPostProcHwDevice::SetPostProcessTypesL(TUint32 /*aCombination*/) 
   1.807 +{ 
   1.808 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPostProcessTypesL ++"), this);
   1.809 +	
   1.810 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPostProcessTypesL --"), this);
   1.811 +}
   1.812 +
   1.813 +void CNGAPostProcHwDevice::SetInputCropOptionsL(const TRect& /*aRect*/) 
   1.814 +{ 
   1.815 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputCropOptionsL ++"), this);
   1.816 +   
   1.817 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputCropOptionsL --"), this);
   1.818 +}    
   1.819 +
   1.820 +void CNGAPostProcHwDevice::SetYuvToRgbOptionsL( const TYuvToRgbOptions&  /*aOptions*/, const TYuvFormat& /*aYuvFormat*/, TRgbFormat /*aRgbFormat*/) 
   1.821 +{ 
   1.822 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL ++"), this);
   1.823 +
   1.824 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL --"), this);
   1.825 +}
   1.826 +
   1.827 +void CNGAPostProcHwDevice::SetYuvToRgbOptionsL(const TYuvToRgbOptions& /*aOptions*/)
   1.828 +{
   1.829 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL ++"), this);
   1.830 +
   1.831 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL --"), this);
   1.832 +}
   1.833 +
   1.834 +void CNGAPostProcHwDevice::SetRotateOptionsL(TRotationType ) 
   1.835 +{ 
   1.836 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetRotateOptionsL ++"), this);
   1.837 +    
   1.838 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetRotateOptionsL --"));
   1.839 +}
   1.840 +
   1.841 +void CNGAPostProcHwDevice::SetScaleOptionsL(const TSize& /*aTargetSize*/, TBool /*aAntiAliasFiltering*/) 
   1.842 +{ 
   1.843 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScaleOptionsL ++"), this);
   1.844 +    
   1.845 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScaleOptionsL --"), this);
   1.846 +}
   1.847 +
   1.848 +void CNGAPostProcHwDevice::SetOutputCropOptionsL(const TRect& /*aRect*/) 
   1.849 +{ 
   1.850 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputCropOptionsL ++"), this);
   1.851 +    
   1.852 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputCropOptionsL --"), this);
   1.853 +}
   1.854 +
   1.855 +void CNGAPostProcHwDevice::SetPostProcSpecificOptionsL(const TDesC8& ) 
   1.856 +{ 
   1.857 +    //ignore 
   1.858 +}
   1.859 +
   1.860 +void CNGAPostProcHwDevice::CommitL() 
   1.861 +{ 
   1.862 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CommitL ++"), this);
   1.863 +
   1.864 +   	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CommitL --"), this);
   1.865 +}
   1.866 +
   1.867 +void CNGAPostProcHwDevice::Revert() 
   1.868 +{
   1.869 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Revert ++"), this);
   1.870 +    
   1.871 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Revert --"), this);
   1.872 +}
   1.873 +
   1.874 +void CNGAPostProcHwDevice::StartDirectScreenAccessL( const TRect& /*aVideoRect*/, CFbsScreenDevice& /*aScreenDevice*/, const TRegion& /*aClipRegion*/) 
   1.875 +{ 
   1.876 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:StartDSA ++"), this);
   1.877 +    
   1.878 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:StartDSA --"), this);
   1.879 +}
   1.880 +
   1.881 +void CNGAPostProcHwDevice::AbortDirectScreenAccess() 
   1.882 +{ 
   1.883 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AbortDSA ++"), this);
   1.884 +
   1.885 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AbortDSA --"), this);
   1.886 +}
   1.887 +
   1.888 +void CNGAPostProcHwDevice::SetScreenClipRegion(const TRegion& /*aRegion*/) 
   1.889 +{ 
   1.890 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScreenClipRegion ++"), this);
   1.891 +    
   1.892 +    
   1.893 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScreenClipRegion --"), this);
   1.894 +}		    
   1.895 +
   1.896 +void CNGAPostProcHwDevice::SetPauseOnClipFail(TBool ) 
   1.897 +{ 
   1.898 +    //ignore. Post Processor will always behave as aPause==False. 
   1.899 +}
   1.900 +
   1.901 +TBool CNGAPostProcHwDevice::IsPlaying()
   1.902 +{
   1.903 +	if( iPPState == EPlaying)
   1.904 +	{
   1.905 +    	return ETrue; 
   1.906 +    }
   1.907 +    else
   1.908 +    {
   1.909 +    	return EFalse;
   1.910 +    }
   1.911 +}
   1.912 +
   1.913 +void CNGAPostProcHwDevice::Redraw() 
   1.914 +{ 
   1.915 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw ++"), this);
   1.916 +	TInt err = KErrNone;
   1.917 +	if(iRedrawSurfaceInUse && !iRedrawDone)
   1.918 +	{
   1.919 +        err = AddHints();
   1.920 +        if (err != KErrNone)
   1.921 +        {
   1.922 +            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to AddHints %d"), 
   1.923 +                         this, err);
   1.924 +            iProxy->MdvppFatalError(this, err);	
   1.925 +            return;   
   1.926 +        }
   1.927 +        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface"), this);
   1.928 +		err = RegisterSurface(iSurfaceId);
   1.929 +		if (err != KErrNone)
   1.930 +		{
   1.931 +		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to Register Surface %d"), 
   1.932 +		   				this, err);
   1.933 +		   	iSurfaceHandler->DestroySurface(iSurfaceId);
   1.934 +	   		iSurfaceId = TSurfaceId::CreateNullId();
   1.935 +			iProxy->MdvppFatalError(this, err);	
   1.936 +			return;   				
   1.937 +		}
   1.938 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface done"), this);
   1.939 +        err = iSessionManager->PostPicture(iSurfaceId, 0, EFalse);
   1.940 +		if (err != KErrNone)
   1.941 +		{
   1.942 +			iProxy->MdvppFatalError(this, err);	
   1.943 +			return;
   1.944 +		}
   1.945 +        PublishSurfaceCreated();
   1.946 +        iRedrawDone = ETrue;
   1.947 +    }
   1.948 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw --"), this);
   1.949 +}
   1.950 +
   1.951 +void CNGAPostProcHwDevice::Start() 
   1.952 +{  
   1.953 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start ++"), this);
   1.954 +	iPPState = EPlaying;
   1.955 +	
   1.956 +	//TBC: when buffers given to post proc even before start. 
   1.957 +	//Even the buffers must be available to PostProc but not displayed. 
   1.958 +	//This will happen only when neighbouring decodeHwDevice decodes earlier than Start()
   1.959 +	//call. Need to check if MDF guidelines allow this.
   1.960 +	AttemptToPost();
   1.961 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start --"), this);
   1.962 +}
   1.963 +
   1.964 +void CNGAPostProcHwDevice::Stop() 
   1.965 +{ 
   1.966 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Stop ++"), this);
   1.967 +    iPPState = EStopped;
   1.968 +	if (iSessionManager)
   1.969 +	{
   1.970 +	    iSessionManager->CancelNotifiers();
   1.971 +	}
   1.972 +	if (iPostingTimer)
   1.973 +	{
   1.974 +        iPostingTimer->Cancel();
   1.975 +	}
   1.976 +	ReleaseProcessQ();
   1.977 +	ReleaseInputQ();
   1.978 +
   1.979 +	//Stop must keep on displaying the last frame. Blank Screen must not be visible
   1.980 +	//to client. No Unregistering of surface should happen here. 
   1.981 +	//This Req is not necessary anymore. Only applicable to Pause.
   1.982 +	
   1.983 +	RDebug::Printf("------ Statistics of Post Processor ------");
   1.984 +    RDebug::Printf("    Pictures Received : %d", iPictureCounters.iTotalPictures);
   1.985 +    RDebug::Printf("    Pictures Displayed: %d", iPictureCounters.iPicturesDisplayed);
   1.986 +    RDebug::Printf("    Pictures Skipped  : %d", iPictureCounters.iPicturesSkipped);
   1.987 +    RDebug::Printf("------------------------------------------");
   1.988 +    
   1.989 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Stop --"), this);
   1.990 +}
   1.991 +
   1.992 +void CNGAPostProcHwDevice::Pause()
   1.993 +{
   1.994 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Pause ++"), this);
   1.995 +	iPPState = EPaused;
   1.996 +    iPostingTimer->Cancel();
   1.997 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Pause --"), this);
   1.998 +}
   1.999 +
  1.1000 +void CNGAPostProcHwDevice::Resume()
  1.1001 +{
  1.1002 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Resume ++"), this);
  1.1003 +	iPPState = EPlaying;
  1.1004 +	AttemptToPost();
  1.1005 +   	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Resume --"), this);
  1.1006 +}
  1.1007 +
  1.1008 +void CNGAPostProcHwDevice::SetPosition(const TTimeIntervalMicroSeconds& aPlaybackPosition) 
  1.1009 +{
  1.1010 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition ++"), this);
  1.1011 +    
  1.1012 +    if (iPPState == EInitializing)
  1.1013 +    { 
  1.1014 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition FAILED: Unexpected state"), this);
  1.1015 +        return;
  1.1016 +    }
  1.1017 +    if (iPPState == EPaused)
  1.1018 +    {	
  1.1019 +        iFirstPictureUpdated = EFalse;
  1.1020 +    }
  1.1021 +    iCurrentPlaybackPosition = aPlaybackPosition;  
  1.1022 +    
  1.1023 +    ReleaseInputQ();
  1.1024 +
  1.1025 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition --"), this);
  1.1026 +}
  1.1027 +
  1.1028 +void CNGAPostProcHwDevice::FreezePicture(const TTimeIntervalMicroSeconds& ) 
  1.1029 +{ 
  1.1030 +    //TODO:
  1.1031 +}
  1.1032 +
  1.1033 +void CNGAPostProcHwDevice::ReleaseFreeze(const TTimeIntervalMicroSeconds&  ) 
  1.1034 +{ 
  1.1035 +    //TODO:
  1.1036 +}
  1.1037 +
  1.1038 +TTimeIntervalMicroSeconds 
  1.1039 +CNGAPostProcHwDevice::PlaybackPosition() 
  1.1040 +{ 
  1.1041 +	if (iPPState == EInitializing)
  1.1042 +    {
  1.1043 +        return TTimeIntervalMicroSeconds(0);
  1.1044 +    }
  1.1045 +    
  1.1046 +    return iCurrentPlaybackPosition; 
  1.1047 +}
  1.1048 +
  1.1049 +TUint CNGAPostProcHwDevice::PictureBufferBytes() 
  1.1050 +{   //TODO 
  1.1051 +    return 0; 
  1.1052 +}
  1.1053 +
  1.1054 +void CNGAPostProcHwDevice::GetPictureCounters( CMMFDevVideoPlay::TPictureCounters&  aCounters) 
  1.1055 +{ 
  1.1056 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetPictureCounters ++"), this);
  1.1057 +	
  1.1058 +	if (iPPState == EInitializing)
  1.1059 +		return;
  1.1060 +	aCounters = iPictureCounters;
  1.1061 +	
  1.1062 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetPictureCounters --"), this);
  1.1063 +}
  1.1064 +
  1.1065 +void CNGAPostProcHwDevice::SetComplexityLevel(TUint ) 
  1.1066 +{ 
  1.1067 +    //not required 
  1.1068 +}
  1.1069 +
  1.1070 +TUint CNGAPostProcHwDevice::NumComplexityLevels() 
  1.1071 +{ 
  1.1072 +    //not required 
  1.1073 +    return 1; 
  1.1074 +}
  1.1075 +
  1.1076 +void CNGAPostProcHwDevice::GetComplexityLevelInfo(TUint , CMMFDevVideoPlay::TComplexityLevelInfo& ) 
  1.1077 +{ 
  1.1078 +    //not required 
  1.1079 +}
  1.1080 +
  1.1081 +void CNGAPostProcHwDevice::ReturnPicture(TVideoPicture* ) 
  1.1082 +{ 
  1.1083 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicture +-"), this);
  1.1084 +    //not required for direct rendering 
  1.1085 +}
  1.1086 +
  1.1087 +TBool CNGAPostProcHwDevice::GetSnapshotL(TPictureData& aPictureData, const TUncompressedVideoFormat& /*aFormat*/)
  1.1088 +{ 
  1.1089 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL %d %d ++"), this, iVBMEnabled, iProcessQ.Count());
  1.1090 +	TVideoPicture* 		pic = NULL;
  1.1091 +	TInt 				err = KErrNone;
  1.1092 +	TBool				frameAvailable =EFalse;
  1.1093 +	tWndParam			inputCropWindow;
  1.1094 +	tWndParam			outputCropWindow;
  1.1095 +	tBaseVideoFrame		inputFrame;
  1.1096 +	inputFrame.lum 		= NULL; 
  1.1097 +	
  1.1098 +	if(aPictureData.iDataFormat == ERgbFbsBitmap)
  1.1099 +	{	
  1.1100 +		if(iProcessQ.Count())
  1.1101 +		{
  1.1102 +			pic = iProcessQ[0]; //frame already submitted for display
  1.1103 +		}
  1.1104 +		else if(iInputQ.Count())
  1.1105 +		{
  1.1106 +			pic = iInputQ[0]; //frame yet to be displayed
  1.1107 +		}
  1.1108 +		if(pic) 
  1.1109 +		{
  1.1110 +			if (iVBMEnabled)
  1.1111 +		    {
  1.1112 +				inputFrame.lum	= (TUint8*)pic->iData.iRawData->Ptr();
  1.1113 +			}
  1.1114 +			else
  1.1115 +			{
  1.1116 +				if (iInputDecoderDevice)
  1.1117 +				{
  1.1118 +					MMmfVideoFetchFrame* VFHandler = NULL;
  1.1119 +					VFHandler = (MMmfVideoFetchFrame*)iInputDecoderDevice->CustomInterface(KUidMMFVideoFetchFrame);
  1.1120 +					if (VFHandler)
  1.1121 +					{
  1.1122 +						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() fetch frame"), this);
  1.1123 +						inputFrame.lum = (TUint8*)VFHandler->MmvffGetFrame(GetID(pic));
  1.1124 +					}
  1.1125 +					else
  1.1126 +					{
  1.1127 +						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() decoder yet to implement MMmfVideoFetchFrame CI"), this);
  1.1128 +					}
  1.1129 +				}
  1.1130 +			}
  1.1131 +		}
  1.1132 +		if(inputFrame.lum)
  1.1133 +		{
  1.1134 +			inputFrame.cb	= inputFrame.lum + iPicSize.iWidth * iPicSize.iHeight;
  1.1135 +			
  1.1136 +			if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
  1.1137 +				(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
  1.1138 +	    		(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))						
  1.1139 +			{
  1.1140 +				inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*5)/4;
  1.1141 +			}
  1.1142 +			else
  1.1143 +			{
  1.1144 +				inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*3)/2;
  1.1145 +			}
  1.1146 +			
  1.1147 +			inputFrame.width	= (unsigned short)iPicSize.iWidth;
  1.1148 +			inputFrame.height	= (unsigned short)iPicSize.iHeight;
  1.1149 +			
  1.1150 +			outputCropWindow.wndHeight  = iPicSize.iHeight;	
  1.1151 +			outputCropWindow.wndWidth	= iPicSize.iWidth; 	
  1.1152 +			outputCropWindow.xOffset	= 0;
  1.1153 +			outputCropWindow.yOffset	= 0;
  1.1154 +			
  1.1155 +			inputCropWindow.wndHeight  = iPicSize.iHeight;	
  1.1156 +			inputCropWindow.wndWidth	= iPicSize.iWidth; 	
  1.1157 +			inputCropWindow.xOffset	= 0;
  1.1158 +			inputCropWindow.yOffset	= 0;
  1.1159 +			
  1.1160 +			RFbsSession fbs;
  1.1161 +			User::LeaveIfError(fbs.Connect());
  1.1162 +			CFbsBitmap* iOutBitmap = aPictureData.iRgbBitmap;
  1.1163 +			TInt status = iOutBitmap->Resize(iPicSize);
  1.1164 +			if (status == KErrNone)
  1.1165 +			{
  1.1166 +				// Lock the heap to prevent the FBS server from invalidating the address
  1.1167 +		        iOutBitmap->LockHeap();
  1.1168 +		        TUint8* dataAddress = (TUint8*)iOutBitmap->DataAddress();
  1.1169 +				err = ColorConvert(&inputFrame, dataAddress, &inputCropWindow, &outputCropWindow);
  1.1170 +				iOutBitmap->UnlockHeap();
  1.1171 +				frameAvailable = ETrue;
  1.1172 +			}
  1.1173 +			fbs.Disconnect();
  1.1174 +		}
  1.1175 +	}
  1.1176 +	else
  1.1177 +	{
  1.1178 +		err = KErrNotSupported;
  1.1179 +	}
  1.1180 +	if(err != KErrNone)
  1.1181 +	{
  1.1182 +		User::Leave(err);
  1.1183 +	}
  1.1184 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL --"), this);
  1.1185 +	return(frameAvailable);
  1.1186 +}
  1.1187 +
  1.1188 +void CNGAPostProcHwDevice::InputEnd() 
  1.1189 +{ 
  1.1190 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd ++"), this);
  1.1191 +    
  1.1192 +	if (iPPState!=EPlaying && iPPState!=EPaused)
  1.1193 +    {
  1.1194 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd FAILED: Unexpected state"), this);
  1.1195 +        return;
  1.1196 +	}
  1.1197 +    iIsInputEnded = ETrue;
  1.1198 +    
  1.1199 +    if( (iProcessQ.Count() <= 1) && (iInputQ.Count() == 0))
  1.1200 +        {
  1.1201 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd() Stream end"), this);
  1.1202 +		iProxy->MdvppStreamEnd();
  1.1203 +	}
  1.1204 +    
  1.1205 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd --"), this);
  1.1206 +}
  1.1207 +
  1.1208 +TAny* CNGAPostProcHwDevice::CustomInterface(TUid aInterface)
  1.1209 +{
  1.1210 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CustomInterface UID = %d ++"), this, aInterface.iUid);
  1.1211 +	
  1.1212 +	if (aInterface == KUidMmfVideoBufferManagement)
  1.1213 +    {
  1.1214 +      return (MMmfVideoBufferManagement *)this;
  1.1215 +    }
  1.1216 +	if (aInterface == KUidMMFVideoSurfaceSupport)
  1.1217 +	{
  1.1218 +      return (MMMFVideoSurfaceSupport *)this;
  1.1219 +    }
  1.1220 +	if (aInterface == KUidMMFVideoSurfaceHandleControl)
  1.1221 +	{
  1.1222 +    	return (MMmfVideoSurfaceHandleControl *)this;
  1.1223 +  }    
  1.1224 +    if (aInterface == KUidMmfVideoPlayRateControl)
  1.1225 +    {
  1.1226 +      return (MMmfVideoPlayRateControl *)this;
  1.1227 +    } 
  1.1228 +    if (aInterface == KMmfVideoAdvancedSecureOutputUid)
  1.1229 +    {
  1.1230 +      return (MMmfAdvancedVideoSecureOutput *)this;
  1.1231 +    }
  1.1232 +    if (aInterface == KUidMmfVideoResourceManagement)
  1.1233 +    {
  1.1234 +      return (MMmfVideoResourceObserver *)this;
  1.1235 +    } 
  1.1236 +    if (aInterface == KUidMmfPostInitializeRequest)
  1.1237 +    {
  1.1238 +      return (MMmfPostInitializeRequest *)this;
  1.1239 +    }
  1.1240 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CustomInterface --"), this);
  1.1241 +    return NULL;
  1.1242 +}
  1.1243 +
  1.1244 +void CNGAPostProcHwDevice::BufferAvailable(TInt aBufId, TInt aStatus)
  1.1245 +{ 
  1.1246 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CNGAPostProcHwDevice::BufferAvailable aStatus = %d aBufId = %d++"), this, aStatus, aBufId);
  1.1247 +    TVideoPicture* pic = NULL;
  1.1248 +    if((aStatus != KErrNone) && (aStatus != KErrOverflow) && (aStatus != KErrNotVisible))
  1.1249 +	{
  1.1250 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:BufferAvailable FAILED: aStatus = %d"), this, aStatus);
  1.1251 +		iProxy->MdvppFatalError(this, aStatus);
  1.1252 +	}
  1.1253 +
  1.1254 +	if(aStatus == KErrOverflow)
  1.1255 +	{
  1.1256 +		iOverflowPictureCounter++;
  1.1257 +		PicturesSkipped();
  1.1258 +	}
  1.1259 +    	
  1.1260 +    if (iVBMEnabled)
  1.1261 +    {
  1.1262 +		for(TInt i=0; i < iProcessQ.Count(); i++)
  1.1263 +		{
  1.1264 +			if(iVBMBufferReferenceQ[aBufId] == iProcessQ[i])
  1.1265 +			{
  1.1266 +				pic = iProcessQ[i];
  1.1267 +				iProcessQ.Remove(i);				
  1.1268 +				ReturnPicToDecoder(pic);
  1.1269 +				if (iIsColorConversionNeeded)
  1.1270 +				{
  1.1271 +				    AddPictureToColorConversionQ(pic);
  1.1272 +				}
  1.1273 +				else
  1.1274 +				{
  1.1275 +				    AddPictureToVBMQ(pic);
  1.1276 +				}
  1.1277 +				break;
  1.1278 +			}
  1.1279 +		} 
  1.1280 +	}
  1.1281 +	else
  1.1282 +	{
  1.1283 +	    for(TInt i=0; i < iProcessQ.Count(); i++)
  1.1284 +		{
  1.1285 +			TInt bufId;
  1.1286 +			if (iUsingExternalSurface)
  1.1287 +			{
  1.1288 +				bufId = GetExternalBufferID(iProcessQ[i]);
  1.1289 +			}
  1.1290 +			else
  1.1291 +			{
  1.1292 +				bufId = GetID(iProcessQ[i]);
  1.1293 +			}
  1.1294 +			
  1.1295 +			if (aBufId == bufId)
  1.1296 +			{
  1.1297 +				pic = iProcessQ[i];
  1.1298 +				iProcessQ.Remove(i);
  1.1299 +				ReturnPicToDecoder(pic);
  1.1300 +				break;
  1.1301 +			}
  1.1302 +		} 
  1.1303 +	}
  1.1304 +	
  1.1305 +	if(aStatus == KErrNone)
  1.1306 +	{
  1.1307 +		if (!iKeyFrameMode && iPlayRate>KDefPlayRate)     
  1.1308 +		{   
  1.1309 +		 	if (iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer]==1)        
  1.1310 +		 	{       
  1.1311 +		 		iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer] = 0;       
  1.1312 +		 		iSkippedFramesInLast64Frames--;       
  1.1313 +		 	}       
  1.1314 +		 	iCurrentPosInFramesCountingBuffer = ++iCurrentPosInFramesCountingBuffer%64;       
  1.1315 +		} 
  1.1316 +		iPictureCounters.iPicturesDisplayed++;
  1.1317 +		if (iStepFrameCount != 0)
  1.1318 +        {       
  1.1319 +        	iStepFrameCount > 0 ? iStepFrameCount-- : iStepFrameCount++;		            	      
  1.1320 +            if (iStepFrameCount==0 && iFPObserver)        
  1.1321 +            {       
  1.1322 +            	iFPObserver->MmvproStepFrameComplete(pic->iTimestamp);       
  1.1323 +            }       
  1.1324 +        }
  1.1325 +	}
  1.1326 +	
  1.1327 +	if(iPPState == EPlaying)
  1.1328 +	{
  1.1329 +		AttemptToPost();
  1.1330 +	}
  1.1331 +
  1.1332 +	if( iIsInputEnded && (iProcessQ.Count() <= 1)  && (iInputQ.Count() == 0))
  1.1333 +	{
  1.1334 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:BufferAvailable() Stream end"), this);
  1.1335 +		iProxy->MdvppStreamEnd();
  1.1336 +	}
  1.1337 +	
  1.1338 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CNGAPostProcHwDevice::BufferAvailable --"), this);
  1.1339 +}
  1.1340 +
  1.1341 +//=== MMmfVideoBufferManagement ===
  1.1342 +void CNGAPostProcHwDevice::MmvbmSetObserver(MMmfVideoBufferManagementObserver* aObserver)
  1.1343 +{
  1.1344 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver() ++"), this);
  1.1345 +
  1.1346 +    if (iPPState != EInitializing)
  1.1347 +    {
  1.1348 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver FAILED: Unexpected state"), this);
  1.1349 +        iProxy->MdvppFatalError(this, KErrNotReady);
  1.1350 +	}
  1.1351 +
  1.1352 +    iVBMObserver  = aObserver;
  1.1353 +
  1.1354 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver() --"), this);
  1.1355 +}
  1.1356 +    
  1.1357 +
  1.1358 +void CNGAPostProcHwDevice::MmvbmEnable(TBool aEnable)
  1.1359 +{
  1.1360 +    if (iPPState != EInitializing)
  1.1361 +    {
  1.1362 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmEnable FAILED: Unexpected state"), this);
  1.1363 +        iProxy->MdvppFatalError(this, KErrNotReady);
  1.1364 +	}
  1.1365 +
  1.1366 +    iVBMEnabled = aEnable;
  1.1367 +}
  1.1368 +    
  1.1369 +void CNGAPostProcHwDevice::MmvbmSetBufferOptionsL(const TBufferOptions& aOptions)
  1.1370 +{
  1.1371 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL ++"), this);
  1.1372 +
  1.1373 +    if (iPPState != EInitializing)
  1.1374 +    {
  1.1375 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Unexpected state"), this);
  1.1376 +        User::Leave(KErrNotReady);
  1.1377 +	}
  1.1378 +
  1.1379 +    // why limiting the number of buffers? any particular reason for this?
  1.1380 +    //if (aOptions.iNumInputBuffers > KMaxVBMBuffers || aOptions.iNumInputBuffers <= 1)          //at least two buffers
  1.1381 +    if (aOptions.iNumInputBuffers <= 1)          //at least two buffers
  1.1382 +    {
  1.1383 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Input buffer count limit"), this);
  1.1384 +        User::Leave(KErrNotSupported);
  1.1385 +	}
  1.1386 +
  1.1387 +    if (aOptions.iNumInputBuffers == 0 
  1.1388 +        || aOptions.iBufferSize.iWidth <= KMinVBMInputWidth 
  1.1389 +        || aOptions.iBufferSize.iHeight <= KMinVBMInputHeight  
  1.1390 +        || aOptions.iBufferSize.iWidth > KMaxVBMInputWidth 
  1.1391 +        || aOptions.iBufferSize.iHeight > KMaxVBMInputHeight)
  1.1392 +    {
  1.1393 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Unexpected buffer size"), this);
  1.1394 +        User::Leave(KErrArgument);
  1.1395 +	}
  1.1396 +
  1.1397 +    iVBMBufferOptions.iNumInputBuffers  = aOptions.iNumInputBuffers;
  1.1398 +    iVBMBufferOptions.iBufferSize       = aOptions.iBufferSize;
  1.1399 +
  1.1400 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL --"), this);
  1.1401 +}
  1.1402 +
  1.1403 +void CNGAPostProcHwDevice::MmvbmGetBufferOptions(TBufferOptions& aOptions)
  1.1404 +{
  1.1405 +    if (iPPState == EInitializing)
  1.1406 +    {
  1.1407 +    	aOptions = iVBMBufferOptions;
  1.1408 +    }
  1.1409 +    else
  1.1410 +    {
  1.1411 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferOptions FAILED: Unexpected state"), this);
  1.1412 +        iProxy->MdvppFatalError(this, KErrNotReady);
  1.1413 +	}
  1.1414 +}
  1.1415 +    
  1.1416 +TVideoPicture* CNGAPostProcHwDevice::MmvbmGetBufferL(const TSize& aSize)
  1.1417 +    {
  1.1418 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() ++"), this);
  1.1419 +    
  1.1420 +    TInt err = KErrNone;
  1.1421 +    TVideoPicture* lPic = NULL;
  1.1422 +
  1.1423 +    if (iPPState == EInitializing)
  1.1424 +    {
  1.1425 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() FAILED: Unexpected state"), this);
  1.1426 +        User::Leave(KErrNotReady);
  1.1427 +	  }
  1.1428 +
  1.1429 +    if (aSize.iWidth < KMinVBMInputWidth 
  1.1430 +        || aSize.iHeight < KMinVBMInputHeight
  1.1431 +        || aSize.iWidth > iVBMBufferOptions.iBufferSize.iWidth 
  1.1432 +        || aSize.iHeight > iVBMBufferOptions.iBufferSize.iHeight)
  1.1433 +  	{
  1.1434 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() FAILED: Unexpected buffer size w=%d h=%d "), this,aSize.iWidth,aSize.iHeight );
  1.1435 +        User::Leave(KErrNotSupported);
  1.1436 +		}
  1.1437 +		
  1.1438 +		if(iVBMBufferReferenceQ.Count() == 0)
  1.1439 +		{
  1.1440 +			iPicSize = aSize;
  1.1441 +			err = SetupSurface();
  1.1442 +			if(err)
  1.1443 +			{
  1.1444 +					PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() Surface Setup Failed %d"), this, err);
  1.1445 +					User::Leave(err);
  1.1446 +			}
  1.1447 +		}
  1.1448 +		
  1.1449 +    if(!iVBMBufferQ.Count())
  1.1450 +    {
  1.1451 +       PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() WARNING: Queue buffer count zero"), this);
  1.1452 +        return NULL;
  1.1453 +    }
  1.1454 +
  1.1455 +    lPic    = iVBMBufferQ[0];
  1.1456 +    iVBMBufferQ.Remove(0);
  1.1457 +
  1.1458 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() -- %d"), this, lPic);
  1.1459 +    return lPic;
  1.1460 +}
  1.1461 +    
  1.1462 +void CNGAPostProcHwDevice::MmvbmReleaseBuffer(TVideoPicture* aBuffer)
  1.1463 +{
  1.1464 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() ++"), this);
  1.1465 +
  1.1466 +    if(!aBuffer)
  1.1467 +    {
  1.1468 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() FAILED: Invalid buffer ptr"), this);
  1.1469 +    	iProxy->MdvppFatalError(this, KErrArgument);
  1.1470 +	}
  1.1471 +
  1.1472 +    TInt err = iVBMBufferQ.Append(aBuffer);
  1.1473 +    if (err)
  1.1474 +    {
  1.1475 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() FAILED: Failed to append"), this);
  1.1476 +		iProxy->MdvppFatalError(this, err);
  1.1477 +	}
  1.1478 +
  1.1479 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() --"), this);
  1.1480 +}
  1.1481 +
  1.1482 +//=== MMMFVideoSurfaceSupport ===
  1.1483 +
  1.1484 +void CNGAPostProcHwDevice::MmvssUseSurfaces()
  1.1485 +{
  1.1486 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssUseSurfaces() ++"), this);
  1.1487 +	// do nothing
  1.1488 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssUseSurfaces() --"), this);
  1.1489 +}
  1.1490 +
  1.1491 +TInt CNGAPostProcHwDevice::MmvshcCreateSurface(const RSurfaceManager::TSurfaceCreationAttributes& aAttributes, TInt aHandle, TSurfaceId& aSurfaceId)
  1.1492 +    {
  1.1493 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcCreateSurface() ++"), this);
  1.1494 +    TInt err(KErrNone);
  1.1495 +    
  1.1496 +    if(!iSurfaceId.IsNull())
  1.1497 +    {
  1.1498 +        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssCreateSurface Cleaning Surface"), this);
  1.1499 +        
  1.1500 +		if (iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1.1501 +		{
  1.1502 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcCreateSurface - Telling client to remove old surface"), this);
  1.1503 +			iVideoSurfaceObserver->MmvsoRemoveSurface();
  1.1504 +			iSurfaceCreatedEventPublished = EFalse;
  1.1505 +		}
  1.1506 +		else
  1.1507 +		{
  1.1508 +			// We never told the client about the surface, so we must destroy it ourselves
  1.1509 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Destroying old surface"), this);
  1.1510 +			TInt numScreens = iWsSession.NumberOfScreens();
  1.1511 +    		for(TInt i=0;i < numScreens;i++)
  1.1512 +    		{
  1.1513 +    			iWsSession.UnregisterSurface(i, iSurfaceId);
  1.1514 +    		}
  1.1515 +   			iWsSession.Flush();
  1.1516 +			iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1517 +		}
  1.1518 +		//remove any handle to chunk. not needed perhaps
  1.1519 +		iChunk.Close();
  1.1520 +		
  1.1521 +    }
  1.1522 +        
  1.1523 +    // Create the surface handler if it doesn't exist.
  1.1524 +    if (!iSurfaceHandler)
  1.1525 +    {
  1.1526 +        TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
  1.1527 +        if (err != KErrNone)
  1.1528 +        {
  1.1529 +            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssCreateSurface -- failed to create SurfaceHandler."), this);
  1.1530 +            return err;
  1.1531 +        }
  1.1532 +    }
  1.1533 +         
  1.1534 +    iChunk.SetHandle(aHandle);
  1.1535 +    err = iSurfaceHandler->CreateSurface(aAttributes, aSurfaceId, iChunk);
  1.1536 +    if (err != KErrNone)
  1.1537 +    {
  1.1538 +       PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssCreateSurface -- failed to create surface %d"), this, err);
  1.1539 +       return err;
  1.1540 +    }
  1.1541 +    iSurfaceId = aSurfaceId;
  1.1542 +    iIsExternalChunk = ETrue;
  1.1543 +
  1.1544 +    err = RegisterSurface(iSurfaceId);
  1.1545 +    if (err != KErrNone)
  1.1546 +    {
  1.1547 +       PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssCreateSurface -- failed RegisterSurface %d"), this, err);
  1.1548 +       iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1549 +       iSurfaceId = TSurfaceId::CreateNullId();
  1.1550 +       return err;
  1.1551 +    }
  1.1552 +    
  1.1553 +    err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1.1554 +    if (err != KErrNone)
  1.1555 +    {
  1.1556 +        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssCreateSurface -- failed to get Surface info %d"), this, err);
  1.1557 +        return err;
  1.1558 +    }
  1.1559 +
  1.1560 +    if(iAttributes().iPixelFormat == EUidPixelFormatYUV_422Interleaved) 
  1.1561 +        {
  1.1562 +            iVideoFrameBufSize          = iInfo().iSize.iWidth * iInfo().iSize.iHeight * 2;
  1.1563 +        }
  1.1564 +        else
  1.1565 +        {//EStUidPixelFormatYUV_420MB
  1.1566 +        // EUidPixelFormatYUV_420Planar            
  1.1567 +            iVideoFrameBufSize          =  iInfo().iSize.iWidth * iInfo().iSize.iHeight * 3/2;
  1.1568 +        }
  1.1569 +    
  1.1570 +     
  1.1571 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcCreateSurface err=%d"), this, err);
  1.1572 +    return err;
  1.1573 +    }
  1.1574 +
  1.1575 +void CNGAPostProcHwDevice::MmvssSetObserver(MMMFVideoSurfaceObserver& aObserver)
  1.1576 +{
  1.1577 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSetObserver() ++"), this);
  1.1578 +	iVideoSurfaceObserver = &aObserver;
  1.1579 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSetObserver() --"), this);
  1.1580 +}
  1.1581 +
  1.1582 +void CNGAPostProcHwDevice::MmvssGetSurfaceParametersL(TSurfaceId& aSurfaceId, 
  1.1583 +						TRect& aCropRect, TVideoAspectRatio& aPixelAspectRatio)
  1.1584 +{
  1.1585 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() ++"), this);
  1.1586 +
  1.1587 +	iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1.1588 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() \
  1.1589 +		surfaceWidth = %d surfaceHeight = %d SurfaceId = 0x%x --"), 
  1.1590 +		this, iInfo().iSize.iWidth, iInfo().iSize.iHeight, iSurfaceId);
  1.1591 +	aSurfaceId = iSurfaceId;
  1.1592 +		aCropRect = TRect(0, 0, iInfo().iSize.iWidth, iInfo().iSize.iHeight);
  1.1593 +		if((iPicSize.iWidth > 0) && (iPicSize.iHeight > 0))
  1.1594 +		{
  1.1595 +			aCropRect.Intersection( iPicSize);
  1.1596 +		}
  1.1597 +	aPixelAspectRatio = TVideoAspectRatio(iAspectRatioNum,iAspectRatioDenom);
  1.1598 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL()  \
  1.1599 +		cropRectWidth = %d cropRectHeight = %d"), this, aCropRect.Width(), aCropRect.Height());
  1.1600 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL()  \
  1.1601 +		PAR Num = %d PAR Denom = %d"), this, aPixelAspectRatio.iNumerator, aPixelAspectRatio.iDenominator);
  1.1602 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() --"), this);
  1.1603 +}
  1.1604 +
  1.1605 +void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
  1.1606 +{
  1.1607 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
  1.1608 +	if(!aSurfaceId.IsNull())
  1.1609 +	{
  1.1610 +	    if(iSurfaceId == aSurfaceId)
  1.1611 +        {//closing down top surface....current surface.
  1.1612 +            if(iSessionManager)
  1.1613 +            {
  1.1614 +                iSessionManager->CancelNotifiers();
  1.1615 +            }
  1.1616 +	    }
  1.1617 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
  1.1618 +		TInt numScreens = iWsSession.NumberOfScreens();
  1.1619 +		for(TInt i=0;i < numScreens;i++)
  1.1620 +		{
  1.1621 +			iWsSession.UnregisterSurface(i, aSurfaceId);
  1.1622 +		}
  1.1623 +		iWsSession.Flush();
  1.1624 +		iSurfaceHandler->DestroySurface(aSurfaceId);
  1.1625 +		if(iSurfaceId == aSurfaceId)
  1.1626 +		{
  1.1627 +			iSurfaceCreatedEventPublished = EFalse;
  1.1628 +			iSurfaceId = TSurfaceId::CreateNullId();
  1.1629 +			 if(!iIsExternalChunk)
  1.1630 +			 {
  1.1631 +				iChunk.Close();
  1.1632 +			 }
  1.1633 +		}
  1.1634 +	}
  1.1635 +
  1.1636 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
  1.1637 +}
  1.1638 +
  1.1639 +// === MMmfVideoPropertiesObserver ===
  1.1640 +    
  1.1641 +void CNGAPostProcHwDevice::MmvpoUpdateVideoProperties(const TYuvFormat& aYuvFormat, const TSize& aPictureSize)
  1.1642 +{
  1.1643 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties ++"), this);
  1.1644 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties PAR \
  1.1645 +		iAspectRatioNum = %d, iAspectRatioDenom = %d"), this,
  1.1646 +					 aYuvFormat.iAspectRatioNum,aYuvFormat.iAspectRatioDenom);
  1.1647 +	iPicSize = aPictureSize;
  1.1648 +	iAspectRatioNum = aYuvFormat.iAspectRatioNum;
  1.1649 +	iAspectRatioDenom = aYuvFormat.iAspectRatioDenom;
  1.1650 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties Picture Size \
  1.1651 +		iWidth = %d, iHeight = %d, iSurfaceCreatedEventPublished = %d"), 
  1.1652 +		this, iPicSize.iWidth,iPicSize.iHeight, iSurfaceCreatedEventPublished?1:0);
  1.1653 +			 
  1.1654 +	if(iVPObserver)
  1.1655 +	{
  1.1656 +		iVPObserver->MmvpoUpdateVideoProperties(aYuvFormat, aPictureSize);
  1.1657 +	} 
  1.1658 +	if(iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1.1659 +	{
  1.1660 +    	iVideoSurfaceObserver->MmvsoSurfaceParametersChanged(); 
  1.1661 +    }
  1.1662 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties --"), this);
  1.1663 +}
  1.1664 +
  1.1665 +// === MMmfVideoResourceObserver ===
  1.1666 +
  1.1667 +void CNGAPostProcHwDevice::MmvroResourcesLost(TUid )
  1.1668 +{
  1.1669 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ++"), this);
  1.1670 +    if(!iResourceLost)
  1.1671 +    {
  1.1672 +		iResourceLost = ETrue;
  1.1673 +		iRedrawDone = EFalse;
  1.1674 +		Pause();
  1.1675 +		ReleaseInputQ();
  1.1676 +		iSessionManager->CancelNotifiers();
  1.1677 +		ReleaseProcessQ();
  1.1678 +		if(iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1.1679 +		{
  1.1680 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost - Telling client to remove surface"), this);
  1.1681 +			iVideoSurfaceObserver->MmvsoRemoveSurface();
  1.1682 +			iSurfaceCreatedEventPublished = EFalse;
  1.1683 +		}
  1.1684 +	}
  1.1685 +	else if(iResourceLost && iRedrawDone)
  1.1686 +	{
  1.1687 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ResourceLost happening \
  1.1688 +					while Postprocessor is already in ResourceLoss state"), 
  1.1689 +	   				this);
  1.1690 +		iProxy->MdvppFatalError(this, KErrHardwareNotAvailable);	   				
  1.1691 +	    return;		
  1.1692 +	}
  1.1693 +	else
  1.1694 +	{
  1.1695 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost Ignoring the \
  1.1696 +					duplicate ResourceLoss call"), 
  1.1697 +	   				this);
  1.1698 +	}
  1.1699 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost --"), this);
  1.1700 +}
  1.1701 +
  1.1702 +// === MMmfVideoPropertiesNotifier ===
  1.1703 +    
  1.1704 +void CNGAPostProcHwDevice::MmvpnSetObserver(MMmfVideoPropertiesObserver* aObserver)
  1.1705 +{
  1.1706 +	PP_DEBUG(_L("ppHwDev[%x]::MmvpnSetObserver ++"), this);
  1.1707 +	iVPObserver = aObserver;
  1.1708 +	PP_DEBUG(_L("ppHwDev[%x]::MmvpnSetObserver --"), this);
  1.1709 +}
  1.1710 +
  1.1711 +void CNGAPostProcHwDevice::MmvroResourcesRestored(TUid )
  1.1712 +{
  1.1713 +   	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesRestored ++"), this);
  1.1714 +	iFirstPictureUpdated = EFalse;
  1.1715 +	iResourceLost = EFalse;
  1.1716 +   	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesRestored state=%d --"), 
  1.1717 +   			this, iPPState);
  1.1718 +}
  1.1719 +
  1.1720 +void CNGAPostProcHwDevice::MmvshcSetSurfaceHandle(const TSurfaceId &aSurfaceID)
  1.1721 +{
  1.1722 +    
  1.1723 +    SetupExternalSurface(aSurfaceID);
  1.1724 +    
  1.1725 +}
  1.1726 +
  1.1727 +void CNGAPostProcHwDevice::MmvshcRedrawBufferToSurface(TPtrC8& aRedrawBuffer)
  1.1728 +{
  1.1729 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface ++"), this);
  1.1730 +	
  1.1731 +    TUint8*         lPtr;
  1.1732 +    TInt 			offset;
  1.1733 +
  1.1734 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface -- Creating %d x %d surface"), this, iPicSize.iWidth, iPicSize.iHeight);
  1.1735 +
  1.1736 +   	TInt err = KErrNone;
  1.1737 +	SetSurfaceAttributes(iPicSize, 1); 
  1.1738 +	
  1.1739 +  	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1.1740 +  	if (err != KErrNone)
  1.1741 +	{
  1.1742 +	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to create Surface %d"), 
  1.1743 +	   				this, err);
  1.1744 +		iProxy->MdvppFatalError(this, err);	   				
  1.1745 +	    return;
  1.1746 +	}
  1.1747 +
  1.1748 +	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1.1749 +	if (err != KErrNone)
  1.1750 +	{
  1.1751 +	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to get Surface info %d"), 
  1.1752 +	   				this, err);
  1.1753 +	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1754 +	   	iSurfaceId = TSurfaceId::CreateNullId();
  1.1755 +		iProxy->MdvppFatalError(this, err);	   				
  1.1756 +	    return;
  1.1757 +	}
  1.1758 +
  1.1759 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface() \
  1.1760 +		surfaceWidth = %d surfaceHeight = %d surfaceStride = %d"), this, iInfo().iSize.iWidth, iInfo().iSize.iHeight, iInfo().iStride);
  1.1761 +
  1.1762 +	TInt redrawBufferSize = aRedrawBuffer.Size();
  1.1763 +	TInt surfaceSize = iInfo().iStride * iInfo().iSize.iHeight;
  1.1764 +
  1.1765 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface RedrawBuffer size= %d Surface size = %d"), this, redrawBufferSize, surfaceSize);
  1.1766 +
  1.1767 +	// Check whether redraw buffer will fit onto the surface.
  1.1768 +	// If this check fails then we won't raise a fatal error - We just won't create the redraw surface
  1.1769 +	if (redrawBufferSize > surfaceSize)
  1.1770 +	{
  1.1771 +    	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface Redraw buffer size larger than surface size"), this);
  1.1772 +    	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1773 +	   	iSurfaceId = TSurfaceId::CreateNullId();
  1.1774 +    	return;
  1.1775 +	}
  1.1776 +
  1.1777 +	err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
  1.1778 +	if (err != KErrNone)
  1.1779 +	{
  1.1780 +	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to map Surface %d"), 
  1.1781 +	   				this, err);
  1.1782 +	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1783 +	   	iSurfaceId = TSurfaceId::CreateNullId();
  1.1784 +		iProxy->MdvppFatalError(this, err);	   				
  1.1785 +	    return;
  1.1786 +	}
  1.1787 +	iIsExternalChunk = EFalse;
  1.1788 +    if((err = iSurfaceHandler->GetBufferOffset(iSurfaceId, 0, offset)) != KErrNone)
  1.1789 +    {
  1.1790 +    	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset query failed %d"), this, err);
  1.1791 +    	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1792 +	   	iSurfaceId = TSurfaceId::CreateNullId();
  1.1793 +		iChunk.Close();
  1.1794 +    	iProxy->MdvppFatalError(this, err);
  1.1795 +    	return;
  1.1796 +    }
  1.1797 +
  1.1798 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset = %d"), this, offset);
  1.1799 +
  1.1800 +	lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
  1.1801 +	memcpy((TAny *)lPtr, (TAny *)aRedrawBuffer.Ptr(), redrawBufferSize);
  1.1802 +
  1.1803 +	iRedrawSurfaceInUse = ETrue;
  1.1804 +
  1.1805 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface(): New surface = 0x%x"), this, iSurfaceId);
  1.1806 +
  1.1807 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface error = %d --"), this, err);
  1.1808 +}
  1.1809 +
  1.1810 +TInt CNGAPostProcHwDevice::SetupExternalSurface(const TSurfaceId &aSurfaceID)
  1.1811 +{
  1.1812 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface(): aSurfaceID = 0x%x"), this, aSurfaceID );
  1.1813 +
  1.1814 +    TInt err = KErrNone;
  1.1815 +    
  1.1816 +    if(!iSurfaceId.IsNull())
  1.1817 +    {
  1.1818 +		if (iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1.1819 +		{
  1.1820 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Telling client to remove old surface"), this);
  1.1821 +			iVideoSurfaceObserver->MmvsoRemoveSurface();
  1.1822 +			iSurfaceCreatedEventPublished = EFalse;
  1.1823 +		}
  1.1824 +		else
  1.1825 +		{
  1.1826 +			// We never told the client about the surface, so we must destroy it ourselves
  1.1827 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Destroying old surface"), this);
  1.1828 +			TInt numScreens = iWsSession.NumberOfScreens();
  1.1829 +    		for(TInt i=0;i < numScreens;i++)
  1.1830 +    		{
  1.1831 +    			iWsSession.UnregisterSurface(i, iSurfaceId);
  1.1832 +    		}
  1.1833 +   			iWsSession.Flush();
  1.1834 +			iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1835 +		}
  1.1836 +
  1.1837 +		iChunk.Close();
  1.1838 +	}
  1.1839 +    
  1.1840 +    iSurfaceId            = aSurfaceID;
  1.1841 +    iUsingExternalSurface = ETrue;
  1.1842 +    iRedrawSurfaceInUse = EFalse;
  1.1843 +
  1.1844 +    // Create the surface handler if it doesn't exist.
  1.1845 +    if (!iSurfaceHandler)
  1.1846 +    {
  1.1847 +        TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
  1.1848 +        if (err != KErrNone)
  1.1849 +        {
  1.1850 +           PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to create SurfaceHandler."), this);
  1.1851 +            return err;
  1.1852 +        }
  1.1853 +    }
  1.1854 +    
  1.1855 +    err = iSurfaceHandler->OpenSurface(iSurfaceId);
  1.1856 +    if (err != KErrNone)
  1.1857 +	{
  1.1858 +	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed OpenSurface %d"), 
  1.1859 +	   				this, err);
  1.1860 +	    return err;
  1.1861 +	}
  1.1862 +    err = AddHints();
  1.1863 +    if (err != KErrNone)
  1.1864 +    {
  1.1865 +        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to AddHints %d"), 
  1.1866 +                    this, err);
  1.1867 +        return err;
  1.1868 +    }
  1.1869 +	err = RegisterSurface(iSurfaceId);
  1.1870 +	if (err != KErrNone)
  1.1871 +	{
  1.1872 +	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed RegisterSurface %d"), 
  1.1873 +	   				this, err);
  1.1874 +	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.1875 +	   	iSurfaceId = TSurfaceId::CreateNullId();
  1.1876 +	    return err;
  1.1877 +	}
  1.1878 +
  1.1879 +    err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1.1880 +    if (err != KErrNone)
  1.1881 +    {
  1.1882 +        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to get Surface info %d"), 
  1.1883 +                     this, err);
  1.1884 +        return err;
  1.1885 +    }
  1.1886 + 
  1.1887 +  PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface err=%d"), this, err);
  1.1888 +   return err;
  1.1889 +}
  1.1890 +
  1.1891 +//=== Internal ===
  1.1892 +TVideoPicture* CNGAPostProcHwDevice::CreateBuffersL(TInt aBufId)
  1.1893 +{
  1.1894 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL ++"), this);
  1.1895 +	
  1.1896 +	TVideoPicture*          lVideoPicture = NULL;
  1.1897 +    TUint8*                 lPtr;
  1.1898 +    TPtr8*                  lTemp;
  1.1899 +    TInt 					offset;
  1.1900 +    
  1.1901 +	lVideoPicture = new (ELeave) TVideoPicture;
  1.1902 +    CleanupStack::PushL(lVideoPicture);
  1.1903 +    if(TInt err = iSurfaceHandler->GetBufferOffset(iSurfaceId, aBufId, offset) != KErrNone)
  1.1904 +    {
  1.1905 +    	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL offset query failed %d"), this, err);
  1.1906 +    }
  1.1907 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL offset = %d id =%d --"), this, offset, aBufId);
  1.1908 +    
  1.1909 +	lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
  1.1910 +
  1.1911 +    lTemp = new (ELeave) TPtr8(lPtr, 0, (iVideoFrameBufSize ));
  1.1912 +    CleanupStack::PushL(lTemp);
  1.1913 +
  1.1914 +    lVideoPicture->iData.iRawData   = lTemp;
  1.1915 +    lVideoPicture->iHeader = NULL ;
  1.1916 +    lVideoPicture->iLayerBitRates = NULL ;
  1.1917 +    
  1.1918 +    CleanupStack::Pop(2);
  1.1919 +    
  1.1920 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL --"), this);
  1.1921 +    return lVideoPicture;
  1.1922 +}
  1.1923 +
  1.1924 +void CNGAPostProcHwDevice::CreateVBMBuffersL()
  1.1925 +{
  1.1926 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL ++"), this);
  1.1927 +    
  1.1928 +    TInt err = KErrNone;
  1.1929 +    TVideoPicture* pic = NULL;
  1.1930 +    iVBMBufferReferenceQ.Reset();
  1.1931 +    iVBMBufferQ.Reset();
  1.1932 +    iColorConversionQ.Reset();
  1.1933 +
  1.1934 +    for(TInt i = 0; i < iVBMBufferOptions.iNumInputBuffers; i++)
  1.1935 +    {
  1.1936 +        TRAP(err, pic = CreateBuffersL(i));
  1.1937 +	    	if (err != KErrNone)
  1.1938 +	    	{
  1.1939 +	    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  1.1940 +	    	    User::Leave(err);
  1.1941 +	    	}
  1.1942 +
  1.1943 +        // This will hold the references which will be used in destructor
  1.1944 +        User::LeaveIfError(iVBMBufferReferenceQ.Append(pic));
  1.1945 +        User::LeaveIfError(iVBMBufferQ.Append(pic));
  1.1946 +    }
  1.1947 +    if(iIsColorConversionNeeded)
  1.1948 +    {
  1.1949 +		    for(TInt i = iVBMBufferOptions.iNumInputBuffers ; 
  1.1950 +		    				 i < (iVBMBufferOptions.iNumInputBuffers + KColorConversionBuffers ); i++)
  1.1951 +		    {
  1.1952 +		        TRAP(err, pic = CreateBuffersL(i));
  1.1953 +			    	if (err != KErrNone)
  1.1954 +			    	{
  1.1955 +			    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  1.1956 +			    	    User::Leave(err);
  1.1957 +			    	}
  1.1958 +		
  1.1959 +		        // This will hold the references which will be used in destructor
  1.1960 +		        User::LeaveIfError(iVBMBufferReferenceQ.Append(pic));
  1.1961 +		        User::LeaveIfError(iColorConversionQ.Append(pic));
  1.1962 +		    }
  1.1963 +		}
  1.1964 +	    
  1.1965 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL --"), this);
  1.1966 +}
  1.1967 +
  1.1968 +void CNGAPostProcHwDevice::ReturnPicToDecoder(TVideoPicture* aPic)
  1.1969 +{
  1.1970 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicToDecoder ++"), this);
  1.1971 +	if (aPic == NULL)
  1.1972 +	{
  1.1973 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture FAILED: Invalid pic ptr."), this);
  1.1974 +		return;
  1.1975 +	}
  1.1976 +	
  1.1977 +   	if (iInputDecoderDevice)
  1.1978 +    {
  1.1979 +       PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture .. before return picture. 2"), this);
  1.1980 +        iInputDecoderDevice->ReturnPicture(aPic);
  1.1981 +    }
  1.1982 +	
  1.1983 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicToDecoder --"), this);
  1.1984 +}
  1.1985 +
  1.1986 +TInt CNGAPostProcHwDevice::AttemptToPost()
  1.1987 +{
  1.1988 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost ++ Q:%d"), this, iInputQ.Count());
  1.1989 +   if (iPPState == EPaused)
  1.1990 +   {
  1.1991 +        return KErrNone;
  1.1992 +   }
  1.1993 +
  1.1994 +    TInt err = KErrNotReady;
  1.1995 +    TInt count = iInputQ.Count();
  1.1996 +    TBool bDone = EFalse;
  1.1997 +    TVideoPicture* pic = PeekQ();   		
  1.1998 +  	while(pic && !bDone)
  1.1999 +  	{
  1.2000 +	    if(!IsGceReady())
  1.2001 +		{  
  1.2002 +			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost GCE not ready"), this );
  1.2003 +			return err; //no need to catch this error
  1.2004 +		}
  1.2005 +		TInt64 delta = 0;
  1.2006 +		TTimeToPost	timeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
  1.2007 +		switch(timeToPost)
  1.2008 +		{
  1.2009 +			case EDelayIt:
  1.2010 +			{
  1.2011 +				iPostingTimer->Cancel();
  1.2012 +				SetTimer(delta);
  1.2013 +				bDone = ETrue;
  1.2014 +			}
  1.2015 +			break;
  1.2016 +			case EPostIt:
  1.2017 +			{
  1.2018 +				RemoveFromQ(); // remove the pic that was returned by PeekQ				
  1.2019 +				if(iIsColorConversionNeeded)
  1.2020 +				{
  1.2021 +				    TVideoPicture* ccPic;
  1.2022 +    				ccPic = DoColorConvert(pic); // output will be in ccPic
  1.2023 +    				pic = ccPic;
  1.2024 +			    }
  1.2025 +				
  1.2026 +                #ifdef _DUMP_YUV_FRAMES
  1.2027 +                    captureYuv(pic);
  1.2028 +                #endif
  1.2029 +				TInt err = iSessionManager->PostPicture(iSurfaceId, GetID(pic), ETrue); 
  1.2030 +				if(err == KErrNone)
  1.2031 +				{
  1.2032 +				    iProcessQ.Append(pic);
  1.2033 +					iCurrentPlaybackPosition = pic->iTimestamp;
  1.2034 +					if(!iFirstPictureUpdated)
  1.2035 +					{
  1.2036 +						iFirstPictureUpdated = ETrue;
  1.2037 +						if(!iSurfaceCreatedEventPublished)
  1.2038 +                    	{
  1.2039 +                        	PublishSurfaceCreated();
  1.2040 +                    	}
  1.2041 +					}
  1.2042 +				}
  1.2043 +				else
  1.2044 +				{
  1.2045 +					ReleasePicture(pic);
  1.2046 +				}
  1.2047 +										 					
  1.2048 +				
  1.2049 +			}	// end of postit
  1.2050 +			break;
  1.2051 +			case ESkipIt: 
  1.2052 +			{
  1.2053 +				RemoveFromQ();
  1.2054 +				ReleasePicture(pic);
  1.2055 +				PicturesSkipped();				
  1.2056 +			}
  1.2057 +			break;
  1.2058 +		} // end of switch
  1.2059 +		
  1.2060 +		// get the next picture
  1.2061 +		pic = PeekQ();	
  1.2062 +    } // end of while
  1.2063 +    
  1.2064 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost --"), this);
  1.2065 + 	return err;
  1.2066 +}
  1.2067 +
  1.2068 +TInt CNGAPostProcHwDevice::IsTimeToPost(TVideoPicture* frame, TInt64& delta)
  1.2069 +{
  1.2070 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost ++"), this);
  1.2071 +
  1.2072 +    if (!frame)
  1.2073 +    {
  1.2074 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost FAILED: Invalid frame ptr."), this);
  1.2075 +		return KErrGeneral;
  1.2076 +	}
  1.2077 +
  1.2078 +    TInt resp = EPostIt;
  1.2079 +    // Frame presentation time
  1.2080 +    TInt64 uPresTime = frame->iTimestamp.Int64();
  1.2081 +      
  1.2082 +    // Check if this is an out of order frame in case of forward playback
  1.2083 +    if((iCurrentPlaybackPosition.Int64() > uPresTime) && (iPlayRate > 0))    
  1.2084 +    {      
  1.2085 +         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (forward playback) Tfm=%d"), this,(TInt)uPresTime);
  1.2086 +         resp = ESkipIt;  //drop      
  1.2087 +    }      // Check if this is an out of order frame in case of backward playback
  1.2088 +    else if((iCurrentPlaybackPosition.Int64() < uPresTime) && (iPlayRate < 0))    
  1.2089 +    {      
  1.2090 +        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (backward playback) Tfm=%d"), this,(TInt)uPresTime);
  1.2091 +        resp = ESkipIt;  //drop      
  1.2092 +    }
  1.2093 +    else if (iClockSource)
  1.2094 +    {
  1.2095 +        // The time to sync with.
  1.2096 +        TInt64 uSyncTime = iClockSource->Time().Int64();
  1.2097 +        
  1.2098 +        delta = uPresTime - uSyncTime;
  1.2099 +        if (( delta > KRenderAhead ) &&  (iPlayRate > 0))	// Delay condition not checked for 
  1.2100 +        {													// backward playback
  1.2101 +        	resp = EDelayIt;  //wait
  1.2102 +        }
  1.2103 +        else if ( (delta < (-KMaxRenderDelay) && (iPlayRate > 0))
  1.2104 +          		||  ((delta > KMaxRenderDelay) && (iPlayRate < 0)))
  1.2105 +        {
  1.2106 +            resp = ESkipIt;  //drop
  1.2107 +        }
  1.2108 +       PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost .. Tfm=%d, Tcs=%d, delta=%d"), this, (TInt)uPresTime, (TInt)uSyncTime, (TInt)delta);
  1.2109 +    }       
  1.2110 +   
  1.2111 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost -- %d BufID = %d"), this, resp, GetID(frame));
  1.2112 +    return resp;
  1.2113 +}
  1.2114 +
  1.2115 +void CNGAPostProcHwDevice::ReleaseInputQ()
  1.2116 +{
  1.2117 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputQ ++ Q = %d"), this, iInputQ.Count());
  1.2118 +    while (iInputQ.Count()>0)
  1.2119 +    {
  1.2120 +    	ReleasePicture(iInputQ[0]);
  1.2121 +        iInputQ.Remove(0);
  1.2122 +    }
  1.2123 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputQ --"), this);
  1.2124 +}
  1.2125 +
  1.2126 +void CNGAPostProcHwDevice::ReleaseProcessQ()
  1.2127 +{
  1.2128 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseProcessQ ++ Q = %d"), this, iProcessQ.Count() );
  1.2129 +	TVideoPicture* pic = NULL;
  1.2130 +	
  1.2131 +    while (iProcessQ.Count()>0)
  1.2132 +    {
  1.2133 +		pic = iProcessQ[0];
  1.2134 +		iProcessQ.Remove(0);
  1.2135 +		ReturnPicToDecoder(pic);
  1.2136 +    }
  1.2137 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseProcessQ --"), this);
  1.2138 +}
  1.2139 +
  1.2140 +void CNGAPostProcHwDevice::ReleasePicture(TVideoPicture *pic)
  1.2141 +{
  1.2142 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleasePicture ++"), this);
  1.2143 +	if (pic == NULL)
  1.2144 +	{
  1.2145 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture FAILED: Invalid pic ptr."), this);
  1.2146 +		return;
  1.2147 +	}
  1.2148 +	
  1.2149 +   	if (iInputDecoderDevice)
  1.2150 +    {
  1.2151 +       PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture .. before return picture. 2"), this);
  1.2152 +        iInputDecoderDevice->ReturnPicture(pic);
  1.2153 +    }
  1.2154 +	if (iVBMEnabled)
  1.2155 +    {
  1.2156 +        iVBMBufferQ.Append(pic);
  1.2157 +
  1.2158 +        if ( !iIsInputEnded && iPPState != EStopped )
  1.2159 +        {
  1.2160 +            iVBMObserver->MmvbmoNewBuffers();
  1.2161 +        }
  1.2162 +	}
  1.2163 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleasePicture --"), this);
  1.2164 +}
  1.2165 +
  1.2166 +void CNGAPostProcHwDevice::PublishSurfaceCreated()
  1.2167 +{
  1.2168 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PublishSurfaceCreated ++"), this);   
  1.2169 +	if(iVideoSurfaceObserver)
  1.2170 +	{
  1.2171 +		iVideoSurfaceObserver->MmvsoSurfaceCreated();
  1.2172 +		iSurfaceCreatedEventPublished = ETrue;
  1.2173 +	}
  1.2174 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PublishSurfaceCreated --"), this);
  1.2175 +}
  1.2176 +
  1.2177 +TInt CNGAPostProcHwDevice::SetupSurface()
  1.2178 +{
  1.2179 +	TInt err = KErrNone;
  1.2180 +	if(iVBMEnabled && iVBMObserver)
  1.2181 +    {
  1.2182 +    	SetSurfaceAttributes(iVBMBufferOptions.iBufferSize, iVBMBufferOptions.iNumInputBuffers);
  1.2183 +    	
  1.2184 +	  	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1.2185 +	  	if (err != KErrNone)
  1.2186 +    	{
  1.2187 +    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create Surface %d"), this, err);
  1.2188 +    	    return err;
  1.2189 +    	}
  1.2190 +    	err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
  1.2191 +    	if (err != KErrNone)
  1.2192 +    	{
  1.2193 +    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to map Surface %d"), this, err);
  1.2194 +    	  	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.2195 +	   		iSurfaceId = TSurfaceId::CreateNullId();
  1.2196 +    	    return err;
  1.2197 +    	}
  1.2198 +    	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1.2199 +    	if (err != KErrNone)
  1.2200 +    	{
  1.2201 +    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to get Surface info %d"), this, err);
  1.2202 +    	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.2203 +	   		iSurfaceId = TSurfaceId::CreateNullId();
  1.2204 +    	    return err;
  1.2205 +    	}
  1.2206 +    	TRAP(err, CreateVBMBuffersL());
  1.2207 +    	if (err != KErrNone)
  1.2208 +    	{
  1.2209 +    	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  1.2210 +    	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1.2211 +	   		iSurfaceId = TSurfaceId::CreateNullId();
  1.2212 +    	    return err;
  1.2213 +    	}
  1.2214 +        err = AddHints();
  1.2215 +        if (err != KErrNone)
  1.2216 +        {
  1.2217 +            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to AddHints %d"), this, err);
  1.2218 +            return err;
  1.2219 +        }
  1.2220 +        err = RegisterSurface(iSurfaceId);
  1.2221 +        if (err != KErrNone)
  1.2222 +        {
  1.2223 +            PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to RegisterSurface %d"), this, err);
  1.2224 +            iSurfaceHandler->DestroySurface(iSurfaceId);
  1.2225 +            iSurfaceId = TSurfaceId::CreateNullId();
  1.2226 +            return err;
  1.2227 +        }
  1.2228 +        
  1.2229 +    }
  1.2230 +    return err;
  1.2231 +} 
  1.2232 +
  1.2233 +void CNGAPostProcHwDevice::SetSurfaceAttributes(const TSize& aSize, TInt aNumBuf)
  1.2234 +{
  1.2235 +	iAttributes().iSize                   = aSize; // size of the video frame
  1.2236 +    iAttributes().iBuffers            	  = aNumBuf;
  1.2237 +    
  1.2238 +    /* The stride needs to be calculated for the surface manager to know
  1.2239 +    how much memory to allocate */
  1.2240 +    
  1.2241 +    if(iAttributes().iPixelFormat == EUidPixelFormatYUV_420Planar)
  1.2242 +    	{
  1.2243 +    		iAttributes().iStride       = aSize.iWidth * 3/2;
  1.2244 +    		iVideoFrameBufSize			= aSize.iWidth * aSize.iHeight * 3/2;
  1.2245 +    	}
  1.2246 +    	else
  1.2247 +    	{
  1.2248 +    		iAttributes().iStride       = aSize.iWidth * 2;
  1.2249 +    		iVideoFrameBufSize			= aSize.iWidth * aSize.iHeight * 2;
  1.2250 +    	}
  1.2251 +    		
  1.2252 +    if(iIsColorConversionNeeded)
  1.2253 +    {
  1.2254 +    	iAttributes().iBuffers            = aNumBuf + KColorConversionBuffers;
  1.2255 +    }
  1.2256 +    else
  1.2257 +    {
  1.2258 +    	iAttributes().iBuffers            = aNumBuf;	
  1.2259 +    }
  1.2260 +    
  1.2261 +    iAttributes().iOffsetToFirstBuffer    = 0;
  1.2262 +#if defined __WINSCW__ 
  1.2263 +    iAttributes().iAlignment              = 4;
  1.2264 +#else //on hw, its always better to have page aligned chunks
  1.2265 +    iAttributes().iAlignment              = -1;
  1.2266 +#endif
  1.2267 +    iAttributes().iContiguous             = ETrue;
  1.2268 +    iAttributes().iHintCount              = 0;
  1.2269 +    iAttributes().iMappable               = ETrue;
  1.2270 +}
  1.2271 +
  1.2272 +TInt CNGAPostProcHwDevice::GetID(TVideoPicture *aPicture)
  1.2273 +{
  1.2274 +    if (iUsingExternalSurface)
  1.2275 +    {
  1.2276 +	    return GetExternalBufferID(aPicture);
  1.2277 +    }
  1.2278 +    else
  1.2279 +    {
  1.2280 +        TUint8* aPtr = (TUint8*) aPicture->iData.iRawData->Ptr();
  1.2281 +        return( (TInt) ((aPtr - iChunk.Base() - iAttributes().iOffsetToFirstBuffer) / 
  1.2282 +			(iVideoFrameBufSize )));
  1.2283 +    }
  1.2284 +}
  1.2285 +
  1.2286 +TInt CNGAPostProcHwDevice::GetExternalBufferID(TVideoPicture *aPicture)
  1.2287 +{
  1.2288 +    // currently type cast the pointer as buffer ID.
  1.2289 +    // FIXME once the new data structure is available.
  1.2290 +    return( (TInt) aPicture->iData.iRawData->Ptr());
  1.2291 +}
  1.2292 +
  1.2293 +TInt CNGAPostProcHwDevice::RegisterSurface(const TSurfaceId& aSurfaceId)
  1.2294 +{
  1.2295 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:RegisterSurface(): RegisterSurface ID = 0x%x"), this, aSurfaceId);
  1.2296 +	TInt err = KErrNone;
  1.2297 +	TInt numScreens = iWsSession.NumberOfScreens();
  1.2298 +	for(TInt i=0; (i < numScreens && err == KErrNone); i++)
  1.2299 +	{
  1.2300 +		err = iWsSession.RegisterSurface(i, aSurfaceId);
  1.2301 +	}	
  1.2302 +	return(err);
  1.2303 +}
  1.2304 +
  1.2305 +TInt CNGAPostProcHwDevice::IsGceReady()
  1.2306 +{
  1.2307 +    if(iProcessQ.Count() >= KMaxBuffersGceCanHold)
  1.2308 +    {
  1.2309 +    		return EFalse;
  1.2310 +    }
  1.2311 +    return ETrue;
  1.2312 +}
  1.2313 +
  1.2314 +void CNGAPostProcHwDevice::SetTimer(TInt64 aDelta)
  1.2315 +{
  1.2316 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetTimer .. aDelta=%d"), this, (TInt)aDelta);
  1.2317 +	if(aDelta <= KRenderAhead)
  1.2318 +	{
  1.2319 +		if(aDelta < 0)
  1.2320 +		{
  1.2321 +			iPostingTimer->After(aDelta * -1);
  1.2322 +		}
  1.2323 +		else
  1.2324 +		{
  1.2325 +			iPostingTimer->After((aDelta - KRenderAhead) * -1);
  1.2326 +		}
  1.2327 +	}
  1.2328 +	else
  1.2329 +	{
  1.2330 +		iPostingTimer->After(aDelta - KRenderAhead - KPostingOfset);
  1.2331 +	}
  1.2332 +}
  1.2333 +//
  1.2334 +// Convert YUV420 to YUV422InterLeaved.
  1.2335 +//
  1.2336 +TInt CNGAPostProcHwDevice::ConvertPostProcBuffer(TVideoPicture* pSrc, TVideoPicture* pDest)
  1.2337 +{
  1.2338 +    PP_DEBUG(_L("CMdfPostingSurfaceProxy::ConvertPostProcBuffer ++"));
  1.2339 +    TInt err = KErrNone;
  1.2340 +    if (!pDest && !pSrc)
  1.2341 +	{
  1.2342 +		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ConvertPostProcBuffer FAILED: Invalid pic pSrc %x pDest %x."), this, pSrc, pDest);
  1.2343 +		return KErrArgument;
  1.2344 +	}
  1.2345 +    
  1.2346 +    // --- Prepare wrappers ---
  1.2347 +    tBaseVideoFrame tFrame420, tFrame422;
  1.2348 +    TInt    frameSize = pSrc->iData.iDataSize.iWidth * pSrc->iData.iDataSize.iHeight;
  1.2349 +
  1.2350 +   PP_DEBUG(_L("CMdfPostingSurfaceProxy::ConvertPostProcBuffer .. w=%d, h=%d"), pSrc->iData.iDataSize.iWidth, pSrc->iData.iDataSize.iHeight);
  1.2351 +
  1.2352 +    tFrame420.width = pSrc->iData.iDataSize.iWidth;
  1.2353 +    tFrame420.height= pSrc->iData.iDataSize.iHeight;
  1.2354 +    tFrame420.lum   = (TUint8*)pSrc->iData.iRawData->Ptr();
  1.2355 +    tFrame420.cb    = (TUint8*)tFrame420.lum + frameSize;
  1.2356 +    tFrame420.cr    = (TUint8*)tFrame420.lum + (frameSize*5)/4;
  1.2357 +    
  1.2358 +    tFrame422.width = pSrc->iData.iDataSize.iWidth;
  1.2359 +    tFrame422.height= pSrc->iData.iDataSize.iHeight;
  1.2360 +    tFrame422.lum   = (TUint8*)pDest->iData.iRawData->Ptr();
  1.2361 +    tFrame422.cb    = 0;
  1.2362 +    tFrame422.cr    = 0;
  1.2363 +    
  1.2364 +    // --- Convertion to posting buffer ---
  1.2365 +    TInt stride     = pSrc->iData.iDataSize.iWidth * 2;
  1.2366 +    EBufferLayout422 layout = YUV422INT_BE;
  1.2367 +        
  1.2368 +    err = gColorConvYUVtoYUV422Int(&tFrame420, &tFrame422, layout, stride);
  1.2369 +    if(err != KErrNone)
  1.2370 +    {
  1.2371 +    		PP_DEBUG(_L("CNGAPostProcHwDevice::ConvertPostProcBuffer .. err= %d."), err);
  1.2372 +    }
  1.2373 +	return err;
  1.2374 +}   
  1.2375 +
  1.2376 +void CNGAPostProcHwDevice::AddPictureToVBMQ(TVideoPicture *pic)
  1.2377 +{
  1.2378 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToVBMQ ++"), this);
  1.2379 +    iVBMBufferQ.Append(pic);
  1.2380 +
  1.2381 +    if ( !iIsInputEnded && iPPState != EStopped )
  1.2382 +    {
  1.2383 +        iVBMObserver->MmvbmoNewBuffers();
  1.2384 +    }
  1.2385 +	
  1.2386 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToVBMQ --"), this);
  1.2387 +}
  1.2388 +
  1.2389 +void CNGAPostProcHwDevice::AddPictureToColorConversionQ(TVideoPicture *pic)
  1.2390 +{
  1.2391 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToColorConversionQ ++"), this);
  1.2392 +    iColorConversionQ.Append(pic);
  1.2393 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToColorConversionQ --"), this);
  1.2394 +}
  1.2395 +
  1.2396 +#ifdef _DUMP_YUV_FRAMES
  1.2397 +void CNGAPostProcHwDevice::captureYuv(TVideoPicture* aPicture)
  1.2398 +{
  1.2399 +	char buf[128];              
  1.2400 +	sprintf(buf, "c:\\fb%d.yuv", count++);          
  1.2401 +	FILE *fp = ::fopen(buf, "w");
  1.2402 +	TInt size = aPicture->iData.iRawData->Size();
  1.2403 +	//{FILE* f1 = fopen(MY_LOG_FILE_NAME, "a+"));if(f1){fprintf(f1, "Size  %d \n"), size );fclose(f1); }}
  1.2404 +
  1.2405 +	::fwrite(aPicture->iData.iRawData->Ptr(), 1, size, fp);
  1.2406 +	::fclose(fp);    	
  1.2407 +}
  1.2408 +#endif
  1.2409 +
  1.2410 +void CNGAPostProcHwDevice::ResetCountingBuffer()
  1.2411 +{       
  1.2412 +	memset(iSkippedFramesCountingBuffer,0,sizeof(iSkippedFramesCountingBuffer));
  1.2413 +    iSkippedFramesInLast64Frames = 0;       
  1.2414 +    iCurrentPosInFramesCountingBuffer = 0;       
  1.2415 +} 
  1.2416 +
  1.2417 +void CNGAPostProcHwDevice::PicturesSkipped()
  1.2418 +{       
  1.2419 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PicturesSkipped ++"), this);
  1.2420 +	iPictureCounters.iPicturesSkipped++;
  1.2421 +	if (!iKeyFrameMode && iPlayRate>KDefPlayRate)
  1.2422 +    {       
  1.2423 +    	if (iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer]==0)        
  1.2424 +        {       
  1.2425 +        	iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer] = 1;       
  1.2426 +            iSkippedFramesInLast64Frames++;       
  1.2427 +            if (iSkippedFramesInLast64Frames>KMaxAllowedSkipInNFrames && iFPObserver )       
  1.2428 +            {       
  1.2429 +            	iFPObserver->MmvproKeyFrameModeRequest();       
  1.2430 +                iKeyFrameMode=ETrue;       
  1.2431 +                ResetCountingBuffer();       
  1.2432 +            }       
  1.2433 +        }       
  1.2434 +        iCurrentPosInFramesCountingBuffer = ++iCurrentPosInFramesCountingBuffer%64;       
  1.2435 +    }
  1.2436 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PicturesSkipped --"), this);   
  1.2437 +}
  1.2438 +
  1.2439 +TVideoPicture* CNGAPostProcHwDevice::DoColorConvert(TVideoPicture* aPicture)
  1.2440 +{
  1.2441 +    TVideoPicture *pOutPicture  = aPicture;
  1.2442 +    					    		
  1.2443 +	if(iColorConversionQ.Count())
  1.2444 +    {
  1.2445 +	    pOutPicture    = iColorConversionQ[0];
  1.2446 +	    iColorConversionQ.Remove(0);
  1.2447 +	    ConvertPostProcBuffer(aPicture, pOutPicture);
  1.2448 +	   	pOutPicture->iTimestamp = aPicture->iTimestamp;
  1.2449 +	    ReleasePicture(aPicture);    	    
  1.2450 +    }				    
  1.2451 +    else
  1.2452 +    {
  1.2453 +       PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: color conversion"), this);
  1.2454 +    }
  1.2455 +
  1.2456 +	return pOutPicture;
  1.2457 +}
  1.2458 +
  1.2459 +TInt CNGAPostProcHwDevice::AddToQ(TVideoPicture* aPicture)
  1.2460 +{
  1.2461 +	TVideoPicture* pic = aPicture;
  1.2462 +	TInt pos = -1;
  1.2463 +	if(iInputQ.Count() == 0)
  1.2464 +	{
  1.2465 +		iInputQ.Append(pic);
  1.2466 +	}
  1.2467 +	else
  1.2468 +	{
  1.2469 +		pos = iInputQ.Count()-1;
  1.2470 +		for(; pos >= 0; pos--)
  1.2471 +		{
  1.2472 +			if(pic->iTimestamp.Int64() > iInputQ[pos]->iTimestamp.Int64())
  1.2473 +			{
  1.2474 +				break;
  1.2475 +			}
  1.2476 +		} 
  1.2477 +		if(iInputQ.Count() == pos+1)
  1.2478 +		{
  1.2479 +			iInputQ.Append(pic);
  1.2480 +		}
  1.2481 +		else
  1.2482 +		{
  1.2483 +			iInputQ.Insert(pic, pos+1);
  1.2484 +		}
  1.2485 +	}
  1.2486 +	return pos+1;
  1.2487 +}
  1.2488 +
  1.2489 +void CNGAPostProcHwDevice::RemoveFromQ()
  1.2490 +{
  1.2491 +	if(iInputQ.Count())
  1.2492 +	{
  1.2493 +		if(iPlayRate > 0)
  1.2494 +		{
  1.2495 +			iInputQ.Remove(0);
  1.2496 +		}
  1.2497 +		else
  1.2498 +		{
  1.2499 +			iInputQ.Remove(iInputQ.Count()-1);
  1.2500 +		}
  1.2501 +	}
  1.2502 +}
  1.2503 +
  1.2504 +TVideoPicture* CNGAPostProcHwDevice::PeekQ()
  1.2505 +{	
  1.2506 +	TVideoPicture *pic = NULL;
  1.2507 +	if(iInputQ.Count())
  1.2508 +	{
  1.2509 +		if(iPlayRate > 0)
  1.2510 +		{			
  1.2511 +			pic = iInputQ[0];
  1.2512 +		}
  1.2513 +		else
  1.2514 +		{			
  1.2515 +			pic = iInputQ[iInputQ.Count()-1];
  1.2516 +		}	
  1.2517 +	}
  1.2518 +	return pic;
  1.2519 +}
  1.2520 +
  1.2521 +TInt CNGAPostProcHwDevice::AddHints()
  1.2522 +{
  1.2523 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints iSurfaceMask 0x%08x ++"), this, iSurfaceMask);
  1.2524 +   TInt err = KErrNone;
  1.2525 +   iHint.Set(iSurfaceKey,iSurfaceMask,ETrue);
  1.2526 +   err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
  1.2527 +   if(err == KErrAlreadyExists)
  1.2528 +   {
  1.2529 +		err = KErrNone;
  1.2530 +		err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
  1.2531 +   }
  1.2532 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
  1.2533 +   iHint.iKey.iUid = surfaceHints::KSurfaceContent;
  1.2534 +   iHint.iValue = surfaceHints::EVideoPlayback;
  1.2535 +   iHint.iMutable = ETrue;
  1.2536 +   err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
  1.2537 +   if(err == KErrAlreadyExists)
  1.2538 +   {
  1.2539 +		err = KErrNone;
  1.2540 +		err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
  1.2541 +   }
  1.2542 +   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
  1.2543 +   return err;
  1.2544 +}
  1.2545 +
  1.2546 +TInt CNGAPostProcHwDevice::ColorConvert(tBaseVideoFrame* aInputFrame, TUint8* aDestPtr, tWndParam* aInputCropWindow, tWndParam* aOutputCropWindow)
  1.2547 +{
  1.2548 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert ++"), this);
  1.2549 +	__ASSERT_ALWAYS(aDestPtr, User::Invariant());
  1.2550 +	TInt				lError = E_SUCCESS;
  1.2551 +	TInt				err = KErrNone;
  1.2552 +	
  1.2553 +	err = SetSourceFormat();
  1.2554 +	if(err == KErrNone)
  1.2555 +	{
  1.2556 +    	err = SetSourceRange();
  1.2557 +    	if(err == KErrNone)
  1.2558 +    	{
  1.2559 +						
  1.2560 +			lError = Emz_VDec_gColorConv_YUVtoRGB(aInputFrame,aDestPtr, 
  1.2561 +						aInputCropWindow, aOutputCropWindow, iSourceFormat,
  1.2562 +						EBitmapColor16MU, iSourceRange);
  1.2563 +
  1.2564 +			if(lError)
  1.2565 +			{
  1.2566 +				if(lError == E_OUT_OF_MEMORY)
  1.2567 +					{
  1.2568 +					err = KErrNoMemory;
  1.2569 +					}
  1.2570 +				else if(lError == E_FAILURE)
  1.2571 +					{
  1.2572 +					err = KErrNotSupported;
  1.2573 +					}
  1.2574 +				else
  1.2575 +					{
  1.2576 +					err = KErrGeneral;
  1.2577 +					}
  1.2578 +			}
  1.2579 +		}
  1.2580 +	}
  1.2581 +	
  1.2582 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert --"), this);
  1.2583 +	return err;
  1.2584 +}
  1.2585 +
  1.2586 +TInt CNGAPostProcHwDevice::SetSourceFormat()
  1.2587 +{
  1.2588 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL ++"), this);
  1.2589 +	TInt err = KErrNone;
  1.2590 +	switch (iVideoFormat.iYuvFormat.iPattern)
  1.2591 +	{
  1.2592 +	    case EYuv420Chroma1:
  1.2593 +    		iSourceFormat = EYuv420Chroma1_Planar;
  1.2594 +    		break;
  1.2595 +        case EYuv420Chroma2:
  1.2596 +    		iSourceFormat = EYuv420Chroma2_Planar;
  1.2597 +    		break;
  1.2598 +        case EYuv420Chroma3:
  1.2599 +    		iSourceFormat = EYuv420Chroma3_Planar;
  1.2600 +    		break;
  1.2601 +	    case EYuv422Chroma1:
  1.2602 +			if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
  1.2603 +    			iSourceFormat = EYuv422Chroma1_LE;
  1.2604 +	    	else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
  1.2605 +				iSourceFormat = EYuv422Chroma1_BE;
  1.2606 +			else
  1.2607 +			    err = KErrArgument;
  1.2608 +			break;
  1.2609 +    	case EYuv422Chroma2:
  1.2610 +    		if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
  1.2611 +	    		iSourceFormat = EYuv422Chroma2_LE;
  1.2612 +    		else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
  1.2613 +    			iSourceFormat = EYuv422Chroma2_BE;
  1.2614 +			else
  1.2615 +			    err = KErrArgument;
  1.2616 +			break;
  1.2617 +      default:
  1.2618 +    		err = KErrNotSupported;
  1.2619 +	}
  1.2620 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL --"), this);
  1.2621 +	return err;
  1.2622 +}
  1.2623 +
  1.2624 +
  1.2625 +TInt CNGAPostProcHwDevice::SetSourceRange()
  1.2626 +{
  1.2627 +	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL ++"), this);
  1.2628 +	TInt err = KErrNone;
  1.2629 +	switch (iVideoFormat.iYuvFormat.iCoefficients)
  1.2630 +	{
  1.2631 +	    case EYuvBt601Range0:
  1.2632 +			iSourceRange = EITU601_5_REDUCEDRANGE;
  1.2633 +            break;
  1.2634 +        case EYuvBt601Range1:
  1.2635 +			iSourceRange = EITU601_5_FULLRANGE;
  1.2636 +			break;
  1.2637 +        case EYuvBt709Range0:
  1.2638 +			iSourceRange = EB709_REDUCEDRANGE;
  1.2639 +			break;
  1.2640 +        case EYuvBt709Range1:
  1.2641 +			iSourceRange = EB709_FULLRANGE;
  1.2642 +            break;
  1.2643 +	    default:
  1.2644 +		    err = KErrNotSupported;
  1.2645 +    }
  1.2646 +    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL --"), this);
  1.2647 +    return err;
  1.2648 +}
  1.2649 +
  1.2650 +CNGAPostProcTimer::CNGAPostProcTimer( CNGAPostProcHwDevice& aParent )
  1.2651 +:CTimer(EPriorityHigh),iParent(aParent)
  1.2652 +{
  1.2653 +	CActiveScheduler::Add(this);
  1.2654 +}
  1.2655 +
  1.2656 +CNGAPostProcTimer::~CNGAPostProcTimer()
  1.2657 +{
  1.2658 +	PP_DEBUG(_L("CNGAPostProcTimer[%x]:~CNGAPostProcTimer ++"), this);
  1.2659 +	Cancel();
  1.2660 +	PP_DEBUG(_L("CNGAPostProcTimer[%x]:~CNGAPostProcTimer --"), this);
  1.2661 +}
  1.2662 +
  1.2663 +CNGAPostProcTimer* CNGAPostProcTimer::NewL( CNGAPostProcHwDevice& aParent )
  1.2664 +{
  1.2665 +	CNGAPostProcTimer* self = new (ELeave)CNGAPostProcTimer(aParent);
  1.2666 +	CleanupStack::PushL( self );
  1.2667 +	self->ConstructL();
  1.2668 +	CleanupStack::Pop( self );
  1.2669 +	return self;
  1.2670 +}
  1.2671 +
  1.2672 +void CNGAPostProcTimer::ConstructL()
  1.2673 +{
  1.2674 +	CTimer::ConstructL();
  1.2675 +}
  1.2676 +
  1.2677 +void CNGAPostProcTimer::RunL()
  1.2678 +{
  1.2679 +	PP_DEBUG(_L("CNGAPostProcTimer[%x]:RunL ++"), this);
  1.2680 +	if (iStatus ==KErrCancel)
  1.2681 +	{
  1.2682 +		PP_DEBUG(_L("CNGAPostProcNotifier[%x]:CNGAPostProcNotifier:RunL State canceled"), this);
  1.2683 +		return;
  1.2684 +	}
  1.2685 +	iParent.AttemptToPost();
  1.2686 +	PP_DEBUG(_L("CNGAPostProcTimer[%x]:RunL --"), this);
  1.2687 +}
  1.2688 +
  1.2689 +void CNGAPostProcHwDevice::MmpirPostInitializeRequest(MMmfPostInitializeResponse& aResponse)
  1.2690 +	{
  1.2691 +	iPostInitializeResponse = &aResponse;
  1.2692 +	}