mirror of
https://github.com/esphome/esphome.git
synced 2026-05-28 04:55:48 +08:00
proactively release the item in the ring buffer when it's fully consumed
This commit is contained in:
@@ -242,8 +242,13 @@ void RingBufferAudioSource::consume(size_t bytes) {
|
|||||||
bytes = std::min(bytes, this->current_available_);
|
bytes = std::min(bytes, this->current_available_);
|
||||||
this->current_data_ += bytes;
|
this->current_data_ += bytes;
|
||||||
this->current_available_ -= bytes;
|
this->current_available_ -= bytes;
|
||||||
// Release of the held item and promotion of queued data are deferred to fill() so callers see new
|
// Promotion of queued data is deferred to fill() so callers see new data as a fresh return value
|
||||||
// data as a fresh return value rather than appearing silently after consume().
|
// rather than appearing silently after consume(). When the held item has nothing left depending
|
||||||
|
// on it (no exposed bytes and no queued region), release it now so the ring buffer can be
|
||||||
|
// reclaimed by writers even if fill() is never called again.
|
||||||
|
if (this->current_available_ == 0 && this->queued_length_ == 0) {
|
||||||
|
this->release_item_();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RingBufferAudioSource::has_buffered_data() const {
|
bool RingBufferAudioSource::has_buffered_data() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user