Revision dd8871a6 libavcodec/aac.c

View differences:

libavcodec/aac.c
120 120
    int err_printed = 0;
121 121
    while (ac->tags_seen_this_frame[type][elem_id] && elem_id < MAX_ELEM_ID) {
122 122
        if (ac->output_configured < OC_LOCKED && !err_printed) {
123
            av_log(ac->avccontext, AV_LOG_WARNING, "Duplicate channel tag found, attempting to remap.\n");
123
            av_log(ac->avctx, AV_LOG_WARNING, "Duplicate channel tag found, attempting to remap.\n");
124 124
            err_printed = 1;
125 125
        }
126 126
        elem_id++;
......
225 225
                            enum ChannelPosition new_che_pos[4][MAX_ELEM_ID],
226 226
                            int channel_config, enum OCStatus oc_type)
227 227
{
228
    AVCodecContext *avctx = ac->avccontext;
228
    AVCodecContext *avctx = ac->avctx;
229 229
    int i, type, channels = 0, ret;
230 230

  
231 231
    memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
......
308 308

  
309 309
    sampling_index = get_bits(gb, 4);
310 310
    if (ac->m4ac.sampling_index != sampling_index)
311
        av_log(ac->avccontext, AV_LOG_WARNING, "Sample rate index in program config element does not match the sample rate index configured by the container.\n");
311
        av_log(ac->avctx, AV_LOG_WARNING, "Sample rate index in program config element does not match the sample rate index configured by the container.\n");
312 312

  
313 313
    num_front       = get_bits(gb, 4);
314 314
    num_side        = get_bits(gb, 4);
......
339 339
    /* comment field, first byte is length */
340 340
    comment_len = get_bits(gb, 8) * 8;
341 341
    if (get_bits_left(gb) < comment_len) {
342
        av_log(ac->avccontext, AV_LOG_ERROR, overread_err);
342
        av_log(ac->avctx, AV_LOG_ERROR, overread_err);
343 343
        return -1;
344 344
    }
345 345
    skip_bits_long(gb, comment_len);
......
359 359
                                      int channel_config)
