diff --git a/include/RTPBuffer.h b/include/RTPBuffer.h index 801a0ad..f13d99b 100644 --- a/include/RTPBuffer.h +++ b/include/RTPBuffer.h @@ -42,8 +42,9 @@ class RTPBuffer /*! * \param maxCapacity The maximum number of packages to buffer * \param maxDelay The maximum delay in milliseconds before dropping packages + * \param minBufferPackages The minimum of packages to buffer before returning valid audio-data */ - RTPBuffer(uint16_t maxCapacity, uint16_t maxDelay); + RTPBuffer(uint16_t maxCapacity, uint16_t maxDelay, uint16_t minBufferPackages = 1); virtual ~RTPBuffer(); /*! @@ -119,6 +120,11 @@ class RTPBuffer * The maximum delay (in milliseconds) before dropping a package */ const uint16_t maxDelay; + /*! + * The minimum number of packages this buffer must contain before packages are read. + * Until this lower limit is reached, silence-packages are returned. + */ + const uint16_t minBufferPackages; /*! * The index to read the next package from, the last position in the buffer */ diff --git a/src/RTPBuffer.cpp b/src/RTPBuffer.cpp index 19f665b..bbe67f6 100644 --- a/src/RTPBuffer.cpp +++ b/src/RTPBuffer.cpp @@ -12,7 +12,7 @@ //TODO implement maxDelay (problem: RTP-timestamp is not guaranteed to be in ms or ns or s, ...) -RTPBuffer::RTPBuffer(uint16_t maxCapacity, uint16_t maxDelay): capacity(maxCapacity), maxDelay(maxDelay) +RTPBuffer::RTPBuffer(uint16_t maxCapacity, uint16_t maxDelay, uint16_t minBufferPackages): capacity(maxCapacity), maxDelay(maxDelay), minBufferPackages(minBufferPackages) { nextReadIndex = 0; ringBuffer = new RTPBufferPackage[maxCapacity]; @@ -89,7 +89,7 @@ RTPBufferStatus RTPBuffer::addPackage(RTPPackage &package, unsigned int contentS RTPBufferStatus RTPBuffer::readPackage(RTPPackage &package) { lockMutex(); - if(size <= 0) + if(size < minBufferPackages) { //buffer is empty //write placeholder package