mmlibs/mmfw/Recogniser/src/readers.h
changeset 0 b8ed18f6c07b
equal deleted inserted replaced
-1:000000000000 0:b8ed18f6c07b
       
     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 READERS_H
       
    17 #define READERS_H
       
    18 
       
    19 #include "constants.h"
       
    20 #include "mmruf.h"
       
    21 
       
    22 
       
    23 static const TInt KAACFrameHeaderSize = 7;
       
    24 static const TInt KMP3FrameHeaderSize = 4;
       
    25 static const TInt KBufSize = 64;
       
    26 
       
    27 
       
    28 //
       
    29 // This class provides a level of abstraction that allows
       
    30 // for parsing data. It is necessary because AppArc may
       
    31 // only provide a buffer that contains a limited snapshot
       
    32 // of the beginning of a file, or a file handle that allows
       
    33 // the whole file to be parsed.
       
    34 //
       
    35 class CReader : public CBase
       
    36 	{
       
    37 public:
       
    38 
       
    39 	//
       
    40 	// Enums used so that CParsers can determine
       
    41 	// the type of reader they've been given.
       
    42 	//
       
    43 	typedef enum
       
    44 		{
       
    45 		EUnknown = 0,
       
    46 		EBuffer = 1,
       
    47 		EFile = 2
       
    48 		}
       
    49 	TReaderType;
       
    50 	
       
    51 	//
       
    52 	// This function resets the reader such that the next
       
    53 	// read operation will be performed from the start of
       
    54 	// the source.
       
    55 	// For a CFileReader the buffer is filled from the start
       
    56 	// of the file, for a CBufferReader the position in the 
       
    57 	// buffer is set to zero.
       
    58 	//
       
    59 	virtual void Reset() { iBufPos = 0; }
       
    60 	
       
    61 	//
       
    62 	// Seeks within the source.
       
    63 	// This function tries to support 64-bit compatible file
       
    64 	// formats as much as possible, but there may be some
       
    65 	// instances when the operation cannot be performed due to
       
    66 	// limitations of the file server.
       
    67 	//
       
    68 	virtual void SeekL(TInt64 aOffset) = 0;
       
    69 	
       
    70 	//
       
    71 	// Seeks within the source.
       
    72 	//
       
    73 	virtual void SeekL(TInt aOffset) = 0;
       
    74 	
       
    75 	//
       
    76 	// Returns the current position in the buffer.
       
    77 	//
       
    78 	virtual TInt Position() { return iBufPos; }
       
    79 		
       
    80 	//
       
    81 	// Data reading routines.
       
    82 	//
       
    83 	TBool Match(const TDesC8& aPattern);
       
    84 	void Read64L(TInt64& aData, TBool aLittleEndian = EFalse);
       
    85 	void Read32L(TUint32& aData, TBool aLittleEndian = EFalse);
       
    86 	void Read16L(TUint16& aData, TBool aLittleEndian = EFalse);
       
    87 	void ReadByteL(TUint8& aData);
       
    88 	void ReadBytesL(TDes8& aData);
       
    89 
       
    90 	//
       
    91 	// Gets the type of Reader being used.
       
    92 	//
       
    93 	inline TReaderType Type() { return iType; }
       
    94 		
       
    95 protected:
       
    96 	CReader(const TDesC8& aBuffer, CReader::TReaderType aType);
       
    97 	
       
    98 	//
       
    99 	// Returns ETrue if there is aAmount of unread bytes available,
       
   100 	// EFalse otherwise.
       
   101 	//
       
   102 	virtual TBool CheckEnoughData(TInt aAmount);
       
   103 	
       
   104 	//
       
   105 	// Non-leaving Seek
       
   106 	//
       
   107 	TInt Seek(TInt aOffset);
       
   108 	TInt Seek(TInt64 aOffset);
       
   109 	
       
   110 private:
       
   111 	const TDesC8& iBuffer;		// The buffer that contains the source data.
       
   112 	TInt iBufPos;				// The current position in the data source.
       
   113 	CReader::TReaderType iType;	// The type of reader it is.
       
   114 	};
       
   115 
       
   116 
       
   117 //
       
   118 // This class allows reading and seeking operations to be
       
   119 // performed on a data buffer. This is used when no file
       
   120 // handle is available to the recogniser.
       
   121 //
       
   122 class CBufferReader : public CReader
       
   123 	{
       
   124 public:
       
   125 	static CBufferReader* NewLC(const TDesC8& aBuffer);
       
   126 	virtual ~CBufferReader();
       
   127 	void Reset();
       
   128 	void SeekL(TInt aOffset);				// CReader
       
   129 	void SeekL(TInt64 aOffset);				// CReader
       
   130 
       
   131 protected:
       
   132 	CBufferReader(const TDesC8& aBuffer);
       
   133 	CBufferReader(const TDesC8& aBuffer, TReaderType aType);
       
   134 	void ConstructL();
       
   135 	};
       
   136 
       
   137 
       
   138 //
       
   139 // This class allows reading and seeking operations to be
       
   140 // performed on a file handle. This is used when a file
       
   141 // handle is available to the recogniser.
       
   142 //
       
   143 class CFileReader : public CBufferReader
       
   144 	{
       
   145 public:
       
   146 	static CFileReader* NewLC(RFile* aFile);
       
   147 	virtual ~CFileReader();
       
   148 	void Reset();
       
   149 	
       
   150 	//
       
   151 	// CReader::Position() override.
       
   152 	//
       
   153 	TInt Position() { return CBufferReader::Position() + iFilePos; }
       
   154 		
       
   155 	void SeekL(TInt aOffset);			// CReader
       
   156 	void SeekL(TInt64 aOffset);			// CReader
       
   157 	
       
   158 protected:
       
   159 	CFileReader(RFile* aFile);
       
   160 	void ConstructL();
       
   161 	TBool CheckEnoughData(TInt aAmount);	// CReader
       
   162 	
       
   163 	//
       
   164 	// Seeks to a new file location and fills the buffer from there.
       
   165 	//
       
   166 	TInt PhysicallySeekAndRead(TInt aAmount);
       
   167 	TInt PhysicallySeekAndRead(TInt64 aOffset);
       
   168 private:
       
   169 	RFile* iFile;
       
   170 	TInt64 iFilePos;
       
   171 	TBuf8<KBufSize> iFileBuffer;
       
   172 	};
       
   173 	
       
   174 	
       
   175 #endif
       
   176