Mercurial > libavcodec.hg
comparison aac.c @ 11833:9103a9b3573a libavcodec
aacdec: Rename avccontext to avctx.
author | alexc |
---|---|
date | Sat, 05 Jun 2010 15:22:19 +0000 |
parents | 9bdc0fe882fa |
children |
comparison
equal
deleted
inserted
replaced
11832:e522dbf60abd | 11833:9103a9b3573a |
---|---|
118 by the spec but we will try to work around it. | 118 by the spec but we will try to work around it. |
119 */ | 119 */ |
120 int err_printed = 0; | 120 int err_printed = 0; |
121 while (ac->tags_seen_this_frame[type][elem_id] && elem_id < MAX_ELEM_ID) { | 121 while (ac->tags_seen_this_frame[type][elem_id] && elem_id < MAX_ELEM_ID) { |
122 if (ac->output_configured < OC_LOCKED && !err_printed) { | 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 err_printed = 1; | 124 err_printed = 1; |
125 } | 125 } |
126 elem_id++; | 126 elem_id++; |
127 } | 127 } |
128 if (elem_id == MAX_ELEM_ID) | 128 if (elem_id == MAX_ELEM_ID) |
223 static av_cold int output_configure(AACContext *ac, | 223 static av_cold int output_configure(AACContext *ac, |
224 enum ChannelPosition che_pos[4][MAX_ELEM_ID], | 224 enum ChannelPosition che_pos[4][MAX_ELEM_ID], |
225 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], | 225 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], |
226 int channel_config, enum OCStatus oc_type) | 226 int channel_config, enum OCStatus oc_type) |
227 { | 227 { |
228 AVCodecContext *avctx = ac->avccontext; | 228 AVCodecContext *avctx = ac->avctx; |
229 int i, type, channels = 0, ret; | 229 int i, type, channels = 0, ret; |
230 | 230 |
231 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); | 231 memcpy(che_pos, new_che_pos, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); |
232 | 232 |
233 if (channel_config) { | 233 if (channel_config) { |
306 | 306 |
307 skip_bits(gb, 2); // object_type | 307 skip_bits(gb, 2); // object_type |
308 | 308 |
309 sampling_index = get_bits(gb, 4); | 309 sampling_index = get_bits(gb, 4); |
310 if (ac->m4ac.sampling_index != sampling_index) | 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 num_front = get_bits(gb, 4); | 313 num_front = get_bits(gb, 4); |
314 num_side = get_bits(gb, 4); | 314 num_side = get_bits(gb, 4); |
315 num_back = get_bits(gb, 4); | 315 num_back = get_bits(gb, 4); |
316 num_lfe = get_bits(gb, 2); | 316 num_lfe = get_bits(gb, 2); |
337 align_get_bits(gb); | 337 align_get_bits(gb); |
338 | 338 |
339 /* comment field, first byte is length */ | 339 /* comment field, first byte is length */ |
340 comment_len = get_bits(gb, 8) * 8; | 340 comment_len = get_bits(gb, 8) * 8; |
341 if (get_bits_left(gb) < comment_len) { | 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 return -1; | 343 return -1; |
344 } | 344 } |
345 skip_bits_long(gb, comment_len); | 345 skip_bits_long(gb, comment_len); |
346 return 0; | 346 return 0; |
347 } | 347 } |
357 static av_cold int set_default_channel_config(AACContext *ac, | 357 static av_cold int set_default_channel_config(AACContext *ac, |
358 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], | 358 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], |
359 int channel_config) | 359 int channel_config) |
360 { | 360 { |
361 if (channel_config < 1 || channel_config > 7) { | 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 channel_config); | 363 channel_config); |
364 return -1; | 364 return -1; |
365 } | 365 } |
366 | 366 |
367 /* default channel configurations: | 367 /* default channel configurations: |
402 { | 402 { |
403 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; | 403 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; |
404 int extension_flag, ret; | 404 int extension_flag, ret; |
405 | 405 |
406 if (get_bits1(gb)) { // frameLengthFlag | 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 return -1; | 408 return -1; |
409 } | 409 } |
410 | 410 |
411 if (get_bits1(gb)) // dependsOnCoreCoder | 411 if (get_bits1(gb)) // dependsOnCoreCoder |
412 skip_bits(gb, 14); // coreCoderDelay | 412 skip_bits(gb, 14); // coreCoderDelay |
466 init_get_bits(&gb, data, data_size * 8); | 466 init_get_bits(&gb, data, data_size * 8); |
467 | 467 |
468 if ((i = ff_mpeg4audio_get_config(&ac->m4ac, data, data_size)) < 0) | 468 if ((i = ff_mpeg4audio_get_config(&ac->m4ac, data, data_size)) < 0) |
469 return -1; | 469 return -1; |
470 if (ac->m4ac.sampling_index > 12) { | 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 return -1; | 472 return -1; |
473 } | 473 } |
474 | 474 |
475 skip_bits_long(&gb, i); | 475 skip_bits_long(&gb, i); |
476 | 476 |
479 case AOT_AAC_LC: | 479 case AOT_AAC_LC: |
480 if (decode_ga_specific_config(ac, &gb, ac->m4ac.chan_config)) | 480 if (decode_ga_specific_config(ac, &gb, ac->m4ac.chan_config)) |
481 return -1; | 481 return -1; |
482 break; | 482 break; |
483 default: | 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 ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type); | 485 ac->m4ac.sbr == 1? "SBR+" : "", ac->m4ac.object_type); |
486 return -1; | 486 return -1; |
487 } | 487 } |
488 return 0; | 488 return 0; |
489 } | 489 } |
522 int i; | 522 int i; |
523 for (i = group_num - 1; i < MAX_PREDICTORS; i += 30) | 523 for (i = group_num - 1; i < MAX_PREDICTORS; i += 30) |
524 reset_predict_state(&ps[i]); | 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 int i; | 530 int i; |
531 | 531 |
532 ac->avccontext = avccontext; | 532 ac->avctx = avctx; |
533 ac->m4ac.sample_rate = avccontext->sample_rate; | 533 ac->m4ac.sample_rate = avctx->sample_rate; |
534 | 534 |
535 if (avccontext->extradata_size > 0) { | 535 if (avctx->extradata_size > 0) { |
536 if (decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) | 536 if (decode_audio_specific_config(ac, avctx->extradata, avctx->extradata_size)) |
537 return -1; | 537 return -1; |
538 } | 538 } |
539 | 539 |
540 avccontext->sample_fmt = SAMPLE_FMT_S16; | 540 avctx->sample_fmt = SAMPLE_FMT_S16; |
541 | 541 |
542 AAC_INIT_VLC_STATIC( 0, 304); | 542 AAC_INIT_VLC_STATIC( 0, 304); |
543 AAC_INIT_VLC_STATIC( 1, 270); | 543 AAC_INIT_VLC_STATIC( 1, 270); |
544 AAC_INIT_VLC_STATIC( 2, 550); | 544 AAC_INIT_VLC_STATIC( 2, 550); |
545 AAC_INIT_VLC_STATIC( 3, 300); | 545 AAC_INIT_VLC_STATIC( 3, 300); |
551 AAC_INIT_VLC_STATIC( 9, 366); | 551 AAC_INIT_VLC_STATIC( 9, 366); |
552 AAC_INIT_VLC_STATIC(10, 462); | 552 AAC_INIT_VLC_STATIC(10, 462); |
553 | 553 |
554 ff_aac_sbr_init(); | 554 ff_aac_sbr_init(); |
555 | 555 |
556 dsputil_init(&ac->dsp, avccontext); | 556 dsputil_init(&ac->dsp, avctx); |
557 | 557 |
558 ac->random_state = 0x1f2e3d4c; | 558 ac->random_state = 0x1f2e3d4c; |
559 | 559 |
560 // -1024 - Compensate wrong IMDCT method. | 560 // -1024 - Compensate wrong IMDCT method. |
561 // 32768 - Required to scale values to the correct range for the bias method | 561 // 32768 - Required to scale values to the correct range for the bias method |
605 count += get_bits(gb, 8); | 605 count += get_bits(gb, 8); |
606 if (byte_align) | 606 if (byte_align) |
607 align_get_bits(gb); | 607 align_get_bits(gb); |
608 | 608 |
609 if (get_bits_left(gb) < 8 * count) { | 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 return -1; | 611 return -1; |
612 } | 612 } |
613 skip_bits_long(gb, 8 * count); | 613 skip_bits_long(gb, 8 * count); |
614 return 0; | 614 return 0; |
615 } | 615 } |
619 { | 619 { |
620 int sfb; | 620 int sfb; |
621 if (get_bits1(gb)) { | 621 if (get_bits1(gb)) { |
622 ics->predictor_reset_group = get_bits(gb, 5); | 622 ics->predictor_reset_group = get_bits(gb, 5); |
623 if (ics->predictor_reset_group == 0 || ics->predictor_reset_group > 30) { | 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 return -1; | 625 return -1; |
626 } | 626 } |
627 } | 627 } |
628 for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->m4ac.sampling_index]); sfb++) { | 628 for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->m4ac.sampling_index]); sfb++) { |
629 ics->prediction_used[sfb] = get_bits1(gb); | 629 ics->prediction_used[sfb] = get_bits1(gb); |
638 */ | 638 */ |
639 static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, | 639 static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, |
640 GetBitContext *gb, int common_window) | 640 GetBitContext *gb, int common_window) |
641 { | 641 { |
642 if (get_bits1(gb)) { | 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 memset(ics, 0, sizeof(IndividualChannelStream)); | 644 memset(ics, 0, sizeof(IndividualChannelStream)); |
645 return -1; | 645 return -1; |
646 } | 646 } |
647 ics->window_sequence[1] = ics->window_sequence[0]; | 647 ics->window_sequence[1] = ics->window_sequence[0]; |
648 ics->window_sequence[0] = get_bits(gb, 2); | 648 ics->window_sequence[0] = get_bits(gb, 2); |
679 if (decode_prediction(ac, ics, gb)) { | 679 if (decode_prediction(ac, ics, gb)) { |
680 memset(ics, 0, sizeof(IndividualChannelStream)); | 680 memset(ics, 0, sizeof(IndividualChannelStream)); |
681 return -1; | 681 return -1; |
682 } | 682 } |
683 } else if (ac->m4ac.object_type == AOT_AAC_LC) { | 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 memset(ics, 0, sizeof(IndividualChannelStream)); | 685 memset(ics, 0, sizeof(IndividualChannelStream)); |
686 return -1; | 686 return -1; |
687 } else { | 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 memset(ics, 0, sizeof(IndividualChannelStream)); | 689 memset(ics, 0, sizeof(IndividualChannelStream)); |
690 return -1; | 690 return -1; |
691 } | 691 } |
692 } | 692 } |
693 } | 693 } |
694 | 694 |
695 if (ics->max_sfb > ics->num_swb) { | 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 "Number of scalefactor bands in group (%d) exceeds limit (%d).\n", | 697 "Number of scalefactor bands in group (%d) exceeds limit (%d).\n", |
698 ics->max_sfb, ics->num_swb); | 698 ics->max_sfb, ics->num_swb); |
699 memset(ics, 0, sizeof(IndividualChannelStream)); | 699 memset(ics, 0, sizeof(IndividualChannelStream)); |
700 return -1; | 700 return -1; |
701 } | 701 } |
722 while (k < ics->max_sfb) { | 722 while (k < ics->max_sfb) { |
723 uint8_t sect_end = k; | 723 uint8_t sect_end = k; |
724 int sect_len_incr; | 724 int sect_len_incr; |
725 int sect_band_type = get_bits(gb, 4); | 725 int sect_band_type = get_bits(gb, 4); |
726 if (sect_band_type == 12) { | 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 return -1; | 728 return -1; |
729 } | 729 } |
730 while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1) | 730 while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1) |
731 sect_end += sect_len_incr; | 731 sect_end += sect_len_incr; |
732 sect_end += sect_len_incr; | 732 sect_end += sect_len_incr; |
733 if (get_bits_left(gb) < 0) { | 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 return -1; | 735 return -1; |
736 } | 736 } |
737 if (sect_end > ics->max_sfb) { | 737 if (sect_end > ics->max_sfb) { |
738 av_log(ac->avccontext, AV_LOG_ERROR, | 738 av_log(ac->avctx, AV_LOG_ERROR, |
739 "Number of bands (%d) exceeds limit (%d).\n", | 739 "Number of bands (%d) exceeds limit (%d).\n", |
740 sect_end, ics->max_sfb); | 740 sect_end, ics->max_sfb); |
741 return -1; | 741 return -1; |
742 } | 742 } |
743 for (; k < sect_end; k++) { | 743 for (; k < sect_end; k++) { |
778 sf[idx] = 0.; | 778 sf[idx] = 0.; |
779 } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { | 779 } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { |
780 for (; i < run_end; i++, idx++) { | 780 for (; i < run_end; i++, idx++) { |
781 offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; | 781 offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; |
782 if (offset[2] > 255U) { | 782 if (offset[2] > 255U) { |
783 av_log(ac->avccontext, AV_LOG_ERROR, | 783 av_log(ac->avctx, AV_LOG_ERROR, |
784 "%s (%d) out of range.\n", sf_str[2], offset[2]); | 784 "%s (%d) out of range.\n", sf_str[2], offset[2]); |
785 return -1; | 785 return -1; |
786 } | 786 } |
787 sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300]; | 787 sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300]; |
788 } | 788 } |
791 if (noise_flag-- > 0) | 791 if (noise_flag-- > 0) |
792 offset[1] += get_bits(gb, 9) - 256; | 792 offset[1] += get_bits(gb, 9) - 256; |
793 else | 793 else |
794 offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; | 794 offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; |
795 if (offset[1] > 255U) { | 795 if (offset[1] > 255U) { |
796 av_log(ac->avccontext, AV_LOG_ERROR, | 796 av_log(ac->avctx, AV_LOG_ERROR, |
797 "%s (%d) out of range.\n", sf_str[1], offset[1]); | 797 "%s (%d) out of range.\n", sf_str[1], offset[1]); |
798 return -1; | 798 return -1; |
799 } | 799 } |
800 sf[idx] = -ff_aac_pow2sf_tab[offset[1] + sf_offset + 100]; | 800 sf[idx] = -ff_aac_pow2sf_tab[offset[1] + sf_offset + 100]; |
801 } | 801 } |
802 } else { | 802 } else { |
803 for (; i < run_end; i++, idx++) { | 803 for (; i < run_end; i++, idx++) { |
804 offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; | 804 offset[0] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; |
805 if (offset[0] > 255U) { | 805 if (offset[0] > 255U) { |
806 av_log(ac->avccontext, AV_LOG_ERROR, | 806 av_log(ac->avctx, AV_LOG_ERROR, |
807 "%s (%d) out of range.\n", sf_str[0], offset[0]); | 807 "%s (%d) out of range.\n", sf_str[0], offset[0]); |
808 return -1; | 808 return -1; |
809 } | 809 } |
810 sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset]; | 810 sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset]; |
811 } | 811 } |
858 for (filt = 0; filt < tns->n_filt[w]; filt++) { | 858 for (filt = 0; filt < tns->n_filt[w]; filt++) { |
859 int tmp2_idx; | 859 int tmp2_idx; |
860 tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); | 860 tns->length[w][filt] = get_bits(gb, 6 - 2 * is8); |
861 | 861 |
862 if ((tns->order[w][filt] = get_bits(gb, 5 - 2 * is8)) > tns_max_order) { | 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 tns->order[w][filt], tns_max_order); | 864 tns->order[w][filt], tns_max_order); |
865 tns->order[w][filt] = 0; | 865 tns->order[w][filt] = 0; |
866 return -1; | 866 return -1; |
867 } | 867 } |
868 if (tns->order[w][filt]) { | 868 if (tns->order[w][filt]) { |
1177 UPDATE_CACHE(re, gb); | 1177 UPDATE_CACHE(re, gb); |
1178 b = GET_CACHE(re, gb); | 1178 b = GET_CACHE(re, gb); |
1179 b = 31 - av_log2(~b); | 1179 b = 31 - av_log2(~b); |
1180 | 1180 |
1181 if (b > 8) { | 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 return -1; | 1183 return -1; |
1184 } | 1184 } |
1185 | 1185 |
1186 #if MIN_CACHE_BITS < 21 | 1186 #if MIN_CACHE_BITS < 21 |
1187 LAST_SKIP_BITS(re, gb, b + 1); | 1187 LAST_SKIP_BITS(re, gb, b + 1); |
1230 } | 1230 } |
1231 } | 1231 } |
1232 return 0; | 1232 return 0; |
1233 | 1233 |
1234 err_cb_overflow: | 1234 err_cb_overflow: |
1235 av_log(ac->avccontext, AV_LOG_ERROR, | 1235 av_log(ac->avctx, AV_LOG_ERROR, |
1236 "Read beyond end of ff_aac_codebook_vectors[%d][]. index %d >= %d\n", | 1236 "Read beyond end of ff_aac_codebook_vectors[%d][]. index %d >= %d\n", |
1237 band_type[idx], err_idx, ff_aac_spectral_sizes[band_type[idx]]); | 1237 band_type[idx], err_idx, ff_aac_spectral_sizes[band_type[idx]]); |
1238 return -1; | 1238 return -1; |
1239 } | 1239 } |
1240 | 1240 |
1351 | 1351 |
1352 pulse_present = 0; | 1352 pulse_present = 0; |
1353 if (!scale_flag) { | 1353 if (!scale_flag) { |
1354 if ((pulse_present = get_bits1(gb))) { | 1354 if ((pulse_present = get_bits1(gb))) { |
1355 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { | 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 return -1; | 1357 return -1; |
1358 } | 1358 } |
1359 if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) { | 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 return -1; | 1361 return -1; |
1362 } | 1362 } |
1363 } | 1363 } |
1364 if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics)) | 1364 if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics)) |
1365 return -1; | 1365 return -1; |
1366 if (get_bits1(gb)) { | 1366 if (get_bits1(gb)) { |
1367 av_log_missing_feature(ac->avccontext, "SSR", 1); | 1367 av_log_missing_feature(ac->avctx, "SSR", 1); |
1368 return -1; | 1368 return -1; |
1369 } | 1369 } |
1370 } | 1370 } |
1371 | 1371 |
1372 if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0) | 1372 if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, &pulse, ics, sce->band_type) < 0) |
1462 i = cpe->ch[1].ics.use_kb_window[0]; | 1462 i = cpe->ch[1].ics.use_kb_window[0]; |
1463 cpe->ch[1].ics = cpe->ch[0].ics; | 1463 cpe->ch[1].ics = cpe->ch[0].ics; |
1464 cpe->ch[1].ics.use_kb_window[1] = i; | 1464 cpe->ch[1].ics.use_kb_window[1] = i; |
1465 ms_present = get_bits(gb, 2); | 1465 ms_present = get_bits(gb, 2); |
1466 if (ms_present == 3) { | 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 return -1; | 1468 return -1; |
1469 } else if (ms_present) | 1469 } else if (ms_present) |
1470 decode_mid_side_stereo(cpe, gb, ms_present); | 1470 decode_mid_side_stereo(cpe, gb, ms_present); |
1471 } | 1471 } |
1472 if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0))) | 1472 if ((ret = decode_ics(ac, &cpe->ch[0], gb, common_window, 0))) |
1649 switch (get_bits(gb, 4)) { // extension type | 1649 switch (get_bits(gb, 4)) { // extension type |
1650 case EXT_SBR_DATA_CRC: | 1650 case EXT_SBR_DATA_CRC: |
1651 crc_flag++; | 1651 crc_flag++; |
1652 case EXT_SBR_DATA: | 1652 case EXT_SBR_DATA: |
1653 if (!che) { | 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 return res; | 1655 return res; |
1656 } else if (!ac->m4ac.sbr) { | 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 skip_bits_long(gb, 8 * cnt - 4); | 1658 skip_bits_long(gb, 8 * cnt - 4); |
1659 return res; | 1659 return res; |
1660 } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) { | 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 skip_bits_long(gb, 8 * cnt - 4); | 1662 skip_bits_long(gb, 8 * cnt - 4); |
1663 return res; | 1663 return res; |
1664 } else { | 1664 } else { |
1665 ac->m4ac.sbr = 1; | 1665 ac->m4ac.sbr = 1; |
1666 } | 1666 } |
1742 int i; | 1742 int i; |
1743 | 1743 |
1744 // imdct | 1744 // imdct |
1745 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { | 1745 if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { |
1746 if (ics->window_sequence[1] == ONLY_LONG_SEQUENCE || ics->window_sequence[1] == LONG_STOP_SEQUENCE) | 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 "Transition from an ONLY_LONG or LONG_STOP to an EIGHT_SHORT sequence detected. " | 1748 "Transition from an ONLY_LONG or LONG_STOP to an EIGHT_SHORT sequence detected. " |
1749 "If you heard an audible artifact, please submit the sample to the FFmpeg developers.\n"); | 1749 "If you heard an audible artifact, please submit the sample to the FFmpeg developers.\n"); |
1750 for (i = 0; i < 1024; i += 128) | 1750 for (i = 0; i < 1024; i += 128) |
1751 ff_imdct_half(&ac->mdct_small, buf + i, in + i); | 1751 ff_imdct_half(&ac->mdct_small, buf + i, in + i); |
1752 } else | 1752 } else |
1808 const uint16_t *offsets = ics->swb_offset; | 1808 const uint16_t *offsets = ics->swb_offset; |
1809 float *dest = target->coeffs; | 1809 float *dest = target->coeffs; |
1810 const float *src = cce->ch[0].coeffs; | 1810 const float *src = cce->ch[0].coeffs; |
1811 int g, i, group, k, idx = 0; | 1811 int g, i, group, k, idx = 0; |
1812 if (ac->m4ac.object_type == AOT_AAC_LTP) { | 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 "Dependent coupling is not supported together with LTP\n"); | 1814 "Dependent coupling is not supported together with LTP\n"); |
1815 return; | 1815 return; |
1816 } | 1816 } |
1817 for (g = 0; g < ics->num_window_groups; g++) { | 1817 for (g = 0; g < ics->num_window_groups; g++) { |
1818 for (i = 0; i < ics->max_sfb; i++, idx++) { | 1818 for (i = 0; i < ics->max_sfb; i++, idx++) { |
1943 if (ac->output_configured != OC_LOCKED) | 1943 if (ac->output_configured != OC_LOCKED) |
1944 ac->m4ac.sbr = -1; | 1944 ac->m4ac.sbr = -1; |
1945 ac->m4ac.sample_rate = hdr_info.sample_rate; | 1945 ac->m4ac.sample_rate = hdr_info.sample_rate; |
1946 ac->m4ac.sampling_index = hdr_info.sampling_index; | 1946 ac->m4ac.sampling_index = hdr_info.sampling_index; |
1947 ac->m4ac.object_type = hdr_info.object_type; | 1947 ac->m4ac.object_type = hdr_info.object_type; |
1948 if (!ac->avccontext->sample_rate) | 1948 if (!ac->avctx->sample_rate) |
1949 ac->avccontext->sample_rate = hdr_info.sample_rate; | 1949 ac->avctx->sample_rate = hdr_info.sample_rate; |
1950 if (hdr_info.num_aac_frames == 1) { | 1950 if (hdr_info.num_aac_frames == 1) { |
1951 if (!hdr_info.crc_absent) | 1951 if (!hdr_info.crc_absent) |
1952 skip_bits(gb, 16); | 1952 skip_bits(gb, 16); |
1953 } else { | 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 return -1; | 1955 return -1; |
1956 } | 1956 } |
1957 } | 1957 } |
1958 return size; | 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 int *data_size, AVPacket *avpkt) | 1962 int *data_size, AVPacket *avpkt) |
1963 { | 1963 { |
1964 const uint8_t *buf = avpkt->data; | 1964 const uint8_t *buf = avpkt->data; |
1965 int buf_size = avpkt->size; | 1965 int buf_size = avpkt->size; |
1966 AACContext *ac = avccontext->priv_data; | 1966 AACContext *ac = avctx->priv_data; |
1967 ChannelElement *che = NULL, *che_prev = NULL; | 1967 ChannelElement *che = NULL, *che_prev = NULL; |
1968 GetBitContext gb; | 1968 GetBitContext gb; |
1969 enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; | 1969 enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; |
1970 int err, elem_id, data_size_tmp; | 1970 int err, elem_id, data_size_tmp; |
1971 int buf_consumed; | 1971 int buf_consumed; |
1974 | 1974 |
1975 init_get_bits(&gb, buf, buf_size * 8); | 1975 init_get_bits(&gb, buf, buf_size * 8); |
1976 | 1976 |
1977 if (show_bits(&gb, 12) == 0xfff) { | 1977 if (show_bits(&gb, 12) == 0xfff) { |
1978 if (parse_adts_frame_header(ac, &gb) < 0) { | 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 return -1; | 1980 return -1; |
1981 } | 1981 } |
1982 if (ac->m4ac.sampling_index > 12) { | 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 return -1; | 1984 return -1; |
1985 } | 1985 } |
1986 } | 1986 } |
1987 | 1987 |
1988 memset(ac->tags_seen_this_frame, 0, sizeof(ac->tags_seen_this_frame)); | 1988 memset(ac->tags_seen_this_frame, 0, sizeof(ac->tags_seen_this_frame)); |
1989 // parse | 1989 // parse |
1990 while ((elem_type = get_bits(&gb, 3)) != TYPE_END) { | 1990 while ((elem_type = get_bits(&gb, 3)) != TYPE_END) { |
1991 elem_id = get_bits(&gb, 4); | 1991 elem_id = get_bits(&gb, 4); |
1992 | 1992 |
1993 if (elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) { | 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 return -1; | 1995 return -1; |
1996 } | 1996 } |
1997 | 1997 |
1998 switch (elem_type) { | 1998 switch (elem_type) { |
1999 | 1999 |
2021 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; | 2021 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; |
2022 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); | 2022 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); |
2023 if ((err = decode_pce(ac, new_che_pos, &gb))) | 2023 if ((err = decode_pce(ac, new_che_pos, &gb))) |
2024 break; | 2024 break; |
2025 if (ac->output_configured > OC_TRIAL_PCE) | 2025 if (ac->output_configured > OC_TRIAL_PCE) |
2026 av_log(avccontext, AV_LOG_ERROR, | 2026 av_log(avctx, AV_LOG_ERROR, |
2027 "Not evaluating a further program_config_element as this construct is dubious at best.\n"); | 2027 "Not evaluating a further program_config_element as this construct is dubious at best.\n"); |
2028 else | 2028 else |
2029 err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE); | 2029 err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE); |
2030 break; | 2030 break; |
2031 } | 2031 } |
2032 | 2032 |
2033 case TYPE_FIL: | 2033 case TYPE_FIL: |
2034 if (elem_id == 15) | 2034 if (elem_id == 15) |
2035 elem_id += get_bits(&gb, 8) - 1; | 2035 elem_id += get_bits(&gb, 8) - 1; |
2036 if (get_bits_left(&gb) < 8 * elem_id) { | 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 return -1; | 2038 return -1; |
2039 } | 2039 } |
2040 while (elem_id > 0) | 2040 while (elem_id > 0) |
2041 elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev); | 2041 elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev); |
2042 err = 0; /* FIXME */ | 2042 err = 0; /* FIXME */ |
2052 | 2052 |
2053 if (err) | 2053 if (err) |
2054 return err; | 2054 return err; |
2055 | 2055 |
2056 if (get_bits_left(&gb) < 3) { | 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 return -1; | 2058 return -1; |
2059 } | 2059 } |
2060 } | 2060 } |
2061 | 2061 |
2062 spectral_to_sample(ac); | 2062 spectral_to_sample(ac); |
2063 | 2063 |
2064 multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0; | 2064 multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0; |
2065 samples <<= multiplier; | 2065 samples <<= multiplier; |
2066 if (ac->output_configured < OC_LOCKED) { | 2066 if (ac->output_configured < OC_LOCKED) { |
2067 avccontext->sample_rate = ac->m4ac.sample_rate << multiplier; | 2067 avctx->sample_rate = ac->m4ac.sample_rate << multiplier; |
2068 avccontext->frame_size = samples; | 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 if (*data_size < data_size_tmp) { | 2072 if (*data_size < data_size_tmp) { |
2073 av_log(avccontext, AV_LOG_ERROR, | 2073 av_log(avctx, AV_LOG_ERROR, |
2074 "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n", | 2074 "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n", |
2075 *data_size, data_size_tmp); | 2075 *data_size, data_size_tmp); |
2076 return -1; | 2076 return -1; |
2077 } | 2077 } |
2078 *data_size = data_size_tmp; | 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 if (ac->output_configured) | 2082 if (ac->output_configured) |
2083 ac->output_configured = OC_LOCKED; | 2083 ac->output_configured = OC_LOCKED; |
2084 | 2084 |
2085 buf_consumed = (get_bits_count(&gb) + 7) >> 3; | 2085 buf_consumed = (get_bits_count(&gb) + 7) >> 3; |
2088 break; | 2088 break; |
2089 | 2089 |
2090 return buf_size > buf_offset ? buf_consumed : buf_size; | 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 int i, type; | 2096 int i, type; |
2097 | 2097 |
2098 for (i = 0; i < MAX_ELEM_ID; i++) { | 2098 for (i = 0; i < MAX_ELEM_ID; i++) { |
2099 for (type = 0; type < 4; type++) { | 2099 for (type = 0; type < 4; type++) { |
2100 if (ac->che[type][i]) | 2100 if (ac->che[type][i]) |