changeset 1310:aa1b1fc2d018 mp3-gapless

Stop reporting sync errors only when we really are at eof, i.e. after the input callback has been called again (previously we just tested whether we'd buffered up all the input, which of course we do in one go at the start)
author Chris Cannam
date Tue, 29 Nov 2016 16:45:29 +0000
parents 2e7fcdd5f627
children 90ac1df228aa
files data/fileio/MP3FileReader.cpp data/fileio/MP3FileReader.h
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/MP3FileReader.cpp	Tue Nov 29 14:35:27 2016 +0000
+++ b/data/fileio/MP3FileReader.cpp	Tue Nov 29 16:45:29 2016 +0000
@@ -317,6 +317,7 @@
 
     data.start = (unsigned char const *)mm;
     data.length = sz;
+    data.finished = false;
     data.reader = this;
 
     mad_decoder_init(&decoder,          // decoder to initialise
@@ -343,7 +344,10 @@
 {
     DecoderData *data = (DecoderData *)dp;
 
-    if (!data->length) return MAD_FLOW_STOP;
+    if (!data->length) {
+        data->finished = true;
+        return MAD_FLOW_STOP;
+    }
 
     unsigned char const *start = data->start;
     sv_frame_t length = data->length;
@@ -569,8 +573,9 @@
     DecoderData *data = (DecoderData *)dp;
 
     if (stream->error == MAD_ERROR_LOSTSYNC &&
-        data->length == 0) {
-        // We are at end of file, losing sync is expected behaviour
+        data->finished) {
+        // We are at end of file, losing sync is expected behaviour,
+        // don't report it
         return MAD_FLOW_CONTINUE;
     }
     
--- a/data/fileio/MP3FileReader.h	Tue Nov 29 14:35:27 2016 +0000
+++ b/data/fileio/MP3FileReader.h	Tue Nov 29 16:45:29 2016 +0000
@@ -124,6 +124,7 @@
     struct DecoderData {
 	unsigned char const *start;
 	sv_frame_t length;
+        bool finished;
 	MP3FileReader *reader;
     };