Skip to content

Commit df5f7bc

Browse files
committed
MP3Decoder: better handle indicating end of mp3 audio data to caller
The old formulation * wouldn't work if there were ID3 tags at the end * would choose whether to background-refill the inbuf based on a check before skipping to the next sync word, which could be incorrect. I think it was aspect "B" that ended up triggering the erroneous EOF problem fixed in the prior commit. This would depend on specific data sizes and offsets occuring in the file such that a read would be scheduled but then the buffer would be filled and left 100% full by find_sync_word(). It's just lucky(?) that a particular person produced such a file, and/or many files produced by Audacity have those characteristics.
1 parent 1841af9 commit df5f7bc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

shared-module/audiomp3/MP3Decoder.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,19 @@ audioio_get_buffer_result_t audiomp3_mp3file_get_buffer(audiomp3_mp3file_obj_t *
356356
return GET_BUFFER_DONE;
357357
}
358358

359+
self->samples_decoded += *buffer_length / sizeof(int16_t);
360+
361+
mp3file_skip_id3v2(self);
362+
int result = mp3file_find_sync_word(self) ? GET_BUFFER_MORE_DATA : GET_BUFFER_DONE;
363+
359364
if (self->inbuf_offset >= 512) {
360365
background_callback_add(
361366
&self->inbuf_fill_cb,
362367
mp3file_update_inbuf_cb,
363368
self);
364369
}
365370

366-
self->samples_decoded += *buffer_length / sizeof(int16_t);
367-
return mp3file_find_sync_word(self) ? GET_BUFFER_MORE_DATA : GET_BUFFER_DONE;
371+
return result;
368372
}
369373

370374
void audiomp3_mp3file_get_buffer_structure(audiomp3_mp3file_obj_t *self, bool single_channel_output,

0 commit comments

Comments
 (0)