Browse code

Merge commit '1914e6f010b3320025c7b692aaea51d9b9a992a8'

* commit '1914e6f010b3320025c7b692aaea51d9b9a992a8':
aacdec: Add support for LD (Low Delay) AAC

Conflicts:
Changelog
libavcodec/aacdec.c
libavcodec/version.h

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

Michael Niedermayer authored on 2013/09/19 19:55:26
Showing 6 changed files
... ...
@@ -28,6 +28,7 @@ version <next>
28 28
 - ffprobe -read_intervals option
29 29
 - Lossless and alpha support for WebP decoder
30 30
 - Error Resilient AAC syntax (ER AAC LC) decoding
31
+- Low Delay AAC (ER AAC LD) decoding
31 32
 
32 33
 
33 34
 version 2.0:
... ...
@@ -290,6 +290,7 @@ struct AACContext {
290 290
      */
291 291
     FFTContext mdct;
292 292
     FFTContext mdct_small;
293
+    FFTContext mdct_ld;
293 294
     FFTContext mdct_ltp;
294 295
     FmtConvertContext fmt_conv;
295 296
     AVFloatDSPContext fdsp;
... ...
@@ -856,6 +856,13 @@ static int decode_audio_specific_config(AACContext *ac,
856 856
                m4ac->sampling_index);
857 857
         return AVERROR_INVALIDDATA;
858 858
     }
859
+    if (m4ac->object_type == AOT_ER_AAC_LD &&
860
+        (m4ac->sampling_index < 3 || m4ac->sampling_index > 7)) {
861
+        av_log(avctx, AV_LOG_ERROR,
862
+               "invalid low delay sampling rate index %d\n",
863
+               m4ac->sampling_index);
864
+        return AVERROR_INVALIDDATA;
865
+    }
859 866
 
860 867
     skip_bits_long(&gb, i);
861 868
 
... ...
@@ -864,6 +871,7 @@ static int decode_audio_specific_config(AACContext *ac,
864 864
     case AOT_AAC_LC:
865 865
     case AOT_AAC_LTP:
866 866
     case AOT_ER_AAC_LC:
867
+    case AOT_ER_AAC_LD:
867 868
         if ((ret = decode_ga_specific_config(ac, avctx, &gb,
868 869
                                             m4ac, m4ac->chan_config)) < 0)
869 870
             return ret;
... ...
@@ -1033,12 +1041,15 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
1033 1033
                     352);
1034 1034
 
1035 1035
     ff_mdct_init(&ac->mdct,       11, 1, 1.0 / (32768.0 * 1024.0));
1036
+    ff_mdct_init(&ac->mdct_ld,    10, 1, 1.0 / (32768.0 * 512.0));
1036 1037
     ff_mdct_init(&ac->mdct_small,  8, 1, 1.0 / (32768.0 * 128.0));
1037 1038
     ff_mdct_init(&ac->mdct_ltp,   11, 0, -2.0 * 32768.0);
1038 1039
     // window initialization
1039 1040
     ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
1041
+    ff_kbd_window_init(ff_aac_kbd_long_512,  4.0, 512);
1040 1042
     ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
1041 1043
     ff_init_ff_sine_windows(10);
1044
+    ff_init_ff_sine_windows( 9);
1042 1045
     ff_init_ff_sine_windows( 7);
1043 1046
 
1044 1047
     cbrt_tableinit();
... ...
@@ -1111,6 +1122,14 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
1111 1111
     }
1112 1112
     ics->window_sequence[1] = ics->window_sequence[0];
1113 1113
     ics->window_sequence[0] = get_bits(gb, 2);
1114
+    if (ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD &&
1115
+        ics->window_sequence[0] != ONLY_LONG_SEQUENCE) {
1116
+        av_log(ac->avctx, AV_LOG_ERROR,
1117
+               "AAC LD is only defined for ONLY_LONG_SEQUENCE but "
1118
+               "window sequence %d found.\n", ics->window_sequence[0]);
1119
+        ics->window_sequence[0] = ONLY_LONG_SEQUENCE;
1120
+        return AVERROR_INVALIDDATA;
1121
+    }
1114 1122
     ics->use_kb_window[1]   = ics->use_kb_window[0];
