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