|
1 /* |
|
2 * Copyright (c) 2005 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: Base class definition of the S60 Audio Stream Player |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "S60AudioPlayer.h" |
|
20 #include "S60AudioSource.h" |
|
21 #include "S60PlayerEventDispatcher.h" |
|
22 |
|
23 CS60AudioPlayer::~CS60AudioPlayer() |
|
24 { |
|
25 #ifdef _DEBUG |
|
26 RDebug::Print(_L("CS60AudioPlayer::~CS60AudioPlayer")); |
|
27 #endif |
|
28 |
|
29 delete iRepeatTrailingSilenceTimer; |
|
30 if (iFindAndOpenController) |
|
31 iFindAndOpenController->Close(); |
|
32 delete iFindAndOpenController; |
|
33 delete iControllerEventMonitor; |
|
34 delete iDispatcher; |
|
35 iController.Close(); |
|
36 |
|
37 } |
|
38 |
|
39 CS60AudioPlayer::CS60AudioPlayer( |
|
40 MS60AudioPlayerObserver& aObserver, |
|
41 TInt aPriority, |
|
42 TMdaPriorityPreference aPref ) : |
|
43 iObserver(aObserver), |
|
44 iSource(NULL), |
|
45 iAudioPlayDeviceCommands(iController) |
|
46 { |
|
47 iPrioritySettings.iPriority = aPriority; |
|
48 iPrioritySettings.iPref = aPref; |
|
49 } |
|
50 |
|
51 EXPORT_C CS60AudioPlayer* CS60AudioPlayer::NewL( |
|
52 MS60AudioPlayerObserver& aObserver, |
|
53 TInt aPriority, |
|
54 TMdaPriorityPreference aPref ) |
|
55 { |
|
56 |
|
57 #ifdef _DEBUG |
|
58 RDebug::Print(_L("CS60AudioPlayer::NewL")); |
|
59 #endif |
|
60 |
|
61 CS60AudioPlayer* self = new(ELeave) CS60AudioPlayer(aObserver, aPriority, aPref); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 return self; |
|
66 } |
|
67 |
|
68 void CS60AudioPlayer::ConstructL() |
|
69 { |
|
70 |
|
71 #ifdef _DEBUG |
|
72 RDebug::Print(_L("CS60AudioPlayer::ConstructL")); |
|
73 #endif |
|
74 iDispatcher = CPlayerEventDispatcher::NewL(iObserver); |
|
75 iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iController); |
|
76 RDebug::Print(_L("CS60AudioPlayer::ConstructL [%x]"),iControllerEventMonitor); |
|
77 iFindAndOpenController = CMMFFindAndOpenController::NewL(*this); |
|
78 RDebug::Print(_L("CS60AudioPlayer::ConstructL [%x]"),iFindAndOpenController); |
|
79 iRepeatTrailingSilenceTimer = CRepeatTrailingSilenceTimer::NewL(*this); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CS60AudioPlayer::AddDataSource |
|
84 // Adds the DataSource |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CS60AudioPlayer::AddDataSource( |
|
88 CS60AudioBaseSource& aDataSource ) |
|
89 { |
|
90 |
|
91 #ifdef _DEBUG |
|
92 RDebug::Print(_L("CS60AudioPlayer::AddDataSource")); |
|
93 #endif |
|
94 |
|
95 iSource = &aDataSource; |
|
96 |
|
97 iFindAndOpenController->Configure(KUidMediaTypeAudio, iPrioritySettings); |
|
98 iFindAndOpenController->ConfigureController(iController, *iControllerEventMonitor, |
|
99 CMMFFindAndOpenController::EPlayback); |
|
100 iFindAndOpenController->ConfigureSourceSink(CMMFFindAndOpenController::TSourceSink(TUid::Uid(0x10207AF3)), |
|
101 CMMFFindAndOpenController::TSourceSink(KUidMmfAudioOutput)); |
|
102 |
|
103 TBuf8<20> mimeType; |
|
104 iSource->GetMimeType(mimeType); |
|
105 iFindAndOpenController->OpenByMimeType(mimeType); |
|
106 } |
|
107 |
|
108 /** |
|
109 Begins playback of the initialised audio sample at the current volume |
|
110 and priority levels. |
|
111 |
|
112 When playing of the audio sample is complete, successfully or |
|
113 otherwise, the callback function |
|
114 MMdaAudioPlayerCallback::MapcPlayComplete() is |
|
115 called. This function raises a CMdaAudioPlayerUtility 1 panic if the |
|
116 audio player utility is not initialised. |
|
117 */ |
|
118 EXPORT_C TInt CS60AudioPlayer::Play() |
|
119 { |
|
120 TInt err = KErrNone; |
|
121 if(iState == EPlayerPlaying) |
|
122 { |
|
123 |
|
124 err = KErrNotReady; |
|
125 |
|
126 } |
|
127 else |
|
128 |
|
129 { |
|
130 |
|
131 err = DoPlay(); |
|
132 } |
|
133 return err; |
|
134 } |
|
135 |
|
136 TInt CS60AudioPlayer::DoPlay() |
|
137 { |
|
138 |
|
139 TInt err = KErrNone; |
|
140 if (iState != EPlayerPaused) |
|
141 { |
|
142 if (err==KErrNone) |
|
143 err = iController.SetPosition(iPosition); |
|
144 } |
|
145 |
|
146 if (err==KErrNone) |
|
147 { |
|
148 err = iController.Play(); |
|
149 |
|
150 if(!err) |
|
151 { |
|
152 iState = EPlayerPlaying; |
|
153 iDispatcher->StateChanged(iState, KErrNone); |
|
154 } |
|
155 |
|
156 } |
|
157 return err; |
|
158 } |
|
159 |
|
160 /** |
|
161 Stops playback of the audio sample as soon as possible. |
|
162 |
|
163 If the audio sample is playing, playback is stopped as soon as |
|
164 possible. If playback is already complete, nothing further happens as |
|
165 a result of calling this function. The callback function |
|
166 MMdaAudioPlayerCallback::MapcPlayComplete() is not |
|
167 called. The function raises a CMdaAudioPlayerUtility 1 panic if the |
|
168 audio player utility is not initialised. |
|
169 |
|
170 */ |
|
171 EXPORT_C TInt CS60AudioPlayer::Stop() |
|
172 { |
|
173 TInt err = KErrNone; |
|
174 |
|
175 // cancel the repeat timer in case the client has called Stop() |
|
176 // during the trailing silence period |
|
177 //iRepeatTrailingSilenceTimer->Cancel(); |
|
178 |
|
179 err = iController.Stop(); |
|
180 |
|
181 //tpoon |
|
182 iPosition = 0; |
|
183 |
|
184 TPlayerState iOldState = iState; |
|
185 iState = EPlayerStopped; |
|
186 |
|
187 if (iOldState==EPlayerPlaying || iOldState==EPlayerPaused) |
|
188 iDispatcher->StateChanged(iState, KErrNone); |
|
189 |
|
190 iController.Prime(); |
|
191 return err; |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CS60AudioPlayer::Pause |
|
196 // Pauses the Audio Playback |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 |
|
200 EXPORT_C TInt CS60AudioPlayer::Pause() |
|
201 { |
|
202 TInt err = KErrNone; |
|
203 if (iState==EPlayerPlaying) |
|
204 { |
|
205 // cancel the repeat timer in case the client has called Stop() |
|
206 // during the trailing silence period |
|
207 //iRepeatTrailingSilenceTimer->Cancel(); |
|
208 |
|
209 err = iController.Pause(); |
|
210 iState = EPlayerPaused; |
|
211 iDispatcher->StateChanged(iState, KErrNone); |
|
212 } |
|
213 return err; |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CS60AudioPlayer::SetPriority |
|
218 // Sets the Priority of the the Audio |
|
219 // returns One of the Standard Error Codes |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C TInt CS60AudioPlayer::SetPriority(TInt aPriority, TMdaPriorityPreference aPref) |
|
223 { |
|
224 iPrioritySettings.iPref = aPref; |
|
225 iPrioritySettings.iPriority = aPriority; |
|
226 iFindAndOpenController->Configure(KUidMediaTypeAudio, iPrioritySettings); |
|
227 return iController.SetPrioritySettings(iPrioritySettings); |
|
228 } |
|
229 |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CS60AudioPlayer::FastForward |
|
233 // FastForwards the Current the the Audio by aStep |
|
234 // returns One of the Standard Error Codes |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 EXPORT_C TInt CS60AudioPlayer::FastForward(TTimeIntervalMicroSeconds& /*aStep*/) |
|
238 { |
|
239 return KErrNotSupported; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CS60AudioPlayer::Rewind |
|
244 // Rewinds the Current the the Audio by aStep |
|
245 // returns One of the Standard Error Codes |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 EXPORT_C TInt CS60AudioPlayer::Rewind(TTimeIntervalMicroSeconds& /*aStep*/) |
|
249 { |
|
250 return KErrNotSupported; |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CS60AudioPlayer::GetMaxVolume |
|
255 // Gets the maximum volume supported |
|
256 // returns One of the Standard Error Codes |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 EXPORT_C TInt CS60AudioPlayer::GetMaxVolume() |
|
260 { |
|
261 TInt maxVolume = 0; |
|
262 #ifdef _DEBUG |
|
263 TInt error = |
|
264 #endif |
|
265 iAudioPlayDeviceCommands.GetMaxVolume(maxVolume); |
|
266 return maxVolume; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CS60AudioPlayer::SetVolume |
|
271 // Sets the volume with aVolume |
|
272 // returns One of the Standard Error Codes |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C TInt CS60AudioPlayer::SetVolume(TInt aVolume) |
|
276 { |
|
277 TInt err = iAudioPlayDeviceCommands.SetVolume(aVolume); |
|
278 return err; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CS60AudioPlayer::GetVolume |
|
283 // Gets the current volume |
|
284 // returns One of the Standard Error Codes |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 EXPORT_C TInt CS60AudioPlayer::GetVolume(TInt& aVolume) |
|
288 { |
|
289 TInt error = iAudioPlayDeviceCommands.GetVolume(aVolume); |
|
290 return error; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CS60AudioPlayer::GetDuration |
|
295 // Gets the current duration |
|
296 // returns Duration in Microseconds |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 EXPORT_C TTimeIntervalMicroSeconds CS60AudioPlayer::GetDuration() |
|
300 { |
|
301 TTimeIntervalMicroSeconds duration = 0; |
|
302 return duration; |
|
303 } |
|
304 |
|
305 // ----------------------------------------------------------------------------- |
|
306 // CS60AudioPlayer::GetBitRate |
|
307 // Gets the Bitrate |
|
308 // returns bitrate |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 EXPORT_C TUint CS60AudioPlayer::GetBitRate() |
|
312 { |
|
313 TUint bitRate; |
|
314 RMMFAudioControllerCustomCommands controller(iController); |
|
315 TInt err = controller.GetSourceBitRate(bitRate); |
|
316 return bitRate; |
|
317 } |
|
318 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // CS60AudioPlayer::GetPosition |
|
321 // Gets the current Position |
|
322 // returns position in Microseconds |
|
323 // ----------------------------------------------------------------------------- |
|
324 // |
|
325 EXPORT_C TTimeIntervalMicroSeconds CS60AudioPlayer::GetPosition() |
|
326 { |
|
327 // if (iState==EPlayerPlaying) |
|
328 iController.GetPosition(iPosition); |
|
329 return iPosition; |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CS60AudioPlayer::SetPosition |
|
334 // Sets the current Position |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 EXPORT_C void CS60AudioPlayer::SetPosition(TTimeIntervalMicroSeconds& aPosition) |
|
338 { |
|
339 const TTimeIntervalMicroSeconds maxPosition(GetDuration()); |
|
340 const TTimeIntervalMicroSeconds minPosition(0); |
|
341 |
|
342 if (aPosition > maxPosition) |
|
343 iPosition = maxPosition; |
|
344 else if (aPosition < minPosition) |
|
345 iPosition = minPosition; |
|
346 else |
|
347 iPosition = aPosition; |
|
348 |
|
349 if (iState==EPlayerPlaying || iState==EPlayerPaused) |
|
350 { |
|
351 iController.SetPosition(iPosition); |
|
352 } |
|
353 |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CS60AudioPlayer::SetPlayWindow |
|
358 // Sets the current Playwindow Position |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C void CS60AudioPlayer::SetPlayWindow(TTimeIntervalMicroSeconds& /*aStart*/, TTimeIntervalMicroSeconds& /*aEnd*/) |
|
362 { |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CS60AudioPlayer::GetPlayWindow |
|
367 // Gets the current Playwindow Position |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 EXPORT_C void CS60AudioPlayer::GetPlayWindow(TTimeIntervalMicroSeconds& /*aStart*/, TTimeIntervalMicroSeconds& /*aEnd*/) |
|
371 { |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CS60AudioPlayer::ResetPlayWindow |
|
376 // Resets the Playwindow |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 EXPORT_C TInt CS60AudioPlayer::ResetPlayWindow() |
|
380 { |
|
381 return KErrNotSupported; |
|
382 } |
|
383 |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CS60AudioPlayer::SetRepeats |
|
386 // Sets the number of times the Audio should be played |
|
387 // ----------------------------------------------------------------------------- |
|
388 // |
|
389 EXPORT_C void CS60AudioPlayer::SetRepeats(TInt /*aNumber*/, const TTimeIntervalMicroSeconds& /*aTrailingSilence*/) |
|
390 { |
|
391 } |
|
392 |
|
393 // ----------------------------------------------------------------------------- |
|
394 // CS60AudioPlayer::GetBalance |
|
395 // Gets the current Balance |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 EXPORT_C TInt CS60AudioPlayer::GetBalance() |
|
399 { |
|
400 TInt balance; |
|
401 TInt err = iAudioPlayDeviceCommands.GetBalance(balance); |
|
402 return balance; |
|
403 } |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // CS60AudioPlayer::SetBalance |
|
407 // Sets the current Balance |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 EXPORT_C TInt CS60AudioPlayer::SetBalance(TInt& aBalance) |
|
411 { |
|
412 TInt err = iAudioPlayDeviceCommands.SetBalance(aBalance); |
|
413 return err; |
|
414 } |
|
415 |
|
416 // ----------------------------------------------------------------------------- |
|
417 // CS60AudioPlayer::IsSeekingSupported |
|
418 // Gets the current Seeking Support |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 EXPORT_C TBool CS60AudioPlayer::IsSeekingSupported() |
|
422 { |
|
423 return EFalse; |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // CS60AudioPlayer::IsRandomSeekingSupported |
|
428 // Gets the current RandomSeeking Support |
|
429 // ----------------------------------------------------------------------------- |
|
430 // |
|
431 EXPORT_C TBool CS60AudioPlayer::IsRandomSeekingSupported() |
|
432 { |
|
433 return EFalse; |
|
434 } |
|
435 |
|
436 // ----------------------------------------------------------------------------- |
|
437 // CS60AudioPlayer::CustomInterface |
|
438 // Gets the CustomInterface |
|
439 // ----------------------------------------------------------------------------- |
|
440 |
|
441 EXPORT_C TAny* CS60AudioPlayer::CustomInterface(TUid /*aInterfaceId*/) |
|
442 { |
|
443 TAny* result = NULL; |
|
444 return result; |
|
445 } |
|
446 |
|
447 /**************************************************************************************************** |
|
448 MRepeatTrailingSilenceTimerObs implementation |
|
449 ****************************************************************************************************/ |
|
450 void CS60AudioPlayer::RepeatTrailingSilenceTimerComplete() |
|
451 { |
|
452 } |
|
453 |
|
454 /**************************************************************************************************** |
|
455 MMMFFindAndOpenControllerObserver implementation |
|
456 ****************************************************************************************************/ |
|
457 |
|
458 void CS60AudioPlayer::MfaocComplete( |
|
459 TInt& aError, |
|
460 RMMFController* aController, |
|
461 TUid aControllerUid, |
|
462 TMMFMessageDestination* aSourceHandle, |
|
463 TMMFMessageDestination* /*aSinkHandle*/) |
|
464 { |
|
465 |
|
466 #ifdef _DEBUG |
|
467 RDebug::Print(_L("CS60AudioPlayer::MfaocComplete")); |
|
468 #endif |
|
469 |
|
470 if (aError == KErrNone) |
|
471 { |
|
472 iSource->iSourceHandle = *aSourceHandle; |
|
473 iSource->iControllerUid = aControllerUid; |
|
474 iSource->iController = *aController; |
|
475 } |
|
476 iDispatcher->AddSourceComplete(aError); |
|
477 iController.Prime(); |
|
478 } |
|
479 |
|
480 /**************************************************************************************************** |
|
481 MMMFControllerEventMonitorObserver implementation |
|
482 ****************************************************************************************************/ |
|
483 |
|
484 void CS60AudioPlayer::HandleEvent(const TMMFEvent& aEvent) |
|
485 { |
|
486 |
|
487 #ifdef _DEBUG |
|
488 RDebug::Print(_L("CS60AudioPlayer::HandleEvent")); |
|
489 #endif |
|
490 |
|
491 // handle loading started/complete messages first, as the later code does not explicitly check the event type |
|
492 |
|
493 if (aEvent.iEventType == KMMFEventCategoryPlaybackComplete) |
|
494 { |
|
495 //we've repeated enough times now |
|
496 iState = EPlayerStopped; |
|
497 iPosition = 0; |
|
498 iDispatcher->StateChanged(iState, aEvent.iErrorCode); |
|
499 iController.Prime(); |
|
500 } |
|
501 // else we have an unexpected event that cannot be dealt with by the client. |
|
502 // We will simply ignore this. |
|
503 } |
|
504 |
|
505 |
|
506 /**************************************************************************************************/ |
|
507 |
|
508 CRepeatTrailingSilenceTimer* CRepeatTrailingSilenceTimer::NewL(MRepeatTrailingSilenceTimerObs& aObs) |
|
509 { |
|
510 CRepeatTrailingSilenceTimer* s = new(ELeave) CRepeatTrailingSilenceTimer(aObs); |
|
511 CleanupStack::PushL(s); |
|
512 s->ConstructL(); |
|
513 CleanupStack::Pop(s); |
|
514 return s; |
|
515 } |
|
516 |
|
517 void CRepeatTrailingSilenceTimer::RunL() |
|
518 { |
|
519 iObs.RepeatTrailingSilenceTimerComplete(); |
|
520 } |
|
521 |
|
522 CRepeatTrailingSilenceTimer::CRepeatTrailingSilenceTimer(MRepeatTrailingSilenceTimerObs& aObs) : |
|
523 CTimer(EPriorityHigh), |
|
524 iObs(aObs) |
|
525 { |
|
526 CActiveScheduler::Add(this); |
|
527 } |
|
528 |