sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Client utility functions sl@0: // sl@0: // sl@0: sl@0: #ifndef __MMF_CLIENT_UTILITY_H__ sl@0: #define __MMF_CLIENT_UTILITY_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "mmf/common/mmfcontrollerpluginresolver.h" sl@0: #include sl@0: #include sl@0: #include "mmf/common/mmfcontroller.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS sl@0: #include sl@0: #include sl@0: #endif sl@0: #ifdef SYMBIAN_BUILD_GCE sl@0: #include sl@0: #endif sl@0: sl@0: class CMMSourceSink; // declared here. sl@0: sl@0: NONSHARABLE_CLASS( CMMSourceSink ): public CBase sl@0: { sl@0: public: sl@0: IMPORT_C static CMMSourceSink* NewL(TUid aUid, const TDesC8& aDescriptor); sl@0: IMPORT_C static CMMSourceSink* NewLC(TUid aUid, const TDesC8& aDescriptor); sl@0: sl@0: virtual ~CMMSourceSink(); sl@0: virtual TUid SourceSinkUid() const; sl@0: virtual const TDesC8& SourceSinkData() const; sl@0: sl@0: virtual TBool CarryingFileHandle() const; sl@0: sl@0: virtual void EvaluateIntentL(); sl@0: protected: sl@0: CMMSourceSink(TUid aUid); sl@0: sl@0: sl@0: private: sl@0: void ConstructL(const TDesC8& aDescriptor); sl@0: sl@0: const TUid iUid; sl@0: HBufC8* iBuf; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: class CMMFileSourceSink; // declared here. sl@0: sl@0: NONSHARABLE_CLASS( CMMFileSourceSink ): public CMMSourceSink sl@0: { sl@0: public: sl@0: IMPORT_C static CMMFileSourceSink* NewL(TUid aUid, const RFile& aFile); sl@0: IMPORT_C static CMMFileSourceSink* NewLC(TUid aUid, const RFile& aFile); sl@0: sl@0: IMPORT_C static CMMFileSourceSink* NewL(TUid aUid, const TMMSource& aMMSource); sl@0: IMPORT_C static CMMFileSourceSink* NewLC(TUid aUid, const TMMSource& aMMSource); sl@0: sl@0: const TDesC& UniqueId() const {return *iUniqueId;} sl@0: sl@0: virtual ~CMMFileSourceSink(); sl@0: sl@0: const TDesC& FileName() const {return *iFileName;} sl@0: const TDesC8& SourceSinkData() const; sl@0: sl@0: IMPORT_C void EvaluateIntentL(ContentAccess::TIntent aIntent); sl@0: virtual void EvaluateIntentL(); sl@0: sl@0: TBool CarryingFileHandle() const; sl@0: sl@0: TBool UsingFileHandle() const {return iUsingFileHandle;}; sl@0: const RFile& FileHandle() const {return iHandle;}; sl@0: protected: sl@0: CMMFileSourceSink(TUid aUid); sl@0: sl@0: private: sl@0: void ConstructL(const TMMSource& aSource); sl@0: void DoCreateFileSourceConfigDataL(); sl@0: void ConstructL(const RFile& aFile); sl@0: void DoCreateFileHandleSourceConfigDataL(); sl@0: sl@0: TBool iUsingFileHandle; sl@0: RFile iHandle; sl@0: HBufC* iFileName; sl@0: HBufC8* iSourceSinkData; sl@0: HBufC* iUniqueId; sl@0: ContentAccess::TIntent iIntent; sl@0: sl@0: TBool iEnableUI; sl@0: }; sl@0: sl@0: sl@0: sl@0: class CMMFMdaObjectStateChangeObserverCallback; // declared here. sl@0: /** sl@0: Active object utility class to allow the callback to be called asynchronously. sl@0: This should help prevent re-entrant code in clients of the mediaframework. sl@0: */ sl@0: NONSHARABLE_CLASS( CMMFMdaObjectStateChangeObserverCallback ): public CActive sl@0: { sl@0: public: sl@0: IMPORT_C static CMMFMdaObjectStateChangeObserverCallback* NewL(MMdaObjectStateChangeObserver& aCallback); sl@0: virtual ~CMMFMdaObjectStateChangeObserverCallback(); sl@0: IMPORT_C void CallBack(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode); sl@0: private: sl@0: CMMFMdaObjectStateChangeObserverCallback(MMdaObjectStateChangeObserver& aCallback); sl@0: void RunL(); sl@0: void DoCancel(); sl@0: private: sl@0: MMdaObjectStateChangeObserver& iCallback; sl@0: CBase* iObject; sl@0: TInt iPreviousState; sl@0: TInt iCurrentState; sl@0: TInt iErrorCode; sl@0: }; sl@0: sl@0: class CMMFClientUtility; // declared here. sl@0: sl@0: NONSHARABLE_CLASS( CMMFClientUtility ) sl@0: { sl@0: public: sl@0: IMPORT_C static TUid ConvertMdaFormatUidToECOMWrite(TUid aMdaFormatUid); sl@0: IMPORT_C static TUid ConvertMdaFormatUidToECOMRead(TUid aMdaFormatUid); sl@0: IMPORT_C static TFourCC ConvertMdaCodecToFourCC(TMdaPackage& aCodec); sl@0: IMPORT_C static TInt GetFileHeaderData(const TDesC& aFileName, TDes8& aHeaderData, TInt aMaxLength); sl@0: IMPORT_C static HBufC8* GetFileExtensionL(const TDesC& aFileName); sl@0: static void PrioritiseControllersL( sl@0: const RMMFControllerImplInfoArray& aControllers, sl@0: const TDesC8& aHeaderDataPlayback, sl@0: const TDesC8& aFileExtensionPlayback, sl@0: const TDesC8& aHeaderDataRecord, sl@0: const TDesC8& aFileExtensionRecord, sl@0: RMMFControllerImplInfoArray& aPrioritisedControllers); sl@0: static TInt GetBestMatchL(const CMMFFormatImplementationInformation* format, const TDesC8& aHeaderData, const TDesC8& aFileExtension); sl@0: sl@0: private: sl@0: CMMFClientUtility(); sl@0: }; sl@0: sl@0: class CMMFUtilityFileInfo; // declared here. sl@0: class RMMFDRMPluginServerProxy; sl@0: sl@0: NONSHARABLE_CLASS( CMMFUtilityFileInfo ): public CBase sl@0: { sl@0: public: sl@0: sl@0: static CMMFUtilityFileInfo* NewL(TMMSource& aSource, TBool aSecureDRMMode = EFalse); sl@0: static CMMFUtilityFileInfo* NewLC(TMMSource& aSource, TBool aSecureDRMMode = EFalse); sl@0: sl@0: ~CMMFUtilityFileInfo(); sl@0: sl@0: TBool GetFileMimeTypeL(TDes8& aMimeType); sl@0: void GetFileHeaderDataL(TDes8& aHeaderData, TInt aMaxLength); sl@0: TInt EvaluateIntent(ContentAccess::TIntent aIntent); sl@0: sl@0: private: sl@0: CMMFUtilityFileInfo(); sl@0: sl@0: void ConstructL(const TMMSource& aSource, TBool aSecureDRMMode); sl@0: sl@0: private: sl@0: ContentAccess::CData* iData; sl@0: RMMFDRMPluginServerProxy* iDrmPluginServer; sl@0: }; sl@0: sl@0: inline CMMFUtilityFileInfo::CMMFUtilityFileInfo() sl@0: { sl@0: }; sl@0: sl@0: /** sl@0: * Mixin class that the user of the class CMMFFindAndOpenController must derive from. sl@0: * @internalComponent sl@0: */ sl@0: class MMMFFindAndOpenControllerObserver sl@0: { sl@0: public: sl@0: /** sl@0: * Callback function to indicate the success or failure sl@0: * of an attempt to find and open a suitable controller and sl@0: * to add a source and sink. sl@0: * @see CMMFFindAndOpenController sl@0: * sl@0: * @param aError sl@0: * Indicates whether a controller has been opened sucessfully sl@0: * This is passed by reference, mainly for the audio recorder utility sl@0: * which opens two controllers: if the secondary controller (which is sl@0: * always opened first) fails to open, then the audio recorder utility sl@0: * may choose to set aError = KErrNone in the MfaocComplete() callback sl@0: * to indicate to CFindAndOpenControler() that it should continue sl@0: * to open the primary controller, even though opening the secondary failed. sl@0: * @param aController sl@0: * A pointer to the controller that has been opened or has failed to open sl@0: * This is mainly for the audio recorder utility to indicate sl@0: * which controller (primary or secondary) has been opened. sl@0: * @param aControllerUid sl@0: * the UID of the controller that has been opened sl@0: * @param aSourceHandle sl@0: * a pointer to the source handle sl@0: * @internalComponent sl@0: * a pointer to the sink handle sl@0: */ sl@0: virtual void MfaocComplete( sl@0: TInt& aError, sl@0: RMMFController* aController, sl@0: TUid aControllerUid = KNullUid, sl@0: TMMFMessageDestination* aSourceHandle = NULL, sl@0: TMMFMessageDestination* aSinkHandle = NULL) = 0; sl@0: }; sl@0: sl@0: sl@0: class CMMFFindAndOpenController; // declared here. sl@0: /** sl@0: * Utility class used by the MMF client API classes. sl@0: * Finds and opens a suitable controller and adds a source and a sink sl@0: * asynchronously. Completion is indicated asynchronously sl@0: * using the MMMFFindAndOpenControllerObserver mixin class. sl@0: * sl@0: * @internalComponent sl@0: */ sl@0: NONSHARABLE_CLASS( CMMFFindAndOpenController ): public CActive, public MMMFAddDataSourceSinkAsyncObserver sl@0: { sl@0: public: sl@0: enum TControllerMode sl@0: { sl@0: EPlayback, sl@0: ERecord, sl@0: EConvert sl@0: }; sl@0: sl@0: enum TControllerNumber sl@0: { sl@0: EPrimaryController, sl@0: ESecondaryController sl@0: }; sl@0: sl@0: class TSourceSink sl@0: { sl@0: public: sl@0: IMPORT_C TSourceSink(TUid aUid, const TDesC8& aData = KNullDesC8); sl@0: IMPORT_C TSourceSink(TUid aUid, const RFile& aFile); sl@0: sl@0: TUid iUid; sl@0: const TDesC8& iConfigData; sl@0: TBool iUseFileHandle; sl@0: RFile iFileHandle; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: public: sl@0: IMPORT_C static CMMFFindAndOpenController* NewL(MMMFFindAndOpenControllerObserver& aObserver); sl@0: virtual ~CMMFFindAndOpenController(); sl@0: sl@0: // from CActive sl@0: virtual void DoCancel(); sl@0: virtual void RunL(); sl@0: sl@0: // from MMMFAddDataSourceSinkAsyncObserver sl@0: virtual void MadssaoAddDataSourceSinkAsyncComplete(TInt aError, const TMMFMessageDestination& aHandle); sl@0: sl@0: IMPORT_C void Configure( sl@0: TUid aMediaId, sl@0: TMMFPrioritySettings aPrioritySettings, sl@0: CMMFPluginSelectionParameters::TMediaIdMatchType aMediaIdMatchType = CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds); sl@0: sl@0: IMPORT_C void ConfigureController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback); sl@0: IMPORT_C void ConfigureSecondaryController(RMMFController& aController, CMMFControllerEventMonitor& aEventMonitor, TControllerMode aControllerMode = EPlayback); sl@0: sl@0: IMPORT_C void UseSharedHeap(); sl@0: sl@0: IMPORT_C void ConfigureSourceSink( sl@0: TSourceSink aSource, sl@0: TSourceSink aSink); sl@0: IMPORT_C void ConfigureSecondarySourceSink( sl@0: TSourceSink aSource, sl@0: TSourceSink aSink); sl@0: sl@0: IMPORT_C void ConfigureSourceSink( sl@0: const TMMSource& aSource, sl@0: TSourceSink aSink); sl@0: sl@0: IMPORT_C void OpenByFileSource(const TMMSource& aFileSource, const TDesC& aFileNameSecondary = KNullDesC); sl@0: sl@0: IMPORT_C void OpenByFormatUid(TUid aFormatUid, TUid aFormatUidSecondary = KNullUid); sl@0: IMPORT_C void OpenByDescriptor(const TDesC8& aDescriptor); sl@0: IMPORT_C void OpenByUrl(const TDesC& aUrl, TInt aIapId, const TDesC8& aMimeType); sl@0: IMPORT_C void OpenByControllerUid(TUid aControllerUid, TUid aSecondaryControllerUid = KNullUid); sl@0: IMPORT_C void ReOpen(); sl@0: IMPORT_C void Close(); sl@0: sl@0: IMPORT_C static TMMFFileConfig GetConfigFile(const TDesC& aFileName); sl@0: IMPORT_C static TMMFDescriptorConfig GetConfigDescriptor(const TDesC8& aDescriptor); sl@0: IMPORT_C void CloseConfig(); sl@0: IMPORT_C static void GetConfigUrlL(CBufFlat*& aUrlCfgBuffer, const TDesC& aUrl, TInt aIapId); sl@0: sl@0: /** made public to check for further selected controllers in the queue */ sl@0: inline TInt ControllerIndex() const; sl@0: inline TInt ControllerCount() const; sl@0: sl@0: /** made public to stop checking for further selected controllers in the queue */ sl@0: inline TBool StopTryLoadController() const; sl@0: IMPORT_C void SetInitScreenNumber(TInt aScreenNumber, RMMFVideoSetInitScreenCustomCommands* aVideoSetInitScreenCustomCommands); sl@0: #ifdef SYMBIAN_BUILD_GCE sl@0: inline void SetSurfaceMode(TBool aUseSurface, RMMFVideoPlaySurfaceSupportCustomCommands* aVideoPlaySurfaceSupportCustomCommands); sl@0: inline TInt SurfaceSupported(); sl@0: #endif sl@0: sl@0: private: sl@0: class CConfig: public CBase sl@0: { sl@0: public: sl@0: CConfig(); sl@0: ~CConfig(); sl@0: void Close(); sl@0: public: sl@0: RMMFController* iController; // not owned sl@0: CMMFControllerEventMonitor* iEventMonitor; // not owned sl@0: sl@0: /** indicates whether this controller is being used for sl@0: playback, recording or converting */ sl@0: TControllerMode iControllerMode; sl@0: sl@0: CMMSourceSink* iSource; sl@0: CMMSourceSink* iSink; sl@0: TUid iControllerUid; sl@0: }; sl@0: sl@0: CMMFFindAndOpenController(MMMFFindAndOpenControllerObserver& aObserver); sl@0: void ConstructL(); sl@0: sl@0: void Init(); sl@0: sl@0: void ConfigureSourceSink( sl@0: CConfig& config, sl@0: TSourceSink aSource, sl@0: TSourceSink aSink); sl@0: sl@0: void ConfigureSourceSink( sl@0: CConfig& config, sl@0: const TMMSource& aSource, sl@0: TSourceSink aSink); sl@0: sl@0: sl@0: void ConfigureController( sl@0: CConfig& config, sl@0: RMMFController& aController, sl@0: CMMFControllerEventMonitor& aEventMonitor, sl@0: TControllerMode aControllerMode); sl@0: sl@0: void CloseController(); sl@0: sl@0: void OpenPrimaryController(void); sl@0: sl@0: void KickState(); sl@0: void Process(); sl@0: void SendError(TInt aError = KErrNone, TBool aForcedError = EFalse); sl@0: void SchedSendError(TInt aError = KErrNone); sl@0: void BuildControllerListFileNameL(); sl@0: void BuildControllerListDescriptorL(); sl@0: void BuildControllerListUrlL(); sl@0: void BuildControllerListFormatL(); sl@0: void TryNextController(); sl@0: sl@0: CMMSourceSink* CreateSourceSinkL(const TSourceSink& aParams); sl@0: CMMSourceSink* CreateSourceSinkL(const TMMSource& aSource); sl@0: sl@0: CMMFUtilityFileInfo* CreateFileInfoL(TBool aSecureDRMMode = EFalse); sl@0: void UseSecureDRMProcessL(TBool& aIsSecureDrmProcess); sl@0: private: sl@0: /** primary controller details */ sl@0: CConfig* iPrimaryConfig; sl@0: /** secondary controller details */ sl@0: CConfig* iSecondaryConfig; sl@0: /** points to either iPrimaryConfig or iSecondaryConfig */ sl@0: CConfig* iCurrentConfig; // not owned sl@0: sl@0: enum TMode sl@0: { sl@0: EOpenByControllerUid, sl@0: EOpenByFileName, sl@0: EOpenByDescriptor, sl@0: EOpenByUrl, sl@0: EOpenByFormatUid sl@0: }; sl@0: TMode iMode; sl@0: sl@0: /** indicates what state the state machine is in */ sl@0: enum TState sl@0: { sl@0: EIdle, sl@0: EBuildControllerList, sl@0: EOpenController, sl@0: EAddSource, sl@0: EAddSink, sl@0: EWaitingForSource, sl@0: EWaitingForSink, sl@0: ESendError sl@0: }; sl@0: TState iState; sl@0: sl@0: MMMFFindAndOpenControllerObserver& iObserver; sl@0: CMMFAddDataSourceSinkAsync* iAddDataSourceSinkAsync; sl@0: sl@0: TInt iControllerIndex; sl@0: TInt iControllerCount; sl@0: sl@0: TFileName iFileNameSecondary; // for converting sl@0: sl@0: TFileName iFileName; sl@0: TBool iUseFileHandle; sl@0: TBool iOwnFileHandle; sl@0: HBufC* iUniqueId; sl@0: RFile iFileHandle; sl@0: ContentAccess::TIntent iIntent; sl@0: sl@0: HBufC* iUrl; sl@0: HBufC8* iMimeType; sl@0: TPtr8 iDescriptor; sl@0: TInt iIapId; sl@0: TUid iFormatUid; sl@0: TUid iFormatUidSecondary; // for converting sl@0: sl@0: TUid iMediaId; sl@0: TMMFPrioritySettings iPrioritySettings; sl@0: CMMFPluginSelectionParameters::TMediaIdMatchType iMediaIdMatchType; sl@0: sl@0: RMMFControllerImplInfoArray iControllers; sl@0: RMMFControllerImplInfoArray iPrioritisedControllers; sl@0: sl@0: // if this is non-null, then it points to an element in sl@0: // either iControllers or iPrioritisedControllers sl@0: CMMFControllerImplementationInformation* iControllerImplInfo; // not owned sl@0: sl@0: TControllerMode iControllerMode; sl@0: TBool iSourceSinkConfigured; sl@0: TInt iError; sl@0: sl@0: TMMFMessageDestination iSourceHandle; sl@0: TMMFMessageDestination iSinkHandle; sl@0: TBool iEnableUi; sl@0: sl@0: TBool iUseSharedHeap; // should new controllers use shared heaps? sl@0: TBool iStopTryLoadController; //stop to try loading the selected conrollers from the list sl@0: RMMFVideoSetInitScreenCustomCommands* iVideoSetInitScreenCustomCommands; sl@0: TInt iScreenNumber; sl@0: TBool iHasDrmCapability; sl@0: TBool iUsingSecureDrmProcess; sl@0: sl@0: #ifdef SYMBIAN_BUILD_GCE sl@0: RMMFVideoPlaySurfaceSupportCustomCommands* iVideoPlaySurfaceSupportCustomCommands; sl@0: TBool iUseVPU2; sl@0: TInt iSurfaceSupported; sl@0: #endif sl@0: }; sl@0: sl@0: inline TInt CMMFFindAndOpenController::ControllerIndex() const sl@0: { sl@0: return iControllerIndex; sl@0: } sl@0: sl@0: inline TInt CMMFFindAndOpenController::ControllerCount() const sl@0: { sl@0: return iControllerCount; sl@0: } sl@0: sl@0: inline TBool CMMFFindAndOpenController::StopTryLoadController() const sl@0: { sl@0: return iStopTryLoadController; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_BUILD_GCE sl@0: inline void CMMFFindAndOpenController::SetSurfaceMode(TBool aUseVPU2, RMMFVideoPlaySurfaceSupportCustomCommands* aVideoPlaySurfaceSupportCustomCommands) sl@0: { sl@0: iUseVPU2 = aUseVPU2; sl@0: iSurfaceSupported = KErrNone; sl@0: iVideoPlaySurfaceSupportCustomCommands = aVideoPlaySurfaceSupportCustomCommands; sl@0: } sl@0: sl@0: inline TInt CMMFFindAndOpenController::SurfaceSupported() sl@0: { sl@0: return iSurfaceSupported; sl@0: } sl@0: #endif // SYMBIAN_BUILD_GCE sl@0: sl@0: #endif // __MMF_CLIENT_UTILITY_H__