Browse code

Merge commit '5cdefc02079a5b899bdec09e15e2bb099cb01734'

* commit '5cdefc02079a5b899bdec09e15e2bb099cb01734':
aacdec: Add support for Error Resilience syntax.

Conflicts:
Changelog
libavcodec/aacdec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/09/19 19:44:06
Showing 2 changed files
... ...
@@ -27,6 +27,7 @@ version <next>
27 27
 - pullup filter ported from libmpcodecs
28 28
 - ffprobe -read_intervals option
29 29
 - Lossless and alpha support for WebP decoder
30
+- Error Resilient AAC syntax (ER AAC LC) decoding
30 31
 
31 32
 
32 33
 version 2.0:
... ...
@@ -745,7 +745,7 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
745 745
                                      MPEG4AudioConfig *m4ac,
746 746
                                      int channel_config)
747 747
 {
748
-    int extension_flag, ret;
748
+    int extension_flag, ret, ep_config, res_flags;
749 749
     uint8_t layout_map[MAX_ELEM_ID*4][3];
750 750
     int tags = 0;
751 751
 
... ...
@@ -791,14 +791,30 @@ static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
791 791
         case AOT_ER_AAC_LTP:
792 792
         case AOT_ER_AAC_SCALABLE:
793 793
         case AOT_ER_AAC_LD:
794
-            skip_bits(gb, 3);      /* aacSectionDataResilienceFlag
795
-                                    * aacScalefactorDataResilienceFlag
796
-                                    * aacSpectralDataResilienceFlag
797
-                                    */
794
+            res_flags = get_bits(gb, 3);
795
+            if (res_flags) {
796
+                av_log(avctx, AV_LOG_ERROR,
797
+                       "AAC data resilience not supported (flags %x)\n",
798
+                       res_flags);
799
+                return AVERROR_PATCHWELCOME;
800
+            }
798 801
             break;
799 802
         }
800 803
         skip_bits1(gb);    // extensionFlag3 (TBD in version 3)
801 804
     }
805
+    switch (m4ac->object_type) {
806
+    case AOT_ER_AAC_LC:
807
+    case AOT_ER_AAC_LTP:
808
+    case AOT_ER_AAC_SCALABLE:
809
+    case AOT_ER_AAC_LD:
810
+        ep_config = get_bits(gb, 2);
811
+        if (ep_config) {
812
+            av_log(avctx, AV_LOG_ERROR,
813
+                   "epConfig %d is not supported.\n",
814
+                   ep_config);
815
+            return AVERROR_PATCHWELCOME;
816
+        }
817
+    }
802 818
     return 0;
803 819
 }
804 820
 
