mmserv/metadatautility/Src/MetaDataUtilityBody.h
changeset 0 71ca22bcf22a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     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:  This class provides implementation body for the API specified
       
    15 *                by CMetaDataUtility.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CMETADATAUTILITYBODY_H
       
    22 #define CMETADATAUTILITYBODY_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include <MetaDataField.hrh>
       
    27 #include <f32file.h>
       
    28 #include <MDUChunkDataObserver.h>
       
    29 
       
    30 // FORWARD DECLARATION
       
    31 class CMetaDataFieldContainer;
       
    32 class CMetaDataParser;
       
    33 class CMetaDataSource;
       
    34 class MMDUChunkDataObserver;
       
    35 class CMetaDataBufferAgg;
       
    36 
       
    37 // LITERALS & CONSTANTS
       
    38 
       
    39 _LIT8(KAmrMimeType, "audio/amr");
       
    40 _LIT8(KAwbMimeType, "audio/amr-wb");
       
    41 _LIT8(KMpegMimeType, "audio/mpeg");
       
    42 _LIT8(KMp3MimeType, "audio/mp3");
       
    43 _LIT8(KMp4AudioMimeType, "audio/mp4");
       
    44 _LIT8(K3gpAudioMimeType, "audio/3gpp");
       
    45 _LIT8(K3g2AudioMimeType, "audio/3gpp2");
       
    46 _LIT8(KAacMimeType, "audio/aac");
       
    47 _LIT8(KMidiMimeType, "audio/midi");
       
    48 _LIT8(KWmaMimeType, "audio/x-ms-wma");
       
    49 _LIT8(KRmfMimeType, "audio/x-beatnik-rmf");
       
    50 _LIT8(KRApnMimeType, "audio/x-pn-realaudio");
       
    51 _LIT8(KRArnMimeType, "audio/vnd.rn-realaudio");
       
    52 _LIT8(KRAxMimeType, "audio/x-realaudio");
       
    53 
       
    54 // CLASS DECLARATION
       
    55 
       
    56 /**
       
    57 *  This class implements the API specified by CMetaDataUtility.
       
    58 *
       
    59 *  @lib MetaDataUtility.lib
       
    60 *  @since 3.0
       
    61 */
       
    62 class CMetaDataUtilityBody : public CBase
       
    63 	{
       
    64     public:  // Constructors and destructor
       
    65 
       
    66         /**
       
    67         * Two-phased constructor.
       
    68 		* @return A pointer to a new instance of this class
       
    69         */
       
    70         static CMetaDataUtilityBody* NewL();
       
    71 
       
    72         /**
       
    73         * Destructor.
       
    74         */
       
    75         virtual ~CMetaDataUtilityBody();
       
    76 
       
    77     public: // New functions
       
    78 
       
    79         /**
       
    80         * Opens and reads metadata from the specified file.
       
    81         * @since 3.0
       
    82 		* @param aFileName The name of the file
       
    83 		* @param aWantedFields An array of TMetaDataFieldId's. Empty array is interpreted as all fields.
       
    84 		* @return void
       
    85         */
       
    86 		void OpenFileL( const TDesC& aFileName, const RArray<TMetaDataFieldId>& aWantedFields );
       
    87 
       
    88 		/**
       
    89         * Opens and reads metadata from the specified file handle
       
    90         * @since 3.0
       
    91 		* @param aFile File handle already open
       
    92 		* @param aWantedFields An array of TMetaDataFieldId's. Empty array is interpreted as all fields.
       
    93 		* @return void
       
    94         */
       
    95 		void OpenFileL(RFile& aFile, const RArray<TMetaDataFieldId>& aWantedFields );
       
    96 
       
    97         /**
       
    98         * Reads metadata from the specified descriptor.
       
    99         * @since 3.0
       
   100 		* @param aDes Source descriptor
       
   101 		* @param aWantedFields An array of TMetaDataFieldId's. Empty array is interpreted as all fields.
       
   102 		* @return void
       
   103         */
       
   104 		void OpenDesL( const TDesC8& aDes, const RArray<TMetaDataFieldId>& aWantedFields  );
       
   105 
       
   106         /**
       
   107         * Returns the number of metadata.
       
   108         * @since 3.0
       
   109 		* @return Number of metadata
       
   110         */
       
   111 		TInt MetaDataCount() const;
       
   112 
       
   113         /**
       
   114         * Returns the metadata fields found in this source.
       
   115         * Calling this function when MetaDataCount() returns 0, will result in
       
   116         * User::Leave with KErrNotFound.
       
   117         * @since 3.0
       
   118         * @return Metadata field container object
       
   119         */
       
   120 		const CMetaDataFieldContainer& MetaDataFieldsL();
       
   121 
       
   122         /**
       
   123         * Resets the utility. Must be called before OpenFileL or OpenDesL can be called again.
       
   124         * @since 3.0
       
   125 		* @return void
       
   126         */
       
   127 		void ResetL();
       
   128 
       
   129 		/**
       
   130         * Returns the ID3 version if the file has ID3 metadata.
       
   131         * @since 3.0
       
   132 		* @return TID3Version
       
   133         */
       
   134 		TID3Version ID3Version();
       
   135 		/**
       
   136         * Opens and reads metadata from the specified file.
       
   137         * @since 3.2
       
   138 		* @param aFileName The name of the file
       
   139 		* @param aWantedFields An array of TMetaDataFieldId's. Empty array is interpreted as all fields.
       
   140 		* @param aMimeType The MIME type of the file
       
   141 		* @return void
       
   142         */
       
   143 		void OpenFileL( const TDesC& aFileName, const RArray<TMetaDataFieldId>& aWantedFields, const TDesC8& aMimeType );
       
   144 
       
   145 		/**
       
   146         * Opens and reads metadata from the specified file handle
       
   147         * @since 3.2
       
   148 		* @param aFile File handle already open
       
   149 		* @param aWantedFields An array of TMetaDataFieldId's. Empty array is interpreted as all fields.
       
   150 		* @param aMimeType The MIME type of the file
       
   151 		* @return void
       
   152         */
       
   153 		void OpenFileL(RFile& aFile, const RArray<TMetaDataFieldId>& aWantedFields, const TDesC8& aMimeType );
       
   154 
       
   155         /**
       
   156         * Reads metadata from the specified descriptor.
       
   157         * @since 3.2
       
   158 		* @param aDes Source descriptor
       
   159 		* @param aWantedFields An array of TMetaDataFieldId's. Empty array is interpreted as all fields.
       
   160 		* @param aMimeType The MIME type of the file
       
   161 		* @return void
       
   162         */
       
   163 		void OpenDesL( const TDesC8& aDes, const RArray<TMetaDataFieldId>& aWantedFields, const TDesC8& aMimeType );
       
   164 		
       
   165         /**
       
   166         * Inititalization for parsing Chunk Data.
       
   167         * @since 5.0
       
   168         * @param aMimeType The MIME type
       
   169         * @param aObserver should not be NULL
       
   170         * @return value
       
   171         *      KErrNone
       
   172         *      KErrInvalidArgument invalid mime type or null observer
       
   173         */
       
   174         TInt InitChunkData( TDesC8& aMimeType, 
       
   175                             MMDUChunkDataObserver& aObserver );
       
   176         
       
   177         /** 
       
   178         * Process the chunk data.
       
   179         * @since 5.0
       
   180         *      Max size of buffer passed in is N bytes for performance optimization
       
   181         *      Buffer overflow (out of memory) results in callback with error.
       
   182         *      invalid chunk data results in callback with error
       
   183         *      parsing APIs are invoked before callback is received results in 0 count or empty container
       
   184         *      parsing APIs are invoked after callback is received results in positive count and full container
       
   185         * @param aChunk the data chunk to be processed
       
   186         * @return value
       
   187         *      KErrNone
       
   188         *      KErrNotReady    Buffer is still being used
       
   189         *      KErrArgument    Chunk size exceeds maximum
       
   190         *      KErrCompletion  Stop sending data. Meta-data has been captured and is being parsed.
       
   191         */
       
   192         TInt ProcessChunkData( TDesC8& aChunk,
       
   193                                TBool aFinalChunk = EFalse  );
       
   194 		
       
   195         /**
       
   196         * Parse the aggregated metadata.
       
   197         * @since 5.0
       
   198         * This is a request from the user to start parsing
       
   199         * @return value
       
   200         *      KErrNone
       
   201         *      KErrNotReady    Buffer is still being used
       
   202         */
       
   203         TInt ParseChunkData();
       
   204         
       
   205         
       
   206         /** 
       
   207         * Verify whether it is in Chunk Data mode.
       
   208         * @since 5.0
       
   209         * @return value
       
   210         *      ETrue
       
   211         *      EFalse        
       
   212         */
       
   213         TBool IsChunkDataMode();
       
   214         
       
   215         /** 
       
   216         * Close and clean up the Chunk Data mode.
       
   217         * Need to kill the MetadataUtility since it wasn't designed to be reused.
       
   218         * @since 5.0
       
   219 		* @return void
       
   220         */
       
   221         void CloseChunkData();
       
   222 		
       
   223         /**
       
   224         * Parses the aggregated metadata.
       
   225         * @since 5.0
       
   226         * This is a callback from the "Buffer Aggregator" to start parsing after all
       
   227         * meta-data has been aggregated. 
       
   228         * @param aChunk The aggregated metadata
       
   229         * @param aMimeType The MIME type
       
   230         * @return void
       
   231         */
       
   232         void DoParseChunkDataL(TDesC8& aChunk, TDesC8& aMimeType);
       
   233         
       
   234 
       
   235 	private:
       
   236 
       
   237         /**
       
   238         * C++ default constructor.
       
   239         */
       
   240 		CMetaDataUtilityBody();
       
   241 
       
   242         /**
       
   243         * By default Symbian 2nd phase constructor is private.
       
   244         */
       
   245 		void ConstructL();
       
   246 
       
   247         /**
       
   248         * Finds the metadata parser that can interpret the specified file.
       
   249         * @param aFileName The name of the file
       
   250         * @return Pointer to parser; NULL if unable to find one.
       
   251 		*/
       
   252 		CMetaDataParser* FindParserFileL( const TDesC& aFileName );
       
   253 
       
   254 		/**
       
   255         * Finds the metadata parser that can interpret the specified file handle.
       
   256         * @param aFile File Handle
       
   257         * @return Pointer to parser; NULL if unable to find one.
       
   258 		*/
       
   259 		CMetaDataParser* FindParserFileL( RFile& aFile );
       
   260 
       
   261 		/**
       
   262         * Implemetation of finding a file parser, used by FindParserFileL
       
   263         * @param none
       
   264         * @return Pointer to parser; NULL if unable to find one.
       
   265 		*/
       
   266 		CMetaDataParser* DoFindParserFileL();
       
   267         /**
       
   268         * Finds the metadata parser that can interpret the specified descriptor.
       
   269         * @param aDes Source descriptor
       
   270         * @return Pointer to parser; NULL if unable to find one.
       
   271 		*/
       
   272 		CMetaDataParser* FindParserDesL( const TDesC8& aDes );
       
   273 		/**
       
   274         * Finds the metadata parser that can interpret the specified file.
       
   275         * @param aFileName The name of the file
       
   276         * @return Pointer to parser; NULL if unable to find one.
       
   277 		*/
       
   278 		CMetaDataParser* FindParserFileL( const TDesC& aFileName, const TDesC8& aMimeType );
       
   279 		/**
       
   280         * Finds the metadata parser that can interpret the specified file handle.
       
   281         * @since 3.2
       
   282         * @param aFile File Handle
       
   283         * @return Pointer to parser; NULL if unable to find one.
       
   284 		*/
       
   285 		CMetaDataParser* FindParserFileL( RFile& aFile, const TDesC8& aMimeType );
       
   286 		/**
       
   287         * Implemetation of finding a file parser, used by FindParserFileL
       
   288         * @since 3.2
       
   289         * @param aMimeType
       
   290         * @return Pointer to parser; NULL if unable to find one.
       
   291 		*/
       
   292 		CMetaDataParser* DoFindParserFileL( const TDesC8& aMimeType);
       
   293 
       
   294         /**
       
   295         * Finds the metadata parser that can interpret the specified descriptor.
       
   296         * @since 3.2
       
   297         * @param aDes Source descriptor
       
   298         * @return Pointer to parser; NULL if unable to find one.
       
   299 		*/
       
   300 		CMetaDataParser* FindParserDesL( const TDesC8& aDes, const TDesC8& aMimeType );
       
   301 
       
   302 		/**
       
   303         * Implemetation of
       
   304         * @since 3.2
       
   305         * @param aMimeType
       
   306         * @return TInt 0(KErrNone) if supported MIME Type else KErrNotSupported(-5)
       
   307 		*/
       
   308 		TInt IsSupportedMimeType( const TDesC8& aMimeType);
       
   309 
       
   310  	private:	// Data
       
   311 
       
   312 		// Metadata container
       
   313 		CMetaDataFieldContainer* iContainer;
       
   314 		// Metadata parser
       
   315 		CMetaDataParser* iParser;
       
   316 		// Metadata source
       
   317 		CMetaDataSource* iSource;
       
   318 		// ID3 Version
       
   319 		TInt iID3Version;
       
   320 		// Operate in chunk data mode
       
   321 	    TBool iChunkMode;
       
   322 	    // Metadata Async
       
   323 	    CMetaDataBufferAgg* iBufferAgg;
       
   324 	    
       
   325 	};
       
   326 
       
   327 #endif      // CMETADATAUTILITYBODY_H
       
   328 
       
   329 // End of File