360 360
{
361 361
    if (channel_config < 1 || channel_config > 7) {
362
        av_log(ac->avccontext, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
362
        av_log(ac->avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n",
363 363
               channel_config);
364 364
        return -1;
365 365
    }
......
404 404
    int extension_flag, ret;
405 405

  
406 406
    if (get_bits1(gb)) { // frameLengthFlag
407
        av_log_missing_feature(ac->avccontext, "960/120 MDCT window is", 1);
407
        av_log_missing_feature(ac->avctx, "960/120 MDCT window is", 1);
408 408
        return -1;
409 409
    }
410 410

  
......
468 468
    if ((i = ff_mpeg4audio_get_config(&ac->m4ac, data, data_size)) < 0)
469 469
        return -1;
470 470
    if (ac->m4ac.sampling_index > 12) {
471
        av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
471
        av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
472 472
        return -1;
473 473
    }
474 474

  
......
481 481
            return -1;
482 482
        break;
483 483
    default:
484
        av_log(ac->avccontext, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n",
484
        av_log(ac->avctx, AV_LOG_ERROR, "Audio object type %s%d is not supported.\n",
485 485
               ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type);
486 486
        return -1;
487 487
    }
......
524 524
        reset_predict_state(&ps[i]);
525 525
}
526 526

  
527
static av_cold int aac_decode_init(AVCodecContext *avccontext)
527
static av_cold int aac_decode_init(AVCodecContext *avctx)
528 528
{
529
    AACContext *ac = avccontext->priv_data;
529
    AACContext *ac = avctx->priv_data;
530 530
    int i;
531 531

  
532
    ac->avccontext = avccontext;
533
    ac->m4ac.sample_rate = avccontext->sample_rate;
532
    ac->avctx = avctx;
533
    ac->m4ac.sample_rate = avctx->sample_rate;
534 534

  
535
    if (avccontext->extradata_size > 0) {
536
        if (decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size))
535
    if (avctx->extradata_size > 0) {
536
        if (decode_audio_specific_config(ac, avctx->extradata, avctx->extradata_size))
537 537
            return -1;
538 538
    }
539 539

  
540
    avccontext->sample_fmt = SAMPLE_FMT_S16;
540
    avctx->sample_fmt = SAMPLE_FMT_S16;
541 541

  
542 542
    AAC_INIT_VLC_STATIC( 0, 304);
543 543
    AAC_INIT_VLC_STATIC( 1, 270);
......
553 553

  
554 554
    ff_aac_sbr_init();
555 555

  
556
    dsputil_init(&ac->dsp, avccontext);
556
    dsputil_init(&ac->dsp, avctx);
557 557

  
558 558
    ac->random_state = 0x1f2e3d4c;
559 559

  
......
607 607
        align_get_bits(gb);
608 608

  
609 609
    if (get_bits_left(gb) < 8 * count) {
610
        av_log(ac->avccontext, AV_LOG_ERROR, overread_err);
610
        av_log(ac->avctx, AV_LOG_ERROR, overread_err);
611 611
        return -1;
612 612
    }
613 613
    skip_bits_long(gb, 8 * count);
......
621 621
    if (get_bits1(gb)) {
622 622
        ics->predictor_reset_group = get_bits(gb, 5);
623 623
        if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30) {
624
            av_log(ac->avccontext, AV_LOG_ERROR, "Invalid Predictor Reset Group.\n");
624
            av_log(ac->avctx, AV_LOG_ERROR, "Invalid Predictor Reset Group.\n");
625 625
            return -1;
626 626
        }
627 627
    }
......
640 640
                           GetBitContext *gb, int common_window)
641 641
{
642 642
    if (get_bits1(gb)) {
643
        av_log(ac->avccontext, AV_LOG_ERROR, "Reserved bit set.\n");
643
        av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n");
644 644
        memset(ics, 0, sizeof(IndividualChannelStream));
645 645
        return -1;
646 646
    }
......
681 681
                    return -1;
682 682
                }
683 683
            } else if (ac->m4ac.object_type == AOT_AAC_LC) {
684
                av_log(ac->avccontext, AV_LOG_ERROR, "Prediction is not allowed in AAC-LC.\n");
684
                av_log(ac->avctx, AV_LOG_ERROR, "Prediction is not allowed in AAC-LC.\n");
685 685
                memset(ics, 0, sizeof(IndividualChannelStream));
686 686
                return -1;
687 687
            } else {
688
                av_log_missing_feature(ac->avccontext, "Predictor bit set but LTP is", 1);
688
                av_log_missing_feature(ac->avctx, "Predictor bit set but LTP is", 1);
689 689
                memset(ics, 0, sizeof(IndividualChannelStream));
690 690
                return -1;
691 691
            }
......
693 693
    }
