|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <mmf/common/mmfpaniccodes.h> |
|
17 |
|
18 #include "mmfclienttoneplayer.h" |
|
19 using namespace ContentAccess; |
|
20 enum TMmfMdaAudioToneUtility |
|
21 { |
|
22 EBadArgument, |
|
23 EPostConditionViolation, |
|
24 EPlayStartedCalledWithError |
|
25 }; |
|
26 |
|
27 void Panic(TInt aPanicCode) |
|
28 { |
|
29 _LIT(KMMFMediaClientAudioPanicCategory, "Stem_MMFAudioClient"); |
|
30 User::Panic(KMMFMediaClientAudioPanicCategory, aPanicCode); |
|
31 } |
|
32 |
|
33 // Dummy DevSound class |
|
34 |
|
35 CDummyDevSound::CDummyDevSound() |
|
36 : CTimer(EPriorityStandard) |
|
37 {} |
|
38 |
|
39 CDummyDevSound* CDummyDevSound::NewL() |
|
40 { |
|
41 CDummyDevSound* self = new(ELeave) CDummyDevSound(); |
|
42 return self; |
|
43 } |
|
44 |
|
45 void CDummyDevSound::InitializeL(MDevSoundObserver& aDevSoundObserver) |
|
46 { |
|
47 iObserver = &aDevSoundObserver; |
|
48 iObserver->InitializeComplete(KErrNone); |
|
49 } |
|
50 |
|
51 void CDummyDevSound::Play(const TTimeIntervalMicroSeconds& aDuration) |
|
52 { |
|
53 if (IsActive()) |
|
54 { |
|
55 // currently playing - ignore the request? |
|
56 return; |
|
57 } |
|
58 TTimeIntervalMicroSeconds32 d = I64LOW(aDuration.Int64()); |
|
59 if (d <= TTimeIntervalMicroSeconds32(0)) |
|
60 { |
|
61 d = 10; |
|
62 } |
|
63 After(d); |
|
64 } |
|
65 |
|
66 void CDummyDevSound::RunL() |
|
67 { |
|
68 RDebug::Printf("!Beep!\n"); |
|
69 iObserver->ToneFinished(KErrNone); |
|
70 } |
|
71 |
|
72 /** |
|
73 Creates a new instance of the tone player utility. |
|
74 The default volume is set to MaxVolume() / 2. |
|
75 |
|
76 @param aObserver |
|
77 A class to receive notifications from the tone player. |
|
78 @param aServer |
|
79 This parameter is no longer used and should be NULL. |
|
80 |
|
81 @return A pointer to the new audio tone player utility object. |
|
82 |
|
83 @since 5.0 |
|
84 */ |
|
85 EXPORT_C CMdaAudioToneUtility* CMdaAudioToneUtility::NewL(MMdaAudioToneObserver& aObserver, CMdaServer* aServer /*= NULL*/) |
|
86 { |
|
87 return CMdaAudioToneUtility::NewL(aObserver, aServer, EMdaPriorityNormal, EMdaPriorityPreferenceTimeAndQuality); |
|
88 } |
|
89 |
|
90 /** |
|
91 Creates a new instance of the tone player utility. |
|
92 The default volume is set to MaxVolume() / 2. |
|
93 |
|
94 @param aObserver |
|
95 A class to receive notifications from the tone player |
|
96 @param aServer |
|
97 This parameter is no longer used and should be NULL |
|
98 @param aPriority |
|
99 The Priority Value - this client's relative priority. This is a value between EMdaPriorityMin and |
|
100 EMdaPriorityMax and represents a relative priority. A higher value indicates a more important request. |
|
101 @param aPref |
|
102 The Priority Preference - an additional audio policy parameter. The suggested default is |
|
103 EMdaPriorityPreferenceNone. Further values are given by TMdaPriorityPreference, and additional |
|
104 values may be supported by given phones and/or platforms, but should not be depended upon by |
|
105 portable code. |
|
106 |
|
107 @return A pointer to the new audio tone player utility object. |
|
108 |
|
109 @since 5.0 |
|
110 |
|
111 Note: The Priority Value and Priority Preference are used primarily when deciding what to do when |
|
112 several audio clients attempt to play or record simultaneously. In addition to the Priority Value and Preference, |
|
113 the adaptation may consider other parameters such as the SecureId and Capabilities of the client process. |
|
114 Whatever, the decision as to what to do in such situations is up to the audio adaptation, and may |
|
115 vary between different phones. Portable applications are advised not to assume any specific behaviour. |
|
116 */ |
|
117 EXPORT_C CMdaAudioToneUtility* CMdaAudioToneUtility::NewL(MMdaAudioToneObserver& aObserver, CMdaServer* /*aServer = NULL*/, |
|
118 TInt aPriority /*= EMdaPriorityNormal*/, |
|
119 TInt aPref /*= EMdaPriorityPreferenceTimeAndQuality*/) |
|
120 { |
|
121 CMdaAudioToneUtility* self = new(ELeave) CMdaAudioToneUtility(); |
|
122 CleanupStack::PushL(self); |
|
123 self->iProperties = CMMFMdaAudioToneUtility::NewL(aObserver, NULL, aPriority, aPref); |
|
124 CleanupStack::Pop(); //self |
|
125 return self; |
|
126 } |
|
127 |
|
128 /** |
|
129 Destructor. Frees any resources held by the tone player |
|
130 |
|
131 @since 5.0 |
|
132 */ |
|
133 CMdaAudioToneUtility::~CMdaAudioToneUtility() |
|
134 { |
|
135 delete iProperties; |
|
136 } |
|
137 |
|
138 /** |
|
139 Returns the current state of the audio tone utility. |
|
140 |
|
141 @return The state of the audio tone utility. |
|
142 |
|
143 @since 5.0 |
|
144 */ |
|
145 TMdaAudioToneUtilityState CMdaAudioToneUtility::State() |
|
146 { |
|
147 ASSERT(iProperties); |
|
148 return iProperties->State(); |
|
149 } |
|
150 |
|
151 /** |
|
152 Returns the maximum volume supported by the device. This is the maximum value which can be |
|
153 passed to CMdaAudioToneUtility::SetVolume(). |
|
154 |
|
155 @return The maximum volume. This value is platform dependent but is always greater than or equal to one. |
|
156 |
|
157 @since 5.0 |
|
158 */ |
|
159 TInt CMdaAudioToneUtility::MaxVolume() |
|
160 { |
|
161 ASSERT(iProperties); |
|
162 return iProperties->MaxVolume(); |
|
163 } |
|
164 |
|
165 /** |
|
166 Returns an integer representing the current volume of the audio device. |
|
167 |
|
168 @return The current volume. |
|
169 |
|
170 @since 5.0 |
|
171 */ |
|
172 TInt CMdaAudioToneUtility::Volume() |
|
173 { |
|
174 ASSERT(iProperties); |
|
175 return iProperties->Volume(); |
|
176 } |
|
177 |
|
178 /** |
|
179 Changes the volume of the audio device. |
|
180 |
|
181 The volume can be changed before or during play and is effective |
|
182 immediately. |
|
183 |
|
184 @param aVolume |
|
185 The volume setting. This can be any value from zero to |
|
186 the value returned by a call to |
|
187 CMdaAudioToneUtility::MaxVolume(). |
|
188 Setting a zero value mutes the sound. Setting the |
|
189 maximum value results in the loudest possible sound. |
|
190 |
|
191 @since 5.0 |
|
192 */ |
|
193 void CMdaAudioToneUtility::SetVolume(TInt aVolume) |
|
194 { |
|
195 ASSERT(iProperties); |
|
196 iProperties->SetVolume(aVolume); |
|
197 } |
|
198 |
|
199 /** |
|
200 Changes the clients priority. |
|
201 |
|
202 @param aPriority |
|
203 The Priority Value. |
|
204 @param aPref |
|
205 The Priority Preference. |
|
206 |
|
207 @see CMdaAudioToneUtility::NewL() |
|
208 |
|
209 @since 5.0 |
|
210 |
|
211 */ |
|
212 void CMdaAudioToneUtility::SetPriority(TInt aPriority, TInt aPref) |
|
213 { |
|
214 ASSERT(iProperties); |
|
215 iProperties->SetPriority(aPriority, aPref); |
|
216 } |
|
217 |
|
218 /** |
|
219 Changes the duration of DTMF tones, the gaps between DTMF tones and the |
|
220 pauses. |
|
221 |
|
222 @param aToneLength |
|
223 The duration of the DTMF tone in microseconds. |
|
224 @param aToneOffLength |
|
225 The gap between DTFM tones in microseconds. |
|
226 @param aPauseLength |
|
227 Pauses in microseconds |
|
228 */ |
|
229 void CMdaAudioToneUtility::SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength, |
|
230 TTimeIntervalMicroSeconds32 aToneOffLength, |
|
231 TTimeIntervalMicroSeconds32 aPauseLength) |
|
232 { |
|
233 ASSERT(iProperties); |
|
234 iProperties->SetDTMFLengths(aToneLength, aToneOffLength, aPauseLength); |
|
235 } |
|
236 |
|
237 /** |
|
238 Sets the number of times the tone sequence is to be repeated during |
|
239 the play operation. |
|
240 |
|
241 A period of silence can follow each playing of the tone sequence. The |
|
242 tone sequence can be repeated indefinitely. |
|
243 |
|
244 @param aRepeatNumberOfTimes |
|
245 The number of times the tone sequence, together with |
|
246 the trailing silence, is to be repeated. If this is |
|
247 set to KMdaRepeatForever, then the tone |
|
248 sequence, together with the trailing silence, is |
|
249 repeated indefinitely. The behaviour is undefined for values other than |
|
250 KMdaRepeatForever, zero and positive. |
|
251 @param aTrailingSilence |
|
252 The time interval of the training silence. The behaviour is undefined |
|
253 for values other than zero and positive. |
|
254 |
|
255 @since 5.0 |
|
256 */ |
|
257 void CMdaAudioToneUtility::SetRepeats(TInt aRepeatNumberOfTimes, |
|
258 const TTimeIntervalMicroSeconds& aTrailingSilence) |
|
259 { |
|
260 ASSERT(iProperties); |
|
261 iProperties->SetRepeats(aRepeatNumberOfTimes, aTrailingSilence); |
|
262 } |
|
263 |
|
264 /** |
|
265 Defines the period over which the volume level is to rise smoothly |
|
266 from nothing to the normal volume level. |
|
267 |
|
268 @param aRampDuration |
|
269 The period over which the volume is to rise. A zero |
|
270 value causes the tone to be played at the normal level |
|
271 for the full duration of the playback. A value which |
|
272 is longer than the duration of the tone sequence means |
|
273 that the tone never reaches its normal volume level. |
|
274 |
|
275 @since 5.0 |
|
276 */ |
|
277 void CMdaAudioToneUtility::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration) |
|
278 { |
|
279 ASSERT(iProperties); |
|
280 iProperties->SetVolumeRamp(aRampDuration); |
|
281 } |
|
282 |
|
283 /** |
|
284 Returns the number of available pre-defined tone sequences. |
|
285 |
|
286 @return The number of tone sequences. This value is implementation |
|
287 dependent but is always greater than or equal to zero. |
|
288 |
|
289 @since 5.0 |
|
290 */ |
|
291 TInt CMdaAudioToneUtility::FixedSequenceCount() |
|
292 { |
|
293 ASSERT(iProperties); |
|
294 return iProperties->FixedSequenceCount(); |
|
295 } |
|
296 |
|
297 /** |
|
298 Returns the name assigned to a specific pre-defined tone sequence. |
|
299 |
|
300 @param aSequenceNumber |
|
301 The index identifying the specific pre-defined tone sequence. |
|
302 Index values are relative to zero. This can be any value from |
|
303 zero to the value returned by a call to FixedSequenceCount() - 1. |
|
304 The function raises a panic if sequence number is not within this |
|
305 range. |
|
306 |
|
307 @see CMMFDevSound::FixedSequenceName(TInt aSequenceNumber) |
|
308 @see FixedSequenceCount() |
|
309 |
|
310 @return The name assigned to the tone sequence. |
|
311 |
|
312 @since 5.0 |
|
313 */ |
|
314 const TDesC& CMdaAudioToneUtility::FixedSequenceName(TInt aSequenceNumber) |
|
315 { |
|
316 ASSERT(iProperties); |
|
317 return iProperties->FixedSequenceName(aSequenceNumber); |
|
318 } |
|
319 |
|
320 /** |
|
321 Configures the audio tone player utility to play a single tone. |
|
322 |
|
323 This function is asynchronous. On completion, the observer callback |
|
324 function MMdaAudioToneObserver::MatoPrepareComplete() is |
|
325 called, indicating the success or failure of the configuration |
|
326 operation.The configuration operation can be cancelled by calling |
|
327 CMdaAudioToneUtility::CancelPrepare(). The configuration |
|
328 operation cannot be started if a play operation is in progress. |
|
329 |
|
330 @param aFrequency |
|
331 The frequency (pitch) of the tone in Hz. |
|
332 @param aDuration |
|
333 The duration of the tone in microseconds. |
|
334 @since 5.0 |
|
335 */ |
|
336 void CMdaAudioToneUtility::PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration) |
|
337 { |
|
338 ASSERT(iProperties); |
|
339 iProperties->PrepareToPlayTone(aFrequency, aDuration); |
|
340 } |
|
341 |
|
342 /** |
|
343 Configures the audio tone player utility to play a dual tone. |
|
344 The generated tone consists of two sine waves of different |
|
345 frequencies summed together. |
|
346 |
|
347 This function is asynchronous. On completion, the observer callback |
|
348 function MMdaAudioToneObserver::MatoPrepareComplete() is |
|
349 called, indicating the success or failure of the configuration |
|
350 operation. The configuration operation can be cancelled by calling |
|
351 CMdaAudioToneUtility::CancelPrepare(). The configuration |
|
352 operation cannot be started if a play operation is in progress. |
|
353 |
|
354 @param aFrequencyOne |
|
355 The first frequency (pitch) of the tone. |
|
356 @param aFrequencyTwo |
|
357 The second frequency (pitch) of the tone. |
|
358 @param aDuration |
|
359 The duration of the tone in microseconds. |
|
360 |
|
361 @since 7.0sy |
|
362 */ |
|
363 EXPORT_C void CMdaAudioToneUtility::PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration) |
|
364 { |
|
365 ASSERT(iProperties); |
|
366 iProperties->PrepareToPlayDualTone(aFrequencyOne, aFrequencyTwo, aDuration); |
|
367 } |
|
368 |
|
369 /** |
|
370 Configures the audio tone utility player to play a DTMF (Dual-Tone |
|
371 Multi-Frequency) string. |
|
372 |
|
373 This function is asynchronous. On completion, the observer callback |
|
374 function MMdaAudioToneObserver::MatoPrepareComplete() is |
|
375 called, indicating the success or failure of the configuration |
|
376 operation. The configuration operation can be cancelled by calling |
|
377 CMdaAudioToneUtility::CancelPrepare(). The configuration |
|
378 operation cannot be started if a play operation is in progress. |
|
379 |
|
380 @param aDTMF |
|
381 A descriptor containing the DTMF string. |
|
382 |
|
383 @since 5.0 |
|
384 */ |
|
385 void CMdaAudioToneUtility::PrepareToPlayDTMFString(const TDesC& aDTMF) |
|
386 { |
|
387 ASSERT(iProperties); |
|
388 iProperties->PrepareToPlayDTMFString(aDTMF); |
|
389 } |
|
390 |
|
391 /** |
|
392 Configures the audio tone player utility to play a tone sequence |
|
393 contained in a descriptor. |
|
394 |
|
395 This function is asynchronous. On completion, the observer callback |
|
396 function MMdaAudioToneObserver::MatoPrepareComplete() is |
|
397 called, indicating the success or failure of the configuration |
|
398 operation. The configuration operation can be cancelled by calling |
|
399 CMdaAudioToneUtility::CancelPrepare(). The configuration |
|
400 operation cannot be started if a play operation is in progress. |
|
401 |
|
402 @param aSequence |
|
403 The descriptor containing the tone sequence. The |
|
404 format of the data is unspecified but is expected to |
|
405 be platform dependent. A device might support more |
|
406 than one form of sequence data. |
|
407 |
|
408 @since 5.0 |
|
409 */ |
|
410 void CMdaAudioToneUtility::PrepareToPlayDesSequence(const TDesC8& aSequence) |
|
411 { |
|
412 ASSERT(iProperties); |
|
413 iProperties->PrepareToPlayDesSequence(aSequence); |
|
414 } |
|
415 |
|
416 /** |
|
417 Configures the audio tone player utility to play a tone sequence |
|
418 contained in a file. |
|
419 |
|
420 This function is asynchronous. On completion, the observer callback |
|
421 function MMdaAudioToneObserver::MatoPrepareComplete() is |
|
422 called, indicating the success or failure of the configuration |
|
423 operation. The configuration operation can be cancelled by calling |
|
424 CMdaAudioToneUtility::CancelPrepare(). The configuration |
|
425 operation cannot be started if a play operation is in progress. |
|
426 |
|
427 @param aFileName |
|
428 The full path name of the file containing the tone |
|
429 sequence. The format of the data is unspecified but is |
|
430 expected to be platform dependent. A device might |
|
431 support more than one form of sequence data. |
|
432 |
|
433 @since 5.0 |
|
434 */ |
|
435 void CMdaAudioToneUtility::PrepareToPlayFileSequence(const TDesC& aFileName) |
|
436 { |
|
437 ASSERT(iProperties); |
|
438 iProperties->PrepareToPlayFileSequence(aFileName); |
|
439 } |
|
440 |
|
441 /** |
|
442 Configures the audio tone player utility to play a tone sequence |
|
443 contained in a file. |
|
444 |
|
445 This function is asynchronous. On completion, the observer callback |
|
446 function MMdaAudioToneObserver::MatoPrepareComplete() is |
|
447 called, indicating the success or failure of the configuration |
|
448 operation. The configuration operation can be cancelled by calling |
|
449 CMdaAudioToneUtility::CancelPrepare(). The configuration |
|
450 operation cannot be started if a play operation is in progress. |
|
451 |
|
452 @param aFile |
|
453 A handle to an open file containing the tone |
|
454 sequence. The format of the data is unspecified but is |
|
455 expected to be platform dependent. A device might |
|
456 support more than one form of sequence data. |
|
457 |
|
458 @since 5.0 |
|
459 */ |
|
460 EXPORT_C void CMdaAudioToneUtility::PrepareToPlayFileSequence(RFile& aFile) |
|
461 { |
|
462 ASSERT(iProperties); |
|
463 iProperties->PrepareToPlayFileSequence(aFile); |
|
464 } |
|
465 |
|
466 |
|
467 /** |
|
468 Configures the audio tone player utility to play the specified |
|
469 pre-defined tone sequence. |
|
470 |
|
471 This function is asynchronous. On completion, the observer callback |
|
472 function MMdaAudioToneObserver::MatoPrepareComplete() is |
|
473 called, indicating the success or failure of the configuration |
|
474 operation. The configuration operation can be cancelled by calling |
|
475 CMdaAudioToneUtility::CancelPrepare(). The configuration |
|
476 operation cannot be started if a play operation is in progress. |
|
477 |
|
478 @param aSequenceNumber |
|
479 An index into the set of pre-defined tone sequences. |
|
480 This can be any value from zero to the value returned by a |
|
481 call to FixedSequenceCount() - 1. |
|
482 If the sequence number is not within this range, a panic will be |
|
483 raised when Play() is called later. |
|
484 |
|
485 @see FixedSequenceCount() |
|
486 @see CMMFDevSound::PlayFixedSequenceL(TInt aSequenceNumber) |
|
487 |
|
488 @since 5.0 |
|
489 */ |
|
490 void CMdaAudioToneUtility::PrepareToPlayFixedSequence(TInt aSequenceNumber) |
|
491 { |
|
492 ASSERT(iProperties); |
|
493 iProperties->PrepareToPlayFixedSequence(aSequenceNumber); |
|
494 } |
|
495 |
|
496 /** |
|
497 Cancels the configuration operation. |
|
498 |
|
499 The observer callback function |
|
500 MMdaAudioToneObserver::MatoPrepareComplete() is not |
|
501 called. |
|
502 |
|
503 @since 5.0 |
|
504 */ |
|
505 void CMdaAudioToneUtility::CancelPrepare() |
|
506 { |
|
507 ASSERT(iProperties); |
|
508 iProperties->CancelPrepare(); |
|
509 } |
|
510 |
|
511 /** |
|
512 Plays the tone. |
|
513 |
|
514 The tone played depends on the current configuration.This function is |
|
515 asynchronous. On completion, the observer callback function |
|
516 MMdaAudioToneObserver::MatoPlayComplete() is called, |
|
517 indicating the success or failure of the play operation.The play |
|
518 operation can be cancelled by |
|
519 calling CMdaAudioToneUtility::CancelPlay(). |
|
520 |
|
521 @since 5.0 |
|
522 */ |
|
523 void CMdaAudioToneUtility::Play() |
|
524 { |
|
525 ASSERT(iProperties); |
|
526 iProperties->Play(); |
|
527 } |
|
528 |
|
529 EXPORT_C TInt CMdaAudioToneUtility::Pause() |
|
530 { |
|
531 ASSERT(iProperties); |
|
532 return iProperties->Pause(); |
|
533 } |
|
534 |
|
535 EXPORT_C TInt CMdaAudioToneUtility::Resume() |
|
536 { |
|
537 ASSERT(iProperties); |
|
538 return iProperties->Resume(); |
|
539 } |
|
540 |
|
541 /** |
|
542 Cancels the tone playing operation. |
|
543 |
|
544 The observer callback |
|
545 function MMdaAudioToneObserver::MatoPlayComplete() is not |
|
546 called. |
|
547 |
|
548 @since 5.0 |
|
549 */ |
|
550 void CMdaAudioToneUtility::CancelPlay() |
|
551 { |
|
552 ASSERT(iProperties); |
|
553 iProperties->CancelPlay(); |
|
554 } |
|
555 |
|
556 /** |
|
557 Sets the stereo balance for playback. |
|
558 |
|
559 @param aBalance |
|
560 The balance. Should be between KMMFBalanceMaxLeft and KMMFBalanceMaxRight. |
|
561 |
|
562 @return An error code indicating if the function call was successful. KErrNone on success, otherwise |
|
563 another of the system-wide error codes. |
|
564 |
|
565 @since 7.0s |
|
566 */ |
|
567 EXPORT_C void CMdaAudioToneUtility::SetBalanceL(TInt aBalance /*=KMMFBalanceCenter*/) |
|
568 { |
|
569 ASSERT(iProperties); |
|
570 iProperties->SetBalanceL(aBalance); |
|
571 } |
|
572 |
|
573 /** |
|
574 * Returns The current playback balance.This function may not return the same value |
|
575 * as passed to SetBalanceL depending on the internal implementation in |
|
576 * the underlying components. |
|
577 * |
|
578 * @return The balance. Should be between KMMFBalanceMaxLeft and KMMFBalanceMaxRight. |
|
579 * |
|
580 * @since 7.0s |
|
581 */ |
|
582 EXPORT_C TInt CMdaAudioToneUtility::GetBalanceL() |
|
583 { |
|
584 ASSERT(iProperties); |
|
585 return iProperties->GetBalanceL(); |
|
586 } |
|
587 |
|
588 /** |
|
589 Retrieves a custom interface to the underlying device. |
|
590 |
|
591 @param aInterfaceId |
|
592 The interface UID, defined with the custom interface. |
|
593 |
|
594 @return A pointer to the interface implementation, or NULL if the device does not |
|
595 implement the interface requested. The return value must be cast to the |
|
596 correct type by the user. |
|
597 */ |
|
598 EXPORT_C TAny* CMdaAudioToneUtility::CustomInterface(TUid aInterfaceId) |
|
599 { |
|
600 ASSERT(iProperties); |
|
601 return 0; |
|
602 } |
|
603 |
|
604 EXPORT_C void CMdaAudioToneUtility::RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver) |
|
605 { |
|
606 ASSERT(iProperties); |
|
607 iProperties->RegisterPlayStartCallback(aObserver); |
|
608 } |
|
609 |
|
610 |
|
611 |
|
612 CMMFMdaAudioToneUtility* CMMFMdaAudioToneUtility::NewL(MMdaAudioToneObserver& aObserver, CMdaServer* /*aServer = NULL*/, |
|
613 TInt aPriority /*= EMdaPriorityNormal*/, |
|
614 TInt aPref /*= EMdaPriorityPreferenceTimeAndQuality*/) |
|
615 |
|
616 { |
|
617 CMMFMdaAudioToneUtility* self = new(ELeave) CMMFMdaAudioToneUtility(aObserver, aPriority, aPref); |
|
618 CleanupStack::PushL(self); |
|
619 self->ConstructL(); |
|
620 CleanupStack::Pop(self); |
|
621 return self; |
|
622 } |
|
623 |
|
624 |
|
625 |
|
626 CMMFMdaAudioToneUtility::CMMFMdaAudioToneUtility(MMdaAudioToneObserver& aCallback, TInt aPriority, TInt aPref) : |
|
627 iCallback(aCallback) |
|
628 { |
|
629 iPrioritySettings.iPref = aPref; |
|
630 iPrioritySettings.iPriority = aPriority; |
|
631 iState = EMdaAudioToneUtilityNotReady; |
|
632 iInitialized = EFalse; |
|
633 iPlayCalled = EFalse; |
|
634 |
|
635 #ifdef _DEBUG |
|
636 iPlayCalledBeforeInitialized = EFalse; |
|
637 #endif |
|
638 } |
|
639 |
|
640 void CMMFMdaAudioToneUtility::ConstructL() |
|
641 { |
|
642 iAsyncCallback = CMMFMdaAudioToneObserverCallback::NewL(*this, *this); |
|
643 |
|
644 // iDevSound = CMMFDevSound::NewL(); |
|
645 // iDevSound->InitializeL(*this,EMMFStateTonePlaying); |
|
646 |
|
647 iTimer = CDummyDevSound::NewL(); |
|
648 iTimer->InitializeL(*this); |
|
649 |
|
650 SetVolume(MaxVolume()/2 ); // set the volume to an intermediate value |
|
651 } |
|
652 |
|
653 CMMFMdaAudioToneUtility::~CMMFMdaAudioToneUtility() |
|
654 { |
|
655 delete iAsyncCallback; |
|
656 } |
|
657 |
|
658 |
|
659 |
|
660 void CMMFMdaAudioToneUtility::InitializeComplete(TInt aError) |
|
661 { |
|
662 #ifdef _DEBUG |
|
663 __ASSERT_ALWAYS(!iPlayCalledBeforeInitialized, User::Panic(_L("PlayInitialized called before InitializeComplete"), 0)); |
|
664 #endif |
|
665 iInitialized = ETrue; |
|
666 |
|
667 if (iPlayCalled) |
|
668 { |
|
669 // Play() is called before InitializeComplete() |
|
670 if (aError == KErrNone) |
|
671 { |
|
672 PlayAfterInitialized(); |
|
673 } |
|
674 else |
|
675 { |
|
676 // InitializeComplete() with error other than KErrNone |
|
677 iState = EMdaAudioToneUtilityNotReady; |
|
678 iAsyncCallback->MatoPlayComplete(aError); |
|
679 } |
|
680 iPlayCalled = EFalse; |
|
681 } |
|
682 iInitializeState = aError; |
|
683 } |
|
684 |
|
685 void CMMFMdaAudioToneUtility::ToneFinished(TInt aError) |
|
686 { |
|
687 if (aError != KErrCancel) |
|
688 { |
|
689 if (aError == KErrUnderflow) |
|
690 { |
|
691 aError = KErrNone; |
|
692 } |
|
693 |
|
694 iAsyncCallback->MatoPlayComplete(aError); |
|
695 } |
|
696 // else don't want to callback after a cancel |
|
697 } |
|
698 |
|
699 |
|
700 TMdaAudioToneUtilityState CMMFMdaAudioToneUtility::State() |
|
701 { |
|
702 return iState; |
|
703 } |
|
704 |
|
705 TInt CMMFMdaAudioToneUtility::MaxVolume() |
|
706 { |
|
707 return 100; |
|
708 } |
|
709 |
|
710 TInt CMMFMdaAudioToneUtility::Volume() |
|
711 { |
|
712 return iDevSoundVolume; |
|
713 } |
|
714 |
|
715 void CMMFMdaAudioToneUtility::SetVolume(TInt aVolume) |
|
716 { |
|
717 iDevSoundVolume = aVolume; |
|
718 } |
|
719 |
|
720 void CMMFMdaAudioToneUtility::SetPriority(TInt aPriority, TInt aPref) |
|
721 { |
|
722 iPrioritySettings.iPref = aPref; |
|
723 iPrioritySettings.iPriority = aPriority; |
|
724 } |
|
725 |
|
726 void CMMFMdaAudioToneUtility::SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength, |
|
727 TTimeIntervalMicroSeconds32 aToneOffLength, |
|
728 TTimeIntervalMicroSeconds32 aPauseLength) |
|
729 { |
|
730 } |
|
731 |
|
732 void CMMFMdaAudioToneUtility::SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence) |
|
733 { |
|
734 // iDevSound->SetToneRepeats(aRepeatNumberOfTimes, aTrailingSilence); |
|
735 } |
|
736 |
|
737 void CMMFMdaAudioToneUtility::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration) |
|
738 { |
|
739 } |
|
740 |
|
741 TInt CMMFMdaAudioToneUtility::FixedSequenceCount() |
|
742 { |
|
743 return 1; // iDevSound->FixedSequenceCount(); |
|
744 } |
|
745 |
|
746 _LIT(KFixedSequenceName, "FixedSequenceName"); |
|
747 const TDesC& CMMFMdaAudioToneUtility::FixedSequenceName(TInt aSequenceNumber) |
|
748 { |
|
749 return KFixedSequenceName; |
|
750 } |
|
751 |
|
752 void CMMFMdaAudioToneUtility::CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const |
|
753 { |
|
754 } |
|
755 |
|
756 |
|
757 void CMMFMdaAudioToneUtility::CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const |
|
758 { |
|
759 } |
|
760 |
|
761 |
|
762 void CMMFMdaAudioToneUtility::SetBalanceL(TInt aBalance) |
|
763 { |
|
764 iDevSoundBalance = aBalance; |
|
765 } |
|
766 |
|
767 TInt CMMFMdaAudioToneUtility::GetBalanceL() |
|
768 { |
|
769 return iDevSoundBalance; |
|
770 } |
|
771 |
|
772 void CMMFMdaAudioToneUtility::PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration) |
|
773 { |
|
774 iDuration = aDuration; |
|
775 iAsyncCallback->MatoPrepareComplete(KErrNone); |
|
776 } |
|
777 |
|
778 void CMMFMdaAudioToneUtility::PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration) |
|
779 { |
|
780 iDuration = aDuration; |
|
781 iAsyncCallback->MatoPrepareComplete(KErrNone); |
|
782 } |
|
783 |
|
784 void CMMFMdaAudioToneUtility::PrepareToPlayDTMFString(const TDesC& aDTMF) |
|
785 { |
|
786 iDuration = TTimeIntervalMicroSeconds(100); |
|
787 iAsyncCallback->MatoPrepareComplete(KErrNone); |
|
788 } |
|
789 |
|
790 void CMMFMdaAudioToneUtility::PrepareToPlayDesSequence(const TDesC8& aSequence) |
|
791 { |
|
792 iDuration = TTimeIntervalMicroSeconds(100); |
|
793 iAsyncCallback->MatoPrepareComplete(KErrNone); |
|
794 } |
|
795 |
|
796 void CMMFMdaAudioToneUtility::PrepareToPlayFileSequence(const TDesC& aFileName) |
|
797 { |
|
798 iDuration = TTimeIntervalMicroSeconds(100); |
|
799 iAsyncCallback->MatoPrepareComplete(KErrNone); |
|
800 } |
|
801 |
|
802 void CMMFMdaAudioToneUtility::PrepareToPlayFileSequence(RFile& aFileName) |
|
803 { |
|
804 iDuration = TTimeIntervalMicroSeconds(100); |
|
805 iAsyncCallback->MatoPrepareComplete(KErrNone); |
|
806 } |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 void CMMFMdaAudioToneUtility::PrepareToPlayFixedSequence(TInt aSequenceNumber) |
|
812 { |
|
813 iDuration = TTimeIntervalMicroSeconds(100); |
|
814 iSequenceNumber = aSequenceNumber; |
|
815 iAsyncCallback->MatoPrepareComplete(KErrNone); |
|
816 } |
|
817 |
|
818 void CMMFMdaAudioToneUtility::CancelPrepare() |
|
819 { |
|
820 if (iState == EMdaAudioToneUtilityPrepared) |
|
821 { |
|
822 iState = EMdaAudioToneUtilityNotReady; |
|
823 } |
|
824 // Cancel the AO |
|
825 iAsyncCallback->Cancel(); |
|
826 } |
|
827 |
|
828 TInt CMMFMdaAudioToneUtility::Pause() |
|
829 { |
|
830 // Handle scenario when Pause is called before playback has started |
|
831 if (iState != EMdaAudioToneUtilityPlaying || (iState == EMdaAudioToneUtilityPlaying && !iInitialized)) |
|
832 { |
|
833 return KErrNotReady; |
|
834 } |
|
835 |
|
836 iState = EMdaAudioToneUtilityPaused; |
|
837 return KErrNone; |
|
838 } |
|
839 |
|
840 TInt CMMFMdaAudioToneUtility::Resume() |
|
841 { |
|
842 if (iState != EMdaAudioToneUtilityPaused) |
|
843 { |
|
844 return KErrNotReady; |
|
845 } |
|
846 |
|
847 iState = EMdaAudioToneUtilityPlaying; |
|
848 return KErrNone; |
|
849 } |
|
850 |
|
851 void CMMFMdaAudioToneUtility::Play() |
|
852 { |
|
853 TInt error = KErrNone; |
|
854 |
|
855 if ((iState == EMdaAudioToneUtilityPlaying) || (iState == EMdaAudioToneUtilityPaused) || iPlayCalled) |
|
856 { |
|
857 iState = EMdaAudioToneUtilityNotReady; |
|
858 iAsyncCallback->MatoPlayComplete(error); |
|
859 return; |
|
860 } |
|
861 |
|
862 iState = EMdaAudioToneUtilityPlaying; |
|
863 |
|
864 if (iInitialized) |
|
865 { |
|
866 // Play() is called after InitializeComplete() |
|
867 if (iInitializeState) |
|
868 { |
|
869 // InitializeComplete() with error other than KErrNone |
|
870 iState = EMdaAudioToneUtilityNotReady; |
|
871 iAsyncCallback->MatoPlayComplete(iInitializeState); |
|
872 } |
|
873 else |
|
874 { |
|
875 PlayAfterInitialized(); |
|
876 } |
|
877 } |
|
878 else |
|
879 { |
|
880 // Play() is called before InitializeComplete() |
|
881 iPlayCalled = ETrue; |
|
882 } |
|
883 } |
|
884 |
|
885 void CMMFMdaAudioToneUtility::PlayAfterInitialized() |
|
886 { |
|
887 #ifdef _DEBUG |
|
888 if (iInitialized == EFalse) |
|
889 { |
|
890 iPlayCalledBeforeInitialized = ETrue; |
|
891 } |
|
892 #endif |
|
893 |
|
894 // Really play something! |
|
895 // TRAP(error, iDevSound->PlayToneL(c->Frequency(), c->Duration())); |
|
896 iTimer->Play(iDuration); |
|
897 |
|
898 #if 0 // the error case |
|
899 iState = EMdaAudioToneUtilityNotReady; |
|
900 iAsyncCallback->MatoPlayComplete(error); |
|
901 return; |
|
902 #endif |
|
903 |
|
904 if(iPlayStartObserver) |
|
905 { |
|
906 iAsyncCallback->MatoPlayStarted(KErrNone); |
|
907 } |
|
908 } |
|
909 |
|
910 void CMMFMdaAudioToneUtility::CancelPlay() |
|
911 { |
|
912 iTimer->Cancel(); |
|
913 if(iState == EMdaAudioToneUtilityPlaying || iState == EMdaAudioToneUtilityPaused) |
|
914 { |
|
915 iState = EMdaAudioToneUtilityPrepared; |
|
916 } |
|
917 // Cancel the AO |
|
918 iAsyncCallback->Cancel(); |
|
919 iPlayCalled = EFalse; |
|
920 } |
|
921 |
|
922 |
|
923 void CMMFMdaAudioToneUtility::SendEventToClient(const TMMFEvent& /*aEvent*/) |
|
924 { |
|
925 if(iState == EMdaAudioToneUtilityPlaying) |
|
926 { |
|
927 iState = EMdaAudioToneUtilityPrepared; |
|
928 } |
|
929 |
|
930 iAsyncCallback->MatoPlayComplete(KErrInUse); |
|
931 } |
|
932 |
|
933 |
|
934 void CMMFMdaAudioToneUtility::RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver) |
|
935 { |
|
936 iPlayStartObserver = &aObserver; |
|
937 } |
|
938 |
|
939 void CMMFMdaAudioToneUtility::MatoPrepareComplete(TInt aError) |
|
940 { |
|
941 if (!aError) |
|
942 { |
|
943 iState = EMdaAudioToneUtilityPrepared; |
|
944 } |
|
945 else |
|
946 { |
|
947 iState = EMdaAudioToneUtilityNotReady; |
|
948 } |
|
949 |
|
950 iCallback.MatoPrepareComplete(aError); |
|
951 } |
|
952 |
|
953 void CMMFMdaAudioToneUtility::MatoPlayComplete(TInt aError) |
|
954 { |
|
955 iState = EMdaAudioToneUtilityPrepared; |
|
956 iCallback.MatoPlayComplete(aError); |
|
957 } |
|
958 |
|
959 void CMMFMdaAudioToneUtility::MatoPlayStarted(TInt aError) |
|
960 { |
|
961 __ASSERT_DEBUG(aError==KErrNone, Panic(EPlayStartedCalledWithError)); |
|
962 |
|
963 // Not always there is an observer registered |
|
964 if(iPlayStartObserver) |
|
965 { |
|
966 iPlayStartObserver->MatoPlayStarted(aError); |
|
967 } |
|
968 } |
|
969 |
|
970 // CustomInferface - just pass on to DevSound. |
|
971 TAny* CMMFMdaAudioToneUtility::CustomInterface(TUid aInterfaceId) |
|
972 { |
|
973 return 0; |
|
974 } |
|
975 |
|
976 |
|
977 CMMFMdaAudioToneObserverCallback* CMMFMdaAudioToneObserverCallback::NewL(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback) |
|
978 { |
|
979 return new(ELeave) CMMFMdaAudioToneObserverCallback(aCallback, aPlayStartCallback); |
|
980 } |
|
981 |
|
982 CMMFMdaAudioToneObserverCallback::CMMFMdaAudioToneObserverCallback(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback) : |
|
983 CActive(CActive::EPriorityHigh), |
|
984 iCallback(aCallback), |
|
985 iPlayStartCallback(aPlayStartCallback) |
|
986 { |
|
987 CActiveScheduler::Add(this); |
|
988 } |
|
989 |
|
990 CMMFMdaAudioToneObserverCallback::~CMMFMdaAudioToneObserverCallback() |
|
991 { |
|
992 Cancel(); |
|
993 } |
|
994 |
|
995 void CMMFMdaAudioToneObserverCallback::MatoPrepareComplete(TInt aError) |
|
996 { |
|
997 iAction = EPrepareComplete; |
|
998 iErrorCode = aError; |
|
999 |
|
1000 TRequestStatus* s = &iStatus; |
|
1001 SetActive(); |
|
1002 User::RequestComplete(s, KErrNone); |
|
1003 } |
|
1004 |
|
1005 void CMMFMdaAudioToneObserverCallback::MatoPlayComplete(TInt aError) |
|
1006 { |
|
1007 if(!IsActive()) |
|
1008 { |
|
1009 iAction = EPlayComplete; |
|
1010 iErrorCode = aError; |
|
1011 |
|
1012 TRequestStatus* s = &iStatus; |
|
1013 SetActive(); |
|
1014 User::RequestComplete(s, KErrNone); |
|
1015 } |
|
1016 } |
|
1017 |
|
1018 void CMMFMdaAudioToneObserverCallback::MatoPlayStarted(TInt aError) |
|
1019 { |
|
1020 iAction = EPlayStarted; |
|
1021 iErrorCode = aError; |
|
1022 |
|
1023 TRequestStatus* s = &iStatus; |
|
1024 SetActive(); |
|
1025 User::RequestComplete(s, KErrNone); |
|
1026 } |
|
1027 |
|
1028 void CMMFMdaAudioToneObserverCallback::RunL() |
|
1029 { |
|
1030 switch (iAction) |
|
1031 { |
|
1032 case EPrepareComplete: |
|
1033 { |
|
1034 iCallback.MatoPrepareComplete(iErrorCode); |
|
1035 break; |
|
1036 } |
|
1037 case EPlayComplete: |
|
1038 { |
|
1039 iCallback.MatoPlayComplete(iErrorCode); |
|
1040 break; |
|
1041 } |
|
1042 case EPlayStarted: |
|
1043 iPlayStartCallback.MatoPlayStarted(iErrorCode); |
|
1044 break; |
|
1045 } |
|
1046 } |
|
1047 |
|
1048 void CMMFMdaAudioToneObserverCallback::DoCancel() |
|
1049 { |
|
1050 //nothing to cancel |
|
1051 } |
|
1052 |
|
1053 void MMMFClientUtility::ReservedVirtual1() {} |
|
1054 void MMMFClientUtility::ReservedVirtual2() {} |
|
1055 void MMMFClientUtility::ReservedVirtual3() {} |
|
1056 void MMMFClientUtility::ReservedVirtual4() {} |
|
1057 void MMMFClientUtility::ReservedVirtual5() {} |
|
1058 void MMMFClientUtility::ReservedVirtual6() {} |
|
1059 |