diff --git a/audio/drain/EndPointWrite.cpp b/audio/drain/EndPointWrite.cpp index e33da78..7130dfa 100644 --- a/audio/drain/EndPointWrite.cpp +++ b/audio/drain/EndPointWrite.cpp @@ -9,7 +9,9 @@ audio::drain::EndPointWrite::EndPointWrite() : m_function(nullptr), - m_bufferSizeMicroseconds(1000000) { + m_bufferSizeMicroseconds(1000000), + m_bufferSizeChunk(32), + m_bufferUnderFlowSize(0) { } @@ -71,14 +73,25 @@ bool audio::drain::EndPointWrite::process(audio::Time& _time, std::unique_lock lock(m_mutex); // check if data in the tmpBuffer if (m_buffer.getSize() == 0) { - DRAIN_WARNING("No data in the user buffer (write null data ... " << _outputNbChunk << " chunks)"); + if (m_bufferUnderFlowSize == 0) { + DRAIN_WARNING("No data in the user buffer (write null data ... " << _outputNbChunk << " chunks)"); + m_bufferUnderFlowSize = 1; + } else { + if (m_bufferUnderFlowSize == 1) { + m_bufferUnderFlowSize = 0; + } + m_bufferUnderFlowSize += _outputNbChunk; + } // clear the buffer to force the flush on the next elements ... m_outputData.clear(); _outputNbChunk = 0; generateStatus("EPW_UNDERFLOW"); // just send no data ... return true; + } else if (m_bufferUnderFlowSize > 1) { + DRAIN_WARNING("No data in the user buffer (write null data ... " << m_bufferUnderFlowSize << " chunks [In the past])"); } + m_bufferUnderFlowSize = 0; DRAIN_VERBOSE("Write " << _outputNbChunk << " chunks"); // check if we have enought data: int32_t nbChunkToCopy = std::min(_inputNbChunk, m_buffer.getSize()); diff --git a/audio/drain/EndPointWrite.hpp b/audio/drain/EndPointWrite.hpp index a929289..c2380f3 100644 --- a/audio/drain/EndPointWrite.hpp +++ b/audio/drain/EndPointWrite.hpp @@ -47,6 +47,7 @@ namespace audio { protected: std::chrono::microseconds m_bufferSizeMicroseconds; // 0 if m_bufferSizeChunk != 0 size_t m_bufferSizeChunk; // 0 if m_bufferSizeMicroseconds != 0 + size_t m_bufferUnderFlowSize; //!< Limit display of underflow in the write callback public: /** * @brief Set buffer size in chunk number