comparison aac.c @ 11393:d23864bc3887 libavcodec

AAC: Set codec parameters in the first frame rather than in .init()
author alexc
date Sun, 07 Mar 2010 23:46:40 +0000
parents 404629a45da1
children 9a171a2c04d9
comparison
equal deleted inserted replaced
11392:384d803faff4 11393:d23864bc3887
507 { 507 {
508 AACContext *ac = avccontext->priv_data; 508 AACContext *ac = avccontext->priv_data;
509 int i; 509 int i;
510 510
511 ac->avccontext = avccontext; 511 ac->avccontext = avccontext;
512 ac->m4ac.sample_rate = avccontext->sample_rate;
512 513
513 if (avccontext->extradata_size > 0) { 514 if (avccontext->extradata_size > 0) {
514 if (decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) 515 if (decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size))
515 return -1; 516 return -1;
516 avccontext->sample_rate = ac->m4ac.sample_rate;
517 } else if (avccontext->channels > 0) {
518 ac->m4ac.sample_rate = avccontext->sample_rate;
519 } 517 }
520 518
521 avccontext->sample_fmt = SAMPLE_FMT_S16; 519 avccontext->sample_fmt = SAMPLE_FMT_S16;
522 avccontext->frame_size = 1024;
523 520
524 AAC_INIT_VLC_STATIC( 0, 304); 521 AAC_INIT_VLC_STATIC( 0, 304);
525 AAC_INIT_VLC_STATIC( 1, 270); 522 AAC_INIT_VLC_STATIC( 1, 270);
526 AAC_INIT_VLC_STATIC( 2, 550); 523 AAC_INIT_VLC_STATIC( 2, 550);
527 AAC_INIT_VLC_STATIC( 3, 300); 524 AAC_INIT_VLC_STATIC( 3, 300);
1948 ChannelElement *che = NULL; 1945 ChannelElement *che = NULL;
1949 GetBitContext gb; 1946 GetBitContext gb;
1950 enum RawDataBlockType elem_type; 1947 enum RawDataBlockType elem_type;
1951 int err, elem_id, data_size_tmp; 1948 int err, elem_id, data_size_tmp;
1952 int buf_consumed; 1949 int buf_consumed;
1950 int samples = 1024, multiplier;
1953 1951
1954 init_get_bits(&gb, buf, buf_size * 8); 1952 init_get_bits(&gb, buf, buf_size * 8);
1955 1953
1956 if (show_bits(&gb, 12) == 0xfff) { 1954 if (show_bits(&gb, 12) == 0xfff) {
1957 if (parse_adts_frame_header(ac, &gb) < 0) { 1955 if (parse_adts_frame_header(ac, &gb) < 0) {
2033 return -1; 2031 return -1;
2034 } 2032 }
2035 } 2033 }
2036 2034
2037 spectral_to_sample(ac); 2035 spectral_to_sample(ac);
2036
2037 multiplier = 1;
2038 samples <<= multiplier;
2039 if (ac->output_configured < OC_LOCKED) {
2040 avccontext->sample_rate = ac->m4ac.sample_rate << multiplier;
2041 avccontext->frame_size = samples;
2042 }
2038 2043
2039 data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t); 2044 data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t);
2040 if (*data_size < data_size_tmp) { 2045 if (*data_size < data_size_tmp) {
2041 av_log(avccontext, AV_LOG_ERROR, 2046 av_log(avccontext, AV_LOG_ERROR,
2042 "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n", 2047 "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",