Ring Daemon
Loading...
Searching...
No Matches
jami::RingBuffer Class Reference

A ring buffer for mutichannel audio samples. More...

#include <ringbuffer.h>

Collaboration diagram for jami::RingBuffer:
Collaboration graph

Public Types

using clock = std::chrono::steady_clock
 
using FrameCallback = std::function< void(const std::shared_ptr< AudioFrame > &)>
 
using time_point = clock::time_point
 

Public Member Functions

size_t availableForGet (const std::string &ringbufferId) const
 To get how much samples are available in the buffer to read in.
 
void createReadOffset (const std::string &ringbufferId)
 Add a new readoffset for this ringbuffer.
 
void createReadOffset (const std::string &ringbufferId, FrameCallback cb)
 
void debug ()
 Debug function print mEnd, mStart, mBufferSize.
 
size_t discard (size_t toDiscard, const std::string &ringbufferId)
 Discard data from the buffer.
 
void flush (const std::string &ringbufferId)
 Reset the counters to 0 for this read offset.
 
void flushAll ()
 
std::shared_ptr< AudioFrameget (const std::string &ringbufferId)
 Get data in the ring buffer.
 
AudioFormat getFormat () const
 
const std::string & getId () const
 
size_t getLength (const std::string &ringbufferId) const
 
std::vector< std::string > getSubscribers ()
 Return the list of subscribers (Ring buffers Id that are reading this ring buffer).
 
bool isAudioMeterActive () const
 
bool isEmpty () const
 
bool isFull () const
 
void put (std::shared_ptr< AudioFrame > &&data)
 Write data in the ring buffer.
 
size_t putLength () const
 Total length of the ring buffer which is available for "putting".
 
size_t readOffsetCount () const
 
void removeReadOffset (const std::string &ringbufferId)
 Remove a readoffset for this ringbuffer.
 
 RingBuffer (const std::string &id, AudioFormat format=AudioFormat::MONO())
 Constructor.
 
void setAudioMeterState (bool state)
 
void setFormat (const AudioFormat &format)
 
void setFrameSize (int nb_samples)
 
size_t waitForDataAvailable (const std::string &ringbufferId, const time_point &deadline=time_point::max()) const
 Blocks until min_data_length samples of data is available, or until deadline has passed.
 
 ~RingBuffer ()
 Destructor.
 

Detailed Description

A ring buffer for mutichannel audio samples.

Definition at line 36 of file ringbuffer.h.

Member Typedef Documentation

◆ clock

using jami::RingBuffer::clock = std::chrono::steady_clock

Definition at line 39 of file ringbuffer.h.

◆ FrameCallback

using jami::RingBuffer::FrameCallback = std::function<void(const std::shared_ptr<AudioFrame>&)>

Definition at line 41 of file ringbuffer.h.

◆ time_point

using jami::RingBuffer::time_point = clock::time_point

Definition at line 40 of file ringbuffer.h.

Constructor & Destructor Documentation

◆ RingBuffer()

jami::RingBuffer::RingBuffer ( const std::string &  id,
AudioFormat  format = AudioFormat::MONO() 
)

Constructor.

Parameters
sizeSize of the buffer to create

Definition at line 33 of file ringbuffer.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ ~RingBuffer()

jami::RingBuffer::~RingBuffer ( )

Destructor.

Definition at line 47 of file ringbuffer.cpp.

References JAMI_LOG.

Member Function Documentation

◆ availableForGet()

size_t jami::RingBuffer::availableForGet ( const std::string &  ringbufferId) const

To get how much samples are available in the buffer to read in.

Returns
int The available (multichannel) samples number

Definition at line 213 of file ringbuffer.cpp.

References jami::emitSignal(), and getLength().

Here is the call graph for this function:

◆ createReadOffset() [1/2]

void jami::RingBuffer::createReadOffset ( const std::string &  ringbufferId)

Add a new readoffset for this ringbuffer.

Definition at line 130 of file ringbuffer.cpp.

References jami::emitSignal().

Referenced by jami::AudioLayer::AudioLayer().

Here is the call graph for this function:

◆ createReadOffset() [2/2]

void jami::RingBuffer::createReadOffset ( const std::string &  ringbufferId,
FrameCallback  cb 
)

◆ debug()

void jami::RingBuffer::debug ( )

Debug function print mEnd, mStart, mBufferSize.

Definition at line 95 of file ringbuffer.cpp.

References JAMI_DBG.

◆ discard()

size_t jami::RingBuffer::discard ( size_t  toDiscard,
const std::string &  ringbufferId 
)

Discard data from the buffer.

Parameters
toDiscardNumber of samples to discard
Returns
size_t Number of samples discarded

