|
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 |
|
17 #ifndef __MMFCLIENTTONEPLAY_H__ |
|
18 #define __MMFCLIENTTONEPLAY_H__ |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32base.h> |
|
23 #include <mdaaudiotoneplayer.h> |
|
24 #include <mmf/server/sounddevice.h> |
|
25 //Panic category and codes |
|
26 _LIT(KMMFMdaAudioToneUtilityPanicCategory, "MMFMdaAudioToneUtility"); |
|
27 enum TMMFMdaAudioToneUtilityPanicCodes |
|
28 { |
|
29 EMMFMdaAudioToneUtilityAlreadyPrepared, |
|
30 EMMFMdaAudioToneUtilityBadToneConfig, |
|
31 EMMFMdaAudioToneUtilityBadMixinCall |
|
32 }; |
|
33 |
|
34 /** |
|
35 Active object utility class to allow the callback to be called asynchronously. |
|
36 This should help prevent re-entrant code in clients of the mediaframework. |
|
37 */ |
|
38 class CMMFMdaAudioToneObserverCallback : public CActive, public MMdaAudioToneObserver, public MMdaAudioTonePlayStartObserver |
|
39 { |
|
40 public: |
|
41 static CMMFMdaAudioToneObserverCallback* NewL(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback); |
|
42 ~CMMFMdaAudioToneObserverCallback(); |
|
43 // From MMdaAudioToneObserver |
|
44 virtual void MatoPrepareComplete(TInt aError); |
|
45 virtual void MatoPlayComplete(TInt aError); |
|
46 // From MMdaAudioTonePlayStartObserver |
|
47 virtual void MatoPlayStarted(TInt aError); |
|
48 private: |
|
49 CMMFMdaAudioToneObserverCallback(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback); |
|
50 void RunL(); |
|
51 void DoCancel(); |
|
52 private: |
|
53 enum TMMFAudioToneObserverCallbackAction {EPrepareComplete, EPlayComplete, EPlayStarted}; |
|
54 MMdaAudioToneObserver& iCallback; |
|
55 MMdaAudioTonePlayStartObserver& iPlayStartCallback; |
|
56 TMMFAudioToneObserverCallbackAction iAction; |
|
57 TInt iErrorCode; |
|
58 }; |
|
59 |
|
60 class CMMFToneConfig; |
|
61 |
|
62 /** |
|
63 Timer class used instead of actual CMMFDevSound - the interface isn't the same either! |
|
64 */ |
|
65 NONSHARABLE_CLASS( CDummyDevSound ) : public CTimer |
|
66 { |
|
67 public: |
|
68 static CDummyDevSound* NewL(); |
|
69 |
|
70 void InitializeL(MDevSoundObserver& aDevSoundObserver); |
|
71 void RunL(); |
|
72 void Play(const TTimeIntervalMicroSeconds& aDuration); |
|
73 |
|
74 private: |
|
75 CDummyDevSound(); |
|
76 |
|
77 private: |
|
78 MDevSoundObserver* iObserver; |
|
79 }; |
|
80 |
|
81 /** |
|
82 Concrete implementation of the CMdaAudioToneUtility API. |
|
83 @see CMdaAudioToneUtility |
|
84 */ |
|
85 class CMMFMdaAudioToneUtility; |
|
86 NONSHARABLE_CLASS( CMMFMdaAudioToneUtility ): public CBase, |
|
87 public MMdaAudioToneObserver, |
|
88 public MDevSoundObserver, |
|
89 public MMdaAudioTonePlayStartObserver |
|
90 { |
|
91 friend class CMdaAudioToneUtility; |
|
92 // only for testing purposes |
|
93 friend class CTestStepUnitMMFAudClient; |
|
94 |
|
95 public: |
|
96 static CMMFMdaAudioToneUtility* NewL(MMdaAudioToneObserver& aObserver, CMdaServer* aServer = NULL, |
|
97 TInt aPriority = EMdaPriorityNormal, |
|
98 TInt aPref = EMdaPriorityPreferenceTimeAndQuality); |
|
99 |
|
100 ~CMMFMdaAudioToneUtility(); |
|
101 |
|
102 TMdaAudioToneUtilityState State(); |
|
103 TInt MaxVolume(); |
|
104 TInt Volume(); |
|
105 void SetVolume(TInt aVolume); |
|
106 void SetPriority(TInt aPriority, TInt aPref); |
|
107 void SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength, |
|
108 TTimeIntervalMicroSeconds32 aToneOffLength, |
|
109 TTimeIntervalMicroSeconds32 aPauseLength); |
|
110 void SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence); |
|
111 void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); |
|
112 TInt FixedSequenceCount(); |
|
113 const TDesC& FixedSequenceName(TInt aSequenceNumber); |
|
114 void PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration); |
|
115 void PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration); |
|
116 void PrepareToPlayDTMFString(const TDesC& aDTMF); |
|
117 void PrepareToPlayDesSequence(const TDesC8& aSequence); |
|
118 void PrepareToPlayFileSequence(const TDesC& aFileName); |
|
119 void PrepareToPlayFileSequence(RFile& aFile); |
|
120 void PrepareToPlayFixedSequence(TInt aSequenceNumber); |
|
121 void CancelPrepare(); |
|
122 void Play(); |
|
123 void CancelPlay(); |
|
124 TInt Pause(); |
|
125 TInt Resume(); |
|
126 |
|
127 void SetBalanceL(TInt aBalance=KMMFBalanceCenter); |
|
128 TInt GetBalanceL(); |
|
129 // From MMdaAudioToneObserver |
|
130 void MatoPrepareComplete(TInt aError); |
|
131 void MatoPlayComplete(TInt aError); |
|
132 |
|
133 // From DevSoundObserver |
|
134 void InitializeComplete(TInt aError); |
|
135 void ToneFinished(TInt aError); |
|
136 void BufferToBeFilled(CMMFBuffer* /*aBuffer*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} |
|
137 void PlayError(TInt /*aError*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} |
|
138 void BufferToBeEmptied(CMMFBuffer* /*aBuffer*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} |
|
139 void RecordError(TInt /*aError*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} |
|
140 void ConvertError(TInt /*aError*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} |
|
141 void DeviceMessage(TUid /*aMessageId*/, const TDesC8& /*aMsg*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} |
|
142 void SendEventToClient(const TMMFEvent& /*aEvent*/); |
|
143 |
|
144 TAny* CustomInterface(TUid aInterfaceId); |
|
145 |
|
146 void PlayAfterInitialized(); |
|
147 |
|
148 void RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver); |
|
149 |
|
150 // From MMdaAudioTonePlayStartObserver |
|
151 void MatoPlayStarted(TInt aError); |
|
152 |
|
153 protected: |
|
154 CMMFMdaAudioToneUtility(MMdaAudioToneObserver& aCallback, TInt aPriority, TInt aPref); |
|
155 void ConstructL(); |
|
156 private: |
|
157 // functions to convert between MediaServer Balance and SoundDev balance |
|
158 void CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const; |
|
159 void CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const; |
|
160 |
|
161 private: |
|
162 CDummyDevSound* iTimer; |
|
163 MMdaAudioToneObserver& iCallback; |
|
164 CMMFMdaAudioToneObserverCallback* iAsyncCallback; |
|
165 |
|
166 TMdaAudioToneUtilityState iState; |
|
167 |
|
168 TMMFPrioritySettings iPrioritySettings; |
|
169 |
|
170 TInt iInitializeState; |
|
171 |
|
172 TInt iSequenceNumber; |
|
173 TBool iPlayCalled; |
|
174 |
|
175 TBool iInitialized; |
|
176 |
|
177 MMdaAudioTonePlayStartObserver* iPlayStartObserver; |
|
178 |
|
179 #ifdef _DEBUG |
|
180 TBool iPlayCalledBeforeInitialized; |
|
181 #endif |
|
182 |
|
183 TInt iDevSoundVolume; |
|
184 TInt iDevSoundBalance; |
|
185 TTimeIntervalMicroSeconds iDuration; |
|
186 }; |
|
187 |
|
188 |
|
189 #endif |