97
97
static VLC vlc_spectral[11];
100
static ChannelElement* get_che(AACContext *ac, int type, int elem_id) {
101
static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 };
102
if (ac->tag_che_map[type][elem_id]) {
103
return ac->tag_che_map[type][elem_id];
105
if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) {
108
switch (ac->m4ac.chan_config) {
110
if (ac->tags_mapped == 3 && type == TYPE_CPE) {
112
return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
115
/* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
116
instead of SCE[0] CPE[0] CPE[0] LFE[0]. If we seem to have
117
encountered such a stream, transfer the LFE[0] element to SCE[1] */
118
if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
120
return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
123
if (ac->tags_mapped == 2 && type == TYPE_CPE) {
125
return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
128
if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
130
return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
134
if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
136
return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
137
} else if (ac->m4ac.chan_config == 2) {
141
if (!ac->tags_mapped && type == TYPE_SCE) {
143
return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
101
151
* Configure output channel order based on the current program configuration element.
106
156
* @return Returns error status. 0 - OK, !0 - error
108
158
static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID],
109
enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]) {
159
enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], int channel_config) {
110
160
AVCodecContext *avctx = ac->avccontext;
111
161
int i, type, channels = 0;
193
if (channel_config) {
194
memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
197
memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
198
ac->tags_mapped = 4*MAX_ELEM_ID;
143
201
avctx->channels = channels;
286
345
if((ret = set_default_channel_config(ac, new_che_pos, channel_config)))
289
if((ret = output_configure(ac, ac->che_pos, new_che_pos)))
348
if((ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config)))
292
351
if (extension_flag) {
394
453
memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
395
454
if(set_default_channel_config(ac, new_che_pos, avccontext->channels - (avccontext->channels == 8)))
397
if(output_configure(ac, ac->che_pos, new_che_pos))
456
if(output_configure(ac, ac->che_pos, new_che_pos, 1))
399
458
ac->m4ac.sample_rate = avccontext->sample_rate;
1538
1597
ac->m4ac.sample_rate = hdr_info.sample_rate;
1539
1598
ac->m4ac.sampling_index = hdr_info.sampling_index;
1540
1599
ac->m4ac.object_type = hdr_info.object_type;
1542
if (hdr_info.num_aac_frames == 1) {
1543
if (!hdr_info.crc_absent)
1546
ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
1600
if (hdr_info.num_aac_frames == 1) {
1601
if (!hdr_info.crc_absent)
1604
ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
1552
1611
static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) {
1553
1612
AACContext * ac = avccontext->priv_data;
1613
ChannelElement * che = NULL;
1554
1614
GetBitContext gb;
1555
1615
enum RawDataBlockType elem_type;
1556
1616
int err, elem_id, data_size_tmp;
1573
1633
elem_id = get_bits(&gb, 4);
1576
if(elem_type == TYPE_SCE && elem_id == 1 &&
1577
!ac->che[TYPE_SCE][elem_id] && ac->che[TYPE_LFE][0]) {
1578
/* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
1579
instead of SCE[0] CPE[0] CPE[0] LFE[0]. If we seem to have
1580
encountered such a stream, transfer the LFE[0] element to SCE[1] */
1581
ac->che[TYPE_SCE][elem_id] = ac->che[TYPE_LFE][0];
1582
ac->che[TYPE_LFE][0] = NULL;
1584
if(elem_type < TYPE_DSE && !ac->che[elem_type][elem_id]) {
1636
if(elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) {
1585
1637
av_log(ac->avccontext, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id);
1589
1641
switch (elem_type) {
1592
err = decode_ics(ac, &ac->che[TYPE_SCE][elem_id]->ch[0], &gb, 0, 0);
1644
err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
1596
err = decode_cpe(ac, &gb, ac->che[TYPE_CPE][elem_id]);
1648
err = decode_cpe(ac, &gb, che);
1600
err = decode_cce(ac, &gb, ac->che[TYPE_CCE][elem_id]);
1652
err = decode_cce(ac, &gb, che);
1604
err = decode_ics(ac, &ac->che[TYPE_LFE][elem_id]->ch[0], &gb, 0, 0);
1656
err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
1615
1667
memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
1616
1668
if((err = decode_pce(ac, new_che_pos, &gb)))
1618
err = output_configure(ac, ac->che_pos, new_che_pos);
1670
err = output_configure(ac, ac->che_pos, new_che_pos, 0);