lavc: Add per-thread surfaces in get_hw_frame_parameters()
[ffmpeg.git] / libavcodec / mpegaudio_parser.c
index 06d46f2..c44c024 100644 (file)
@@ -21,8 +21,8 @@
  */
 
 #include "parser.h"
-#include "mpegaudio.h"
 #include "mpegaudiodecheader.h"
+#include "libavutil/common.h"
 
 
 typedef struct MpegAudioParseContext {
@@ -30,6 +30,7 @@ typedef struct MpegAudioParseContext {
     int frame_size;
     uint32_t header;
     int header_count;
+    int no_bitrate;
 } MpegAudioParseContext;
 
 #define MPA_HEADER_SIZE 4
@@ -62,12 +63,14 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
         }else{
             while(i<buf_size){
                 int ret, sr, channels, bit_rate, frame_size;
+                enum AVCodecID codec_id = avctx->codec_id;
 
                 state= (state<<8) + buf[i++];
 
                 ret = ff_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate);
                 if (ret < 4) {
-                    s->header_count= -2;
+                    if (i > 4)
+                        s->header_count = -2;
                 } else {
                     if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
                         s->header_count= -3;
@@ -75,12 +78,25 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
                     s->header_count++;
                     s->frame_size = ret-4;
 
-                    if(s->header_count > 1){
+                    if (s->header_count > 0) {
                         avctx->sample_rate= sr;
                         avctx->channels   = channels;
-                        avctx->frame_size = frame_size;
-                        avctx->bit_rate   = bit_rate;
+                        s1->duration      = frame_size;
+                        if (s->no_bitrate || !avctx->bit_rate) {
+                            s->no_bitrate = 1;
+                            avctx->bit_rate += (bit_rate - avctx->bit_rate) / s->header_count;
+                        }
                     }
+
+                    if (s1->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+                        s->frame_size = 0;
+                        next = buf_size;
+                    } else if (codec_id == AV_CODEC_ID_MP3ADU) {
+                        avpriv_report_missing_feature(avctx,
+                            "MP3ADU full parser");
+                        return AVERROR_PATCHWELCOME;
+                    }
+
                     break;
                 }
             }
@@ -101,9 +117,8 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
 
 
 AVCodecParser ff_mpegaudio_parser = {
-    { CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 },
-    sizeof(MpegAudioParseContext),
-    NULL,
-    mpegaudio_parse,
-    ff_parse_close,
+    .codec_ids      = { AV_CODEC_ID_MP1, AV_CODEC_ID_MP2, AV_CODEC_ID_MP3, AV_CODEC_ID_MP3ADU },
+    .priv_data_size = sizeof(MpegAudioParseContext),
+    .parser_parse   = mpegaudio_parse,
+    .parser_close   = ff_parse_close,
 };