mdfdevvideoextensions/nga_mdf_postprocessor/src/NGAPostProcHwDevice.cpp
changeset 29 eb1e5d7cc688
parent 15 c1e808730d6c
child 31 ae0addfe117e
equal deleted inserted replaced
26:c36d67f77f75 29:eb1e5d7cc688
    17 
    17 
    18 
    18 
    19 #include "NGAPostProcHwDevice.h"
    19 #include "NGAPostProcHwDevice.h"
    20 #include "NGAPostProcSessionManager.h"
    20 #include "NGAPostProcSessionManager.h"
    21 #include "NGAPostProcSurfaceHandler.h"
    21 #include "NGAPostProcSurfaceHandler.h"
    22 #include "common.h"
       
    23 
    22 
    24 // post-processor info
    23 // post-processor info
    25 const TUid KUidVideoPostProcHwDevice = {KUidNGAPostProcHwDeviceImplUid};
    24 const TUid KUidVideoPostProcHwDevice = {KUidNGAPostProcHwDeviceImplUid};
    26 _LIT(KManufacturer, "Nokia Inc.");
    25 _LIT(KManufacturer, "Nokia Inc.");
    27 _LIT(KIdentifier, "Nokia S60 Video Post Processor Hardware Device Plugin");
    26 _LIT(KIdentifier, "Nokia S60 Video Post Processor Hardware Device Plugin");
    45 #endif
    44 #endif
    46 
    45 
    47 int32 gColorConvYUVtoYUV422Int (tBaseVideoFrame *yuv420Frame, tBaseVideoFrame* yuv422Frame,
    46 int32 gColorConvYUVtoYUV422Int (tBaseVideoFrame *yuv420Frame, tBaseVideoFrame* yuv422Frame,
    48 							   uint8 outClrFmt, int16 stride); 
    47 							   uint8 outClrFmt, int16 stride); 
    49 
    48 
       
    49 int32 Emz_VDec_gColorConv_YUVtoRGB ( 
       
    50 	  tBaseVideoFrame *srcImage, uint8 *dstImage, tWndParam *srcWindow, 
       
    51 	  tWndParam *dstWindow, uint8 srcImageFormat, uint8 dstImageFormat,
       
    52 	  uint8 colorConvScheme);
       
    53 		 	  
    50 #ifdef __cplusplus
    54 #ifdef __cplusplus
    51 }
    55 }
    52 #endif
    56 #endif
    53 
    57 
    54 //**************************************************
    58 //**************************************************
    93             iSurfaceCreatedEventPublished(EFalse),
    97             iSurfaceCreatedEventPublished(EFalse),
    94             iOverflowPictureCounter(0),
    98             iOverflowPictureCounter(0),
    95             iVideoFrameBufSize(0),
    99             iVideoFrameBufSize(0),
    96             iResourceLost(EFalse),
   100             iResourceLost(EFalse),
    97             iRedrawDone(EFalse),
   101             iRedrawDone(EFalse),
       
   102 			iRedrawSurfaceInUse(EFalse),
    98             iVBMObserver(NULL),
   103             iVBMObserver(NULL),
    99             count(0),
   104             count(0),
   100             iSurfaceMask(surfaceHints::EAllowAllExternals),
   105             iSurfaceMask(surfaceHints::EAllowAllExternals),
   101             iSurfaceKey(TUid::Uid(surfaceHints::KSurfaceProtection)),
   106             iSurfaceKey(TUid::Uid(surfaceHints::KSurfaceProtection)),
   102             iVideoSurfaceObserver(NULL),
   107             iVideoSurfaceObserver(NULL),
   103             iVPObserver(NULL),
   108             iVPObserver(NULL),
   104             iPicSize(0,0),
   109             iPicSize(0,0),
       
   110 			iAspectRatioNum(1),
       
   111 			iAspectRatioDenom(1),
   105             iStepFrameCount(0),
   112             iStepFrameCount(0),
   106             iPlayRate(KDefPlayRate),
   113             iPlayRate(KDefPlayRate),
   107             iKeyFrameMode(EFalse),
   114             iKeyFrameMode(EFalse),
   108             iFPObserver(NULL)
   115             iFPObserver(NULL)
   109 {
   116 {
   140     
   147     
   141     while (iVBMBufferReferenceQ.Count()>0)
   148     while (iVBMBufferReferenceQ.Count()>0)
   142     {
   149     {
   143         TVideoPicture* pic = iVBMBufferReferenceQ[0];
   150         TVideoPicture* pic = iVBMBufferReferenceQ[0];
   144         iVBMBufferReferenceQ.Remove(0);
   151         iVBMBufferReferenceQ.Remove(0);
       
   152         if (iColorConversionQ.Count()>0)
       
   153     	{
       
   154 	        iColorConversionQ.Remove(0);
       
   155 	    }
   145 
   156 
   146         if (pic->iHeader) delete pic->iHeader;
   157         if (pic->iHeader) delete pic->iHeader;
   147         delete pic->iData.iRawData;
   158         delete pic->iData.iRawData;
   148         delete pic;
   159         delete pic;
   149     }
   160     }
   151     iSupportedInputFormats.Reset();
   162     iSupportedInputFormats.Reset();
   152     iSupportedInputFormats.Close();
   163     iSupportedInputFormats.Close();
   153     
   164     
   154     iVBMBufferReferenceQ.Reset();
   165     iVBMBufferReferenceQ.Reset();
   155     iVBMBufferReferenceQ.Close();
   166     iVBMBufferReferenceQ.Close();
       
   167     
       
   168     iColorConversionQ.Reset();
       
   169     iColorConversionQ.Close();
   156     
   170     
   157     iVBMBufferQ.Reset();
   171     iVBMBufferQ.Reset();
   158     iVBMBufferQ.Close();
   172     iVBMBufferQ.Close();
   159     
   173     
   160     iProcessQ.Reset();
   174     iProcessQ.Reset();
   166     if (iSurfaceHandler)
   180     if (iSurfaceHandler)
   167     {
   181     {
   168     	if(!iSurfaceId.IsNull())
   182     	if(!iSurfaceId.IsNull())
   169     	{
   183     	{
   170     		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::UnregisterSurface"), this);
   184     		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::UnregisterSurface"), this);
   171     		iWsSession.UnregisterSurface(0, iSurfaceId);
   185 			TInt numScreens = iWsSession.NumberOfScreens();
       
   186     		for(TInt i=0;i < numScreens;i++)
       
   187     		{
       
   188     			iWsSession.UnregisterSurface(i, iSurfaceId);
       
   189     		}
       
   190     		iWsSession.Flush();
   172         	iSurfaceHandler->DestroySurface(iSurfaceId);
   191         	iSurfaceHandler->DestroySurface(iSurfaceId);
   173     	}
   192     	}
   174         delete iSurfaceHandler;
   193         delete iSurfaceHandler;
   175         iSurfaceHandler = NULL;
   194         iSurfaceHandler = NULL;
   176     }
   195     }
   194     {
   213     {
   195 				PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() FAILED: Unexpected state"), this);
   214 				PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() FAILED: Unexpected state"), this);
   196         User::Leave(KErrNotReady);
   215         User::Leave(KErrNotReady);
   197 	  }
   216 	  }
   198 
   217 
   199 
   218 		iVideoFormat = aFormat; 
   200 		if( ((aFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
   219 		if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
   201 			(aFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
   220 			(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
   202     		(aFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))
   221     		(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))
   203 		{
   222 		{
       
   223 			iVideoFormat.iYuvFormat.iCoefficients  	     = EYuvBt709Range1;
       
   224     		iVideoFormat.iYuvFormat.iPattern       	     = EYuv422Chroma1;
       
   225     		iVideoFormat.iYuvFormat.iDataLayout          = EYuvDataInterleavedBE;
       
   226 			
   204 #if defined __WINSCW__				
   227 #if defined __WINSCW__				
   205 				iIsColorConversionNeeded = ETrue; 
   228 				iIsColorConversionNeeded = ETrue; 
   206 #else
   229 #else
   207 				iAttributes().iPixelFormat = EUidPixelFormatYUV_420Planar;
   230 				iAttributes().iPixelFormat = EUidPixelFormatYUV_420Planar;
   208 #endif //__WINSCW__
   231 #endif //__WINSCW__
   347    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize --"), this);
   370    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize --"), this);
   348 }
   371 }
   349 
   372 
   350 void CNGAPostProcHwDevice::WritePictureL(TVideoPicture* aPicture) 
   373 void CNGAPostProcHwDevice::WritePictureL(TVideoPicture* aPicture) 
   351 { 
   374 { 
   352 	PP_DEBUG(_L("CNGAPostProcHwDevice:WritePicture ++"));
   375 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture bufId = %d"), this,GetID(aPicture));
   353 	TVideoPicture* pic;
   376 	TVideoPicture* pic;
   354 	if (iPPState==EInitializing || iPPState==EStopped || iIsInputEnded)
   377 	if (iPPState==EInitializing || iPPState==EStopped || iIsInputEnded)
   355     {
   378     {
   356 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Unexpected state"), this);
   379 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Unexpected state"), this);
   357         User::Leave(KErrNotReady);
   380         User::Leave(KErrNotReady);
   361     {
   384     {
   362 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Invalid argument"), this);
   385 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Invalid argument"), this);
   363 		User::Leave(KErrArgument);
   386 		User::Leave(KErrArgument);
   364 	}
   387 	}
   365 	pic = aPicture;	
   388 	pic = aPicture;	
   366     if (iInputQ.Count() > 0)
   389 	iPictureCounters.iTotalPictures++;
   367     {
   390 	if((iPPState != EPlaying) && (iFirstPictureUpdated))
   368         AddToQ(pic);
   391 	{
   369         AttemptToPost();
   392 		AddToQ(pic);
   370     }
   393 	}
   371     else
   394 	else if( iInputQ.Count() > 0 )
   372     {
   395 	{
   373 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture bufId = %d"), this,GetID(pic));
   396 		AddToQ(pic);
   374 		iPictureCounters.iTotalPictures++;
   397 		AttemptToPost();
       
   398 	}
       
   399 	else
       
   400 	{
   375 		TInt64 delta = 0;
   401 		TInt64 delta = 0;
   376 		TTimeToPost iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
   402 		TTimeToPost iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
   377 		if(!IsGceReady())
   403 		if(!IsGceReady())
   378 	    {  
   404 	    {  
   379 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL GCE not ready"), this );
   405 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL GCE not ready"), this );
   385 	    if (delta > 0x7FFFFFFF)
   411 	    if (delta > 0x7FFFFFFF)
   386 	    {
   412 	    {
   387 	         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL Too large delta .. skipping"), this ); 
   413 	         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL Too large delta .. skipping"), this ); 
   388 	         iTimeToPost = ESkipIt;
   414 	         iTimeToPost = ESkipIt;
   389 	    }
   415 	    }
   390 	
   416 		if(!iFirstPictureUpdated)
       
   417 		{
       
   418             if(iTimeToPost == EDelayIt)
       
   419             {
       
   420                 iTimeToPost = EPostIt;
       
   421             }
       
   422 		}
   391 		switch(iTimeToPost)
   423 		switch(iTimeToPost)
   392 		{
   424 		{
   393 			case EDelayIt:
   425 			case EDelayIt:
   394 			{
   426 			{
   395 				if(AddToQ(pic) != 0)
   427 				if(AddToQ(pic) != 0)
   418 				iCurrentPlaybackPosition = pic->iTimestamp;			
   450 				iCurrentPlaybackPosition = pic->iTimestamp;			
   419 			
   451 			
   420 				if(!iFirstPictureUpdated)
   452 				if(!iFirstPictureUpdated)
   421 				{
   453 				{
   422 					iFirstPictureUpdated = ETrue;
   454 					iFirstPictureUpdated = ETrue;
   423 					PublishSurfaceCreated();
   455                     if(!iSurfaceCreatedEventPublished)
       
   456                     {
       
   457                         PublishSurfaceCreated();
       
   458                     }
   424 				}
   459 				}
   425 			}
   460 			}
   426 			break;
   461 			break;
   427 			case ESkipIt:
   462 			case ESkipIt:
   428 			{
   463 			{
   825 
   860 
   826 void CNGAPostProcHwDevice::Redraw() 
   861 void CNGAPostProcHwDevice::Redraw() 
   827 { 
   862 { 
   828 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw ++"), this);
   863 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw ++"), this);
   829 	TInt err = KErrNone;
   864 	TInt err = KErrNone;
   830 	if(iResourceLost && !iRedrawDone)
   865 	if(iRedrawSurfaceInUse && !iRedrawDone)
   831 	{
   866 	{
   832         err = AddHints();
   867         err = AddHints();
   833         if (err != KErrNone)
   868         if (err != KErrNone)
   834         {
   869         {
   835             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to AddHints %d"), 
   870             PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to AddHints %d"), 
   836                          this, err);
   871                          this, err);
   837             iProxy->MdvppFatalError(this, err);	
   872             iProxy->MdvppFatalError(this, err);	
   838             return;   
   873             return;   
   839         }
   874         }
   840         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface"), this);
   875         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface"), this);
   841 		err = RegisterSurface(iSurfaceId);
   876 		err = RegisterSurface(iSurfaceId);
   842 		if (err != KErrNone)
   877 		if (err != KErrNone)
   843 		{
   878 		{
   844 		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost -- failed to Register Surface %d"), 
   879 		   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to Register Surface %d"), 
   845 		   				this, err);
   880 		   				this, err);
   846 		   	iSurfaceHandler->DestroySurface(iSurfaceId);
   881 		   	iSurfaceHandler->DestroySurface(iSurfaceId);
   847 	   		iSurfaceId = TSurfaceId::CreateNullId();
   882 	   		iSurfaceId = TSurfaceId::CreateNullId();
   848 			iProxy->MdvppFatalError(this, err);	
   883 			iProxy->MdvppFatalError(this, err);	
   849 			return;   				
   884 			return;   				
   858 
   893 
   859 void CNGAPostProcHwDevice::Start() 
   894 void CNGAPostProcHwDevice::Start() 
   860 {  
   895 {  
   861 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start ++"), this);
   896 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start ++"), this);
   862 	iPPState = EPlaying;
   897 	iPPState = EPlaying;
       
   898 	AttemptToPost();
   863 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start --"), this);
   899 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start --"), this);
   864 }
   900 }
   865 
   901 
   866 void CNGAPostProcHwDevice::Stop() 
   902 void CNGAPostProcHwDevice::Stop() 
   867 { 
   903 { 
   902     if (iPPState == EInitializing)
   938     if (iPPState == EInitializing)
   903     { 
   939     { 
   904 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition FAILED: Unexpected state"), this);
   940 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition FAILED: Unexpected state"), this);
   905         return;
   941         return;
   906     }
   942     }
   907     
   943     if (iPPState == EPaused)
       
   944     {	
       
   945         iFirstPictureUpdated = EFalse;
       
   946     }
   908     iCurrentPlaybackPosition = aPlaybackPosition;  
   947     iCurrentPlaybackPosition = aPlaybackPosition;  
   909     
   948     
   910     ReleaseInputQ();
   949     ReleaseInputQ();
   911 
   950 
   912    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition --"), this);
   951    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition --"), this);
   967 
  1006 
   968 void CNGAPostProcHwDevice::ReturnPicture(TVideoPicture* ) 
  1007 void CNGAPostProcHwDevice::ReturnPicture(TVideoPicture* ) 
   969 { 
  1008 { 
   970 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicture +-"), this);
  1009 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicture +-"), this);
   971     //not required for direct rendering 
  1010     //not required for direct rendering 
       
  1011 }
       
  1012 
       
  1013 TBool CNGAPostProcHwDevice::GetSnapshotL(TPictureData& aPictureData, const TUncompressedVideoFormat& /*aFormat*/)
       
  1014 { 
       
  1015 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL %d %d ++"), this, iVBMEnabled, iProcessQ.Count());
       
  1016 	TVideoPicture* 		pic = NULL;
       
  1017 	TInt 				err = KErrNone;
       
  1018 	TBool				frameAvailable =EFalse;
       
  1019 	tWndParam			inputCropWindow;
       
  1020 	tWndParam			outputCropWindow;
       
  1021 	tBaseVideoFrame		inputFrame;
       
  1022 	inputFrame.lum 		= NULL; 
       
  1023 	
       
  1024 	if(aPictureData.iDataFormat == ERgbFbsBitmap)
       
  1025 	{	
       
  1026 		if(iProcessQ.Count())
       
  1027 		{
       
  1028 			pic = iProcessQ[0]; //frame already submitted for display
       
  1029 		}
       
  1030 		else if(iInputQ.Count())
       
  1031 		{
       
  1032 			pic = iInputQ[0]; //frame yet to be displayed
       
  1033 		}
       
  1034 		if(pic) 
       
  1035 		{
       
  1036 			if (iVBMEnabled)
       
  1037 		    {
       
  1038 				inputFrame.lum	= (TUint8*)pic->iData.iRawData->Ptr();
       
  1039 			}
       
  1040 			else
       
  1041 			{
       
  1042 				if (iInputDecoderDevice)
       
  1043 				{
       
  1044 					MMmfVideoFetchFrame* VFHandler = NULL;
       
  1045 					VFHandler = (MMmfVideoFetchFrame*)iInputDecoderDevice->CustomInterface(KUidMMFVideoFetchFrame);
       
  1046 					if (VFHandler)
       
  1047 					{
       
  1048 						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() fetch frame"), this);
       
  1049 						inputFrame.lum = (TUint8*)VFHandler->MmvffGetFrame(GetID(pic));
       
  1050 					}
       
  1051 					else
       
  1052 					{
       
  1053 						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() decoder yet to implement MMmfVideoFetchFrame CI"), this);
       
  1054 					}
       
  1055 				}
       
  1056 			}
       
  1057 		}
       
  1058 		if(inputFrame.lum)
       
  1059 		{
       
  1060 			inputFrame.cb	= inputFrame.lum + iPicSize.iWidth * iPicSize.iHeight;
       
  1061 			
       
  1062 			if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
       
  1063 				(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
       
  1064 	    		(iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))						
       
  1065 			{
       
  1066 				inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*5)/4;
       
  1067 			}
       
  1068 			else
       
  1069 			{
       
  1070 				inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*3)/2;
       
  1071 			}
       
  1072 			
       
  1073 			inputFrame.width	= (unsigned short)iPicSize.iWidth;
       
  1074 			inputFrame.height	= (unsigned short)iPicSize.iHeight;
       
  1075 			
       
  1076 			outputCropWindow.wndHeight  = iPicSize.iHeight;	
       
  1077 			outputCropWindow.wndWidth	= iPicSize.iWidth; 	
       
  1078 			outputCropWindow.xOffset	= 0;
       
  1079 			outputCropWindow.yOffset	= 0;
       
  1080 			
       
  1081 			inputCropWindow.wndHeight  = iPicSize.iHeight;	
       
  1082 			inputCropWindow.wndWidth	= iPicSize.iWidth; 	
       
  1083 			inputCropWindow.xOffset	= 0;
       
  1084 			inputCropWindow.yOffset	= 0;
       
  1085 			
       
  1086 			RFbsSession fbs;
       
  1087 			fbs.Connect();
       
  1088 			CFbsBitmap* iOutBitmap = aPictureData.iRgbBitmap;
       
  1089 			TInt status = iOutBitmap->Resize(iPicSize);
       
  1090 			if (status == KErrNone)
       
  1091 			{
       
  1092 				// Lock the heap to prevent the FBS server from invalidating the address
       
  1093 		        iOutBitmap->LockHeap();
       
  1094 		        TUint8* dataAddress = (TUint8*)iOutBitmap->DataAddress();
       
  1095 				err = ColorConvert(&inputFrame, dataAddress, &inputCropWindow, &outputCropWindow);
       
  1096 				iOutBitmap->UnlockHeap();
       
  1097 				frameAvailable = ETrue;
       
  1098 			}
       
  1099 			fbs.Disconnect();
       
  1100 		}
       
  1101 	}
       
  1102 	else
       
  1103 	{
       
  1104 		err = KErrNotSupported;
       
  1105 	}
       
  1106 	if(err != KErrNone)
       
  1107 	{
       
  1108 		User::Leave(err);
       
  1109 	}
       
  1110 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL --"), this);
       
  1111 	return(frameAvailable);
   972 }
  1112 }
   973 
  1113 
   974 void CNGAPostProcHwDevice::InputEnd() 
  1114 void CNGAPostProcHwDevice::InputEnd() 
   975 { 
  1115 { 
   976    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd ++"), this);
  1116    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd ++"), this);
  1206         User::Leave(KErrNotSupported);
  1346         User::Leave(KErrNotSupported);
  1207 		}
  1347 		}
  1208 		
  1348 		
  1209 		if(iVBMBufferReferenceQ.Count() == 0)
  1349 		if(iVBMBufferReferenceQ.Count() == 0)
  1210 		{
  1350 		{
  1211 				err = SetupSurface(aSize);
  1351 			iPicSize = aSize;
  1212 				if(err)
  1352 			err = SetupSurface(aSize);
  1213 				{
  1353 			if(err)
  1214 						PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() Surface Setup Failed %d"), this, err);
  1354 			{
  1215 						User::Leave(err);
  1355 					PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() Surface Setup Failed %d"), this, err);
  1216 				}
  1356 					User::Leave(err);
       
  1357 			}
  1217 		}
  1358 		}
  1218 		
  1359 		
  1219     if(!iVBMBufferQ.Count())
  1360     if(!iVBMBufferQ.Count())
  1220     {
  1361     {
  1221        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() WARNING: Queue buffer count zero"), this);
  1362        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() WARNING: Queue buffer count zero"), this);
  1278 		aCropRect = TRect(0, 0, iInfo().iSize.iWidth, iInfo().iSize.iHeight);
  1419 		aCropRect = TRect(0, 0, iInfo().iSize.iWidth, iInfo().iSize.iHeight);
  1279 		if((iPicSize.iWidth > 0) && (iPicSize.iHeight > 0))
  1420 		if((iPicSize.iWidth > 0) && (iPicSize.iHeight > 0))
  1280 		{
  1421 		{
  1281 			aCropRect.Intersection( iPicSize);
  1422 			aCropRect.Intersection( iPicSize);
  1282 		}
  1423 		}
  1283 	aPixelAspectRatio = TVideoAspectRatio(1,1);
  1424 	aPixelAspectRatio = TVideoAspectRatio(iAspectRatioNum,iAspectRatioDenom);
  1284 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL()--  \
  1425 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL()  \
  1285 		cropRectWidth = %d cropRectHeight = %d --"), this, aCropRect.Width(), aCropRect.Height());
  1426 		cropRectWidth = %d cropRectHeight = %d"), this, aCropRect.Width(), aCropRect.Height());
  1286 
  1427 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL()  \
       
  1428 		PAR Num = %d PAR Denom = %d"), this, aPixelAspectRatio.iNumerator, aPixelAspectRatio.iDenominator);
       
  1429 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() --"), this);
  1287 }
  1430 }
  1288 
  1431 
  1289 void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
  1432 void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
  1290 {
  1433 {
  1291 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
  1434 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
  1292 	if(!aSurfaceId.IsNull())
  1435 	if(!aSurfaceId.IsNull())
  1293 	{
  1436 	{
  1294 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
  1437 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
  1295 		iWsSession.UnregisterSurface(0, aSurfaceId);
  1438 		TInt numScreens = iWsSession.NumberOfScreens();
       
  1439 		for(TInt i=0;i < numScreens;i++)
       
  1440 		{
       
  1441 			iWsSession.UnregisterSurface(i, aSurfaceId);
       
  1442 		}
       
  1443 		iWsSession.Flush();
  1296 		iSurfaceHandler->DestroySurface(aSurfaceId);
  1444 		iSurfaceHandler->DestroySurface(aSurfaceId);
  1297 	}
  1445 		if(iSurfaceId == aSurfaceId)
  1298 		
  1446 		{
       
  1447 			iSurfaceCreatedEventPublished = EFalse;
       
  1448 			iSurfaceId = TSurfaceId::CreateNullId();
       
  1449 			iChunk.Close();
       
  1450 		}
       
  1451 	}
  1299 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
  1452 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
  1300 }
  1453 }
  1301 
  1454 
  1302 // === MMmfVideoPropertiesObserver ===
  1455 // === MMmfVideoPropertiesObserver ===
  1303     
  1456     
  1305 {
  1458 {
  1306 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties ++"), this);
  1459 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties ++"), this);
  1307 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties PAR \
  1460 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties PAR \
  1308 		iAspectRatioNum = %d, iAspectRatioDenom = %d"), this,
  1461 		iAspectRatioNum = %d, iAspectRatioDenom = %d"), this,
  1309 					 aYuvFormat.iAspectRatioNum,aYuvFormat.iAspectRatioDenom);
  1462 					 aYuvFormat.iAspectRatioNum,aYuvFormat.iAspectRatioDenom);
  1310 					 iPicSize = aPictureSize;
  1463 	iPicSize = aPictureSize;
       
  1464 	iAspectRatioNum = aYuvFormat.iAspectRatioNum;
       
  1465 	iAspectRatioDenom = aYuvFormat.iAspectRatioDenom;
  1311 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties Picture Size \
  1466 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties Picture Size \
  1312 		iWidth = %d, iHeight = %d, iSurfaceCreatedEventPublished = %d"), 
  1467 		iWidth = %d, iHeight = %d, iSurfaceCreatedEventPublished = %d"), 
  1313 		this, iPicSize.iWidth,iPicSize.iHeight, iSurfaceCreatedEventPublished?1:0);
  1468 		this, iPicSize.iWidth,iPicSize.iHeight, iSurfaceCreatedEventPublished?1:0);
  1314 			 
  1469 			 
  1315 	if(iVPObserver)
  1470 	if(iVPObserver)
  1334 		iRedrawDone = EFalse;
  1489 		iRedrawDone = EFalse;
  1335 		Pause();
  1490 		Pause();
  1336 		ReleaseInputQ();
  1491 		ReleaseInputQ();
  1337 		iSessionManager->CancelUpdate();
  1492 		iSessionManager->CancelUpdate();
  1338 		ReleaseProcessQ();
  1493 		ReleaseProcessQ();
  1339 		iVideoSurfaceObserver->MmvsoRemoveSurface();
  1494 		if(iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
       
  1495 		{
       
  1496 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost - Telling client to remove surface"), this);
       
  1497 			iVideoSurfaceObserver->MmvsoRemoveSurface();
       
  1498 			iSurfaceCreatedEventPublished = EFalse;
       
  1499 		}
  1340 	}
  1500 	}
  1341 	else if(iResourceLost && iRedrawDone)
  1501 	else if(iResourceLost && iRedrawDone)
  1342 	{
  1502 	{
  1343 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ResourceLost happening \
  1503 		PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ResourceLost happening \
  1344 					while Postprocessor is already in ResourceLoss state"), 
  1504 					while Postprocessor is already in ResourceLoss state"), 
  1380     
  1540     
  1381 }
  1541 }
  1382 
  1542 
  1383 void CNGAPostProcHwDevice::MmvshcRedrawBufferToSurface(TPtrC8& aRedrawBuffer)
  1543 void CNGAPostProcHwDevice::MmvshcRedrawBufferToSurface(TPtrC8& aRedrawBuffer)
  1384 {
  1544 {
  1385     PP_DEBUG(_L("CNGAPostProcHwDevice::MmvshcRedrawBufferToSurface ++"), this);
  1545     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface ++"), this);
  1386 	
  1546 	
  1387 	TSize 			surfaceSize; 
       
  1388     TUint8*         lPtr;
  1547     TUint8*         lPtr;
  1389     TInt 			offset;
  1548     TInt 			offset;
  1390     if(iPicSize.iWidth > iPicSize.iHeight)
  1549 
  1391     {
  1550     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface -- Creating %d x %d surface"), this, iPicSize.iWidth, iPicSize.iHeight);
  1392     	surfaceSize.iWidth = iPicSize.iWidth;
       
  1393     	surfaceSize.iHeight = iPicSize.iWidth;
       
  1394     }
       
  1395     else
       
  1396     {
       
  1397     	surfaceSize.iWidth = iPicSize.iHeight;
       
  1398     	surfaceSize.iHeight = iPicSize.iHeight;
       
  1399     }
       
  1400 
  1551 
  1401    	TInt err = KErrNone;
  1552    	TInt err = KErrNone;
  1402 	SetSurfaceAttributes(surfaceSize, 1); 
  1553 	SetSurfaceAttributes(iPicSize, 1); 
  1403 	
  1554 	
  1404   	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1555   	err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
  1405   	if (err != KErrNone)
  1556   	if (err != KErrNone)
  1406 	{
  1557 	{
  1407 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to create Surface %d"), 
  1558 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to create Surface %d"), 
  1408 	   				this, err);
  1559 	   				this, err);
  1409 		iProxy->MdvppFatalError(this, err);	   				
  1560 		iProxy->MdvppFatalError(this, err);	   				
  1410 	    return;
  1561 	    return;
  1411 	}
  1562 	}
       
  1563 
       
  1564 	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
       
  1565 	if (err != KErrNone)
       
  1566 	{
       
  1567 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to get Surface info %d"), 
       
  1568 	   				this, err);
       
  1569 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
       
  1570 	   	iSurfaceId = TSurfaceId::CreateNullId();
       
  1571 		iProxy->MdvppFatalError(this, err);	   				
       
  1572 	    return;
       
  1573 	}
       
  1574 
       
  1575 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface() \
       
  1576 		surfaceWidth = %d surfaceHeight = %d surfaceStride = %d"), this, iInfo().iSize.iWidth, iInfo().iSize.iHeight, iInfo().iStride);
       
  1577 
       
  1578 	TInt redrawBufferSize = aRedrawBuffer.Size();
       
  1579 	TInt surfaceSize = iInfo().iStride * iInfo().iSize.iHeight;
       
  1580 
       
  1581     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface RedrawBuffer size= %d Surface size = %d"), this, redrawBufferSize, surfaceSize);
       
  1582 
       
  1583 	// Check whether redraw buffer will fit onto the surface.
       
  1584 	// If this check fails then we won't raise a fatal error - We just won't create the redraw surface
       
  1585 	if (redrawBufferSize > surfaceSize)
       
  1586 	{
       
  1587     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface Redraw buffer size larger than surface size"), this);
       
  1588     	iSurfaceHandler->DestroySurface(iSurfaceId);
       
  1589 	   	iSurfaceId = TSurfaceId::CreateNullId();
       
  1590     	return;
       
  1591 	}
       
  1592 
  1412 	err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
  1593 	err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
  1413 	if (err != KErrNone)
  1594 	if (err != KErrNone)
  1414 	{
  1595 	{
  1415 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to map Surface %d"), 
  1596 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to map Surface %d"), 
  1416 	   				this, err);
  1597 	   				this, err);
  1417 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1598 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
  1418 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1599 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1419 		iProxy->MdvppFatalError(this, err);	   				
  1600 		iProxy->MdvppFatalError(this, err);	   				
  1420 	    return;
  1601 	    return;
  1421 	}
  1602 	}
  1422 	err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
       
  1423 	if (err != KErrNone)
       
  1424 	{
       
  1425 	   PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to get Surface info %d"), 
       
  1426 	   				this, err);
       
  1427 	   	iSurfaceHandler->DestroySurface(iSurfaceId);
       
  1428 	   	iSurfaceId = TSurfaceId::CreateNullId();
       
  1429 		iProxy->MdvppFatalError(this, err);	   				
       
  1430 	    return;
       
  1431 	}
       
  1432 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface() \
       
  1433 		surfaceWidth = %d surfaceHeight = %d --"), this, iInfo().iSize.iWidth, iInfo().iSize.iHeight);
       
  1434 
  1603 
  1435     if((err = iSurfaceHandler->GetBufferOffset(iSurfaceId, 0, offset)) != KErrNone)
  1604     if((err = iSurfaceHandler->GetBufferOffset(iSurfaceId, 0, offset)) != KErrNone)
  1436     {
  1605     {
  1437     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset query failed %d"), this, err);
  1606     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset query failed %d"), this, err);
  1438     	iSurfaceHandler->DestroySurface(iSurfaceId);
  1607     	iSurfaceHandler->DestroySurface(iSurfaceId);
  1439 	   	iSurfaceId = TSurfaceId::CreateNullId();
  1608 	   	iSurfaceId = TSurfaceId::CreateNullId();
       
  1609 		iChunk.Close();
  1440     	iProxy->MdvppFatalError(this, err);
  1610     	iProxy->MdvppFatalError(this, err);
  1441     	return;
  1611     	return;
  1442     }
  1612     }
  1443     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset = %d aRedrawBuffer.Size()= %d  --"), this, offset, aRedrawBuffer.Size());
  1613 
  1444     
  1614     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset = %d"), this, offset);
       
  1615 
  1445 	lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
  1616 	lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
  1446 	memcpy((TAny *)lPtr, (TAny *)aRedrawBuffer.Ptr(), aRedrawBuffer.Size());
  1617 	memcpy((TAny *)lPtr, (TAny *)aRedrawBuffer.Ptr(), redrawBufferSize);
  1447 	
  1618 
       
  1619 	iRedrawSurfaceInUse = ETrue;
       
  1620 
       
  1621 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface(): New surface = 0x%x"), this, iSurfaceId);
       
  1622 
  1448     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface error = %d --"), this, err);
  1623     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface error = %d --"), this, err);
  1449 }
  1624 }
  1450 
  1625 
  1451 TInt CNGAPostProcHwDevice::SetupExternalSurface(const TSurfaceId &aSurfaceID)
  1626 TInt CNGAPostProcHwDevice::SetupExternalSurface(const TSurfaceId &aSurfaceID)
  1452 {
  1627 {
       
  1628 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface(): aSurfaceID = 0x%x"), this, aSurfaceID );
       
  1629 
  1453     TInt err = KErrNone;
  1630     TInt err = KErrNone;
  1454     
  1631     
  1455     if(!iSurfaceId.IsNull())
  1632     if(!iSurfaceId.IsNull())
  1456     {
  1633     {
  1457     	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface Cleaning ReDraw Surface"), this);
  1634 		if (iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
  1458 		iVideoSurfaceObserver->MmvsoRemoveSurface();
  1635 		{
       
  1636 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Telling client to remove old surface"), this);
       
  1637 			iVideoSurfaceObserver->MmvsoRemoveSurface();
       
  1638 			iSurfaceCreatedEventPublished = EFalse;
       
  1639 		}
       
  1640 		else
       
  1641 		{
       
  1642 			// We never told the client about the surface, so we must destroy it ourselves
       
  1643 			PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Destroying old surface"), this);
       
  1644 			TInt numScreens = iWsSession.NumberOfScreens();
       
  1645     		for(TInt i=0;i < numScreens;i++)
       
  1646     		{
       
  1647     			iWsSession.UnregisterSurface(i, iSurfaceId);
       
  1648     		}
       
  1649    			iWsSession.Flush();
       
  1650 			iSurfaceHandler->DestroySurface(iSurfaceId);
       
  1651 		}
       
  1652 
       
  1653 		iChunk.Close();
  1459 	}
  1654 	}
  1460     
  1655     
  1461     iSurfaceId            = aSurfaceID;
  1656     iSurfaceId            = aSurfaceID;
  1462     iUsingExternalSurface = ETrue;
  1657     iUsingExternalSurface = ETrue;
  1463     
  1658     iRedrawSurfaceInUse = EFalse;
  1464     
  1659 
  1465     // Create the surface handler if it doesn't exist.
  1660     // Create the surface handler if it doesn't exist.
  1466     if (!iSurfaceHandler)
  1661     if (!iSurfaceHandler)
  1467     {
  1662     {
  1468         TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
  1663         TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
  1469         if (err != KErrNone)
  1664         if (err != KErrNone)
  1650 				iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue); 
  1845 				iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue); 
  1651 				iCurrentPlaybackPosition = pic->iTimestamp;						 					
  1846 				iCurrentPlaybackPosition = pic->iTimestamp;						 					
  1652 				if(!iFirstPictureUpdated)
  1847 				if(!iFirstPictureUpdated)
  1653 				{
  1848 				{
  1654 					iFirstPictureUpdated = ETrue;
  1849 					iFirstPictureUpdated = ETrue;
  1655 					PublishSurfaceCreated();
  1850                     if(!iSurfaceCreatedEventPublished)
       
  1851                     {
       
  1852                         PublishSurfaceCreated();
       
  1853                     }
  1656 				}	
  1854 				}	
  1657 			}	// end of postit
  1855 			}	// end of postit
  1658 			break;
  1856 			break;
  1659 			case ESkipIt: 
  1857 			case ESkipIt: 
  1660 			{
  1858 			{
  1686     TInt resp = EPostIt;
  1884     TInt resp = EPostIt;
  1687     // Frame presentation time
  1885     // Frame presentation time
  1688     TInt64 uPresTime = frame->iTimestamp.Int64();
  1886     TInt64 uPresTime = frame->iTimestamp.Int64();
  1689       
  1887       
  1690     // Check if this is an out of order frame in case of forward playback
  1888     // Check if this is an out of order frame in case of forward playback
  1691     if((iCurrentPlaybackPosition.Int64() >= uPresTime) && (iPlayRate > 0))    
  1889     if((iCurrentPlaybackPosition.Int64() > uPresTime) && (iPlayRate > 0))    
  1692     {      
  1890     {      
  1693          PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (forward playback) Tfm=%d"), this,(TInt)uPresTime);
  1891          PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (forward playback) Tfm=%d"), this,(TInt)uPresTime);
  1694          resp = ESkipIt;  //drop      
  1892          resp = ESkipIt;  //drop      
  1695     }      // Check if this is an out of order frame in case of backward playback
  1893     }      // Check if this is an out of order frame in case of backward playback
  1696     else if((iCurrentPlaybackPosition.Int64() <= uPresTime) && (iPlayRate < 0))    
  1894     else if((iCurrentPlaybackPosition.Int64() < uPresTime) && (iPlayRate < 0))    
  1697     {      
  1895     {      
  1698         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (backward playback) Tfm=%d"), this,(TInt)uPresTime);
  1896         PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (backward playback) Tfm=%d"), this,(TInt)uPresTime);
  1699         resp = ESkipIt;  //drop      
  1897         resp = ESkipIt;  //drop      
  1700     }
  1898     }
  1701     else if (iClockSource)
  1899     else if (iClockSource)
  1714             resp = ESkipIt;  //drop
  1912             resp = ESkipIt;  //drop
  1715         }
  1913         }
  1716        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost .. Tfm=%d, Tcs=%d, delta=%d"), this, (TInt)uPresTime, (TInt)uSyncTime, (TInt)delta);
  1914        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost .. Tfm=%d, Tcs=%d, delta=%d"), this, (TInt)uPresTime, (TInt)uSyncTime, (TInt)delta);
  1717     }       
  1915     }       
  1718    
  1916    
  1719    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost -- %d"), this, resp);
  1917    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost -- %d BufID = %d"), this, resp, GetID(frame));
  1720     return resp;
  1918     return resp;
  1721 }
  1919 }
  1722 
  1920 
  1723 void CNGAPostProcHwDevice::ReleaseInputQ()
  1921 void CNGAPostProcHwDevice::ReleaseInputQ()
  1724 {
  1922 {
  1899 }
  2097 }
  1900 
  2098 
  1901 TInt CNGAPostProcHwDevice::RegisterSurface(const TSurfaceId& aSurfaceId)
  2099 TInt CNGAPostProcHwDevice::RegisterSurface(const TSurfaceId& aSurfaceId)
  1902 {
  2100 {
  1903 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:RegisterSurface(): RegisterSurface ID = 0x%x"), this, aSurfaceId);
  2101 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:RegisterSurface(): RegisterSurface ID = 0x%x"), this, aSurfaceId);
  1904 	return(iWsSession.RegisterSurface(0, aSurfaceId));
  2102 	TInt err = KErrNone;
       
  2103 	TInt numScreens = iWsSession.NumberOfScreens();
       
  2104 	for(TInt i=0; (i < numScreens && err == KErrNone); i++)
       
  2105 	{
       
  2106 		err = iWsSession.RegisterSurface(i, aSurfaceId);
       
  2107 	}	
       
  2108 	return(err);
  1905 }
  2109 }
  1906 
  2110 
  1907 TInt CNGAPostProcHwDevice::IsGceReady()
  2111 TInt CNGAPostProcHwDevice::IsGceReady()
  1908 {
  2112 {
  1909     if(iProcessQ.Count() >= KMaxBuffersGceCanHold)
  2113     if(iProcessQ.Count() >= KMaxBuffersGceCanHold)
  2045 	if(iColorConversionQ.Count())
  2249 	if(iColorConversionQ.Count())
  2046     {
  2250     {
  2047 	    pOutPicture    = iColorConversionQ[0];
  2251 	    pOutPicture    = iColorConversionQ[0];
  2048 	    iColorConversionQ.Remove(0);
  2252 	    iColorConversionQ.Remove(0);
  2049 	    ConvertPostProcBuffer(aPicture, pOutPicture);
  2253 	    ConvertPostProcBuffer(aPicture, pOutPicture);
       
  2254 	   	pOutPicture->iTimestamp = aPicture->iTimestamp;
  2050 	    ReleasePicture(aPicture);    	    
  2255 	    ReleasePicture(aPicture);    	    
  2051     }				    
  2256     }				    
  2052     else
  2257     else
  2053     {
  2258     {
  2054        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: color conversion"), this);
  2259        PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: color conversion"), this);
  2129    {
  2334    {
  2130 		err = KErrNone;
  2335 		err = KErrNone;
  2131 		err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
  2336 		err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
  2132    }
  2337    }
  2133    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
  2338    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
       
  2339    iHint.iKey.iUid = surfaceHints::KSurfaceContent;
       
  2340    iHint.iValue = surfaceHints::EVideoPlayback;
       
  2341    iHint.iMutable = ETrue;
       
  2342    err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
       
  2343    if(err == KErrAlreadyExists)
       
  2344    {
       
  2345 		err = KErrNone;
       
  2346 		err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
       
  2347    }
       
  2348    PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
  2134    return err;
  2349    return err;
       
  2350 }
       
  2351 
       
  2352 TInt CNGAPostProcHwDevice::ColorConvert(tBaseVideoFrame* aInputFrame, TUint8* aDestPtr, tWndParam* aInputCropWindow, tWndParam* aOutputCropWindow)
       
  2353 {
       
  2354 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert ++"), this);
       
  2355 	__ASSERT_ALWAYS(aDestPtr, User::Invariant());
       
  2356 	TInt				lError = E_SUCCESS;
       
  2357 	TInt				err = KErrNone;
       
  2358 	
       
  2359 	err = SetSourceFormat();
       
  2360 	if(err == KErrNone)
       
  2361 	{
       
  2362     	err = SetSourceRange();
       
  2363     	if(err == KErrNone)
       
  2364     	{
       
  2365 						
       
  2366 			lError = Emz_VDec_gColorConv_YUVtoRGB(aInputFrame,aDestPtr, 
       
  2367 						aInputCropWindow, aOutputCropWindow, iSourceFormat,
       
  2368 						EBitmapColor16MU, iSourceRange);
       
  2369 
       
  2370 			if(lError)
       
  2371 			{
       
  2372 				if(lError == E_OUT_OF_MEMORY)
       
  2373 					{
       
  2374 					err = KErrNoMemory;
       
  2375 					}
       
  2376 				else if(lError == E_FAILURE)
       
  2377 					{
       
  2378 					err = KErrNotSupported;
       
  2379 					}
       
  2380 				else
       
  2381 					{
       
  2382 					err = KErrGeneral;
       
  2383 					}
       
  2384 			}
       
  2385 		}
       
  2386 	}
       
  2387 	
       
  2388 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert --"), this);
       
  2389 	return err;
       
  2390 }
       
  2391 
       
  2392 TInt CNGAPostProcHwDevice::SetSourceFormat()
       
  2393 {
       
  2394 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL ++"), this);
       
  2395 	TInt err = KErrNone;
       
  2396 	switch (iVideoFormat.iYuvFormat.iPattern)
       
  2397 	{
       
  2398 	    case EYuv420Chroma1:
       
  2399     		iSourceFormat = EYuv420Chroma1_Planar;
       
  2400     		break;
       
  2401         case EYuv420Chroma2:
       
  2402     		iSourceFormat = EYuv420Chroma2_Planar;
       
  2403     		break;
       
  2404         case EYuv420Chroma3:
       
  2405     		iSourceFormat = EYuv420Chroma3_Planar;
       
  2406     		break;
       
  2407 	    case EYuv422Chroma1:
       
  2408 			if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
       
  2409     			iSourceFormat = EYuv422Chroma1_LE;
       
  2410 	    	else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
       
  2411 				iSourceFormat = EYuv422Chroma1_BE;
       
  2412 			else
       
  2413 			    err = KErrArgument;
       
  2414 			break;
       
  2415     	case EYuv422Chroma2:
       
  2416     		if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
       
  2417 	    		iSourceFormat = EYuv422Chroma2_LE;
       
  2418     		else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
       
  2419     			iSourceFormat = EYuv422Chroma2_BE;
       
  2420 			else
       
  2421 			    err = KErrArgument;
       
  2422 			break;
       
  2423       default:
       
  2424     		err = KErrNotSupported;
       
  2425 	}
       
  2426 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL --"), this);
       
  2427 	return err;
       
  2428 }
       
  2429 
       
  2430 
       
  2431 TInt CNGAPostProcHwDevice::SetSourceRange()
       
  2432 {
       
  2433 	PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL ++"), this);
       
  2434 	TInt err = KErrNone;
       
  2435 	switch (iVideoFormat.iYuvFormat.iCoefficients)
       
  2436 	{
       
  2437 	    case EYuvBt601Range0:
       
  2438 			iSourceRange = EITU601_5_REDUCEDRANGE;
       
  2439             break;
       
  2440         case EYuvBt601Range1:
       
  2441 			iSourceRange = EITU601_5_FULLRANGE;
       
  2442 			break;
       
  2443         case EYuvBt709Range0:
       
  2444 			iSourceRange = EB709_REDUCEDRANGE;
       
  2445 			break;
       
  2446         case EYuvBt709Range1:
       
  2447 			iSourceRange = EB709_FULLRANGE;
       
  2448             break;
       
  2449 	    default:
       
  2450 		    err = KErrNotSupported;
       
  2451     }
       
  2452     PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL --"), this);
       
  2453     return err;
  2135 }
  2454 }
  2136 
  2455 
  2137 CNGAPostProcTimer::CNGAPostProcTimer( CNGAPostProcHwDevice& aParent )
  2456 CNGAPostProcTimer::CNGAPostProcTimer( CNGAPostProcHwDevice& aParent )
  2138 :CTimer(EPriorityHigh),iParent(aParent)
  2457 :CTimer(EPriorityHigh),iParent(aParent)
  2139 {
  2458 {