mmhais/refacladapt/src/tonehwdevice/tonehwdevice.h
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_TONEHWDEVICE_H
       
    21 #define C_TONEHWDEVICE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <mmf/server/mmfhwdevice.h>
       
    25 #include <mmf/server/sounddevice.h>
       
    26 #include <mmf/server/mmfhwdevicesetup.h>
       
    27 #include <mmf/server/mmfswcodecwrappercustominterfacesuids.hrh>
       
    28 #include <a3f/a3f_trace_utils.h>
       
    29 #include "mdasoundadapter.h"
       
    30 #include "ToneGenerator.h"
       
    31 #include "tonedatapath.h"
       
    32 #include <a3f/tonedata.h>
       
    33 
       
    34 
       
    35 //note we need to keep this buffer at 8K as the tone utility expects 8K
       
    36 const TInt KPCM16ToPCM16BufferSize = 0x2000;
       
    37 
       
    38 //controlls buffer sizes
       
    39 const TInt KDevSoundDefaultFrameSize = 0x1000;
       
    40 const TInt KDevSoundMinFrameSize = 0x800; //2K
       
    41 const TInt KDevSoundMaxFrameSize = 0x4000;  //16K
       
    42 const TInt KDevSoundDeltaFrameSize = 0x800; //2K
       
    43 const TInt KDevSoundFramesPerSecond = 4;
       
    44 
       
    45 // FORWARD DECLARATIONS
       
    46 class CToneDataPath;
       
    47 
       
    48 // CLASS DECLARATION
       
    49 
       
    50 /**
       
    51  * Implementation of custom interface class for tone play functionality created by the
       
    52  * CToneCodec::CustomInterface() method.  It provides
       
    53  * access to miscellaneous functionality such as volume settings
       
    54  */
       
    55 class TToneCustomInterface : public MPlayCustomInterface
       
    56 	{
       
    57 public:
       
    58 	TToneCustomInterface() : iVolume(0),iBytesPlayed(0),iDevice(NULL),iRampDuration(0) {}
       
    59 	void SetVolume(TUint aVolume);
       
    60 	TUint Volume();
       
    61 	TUint BytesPlayed();
       
    62 	void SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration);
       
    63 	TTimeIntervalMicroSeconds& VolumeRamp();
       
    64 	void SetDevice(RMdaDevSound* iDevice);
       
    65 private:
       
    66 	TUint iVolume;
       
    67 	TUint iBytesPlayed;
       
    68 	RMdaDevSound* iDevice;
       
    69 	TTimeIntervalMicroSeconds iRampDuration;
       
    70 	};
       
    71 
       
    72 
       
    73 
       
    74 /*
       
    75 * Codec Implementation
       
    76 */
       
    77 
       
    78 class CToneCodec : public CBase
       
    79 	{
       
    80 public:
       
    81 	/**
       
    82 	Indicates the result of processing data from the source buffer to a destination buffer
       
    83 	and provides functions to compare the result code.
       
    84 	The CToneCodec buffer sizes should be set to return EProcessComplete
       
    85 	The other return codes are to keep the ProcessL method compatible with
       
    86 	the 7.0s CMMFCodec API.
       
    87 	*/
       
    88 	class TCodecProcessResult
       
    89 		{
       
    90 	public:
       
    91 		/**
       
    92 		Flag to track the codec's processing status.
       
    93 		*/
       
    94 		enum TCodecProcessResultStatus
       
    95 			{
       
    96 			/** The codec has successfully completed its processing. */
       
    97 			EProcessComplete,
       
    98 			/** Could not empty the source buffer because the destination buffer became full. */
       
    99 			EProcessIncomplete,
       
   100 			/** Codec came across an end of data. */
       
   101 			EEndOfData,
       
   102 			/** Could not fill the destination buffer because the source buffer has been emptied. */
       
   103 			EDstNotFilled,
       
   104 			/** An error occured. */
       
   105 			EProcessError
       
   106 			};
       
   107 
       
   108 		/** Overloaded operator to test equality. */
       
   109 		TBool operator==(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus == aStatus);}
       
   110 		/** Overloaded operator to test inequality. */
       
   111 		TBool operator!=(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus != aStatus);}
       
   112 
       
   113 		/**
       
   114 		Default constructor.
       
   115 		*/
       
   116 		TCodecProcessResult()
       
   117 			:iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {};
       
   118 
       
   119 		public:
       
   120 		/**
       
   121 		The codec's processing status
       
   122 
       
   123 		@see enum TCodecProcessResultStatus
       
   124 		*/
       
   125 		TCodecProcessResultStatus iCodecProcessStatus;
       
   126 
       
   127 		/** The number of source bytes processed */
       
   128 		TUint iSrcBytesProcessed;
       
   129 
       
   130 		/** The number of bytes added to the destination buffer */
       
   131 		TUint iDstBytesAdded;
       
   132 		};
       
   133 public:
       
   134 
       
   135 	CToneCodec();
       
   136 	~CToneCodec();
       
   137 
       
   138 	void ConstructL();
       
   139 
       
   140 
       
   141 	/**
       
   142 	Processes the data in the specified source buffer and writes the processed data to
       
   143 	the specified destination buffer.
       
   144 
       
   145 	This function is synchronous, when the function returns the data has been processed.
       
   146 
       
   147 	@param	aSource
       
   148 			The source buffer containing data to encode or decode.
       
   149 	@param	aDest
       
   150 	 		The destination buffer to hold the data after encoding or decoding.
       
   151 
       
   152 	@return	The result of the processing.
       
   153 
       
   154 	@see    TCodecProcessResult
       
   155 	*/
       
   156 	TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest);
       
   157 
       
   158 	/**
       
   159 	Gets the max size of the source buffer passed into the
       
   160 	CToneCodec::ProcessL function.
       
   161 
       
   162 	Note that this means that this is the Max size of each buffer passed to the codec.  The actual
       
   163 	size of the data could be less than the max size.
       
   164 
       
   165 	@return The max size of the source buffer in bytes.
       
   166 	*/
       
   167 	TUint SourceBufferSize();
       
   168 
       
   169 	/**
       
   170 	Gets the max size of the sink (destination) buffer passed into the
       
   171 	CToneCodec::ProcessL method.
       
   172 
       
   173 	Note that this means that this is the Max size of each buffer passed to the codec.  The actual
       
   174 	size of the data written to this buffer could be less than the max size.
       
   175 
       
   176 	@return The max size of the sink buffer in bytes.
       
   177 	*/
       
   178 	TUint SinkBufferSize();
       
   179 
       
   180 	TBool IsNullCodec() {return ETrue;};
       
   181 
       
   182 
       
   183 	private:
       
   184 
       
   185 	TUint iBufferSize;
       
   186 
       
   187 	};
       
   188 
       
   189 
       
   190 class CToneHwDevice : public CMMFHwDevice,
       
   191 					  public MMMFHwDeviceObserver
       
   192 
       
   193 	{
       
   194 	public:  // Constructors and destructor
       
   195 
       
   196 	static CToneHwDevice* NewL();
       
   197 	~CToneHwDevice();
       
   198 
       
   199 	public: // New functions
       
   200 
       
   201 	public: // Functions from base classes
       
   202 
       
   203 
       
   204 	TInt Init(THwDeviceInitParams& aDevInfo);
       
   205 	TInt Start(TDeviceFunc /*aFuncCmd*/, TDeviceFlow /*aFlowCmd*/);
       
   206 	TInt Stop();
       
   207 
       
   208 	/* This function is not used in tone playback*/
       
   209 	TInt Pause();
       
   210 
       
   211 	TAny* CustomInterface(TUid aInterfaceUid);
       
   212 
       
   213 	TInt FillThisHwBuffer(CMMFBuffer& aHwBuffer);
       
   214 
       
   215 	TInt ThisHwBufferFilled(CMMFBuffer& aMmfBuffer);
       
   216 
       
   217 	/*From MMMFHwDeviceObserver*/
       
   218 	/* This function is not used in tone playback*/
       
   219 	TInt ThisHwBufferEmptied(CMMFBuffer& aMmfBuffer);
       
   220 
       
   221 	/*From MMMFHwDeviceObserver*/
       
   222 	/* This function is not used in tone playback*/
       
   223 	TInt EmptyThisHwBuffer(CMMFBuffer& aMmfBuffer);
       
   224 
       
   225 	/*From MMMFHwDeviceObserver*/
       
   226 	TInt MsgFromHwDevice(TUid aMessageType, const TDesC8 &aMsg);
       
   227 
       
   228 	/*From MMMFHwDeviceObserver*/
       
   229 	void Stopped();
       
   230 
       
   231 	/*From MMMFHwDeviceObserver*/
       
   232 	void Error(TInt aError);
       
   233 
       
   234 	TInt SetConfig(TTaskConfig& aConfig);
       
   235 
       
   236 	/* This function is not used in tone playback*/
       
   237 	TInt StopAndDeleteCodec();
       
   238 
       
   239 	/* This function is not used in tone playback*/
       
   240 	TInt DeleteCodec();
       
   241 
       
   242 	CToneCodec& Codec();
       
   243 
       
   244 	TInt GenerateBufferData();
       
   245 
       
   246 	void SetActiveToneBuffer();
       
   247 
       
   248 	TInt SamplingFrequency();
       
   249 
       
   250 	TInt NumberOfChannels();
       
   251 
       
   252 	TInt FillFreeToneBuffer();
       
   253 
       
   254 	TInt ReadToneData();
       
   255 
       
   256 	void FreeBuffers();
       
   257 
       
   258 	TBool ValidDTMFString(const TDesC& aDTMFString);
       
   259 
       
   260 	TBool RecognizeSequence(const TDesC8& aData);
       
   261 
       
   262 	protected:  // New functions
       
   263 	protected:  // Functions from base classes
       
   264 
       
   265 	private:
       
   266 
       
   267 	CToneHwDevice();
       
   268 	void ConstructL();
       
   269 
       
   270 	public:		// Data
       
   271 	protected:	// Data
       
   272 	private:	// Data
       
   273 
       
   274 	/**
       
   275 	* Pointer to the buffer that was last sent to the observer to be filled.
       
   276 	* Own pointer.
       
   277 	*/
       
   278 	CMMFDataBuffer* iHwDataBufferFill;
       
   279 
       
   280 	/**
       
   281 	* Hwdevice observer. Information is send to upper level by using this pointer.
       
   282 	*/
       
   283 	MMMFHwDeviceObserver* iHwDeviceObserver;
       
   284 
       
   285 	/**
       
   286 	The datapath used to transfer the data
       
   287 	*/
       
   288 	CToneDataPath* iDataPath;
       
   289 
       
   290 	MPlayCustomInterface* iPlayCustomInterface;
       
   291 
       
   292 	/**
       
   293 	* Initialize status of the tone
       
   294 	*/
       
   295 	TBool iToneInitialized;
       
   296 
       
   297 	/**
       
   298 	* Playback status of the tone
       
   299 	*/
       
   300 	TBool iTonePlaying;
       
   301 
       
   302 	/**
       
   303 	* Pointer to information about hwdevice initializing parameters.
       
   304 	*/
       
   305 	//TSizeHwDeviceInitArgs* iSizeHwDeviceInitArgs;
       
   306 
       
   307 	/**
       
   308 	* Type of the tone
       
   309 	*/
       
   310 	TToneData::TToneType iToneType;
       
   311 
       
   312 	/**
       
   313 	* Tone Data
       
   314 	*/
       
   315 	TToneData myToneData;
       
   316 
       
   317 	/**
       
   318 	* Tone Codec
       
   319 	*/
       
   320 	CToneCodec *iCodec;
       
   321 
       
   322 	/**
       
   323 	The buffer size of the sound device
       
   324 	*/
       
   325 	TUint iDeviceBufferSize;
       
   326 
       
   327 	/**
       
   328 	The sample rate of the sound device
       
   329 	*/
       
   330 	TInt iSampleRate;
       
   331 	
       
   332 	/**
       
   333 	The number of channels of the sound device
       
   334 	*/
       
   335 	TInt iChannels;
       
   336 
       
   337 	TBool iLastBuffer;
       
   338 
       
   339 	TTimeIntervalMicroSeconds iRampDuration;
       
   340 
       
   341 	//WINS Sound Device Structures
       
   342 	RMdaDevSound::TCurrentSoundFormatBuf soundDeviceSettings;
       
   343 
       
   344 	// Double buffer tone playing
       
   345 	CMMFDataBuffer*				iToneBuffer1;
       
   346 	CMMFDataBuffer*				iToneBuffer2;
       
   347 	// Reference to current tone buffer playing
       
   348 	CMMFDataBuffer*				iActiveToneBuffer;
       
   349 
       
   350 	TBool						iFirstCallFromHwDevice;
       
   351 
       
   352 	//Tone Stuff:
       
   353 
       
   354 	MMdaToneSynthesis*			iCurrentGenerator;
       
   355 	TMdaSimpleToneGenerator		iToneGen;
       
   356 	TMdaDualToneGenerator		iDualToneGen;
       
   357 	TMdaDTMFGenerator			iDTMFGen;
       
   358 	TMdaSequenceGenerator		iSequenceGen; // Not Supported
       
   359 	TInt						iRepeatCount;
       
   360 	TInt						iFrequency1;
       
   361 	TInt						iFrequency2;
       
   362 	TTimeIntervalMicroSeconds	iRepeatTrailingSilence;
       
   363 	TTimeIntervalMicroSeconds	iDuration;
       
   364 
       
   365 	TTimeIntervalMicroSeconds32 myToneOnLength;
       
   366 	TTimeIntervalMicroSeconds32 myToneOffLength;
       
   367 	TTimeIntervalMicroSeconds32 myPauseLength;
       
   368 
       
   369 	TDesC *iDTMFString;
       
   370 
       
   371 	TDesC8 *iSequenceData;
       
   372 	};
       
   373 
       
   374 	#include "tonehwdevice.inl"
       
   375 
       
   376 #endif
       
   377 
       
   378 // End of File