1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/Recogniser/src/readers.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,176 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef READERS_H
1.20 +#define READERS_H
1.21 +
1.22 +#include "constants.h"
1.23 +#include "mmruf.h"
1.24 +
1.25 +
1.26 +static const TInt KAACFrameHeaderSize = 7;
1.27 +static const TInt KMP3FrameHeaderSize = 4;
1.28 +static const TInt KBufSize = 64;
1.29 +
1.30 +
1.31 +//
1.32 +// This class provides a level of abstraction that allows
1.33 +// for parsing data. It is necessary because AppArc may
1.34 +// only provide a buffer that contains a limited snapshot
1.35 +// of the beginning of a file, or a file handle that allows
1.36 +// the whole file to be parsed.
1.37 +//
1.38 +class CReader : public CBase
1.39 + {
1.40 +public:
1.41 +
1.42 + //
1.43 + // Enums used so that CParsers can determine
1.44 + // the type of reader they've been given.
1.45 + //
1.46 + typedef enum
1.47 + {
1.48 + EUnknown = 0,
1.49 + EBuffer = 1,
1.50 + EFile = 2
1.51 + }
1.52 + TReaderType;
1.53 +
1.54 + //
1.55 + // This function resets the reader such that the next
1.56 + // read operation will be performed from the start of
1.57 + // the source.
1.58 + // For a CFileReader the buffer is filled from the start
1.59 + // of the file, for a CBufferReader the position in the
1.60 + // buffer is set to zero.
1.61 + //
1.62 + virtual void Reset() { iBufPos = 0; }
1.63 +
1.64 + //
1.65 + // Seeks within the source.
1.66 + // This function tries to support 64-bit compatible file
1.67 + // formats as much as possible, but there may be some
1.68 + // instances when the operation cannot be performed due to
1.69 + // limitations of the file server.
1.70 + //
1.71 + virtual void SeekL(TInt64 aOffset) = 0;
1.72 +
1.73 + //
1.74 + // Seeks within the source.
1.75 + //
1.76 + virtual void SeekL(TInt aOffset) = 0;
1.77 +
1.78 + //
1.79 + // Returns the current position in the buffer.
1.80 + //
1.81 + virtual TInt Position() { return iBufPos; }
1.82 +
1.83 + //
1.84 + // Data reading routines.
1.85 + //
1.86 + TBool Match(const TDesC8& aPattern);
1.87 + void Read64L(TInt64& aData, TBool aLittleEndian = EFalse);
1.88 + void Read32L(TUint32& aData, TBool aLittleEndian = EFalse);
1.89 + void Read16L(TUint16& aData, TBool aLittleEndian = EFalse);
1.90 + void ReadByteL(TUint8& aData);
1.91 + void ReadBytesL(TDes8& aData);
1.92 +
1.93 + //
1.94 + // Gets the type of Reader being used.
1.95 + //
1.96 + inline TReaderType Type() { return iType; }
1.97 +
1.98 +protected:
1.99 + CReader(const TDesC8& aBuffer, CReader::TReaderType aType);
1.100 +
1.101 + //
1.102 + // Returns ETrue if there is aAmount of unread bytes available,
1.103 + // EFalse otherwise.
1.104 + //
1.105 + virtual TBool CheckEnoughData(TInt aAmount);
1.106 +
1.107 + //
1.108 + // Non-leaving Seek
1.109 + //
1.110 + TInt Seek(TInt aOffset);
1.111 + TInt Seek(TInt64 aOffset);
1.112 +
1.113 +private:
1.114 + const TDesC8& iBuffer; // The buffer that contains the source data.
1.115 + TInt iBufPos; // The current position in the data source.
1.116 + CReader::TReaderType iType; // The type of reader it is.
1.117 + };
1.118 +
1.119 +
1.120 +//
1.121 +// This class allows reading and seeking operations to be
1.122 +// performed on a data buffer. This is used when no file
1.123 +// handle is available to the recogniser.
1.124 +//
1.125 +class CBufferReader : public CReader
1.126 + {
1.127 +public:
1.128 + static CBufferReader* NewLC(const TDesC8& aBuffer);
1.129 + virtual ~CBufferReader();
1.130 + void Reset();
1.131 + void SeekL(TInt aOffset); // CReader
1.132 + void SeekL(TInt64 aOffset); // CReader
1.133 +
1.134 +protected:
1.135 + CBufferReader(const TDesC8& aBuffer);
1.136 + CBufferReader(const TDesC8& aBuffer, TReaderType aType);
1.137 + void ConstructL();
1.138 + };
1.139 +
1.140 +
1.141 +//
1.142 +// This class allows reading and seeking operations to be
1.143 +// performed on a file handle. This is used when a file
1.144 +// handle is available to the recogniser.
1.145 +//
1.146 +class CFileReader : public CBufferReader
1.147 + {
1.148 +public:
1.149 + static CFileReader* NewLC(RFile* aFile);
1.150 + virtual ~CFileReader();
1.151 + void Reset();
1.152 +
1.153 + //
1.154 + // CReader::Position() override.
1.155 + //
1.156 + TInt Position() { return CBufferReader::Position() + iFilePos; }
1.157 +
1.158 + void SeekL(TInt aOffset); // CReader
1.159 + void SeekL(TInt64 aOffset); // CReader
1.160 +
1.161 +protected:
1.162 + CFileReader(RFile* aFile);
1.163 + void ConstructL();
1.164 + TBool CheckEnoughData(TInt aAmount); // CReader
1.165 +
1.166 + //
1.167 + // Seeks to a new file location and fills the buffer from there.
1.168 + //
1.169 + TInt PhysicallySeekAndRead(TInt aAmount);
1.170 + TInt PhysicallySeekAndRead(TInt64 aOffset);
1.171 +private:
1.172 + RFile* iFile;
1.173 + TInt64 iFilePos;
1.174 + TBuf8<KBufSize> iFileBuffer;
1.175 + };
1.176 +
1.177 +
1.178 +#endif
1.179 +