Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

CircularBuffer Class Reference

Inherited by ResamplingBuffer.

List of all members.


Detailed Description

Simple circular buffer for one producer and consumer with a head and a tail that chase each other. The capacity is 1 byte bigger than necessary due to a sentinel, to tell apart full from empty by the following equations:

full := head_next == tail empty := head == tail

Inspired by CircularBuffer from beaudio. We need a lock when updating the tail index, due to the overwrite mechanism in case of buffer overflow. The head index needs no locking because overwrite does not make sense in case of buffer underrun.

Keep in mind that this buffer does no know about frames or packets, it's up to you to make sure you get the right number of bytes. In doubt use size() to compute how many frames/packets it is save to drain/fill.

Definition at line 581 of file beaudio.cxx.


Public Types

enum  State {
  Empty = 1, Filled = 2, NotFull = 3, Full = 4,
  NotEmpty = 6, Flushed = 8, FullEnough = 16, EmptyEnough = 32
}

Public Member Functions

 CircularBuffer (PINDEX len)
 CircularBuffer (PINDEX size, PINDEX fillthreshold=0, PINDEX drainthreshold=0)
PINDEX Drain (char *outbuf, PINDEX len, Boolean lock=true)
void Drain (BYTE **extbuf, size_t *extsize)
BOOL Empty ()
PINDEX Fill (const char *inbuf, PINDEX len, Boolean lock=true, Boolean overwrite=false)
void Fill (const BYTE **extbuf, size_t *extsize)
PINDEX free ()
BOOL Full ()
PINDEX GetSize (void)
bool IsEmpty ()
bool IsFull ()
void Reset (void)
PINDEX size ()
void WaitForState (State state)

Protected Member Functions

virtual size_t Read (BYTE **extbuf, const BYTE *src, size_t *extsize, size_t size)
void UpdateState (void)
virtual size_t Write (BYTE *dest, const BYTE **extbuf, size_t size, size_t *extsize)

Protected Attributes

BYTE * mBuffer
volatile PINDEX mDrainThreshold
volatile PINDEX mFillThreshold
volatile PINDEX mHead
volatile PINDEX mHeadRoom
sem_id mSemInUse
sem_id mSemStateChange
PINDEX mSize
volatile PINDEX mSizeUsed
volatile State mState
volatile PINDEX mTail
volatile PINDEX mTailRoom

Private Member Functions

PINDEX head_next ()
void increment_head (PINDEX inc)
void increment_index (PINDEX &index, PINDEX inc)
void increment_tail (PINDEX inc)

Private Attributes

char * buffer
const PINDEX capacity
pthread_cond_t cond
PINDEX head
Boolean init
pthread_mutex_t mutex
PINDEX tail

Friends

class ResamplingBuffer

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index