Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #ifndef __MMFCLIENTTONEPLAY_H__
18 #define __MMFCLIENTTONEPLAY_H__
23 #include <mdaaudiotoneplayer.h>
24 #include <mmf/server/sounddevice.h>
26 #include <caf/content.h>
27 //Panic category and codes
28 _LIT(KMMFMdaAudioToneUtilityPanicCategory, "MMFMdaAudioToneUtility");
29 enum TMMFMdaAudioToneUtilityPanicCodes
31 EMMFMdaAudioToneUtilityAlreadyPrepared,
32 EMMFMdaAudioToneUtilityBadToneConfig,
33 EMMFMdaAudioToneUtilityBadMixinCall
37 Active object utility class to allow the callback to be called asynchronously.
38 This should help prevent re-entrant code in clients of the mediaframework.
40 class CMMFMdaAudioToneObserverCallback : public CActive, public MMdaAudioToneObserver, public MMdaAudioTonePlayStartObserver
43 static CMMFMdaAudioToneObserverCallback* NewL(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback);
44 ~CMMFMdaAudioToneObserverCallback();
45 // From MMdaAudioToneObserver
46 virtual void MatoPrepareComplete(TInt aError);
47 virtual void MatoPlayComplete(TInt aError);
48 // From MMdaAudioTonePlayStartObserver
49 virtual void MatoPlayStarted(TInt aError);
51 CMMFMdaAudioToneObserverCallback(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback);
55 enum TMMFAudioToneObserverCallbackAction {EPrepareComplete, EPlayComplete, EPlayStarted};
56 MMdaAudioToneObserver& iCallback;
57 MMdaAudioTonePlayStartObserver& iPlayStartCallback;
58 TMMFAudioToneObserverCallbackAction iAction;
60 RArray <TInt> iCallBackQueue;
61 RArray <TInt> iCallBackQueueError;
67 Concrete implementation of the CMdaAudioToneUtility API.
68 @see CMdaAudioToneUtility
70 class CMMFMdaAudioToneUtility;
71 NONSHARABLE_CLASS( CMMFMdaAudioToneUtility ): public CBase,
72 public MMdaAudioToneObserver,
73 public MDevSoundObserver,
74 public MMdaAudioTonePlayStartObserver
76 friend class CMdaAudioToneUtility;
77 // only for testing purposes
78 friend class CTestStepUnitMMFAudClient;
81 static CMMFMdaAudioToneUtility* NewL(MMdaAudioToneObserver& aObserver, CMdaServer* aServer = NULL,
82 TInt aPriority = EMdaPriorityNormal,
83 TInt aPref = EMdaPriorityPreferenceTimeAndQuality);
85 ~CMMFMdaAudioToneUtility();
87 TMdaAudioToneUtilityState State();
90 void SetVolume(TInt aVolume);
91 void SetPriority(TInt aPriority, TInt aPref);
92 void SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength,
93 TTimeIntervalMicroSeconds32 aToneOffLength,
94 TTimeIntervalMicroSeconds32 aPauseLength);
95 void SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence);
96 void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
97 TInt FixedSequenceCount();
98 const TDesC& FixedSequenceName(TInt aSequenceNumber);
99 void PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
100 void PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
101 void PrepareToPlayDTMFString(const TDesC& aDTMF);
102 void PrepareToPlayDesSequence(const TDesC8& aSequence);
103 void PrepareToPlayFileSequence(const TDesC& aFileName);
104 void PrepareToPlayFileSequence(RFile& aFile);
105 void PrepareToPlayFixedSequence(TInt aSequenceNumber);
106 void CancelPrepare();
112 void SetBalanceL(TInt aBalance=KMMFBalanceCenter);
114 // From MMdaAudioToneObserver
115 void MatoPrepareComplete(TInt aError);
116 void MatoPlayComplete(TInt aError);
118 // From DevSoundObserver
119 void InitializeComplete(TInt aError);
120 void ToneFinished(TInt aError);
121 void BufferToBeFilled(CMMFBuffer* /*aBuffer*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
122 void PlayError(TInt /*aError*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
123 void BufferToBeEmptied(CMMFBuffer* /*aBuffer*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
124 void RecordError(TInt /*aError*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
125 void ConvertError(TInt /*aError*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
126 void DeviceMessage(TUid /*aMessageId*/, const TDesC8& /*aMsg*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
127 void SendEventToClient(const TMMFEvent& /*aEvent*/);
129 TAny* CustomInterface(TUid aInterfaceId);
131 void PlayAfterInitialized();
133 void RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver);
135 // From MMdaAudioTonePlayStartObserver
136 void MatoPlayStarted(TInt aError);
139 CMMFMdaAudioToneUtility(MMdaAudioToneObserver& aCallback, TInt aPriority, TInt aPref);
142 // functions to convert between MediaServer Balance and SoundDev balance
143 void CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const;
144 void CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const;
147 CMMFDevSound* iDevSound;
148 MMdaAudioToneObserver& iCallback;
149 CMMFMdaAudioToneObserverCallback* iAsyncCallback;
151 CMMFToneConfig* iToneConfig;
152 // Devsound doesn't take copies of descriptors we pass to it, so we
153 // need to cache the config info until it has finished playing.
154 CMMFToneConfig* iPlayingToneConfig; //unused remove when BC break allowed
156 TMdaAudioToneUtilityState iState;
158 TMMFPrioritySettings iPrioritySettings;
160 TInt iInitializeState;
162 TInt iSequenceNumber;
167 MMdaAudioTonePlayStartObserver* iPlayStartObserver;
170 TBool iPlayCalledBeforeInitialized;
175 // Tone configurations
176 class CMMFToneConfig : public CBase
185 EMmfToneTypeFixedSeq,
188 virtual ~CMMFToneConfig() {}
189 TMMFToneType Type() {return iType;}
191 CMMFToneConfig(TMMFToneType aType) : iType(aType) {}
196 class CMMFSimpleToneConfig : public CMMFToneConfig
199 static CMMFToneConfig* NewL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
200 virtual ~CMMFSimpleToneConfig();
202 const TTimeIntervalMicroSeconds& Duration();
204 CMMFSimpleToneConfig(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
207 TTimeIntervalMicroSeconds iDuration;
210 class CMMFDualToneConfig : public CMMFToneConfig
213 static CMMFToneConfig* NewL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
214 virtual ~CMMFDualToneConfig();
217 const TTimeIntervalMicroSeconds& Duration();
219 CMMFDualToneConfig(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
223 TTimeIntervalMicroSeconds iDuration;
226 class CMMFDTMFStringToneConfig : public CMMFToneConfig
229 static CMMFToneConfig* NewL(const TDesC& aDTMF);
230 static CMMFToneConfig* NewL(RFile& aFile);
231 virtual ~CMMFDTMFStringToneConfig();
234 CMMFDTMFStringToneConfig();
235 void ConstructL(const TDesC& aDTMF);
240 class CMMFDesSeqToneConfig : public CMMFToneConfig
243 static CMMFToneConfig* NewL(const TDesC8& aDesSeq);
244 virtual ~CMMFDesSeqToneConfig();
245 const TDesC8& DesSeq();
247 CMMFDesSeqToneConfig();
248 void ConstructL(const TDesC8& aDesSeq);
254 class CMMFFileSeqToneConfig : public CMMFToneConfig
257 static CMMFToneConfig* NewL(const TDesC& aFileSeq);
258 static CMMFToneConfig* NewL(RFile& aFile);
259 virtual ~CMMFFileSeqToneConfig();
260 const TDesC8& FileSeq();
262 // CAF support for Tone Utility
263 void ExecuteIntentL();
265 CMMFFileSeqToneConfig();
266 void ConstructL(const TDesC& aFileSeq);
267 void ConstructL(RFile& aFile);
269 ContentAccess::CContent* iCAFContent;
270 ContentAccess::CData* iCAFData;
274 class CMMFFixedSeqToneConfig : public CMMFToneConfig
277 static CMMFToneConfig* NewL(TInt aSeqNo);
278 virtual ~CMMFFixedSeqToneConfig();
279 TInt SequenceNumber();
281 CMMFFixedSeqToneConfig(TInt aSeqNo);
283 TInt iSequenceNumber;