mmlibs/mmfw/src/Client/Audio/mmfclienttoneplayer.h
changeset 0 40261b775718
child 54 b68f3e90dca1
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 #include <caf/data.h>
       
    26 #include <caf/content.h>
       
    27 //Panic category and codes
       
    28 _LIT(KMMFMdaAudioToneUtilityPanicCategory, "MMFMdaAudioToneUtility");
       
    29 enum TMMFMdaAudioToneUtilityPanicCodes
       
    30 	{
       
    31 	EMMFMdaAudioToneUtilityAlreadyPrepared,
       
    32 	EMMFMdaAudioToneUtilityBadToneConfig,
       
    33 	EMMFMdaAudioToneUtilityBadMixinCall
       
    34 	};
       
    35 
       
    36 /**
       
    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.
       
    39 */
       
    40 class CMMFMdaAudioToneObserverCallback : public CActive, public MMdaAudioToneObserver, public MMdaAudioTonePlayStartObserver
       
    41 	{
       
    42 public:
       
    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);
       
    50 private:
       
    51 	CMMFMdaAudioToneObserverCallback(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback);
       
    52 	void RunL();
       
    53 	void DoCancel();
       
    54 private:
       
    55 	enum TMMFAudioToneObserverCallbackAction {EPrepareComplete, EPlayComplete, EPlayStarted};
       
    56 	MMdaAudioToneObserver& iCallback;
       
    57 	MMdaAudioTonePlayStartObserver& iPlayStartCallback; 
       
    58 	TMMFAudioToneObserverCallbackAction iAction;
       
    59 	TInt iErrorCode;
       
    60 	};
       
    61 
       
    62 class CMMFToneConfig;
       
    63 
       
    64 /**
       
    65 Concrete implementation of the CMdaAudioToneUtility API.
       
    66 @see CMdaAudioToneUtility
       
    67 */
       
    68 class CMMFMdaAudioToneUtility;
       
    69 NONSHARABLE_CLASS( CMMFMdaAudioToneUtility ): public CBase,
       
    70 											  public MMdaAudioToneObserver,
       
    71 											  public MDevSoundObserver, 
       
    72 											  public MMdaAudioTonePlayStartObserver
       
    73 	{
       
    74 friend class CMdaAudioToneUtility;
       
    75 // only for testing purposes
       
    76 friend class CTestStepUnitMMFAudClient;
       
    77 
       
    78 public:
       
    79 	static CMMFMdaAudioToneUtility* NewL(MMdaAudioToneObserver& aObserver, CMdaServer* aServer = NULL,
       
    80 											   TInt aPriority = EMdaPriorityNormal, 
       
    81 											   TInt aPref = EMdaPriorityPreferenceTimeAndQuality);
       
    82 
       
    83 	~CMMFMdaAudioToneUtility();
       
    84 	
       
    85 	TMdaAudioToneUtilityState State();
       
    86 	TInt MaxVolume();
       
    87 	TInt Volume();
       
    88 	void SetVolume(TInt aVolume); 
       
    89 	void SetPriority(TInt aPriority, TInt aPref);
       
    90 	void SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength, 
       
    91 										 TTimeIntervalMicroSeconds32 aToneOffLength,
       
    92 										 TTimeIntervalMicroSeconds32 aPauseLength);
       
    93 	void SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence);
       
    94 	void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
       
    95 	TInt FixedSequenceCount();
       
    96 	const TDesC& FixedSequenceName(TInt aSequenceNumber);
       
    97 	void PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
       
    98 	void PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
       
    99 	void PrepareToPlayDTMFString(const TDesC& aDTMF);
       
   100 	void PrepareToPlayDesSequence(const TDesC8& aSequence);
       
   101 	void PrepareToPlayFileSequence(const TDesC& aFileName);
       
   102 	void PrepareToPlayFileSequence(RFile& aFile);
       
   103 	void PrepareToPlayFixedSequence(TInt aSequenceNumber);
       
   104 	void CancelPrepare();
       
   105 	void Play();
       
   106 	void CancelPlay();
       
   107 	TInt Pause();
       
   108 	TInt Resume();
       
   109 
       
   110 	void SetBalanceL(TInt aBalance=KMMFBalanceCenter);
       
   111 	TInt GetBalanceL();
       
   112 // From MMdaAudioToneObserver
       
   113 	void MatoPrepareComplete(TInt aError);
       
   114 	void MatoPlayComplete(TInt aError);
       
   115 
       
   116 // From DevSoundObserver
       
   117 	void InitializeComplete(TInt aError);
       
   118 	void ToneFinished(TInt aError); 
       
   119 	void BufferToBeFilled(CMMFBuffer* /*aBuffer*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
       
   120 	void PlayError(TInt /*aError*/)	{User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
       
   121 	void BufferToBeEmptied(CMMFBuffer* /*aBuffer*/)	{User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} 
       
   122 	void RecordError(TInt /*aError*/)	{User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
       
   123 	void ConvertError(TInt /*aError*/)  {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
       
   124 	void DeviceMessage(TUid /*aMessageId*/, const TDesC8& /*aMsg*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}	
       
   125 	void SendEventToClient(const TMMFEvent& /*aEvent*/);
       
   126 	
       
   127 	TAny* CustomInterface(TUid aInterfaceId);
       
   128 	
       
   129 	void PlayAfterInitialized();
       
   130 
       
   131 	void RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver);
       
   132 
       
   133 // From MMdaAudioTonePlayStartObserver
       
   134 	void MatoPlayStarted(TInt aError);
       
   135 	
       
   136 protected:
       
   137 	CMMFMdaAudioToneUtility(MMdaAudioToneObserver& aCallback, TInt aPriority, TInt aPref);
       
   138 	void ConstructL();
       
   139 private:
       
   140 	// functions to convert between MediaServer Balance and SoundDev balance
       
   141 	void CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const;
       
   142 	void CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const;
       
   143 	
       
   144 private:
       
   145 	CMMFDevSound* iDevSound;
       
   146 	MMdaAudioToneObserver& iCallback;
       
   147 	CMMFMdaAudioToneObserverCallback* iAsyncCallback;
       
   148 
       
   149 	CMMFToneConfig* iToneConfig;
       
   150 	// Devsound doesn't take copies of descriptors we pass to it, so we 
       
   151 	// need to cache the config info until it has finished playing.
       
   152 	CMMFToneConfig* iPlayingToneConfig; //unused remove when BC break allowed
       
   153 
       
   154 	TMdaAudioToneUtilityState iState;
       
   155 
       
   156 	TMMFPrioritySettings iPrioritySettings;
       
   157 	
       
   158 	TInt iInitializeState;   
       
   159 	
       
   160 	TInt iSequenceNumber;
       
   161 	TBool iPlayCalled;
       
   162 	
       
   163 	TBool iInitialized;
       
   164 	
       
   165 	MMdaAudioTonePlayStartObserver* iPlayStartObserver;
       
   166 	
       
   167 #ifdef _DEBUG
       
   168 	TBool iPlayCalledBeforeInitialized;
       
   169 #endif
       
   170 	};
       
   171 
       
   172 
       
   173 // Tone configurations
       
   174 class CMMFToneConfig : public CBase
       
   175 	{
       
   176 public:
       
   177 	enum TMMFToneType 
       
   178 		{	
       
   179 		EMmfToneTypeSimple,
       
   180 		EMmfToneTypeDTMF,
       
   181 		EMmfToneTypeDesSeq,
       
   182 		EMmfToneTypeFileSeq,
       
   183 		EMmfToneTypeFixedSeq,
       
   184 		EMmfToneTypeDual,
       
   185 		};
       
   186 	virtual ~CMMFToneConfig() {}
       
   187 	TMMFToneType Type() {return iType;}
       
   188 protected:
       
   189 	CMMFToneConfig(TMMFToneType aType) : iType(aType) {}
       
   190 private:
       
   191 	TMMFToneType iType;
       
   192 	};
       
   193 
       
   194 class CMMFSimpleToneConfig : public CMMFToneConfig
       
   195 	{
       
   196 public:
       
   197 	static CMMFToneConfig* NewL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
       
   198 	virtual ~CMMFSimpleToneConfig();
       
   199 	TInt Frequency();
       
   200 	const TTimeIntervalMicroSeconds& Duration();
       
   201 protected:
       
   202 	CMMFSimpleToneConfig(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
       
   203 private:
       
   204 	TInt iFrequency;
       
   205 	TTimeIntervalMicroSeconds iDuration;
       
   206 	};
       
   207 
       
   208 class CMMFDualToneConfig : public CMMFToneConfig
       
   209 	{
       
   210 public:
       
   211 	static CMMFToneConfig* NewL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
       
   212 	virtual ~CMMFDualToneConfig();
       
   213 	TInt FrequencyOne();
       
   214 	TInt FrequencyTwo();
       
   215 	const TTimeIntervalMicroSeconds& Duration();
       
   216 protected:
       
   217 	CMMFDualToneConfig(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
       
   218 private:
       
   219 	TInt iFrequencyOne;
       
   220 	TInt iFrequencyTwo;
       
   221 	TTimeIntervalMicroSeconds iDuration;
       
   222 	};
       
   223 
       
   224 class CMMFDTMFStringToneConfig : public CMMFToneConfig
       
   225 	{
       
   226 public:
       
   227 	static CMMFToneConfig* NewL(const TDesC& aDTMF);
       
   228 	static CMMFToneConfig* NewL(RFile& aFile);
       
   229 	virtual ~CMMFDTMFStringToneConfig();
       
   230 	const TDesC& DTMF();
       
   231 protected:
       
   232 	CMMFDTMFStringToneConfig();
       
   233 	void ConstructL(const TDesC& aDTMF);
       
   234 private:
       
   235 	HBufC* iDTMF;
       
   236 	};
       
   237 
       
   238 class CMMFDesSeqToneConfig : public CMMFToneConfig
       
   239 	{
       
   240 public:
       
   241 	static CMMFToneConfig* NewL(const TDesC8& aDesSeq);
       
   242 	virtual ~CMMFDesSeqToneConfig();
       
   243 	const TDesC8& DesSeq();
       
   244 protected:
       
   245 	CMMFDesSeqToneConfig();
       
   246 	void ConstructL(const TDesC8& aDesSeq);
       
   247 private:
       
   248 	HBufC8* iDesSeq;
       
   249 	};
       
   250 
       
   251 
       
   252 class CMMFFileSeqToneConfig : public CMMFToneConfig
       
   253 	{
       
   254 public:
       
   255 	static CMMFToneConfig* NewL(const TDesC& aFileSeq);
       
   256 	static CMMFToneConfig* NewL(RFile& aFile);
       
   257 	virtual ~CMMFFileSeqToneConfig();
       
   258 	const TDesC8& FileSeq();
       
   259 	
       
   260 	// CAF support for Tone Utility
       
   261 	void ExecuteIntentL();
       
   262 protected:
       
   263 	CMMFFileSeqToneConfig();
       
   264 	void ConstructL(const TDesC& aFileSeq);
       
   265 	void ConstructL(RFile& aFile);
       
   266 private:
       
   267 	ContentAccess::CContent* iCAFContent;
       
   268 	ContentAccess::CData* iCAFData;
       
   269 	HBufC8* iDesSeq;
       
   270 	};
       
   271 
       
   272 class CMMFFixedSeqToneConfig : public CMMFToneConfig
       
   273 	{
       
   274 public:
       
   275 	static CMMFToneConfig* NewL(TInt aSeqNo);
       
   276 	virtual ~CMMFFixedSeqToneConfig();
       
   277 	TInt SequenceNumber();
       
   278 protected:
       
   279 	CMMFFixedSeqToneConfig(TInt aSeqNo);
       
   280 private:
       
   281 	TInt iSequenceNumber;
       
   282 	};
       
   283 
       
   284 #endif