1 /* |
|
2 * Copyright (c) 2010 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: Audio player implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <e32std.h> |
|
20 #include <utf.h> // For converting data for TTS |
|
21 #include "tmsshared.h" |
|
22 #include "tmsutility.h" |
|
23 #include "tmsrtaudiohdlr.h" |
|
24 #include "tmsrtcontainer.h" |
|
25 #include "tmsrtaudiohdlrobsrv.h" |
|
26 |
|
27 using namespace TMS; |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KMinVolumeLevel = 1; |
|
31 const TInt KMaxVolumeLevel = 10; |
|
32 const TInt KTMSRingingRepeatsTrailPause = 1000000; |
|
33 const TInt KTMSAudioAscendingRampDuration = 3000000; |
|
34 const TInt KTMSMdaAudioToneRepeatForever = -2; |
|
35 const TInt KUTF8Multiply = 2; |
|
36 |
|
37 _LIT(KFileListRngMimeType, "application/vnd.nokia.ringing-tone"); |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // TMSRtAudioHdlr::TMSRtAudioHdlr |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 TMSRtAudioHdlr::TMSRtAudioHdlr(TAudioDataFormat aDataFormat, |
|
44 TMSRtAudioHdlrObsrv& aObserver, TUint aPriority, TUint aPreference, |
|
45 TInt aType) : |
|
46 iFormat(aDataFormat), |
|
47 iObserver(aObserver), |
|
48 iPriority(aPriority), |
|
49 iPreference(aPreference), |
|
50 iRtType(aType) |
|
51 { |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // TMSRtAudioHdlr::ConstructL |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void TMSRtAudioHdlr::ConstructL(const TDesC& aFileName) |
|
59 { |
|
60 TRACE_PRN_FN_ENT; |
|
61 if (iFormat == EFormatTone) |
|
62 { |
|
63 iTonePlayer = CMdaAudioToneUtility::NewL(*this); |
|
64 iTonePlayer->PrepareToPlayFileSequence(aFileName); |
|
65 iPlayerStatus = EToneLoading; |
|
66 } |
|
67 else |
|
68 { |
|
69 iSamplePlayer = CMdaAudioPlayerUtility::NewFilePlayerL(aFileName, *this, |
|
70 iPriority, iPreference); |
|
71 iPlayerStatus = EToneLoading; |
|
72 } |
|
73 TRACE_PRN_FN_EXT; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // TMSRtAudioHdlr::ConstructSeqL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void TMSRtAudioHdlr::ConstructSeqL(const TDesC8& aSequence) |
|
81 { |
|
82 TRACE_PRN_FN_ENT; |
|
83 iTonePlayer = CMdaAudioToneUtility::NewL(*this); |
|
84 iSequence = aSequence.AllocL(); |
|
85 iTonePlayer->PrepareToPlayDesSequence(*iSequence); |
|
86 iPlayerStatus = EToneLoading; |
|
87 TRACE_PRN_FN_EXT; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // TMSRtAudioHdlr::ConstructTtsL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void TMSRtAudioHdlr::ConstructTtsL(const TDesC& aTtsText, TUint aPriority, |
|
95 TUint aPreference) |
|
96 { |
|
97 TRACE_PRN_FN_ENT; |
|
98 delete iTtsPlayer; |
|
99 iTtsPlayer = NULL; |
|
100 iTtsPlayer = CMdaAudioPlayerUtility::NewL(*this, aPriority, aPreference); |
|
101 |
|
102 __ASSERT_DEBUG(iTtsPlayer, PANIC(TMS_RESULT_UNINITIALIZED_OBJECT)); |
|
103 |
|
104 delete iTtsText; |
|
105 iTtsText = NULL; |
|
106 // UTF-8 strings can take up to 4 bytes per character |
|
107 iTtsText = HBufC8::NewL(aTtsText.Length() << KUTF8Multiply); |
|
108 |
|
109 __ASSERT_DEBUG(iTtsText, PANIC(TMS_RESULT_UNINITIALIZED_OBJECT)); |
|
110 |
|
111 TPtr8 refText = iTtsText->Des(); |
|
112 User::LeaveIfError(CnvUtfConverter::ConvertFromUnicodeToUtf8(refText, |
|
113 aTtsText)); |
|
114 |
|
115 // UTF-8 chars can be up to 4 bytes long, but usually |
|
116 // take 1-2 bytes, 3 for asian chars. |
|
117 HBufC8* oldText = iTtsText; |
|
118 iTtsText = iTtsText->ReAlloc(iTtsText->Length()); |
|
119 if (!iTtsText) |
|
120 { |
|
121 // ReAlloc failed, set back to original. |
|
122 iTtsText = oldText; |
|
123 } |
|
124 iTtsPlayer->OpenDesL(*iTtsText); |
|
125 TRACE_PRN_FN_EXT; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // TMSRtAudioHdlr::NewL |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TMSRtAudioHdlr* TMSRtAudioHdlr::NewL(const TMSRtContainer& aRingingTone, |
|
133 TUint aPriority, TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, |
|
134 TInt aType, TBool aExtSecNeeded) |
|
135 { |
|
136 TRACE_PRN_FN_ENT; |
|
137 // Check file DRM property if extended security is needed. |
|
138 if (aExtSecNeeded) |
|
139 { |
|
140 if (!aRingingTone.IsFileInRom() && !aRingingTone.IsFileDrmProtected()) |
|
141 { |
|
142 // DRM extended security check permission denied |
|
143 User::Leave(KErrPermissionDenied); |
|
144 } |
|
145 // DRM extended security check ok |
|
146 } |
|
147 |
|
148 // RNG file types have to be played with CMdaAudioToneUtility player. |
|
149 // Other audio formats use sample player |
|
150 TAudioDataFormat format = (aRingingTone.MimeType().CompareF( |
|
151 KFileListRngMimeType) == KErrNone) ? EFormatTone : EFormatSample; |
|
152 |
|
153 TMSRtAudioHdlr* self = new (ELeave) TMSRtAudioHdlr(format, aObserver, |
|
154 aPriority, aPreference, aType); |
|
155 CleanupStack::PushL(self); |
|
156 self->ConstructL(aRingingTone.FileName()); |
|
157 CleanupStack::Pop(self); |
|
158 TRACE_PRN_FN_EXT; |
|
159 return self; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // TMSRtAudioHdlr::NewL |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TMSRtAudioHdlr* TMSRtAudioHdlr::NewL(const TDesC& aFileName, TUint aPriority, |
|
167 TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, TInt aType, |
|
168 TBool aExtSecNeeded) |
|
169 { |
|
170 TRACE_PRN_FN_ENT; |
|
171 TMSRtContainer* tone = TMSRtContainer::NewL(aFileName); |
|
172 CleanupStack::PushL(tone); |
|
173 TMSRtAudioHdlr* player = TMSRtAudioHdlr::NewL(*tone, aPriority, aPreference, |
|
174 aObserver, aType, aExtSecNeeded); |
|
175 CleanupStack::PopAndDestroy(tone); |
|
176 TRACE_PRN_FN_EXT; |
|
177 return player; |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // TMSRtAudioHdlr::NewSeqL |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 TMSRtAudioHdlr* TMSRtAudioHdlr::NewSeqL(const TDesC8& aSequence, |
|
185 TUint aPriority, TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, |
|
186 TInt aType) |
|
187 { |
|
188 TRACE_PRN_FN_ENT; |
|
189 TMSRtAudioHdlr* self = new (ELeave) TMSRtAudioHdlr(EFormatTone, |
|
190 aObserver, aPriority, aPreference, aType); |
|
191 CleanupStack::PushL(self); |
|
192 self->ConstructSeqL(aSequence); |
|
193 CleanupStack::Pop(self); |
|
194 TRACE_PRN_FN_EXT; |
|
195 return self; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // TMSRtAudioHdlr::NewTtsL |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TMSRtAudioHdlr* TMSRtAudioHdlr::NewTtsL(const TDesC& aText, TUint aPriority, |
|
203 TUint aPreference, TMSRtAudioHdlrObsrv& aObserver, TInt aType) |
|
204 { |
|
205 TRACE_PRN_FN_ENT; |
|
206 TMSRtAudioHdlr* self = new (ELeave) TMSRtAudioHdlr(EFormatTts, aObserver, |
|
207 aPriority, aPreference, aType); |
|
208 CleanupStack::PushL(self); |
|
209 self->ConstructTtsL(aText, aPriority, aPreference); |
|
210 CleanupStack::Pop(self); |
|
211 TRACE_PRN_FN_EXT; |
|
212 return self; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // TMSRtAudioHdlr::~TMSRtAudioHdlr |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 TMSRtAudioHdlr::~TMSRtAudioHdlr() |
|
220 { |
|
221 TRACE_PRN_FN_ENT; |
|
222 /*if (i3DPlugin) |
|
223 { |
|
224 i3DPlugin->Stop(); |
|
225 } |
|
226 delete i3DPlugin; |
|
227 delete iAudioOutput;*/ |
|
228 delete iTonePlayer; |
|
229 delete iSamplePlayer; |
|
230 delete iTtsPlayer; |
|
231 delete iSequence; |
|
232 delete iTtsText; |
|
233 REComSession::FinalClose(); |
|
234 TRACE_PRN_FN_EXT; |
|
235 } |
|
236 |
|
237 // ----------------------------------------------------------------------------- |
|
238 // TMSRtAudioHdlr::Play |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 void TMSRtAudioHdlr::Play(TRingingType aRingType, TInt aVolume, |
|
242 TInt aTTsToBePlayed) |
|
243 { |
|
244 TRACE_PRN_FN_ENT; |
|
245 iRingType = aRingType; |
|
246 iVolume = aVolume; |
|
247 iTTsToBePlayed = aTTsToBePlayed; |
|
248 |
|
249 if (iFormat == EFormatTone) |
|
250 { |
|
251 switch (iPlayerStatus) |
|
252 { |
|
253 case ETonePlaying: |
|
254 if (iTonePlayer) |
|
255 { |
|
256 iTonePlayer->CancelPlay(); |
|
257 } |
|
258 DoPlay(); |
|
259 break; |
|
260 case EToneReady: |
|
261 iPlayerStatus = ETonePlaying; |
|
262 DoPlay(); |
|
263 break; |
|
264 case EToneLoading: |
|
265 iToBePlaying = ETrue; |
|
266 break; |
|
267 default: |
|
268 __ASSERT_DEBUG(EFalse, |
|
269 User::Panic(KTMSPanic, TMS_RESULT_DOES_NOT_EXIST)); |
|
270 break; |
|
271 } |
|
272 } |
|
273 else if (iFormat == EFormatTts) |
|
274 { |
|
275 switch (iPlayerStatus) |
|
276 { |
|
277 case ETonePlaying: |
|
278 if (iTtsPlayer) |
|
279 { |
|
280 iTtsPlayer->Stop(); |
|
281 } |
|
282 DoPlay(); |
|
283 break; |
|
284 case EToneReady: |
|
285 iPlayerStatus = ETonePlaying; |
|
286 DoPlay(); |
|
287 break; |
|
288 case EToneLoading: |
|
289 iToBePlaying = ETrue; |
|
290 break; |
|
291 default: |
|
292 __ASSERT_DEBUG(EFalse, |
|
293 User::Panic(KTMSPanic, TMS_RESULT_DOES_NOT_EXIST)); |
|
294 break; |
|
295 } |
|
296 } |
|
297 else |
|
298 { |
|
299 switch (iPlayerStatus) |
|
300 { |
|
301 case ETonePlaying: |
|
302 StopPlaying(); |
|
303 iPlayerStatus = ETonePlaying; |
|
304 DoPlay(); |
|
305 break; |
|
306 case EToneReady: |
|
307 iPlayerStatus = ETonePlaying; |
|
308 DoPlay(); |
|
309 break; |
|
310 case EToneLoading: |
|
311 iToBePlaying = ETrue; |
|
312 break; |
|
313 default: |
|
314 __ASSERT_DEBUG(EFalse, |
|
315 User::Panic(KTMSPanic, TMS_RESULT_DOES_NOT_EXIST)); |
|
316 break; |
|
317 } |
|
318 } |
|
319 TRACE_PRN_FN_EXT; |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // TMSRtAudioHdlr::ReStartPlaying |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 void TMSRtAudioHdlr::ReStartPlaying() |
|
327 { |
|
328 TRACE_PRN_FN_ENT; |
|
329 if (iFormat == EFormatTone && iTonePlayer) |
|
330 { |
|
331 iTonePlayer->Play(); |
|
332 iPlayerStatus = ETonePlaying; |
|
333 } |
|
334 else if (iFormat == EFormatTts && iTtsPlayer) |
|
335 { |
|
336 iTtsPlayer->Play(); |
|
337 iPlayerStatus = ETonePlaying; |
|
338 } |
|
339 else if (iFormat == EFormatSample && iSamplePlayer) |
|
340 { |
|
341 iSamplePlayer->Play(); |
|
342 iPlayerStatus = ETonePlaying; |
|
343 } |
|
344 TRACE_PRN_FN_EXT; |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // TMSRtAudioHdlr::StopPlaying |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 void TMSRtAudioHdlr::StopPlaying() |
|
352 { |
|
353 TRACE_PRN_FN_ENT; |
|
354 iToBePlaying = EFalse; |
|
355 |
|
356 if (iFormat == EFormatTone) |
|
357 { |
|
358 if (EMdaAudioToneUtilityPrepared == iTonePlayer->State()) |
|
359 { |
|
360 iTonePlayer->CancelPrepare(); |
|
361 } |
|
362 else if (EMdaAudioToneUtilityPlaying == iTonePlayer->State()) |
|
363 { |
|
364 iTonePlayer->CancelPlay(); |
|
365 } |
|
366 } |
|
367 else if (iFormat == EFormatTts) |
|
368 { |
|
369 iTtsPlayer->Stop(); |
|
370 } |
|
371 else |
|
372 { |
|
373 /* if (i3DPlugin) |
|
374 { |
|
375 i3DPlugin->Stop(); |
|
376 delete i3DPlugin; |
|
377 i3DPlugin = NULL; |
|
378 } |
|
379 else |
|
380 {*/ |
|
381 iSamplePlayer->Stop(); |
|
382 /* }*/ |
|
383 } |
|
384 iPlayerStatus = EToneReady; |
|
385 TRACE_PRN_FN_EXT; |
|
386 } |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // TMSRtAudioHdlr::MapcInitComplete |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 void TMSRtAudioHdlr::MapcInitComplete(TInt aError, |
|
393 const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
394 { |
|
395 TRACE_PRN_FN_ENT; |
|
396 TRACE_PRN_N2(_L("RT player type[%d], err[%d]"), iRtType, aError); |
|
397 |
|
398 __ASSERT_DEBUG((iFormat == EFormatSample) || |
|
399 ((iFormat == EFormatTts) && (iPlayerStatus == EToneLoading)), |
|
400 PANIC(TMS_RESULT_INVALID_STATE)); |
|
401 |
|
402 if (aError == TMS_RESULT_SUCCESS) |
|
403 { |
|
404 if (iToBePlaying) |
|
405 { |
|
406 iPlayerStatus = ETonePlaying; |
|
407 iToBePlaying = EFalse; |
|
408 DoPlay(); |
|
409 } |
|
410 else |
|
411 { |
|
412 iPlayerStatus = EToneReady; |
|
413 } |
|
414 } |
|
415 iObserver.RtAudioHdlrEvent(ECmdRingToneOpenComplete, aError, iRtType); |
|
416 TRACE_PRN_FN_EXT; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // TMSRtAudioHdlr::MapcPlayComplete |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 void TMSRtAudioHdlr::MapcPlayComplete(TInt aError) |
|
424 { |
|
425 TRACE_PRN_FN_ENT; |
|
426 TRACE_PRN_N2(_L("RT player type[%d], err[%d]"), iRtType, aError); |
|
427 |
|
428 iPlayerStatus = EToneReady; |
|
429 |
|
430 // Delete 3D plugin before RT player. In case of continuous ringing type, |
|
431 // 3D plugin is destructed in StopPlaying(). |
|
432 /* if (i3DPlugin) |
|
433 { |
|
434 i3DPlugin->Stop(); |
|
435 delete i3DPlugin; |
|
436 i3DPlugin = NULL; |
|
437 }*/ |
|
438 iObserver.RtAudioHdlrEvent(ECmdRingTonePlayComplete, aError, iRtType); |
|
439 TRACE_PRN_FN_EXT; |
|
440 } |
|
441 |
|
442 // ----------------------------------------------------------------------------- |
|
443 // TMSRtAudioHdlr::MatoPrepareComplete |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 void TMSRtAudioHdlr::MatoPrepareComplete(TInt aError) |
|
447 { |
|
448 TRACE_PRN_FN_ENT; |
|
449 TRACE_PRN_N2(_L("RT player type[%d], err[%d]"), iRtType, aError); |
|
450 |
|
451 __ASSERT_DEBUG(((iFormat == EFormatTone) && |
|
452 (iPlayerStatus == EToneLoading)), PANIC(TMS_RESULT_INVALID_STATE)); |
|
453 |
|
454 if (aError == TMS_RESULT_SUCCESS) |
|
455 { |
|
456 if (iToBePlaying) |
|
457 { |
|
458 iPlayerStatus = ETonePlaying; |
|
459 iToBePlaying = EFalse; |
|
460 DoPlay(); |
|
461 } |
|
462 else |
|
463 { |
|
464 iPlayerStatus = EToneReady; |
|
465 } |
|
466 } |
|
467 iObserver.RtAudioHdlrEvent(ECmdRingToneOpenComplete, aError, iRtType); |
|
468 TRACE_PRN_FN_ENT; |
|
469 } |
|
470 |
|
471 // ----------------------------------------------------------------------------- |
|
472 // TMSRtAudioHdlr::MatoPlayComplete |
|
473 // ----------------------------------------------------------------------------- |
|
474 // |
|
475 void TMSRtAudioHdlr::MatoPlayComplete(TInt aError) |
|
476 { |
|
477 TRACE_PRN_FN_ENT; |
|
478 TRACE_PRN_N2(_L("RT player type[%d], err[%d]"), iRtType, aError); |
|
479 iObserver.RtAudioHdlrEvent(ECmdRingTonePlayComplete, aError, iRtType); |
|
480 TRACE_PRN_FN_EXT; |
|
481 } |
|
482 |
|
483 // ----------------------------------------------------------------------------- |
|
484 // TMSRtAudioHdlr::DoPlay |
|
485 // ----------------------------------------------------------------------------- |
|
486 // |
|
487 void TMSRtAudioHdlr::DoPlay() |
|
488 { |
|
489 TRACE_PRN_FN_ENT; |
|
490 |
|
491 __ASSERT_DEBUG(iPlayerStatus == ETonePlaying, |
|
492 PANIC(TMS_RESULT_INVALID_STATE)); |
|
493 |
|
494 //TInt err(TMS_RESULT_SUCCESS); |
|
495 SetRingingTypeProperties(); |
|
496 |
|
497 if (iFormat == EFormatTone) |
|
498 { |
|
499 iTonePlayer->Play(); |
|
500 } |
|
501 else if (iFormat == EFormatTts) |
|
502 { |
|
503 iTtsPlayer->Play(); |
|
504 } |
|
505 else |
|
506 { |
|
507 #ifdef __WINSCW__ |
|
508 iSamplePlayer->Play(); |
|
509 #else |
|
510 /* |
|
511 //TODO: compare with phoneapp |
|
512 TInt err = KErrNone; |
|
513 TRAP(err, i3DPlugin = C3DRingingToneInterface::NewL(KNullUid)); |
|
514 if (!err && i3DPlugin) |
|
515 { |
|
516 i3DPlugin->SetAttr(E3DRTIAttrAudioPlayerUtility, iSamplePlayer); |
|
517 TRAP(err, i3DPlugin->PlayL()) |
|
518 } |
|
519 if (err || !i3DPlugin) |
|
520 { |
|
521 if (!iAudioOutput) |
|
522 { |
|
523 TRAP(err, iAudioOutput = CAudioOutput::NewL(*iSamplePlayer)); |
|
524 } |
|
525 if (!err && iAudioOutput) |
|
526 { |
|
527 TRAP(err, iAudioOutput->SetAudioOutputL(CAudioOutput::EAll)); |
|
528 } |
|
529 }*/ |
|
530 iSamplePlayer->Play(); |
|
531 #endif //__WINSCW__ |
|
532 } |
|
533 |
|
534 TRACE_PRN_FN_EXT; |
|
535 } |
|
536 |
|
537 // ----------------------------------------------------------------------------- |
|
538 // TMSRtAudioHdlr::SetRingingTypeProperties |
|
539 // ----------------------------------------------------------------------------- |
|
540 // |
|
541 void TMSRtAudioHdlr::SetRingingTypeProperties() |
|
542 { |
|
543 TInt rampTime(0); |
|
544 if (iFormat == EFormatTone) |
|
545 { |
|
546 __ASSERT_DEBUG(iTonePlayer, PANIC(TMS_RESULT_UNINITIALIZED_OBJECT)); |
|
547 switch (iRingType) |
|
548 { |
|
549 case ETypeRinging: |
|
550 { |
|
551 // If we have TTS activated and ringing type is "ringing", then |
|
552 // we need to play TTS sequence again when ringtone restarts. |
|
553 // That's why we need to set ringing type to ETypeRingingOnce, |
|
554 // because it is the only way of knowing when ringtone playback |
|
555 // is completed. Then we can restart it with new TTS iterations. |
|
556 if (iTTsToBePlayed) |
|
557 { |
|
558 // Play only once |
|
559 iTonePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
560 KTMSRingingRepeatsTrailPause)); |
|
561 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
562 } |
|
563 else |
|
564 { |
|
565 iTonePlayer->SetRepeats(KTMSMdaAudioToneRepeatForever, |
|
566 TTimeIntervalMicroSeconds( |
|
567 KTMSRingingRepeatsTrailPause)); |
|
568 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
569 } |
|
570 break; |
|
571 } |
|
572 case ETypeRingingOnce: |
|
573 { |
|
574 // Play only once |
|
575 iTonePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
576 KTMSRingingRepeatsTrailPause)); |
|
577 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
578 break; |
|
579 } |
|
580 case ETypeAscending: |
|
581 { |
|
582 iTonePlayer->SetRepeats(KTMSMdaAudioToneRepeatForever, |
|
583 TTimeIntervalMicroSeconds( |
|
584 KTMSRingingRepeatsTrailPause)); |
|
585 |
|
586 // Special case for TTS + ascending profile. Volume and |
|
587 // ramptime need to be different then usual |
|
588 if (iTTsToBePlayed) |
|
589 { |
|
590 // RampTime is only 3 seconds and volume is 1. |
|
591 rampTime = KTMSAudioAscendingRampDuration; |
|
592 iTonePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
593 rampTime)); |
|
594 iCurrentVolume = 1; //we start from the lowest volume |
|
595 iTonePlayer->SetVolume(ConvertVolume(iCurrentVolume)); |
|
596 } |
|
597 else |
|
598 { |
|
599 // RampTime: time for one step * volume level |
|
600 rampTime = KTMSAudioAscendingRampDuration * iVolume; |
|
601 iTonePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
602 rampTime)); |
|
603 iCurrentVolume = 1; //we start from the lowest volume |
|
604 iTonePlayer->SetVolume(ConvertVolume(iVolume)); |
|
605 } |
|
606 break; |
|
607 } |
|
608 default: |
|
609 //PANIC(TMS_RESULT_DOES_NOT_EXIST); |
|
610 break; |
|
611 } |
|
612 //Set priority and preference |
|
613 iTonePlayer->SetPriority(iPriority, iPreference); |
|
614 } |
|
615 else if (iFormat == EFormatTts) |
|
616 { |
|
617 __ASSERT_DEBUG(iTtsPlayer, PANIC(TMS_RESULT_UNINITIALIZED_OBJECT)); |
|
618 switch (iRingType) |
|
619 { |
|
620 case ETypeRinging: |
|
621 case ETypeAscending: |
|
622 { |
|
623 // Not allowed for TTS. |
|
624 break; |
|
625 } |
|
626 case ETypeRingingOnce: |
|
627 { |
|
628 iTtsPlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
629 KTMSRingingRepeatsTrailPause)); |
|
630 iTtsPlayer->SetVolume(ConvertVolume(iVolume)); |
|
631 break; |
|
632 } |
|
633 default: |
|
634 { |
|
635 __ASSERT_DEBUG(EFalse, PANIC(TMS_RESULT_DOES_NOT_EXIST)); |
|
636 break; |
|
637 } |
|
638 } |
|
639 } |
|
640 else |
|
641 { |
|
642 __ASSERT_DEBUG(iSamplePlayer, PANIC(TMS_RESULT_UNINITIALIZED_OBJECT)); |
|
643 switch (iRingType) |
|
644 { |
|
645 case ETypeRinging: |
|
646 { |
|
647 // If we have TTS activated and ringing type is "ringing", then |
|
648 // we need to play TTS sequence again when ringtone restarts. |
|
649 // That's why we need to set ringingtype to ETypeRingingOnce, |
|
650 // because it is the only way of knowing when ringtone playback |
|
651 // is completed. Then we can restart it with new TTS iterations. |
|
652 if (iTTsToBePlayed) |
|
653 { |
|
654 // Play only once |
|
655 iSamplePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
656 KTMSRingingRepeatsTrailPause)); |
|
657 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
658 } |
|
659 else |
|
660 { |
|
661 iSamplePlayer->SetRepeats( |
|
662 KTMSMdaAudioToneRepeatForever, |
|
663 TTimeIntervalMicroSeconds( |
|
664 KTMSRingingRepeatsTrailPause)); |
|
665 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
666 } |
|
667 break; |
|
668 } |
|
669 case ETypeRingingOnce: |
|
670 { |
|
671 iSamplePlayer->SetRepeats(0, TTimeIntervalMicroSeconds( |
|
672 KTMSRingingRepeatsTrailPause)); |
|
673 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
674 break; |
|
675 } |
|
676 case ETypeAscending: |
|
677 { |
|
678 iSamplePlayer->SetRepeats(KTMSMdaAudioToneRepeatForever, |
|
679 TTimeIntervalMicroSeconds( |
|
680 KTMSRingingRepeatsTrailPause)); |
|
681 |
|
682 // Special case for TTS + ascending profile. Volume and |
|
683 // ramptime need to be different then usual |
|
684 if (iTTsToBePlayed) |
|
685 { |
|
686 // RampTime is only 3 seconds and volume is 1. |
|
687 rampTime = KTMSAudioAscendingRampDuration; |
|
688 iSamplePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
689 rampTime)); |
|
690 iCurrentVolume = 1; //we start from the lowest volume |
|
691 iSamplePlayer->SetVolume(ConvertVolume(iCurrentVolume)); |
|
692 } |
|
693 else |
|
694 { |
|
695 // RampTime: time for one step * volume level |
|
696 rampTime = KTMSAudioAscendingRampDuration * iVolume; |
|
697 iSamplePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds( |
|
698 rampTime)); |
|
699 |
|
700 iCurrentVolume = 1; //we start from the lowest volume |
|
701 iSamplePlayer->SetVolume(ConvertVolume(iVolume)); |
|
702 } |
|
703 break; |
|
704 } |
|
705 default: |
|
706 { |
|
707 break; |
|
708 } |
|
709 } |
|
710 } |
|
711 } |
|
712 |
|
713 // ----------------------------------------------------------------------------- |
|
714 // TMSRtAudioHdlr::SetNewVolumeAndRamptime |
|
715 // ----------------------------------------------------------------------------- |
|
716 // |
|
717 void TMSRtAudioHdlr::SetNewVolumeAndRamptime(TInt aVolume, TInt aRamptime) |
|
718 { |
|
719 // Check that volume is in a valid range. |
|
720 TInt volume = aVolume < 1 ? 1 : aVolume; |
|
721 |
|
722 if (iFormat == EFormatTone) |
|
723 { |
|
724 if (iTonePlayer) |
|
725 { |
|
726 iTonePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(aRamptime)); |
|
727 iTonePlayer->SetVolume(ConvertVolume(volume)); |
|
728 } |
|
729 } |
|
730 else if (iFormat == EFormatTts) |
|
731 { |
|
732 if (iTtsPlayer) |
|
733 { |
|
734 iTtsPlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(aRamptime)); |
|
735 iTtsPlayer->SetVolume(ConvertVolume(volume)); |
|
736 } |
|
737 } |
|
738 else |
|
739 { |
|
740 if (iSamplePlayer) |
|
741 { |
|
742 iSamplePlayer->SetVolumeRamp(TTimeIntervalMicroSeconds(aRamptime)); |
|
743 iSamplePlayer->SetVolume(ConvertVolume(volume)); |
|
744 } |
|
745 } |
|
746 } |
|
747 |
|
748 // ----------------------------------------------------------------------------- |
|
749 // TMSRtAudioHdlr::ConvertVolume |
|
750 // ----------------------------------------------------------------------------- |
|
751 // |
|
752 TInt TMSRtAudioHdlr::ConvertVolume(TInt aVolume) |
|
753 { |
|
754 TInt result(0); |
|
755 |
|
756 if (iFormat == EFormatTone) |
|
757 { |
|
758 if (iTonePlayer) |
|
759 { |
|
760 result = iTonePlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
761 } |
|
762 } |
|
763 else if (iFormat == EFormatTts) |
|
764 { |
|
765 if (iTtsPlayer) |
|
766 { |
|
767 result = iTtsPlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
768 } |
|
769 } |
|
770 else |
|
771 { |
|
772 if (iSamplePlayer) |
|
773 { |
|
774 result = iSamplePlayer->MaxVolume() * aVolume / KMaxVolumeLevel; |
|
775 } |
|
776 } |
|
777 |
|
778 // If user selected minimum volume level set HW volume 1 |
|
779 if (aVolume == KMinVolumeLevel && result == 0) |
|
780 { |
|
781 result = 1; |
|
782 } |
|
783 return result; |
|
784 } |
|
785 |
|
786 // ----------------------------------------------------------------------------- |
|
787 // TMSRtAudioHdlr::SetTTsToBePlayed |
|
788 // ----------------------------------------------------------------------------- |
|
789 // |
|
790 void TMSRtAudioHdlr::SetTTsToBePlayed(const TBool aTTsToBePlayed) |
|
791 { |
|
792 iTTsToBePlayed = aTTsToBePlayed; |
|
793 } |
|
794 |
|
795 // ----------------------------------------------------------------------------- |
|
796 // TMSRtAudioHdlr::MutePlaying |
|
797 // ----------------------------------------------------------------------------- |
|
798 // |
|
799 void TMSRtAudioHdlr::MutePlaying() |
|
800 { |
|
801 if (iPlayerStatus == ETonePlaying) |
|
802 { |
|
803 if (iFormat == EFormatTone) |
|
804 { |
|
805 if (iTonePlayer) |
|
806 { |
|
807 iTonePlayer->SetVolume(0); |
|
808 } |
|
809 } |
|
810 else if (iFormat == EFormatTts && iTtsPlayer) |
|
811 { |
|
812 if (iTtsPlayer) |
|
813 { |
|
814 iTtsPlayer->SetVolume(0); |
|
815 } |
|
816 } |
|
817 else // EFormatSample |
|
818 { |
|
819 if (iSamplePlayer) |
|
820 { |
|
821 iSamplePlayer->SetVolume(0); |
|
822 } |
|
823 } |
|
824 } |
|
825 else |
|
826 { |
|
827 // Mute during EToneLoading state. |
|
828 iToBePlaying = EFalse; |
|
829 } |
|
830 } |
|
831 |
|