Definition at line 274 of file ringbuffer.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ flush()

void jami::RingBuffer::flush ( const std::string &  ringbufferId)

Reset the counters to 0 for this read offset.

Definition at line 53 of file ringbuffer.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ flushAll()

void jami::RingBuffer::flushAll ( )

◆ get()

std::shared_ptr< AudioFrame > jami::RingBuffer::get ( const std::string &  ringbufferId)

Get data in the ring buffer.

Parameters
ringbufferId
Returns
AudioFRame

Definition at line 220 of file ringbuffer.cpp.

References jami::emitSignal().

Referenced by jami::AudioLayer::getToPlay().

Here is the call graph for this function:

◆ getFormat()

AudioFormat jami::RingBuffer::getFormat ( ) const
inline

Definition at line 68 of file ringbuffer.h.

◆ getId()

const std::string & jami::RingBuffer::getId ( ) const
inline

Definition at line 54 of file ringbuffer.h.

◆ getLength()

size_t jami::RingBuffer::getLength ( const std::string &  ringbufferId) const

Definition at line 86 of file ringbuffer.cpp.

References jami::emitSignal().

Referenced by availableForGet().

Here is the call graph for this function:

◆ getSubscribers()

std::vector< std::string > jami::RingBuffer::getSubscribers ( )

Return the list of subscribers (Ring buffers Id that are reading this ring buffer).

Definition at line 66 of file ringbuffer.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ isAudioMeterActive()

bool jami::RingBuffer::isAudioMeterActive ( ) const
inline

Definition at line 147 of file ringbuffer.h.

◆ isEmpty()

bool jami::RingBuffer::isEmpty ( ) const
inline

Definition at line 127 of file ringbuffer.h.

References putLength().

Here is the call graph for this function:

◆ isFull()

bool jami::RingBuffer::isFull ( ) const
inline

Definition at line 125 of file ringbuffer.h.

References putLength().

Here is the call graph for this function:

◆ put()

void jami::RingBuffer::put ( std::shared_ptr< AudioFrame > &&  data)

Write data in the ring buffer.

Parameters
AudioFrame

Definition at line 163 of file ringbuffer.cpp.

References jami::emitSignal(), jami::AudioFrameResizer::enqueue(), and jami::Resampler::resample().

Referenced by jami::AudioLayer::notifyIncomingCall(), and jami::AudioLayer::putUrgent().

Here is the call graph for this function:

◆ putLength()

size_t jami::RingBuffer::putLength ( ) const

Total length of the ring buffer which is available for "putting".

Returns
int

Definition at line 76 of file ringbuffer.cpp.

References jami::emitSignal().

Referenced by isEmpty(), and isFull().

Here is the call graph for this function:

◆ readOffsetCount()

size_t jami::RingBuffer::readOffsetCount ( ) const
inline

Definition at line 89 of file ringbuffer.h.

◆ removeReadOffset()

void jami::RingBuffer::removeReadOffset ( const std::string &  ringbufferId)

Remove a readoffset for this ringbuffer.

Definition at line 138 of file ringbuffer.cpp.

References jami::emitSignal().

Here is the call graph for this function:

◆ setAudioMeterState()

void jami::RingBuffer::setAudioMeterState ( bool  state)
inline

Definition at line 148 of file ringbuffer.h.

◆ setFormat()

void jami::RingBuffer::setFormat ( const AudioFormat format)
inline

Definition at line 70 of file ringbuffer.h.

References jami::emitSignal(), jami::AudioFormat::sample_rate, and jami::AudioFrameResizer::setFormat().

Referenced by jami::AudioLayer::hardwareFormatAvailable().

Here is the call graph for this function:

◆ setFrameSize()

void jami::RingBuffer::setFrameSize ( int  nb_samples)
inline

Definition at line 129 of file ringbuffer.h.

References jami::emitSignal(), and jami::AudioFrameResizer::setFrameSize().

Here is the call graph for this function:

◆ waitForDataAvailable()

size_t jami::RingBuffer::waitForDataAvailable ( const std::string &  ringbufferId,
const time_point deadline = time_point::max() 
) const

Blocks until min_data_length samples of data is available, or until deadline has passed.

Parameters
ringbufferIdThe read offset for which data should be available.
min_data_lengthMinimum number of samples that should be available for the call to return
deadlineThe ringbufferId is guaranteed to end after this time point. If no deadline is provided, the call blocks indefinitely.
Returns
available data for ringbufferId after the call returned (same as calling getLength(ringbufferId) ).

Definition at line 243 of file ringbuffer.cpp.

References jami::emitSignal().

Here is the call graph for this function:

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