changeset 36340:6198c908db85

libmad: try decoding buffered data after EOF. Fixes bugzilla #2152.
author reimar
date Fri, 30 Aug 2013 19:41:38 +0000
parents 83d0141a1cdc
children 63f19afc5a6f
files libmpcodecs/ad_libmad.c
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/ad_libmad.c	Fri Aug 30 19:41:37 2013 +0000
+++ b/libmpcodecs/ad_libmad.c	Fri Aug 30 19:41:38 2013 +0000
@@ -67,11 +67,7 @@
 
 static int read_frame(sh_audio_t *sh){
   mad_decoder_t *this = sh->context;
-  int len;
 
-while((len=demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],
-          sh->a_in_buffer_size-sh->a_in_buffer_len))>0){
-  sh->a_in_buffer_len+=len;
   while(1){
     int ret;
     mad_stream_buffer (&this->stream, sh->a_in_buffer, sh->a_in_buffer_len);
@@ -84,8 +80,12 @@
     }
     if (ret == 0) return 1; // OK!!!
     // error! try to resync!
-    if(this->stream.error==MAD_ERROR_BUFLEN) break;
-  }
+    if(this->stream.error==MAD_ERROR_BUFLEN) {
+        int len=demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len],
+                                sh->a_in_buffer_size-sh->a_in_buffer_len);
+        if (len <= 0) break;
+        sh->a_in_buffer_len+=len;
+    }
 }
 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Cannot sync MAD frame\n");
 return 0;