First public contribution.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "mdfplayerengine.h"
20 #if defined (SYMBIAN_MDFPLAYERENGINE_DEBUG)
21 #define DEBUG_PRINT RDebug::Print
24 #endif // defined(SYMBIAN_MDFPLAYERENGINE_DEBUG)
26 const TInt KOneSecond = 1000000;
29 Constructs a new instance of CMdfVideoPlayerEngine.
30 @return "CMdfVideoPlayerEngine*"
31 A pointer to the newly constructed CMdfVideoPlayerEngine
33 CMdfVideoPlayerEngine* CMdfVideoPlayerEngine::NewL(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver)
35 CMdfVideoPlayerEngine* self = new (ELeave) CMdfVideoPlayerEngine(aDeviceObserver);
36 CleanupStack::PushL(self);
38 CleanupStack::Pop(self);
44 Constructs and initialises a new instance of CMdfVideoPlayerEngine.
46 @param "MMdfVideoPlayerHwDeviceObserver& aDeviceObserver"
47 A reference to the HwDevice on which it will operate
49 CMdfVideoPlayerEngine::CMdfVideoPlayerEngine(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver)
50 : iDeviceObserver(aDeviceObserver)
55 void CMdfVideoPlayerEngine::ConstructL()
57 iTimer = CPeriodic::NewL(EPriorityHigh);
63 CMdfVideoPlayerEngine::~CMdfVideoPlayerEngine()
70 Starts the player engine.
72 @param "TUint aFrameRate"
73 The actual frame rate for display, or KUnsynchronized
74 @leave May leave with KErrNotReady if the frame rate is not initialized.
76 void CMdfVideoPlayerEngine::StartL(TUint aFrameRate)
80 User::Leave(KErrNotReady);
83 iFrameRate = aFrameRate;
85 // get current tick count, save this
86 iStartTime = iDeviceObserver.Time();
89 DEBUG_PRINT(_L("+++ PlayerEngine: Starting"));
91 iTimer->Start(KMaxFrameRate, KMaxFrameRate, TCallBack(DisplayFrame, this));
95 Stops the player engine.
97 void CMdfVideoPlayerEngine::Stop()
101 DEBUG_PRINT(_L("+++ PlayerEngine: Stopping"));
109 Returns the frame rate.
111 @return The frame rate.
113 TInt CMdfVideoPlayerEngine::FrameRate()
119 Returns the frame count.
121 @return The frame count.
123 TInt CMdfVideoPlayerEngine::FrameCount()
129 Static callback method for the CPeriodic timer
131 TInt CMdfVideoPlayerEngine::DisplayFrame(TAny* aObject)
133 // cast, and call non-static function
134 (reinterpret_cast<CMdfVideoPlayerEngine*>(aObject))->DoDisplayFrame();
139 Processes one frame if available.
141 void CMdfVideoPlayerEngine::DoDisplayFrame()
143 if(iDeviceObserver.FrameAvailable())
145 // if we're playing unsynchronized, then return the frame
146 // regardless of time
147 if(iFrameRate == KUnsynchronized)
150 DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo"));
151 iDeviceObserver.DisplayFrame();
155 TUint curPlayTime = iDeviceObserver.Time();
157 // if we've missed a tick, then discard the frame.
158 // (unless it's the first frame; always display this)
161 TUint nextNextFrameTime = iStartTime + ((iFrameCount + 1) * (KOneSecond / iFrameRate));
162 if(nextNextFrameTime <= curPlayTime)
165 DEBUG_PRINT(_L("+++ PlayerEngine: Discarding frame buffer"));
166 iDeviceObserver.DiscardFrame();
170 // else if we're past the expected display time
171 // then display the frame.
172 TUint nextFrameTime = iStartTime + (iFrameCount * (KOneSecond / iFrameRate));
173 if(!iFrameCount || nextFrameTime <= curPlayTime)
176 DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo"));
177 iDeviceObserver.DisplayFrame();