sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: sl@0: #include "mdfplayerengine.h" sl@0: sl@0: #if defined (SYMBIAN_MDFPLAYERENGINE_DEBUG) sl@0: #define DEBUG_PRINT RDebug::Print sl@0: #else sl@0: #define DEBUG_PRINT sl@0: #endif // defined(SYMBIAN_MDFPLAYERENGINE_DEBUG) sl@0: sl@0: const TInt KOneSecond = 1000000; sl@0: sl@0: /* sl@0: Constructs a new instance of CMdfVideoPlayerEngine. sl@0: @return "CMdfVideoPlayerEngine*" sl@0: A pointer to the newly constructed CMdfVideoPlayerEngine sl@0: */ sl@0: CMdfVideoPlayerEngine* CMdfVideoPlayerEngine::NewL(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver) sl@0: { sl@0: CMdfVideoPlayerEngine* self = new (ELeave) CMdfVideoPlayerEngine(aDeviceObserver); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Constructs and initialises a new instance of CMdfVideoPlayerEngine. sl@0: sl@0: @param "MMdfVideoPlayerHwDeviceObserver& aDeviceObserver" sl@0: A reference to the HwDevice on which it will operate sl@0: */ sl@0: CMdfVideoPlayerEngine::CMdfVideoPlayerEngine(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver) sl@0: : iDeviceObserver(aDeviceObserver) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CMdfVideoPlayerEngine::ConstructL() sl@0: { sl@0: iTimer = CPeriodic::NewL(EPriorityHigh); sl@0: } sl@0: sl@0: /** sl@0: Default destructor sl@0: */ sl@0: CMdfVideoPlayerEngine::~CMdfVideoPlayerEngine() sl@0: { sl@0: // stop if we need to sl@0: Stop(); sl@0: } sl@0: sl@0: /** sl@0: Starts the player engine. sl@0: sl@0: @param "TUint aFrameRate" sl@0: The actual frame rate for display, or KUnsynchronized sl@0: @leave May leave with KErrNotReady if the frame rate is not initialized. sl@0: */ sl@0: void CMdfVideoPlayerEngine::StartL(TUint aFrameRate) sl@0: { sl@0: if(aFrameRate == 0) sl@0: { sl@0: User::Leave(KErrNotReady); sl@0: } sl@0: sl@0: iFrameRate = aFrameRate; sl@0: sl@0: // get current tick count, save this sl@0: iStartTime = iDeviceObserver.Time(); sl@0: iFrameCount = 0; sl@0: sl@0: DEBUG_PRINT(_L("+++ PlayerEngine: Starting")); sl@0: iTimer->Cancel(); sl@0: iTimer->Start(KMaxFrameRate, KMaxFrameRate, TCallBack(DisplayFrame, this)); sl@0: } sl@0: sl@0: /** sl@0: Stops the player engine. sl@0: */ sl@0: void CMdfVideoPlayerEngine::Stop() sl@0: { sl@0: if(iTimer) sl@0: { sl@0: DEBUG_PRINT(_L("+++ PlayerEngine: Stopping")); sl@0: iTimer->Cancel(); sl@0: delete iTimer; sl@0: iTimer = NULL; sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Returns the frame rate. sl@0: sl@0: @return The frame rate. sl@0: */ sl@0: TInt CMdfVideoPlayerEngine::FrameRate() sl@0: { sl@0: return iFrameRate; sl@0: } sl@0: sl@0: /** sl@0: Returns the frame count. sl@0: sl@0: @return The frame count. sl@0: */ sl@0: TInt CMdfVideoPlayerEngine::FrameCount() sl@0: { sl@0: return iFrameCount; sl@0: } sl@0: sl@0: /** sl@0: Static callback method for the CPeriodic timer sl@0: */ sl@0: TInt CMdfVideoPlayerEngine::DisplayFrame(TAny* aObject) sl@0: { sl@0: // cast, and call non-static function sl@0: (reinterpret_cast(aObject))->DoDisplayFrame(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Processes one frame if available. sl@0: */ sl@0: void CMdfVideoPlayerEngine::DoDisplayFrame() sl@0: { sl@0: if(iDeviceObserver.FrameAvailable()) sl@0: { sl@0: // if we're playing unsynchronized, then return the frame sl@0: // regardless of time sl@0: if(iFrameRate == KUnsynchronized) sl@0: { sl@0: iFrameCount++; sl@0: DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo")); sl@0: iDeviceObserver.DisplayFrame(); sl@0: } sl@0: else sl@0: { sl@0: TUint curPlayTime = iDeviceObserver.Time(); sl@0: sl@0: // if we've missed a tick, then discard the frame. sl@0: // (unless it's the first frame; always display this) sl@0: if(iFrameCount) sl@0: { sl@0: TUint nextNextFrameTime = iStartTime + ((iFrameCount + 1) * (KOneSecond / iFrameRate)); sl@0: if(nextNextFrameTime <= curPlayTime) sl@0: { sl@0: iFrameCount++; sl@0: DEBUG_PRINT(_L("+++ PlayerEngine: Discarding frame buffer")); sl@0: iDeviceObserver.DiscardFrame(); sl@0: return; sl@0: } sl@0: } sl@0: // else if we're past the expected display time sl@0: // then display the frame. sl@0: TUint nextFrameTime = iStartTime + (iFrameCount * (KOneSecond / iFrameRate)); sl@0: if(!iFrameCount || nextFrameTime <= curPlayTime) sl@0: { sl@0: iFrameCount++; sl@0: DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo")); sl@0: iDeviceObserver.DisplayFrame(); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: // end