1115 1123
     ics->use_kb_window[0]   = get_bits1(gb);
1116 1124
     ics->num_window_groups  = 1;
... ...
@@ -1134,8 +1153,15 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
1134 1134
     } else {
1135 1135
         ics->max_sfb               = get_bits(gb, 6);
1136 1136
         ics->num_windows           = 1;
1137
-        ics->swb_offset            =    ff_swb_offset_1024[ac->oc[1].m4ac.sampling_index];
1138
-        ics->num_swb               =   ff_aac_num_swb_1024[ac->oc[1].m4ac.sampling_index];
1137
+        if (ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD) {
1138
+            ics->swb_offset        =     ff_swb_offset_512[ac->oc[1].m4ac.sampling_index];
1139
+            ics->num_swb           =    ff_aac_num_swb_512[ac->oc[1].m4ac.sampling_index];
1140
+            if (!ics->num_swb || !ics->swb_offset)
1141
+                return AVERROR_BUG;
1142
+        } else {
1143
+            ics->swb_offset        =    ff_swb_offset_1024[ac->oc[1].m4ac.sampling_index];
1144
+            ics->num_swb           =   ff_aac_num_swb_1024[ac->oc[1].m4ac.sampling_index];
1145
+        }
1139 1146
         ics->tns_max_bands         = ff_tns_max_bands_1024[ac->oc[1].m4ac.sampling_index];
1140 1147
         ics->predictor_present     = get_bits1(gb);
1141 1148
         ics->predictor_reset_group = 0;
... ...
@@ -1150,6 +1176,11 @@ static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
1150 1150
                        "Prediction is not allowed in AAC-LC.\n");
1151 1151
                 goto fail;
1152 1152
             } else {
1153
+                if (ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD) {
1154
+                    av_log(ac->avctx, AV_LOG_ERROR,
1155
+                           "LTP in ER AAC LD not yet implemented.\n");
1156
+                    return AVERROR_PATCHWELCOME;
1157
+                }
1153 1158
                 if ((ics->ltp.present = get_bits(gb, 1)))
1154 1159
                     decode_ltp(&ics->ltp, gb, ics->max_sfb);
1155 1160
             }
... ...
@@ -2393,6 +2424,25 @@ static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
2393 2393
     }
2394 2394
 }
2395 2395
 
