os/mm/devsound/sounddevbt/inc/SwCodecWrapper/MmfBtSwCodecWrapper.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __MMFBTSWCODECWRAPPER_H__
sl@0
    17
#define __MMFBTSWCODECWRAPPER_H__
sl@0
    18
sl@0
    19
#include <mmfbthwdevice2.h>
sl@0
    20
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    21
#include <mmfbtswcodecwrapperinterface.h>
sl@0
    22
#include <routingsounddeviceopenhandler.h>
sl@0
    23
#endif
sl@0
    24
sl@0
    25
class CMMFSwCodecDataPath; //forward reference
sl@0
    26
sl@0
    27
class CRoutingSoundPlayDevice;
sl@0
    28
class CRoutingSoundRecordDevice;
sl@0
    29
sl@0
    30
/** 
sl@0
    31
@publishedAll
sl@0
    32
@released
sl@0
    33
sl@0
    34
Class for a software codec used by the CMMFSwCodecWrapper class to make the CMMFSwCodec a 
sl@0
    35
CMMFHwDevice plugin. The CMMFSwCodec processes source data in a certain fourCC coding type and
sl@0
    36
converts it to a destination buffer of another fourCC coding type.
sl@0
    37
sl@0
    38
A CMMFSwCodec object would usually not be instantiated directly
sl@0
    39
but instead would be instantiated via the CMMFSwCodecWrapper class's Codec()
sl@0
    40
method.
sl@0
    41
sl@0
    42
The processing of the data is handled by the codecs ProcessL() member.
sl@0
    43
The intention is that the source buffer for conversion is converted to the appropriate coding type
sl@0
    44
in the destination buffer.  The size of the buffers passed in are determined by SourceBufferSize()
sl@0
    45
and SinkBufferSize() methods.  The buffer sizes should be chosen such that
sl@0
    46
the ProcessL() method can be guaranteed to have enough destination buffer to
sl@0
    47
completely process one source buffer.
sl@0
    48
sl@0
    49
The ProcessL should return a TCodecProcessResult returning the number of source bytes processed
sl@0
    50
and the number of destination bytes processed along with a process result code defined thus:
sl@0
    51
- EProcessComplete: the codec processed all the source data into the sink buffer
sl@0
    52
- EProcessIncomplete: the codec filled sink buffer before all the source buffer was processed
sl@0
    53
- EDstNotFilled: the codec processed the source buffer but the sink buffer was not filled
sl@0
    54
- EEndOfData: the codec detected the end data - all source data in processed but sink may not be full
sl@0
    55
- EProcessError: the codec process error condition
sl@0
    56
sl@0
    57
Unlike the 7.0s CMMFCodec::ProcessL method, the CMMFSwCodec::ProcessL method
sl@0
    58
should not return EProcessIncomplete as this case is not handled by the
sl@0
    59
CMMFSwCodecWrapper.
sl@0
    60
*/
sl@0
    61
class CMMFSwCodec : public CBase
sl@0
    62
	{
sl@0
    63
public:
sl@0
    64
	/**
sl@0
    65
	@publishedAll
sl@0
    66
	@released
sl@0
    67
sl@0
    68
	Indicates the result of processing data from the source buffer to a destination buffer
sl@0
    69
	and provides functions to compare the result code.
sl@0
    70
	The CMMFSwCodec buffer sizes should be set to return EProcessComplete
sl@0
    71
	The other return codes are to keep the ProcessL method compatible with
sl@0
    72
	the 7.0s CMMFCodec API.
sl@0
    73
	*/
sl@0
    74
	class TCodecProcessResult
sl@0
    75
		{
sl@0
    76
	public:
sl@0
    77
		/**
sl@0
    78
		Flag to track the codec's processing status.
sl@0
    79
		*/
sl@0
    80
		enum TCodecProcessResultStatus
sl@0
    81
			{
sl@0
    82
			/** The codec has successfully completed its processing. */
sl@0
    83
			EProcessComplete,
sl@0
    84
			/** Could not empty the source buffer because the destination buffer became full. */
sl@0
    85
			EProcessIncomplete,
sl@0
    86
			/** Codec came across an end of data. */
sl@0
    87
			EEndOfData,
sl@0
    88
			/** Could not fill the destination buffer because the source buffer has been emptied. */
sl@0
    89
			EDstNotFilled,
sl@0
    90
			/** An error occured. */
sl@0
    91
			EProcessError
sl@0
    92
			};
sl@0
    93
sl@0
    94
		/** Overloaded operator to test equality. */
sl@0
    95
		TBool operator==(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus == aStatus);}
sl@0
    96
		/** Overloaded operator to test inequality. */
sl@0
    97
		TBool operator!=(const TCodecProcessResultStatus aStatus) const {return (iCodecProcessStatus != aStatus);}
sl@0
    98
sl@0
    99
		/**
sl@0
   100
		Default constructor.
sl@0
   101
		*/
sl@0
   102
		TCodecProcessResult()
sl@0
   103
			:iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {};
sl@0
   104
sl@0
   105
		public:
sl@0
   106
		/**
sl@0
   107
		The codec's processing status
sl@0
   108
sl@0
   109
		@see enum TCodecProcessResultStatus
sl@0
   110
		*/
sl@0
   111
		TCodecProcessResultStatus iCodecProcessStatus;
sl@0
   112
sl@0
   113
		/** The number of source bytes processed */
sl@0
   114
		TUint iSrcBytesProcessed;
sl@0
   115
sl@0
   116
		/** The number of bytes added to the destination buffer */
sl@0
   117
		TUint iDstBytesAdded;
sl@0
   118
		};
