[FFmpeg-cvslog] r16259 - in trunk: libavcodec/mpegaudio.h libavcodec/mpegaudio_parser.c libavformat/mp3.c

michael subversion
Mon Dec 22 00:50:17 CET 2008


Author: michael
Date: Mon Dec 22 00:50:16 2008
New Revision: 16259

Log:
Change mpeg audio parser so it only sets frame_size, channels and bit_rate
after it has a few valid frames.
Fixes issue762


Modified:
   trunk/libavcodec/mpegaudio.h
   trunk/libavcodec/mpegaudio_parser.c
   trunk/libavformat/mp3.c

Modified: trunk/libavcodec/mpegaudio.h
==============================================================================
--- trunk/libavcodec/mpegaudio.h	(original)
+++ trunk/libavcodec/mpegaudio.h	Mon Dec 22 00:50:16 2008
@@ -128,7 +128,7 @@ typedef struct HuffTable {
 } HuffTable;
 
 int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
+int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
 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,

Modified: trunk/libavcodec/mpegaudio_parser.c
==============================================================================
--- trunk/libavcodec/mpegaudio_parser.c	(original)
+++ trunk/libavcodec/mpegaudio_parser.c	Mon Dec 22 00:50:16 2008
@@ -44,7 +44,7 @@ typedef struct MpegAudioParseContext {
 
 /* useful helper to get mpeg audio stream infos. Return -1 if error in
    header, otherwise the coded frame size in bytes */
-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate)
+int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
 {
     MPADecodeContext s1, *s = &s1;
     s1.avctx = avctx;
@@ -58,23 +58,23 @@ int ff_mpa_decode_header(AVCodecContext 
 
     switch(s->layer) {
     case 1:
-        avctx->frame_size = 384;
+        *frame_size = 384;
         break;
     case 2:
-        avctx->frame_size = 1152;
+        *frame_size = 1152;
         break;
     default:
     case 3:
         if (s->lsf)
-            avctx->frame_size = 576;
+            *frame_size = 576;
         else
-            avctx->frame_size = 1152;
+            *frame_size = 1152;
         break;
     }
 
     *sample_rate = s->sample_rate;
-    avctx->channels = s->nb_channels;
-    avctx->bit_rate = s->bit_rate;
+    *channels = s->nb_channels;
+    *bit_rate = s->bit_rate;
     avctx->sub_id = s->layer;
     return s->frame_size;
 }
@@ -92,7 +92,7 @@ static int mpegaudio_parse(AVCodecParser
                            const uint8_t *buf, int buf_size)
 {
     MpegAudioParseContext *s = s1->priv_data;
-    int len, ret, sr;
+    int len, ret, sr, channels, bit_rate, frame_size;
     uint32_t header;
     const uint8_t *buf_ptr;
 
@@ -123,7 +123,7 @@ static int mpegaudio_parse(AVCodecParser
             got_header:
                 header = AV_RB32(s->inbuf);
 
-                ret = ff_mpa_decode_header(avctx, header, &sr);
+                ret = ff_mpa_decode_header(avctx, header, &sr, &channels, &frame_size, &bit_rate);
                 if (ret < 0) {
                     s->header_count= -2;
                     /* no sync found : move by one byte (inefficient, but simple!) */
@@ -146,8 +146,12 @@ static int mpegaudio_parse(AVCodecParser
                         s->frame_size = -1;
                     }
 #endif
-                    if(s->header_count > 1)
+                    if(s->header_count > 1){
                         avctx->sample_rate= sr;
+                        avctx->channels   = channels;
+                        avctx->frame_size = frame_size;
+                        avctx->bit_rate   = bit_rate;
+                    }
                 }
             }
         } else

Modified: trunk/libavformat/mp3.c
==============================================================================
--- trunk/libavformat/mp3.c	(original)
+++ trunk/libavformat/mp3.c	Mon Dec 22 00:50:16 2008
@@ -383,7 +383,7 @@ static int mp3_read_probe(AVProbeData *p
 
         for(frames = 0; buf2 < end; frames++) {
             header = AV_RB32(buf2);
-            fsize = ff_mpa_decode_header(&avctx, header, &sample_rate);
+            fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate);
             if(fsize < 0)
                 break;
             buf2 += fsize;




More information about the ffmpeg-cvslog mailing list