2396
+static void imdct_and_windowing_ld(AACContext *ac, SingleChannelElement *sce)
2397
+{
2398
+    IndividualChannelStream *ics = &sce->ics;
2399
+    float *in    = sce->coeffs;
2400
+    float *out   = sce->ret;
2401
+    float *saved = sce->saved;
2402
+    const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_512 : ff_sine_512;
2403
+    float *buf  = ac->buf_mdct;
2404
+
2405
+    // imdct
2406
+    ac->mdct.imdct_half(&ac->mdct_ld, buf, in);
2407
+
2408
+    // window overlapping
2409
+    ac->fdsp.vector_fmul_window(out, saved, buf, lwindow_prev, 256);
2410
+
2411
+    // buffer update
2412
+    memcpy(saved, buf + 256, 256 * sizeof(float));
2413
+}
2414
+
2396 2415
 /**
2397 2416
  * Apply dependent channel coupling (applied before IMDCT).
2398 2417
  *
... ...
@@ -2489,6 +2539,11 @@ static void apply_channel_coupling(AACContext *ac, ChannelElement *cc,
2489 2489
 static void spectral_to_sample(AACContext *ac)
2490 2490
 {
2491 2491
     int i, type;
2492
+    void (*imdct_and_window)(AACContext *ac, SingleChannelElement *sce);
2493
+    if (ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD)
2494
+        imdct_and_window = imdct_and_windowing_ld;
2495
+    else
2496
+        imdct_and_window = ac->imdct_and_windowing;
2492 2497
     for (type = 3; type >= 0; type--) {
2493 2498
         for (i = 0; i < MAX_ELEM_ID; i++) {
2494 2499
             ChannelElement *che = ac->che[type][i];
... ...
@@ -2510,11 +2565,11 @@ static void spectral_to_sample(AACContext *ac)
2510 2510
                 if (type <= TYPE_CPE)
2511 2511
                     apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling);
2512 2512
                 if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) {
2513
-                    ac->imdct_and_windowing(ac, &che->ch[0]);
2513
+                    imdct_and_window(ac, &che->ch[0]);
2514 2514
                     if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
2515 2515
                         ac->update_ltp(ac, &che->ch[0]);
2516 2516
                     if (type == TYPE_CPE) {
2517
-                        ac->imdct_and_windowing(ac, &che->ch[1]);
2517
+                        imdct_and_window(ac, &che->ch[1]);
2518 2518
                         if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
2519 2519
                             ac->update_ltp(ac, &che->ch[1]);
2520 2520
                     }
... ...
@@ -2599,6 +2654,9 @@ static int aac_decode_er_frame(AVCodecContext *avctx, void *data,
2599 2599
     int samples = 1024;
2600 2600
     int chan_config = ac->oc[1].m4ac.chan_config;
2601 2601
 
2602
+    if (ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD)
2603
+        samples >>= 1;
2604
+
2602 2605
     ac->frame = data;
2603 2606
 
2604 2607
     if ((err = frame_configure_elements(avctx)) < 0)
... ...
@@ -2887,6 +2945,7 @@ static av_cold int aac_decode_close(AVCodecContext *avctx)
2887 2887
 
2888 2888
     ff_mdct_end(&ac->mdct);
2889 2889
     ff_mdct_end(&ac->mdct_small);
2890
+    ff_mdct_end(&ac->mdct_ld);
2890 2891
     ff_mdct_end(&ac->mdct_ltp);
2891 2892
     return 0;
2892 2893
 }
... ...
@@ -34,12 +34,17 @@
34 34
 #include <stdint.h>
35 35
 
36 36
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_long_1024)[1024];
37
+DECLARE_ALIGNED(32, float,  ff_aac_kbd_long_512 )[512];
37 38
 DECLARE_ALIGNED(32, float,  ff_aac_kbd_short_128)[128];
38 39
 
39 40
 const uint8_t ff_aac_num_swb_1024[] = {
40 41
     41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40, 40
41 42
 };
42 43
 
44
+const uint8_t ff_aac_num_swb_512[] = {
45
+     0,  0,  0, 36, 36, 37, 31, 31,  0,  0,  0,  0,  0
46
+};
47
+
43 48
 const uint8_t ff_aac_num_swb_128[] = {
44 49
     12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15
45 50
 };
... ...
@@ -1114,6 +1119,14 @@ static const uint16_t swb_offset_1024_48[] = {
1114 1114
     928, 1024
1115 1115
 };
1116 1116
 
1117
+static const uint16_t swb_offset_512_48[] = {
1118
+      0,   4,   8,  12,  16,  20,  24,  28,
1119
+     32,  36,  40,  44,  48,  52,  56,  60,
1120
+     68,  76,  84,  92, 100, 112, 124, 136,
1121
+    148, 164, 184, 208, 236, 268, 300, 332,
1122
+    364, 396, 428, 460, 512
1123
+};
1124
+
1117 1125
 static const uint16_t swb_offset_128_48[] = {
1118 1126
      0,   4,   8,  12,  16,  20,  28,  36,
1119 1127
     44,  56,  68,  80,  96, 112, 128
... ...
@@ -1129,6 +1142,14 @@ static const uint16_t swb_offset_1024_32[] = {
1129 1129
     928, 960, 992, 1024
1130 1130
 };
1131 1131
 
1132
+static const uint16_t swb_offset_512_32[] = {
1133
+      0,   4,   8,  12,  16,  20,  24,  28,
1134
+     32,  36,  40,  44,  48,  52,  56,  64,
1135
+     72,  80,  88,  96, 108, 120, 132, 144,
1136
+    160, 176, 192, 212, 236, 260, 288, 320,
1137
+    352, 384, 416, 448, 480, 512
1138
+};
1139
+
1132 1140
 static const uint16_t swb_offset_1024_24[] = {
1133 1141
       0,   4,   8,  12,  16,  20,  24,  28,
1134 1142
      32,  36,  40,  44,  52,  60,  68,  76,
... ...
@@ -1138,6 +1159,13 @@ static const uint16_t swb_offset_1024_24[] = {
1138 1138
     600, 652, 704, 768, 832, 896, 960, 1024
1139 1139
 };
1140 1140
 
1141
+static const uint16_t swb_offset_512_24[] = {
1142
+      0,   4,   8,  12,  16,  20,  24,  28,
1143
+     32,  36,  40,  44,  52,  60,  68,  80,
1144
+     92, 104, 120, 140, 164, 192, 224, 256,
1145
+    288, 320, 352, 384, 416, 448, 480, 512,
1146
+};
1147
+
1141 1148
 static const uint16_t swb_offset_128_24[] = {
1142 1149
      0,   4,   8,  12,  16,  20,  24,  28,
1143 1150
     36,  44,  52,  64,  76,  92, 108, 128
... ...
@@ -1179,6 +1207,14 @@ const uint16_t * const ff_swb_offset_1024[] = {
1179 1179
     swb_offset_1024_8
1180 1180
 };
1181 1181
 
1182
+const uint16_t * const ff_swb_offset_512[] = {
1183
+    NULL,               NULL,               NULL,
1184
+    swb_offset_512_48,  swb_offset_512_48,  swb_offset_512_32,
1185
+    swb_offset_512_24,  swb_offset_512_24,  NULL,
1186
+    NULL,               NULL,               NULL,
1187
+    NULL
1188
+};
1189
+
1182 1190
 const uint16_t * const ff_swb_offset_128[] = {
1183 1191
     /* The last entry on the following row is swb_offset_128_64 but is a
1184 1192
        duplicate of swb_offset_128_96. */
