25#include <condition_variable>
40 using clock = std::chrono::high_resolution_clock;
55 const std::string&
getId()
const {
return id; }
67 std::vector<std::string>
74 std::lock_guard
l(writeLock_);
97 void put(std::shared_ptr<AudioFrame>&& data);
159 using ReadOffsetMap = std::map<std::string, ReadOffset>;
162 void putToBuffer(std::shared_ptr<AudioFrame>&& data);
164 bool hasNoReadOffsets()
const;
169 size_t getSmallestReadOffset()
const;
174 size_t getReadOffset(
const std::string&
ringbufferId)
const;
179 void storeReadOffset(
size_t offset,
const std::string&
ringbufferId);
184 bool hasThisReadOffset(
const std::string&
ringbufferId)
const;
191 const std::string id;
198 std::vector<std::shared_ptr<AudioFrame>> buffer_ {16};
200 mutable std::mutex lock_;
201 mutable std::condition_variable not_empty_;
202 std::mutex writeLock_;
204 ReadOffsetMap readoffsets_;
206 Resampler resampler_;
207 AudioFrameResizer resizer_;
209 std::atomic_bool rmsSignal_ {
false};
210 double rmsLevel_ {0};
211 int rmsFrameCount_ {0};
void setFrameSize(int frameSize)
void setFormat(const AudioFormat &format, int frameSize)
A ring buffer for mutichannel audio samples.
std::chrono::high_resolution_clock clock
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
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)