mdfdevvideoextensions/nga_mdf_postprocessor/src/NGAPostProcHwDevice.cpp
changeset 13 efebd1779a59
parent 0 40261b775718
child 15 c1e808730d6c
equal deleted inserted replaced
0:40261b775718 13:efebd1779a59
    53 
    53 
    54 //**************************************************
    54 //**************************************************
    55 
    55 
    56 CMMFVideoPostProcHwDevice* CNGAPostProcHwDevice::NewL() 
    56 CMMFVideoPostProcHwDevice* CNGAPostProcHwDevice::NewL() 
    57 { 
    57 { 
    58    PP_DEBUG(_L("CNGAPostProcHwDevice:NewL() ++"));
    58    PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() ++"));
    59 
    59 
    60     CNGAPostProcHwDevice* self = new (ELeave) CNGAPostProcHwDevice; 
    60     CNGAPostProcHwDevice* self = new (ELeave) CNGAPostProcHwDevice; 
    61     CleanupStack::PushL(self);
    61     CleanupStack::PushL(self);
    62     self->ConstructL(); 
    62     self->ConstructL(); 
    63     CleanupStack::Pop();
    63     CleanupStack::Pop();
    64 
    64 
    65    PP_DEBUG(_L("CNGAPostProcHwDevice:NewL() --"));
    65    PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() --"));
    66     return (CMMFVideoPostProcHwDevice*)self; 
    66     return (CMMFVideoPostProcHwDevice*)self; 
    67 }
    67 }
    68 
    68 
    69 void CNGAPostProcHwDevice::ConstructL() 
    69 void CNGAPostProcHwDevice::ConstructL() 
    70 { 
    70 { 
    71    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ConstructL() ++"), this);
    71    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() ++"), this);
    72     
    72     
    73     // support for VBM buffer interface
    73     // support for VBM buffer interface
    74     iVBMBufferOptions.iNumInputBuffers  = KMaxVBMBuffers; 
    74     iVBMBufferOptions.iNumInputBuffers  = KMaxVBMBuffers; 
    75     iVBMBufferOptions.iBufferSize = TSize(KMaxVBMInputWidth, KMaxVBMInputHeight);
    75     iVBMBufferOptions.iBufferSize = TSize(KMaxVBMInputWidth, KMaxVBMInputHeight);
    76     iPostingTimer = CNGAPostProcTimer::NewL(*this);
    76     iPostingTimer = CNGAPostProcTimer::NewL(*this);
    77     iWsSession.Connect();
    77     iWsSession.Connect();
    78    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ConstructL() --"), this);
    78    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() --"), this);
    79 }
    79 }
    80 
    80 
    81 CNGAPostProcHwDevice::CNGAPostProcHwDevice() 
    81 CNGAPostProcHwDevice::CNGAPostProcHwDevice() 
    82         :   iProxy(NULL), 
    82         :   iProxy(NULL), 
    83             iInputDecoderDevice(NULL),
    83             iInputDecoderDevice(NULL),
   104             iStepFrameCount(0),
   104             iStepFrameCount(0),
   105             iPlayRate(KDefPlayRate),
   105             iPlayRate(KDefPlayRate),
   106             iKeyFrameMode(EFalse),
   106             iKeyFrameMode(EFalse),
   107             iFPObserver(NULL)
   107             iFPObserver(NULL)
   108 {
   108 {
   109 	iRedrawSurfaceId = TSurfaceId::CreateNullId();
       
   110 	iSurfaceId 		 = TSurfaceId::CreateNullId();
   109 	iSurfaceId 		 = TSurfaceId::CreateNullId();
   111 	iAttributes().iPixelFormat    = EUidPixelFormatYUV_422Interleaved;
   110 	iAttributes().iPixelFormat    = EUidPixelFormatYUV_422Interleaved;
   112 }
   111 }
   113 
   112 
   114 CNGAPostProcHwDevice::~CNGAPostProcHwDevice()
   113 CNGAPostProcHwDevice::~CNGAPostProcHwDevice()
   115 {
   114 {
   116    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:~() ++"), this);
   115    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::~CNGAPostProcHwDevice() ++"), this);
   117    	if (iSessionManager)
   116    	if (iSessionManager)
   118     {
   117     {
   119         iSessionManager->CancelUpdate();
   118         iSessionManager->CancelUpdate();
   120         delete iSessionManager;
   119         delete iSessionManager;
   121         iSessionManager = NULL;
   120         iSessionManager = NULL;
   361     {
   360     {
   362 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Invalid argument"), this);
   361 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Invalid argument"), this);
   363 		User::Leave(KErrArgument);
   362 		User::Leave(KErrArgument);
   364 	}
   363 	}
   365 	pic = aPicture;	
   364 	pic = aPicture;	
   366 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture bufId = %d"), this,GetID(pic));
   365     if (iInputQ.Count() > 0)
   367 	iPictureCounters.iTotalPictures++;
   366     {
   368 	TInt64 delta = 0;
   367         AddToQ(pic);
   369 	TTimeToPost iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
   368         AttemptToPost();
   370 	if(!IsGceReady())
   369     }
   371     {  
   370     else
   372 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL GCE not ready"), this );
   371     {
   373 		if(iTimeToPost == EPostIt)
   372 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture bufId = %d"), this,GetID(pic));
       
   373 		iPictureCounters.iTotalPictures++;
       
   374 		TInt64 delta = 0;
       
   375 		TTimeToPost iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
       
   376 		if(!IsGceReady())
       
   377 	    {  
       
   378 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL GCE not ready"), this );
       
   379 			if(iTimeToPost == EPostIt)
       
   380 			{
       
   381 					iTimeToPost = EDelayIt;
       
   382 			}
       
   383 	    }
       
   384 	    if (delta > 0x7FFFFFFF)
       
   385 	    {
       
   386 	         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL Too large delta .. skipping"), this ); 
       
   387 	         iTimeToPost = ESkipIt;
       
   388 	    }
       
   389 	
       
   390 		switch(iTimeToPost)
   374 		{
   391 		{
   375 				iTimeToPost = EDelayIt;
   392 			case EDelayIt:
       
   393 			{
       
   394 				if(AddToQ(pic) != 0)
       
   395 				{
       
   396 					break;
       
   397 				}
       
   398 				iPostingTimer->Cancel();
       
   399 				SetTimer(delta);
       
   400 			}
       
   401 			break;
       
   402 			case EPostIt:
       
   403 			{
       
   404 		
       
   405 				if(iIsColorConversionNeeded)
       
   406 				{
       
   407 					TVideoPicture* ccPic;				
       
   408 	    			ccPic = DoColorConvert(pic); // output will be in ccPic
       
   409 	    			pic = ccPic;			   
       
   410 				}
       
   411 				iProcessQ.Append(pic);
       
   412 						
       
   413 				#ifdef _DUMP_YUV_FRAMES
       
   414 				captureYuv(pic);
       
   415 				#endif
       
   416 				iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue);	
       
   417 				iCurrentPlaybackPosition = pic->iTimestamp;			
       
   418 			
       
   419 				if(!iFirstPictureUpdated)
       
   420 				{
       
   421 					iFirstPictureUpdated = ETrue;
       
   422 					PublishSurfaceCreated();
       
   423 				}
       
   424 			}
       
   425 			break;
       
   426 			case ESkipIt:
       
   427 			{
       
   428 				ReleasePicture(pic); 
       
   429 				PicturesSkipped();
       
   430 			}
       
   431 			break;
   376 		}
   432 		}
   377     }
   433     }
   378 	switch(iTimeToPost)
       
   379 	{
       
   380 		case EDelayIt:
       
   381 		{
       
   382 			if(AddToQ(pic) != 0)
       
   383 			{
       
   384 				break;
       
   385 			}
       
   386 			iPostingTimer->Cancel();
       
   387 			SetTimer(delta);
       
   388 		}
       
   389 		break;
       
   390 		case EPostIt:
       
   391 		{
       
   392 		
       
   393 			if(iIsColorConversionNeeded)
       
   394 			{
       
   395 				TVideoPicture* ccPic;				
       
   396     			ccPic = DoColorConvert(pic); // output will be in ccPic
       
   397     			pic = ccPic;			   
       
   398 			}
       
   399 			iProcessQ.Append(pic);
       
   400 						
       
   401 			#ifdef _DUMP_YUV_FRAMES
       
   402 			captureYuv(pic);
       
   403 			#endif
       
   404 			iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue);	
       
   405 			iCurrentPlaybackPosition = pic->iTimestamp;			
       
   406 			
       
   407 			if(!iFirstPictureUpdated)
       
   408 			{
       
   409 				iFirstPictureUpdated = ETrue;
       
   410 				PublishSurfaceCreated();
       
   411 			}
       
   412 		}
       
   413 		break;
       
   414 		case ESkipIt:
       
   415 		{
       
   416 			ReleasePicture(pic); 
       
   417 			PicturesSkipped();
       
   418 		}
       
   419 		break;
       
   420 	}
       
   421 
       
   422 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture --"), this);
   434 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture --"), this);
   423 }
   435 }
   424 
   436 
   425 
   437 
   426 CPostProcessorInfo* 
   438 CPostProcessorInfo* 
   653     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL --"), this);
   665     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL --"), this);
   654 }
   666 }
   655 
   667 
   656 void CNGAPostProcHwDevice::MmavsoSetAllowedOutputL(TUint aAllowedOutputMask)
   668 void CNGAPostProcHwDevice::MmavsoSetAllowedOutputL(TUint aAllowedOutputMask)
   657 {
   669 {
   658    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL aAllowedOutputMask=%d ++"), this,aAllowedOutputMask);  
   670    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL aAllowedOutputMask=0x%08x ++"), this,aAllowedOutputMask);  
   659    TInt err = KErrNone;
   671    TInt err = KErrNone;
   660    iSurfaceMask = surfaceHints::EAllowInternalOnly;
   672    iSurfaceMask = surfaceHints::EAllowInternalOnly;
   661     if (aAllowedOutputMask == EVideoAllowAll)
   673     if (aAllowedOutputMask == EVideoAllowAll)
   662     {
   674     {
   663         iSurfaceMask = surfaceHints::EAllowAllExternals;
   675         iSurfaceMask = surfaceHints::EAllowAllExternals;
   814 { 
   826 { 
   815 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw ++"), this);
   827 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw ++"), this);
   816 	TInt err = KErrNone;
   828 	TInt err = KErrNone;
   817 	if(iResourceLost)
   829 	if(iResourceLost)
   818 	{
   830 	{
       
   831         err = AddHints();
       
   832         if (err != KErrNone)
       
   833         {
       
   834             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to AddHints %d"), 
       
   835                          this, err);
       
   836             iProxy->MdvppFatalError(this, err);	
       
   837             return;   
       
   838         }
   819 		err = RegisterSurface(iSurfaceId);
   839 		err = RegisterSurface(iSurfaceId);
   820 		if (err != KErrNone)
   840 		if (err != KErrNone)
   821 		{
   841 		{
   822 		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to Register Surface %d"), 
   842 		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to Register Surface %d"), 
   823 		   				this, err);
   843 		   				this, err);
   824 		   	iSurfaceHandler->DestroySurface(iSurfaceId);
   844 		   	iSurfaceHandler->DestroySurface(iSurfaceId);
   825 	   		iSurfaceId = TSurfaceId::CreateNullId();
   845 	   		iSurfaceId = TSurfaceId::CreateNullId();
   826 			iProxy->MdvppFatalError(this, err);	
   846 			iProxy->MdvppFatalError(this, err);	
   827 			return;   				
   847 			return;   				
   828 		}
   848 		}
   829         err = AddHints();
   849 
   830         if (err != KErrNone)
   850         iSessionManager->PostPicture(iSurfaceId, 0, 1, EFalse);
   831 		{
   851         PublishSurfaceCreated();
   832 		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to AddHints %d"), 
   852         iResourceLost = EFalse;
   833 		   				this, err);
   853     }
   834 			iProxy->MdvppFatalError(this, err);	
   854     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw --"), this);
   835 			return;   				
       
   836 		}
       
   837 		iSessionManager->PostPicture(iSurfaceId, 0, 1, EFalse);
       
   838 	   	PublishSurfaceCreated();
       
   839 	   	iResourceLost = EFalse;
       
   840 	}
       
   841 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw --"), this);
       
   842 }
   855 }
   843 
   856 
   844 void CNGAPostProcHwDevice::Start() 
   857 void CNGAPostProcHwDevice::Start() 
   845 {  
   858 {  
   846 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start ++"), this);
   859 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start ++"), this);
  1195 		{
  1208 		{
  1196 				err = SetupSurface(aSize);
  1209 				err = SetupSurface(aSize);
  1197 				if(err)
  1210 				if(err)
  1198 				{
  1211 				{
  1199 						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() Surface Setup Failed %d"), this, err);
  1212 						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() Surface Setup Failed %d"), this, err);
  1200         		return NULL;
  1213 						User::Leave(err);
  1201 				}
  1214 				}
  1202 		}
  1215 		}
  1203 		
  1216 		
  1204     if(!iVBMBufferQ.Count())
  1217     if(!iVBMBufferQ.Count())
  1205     {
  1218     {
  1272 }
  1285 }
  1273 
  1286 
  1274 void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
  1287 void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
  1275 {
  1288 {
  1276 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
  1289 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
  1277 	if(iSurfaceId == aSurfaceId && !aSurfaceId.IsNull())
  1290 	if(!aSurfaceId.IsNull())
  1278 	{
  1291 	{
  1279 		if(iInfo().iBuffers > 1) // No need to return temprory redraw surface buffer to decoder
       
  1280 		{
       
  1281 			ReleaseProcessQ();
       
  1282 		}
       
  1283 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
  1292 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
  1284 		iWsSession.UnregisterSurface(0, iSurfaceId);
  1293 		iWsSession.UnregisterSurface(0, aSurfaceId);
  1285 		iSurfaceHandler->DestroySurface(iSurfaceId);
  1294 		iSurfaceHandler->DestroySurface(aSurfaceId);
  1286 		iSurfaceId = TSurfaceId::CreateNullId();
       
  1287 	}
  1295 	}
  1288 		
  1296 		
  1289 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
  1297 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
  1290 }
  1298 }
  1291 
  1299 
  1316 // === MMmfVideoResourceObserver ===
  1324 // === MMmfVideoResourceObserver ===
  1317 
  1325 
  1318 void CNGAPostProcHwDevice::MmvroResourcesLost(TUid )
  1326 void CNGAPostProcHwDevice::MmvroResourcesLost(TUid )
  1319 {
  1327 {
  1320     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ++"), this);
  1328     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ++"), this);
  1321     if(!iRedrawSurfaceId.IsNull())
  1329 	iResourceLost = ETrue;
  1322 	{
  1330 	Pause();
  1323 		iResourceLost = ETrue;
  1331 	ReleaseInputQ();
  1324 		Pause();
  1332 	iSessionManager->CancelUpdate();
  1325 		ReleaseInputQ();
  1333 	ReleaseProcessQ();
  1326 		iSessionManager->CancelUpdate();
  1334 	iVideoSurfaceObserver->MmvsoRemoveSurface();
  1327 		ReleaseProcessQ();
       
  1328 		iWsSession.UnregisterSurface(0, iRedrawSurfaceId);
       
  1329 		iSurfaceHandler->DestroySurface(iRedrawSurfaceId);
       
  1330 		iRedrawSurfaceId = TSurfaceId::CreateNullId();
       
  1331 	}
       
  1332 	else
       
  1333 	{
       
  1334 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesLost ERROR iRedrawSurfaceId NULL"), this);
       
  1335 	}
       
  1336     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost --"), this);
  1335     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost --"), this);
  1337 }
  1336 }
  1338 
  1337 
  1339 // === MMmfVideoPropertiesNotifier ===
  1338 // === MMmfVideoPropertiesNotifier ===
  1340     
  1339     
  1380     }
  1379     }
  1381 
  1380 
  1382    	TInt err = KErrNone;
  1381    	TInt err = KErrNone;
  1383 	SetSurfaceAttributes(surfaceSize, 1); 
  1382 	SetSurfaceAttributes(surfaceSize, 1); 
  1384 	
  1383 	
  1385 	iRedrawSurfaceId = iSurfaceId;
       
  1386 	
       
  1387   	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1384   	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1388   	if (err != KErrNone)
  1385   	if (err != KErrNone)
  1389 	{
  1386 	{
  1390 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to create Surface %d"), 
  1387 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to create Surface %d"), 
  1391 	   				this, err);
  1388 	   				this, err);
  1436     TInt err = KErrNone;
  1433     TInt err = KErrNone;
  1437     
  1434     
  1438     if(!iSurfaceId.IsNull())
  1435     if(!iSurfaceId.IsNull())
  1439     {
  1436     {
  1440     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface Cleaning ReDraw Surface"), this);
  1437     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface Cleaning ReDraw Surface"), this);
  1441 	    iWsSession.UnregisterSurface(0, iSurfaceId);
  1438 		iVideoSurfaceObserver->MmvsoRemoveSurface();
  1442 		iSurfaceHandler->DestroySurface(iSurfaceId);
       
  1443 	}
  1439 	}
  1444     
  1440     
  1445     iSurfaceId            = aSurfaceID;
  1441     iSurfaceId            = aSurfaceID;
  1446     iUsingExternalSurface = ETrue;
  1442     iUsingExternalSurface = ETrue;
  1447     
  1443     
  1462 	{
  1458 	{
  1463 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed OpenSurface %d"), 
  1459 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed OpenSurface %d"), 
  1464 	   				this, err);
  1460 	   				this, err);
  1465 	    return err;
  1461 	    return err;
  1466 	}
  1462 	}
       
  1463     err = AddHints();
       
  1464     if (err != KErrNone)
       
  1465     {
       
  1466         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to AddHints %d"), 
       
  1467                     this, err);
       
  1468         return err;
       
  1469     }
  1467 	err = RegisterSurface(iSurfaceId);
  1470 	err = RegisterSurface(iSurfaceId);
  1468 	if (err != KErrNone)
  1471 	if (err != KErrNone)
  1469 	{
  1472 	{
  1470 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed RegisterSurface %d"), 
  1473 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed RegisterSurface %d"), 
  1471 	   				this, err);
  1474 	   				this, err);
  1472 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1475 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1473 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1476 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1474 	    return err;
  1477 	    return err;
  1475 	}
  1478 	}
  1476 	err = AddHints();
  1479 
  1477 	if (err != KErrNone)
  1480     err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1478 	{
  1481     if (err != KErrNone)
  1479 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to AddHints %d"), 
  1482     {
  1480 	   				this, err);
  1483         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to get Surface info %d"), 
  1481 	    return err;
  1484                      this, err);
  1482 	}
  1485         return err;
  1483 	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
  1486     }
  1484 	if (err != KErrNone)
  1487  
  1485 	{
       
  1486 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to get Surface info %d"), 
       
  1487 	   				this, err);
       
  1488 	    return err;
       
  1489 	}		
       
  1490 	  
       
  1491   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface err=%d"), this, err);
  1488   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface err=%d"), this, err);
  1492    return err;
  1489    return err;
  1493 }
  1490 }
  1494 
  1491 
  1495 //=== Internal ===
  1492 //=== Internal ===
  1588 }
  1585 }
  1589 
  1586 
  1590 TInt CNGAPostProcHwDevice::AttemptToPost()
  1587 TInt CNGAPostProcHwDevice::AttemptToPost()
  1591 {
  1588 {
  1592    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost ++ Q:%d"), this, iInputQ.Count());
  1589    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost ++ Q:%d"), this, iInputQ.Count());
       
  1590    if (iPPState == EPaused)
       
  1591    {
       
  1592         return KErrNone;
       
  1593    }
       
  1594 
  1593     TInt err = KErrNotReady;
  1595     TInt err = KErrNotReady;
  1594     TInt count = iInputQ.Count();
  1596     TInt count = iInputQ.Count();
  1595     TBool bDone = EFalse;
  1597     TBool bDone = EFalse;
  1596     TVideoPicture* pic = PeekQ();   		
  1598     TVideoPicture* pic = PeekQ();   		
  1597   	while(pic && !bDone)
  1599   	while(pic && !bDone)
  1660 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost FAILED: Invalid frame ptr."), this);
  1662 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost FAILED: Invalid frame ptr."), this);
  1661 		return KErrGeneral;
  1663 		return KErrGeneral;
  1662 	}
  1664 	}
  1663 
  1665 
  1664     TInt resp = EPostIt;
  1666     TInt resp = EPostIt;
  1665     
  1667     // Frame presentation time
  1666     if (iClockSource)
  1668     TInt64 uPresTime = frame->iTimestamp.Int64();
  1667     {
  1669       
  1668         // Frame presentation time
  1670     // Check if this is an out of order frame in case of forward playback
  1669         TInt64 uPresTime = frame->iTimestamp.Int64();
  1671     if((iCurrentPlaybackPosition.Int64() >= uPresTime) && (iPlayRate > 0))    
       
  1672     {      
       
  1673          PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (forward playback) Tfm=%d"), this,(TInt)uPresTime);
       
  1674          resp = ESkipIt;  //drop      
       
  1675     }      // Check if this is an out of order frame in case of backward playback
       
  1676     else if((iCurrentPlaybackPosition.Int64() <= uPresTime) && (iPlayRate < 0))    
       
  1677     {      
       
  1678         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (backward playback) Tfm=%d"), this,(TInt)uPresTime);
       
  1679         resp = ESkipIt;  //drop      
       
  1680     }
       
  1681     else if (iClockSource)
       
  1682     {
  1670         // The time to sync with.
  1683         // The time to sync with.
  1671         TInt64 uSyncTime = iClockSource->Time().Int64();
  1684         TInt64 uSyncTime = iClockSource->Time().Int64();
  1672         
  1685         
  1673         delta = uPresTime - uSyncTime;
  1686         delta = uPresTime - uSyncTime;
  1674         if (( delta > KRenderAhead ) &&  (iPlayRate > 0))	// Delay condition not checked for 
  1687         if (( delta > KRenderAhead ) &&  (iPlayRate > 0))	// Delay condition not checked for 
  1788     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  1801     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
  1789     	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1802     	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1790 	   		iSurfaceId = TSurfaceId::CreateNullId();
  1803 	   		iSurfaceId = TSurfaceId::CreateNullId();
  1791     	    return err;
  1804     	    return err;
  1792     	}
  1805     	}
  1793     	err = RegisterSurface(iSurfaceId);
  1806         err = AddHints();
  1794     	if (err != KErrNone)
  1807         if (err != KErrNone)
  1795     	{
  1808         {
  1796     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to RegisterSurface %d"), this, err);
  1809             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to AddHints %d"), this, err);
  1797     	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1810             return err;
  1798 	   		iSurfaceId = TSurfaceId::CreateNullId();
  1811         }
  1799     	    return err;
  1812         err = RegisterSurface(iSurfaceId);
  1800     	}
  1813         if (err != KErrNone)
  1801    	    err = AddHints();
  1814         {
  1802    	    if (err != KErrNone)
  1815             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to RegisterSurface %d"), this, err);
  1803     	{
  1816             iSurfaceHandler->DestroySurface(iSurfaceId);
  1804     	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to AddHints %d"), this, err);
  1817             iSurfaceId = TSurfaceId::CreateNullId();
  1805     	    return err;
  1818             return err;
  1806     	}
  1819         }
       
  1820 
  1807     }
  1821     }
  1808     return err;
  1822     return err;
  1809 } 
  1823 } 
  1810 
  1824 
  1811 void CNGAPostProcHwDevice::SetSurfaceAttributes(const TSize& aSize, TInt aNumBuf)
  1825 void CNGAPostProcHwDevice::SetSurfaceAttributes(const TSize& aSize, TInt aNumBuf)
  2085 	return pic;
  2099 	return pic;
  2086 }
  2100 }
  2087 
  2101 
  2088 TInt CNGAPostProcHwDevice::AddHints()
  2102 TInt CNGAPostProcHwDevice::AddHints()
  2089 {
  2103 {
  2090    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints ++"), this);
  2104    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints iSurfaceMask 0x%08x ++"), this, iSurfaceMask);
  2091    TInt err = KErrNone;
  2105    TInt err = KErrNone;
  2092    iHint.Set(iSurfaceKey,iSurfaceMask,ETrue);
  2106    iHint.Set(iSurfaceKey,iSurfaceMask,ETrue);
  2093    err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
  2107    err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
  2094    if(err == KErrAlreadyExists)
  2108    if(err == KErrAlreadyExists)
  2095    {
  2109    {