From ee29f6dbd130f26ed51b7a94b34790ba4c039089 Mon Sep 17 00:00:00 2001 From: MaPePeR Date: Fri, 1 Jun 2018 14:10:54 +0200 Subject: Check if overruns occured even when drift compensation is not turned on (cherry picked from commit 15610351b76113f1026e4ad40ec7ba9926d09498) --- src/SampleQueue.h | 9 ++++++++- src/odr-audioenc.cpp | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/SampleQueue.h b/src/SampleQueue.h index dd01986..646f3dd 100644 --- a/src/SampleQueue.h +++ b/src/SampleQueue.h @@ -120,10 +120,12 @@ public: /*! Wait until len elements in the queue are available, * and then fill the buf. If the timeout_ms (expressed in milliseconds * expires), fill the available number of elements. + * Also update the overrun variable with the information + * of how many overruns we saw since the last pop. * * \return the number of elemets written into buf */ - size_t pop_wait(T* buf, size_t len, int timeout_ms) + size_t pop_wait(T* buf, size_t len, int timeout_ms, size_t* overruns = NULL) { assert(len % (m_channels * m_bytes_per_sample) == 0); @@ -132,6 +134,11 @@ public: #endif std::unique_lock lock(m_mutex); + if (overruns) { + *overruns = m_overruns; + m_overruns = 0; + } + auto time_start = std::chrono::steady_clock::now(); const auto timeout = std::chrono::milliseconds(timeout_ms); diff --git a/src/odr-audioenc.cpp b/src/odr-audioenc.cpp index da9b93a..b5f7b9f 100644 --- a/src/odr-audioenc.cpp +++ b/src/odr-audioenc.cpp @@ -1099,9 +1099,16 @@ int main(int argc, char *argv[]) const int timeout_ms = 10000; read_bytes = input_buf.size(); + size_t overruns = 0; + /*! pop_wait() must return after a timeout, otherwise the silence detector cannot do * its job. */ - size_t bytes_from_queue = queue.pop_wait(&input_buf[0], read_bytes, timeout_ms); // returns bytes + size_t bytes_from_queue = queue.pop_wait(&input_buf[0], read_bytes, timeout_ms, &overruns); // returns bytes + + if (overruns) { + fprintf(stderr, "%zd overruns occured!\n", overruns); + status |= STATUS_OVERRUN; + } if (bytes_from_queue < read_bytes) { // queue timeout occurred -- cgit v1.2.3