diff --git a/src/media/audio/ringbuffer.cpp b/src/media/audio/ringbuffer.cpp index f70c37b854a7e262f93d8bbc4e7dd13de6b90497..e21415f54c5e699b66a32a37b7d4a2f72a445ed1 100644 --- a/src/media/audio/ringbuffer.cpp +++ b/src/media/audio/ringbuffer.cpp @@ -90,8 +90,6 @@ RingBuffer::debug() size_t RingBuffer::getReadOffset(const std::string &call_id) const { - if (hasNoReadOffsets()) - return 0; ReadOffset::const_iterator iter = readoffsets_.find(call_id); return (iter != readoffsets_.end()) ? iter->second : 0; } @@ -207,9 +205,6 @@ size_t RingBuffer::get(AudioBuffer& buf, const std::string &call_id) { std::lock_guard<std::mutex> l(lock_); - if (hasNoReadOffsets()) - return 0; - if (not hasThisReadOffset(call_id)) return 0; @@ -247,7 +242,7 @@ size_t RingBuffer::get(AudioBuffer& buf, const std::string &call_id) } -size_t RingBuffer::waitForDataAvailable(const std::string &call_id, const size_t min_data_length, const std::chrono::high_resolution_clock::time_point& deadline) const +size_t RingBuffer::waitForDataAvailable(const std::string &call_id, size_t min_data_length, const time_point& deadline) const { std::unique_lock<std::mutex> l(lock_); @@ -266,7 +261,7 @@ size_t RingBuffer::waitForDataAvailable(const std::string &call_id, const size_t return getl >= min_data_length; }; - if (deadline == std::chrono::high_resolution_clock::time_point()) { + if (deadline == time_point::max()) { // no timeout provided, wait as long as necessary not_empty_.wait(l, check); } else { diff --git a/src/media/audio/ringbuffer.h b/src/media/audio/ringbuffer.h index 785d86cacad9cf3ad3e21c30b29b62ce2435991b..5db1ec18e5b16983fc5b266bcac11436ebbc9bda 100644 --- a/src/media/audio/ringbuffer.h +++ b/src/media/audio/ringbuffer.h @@ -21,8 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef __RING_BUFFER__ -#define __RING_BUFFER__ +#pragma once #include "audiobuffer.h" #include "noncopyable.h" @@ -34,7 +33,6 @@ #include <vector> #include <fstream> -typedef std::map<std::string, size_t> ReadOffset; namespace ring { @@ -43,6 +41,9 @@ namespace ring { */ class RingBuffer { public: + using clock = std::chrono::high_resolution_clock; + using time_point = clock::time_point; + /** * Constructor * @param size Size of the buffer to create @@ -77,8 +78,6 @@ class RingBuffer { size_t readOffsetCount() const { return readoffsets_.size(); } - bool hasNoReadOffsets() const; - /** * Write data in the ring buffer * @param buffer Data to copied @@ -123,7 +122,6 @@ class RingBuffer { return putLength() == 0; } - /** * Blocks until min_data_length samples of data is available, or until deadline has passed. * @@ -132,7 +130,7 @@ class RingBuffer { * @param deadline The call is guaranteed to end after this time point. If no deadline is provided, the call blocks indefinitely. * @return available data for call_id after the call returned (same as calling getLength(call_id) ). */ - size_t waitForDataAvailable(const std::string &call_id, const size_t min_data_length, const std::chrono::high_resolution_clock::time_point& deadline = {}) const; + size_t waitForDataAvailable(const std::string& call_id, size_t min_data_length, const time_point& deadline = time_point::max()) const; /** * Debug function print mEnd, mStart, mBufferSize @@ -142,8 +140,11 @@ class RingBuffer { const std::string id; private: + using ReadOffset = std::map<std::string, size_t>; NON_COPYABLE(RingBuffer); + bool hasNoReadOffsets() const; + /** * Return the smalest readoffset. Useful to evaluate if ringbuffer is full */ @@ -182,5 +183,3 @@ class RingBuffer { }; } // namespace ring - -#endif /* __RING_BUFFER__ */