changeset 4104:04ff8026d9c0 libavcodec

dont set the sampling rate just because 1 mp3 packet header says so (fixes playback speed on some old mencoder generated avis which where then dumped to mp3)
author michael
date Mon, 30 Oct 2006 02:19:55 +0000
parents 4da24acf4e20
children 225d287b337f
files mpegaudio.h mpegaudiodec.c parser.c
diffstat 3 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mpegaudio.h	Mon Oct 30 01:29:56 2006 +0000
+++ b/mpegaudio.h	Mon Oct 30 02:19:55 2006 +0000
@@ -72,7 +72,7 @@
 #endif
 
 int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
-int mpa_decode_header(AVCodecContext *avctx, uint32_t head);
+int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
 void ff_mpa_synth_init(MPA_INT *window);
 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
                          MPA_INT *window, int *dither_state,
--- a/mpegaudiodec.c	Mon Oct 30 01:29:56 2006 +0000
+++ b/mpegaudiodec.c	Mon Oct 30 02:19:55 2006 +0000
@@ -1190,7 +1190,7 @@
 
 /* useful helper to get mpeg audio stream infos. Return -1 if error in
    header, otherwise the coded frame size in bytes */
-int mpa_decode_header(AVCodecContext *avctx, uint32_t head)
+int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate)
 {
     MPADecodeContext s1, *s = &s1;
 
@@ -1217,7 +1217,7 @@
         break;
     }
 
-    avctx->sample_rate = s->sample_rate;
+    *sample_rate = s->sample_rate;
     avctx->channels = s->nb_channels;
     avctx->bit_rate = s->bit_rate;
     avctx->sub_id = s->layer;
@@ -2547,7 +2547,6 @@
         return -1;
     }
     /* update codec info */
-    avctx->sample_rate = s->sample_rate;
     avctx->channels = s->nb_channels;
     avctx->bit_rate = s->bit_rate;
     avctx->sub_id = s->layer;
@@ -2574,9 +2573,11 @@
     }
 
     out_size = mp_decode_frame(s, out_samples, buf, buf_size);
-    if(out_size>=0)
+    if(out_size>=0){
         *data_size = out_size;
-    else
+        avctx->sample_rate = s->sample_rate;
+        //FIXME maybe move the other codec info stuff from above here too
+    }else
         av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed
     s->frame_size = 0;
     return buf_size;
--- a/parser.c	Mon Oct 30 01:29:56 2006 +0000
+++ b/parser.c	Mon Oct 30 02:19:55 2006 +0000
@@ -666,11 +666,10 @@
             }
             if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
             got_header:
-                sr= avctx->sample_rate;
                 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
                     (s->inbuf[2] << 8) | s->inbuf[3];
 
-                ret = mpa_decode_header(avctx, header);
+                ret = mpa_decode_header(avctx, header, &sr);
                 if (ret < 0) {
                     s->header_count= -2;
                     /* no sync found : move by one byte (inefficient, but simple!) */
@@ -694,8 +693,8 @@
                     }
 #endif
                 }
-                if(s->header_count <= 0)
-                    avctx->sample_rate= sr; //FIXME ugly
+                if(s->header_count > 1)
+                    avctx->sample_rate= sr;
             }
         } else
 #if 0