Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include "constants.h"
23 static const TInt KAACFrameHeaderSize = 7;
24 static const TInt KMP3FrameHeaderSize = 4;
25 static const TInt KBufSize = 64;
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.
35 class CReader : public CBase
40 // Enums used so that CParsers can determine
41 // the type of reader they've been given.
52 // This function resets the reader such that the next
53 // read operation will be performed from the start of
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.
59 virtual void Reset() { iBufPos = 0; }
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.
68 virtual void SeekL(TInt64 aOffset) = 0;
71 // Seeks within the source.
73 virtual void SeekL(TInt aOffset) = 0;
76 // Returns the current position in the buffer.
78 virtual TInt Position() { return iBufPos; }
81 // Data reading routines.
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);
91 // Gets the type of Reader being used.
93 inline TReaderType Type() { return iType; }
96 CReader(const TDesC8& aBuffer, CReader::TReaderType aType);
99 // Returns ETrue if there is aAmount of unread bytes available,
102 virtual TBool CheckEnoughData(TInt aAmount);
107 TInt Seek(TInt aOffset);
108 TInt Seek(TInt64 aOffset);
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.
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.
122 class CBufferReader : public CReader
125 static CBufferReader* NewLC(const TDesC8& aBuffer);
126 virtual ~CBufferReader();
128 void SeekL(TInt aOffset); // CReader
129 void SeekL(TInt64 aOffset); // CReader
132 CBufferReader(const TDesC8& aBuffer);
133 CBufferReader(const TDesC8& aBuffer, TReaderType aType);
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.
143 class CFileReader : public CBufferReader
146 static CFileReader* NewLC(RFile* aFile);
147 virtual ~CFileReader();
151 // CReader::Position() override.
153 TInt Position() { return CBufferReader::Position() + iFilePos; }
155 void SeekL(TInt aOffset); // CReader
156 void SeekL(TInt64 aOffset); // CReader
159 CFileReader(RFile* aFile);
161 TBool CheckEnoughData(TInt aAmount); // CReader
164 // Seeks to a new file location and fills the buffer from there.
166 TInt PhysicallySeekAndRead(TInt aAmount);
167 TInt PhysicallySeekAndRead(TInt64 aOffset);
171 TBuf8<KBufSize> iFileBuffer;