mmlibs/mmfw/Recogniser/src/parsers.h
changeset 0 40261b775718
child 54 b68f3e90dca1
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2006-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef PARSERS_H
       
    17 #define PARSERS_H
       
    18 
       
    19 #include "readers.h"
       
    20 
       
    21 //
       
    22 // Utility class for performing bit operations.
       
    23 //
       
    24 class TFlags
       
    25 	{
       
    26 public:
       
    27 	TFlags()
       
    28 	 : iFlags(0)
       
    29 		{
       
    30 		}
       
    31 		
       
    32 	void SetExtensionFlag(){ iFlags |= KBit0; }
       
    33 	void SetBit(TUint32 aMask) { iFlags |= aMask; }
       
    34 	
       
    35 	TUint32 GetBitField(TUint32 aMask, TUint8 aRightShift = 0)
       
    36 		{
       
    37 		return ((iFlags & aMask) >> aRightShift);
       
    38 		}
       
    39 		
       
    40 private:
       
    41 	TUint32 iFlags;
       
    42 	};
       
    43 
       
    44 
       
    45 //
       
    46 // An ID3 tag parser.
       
    47 //
       
    48 class TID3Parser
       
    49 	{
       
    50 public:
       
    51 	static TBool ReadAndSkipID3L(CReader& aReader);
       
    52 	};
       
    53 	
       
    54 
       
    55 //
       
    56 // A raw-AAC audio file parser.
       
    57 //
       
    58 class TAACParser
       
    59 	{
       
    60 public:
       
    61 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
    62 
       
    63 protected:
       
    64 	TAACParser(CReader& aReader, TFlags& aFlags);
       
    65 	void ParseL();
       
    66 	TInt CheckForFrameHeaderL(TInt& aFrameLength);
       
    67 	
       
    68 private:
       
    69 	CReader& iReader;
       
    70 	TFlags& iFlags;
       
    71 	};
       
    72 
       
    73 
       
    74 //
       
    75 // A raw-MP3 audio file parser.
       
    76 //
       
    77 class TMP3Parser
       
    78 	{
       
    79 public:
       
    80 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
    81 
       
    82 protected:
       
    83 	TMP3Parser(CReader& aReader, TFlags& aFlags);
       
    84 	void ParseL();
       
    85 	TInt CheckForFrameHeaderL(TInt& aFrameLength);
       
    86 
       
    87 private:
       
    88 	CReader& iReader;
       
    89 	TFlags& iFlags;
       
    90 	};
       
    91 
       
    92 
       
    93 //
       
    94 // An MPEG4 container file format parser.
       
    95 //
       
    96 #define KMPEG4BoxTitleLen		4
       
    97 
       
    98 class TMPEG4Parser
       
    99 	{
       
   100 public:
       
   101 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   102 
       
   103 protected:
       
   104 	TMPEG4Parser(CReader& aReader, TFlags& aFlags);
       
   105 	const TText8* MatchFileType(const TDesC& aExt);
       
   106 	static TInt IsCompatibleBrand(TUint32 aBrand, TInt aStartPos = 0);
       
   107 
       
   108 	// Parsing routines.
       
   109 	void ParseL();
       
   110 	void SkipCurrentBoxL();
       
   111 	void ReadBoxHeaderL();
       
   112 	void ReadFileTypeL();
       
   113 	void ReadMovieL();
       
   114 	void ReadTrackL();
       
   115 	void ReadTrackHeaderL();
       
   116 	void ReadMediaL();
       
   117 	void ReadHandlerL();
       
   118 			
       
   119 private:
       
   120 	// Data members.
       
   121 	TUint32 iTitle;			// The title of the current box.
       
   122 	TInt iBrandIndex;
       
   123 	TBool iIsFinished;
       
   124 	TInt64 iSize; 			// The current box's size.
       
   125 	CReader& iReader;
       
   126 	TFlags& iFlags;
       
   127 	TBool iVideoAssumed;
       
   128 	};
       
   129 
       
   130 
       
   131 //
       
   132 // An MPEG2 container file format parser.
       
   133 //
       
   134 class TMPEG2Parser
       
   135 	{
       
   136 public:
       
   137 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   138 
       
   139 protected:
       
   140 	TMPEG2Parser(CReader& aReader, TFlags& aFlags);
       
   141 	void ParseL();
       
   142 	TBool NextStartCodeL();
       
   143 	void ReadPackHeaderL();
       
   144 	void SkipL();
       
   145 	const TText8* MatchExtension(const TDesC& aExt);
       
   146 	
       
   147 private:
       
   148 	CReader& iReader;
       
   149 	TFlags& iFlags;
       
   150 	};
       
   151 
       
   152 
       
   153 //
       
   154 // A Matroska container file format parser.
       
   155 //
       
   156 class TMatroskaParser
       
   157 	{
       
   158 public:
       
   159 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   160 
       
   161 protected:
       
   162 	TMatroskaParser(CReader& aReader, TFlags& aFlags);
       
   163 	void ParseL();
       
   164 	TUint64 ReadDataL(TBool aTurnOffHighestSetBit = EFalse);
       
   165 	void ReadElementL(TUint64& aElementID, TInt64& aSize);
       
   166 	TBool ReadSegmentL(TUint64& aNextID, TInt64& aNextSize);
       
   167 	TBool ReadTrackL(TInt64 aTrackSize);
       
   168 	const TText8* MatchExtension(const TDesC& aExt);
       
   169 
       
   170 private:
       
   171 	CReader& iReader;
       
   172 	TFlags& iFlags;
       
   173 	};
       
   174 
       
   175 
       
   176 //
       
   177 // A Windows Media ASF file format parser.
       
   178 //
       
   179 class TASFParser
       
   180 	{
       
   181 public:
       
   182 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   183 
       
   184 protected:
       
   185 	TASFParser(CReader& aReader, TFlags& aFlags);
       
   186 	void ParseL();
       
   187 	void ReadObjectL(TDes8& aGUID, TInt64& aSize);
       
   188 	void ReadGUIDL(TDes8& aGUID);
       
   189 	const TText8* MatchExtension(const TDesC& aExt, TBool aVideo);
       
   190 	
       
   191 private:
       
   192 	CReader& iReader;
       
   193 	TFlags& iFlags;
       
   194 	};
       
   195 	
       
   196 
       
   197 //
       
   198 // A RealMedia file format parser.
       
   199 //
       
   200 class TRMParser
       
   201 	{
       
   202 public:
       
   203 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   204 
       
   205 protected:
       
   206 	TRMParser(CReader& aReader, TFlags& aFlags);
       
   207 	void ParseL();
       
   208 	void ReadChunkHeaderL(TUint32& aObjectId, TUint32& aSize, TBool aFirstChunk = EFalse);
       
   209 	void MatchExtension(const TDesC& aFileExt);
       
   210 	TBool ReadMediaPropertiesL();
       
   211 	
       
   212 private:
       
   213 	CReader& iReader;
       
   214 	TFlags& iFlags;
       
   215 	};
       
   216 
       
   217 
       
   218 //
       
   219 // A RAM file parser.
       
   220 //
       
   221 class TRAMParser
       
   222 	{
       
   223 public:
       
   224 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   225 	};
       
   226 
       
   227 
       
   228 //
       
   229 // An SDP file parser.
       
   230 //
       
   231 class TSDPParser
       
   232 	{
       
   233 public:
       
   234 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   235 	};
       
   236 
       
   237 
       
   238 //
       
   239 // An XPS file parser.
       
   240 //
       
   241 class TXPSParser
       
   242 	{
       
   243 public:
       
   244 	static void DoRecognise(const TDesC& aFileExt, CReader& aReader, TMatch& aMatch);
       
   245 	};
       
   246 
       
   247 #endif