]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mpegaudiodec.c
vda: Merge implementation into one file
[ffmpeg] / libavcodec / mpegaudiodec.c
index 6ed124b5f1ca92f9483fd93a18ee074ab0f9912d..03094f62601e35408c7ca0ecf8dc942157524398 100644 (file)
@@ -174,9 +174,12 @@ static void ff_region_offset2size(GranuleDef *g)
 
 static void ff_init_short_region(MPADecodeContext *s, GranuleDef *g)
 {
-    if (g->block_type == 2)
-        g->region_size[0] = (36 / 2);
-    else {
+    if (g->block_type == 2) {
+        if (s->sample_rate_index != 8)
+            g->region_size[0] = (36 / 2);
+        else
+            g->region_size[0] = (72 / 2);
+    } else {
         if (s->sample_rate_index <= 2)
             g->region_size[0] = (36 / 2);
         else if (s->sample_rate_index != 8)
@@ -201,14 +204,12 @@ static void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g)
     if (g->block_type == 2) {
         if (g->switch_point) {
             /* if switched mode, we handle the 36 first samples as
-                long blocks.  For 8000Hz, we handle the 48 first
-                exponents as long blocks (XXX: check this!) */
+                long blocks.  For 8000Hz, we handle the 72 first
+                exponents as long blocks */
             if (s->sample_rate_index <= 2)
                 g->long_end = 8;
-            else if (s->sample_rate_index != 8)
-                g->long_end = 6;
             else
-                g->long_end = 4; /* 8000 Hz */
+                g->long_end = 6;
 
             g->short_start = 2 + (s->sample_rate_index != 8);
         } else {
@@ -436,7 +437,7 @@ static av_cold int decode_init(AVCodecContext * avctx)
     avctx->sample_fmt= OUT_FMT;
     s->err_recognition = avctx->err_recognition;
 
-    if (avctx->codec_id == CODEC_ID_MP3ADU)
+    if (avctx->codec_id == AV_CODEC_ID_MP3ADU)
         s->adu_mode = 1;
 
     avcodec_get_frame_defaults(&s->frame);
@@ -1018,7 +1019,7 @@ static void reorder_block(MPADecodeContext *s, GranuleDef *g)
         if (s->sample_rate_index != 8)
             ptr = g->sb_hybrid + 36;
         else
-            ptr = g->sb_hybrid + 48;
+            ptr = g->sb_hybrid + 72;
     } else {
         ptr = g->sb_hybrid;
     }
@@ -1533,7 +1534,7 @@ static int mp_decode_layer3(MPADecodeContext *s)
             huffman_decode(s, g, exponents, bits_pos + g->part2_3_length);
         } /* ch */
 
-        if (s->nb_channels == 2)
+        if (s->mode == MPA_JSTEREO)
             compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]);
 
         for (ch = 0; ch < s->nb_channels; ch++) {
@@ -1662,7 +1663,6 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
         av_log(avctx, AV_LOG_ERROR, "incomplete frame\n");
         return AVERROR_INVALIDDATA;
     } else if (s->frame_size < buf_size) {
-        av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n");
         buf_size= s->frame_size;
     }
 
@@ -1733,6 +1733,10 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
     s->frame_size = len;
 
     out_size = mp_decode_frame(s, NULL, buf, buf_size);
+    if (out_size < 0) {
+        av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n");
+        return AVERROR_INVALIDDATA;
+    }
 
     *got_frame_ptr   = 1;
     *(AVFrame *)data = s->frame;
@@ -1979,7 +1983,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
 AVCodec ff_mp1_decoder = {
     .name           = "mp1",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_MP1,
+    .id             = AV_CODEC_ID_MP1,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
     .decode         = decode_frame,
@@ -1992,7 +1996,7 @@ AVCodec ff_mp1_decoder = {
 AVCodec ff_mp2_decoder = {
     .name           = "mp2",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_MP2,
+    .id             = AV_CODEC_ID_MP2,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
     .decode         = decode_frame,
@@ -2005,7 +2009,7 @@ AVCodec ff_mp2_decoder = {
 AVCodec ff_mp3_decoder = {
     .name           = "mp3",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_MP3,
+    .id             = AV_CODEC_ID_MP3,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
     .decode         = decode_frame,
@@ -2018,7 +2022,7 @@ AVCodec ff_mp3_decoder = {
 AVCodec ff_mp3adu_decoder = {
     .name           = "mp3adu",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_MP3ADU,
+    .id             = AV_CODEC_ID_MP3ADU,
     .priv_data_size = sizeof(MPADecodeContext),
     .init           = decode_init,
     .decode         = decode_frame_adu,
@@ -2031,7 +2035,7 @@ AVCodec ff_mp3adu_decoder = {
 AVCodec ff_mp3on4_decoder = {
     .name           = "mp3on4",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_MP3ON4,
+    .id             = AV_CODEC_ID_MP3ON4,
     .priv_data_size = sizeof(MP3On4DecodeContext),
     .init           = decode_init_mp3on4,
     .close          = decode_close_mp3on4,