First public contribution.
1 // Copyright (c) 2002-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Client utility functions
18 #ifndef __MMF_CLIENT_UTILITY_H__
19 #define __MMF_CLIENT_UTILITY_H__
21 #include <mda/common/audio.h>
22 #include <mda/common/gsmaudio.h>
23 #include <mda/client/utility.h>
24 #include <mmf/common/mmffourcc.h>
25 #include <mmfformatimplementationuids.hrh>
26 #include "mmf/common/mmfcontrollerpluginresolver.h"
27 #include <mmf/server/mmffile.h>
28 #include <mmf/server/mmfdes.h>
29 #include "mmf/common/mmfcontroller.h"
32 #include <caf/content.h>
34 #include <mmf/common/mmfstandardcustomcommands.h>
35 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
36 #include <mmf/common/mmfstandardcustomcommandsenums.h>
37 #include <mmf/common/mmfstandardcustomcommandsimpl.h>
39 #ifdef SYMBIAN_BUILD_GCE
40 #include <mmf/common/mmfvideosurfacecustomcommands.h>
43 class CMMSourceSink; // declared here.
45 NONSHARABLE_CLASS( CMMSourceSink ): public CBase
48 IMPORT_C static CMMSourceSink* NewL(TUid aUid, const TDesC8& aDescriptor);
49 IMPORT_C static CMMSourceSink* NewLC(TUid aUid, const TDesC8& aDescriptor);
51 virtual ~CMMSourceSink();
52 virtual TUid SourceSinkUid() const;
53 virtual const TDesC8& SourceSinkData() const;
55 virtual TBool CarryingFileHandle() const;
57 virtual void EvaluateIntentL();
59 CMMSourceSink(TUid aUid);
63 void ConstructL(const TDesC8& aDescriptor);
72 class CMMFileSourceSink; // declared here.
74 NONSHARABLE_CLASS( CMMFileSourceSink ): public CMMSourceSink
77 IMPORT_C static CMMFileSourceSink* NewL(TUid aUid, const RFile& aFile);
78 IMPORT_C static CMMFileSourceSink* NewLC(TUid aUid, const RFile& aFile);
80 IMPORT_C static CMMFileSourceSink* NewL(TUid aUid, const TMMSource& aMMSource);
81 IMPORT_C static CMMFileSourceSink* NewLC(TUid aUid, const TMMSource& aMMSource);
83 const TDesC& UniqueId() const {return *iUniqueId;}
85 virtual ~CMMFileSourceSink();
87 const TDesC& FileName() const {return *iFileName;}
88 const TDesC8& SourceSinkData() const;
90 IMPORT_C void EvaluateIntentL(ContentAccess::TIntent aIntent);
91 virtual void EvaluateIntentL();
93 TBool CarryingFileHandle() const;
95 TBool UsingFileHandle() const {return iUsingFileHandle;};
96 const RFile& FileHandle() const {return iHandle;};
98 CMMFileSourceSink(TUid aUid);
101 void ConstructL(const TMMSource& aSource);
102 void DoCreateFileSourceConfigDataL();
103 void ConstructL(const RFile& aFile);
104 void DoCreateFileHandleSourceConfigDataL();
106 TBool iUsingFileHandle;
109 HBufC8* iSourceSinkData;
111 ContentAccess::TIntent iIntent;
118 class CMMFMdaObjectStateChangeObserverCallback; // declared here.
120 Active object utility class to allow the callback to be called asynchronously.
121 This should help prevent re-entrant code in clients of the mediaframework.
123 NONSHARABLE_CLASS( CMMFMdaObjectStateChangeObserverCallback ): public CActive
126 IMPORT_C static CMMFMdaObjectStateChangeObserverCallback* NewL(MMdaObjectStateChangeObserver& aCallback);
127 virtual ~CMMFMdaObjectStateChangeObserverCallback();
128 IMPORT_C void CallBack(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode);
130 CMMFMdaObjectStateChangeObserverCallback(MMdaObjectStateChangeObserver& aCallback);
134 MMdaObjectStateChangeObserver& iCallback;
141 class CMMFClientUtility; // declared here.
143 NONSHARABLE_CLASS( CMMFClientUtility )
146 IMPORT_C static TUid ConvertMdaFormatUidToECOMWrite(TUid aMdaFormatUid);
147 IMPORT_C static TUid ConvertMdaFormatUidToECOMRead(TUid aMdaFormatUid);
148 IMPORT_C static TFourCC ConvertMdaCodecToFourCC(TMdaPackage& aCodec);
149 IMPORT_C static TInt GetFileHeaderData(const TDesC& aFileName, TDes8& aHeaderData, TInt aMaxLength);
150 IMPORT_C static HBufC8* GetFileExtensionL(const TDesC& aFileName);
151 static void PrioritiseControllersL(
152 const RMMFControllerImplInfoArray& aControllers,
153 const TDesC8& aHeaderDataPlayback,
154 const TDesC8& aFileExtensionPlayback,
155 const TDesC8& aHeaderDataRecord,
156 const TDesC8& aFileExtensionRecord,
157 RMMFControllerImplInfoArray& aPrioritisedControllers);
158 static TInt GetBestMatchL(const CMMFFormatImplementationInformation* format, const TDesC8& aHeaderData, const TDesC8& aFileExtension);
164 class CMMFUtilityFileInfo; // declared here.
165 class RMMFDRMPluginServerProxy;
167 NONSHARABLE_CLASS( CMMFUtilityFileInfo ): public CBase
171 static CMMFUtilityFileInfo* NewL(TMMSource& aSource, TBool aSecureDRMMode = EFalse);
172 static CMMFUtilityFileInfo* NewLC(TMMSource& aSource, TBool aSecureDRMMode = EFalse);
174 ~CMMFUtilityFileInfo();
176 TBool GetFileMimeTypeL(TDes8& aMimeType);
177 void GetFileHeaderDataL(TDes8& aHeaderData, TInt aMaxLength);
178 TInt EvaluateIntent(ContentAccess::TIntent aIntent);
181 CMMFUtilityFileInfo();
183 void ConstructL(const TMMSource& aSource, TBool aSecureDRMMode);
186 ContentAccess::CData* iData;
187 RMMFDRMPluginServerProxy* iDrmPluginServer;
190 inline CMMFUtilityFileInfo::CMMFUtilityFileInfo()
195 * Mixin class that the user of the class CMMFFindAndOpenController must derive from.
198 class MMMFFindAndOpenControllerObserver
202 * Callback function to indicate the success or failure
203 * of an attempt to find and open a suitable controller and
204 * to add a source and sink.
205 * @see CMMFFindAndOpenController
208 * Indicates whether a controller has been opened sucessfully
209 * This is passed by reference, mainly for the audio recorder utility
210 * which opens two controllers: if the secondary controller (which is
211 * always opened first) fails to open, then the audio recorder utility
212 * may choose to set aError = KErrNone in the MfaocComplete() callback
213 * to indicate to CFindAndOpenControler() that it should continue
214 * to open the primary controller, even though opening the secondary failed.
216 * A pointer to the controller that has been opened or has failed to open
217 * This is mainly for the audio recorder utility to indicate
218 * which controller (primary or secondary) has been opened.
219 * @param aControllerUid
220 * the UID of the controller that has been opened
221 * @param aSourceHandle
222 * a pointer to the source handle
224 * a pointer to the sink handle
226 virtual void MfaocComplete(
228 RMMFController* aController,
229 TUid aControllerUid = KNullUid,
230 TMMFMessageDestination* aSourceHandle = NULL,
231 TMMFMessageDestination* aSinkHandle = NULL) = 0;
235 class CMMFFindAndOpenController; // declared here.
237 * Utility class used by the MMF client API classes.
238 * Finds and opens a suitable controller and adds a source and a sink
239 * asynchronously. Completion is indicated asynchronously
240 * using the MMMFFindAndOpenControllerObserver mixin class.
244 NONSHARABLE_CLASS( CMMFFindAndOpenController ): public CActive, public MMMFAddDataSourceSinkAsyncObserver
254 enum TControllerNumber
263 IMPORT_C TSourceSink(TUid aUid, const TDesC8& aData = KNullDesC8);
264 IMPORT_C TSourceSink(TUid aUid, const RFile& aFile);
267 const TDesC8& iConfigData;
268 TBool iUseFileHandle;
276 IMPORT_C static CMMFFindAndOpenController* NewL(MMMFFindAndOpenControllerObserver& aObserver);
277 virtual ~CMMFFindAndOpenController();
280 virtual void DoCancel();
283 // from MMMFAddDataSourceSinkAsyncObserver
284 virtual void MadssaoAddDataSourceSinkAsyncComplete(TInt aError, const TMMFMessageDestination& aHandle);
286 IMPORT_C void Configure(
288 TMMFPrioritySettings aPrioritySettings,
289 CMMFPluginSelectionParameters::TMediaIdMatchType aMediaIdMatchType = CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds);
291 IMPORT_C void ConfigureController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback);
292 IMPORT_C void ConfigureSecondaryController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback);
294 IMPORT_C void UseSharedHeap();
296 IMPORT_C void ConfigureSourceSink(
299 IMPORT_C void ConfigureSecondarySourceSink(
303 IMPORT_C void ConfigureSourceSink(
304 const TMMSource& aSource,
307 IMPORT_C void OpenByFileSource(const TMMSource& aFileSource, const TDesC& aFileNameSecondary = KNullDesC);
309 IMPORT_C void OpenByFormatUid(TUid aFormatUid, TUid aFormatUidSecondary = KNullUid);
310 IMPORT_C void OpenByDescriptor(const TDesC8& aDescriptor);
311 IMPORT_C void OpenByUrl(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType);
312 IMPORT_C void OpenByControllerUid(TUid aControllerUid, TUid aSecondaryControllerUid = KNullUid);
313 IMPORT_C void ReOpen();
314 IMPORT_C void Close();
316 IMPORT_C static TMMFFileConfig GetConfigFile(const TDesC& aFileName);
317 IMPORT_C static TMMFDescriptorConfig GetConfigDescriptor(const TDesC8& aDescriptor);
318 IMPORT_C void CloseConfig();
319 IMPORT_C static void GetConfigUrlL(CBufFlat*& aUrlCfgBuffer, const TDesC& aUrl, TInt aIapId);
321 /** made public to check for further selected controllers in the queue */
322 inline TInt ControllerIndex() const;
323 inline TInt ControllerCount() const;
325 /** made public to stop checking for further selected controllers in the queue */
326 inline TBool StopTryLoadController() const;
327 IMPORT_C void SetInitScreenNumber(TInt aScreenNumber, RMMFVideoSetInitScreenCustomCommands* aVideoSetInitScreenCustomCommands);
328 #ifdef SYMBIAN_BUILD_GCE
329 inline void SetSurfaceMode(TBool aUseSurface, RMMFVideoPlaySurfaceSupportCustomCommands* aVideoPlaySurfaceSupportCustomCommands);
330 inline TInt SurfaceSupported();
334 class CConfig: public CBase
341 RMMFController* iController; // not owned
342 CMMFControllerEventMonitor* iEventMonitor; // not owned
344 /** indicates whether this controller is being used for
345 playback, recording or converting */
346 TControllerMode iControllerMode;
348 CMMSourceSink* iSource;
349 CMMSourceSink* iSink;
353 CMMFFindAndOpenController(MMMFFindAndOpenControllerObserver& aObserver);
358 void ConfigureSourceSink(
363 void ConfigureSourceSink(
365 const TMMSource& aSource,
369 void ConfigureController(
371 RMMFController& aController,
372 CMMFControllerEventMonitor& aEventMonitor,
373 TControllerMode aControllerMode);
375 void CloseController();
377 void OpenPrimaryController(void);
381 void SendError(TInt aError = KErrNone, TBool aForcedError = EFalse);
382 void SchedSendError(TInt aError = KErrNone);
383 void BuildControllerListFileNameL();
384 void BuildControllerListDescriptorL();
385 void BuildControllerListUrlL();
386 void BuildControllerListFormatL();
387 void TryNextController();
389 CMMSourceSink* CreateSourceSinkL(const TSourceSink& aParams);
390 CMMSourceSink* CreateSourceSinkL(const TMMSource& aSource);
392 CMMFUtilityFileInfo* CreateFileInfoL(TBool aSecureDRMMode = EFalse);
393 void UseSecureDRMProcessL(TBool& aIsSecureDrmProcess);
395 /** primary controller details */
396 CConfig* iPrimaryConfig;
397 /** secondary controller details */
398 CConfig* iSecondaryConfig;
399 /** points to either iPrimaryConfig or iSecondaryConfig */
400 CConfig* iCurrentConfig; // not owned
404 EOpenByControllerUid,
412 /** indicates what state the state machine is in */
416 EBuildControllerList,
426 MMMFFindAndOpenControllerObserver& iObserver;
427 CMMFAddDataSourceSinkAsync* iAddDataSourceSinkAsync;
429 TInt iControllerIndex;
430 TInt iControllerCount;
432 TFileName iFileNameSecondary; // for converting
435 TBool iUseFileHandle;
436 TBool iOwnFileHandle;
439 ContentAccess::TIntent iIntent;
446 TUid iFormatUidSecondary; // for converting
449 TMMFPrioritySettings iPrioritySettings;
450 CMMFPluginSelectionParameters::TMediaIdMatchType iMediaIdMatchType;
452 RMMFControllerImplInfoArray iControllers;
453 RMMFControllerImplInfoArray iPrioritisedControllers;
455 // if this is non-null, then it points to an element in
456 // either iControllers or iPrioritisedControllers
457 CMMFControllerImplementationInformation* iControllerImplInfo; // not owned
459 TControllerMode iControllerMode;
460 TBool iSourceSinkConfigured;
463 TMMFMessageDestination iSourceHandle;
464 TMMFMessageDestination iSinkHandle;
467 TBool iUseSharedHeap; // should new controllers use shared heaps?
468 TBool iStopTryLoadController; //stop to try loading the selected conrollers from the list
469 RMMFVideoSetInitScreenCustomCommands* iVideoSetInitScreenCustomCommands;
471 TBool iHasDrmCapability;
472 TBool iUsingSecureDrmProcess;
474 #ifdef SYMBIAN_BUILD_GCE
475 RMMFVideoPlaySurfaceSupportCustomCommands* iVideoPlaySurfaceSupportCustomCommands;
477 TInt iSurfaceSupported;
481 inline TInt CMMFFindAndOpenController::ControllerIndex() const
483 return iControllerIndex;
486 inline TInt CMMFFindAndOpenController::ControllerCount() const
488 return iControllerCount;
491 inline TBool CMMFFindAndOpenController::StopTryLoadController() const
493 return iStopTryLoadController;
496 #ifdef SYMBIAN_BUILD_GCE
497 inline void CMMFFindAndOpenController::SetSurfaceMode(TBool aUseVPU2, RMMFVideoPlaySurfaceSupportCustomCommands* aVideoPlaySurfaceSupportCustomCommands)
500 iSurfaceSupported = KErrNone;
501 iVideoPlaySurfaceSupportCustomCommands = aVideoPlaySurfaceSupportCustomCommands;
504 inline TInt CMMFFindAndOpenController::SurfaceSupported()
506 return iSurfaceSupported;
508 #endif // SYMBIAN_BUILD_GCE
510 #endif // __MMF_CLIENT_UTILITY_H__