Mercurial > libavcodec.hg
comparison aac.c @ 8549:2cbfa4cd4670 libavcodec
Support ADTS AAC files in the ffaac decoder (limited to streams containing one
raw_data_block() per ADTS frame)
Patch by Alex Converse ( alex converse gmail com) based on a patch by Robert
Swain ( robert swain gmail com )
author | superdump |
---|---|
date | Wed, 07 Jan 2009 22:09:21 +0000 |
parents | e6909fa99317 |
children | 7a463923ecd1 |
comparison
equal
deleted
inserted
replaced
8548:3586e03586a0 | 8549:2cbfa4cd4670 |
---|---|
84 | 84 |
85 #include "aac.h" | 85 #include "aac.h" |
86 #include "aactab.h" | 86 #include "aactab.h" |
87 #include "aacdectab.h" | 87 #include "aacdectab.h" |
88 #include "mpeg4audio.h" | 88 #include "mpeg4audio.h" |
89 #include "aac_parser.h" | |
89 | 90 |
90 #include <assert.h> | 91 #include <assert.h> |
91 #include <errno.h> | 92 #include <errno.h> |
92 #include <math.h> | 93 #include <math.h> |
93 #include <string.h> | 94 #include <string.h> |
382 AACContext * ac = avccontext->priv_data; | 383 AACContext * ac = avccontext->priv_data; |
383 int i; | 384 int i; |
384 | 385 |
385 ac->avccontext = avccontext; | 386 ac->avccontext = avccontext; |
386 | 387 |
387 if (avccontext->extradata_size <= 0 || | 388 if (avccontext->extradata_size > 0) { |
388 decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) | 389 if(decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size)) |
390 return -1; | |
391 avccontext->sample_rate = ac->m4ac.sample_rate; | |
392 } else if (avccontext->channels > 0) { | |
393 enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; | |
394 memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); | |
395 if(set_default_channel_config(ac, new_che_pos, avccontext->channels - (avccontext->channels == 8))) | |
396 return -1; | |
397 if(output_configure(ac, ac->che_pos, new_che_pos)) | |
398 return -1; | |
399 ac->m4ac.sample_rate = avccontext->sample_rate; | |
400 } else { | |
401 ff_log_missing_feature(ac->avccontext, "Implicit channel configuration is", 0); | |
389 return -1; | 402 return -1; |
403 } | |
390 | 404 |
391 avccontext->sample_fmt = SAMPLE_FMT_S16; | 405 avccontext->sample_fmt = SAMPLE_FMT_S16; |
392 avccontext->sample_rate = ac->m4ac.sample_rate; | |
393 avccontext->frame_size = 1024; | 406 avccontext->frame_size = 1024; |
394 | 407 |
395 AAC_INIT_VLC_STATIC( 0, 144); | 408 AAC_INIT_VLC_STATIC( 0, 144); |
396 AAC_INIT_VLC_STATIC( 1, 114); | 409 AAC_INIT_VLC_STATIC( 1, 114); |
397 AAC_INIT_VLC_STATIC( 2, 188); | 410 AAC_INIT_VLC_STATIC( 2, 188); |
1504 } | 1517 } |
1505 } | 1518 } |
1506 } | 1519 } |
1507 } | 1520 } |
1508 | 1521 |
1522 static int parse_adts_frame_header(AACContext * ac, GetBitContext * gb) { | |
1523 | |
1524 int size; | |
1525 AACADTSHeaderInfo hdr_info; | |
1526 | |
1527 size = ff_aac_parse_header(gb, &hdr_info); | |
1528 if (size > 0) { | |
1529 if (hdr_info.chan_config) | |
1530 ac->m4ac.chan_config = hdr_info.chan_config; | |
1531 ac->m4ac.sample_rate = hdr_info.sample_rate; | |
1532 ac->m4ac.sampling_index = hdr_info.sampling_index; | |
1533 ac->m4ac.object_type = hdr_info.object_type; | |
1534 } | |
1535 if (hdr_info.num_aac_frames == 1) { | |
1536 if (!hdr_info.crc_absent) | |
1537 skip_bits(gb, 16); | |
1538 } else { | |
1539 ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0); | |
1540 return -1; | |
1541 } | |
1542 return size; | |
1543 } | |
1544 | |
1509 static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) { | 1545 static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) { |
1510 AACContext * ac = avccontext->priv_data; | 1546 AACContext * ac = avccontext->priv_data; |
1511 GetBitContext gb; | 1547 GetBitContext gb; |
1512 enum RawDataBlockType elem_type; | 1548 enum RawDataBlockType elem_type; |
1513 int err, elem_id, data_size_tmp; | 1549 int err, elem_id, data_size_tmp; |
1514 | 1550 |
1515 init_get_bits(&gb, buf, buf_size*8); | 1551 init_get_bits(&gb, buf, buf_size*8); |
1552 | |
1553 if (show_bits(&gb, 12) == 0xfff) { | |
1554 if ((err = parse_adts_frame_header(ac, &gb)) < 0) { | |
1555 av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); | |
1556 return -1; | |
1557 } | |
1558 } | |
1516 | 1559 |
1517 // parse | 1560 // parse |
1518 while ((elem_type = get_bits(&gb, 3)) != TYPE_END) { | 1561 while ((elem_type = get_bits(&gb, 3)) != TYPE_END) { |
1519 elem_id = get_bits(&gb, 4); | 1562 elem_id = get_bits(&gb, 4); |
1520 err = -1; | 1563 err = -1; |