694 694

  
695 695
    if (ics->max_sfb > ics->num_swb) {
696
        av_log(ac->avccontext, AV_LOG_ERROR,
696
        av_log(ac->avctx, AV_LOG_ERROR,
697 697
               "Number of scalefactor bands in group (%d) exceeds limit (%d).\n",
698 698
               ics->max_sfb, ics->num_swb);
699 699
        memset(ics, 0, sizeof(IndividualChannelStream));
......
724 724
            int sect_len_incr;
725 725
            int sect_band_type = get_bits(gb, 4);
726 726
            if (sect_band_type == 12) {
727
                av_log(ac->avccontext, AV_LOG_ERROR, "invalid band type\n");
727
                av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n");
728 728
                return -1;
729 729
            }
730 730
            while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1)
731 731
                sect_end += sect_len_incr;
732 732
            sect_end += sect_len_incr;
733 733
            if (get_bits_left(gb) < 0) {
734
                av_log(ac->avccontext, AV_LOG_ERROR, overread_err);
734
                av_log(ac->avctx, AV_LOG_ERROR, overread_err);
735 735
                return -1;
736 736
            }
737 737
            if (sect_end > ics->max_sfb) {
738
                av_log(ac->avccontext, AV_LOG_ERROR,
738
                av_log(ac->avctx, AV_LOG_ERROR,
739 739
                       "Number of bands (%d) exceeds limit (%d).\n",
740 740
                       sect_end, ics->max_sfb);
741 741
                return -1;
......
780 780
                for (; i < run_end; i++, idx++) {
781 781
                    offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
782 782
                    if (offset[2] > 255U) {
783
                        av_log(ac->avccontext, AV_LOG_ERROR,
783
                        av_log(ac->avctx, AV_LOG_ERROR,
784 784
                               "%s (%d) out of range.\n", sf_str[2], offset[2]);
785 785
                        return -1;
786 786
                    }
......
793 793
                    else
794 794
                        offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
795 795
                    if (offset[1] > 255U) {
796
                        av_log(ac->avccontext, AV_LOG_ERROR,
796
                        av_log(ac->avctx, AV_LOG_ERROR,
797 797
                               "%s (%d) out of range.\n", sf_str[1], offset[1]);
798 798
                        return -1;
799 799
                    }
......
803 803
                for (; i < run_end; i++, idx++) {
804 804
                    offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60;
805 805
                    if (offset[0] > 255U) {
806
                        av_log(ac->avccontext, AV_LOG_ERROR,
806
                        av_log(ac->avctx, AV_LOG_ERROR,
807 807
                               "%s (%d) out of range.\n", sf_str[0], offset[0]);
808 808
                        return -1;
809 809
                    }
......
860 860
                tns->length[w][filt] = get_bits(gb, 6 - 2 * is8);
861 861

  
862 862
                if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) {
863
                    av_log(ac->avccontext, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.\n",
863
                    av_log(ac->avctx, AV_LOG_ERROR, "TNS filter order %d is greater than maximum %d.\n",
864 864
                           tns->order[w][filt], tns_max_order);
865 865
                    tns->order[w][filt] = 0;
866 866
                    return -1;
......
1179 1179
                                    b = 31 - av_log2(~b);
1180 1180

  
1181 1181
                                    if (b > 8) {
1182
                                        av_log(ac->avccontext, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
1182
                                        av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
1183 1183
                                        return -1;
1184 1184
                                    }
1185 1185

  
......
1232 1232
    return 0;
1233 1233

  
1234 1234
err_cb_overflow:
1235
    av_log(ac->avccontext, AV_LOG_ERROR,
1235
    av_log(ac->avctx, AV_LOG_ERROR,
1236 1236
           "Read beyond end of ff_aac_codebook_vectors[%d][]. index %d >= %d\n",
1237 1237
           band_type[idx], err_idx, ff_aac_spectral_sizes[band_type[idx]]);
1238 1238
    return -1;
......
1353 1353
    if (!scale_flag) {
1354 1354
        if ((pulse_present = get_bits1(gb))) {
1355 1355
            if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1356
                av_log(ac->avccontext, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n");
1356
                av_log(ac->avctx, AV_LOG_ERROR, "Pulse tool not allowed in eight short sequence.\n");
1357 1357
                return -1;
1358 1358
            }
1359 1359
            if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) {
1360
                av_log(ac->avccontext, AV_LOG_ERROR, "Pulse data corrupt or invalid.\n");
1360
                av_log(ac->avctx, AV_LOG_ERROR, "Pulse data corrupt or invalid.\n");
1361 1361
                return -1;
1362 1362
            }
1363 1363
        }
1364 1364
        if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
1365 1365
            return -1;
1366 1366
        if (get_bits1(gb)) {
1367
            av_log_missing_feature(ac->avccontext, "SSR", 1);
1367
            av_log_missing_feature(ac->avctx, "SSR", 1);
1368 1368
            return -1;
1369 1369
        }
1370 1370
    }
......
1464 1464
        cpe->ch[1].ics.use_kb_window[1] = i;
1465 1465
        ms_present = get_bits(gb, 2);
1466 1466
        if (ms_present == 3) {
1467
            av_log(ac->avccontext, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
1467
            av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
1468 1468
            return -1;
1469 1469
        } else if (ms_present)
1470 1470
            decode_mid_side_stereo(cpe, gb, ms_present);
......
1651 1651
        crc_flag++;
1652 1652
    case EXT_SBR_DATA:
1653 1653
        if (!che) {
1654
            av_log(ac->avccontext, AV_LOG_ERROR, "SBR was found before the first channel element.\n");
1654
            av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\n");
1655 1655
            return res;
1656 1656
        } else if (!ac->m4ac.sbr) {
1657
            av_log(ac->avccontext, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n");
1657
            av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\n");
1658 1658
            skip_bits_long(gb, 8 * cnt - 4);
1659 1659
            return res;
1660 1660
        } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) {
1661
            av_log(ac->avccontext, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n");
1661
            av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\n");
1662 1662
            skip_bits_long(gb, 8 * cnt - 4);
1663 1663
            return res;
1664 1664
        } else {
......
1744 1744
    // imdct
1745 1745
    if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
1746 1746
        if (ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE)
1747
            av_log(ac->avccontext, AV_LOG_WARNING,
1747
            av_log(ac->avctx, AV_LOG_WARNING,
1748 1748
                   "Transition from an ONLY_LONG or LONG_STOP to an EIGHT_SHORT sequence detected. "
1749 1749
                   "If you heard an audible artifact, please submit the sample to the FFmpeg developers.\n");
1750 1750
        for (i = 0; i < 1024; i += 128)
......
1810 1810
    const float *src = cce->ch[0].coeffs;
1811 1811
    int g, i, group, k, idx = 0;
1812 1812
    if (ac->m4ac.object_type == AOT_AAC_LTP) {
1813
        av_log(ac->avccontext, AV_LOG_ERROR,
1813
        av_log(ac->avctx, AV_LOG_ERROR,
1814 1814
               "Dependent coupling is not supported together with LTP\n");
1815 1815
        return;
1816 1816
    }
......
1945 1945
        ac->m4ac.sample_rate     = hdr_info.sample_rate;
1946 1946
        ac->m4ac.sampling_index  = hdr_info.sampling_index;
1947 1947
        ac->m4ac.object_type     = hdr_info.object_type;
1948
        if (!ac->avccontext->sample_rate)
1949
            ac->avccontext->sample_rate = hdr_info.sample_rate;
1948
        if (!ac->avctx->sample_rate)
1949
            ac->avctx->sample_rate = hdr_info.sample_rate;
1950 1950
        if (hdr_info.num_aac_frames == 1) {
1951 1951
            if (!hdr_info.crc_absent)
1952 1952
                skip_bits(gb, 16);
1953 1953
        } else {
1954
            av_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
1954
            av_log_missing_feature(ac->avctx, "More than one AAC RDB per ADTS frame is", 0);
1955 1955
            return -1;
1956 1956
        }
1957 1957
    }
1958 1958
    return size;
1959 1959
}
1960 1960

  
1961
static int aac_decode_frame(AVCodecContext *avccontext, void *data,
1961
static int aac_decode_frame(AVCodecContext *avctx, void *data,
1962 1962
                            int *data_size, AVPacket *avpkt)
1963 1963
{
1964 1964
    const uint8_t *buf = avpkt->data;
1965 1965
    int buf_size = avpkt->size;
1966
    AACContext *ac = avccontext->priv_data;
1966
    AACContext *ac = avctx->priv_data;
1967 1967
    ChannelElement *che = NULL, *che_prev = NULL;
1968 1968
    GetBitContext gb;
1969 1969
    enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;
......
1976 1976

  
1977 1977
    if (show_bits(&gb, 12) == 0xfff) {
1978 1978
        if (parse_adts_frame_header(ac, &gb) < 0) {
1979
            av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n");
1979
            av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n");
1980 1980
            return -1;
1981 1981
        }
1982 1982
        if (ac->m4ac.sampling_index > 12) {
1983
            av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
1983
            av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index);
1984 1984
            return -1;
1985 1985
        }
1986 1986
    }
......
1991 1991
        elem_id = get_bits(&gb, 4);
1992 1992

  
1993 1993
        if (elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) {
1994
            av_log(ac->avccontext, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id);
1994
            av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id);
1995 1995
            return -1;
1996 1996
        }
1997 1997

  
......
2023 2023
            if ((err = decode_pce(ac, new_che_pos, &gb)))
2024 2024
                break;
2025 2025
            if (ac->output_configured > OC_TRIAL_PCE)
2026
                av_log(avccontext, AV_LOG_ERROR,
2026
                av_log(avctx, AV_LOG_ERROR,
2027 2027
                       "Not evaluating a further program_config_element as this construct is dubious at best.\n");
2028 2028
            else
2029 2029
                err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE);
......
2034 2034
            if (elem_id == 15)
2035 2035
                elem_id += get_bits(&gb, 8) - 1;
2036 2036
            if (get_bits_left(&gb) < 8 * elem_id) {
2037
                    av_log(avccontext, AV_LOG_ERROR, overread_err);
2037
                    av_log(avctx, AV_LOG_ERROR, overread_err);
2038 2038
                    return -1;
2039 2039
            }
2040 2040
            while (elem_id > 0)
......
2054 2054
            return err;
2055 2055

  
2056 2056
        if (get_bits_left(&gb) < 3) {
2057
            av_log(avccontext, AV_LOG_ERROR, overread_err);
2057
            av_log(avctx, AV_LOG_ERROR, overread_err);
2058 2058
            return -1;
2059 2059
        }
2060 2060
    }
......
2064 2064
    multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0;
2065 2065
    samples <<= multiplier;
2066 2066
    if (ac->output_configured < OC_LOCKED) {
2067
        avccontext->sample_rate = ac->m4ac.sample_rate << multiplier;
2068
        avccontext->frame_size = samples;
2067
        avctx->sample_rate = ac->m4ac.sample_rate << multiplier;
2068
        avctx->frame_size = samples;
2069 2069
    }
2070 2070

  
2071
    data_size_tmp = samples * avccontext->channels * sizeof(int16_t);
2071
    data_size_tmp = samples * avctx->channels * sizeof(int16_t);
2072 2072
    if (*data_size < data_size_tmp) {
2073
        av_log(avccontext, AV_LOG_ERROR,
2073
        av_log(avctx, AV_LOG_ERROR,
2074 2074
               "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",
2075 2075
               *data_size, data_size_tmp);
2076 2076
        return -1;
2077 2077
    }
2078 2078
    *data_size = data_size_tmp;
2079 2079

  
2080
    ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avccontext->channels);
2080
    ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avctx->channels);
2081 2081

  
2082 2082
    if (ac->output_configured)
2083 2083
        ac->output_configured = OC_LOCKED;
......
2090 2090
    return buf_size > buf_offset ? buf_consumed : buf_size;
2091 2091
}
2092 2092

  
2093
static av_cold int aac_decode_close(AVCodecContext *avccontext)
2093
static av_cold int aac_decode_close(AVCodecContext *avctx)
2094 2094
{
2095
    AACContext *ac = avccontext->priv_data;
2095
    AACContext *ac = avctx->priv_data;
2096 2096
    int i, type;
2097 2097

  
2098 2098
    for (i = 0; i < MAX_ELEM_ID; i++) {

Also available in: Unified diff