Update contrib.
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include "NGAPostProcHwDevice.h"
20 #include "NGAPostProcSessionManager.h"
21 #include "NGAPostProcSurfaceHandler.h"
23 // post-processor info
24 const TUid KUidVideoPostProcHwDevice = {KUidNGAPostProcHwDeviceImplUid};
25 _LIT(KManufacturer, "Nokia Inc.");
26 _LIT(KIdentifier, "Nokia S60 Video Post Processor Hardware Device Plugin");
29 const TInt KMaxVBMBuffers = 4;
30 const TInt KMinVBMInputWidth = 32;
31 const TInt KMinVBMInputHeight = 32;
32 const TInt KMaxVBMInputWidth = 1280;
33 const TInt KMaxVBMInputHeight = 720;
34 const TInt KRenderAhead = 50000;
35 const TInt KMaxRenderDelay = 50000;
36 const TInt KPostingOfset = 0;
37 const TInt KColorConversionBuffers = 3;
38 const TInt KMaxBuffersGceCanHold = 3;
39 const TInt KDefPlayRate = 100;
40 const TInt KMaxAllowedSkipInNFrames = 40;
46 int32 gColorConvYUVtoYUV422Int (tBaseVideoFrame *yuv420Frame, tBaseVideoFrame* yuv422Frame,
47 uint8 outClrFmt, int16 stride);
49 int32 Emz_VDec_gColorConv_YUVtoRGB (
50 tBaseVideoFrame *srcImage, uint8 *dstImage, tWndParam *srcWindow,
51 tWndParam *dstWindow, uint8 srcImageFormat, uint8 dstImageFormat,
52 uint8 colorConvScheme);
58 //**************************************************
60 CMMFVideoPostProcHwDevice* CNGAPostProcHwDevice::NewL()
62 PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() ++"));
64 CNGAPostProcHwDevice* self = new (ELeave) CNGAPostProcHwDevice;
65 CleanupStack::PushL(self);
69 PP_DEBUG(_L("CNGAPostProcHwDevice::NewL() --"));
70 return (CMMFVideoPostProcHwDevice*)self;
73 void CNGAPostProcHwDevice::ConstructL()
75 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() ++"), this);
77 // support for VBM buffer interface
78 iVBMBufferOptions.iNumInputBuffers = KMaxVBMBuffers;
79 iVBMBufferOptions.iBufferSize = TSize(KMaxVBMInputWidth, KMaxVBMInputHeight);
80 iPostingTimer = CNGAPostProcTimer::NewL(*this);
82 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::ConstructL() --"), this);
85 CNGAPostProcHwDevice::CNGAPostProcHwDevice()
87 iInputDecoderDevice(NULL),
88 iCurrentPlaybackPosition(TTimeIntervalMicroSeconds(0)),
89 iPPState(EInitializing),
90 iSurfaceHandler(NULL),
91 iSessionManager(NULL),
92 iIsInputEnded(EFalse),
94 iFirstPictureUpdated(EFalse),
95 iUsingExternalSurface(EFalse),
96 iIsColorConversionNeeded(EFalse),
97 iSurfaceCreatedEventPublished(EFalse),
98 iOverflowPictureCounter(0),
99 iVideoFrameBufSize(0),
100 iResourceLost(EFalse),
102 iRedrawSurfaceInUse(EFalse),
105 iSurfaceMask(surfaceHints::EAllowAllExternals),
106 iSurfaceKey(TUid::Uid(surfaceHints::KSurfaceProtection)),
107 iVideoSurfaceObserver(NULL),
111 iAspectRatioDenom(1),
113 iPlayRate(KDefPlayRate),
114 iKeyFrameMode(EFalse),
117 iSurfaceId = TSurfaceId::CreateNullId();
118 iAttributes().iPixelFormat = EUidPixelFormatYUV_422Interleaved;
121 CNGAPostProcHwDevice::~CNGAPostProcHwDevice()
123 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::~CNGAPostProcHwDevice() ++"), this);
126 iSessionManager->CancelUpdate();
127 delete iSessionManager;
128 iSessionManager = NULL;
131 while (iSupportedInputFormats.Count()>0)
133 iSupportedInputFormats.Remove(0);
136 while (iProcessQ.Count()>0)
143 iPostingTimer->Cancel();
144 delete iPostingTimer;
145 iPostingTimer = NULL;
148 while (iVBMBufferReferenceQ.Count()>0)
150 TVideoPicture* pic = iVBMBufferReferenceQ[0];
151 iVBMBufferReferenceQ.Remove(0);
152 if (iColorConversionQ.Count()>0)
154 iColorConversionQ.Remove(0);
157 if (pic->iHeader) delete pic->iHeader;
158 delete pic->iData.iRawData;
162 iSupportedInputFormats.Reset();
163 iSupportedInputFormats.Close();
165 iVBMBufferReferenceQ.Reset();
166 iVBMBufferReferenceQ.Close();
168 iColorConversionQ.Reset();
169 iColorConversionQ.Close();
182 if(!iSurfaceId.IsNull())
184 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::UnregisterSurface"), this);
185 TInt numScreens = iWsSession.NumberOfScreens();
186 for(TInt i=0;i < numScreens;i++)
188 iWsSession.UnregisterSurface(i, iSurfaceId);
191 iSurfaceHandler->DestroySurface(iSurfaceId);
193 delete iSurfaceHandler;
194 iSurfaceHandler = NULL;
199 RDebug::Printf("------ Statistics of Post Processor ------");
200 RDebug::Printf(" Pictures Received : %d", iPictureCounters.iTotalPictures);
201 RDebug::Printf(" Pictures Displayed: %d", iPictureCounters.iPicturesDisplayed);
202 RDebug::Printf(" Pictures Skipped : %d", iPictureCounters.iPicturesSkipped);
203 RDebug::Printf(" Pictures overflow : %d", iOverflowPictureCounter);
204 RDebug::Printf("------------------------------------------");
206 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:~() --"), this);
209 void CNGAPostProcHwDevice::SetInputFormatL(const TUncompressedVideoFormat& aFormat)
211 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() Pattern= %x ++"), this, aFormat.iYuvFormat.iPattern);
212 if (iPPState != EInitializing)
214 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() FAILED: Unexpected state"), this);
215 User::Leave(KErrNotReady);
218 iVideoFormat = aFormat;
219 if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
220 (iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
221 (iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))
223 iVideoFormat.iYuvFormat.iCoefficients = EYuvBt709Range1;
224 iVideoFormat.iYuvFormat.iPattern = EYuv422Chroma1;
225 iVideoFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedBE;
227 #if defined __WINSCW__
228 iIsColorConversionNeeded = ETrue;
230 iAttributes().iPixelFormat = EUidPixelFormatYUV_420Planar;
234 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputFormatL() WARNING: -- Not Found!"), this);
238 void CNGAPostProcHwDevice::SetInputDevice(CMMFVideoDecodeHwDevice* aDevice)
240 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() ++"), this);
242 if (iPPState != EInitializing)
244 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() FAILED: unexpected state"), this);
248 iInputDecoderDevice = aDevice;
250 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputDevice() --"), this);
253 void CNGAPostProcHwDevice::GetOutputFormatListL(RArray<TUncompressedVideoFormat>& )
255 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetOutputFormatListL() ++"), this);
258 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetOutputFormatListL() --"), this);
261 void CNGAPostProcHwDevice::SetOutputFormatL(const TUncompressedVideoFormat& )
263 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputFormatL() ++"), this);
265 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputFormatL() --"), this);
268 void CNGAPostProcHwDevice::SetClockSource(MMMFClockSource* aClock)
270 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() ++"), this);
272 if (iPPState != EInitializing)
274 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() FAILED: Unexpected state"), this);
277 iClockSource = aClock;
279 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetClockSource() --"), this);
282 void CNGAPostProcHwDevice::SetVideoDestScreenL(TBool /*aScreen*/)
284 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetVideoDestScreenL() ++"), this);
286 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetVideoDestScreenL() --"), this);
289 void CNGAPostProcHwDevice::SetProxy(MMMFDevVideoPlayProxy& aProxy)
291 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() ++"), this);
293 if (iPPState != EInitializing)
295 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() FAILED: Unexpected state"), this);
301 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetProxy() --"), this);
304 void CNGAPostProcHwDevice::Initialize()
306 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize ++"));
309 if (iPPState != EInitializing)
311 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize() FAILED: Unexpected state"), this);
314 if (!iSurfaceHandler)
316 TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
319 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create SurfaceHandler."), this);
323 if (!iSessionManager)
325 TRAP(err, iSessionManager = CNGAPostProcSessionManager::NewL());
328 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create SessionManager."), this);
331 iSessionManager->SetObserver(*this);
334 if (iInputDecoderDevice)
336 MMmfVideoResourceHandler* handler = NULL;
337 handler = (MMmfVideoResourceHandler*)iInputDecoderDevice->CustomInterface(KUidMmfVideoResourceManagement);
340 handler->MmvrhSetObserver((MMmfVideoResourceObserver*)this);
344 PP_DEBUG(_L("ppHwDev[%x]:Initialize() decoder yet to implement MMmfVideoResourceHandler CI"), this);
347 MMmfVideoPropertiesNotifier* VPHandler = NULL;
348 VPHandler = (MMmfVideoPropertiesNotifier*)iInputDecoderDevice->CustomInterface(KUidMmfVideoPropertiesManagement);
351 PP_DEBUG(_L("ppHwDev[%x]:Initialize() Register for video property changes"), this);
352 VPHandler->MmvpnSetObserver((MMmfVideoPropertiesObserver*)this);
356 PP_DEBUG(_L("ppHwDev[%x]:Initialize() decoder yet to implement MMmfVideoPropertiesNotifier CI"), this);
360 // Initialize picture counters
361 iPictureCounters.iPicturesSkipped = 0;
362 iPictureCounters.iPicturesDisplayed = 0;
363 iPictureCounters.iTotalPictures = 0;
364 iOverflowPictureCounter = 0;
367 iProxy->MdvppInitializeComplete(this, err);
369 iPPState = EInitialized;
370 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize --"), this);
373 void CNGAPostProcHwDevice::WritePictureL(TVideoPicture* aPicture)
375 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture bufId = %d"), this,GetID(aPicture));
377 if (iPPState==EInitializing || iPPState==EStopped || iIsInputEnded)
379 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Unexpected state"), this);
380 User::Leave(KErrNotReady);
385 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: Invalid argument"), this);
386 User::Leave(KErrArgument);
389 iPictureCounters.iTotalPictures++;
390 if((iPPState != EPlaying) && (iFirstPictureUpdated))
394 else if( iInputQ.Count() > 0 )
402 TTimeToPost iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
405 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL GCE not ready"), this );
406 if(iTimeToPost == EPostIt)
408 iTimeToPost = EDelayIt;
411 if (delta > 0x7FFFFFFF)
413 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL Too large delta .. skipping"), this );
414 iTimeToPost = ESkipIt;
416 if(!iFirstPictureUpdated)
418 if(iTimeToPost == EDelayIt)
420 iTimeToPost = EPostIt;
431 iPostingTimer->Cancel();
438 if(iIsColorConversionNeeded)
440 TVideoPicture* ccPic;
441 ccPic = DoColorConvert(pic); // output will be in ccPic
444 iProcessQ.Append(pic);
446 #ifdef _DUMP_YUV_FRAMES
449 iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue);
450 iCurrentPlaybackPosition = pic->iTimestamp;
452 if(!iFirstPictureUpdated)
454 iFirstPictureUpdated = ETrue;
455 if(!iSurfaceCreatedEventPublished)
457 PublishSurfaceCreated();
470 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePicture --"), this);
475 CNGAPostProcHwDevice::PostProcessorInfoLC()
477 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PostProcessorInfoLC() ++"), this);
478 TUncompressedVideoFormat yuvFormat;
479 RArray<TUint32> SupportedPostProcess;
480 TBool SupportedHwAcceleration = ETrue; //Non-Accelerated ETrue,
481 TYuvToRgbCapabilities SupportedYuvToRgbCapab;
482 TInt32 SupportedRotations = ERotateNone; // no rotation supported
484 TBool SupportedArbitraryScaling = EFalse; // no scaling supported
485 RArray<TScaleFactor> SupportedScaleFactors;
486 TBool SupportedAntiAliasing = EFalse;
489 yuvFormat.iDataFormat = EYuvRawData;
490 yuvFormat.iYuvFormat.iYuv2RgbMatrix = 0;
491 yuvFormat.iYuvFormat.iRgb2YuvMatrix = 0;
492 yuvFormat.iYuvFormat.iAspectRatioNum = 1;
493 yuvFormat.iYuvFormat.iAspectRatioDenom = 1;
494 yuvFormat.iYuvFormat.iCoefficients = EYuvBt709Range1;
495 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
496 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedBE;
498 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
500 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
501 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
503 yuvFormat.iYuvFormat.iCoefficients = EYuvBt709Range0;
504 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
505 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedBE;
506 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
508 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
509 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
511 yuvFormat.iYuvFormat.iCoefficients = EYuvBt709Range0;
512 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
513 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedLE;
514 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
516 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
517 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
519 yuvFormat.iYuvFormat.iCoefficients = EYuvBt709Range1;
520 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
521 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedLE;
522 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
524 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
525 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
527 yuvFormat.iYuvFormat.iCoefficients = EYuvBt601Range0;
528 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
529 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedBE;
530 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
532 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
533 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
535 yuvFormat.iYuvFormat.iCoefficients = EYuvBt601Range1;
536 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
537 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedBE;
538 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
540 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
541 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
543 yuvFormat.iYuvFormat.iCoefficients = EYuvBt601Range0;
544 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
545 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedLE;
546 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
548 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
549 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
551 yuvFormat.iYuvFormat.iCoefficients = EYuvBt601Range1;
552 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma1;
553 yuvFormat.iYuvFormat.iDataLayout = EYuvDataInterleavedLE;
554 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
556 yuvFormat.iYuvFormat.iPattern = EYuv422Chroma2;
557 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
560 yuvFormat.iYuvFormat.iCoefficients = EYuvBt709Range1;
561 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma1;
562 yuvFormat.iYuvFormat.iDataLayout = EYuvDataPlanar;
563 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
565 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma2;
566 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
568 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma3;
569 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
571 yuvFormat.iYuvFormat.iCoefficients = EYuvBt709Range0;
572 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma1;
573 yuvFormat.iYuvFormat.iDataLayout = EYuvDataPlanar;
574 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
576 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma2;
577 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
579 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma3;
580 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
582 yuvFormat.iYuvFormat.iCoefficients = EYuvBt601Range1;
583 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma1;
584 yuvFormat.iYuvFormat.iDataLayout = EYuvDataPlanar;
585 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
587 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma2;
588 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
590 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma3;
591 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
593 yuvFormat.iYuvFormat.iCoefficients = EYuvBt601Range0;
594 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma1;
595 yuvFormat.iYuvFormat.iDataLayout = EYuvDataPlanar;
596 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
598 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma2;
599 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
601 yuvFormat.iYuvFormat.iPattern = EYuv420Chroma3;
602 User::LeaveIfError(iSupportedInputFormats.Append(yuvFormat));
604 CPostProcessorInfo* postProcessorInfo = CPostProcessorInfo::NewL(
605 KUidVideoPostProcHwDevice,
609 iSupportedInputFormats.Array(),
610 SupportedPostProcess.Array(),
611 SupportedHwAcceleration,
612 ETrue, //Direct Display
613 SupportedYuvToRgbCapab,
615 SupportedArbitraryScaling,
616 SupportedScaleFactors.Array(),
617 SupportedAntiAliasing);
619 CleanupStack::PushL(postProcessorInfo);
620 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PostProcessorInfoLC() --"), this);
621 return postProcessorInfo;
624 void CNGAPostProcHwDevice::MmvprcGetPlayRateCapabilitiesL(TVideoPlayRateCapabilities& aCap)
626 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcGetPlayRateCapabilitiesL ++"), this);
627 aCap.iPlayForward = ETrue;
628 aCap.iPlayBackward = ETrue;
629 aCap.iStepForward = ETrue;
630 aCap.iStepBackward = ETrue;
631 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcGetPlayRateCapabilitiesL --"), this);
634 void CNGAPostProcHwDevice::MmvprcSetPlayRateL(const TInt aRate)
636 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetPlayRateL ++"), this);
640 iKeyFrameMode = ETrue;
644 iKeyFrameMode = EFalse;
645 ResetCountingBuffer();
647 //In fast forward go direct to key frame mode if speed >4X =
648 if (iPlayRate>KDefPlayRate*4)
652 iFPObserver->MmvproKeyFrameModeRequest();
656 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetPlayRateL=%d --"), this, aRate);
659 TInt CNGAPostProcHwDevice::MmvprcPlayRateL()
661 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcPlayRateL= ++"), this);
662 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcPlayRateL= --"), this);
666 void CNGAPostProcHwDevice::MmvprcStepFrameL(const TInt aStep)
668 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcStepFrameL= ++"), this);
669 iStepFrameCount = aStep;
670 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcStepFrameL=%d --"), this, aStep);
673 void CNGAPostProcHwDevice::MmvprcSetObserver(MMmfVideoPlayRateObserver& aObserver)
675 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetObserver ++"), this);
676 iFPObserver = &aObserver;
677 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvprcSetObserver --"), this);
680 void CNGAPostProcHwDevice::MmvsoSetSecureOutputL(TBool aSecure)
682 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL aSecure = %d++"), this, aSecure);
686 iSurfaceMask = surfaceHints::EAllowInternalOnly;
690 iSurfaceMask = surfaceHints::EAllowAllExternals;
692 if(!iSurfaceId.IsNull())
697 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvsoSetSecureOutputL -- leaving err = %d"), this, err);
701 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvsoSetSecureOutputL --"), this);
704 void CNGAPostProcHwDevice::MmavsoSetAllowedOutputL(TUint aAllowedOutputMask)
706 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL aAllowedOutputMask=0x%08x ++"), this,aAllowedOutputMask);
708 iSurfaceMask = surfaceHints::EAllowInternalOnly;
709 if (aAllowedOutputMask == EVideoAllowAll)
711 iSurfaceMask = surfaceHints::EAllowAllExternals;
713 else if (aAllowedOutputMask == EVideoAllowInternalOnly)
715 iSurfaceMask = surfaceHints::EAllowInternalOnly;
719 // we hope to find some valid output prefs
720 if (aAllowedOutputMask & EVideoAllowAnalog)
722 iSurfaceMask |= surfaceHints::EAllowAnalog;
724 if (aAllowedOutputMask & EVideoAllowMacroVision)
726 iSurfaceMask |= surfaceHints::EAllowAnalogProtectionRequired;
728 if (aAllowedOutputMask & EVideoAllowHDMI)
730 iSurfaceMask |= surfaceHints::EAllowDigital;
732 if (aAllowedOutputMask & EVideoAllowHdmiHdcpRequested)
734 iSurfaceMask |= surfaceHints::EAllowDigitalProtectionRequested;
736 if (aAllowedOutputMask & EVideoAllowHdmiHdcpRequired)
738 iSurfaceMask |= surfaceHints::EAllowDigitalProtectionRequired;
742 if((!iSurfaceId.IsNull()))
747 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmavsoSetAllowedOutputL -- leaving err = %d"), this, err);
751 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmavsoSetAllowedOutputL --"), this);
754 void CNGAPostProcHwDevice::SetPostProcessTypesL(TUint32 /*aCombination*/)
756 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPostProcessTypesL ++"), this);
758 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPostProcessTypesL --"), this);
761 void CNGAPostProcHwDevice::SetInputCropOptionsL(const TRect& /*aRect*/)
763 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputCropOptionsL ++"), this);
765 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetInputCropOptionsL --"), this);
768 void CNGAPostProcHwDevice::SetYuvToRgbOptionsL( const TYuvToRgbOptions& /*aOptions*/, const TYuvFormat& /*aYuvFormat*/, TRgbFormat /*aRgbFormat*/)
770 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL ++"), this);
772 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL --"), this);
775 void CNGAPostProcHwDevice::SetYuvToRgbOptionsL(const TYuvToRgbOptions& /*aOptions*/)
777 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL ++"), this);
779 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetYuvToRgbOptionsL --"), this);
782 void CNGAPostProcHwDevice::SetRotateOptionsL(TRotationType )
784 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetRotateOptionsL ++"), this);
786 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetRotateOptionsL --"));
789 void CNGAPostProcHwDevice::SetScaleOptionsL(const TSize& /*aTargetSize*/, TBool /*aAntiAliasFiltering*/)
791 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScaleOptionsL ++"), this);
793 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScaleOptionsL --"), this);
796 void CNGAPostProcHwDevice::SetOutputCropOptionsL(const TRect& /*aRect*/)
798 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputCropOptionsL ++"), this);
800 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetOutputCropOptionsL --"), this);
803 void CNGAPostProcHwDevice::SetPostProcSpecificOptionsL(const TDesC8& )
808 void CNGAPostProcHwDevice::CommitL()
810 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CommitL ++"), this);
812 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CommitL --"), this);
815 void CNGAPostProcHwDevice::Revert()
817 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Revert ++"), this);
819 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Revert --"), this);
822 void CNGAPostProcHwDevice::StartDirectScreenAccessL( const TRect& /*aVideoRect*/, CFbsScreenDevice& /*aScreenDevice*/, const TRegion& /*aClipRegion*/)
824 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:StartDSA ++"), this);
826 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:StartDSA --"), this);
829 void CNGAPostProcHwDevice::AbortDirectScreenAccess()
831 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AbortDSA ++"), this);
833 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AbortDSA --"), this);
836 void CNGAPostProcHwDevice::SetScreenClipRegion(const TRegion& /*aRegion*/)
838 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScreenClipRegion ++"), this);
841 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetScreenClipRegion --"), this);
844 void CNGAPostProcHwDevice::SetPauseOnClipFail(TBool )
846 //ignore. Post Processor will always behave as aPause==False.
849 TBool CNGAPostProcHwDevice::IsPlaying()
851 if( iPPState == EPlaying)
861 void CNGAPostProcHwDevice::Redraw()
863 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw ++"), this);
865 if(iRedrawSurfaceInUse && !iRedrawDone)
870 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to AddHints %d"),
872 iProxy->MdvppFatalError(this, err);
875 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface"), this);
876 err = RegisterSurface(iSurfaceId);
879 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw -- failed to Register Surface %d"),
881 iSurfaceHandler->DestroySurface(iSurfaceId);
882 iSurfaceId = TSurfaceId::CreateNullId();
883 iProxy->MdvppFatalError(this, err);
886 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw registering the temp surface done"), this);
887 iSessionManager->PostPicture(iSurfaceId, 0, 1, EFalse);
888 PublishSurfaceCreated();
891 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Redraw --"), this);
894 void CNGAPostProcHwDevice::Start()
896 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start ++"), this);
899 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Start --"), this);
902 void CNGAPostProcHwDevice::Stop()
904 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Stop ++"), this);
906 iPostingTimer->Cancel();
909 RDebug::Printf("------ Statistics of Post Processor ------");
910 RDebug::Printf(" Pictures Received : %d", iPictureCounters.iTotalPictures);
911 RDebug::Printf(" Pictures Displayed: %d", iPictureCounters.iPicturesDisplayed);
912 RDebug::Printf(" Pictures Skipped : %d", iPictureCounters.iPicturesSkipped);
913 RDebug::Printf("------------------------------------------");
915 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Stop --"), this);
918 void CNGAPostProcHwDevice::Pause()
920 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Pause ++"), this);
922 iPostingTimer->Cancel();
923 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Pause --"), this);
926 void CNGAPostProcHwDevice::Resume()
928 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Resume ++"), this);
931 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Resume --"), this);
934 void CNGAPostProcHwDevice::SetPosition(const TTimeIntervalMicroSeconds& aPlaybackPosition)
936 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition ++"), this);
938 if (iPPState == EInitializing)
940 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition FAILED: Unexpected state"), this);
943 if (iPPState == EPaused)
945 iFirstPictureUpdated = EFalse;
947 iCurrentPlaybackPosition = aPlaybackPosition;
951 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetPosition --"), this);
954 void CNGAPostProcHwDevice::FreezePicture(const TTimeIntervalMicroSeconds& )
959 void CNGAPostProcHwDevice::ReleaseFreeze(const TTimeIntervalMicroSeconds& )
964 TTimeIntervalMicroSeconds
965 CNGAPostProcHwDevice::PlaybackPosition()
967 if (iPPState == EInitializing)
969 return TTimeIntervalMicroSeconds(0);
972 return iCurrentPlaybackPosition;
975 TUint CNGAPostProcHwDevice::PictureBufferBytes()
980 void CNGAPostProcHwDevice::GetPictureCounters( CMMFDevVideoPlay::TPictureCounters& aCounters)
982 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetPictureCounters ++"), this);
984 if (iPPState == EInitializing)
986 aCounters = iPictureCounters;
988 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetPictureCounters --"), this);
991 void CNGAPostProcHwDevice::SetComplexityLevel(TUint )
996 TUint CNGAPostProcHwDevice::NumComplexityLevels()
1002 void CNGAPostProcHwDevice::GetComplexityLevelInfo(TUint , CMMFDevVideoPlay::TComplexityLevelInfo& )
1007 void CNGAPostProcHwDevice::ReturnPicture(TVideoPicture* )
1009 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicture +-"), this);
1010 //not required for direct rendering
1013 TBool CNGAPostProcHwDevice::GetSnapshotL(TPictureData& aPictureData, const TUncompressedVideoFormat& /*aFormat*/)
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;
1024 if(aPictureData.iDataFormat == ERgbFbsBitmap)
1026 if(iProcessQ.Count())
1028 pic = iProcessQ[0]; //frame already submitted for display
1030 else if(iInputQ.Count())
1032 pic = iInputQ[0]; //frame yet to be displayed
1038 inputFrame.lum = (TUint8*)pic->iData.iRawData->Ptr();
1042 if (iInputDecoderDevice)
1044 MMmfVideoFetchFrame* VFHandler = NULL;
1045 VFHandler = (MMmfVideoFetchFrame*)iInputDecoderDevice->CustomInterface(KUidMMFVideoFetchFrame);
1048 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() fetch frame"), this);
1049 inputFrame.lum = (TUint8*)VFHandler->MmvffGetFrame(GetID(pic));
1053 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL() decoder yet to implement MMmfVideoFetchFrame CI"), this);
1060 inputFrame.cb = inputFrame.lum + iPicSize.iWidth * iPicSize.iHeight;
1062 if( ((iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma1) ||
1063 (iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma2) ||
1064 (iVideoFormat.iYuvFormat.iPattern == EYuv420Chroma3) ))
1066 inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*5)/4;
1070 inputFrame.cr = inputFrame.lum + (iPicSize.iWidth * iPicSize.iHeight*3)/2;
1073 inputFrame.width = (unsigned short)iPicSize.iWidth;
1074 inputFrame.height = (unsigned short)iPicSize.iHeight;
1076 outputCropWindow.wndHeight = iPicSize.iHeight;
1077 outputCropWindow.wndWidth = iPicSize.iWidth;
1078 outputCropWindow.xOffset = 0;
1079 outputCropWindow.yOffset = 0;
1081 inputCropWindow.wndHeight = iPicSize.iHeight;
1082 inputCropWindow.wndWidth = iPicSize.iWidth;
1083 inputCropWindow.xOffset = 0;
1084 inputCropWindow.yOffset = 0;
1088 CFbsBitmap* iOutBitmap = aPictureData.iRgbBitmap;
1089 TInt status = iOutBitmap->Resize(iPicSize);
1090 if (status == KErrNone)
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;
1104 err = KErrNotSupported;
1110 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:GetSnapshotL --"), this);
1111 return(frameAvailable);
1114 void CNGAPostProcHwDevice::InputEnd()
1116 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd ++"), this);
1118 if (iPPState!=EPlaying && iPPState!=EPaused)
1120 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd FAILED: Unexpected state"), this);
1123 iIsInputEnded = ETrue;
1125 if( (iProcessQ.Count() == 1) && (iInputQ.Count() == 0))
1127 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd() Stream end"), this);
1128 iProxy->MdvppStreamEnd();
1131 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:InputEnd --"), this);
1134 TAny* CNGAPostProcHwDevice::CustomInterface(TUid aInterface)
1136 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CustomInterface UID = %d ++"), this, aInterface.iUid);
1138 if (aInterface == KUidMmfVideoBufferManagement)
1140 return (MMmfVideoBufferManagement *)this;
1142 if (aInterface == KUidMMFVideoSurfaceSupport)
1144 return (MMMFVideoSurfaceSupport *)this;
1146 if (aInterface == KUidMMFVideoSurfaceHandleControl)
1148 return (MMmfVideoSurfaceHandleControl *)this;
1150 if (aInterface == KUidMmfVideoPlayRateControl)
1152 return (MMmfVideoPlayRateControl *)this;
1154 if (aInterface == KMmfVideoAdvancedSecureOutputUid)
1156 return (MMmfAdvancedVideoSecureOutput *)this;
1158 if (aInterface == KUidMmfVideoResourceManagement)
1160 return (MMmfVideoResourceObserver *)this;
1162 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CustomInterface --"), this);
1166 void CNGAPostProcHwDevice::BufferAvailable(TInt aBufId, TInt aStatus)
1168 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CNGAPostProcHwDevice::BufferAvailable aStatus = %d aBufId = %d++"), this, aStatus, aBufId);
1169 TVideoPicture* pic = NULL;
1170 if((aStatus != KErrNone) && (aStatus != KErrOverflow) && (aStatus != KErrNotVisible))
1172 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:BufferAvailable FAILED: aStatus = %d"), this, aStatus);
1173 iProxy->MdvppFatalError(this, aStatus);
1176 if(aStatus == KErrOverflow)
1178 iOverflowPictureCounter++;
1184 for(TInt i=0; i < iProcessQ.Count(); i++)
1186 if(iVBMBufferReferenceQ[aBufId] == iProcessQ[i])
1189 iProcessQ.Remove(i);
1190 ReturnPicToDecoder(pic);
1191 if (iIsColorConversionNeeded)
1193 AddPictureToColorConversionQ(pic);
1197 AddPictureToVBMQ(pic);
1203 else if (iUsingExternalSurface)
1205 for(TInt i=0; i < iProcessQ.Count(); i++)
1207 if (aBufId == GetExternalBufferID(iProcessQ[i]))
1210 iProcessQ.Remove(i);
1211 ReturnPicToDecoder(pic);
1217 if(aStatus == KErrNone)
1219 if (!iKeyFrameMode && iPlayRate>KDefPlayRate)
1221 if (iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer]==1)
1223 iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer] = 0;
1224 iSkippedFramesInLast64Frames--;
1226 iCurrentPosInFramesCountingBuffer = ++iCurrentPosInFramesCountingBuffer%64;
1228 iPictureCounters.iPicturesDisplayed++;
1229 if (iStepFrameCount != 0)
1231 iStepFrameCount > 0 ? iStepFrameCount-- : iStepFrameCount++;
1232 if (iStepFrameCount==0 && iFPObserver)
1234 iFPObserver->MmvproStepFrameComplete(pic->iTimestamp);
1239 if(iPPState == EPlaying)
1244 if( iIsInputEnded && (iProcessQ.Count() == 1) && (iInputQ.Count() == 0))
1246 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:BufferAvailable() Stream end"), this);
1247 iProxy->MdvppStreamEnd();
1250 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:CNGAPostProcHwDevice::BufferAvailable --"), this);
1253 //=== MMmfVideoBufferManagement ===
1254 void CNGAPostProcHwDevice::MmvbmSetObserver(MMmfVideoBufferManagementObserver* aObserver)
1256 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver() ++"), this);
1258 if (iPPState != EInitializing)
1260 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver FAILED: Unexpected state"), this);
1261 iProxy->MdvppFatalError(this, KErrNotReady);
1264 iVBMObserver = aObserver;
1266 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetObserver() --"), this);
1270 void CNGAPostProcHwDevice::MmvbmEnable(TBool aEnable)
1272 if (iPPState != EInitializing)
1274 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmEnable FAILED: Unexpected state"), this);
1275 iProxy->MdvppFatalError(this, KErrNotReady);
1278 iVBMEnabled = aEnable;
1281 void CNGAPostProcHwDevice::MmvbmSetBufferOptionsL(const TBufferOptions& aOptions)
1283 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL ++"), this);
1285 if (iPPState != EInitializing)
1287 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Unexpected state"), this);
1288 User::Leave(KErrNotReady);
1291 if (aOptions.iNumInputBuffers > KMaxVBMBuffers
1292 || aOptions.iNumInputBuffers <= 1) //at least two buffers
1294 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Input buffer count limit"), this);
1295 User::Leave(KErrNotSupported);
1298 if (aOptions.iNumInputBuffers == 0
1299 || aOptions.iBufferSize.iWidth <= KMinVBMInputWidth
1300 || aOptions.iBufferSize.iHeight <= KMinVBMInputHeight
1301 || aOptions.iBufferSize.iWidth > KMaxVBMInputWidth
1302 || aOptions.iBufferSize.iHeight > KMaxVBMInputHeight)
1304 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL FAILED: Unexpected buffer size"), this);
1305 User::Leave(KErrArgument);
1308 iVBMBufferOptions.iNumInputBuffers = aOptions.iNumInputBuffers;
1309 iVBMBufferOptions.iBufferSize = aOptions.iBufferSize;
1311 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmSetBufferOptionsL --"), this);
1314 void CNGAPostProcHwDevice::MmvbmGetBufferOptions(TBufferOptions& aOptions)
1316 if (iPPState == EInitializing)
1318 aOptions = iVBMBufferOptions;
1322 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferOptions FAILED: Unexpected state"), this);
1323 iProxy->MdvppFatalError(this, KErrNotReady);
1327 TVideoPicture* CNGAPostProcHwDevice::MmvbmGetBufferL(const TSize& aSize)
1329 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() ++"), this);
1331 TInt err = KErrNone;
1332 TVideoPicture* lPic = NULL;
1334 if (iPPState == EInitializing)
1336 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() FAILED: Unexpected state"), this);
1337 User::Leave(KErrNotReady);
1340 if (aSize.iWidth < KMinVBMInputWidth
1341 || aSize.iHeight < KMinVBMInputHeight
1342 || aSize.iWidth > iVBMBufferOptions.iBufferSize.iWidth
1343 || aSize.iHeight > iVBMBufferOptions.iBufferSize.iHeight)
1345 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() FAILED: Unexpected buffer size w=%d h=%d "), this,aSize.iWidth,aSize.iHeight );
1346 User::Leave(KErrNotSupported);
1349 if(iVBMBufferReferenceQ.Count() == 0)
1352 err = SetupSurface(aSize);
1355 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() Surface Setup Failed %d"), this, err);
1360 if(!iVBMBufferQ.Count())
1362 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() WARNING: Queue buffer count zero"), this);
1366 lPic = iVBMBufferQ[0];
1367 iVBMBufferQ.Remove(0);
1369 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmGetBufferL() -- %d"), this, lPic);
1373 void CNGAPostProcHwDevice::MmvbmReleaseBuffer(TVideoPicture* aBuffer)
1375 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() ++"), this);
1379 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() FAILED: Invalid buffer ptr"), this);
1380 iProxy->MdvppFatalError(this, KErrArgument);
1383 TInt err = iVBMBufferQ.Append(aBuffer);
1386 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() FAILED: Failed to append"), this);
1387 iProxy->MdvppFatalError(this, err);
1390 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvbmReleaseBuffer() --"), this);
1393 //=== MMMFVideoSurfaceSupport ===
1395 void CNGAPostProcHwDevice::MmvssUseSurfaces()
1397 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssUseSurfaces() ++"), this);
1399 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssUseSurfaces() --"), this);
1402 void CNGAPostProcHwDevice::MmvssSetObserver(MMMFVideoSurfaceObserver& aObserver)
1404 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSetObserver() ++"), this);
1405 iVideoSurfaceObserver = &aObserver;
1406 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSetObserver() --"), this);
1409 void CNGAPostProcHwDevice::MmvssGetSurfaceParametersL(TSurfaceId& aSurfaceId,
1410 TRect& aCropRect, TVideoAspectRatio& aPixelAspectRatio)
1412 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() ++"), this);
1414 iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
1415 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() \
1416 surfaceWidth = %d surfaceHeight = %d SurfaceId = 0x%x --"),
1417 this, iInfo().iSize.iWidth, iInfo().iSize.iHeight, iSurfaceId);
1418 aSurfaceId = iSurfaceId;
1419 aCropRect = TRect(0, 0, iInfo().iSize.iWidth, iInfo().iSize.iHeight);
1420 if((iPicSize.iWidth > 0) && (iPicSize.iHeight > 0))
1422 aCropRect.Intersection( iPicSize);
1424 aPixelAspectRatio = TVideoAspectRatio(iAspectRatioNum,iAspectRatioDenom);
1425 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() \
1426 cropRectWidth = %d cropRectHeight = %d"), this, aCropRect.Width(), aCropRect.Height());
1427 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() \
1428 PAR Num = %d PAR Denom = %d"), this, aPixelAspectRatio.iNumerator, aPixelAspectRatio.iDenominator);
1429 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssGetSurfaceParametersL() --"), this);
1432 void CNGAPostProcHwDevice::MmvssSurfaceRemovedL(const TSurfaceId& aSurfaceId)
1434 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL()++"), this);
1435 if(!aSurfaceId.IsNull())
1437 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL(): UnregisterSurface ID = 0x%x"), this, aSurfaceId );
1438 TInt numScreens = iWsSession.NumberOfScreens();
1439 for(TInt i=0;i < numScreens;i++)
1441 iWsSession.UnregisterSurface(i, aSurfaceId);
1444 iSurfaceHandler->DestroySurface(aSurfaceId);
1445 if(iSurfaceId == aSurfaceId)
1447 iSurfaceCreatedEventPublished = EFalse;
1448 iSurfaceId = TSurfaceId::CreateNullId();
1452 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvssSurfaceRemovedL() --"), this);
1455 // === MMmfVideoPropertiesObserver ===
1457 void CNGAPostProcHwDevice::MmvpoUpdateVideoProperties(const TYuvFormat& aYuvFormat, const TSize& aPictureSize)
1459 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties ++"), this);
1460 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties PAR \
1461 iAspectRatioNum = %d, iAspectRatioDenom = %d"), this,
1462 aYuvFormat.iAspectRatioNum,aYuvFormat.iAspectRatioDenom);
1463 iPicSize = aPictureSize;
1464 iAspectRatioNum = aYuvFormat.iAspectRatioNum;
1465 iAspectRatioDenom = aYuvFormat.iAspectRatioDenom;
1466 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties Picture Size \
1467 iWidth = %d, iHeight = %d, iSurfaceCreatedEventPublished = %d"),
1468 this, iPicSize.iWidth,iPicSize.iHeight, iSurfaceCreatedEventPublished?1:0);
1472 iVPObserver->MmvpoUpdateVideoProperties(aYuvFormat, aPictureSize);
1474 if(iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
1476 iVideoSurfaceObserver->MmvsoSurfaceParametersChanged();
1478 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvpoUpdateVideoProperties --"), this);
1481 // === MMmfVideoResourceObserver ===
1483 void CNGAPostProcHwDevice::MmvroResourcesLost(TUid )
1485 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ++"), this);
1488 iResourceLost = ETrue;
1489 iRedrawDone = EFalse;
1492 iSessionManager->CancelUpdate();
1494 if(iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
1496 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost - Telling client to remove surface"), this);
1497 iVideoSurfaceObserver->MmvsoRemoveSurface();
1498 iSurfaceCreatedEventPublished = EFalse;
1501 else if(iResourceLost && iRedrawDone)
1503 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost ResourceLost happening \
1504 while Postprocessor is already in ResourceLoss state"),
1506 iProxy->MdvppFatalError(this, KErrHardwareNotAvailable);
1511 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost Ignoring the \
1512 duplicate ResourceLoss call"),
1515 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvroResourcesLost --"), this);
1518 // === MMmfVideoPropertiesNotifier ===
1520 void CNGAPostProcHwDevice::MmvpnSetObserver(MMmfVideoPropertiesObserver* aObserver)
1522 PP_DEBUG(_L("ppHwDev[%x]::MmvpnSetObserver ++"), this);
1523 iVPObserver = aObserver;
1524 PP_DEBUG(_L("ppHwDev[%x]::MmvpnSetObserver --"), this);
1527 void CNGAPostProcHwDevice::MmvroResourcesRestored(TUid )
1529 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesRestored ++"), this);
1530 iFirstPictureUpdated = EFalse;
1531 iResourceLost = EFalse;
1532 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvroResourcesRestored state=%d --"),
1536 void CNGAPostProcHwDevice::MmvshcSetSurfaceHandle(const TSurfaceId &aSurfaceID)
1539 SetupExternalSurface(aSurfaceID);
1543 void CNGAPostProcHwDevice::MmvshcRedrawBufferToSurface(TPtrC8& aRedrawBuffer)
1545 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface ++"), this);
1550 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface -- Creating %d x %d surface"), this, iPicSize.iWidth, iPicSize.iHeight);
1552 TInt err = KErrNone;
1553 SetSurfaceAttributes(iPicSize, 1);
1555 err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
1556 if (err != KErrNone)
1558 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to create Surface %d"),
1560 iProxy->MdvppFatalError(this, err);
1564 err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
1565 if (err != KErrNone)
1567 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to get Surface info %d"),
1569 iSurfaceHandler->DestroySurface(iSurfaceId);
1570 iSurfaceId = TSurfaceId::CreateNullId();
1571 iProxy->MdvppFatalError(this, err);
1575 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface() \
1576 surfaceWidth = %d surfaceHeight = %d surfaceStride = %d"), this, iInfo().iSize.iWidth, iInfo().iSize.iHeight, iInfo().iStride);
1578 TInt redrawBufferSize = aRedrawBuffer.Size();
1579 TInt surfaceSize = iInfo().iStride * iInfo().iSize.iHeight;
1581 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface RedrawBuffer size= %d Surface size = %d"), this, redrawBufferSize, surfaceSize);
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)
1587 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface Redraw buffer size larger than surface size"), this);
1588 iSurfaceHandler->DestroySurface(iSurfaceId);
1589 iSurfaceId = TSurfaceId::CreateNullId();
1593 err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
1594 if (err != KErrNone)
1596 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:MmvshcRedrawBufferToSurface -- failed to map Surface %d"),
1598 iSurfaceHandler->DestroySurface(iSurfaceId);
1599 iSurfaceId = TSurfaceId::CreateNullId();
1600 iProxy->MdvppFatalError(this, err);
1604 if((err = iSurfaceHandler->GetBufferOffset(iSurfaceId, 0, offset)) != KErrNone)
1606 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset query failed %d"), this, err);
1607 iSurfaceHandler->DestroySurface(iSurfaceId);
1608 iSurfaceId = TSurfaceId::CreateNullId();
1610 iProxy->MdvppFatalError(this, err);
1614 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface offset = %d"), this, offset);
1616 lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
1617 memcpy((TAny *)lPtr, (TAny *)aRedrawBuffer.Ptr(), redrawBufferSize);
1619 iRedrawSurfaceInUse = ETrue;
1621 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface(): New surface = 0x%x"), this, iSurfaceId);
1623 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::MmvshcRedrawBufferToSurface error = %d --"), this, err);
1626 TInt CNGAPostProcHwDevice::SetupExternalSurface(const TSurfaceId &aSurfaceID)
1628 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface(): aSurfaceID = 0x%x"), this, aSurfaceID );
1630 TInt err = KErrNone;
1632 if(!iSurfaceId.IsNull())
1634 if (iVideoSurfaceObserver && iSurfaceCreatedEventPublished)
1636 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface - Telling client to remove old surface"), this);
1637 iVideoSurfaceObserver->MmvsoRemoveSurface();
1638 iSurfaceCreatedEventPublished = EFalse;
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++)
1647 iWsSession.UnregisterSurface(i, iSurfaceId);
1650 iSurfaceHandler->DestroySurface(iSurfaceId);
1656 iSurfaceId = aSurfaceID;
1657 iUsingExternalSurface = ETrue;
1658 iRedrawSurfaceInUse = EFalse;
1660 // Create the surface handler if it doesn't exist.
1661 if (!iSurfaceHandler)
1663 TRAP(err, iSurfaceHandler = CNGAPostProcSurfaceHandler::NewL());
1664 if (err != KErrNone)
1666 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to create SurfaceHandler."), this);
1671 err = iSurfaceHandler->OpenSurface(iSurfaceId);
1672 if (err != KErrNone)
1674 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed OpenSurface %d"),
1679 if (err != KErrNone)
1681 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to AddHints %d"),
1685 err = RegisterSurface(iSurfaceId);
1686 if (err != KErrNone)
1688 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed RegisterSurface %d"),
1690 iSurfaceHandler->DestroySurface(iSurfaceId);
1691 iSurfaceId = TSurfaceId::CreateNullId();
1695 err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
1696 if (err != KErrNone)
1698 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface -- failed to get Surface info %d"),
1703 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetupExternalSurface err=%d"), this, err);
1708 TVideoPicture* CNGAPostProcHwDevice::CreateBuffersL(TInt aBufId)
1710 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL ++"), this);
1712 TVideoPicture* lVideoPicture = NULL;
1717 lVideoPicture = new (ELeave) TVideoPicture;
1718 CleanupStack::PushL(lVideoPicture);
1719 if(TInt err = iSurfaceHandler->GetBufferOffset(iSurfaceId, aBufId, offset) != KErrNone)
1721 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL offset query failed %d"), this, err);
1723 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateBuffersL offset = %d id =%d --"), this, offset, aBufId);
1725 lPtr = reinterpret_cast<TUint8*>(iChunk.Base() + offset);
1727 lTemp = new (ELeave) TPtr8(lPtr, 0, (iVideoFrameBufSize ));
1728 CleanupStack::PushL(lTemp);
1730 lVideoPicture->iData.iRawData = lTemp;
1731 lVideoPicture->iHeader = NULL ;
1732 lVideoPicture->iLayerBitRates = NULL ;
1734 CleanupStack::Pop(2);
1736 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL --"), this);
1737 return lVideoPicture;
1740 void CNGAPostProcHwDevice::CreateVBMBuffersL()
1742 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL ++"), this);
1744 TInt err = KErrNone;
1745 TVideoPicture* pic = NULL;
1746 iVBMBufferReferenceQ.Reset();
1747 iVBMBufferQ.Reset();
1748 iColorConversionQ.Reset();
1750 for(TInt i = 0; i < iVBMBufferOptions.iNumInputBuffers; i++)
1752 TRAP(err, pic = CreateBuffersL(i));
1753 if (err != KErrNone)
1755 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
1759 // This will hold the references which will be used in destructor
1760 User::LeaveIfError(iVBMBufferReferenceQ.Append(pic));
1761 User::LeaveIfError(iVBMBufferQ.Append(pic));
1763 if(iIsColorConversionNeeded)
1765 for(TInt i = iVBMBufferOptions.iNumInputBuffers ;
1766 i < (iVBMBufferOptions.iNumInputBuffers + KColorConversionBuffers ); i++)
1768 TRAP(err, pic = CreateBuffersL(i));
1769 if (err != KErrNone)
1771 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
1775 // This will hold the references which will be used in destructor
1776 User::LeaveIfError(iVBMBufferReferenceQ.Append(pic));
1777 User::LeaveIfError(iColorConversionQ.Append(pic));
1781 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]::CreateVBMBuffersL --"), this);
1784 void CNGAPostProcHwDevice::ReturnPicToDecoder(TVideoPicture* aPic)
1786 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicToDecoder ++"), this);
1789 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture FAILED: Invalid pic ptr."), this);
1793 if (iInputDecoderDevice)
1795 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture .. before return picture. 2"), this);
1796 iInputDecoderDevice->ReturnPicture(aPic);
1799 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReturnPicToDecoder --"), this);
1802 TInt CNGAPostProcHwDevice::AttemptToPost()
1804 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost ++ Q:%d"), this, iInputQ.Count());
1805 if (iPPState == EPaused)
1810 TInt err = KErrNotReady;
1811 TInt count = iInputQ.Count();
1812 TBool bDone = EFalse;
1813 TVideoPicture* pic = PeekQ();
1814 while(pic && !bDone)
1818 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost GCE not ready"), this );
1819 return err; //no need to catch this error
1822 TTimeToPost iTimeToPost = (TTimeToPost)IsTimeToPost(pic, delta);
1827 iPostingTimer->Cancel();
1834 RemoveFromQ(); // remove the pic that was returned by PeekQ
1835 if(iIsColorConversionNeeded)
1837 TVideoPicture* ccPic;
1838 ccPic = DoColorConvert(pic); // output will be in ccPic
1841 iProcessQ.Append(pic);
1842 #ifdef _DUMP_YUV_FRAMES
1845 iSessionManager->PostPicture(iSurfaceId, GetID(pic), iInfo().iBuffers, ETrue);
1846 iCurrentPlaybackPosition = pic->iTimestamp;
1847 if(!iFirstPictureUpdated)
1849 iFirstPictureUpdated = ETrue;
1850 if(!iSurfaceCreatedEventPublished)
1852 PublishSurfaceCreated();
1860 ReleasePicture(pic);
1866 // get the next picture
1870 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AttemptToPost --"), this);
1874 TInt CNGAPostProcHwDevice::IsTimeToPost(TVideoPicture* frame, TInt64& delta)
1876 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost ++"), this);
1880 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost FAILED: Invalid frame ptr."), this);
1884 TInt resp = EPostIt;
1885 // Frame presentation time
1886 TInt64 uPresTime = frame->iTimestamp.Int64();
1888 // Check if this is an out of order frame in case of forward playback
1889 if((iCurrentPlaybackPosition.Int64() > uPresTime) && (iPlayRate > 0))
1891 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (forward playback) Tfm=%d"), this,(TInt)uPresTime);
1892 resp = ESkipIt; //drop
1893 } // Check if this is an out of order frame in case of backward playback
1894 else if((iCurrentPlaybackPosition.Int64() < uPresTime) && (iPlayRate < 0))
1896 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost : Out of order frame (backward playback) Tfm=%d"), this,(TInt)uPresTime);
1897 resp = ESkipIt; //drop
1899 else if (iClockSource)
1901 // The time to sync with.
1902 TInt64 uSyncTime = iClockSource->Time().Int64();
1904 delta = uPresTime - uSyncTime;
1905 if (( delta > KRenderAhead ) && (iPlayRate > 0)) // Delay condition not checked for
1906 { // backward playback
1907 resp = EDelayIt; //wait
1909 else if ( (delta < (-KMaxRenderDelay) && (iPlayRate > 0))
1910 || ((delta > KMaxRenderDelay) && (iPlayRate < 0)))
1912 resp = ESkipIt; //drop
1914 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost .. Tfm=%d, Tcs=%d, delta=%d"), this, (TInt)uPresTime, (TInt)uSyncTime, (TInt)delta);
1917 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:IsTimeToPost -- %d BufID = %d"), this, resp, GetID(frame));
1921 void CNGAPostProcHwDevice::ReleaseInputQ()
1923 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputQ ++ Q = %d"), this, iInputQ.Count());
1924 while (iInputQ.Count()>0)
1926 ReleasePicture(iInputQ[0]);
1929 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputQ --"), this);
1932 void CNGAPostProcHwDevice::ReleaseProcessQ()
1934 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseProcessQ ++ Q = %d"), this, iProcessQ.Count() );
1935 TVideoPicture* pic = NULL;
1937 while (iProcessQ.Count()>0)
1940 iProcessQ.Remove(0);
1941 ReturnPicToDecoder(pic);
1943 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseProcessQ --"), this);
1946 void CNGAPostProcHwDevice::ReleasePicture(TVideoPicture *pic)
1948 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleasePicture ++"), this);
1951 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture FAILED: Invalid pic ptr."), this);
1955 if (iInputDecoderDevice)
1957 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleaseInputPicture .. before return picture. 2"), this);
1958 iInputDecoderDevice->ReturnPicture(pic);
1962 iVBMBufferQ.Append(pic);
1964 if ( !iIsInputEnded && iPPState != EStopped )
1966 iVBMObserver->MmvbmoNewBuffers();
1969 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ReleasePicture --"), this);
1972 void CNGAPostProcHwDevice::PublishSurfaceCreated()
1974 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PublishSurfaceCreated ++"), this);
1975 if(iVideoSurfaceObserver)
1977 iVideoSurfaceObserver->MmvsoSurfaceCreated();
1978 iSurfaceCreatedEventPublished = ETrue;
1980 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PublishSurfaceCreated --"), this);
1983 TInt CNGAPostProcHwDevice::SetupSurface(const TSize& aSize)
1985 TInt err = KErrNone;
1986 if(iVBMEnabled && iVBMObserver)
1988 SetSurfaceAttributes(aSize, KMaxVBMBuffers);
1989 iVBMBufferOptions.iNumInputBuffers = KMaxVBMBuffers;
1991 //Decoder needs the buffer size to fit in yuv422 decoded output.
1992 iVBMBufferOptions.iBufferSize = aSize;
1994 err = iSurfaceHandler->CreateSurface(iAttributes, iSurfaceId);
1995 if (err != KErrNone)
1997 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create Surface %d"), this, err);
2000 err = iSurfaceHandler->MapSurface(iSurfaceId, iChunk);
2001 if (err != KErrNone)
2003 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to map Surface %d"), this, err);
2004 iSurfaceHandler->DestroySurface(iSurfaceId);
2005 iSurfaceId = TSurfaceId::CreateNullId();
2008 err = iSurfaceHandler->SurfaceInfo(iSurfaceId, iInfo);
2009 if (err != KErrNone)
2011 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to get Surface info %d"), this, err);
2012 iSurfaceHandler->DestroySurface(iSurfaceId);
2013 iSurfaceId = TSurfaceId::CreateNullId();
2016 TRAP(err, CreateVBMBuffersL());
2017 if (err != KErrNone)
2019 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to create VBM buffer %d"), this, err);
2020 iSurfaceHandler->DestroySurface(iSurfaceId);
2021 iSurfaceId = TSurfaceId::CreateNullId();
2025 if (err != KErrNone)
2027 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to AddHints %d"), this, err);
2030 err = RegisterSurface(iSurfaceId);
2031 if (err != KErrNone)
2033 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:Initialize -- failed to RegisterSurface %d"), this, err);
2034 iSurfaceHandler->DestroySurface(iSurfaceId);
2035 iSurfaceId = TSurfaceId::CreateNullId();
2043 void CNGAPostProcHwDevice::SetSurfaceAttributes(const TSize& aSize, TInt aNumBuf)
2045 iAttributes().iSize = aSize; // size of the video frame
2046 iAttributes().iBuffers = aNumBuf;
2048 /* The stride needs to be calculated for the surface manager to know
2049 how much memory to allocate */
2051 if(iAttributes().iPixelFormat == EUidPixelFormatYUV_420Planar)
2053 iAttributes().iStride = aSize.iWidth * 3/2;
2054 iVideoFrameBufSize = aSize.iWidth * aSize.iHeight * 3/2;
2058 iAttributes().iStride = aSize.iWidth * 2;
2059 iVideoFrameBufSize = aSize.iWidth * aSize.iHeight * 2;
2062 if(iIsColorConversionNeeded)
2064 iAttributes().iBuffers = aNumBuf + KColorConversionBuffers;
2068 iAttributes().iBuffers = aNumBuf;
2071 iAttributes().iOffsetToFirstBuffer = 0;
2072 iAttributes().iAlignment = 4;
2073 iAttributes().iContiguous = ETrue;
2074 iAttributes().iHintCount = 0;
2075 iAttributes().iMappable = ETrue;
2078 TInt CNGAPostProcHwDevice::GetID(TVideoPicture *aPicture)
2080 if (iUsingExternalSurface)
2082 return GetExternalBufferID(aPicture);
2086 TUint8* aPtr = (TUint8*) aPicture->iData.iRawData->Ptr();
2087 return( (TInt) ((aPtr - iChunk.Base() - iAttributes().iOffsetToFirstBuffer) /
2088 (iVideoFrameBufSize )));
2092 TInt CNGAPostProcHwDevice::GetExternalBufferID(TVideoPicture *aPicture)
2094 // currently type cast the pointer as buffer ID.
2095 // FIXME once the new data structure is available.
2096 return( (TInt) aPicture->iData.iRawData->Ptr());
2099 TInt CNGAPostProcHwDevice::RegisterSurface(const TSurfaceId& aSurfaceId)
2101 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:RegisterSurface(): RegisterSurface ID = 0x%x"), this, aSurfaceId);
2102 TInt err = KErrNone;
2103 TInt numScreens = iWsSession.NumberOfScreens();
2104 for(TInt i=0; (i < numScreens && err == KErrNone); i++)
2106 err = iWsSession.RegisterSurface(i, aSurfaceId);
2111 TInt CNGAPostProcHwDevice::IsGceReady()
2113 if(iProcessQ.Count() >= KMaxBuffersGceCanHold)
2120 void CNGAPostProcHwDevice::SetTimer(TInt64 aDelta)
2122 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetTimer .. aDelta=%d"), this, (TInt)aDelta);
2123 if(aDelta <= KRenderAhead)
2127 iPostingTimer->After(aDelta * -1);
2131 iPostingTimer->After((aDelta - KRenderAhead) * -1);
2136 iPostingTimer->After(aDelta - KRenderAhead - KPostingOfset);
2140 // Convert YUV420 to YUV422InterLeaved.
2142 TInt CNGAPostProcHwDevice::ConvertPostProcBuffer(TVideoPicture* pSrc, TVideoPicture* pDest)
2144 PP_DEBUG(_L("CMdfPostingSurfaceProxy::ConvertPostProcBuffer ++"));
2145 TInt err = KErrNone;
2146 if (!pDest && !pSrc)
2148 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ConvertPostProcBuffer FAILED: Invalid pic pSrc %x pDest %x."), this, pSrc, pDest);
2149 return KErrArgument;
2152 // --- Prepare wrappers ---
2153 tBaseVideoFrame tFrame420, tFrame422;
2154 TInt frameSize = pSrc->iData.iDataSize.iWidth * pSrc->iData.iDataSize.iHeight;
2156 PP_DEBUG(_L("CMdfPostingSurfaceProxy::ConvertPostProcBuffer .. w=%d, h=%d"), pSrc->iData.iDataSize.iWidth, pSrc->iData.iDataSize.iHeight);
2158 tFrame420.width = pSrc->iData.iDataSize.iWidth;
2159 tFrame420.height= pSrc->iData.iDataSize.iHeight;
2160 tFrame420.lum = (TUint8*)pSrc->iData.iRawData->Ptr();
2161 tFrame420.cb = (TUint8*)tFrame420.lum + frameSize;
2162 tFrame420.cr = (TUint8*)tFrame420.lum + (frameSize*5)/4;
2164 tFrame422.width = pSrc->iData.iDataSize.iWidth;
2165 tFrame422.height= pSrc->iData.iDataSize.iHeight;
2166 tFrame422.lum = (TUint8*)pDest->iData.iRawData->Ptr();
2170 // --- Convertion to posting buffer ---
2171 TInt stride = pSrc->iData.iDataSize.iWidth * 2;
2172 EBufferLayout422 layout = YUV422INT_BE;
2174 err = gColorConvYUVtoYUV422Int(&tFrame420, &tFrame422, layout, stride);
2177 PP_DEBUG(_L("CNGAPostProcHwDevice::ConvertPostProcBuffer .. err= %d."), err);
2182 void CNGAPostProcHwDevice::AddPictureToVBMQ(TVideoPicture *pic)
2184 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToVBMQ ++"), this);
2185 iVBMBufferQ.Append(pic);
2187 if ( !iIsInputEnded && iPPState != EStopped )
2189 iVBMObserver->MmvbmoNewBuffers();
2192 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToVBMQ --"), this);
2195 void CNGAPostProcHwDevice::AddPictureToColorConversionQ(TVideoPicture *pic)
2197 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToColorConversionQ ++"), this);
2198 iColorConversionQ.Append(pic);
2199 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddPictureToColorConversionQ --"), this);
2202 #ifdef _DUMP_YUV_FRAMES
2203 void CNGAPostProcHwDevice::captureYuv(TVideoPicture* aPicture)
2206 sprintf(buf, "c:\\fb%d.yuv", count++);
2207 FILE *fp = ::fopen(buf, "w");
2208 TInt size = aPicture->iData.iRawData->Size();
2209 //{FILE* f1 = fopen(MY_LOG_FILE_NAME, "a+"));if(f1){fprintf(f1, "Size %d \n"), size );fclose(f1); }}
2211 ::fwrite(aPicture->iData.iRawData->Ptr(), 1, size, fp);
2216 void CNGAPostProcHwDevice::ResetCountingBuffer()
2218 memset(iSkippedFramesCountingBuffer,0,sizeof(iSkippedFramesCountingBuffer));
2219 iSkippedFramesInLast64Frames = 0;
2220 iCurrentPosInFramesCountingBuffer = 0;
2223 void CNGAPostProcHwDevice::PicturesSkipped()
2225 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PicturesSkipped ++"), this);
2226 iPictureCounters.iPicturesSkipped++;
2227 if (!iKeyFrameMode && iPlayRate>KDefPlayRate)
2229 if (iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer]==0)
2231 iSkippedFramesCountingBuffer[iCurrentPosInFramesCountingBuffer] = 1;
2232 iSkippedFramesInLast64Frames++;
2233 if (iSkippedFramesInLast64Frames>KMaxAllowedSkipInNFrames && iFPObserver )
2235 iFPObserver->MmvproKeyFrameModeRequest();
2236 iKeyFrameMode=ETrue;
2237 ResetCountingBuffer();
2240 iCurrentPosInFramesCountingBuffer = ++iCurrentPosInFramesCountingBuffer%64;
2242 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:PicturesSkipped --"), this);
2245 TVideoPicture* CNGAPostProcHwDevice::DoColorConvert(TVideoPicture* aPicture)
2247 TVideoPicture *pOutPicture = aPicture;
2249 if(iColorConversionQ.Count())
2251 pOutPicture = iColorConversionQ[0];
2252 iColorConversionQ.Remove(0);
2253 ConvertPostProcBuffer(aPicture, pOutPicture);
2254 pOutPicture->iTimestamp = aPicture->iTimestamp;
2255 ReleasePicture(aPicture);
2259 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:WritePictureL() FAILED: color conversion"), this);
2265 TInt CNGAPostProcHwDevice::AddToQ(TVideoPicture* aPicture)
2267 TVideoPicture* pic = aPicture;
2269 if(iInputQ.Count() == 0)
2271 iInputQ.Append(pic);
2275 pos = iInputQ.Count()-1;
2276 for(; pos >= 0; pos--)
2278 if(pic->iTimestamp.Int64() > iInputQ[pos]->iTimestamp.Int64())
2283 if(iInputQ.Count() == pos+1)
2285 iInputQ.Append(pic);
2289 iInputQ.Insert(pic, pos+1);
2295 void CNGAPostProcHwDevice::RemoveFromQ()
2305 iInputQ.Remove(iInputQ.Count()-1);
2310 TVideoPicture* CNGAPostProcHwDevice::PeekQ()
2312 TVideoPicture *pic = NULL;
2321 pic = iInputQ[iInputQ.Count()-1];
2327 TInt CNGAPostProcHwDevice::AddHints()
2329 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints iSurfaceMask 0x%08x ++"), this, iSurfaceMask);
2330 TInt err = KErrNone;
2331 iHint.Set(iSurfaceKey,iSurfaceMask,ETrue);
2332 err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
2333 if(err == KErrAlreadyExists)
2335 err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
2337 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
2338 iHint.iKey.iUid = surfaceHints::KSurfaceContent;
2339 iHint.iValue = surfaceHints::EVideoPlayback;
2340 iHint.iMutable = ETrue;
2341 err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
2342 if(err == KErrAlreadyExists)
2344 err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
2346 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
2347 if(iUsingExternalSurface)
2349 iHint.iKey.iUid = surfaceHints::KSurfaceCharacteristics;
2350 iHint.iValue = surfaceHints::ENotPersistable;
2351 iHint.iMutable = ETrue;
2352 err = iSurfaceHandler->AddSurfaceHint(iSurfaceId,iHint);
2353 if(err == KErrAlreadyExists)
2355 err = iSurfaceHandler->SetSurfaceHint(iSurfaceId,iHint);
2357 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:AddHints. err = %d --"), this,err);
2362 TInt CNGAPostProcHwDevice::ColorConvert(tBaseVideoFrame* aInputFrame, TUint8* aDestPtr, tWndParam* aInputCropWindow, tWndParam* aOutputCropWindow)
2364 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert ++"), this);
2365 __ASSERT_ALWAYS(aDestPtr, User::Invariant());
2366 TInt lError = E_SUCCESS;
2367 TInt err = KErrNone;
2369 err = SetSourceFormat();
2372 err = SetSourceRange();
2376 lError = Emz_VDec_gColorConv_YUVtoRGB(aInputFrame,aDestPtr,
2377 aInputCropWindow, aOutputCropWindow, iSourceFormat,
2378 EBitmapColor16MU, iSourceRange);
2382 if(lError == E_OUT_OF_MEMORY)
2386 else if(lError == E_FAILURE)
2388 err = KErrNotSupported;
2398 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:ColorConvert --"), this);
2402 TInt CNGAPostProcHwDevice::SetSourceFormat()
2404 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL ++"), this);
2405 TInt err = KErrNone;
2406 switch (iVideoFormat.iYuvFormat.iPattern)
2408 case EYuv420Chroma1:
2409 iSourceFormat = EYuv420Chroma1_Planar;
2411 case EYuv420Chroma2:
2412 iSourceFormat = EYuv420Chroma2_Planar;
2414 case EYuv420Chroma3:
2415 iSourceFormat = EYuv420Chroma3_Planar;
2417 case EYuv422Chroma1:
2418 if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
2419 iSourceFormat = EYuv422Chroma1_LE;
2420 else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
2421 iSourceFormat = EYuv422Chroma1_BE;
2425 case EYuv422Chroma2:
2426 if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedLE)
2427 iSourceFormat = EYuv422Chroma2_LE;
2428 else if( iVideoFormat.iYuvFormat.iDataLayout == EYuvDataInterleavedBE )
2429 iSourceFormat = EYuv422Chroma2_BE;
2434 err = KErrNotSupported;
2436 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceFormatL --"), this);
2441 TInt CNGAPostProcHwDevice::SetSourceRange()
2443 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL ++"), this);
2444 TInt err = KErrNone;
2445 switch (iVideoFormat.iYuvFormat.iCoefficients)
2447 case EYuvBt601Range0:
2448 iSourceRange = EITU601_5_REDUCEDRANGE;
2450 case EYuvBt601Range1:
2451 iSourceRange = EITU601_5_FULLRANGE;
2453 case EYuvBt709Range0:
2454 iSourceRange = EB709_REDUCEDRANGE;
2456 case EYuvBt709Range1:
2457 iSourceRange = EB709_FULLRANGE;
2460 err = KErrNotSupported;
2462 PP_DEBUG(_L("CNGAPostProcHwDevice[%x]:SetSourceRangeL --"), this);
2466 CNGAPostProcTimer::CNGAPostProcTimer( CNGAPostProcHwDevice& aParent )
2467 :CTimer(EPriorityHigh),iParent(aParent)
2469 CActiveScheduler::Add(this);
2472 CNGAPostProcTimer::~CNGAPostProcTimer()
2474 PP_DEBUG(_L("CNGAPostProcTimer[%x]:~CNGAPostProcTimer ++"), this);
2476 PP_DEBUG(_L("CNGAPostProcTimer[%x]:~CNGAPostProcTimer --"), this);
2479 CNGAPostProcTimer* CNGAPostProcTimer::NewL( CNGAPostProcHwDevice& aParent )
2481 CNGAPostProcTimer* self = new (ELeave)CNGAPostProcTimer(aParent);
2482 CleanupStack::PushL( self );
2484 CleanupStack::Pop( self );
2488 void CNGAPostProcTimer::ConstructL()
2490 CTimer::ConstructL();
2493 void CNGAPostProcTimer::RunL()
2495 PP_DEBUG(_L("CNGAPostProcTimer[%x]:RunL ++"), this);
2496 if (iStatus ==KErrCancel)
2498 PP_DEBUG(_L("CNGAPostProcNotifier[%x]:CNGAPostProcNotifier:RunL State canceled"), this);
2501 iParent.AttemptToPost();
2502 PP_DEBUG(_L("CNGAPostProcTimer[%x]:RunL --"), this);