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 * The source file for tone previewing. |
|
16 * |
|
17 */ |
|
18 #include "tonepreviewprivate.h" |
|
19 #include "tonefetcherutils.h" |
|
20 #include <AudioPreference.h> // KAudioPriorityPreview |
|
21 #include <c3dringingtoneinterface.h> // C3DRingingToneInterface |
|
22 #include <ctsydomainpskeys.h> // for phone call states |
|
23 #include <MProfileEngine.h> |
|
24 #include <MProfile.h> |
|
25 #include <MProfileTones.h> |
|
26 #include "TProfileToneSettings.h" |
|
27 #include <MProfileExtraSettings.h> |
|
28 #include <MProfile3DToneSettings.h> |
|
29 #include <ProfileInternal.hrh> |
|
30 #include <ProfileEngineDomainCRKeys.h> // KProEngDefaultRingingTone |
|
31 #include <XQConversions> |
|
32 #include <QChar> |
|
33 |
|
34 CMFPreviewHandlerBase::CMFPreviewHandlerBase( QObject *parent ) : QObject( parent ) |
|
35 { |
|
36 iMediaType = KErrNotFound; |
|
37 iRingingVolume = KErrNotFound; |
|
38 iRingingType = KErrNotFound; |
|
39 iVibra = KErrNotFound; |
|
40 i3DEffect = KErrNotFound; |
|
41 i3DEcho = KErrNotFound; |
|
42 iFileSize = KErrNotFound; |
|
43 iFullName = 0; |
|
44 iActiveProfileRead = EFalse; |
|
45 iPlayerStatus = EPlayerNotCreated; |
|
46 |
|
47 } |
|
48 |
|
49 void CMFPreviewHandlerBase::ConstructL() |
|
50 { |
|
51 // To allow/not allow screensaver |
|
52 // Errors ignored, no actions needed if API is not available |
|
53 //iProperty.Attach( KPSUidScreenSaver, KScreenSaverAllowScreenSaver ); |
|
54 TRAP_IGNORE(User::LeaveIfError( iApaSession.Connect() ) ); |
|
55 |
|
56 TRAP_IGNORE( ReadDefaultToneL() ); |
|
57 // To keep backlight on while a video is being previewed |
|
58 iBacklightTimer = CPeriodic::NewL( EPriorityLow ); |
|
59 } |
|
60 |
|
61 CMFPreviewHandlerBase::~CMFPreviewHandlerBase() |
|
62 { |
|
63 delete iFullName; |
|
64 iProperty.Close(); |
|
65 |
|
66 iApaSession.Close(); |
|
67 } |
|
68 |
|
69 void CMFPreviewHandlerBase::SetAttr(const QString &file ) |
|
70 { |
|
71 if ( !file.isNull() ) |
|
72 { |
|
73 QString path = ToneFetcherUtils::normalizeSeperator(file); |
|
74 delete iFullName; |
|
75 iFullName = 0; |
|
76 iFullName = XQConversions::qStringToS60Desc( path ); |
|
77 } |
|
78 } |
|
79 |
|
80 TInt CMFPreviewHandlerBase::RingingVolume() |
|
81 { |
|
82 const TInt KDefaultVolumeLevel = 7; // see profile.hrh for volume levels |
|
83 |
|
84 if ( iRingingVolume != KErrNotFound ) |
|
85 { |
|
86 return iRingingVolume; |
|
87 } |
|
88 |
|
89 if ( iActiveProfileRead ) |
|
90 { |
|
91 return iActiveProfileRingingVolume; |
|
92 } |
|
93 |
|
94 return KDefaultVolumeLevel; |
|
95 } |
|
96 |
|
97 TInt CMFPreviewHandlerBase::RingingType() |
|
98 { |
|
99 if ( iRingingType != KErrNotFound ) |
|
100 { |
|
101 return iRingingType; |
|
102 } |
|
103 |
|
104 if ( iActiveProfileRead ) |
|
105 { |
|
106 return iActiveProfileRingingType; |
|
107 } |
|
108 |
|
109 return ERingingTypeRinging; |
|
110 } |
|
111 |
|
112 TInt CMFPreviewHandlerBase::Vibra() |
|
113 { |
|
114 if ( iVibra != KErrNotFound ) |
|
115 { |
|
116 return iVibra; |
|
117 } |
|
118 |
|
119 if ( iActiveProfileRead ) |
|
120 { |
|
121 return iActiveProfileVibra; |
|
122 } |
|
123 |
|
124 return 0; // in case of error vibra is off |
|
125 } |
|
126 |
|
127 TInt CMFPreviewHandlerBase::Echo3D() |
|
128 { |
|
129 if ( i3DEcho != KErrNotFound ) |
|
130 { |
|
131 return i3DEcho; |
|
132 } |
|
133 |
|
134 if ( iActiveProfileRead ) |
|
135 { |
|
136 return iActiveProfile3DEcho; |
|
137 } |
|
138 |
|
139 return EProfile3DEchoOff; // from ProfileInternal.hrh |
|
140 } |
|
141 |
|
142 TInt CMFPreviewHandlerBase::Effect3D() |
|
143 { |
|
144 if ( i3DEffect != KErrNotFound ) |
|
145 { |
|
146 return i3DEffect; |
|
147 } |
|
148 |
|
149 if ( iActiveProfileRead ) |
|
150 { |
|
151 return iActiveProfile3DEffect; |
|
152 } |
|
153 |
|
154 return EProfile3DEffectOff; |
|
155 } |
|
156 |
|
157 TInt CMFPreviewHandlerBase::ConvertVolume( TInt aVolume, TInt aMaxVolume ) |
|
158 { |
|
159 const TInt KMinVolumeLevel = 1; |
|
160 const TInt KMaxVolumeLevel = 10; |
|
161 |
|
162 TInt result = aMaxVolume * aVolume / KMaxVolumeLevel; |
|
163 |
|
164 // if user has selected minimum volume level set HW volume 1 |
|
165 if ( aVolume == KMinVolumeLevel && result == 0 ) |
|
166 { |
|
167 result = 1; |
|
168 } |
|
169 |
|
170 return result; |
|
171 } |
|
172 |
|
173 void CMFPreviewHandlerBase::ReadActiveProfileL() |
|
174 { |
|
175 iActiveProfileRead = EFalse; |
|
176 |
|
177 MProfileEngine* profileEngine = CreateProfileEngineL(); |
|
178 CleanupReleasePushL( *profileEngine ); |
|
179 |
|
180 MProfile* activeProfile = profileEngine->ActiveProfileL(); |
|
181 CleanupReleasePushL( *activeProfile ); |
|
182 |
|
183 const MProfileTones& profileTones = activeProfile->ProfileTones(); |
|
184 |
|
185 const TProfileToneSettings& toneSettings = profileTones.ToneSettings(); |
|
186 iActiveProfileVibra = toneSettings.iVibratingAlert; |
|
187 iActiveProfileRingingVolume = toneSettings.iRingingVolume; |
|
188 iActiveProfileRingingType = toneSettings.iRingingType; |
|
189 |
|
190 const MProfileExtraSettings& extra = activeProfile->ProfileExtraSettings(); |
|
191 const MProfile3DToneSettings& threeD = extra.Profile3DToneSettings(); |
|
192 |
|
193 iActiveProfile3DEffect = threeD.Effect(); |
|
194 iActiveProfile3DEcho = threeD.Echo(); |
|
195 |
|
196 CleanupStack::PopAndDestroy( activeProfile ); |
|
197 CleanupStack::PopAndDestroy( profileEngine ); |
|
198 |
|
199 iActiveProfileRead = ETrue; |
|
200 } |
|
201 |
|
202 void CMFPreviewHandlerBase::ReadDefaultToneL() |
|
203 { |
|
204 CRepository* cenrep = CRepository::NewLC( KCRUidProfileEngine ); |
|
205 |
|
206 User::LeaveIfError( cenrep->Get( KProEngDefaultRingingTone, iDefaultTone ) ); |
|
207 CleanupStack::PopAndDestroy( cenrep ); |
|
208 } |
|
209 |
|
210 TInt CMFPreviewHandlerBase::GetDataType( const TDesC& aFileName, TDataType& aDataType ) |
|
211 { |
|
212 TUid dummyUid( KNullUid ); |
|
213 return iApaSession.AppForDocument( aFileName, dummyUid, aDataType ); |
|
214 } |
|
215 |
|
216 TInt CMFPreviewHandlerBase::DoResetInactivityTimer( TAny* /*aObject*/ ) |
|
217 { |
|
218 User::ResetInactivityTime(); |
|
219 return KErrNone; |
|
220 } |
|
221 |
|
222 void CMFPreviewHandlerBase::DisableBackLight() |
|
223 { |
|
224 const TInt KResetInactivityTimerDelay = 2000000; |
|
225 iBacklightTimer->Cancel(); // Just in case |
|
226 // Disable backlight turn off during video preview |
|
227 iBacklightTimer->Start( KResetInactivityTimerDelay, |
|
228 KResetInactivityTimerDelay, |
|
229 TCallBack( DoResetInactivityTimer, 0 ) ); |
|
230 |
|
231 } |
|
232 |
|
233 |
|
234 |
|
235 TonePreviewPrivate::TonePreviewPrivate( QObject *parent ) : CMFPreviewHandlerBase( parent ) |
|
236 { |
|
237 iAudioPlayerStatus = EPlayerNotCreated; |
|
238 CMFPreviewHandlerBase::ConstructL(); |
|
239 iTonePlayerStatus = EPlayerNotCreated; |
|
240 } |
|
241 |
|
242 TonePreviewPrivate::~TonePreviewPrivate() |
|
243 { |
|
244 Cancel(); |
|
245 |
|
246 delete iAudioPlayer; |
|
247 delete iTonePlayer; |
|
248 delete i3dRingingTonePlugin; |
|
249 } |
|
250 |
|
251 TBool TonePreviewPrivate::IsPlaying() |
|
252 { |
|
253 if ( iAudioPlayerStatus != EPlayerNotCreated ) |
|
254 { |
|
255 return ETrue; |
|
256 } |
|
257 |
|
258 if ( iTonePlayerStatus != EPlayerNotCreated ) |
|
259 { |
|
260 return ETrue; |
|
261 } |
|
262 |
|
263 return EFalse; |
|
264 } |
|
265 |
|
266 void TonePreviewPrivate::Play() |
|
267 { |
|
268 if( IsPlaying() ) |
|
269 { |
|
270 Stop(); |
|
271 return; |
|
272 } |
|
273 //sequence for playing a beep once sound |
|
274 _LIT8( KFileListBeepSequence, "\x00\x11\x06\x0A\x08\x73\x0A\x40\x28\x0A\xF7\ |
|
275 \x05\xFC\x40\x64\x0A\x08\x40\x32\x0A\xF7\x06\x0B" ); |
|
276 |
|
277 // rng mime type |
|
278 _LIT( KFileListRngMimeType, "application/vnd.nokia.ringing-tone" ); |
|
279 |
|
280 Cancel(); // stop previous play |
|
281 |
|
282 if ( !iFullName || iFullName->Des().Length() == 0 ) |
|
283 { |
|
284 User::Leave( KErrNotFound ); |
|
285 } |
|
286 |
|
287 TRAP_IGNORE( ReadActiveProfileL() ); |
|
288 |
|
289 TPtrC fileName( iFullName->Des() ); |
|
290 TDataType dataType; |
|
291 TInt err = GetDataType( fileName, dataType ); |
|
292 if ( err == KErrNotFound ) |
|
293 { |
|
294 fileName.Set( iDefaultTone ); |
|
295 if ( fileName.Length() == 0 ) |
|
296 { |
|
297 User::Leave( KErrNotFound ); |
|
298 } |
|
299 } |
|
300 else if ( err != KErrNone ) |
|
301 { |
|
302 User::Leave( err ); |
|
303 } |
|
304 |
|
305 TBool mimeTypeRng = EFalse; |
|
306 |
|
307 if ( err == KErrNone ) |
|
308 { |
|
309 if( dataType.Des().CompareF( KFileListRngMimeType ) == 0 ) |
|
310 { |
|
311 mimeTypeRng = ETrue; |
|
312 } |
|
313 } |
|
314 |
|
315 TInt ringingType = RingingType(); |
|
316 if ( ringingType == ERingingTypeBeepOnce ) |
|
317 { |
|
318 // Active profile ringing tone is set to Beep Once |
|
319 // Don't initialize a FileSequence but use DesSequence instead |
|
320 iTonePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
321 iTonePlayer->PrepareToPlayDesSequence( KFileListBeepSequence() ); |
|
322 iTonePlayerStatus = EPlayerInitializing; |
|
323 } |
|
324 else |
|
325 { |
|
326 if( mimeTypeRng ) |
|
327 { |
|
328 //Ringingtone is a RNG-file |
|
329 iTonePlayer = CMdaAudioToneUtility::NewL( *this ); |
|
330 iTonePlayer->PrepareToPlayFileSequence( fileName ); |
|
331 iTonePlayerStatus = EPlayerInitializing; |
|
332 } |
|
333 else |
|
334 { |
|
335 delete iAudioPlayer; |
|
336 iAudioPlayer = 0; |
|
337 |
|
338 iAudioPlayer = CDrmPlayerUtility::NewFilePlayerL( |
|
339 fileName, *this, KAudioPriorityRingingTonePreview, |
|
340 ( TMdaPriorityPreference )KAudioPrefRingFilePreview ); |
|
341 |
|
342 iAudioPlayerStatus = EPlayerInitializing; |
|
343 } |
|
344 } |
|
345 DisableBackLight(); |
|
346 } |
|
347 |
|
348 void TonePreviewPrivate::Stop() |
|
349 { |
|
350 Cancel(); |
|
351 } |
|
352 |
|
353 TInt TonePreviewPrivate::ConvertVolume( TInt aVolume ) |
|
354 { |
|
355 TInt result = 0; |
|
356 if ( iAudioPlayer ) |
|
357 { |
|
358 result = CMFPreviewHandlerBase::ConvertVolume( aVolume, iAudioPlayer->MaxVolume() ); |
|
359 } |
|
360 else if ( iTonePlayer ) |
|
361 { |
|
362 result = CMFPreviewHandlerBase::ConvertVolume( aVolume, iTonePlayer->MaxVolume() ); |
|
363 } |
|
364 |
|
365 //if user has selected silent ringing type, set volume off |
|
366 TInt ringingType = RingingType(); |
|
367 if( ringingType == ERingingTypeSilent ) |
|
368 { |
|
369 result = 0; |
|
370 } |
|
371 |
|
372 return result; |
|
373 } |
|
374 |
|
375 void TonePreviewPrivate::SetToneRingingType( TInt aRingingType ) |
|
376 { |
|
377 const TInt KToneInterval = 1000000; // 1 second pause between tones |
|
378 const TInt KAscendingVolumeInterval = 3000000; // 3 seconds |
|
379 |
|
380 if ( !iTonePlayer ) |
|
381 { |
|
382 return; |
|
383 } |
|
384 |
|
385 |
|
386 TInt ringingVolume = RingingVolume(); |
|
387 |
|
388 switch( aRingingType ) |
|
389 { |
|
390 case ERingingTypeRinging: |
|
391 case ERingingTypeSilent: |
|
392 { |
|
393 iTonePlayer->SetRepeats( KMdaAudioToneRepeatForever, |
|
394 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
395 break; |
|
396 } |
|
397 case ERingingTypeAscending: |
|
398 { |
|
399 iTonePlayer->SetRepeats( KMdaAudioToneRepeatForever, |
|
400 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
401 |
|
402 TInt volRamp = KAscendingVolumeInterval * ringingVolume; |
|
403 iTonePlayer->SetVolumeRamp( TTimeIntervalMicroSeconds( volRamp ) ); |
|
404 break; |
|
405 } |
|
406 case ERingingTypeRingOnce: |
|
407 case ERingingTypeBeepOnce: |
|
408 { |
|
409 iTonePlayer->SetRepeats( 0, TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
410 break; |
|
411 } |
|
412 default: |
|
413 { |
|
414 break; |
|
415 } |
|
416 } |
|
417 } |
|
418 |
|
419 void TonePreviewPrivate::SetAudioRingingType( TInt aRingingType ) |
|
420 { |
|
421 const TInt KToneInterval = 1000000; // 1 second pause between tones |
|
422 const TInt KAscendingVolumeInterval = 3000000; // 3 seconds |
|
423 |
|
424 if ( !iAudioPlayer ) |
|
425 { |
|
426 return; |
|
427 } |
|
428 |
|
429 TInt ringingVolume = RingingVolume(); |
|
430 |
|
431 switch( aRingingType ) |
|
432 { |
|
433 case ERingingTypeRinging: |
|
434 case ERingingTypeSilent: |
|
435 { |
|
436 iAudioPlayer->SetRepeats( KMdaAudioToneRepeatForever, |
|
437 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
438 break; |
|
439 } |
|
440 case ERingingTypeAscending: |
|
441 { |
|
442 iAudioPlayer->SetRepeats( KMdaAudioToneRepeatForever, |
|
443 TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
444 TInt volRamp = KAscendingVolumeInterval * ringingVolume; |
|
445 iAudioPlayer->SetVolumeRamp( TTimeIntervalMicroSeconds( volRamp ) ); |
|
446 break; |
|
447 } |
|
448 case ERingingTypeRingOnce: |
|
449 { |
|
450 iAudioPlayer->SetRepeats( 0, TTimeIntervalMicroSeconds( KToneInterval ) ); |
|
451 break; |
|
452 } |
|
453 |
|
454 default: |
|
455 { |
|
456 break; |
|
457 } |
|
458 } |
|
459 } |
|
460 |
|
461 void TonePreviewPrivate::Cancel() |
|
462 { |
|
463 TBool isPlaying = EFalse; |
|
464 |
|
465 if ( iAudioPlayer ) |
|
466 { |
|
467 isPlaying = ETrue; |
|
468 if ( iAudioPlayerStatus == EPlayerPlayingWith3DEffect ) |
|
469 { |
|
470 i3dRingingTonePlugin->Stop(); |
|
471 // plugin calls AudioPlayer->Stop() |
|
472 iAudioPlayer->Close(); |
|
473 } |
|
474 if ( iAudioPlayerStatus == EPlayerPlaying ) |
|
475 { |
|
476 iAudioPlayer->Stop(); |
|
477 iAudioPlayer->Close(); |
|
478 } |
|
479 |
|
480 delete iAudioPlayer; |
|
481 iAudioPlayer = 0; |
|
482 iAudioPlayerStatus = EPlayerNotCreated; |
|
483 } |
|
484 |
|
485 if ( iTonePlayer ) |
|
486 { |
|
487 isPlaying = ETrue; |
|
488 if ( iTonePlayerStatus == EPlayerPlaying ) |
|
489 { |
|
490 iTonePlayer->CancelPlay(); |
|
491 } |
|
492 |
|
493 delete iTonePlayer; |
|
494 iTonePlayer = 0; |
|
495 iTonePlayerStatus = EPlayerNotCreated; |
|
496 } |
|
497 |
|
498 |
|
499 if ( isPlaying ) |
|
500 { |
|
501 //User::InfoPrint(_L("cancel")); |
|
502 // EnableScreenSaver( ETrue ); |
|
503 iBacklightTimer->Cancel(); |
|
504 } |
|
505 } |
|
506 |
|
507 void TonePreviewPrivate::MatoPlayComplete( TInt aError ) |
|
508 { |
|
509 Cancel(); |
|
510 emit notifyPreviewEvent( ToneFetcherEngine::EAudioPreviewComplete, aError ); |
|
511 } |
|
512 |
|
513 void TonePreviewPrivate::MatoPrepareComplete( TInt aError ) |
|
514 { |
|
515 if ( aError != KErrNone ) |
|
516 { |
|
517 Cancel(); |
|
518 |
|
519 emit notifyPreviewEvent( ToneFetcherEngine::EPreviewError, aError ); |
|
520 return; |
|
521 } |
|
522 |
|
523 TInt ringingVolume = RingingVolume(); |
|
524 TInt ringingType = RingingType(); |
|
525 TInt vibra = Vibra(); |
|
526 |
|
527 iTonePlayerStatus = EPlayerInitialized; |
|
528 SetToneRingingType( ringingType ); |
|
529 iTonePlayer->SetVolume( ConvertVolume( ringingVolume ) ); |
|
530 |
|
531 TMdaPriorityPreference pref = (TMdaPriorityPreference) KAudioPrefRingFilePreview; |
|
532 if ( vibra ) |
|
533 { |
|
534 pref = (TMdaPriorityPreference) KAudioPrefRingFilePreviewVibra; |
|
535 } |
|
536 iTonePlayer->SetPriority( KAudioPriorityPreview, pref ); |
|
537 |
|
538 iTonePlayer->Play(); |
|
539 iTonePlayerStatus = EPlayerPlaying; |
|
540 } |
|
541 |
|
542 void TonePreviewPrivate::MdapcInitComplete( TInt aError, |
|
543 const TTimeIntervalMicroSeconds& /* aDuration */ ) |
|
544 { |
|
545 if ( aError != KErrNone ) |
|
546 { |
|
547 Cancel(); |
|
548 emit notifyPreviewEvent( ToneFetcherEngine::EPreviewError, aError ); |
|
549 return; |
|
550 } |
|
551 |
|
552 |
|
553 TInt ringingVolume = RingingVolume(); |
|
554 TInt ringingType = RingingType(); |
|
555 TInt vibra = Vibra(); |
|
556 TInt echo3D = Echo3D(); |
|
557 TInt effect3D = Effect3D(); |
|
558 |
|
559 |
|
560 |
|
561 iAudioPlayerStatus = EPlayerInitialized; |
|
562 SetAudioRingingType( ringingType ); |
|
563 iAudioPlayer->SetVolume( ConvertVolume( ringingVolume ) ); |
|
564 |
|
565 TMdaPriorityPreference pref = (TMdaPriorityPreference) KAudioPrefRingFilePreview; |
|
566 if ( vibra ) |
|
567 { |
|
568 pref = (TMdaPriorityPreference) KAudioPrefRingFilePreviewVibra; |
|
569 } |
|
570 iAudioPlayer->SetPriority( KAudioPriorityPreview, pref ); |
|
571 |
|
572 iAudioPlayerStatus = EPlayerPlaying; |
|
573 |
|
574 if ( effect3D == EProfile3DEffectOff ) |
|
575 { |
|
576 iAudioPlayer->Play(); // 3D not used |
|
577 return; |
|
578 } |
|
579 |
|
580 if ( !i3dRingingTonePlugin ) |
|
581 { |
|
582 TUid emptyUid = { 0 }; |
|
583 TRAPD( err, i3dRingingTonePlugin = C3DRingingToneInterface::NewL( emptyUid ) ); |
|
584 if ( err != KErrNone || !i3dRingingTonePlugin ) |
|
585 { |
|
586 iAudioPlayer->Play(); |
|
587 return; |
|
588 } |
|
589 } |
|
590 |
|
591 i3dRingingTonePlugin->SetAttr( E3DRTIAttr3DEffect, effect3D ); |
|
592 i3dRingingTonePlugin->SetAttr( E3DRTIAttr3DEcho, echo3D ); |
|
593 i3dRingingTonePlugin->SetAttr( E3DRTIAttrDrmPlayerUtility, iAudioPlayer ); |
|
594 TRAP_IGNORE( i3dRingingTonePlugin->PlayL() ); |
|
595 |
|
596 iAudioPlayerStatus = EPlayerPlayingWith3DEffect; |
|
597 } |
|
598 |
|
599 void TonePreviewPrivate::MdapcPlayComplete( TInt aError ) |
|
600 { |
|
601 Cancel(); |
|
602 emit notifyPreviewEvent( ToneFetcherEngine::EAudioPreviewComplete, aError ); |
|
603 } |
|