sl@0
   119
public:
sl@0
   120
sl@0
   121
	/**
sl@0
   122
	Processes the data in the specified source buffer and writes the processed data to
sl@0
   123
	the specified destination buffer.
sl@0
   124
sl@0
   125
	This function is synchronous, when the function returns the data has been processed.
sl@0
   126
	This is a virtual function that each derived class must implement.
sl@0
   127
sl@0
   128
	@param	aSource
sl@0
   129
			The source buffer containing data to encode or decode.
sl@0
   130
	@param	aDest
sl@0
   131
	 		The destination buffer to hold the data after encoding or decoding.
sl@0
   132
sl@0
   133
	@return	The result of the processing.
sl@0
   134
sl@0
   135
	@see    TCodecProcessResult
sl@0
   136
	*/
sl@0
   137
	virtual TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest) = 0;
sl@0
   138
sl@0
   139
	/**
sl@0
   140
	Gets the max size of the source buffer passed into the
sl@0
   141
	CMMFSwCodec::ProcessL function. 
sl@0
   142
sl@0
   143
	Note that this means that this is the Max size of each buffer passed to the codec.  The actual 
sl@0
   144
	size of the data could be less than the max size. This is a virtual function that each derived 
sl@0
   145
	class must implement.
sl@0
   146
sl@0
   147
	@return The max size of the source buffer in bytes.
sl@0
   148
	*/
sl@0
   149
	virtual TUint SourceBufferSize() = 0;
sl@0
   150
sl@0
   151
	/**
sl@0
   152
	Gets the max size of the sink (destination) buffer passed into the
sl@0
   153
	CMMFSwCodec::ProcessL method.  
sl@0
   154
sl@0
   155
	Note that this means that this is the Max size of each buffer passed to the codec.  The actual 
sl@0
   156
	size of the data written to this buffer could be less than the max size. This is a virtual 
sl@0
   157
	function that each derived class must implement.
sl@0
   158
sl@0
   159
	@return The max size of the sink buffer in bytes.
sl@0
   160
	*/
sl@0
   161
	virtual TUint SinkBufferSize() = 0;
sl@0
   162
sl@0
   163
	/**
sl@0
   164
	@internalAll
sl@0
   165
sl@0
   166
	Function that needs to be overriden if the codec is a 'Null' codec
sl@0
   167
	ie. it does not perform any data type transformation.  The 'Null' codec
sl@0
   168
	should override this to return ETrue and provide a dummy
sl@0
   169
	ProcessL. The CMMFSwCodecWrapper will then use the same buffer
sl@0
   170
	for both the source and the sink. Null codecs should return the same
sl@0
   171
	buffer size for both the Source and SinkBufferSize methods.
sl@0
   172
	Since most CMMFSwCodec implementations will not be null codecs
sl@0
   173
	this method can be ignored.
sl@0
   174
sl@0
   175
	Would not normally expect 3rd parties to have to implement this.
sl@0
   176
	*/
sl@0
   177
	virtual TBool IsNullCodec() {return EFalse;};
sl@0
   178
	};
sl@0
   179
sl@0
   180
sl@0
   181
//fwd declaration
sl@0
   182
class CRoutingSoundDeviceOpenHandler;
sl@0
   183
sl@0
   184
/** 
sl@0
   185
@publishedAll
sl@0
   186
@released
sl@0
   187
sl@0
   188
Class to make a CMMFSwCodec into a CMMFHwDevice ECOM plugin.
sl@0
   189
sl@0
   190
Most of the code to make a CMMFSwCodec into a CMMFHwDevice ECOM plugin is provided
sl@0
   191
in CMMFSwCodecWrapper.  Someone writing a plugin derrived from CMMFSwCodecWrapper
sl@0
   192
only needs to provide the standard ECOM implementation code, constructors
sl@0
   193
and destructors and implement the Codec() function which should return the
sl@0
   194
appropriate CMMFSwCodec.
sl@0
   195
sl@0
   196
Third parties using CMMFSwCodecWrapper that do not use the RMdaDevSound API
sl@0
   197
to talk to the sound drivers would need to port the datapaths for their own
sl@0
   198
sound drivers. Third parties would also need to change the custom interfaces
sl@0
   199
where necessary.
sl@0
   200
*/
sl@0
   201
