History

als: convert to new channel layout API

Vittorio Giovara committed 9 years ago

Commit 62473cb1 parent d1990991 file · +49 −41Browse files

Showing the changes to libavcodec/alsdec.c (1 of 1 file). Show all

Unified · Split

libavcodec/alsdec.c+49−41
@@ -319,7 +319,13 @@ static av_cold int read_specific_config(ALSDecContext *ctx) · 318 unmodified lines
319319 avctx->sample_rate = m4ac.sample_rate;
320320 skip_bits_long(&gb, 32); // sample rate already known
321321 sconf->samples = get_bits_long(&gb, 32);
322− avctx->channels = m4ac.channels;
322+
323+ if (avctx->ch_layout.nb_channels != m4ac.channels) {
324+ av_channel_layout_uninit(&avctx->ch_layout);
325+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
326+ avctx->ch_layout.nb_channels = m4ac.channels;
327+ }
328+
323329 skip_bits(&gb, 16); // number of channels already known
324330 skip_bits(&gb, 3); // skip file_type
325331 sconf->resolution = get_bits(&gb, 3);
@@ -349,7 +355,7 @@ static av_cold int read_specific_config(ALSDecContext *ctx) · 23 unmodified lines
349355 if (als_id != MKBETAG('A','L','S','\0'))
350356 return AVERROR_INVALIDDATA;
351357
352− if (avctx->channels > FF_SANE_NB_CHANNELS) {
358+ if (avctx->ch_layout.nb_channels > FF_SANE_NB_CHANNELS) {
353359 avpriv_request_sample(avctx, "Huge number of channels");
354360 return AVERROR_PATCHWELCOME;
355361 }
@@ -363,26 +369,26 @@ static av_cold int read_specific_config(ALSDecContext *ctx) · 7 unmodified lines
363369
364370
365371 // read channel sorting
366− if (sconf->chan_sort && avctx->channels > 1) {
367− int chan_pos_bits = av_ceil_log2(avctx->channels);
368− int bits_needed = avctx->channels * chan_pos_bits + 7;
372+ if (sconf->chan_sort && avctx->ch_layout.nb_channels > 1) {
373+ int chan_pos_bits = av_ceil_log2(avctx->ch_layout.nb_channels);
374+ int bits_needed = avctx->ch_layout.nb_channels * chan_pos_bits + 7;
369375 if (get_bits_left(&gb) < bits_needed)
370376 return AVERROR_INVALIDDATA;
371377
372− if (!(sconf->chan_pos = av_malloc_array(avctx->channels, sizeof(*sconf->chan_pos))))
378+ if (!(sconf->chan_pos = av_malloc_array(avctx->ch_layout.nb_channels, sizeof(*sconf->chan_pos))))
373379 return AVERROR(ENOMEM);
374380
375381 ctx->cs_switch = 1;
376382
377− for (i = 0; i < avctx->channels; i++) {
383+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
378384 sconf->chan_pos[i] = -1;
379385 }
380386
381− for (i = 0; i < avctx->channels; i++) {
387+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
382388 int idx;
383389
384390 idx = get_bits(&gb, chan_pos_bits);
385− if (idx >= avctx->channels || sconf->chan_pos[idx] != -1) {
391+ if (idx >= avctx->ch_layout.nb_channels || sconf->chan_pos[idx] != -1) {
386392 av_log(avctx, AV_LOG_WARNING, "Invalid channel reordering.\n");
387393 ctx->cs_switch = 0;
388394 break;
@@ -1228,7 +1234,7 @@ static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c) · 839 unmodified lines
12281234 {
12291235 GetBitContext *gb = &ctx->gb;
12301236 ALSChannelData *current = cd;
1231− unsigned int channels = ctx->avctx->channels;
1237+ unsigned int channels = ctx->avctx->ch_layout.nb_channels;
12321238 int entries = 0;
12331239
12341240 while (entries < channels && !(current->stop_flag = get_bits1(gb))) {
@@ -1277,7 +1283,7 @@ static int revert_channel_correlation(ALSDecContext *ctx, ALSBlockData *bd, · 42 unmodified lines
12771283 {
12781284 ALSChannelData *ch = cd[c];
12791285 unsigned int dep = 0;
1280− unsigned int channels = ctx->avctx->channels;
1286+ unsigned int channels = ctx->avctx->ch_layout.nb_channels;
12811287 unsigned int channel_size = ctx->sconf.frame_length + ctx->sconf.max_order;
12821288
12831289 if (reverted[c])
@@ -1475,15 +1481,15 @@ static int read_diff_float_data(ALSDecContext *ctx, unsigned int ra_frame) { · 191 unmodified lines
14751481 use_acf = get_bits1(gb);
14761482
14771483 if (ra_frame) {
1478− memset(last_acf_mantissa, 0, avctx->channels * sizeof(*last_acf_mantissa));
1479− memset(last_shift_value, 0, avctx->channels * sizeof(*last_shift_value) );
1484+ memset(last_acf_mantissa, 0, avctx->ch_layout.nb_channels * sizeof(*last_acf_mantissa));
1485+ memset(last_shift_value, 0, avctx->ch_layout.nb_channels * sizeof(*last_shift_value) );
14801486 ff_mlz_flush_dict(ctx->mlz);
14811487 }
14821488
1483− if (avctx->channels * 8 > get_bits_left(gb))
1489+ if (avctx->ch_layout.nb_channels * 8 > get_bits_left(gb))
14841490 return AVERROR_INVALIDDATA;
14851491
1486− for (c = 0; c < avctx->channels; ++c) {
1492+ for (c = 0; c < avctx->ch_layout.nb_channels; ++c) {
14871493 if (use_acf) {
14881494 //acf_flag
14891495 if (get_bits1(gb)) {
@@ -1634,6 +1640,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) · 144 unmodified lines
16341640 unsigned int div_blocks[32]; ///< block sizes.
16351641 int c;
16361642 unsigned int js_blocks[2];
1643+ int channels = avctx->ch_layout.nb_channels;
16371644 uint32_t bs_info = 0;
16381645 int ret;
16391646
@@ -1649,7 +1656,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) · 9 unmodified lines
16491656 if (!sconf->mc_coding || ctx->js_switch) {
16501657 int independent_bs = !sconf->joint_stereo;
16511658
1652− for (c = 0; c < avctx->channels; c++) {
1659+ for (c = 0; c < channels; c++) {
16531660 js_blocks[0] = 0;
16541661 js_blocks[1] = 0;
16551662
@@ -1662,7 +1669,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) · 6 unmodified lines
16621669 independent_bs = 2;
16631670
16641671 // if this is the last channel, it has to be decoded independently
1665− if (c == avctx->channels - 1 || (c & 1))
1672+ if (c == channels - 1 || (c & 1))
16661673 independent_bs = 1;
16671674
16681675 if (independent_bs) {
@@ -1691,13 +1698,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) · 22 unmodified lines
16911698 int *reverted_channels = ctx->reverted_channels;
16921699 unsigned int offset = 0;
16931700
1694− for (c = 0; c < avctx->channels; c++)
1701+ for (c = 0; c < channels; c++)
16951702 if (ctx->chan_data[c] < ctx->chan_data_buffer) {
16961703 av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data.\n");
16971704 return AVERROR_INVALIDDATA;
16981705 }
16991706
1700− memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);
1707+ memset(reverted_channels, 0, sizeof(*reverted_channels) * channels);
17011708
17021709 bd.ra_block = ra_frame;
17031710 bd.prev_raw_samples = ctx->prev_raw_samples;
@@ -1713,7 +1720,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) · 9 unmodified lines
17131720 continue;
17141721 }
17151722
1716− for (c = 0; c < avctx->channels; c++) {
1723+ for (c = 0; c < channels; c++) {
17171724 bd.const_block = ctx->const_block + c;
17181725 bd.shift_lsbs = ctx->shift_lsbs + c;
17191726 bd.opt_order = ctx->opt_order + c;
@@ -1732,13 +1739,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) · 12 unmodified lines
17321739 return ret;
17331740 }
17341741
1735− for (c = 0; c < avctx->channels; c++) {
1742+ for (c = 0; c < channels; c++) {
17361743 ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,
17371744 reverted_channels, offset, c);
17381745 if (ret < 0)
17391746 return ret;
17401747 }
1741− for (c = 0; c < avctx->channels; c++) {
1748+ for (c = 0; c < channels; c++) {
17421749 bd.const_block = ctx->const_block + c;
17431750 bd.shift_lsbs = ctx->shift_lsbs + c;
17441751 bd.opt_order = ctx->opt_order + c;
@@ -1756,13 +1763,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) · 11 unmodified lines
17561763 ctx->highest_decoded_channel = FFMAX(ctx->highest_decoded_channel, c);
17571764 }
17581765
1759− memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));
1766+ memset(reverted_channels, 0, channels * sizeof(*reverted_channels));
17601767 offset += div_blocks[b];
17611768 bd.ra_block = 0;
17621769 }
17631770
17641771 // store carryover raw samples
1765− for (c = 0; c < avctx->channels; c++)
1772+ for (c = 0; c < channels; c++)
17661773 memmove(ctx->raw_samples[c] - sconf->max_order,
17671774 ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,
17681775 sizeof(*ctx->raw_samples[c]) * sconf->max_order);
@@ -1792,6 +1799,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, · 23 unmodified lines
17921799 const uint8_t *buffer = avpkt->data;
17931800 int buffer_size = avpkt->size;
17941801 int invalid_frame, ret;
1802+ int channels = avctx->ch_layout.nb_channels;
17951803 unsigned int c, sample, ra_frame, bytes_read, shift;
17961804
17971805 if ((ret = init_get_bits8(&ctx->gb, buffer, buffer_size)) < 0)
@@ -1833,7 +1841,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, · 35 unmodified lines
18331841 #define INTERLEAVE_OUTPUT(bps) \
18341842 { \
18351843 int##bps##_t *dest = (int##bps##_t*)frame->data[0]; \
1836− int channels = avctx->channels; \
18371844 int32_t *raw_samples = ctx->raw_samples[0]; \
18381845 int raw_step = channels > 1 ? ctx->raw_samples[1] - raw_samples : 1; \
18391846 shift = bps - ctx->avctx->bits_per_raw_sample; \
@@ -1862,7 +1869,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, · 22 unmodified lines
18621869 int32_t *src = (int32_t *)frame->data[0];
18631870
18641871 for (sample = 0;
1865− sample < ctx->cur_frame_length * avctx->channels;
1872+ sample < ctx->cur_frame_length * channels;
18661873 sample++) {
18671874 int32_t v;
18681875
@@ -1883,13 +1890,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, · 14 unmodified lines
18831890 int16_t *src = (int16_t*) frame->data[0];
18841891 int16_t *dest = (int16_t*) ctx->crc_buffer;
18851892 for (sample = 0;
1886− sample < ctx->cur_frame_length * avctx->channels;
1893+ sample < ctx->cur_frame_length * channels;
18871894 sample++)
18881895 *dest++ = av_bswap16(src[sample]);
18891896 } else {
18901897 ctx->bdsp.bswap_buf((uint32_t *) ctx->crc_buffer,
18911898 (uint32_t *) frame->data[0],
1892− ctx->cur_frame_length * avctx->channels);
1899+ ctx->cur_frame_length * channels);
18931900 }
18941901 crc_source = ctx->crc_buffer;
18951902 } else {
@@ -1897,7 +1904,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, · 1 unmodified line
18971904 }
18981905
18991906 ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source,
1900− ctx->cur_frame_length * avctx->channels *
1907+ ctx->cur_frame_length * channels *
19011908 av_get_bytes_per_sample(avctx->sample_fmt));
19021909 }
19031910
@@ -1960,7 +1967,7 @@ static av_cold int decode_end(AVCodecContext *avctx) · 56 unmodified lines
19601967 av_freep(&ctx->shift_value);
19611968 av_freep(&ctx->last_shift_value);
19621969 if (ctx->raw_mantissa) {
1963− for (i = 0; i < avctx->channels; i++) {
1970+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
19641971 av_freep(&ctx->raw_mantissa[i]);
19651972 }
19661973 av_freep(&ctx->raw_mantissa);
@@ -1979,6 +1986,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 12 unmodified lines
19791986 unsigned int c;
19801987 unsigned int channel_size;
19811988 int num_buffers, ret;
1989+ int channels = avctx->ch_layout.nb_channels;
19821990 ALSDecContext *ctx = avctx->priv_data;
19831991 ALSSpecificConfig *sconf = &ctx->sconf;
19841992 ctx->avctx = avctx;
@@ -2026,7 +2034,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 41 unmodified lines
20262034 (avctx->sample_rate >= 192000);
20272035
20282036 // allocate quantized parcor coefficient buffer
2029− num_buffers = sconf->mc_coding ? avctx->channels : 1;
2037+ num_buffers = sconf->mc_coding ? channels : 1;
20302038 if (num_buffers * (uint64_t)num_buffers > INT_MAX) // protect chan_data_buffer allocation
20312039 return AVERROR_INVALIDDATA;
20322040
@@ -2095,11 +2103,11 @@ static av_cold int decode_init(AVCodecContext *avctx) · 62 unmodified lines
20952103 }
20962104
20972105 if (sconf->floating) {
2098− ctx->acf = av_malloc_array(avctx->channels, sizeof(*ctx->acf));
2099− ctx->shift_value = av_malloc_array(avctx->channels, sizeof(*ctx->shift_value));
2100− ctx->last_shift_value = av_malloc_array(avctx->channels, sizeof(*ctx->last_shift_value));
2101− ctx->last_acf_mantissa = av_malloc_array(avctx->channels, sizeof(*ctx->last_acf_mantissa));
2102− ctx->raw_mantissa = av_calloc(avctx->channels, sizeof(*ctx->raw_mantissa));
2106+ ctx->acf = av_malloc_array(channels, sizeof(*ctx->acf));
2107+ ctx->shift_value = av_malloc_array(channels, sizeof(*ctx->shift_value));
2108+ ctx->last_shift_value = av_malloc_array(channels, sizeof(*ctx->last_shift_value));
2109+ ctx->last_acf_mantissa = av_malloc_array(channels, sizeof(*ctx->last_acf_mantissa));
2110+ ctx->raw_mantissa = av_calloc(channels, sizeof(*ctx->raw_mantissa));
21032111
21042112 ctx->larray = av_malloc_array(ctx->cur_frame_length * 4, sizeof(*ctx->larray));
21052113 ctx->nbits = av_malloc_array(ctx->cur_frame_length, sizeof(*ctx->nbits));
@@ -2116,7 +2124,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 10 unmodified lines
21162124 return ret;
21172125 ff_mlz_flush_dict(ctx->mlz);
21182126
2119− for (c = 0; c < avctx->channels; ++c) {
2127+ for (c = 0; c < channels; ++c) {
21202128 ctx->raw_mantissa[c] = av_calloc(ctx->cur_frame_length, sizeof(**ctx->raw_mantissa));
21212129 }
21222130 }
@@ -2125,8 +2133,8 @@ static av_cold int decode_init(AVCodecContext *avctx) · 2 unmodified lines
21252133
21262134 // allocate previous raw sample buffer
21272135 ctx->prev_raw_samples = av_malloc_array(sconf->max_order, sizeof(*ctx->prev_raw_samples));
2128− ctx->raw_buffer = av_calloc(avctx->channels * channel_size, sizeof(*ctx->raw_buffer));
2129− ctx->raw_samples = av_malloc_array(avctx->channels, sizeof(*ctx->raw_samples));
2136+ ctx->raw_buffer = av_calloc(channels * channel_size, sizeof(*ctx->raw_buffer));
2137+ ctx->raw_samples = av_malloc_array(channels, sizeof(*ctx->raw_samples));
21302138 if (!ctx->prev_raw_samples || !ctx->raw_buffer|| !ctx->raw_samples) {
21312139 av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
21322140 return AVERROR(ENOMEM);
@@ -2134,14 +2142,14 @@ static av_cold int decode_init(AVCodecContext *avctx) · 1 unmodified line
21342142
21352143 // assign raw samples buffers
21362144 ctx->raw_samples[0] = ctx->raw_buffer + sconf->max_order;
2137− for (c = 1; c < avctx->channels; c++)
2145+ for (c = 1; c < channels; c++)
21382146 ctx->raw_samples[c] = ctx->raw_samples[c - 1] + channel_size;
21392147
21402148 // allocate crc buffer
21412149 if (HAVE_BIGENDIAN != sconf->msb_first && sconf->crc_enabled &&
21422150 (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL))) {
21432151 ctx->crc_buffer = av_malloc_array(ctx->cur_frame_length *
2144− avctx->channels *
2152+ channels *
21452153 av_get_bytes_per_sample(avctx->sample_fmt),
21462154 sizeof(*ctx->crc_buffer));
21472155 if (!ctx->crc_buffer) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t