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