wavelength 1.0.0
Loading...
Searching...
No Matches
streambuffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
12class StreamBuffer {
13public:
21 explicit StreamBuffer(int nSize);
22
29 virtual ~StreamBuffer();
30
43 virtual void Add(const char *pData, int nBytes, int bLast);
44
50 virtual void Poll() = 0;
51
58 virtual void Rewind();
59
69 bool IsEof();
70
80 bool IsEmpty();
81
93 char *AcquireReadRun(int nMaxBytes, int *pnBytes);
94
104 void CommitReadRun(char **ppRun);
105
114
125 int BytesAvailable(int *pbInputDone);
126
128 int GetSize() const {
129 return mSize;
130 }
131
133 char *GetBuffer() const {
134 return mBuffer.get();
135 }
136
137protected:
139
140private:
141 int mSize;
142 std::unique_ptr<char[]> mBuffer;
143 char *mReadHead;
144 char *mWriteHead;
145 char *mEndOfBuffer;
146 char *mReadRunEnd;
147 int mMargin;
148
149 // Report the heads through DebugPrint() when the write head is not before the end.
150 inline void CheckHeads();
151};
152
159extern int g_nAddWasEntered;
The ring buffer the EE streams samples into.
Definition streambuffer.h:17
virtual ~StreamBuffer()
Free the buffer.
virtual void Poll()=0
Let the producer append what it has.
char * AcquireReadRun(int nMaxBytes, int *pnBytes)
Take the next run of bytes, after a Poll().
int mInputDone
Definition streambuffer.h:138
virtual void Add(const char *pData, int nBytes, int bLast)
Append bytes behind the write head, wrapping at the end of the buffer.
int BytesAvailable(int *pbInputDone)
Report the bytes the consumer has not taken yet.
bool IsEmpty()
Report whether the consumer has taken every byte appended so far.
int EmptySpaceForFilling()
Report the room the producer may fill, which keeps mMargin bytes free.
char * GetBuffer() const
Definition streambuffer.h:133
bool IsEof()
Report whether the consumer took every byte and the producer has no more.
void CommitReadRun(char **ppRun)
Release the run AcquireReadRun() handed out, Poll(), and clear the caller's pointer.
virtual void Rewind()
Move both heads back to the start of the buffer.
StreamBuffer(int nSize)
Allocate a cleared buffer.
int GetSize() const
Definition streambuffer.h:128
int g_nAddWasEntered
Non-zero while StreamBuffer::Add() runs.