Ring Daemon 16.0.0
|
Buffers extra samples. More...
#include <audio_frame_resizer.h>
Public Member Functions | |
AudioFrameResizer (const AudioFormat &format, int frameSize, std::function< void(std::shared_ptr< AudioFrame > &&)> cb={}) | |
std::shared_ptr< AudioFrame > | dequeue () |
Notifies owner of a new frame. | |
void | enqueue (std::shared_ptr< AudioFrame > &&frame) |
Write @frame's data to the queue. | |
AudioFormat | format () const |
Gets the format used by @queue_, input frames must match this format or enqueuing will fail. | |
int | frameSize () const |
Gets the number of samples per output frame. | |
int | samples () const |
Gets the numbers of samples available for reading. | |
void | setFormat (const AudioFormat &format, int frameSize) |
void | setFrameSize (int frameSize) |
~AudioFrameResizer () | |
Buffers extra samples.
This is in case an input's frame size (number of samples in a frame) and the output's frame size don't match. The queue will store the extra samples until a frame can be read. Will call passed in callback once a frame is output.
Works at frame-level instead of sample- or byte-level like FFmpeg's FIFO buffers.
Definition at line 38 of file audio_frame_resizer.h.
jami::AudioFrameResizer::AudioFrameResizer | ( | const AudioFormat & | format, |
int | frameSize, | ||
std::function< void(std::shared_ptr< AudioFrame > &&)> | cb = {} |
||
) |
Definition at line 30 of file audio_frame_resizer.cpp.
jami::AudioFrameResizer::~AudioFrameResizer | ( | ) |
Definition at line 39 of file audio_frame_resizer.cpp.
References jami::emitSignal().
std::shared_ptr< AudioFrame > jami::AudioFrameResizer::dequeue | ( | ) |
Notifies owner of a new frame.
Definition at line 126 of file audio_frame_resizer.cpp.
References jami::emitSignal(), jami::libav_utils::getError(), JAMI_ERR, and samples().
Referenced by enqueue(), jami::NullAudioProcessor::getProcessed(), jami::SpeexAudioProcessor::getProcessed(), jami::WebRTCAudioProcessor::getProcessed(), setFrameSize(), and jami::AudioProcessor::tidyQueues().
void jami::AudioFrameResizer::enqueue | ( | std::shared_ptr< AudioFrame > && | frame | ) |
Write @frame's data to the queue.
The internal buffer will be reallocated if there's not enough space for @frame's samples.
Returns the number of samples written, or negative on error.
NOTE @frame's format must match @format_, or this will fail.
Definition at line 88 of file audio_frame_resizer.cpp.
References dequeue(), jami::emitSignal(), format(), jami::libav_utils::getError(), JAMI_ERR, JAMI_WARNING, samples(), setFormat(), and jami::AudioFormat::toString().
Referenced by jami::RingBuffer::put().
AudioFormat jami::AudioFrameResizer::format | ( | ) | const |
Gets the format used by @queue_, input frames must match this format or enqueuing will fail.
Returned frames are in this format.
Definition at line 57 of file audio_frame_resizer.cpp.
Referenced by enqueue(), and setFormat().
int jami::AudioFrameResizer::frameSize | ( | ) | const |
Gets the number of samples per output frame.
Definition at line 51 of file audio_frame_resizer.cpp.
Referenced by setFrameSize(), and jami::AudioProcessor::tidyQueues().
int jami::AudioFrameResizer::samples | ( | ) | const |
Gets the numbers of samples available for reading.
Definition at line 45 of file audio_frame_resizer.cpp.
References jami::emitSignal().
Referenced by dequeue(), enqueue(), jami::WebRTCAudioProcessor::getProcessed(), setFormat(), and jami::AudioProcessor::tidyQueues().
void jami::AudioFrameResizer::setFormat | ( | const AudioFormat & | format, |
int | frameSize | ||
) |
Definition at line 63 of file audio_frame_resizer.cpp.
References jami::emitSignal(), format(), JAMI_WARN, jami::AudioFormat::nb_channels, jami::AudioFormat::sampleFormat, samples(), and setFrameSize().
Referenced by enqueue(), and jami::RingBuffer::setFormat().
Definition at line 77 of file audio_frame_resizer.cpp.
References dequeue(), jami::emitSignal(), and frameSize().
Referenced by setFormat(), and jami::RingBuffer::setFrameSize().