|
1 /* |
|
2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Client utility functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __S60AUDIOUTILITY_H__ |
|
20 #define __S60AUDIOUTILITY_H__ |
|
21 |
|
22 #include <mda/common/audio.h> |
|
23 #include <mda/common/gsmaudio.h> |
|
24 #include <mda/client/utility.h> |
|
25 #include <mmf/common/mmffourcc.h> |
|
26 #include <mmfformatimplementationuids.hrh> |
|
27 #include "mmf/common/mmfcontrollerpluginresolver.h" |
|
28 #include "mmf/server/mmffile.h" |
|
29 #include "mmf/server/mmfdes.h" |
|
30 #include "mmf/common/mmfcontroller.h" |
|
31 |
|
32 #include <f32file.h> |
|
33 #include <caf/content.h> |
|
34 #include <caf/data.h> |
|
35 |
|
36 |
|
37 class CMMSourceSink; // declared here. |
|
38 |
|
39 NONSHARABLE_CLASS( CMMSourceSink ): public CBase |
|
40 { |
|
41 public: |
|
42 IMPORT_C static CMMSourceSink* NewL(TUid aUid, const TDesC8& aDescriptor); |
|
43 IMPORT_C static CMMSourceSink* NewLC(TUid aUid, const TDesC8& aDescriptor); |
|
44 |
|
45 virtual ~CMMSourceSink(); |
|
46 virtual TUid SourceSinkUid() const; |
|
47 virtual const TDesC8& SourceSinkData() const; |
|
48 |
|
49 virtual void EvaluateIntentL(); |
|
50 protected: |
|
51 CMMSourceSink(TUid aUid); |
|
52 |
|
53 |
|
54 private: |
|
55 void ConstructL(const TDesC8& aDescriptor); |
|
56 |
|
57 const TUid iUid; |
|
58 HBufC8* iBuf; |
|
59 }; |
|
60 |
|
61 |
|
62 |
|
63 #ifdef SYMBIAN_CAF_V2 |
|
64 |
|
65 class CMMFileSourceSink; // declared here. |
|
66 |
|
67 NONSHARABLE_CLASS( CMMFileSourceSink ): public CMMSourceSink |
|
68 { |
|
69 public: |
|
70 IMPORT_C static CMMFileSourceSink* NewL(TUid aUid, const RFile& aFile); |
|
71 IMPORT_C static CMMFileSourceSink* NewLC(TUid aUid, const RFile& aFile); |
|
72 |
|
73 IMPORT_C static CMMFileSourceSink* NewL(TUid aUid, const TMMSource& aMMSource); |
|
74 IMPORT_C static CMMFileSourceSink* NewLC(TUid aUid, const TMMSource& aMMSource); |
|
75 |
|
76 const TDesC& UniqueId() const {return *iUniqueId;} |
|
77 |
|
78 virtual ~CMMFileSourceSink(); |
|
79 |
|
80 const TDesC& FileName() const {return *iFileName;} |
|
81 const TDesC8& SourceSinkData() const; |
|
82 |
|
83 IMPORT_C void EvaluateIntentL(ContentAccess::TIntent aIntent); |
|
84 virtual void EvaluateIntentL(); |
|
85 |
|
86 protected: |
|
87 CMMFileSourceSink(TUid aUid); |
|
88 |
|
89 private: |
|
90 void ConstructL(const TMMSource& aSource); |
|
91 void DoCreateFileSourceConfigDataL(); |
|
92 void ConstructL(const RFile& aFile); |
|
93 void DoCreateFileHandleSourceConfigDataL(); |
|
94 |
|
95 TBool iUsingFileHandle; |
|
96 RFile iHandle; |
|
97 HBufC* iFileName; |
|
98 HBufC8* iSourceSinkData; |
|
99 HBufC* iUniqueId; |
|
100 ContentAccess::TIntent iIntent; |
|
101 TBool iEnableUI; |
|
102 }; |
|
103 |
|
104 #endif |
|
105 |
|
106 |
|
107 class CMMFMdaObjectStateChangeObserverCallback; // declared here. |
|
108 /** |
|
109 Active object utility class to allow the callback to be called asynchronously. |
|
110 This should help prevent re-entrant code in clients of the mediaframework. |
|
111 */ |
|
112 NONSHARABLE_CLASS( CMMFMdaObjectStateChangeObserverCallback ): public CActive |
|
113 { |
|
114 public: |
|
115 IMPORT_C static CMMFMdaObjectStateChangeObserverCallback* NewL(MMdaObjectStateChangeObserver& aCallback); |
|
116 virtual ~CMMFMdaObjectStateChangeObserverCallback(); |
|
117 IMPORT_C void CallBack(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode); |
|
118 private: |
|
119 CMMFMdaObjectStateChangeObserverCallback(MMdaObjectStateChangeObserver& aCallback); |
|
120 void RunL(); |
|
121 void DoCancel(); |
|
122 private: |
|
123 MMdaObjectStateChangeObserver& iCallback; |
|
124 CBase* iObject; |
|
125 TInt iPreviousState; |
|
126 TInt iCurrentState; |
|
127 TInt iErrorCode; |
|
128 }; |
|
129 |
|
130 class CMMFClientUtility; // declared here. |
|
131 |
|
132 NONSHARABLE_CLASS( CMMFClientUtility ) |
|
133 { |
|
134 public: |
|
135 IMPORT_C static TUid ConvertMdaFormatUidToECOMWrite(TUid aMdaFormatUid); |
|
136 IMPORT_C static TUid ConvertMdaFormatUidToECOMRead(TUid aMdaFormatUid); |
|
137 IMPORT_C static TFourCC ConvertMdaCodecToFourCC(TMdaPackage& aCodec); |
|
138 IMPORT_C static TInt GetFileHeaderData(const TDesC& aFileName, TDes8& aHeaderData, TInt aMaxLength); |
|
139 IMPORT_C static HBufC8* GetFileExtensionL(const TDesC& aFileName); |
|
140 static void PrioritiseControllersL( |
|
141 const RMMFControllerImplInfoArray& aControllers, |
|
142 const TDesC8& aHeaderDataPlayback, |
|
143 const TDesC8& aFileExtensionPlayback, |
|
144 const TDesC8& aHeaderDataRecord, |
|
145 const TDesC8& aFileExtensionRecord, |
|
146 RMMFControllerImplInfoArray& aPrioritisedControllers); |
|
147 static TInt GetBestMatchL(const CMMFFormatImplementationInformation* format, const TDesC8& aHeaderData, const TDesC8& aFileExtension); |
|
148 |
|
149 private: |
|
150 CMMFClientUtility(); |
|
151 }; |
|
152 |
|
153 class CMMFUtilityFileInfo; // declared here. |
|
154 |
|
155 NONSHARABLE_CLASS( CMMFUtilityFileInfo ): public CBase |
|
156 { |
|
157 public: |
|
158 |
|
159 static CMMFUtilityFileInfo* NewL(TMMSource& aSource); |
|
160 static CMMFUtilityFileInfo* NewLC(TMMSource& aSource); |
|
161 |
|
162 ~CMMFUtilityFileInfo(); |
|
163 |
|
164 TBool GetFileMimeTypeL(TDes8& aMimeType); |
|
165 void GetFileHeaderDataL(TDes8& aHeaderData, TInt aMaxLength); |
|
166 TInt EvaluateIntent(ContentAccess::TIntent aIntent); |
|
167 |
|
168 private: |
|
169 CMMFUtilityFileInfo(); |
|
170 |
|
171 void ConstructL(const TMMSource& aSource); |
|
172 |
|
173 private: |
|
174 ContentAccess::CData* iData; |
|
175 }; |
|
176 |
|
177 inline CMMFUtilityFileInfo::CMMFUtilityFileInfo() |
|
178 { |
|
179 }; |
|
180 |
|
181 /** |
|
182 * Mixin class that the user of the class CMMFFindAndOpenController must derive from. |
|
183 * @internalComponent |
|
184 */ |
|
185 class MMMFFindAndOpenControllerObserver |
|
186 { |
|
187 public: |
|
188 /** |
|
189 * Callback function to indicate the success or failure |
|
190 * of an attempt to find and open a suitable controller and |
|
191 * to add a source and sink. |
|
192 * @see CMMFFindAndOpenController |
|
193 * |
|
194 * @param aError |
|
195 * Indicates whether a controller has been opened sucessfully |
|
196 * This is passed by reference, mainly for the audio recorder utility |
|
197 * which opens two controllers: if the secondary controller (which is |
|
198 * always opened first) fails to open, then the audio recorder utility |
|
199 * may choose to set aError = KErrNone in the MfaocComplete() callback |
|
200 * to indicate to CFindAndOpenControler() that it should continue |
|
201 * to open the primary controller, even though opening the secondary failed. |
|
202 * @param aController |
|
203 * A pointer to the controller that has been opened or has failed to open |
|
204 * This is mainly for the audio recorder utility to indicate |
|
205 * which controller (primary or secondary) has been opened. |
|
206 * @param aControllerUid |
|
207 * the UID of the controller that has been opened |
|
208 * @param aSourceHandle |
|
209 * a pointer to the source handle |
|
210 * @internalComponent |
|
211 * a pointer to the sink handle |
|
212 */ |
|
213 virtual void MfaocComplete( |
|
214 TInt& aError, |
|
215 RMMFController* aController, |
|
216 TUid aControllerUid = KNullUid, |
|
217 TMMFMessageDestination* aSourceHandle = NULL, |
|
218 TMMFMessageDestination* aSinkHandle = NULL) = 0; |
|
219 }; |
|
220 |
|
221 |
|
222 class CMMFFindAndOpenController; // declared here. |
|
223 /** |
|
224 * Utility class used by the MMF client API classes. |
|
225 * Finds and opens a suitable controller and adds a source and a sink |
|
226 * asynchronously. Completion is indicated asynchronously |
|
227 * using the MMMFFindAndOpenControllerObserver mixin class. |
|
228 * |
|
229 * @internalComponent |
|
230 */ |
|
231 NONSHARABLE_CLASS( CMMFFindAndOpenController ): public CActive, public MMMFAddDataSourceSinkAsyncObserver |
|
232 { |
|
233 public: |
|
234 enum TControllerMode |
|
235 { |
|
236 EPlayback, |
|
237 ERecord, |
|
238 EConvert |
|
239 }; |
|
240 |
|
241 enum TControllerNumber |
|
242 { |
|
243 EPrimaryController, |
|
244 ESecondaryController |
|
245 }; |
|
246 |
|
247 class TSourceSink |
|
248 { |
|
249 public: |
|
250 IMPORT_C TSourceSink(TUid aUid, const TDesC8& aData = KNullDesC8); |
|
251 IMPORT_C TSourceSink(TUid aUid, const RFile& aFile); |
|
252 |
|
253 TUid iUid; |
|
254 const TDesC8& iConfigData; |
|
255 TBool iUseFileHandle; |
|
256 RFile iFileHandle; |
|
257 }; |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 public: |
|
263 IMPORT_C static CMMFFindAndOpenController* NewL(MMMFFindAndOpenControllerObserver& aObserver); |
|
264 virtual ~CMMFFindAndOpenController(); |
|
265 |
|
266 // from CActive |
|
267 virtual void DoCancel(); |
|
268 virtual void RunL(); |
|
269 |
|
270 // from MMMFAddDataSourceSinkAsyncObserver |
|
271 virtual void MadssaoAddDataSourceSinkAsyncComplete(TInt aError, const TMMFMessageDestination& aHandle); |
|
272 |
|
273 IMPORT_C void Configure( |
|
274 TUid aMediaId, |
|
275 TMMFPrioritySettings aPrioritySettings, |
|
276 CMMFPluginSelectionParameters::TMediaIdMatchType aMediaIdMatchType = CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds); |
|
277 |
|
278 IMPORT_C void ConfigureController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback); |
|
279 IMPORT_C void ConfigureSecondaryController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback); |
|
280 IMPORT_C void ConfigureSourceSink( |
|
281 TSourceSink aSource, |
|
282 TSourceSink aSink); |
|
283 IMPORT_C void ConfigureSecondarySourceSink( |
|
284 TSourceSink aSource, |
|
285 TSourceSink aSink); |
|
286 |
|
287 #ifdef SYMBIAN_CAF_V2 |
|
288 IMPORT_C void ConfigureSourceSink( |
|
289 const TMMSource& aSource, |
|
290 TSourceSink aSink); |
|
291 #endif |
|
292 |
|
293 #ifdef SYMBIAN_CAF_V2 |
|
294 IMPORT_C void OpenByFileSource(const TMMSource& aFileSource, const TDesC& aFileNameSecondary = KNullDesC); |
|
295 #else |
|
296 IMPORT_C void OpenByFilename(const TDesC& aFileName, const TDesC& aFileNameSecondary = KNullDesC); |
|
297 IMPORT_C void OpenByFileHandle(const RFile& aFile); |
|
298 #endif |
|
299 |
|
300 IMPORT_C void OpenByFormatUid(TUid aFormatUid, TUid aFormatUidSecondary = KNullUid); |
|
301 IMPORT_C void OpenByDescriptor(const TDesC8& aDescriptor); |
|
302 IMPORT_C void OpenByUrl(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType); |
|
303 IMPORT_C void OpenByControllerUid(TUid aControllerUid, TUid aSecondaryControllerUid = KNullUid); |
|
304 IMPORT_C void OpenByMimeType(const TDesC8& aMimeType); |
|
305 |
|
306 IMPORT_C void FindByMimeTypeL(const TDesC8& aMimeType); |
|
307 IMPORT_C void OpenController(); |
|
308 |
|
309 IMPORT_C void ReOpen(); |
|
310 IMPORT_C void Close(); |
|
311 |
|
312 IMPORT_C static TMMFFileConfig GetConfigFile(const TDesC& aFileName); |
|
313 IMPORT_C static TMMFDescriptorConfig GetConfigDescriptor(const TDesC8& aDescriptor); |
|
314 IMPORT_C static TInt GetConfigUrl(CBufFlat*& aUrlCfgBuffer, const TDesC& aUrl, TInt aIapId); |
|
315 |
|
316 private: |
|
317 class CConfig: public CBase |
|
318 { |
|
319 public: |
|
320 CConfig(); |
|
321 ~CConfig(); |
|
322 void Close(); |
|
323 public: |
|
324 RMMFController* iController; // not owned |
|
325 CMMFControllerEventMonitor* iEventMonitor; // not owned |
|
326 |
|
327 /** indicates whether this controller is being used for |
|
328 playback, recording or converting */ |
|
329 TControllerMode iControllerMode; |
|
330 |
|
331 CMMSourceSink* iSource; |
|
332 CMMSourceSink* iSink; |
|
333 TUid iControllerUid; |
|
334 }; |
|
335 |
|
336 CMMFFindAndOpenController(MMMFFindAndOpenControllerObserver& aObserver); |
|
337 void ConstructL(); |
|
338 |
|
339 void Init(); |
|
340 |
|
341 void ConfigureSourceSink( |
|
342 CConfig& config, |
|
343 TSourceSink aSource, |
|
344 TSourceSink aSink); |
|
345 |
|
346 #ifdef SYMBIAN_CAF_V2 |
|
347 void ConfigureSourceSink( |
|
348 CConfig& config, |
|
349 const TMMSource& aSource, |
|
350 TSourceSink aSink); |
|
351 #endif |
|
352 |
|
353 |
|
354 void ConfigureController( |
|
355 CConfig& config, |
|
356 RMMFController& aController, |
|
357 CMMFControllerEventMonitor& aEventMonitor, |
|
358 TControllerMode aControllerMode); |
|
359 |
|
360 void CloseController(); |
|
361 |
|
362 void OpenPrimaryController(void); |
|
363 |
|
364 void KickState(); |
|
365 void Process(); |
|
366 void SendError(TInt aError = KErrNone); |
|
367 void SchedSendError(TInt aError = KErrNone); |
|
368 void BuildControllerListFileNameL(); |
|
369 void BuildControllerListDescriptorL(); |
|
370 void BuildControllerListUrlL(); |
|
371 void BuildControllerListFormatL(); |
|
372 void BuildControllerListMimeTypeL(); |
|
373 void TryNextController(); |
|
374 |
|
375 CMMSourceSink* CreateSourceSinkL(const TSourceSink& aParams); |
|
376 #ifdef SYMBIAN_CAF_V2 |
|
377 CMMSourceSink* CreateSourceSinkL(const TMMSource& aSource); |
|
378 #endif |
|
379 |
|
380 private: |
|
381 /** primary controller details */ |
|
382 CConfig* iPrimaryConfig; |
|
383 /** secondary controller details */ |
|
384 CConfig* iSecondaryConfig; |
|
385 /** points to either iPrimaryConfig or iSecondaryConfig */ |
|
386 CConfig* iCurrentConfig; // not owned |
|
387 |
|
388 enum TMode |
|
389 { |
|
390 EOpenByControllerUid, |
|
391 EOpenByFileName, |
|
392 EOpenByDescriptor, |
|
393 EOpenByUrl, |
|
394 EOpenByFormatUid, |
|
395 EOpenByMimeType |
|
396 }; |
|
397 TMode iMode; |
|
398 |
|
399 /** indicates what state the state machine is in */ |
|
400 enum TState |
|
401 { |
|
402 EIdle, |
|
403 EBuildControllerList, |
|
404 EOpenController, |
|
405 EAddSource, |
|
406 EAddSink, |
|
407 EWaitingForSource, |
|
408 EWaitingForSink, |
|
409 ESendError |
|
410 }; |
|
411 TState iState; |
|
412 |
|
413 MMMFFindAndOpenControllerObserver& iObserver; |
|
414 CMMFAddDataSourceSinkAsync* iAddDataSourceSinkAsync; |
|
415 |
|
416 TInt iControllerIndex; |
|
417 TInt iControllerCount; |
|
418 |
|
419 TFileName iFileNameSecondary; // for converting |
|
420 |
|
421 TFileName iFileName; |
|
422 TBool iUseFileHandle; |
|
423 TBool iUseFileSource; |
|
424 HBufC* iUniqueId; |
|
425 RFile iFileHandle; |
|
426 ContentAccess::TIntent iIntent; |
|
427 |
|
428 HBufC* iUrl; |
|
429 HBufC8* iMimeType; |
|
430 TPtr8 iDescriptor; |
|
431 TInt iIapId; |
|
432 TUid iFormatUid; |
|
433 TUid iFormatUidSecondary; // for converting |
|
434 |
|
435 TUid iMediaId; |
|
436 TMMFPrioritySettings iPrioritySettings; |
|
437 CMMFPluginSelectionParameters::TMediaIdMatchType iMediaIdMatchType; |
|
438 |
|
439 RMMFControllerImplInfoArray iControllers; |
|
440 RMMFControllerImplInfoArray iPrioritisedControllers; |
|
441 |
|
442 // if this is non-null, then it points to an element in |
|
443 // either iControllers or iPrioritisedControllers |
|
444 CMMFControllerImplementationInformation* iControllerImplInfo; // not owned |
|
445 |
|
446 TControllerMode iControllerMode; |
|
447 TBool iSourceSinkConfigured; |
|
448 TInt iError; |
|
449 |
|
450 TMMFMessageDestination iSourceHandle; |
|
451 TMMFMessageDestination iSinkHandle; |
|
452 }; |
|
453 |
|
454 #endif //__S60AUDIOUTILITY_H__ |
|
455 |
|
456 // End of File |