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