|
1 /* |
|
2 * Copyright (c) 2004 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: Progressive Download Utility Client utility functions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __MMF_CLIENT_UTILITY_H__ |
|
21 #define __MMF_CLIENT_UTILITY_H__ |
|
22 |
|
23 #include <mda/common/audio.h> |
|
24 #include <mda/common/gsmaudio.h> |
|
25 #include <mda/client/utility.h> |
|
26 #include <mmf/common/mmffourcc.h> |
|
27 #include <mmfformatimplementationuids.hrh> |
|
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 static CMMSourceSink* NewL(TUid aUid, const TDesC8& aDescriptor); |
|
43 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 |
|
64 |
|
65 class CMMFileSourceSink; // declared here. |
|
66 |
|
67 NONSHARABLE_CLASS( CMMFileSourceSink ): public CMMSourceSink |
|
68 { |
|
69 public: |
|
70 static CMMFileSourceSink* NewL(TUid aUid, const RFile& aFile); |
|
71 static CMMFileSourceSink* NewLC(TUid aUid, const RFile& aFile); |
|
72 |
|
73 static CMMFileSourceSink* NewL(TUid aUid, const TMMSource& aMMSource); |
|
74 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 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 |
|
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 static CMMFMdaObjectStateChangeObserverCallback* NewL(MMdaObjectStateChangeObserver& aCallback); |
|
116 virtual ~CMMFMdaObjectStateChangeObserverCallback(); |
|
117 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 static TUid ConvertMdaFormatUidToECOMWrite(TUid aMdaFormatUid); |
|
136 static TUid ConvertMdaFormatUidToECOMRead(TUid aMdaFormatUid); |
|
137 static TFourCC ConvertMdaCodecToFourCC(TMdaPackage& aCodec); |
|
138 static TInt GetFileHeaderData(const TDesC& aFileName, TDes8& aHeaderData, TInt aMaxLength); |
|
139 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 TSourceSink(TUid aUid, const TDesC8& aData = KNullDesC8); |
|
251 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 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 void Configure( |
|
274 TUid aMediaId, |
|
275 TMMFPrioritySettings aPrioritySettings, |
|
276 CMMFPluginSelectionParameters::TMediaIdMatchType aMediaIdMatchType = CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds); |
|
277 |
|
278 void ConfigureController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback); |
|
279 void ConfigureSecondaryController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback); |
|
280 void ConfigureSourceSink( |
|
281 TSourceSink aSource, |
|
282 TSourceSink aSink); |
|
283 void ConfigureSecondarySourceSink( |
|
284 TSourceSink aSource, |
|
285 TSourceSink aSink); |
|
286 |
|
287 |
|
288 void ConfigureSourceSink( |
|
289 const TMMSource& aSource, |
|
290 TSourceSink aSink); |
|
291 |
|
292 |
|
293 |
|
294 void OpenByFileSource(const TMMSource& aFileSource, const TDesC& aFileNameSecondary = KNullDesC); |
|
295 |
|
296 void OpenByFilename(const TDesC& aFileName, const TDesC& aFileNameSecondary = KNullDesC); |
|
297 void OpenByFileHandle(const RFile& aFile); |
|
298 |
|
299 |
|
300 void OpenByFormatUid(TUid aFormatUid, TUid aFormatUidSecondary = KNullUid); |
|
301 void OpenByDescriptor(const TDesC8& aDescriptor); |
|
302 void OpenByUrl(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType); |
|
303 void OpenByControllerUid(TUid aControllerUid, TUid aSecondaryControllerUid = KNullUid); |
|
304 void ReOpen(); |
|
305 void Close(); |
|
306 |
|
307 static TMMFFileConfig GetConfigFile(const TDesC& aFileName); |
|
308 static TMMFDescriptorConfig GetConfigDescriptor(const TDesC8& aDescriptor); |
|
309 static TInt GetConfigUrl(CBufFlat*& aUrlCfgBuffer, const TDesC& aUrl, TInt aIapId); |
|
310 |
|
311 private: |
|
312 class CConfig: public CBase |
|
313 { |
|
314 public: |
|
315 CConfig(); |
|
316 ~CConfig(); |
|
317 void Close(); |
|
318 public: |
|
319 RMMFController* iController; // not owned |
|
320 CMMFControllerEventMonitor* iEventMonitor; // not owned |
|
321 |
|
322 /** indicates whether this controller is being used for |
|
323 playback, recording or converting */ |
|
324 TControllerMode iControllerMode; |
|
325 |
|
326 CMMSourceSink* iSource; |
|
327 CMMSourceSink* iSink; |
|
328 TUid iControllerUid; |
|
329 }; |
|
330 |
|
331 CMMFFindAndOpenController(MMMFFindAndOpenControllerObserver& aObserver); |
|
332 void ConstructL(); |
|
333 |
|
334 void Init(); |
|
335 |
|
336 void ConfigureSourceSink( |
|
337 CConfig& config, |
|
338 TSourceSink aSource, |
|
339 TSourceSink aSink); |
|
340 |
|
341 |
|
342 void ConfigureSourceSink( |
|
343 CConfig& config, |
|
344 const TMMSource& aSource, |
|
345 TSourceSink aSink); |
|
346 |
|
347 |
|
348 |
|
349 void ConfigureController( |
|
350 CConfig& config, |
|
351 RMMFController& aController, |
|
352 CMMFControllerEventMonitor& aEventMonitor, |
|
353 TControllerMode aControllerMode); |
|
354 |
|
355 void CloseController(); |
|
356 |
|
357 void OpenPrimaryController(void); |
|
358 |
|
359 void KickState(); |
|
360 void Process(); |
|
361 void SendError(TInt aError = KErrNone); |
|
362 void SchedSendError(TInt aError = KErrNone); |
|
363 void BuildControllerListFileNameL(); |
|
364 void BuildControllerListDescriptorL(); |
|
365 void BuildControllerListUrlL(); |
|
366 void BuildControllerListFormatL(); |
|
367 void TryNextController(); |
|
368 |
|
369 CMMSourceSink* CreateSourceSinkL(const TSourceSink& aParams); |
|
370 |
|
371 CMMSourceSink* CreateSourceSinkL(const TMMSource& aSource); |
|
372 |
|
373 |
|
374 private: |
|
375 /** primary controller details */ |
|
376 CConfig* iPrimaryConfig; |
|
377 /** secondary controller details */ |
|
378 CConfig* iSecondaryConfig; |
|
379 /** points to either iPrimaryConfig or iSecondaryConfig */ |
|
380 CConfig* iCurrentConfig; // not owned |
|
381 |
|
382 enum TMode |
|
383 { |
|
384 EOpenByControllerUid, |
|
385 EOpenByFileName, |
|
386 EOpenByDescriptor, |
|
387 EOpenByUrl, |
|
388 EOpenByFormatUid |
|
389 }; |
|
390 TMode iMode; |
|
391 |
|
392 /** indicates what state the state machine is in */ |
|
393 enum TState |
|
394 { |
|
395 EIdle, |
|
396 EBuildControllerList, |
|
397 EOpenController, |
|
398 EAddSource, |
|
399 EAddSink, |
|
400 EWaitingForSource, |
|
401 EWaitingForSink, |
|
402 ESendError |
|
403 }; |
|
404 TState iState; |
|
405 |
|
406 MMMFFindAndOpenControllerObserver& iObserver; |
|
407 CMMFAddDataSourceSinkAsync* iAddDataSourceSinkAsync; |
|
408 |
|
409 TInt iControllerIndex; |
|
410 TInt iControllerCount; |
|
411 |
|
412 TFileName iFileNameSecondary; // for converting |
|
413 |
|
414 TFileName iFileName; |
|
415 TBool iUseFileHandle; |
|
416 TBool iUseFileSource; |
|
417 HBufC* iUniqueId; |
|
418 RFile iFileHandle; |
|
419 ContentAccess::TIntent iIntent; |
|
420 |
|
421 HBufC* iUrl; |
|
422 HBufC8* iMimeType; |
|
423 TPtr8 iDescriptor; |
|
424 TInt iIapId; |
|
425 TUid iFormatUid; |
|
426 TUid iFormatUidSecondary; // for converting |
|
427 |
|
428 TUid iMediaId; |
|
429 TMMFPrioritySettings iPrioritySettings; |
|
430 CMMFPluginSelectionParameters::TMediaIdMatchType iMediaIdMatchType; |
|
431 |
|
432 RMMFControllerImplInfoArray iControllers; |
|
433 RMMFControllerImplInfoArray iPrioritisedControllers; |
|
434 |
|
435 // if this is non-null, then it points to an element in |
|
436 // either iControllers or iPrioritisedControllers |
|
437 CMMFControllerImplementationInformation* iControllerImplInfo; // not owned |
|
438 |
|
439 TControllerMode iControllerMode; |
|
440 TBool iSourceSinkConfigured; |
|
441 TInt iError; |
|
442 |
|
443 TMMFMessageDestination iSourceHandle; |
|
444 TMMFMessageDestination iSinkHandle; |
|
445 }; |
|
446 |
|
447 #endif |