... ...
@@ -45,6 +45,7 @@
45 45
  * @{
46 46
  */
47 47
 DECLARE_ALIGNED(32, extern float,  ff_aac_kbd_long_1024)[1024];
48
+DECLARE_ALIGNED(32, extern float,  ff_aac_kbd_long_512 )[512];
48 49
 DECLARE_ALIGNED(32, extern float,  ff_aac_kbd_short_128)[128];
49 50
 // @}
50 51
 
... ...
@@ -52,6 +53,7 @@ DECLARE_ALIGNED(32, extern float,  ff_aac_kbd_short_128)[128];
52 52
  * @{
53 53
  */
54 54
 extern const uint8_t ff_aac_num_swb_1024[];
55
+extern const uint8_t ff_aac_num_swb_512 [];
55 56
 extern const uint8_t ff_aac_num_swb_128 [];
56 57
 // @}
57 58
 
... ...
@@ -69,6 +71,7 @@ extern const float *ff_aac_codebook_vector_vals[];
69 69
 extern const uint16_t *ff_aac_codebook_vector_idx[];
70 70
 
71 71
 extern const uint16_t * const ff_swb_offset_1024[13];
72
+extern const uint16_t * const ff_swb_offset_512 [13];
72 73
 extern const uint16_t * const ff_swb_offset_128 [13];
73 74
 
74 75
 extern const uint8_t ff_tns_max_bands_1024[13];
... ...
@@ -29,7 +29,7 @@
29 29
 #include "libavutil/avutil.h"
30 30
 
31 31
 #define LIBAVCODEC_VERSION_MAJOR 55
32
-#define LIBAVCODEC_VERSION_MINOR  32
32
+#define LIBAVCODEC_VERSION_MINOR  33
33 33
 #define LIBAVCODEC_VERSION_MICRO 100
34 34
 
35 35
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \