os/mm/mmlibs/mmfw/src/Client/Audio/mmfclienttoneplayer.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 	RArray <TInt> iCallBackQueue;
    61 	RArray <TInt> iCallBackQueueError;
    62 	};
    63 
    64 class CMMFToneConfig;
    65 
    66 /**
    67 Concrete implementation of the CMdaAudioToneUtility API.
    68 @see CMdaAudioToneUtility
    69 */
    70 class CMMFMdaAudioToneUtility;
    71 NONSHARABLE_CLASS( CMMFMdaAudioToneUtility ): public CBase,
    72 											  public MMdaAudioToneObserver,
    73 											  public MDevSoundObserver, 
    74 											  public MMdaAudioTonePlayStartObserver
    75 	{
    76 friend class CMdaAudioToneUtility;
    77 // only for testing purposes
    78 friend class CTestStepUnitMMFAudClient;
    79 
    80 public:
    81 	static CMMFMdaAudioToneUtility* NewL(MMdaAudioToneObserver& aObserver, CMdaServer* aServer = NULL,
    82 											   TInt aPriority = EMdaPriorityNormal, 
    83 											   TInt aPref = EMdaPriorityPreferenceTimeAndQuality);
    84 
    85 	~CMMFMdaAudioToneUtility();
    86 	
    87 	TMdaAudioToneUtilityState State();
    88 	TInt MaxVolume();
    89 	TInt Volume();
    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();
   107 	void Play();
   108 	void CancelPlay();
   109 	TInt Pause();
   110 	TInt Resume();
   111 
   112 	void SetBalanceL(TInt aBalance=KMMFBalanceCenter);
   113 	TInt GetBalanceL();
   114 // From MMdaAudioToneObserver
   115 	void MatoPrepareComplete(TInt aError);
   116 	void MatoPlayComplete(TInt aError);
   117 
   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*/);
   128 	
   129 	TAny* CustomInterface(TUid aInterfaceId);
   130 	
   131 	void PlayAfterInitialized();
   132 
   133 	void RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver);
   134 
   135 // From MMdaAudioTonePlayStartObserver
   136 	void MatoPlayStarted(TInt aError);
   137 	
   138 protected:
   139 	CMMFMdaAudioToneUtility(MMdaAudioToneObserver& aCallback, TInt aPriority, TInt aPref);
   140 	void ConstructL();
   141 private:
   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;
   145 	
   146 private:
   147 	CMMFDevSound* iDevSound;
   148 	MMdaAudioToneObserver& iCallback;
   149 	CMMFMdaAudioToneObserverCallback* iAsyncCallback;
   150 
   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
   155 
   156 	TMdaAudioToneUtilityState iState;
   157 
   158 	TMMFPrioritySettings iPrioritySettings;
   159 	
   160 	TInt iInitializeState;   
   161 	
   162 	TInt iSequenceNumber;
   163 	TBool iPlayCalled;
   164 	
   165 	TBool iInitialized;
   166 	
   167 	MMdaAudioTonePlayStartObserver* iPlayStartObserver;
   168 	
   169 #ifdef _DEBUG
   170 	TBool iPlayCalledBeforeInitialized;
   171 #endif
   172 	};
   173 
   174 
   175 // Tone configurations
   176 class CMMFToneConfig : public CBase
   177 	{
   178 public:
   179 	enum TMMFToneType 
   180 		{	
   181 		EMmfToneTypeSimple,
   182 		EMmfToneTypeDTMF,
   183 		EMmfToneTypeDesSeq,
   184 		EMmfToneTypeFileSeq,
   185 		EMmfToneTypeFixedSeq,
   186 		EMmfToneTypeDual,
   187 		};
   188 	virtual ~CMMFToneConfig() {}
   189 	TMMFToneType Type() {return iType;}
   190 protected:
   191 	CMMFToneConfig(TMMFToneType aType) : iType(aType) {}
   192 private:
   193 	TMMFToneType iType;
   194 	};
   195 
   196 class CMMFSimpleToneConfig : public CMMFToneConfig
   197 	{
   198 public:
   199 	static CMMFToneConfig* NewL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
   200 	virtual ~CMMFSimpleToneConfig();
   201 	TInt Frequency();
   202 	const TTimeIntervalMicroSeconds& Duration();
   203 protected:
   204 	CMMFSimpleToneConfig(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
   205 private:
   206 	TInt iFrequency;
   207 	TTimeIntervalMicroSeconds iDuration;
   208 	};
   209 
   210 class CMMFDualToneConfig : public CMMFToneConfig
   211 	{
   212 public:
   213 	static CMMFToneConfig* NewL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
   214 	virtual ~CMMFDualToneConfig();
   215 	TInt FrequencyOne();
   216 	TInt FrequencyTwo();
   217 	const TTimeIntervalMicroSeconds& Duration();
   218 protected:
   219 	CMMFDualToneConfig(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
   220 private:
   221 	TInt iFrequencyOne;
   222 	TInt iFrequencyTwo;
   223 	TTimeIntervalMicroSeconds iDuration;
   224 	};
   225 
   226 class CMMFDTMFStringToneConfig : public CMMFToneConfig
   227 	{
   228 public:
   229 	static CMMFToneConfig* NewL(const TDesC& aDTMF);
   230 	static CMMFToneConfig* NewL(RFile& aFile);
   231 	virtual ~CMMFDTMFStringToneConfig();
   232 	const TDesC& DTMF();
   233 protected:
   234 	CMMFDTMFStringToneConfig();
   235 	void ConstructL(const TDesC& aDTMF);
   236 private:
   237 	HBufC* iDTMF;
   238 	};
   239 
   240 class CMMFDesSeqToneConfig : public CMMFToneConfig
   241 	{
   242 public:
   243 	static CMMFToneConfig* NewL(const TDesC8& aDesSeq);
   244 	virtual ~CMMFDesSeqToneConfig();
   245 	const TDesC8& DesSeq();
   246 protected:
   247 	CMMFDesSeqToneConfig();
   248 	void ConstructL(const TDesC8& aDesSeq);
   249 private:
   250 	HBufC8* iDesSeq;
   251 	};
   252 
   253 
   254 class CMMFFileSeqToneConfig : public CMMFToneConfig
   255 	{
   256 public:
   257 	static CMMFToneConfig* NewL(const TDesC& aFileSeq);
   258 	static CMMFToneConfig* NewL(RFile& aFile);
   259 	virtual ~CMMFFileSeqToneConfig();
   260 	const TDesC8& FileSeq();
   261 	
   262 	// CAF support for Tone Utility
   263 	void ExecuteIntentL();
   264 protected:
   265 	CMMFFileSeqToneConfig();
   266 	void ConstructL(const TDesC& aFileSeq);
   267 	void ConstructL(RFile& aFile);
   268 private:
   269 	ContentAccess::CContent* iCAFContent;
   270 	ContentAccess::CData* iCAFData;
   271 	HBufC8* iDesSeq;
   272 	};
   273 
   274 class CMMFFixedSeqToneConfig : public CMMFToneConfig
   275 	{
   276 public:
   277 	static CMMFToneConfig* NewL(TInt aSeqNo);
   278 	virtual ~CMMFFixedSeqToneConfig();
   279 	TInt SequenceNumber();
   280 protected:
   281 	CMMFFixedSeqToneConfig(TInt aSeqNo);
   282 private:
   283 	TInt iSequenceNumber;
   284 	};
   285 
   286 #endif