Commit 175c5381 authored by Adrien Béraud's avatar Adrien Béraud Committed by Philippe Gorley

ringbuffer: cleanup

Change-Id: I7c17134c7e91e670c732a0efb94dbaba4713cb5b
Reviewed-by: Philippe Gorley's avatarPhilippe Gorley <philippe.gorley@savoirfairelinux.com>
parent f8ba6bc8
......@@ -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 {
......
......@@ -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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment