1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class is used for playing sounds |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <mmf/server/mmfdes.h> |
|
21 #include <AudioPreference.h> |
|
22 #include <logger.h> |
|
23 #include "cmmammfplayerbase.h" |
|
24 #include "cmmammfresolver.h" |
|
25 |
|
26 |
|
27 CMMAMMFPlayerBase::~CMMAMMFPlayerBase() |
|
28 { |
|
29 // First delete the control and then close the controller |
|
30 // Added after AudioOutputControl |
|
31 DeleteControls(); |
|
32 if (iControllerInfos) |
|
33 { |
|
34 iControllerInfos->ResetAndDestroy(); |
|
35 } |
|
36 delete iControllerInfos; |
|
37 |
|
38 if (iEventMonitor) |
|
39 { |
|
40 iEventMonitor->Cancel(); |
|
41 } |
|
42 |
|
43 iController.Close(); |
|
44 |
|
45 delete iEventMonitor; |
|
46 |
|
47 delete iFileName; |
|
48 } |
|
49 |
|
50 |
|
51 CMMAMMFPlayerBase::CMMAMMFPlayerBase( |
|
52 CMMAMMFResolver* aResolver) : |
|
53 iMediaTime(KTimeUnknown), iStartedEventTime(0) |
|
54 { |
|
55 // implementation array ownership is transferred |
|
56 iControllerInfos = aResolver->ImplementationsOwnership(); |
|
57 |
|
58 // content type ownership is transferred |
|
59 iContentType = aResolver->ContentTypeOwnership(); |
|
60 |
|
61 // file name ownership is transferred |
|
62 iFileName = aResolver->FileNameOwnership(); |
|
63 } |
|
64 |
|
65 |
|
66 void CMMAMMFPlayerBase::ConstructL() |
|
67 { |
|
68 CMMAPlayer::ConstructL(); |
|
69 |
|
70 // Create an event monitor |
|
71 iEventMonitor = |
|
72 CMMFControllerEventMonitor::NewL(*this, iController); |
|
73 } |
|
74 |
|
75 |
|
76 EXPORT_C RMMFController& CMMAMMFPlayerBase::Controller() |
|
77 { |
|
78 return iController; |
|
79 } |
|
80 |
|
81 EXPORT_C TInt CMMAMMFPlayerBase::DoOpen(TUid aSourceUid, |
|
82 const TDesC8& aSourceData, |
|
83 TUid aSinkUid, |
|
84 const TDesC8& aSinkData, |
|
85 TMMFPrioritySettings aPrioritySettings) |
|
86 { |
|
87 // Make sure any existing controller is closed. |
|
88 iEventMonitor->Cancel(); |
|
89 iController.Close(); |
|
90 |
|
91 // Try opening and configuring each controller in turn |
|
92 TInt error = KErrNotSupported; |
|
93 TInt index = 0; |
|
94 |
|
95 // Try controllers until found a good controller or out of list |
|
96 while ((error != KErrNone) && |
|
97 (index < iControllerInfos->Count())) |
|
98 { |
|
99 // Open the controller |
|
100 error = iController.Open((*iControllerInfos)[ index ]->Uid(), |
|
101 aPrioritySettings, ETrue); |
|
102 |
|
103 // If the controller was opened without error, start receiving events from it. |
|
104 if (!error) |
|
105 { |
|
106 iEventMonitor->Start(); |
|
107 |
|
108 // Add the data source to the controller. |
|
109 error = iController.AddDataSource(aSourceUid, aSourceData); |
|
110 } |
|
111 |
|
112 // Add the data sink |
|
113 if (!error) |
|
114 { |
|
115 error = iController.AddDataSink(aSinkUid, aSinkData); |
|
116 } |
|
117 |
|
118 // If an error occurred in any of the above, close the controller. |
|
119 if (error) |
|
120 { |
|
121 iEventMonitor->Cancel(); |
|
122 iController.Close(); |
|
123 } |
|
124 |
|
125 index++; |
|
126 } |
|
127 |
|
128 return error; |
|
129 } |
|
130 |
|
131 TBool CMMAMMFPlayerBase::IsFilePlayer() |
|
132 { |
|
133 if (iFileName != NULL) |
|
134 { |
|
135 return ETrue; |
|
136 } |
|
137 return EFalse; |
|
138 } |
|
139 |
|
140 void CMMAMMFPlayerBase::StartL() |
|
141 { |
|
142 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::StartL +"); |
|
143 iMediaTime = KTimeUnknown; |
|
144 User::LeaveIfError(iController.Play()); |
|
145 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::StartL after iController.Play() "); |
|
146 // inform java side |
|
147 ChangeState(EStarted); |
|
148 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::StartL after ChangeState "); |
|
149 PostLongEvent(CMMAPlayerEvent::EStarted, iStartedEventTime); |
|
150 PostActionCompletedStart(); |
|
151 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::StartL after PostLongEvent "); |
|
152 |
|
153 // PostActionCompleted(KErrNone); // java start return |
|
154 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::StartL after PostActionCompleted "); |
|
155 } |
|
156 |
|
157 void CMMAMMFPlayerBase::StopL(TBool aPostEvent) |
|
158 { |
|
159 if (iState == EStarted) |
|
160 { |
|
161 TInt64 time; |
|
162 GetMediaTime(&time); |
|
163 iStartedEventTime = time; |
|
164 |
|
165 TInt err = KErrNone; |
|
166 // AAC controller does not support multiple |
|
167 // calls to pause but leave with KErrNotReady. |
|
168 // That error is dismissed as player should |
|
169 // be paused already in that case. |
|
170 if (time == 0) |
|
171 { |
|
172 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::StopL: Position is zero, stopping"); |
|
173 // Normally pause would be called, but if |
|
174 // current time is zero, Stop is called instead. |
|
175 // This is done because video playback breaks |
|
176 // if pause is called between events |
|
177 // KMMFEventCategoryVideoLoadingStarted and |
|
178 // KMMFEventCategoryVideoLoadingCompleted |
|
179 // (no wurther events are delivered altough |
|
180 // playback continues fine). |
|
181 // However calling Stop is tolerated in that |
|
182 // situation. |
|
183 err = iController.Stop(); |
|
184 if (err == KErrNone) |
|
185 { |
|
186 err = iController.Prime(); |
|
187 } |
|
188 } |
|
189 else |
|
190 { |
|
191 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::StopL: Position not zero, pausing"); |
|
192 err = iController.Pause(); |
|
193 } |
|
194 |
|
195 if ((err != KErrNone) && (err != KErrNotReady)) |
|
196 { |
|
197 ELOG1( EJavaMMAPI, "CMMAMMFPlayerBase::StopL: pause/stop failed %d, leaving", err); |
|
198 User::Leave(err); |
|
199 } |
|
200 |
|
201 if (aPostEvent) |
|
202 { |
|
203 PostLongEvent(CMMAPlayerEvent::EStopped, time); |
|
204 } |
|
205 // go back to prefetched state |
|
206 ChangeState(EPrefetched); |
|
207 } |
|
208 } |
|
209 |
|
210 |
|
211 void CMMAMMFPlayerBase::DeallocateL() |
|
212 { |
|
213 if (iState == EPrefetched) |
|
214 { |
|
215 // release all resources |
|
216 if (iEventMonitor) |
|
217 { |
|
218 iEventMonitor->Cancel(); |
|
219 } |
|
220 |
|
221 // Change state first to enable AMMS to delete Effect API classes |
|
222 ChangeState(ERealized); |
|
223 iController.Stop(); |
|
224 ResetSourceStreams(); |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 EXPORT_C void CMMAMMFPlayerBase::GetDuration(TInt64* aDuration) |
|
230 { |
|
231 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetDuration "); |
|
232 if (iDuration == KTimeUnknown) |
|
233 { |
|
234 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetDuration Time unknown "); |
|
235 TTimeIntervalMicroSeconds duration; |
|
236 TInt err = iController.GetDuration(duration); |
|
237 if (!err) |
|
238 { |
|
239 iDuration = duration.Int64(); |
|
240 } |
|
241 } |
|
242 *aDuration = iDuration; |
|
243 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetDuration - "); |
|
244 } |
|
245 |
|
246 void CMMAMMFPlayerBase::SetMediaTimeL(TInt64* aTime) |
|
247 { |
|
248 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::SetMediaTimeL"); |
|
249 |
|
250 // Negative values are not checked here |
|
251 // because it's done already in Java side. |
|
252 |
|
253 // Get clip duration |
|
254 TTimeIntervalMicroSeconds duration; |
|
255 User::LeaveIfError(iController.GetDuration(duration)); |
|
256 LOG1( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::SetMediaTimeL iController.GetDuration=%d", duration.Int64()); |
|
257 |
|
258 TTimeIntervalMicroSeconds position; |
|
259 |
|
260 // If the desired media time is beyond the duration, |
|
261 // the time is set to the end of the media. |
|
262 if (*aTime > duration.Int64()) |
|
263 { |
|
264 position = duration; |
|
265 } |
|
266 else |
|
267 { |
|
268 position = *aTime; |
|
269 } |
|
270 |
|
271 TBool paused = EFalse; |
|
272 TInt err = KErrNone; |
|
273 |
|
274 if (iState == EStarted) |
|
275 { |
|
276 paused = ETrue; |
|
277 User::LeaveIfError(err = iController.Pause()); |
|
278 ELOG1( EJavaMMAPI, "CMMAMMFPlayerBase::SetMediaTimeL after iController.Pause = %d", err); |
|
279 } |
|
280 |
|
281 if (err == KErrNone) |
|
282 { |
|
283 // The controller must be in the PRIMED or PLAYING state |
|
284 User::LeaveIfError(err = iController.SetPosition(position)); |
|
285 ELOG1( EJavaMMAPI, "CMMAMMFPlayerBase::SetMediaTimeL iController.SetPosition() = %d", err); |
|
286 } |
|
287 |
|
288 // Reset cached media time, because actual set position may be |
|
289 // something else than aTime. |
|
290 iMediaTime = KTimeUnknown; |
|
291 |
|
292 // Inform about the position change to the StateListeners |
|
293 ChangeState(iState); |
|
294 |
|
295 // Get the actual media time |
|
296 GetMediaTime(aTime); |
|
297 |
|
298 iStartedEventTime = iMediaTime; |
|
299 |
|
300 if (err == KErrNone) |
|
301 { |
|
302 if (paused == (TBool)ETrue) |
|
303 { |
|
304 User::LeaveIfError(err = iController.Play()); |
|
305 ELOG1( EJavaMMAPI, "CMMAMMFPlayerBase::SetMediaTimeL iController.Play() = %d", err); |
|
306 } |
|
307 } |
|
308 |
|
309 if (err != KErrNone) |
|
310 { |
|
311 User::Leave(err); |
|
312 } |
|
313 } |
|
314 |
|
315 void CMMAMMFPlayerBase::GetMediaTime(TInt64* aMediaTime) |
|
316 { |
|
317 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetMediaTime +"); |
|
318 TTimeIntervalMicroSeconds position(0); |
|
319 |
|
320 if (iMediaTime == KTimeUnknown || iState == EStarted) |
|
321 { |
|
322 // The controller must be in the PRIMED or PLAYING state |
|
323 TInt error(iController.GetPosition(position)); |
|
324 |
|
325 if (error == KErrNone) |
|
326 { |
|
327 TInt64 newTime = position.Int64(); |
|
328 LOG1( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetMediaTime iController.GetPosition : %d", newTime); |
|
329 |
|
330 // Sanity check for media time going backwards or beyond the |
|
331 // duration. |
|
332 // Some native controls may return zero media time for |
|
333 // a few moments just before playback will complete. |
|
334 if (newTime < iMediaTime || |
|
335 (iDuration > 0 && newTime > iDuration)) |
|
336 { |
|
337 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetMediaTime.GetDuration "); |
|
338 GetDuration(&iMediaTime); |
|
339 } |
|
340 else |
|
341 { |
|
342 LOG( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetMediaTime.else "); |
|
343 // set return value |
|
344 iMediaTime = newTime; |
|
345 } |
|
346 } |
|
347 else |
|
348 { |
|
349 LOG1( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetMediaTime: error=%d, returning TIME_UNKNOWN", error); |
|
350 // cannot get media time |
|
351 iMediaTime = KTimeUnknown; |
|
352 } |
|
353 } |
|
354 *aMediaTime = iMediaTime; |
|
355 LOG1( EJavaMMAPI, EInfo, "CMMAMMFPlayerBase::GetMediaTime - %d", *aMediaTime); |
|
356 } |
|
357 |
|
358 void CMMAMMFPlayerBase::CloseL() |
|
359 { |
|
360 CMMAPlayer::CloseL(); |
|
361 if (iEventMonitor) |
|
362 { |
|
363 iEventMonitor->Cancel(); |
|
364 } |
|
365 // First delete the control and then close the controller |
|
366 // Added after AudioOutputControl |
|
367 iController.Stop(); |
|
368 delete iEventMonitor; |
|
369 iEventMonitor = NULL; |
|
370 } |
|
371 |
|
372 void CMMAMMFPlayerBase::HandleEvent(const TMMFEvent& /*aEvent*/) |
|
373 { |
|
374 // empty implementation |
|
375 } |
|
376 |
|
377 // END OF FILE |
|