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