os/mm/mmlibs/mmfw/src/Client/Audio/mmfclienttoneplayer.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/src/Client/Audio/mmfclienttoneplayer.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,286 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +
    1.20 +#ifndef __MMFCLIENTTONEPLAY_H__
    1.21 +#define __MMFCLIENTTONEPLAY_H__
    1.22 +
    1.23 +
    1.24 +#include <e32std.h>
    1.25 +#include <e32base.h>
    1.26 +#include <mdaaudiotoneplayer.h>
    1.27 +#include <mmf/server/sounddevice.h>
    1.28 +#include <caf/data.h>
    1.29 +#include <caf/content.h>
    1.30 +//Panic category and codes
    1.31 +_LIT(KMMFMdaAudioToneUtilityPanicCategory, "MMFMdaAudioToneUtility");
    1.32 +enum TMMFMdaAudioToneUtilityPanicCodes
    1.33 +	{
    1.34 +	EMMFMdaAudioToneUtilityAlreadyPrepared,
    1.35 +	EMMFMdaAudioToneUtilityBadToneConfig,
    1.36 +	EMMFMdaAudioToneUtilityBadMixinCall
    1.37 +	};
    1.38 +
    1.39 +/**
    1.40 +Active object utility class to allow the callback to be called asynchronously.
    1.41 +This should help prevent re-entrant code in clients of the mediaframework.
    1.42 +*/
    1.43 +class CMMFMdaAudioToneObserverCallback : public CActive, public MMdaAudioToneObserver, public MMdaAudioTonePlayStartObserver
    1.44 +	{
    1.45 +public:
    1.46 +	static CMMFMdaAudioToneObserverCallback* NewL(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback);
    1.47 +	~CMMFMdaAudioToneObserverCallback();
    1.48 +// From MMdaAudioToneObserver
    1.49 +	virtual void MatoPrepareComplete(TInt aError);
    1.50 +	virtual void MatoPlayComplete(TInt aError);
    1.51 +// From MMdaAudioTonePlayStartObserver
    1.52 +	virtual void MatoPlayStarted(TInt aError);
    1.53 +private:
    1.54 +	CMMFMdaAudioToneObserverCallback(MMdaAudioToneObserver& aCallback, MMdaAudioTonePlayStartObserver& aPlayStartCallback);
    1.55 +	void RunL();
    1.56 +	void DoCancel();
    1.57 +private:
    1.58 +	enum TMMFAudioToneObserverCallbackAction {EPrepareComplete, EPlayComplete, EPlayStarted};
    1.59 +	MMdaAudioToneObserver& iCallback;
    1.60 +	MMdaAudioTonePlayStartObserver& iPlayStartCallback; 
    1.61 +	TMMFAudioToneObserverCallbackAction iAction;
    1.62 +	TInt iErrorCode;
    1.63 +	RArray <TInt> iCallBackQueue;
    1.64 +	RArray <TInt> iCallBackQueueError;
    1.65 +	};
    1.66 +
    1.67 +class CMMFToneConfig;
    1.68 +
    1.69 +/**
    1.70 +Concrete implementation of the CMdaAudioToneUtility API.
    1.71 +@see CMdaAudioToneUtility
    1.72 +*/
    1.73 +class CMMFMdaAudioToneUtility;
    1.74 +NONSHARABLE_CLASS( CMMFMdaAudioToneUtility ): public CBase,
    1.75 +											  public MMdaAudioToneObserver,
    1.76 +											  public MDevSoundObserver, 
    1.77 +											  public MMdaAudioTonePlayStartObserver
    1.78 +	{
    1.79 +friend class CMdaAudioToneUtility;
    1.80 +// only for testing purposes
    1.81 +friend class CTestStepUnitMMFAudClient;
    1.82 +
    1.83 +public:
    1.84 +	static CMMFMdaAudioToneUtility* NewL(MMdaAudioToneObserver& aObserver, CMdaServer* aServer = NULL,
    1.85 +											   TInt aPriority = EMdaPriorityNormal, 
    1.86 +											   TInt aPref = EMdaPriorityPreferenceTimeAndQuality);
    1.87 +
    1.88 +	~CMMFMdaAudioToneUtility();
    1.89 +	
    1.90 +	TMdaAudioToneUtilityState State();
    1.91 +	TInt MaxVolume();
    1.92 +	TInt Volume();
    1.93 +	void SetVolume(TInt aVolume); 
    1.94 +	void SetPriority(TInt aPriority, TInt aPref);
    1.95 +	void SetDTMFLengths(TTimeIntervalMicroSeconds32 aToneLength, 
    1.96 +										 TTimeIntervalMicroSeconds32 aToneOffLength,
    1.97 +										 TTimeIntervalMicroSeconds32 aPauseLength);
    1.98 +	void SetRepeats(TInt aRepeatNumberOfTimes, const TTimeIntervalMicroSeconds& aTrailingSilence);
    1.99 +	void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
   1.100 +	TInt FixedSequenceCount();
   1.101 +	const TDesC& FixedSequenceName(TInt aSequenceNumber);
   1.102 +	void PrepareToPlayTone(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
   1.103 +	void PrepareToPlayDualTone(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
   1.104 +	void PrepareToPlayDTMFString(const TDesC& aDTMF);
   1.105 +	void PrepareToPlayDesSequence(const TDesC8& aSequence);
   1.106 +	void PrepareToPlayFileSequence(const TDesC& aFileName);
   1.107 +	void PrepareToPlayFileSequence(RFile& aFile);
   1.108 +	void PrepareToPlayFixedSequence(TInt aSequenceNumber);
   1.109 +	void CancelPrepare();
   1.110 +	void Play();
   1.111 +	void CancelPlay();
   1.112 +	TInt Pause();
   1.113 +	TInt Resume();
   1.114 +
   1.115 +	void SetBalanceL(TInt aBalance=KMMFBalanceCenter);
   1.116 +	TInt GetBalanceL();
   1.117 +// From MMdaAudioToneObserver
   1.118 +	void MatoPrepareComplete(TInt aError);
   1.119 +	void MatoPlayComplete(TInt aError);
   1.120 +
   1.121 +// From DevSoundObserver
   1.122 +	void InitializeComplete(TInt aError);
   1.123 +	void ToneFinished(TInt aError); 
   1.124 +	void BufferToBeFilled(CMMFBuffer* /*aBuffer*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
   1.125 +	void PlayError(TInt /*aError*/)	{User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
   1.126 +	void BufferToBeEmptied(CMMFBuffer* /*aBuffer*/)	{User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);} 
   1.127 +	void RecordError(TInt /*aError*/)	{User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
   1.128 +	void ConvertError(TInt /*aError*/)  {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}
   1.129 +	void DeviceMessage(TUid /*aMessageId*/, const TDesC8& /*aMsg*/) {User::Panic(KMMFMdaAudioToneUtilityPanicCategory,EMMFMdaAudioToneUtilityBadMixinCall);}	
   1.130 +	void SendEventToClient(const TMMFEvent& /*aEvent*/);
   1.131 +	
   1.132 +	TAny* CustomInterface(TUid aInterfaceId);
   1.133 +	
   1.134 +	void PlayAfterInitialized();
   1.135 +
   1.136 +	void RegisterPlayStartCallback(MMdaAudioTonePlayStartObserver& aObserver);
   1.137 +
   1.138 +// From MMdaAudioTonePlayStartObserver
   1.139 +	void MatoPlayStarted(TInt aError);
   1.140 +	
   1.141 +protected:
   1.142 +	CMMFMdaAudioToneUtility(MMdaAudioToneObserver& aCallback, TInt aPriority, TInt aPref);
   1.143 +	void ConstructL();
   1.144 +private:
   1.145 +	// functions to convert between MediaServer Balance and SoundDev balance
   1.146 +	void CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const;
   1.147 +	void CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const;
   1.148 +	
   1.149 +private:
   1.150 +	CMMFDevSound* iDevSound;
   1.151 +	MMdaAudioToneObserver& iCallback;
   1.152 +	CMMFMdaAudioToneObserverCallback* iAsyncCallback;
   1.153 +
   1.154 +	CMMFToneConfig* iToneConfig;
   1.155 +	// Devsound doesn't take copies of descriptors we pass to it, so we 
   1.156 +	// need to cache the config info until it has finished playing.
   1.157 +	CMMFToneConfig* iPlayingToneConfig; //unused remove when BC break allowed
   1.158 +
   1.159 +	TMdaAudioToneUtilityState iState;
   1.160 +
   1.161 +	TMMFPrioritySettings iPrioritySettings;
   1.162 +	
   1.163 +	TInt iInitializeState;   
   1.164 +	
   1.165 +	TInt iSequenceNumber;
   1.166 +	TBool iPlayCalled;
   1.167 +	
   1.168 +	TBool iInitialized;
   1.169 +	
   1.170 +	MMdaAudioTonePlayStartObserver* iPlayStartObserver;
   1.171 +	
   1.172 +#ifdef _DEBUG
   1.173 +	TBool iPlayCalledBeforeInitialized;
   1.174 +#endif
   1.175 +	};
   1.176 +
   1.177 +
   1.178 +// Tone configurations
   1.179 +class CMMFToneConfig : public CBase
   1.180 +	{
   1.181 +public:
   1.182 +	enum TMMFToneType 
   1.183 +		{	
   1.184 +		EMmfToneTypeSimple,
   1.185 +		EMmfToneTypeDTMF,
   1.186 +		EMmfToneTypeDesSeq,
   1.187 +		EMmfToneTypeFileSeq,
   1.188 +		EMmfToneTypeFixedSeq,
   1.189 +		EMmfToneTypeDual,
   1.190 +		};
   1.191 +	virtual ~CMMFToneConfig() {}
   1.192 +	TMMFToneType Type() {return iType;}
   1.193 +protected:
   1.194 +	CMMFToneConfig(TMMFToneType aType) : iType(aType) {}
   1.195 +private:
   1.196 +	TMMFToneType iType;
   1.197 +	};
   1.198 +
   1.199 +class CMMFSimpleToneConfig : public CMMFToneConfig
   1.200 +	{
   1.201 +public:
   1.202 +	static CMMFToneConfig* NewL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
   1.203 +	virtual ~CMMFSimpleToneConfig();
   1.204 +	TInt Frequency();
   1.205 +	const TTimeIntervalMicroSeconds& Duration();
   1.206 +protected:
   1.207 +	CMMFSimpleToneConfig(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration);
   1.208 +private:
   1.209 +	TInt iFrequency;
   1.210 +	TTimeIntervalMicroSeconds iDuration;
   1.211 +	};
   1.212 +
   1.213 +class CMMFDualToneConfig : public CMMFToneConfig
   1.214 +	{
   1.215 +public:
   1.216 +	static CMMFToneConfig* NewL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
   1.217 +	virtual ~CMMFDualToneConfig();
   1.218 +	TInt FrequencyOne();
   1.219 +	TInt FrequencyTwo();
   1.220 +	const TTimeIntervalMicroSeconds& Duration();
   1.221 +protected:
   1.222 +	CMMFDualToneConfig(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration);
   1.223 +private:
   1.224 +	TInt iFrequencyOne;
   1.225 +	TInt iFrequencyTwo;
   1.226 +	TTimeIntervalMicroSeconds iDuration;
   1.227 +	};
   1.228 +
   1.229 +class CMMFDTMFStringToneConfig : public CMMFToneConfig
   1.230 +	{
   1.231 +public:
   1.232 +	static CMMFToneConfig* NewL(const TDesC& aDTMF);
   1.233 +	static CMMFToneConfig* NewL(RFile& aFile);
   1.234 +	virtual ~CMMFDTMFStringToneConfig();
   1.235 +	const TDesC& DTMF();
   1.236 +protected:
   1.237 +	CMMFDTMFStringToneConfig();
   1.238 +	void ConstructL(const TDesC& aDTMF);
   1.239 +private:
   1.240 +	HBufC* iDTMF;
   1.241 +	};
   1.242 +
   1.243 +class CMMFDesSeqToneConfig : public CMMFToneConfig
   1.244 +	{
   1.245 +public:
   1.246 +	static CMMFToneConfig* NewL(const TDesC8& aDesSeq);
   1.247 +	virtual ~CMMFDesSeqToneConfig();
   1.248 +	const TDesC8& DesSeq();
   1.249 +protected:
   1.250 +	CMMFDesSeqToneConfig();
   1.251 +	void ConstructL(const TDesC8& aDesSeq);
   1.252 +private:
   1.253 +	HBufC8* iDesSeq;
   1.254 +	};
   1.255 +
   1.256 +
   1.257 +class CMMFFileSeqToneConfig : public CMMFToneConfig
   1.258 +	{
   1.259 +public:
   1.260 +	static CMMFToneConfig* NewL(const TDesC& aFileSeq);
   1.261 +	static CMMFToneConfig* NewL(RFile& aFile);
   1.262 +	virtual ~CMMFFileSeqToneConfig();
   1.263 +	const TDesC8& FileSeq();
   1.264 +	
   1.265 +	// CAF support for Tone Utility
   1.266 +	void ExecuteIntentL();
   1.267 +protected:
   1.268 +	CMMFFileSeqToneConfig();
   1.269 +	void ConstructL(const TDesC& aFileSeq);
   1.270 +	void ConstructL(RFile& aFile);
   1.271 +private:
   1.272 +	ContentAccess::CContent* iCAFContent;
   1.273 +	ContentAccess::CData* iCAFData;
   1.274 +	HBufC8* iDesSeq;
   1.275 +	};
   1.276 +
   1.277 +class CMMFFixedSeqToneConfig : public CMMFToneConfig
   1.278 +	{
   1.279 +public:
   1.280 +	static CMMFToneConfig* NewL(TInt aSeqNo);
   1.281 +	virtual ~CMMFFixedSeqToneConfig();
   1.282 +	TInt SequenceNumber();
   1.283 +protected:
   1.284 +	CMMFFixedSeqToneConfig(TInt aSeqNo);
   1.285 +private:
   1.286 +	TInt iSequenceNumber;
   1.287 +	};
   1.288 +
   1.289 +#endif