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