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