~ubuntu-branches/debian/squeeze/mplayer/squeeze

« back to all changes in this revision

Viewing changes to libavcodec/aac.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2010-05-03 20:19:41 UTC
  • mfrom: (1.1.3 upstream) (0.1.66 lucid)
  • Revision ID: james.westby@ubuntu.com-20100503201941-yt932nfarr850vj2
Tags: 2:1.0~rc3+svn20100502-2
Remove mencoder from Depends in mplayer-dbg package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
static VLC vlc_spectral[11];
98
98
 
99
99
 
 
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];
 
104
    }
 
105
    if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) {
 
106
        return NULL;
 
107
    }
 
108
    switch (ac->m4ac.chan_config) {
 
109
        case 7:
 
110
            if (ac->tags_mapped == 3 && type == TYPE_CPE) {
 
111
                ac->tags_mapped++;
 
112
                return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
 
113
            }
 
114
        case 6:
 
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)) {
 
119
                ac->tags_mapped++;
 
120
                return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
 
121
            }
 
122
        case 5:
 
123
            if (ac->tags_mapped == 2 && type == TYPE_CPE) {
 
124
                ac->tags_mapped++;
 
125
                return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
 
126
            }
 
127
        case 4:
 
128
            if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
 
129
                ac->tags_mapped++;
 
130
                return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
 
131
            }
 
132
        case 3:
 
133
        case 2:
 
134
            if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
 
135
                ac->tags_mapped++;
 
136
                return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
 
137
            } else if (ac->m4ac.chan_config == 2) {
 
138
                return NULL;
 
139
            }
 
140
        case 1:
 
141
            if (!ac->tags_mapped && type == TYPE_SCE) {
 
142
                ac->tags_mapped++;
 
143
                return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
 
144
            }
 
145
        default:
 
146
            return NULL;
 
147
    }
 
148
}
 
149
 
100
150
/**
101
151
 * Configure output channel order based on the current program configuration element.
102
152
 *
106
156
 * @return  Returns error status. 0 - OK, !0 - error
107
157
 */
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;
112
162
 
140
190
        }
141
191
    }
142
192
 
 
193
    if (channel_config) {
 
194
        memset(ac->tag_che_map, 0,       4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
 
195
        ac->tags_mapped = 0;
 
196
    } else {
 
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;
 
199
    }
 
200
 
143
201
    avctx->channels = channels;
 
202
 
144
203
    return 0;
145
204
}
146
205
 
286
345
        if((ret = set_default_channel_config(ac, new_che_pos, channel_config)))
287
346
            return ret;
288
347
    }
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)))
290
349
        return ret;
291
350
 
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)))
396
455
            return -1;
397
 
        if(output_configure(ac, ac->che_pos, new_che_pos))
 
456
        if(output_configure(ac, ac->che_pos, new_che_pos, 1))
398
457
            return -1;
399
458
        ac->m4ac.sample_rate = avccontext->sample_rate;
400
459
    } else {
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;
1541
 
    }
1542
 
    if (hdr_info.num_aac_frames == 1) {
1543
 
        if (!hdr_info.crc_absent)
1544
 
            skip_bits(gb, 16);
1545
 
    } else {
1546
 
        ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
1547
 
        return -1;
 
1600
        if (hdr_info.num_aac_frames == 1) {
 
1601
            if (!hdr_info.crc_absent)
 
1602
                skip_bits(gb, 16);
 
1603
        } else {
 
1604
            ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
 
1605
            return -1;
 
1606
        }
1548
1607
    }
1549
1608
    return size;
1550
1609
}
1551
1610
 
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);
1574
1634
        err = -1;
1575
1635
 
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;
1583
 
        }
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);
1586
1638
            return -1;
1587
1639
        }
1589
1641
        switch (elem_type) {
1590
1642
 
1591
1643
        case TYPE_SCE:
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);
1593
1645
            break;
1594
1646
 
1595
1647
        case TYPE_CPE:
1596
 
            err = decode_cpe(ac, &gb, ac->che[TYPE_CPE][elem_id]);
 
1648
            err = decode_cpe(ac, &gb, che);
1597
1649
            break;
1598
1650
 
1599
1651
        case TYPE_CCE:
1600
 
            err = decode_cce(ac, &gb, ac->che[TYPE_CCE][elem_id]);
 
1652
            err = decode_cce(ac, &gb, che);
1601
1653
            break;
1602
1654
 
1603
1655
        case TYPE_LFE:
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);
1605
1657
            break;
1606
1658
 
1607
1659
        case TYPE_DSE:
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)))
1617
1669
                break;
1618
 
            err = output_configure(ac, ac->che_pos, new_che_pos);
 
1670
            err = output_configure(ac, ac->che_pos, new_che_pos, 0);
1619
1671
            break;
1620
1672
        }
1621
1673