Skip to content

Commit 29ad6c2

Browse files
Bail out after 2000ms if buffer empty
1 parent cb66e6e commit 29ad6c2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/ESP32_VS1053_Stream.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,26 @@ void ESP32_VS1053_Stream::_playFromRingBuffer()
399399
portDISABLE_INTERRUPTS();
400400
uint8_t *data = (uint8_t *)xRingbufferReceiveUpTo(_ringbuffer_handle, &size, pdMS_TO_TICKS(0), VS1053_PLAYBUFFER_SIZE);
401401
portENABLE_INTERRUPTS();
402+
static auto ringbufferEmpty = 0;
402403
if (!data)
403404
{
404-
log_i("No ringbuffer data available");
405-
break;
405+
if (!ringbufferEmpty)
406+
{
407+
ringbufferEmpty = millis();
408+
ringbufferEmpty += ringbufferEmpty ? 0 : 1;
409+
log_i("No buffer data available");
410+
return;
411+
}
412+
const auto BAILOUT_MS = 2000;
413+
if (millis() - ringbufferEmpty > BAILOUT_MS)
414+
{
415+
log_e("Buffer empty for %i ms, bailing out...", BAILOUT_MS);
416+
_remainingBytes = 0;
417+
return;
418+
}
419+
return;
406420
}
421+
ringbufferEmpty = 0;
407422
_vs1053->playChunk(data, size);
408423
vRingbufferReturnItem(_ringbuffer_handle, data);
409424
// bytesToDecoder += size;

0 commit comments

Comments
 (0)