25#include <condition_variable>
39 using clock = std::chrono::steady_clock;
54 const std::string&
getId()
const {
return id; }
72 std::lock_guard
l(writeLock_);
95 void put(std::shared_ptr<AudioFrame>&& data);
156 using ReadOffsetMap = std::map<std::string, ReadOffset>;
159 void putToBuffer(std::shared_ptr<AudioFrame>&& data);
161 bool hasNoReadOffsets()
const;
166 size_t getSmallestReadOffset()
const;
171 size_t getReadOffset(
const std::string&
ringbufferId)
const;
176 void storeReadOffset(
size_t offset,
const std::string&
ringbufferId);
181 bool hasThisReadOffset(
const std::string&
ringbufferId)
const;
188 const std::string id;
195 std::vector<std::shared_ptr<AudioFrame>> buffer_ {16};
197 mutable std::mutex lock_;
198 mutable std::condition_variable not_empty_;
199 std::mutex writeLock_;
201 ReadOffsetMap readoffsets_;
203 Resampler resampler_;
204 AudioFrameResizer resizer_;
206 std::atomic_bool rmsSignal_ {
false};
207 double rmsLevel_ {0};
208 int rmsFrameCount_ {0};
void setFrameSize(int frameSize)
void setFormat(const AudioFormat &format, int frameSize)
A ring buffer for mutichannel audio samples.
std::function< void(const std::shared_ptr< AudioFrame > &)> FrameCallback
void createReadOffset(const std::string &ringbufferId, FrameCallback cb)
void debug()
Debug function print mEnd, mStart, mBufferSize.
void setFormat(const AudioFormat &format)
clock::time_point time_point
void removeReadOffset(const std::string &ringbufferId)
Remove a readoffset for this ringbuffer.
void flush(const std::string &ringbufferId)
Reset the counters to 0 for this read offset.
void createReadOffset(const std::string &ringbufferId)
Add a new readoffset for this ringbuffer.
size_t availableForGet(const std::string &ringbufferId) const
To get how much samples are available in the buffer to read in.
std::shared_ptr< AudioFrame > get(const std::string &ringbufferId)
Get data in the ring buffer.
size_t readOffsetCount() const
std::vector< std::string > getSubscribers()
Return the list of subscribers (Ring buffers Id that are reading this ring buffer).
bool isAudioMeterActive() const
size_t getLength(const std::string &ringbufferId) const
std::chrono::steady_clock clock
size_t discard(size_t toDiscard, const std::string &ringbufferId)
Discard data from the buffer.
void put(std::shared_ptr< AudioFrame > &&data)
Write data in the ring buffer.
const std::string & getId() const
void setAudioMeterState(bool state)
size_t putLength() const
Total length of the ring buffer which is available for "putting".
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.
void setFrameSize(int nb_samples)
AudioFormat getFormat() const
void emitSignal(Args... args)
Simple macro to hide class' copy constructor and assignment operator.
#define NON_COPYABLE(ClassName)