... ...
@@ -847,6 +863,7 @@ static int decode_audio_specific_config(AACContext *ac,
847 847
     case AOT_AAC_MAIN:
848 848
     case AOT_AAC_LC:
849 849
     case AOT_AAC_LTP:
850
+    case AOT_ER_AAC_LC:
850 851
         if ((ret = decode_ga_specific_config(ac, avctx, &gb,
851 852
                                             m4ac, m4ac->chan_config)) < 0)
852 853
             return ret;
... ...
@@ -1127,7 +1144,8 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
1127 1127
                 if (decode_prediction(ac, ics, gb)) {
1128 1128
                     goto fail;
1129 1129
                 }
1130
-            } else if (ac->oc[1].m4ac.object_type == AOT_AAC_LC) {
1130
+            } else if (ac->oc[1].m4ac.object_type == AOT_AAC_LC ||
1131
+                       ac->oc[1].m4ac.object_type == AOT_ER_AAC_LC) {
1131 1132
                 av_log(ac->avctx, AV_LOG_ERROR,
1132 1133
                        "Prediction is not allowed in AAC-LC.\n");
1133 1134
                 goto fail;
... ...
@@ -1752,7 +1770,7 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
1752 1752
     TemporalNoiseShaping    *tns = &sce->tns;
1753 1753
     IndividualChannelStream *ics = &sce->ics;
1754 1754
     float *out = sce->coeffs;
1755
-    int global_gain, pulse_present = 0;
1755
+    int global_gain, er_syntax, pulse_present = 0;
1756 1756
     int ret;
1757 1757
 
1758 1758
     /* This assignment is to silence a GCC warning about the variable being used
... ...
@@ -1775,6 +1793,9 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
1775 1775
         return ret;
1776 1776
 
1777 1777
     pulse_present = 0;
1778
+    er_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_LC ||
1779
+                ac->oc[1].m4ac.object_type == AOT_ER_AAC_LTP ||
1780
+                ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD;
1778 1781
     if (!scale_flag) {
1779 1782
         if ((pulse_present = get_bits1(gb))) {
1780 1783
             if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
... ...
@@ -1788,12 +1809,19 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
1788 1788
                 return AVERROR_INVALIDDATA;
1789 1789
             }
1790 1790
         }
1791
-        if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
1792
-            return AVERROR_INVALIDDATA;
1791
+        tns->present = get_bits1(gb);
1792
+        if (tns->present && !er_syntax)
1793
+            if (decode_tns(ac, tns, gb, ics) < 0)
1794
+                return AVERROR_INVALIDDATA;
1793 1795
         if (get_bits1(gb)) {
1794 1796
             avpriv_request_sample(ac->avctx, "SSR");
1795 1797
             return AVERROR_PATCHWELCOME;
1796 1798
         }
1799
+        // I see no textual basis in the spec for this occuring after SSR gain
1800
+        // control, but this is what both reference and real implmentations do
1801
+        if (tns->present && er_syntax)
1802
+            if (decode_tns(ac, tns, gb, ics) < 0)
1803
+                return AVERROR_INVALIDDATA;
1797 1804
     }
1798 1805
 
1799 1806
     if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present,
... ...
@@ -2562,6 +2590,61 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
2562 2562
     return size;
2563 2563
 }
2564 2564
 
2565
+static int aac_decode_er_frame(AVCodecContext *avctx, void *data,
2566
+                               int *got_frame_ptr, GetBitContext *gb)
2567
+{
2568
+    AACContext *ac = avctx->priv_data;
2569
+    ChannelElement *che;
2570
+    int err, i;
2571
+    int samples = 1024;
2572
+    int chan_config = ac->oc[1].m4ac.chan_config;
2573
+
2574
+    ac->frame = data;
2575
+
2576
+    if ((err = frame_configure_elements(avctx)) < 0)
2577
+        return err;
2578
+
2579
+    ac->tags_mapped = 0;
2580
+
2581
+    if (chan_config < 0 || chan_config >= 8) {
2582
+        avpriv_request_sample(avctx, "Unknown ER channel configuration %d",
2583
+                              ac->oc[1].m4ac.chan_config);
2584
+        return AVERROR_INVALIDDATA;
2585
+    }
2586
+    for (i = 0; i < tags_per_config[chan_config]; i++) {
2587
+        const int elem_type = aac_channel_layout_map[chan_config-1][i][0];
2588
+        const int elem_id   = aac_channel_layout_map[chan_config-1][i][1];
2589
+        if (!(che=get_che(ac, elem_type, elem_id))) {
2590
+            av_log(ac->avctx, AV_LOG_ERROR,
2591
+                   "channel element %d.%d is not allocated\n",
2592
+                   elem_type, elem_id);
2593
+            return AVERROR_INVALIDDATA;
2594
+        }
2595
+        skip_bits(gb, 4);
2596
+        switch (elem_type) {
2597
+        case TYPE_SCE:
2598
+            err = decode_ics(ac, &che->ch[0], gb, 0, 0);
2599
+            break;
2600
+        case TYPE_CPE:
2601
+            err = decode_cpe(ac, gb, che);
2602
+            break;
2603
+        case TYPE_LFE:
2604
+            err = decode_ics(ac, &che->ch[0], gb, 0, 0);
2605
+            break;
2606
+        }
2607
+        if (err < 0)
2608
+            return err;
2609
+    }
2610
+
2611
+    spectral_to_sample(ac);
2612
+
2613
+    ac->frame->nb_samples = samples;
2614
+    *got_frame_ptr = 1;
2615
+
2616
+    skip_bits_long(gb, get_bits_left(gb));
2617
+    return 0;
2618
+}
2619
+
2565 2620
 static int aac_decode_frame_int(AVCodecContext *avctx, void *data,
2566 2621
                                 int *got_frame_ptr, GetBitContext *gb, AVPacket *avpkt)
2567 2622
 {
... ...
@@ -2769,7 +2852,16 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
2769 2769
     if ((err = init_get_bits(&gb, buf, buf_size * 8)) < 0)
2770 2770
         return err;
2771 2771
 
2772
-    if ((err = aac_decode_frame_int(avctx, data, got_frame_ptr, &gb, avpkt)) < 0)
2772
+    switch (ac->oc[1].m4ac.object_type) {
2773
+    case AOT_ER_AAC_LC:
2774
+    case AOT_ER_AAC_LTP:
2775
+    case AOT_ER_AAC_LD:
2776
+        err = aac_decode_er_frame(avctx, data, got_frame_ptr, &gb);
2777
+        break;
2778
+    default:
2779
+        err = aac_decode_frame_int(avctx, data, got_frame_ptr, &gb, avpkt);
2780
+    }
2781
+    if (err < 0)
2773 2782
         return err;
2774 2783
 
2775 2784
     buf_consumed = (get_bits_count(&gb) + 7) >> 3;