| 1 |
/* |
|---|
| 2 |
* ringbuffer.h |
|---|
| 3 |
* |
|---|
| 4 |
* RingBuffer class definition. Simple ring buffer implementation. |
|---|
| 5 |
* |
|---|
| 6 |
* |
|---|
| 7 |
* Copyright (c) 2005,2007 Arek Korbik |
|---|
| 8 |
* |
|---|
| 9 |
* This file is part of XiphQT, the Xiph QuickTime Components. |
|---|
| 10 |
* |
|---|
| 11 |
* XiphQT is free software; you can redistribute it and/or |
|---|
| 12 |
* modify it under the terms of the GNU Lesser General Public |
|---|
| 13 |
* License as published by the Free Software Foundation; either |
|---|
| 14 |
* version 2.1 of the License, or (at your option) any later version. |
|---|
| 15 |
* |
|---|
| 16 |
* XiphQT is distributed in the hope that it will be useful, |
|---|
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 19 |
* Lesser General Public License for more details. |
|---|
| 20 |
* |
|---|
| 21 |
* You should have received a copy of the GNU Lesser General Public |
|---|
| 22 |
* License along with XiphQT; if not, write to the Free Software |
|---|
| 23 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 24 |
* |
|---|
| 25 |
* |
|---|
| 26 |
* Last modified: $Id: ringbuffer.h 12356 2007-01-20 00:18:04Z arek $ |
|---|
| 27 |
* |
|---|
| 28 |
*/ |
|---|
| 29 |
|
|---|
| 30 |
#if !defined(__ringbuffer_h__) |
|---|
| 31 |
#define __ringbuffer_h__ |
|---|
| 32 |
|
|---|
| 33 |
#include <list> |
|---|
| 34 |
|
|---|
| 35 |
using namespace std; |
|---|
| 36 |
|
|---|
| 37 |
class RingBuffer |
|---|
| 38 |
{ |
|---|
| 39 |
public: |
|---|
| 40 |
RingBuffer(); |
|---|
| 41 |
virtual ~RingBuffer(); |
|---|
| 42 |
|
|---|
| 43 |
public: |
|---|
| 44 |
virtual void Initialize(UInt32 inBufferByteSize); |
|---|
| 45 |
virtual void Uninitialize(); |
|---|
| 46 |
virtual void Reset(); |
|---|
| 47 |
virtual UInt32 Reallocate(UInt32 inBufferByteSize); |
|---|
| 48 |
|
|---|
| 49 |
virtual UInt32 GetBufferByteSize() const; |
|---|
| 50 |
virtual UInt32 GetDataAvailable() const; |
|---|
| 51 |
virtual UInt32 GetSpaceAvailable() const; |
|---|
| 52 |
|
|---|
| 53 |
// packet sizes are considered to be the same as each call to In() |
|---|
| 54 |
virtual UInt32 GetCurrentPacketSize() const { return packetSizes.front(); } |
|---|
| 55 |
virtual UInt32 GetNumPackets() const { return packetSizes.size(); } |
|---|
| 56 |
|
|---|
| 57 |
// reallocates the buffer as needed |
|---|
| 58 |
virtual void In(const void* data, UInt32& ioBytes); |
|---|
| 59 |
virtual void Zap(UInt32 inBytes); |
|---|
| 60 |
|
|---|
| 61 |
virtual Byte * GetData(); |
|---|
| 62 |
virtual Byte * GetDataEnd(); |
|---|
| 63 |
|
|---|
| 64 |
protected: |
|---|
| 65 |
Byte * mBuffer; |
|---|
| 66 |
|
|---|
| 67 |
UInt32 mBStart; |
|---|
| 68 |
UInt32 mBEnd; |
|---|
| 69 |
|
|---|
| 70 |
UInt32 mBSize; |
|---|
| 71 |
|
|---|
| 72 |
Boolean mNeedsWrapping; |
|---|
| 73 |
|
|---|
| 74 |
list<UInt32> packetSizes; |
|---|
| 75 |
}; |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
#endif /* __ringbuffer_h__ */ |
|---|