|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Handles the playing of sounds and tones for the Camera App* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <AknSoundSystem.h> //CAknKeySoundSystem |
|
21 |
|
22 #include <cameraapp.rsg> |
|
23 #include <vgacamsettings.rsg> |
|
24 |
|
25 #include <avkon.rsg> |
|
26 #include <StringLoader.h> |
|
27 #include <AudioPreference.h> |
|
28 #include <AknAppUi.h> |
|
29 |
|
30 #include "CamSoundPlayer.h" |
|
31 #include "Cam.hrh" |
|
32 #include "camutility.h" |
|
33 |
|
34 // EXTERNAL DATA STRUCTURES |
|
35 |
|
36 // EXTERNAL FUNCTION PROTOTYPES |
|
37 |
|
38 // CONSTANTS |
|
39 #if 0 // Old constants that may be used again in the future |
|
40 const TInt KCamInCallToneHz = 1760; |
|
41 const TInt KCamInCallToneLen= 450000; |
|
42 _LIT( KCamSelfTimerSoundFile , "z:\\system\\sounds\\simple\\cameraappSelfTimer.rng" ); |
|
43 #endif |
|
44 |
|
45 const TReal32 KCamInCallToneVol = 0.75f; |
|
46 |
|
47 _LIT( KCamAutoFocusComplete, "z:\\system\\sounds\\digital\\cameraappFocusSucc.wav" ); |
|
48 //_LIT( KCamAutoFocusFailed, "c:\\system\\sounds\\digital\\focus2.wav" ); NOT DEFINED YET |
|
49 |
|
50 |
|
51 // ============================= LOCAL FUNCTIONS =============================== |
|
52 |
|
53 // ============================ MEMBER FUNCTIONS =============================== |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CCamSoundPlayer::CCamSoundPlayer |
|
57 // C++ default constructor can NOT contain any code, that |
|
58 // might leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 CCamSoundPlayer::CCamSoundPlayer( MCamSoundPlayerObserver* aObs ) |
|
62 { |
|
63 iObserver = aObs; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CCamSoundPlayer::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CCamSoundPlayer::ConstructL() |
|
72 { |
|
73 iAudioPlayer = CMdaAudioPlayerUtility::NewL( *this, |
|
74 KAudioPriorityCameraTone, |
|
75 TMdaPriorityPreference( KAudioPrefCamera ) ); |
|
76 |
|
77 iTonePlayer = CMdaAudioToneUtility::NewL( *this, |
|
78 NULL, |
|
79 KAudioPriorityVideoRecording, |
|
80 TMdaPriorityPreference( KAudioPrefCamera ) ); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CCamSoundPlayer::NewL |
|
85 // Two-phased constructor. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 CCamSoundPlayer* CCamSoundPlayer::NewL( MCamSoundPlayerObserver* aObs ) |
|
89 { |
|
90 CCamSoundPlayer* self = new( ELeave ) CCamSoundPlayer( aObs ); |
|
91 |
|
92 CleanupStack::PushL( self ); |
|
93 self->ConstructL(); |
|
94 CleanupStack::Pop(); |
|
95 |
|
96 return self; |
|
97 } |
|
98 |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CCamSoundPlayer::~CCamSoundPlayer |
|
102 // Destructor |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CCamSoundPlayer::~CCamSoundPlayer() |
|
106 { |
|
107 PRINT( _L("Camera => ~CCamSoundPlayer") ); |
|
108 if ( iAudioPlayer ) |
|
109 { |
|
110 iAudioPlayer->Close(); |
|
111 delete iAudioPlayer; |
|
112 } |
|
113 |
|
114 CancelTonePlayer(); |
|
115 delete iTonePlayer; |
|
116 PRINT( _L("Camera <= ~CCamSoundPlayer") ); |
|
117 } |
|
118 |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CCamSoundPlayer::InitialiseL |
|
122 // Initialize sound player. |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CCamSoundPlayer::InitialiseL() |
|
126 { |
|
127 if ( iInitialised ) |
|
128 { |
|
129 return; |
|
130 } |
|
131 |
|
132 iKeySoundSystem = static_cast<CAknAppUi*>( CEikonEnv::Static()->AppUi() )->KeySounds(); |
|
133 |
|
134 if ( !iKeySoundSystem ) |
|
135 { |
|
136 return; |
|
137 } |
|
138 |
|
139 TRAPD( error, iKeySoundSystem->AddAppSoundInfoListL( R_CAM_SOUND_LIST ) ); |
|
140 |
|
141 if ( error && error != KErrAlreadyExists ) |
|
142 { |
|
143 User::Leave( error ); |
|
144 } |
|
145 |
|
146 iInitialised = ETrue; |
|
147 } |
|
148 |
|
149 |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CCamSoundPlayer::PlaySound |
|
153 // Plays the requested sound |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CCamSoundPlayer::PlaySound( TCamSoundId aSoundId, |
|
157 TBool aEnableCallback ) |
|
158 { |
|
159 PRINT( _L("Camera => CCamSoundPlayer::PlaySound") ); |
|
160 |
|
161 // Get into a known state before we begin |
|
162 switch( aSoundId ) |
|
163 { |
|
164 case ECamVideoStartSoundId: |
|
165 { |
|
166 StartPlaySound( KCamVideoStartTone(), aEnableCallback ); |
|
167 break; |
|
168 } |
|
169 |
|
170 case ECamVideoStopSoundId: |
|
171 { |
|
172 StartPlaySound( KCamVideoStopTone(), aEnableCallback ); |
|
173 break; |
|
174 } |
|
175 |
|
176 case ECamVideoPauseSoundId: |
|
177 { |
|
178 StartPlaySound( KCamVideoPauseTone(), aEnableCallback ); |
|
179 break; |
|
180 } |
|
181 |
|
182 case ECamVideoResumeSoundId: |
|
183 { |
|
184 StartPlaySound( KCamVideoStartTone(), aEnableCallback ); |
|
185 break; |
|
186 } |
|
187 |
|
188 case ECamAutoFocusFailed: |
|
189 { |
|
190 PRINT( _L("Camera <> PlaySound - ECamAutoFocusFailed") ); |
|
191 // Do nothing as no failed WAV sound has been specified |
|
192 break; |
|
193 } |
|
194 |
|
195 case ECamAutoFocusComplete: |
|
196 { |
|
197 PRINT( _L("Camera <> PlaySound - ECamAutoFocusComplete") ); |
|
198 StartPlaySound( KCamAutoFocusComplete(), aEnableCallback ); |
|
199 break; |
|
200 } |
|
201 |
|
202 case ECamStillCaptureSoundId1: |
|
203 { |
|
204 StartPlaySound( KCamCaptureTone1(), aEnableCallback ); |
|
205 break; |
|
206 } |
|
207 |
|
208 case ECamStillCaptureSoundId2: |
|
209 { |
|
210 StartPlaySound( KCamCaptureTone2(), aEnableCallback ); |
|
211 break; |
|
212 } |
|
213 |
|
214 case ECamStillCaptureSoundId3: |
|
215 { |
|
216 StartPlaySound( KCamCaptureTone3(), aEnableCallback ); |
|
217 break; |
|
218 } |
|
219 |
|
220 case ECamStillCaptureSoundId4: |
|
221 { |
|
222 StartPlaySound( KCamCaptureTone4(), aEnableCallback ); |
|
223 break; |
|
224 } |
|
225 #if 0 |
|
226 case ECamInCallToneId: |
|
227 { |
|
228 PlayTone( KCamInCallToneHz, KCamInCallToneLen, KCamInCallToneVol, aEnableCallback ); |
|
229 break; |
|
230 } |
|
231 #endif |
|
232 |
|
233 default: |
|
234 { |
|
235 // Other sounds are played using the key sound system |
|
236 #if !( defined(__WINS__) || defined(__WINSCW__) ) |
|
237 #if 0 |
|
238 iKeySoundSystem->PlaySound( aSoundId ); |
|
239 #endif |
|
240 #endif |
|
241 iEnableCallback = EFalse; |
|
242 break; |
|
243 } |
|
244 } |
|
245 PRINT( _L("Camera <= CCamSoundPlayer::PlaySound") ); |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CCamSoundPlayer::PlayTone |
|
250 // Plays the requested tone |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void CCamSoundPlayer::PlayTone( TInt aToneHz, TInt aLenMicSec, TReal32 aVolume, TBool aEnableCallback ) |
|
254 { |
|
255 if ( !iOpenFileInProgress ) |
|
256 { |
|
257 iOpenFileInProgress = ETrue; |
|
258 TInt64 len = aLenMicSec; |
|
259 iTonePlayer->PrepareToPlayTone( aToneHz, TTimeIntervalMicroSeconds( len ) ); |
|
260 iTonePlayer->SetVolume( static_cast<TInt>( aVolume * iTonePlayer->MaxVolume() ) ); |
|
261 } |
|
262 else |
|
263 { |
|
264 if ( iEnableCallback ) |
|
265 { |
|
266 iObserver->PlaySoundComplete(); |
|
267 iEnableCallback = EFalse; |
|
268 } |
|
269 } |
|
270 |
|
271 iEnableCallback = aEnableCallback; |
|
272 } |
|
273 |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // CCamSoundPlayer::StartPlaySound |
|
277 // Starts the opening (and playback) of specified wav file |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 void CCamSoundPlayer::StartPlaySound( const TDesC& aFile, const TBool aEnableCallback ) |
|
281 { |
|
282 PRINT(_L("CCamSoundPlayer::StartPlaySound") ) |
|
283 iAudioPlayer->Stop(); |
|
284 iAudioPlayer->Close(); |
|
285 |
|
286 TInt err = KErrNone; |
|
287 iEnableCallback = aEnableCallback; |
|
288 |
|
289 TRAP( err, iAudioPlayer->OpenFileL( aFile ) ); |
|
290 if ( !err ) |
|
291 { |
|
292 iOpenFileInProgress = ETrue; |
|
293 } |
|
294 else |
|
295 { |
|
296 // The last OpenFileL call hasn't completed yet. |
|
297 err = KErrInUse; |
|
298 } |
|
299 |
|
300 PRINT1(_L("CCamSoundPlayer::StartPlaySound err (%d)"), err ) |
|
301 |
|
302 if ( err && aEnableCallback ) |
|
303 { |
|
304 // Cannot play sound, so notify client. |
|
305 iObserver->PlaySoundComplete(); |
|
306 iEnableCallback = EFalse; |
|
307 } |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // CCamSoundPlayer::StartPlayTone |
|
312 // Attempts to begin playing the specified tone |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 void CCamSoundPlayer::StartPlayTone( const TDesC& aFile, const TBool aEnableCallback ) |
|
316 { |
|
317 // Check if we are already trying to open/play a tone, and stop it |
|
318 // if so |
|
319 if ( iOpenFileInProgress ) |
|
320 { |
|
321 iTonePlayer->CancelPrepare(); |
|
322 iOpenFileInProgress = EFalse; |
|
323 if ( iEnableCallback ) |
|
324 { |
|
325 iObserver->PlaySoundComplete(); |
|
326 iEnableCallback = EFalse; |
|
327 } |
|
328 } |
|
329 else if ( iTonePlayInProgress ) |
|
330 { |
|
331 iTonePlayer->CancelPlay(); |
|
332 iTonePlayInProgress = EFalse; |
|
333 if ( iEnableCallback ) |
|
334 { |
|
335 iObserver->PlaySoundComplete(); |
|
336 iEnableCallback = EFalse; |
|
337 } |
|
338 } |
|
339 else |
|
340 { |
|
341 // empty statement to remove Lint error. |
|
342 } |
|
343 |
|
344 iEnableCallback = aEnableCallback; |
|
345 |
|
346 iOpenFileInProgress = ETrue; |
|
347 iTonePlayer->PrepareToPlayFileSequence( aFile ); |
|
348 iTonePlayer->SetVolume( static_cast<TInt>( KCamInCallToneVol * iTonePlayer->MaxVolume() ) ); |
|
349 } |
|
350 |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // CCamSoundPlayer::MapcInitComplete |
|
354 // CMdaAudioPlayerUtility initialization complete |
|
355 // --------------------------------------------------------------------------- |
|
356 // |
|
357 void CCamSoundPlayer::MapcInitComplete( TInt aError, |
|
358 const TTimeIntervalMicroSeconds& /*aDuration*/ ) |
|
359 { |
|
360 iOpenFileInProgress = EFalse; |
|
361 |
|
362 if ( !aError ) |
|
363 { |
|
364 iAudioPlayer->Play(); |
|
365 } |
|
366 else |
|
367 { |
|
368 if ( iEnableCallback ) |
|
369 { |
|
370 iObserver->PlaySoundComplete(); |
|
371 iEnableCallback = EFalse; |
|
372 } |
|
373 } |
|
374 } |
|
375 |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // CCamSoundPlayer::MapcPlayComplete |
|
379 // Playback complete, notify observer |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 void CCamSoundPlayer::MapcPlayComplete( TInt /*aError*/ ) |
|
383 { |
|
384 if ( iEnableCallback && iObserver) |
|
385 { |
|
386 iObserver->PlaySoundComplete(); |
|
387 iEnableCallback = EFalse; |
|
388 } |
|
389 } |
|
390 |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // CCamSoundPlayer::MatoPrepareComplete |
|
394 // Tone prepare complete. |
|
395 // --------------------------------------------------------------------------- |
|
396 // |
|
397 void CCamSoundPlayer::MatoPrepareComplete( TInt aError ) |
|
398 { |
|
399 iOpenFileInProgress = EFalse; |
|
400 |
|
401 if ( !aError ) |
|
402 { |
|
403 iTonePlayInProgress = ETrue; |
|
404 iTonePlayer->Play(); |
|
405 #ifdef __WINS__ |
|
406 // The tone player does not give a call back on the emulator so |
|
407 // we have to force a callback here |
|
408 MatoPlayComplete( KErrNone ); |
|
409 #endif // __WINS__ |
|
410 } |
|
411 else |
|
412 { |
|
413 if ( iEnableCallback ) |
|
414 { |
|
415 iObserver->PlaySoundComplete(); |
|
416 iEnableCallback = EFalse; |
|
417 } |
|
418 } |
|
419 } |
|
420 |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // CCamSoundPlayer::MatoPlayComplete |
|
424 // Tone playback complete. |
|
425 // --------------------------------------------------------------------------- |
|
426 // |
|
427 void CCamSoundPlayer::MatoPlayComplete( TInt /*aError*/ ) |
|
428 { |
|
429 iTonePlayInProgress = EFalse; |
|
430 if ( iEnableCallback ) |
|
431 { |
|
432 iObserver->PlaySoundComplete(); |
|
433 iEnableCallback = EFalse; |
|
434 } |
|
435 } |
|
436 |
|
437 |
|
438 |
|
439 // --------------------------------------------------------------------------- |
|
440 // CCamSoundPlayer::DisableSelectionKeySoundL |
|
441 // Called to disable certain key press clicks |
|
442 // --------------------------------------------------------------------------- |
|
443 // |
|
444 void CCamSoundPlayer::DisableSelectionKeySoundL() |
|
445 { |
|
446 if ( iKeySoundSystem && !iSelectionKeySilent ) |
|
447 { |
|
448 iKeySoundSystem->PushContextL( R_CAM_SILENT_OK_KEY_LIST ); |
|
449 iSelectionKeySilent = ETrue; |
|
450 } |
|
451 } |
|
452 |
|
453 |
|
454 // --------------------------------------------------------------------------- |
|
455 // CCamSoundPlayer::EnableSelectionKeySound |
|
456 // Called to enable certain key press clicks |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 void CCamSoundPlayer::EnableSelectionKeySound() |
|
460 { |
|
461 if ( iKeySoundSystem && iSelectionKeySilent ) |
|
462 { |
|
463 iKeySoundSystem->PopContext(); |
|
464 iSelectionKeySilent = EFalse; |
|
465 } |
|
466 } |
|
467 |
|
468 |
|
469 // --------------------------------------------------------------------------- |
|
470 // CCamSoundPlayer::DisableAllKeySoundsL |
|
471 // Called to disable all key sounds, usually when video recording |
|
472 // --------------------------------------------------------------------------- |
|
473 // |
|
474 void CCamSoundPlayer::DisableAllKeySoundsL() |
|
475 { |
|
476 if ( iKeySoundSystem && !iAllKeysSilent ) |
|
477 { |
|
478 iKeySoundSystem->PushContextL( R_AVKON_SILENT_SKEY_LIST ); |
|
479 iKeySoundSystem->BringToForeground(); |
|
480 iKeySoundSystem->LockContext(); |
|
481 iAllKeysSilent = ETrue; |
|
482 } |
|
483 } |
|
484 |
|
485 |
|
486 // --------------------------------------------------------------------------- |
|
487 // CCamSoundPlayer::EnableAllKeySoundsL |
|
488 // Called to enable all key sounds, usually when video recording |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 void CCamSoundPlayer::EnableAllKeySounds() |
|
492 { |
|
493 if ( iKeySoundSystem && iAllKeysSilent ) |
|
494 { |
|
495 iKeySoundSystem->ReleaseContext(); |
|
496 iKeySoundSystem->PopContext(); |
|
497 iAllKeysSilent = EFalse; |
|
498 } |
|
499 } |
|
500 |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // CCamSoundPlayer::CancelTonePlayer |
|
504 // Cancels any outstanding tone player activity |
|
505 // --------------------------------------------------------------------------- |
|
506 // |
|
507 void CCamSoundPlayer::CancelTonePlayer() |
|
508 { |
|
509 if ( iOpenFileInProgress && iTonePlayer ) |
|
510 { |
|
511 iTonePlayer->CancelPrepare(); |
|
512 iOpenFileInProgress = EFalse; |
|
513 |
|
514 if ( iEnableCallback && iObserver ) |
|
515 { |
|
516 iObserver->PlaySoundComplete(); |
|
517 iEnableCallback = EFalse; |
|
518 } |
|
519 } |
|
520 |
|
521 if ( iTonePlayInProgress && iTonePlayer ) |
|
522 { |
|
523 iTonePlayer->CancelPlay(); |
|
524 iTonePlayInProgress = EFalse; |
|
525 |
|
526 if ( iEnableCallback && iObserver ) |
|
527 { |
|
528 iObserver->PlaySoundComplete(); |
|
529 iEnableCallback = EFalse; |
|
530 } |
|
531 } |
|
532 } |
|
533 |
|
534 |
|
535 |
|
536 // End of File |