os/mm/mmhais/refacladapt/src/tonehwdevice/tonehwdevice.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmhais/refacladapt/src/tonehwdevice/tonehwdevice.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,378 @@
     1.4 +/*
     1.5 +* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +#ifndef C_TONEHWDEVICE_H
    1.24 +#define C_TONEHWDEVICE_H
    1.25 +
    1.26 +//  INCLUDES
    1.27 +#include <mmf/server/mmfhwdevice.h>
    1.28 +#include <mmf/server/sounddevice.h>
    1.29 +#include <mmf/server/mmfhwdevicesetup.h>
    1.30 +#include <mmf/server/mmfswcodecwrappercustominterfacesuids.hrh>
    1.31 +#include <a3f/a3f_trace_utils.h>
    1.32 +#include "mdasoundadapter.h"
    1.33 +#include "ToneGenerator.h"
    1.34 +#include "tonedatapath.h"
    1.35 +#include <a3f/tonedata.h>
    1.36 +
    1.37 +
    1.38 +//note we need to keep this buffer at 8K as the tone utility expects 8K
    1.39 +const TInt KPCM16ToPCM16BufferSize = 0x2000;
    1.40 +
    1.41 +//controlls buffer sizes
    1.42 +const TInt KDevSoundDefaultFrameSize = 0x1000;
    1.43 +const TInt KDevSoundMinFrameSize = 0x800; //2K
    1.44 +const TInt KDevSoundMaxFrameSize = 0x4000;  //16K
    1.45 +const TInt KDevSoundDeltaFrameSize = 0x800; //2K
    1.46 +const TInt KDevSoundFramesPerSecond = 4;
    1.47 +
    1.48 +// FORWARD DECLARATIONS
    1.49 +class CToneDataPath;
    1.50 +
    1.51 +// CLASS DECLARATION
    1.52 +
    1.53 +/**
    1.54 + * Implementation of custom interface class for tone play functionality created by the
    1.55 + * CToneCodec::CustomInterface() method.  It provides
    1.56 + * access to miscellaneous functionality such as volume settings
    1.57 + */
    1.58 +class TToneCustomInterface : public MPlayCustomInterface
    1.59 +	{
    1.60 +public:
    1.61 +	TToneCustomInterface() : iVolume(0),iBytesPlayed(0),iDevice(NULL),iRampDuration(0) {}
    1.62 +	void SetVolume(TUint aVolume);
    1.63 +	TUint Volume();
    1.64 +	TUint BytesPlayed();
    1.65 +	void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
    1.66 +	TTimeIntervalMicroSeconds& VolumeRamp();
    1.67 +	void SetDevice(RMdaDevSound* iDevice);
    1.68 +private:
    1.69 +	TUint iVolume;
    1.70 +	TUint iBytesPlayed;
    1.71 +	RMdaDevSound* iDevice;
    1.72 +	TTimeIntervalMicroSeconds iRampDuration;
    1.73 +	};
    1.74 +
    1.75 +
    1.76 +
    1.77 +/*
    1.78 +* Codec Implementation
    1.79 +*/
    1.80 +
    1.81 +class CToneCodec : public CBase
    1.82 +	{
    1.83 +public:
    1.84 +	/**
    1.85 +	Indicates the result of processing data from the source buffer to a destination buffer
    1.86 +	and provides functions to compare the result code.
    1.87 +	The CToneCodec buffer sizes should be set to return EProcessComplete
    1.88 +	The other return codes are to keep the ProcessL method compatible with
    1.89 +	the 7.0s CMMFCodec API.
    1.90 +	*/
    1.91 +	class TCodecProcessResult
    1.92 +		{
    1.93 +	public:
    1.94 +		/**
    1.95 +		Flag to track the codec's processing status.
    1.96 +		*/
    1.97 +		enum TCodecProcessResultStatus
    1.98 +			{
    1.99 +			/** The codec has successfully completed its processing. */
   1.100 +			EProcessComplete,
   1.101 +			/** Could not empty the source buffer because the destination buffer became full. */
   1.102 +			EProcessIncomplete,
   1.103 +			/** Codec came across an end of data. */
   1.104 +			EEndOfData,
   1.105 +			/** Could not fill the destination buffer because the source buffer has been emptied. */
   1.106 +			EDstNotFilled,
   1.107 +			/** An error occured. */
   1.108 +			EProcessError
   1.109 +			};
   1.110 +
   1.111 +		/** Overloaded operator to test equality. */
   1.112 +		TBool operator==(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus == aStatus);}
   1.113 +		/** Overloaded operator to test inequality. */
   1.114 +		TBool operator!=(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus != aStatus);}
   1.115 +
   1.116 +		/**
   1.117 +		Default constructor.
   1.118 +		*/
   1.119 +		TCodecProcessResult()
   1.120 +			:iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {};
   1.121 +
   1.122 +		public:
   1.123 +		/**
   1.124 +		The codec's processing status
   1.125 +
   1.126 +		@see enum TCodecProcessResultStatus
   1.127 +		*/
   1.128 +		TCodecProcessResultStatus iCodecProcessStatus;
   1.129 +
   1.130 +		/** The number of source bytes processed */
   1.131 +		TUint iSrcBytesProcessed;
   1.132 +
   1.133 +		/** The number of bytes added to the destination buffer */
   1.134 +		TUint iDstBytesAdded;
   1.135 +		};
   1.136 +public:
   1.137 +
   1.138 +	CToneCodec();
   1.139 +	~CToneCodec();
   1.140 +
   1.141 +	void ConstructL();
   1.142 +
   1.143 +
   1.144 +	/**
   1.145 +	Processes the data in the specified source buffer and writes the processed data to
   1.146 +	the specified destination buffer.
   1.147 +
   1.148 +	This function is synchronous, when the function returns the data has been processed.
   1.149 +
   1.150 +	@param	aSource
   1.151 +			The source buffer containing data to encode or decode.
   1.152 +	@param	aDest
   1.153 +	 		The destination buffer to hold the data after encoding or decoding.
   1.154 +
   1.155 +	@return	The result of the processing.
   1.156 +
   1.157 +	@see    TCodecProcessResult
   1.158 +	*/
   1.159 +	TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest);
   1.160 +
   1.161 +	/**
   1.162 +	Gets the max size of the source buffer passed into the
   1.163 +	CToneCodec::ProcessL function.
   1.164 +
   1.165 +	Note that this means that this is the Max size of each buffer passed to the codec.  The actual
   1.166 +	size of the data could be less than the max size.
   1.167 +
   1.168 +	@return The max size of the source buffer in bytes.
   1.169 +	*/
   1.170 +	TUint SourceBufferSize();
   1.171 +
   1.172 +	/**
   1.173 +	Gets the max size of the sink (destination) buffer passed into the
   1.174 +	CToneCodec::ProcessL method.
   1.175 +
   1.176 +	Note that this means that this is the Max size of each buffer passed to the codec.  The actual
   1.177 +	size of the data written to this buffer could be less than the max size.
   1.178 +
   1.179 +	@return The max size of the sink buffer in bytes.
   1.180 +	*/
   1.181 +	TUint SinkBufferSize();
   1.182 +
   1.183 +	TBool IsNullCodec() {return ETrue;};
   1.184 +
   1.185 +
   1.186 +	private:
   1.187 +
   1.188 +	TUint iBufferSize;
   1.189 +
   1.190 +	};
   1.191 +
   1.192 +
   1.193 +class CToneHwDevice : public CMMFHwDevice,
   1.194 +					  public MMMFHwDeviceObserver
   1.195 +
   1.196 +	{
   1.197 +	public:  // Constructors and destructor
   1.198 +
   1.199 +	static CToneHwDevice* NewL();
   1.200 +	~CToneHwDevice();
   1.201 +
   1.202 +	public: // New functions
   1.203 +
   1.204 +	public: // Functions from base classes
   1.205 +
   1.206 +
   1.207 +	TInt Init(THwDeviceInitParams& aDevInfo);
   1.208 +	TInt Start(TDeviceFunc /*aFuncCmd*/, TDeviceFlow /*aFlowCmd*/);
   1.209 +	TInt Stop();
   1.210 +
   1.211 +	/* This function is not used in tone playback*/
   1.212 +	TInt Pause();
   1.213 +
   1.214 +	TAny* CustomInterface(TUid aInterfaceUid);
   1.215 +
   1.216 +	TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
   1.217 +
   1.218 +	TInt ThisHwBufferFilled(CMMFBuffer& aMmfBuffer);
   1.219 +
   1.220 +	/*From MMMFHwDeviceObserver*/
   1.221 +	/* This function is not used in tone playback*/
   1.222 +	TInt ThisHwBufferEmptied(CMMFBuffer& aMmfBuffer);
   1.223 +
   1.224 +	/*From MMMFHwDeviceObserver*/
   1.225 +	/* This function is not used in tone playback*/
   1.226 +	TInt EmptyThisHwBuffer(CMMFBuffer& aMmfBuffer);
   1.227 +
   1.228 +	/*From MMMFHwDeviceObserver*/
   1.229 +	TInt MsgFromHwDevice(TUid aMessageType, const TDesC8 &aMsg);
   1.230 +
   1.231 +	/*From MMMFHwDeviceObserver*/
   1.232 +	void Stopped();
   1.233 +
   1.234 +	/*From MMMFHwDeviceObserver*/
   1.235 +	void Error(TInt aError);
   1.236 +
   1.237 +	TInt SetConfig(TTaskConfig& aConfig);
   1.238 +
   1.239 +	/* This function is not used in tone playback*/
   1.240 +	TInt StopAndDeleteCodec();
   1.241 +
   1.242 +	/* This function is not used in tone playback*/
   1.243 +	TInt DeleteCodec();
   1.244 +
   1.245 +	CToneCodec& Codec();
   1.246 +
   1.247 +	TInt GenerateBufferData();
   1.248 +
   1.249 +	void SetActiveToneBuffer();
   1.250 +
   1.251 +	TInt SamplingFrequency();
   1.252 +
   1.253 +	TInt NumberOfChannels();
   1.254 +
   1.255 +	TInt FillFreeToneBuffer();
   1.256 +
   1.257 +	TInt ReadToneData();
   1.258 +
   1.259 +	void FreeBuffers();
   1.260 +
   1.261 +	TBool ValidDTMFString(const TDesC& aDTMFString);
   1.262 +
   1.263 +	TBool RecognizeSequence(const TDesC8& aData);
   1.264 +
   1.265 +	protected:  // New functions
   1.266 +	protected:  // Functions from base classes
   1.267 +
   1.268 +	private:
   1.269 +
   1.270 +	CToneHwDevice();
   1.271 +	void ConstructL();
   1.272 +
   1.273 +	public:		// Data
   1.274 +	protected:	// Data
   1.275 +	private:	// Data
   1.276 +
   1.277 +	/**
   1.278 +	* Pointer to the buffer that was last sent to the observer to be filled.
   1.279 +	* Own pointer.
   1.280 +	*/
   1.281 +	CMMFDataBuffer* iHwDataBufferFill;
   1.282 +
   1.283 +	/**
   1.284 +	* Hwdevice observer. Information is send to upper level by using this pointer.
   1.285 +	*/
   1.286 +	MMMFHwDeviceObserver* iHwDeviceObserver;
   1.287 +
   1.288 +	/**
   1.289 +	The datapath used to transfer the data
   1.290 +	*/
   1.291 +	CToneDataPath* iDataPath;
   1.292 +
   1.293 +	MPlayCustomInterface* iPlayCustomInterface;
   1.294 +
   1.295 +	/**
   1.296 +	* Initialize status of the tone
   1.297 +	*/
   1.298 +	TBool iToneInitialized;
   1.299 +
   1.300 +	/**
   1.301 +	* Playback status of the tone
   1.302 +	*/
   1.303 +	TBool iTonePlaying;
   1.304 +
   1.305 +	/**
   1.306 +	* Pointer to information about hwdevice initializing parameters.
   1.307 +	*/
   1.308 +	//TSizeHwDeviceInitArgs* iSizeHwDeviceInitArgs;
   1.309 +
   1.310 +	/**
   1.311 +	* Type of the tone
   1.312 +	*/
   1.313 +	TToneData::TToneType iToneType;
   1.314 +
   1.315 +	/**
   1.316 +	* Tone Data
   1.317 +	*/
   1.318 +	TToneData myToneData;
   1.319 +
   1.320 +	/**
   1.321 +	* Tone Codec
   1.322 +	*/
   1.323 +	CToneCodec *iCodec;
   1.324 +
   1.325 +	/**
   1.326 +	The buffer size of the sound device
   1.327 +	*/
   1.328 +	TUint iDeviceBufferSize;
   1.329 +
   1.330 +	/**
   1.331 +	The sample rate of the sound device
   1.332 +	*/
   1.333 +	TInt iSampleRate;
   1.334 +	
   1.335 +	/**
   1.336 +	The number of channels of the sound device
   1.337 +	*/
   1.338 +	TInt iChannels;
   1.339 +
   1.340 +	TBool iLastBuffer;
   1.341 +
   1.342 +	TTimeIntervalMicroSeconds iRampDuration;
   1.343 +
   1.344 +	//WINS Sound Device Structures
   1.345 +	RMdaDevSound::TCurrentSoundFormatBuf soundDeviceSettings;
   1.346 +
   1.347 +	// Double buffer tone playing
   1.348 +	CMMFDataBuffer*				iToneBuffer1;
   1.349 +	CMMFDataBuffer*				iToneBuffer2;
   1.350 +	// Reference to current tone buffer playing
   1.351 +	CMMFDataBuffer*				iActiveToneBuffer;
   1.352 +
   1.353 +	TBool						iFirstCallFromHwDevice;
   1.354 +
   1.355 +	//Tone Stuff:
   1.356 +
   1.357 +	MMdaToneSynthesis*			iCurrentGenerator;
   1.358 +	TMdaSimpleToneGenerator		iToneGen;
   1.359 +	TMdaDualToneGenerator		iDualToneGen;
   1.360 +	TMdaDTMFGenerator			iDTMFGen;
   1.361 +	TMdaSequenceGenerator		iSequenceGen; // Not Supported
   1.362 +	TInt						iRepeatCount;
   1.363 +	TInt						iFrequency1;
   1.364 +	TInt						iFrequency2;
   1.365 +	TTimeIntervalMicroSeconds	iRepeatTrailingSilence;
   1.366 +	TTimeIntervalMicroSeconds	iDuration;
   1.367 +
   1.368 +	TTimeIntervalMicroSeconds32 myToneOnLength;
   1.369 +	TTimeIntervalMicroSeconds32 myToneOffLength;
   1.370 +	TTimeIntervalMicroSeconds32 myPauseLength;
   1.371 +
   1.372 +	TDesC *iDTMFString;
   1.373 +
   1.374 +	TDesC8 *iSequenceData;
   1.375 +	};
   1.376 +
   1.377 +	#include "tonehwdevice.inl"
   1.378 +
   1.379 +#endif
   1.380 +
   1.381 +// End of File