|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <e32debug.h> |
|
17 |
|
18 #include "mdfplayerengine.h" |
|
19 |
|
20 #if defined (SYMBIAN_MDFPLAYERENGINE_DEBUG) |
|
21 #define DEBUG_PRINT RDebug::Print |
|
22 #else |
|
23 #define DEBUG_PRINT |
|
24 #endif // defined(SYMBIAN_MDFPLAYERENGINE_DEBUG) |
|
25 |
|
26 const TInt KOneSecond = 1000000; |
|
27 |
|
28 /* |
|
29 Constructs a new instance of CMdfVideoPlayerEngine. |
|
30 @return "CMdfVideoPlayerEngine*" |
|
31 A pointer to the newly constructed CMdfVideoPlayerEngine |
|
32 */ |
|
33 CMdfVideoPlayerEngine* CMdfVideoPlayerEngine::NewL(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver) |
|
34 { |
|
35 CMdfVideoPlayerEngine* self = new (ELeave) CMdfVideoPlayerEngine(aDeviceObserver); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop(self); |
|
39 return self; |
|
40 } |
|
41 |
|
42 |
|
43 /** |
|
44 Constructs and initialises a new instance of CMdfVideoPlayerEngine. |
|
45 |
|
46 @param "MMdfVideoPlayerHwDeviceObserver& aDeviceObserver" |
|
47 A reference to the HwDevice on which it will operate |
|
48 */ |
|
49 CMdfVideoPlayerEngine::CMdfVideoPlayerEngine(MMdfVideoPlayerHwDeviceObserver& aDeviceObserver) |
|
50 : iDeviceObserver(aDeviceObserver) |
|
51 { |
|
52 } |
|
53 |
|
54 |
|
55 void CMdfVideoPlayerEngine::ConstructL() |
|
56 { |
|
57 iTimer = CPeriodic::NewL(EPriorityHigh); |
|
58 } |
|
59 |
|
60 /** |
|
61 Default destructor |
|
62 */ |
|
63 CMdfVideoPlayerEngine::~CMdfVideoPlayerEngine() |
|
64 { |
|
65 // stop if we need to |
|
66 Stop(); |
|
67 } |
|
68 |
|
69 /** |
|
70 Starts the player engine. |
|
71 |
|
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. |
|
75 */ |
|
76 void CMdfVideoPlayerEngine::StartL(TUint aFrameRate) |
|
77 { |
|
78 if(aFrameRate == 0) |
|
79 { |
|
80 User::Leave(KErrNotReady); |
|
81 } |
|
82 |
|
83 iFrameRate = aFrameRate; |
|
84 |
|
85 // get current tick count, save this |
|
86 iStartTime = iDeviceObserver.Time(); |
|
87 iFrameCount = 0; |
|
88 |
|
89 DEBUG_PRINT(_L("+++ PlayerEngine: Starting")); |
|
90 iTimer->Cancel(); |
|
91 iTimer->Start(KMaxFrameRate, KMaxFrameRate, TCallBack(DisplayFrame, this)); |
|
92 } |
|
93 |
|
94 /** |
|
95 Stops the player engine. |
|
96 */ |
|
97 void CMdfVideoPlayerEngine::Stop() |
|
98 { |
|
99 if(iTimer) |
|
100 { |
|
101 DEBUG_PRINT(_L("+++ PlayerEngine: Stopping")); |
|
102 iTimer->Cancel(); |
|
103 delete iTimer; |
|
104 iTimer = NULL; |
|
105 } |
|
106 } |
|
107 |
|
108 /** |
|
109 Returns the frame rate. |
|
110 |
|
111 @return The frame rate. |
|
112 */ |
|
113 TInt CMdfVideoPlayerEngine::FrameRate() |
|
114 { |
|
115 return iFrameRate; |
|
116 } |
|
117 |
|
118 /** |
|
119 Returns the frame count. |
|
120 |
|
121 @return The frame count. |
|
122 */ |
|
123 TInt CMdfVideoPlayerEngine::FrameCount() |
|
124 { |
|
125 return iFrameCount; |
|
126 } |
|
127 |
|
128 /** |
|
129 Static callback method for the CPeriodic timer |
|
130 */ |
|
131 TInt CMdfVideoPlayerEngine::DisplayFrame(TAny* aObject) |
|
132 { |
|
133 // cast, and call non-static function |
|
134 (reinterpret_cast<CMdfVideoPlayerEngine*>(aObject))->DoDisplayFrame(); |
|
135 return KErrNone; |
|
136 } |
|
137 |
|
138 /** |
|
139 Processes one frame if available. |
|
140 */ |
|
141 void CMdfVideoPlayerEngine::DoDisplayFrame() |
|
142 { |
|
143 if(iDeviceObserver.FrameAvailable()) |
|
144 { |
|
145 // if we're playing unsynchronized, then return the frame |
|
146 // regardless of time |
|
147 if(iFrameRate == KUnsynchronized) |
|
148 { |
|
149 iFrameCount++; |
|
150 DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo")); |
|
151 iDeviceObserver.DisplayFrame(); |
|
152 } |
|
153 else |
|
154 { |
|
155 TUint curPlayTime = iDeviceObserver.Time(); |
|
156 |
|
157 // if we've missed a tick, then discard the frame. |
|
158 // (unless it's the first frame; always display this) |
|
159 if(iFrameCount) |
|
160 { |
|
161 TUint nextNextFrameTime = iStartTime + ((iFrameCount + 1) * (KOneSecond / iFrameRate)); |
|
162 if(nextNextFrameTime <= curPlayTime) |
|
163 { |
|
164 iFrameCount++; |
|
165 DEBUG_PRINT(_L("+++ PlayerEngine: Discarding frame buffer")); |
|
166 iDeviceObserver.DiscardFrame(); |
|
167 return; |
|
168 } |
|
169 } |
|
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) |
|
174 { |
|
175 iFrameCount++; |
|
176 DEBUG_PRINT(_L("+++ PlayerEngine: Sending frame buffer to DevVideo")); |
|
177 iDeviceObserver.DisplayFrame(); |
|
178 } |
|
179 } |
|
180 } |
|
181 } |
|
182 |
|
183 // end |