Lines Matching refs:ac
99 static int output_configure(AACContext *ac,
129 static av_cold int che_configure(AACContext *ac,
136 if (!ac->che[type][id]) {
137 if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement))))
139 AAC_RENAME(ff_aac_sbr_ctx_init)(ac, &ac->che[type][id]->sbr, type);
142 if (*channels >= MAX_CHANNELS - (type == TYPE_CPE || (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1))) {
143 av_log(ac->avctx, AV_LOG_ERROR, "Too many channels\n");
146 ac->output_element[(*channels)++] = &ac->che[type][id]->ch[0];
148 (type == TYPE_SCE && ac->oc[1].m4ac.ps == 1)) {
149 ac->output_element[(*channels)++] = &ac->che[type][id]->ch[1];
153 if (ac->che[type][id])
154 AAC_RENAME(ff_aac_sbr_ctx_close)(&ac->che[type][id]->sbr);
155 av_freep(&ac->che[type][id]);
162 AACContext *ac = avctx->priv_data;
168 ChannelElement *che = ac->che[type][id];
177 av_frame_unref(ac->frame);
181 ac->frame->nb_samples = 2048;
182 if ((ret = ff_get_buffer(avctx, ac->frame, 0)) < 0)
187 if (ac->output_element[ch])
188 ac->output_element[ch]->ret = (INTFLOAT *)ac->frame->extended_data[ch];
503 static int push_output_configuration(AACContext *ac) {
506 if (ac->oc[1].status == OC_LOCKED || ac->oc[0].status == OC_NONE) {
507 ac->oc[0] = ac->oc[1];
510 ac->oc[1].status = OC_NONE;
518 static void pop_output_configuration(AACContext *ac) {
519 if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) {
520 ac->oc[1] = ac->oc[0];
521 ac->avctx->ch_layout = ac->oc[1].ch_layout;
522 output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags,
523 ac->oc[1].status, 0);
533 static int output_configure(AACContext *ac,
537 AVCodecContext *avctx = ac->avctx;
543 if (ac->oc[1].layout_map != layout_map) {
544 memcpy(ac->oc[1].layout_map, layout_map, tags * sizeof(layout_map[0]));
545 ac->oc[1].layout_map_tags = tags;
552 avpriv_request_sample(ac->avctx, "Too large remapped id");
561 ac->output_channel_order = CHANNEL_ORDER_CODED;
565 if (ac->output_channel_order == CHANNEL_ORDER_DEFAULT)
574 ret = che_configure(ac, position, type, iid, &channels);
577 ac->tag_che_map[type][id] = ac->che[type][iid];
579 if (ac->oc[1].m4ac.ps == 1 && channels == 2) {
587 av_channel_layout_uninit(&ac->oc[1].ch_layout);
589 av_channel_layout_from_mask(&ac->oc[1].ch_layout, layout);
591 ac->oc[1].ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
592 ac->oc[1].ch_layout.nb_channels = channels;
595 av_channel_layout_copy(&avctx->ch_layout, &ac->oc[1].ch_layout);
596 ac->oc[1].status = oc_type;
599 if ((ret = frame_configure_elements(ac->avctx)) < 0)
608 AACContext *ac= avctx->priv_data;
613 ChannelElement *che = ac->che[type][i];
629 static int set_default_channel_config(AACContext *ac, AVCodecContext *avctx,
659 if (!ac || !ac->warned_71_wide++) {
669 static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
673 if (!ac->oc[1].m4ac.chan_config) {
674 return ac->tag_che_map[type][elem_id];
677 if (!ac->tags_mapped && type == TYPE_CPE &&
678 ac->oc[1].m4ac.chan_config == 1) {
681 push_output_configuration(ac);
683 av_log(ac->avctx, AV_LOG_DEBUG, "mono with CPE\n");
685 if (set_default_channel_config(ac, ac->avctx, layout_map,
688 if (output_configure(ac, layout_map, layout_map_tags,
692 ac->oc[1].m4ac.chan_config = 2;
693 ac->oc[1].m4ac.ps = 0;
696 if (!ac->tags_mapped && type == TYPE_SCE &&
697 ac->oc[1].m4ac.chan_config == 2) {
700 push_output_configuration(ac);
702 av_log(ac->avctx, AV_LOG_DEBUG, "stereo with SCE\n");
709 if (output_configure(ac, layout_map, layout_map_tags,
713 if (ac->oc[1].m4ac.sbr)
714 ac->oc[1].m4ac.ps = -1;
718 switch (ac->oc[1].m4ac.chan_config) {
720 if (ac->tags_mapped > 3 && ((type == TYPE_CPE && elem_id < 8) ||
723 ac->tags_mapped++;
724 return ac->tag_che_map[type][elem_id] = ac->che[type][elem_id];
728 if (ac->tags_mapped == 3 && type == TYPE_CPE) {
729 ac->tags_mapped++;
730 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
733 if (ac->tags_mapped == 3 && type == TYPE_SCE) {
734 ac->tags_mapped++;
735 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
744 if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
745 if (!ac->warned_remapping_once && (type != TYPE_LFE || elem_id != 0)) {
746 av_log(ac->avctx, AV_LOG_WARNING,
749 ac->warned_remapping_once++;
751 ac->tags_mapped++;
752 return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
755 if (ac->tags_mapped == 2 && type == TYPE_CPE) {
756 ac->tags_mapped++;
757 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
766 if (ac->tags_mapped == tags_per_config[ac->oc[1].m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
767 if (!ac->warned_remapping_once && (type != TYPE_SCE || elem_id != 1)) {
768 av_log(ac->avctx, AV_LOG_WARNING,
771 ac->warned_remapping_once++;
773 ac->tags_mapped++;
774 return ac->tag_che_map[type][elem_id] = ac->che[TYPE_SCE][1];
776 if (ac->tags_mapped == 2 &&
777 ac->oc[1].m4ac.chan_config == 4 &&
779 ac->tags_mapped++;
780 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
784 if (ac->tags_mapped == (ac->oc[1].m4ac.chan_config != 2) &&
786 ac->tags_mapped++;
787 return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
788 } else if (ac->tags_mapped == 1 && ac->oc[1].m4ac.chan_config == 2 &&
790 ac->tags_mapped++;
791 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
794 if (!ac->tags_mapped && type == TYPE_SCE) {
795 ac->tags_mapped++;
796 return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
916 * @param ac pointer to AACContext, may be null
921 static int decode_ga_specific_config(AACContext *ac, AVCodecContext *avctx,
941 if (ac) ac->warned_960_sbr = 1;
961 if ((ret = set_default_channel_config(ac, avctx, layout_map,
971 if (ac && (ret = output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0)))
1010 static int decode_eld_specific_config(AACContext *ac, AVCodecContext *avctx,
1057 if ((ret = set_default_channel_config(ac, avctx, layout_map,
1061 if (ac && (ret = output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0)))
1076 * @param ac pointer to AACContext, may be null
1085 static int decode_audio_specific_config_gb(AACContext *ac,
1126 if ((ret = decode_ga_specific_config(ac, avctx, gb, get_bit_alignment,
1131 if ((ret = decode_eld_specific_config(ac, avctx, gb,
1152 static int decode_audio_specific_config(AACContext *ac,
1174 return decode_audio_specific_config_gb(ac, avctx, m4ac, &gb, 0,
1221 static void aacdec_init(AACContext *ac);
1276 AACContext *ac = avctx->priv_data;
1286 ac->avctx = avctx;
1287 ac->oc[1].m4ac.sample_rate = avctx->sample_rate;
1289 aacdec_init(ac);
1297 if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac,
1308 ac->oc[1].m4ac.sampling_index = sr;
1309 ac->oc[1].m4ac.channels = avctx->ch_layout.nb_channels;
1310 ac->oc[1].m4ac.sbr = -1;
1311 ac->oc[1].m4ac.ps = -1;
1319 ac->oc[1].m4ac.chan_config = i;
1321 if (ac->oc[1].m4ac.chan_config) {
1322 int ret = set_default_channel_config(ac, avctx, layout_map,
1323 &layout_map_tags, ac->oc[1].m4ac.chan_config);
1325 output_configure(ac, layout_map, layout_map_tags,
1338 ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT);
1340 ac->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
1342 if (!ac->fdsp) {
1346 ac->random_state = 0x1f2e3d4c;
1348 AAC_RENAME_32(ff_mdct_init)(&ac->mdct, 11, 1, 1.0 / RANGE15(1024.0));
1349 AAC_RENAME_32(ff_mdct_init)(&ac->mdct_ld, 10, 1, 1.0 / RANGE15(512.0));
1350 AAC_RENAME_32(ff_mdct_init)(&ac->mdct_small, 8, 1, 1.0 / RANGE15(128.0));
1351 AAC_RENAME_32(ff_mdct_init)(&ac->mdct_ltp, 11, 0, RANGE15(-2.0));
1353 ret = ff_mdct15_init(&ac->mdct120, 1, 3, 1.0f/(16*1024*120*2));
1356 ret = ff_mdct15_init(&ac->mdct480, 1, 5, 1.0f/(16*1024*960));
1359 ret = ff_mdct15_init(&ac->mdct960, 1, 6, 1.0f/(16*1024*960*2));
1370 static int skip_data_stream_element(AACContext *ac, GetBitContext *gb)
1380 av_log(ac->avctx, AV_LOG_ERROR, "skip_data_stream_element: "overread_err);
1387 static int decode_prediction(AACContext *ac, IndividualChannelStream *ics,
1395 av_log(ac->avctx, AV_LOG_ERROR,
1400 for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]); sfb++) {
1423 static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics,
1426 const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac;
1433 av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n");
1434 if (ac->avctx->err_recognition & AV_EF_BITSTREAM)
1441 av_log(ac->avctx, AV_LOG_ERROR,
1506 if (decode_prediction(ac, ics, gb)) {
1511 av_log(ac->avctx, AV_LOG_ERROR,
1516 av_log(ac->avctx, AV_LOG_ERROR,
1528 av_log(ac->avctx, AV_LOG_ERROR,
1549 static int decode_band_types(AACContext *ac, enum BandType band_type[120],
1562 av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n");
1569 av_log(ac->avctx, AV_LOG_ERROR, "decode_band_types: "overread_err);
1573 av_log(ac->avctx, AV_LOG_ERROR,
1598 static int decode_scalefactors(AACContext *ac, INTFLOAT sf[120], GetBitContext *gb,
1620 avpriv_request_sample(ac->avctx,
1639 avpriv_request_sample(ac->avctx,
1654 av_log(ac->avctx, AV_LOG_ERROR,
1700 static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns,
1705 const int tns_max_order = is8 ? 7 : ac->oc[1].m4ac.object_type == AOT_AAC_MAIN ? 20 : 12;
1715 av_log(ac->avctx, AV_LOG_ERROR,
1768 static int decode_spectrum_and_dequant(AACContext *ac, INTFLOAT coef[1024],
1801 ac->random_state = lcg_random(ac->random_state);
1802 cfo[k] = ac->random_state >> 3;
1805 band_energy = ac->fdsp->scalarproduct_fixed(cfo, cfo, off_len);
1812 ac->random_state = lcg_random(ac->random_state);
1813 cfo[k] = ac->random_state;
1816 band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len);
1818 ac->fdsp->vector_fmul_scalar(cfo, cfo, scale, off_len);
1968 av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
2001 ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len);
2049 ac->vector_pow43(cfo, off_len);
2050 ac->subband_scale(cfo, cfo, sf[idx], 34, off_len, ac->avctx);
2063 static void apply_prediction(AACContext *ac, SingleChannelElement *sce)
2074 sfb < ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index];
2126 static int decode_ics(AACContext *ac, SingleChannelElement *sce,
2136 eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
2137 er_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_LC ||
2138 ac->oc[1].m4ac.object_type == AOT_ER_AAC_LTP ||
2139 ac->oc[1].m4ac.object_type == AOT_ER_AAC_LD ||
2140 ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
2150 ret = decode_ics_info(ac, ics, gb);
2155 if ((ret = decode_band_types(ac, sce->band_type,
2158 if ((ret = decode_scalefactors(ac, sce->sf, gb, global_gain, ics,
2166 av_log(ac->avctx, AV_LOG_ERROR,
2172 av_log(ac->avctx, AV_LOG_ERROR,
2180 ret = decode_tns(ac, tns, gb, ics);
2186 if (!ac->warned_gain_control) {
2187 avpriv_report_missing_feature(ac->avctx, "Gain control");
2188 ac->warned_gain_control = 1;
2194 ret = decode_tns(ac, tns, gb, ics);
2200 ret = decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present,
2205 if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window)
2206 apply_prediction(ac, sce);
2217 static void apply_mid_side_stereo(AACContext *ac, ChannelElement *cpe)
2231 ac->fdsp->butterflies_fixed(ch0 + group * 128 + offsets[i],
2236 ac->fdsp->butterflies_float(ch0 + group * 128 + offsets[i],
2255 static void apply_intensity_stereo(AACContext *ac,
2277 ac->subband_scale(coef1 + group * 128 + offsets[i],
2281 offsets[i + 1] - offsets[i] ,ac->avctx);
2283 ac->fdsp->vector_fmul_scalar(coef1 + group * 128 + offsets[i],
2305 static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe)
2308 int eld_syntax = ac->oc[1].m4ac.object_type == AOT_ER_AAC_ELD;
2312 if (decode_ics_info(ac, &cpe->ch[0].ics, gb))
2318 (ac->oc[1].m4ac.object_type != AOT_AAC_MAIN))
2323 av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
2328 if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0)))
2330 if ((ret = decode_ics(ac, &cpe->ch[1], gb, common_window, 0)))
2335 apply_mid_side_stereo(ac, cpe);
2336 if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN) {
2337 apply_prediction(ac, &cpe->ch[0]);
2338 apply_prediction(ac, &cpe->ch[1]);
2342 apply_intensity_stereo(ac, cpe, ms_present);
2358 static int decode_cce(AACContext *ac, GetBitContext *gb, ChannelElement *che)
2389 if ((ret = decode_ics(ac, sce, gb, 0, 0)))
2508 static int decode_fill(AACContext *ac, GetBitContext *gb, int len) {
2521 if (ac->avctx->debug & FF_DEBUG_PICT_INFO)
2522 av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf);
2525 ac->avctx->internal->skip_samples = 1024;
2541 static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt,
2548 if (ac->avctx->debug & FF_DEBUG_STARTCODE)
2549 av_log(ac->avctx, AV_LOG_DEBUG, "extension type: %d len:%d\n", type, cnt);
2556 av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n");
2558 } else if (ac->oc[1].m4ac.frame_length_short) {
2559 if (!ac->warned_960_sbr)
2560 avpriv_report_missing_feature(ac->avctx,
2562 ac->warned_960_sbr = 1;
2565 } else if (!ac->oc[1].m4ac.sbr) {
2566 av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n");
2569 } else if (ac->oc[1].m4ac.sbr == -1 && ac->oc[1].status == OC_LOCKED) {
2570 av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n");
2573 } else if (ac->oc[1].m4ac.ps == -1 && ac->oc[1].status < OC_LOCKED &&
2574 ac->avctx->ch_layout.nb_channels == 1) {
2575 ac->oc[1].m4ac.sbr = 1;
2576 ac->oc[1].m4ac.ps = 1;
2577 ac->avctx->profile = FF_PROFILE_AAC_HE_V2;
2578 output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags,
2579 ac->oc[1].status, 1);
2581 ac->oc[1].m4ac.sbr = 1;
2582 ac->avctx->profile = FF_PROFILE_AAC_HE;
2584 res = AAC_RENAME(ff_decode_sbr_extension)(ac, &che->sbr, gb, crc_flag, cnt, elem_type);
2587 res = decode_dynamic_range(&ac->che_drc, gb);
2590 decode_fill(ac, gb, 8 * cnt - 4);
2667 static void windowing_and_mdct_ltp(AACContext *ac, INTFLOAT *out,
2676 ac->fdsp->vector_fmul(in, in, lwindow_prev, 1024);
2679 ac->fdsp->vector_fmul(in + 448, in + 448, swindow_prev, 128);
2682 ac->fdsp->vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024);
2684 ac->fdsp->vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128);
2687 ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in);
2693 static void apply_ltp(AACContext *ac, SingleChannelElement *sce)
2701 INTFLOAT *predFreq = ac->buf_mdct;
2710 ac->windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics);
2713 ac->apply_tns(predFreq, &sce->tns, &sce->ics, 0);
2725 static void update_ltp(AACContext *ac, SingleChannelElement *sce)
2737 ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
2740 saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], swindow[63 - i]);
2742 memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(*saved_ltp));
2744 ac->fdsp->vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64);
2747 saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], swindow[63 - i]);
2749 ac->fdsp->vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512);
2752 saved_ltp[i + 512] = AAC_MUL31(ac->buf_mdct[1023 - i], lwindow[511 - i]);
2763 static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce)
2772 INTFLOAT *buf = ac->buf_mdct;
2773 INTFLOAT *temp = ac->temp;
2779 ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i);
2781 ac->mdct.imdct_half(&ac->mdct, buf, in);
2796 ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 512);
2801 ac->fdsp->vector_fmul_window(out + 448 + 0*128, saved + 448, buf + 0*128, swindow_prev, 64);
2802 ac->fdsp->vector_fmul_window(out + 448 + 1*128, buf + 0*128 + 64, buf + 1*128, swindow, 64);
2803 ac->fdsp->vector_fmul_window(out + 448 + 2*128, buf + 1*128 + 64, buf + 2*128, swindow, 64);
2804 ac->fdsp->vector_fmul_window(out + 448 + 3*128, buf + 2*128 + 64, buf + 3*128, swindow, 64);
2805 ac->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, swindow, 64);
2808 ac->fdsp->vector_fmul_window(out + 448, saved + 448, buf, swindow_prev, 64);
2816 ac->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, swindow, 64);
2817 ac->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, swindow, 64);
2818 ac->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, swindow, 64);
2831 static void imdct_and_windowing_960(AACContext *ac, SingleChannelElement *sce)
2841 INTFLOAT *buf = ac->buf_mdct;
2842 INTFLOAT *temp = ac->temp;
2848 ac->mdct120->imdct_half(ac->mdct120, buf + i * 120, in + i * 128, 1);
2850 ac->mdct960->imdct_half(ac->mdct960, buf, in, 1);
2862 ac->fdsp->vector_fmul_window( out, saved, buf, lwindow_prev, 480);
2867 ac->fdsp->vector_fmul_window(out + 420 + 0*120, saved + 420, buf + 0*120, swindow_prev, 60);
2868 ac->fdsp->vector_fmul_window(out + 420 + 1*120, buf + 0*120 + 60, buf + 1*120, swindow, 60);
2869 ac->fdsp->vector_fmul_window(out + 420 + 2*120, buf + 1*120 + 60, buf + 2*120, swindow, 60);
2870 ac->fdsp->vector_fmul_window(out + 420 + 3*120, buf + 2*120 + 60, buf + 3*120, swindow, 60);
2871 ac->fdsp->vector_fmul_window(temp, buf + 3*120 + 60, buf + 4*120, swindow, 60);
2874 ac->fdsp->vector_fmul_window(out + 420, saved + 420, buf, swindow_prev, 60);
2882 ac->fdsp->vector_fmul_window(saved + 60, buf + 4*120 + 60, buf + 5*120, swindow, 60);
2883 ac->fdsp->vector_fmul_window(saved + 180, buf + 5*120 + 60, buf + 6*120, swindow, 60);
2884 ac->fdsp->vector_fmul_window(saved + 300, buf + 6*120 + 60, buf + 7*120, swindow, 60);
2894 static void imdct_and_windowing_ld(AACContext *ac, SingleChannelElement *sce)
2900 INTFLOAT *buf = ac->buf_mdct;
2906 ac->mdct.imdct_half(&ac->mdct_ld, buf, in);
2917 ac->fdsp->vector_fmul_window(out + 192, saved + 192, buf, AAC_RENAME2(sine_128), 64);
2920 ac->fdsp->vector_fmul_window(out, saved, buf, AAC_RENAME2(sine_512), 256);
2927 static void imdct_and_windowing_eld(AACContext *ac, SingleChannelElement *sce)
2932 INTFLOAT *buf = ac->buf_mdct;
2934 const int n = ac->oc[1].m4ac.frame_length_short ? 480 : 512;
2952 ac->mdct480->imdct_half(ac->mdct480, buf, in, 1);
2955 ac->mdct.imdct_half(&ac->mdct_ld, buf, in);
3000 static void apply_channel_coupling(AACContext *ac, ChannelElement *cc,
3003 void (*apply_coupling_method)(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index))
3008 ChannelElement *cce = ac->che[TYPE_CCE][i];
3017 apply_coupling_method(ac, &cc->ch[0], cce, index);
3022 apply_coupling_method(ac, &cc->ch[1], cce, index++);
3033 static void spectral_to_sample(AACContext *ac, int samples)
3036 void (*imdct_and_window)(AACContext *ac, SingleChannelElement *sce);
3037 switch (ac->oc[1].m4ac.object_type) {
3045 if (ac->oc[1].m4ac.frame_length_short)
3048 imdct_and_window = ac->imdct_and_windowing;
3052 ChannelElement *che = ac->che[type][i];
3055 apply_channel_coupling(ac, che, type, i, BEFORE_TNS, AAC_RENAME(apply_dependent_coupling));
3056 if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) {
3059 ac->apply_ltp(ac, &che->ch[0]);
3061 ac->apply_ltp(ac, &che->ch[1]);
3065 ac->apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1);
3067 ac->apply_tns(che->ch[1].coeffs, &che->ch[1].tns, &che->ch[1].ics, 1);
3069 apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, AAC_RENAME(apply_dependent_coupling));
3071 imdct_and_window(ac, &che->ch[0]);
3072 if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
3073 ac->update_ltp(ac, &che->ch[0]);
3075 imdct_and_window(ac, &che->ch[1]);
3076 if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP)
3077 ac->update_ltp(ac, &che->ch[1]);
3079 if (ac->oc[1].m4ac.sbr > 0) {
3080 AAC_RENAME(ff_sbr_apply)(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret);
3084 apply_channel_coupling(ac, che, type, i, AFTER_IMDCT, AAC_RENAME(apply_independent_coupling));
3099 av_log(ac->avctx, AV_LOG_VERBOSE, "ChannelElement %d.%d missing \n", type, i);
3105 static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
3114 if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) {
3117 avpriv_report_missing_feature(ac->avctx,
3119 ac->warned_num_aac_frames = 1;
3121 push_output_configuration(ac);
3123 ac->oc[1].m4ac.chan_config = hdr_info.chan_config;
3124 if ((ret = set_default_channel_config(ac, ac->avctx,
3129 if ((ret = output_configure(ac, layout_map, layout_map_tags,
3130 FFMAX(ac->oc[1].status,
3134 ac->oc[1].m4ac.chan_config = 0;
3140 if (ac->dmono_mode && ac->oc[0].status == OC_NONE) {
3146 if (output_configure(ac, layout_map, layout_map_tags,
3151 ac->oc[1].m4ac.sample_rate = hdr_info.sample_rate;
3152 ac->oc[1].m4ac.sampling_index = hdr_info.sampling_index;
3153 ac->oc[1].m4ac.object_type = hdr_info.object_type;
3154 ac->oc[1].m4ac.frame_length_short = 0;
3155 if (ac->oc[0].status != OC_LOCKED ||
3156 ac->oc[0].m4ac.chan_config != hdr_info.chan_config ||
3157 ac->oc[0].m4ac.sample_rate != hdr_info.sample_rate) {
3158 ac->oc[1].m4ac.sbr = -1;
3159 ac->oc[1].m4ac.ps = -1;
3170 AACContext *ac = avctx->priv_data;
3171 const MPEG4AudioConfig *const m4ac = &ac->oc[1].m4ac;
3181 ac->frame = data;
3188 ac->avctx->profile = aot - 1;
3190 ac->tags_mapped = 0;
3200 if (!(che=get_che(ac, elem_type, elem_id))) {
3201 av_log(ac->avctx, AV_LOG_ERROR,
3211 err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3214 err = decode_cpe(ac, gb, che);
3217 err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3224 spectral_to_sample(ac, samples);
3226 if (!ac->frame->data[0] && samples) {
3231 ac->frame->nb_samples = samples;
3232 ac->frame->sample_rate = avctx->sample_rate;
3243 AACContext *ac = avctx->priv_data;
3252 ac->frame = frame;
3255 if ((err = parse_adts_frame_header(ac, gb)) < 0) {
3259 if (ac->oc[1].m4ac.sampling_index > 12) {
3260 av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->oc[1].m4ac.sampling_index);
3271 ac->avctx->profile = ac->oc[1].m4ac.object_type - 1;
3274 ac->tags_mapped = 0;
3290 av_log(ac->avctx, error ? AV_LOG_ERROR : AV_LOG_DEBUG, "channel element %d.%d duplicate\n",
3299 if (!(che=get_che(ac, elem_type, elem_id))) {
3300 av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n",
3305 samples = ac->oc[1].m4ac.frame_length_short ? 960 : 1024;
3312 err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3318 err = decode_cpe(ac, gb, che);
3323 err = decode_cce(ac, gb, che);
3327 err = decode_ics(ac, &che->ch[0], gb, 0, 0);
3332 err = skip_data_stream_element(ac, gb);
3339 int pushed = push_output_configuration(ac);
3345 tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb,
3354 pop_output_configuration(ac);
3356 err = output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1);
3358 ac->oc[1].m4ac.chan_config = 0;
3374 int ret = decode_extension_payload(ac, gb, elem_id, che_prev, che_prev_type);
3408 multiplier = (ac->oc[1].m4ac.sbr == 1) ? ac->oc[1].m4ac.ext_sample_rate > ac->oc[1].m4ac.sample_rate : 0;
3411 spectral_to_sample(ac, samples);
3413 if (ac->oc[1].status && audio_found) {
3414 avctx->sample_rate = ac->oc[1].m4ac.sample_rate << multiplier;
3416 ac->oc[1].status = OC_LOCKED;
3422 if (!ac->frame->data[0] && samples) {
3429 ac->frame->nb_samples = samples;
3430 ac->frame->sample_rate = avctx->sample_rate;
3432 av_frame_unref(ac->frame);
3436 is_dmono = ac->dmono_mode && sce_count == 2 &&
3437 !av_channel_layout_compare(&ac->oc[1].ch_layout,
3440 if (ac->dmono_mode == 1)
3442 else if (ac->dmono_mode == 2)
3448 pop_output_configuration(ac);
3455 AACContext *ac = avctx->priv_data;
3473 ac->oc[1].status = OC_NONE;
3474 err = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac,
3482 ac->dmono_mode = 0;
3484 ac->dmono_mode = 1 + *jp_dualmono;
3485 if (ac->force_dmono_mode >= 0)
3486 ac->dmono_mode = ac->force_dmono_mode;
3494 switch (ac->oc[1].m4ac.object_type) {
3517 AACContext *ac = avctx->priv_data;
3522 if (ac->che[type][i])
3523 AAC_RENAME(ff_aac_sbr_ctx_close)(&ac->che[type][i]->sbr);
3524 av_freep(&ac->che[type][i]);
3528 ff_mdct_end(&ac->mdct);
3529 ff_mdct_end(&ac->mdct_small);
3530 ff_mdct_end(&ac->mdct_ld);
3531 ff_mdct_end(&ac->mdct_ltp);
3533 ff_mdct15_uninit(&ac->mdct120);
3534 ff_mdct15_uninit(&ac->mdct480);
3535 ff_mdct15_uninit(&ac->mdct960);
3537 av_freep(&ac->fdsp);