sl@0: // Copyright (c) 2006-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: // sl@0: sl@0: #ifndef READERS_H sl@0: #define READERS_H sl@0: sl@0: #include "constants.h" sl@0: #include "mmruf.h" sl@0: sl@0: sl@0: static const TInt KAACFrameHeaderSize = 7; sl@0: static const TInt KMP3FrameHeaderSize = 4; sl@0: static const TInt KBufSize = 64; sl@0: sl@0: sl@0: // sl@0: // This class provides a level of abstraction that allows sl@0: // for parsing data. It is necessary because AppArc may sl@0: // only provide a buffer that contains a limited snapshot sl@0: // of the beginning of a file, or a file handle that allows sl@0: // the whole file to be parsed. sl@0: // sl@0: class CReader : public CBase sl@0: { sl@0: public: sl@0: sl@0: // sl@0: // Enums used so that CParsers can determine sl@0: // the type of reader they've been given. sl@0: // sl@0: typedef enum sl@0: { sl@0: EUnknown = 0, sl@0: EBuffer = 1, sl@0: EFile = 2 sl@0: } sl@0: TReaderType; sl@0: sl@0: // sl@0: // This function resets the reader such that the next sl@0: // read operation will be performed from the start of sl@0: // the source. sl@0: // For a CFileReader the buffer is filled from the start sl@0: // of the file, for a CBufferReader the position in the sl@0: // buffer is set to zero. sl@0: // sl@0: virtual void Reset() { iBufPos = 0; } sl@0: sl@0: // sl@0: // Seeks within the source. sl@0: // This function tries to support 64-bit compatible file sl@0: // formats as much as possible, but there may be some sl@0: // instances when the operation cannot be performed due to sl@0: // limitations of the file server. sl@0: // sl@0: virtual void SeekL(TInt64 aOffset) = 0; sl@0: sl@0: // sl@0: // Seeks within the source. sl@0: // sl@0: virtual void SeekL(TInt aOffset) = 0; sl@0: sl@0: // sl@0: // Returns the current position in the buffer. sl@0: // sl@0: virtual TInt Position() { return iBufPos; } sl@0: sl@0: // sl@0: // Data reading routines. sl@0: // sl@0: TBool Match(const TDesC8& aPattern); sl@0: void Read64L(TInt64& aData, TBool aLittleEndian = EFalse); sl@0: void Read32L(TUint32& aData, TBool aLittleEndian = EFalse); sl@0: void Read16L(TUint16& aData, TBool aLittleEndian = EFalse); sl@0: void ReadByteL(TUint8& aData); sl@0: void ReadBytesL(TDes8& aData); sl@0: sl@0: // sl@0: // Gets the type of Reader being used. sl@0: // sl@0: inline TReaderType Type() { return iType; } sl@0: sl@0: protected: sl@0: CReader(const TDesC8& aBuffer, CReader::TReaderType aType); sl@0: sl@0: // sl@0: // Returns ETrue if there is aAmount of unread bytes available, sl@0: // EFalse otherwise. sl@0: // sl@0: virtual TBool CheckEnoughData(TInt aAmount); sl@0: sl@0: // sl@0: // Non-leaving Seek sl@0: // sl@0: TInt Seek(TInt aOffset); sl@0: TInt Seek(TInt64 aOffset); sl@0: sl@0: private: sl@0: const TDesC8& iBuffer; // The buffer that contains the source data. sl@0: TInt iBufPos; // The current position in the data source. sl@0: CReader::TReaderType iType; // The type of reader it is. sl@0: }; sl@0: sl@0: sl@0: // sl@0: // This class allows reading and seeking operations to be sl@0: // performed on a data buffer. This is used when no file sl@0: // handle is available to the recogniser. sl@0: // sl@0: class CBufferReader : public CReader sl@0: { sl@0: public: sl@0: static CBufferReader* NewLC(const TDesC8& aBuffer); sl@0: virtual ~CBufferReader(); sl@0: void Reset(); sl@0: void SeekL(TInt aOffset); // CReader sl@0: void SeekL(TInt64 aOffset); // CReader sl@0: sl@0: protected: sl@0: CBufferReader(const TDesC8& aBuffer); sl@0: CBufferReader(const TDesC8& aBuffer, TReaderType aType); sl@0: void ConstructL(); sl@0: }; sl@0: sl@0: sl@0: // sl@0: // This class allows reading and seeking operations to be sl@0: // performed on a file handle. This is used when a file sl@0: // handle is available to the recogniser. sl@0: // sl@0: class CFileReader : public CBufferReader sl@0: { sl@0: public: sl@0: static CFileReader* NewLC(RFile* aFile); sl@0: virtual ~CFileReader(); sl@0: void Reset(); sl@0: sl@0: // sl@0: // CReader::Position() override. sl@0: // sl@0: TInt Position() { return CBufferReader::Position() + iFilePos; } sl@0: sl@0: void SeekL(TInt aOffset); // CReader sl@0: void SeekL(TInt64 aOffset); // CReader sl@0: sl@0: protected: sl@0: CFileReader(RFile* aFile); sl@0: void ConstructL(); sl@0: TBool CheckEnoughData(TInt aAmount); // CReader sl@0: sl@0: // sl@0: // Seeks to a new file location and fills the buffer from there. sl@0: // sl@0: TInt PhysicallySeekAndRead(TInt aAmount); sl@0: TInt PhysicallySeekAndRead(TInt64 aOffset); sl@0: private: sl@0: RFile* iFile; sl@0: TInt64 iFilePos; sl@0: TBuf8 iFileBuffer; sl@0: }; sl@0: sl@0: sl@0: #endif sl@0: