From d67acb8a642aa7c361a8e2335c009e668840611f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 17 Aug 2021 10:00:19 -0500 Subject: [PATCH] MP3Decoder: Fix playback stopping issue Closes: #5164 --- shared-module/audiomp3/MP3Decoder.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shared-module/audiomp3/MP3Decoder.c b/shared-module/audiomp3/MP3Decoder.c index 27c69f735b..cc755d7d2f 100644 --- a/shared-module/audiomp3/MP3Decoder.c +++ b/shared-module/audiomp3/MP3Decoder.c @@ -319,6 +319,7 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t * uint8_t **bufptr, uint32_t *buffer_length) { if (!self->inbuf) { + *buffer_length = 0; return GET_BUFFER_ERROR; } if (!single_channel_output) { @@ -342,6 +343,7 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t * mp3file_skip_id3v2(self); if (!mp3file_find_sync_word(self)) { + *buffer_length = 0; return self->eof ? GET_BUFFER_DONE : GET_BUFFER_ERROR; } int bytes_left = BYTES_LEFT(self); @@ -349,6 +351,11 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t * int err = MP3Decode(self->decoder, &inbuf, &bytes_left, buffer, 0); CONSUME(self, BYTES_LEFT(self) - bytes_left); + if (err) { + *buffer_length = 0; + return GET_BUFFER_DONE; + } + if (self->inbuf_offset >= 512) { background_callback_add( &self->inbuf_fill_cb, @@ -356,10 +363,6 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t * self); } - if (err) { - return GET_BUFFER_DONE; - } - return GET_BUFFER_MORE_DATA; }