class CMMFSwCodecWrapper : public CMMFHwDevice2
sl@0
   202
	{
sl@0
   203
public:
sl@0
   204
	IMPORT_C virtual ~CMMFSwCodecWrapper();
sl@0
   205
/**
sl@0
   206
@internalTechnology
sl@0
   207
*/
sl@0
   208
	TInt OpenComplete(TInt aError);	// Callback	
sl@0
   209
protected:
sl@0
   210
	IMPORT_C CMMFSwCodecWrapper();
sl@0
   211
	IMPORT_C virtual TInt Init(THwDeviceInitParams &aDevInfo);
sl@0
   212
	IMPORT_C virtual TInt Start(TDeviceFunc aFuncCmd, TDeviceFlow aFlowCmd);
sl@0
   213
	IMPORT_C virtual TInt Stop();
sl@0
   214
	IMPORT_C virtual TInt Pause();
sl@0
   215
	IMPORT_C virtual TAny* CustomInterface(TUid aInterfaceId);
sl@0
   216
	IMPORT_C virtual TInt ThisHwBufferFilled(CMMFBuffer& aFillBufferPtr);
sl@0
   217
	IMPORT_C virtual TInt ThisHwBufferEmptied(CMMFBuffer& aBuffer);
sl@0
   218
	IMPORT_C virtual TInt SetConfig(TTaskConfig& aConfig);
sl@0
   219
	IMPORT_C virtual TInt StopAndDeleteCodec();
sl@0
   220
	IMPORT_C virtual TInt DeleteCodec();
sl@0
   221
sl@0
   222
	/**
sl@0
   223
	This method must return the CMMFSwCodec used by the derived
sl@0
   224
	CMMFSwCodecWrapper class.  The method should create the CMMFSwCodec
sl@0
   225
	if it hasn't done so already.
sl@0
   226
sl@0
   227
	This is a virtual function that each derived class must implement.
sl@0
   228
sl@0
   229
	@return The CMMFSwCodec used by the derrived CMMFSwCodecWrapper
sl@0
   230
	*/
sl@0
   231
	virtual CMMFSwCodec& Codec() = 0;
sl@0
   232
sl@0
   233
	// from CMMFHwDevice2
sl@0
   234
	IMPORT_C virtual void Init(THwDeviceInitParams &aDevInfo, TRequestStatus& aStatus);
sl@0
   235
sl@0
   236
private:
sl@0
   237
	TInt StartEncode();
sl@0
   238
	TInt StartDecode();
sl@0
   239
	TInt StartConvert();
sl@0
   240
	// Async handlers
sl@0
   241
	TInt OpenPlayComplete(TInt aError);
sl@0
   242
	TInt OpenRecordComplete(TInt aError);
sl@0
   243
protected: 
sl@0
   244
	/** 
sl@0
   245
	The software codec used
sl@0
   246
	*/
sl@0
   247
	CMMFSwCodec* iCodec;
sl@0
   248
	
sl@0
   249
	/** 
sl@0
   250
	The source buffer for the codec
sl@0
   251
	*/
sl@0
   252
	CMMFDataBuffer* iSourceBuffer;
sl@0
   253
	
sl@0
   254
	/** 
sl@0
   255
	The sink buffer for the codec
sl@0
   256
	*/
sl@0
   257
	CMMFDataBuffer* iSinkBuffer;
sl@0
   258
	
sl@0
   259
	/** 
sl@0
   260
	The datapath used to transfer the data
sl@0
   261
	*/
sl@0
   262
	CMMFSwCodecDataPath* iDataPath;
sl@0
   263
	
sl@0
   264
	/** 
sl@0
   265
	The play custom interface
sl@0
   266
	*/
sl@0
   267
	MPlayCustomInterface* iPlayCustomInterface;
sl@0
   268
	
sl@0
   269
	/** 
sl@0
   270
	The record custom interface
sl@0
   271
	*/
sl@0
   272
	MRecordCustomInterface* iRecordCustomInterface;
sl@0
   273
	
sl@0
   274
	/** 
sl@0
   275
	The buffer size of the sound device
sl@0
   276
	*/
sl@0
   277
	TUint iDeviceBufferSize;
sl@0
   278
	
sl@0
   279
	/**
sl@0
   280
	The sample rate of the sound device
sl@0
   281
	*/
sl@0
   282
	TInt iSampleRate;
sl@0
   283
sl@0
   284
	/**
sl@0
   285
	The number of channels of the sound device
sl@0
   286
	*/
sl@0
   287
	TInt iChannels;
sl@0
   288
sl@0
   289
	/**
sl@0
   290
	The id device
sl@0
   291
	*/
sl@0
   292
	TUid iDeviceUid;
sl@0
   293
	
sl@0
   294
	/**
sl@0
   295
	*/
sl@0
   296
	CRoutingSoundPlayDevice* iPlayDevice;
sl@0
   297
	
sl@0
   298
	/**
sl@0
   299
	*/
sl@0
   300
	CRoutingSoundRecordDevice* iRecordDevice;
sl@0
   301
	
sl@0
   302
	/**
sl@0
   303
	*/
sl@0
   304
	CRoutingSoundDeviceOpenHandler* iOpenHandler;
sl@0
   305
	};
sl@0
   306
sl@0
   307
#endif
sl@0
   308