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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __MMFSWCODECWRAPPER_H__
17 #define __MMFSWCODECWRAPPER_H__
19 #include <mmf/server/mmfhwdevice.h>
20 #include <mmf/server/mmfhwdevicesetup.h>
22 class CMMFSwCodecDataPath; //forward reference
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.
32 A CMMFSwCodec object would usually not be instantiated directly
33 but instead would be instantiated via the CMMFSwCodecWrapper class's Codec()
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.
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
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
55 class CMMFSwCodec : public CBase
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.
68 class TCodecProcessResult
72 Flag to track the codec's processing status.
74 enum TCodecProcessResultStatus
76 /** The codec has successfully completed its processing. */
78 /** Could not empty the source buffer because the destination buffer became full. */
80 /** Codec came across an end of data. */
82 /** Could not fill the destination buffer because the source buffer has been emptied. */
84 /** An error occured. */
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);}
97 :iCodecProcessStatus(EProcessError), iSrcBytesProcessed(0), iDstBytesAdded(0) {};
101 The codec's processing status
103 @see enum TCodecProcessResultStatus
105 TCodecProcessResultStatus iCodecProcessStatus;
107 /** The number of source bytes processed */
108 TUint iSrcBytesProcessed;
110 /** The number of bytes added to the destination buffer */
111 TUint iDstBytesAdded;
116 Processes the data in the specified source buffer and writes the processed data to
117 the specified destination buffer.
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.
123 The source buffer containing data to encode or decode.
125 The destination buffer to hold the data after encoding or decoding.
127 @return The result of the processing.
129 @see TCodecProcessResult
131 virtual TCodecProcessResult ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest) = 0;
134 Gets the max size of the source buffer passed into the
135 CMMFSwCodec::ProcessL function.
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.
141 @return The max size of the source buffer in bytes.
143 virtual TUint SourceBufferSize() = 0;
146 Gets the max size of the sink (destination) buffer passed into the
147 CMMFSwCodec::ProcessL method.
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.
153 @return The max size of the sink buffer in bytes.
155 virtual TUint SinkBufferSize() = 0;
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.
169 Would not normally expect 3rd parties to have to implement this.
171 virtual TBool IsNullCodec() {return EFalse;};
178 Class to make a CMMFSwCodec into a CMMFHwDevice ECOM plugin.
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.
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
191 class CMMFSwCodecWrapper : public CMMFHwDevice
194 IMPORT_C virtual ~CMMFSwCodecWrapper();
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();
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.
212 This is a virtual function that each derived class must implement.
214 @return The CMMFSwCodec used by the derrived CMMFSwCodecWrapper
216 virtual CMMFSwCodec& Codec() = 0;
217 IMPORT_C void SetVbrFlag();
225 The software codec used
230 The source buffer for the codec
232 CMMFDataBuffer* iSourceBuffer;
235 The sink buffer for the codec
237 CMMFDataBuffer* iSinkBuffer;
240 The datapath used to transfer the data
242 CMMFSwCodecDataPath* iDataPath;
245 The play custom interface
247 MPlayCustomInterface* iPlayCustomInterface;
250 The record custom interface
252 MRecordCustomInterface* iRecordCustomInterface;
255 The buffer size of the sound device
257 TUint iDeviceBufferSize;
260 The sample rate of the sound device
265 The number of channels of the sound device