JackTrip
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RingBuffer Class Reference

Provides a ring-buffer (or circular-buffer) that can be written to and read from asynchronously (blocking) or synchronously (non-blocking). More...

#include <RingBuffer.h>

Inheritance diagram for RingBuffer:
Inheritance graph
[legend]

Classes

struct  IOStat
 

Public Member Functions

 RingBuffer (int SlotSize, int NumSlots)
 The class constructor. More...
 
virtual ~RingBuffer ()
 The class destructor. More...
 
void insertSlotBlocking (const int8_t *ptrToSlot)
 Insert a slot into the RingBuffer from ptrToSlot. This method will block until there's space in the buffer. More...
 
void readSlotBlocking (int8_t *ptrToReadSlot)
 Read a slot from the RingBuffer into ptrToReadSlot. This method will block until there's space in the buffer. More...
 
virtual bool insertSlotNonBlocking (const int8_t *ptrToSlot, int len, int lostLen)
 Same as insertSlotBlocking but non-blocking (asynchronous) More...
 
virtual void readSlotNonBlocking (int8_t *ptrToReadSlot)
 Same as readSlotBlocking but non-blocking (asynchronous) More...
 
virtual void readBroadcastSlot (int8_t *ptrToReadSlot)
 
virtual bool getStats (IOStat *stat, bool reset)
 

Protected Member Functions

virtual void setUnderrunReadSlot (int8_t *ptrToReadSlot)
 Sets the memory in the Read Slot when uderrun occurs. By default, this sets it to 0. Override this method in a subclass for a different behavior. More...
 
virtual void setMemoryInReadSlotWithLastReadSlot (int8_t *ptrToReadSlot)
 Uses the last read slot to set the memory in the Read Slot. More...
 
void underrunReset ()
 Resets the ring buffer for reads under-runs non-blocking. More...
 
void overflowReset ()
 Resets the ring buffer for writes over-flows non-blocking. More...
 
void debugDump () const
 Helper method to debug, prints member variables to terminal. More...
 
void updateReadStats ()
 

Protected Attributes

int mSlotSize
 The size of one slot in byes. More...
 
int mNumSlots
 Number of Slots. More...
 
int mTotalSize
 Total size of the mRingBuffer = mSlotSize*mNumSlotss. More...
 
uint32_t mReadPosition
 Read Positions in the RingBuffer (Tail) More...
 
uint32_t mWritePosition
 Write Position in the RingBuffer (Head) More...
 
int mFullSlots
 Number of used (full) slots, in slot-size. More...
 
int8_tmRingBuffer
 8-bit array of data (1-byte) More...
 
int8_tmLastReadSlot
 Last slot read. More...
 
QMutex mMutex
 Mutex to protect read and write operations. More...
 
QWaitCondition mBufferIsNotFull
 Buffer not full condition to monitor threads. More...
 
QWaitCondition mBufferIsNotEmpty
 Buffer not empty condition to monitor threads. More...
 
int mStatUnit
 
uint32_t mUnderruns
 
uint32_t mOverflows
 
int32_t mSkewRaw
 
double mLevelCur
 
double mLevelDownRate
 
int32_t mLevel
 
uint32_t mBufDecOverflow
 
uint32_t mBufDecPktLoss
 
uint32_t mBufIncUnderrun
 
uint32_t mBufIncCompensate
 
uint32_t mReadsNew
 
uint32_t mUnderrunsNew
 
int32_t mSkew0
 
int32_t mBroadcastSkew
 
int32_t mBroadcastDelta
 

Detailed Description

Provides a ring-buffer (or circular-buffer) that can be written to and read from asynchronously (blocking) or synchronously (non-blocking).

The RingBuffer is an array of NumSlots slots of memory each of which is of size SlotSize bytes (8-bits). Slots can be read and written asynchronously/synchronously by multiple threads.

Constructor & Destructor Documentation

◆ RingBuffer()

RingBuffer::RingBuffer ( int  SlotSize,
int  NumSlots 
)

The class constructor.

Parameters
SlotSizeSize of one slot in bytes
NumSlotsNumber of slots

◆ ~RingBuffer()

RingBuffer::~RingBuffer ( )
virtual

The class destructor.

Member Function Documentation

◆ debugDump()

void RingBuffer::debugDump ( ) const
protected

Helper method to debug, prints member variables to terminal.

◆ getStats()

bool RingBuffer::getStats ( RingBuffer::IOStat stat,
bool  reset 
)
virtual

Reimplemented in JitterBuffer.

◆ insertSlotBlocking()

void RingBuffer::insertSlotBlocking ( const int8_t ptrToSlot)

Insert a slot into the RingBuffer from ptrToSlot. This method will block until there's space in the buffer.

The caller is responsible to make sure sizeof(WriteSlot) = SlotSize. This method should be use when the caller can block against its output, like sending/receiving UDP packets. It shouldn't be used by audio. For that, use the insertSlotNonBlocking.

Parameters
ptrToSlotPointer to slot to insert into the RingBuffer

◆ insertSlotNonBlocking()

bool RingBuffer::insertSlotNonBlocking ( const int8_t ptrToSlot,
int  len,
int  lostLen 
)
virtual

