1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 #include <eikenv.h> |
|
21 #include <apgcli.h> |
|
22 #include <apmrec.h> |
|
23 #include <AudioPreference.h> |
|
24 #include <utf.h> // for converting data for tts |
|
25 #include <c3dringingtoneinterface.h> |
|
26 #include <AudioOutput.h> |
|
27 |
|
28 #include "cphoneaudioplayer.h" |
|
29 #include "cphoneringingtone.h" |
|
30 #include "mphoneaudioplayerobserver.h" |
|
31 #include "phoneconstants.h" |
|
32 #include "phonelogger.h" |
|
33 #include "phoneui.pan" |
|
34 |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 |
|
39 _LIT( KFileListRngMimeType, "application/vnd.nokia.ringing-tone" ); |
|
40 //Min volume level |
|
41 const TInt KMinVolumeLevel = 1; |
|
42 //Max volume level |
|
43 const TInt KMaxVolumeLevel = 10; |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CPhoneAudioPlayer::CPhoneAudioPlayer |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CPhoneAudioPlayer::CPhoneAudioPlayer( TAudioDataFormat aDataFormat, |
|
51 MPhoneAudioPlayerObserver& aObserver, |
|
52 TInt aPriority, |
|
53 TUint aPreference, |
|
54 TInt aId ) |
|
55 : iFormat( aDataFormat ), |
|
56 iObserver( aObserver ), |
|
57 iPriority( aPriority ), |
|
58 iPreference( aPreference ), |
|
59 iId( aId ) |
|
60 { |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPhoneAudioPlayer::ConstructL |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CPhoneAudioPlayer::ConstructL( |
|
68 const TDesC& aFileName, |
|
69 CMdaServer* aMdaServer ) |
|
70 { |
|
71 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::ConstructL()" ); |
|
72 if ( iFormat == EFormatTone ) |
|
73 { |
|
74 iTonePlayer = CMdaAudioToneUtility::NewL( *this, aMdaServer ); |
|
75 iTonePlayer->PrepareToPlayFileSequence( aFileName ); |
|
76 iPlayerStatus = EToneLoading; |
|
77 } |
|
78 else |
|
79 { |
|
80 //audio sample player |
|
81 __PHONELOG3( |
|
82 EBasic, |
|
83 EPhoneControl, |
|
84 "CPhoneAudioPlayer::ConstructL - aFileName(%S), iPriority(%d), iPreference(%d)", |
|
85 &aFileName, |
|
86 iPriority, |
|
87 iPreference ); |
|
88 |
|
89 iSamplePlayer = CMdaAudioPlayerUtility::NewFilePlayerL( |
|
90 aFileName, |
|
91 *this, |
|
92 iPriority, |
|
93 static_cast< TMdaPriorityPreference >( iPreference ), |
|
94 aMdaServer ); |
|
95 iPlayerStatus = EToneLoading; |
|
96 |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CPhoneAudioPlayer::ConstructSeqL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CPhoneAudioPlayer::ConstructSeqL( |
|
105 const TDesC8& aSequence, |
|
106 CMdaServer* aMdaServer ) |
|
107 { |
|
108 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::ConstructSeqL()" ); |
|
109 iTonePlayer = CMdaAudioToneUtility::NewL( *this, aMdaServer ); |
|
110 iSequence = aSequence.AllocL(); |
|
111 iTonePlayer->PrepareToPlayDesSequence( *iSequence ); |
|
112 iPlayerStatus = EToneLoading; |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CPhoneAudioPlayer::ConstructTtsL |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CPhoneAudioPlayer::ConstructTtsL( |
|
120 const TDesC& aTtsText, |
|
121 TInt aPriority, |
|
122 TUint aPreference ) |
|
123 { |
|
124 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::ConstructTtsL()" ); |
|
125 delete iTtsPlayer; // if any |
|
126 iTtsPlayer = NULL; |
|
127 iTtsPlayer = |
|
128 CMdaAudioPlayerUtility::NewL( |
|
129 *this, aPriority, |
|
130 static_cast< TMdaPriorityPreference >( aPreference ) ); |
|
131 |
|
132 delete iTtsText; // if any |
|
133 iTtsText = NULL; |
|
134 // UTF-8 strings can take up to 4 bytes per character |
|
135 iTtsText = HBufC8::NewL( aTtsText.Length() << KTimesToMultiply ); |
|
136 |
|
137 TPtr8 refText = iTtsText->Des(); |
|
138 User::LeaveIfError( |
|
139 CnvUtfConverter::ConvertFromUnicodeToUtf8( refText, aTtsText ) ); |
|
140 |
|
141 // UTF-8 chars can be up to 4 bytes long, but usually |
|
142 // take 1-2 bytes, 3 for asian chars. |
|
143 HBufC8* oldText = iTtsText; |
|
144 iTtsText = iTtsText->ReAlloc( iTtsText->Length() ); |
|
145 if ( !iTtsText ) |
|
146 { |
|
147 // ReAlloc failed, set back to original. |
|
148 iTtsText = oldText; |
|
149 } |
|
150 |
|
151 iTtsPlayer->OpenDesL( *iTtsText ); |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CPhoneAudioPlayer::New |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 CPhoneAudioPlayer* CPhoneAudioPlayer::New( |
|
159 const CPhoneRingingTone& aRingingTone, |
|
160 TInt aPriority, |
|
161 TUint aPreference, |
|
162 MPhoneAudioPlayerObserver& aObserver, |
|
163 TInt aId, |
|
164 CMdaServer* aMdaServer, |
|
165 TBool aExtSecNeeded ) |
|
166 { |
|
167 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::New()" ); |
|
168 CPhoneAudioPlayer* self = NULL; |
|
169 TRAPD( err, self = CPhoneAudioPlayer::NewL( |
|
170 aRingingTone, |
|
171 aPriority, |
|
172 aPreference, |
|
173 aObserver, |
|
174 aId, |
|
175 aMdaServer, |
|
176 aExtSecNeeded ) ); |
|
177 if ( err != KErrNone ) |
|
178 { |
|
179 return NULL; |
|
180 } |
|
181 return self; |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CPhoneAudioPlayer::NewL |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 CPhoneAudioPlayer* CPhoneAudioPlayer::NewL( |
|
189 const CPhoneRingingTone& aRingingTone, |
|
190 TInt aPriority, |
|
191 TUint aPreference, |
|
192 MPhoneAudioPlayerObserver& aObserver, |
|
193 TInt aId, |
|
194 CMdaServer* aMdaServer, |
|
195 TBool aExtSecNeeded ) |
|
196 { |
|
197 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::NewL()" ); |
|
198 __PHONELOG1( EBasic, EPhoneControl, "CPhoneAudioPlayer::NewL - aExtSecNeeded(%d)", |
|
199 aExtSecNeeded ); |
|
200 |
|
201 // Check the file DRM property if extend secure is needed. |
|
202 if ( aExtSecNeeded ) |
|
203 { |
|
204 if ( !aRingingTone.IsFileInRom() && |
|
205 !aRingingTone.IsFileDrmProtected() ) |
|
206 { |
|
207 __PHONELOG( EBasic, EPhoneControl, "CPhoneAudioPlayer::NewL - DRM extend security check permission denied" ); |
|
208 User::Leave( KErrPermissionDenied ); |
|
209 } |
|
210 __PHONELOG( EBasic, EPhoneControl, "CPhoneAudioPlayer::NewL - DRM extend security check ok" ); |
|
211 } |
|
212 // RNG file types have to be played with CMdaAudioToneUtility player. |
|
213 // Otherwise use sample player |
|
214 TAudioDataFormat format = |
|
215 ( aRingingTone.MimeType().CompareF( KFileListRngMimeType ) == KErrNone ) |
|
216 ? EFormatTone :EFormatSample; |
|
217 |
|
218 CPhoneAudioPlayer* self = |
|
219 new (ELeave) CPhoneAudioPlayer( |
|
220 format, |
|
221 aObserver, |
|
222 aPriority, |
|
223 aPreference, |
|
224 aId ); |
|
225 |
|
226 CleanupStack::PushL( self ); |
|
227 self->ConstructL( aRingingTone.FileName(), aMdaServer ); |
|
228 CleanupStack::Pop( self ); |
|
229 |
|
230 return self; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CPhoneAudioPlayer::NewL |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 CPhoneAudioPlayer* CPhoneAudioPlayer::NewL( |
|
238 const TDesC& aFileName, |
|
239 TInt aPriority, |
|
240 TUint aPreference, |
|
241 MPhoneAudioPlayerObserver& aObserver, |
|
242 TInt aId, |
|
243 CMdaServer* aMdaServer, |
|
244 TBool aExtSecNeeded ) |
|
245 { |
|
246 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::NewL()" ); |
|
247 CPhoneRingingTone* tone = CPhoneRingingTone::NewL( aFileName ); |
|
248 CleanupStack::PushL( tone ); |
|
249 |
|
250 CPhoneAudioPlayer* player = CPhoneAudioPlayer::NewL( *tone, |
|
251 aPriority, |
|
252 aPreference, |
|
253 aObserver, |
|
254 aId, |
|
255 aMdaServer, |
|
256 aExtSecNeeded ); |
|
257 |
|
258 CleanupStack::PopAndDestroy( tone ); |
|
259 |
|
260 return player; |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CPhoneAudioPlayer::NewSeqL |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 CPhoneAudioPlayer* CPhoneAudioPlayer::NewSeqL( |
|
268 const TDesC8& aSequence, |
|
269 TInt aPriority, |
|
270 TUint aPreference, |
|
271 MPhoneAudioPlayerObserver& aObserver, |
|
272 TInt aId, |
|
273 CMdaServer* aMdaServer ) |
|
274 { |
|
275 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::NewSeqL()" ); |
|
276 CPhoneAudioPlayer* self = |
|
277 new (ELeave) CPhoneAudioPlayer( |
|
278 EFormatTone, |
|
279 aObserver, |
|
280 aPriority, |
|
281 aPreference, |
|
282 aId ); |
|
283 |
|
284 CleanupStack::PushL( self ); |
|
285 self->ConstructSeqL( aSequence, aMdaServer ); |
|
286 CleanupStack::Pop( self ); |
|
287 |
|
288 return self; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CPhoneAudioPlayer::NewTtsL |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 CPhoneAudioPlayer* CPhoneAudioPlayer::NewTtsL( |
|
296 const TDesC& aText, |
|
297 TInt aPriority, |
|
298 TUint aPreference, |
|
299 MPhoneAudioPlayerObserver& aObserver, |
|
300 TInt aId ) |
|
301 { |
|
302 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::NewTtsL()" ); |
|
303 CPhoneAudioPlayer* self = |
|
304 new (ELeave) CPhoneAudioPlayer( |
|
305 EFormatTts, |
|
306 aObserver, |
|
307 aPriority, |
|
308 aPreference, |
|
309 aId ); |
|
310 |
|
311 CleanupStack::PushL( self ); |
|
312 self->ConstructTtsL( aText, aPriority, aPreference ); |
|
313 CleanupStack::Pop( self ); |
|
314 |
|
315 return self; |
|
316 } |
|
317 |
|
318 // ----------------------------------------------------------------------------- |
|
319 // CPhoneAudioPlayer::~CPhoneAudioPlayer |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 CPhoneAudioPlayer::~CPhoneAudioPlayer() |
|
323 { |
|
324 |
|
325 if ( iAudioOutput ) |
|
326 { |
|
327 delete iAudioOutput; |
|
328 } |
|
329 if ( iTonePlayer ) |
|
330 { |
|
331 delete iTonePlayer; |
|
332 } |
|
333 if ( i3DPlugin ) |
|
334 { |
|
335 i3DPlugin->Stop(); |
|
336 delete i3DPlugin; |
|
337 } |
|
338 // ECom cleanup |
|
339 REComSession::FinalClose(); |
|
340 if ( iSamplePlayer ) |
|
341 { |
|
342 delete iSamplePlayer; |
|
343 } |
|
344 if ( iTtsPlayer ) |
|
345 { |
|
346 delete iTtsPlayer; |
|
347 } |
|
348 if ( iSequence ) |
|
349 { |
|
350 delete iSequence; |
|
351 } |
|
352 if ( iTtsText ) |
|
353 { |
|
354 delete iTtsText; |
|
355 } |
|
356 } |
|
357 |
|
358 // ----------------------------------------------------------------------------- |
|
359 // CPhoneAudioPlayer::Play |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 void CPhoneAudioPlayer::Play( TRingingType aRingType, TInt aVolume, TInt aTTsToBePlayed ) |
|
363 { |
|
364 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::Play()" ); |
|
365 __PHONELOG2( |
|
366 EBasic, |
|
367 EPhoneControl, |
|
368 "CPhoneAudioPlayer::Play - iFormat(%d), iPlayerStatus(%d)", |
|
369 iFormat, |
|
370 iPlayerStatus ); |
|
371 __PHONELOG3( |
|
372 EBasic, |
|
373 EPhoneControl, |
|
374 "CPhoneAudioPlayer::Play - aRingType(%d), aVolume(%d), aTTsToBePlayed(%d)", |
|
375 aRingType, |
|
376 aVolume, |
|
377 aTTsToBePlayed ); |
|
378 iRingType = aRingType; |
|
379 iVolume = aVolume; |
|
380 iTTsToBePlayed = aTTsToBePlayed; |
|
381 |
|
382 if ( iFormat == EFormatTone ) |
|
383 { |
|
384 switch ( iPlayerStatus ) |
|
385 { |
|
386 case ETonePlaying: |
|
387 iTonePlayer->CancelPlay(); |
|
388 DoPlay(); |
|
389 break; |
|
390 |
|
391 case EToneReady: |
|
392 iPlayerStatus = ETonePlaying; |
|
393 DoPlay(); |
|
394 break; |
|
395 |
|
396 case EToneLoading: |
|
397 iToBePlaying = ETrue; |
|
398 break; |
|
399 |
|
400 default: |
|
401 __ASSERT_DEBUG( EFalse, |
|
402 |
|
403 Panic( EPhoneViewCaseNotHandled ) ); |
|
404 } |
|
405 } |
|
406 else if ( iFormat == EFormatTts ) |
|
407 { |
|
408 switch ( iPlayerStatus ) |
|
409 { |
|
410 case ETonePlaying: |
|
411 //stop previous playing |
|
412 iTtsPlayer->Stop(); |
|
413 DoPlay(); |
|
414 break; |
|
415 |
|
416 case EToneReady: |
|
417 iPlayerStatus = ETonePlaying; |
|
418 DoPlay(); |
|
419 break; |
|
420 |
|
421 case EToneLoading: |
|
422 iToBePlaying = ETrue; |
|
423 break; |
|
424 |
|
425 default: |
|
426 __ASSERT_DEBUG( EFalse, |
|
427 Panic( EPhoneViewCaseNotHandled ) ); |
|
428 } |
|
429 } |
|
430 else |
|
431 { |
|
432 switch ( iPlayerStatus ) |
|
433 { |
|
434 case ETonePlaying: |
|
435 //stop previous playing |
|
436 StopPlaying(); |
|
437 iPlayerStatus = ETonePlaying; |
|
438 DoPlay(); |
|
439 break; |
|
440 |
|
441 case EToneReady: |
|
442 iPlayerStatus = ETonePlaying; |
|
443 DoPlay(); |
|
444 break; |
|
445 |
|
446 case EToneLoading: |
|
447 iToBePlaying = ETrue; |
|
448 break; |
|
449 |
|
450 default: |
|
451 __ASSERT_DEBUG( EFalse, |
|
452 |
|
453 Panic( EPhoneViewCaseNotHandled ) ); |
|
454 } |
|
455 } |
|
456 } |
|
457 |
|
458 // ----------------------------------------------------------------------------- |
|
459 // CPhoneAudioPlayer::ReStartPlaying |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 void CPhoneAudioPlayer::ReStartPlaying() |
|
463 { |
|
464 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::ReStartPlaying()" ); |
|
465 __PHONELOG3( |
|
466 EBasic, |
|
467 EPhoneControl, |
|
468 "CPhoneAudioPlayer::ReStartPlaying - iFormat(%d), iRingType(%d), iVolume(%d)", |
|
469 iFormat, |
|
470 iRingType, |
|
471 iVolume ); |
|
472 |
|
473 if ( iFormat == EFormatTone ) |
|
474 { |
|
475 iTonePlayer->Play(); |
|
476 iPlayerStatus = ETonePlaying; |
|
477 } |
|
478 else if ( iFormat == EFormatTts ) |
|
479 { |
|
480 iTtsPlayer->Play(); |
|
481 iPlayerStatus = ETonePlaying; |
|
482 } |
|
483 else |
|
484 { |
|
485 iSamplePlayer->Play(); |
|
486 iPlayerStatus = ETonePlaying; |
|
487 } |
|
488 } |
|
489 |
|
490 // ----------------------------------------------------------------------------- |
|
491 // CPhoneAudioPlayer::StopPlaying |
|
492 // ----------------------------------------------------------------------------- |
|
493 // |
|
494 void CPhoneAudioPlayer::StopPlaying() |
|
495 { |
|
496 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::StopPlaying()" ); |
|
497 iToBePlaying = EFalse; |
|
498 |
|
499 if ( iFormat == EFormatTone ) |
|
500 { |
|
501 if ( EMdaAudioToneUtilityPrepared == iTonePlayer->State() ) |
|
502 { |
|
503 iTonePlayer->CancelPrepare(); |
|
504 } |
|
505 else if ( EMdaAudioToneUtilityPlaying == iTonePlayer->State() ) |
|
506 { |
|
507 iTonePlayer->CancelPlay(); |
|
508 } |
|
509 } |
|
510 else if ( iFormat == EFormatTts ) |
|
511 { |
|
512 iTtsPlayer->Stop(); |
|
513 } |
|
514 else |
|
515 { |
|
516 if ( i3DPlugin ) |
|
517 { |
|
518 i3DPlugin->Stop(); |
|
519 delete i3DPlugin; |
|
520 i3DPlugin = NULL; |
|
521 } |
|
522 else |
|
523 { |
|
524 iSamplePlayer->Stop(); |
|
525 } |
|
526 } |
|
527 |
|
528 iPlayerStatus = EToneReady; |
|
529 } |
|
530 |
|
531 // ----------------------------------------------------------------------------- |
|
532 // CPhoneAudioPlayer::MapcInitComplete |
|
533 // ----------------------------------------------------------------------------- |
|
534 // |
|
535 void CPhoneAudioPlayer::MapcInitComplete( |
|
536 TInt aError, |
|
537 const TTimeIntervalMicroSeconds& /*aDuration*/ ) |
|
538 { |
|
539 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::MapcInitComplete()" ); |
|
540 __PHONELOG1( EBasic, EPhoneControl, "CPhoneAudioPlayer::MapcInitComplete - aError(%d)", |
|
541 aError ); |
|
542 __ASSERT_DEBUG( ( ( iFormat == EFormatSample ) || ( iFormat == EFormatTts ) ) && |
|
543 ( iPlayerStatus == EToneLoading ), Panic( EPhoneViewGeneralError ) ); |
|
544 if ( aError == KErrNone ) |
|
545 { |
|
546 if ( iToBePlaying ) |
|
547 { |
|
548 iPlayerStatus = ETonePlaying; |
|
549 iToBePlaying = EFalse; |
|
550 DoPlay(); |
|
551 } |
|
552 else |
|
553 { |
|
554 iPlayerStatus = EToneReady; |
|
555 } |
|
556 iObserver.HandleAudioPlayerInitComplete( iId ); |
|
557 } |
|
558 else |
|
559 { |
|
560 iObserver.HandleAudioPlayerError( |
|
561 MPhoneAudioPlayerObserver::EAudioPlayerInitializingFailure, |
|
562 aError, iId ); |
|
563 } |
|
564 } |
|
565 |
|
566 // ----------------------------------------------------------------------------- |
|
567 // CPhoneAudioPlayer::MapcPlayComplete |
|
568 // ----------------------------------------------------------------------------- |
|
569 // |
|
570 void CPhoneAudioPlayer::MapcPlayComplete( TInt aError ) |
|
571 { |
|
572 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::MapcPlayComplete()" ); |
|
573 __PHONELOG2( EBasic, EPhoneControl, "CPhoneAudioPlayer::MapcPlayComplete - iFormat(%d), aError(%d)", |
|
574 iFormat, aError ); |
|
575 iPlayerStatus = EToneReady; |
|
576 |
|
577 //Destruct 3D plugin before player itself gets destructed. |
|
578 //In case of continuous ringing type, stopplaying() handles |
|
579 //3d plugin destruction |
|
580 if ( i3DPlugin ) |
|
581 { |
|
582 i3DPlugin->Stop(); |
|
583 delete i3DPlugin; |
|
584 i3DPlugin = NULL; |
|
585 } |
|
586 |
|
587 if ( aError != KErrNone ) |
|
588 { |
|
589 iObserver.HandleAudioPlayerError( |
|
590 MPhoneAudioPlayerObserver::EAudioPlayerPlayingFailure, |
|
591 aError, iId ); |
|
592 } |
|
593 else |
|
594 { |
|
595 iObserver.HandlePlayingComplete( iId ); |
|
596 } |
|
597 } |
|
598 |
|
599 // ----------------------------------------------------------------------------- |
|
600 // CPhoneAudioPlayer::MatoPrepareComplete |
|
601 // ----------------------------------------------------------------------------- |
|
602 // |
|
603 void CPhoneAudioPlayer::MatoPrepareComplete( TInt aError ) |
|
604 { |
|
605 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::MatoPrepareComplete()" ); |
|
606 __PHONELOG1( EBasic, EPhoneControl, "CPhoneAudioPlayer::MatoPrepareComplete - aError(%d)", |
|
607 aError ); |
|
608 |
|
609 __ASSERT_DEBUG( ( iFormat == EFormatTone ) && ( iPlayerStatus == EToneLoading ), |
|
610 Panic( EPhoneViewGeneralError ) ); |
|
611 if ( aError == KErrNone ) |
|
612 { |
|
613 if ( iToBePlaying ) |
|
614 { |
|
615 iPlayerStatus = ETonePlaying; |
|
616 iToBePlaying = EFalse; |
|
617 DoPlay(); |
|
618 } |
|
619 else |
|
620 { |
|
621 iPlayerStatus = EToneReady; |
|
622 } |
|
623 iObserver.HandleAudioPlayerInitComplete( iId ); |
|
624 } |
|
625 else |
|
626 { |
|
627 iObserver.HandleAudioPlayerError( |
|
628 MPhoneAudioPlayerObserver::EAudioPlayerInitializingFailure, |
|
629 aError, iId ); |
|
630 } |
|
631 } |
|
632 |
|
633 // ----------------------------------------------------------------------------- |
|
634 // CPhoneAudioPlayer::MatoPlayComplete |
|
635 // ----------------------------------------------------------------------------- |
|
636 // |
|
637 void CPhoneAudioPlayer::MatoPlayComplete(TInt aError) |
|
638 { |
|
639 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::MatoPlayComplete()" ); |
|
640 __PHONELOG1( EBasic, EPhoneControl, "CPhoneAudioPlayer::MatoPlayComplete - aError(%d)", |
|
641 aError ); |
|
642 if ( aError != KErrNone ) |
|
643 { |
|
644 iObserver.HandleAudioPlayerError( |
|
645 MPhoneAudioPlayerObserver::EAudioPlayerPlayingFailure, |
|
646 aError, iId ); |
|
647 } |
|
648 else |
|
649 { |
|
650 iObserver.HandlePlayingComplete( iId ); |
|
651 } |
|
652 } |
|
653 |
|
654 // ----------------------------------------------------------------------------- |
|
655 // CPhoneAudioPlayer::DoPlay |
|
656 // ----------------------------------------------------------------------------- |
|
657 // |
|
658 void CPhoneAudioPlayer::DoPlay() |
|
659 { |
|
660 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::DoPlay()" ); |
|
661 __ASSERT_DEBUG( iPlayerStatus == ETonePlaying, |
|
662 Panic( EPhoneViewGeneralError ) ); |
|
663 |
|
664 SetRingingTypeProperties(); |
|
665 |
|
666 TInt err(KErrNone); |
|
667 if ( iFormat == EFormatTone ) |
|
668 { |
|
669 iTonePlayer->Play(); |
|
670 } |
|
671 else if ( iFormat == EFormatTts ) |
|
672 { |
|
673 iTtsPlayer->Play(); |
|
674 } |
|
675 else |
|
676 { |
|
677 TRAP( err,i3DPlugin = C3DRingingToneInterface::NewL( KNullUid ) ); |
|
678 if ( !err && i3DPlugin ) |
|
679 { |
|
680 i3DPlugin->SetAttr( E3DRTIAttrAudioPlayerUtility, iSamplePlayer ); |
|
681 TRAP( err,i3DPlugin->PlayL() ) |
|
682 } |
|
683 if ( err || !i3DPlugin ) |
|
684 { |
|
685 if ( !iAudioOutput ) |
|
686 { |
|
687 __PHONELOG( EBasic, EPhoneControl, "CPhoneAudioPlayer::DoPlay c aud "); |
|
688 TRAP (err, iAudioOutput = CAudioOutput::NewL( *iSamplePlayer ) ); |
|
689 if ( err ) |
|
690 { |
|
691 __PHONELOG1(EBasic, EPhoneControl, |
|
692 "P.AudPlayer.DoPlay.iAudioOutput.err ", err ); |
|
693 } |
|
694 } |
|
695 if ( !err && iAudioOutput ) |
|
696 { |
|
697 __PHONELOG( EBasic, EPhoneControl, "CPhoneAudioPlayer::DoPlay EALL "); |
|
698 TRAP (err, iAudioOutput->SetAudioOutputL( CAudioOutput::EAll ) ); |
|
699 if ( err ) |
|
700 { |
|
701 __PHONELOG1( EBasic, EPhoneControl, |
|
702 "P.AudPlayer.DoPlay.SetAudioOutputL.err ", err ); |
|
703 } |
|
704 |
|
705 } |
|
706 iSamplePlayer->Play(); |
|
707 } |
|
708 } |
|
709 } |
|
710 |
|
711 // ----------------------------------------------------------------------------- |
|
712 // CPhoneAudioPlayer::SetRingingTypeProperties |
|
713 // ----------------------------------------------------------------------------- |
|
714 // |
|
715 void CPhoneAudioPlayer::SetRingingTypeProperties() |
|
716 { |
|
717 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::SetRingingTypeProperties()" ); |
|
718 __PHONELOG2( EBasic, EPhoneControl, "CPhoneAudioPlayer::SetRingingTypeProperties - iFormat(%d), iRingType(%d)", |
|
719 iFormat, iRingType ); |
|
720 TInt rampTime( 0 ); |
|
721 if ( iFormat == EFormatTone ) |
|
722 { |
|
723 switch ( iRingType ) |
|
724 { |
|
725 case ETypeRinging: |
|
726 //If we have TTS activated and ringingtype is ringing: |
|
727 //We need to play TTS sequence again when ringingtone restarts. |
|
728 //Thats why we need to set ringingtype to ETypeRingingOnce because |
|
729 //it is the only way of knowing when ringingtone is completed. |
|
730 //Then we can restart it with new TTS iterations. |
|
731 if ( iTTsToBePlayed ) |
|
732 { |
|
733 //play only once |
|
734 iTonePlayer->SetRepeats( 0, |
|
735 TTimeIntervalMicroSeconds( |
|
736 KPhoneRingingRepeatsTrailPause ) ); |
|
737 iTonePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
738 __PHONELOG1( |
|
739 EBasic, |
|
740 EPhoneControl, |
|
741 "CPhoneAudioPlayer::SetRingingTypeProperties - Ringing tone with TTS, Set volume(%d) and ring once", |
|
742 iVolume ); |
|
743 } |
|
744 else |
|
745 { |
|
746 iTonePlayer->SetRepeats( KPhoneMdaAudioToneRepeatForever, |
|
747 TTimeIntervalMicroSeconds( |
|
748 KPhoneRingingRepeatsTrailPause ) ); |
|
749 iTonePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
750 __PHONELOG1( |
|
751 EBasic, |
|
752 EPhoneControl, |
|
753 "CPhoneAudioPlayer::SetRingingTypeProperties - Ringing tone, Set volume(%d)", |
|
754 iVolume ); |
|
755 } |
|
756 break; |
|
757 |
|
758 case ETypeRingingOnce: |
|
759 //play only once |
|
760 iTonePlayer->SetRepeats( 0, |
|
761 TTimeIntervalMicroSeconds( |
|
762 KPhoneRingingRepeatsTrailPause ) ); |
|
763 iTonePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
764 __PHONELOG1( |
|
765 EBasic, |
|
766 EPhoneControl, |
|
767 "CPhoneAudioPlayer::SetRingingTypeProperties - Ring once tone, set volume(%d)", |
|
768 iVolume ); |
|
769 break; |
|
770 |
|
771 case ETypeAscending: |
|
772 iTonePlayer->SetRepeats( KPhoneMdaAudioToneRepeatForever, |
|
773 TTimeIntervalMicroSeconds( |
|
774 KPhoneRingingRepeatsTrailPause ) ); |
|
775 |
|
776 //Special case for TTs + ascending profile. Volume |
|
777 //and ramptime needs to be different as usual |
|
778 if ( iTTsToBePlayed ) |
|
779 { |
|
780 //rampTime in this case is only 3 seconds and volume is 1. |
|
781 rampTime = KPhoneAudioAscendingRampDuration; |
|
782 __PHONELOG1( |
|
783 EBasic, |
|
784 EPhoneControl, |
|
785 "CPhoneAudioPlayer::SetRingingTypeProperties - Ascending tone with TTS, Start from lowest volume, rampTime(%d)", |
|
786 rampTime ); |
|
787 iTonePlayer->SetVolumeRamp( |
|
788 TTimeIntervalMicroSeconds( rampTime ) ); |
|
789 |
|
790 iCurrentVolume = 1; //we start from the lowest volume |
|
791 iTonePlayer->SetVolume( ConvertVolume( iCurrentVolume ) ); |
|
792 } |
|
793 else |
|
794 { |
|
795 //rampTime: time for one step * volume level |
|
796 rampTime = KPhoneAudioAscendingRampDuration*iVolume; |
|
797 __PHONELOG2( |
|
798 EBasic, |
|
799 EPhoneControl, |
|
800 "CPhoneAudioPlayer::SetRingingTypeProperties - Ascending tone, Set volume(%d), rampTime(%d)", |
|
801 iVolume, rampTime ); |
|
802 iTonePlayer->SetVolumeRamp( |
|
803 TTimeIntervalMicroSeconds( rampTime ) ); |
|
804 |
|
805 iCurrentVolume = 1; //we start from the lowest volume |
|
806 iTonePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
807 } |
|
808 break; |
|
809 |
|
810 default: |
|
811 Panic( EPhoneViewGeneralError ); |
|
812 break; |
|
813 } |
|
814 |
|
815 __PHONELOG3( |
|
816 EBasic, |
|
817 EPhoneControl, |
|
818 "CPhoneAudioPlayer::SetRingingTypeProperties - Tone, iPriority(%d), iPreference(%d), iVolume(%d)", |
|
819 iPriority, iPreference, iVolume ); |
|
820 |
|
821 //Set priority and preference |
|
822 iTonePlayer->SetPriority( iPriority, |
|
823 static_cast< TMdaPriorityPreference >( iPreference ) ); |
|
824 } |
|
825 else if ( iFormat == EFormatTts ) |
|
826 { |
|
827 switch ( iRingType ) |
|
828 { |
|
829 case ETypeRinging: |
|
830 case ETypeAscending: |
|
831 // Not possible iRingType for TTS. |
|
832 break; |
|
833 |
|
834 case ETypeRingingOnce: |
|
835 iTtsPlayer->SetRepeats( 0, // play only once |
|
836 TTimeIntervalMicroSeconds( |
|
837 KPhoneRingingRepeatsTrailPause ) ); |
|
838 iTtsPlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
839 __PHONELOG1( |
|
840 EBasic, |
|
841 EPhoneControl, |
|
842 "CPhoneAudioPlayer::SetRingingTypeProperties - TTS, Set volume(%d)", |
|
843 iVolume ); |
|
844 break; |
|
845 |
|
846 default: |
|
847 __ASSERT_DEBUG( EFalse, |
|
848 Panic( EPhoneViewCaseNotHandled ) ); |
|
849 } |
|
850 __PHONELOG( |
|
851 EBasic, |
|
852 EPhoneControl, |
|
853 "CPhoneAudioPlayer::SetRingingTypeProperties - TTS" ); |
|
854 } |
|
855 else |
|
856 { |
|
857 switch ( iRingType ) |
|
858 { |
|
859 case ETypeRinging: |
|
860 //If we have TTS activated and ringingtype is ringing: |
|
861 //We need to play TTS sequence again when ringingtone restarts. |
|
862 //Thats why we need to set ringingtype to ETypeRingingOnce because |
|
863 //it is theonly way of knowing when ringingtone is completed. |
|
864 //Then we can restartit with new TTS iterations. |
|
865 if ( iTTsToBePlayed ) |
|
866 { |
|
867 //play only once |
|
868 iSamplePlayer->SetRepeats( 0, |
|
869 TTimeIntervalMicroSeconds( |
|
870 KPhoneRingingRepeatsTrailPause ) ); |
|
871 iSamplePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
872 __PHONELOG1( |
|
873 EBasic, |
|
874 EPhoneControl, |
|
875 "CPhoneAudioPlayer::SetRingingTypeProperties - Ringing sample with TTS, Ring only once, Set volume(%d)", |
|
876 iVolume ); |
|
877 } |
|
878 else |
|
879 { |
|
880 iSamplePlayer->SetRepeats( KPhoneMdaAudioToneRepeatForever, |
|
881 TTimeIntervalMicroSeconds( |
|
882 KPhoneRingingRepeatsTrailPause ) ); |
|
883 iSamplePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
884 __PHONELOG1( |
|
885 EBasic, |
|
886 EPhoneControl, |
|
887 "CPhoneAudioPlayer::SetRingingTypeProperties - Ringing sample, Set volume(%d)", |
|
888 iVolume ); |
|
889 } |
|
890 break; |
|
891 |
|
892 case ETypeRingingOnce: |
|
893 iSamplePlayer->SetRepeats( 0,//play only once |
|
894 TTimeIntervalMicroSeconds( |
|
895 KPhoneRingingRepeatsTrailPause ) ); |
|
896 iSamplePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
897 __PHONELOG1( |
|
898 EBasic, |
|
899 EPhoneControl, |
|
900 "CPhoneAudioPlayer::SetRingingTypeProperties - Ring once sample, set volume(%d)", |
|
901 iVolume ); |
|
902 break; |
|
903 |
|
904 case ETypeAscending: |
|
905 iSamplePlayer->SetRepeats( KPhoneMdaAudioToneRepeatForever, |
|
906 TTimeIntervalMicroSeconds( |
|
907 KPhoneRingingRepeatsTrailPause ) ); |
|
908 |
|
909 //Special case for TTs + ascending profile. Volume |
|
910 //and ramptime needs to be different as usual |
|
911 if ( iTTsToBePlayed ) |
|
912 { |
|
913 //rampTime in this case is only 3 seconds and volume is 1. |
|
914 rampTime = KPhoneAudioAscendingRampDuration; |
|
915 __PHONELOG1( |
|
916 EBasic, |
|
917 EPhoneControl, |
|
918 "CPhoneAudioPlayer::SetRingingTypeProperties - Ascending sample with TTS, Start from lowest volume, rampTime(%d)", |
|
919 rampTime ); |
|
920 iSamplePlayer->SetVolumeRamp( |
|
921 TTimeIntervalMicroSeconds( rampTime ) ); |
|
922 |
|
923 iCurrentVolume = 1; //we start from the lowest volume |
|
924 iSamplePlayer->SetVolume( ConvertVolume( iCurrentVolume ) ); |
|
925 } |
|
926 else |
|
927 { |
|
928 //rampTime: time for one step * volume level |
|
929 rampTime = KPhoneAudioAscendingRampDuration*iVolume; |
|
930 __PHONELOG2( |
|
931 EBasic, |
|
932 EPhoneControl, |
|
933 "CPhoneAudioPlayer::SetRingingTypeProperties - Ascending sample, Set volume(%d), rampTime(%d)", |
|
934 iVolume, rampTime ); |
|
935 iSamplePlayer->SetVolumeRamp( |
|
936 TTimeIntervalMicroSeconds( rampTime ) ); |
|
937 |
|
938 iCurrentVolume = 1; //we start from the lowest volume |
|
939 iSamplePlayer->SetVolume( ConvertVolume( iVolume ) ); |
|
940 } |
|
941 break; |
|
942 |
|
943 default: |
|
944 Panic( EPhoneViewGeneralError ); |
|
945 break; |
|
946 } |
|
947 |
|
948 __PHONELOG( |
|
949 EBasic, |
|
950 EPhoneControl, |
|
951 "CPhoneAudioPlayer::SetRingingTypeProperties - Sample" ); |
|
952 } |
|
953 } |
|
954 |
|
955 // ----------------------------------------------------------------------------- |
|
956 // CPhoneAudioPlayer::SetNewVolumeAndRamptime |
|
957 // ----------------------------------------------------------------------------- |
|
958 // |
|
959 void CPhoneAudioPlayer::SetNewVolumeAndRamptime( TInt aVolume, TInt aRamptime ) |
|
960 { |
|
961 __LOGMETHODSTARTEND( EPhoneControl, "CPhoneAudioPlayer::SetNewVolumeAndRamptime()" ); |
|
962 |
|
963 //Check that volume is in valid range. |
|
964 TInt volume = aVolume<1 ? 1:aVolume; |
|
965 __PHONELOG1( EBasic, EPhoneControl, "CPhoneAudioPlayer::SetNewVolumeAndRamptime - aVolume(%d)", |
|
966 aVolume ); |
|
967 |
|
968 if ( iFormat == EFormatTone && iTonePlayer ) |
|
969 { |
|
970 iTonePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( aRamptime ) ); |
|
971 iTonePlayer->SetVolume( ConvertVolume( volume ) ); |
|
972 __PHONELOG( EBasic, EPhoneControl, "CPhoneAudioPlayer::SetNewVolumeAndRamptime - Tone player" ); |
|
973 } |
|
974 else if ( iFormat == EFormatTts && iTtsPlayer ) |
|
975 { |
|
976 iTtsPlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( aRamptime ) ); |
|
977 iTtsPlayer->SetVolume( ConvertVolume( volume ) ); |
|
978 __PHONELOG( EBasic, EPhoneControl, "CPhoneAudioPlayer::SetNewVolumeAndRamptime - TTS player" ); |
|
979 } |
|
980 else |
|
981 { |
|
982 iSamplePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( aRamptime ) ); |
|
983 iSamplePlayer->SetVolume( ConvertVolume( volume ) ); |
|
984 __PHONELOG( EBasic, EPhoneControl, "CPhoneAudioPlayer::SetNewVolumeAndRamptime - Sample player" ); |
|
985 } |
|
986 |
|
987 } |
|
988 |
|
989 |
|
990 // ----------------------------------------------------------------------------- |
|
991 // CPhoneAudioPlayer::ConvertVolume |
|
992 // ----------------------------------------------------------------------------- |
|
993 // |
|
994 TInt CPhoneAudioPlayer::ConvertVolume( TInt aVolume ) |
|
995 { |
|
996 //_DDPRINT( 5, "P.AudPlayer.ConvertVolume.aVolume", aVolume ); |
|
997 |
|
998 TInt result( 0 ); |
|
999 |
|
1000 if ( iFormat == EFormatTone ) |
|
1001 { |
|
1002 result = iTonePlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
1003 } |
|
1004 else if ( iFormat == EFormatTts ) |
|
1005 { |
|
1006 result = iTtsPlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
1007 } |
|
1008 else |
|
1009 { |
|
1010 result = iSamplePlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
1011 } |
|
1012 |
|
1013 // if user has selected minimum volume level |
|
1014 // set HW volume 1 |
|
1015 if ( aVolume == KMinVolumeLevel && result == 0 ) |
|
1016 { |
|
1017 result = 1; |
|
1018 } |
|
1019 |
|
1020 //_DDPRINT( 5, "P.AudPlayer.ConvertVolume.result", result ); |
|
1021 return result; |
|
1022 } |
|
1023 |
|
1024 |
|
1025 // ----------------------------------------------------------------------------- |
|
1026 // CPhoneAudioPlayer::SetTTsToBePlayed |
|
1027 // ----------------------------------------------------------------------------- |
|
1028 // |
|
1029 void CPhoneAudioPlayer::SetTTsToBePlayed( TBool aTTsToBePlayed ) |
|
1030 { |
|
1031 iTTsToBePlayed = aTTsToBePlayed; |
|
1032 } |
|
1033 |
|
1034 // ----------------------------------------------------------------------------- |
|
1035 // CPhoneAudioPlayer::MutePlaying |
|
1036 // ----------------------------------------------------------------------------- |
|
1037 // |
|
1038 void CPhoneAudioPlayer::MutePlaying() |
|
1039 { |
|
1040 //_DPRINT( 5, "P.Aud.Mute" ); |
|
1041 if ( iPlayerStatus == ETonePlaying ) |
|
1042 { |
|
1043 if ( iFormat == EFormatTone ) |
|
1044 { |
|
1045 iTonePlayer->SetVolume(0); |
|
1046 } |
|
1047 else if ( iFormat == EFormatTts ) |
|
1048 { |
|
1049 iTtsPlayer->SetVolume(0); |
|
1050 } |
|
1051 else // EFormatSample |
|
1052 { |
|
1053 iSamplePlayer->SetVolume(0); |
|
1054 } |
|
1055 } |
|
1056 else |
|
1057 { |
|
1058 // Mute called during EToneLoading state. |
|
1059 iToBePlaying = EFalse; |
|
1060 } |
|
1061 } |
|
1062 |
|
1063 // End of File |
|