summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-08-15 09:44:29 +1000
committerjacqueline <me@jacqueline.id.au>2024-08-15 09:44:29 +1000
commitd94c32d615e266de69f424261c46983ad10f9c70 (patch)
tree165b455f72b9348e205f4cfb6b0b6a53c32093fb /src
parent326cc42a63ec1bd8ff4e62da44658e8facd181c2 (diff)
parent40c754a72a23a849321b60dbd77fa1303c77953b (diff)
downloadtangara-fw-d94c32d615e266de69f424261c46983ad10f9c70.tar.gz
Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw
Diffstat (limited to 'src')
-rw-r--r--src/drivers/pcm_buffer.cpp13
-rw-r--r--src/tangara/audio/track_queue.cpp1
2 files changed, 11 insertions, 3 deletions
diff --git a/src/drivers/pcm_buffer.cpp b/src/drivers/pcm_buffer.cpp
index 3f4a0443..142a6376 100644
--- a/src/drivers/pcm_buffer.cpp
+++ b/src/drivers/pcm_buffer.cpp
@@ -66,10 +66,17 @@ IRAM_ATTR auto PcmBuffer::receive(std::span<int16_t> dest, bool isr)
auto PcmBuffer::clear() -> void {
while (!isEmpty()) {
- size_t bytes_cleared;
+ size_t bytes_cleared = 0;
void* data = xRingbufferReceive(ringbuf_, &bytes_cleared, 0);
- vRingbufferReturnItem(ringbuf_, data);
- received_ += bytes_cleared / sizeof(int16_t);
+ if (data) {
+ vRingbufferReturnItem(ringbuf_, data);
+ received_ += bytes_cleared / sizeof(int16_t);
+ } else {
+ // Defensively guard against looping forever if for some reason the
+ // buffer isn't draining.
+ ESP_LOGW(kTag, "PcmBuffer not draining");
+ break;
+ }
}
}
diff --git a/src/tangara/audio/track_queue.cpp b/src/tangara/audio/track_queue.cpp
index 5d730a09..6faa5340 100644
--- a/src/tangara/audio/track_queue.cpp
+++ b/src/tangara/audio/track_queue.cpp
@@ -290,6 +290,7 @@ auto TrackQueue::finish() -> void {
auto TrackQueue::clear() -> void {
{
const std::unique_lock<std::shared_mutex> lock(mutex_);
+ position_ = 0;
playlist_.clear();
opened_playlist_.reset();
if (shuffle_) {