Same as insertSlotBlocking but non-blocking (asynchronous)

Parameters
ptrToSlotPointer to slot to insert into the RingBuffer
Todo:
It may be better here to insert the slot anyways, instead of not writing anything

Reimplemented in JitterBuffer.

◆ overflowReset()

void RingBuffer::overflowReset ( )
protected

Resets the ring buffer for writes over-flows non-blocking.

◆ readBroadcastSlot()

void RingBuffer::readBroadcastSlot ( int8_t ptrToReadSlot)
virtual

Reimplemented in JitterBuffer.

◆ readSlotBlocking()

void RingBuffer::readSlotBlocking ( int8_t ptrToReadSlot)

Read a slot from the RingBuffer into ptrToReadSlot. This method will block until there's space in the buffer.

The caller is responsible to make sure sizeof(ptrToReadSlot) = SlotSize. This method should be use when the caller can block against its input, like sending/receiving UDP packets. It shouldn't be used by audio. For that, use the readSlotNonBlocking.

Parameters
ptrToReadSlotPointer to read slot from the RingBuffer

◆ readSlotNonBlocking()

void RingBuffer::readSlotNonBlocking ( int8_t ptrToReadSlot)
virtual

Same as readSlotBlocking but non-blocking (asynchronous)

Parameters
ptrToReadSlotPointer to read slot from the RingBuffer

Reimplemented in JitterBuffer.

◆ setMemoryInReadSlotWithLastReadSlot()

void RingBuffer::setMemoryInReadSlotWithLastReadSlot ( int8_t ptrToReadSlot)
protectedvirtual

Uses the last read slot to set the memory in the Read Slot.

The last read slot is the last packet that arrived, so if no new packets are received, it keeps looping the same packet.

Parameters
ptrToReadSlotPointer to read slot from the RingBuffer

◆ setUnderrunReadSlot()

void RingBuffer::setUnderrunReadSlot ( int8_t ptrToReadSlot)
protectedvirtual

Sets the memory in the Read Slot when uderrun occurs. By default, this sets it to 0. Override this method in a subclass for a different behavior.

Parameters
ptrToReadSlotPointer to read slot from the RingBuffer

Reimplemented in RingBufferWavetable.

◆ underrunReset()

void RingBuffer::underrunReset ( )
protected

Resets the ring buffer for reads under-runs non-blocking.

◆ updateReadStats()

void RingBuffer::updateReadStats ( )
protected

Member Data Documentation

◆ mBroadcastDelta

int32_t RingBuffer::mBroadcastDelta
protected

◆ mBroadcastSkew

int32_t RingBuffer::mBroadcastSkew
protected

◆ mBufDecOverflow

uint32_t RingBuffer::mBufDecOverflow
protected

◆ mBufDecPktLoss

uint32_t RingBuffer::mBufDecPktLoss
protected

◆ mBufferIsNotEmpty

QWaitCondition RingBuffer::mBufferIsNotEmpty
protected

Buffer not empty condition to monitor threads.

◆ mBufferIsNotFull

QWaitCondition RingBuffer::mBufferIsNotFull
protected

Buffer not full condition to monitor threads.

◆ mBufIncCompensate

uint32_t RingBuffer::mBufIncCompensate
protected

◆ mBufIncUnderrun

uint32_t RingBuffer::mBufIncUnderrun
protected

◆ mFullSlots

int RingBuffer::mFullSlots
protected

Number of used (full) slots, in slot-size.

◆ mLastReadSlot

int8_t* RingBuffer::mLastReadSlot
protected

Last slot read.

◆ mLevel

int32_t RingBuffer::mLevel
protected

◆ mLevelCur

double RingBuffer::mLevelCur
protected

◆ mLevelDownRate

double RingBuffer::mLevelDownRate
protected

◆ mMutex

QMutex RingBuffer::mMutex
protected

Mutex to protect read and write operations.

◆ mNumSlots

int RingBuffer::mNumSlots
protected

Number of Slots.

◆ mOverflows

uint32_t RingBuffer::mOverflows
protected

◆ mReadPosition

uint32_t RingBuffer::mReadPosition
protected

Read Positions in the RingBuffer (Tail)

◆ mReadsNew

uint32_t RingBuffer::mReadsNew
protected

◆ mRingBuffer

int8_t* RingBuffer::mRingBuffer
protected

8-bit array of data (1-byte)

◆ mSkew0

int32_t RingBuffer::mSkew0
protected

◆ mSkewRaw

int32_t RingBuffer::mSkewRaw
protected

◆ mSlotSize

int RingBuffer::mSlotSize
protected

The size of one slot in byes.

◆ mStatUnit

int RingBuffer::mStatUnit
protected

◆ mTotalSize

int RingBuffer::mTotalSize
protected

Total size of the mRingBuffer = mSlotSize*mNumSlotss.

◆ mUnderruns

uint32_t RingBuffer::mUnderruns
protected

◆ mUnderrunsNew

uint32_t RingBuffer::mUnderrunsNew
protected

◆ mWritePosition

uint32_t RingBuffer::mWritePosition
protected

Write Position in the RingBuffer (Head)


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