This patch contains the following commits:
libfdk-aac: convert to new channel layout API
8svx: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
adpcm: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
adx: convert to new channel layout API
alac: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
als: convert to new channel layout API
amrnbdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
amrwbdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
atrac1: convert to new channel layout API
atrac3: convert to new channel layout API
atrac3plus: convert to new channel layout API
apedec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
binkaudio: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
bmvaudio: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
cng: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
cook: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
dcadec: convert to new channel layout API
dpcm: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
dsicinav: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
dss_sp: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
flacdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
g722: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
g723_1: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
g726: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
gsmdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
imc: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
libdcadec: convert to new channel layout API
libilbcdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
libgsm: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
libopencore-amr: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
libopus: convert to new channel layout API
Drop the multiple validation steps for the decoding part.
Signed-off-by: Vittorio Giovara <***@gmail.com>
libspeexdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
mace: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
metasound: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
mlpdec: convert to new channel layout API
mpc7: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
mpc8: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
mpegaudiodec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
nellymoser: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
on2avc: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
opus: convert to new channel layout API
pafaudio: convert to new channel layout API
pcm: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
psymodel: convert to new channel layout API
qcelpdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
qdm2: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
ra144: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
ra288: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
ralf: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
roqaudioenc: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
s302m: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
shorten: convert to new channel layout API
sipr: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
smacker: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
takdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
truespeech: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
tta: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
twinvq: convert to new channel layout API
vima: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
vmdaudio: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
vorbis: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
wavpack: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
wma: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
wmaprodec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
wmalosslessdec: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
ws-snd1: convert to new channel layout API
Signed-off-by: Vittorio Giovara <***@gmail.com>
---
libavcodec/8svx.c | 15 +++---
libavcodec/adpcm.c | 57 +++++++++++-----------
libavcodec/adpcmenc.c | 92 +++++++++++++++++++-----------------
libavcodec/adx.c | 16 +++++--
libavcodec/adxdec.c | 6 +--
libavcodec/adxenc.c | 11 +++--
libavcodec/alac.c | 18 +++----
libavcodec/alac_data.c | 12 +++++
libavcodec/alac_data.h | 6 +++
libavcodec/alacenc.c | 20 +++++---
libavcodec/alsdec.c | 65 +++++++++++++++-----------
libavcodec/amrnbdec.c | 6 +--
libavcodec/amrwbdec.c | 6 +--
libavcodec/apedec.c | 9 ++--
libavcodec/atrac1.c | 10 ++--
libavcodec/atrac3.c | 26 ++++++-----
libavcodec/atrac3plusdec.c | 25 +++++-----
libavcodec/binkaudio.c | 17 +++----
libavcodec/bmvaudio.c | 4 +-
libavcodec/cngdec.c | 3 +-
libavcodec/cngenc.c | 6 +--
libavcodec/cook.c | 22 +++++----
libavcodec/cook_parser.c | 4 +-
libavcodec/dca.h | 2 +
libavcodec/dca_xll.c | 6 +--
libavcodec/dcadec.c | 54 +++++++++++++--------
libavcodec/dpcm.c | 14 +++---
libavcodec/dsicinaudio.c | 4 +-
libavcodec/dss_sp.c | 4 +-
libavcodec/flac.c | 37 ++++++++-------
libavcodec/flac.h | 2 +-
libavcodec/flac_parser.c | 7 +--
libavcodec/flacdec.c | 10 ++--
libavcodec/flacenc.c | 2 +-
libavcodec/g722dec.c | 4 +-
libavcodec/g722enc.c | 8 ++--
libavcodec/g723_1dec.c | 4 +-
libavcodec/g723_1enc.c | 8 ++--
libavcodec/g726.c | 6 +--
libavcodec/gsmdec.c | 4 +-
libavcodec/imc.c | 22 ++++-----
libavcodec/libdcadec.c | 6 +--
libavcodec/libfdk-aacdec.c | 32 ++++++++-----
libavcodec/libfdk-aacenc.c | 35 +++++++++++---
libavcodec/libgsmdec.c | 4 +-
libavcodec/libgsmenc.c | 4 +-
libavcodec/libilbc.c | 4 +-
libavcodec/libopencore-amr.c | 8 ++--
libavcodec/libopusdec.c | 42 +++++++----------
libavcodec/libopusenc.c | 32 +++++++------
libavcodec/libspeexdec.c | 18 +++----
libavcodec/mace.c | 11 +++--
libavcodec/metasound.c | 31 ++++++------
libavcodec/mlp_parser.c | 34 ++------------
libavcodec/mlp_parser.h | 4 +-
libavcodec/mlpdec.c | 96 ++++++++++++++++++++++----------------
libavcodec/mpc7.c | 7 +--
libavcodec/mpc8.c | 5 +-
libavcodec/mpegaudio_parser.c | 2 +-
libavcodec/mpegaudiodec_template.c | 37 ++++++++-------
libavcodec/mpegaudioenc.c | 11 ++++-
libavcodec/nellymoserdec.c | 4 +-
libavcodec/nellymoserenc.c | 6 +--
libavcodec/on2avc.c | 19 ++++----
libavcodec/opus.c | 16 ++++---
libavcodec/opusdec.c | 13 +++---
libavcodec/pafaudio.c | 5 +-
libavcodec/pcm-bluray.c | 36 +++++++-------
libavcodec/pcm-dvd.c | 24 ++++++----
libavcodec/pcm.c | 23 ++++-----
libavcodec/psymodel.c | 8 ++--
libavcodec/qcelpdec.c | 4 +-
libavcodec/qdm2.c | 6 +--
libavcodec/ra144dec.c | 4 +-
libavcodec/ra144enc.c | 6 +--
libavcodec/ra288.c | 4 +-
libavcodec/ralf.c | 16 +++----
libavcodec/roqaudioenc.c | 20 ++++----
libavcodec/s302m.c | 15 ++++--
libavcodec/shorten.c | 6 ++-
libavcodec/sipr.c | 4 +-
libavcodec/smacker.c | 11 +++--
libavcodec/takdec.c | 40 +++++++++-------
libavcodec/truespeech.c | 7 +--
libavcodec/tta.c | 15 ++++--
libavcodec/twinvq.c | 20 ++++----
libavcodec/twinvqdec.c | 18 +++----
libavcodec/vima.c | 5 +-
libavcodec/vmdaudio.c | 22 ++++-----
libavcodec/vorbis.h | 5 ++
libavcodec/vorbis_data.c | 18 +++++++
libavcodec/vorbisdec.c | 18 ++++---
libavcodec/vorbisenc.c | 4 +-
libavcodec/wavpack.c | 19 ++++----
libavcodec/wma.c | 13 +++---
libavcodec/wmadec.c | 25 +++++-----
libavcodec/wmaenc.c | 27 +++++------
libavcodec/wmalosslessdec.c | 36 ++++++--------
libavcodec/wmaprodec.c | 66 ++++++++++++--------------
libavcodec/wmavoice.c | 4 +-
libavcodec/ws-snd1.c | 4 +-
tests/fate/lossless-audio.mak | 2 +-
102 files changed, 915 insertions(+), 780 deletions(-)
diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c
index fe90b168e3..540e461d5a 100644
--- a/libavcodec/8svx.c
+++ b/libavcodec/8svx.c
@@ -85,6 +85,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
{
EightSvxContext *esc = avctx->priv_data;
AVFrame *frame = data;
+ int channels = avctx->ch_layout.nb_channels;
int buf_size;
int ch, ret;
int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR);
@@ -92,9 +93,9 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
/* for the first packet, copy data to buffer */
if (avpkt->data) {
int hdr_size = is_compr ? 2 : 0;
- int chan_size = (avpkt->size - hdr_size * avctx->channels) / avctx->channels;
+ int chan_size = (avpkt->size - hdr_size * channels) / channels;
- if (avpkt->size < hdr_size * avctx->channels) {
+ if (avpkt->size < hdr_size * channels) {
av_log(avctx, AV_LOG_ERROR, "packet size is too small\n");
return AVERROR_INVALIDDATA;
}
@@ -105,7 +106,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
if (is_compr) {
esc->fib_acc[0] = avpkt->data[1] + 128;
- if (avctx->channels == 2)
+ if (channels == 2)
esc->fib_acc[1] = avpkt->data[2+chan_size+1] + 128;
}
@@ -113,14 +114,14 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
esc->data_size = chan_size;
if (!(esc->data[0] = av_malloc(chan_size)))
return AVERROR(ENOMEM);
- if (avctx->channels == 2) {
+ if (channels == 2) {
if (!(esc->data[1] = av_malloc(chan_size))) {
av_freep(&esc->data[0]);
return AVERROR(ENOMEM);
}
}
memcpy(esc->data[0], &avpkt->data[hdr_size], chan_size);
- if (avctx->channels == 2)
+ if (channels == 2)
memcpy(esc->data[1], &avpkt->data[2*hdr_size+chan_size], chan_size);
}
if (!esc->data[0]) {
@@ -142,7 +143,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
return ret;
}
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (is_compr) {
delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx],
buf_size, &esc->fib_acc[ch], esc->table);
@@ -164,7 +165,7 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
{
EightSvxContext *esc = avctx->priv_data;
- if (avctx->channels < 1 || avctx->channels > 2) {
+ if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
av_log(avctx, AV_LOG_ERROR, "8SVX does not support more than 2 channels\n");
return AVERROR_INVALIDDATA;
}
diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c
index fe51c0d008..dd66de246c 100644
--- a/libavcodec/adpcm.c
+++ b/libavcodec/adpcm.c
@@ -107,7 +107,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx)
max_channels = 6;
break;
}
- if (avctx->channels < min_channels || avctx->channels > max_channels) {
+ if (avctx->ch_layout.nb_channels < min_channels ||
+ avctx->ch_layout.nb_channels > max_channels) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR(EINVAL);
}
@@ -369,6 +370,7 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_
ADPCMDecodeContext *c = avctx->priv_data;
BitstreamContext bc;
const int *table;
+ int channels = avctx->ch_layout.nb_channels;
int k0, signmask, nb_bits, count;
int size = buf_size*8;
int i;
@@ -381,17 +383,17 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_
k0 = 1 << (nb_bits-2);
signmask = 1 << (nb_bits-1);
- while (bitstream_tell(&bc) <= size - 22 * avctx->channels) {
- for (i = 0; i < avctx->channels; i++) {
+ while (bitstream_tell(&bc) <= size - 22 * channels) {
+ for (i = 0; i < channels; i++) {
*samples++ =
c->status[i].predictor = bitstream_read_signed(&bc, 16);
c->status[i].step_index = bitstream_read(&bc, 6);
}
- for (count = 0; bitstream_tell(&bc) <= size - nb_bits * avctx->channels && count < 4095; count++) {
+ for (count = 0; bitstream_tell(&bc) <= size - nb_bits * channels && count < 4095; count++) {
int i;
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
// similar to IMA adpcm
int delta = bitstream_read(&bc, nb_bits);
int step = ff_adpcm_step_table[c->status[i].step_index];
@@ -436,7 +438,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
{
ADPCMDecodeContext *s = avctx->priv_data;
int nb_samples = 0;
- int ch = avctx->channels;
+ int ch = avctx->ch_layout.nb_channels;
int has_coded_samples = 0;
int header_size;
@@ -594,6 +596,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
int buf_size = avpkt->size;
ADPCMDecodeContext *c = avctx->priv_data;
ADPCMChannelStatus *cs;
+ int channels = avctx->ch_layout.nb_channels;
int n, m, channel, i;
short *samples;
int16_t **samples_p;
@@ -626,13 +629,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
frame->nb_samples = nb_samples = coded_samples;
}
- st = avctx->channels == 2 ? 1 : 0;
+ st = channels == 2 ? 1 : 0;
switch(avctx->codec->id) {
case AV_CODEC_ID_ADPCM_IMA_QT:
/* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
Channel data is interleaved per-chunk. */
- for (channel = 0; channel < avctx->channels; channel++) {
+ for (channel = 0; channel < channels; channel++) {
int predictor;
int step_index;
cs = &(c->status[channel]);
@@ -671,7 +674,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
}
break;
case AV_CODEC_ID_ADPCM_IMA_WAV:
- for(i=0; i<avctx->channels; i++){
+ for (i = 0; i < channels; i++) {
cs = &(c->status[i]);
cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -684,7 +687,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
}
for (n = 0; n < (nb_samples - 1) / 8; n++) {
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
cs = &c->status[i];
samples = &samples_p[i][1 + n * 8];
for (m = 0; m < 8; m += 2) {
@@ -696,10 +699,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
}
break;
case AV_CODEC_ID_ADPCM_4XM:
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < channels; i++)
c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
if (c->status[i].step_index > 88u) {
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
@@ -708,7 +711,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
}
}
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
samples = (int16_t *)frame->data[i];
cs = &c->status[i];
for (n = nb_samples >> 1; n > 0; n--) {
@@ -762,7 +765,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
break;
}
case AV_CODEC_ID_ADPCM_IMA_DK4:
- for (channel = 0; channel < avctx->channels; channel++) {
+ for (channel = 0; channel < channels; channel++) {
cs = &c->status[channel];
cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -784,7 +787,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
int nibble;
int decode_top_nibble_next = 0;
int diff_channel;
- const int16_t *samples_end = samples + avctx->channels * nb_samples;
+ const int16_t *samples_end = samples + channels * nb_samples;
bytestream2_skipu(&gb, 10);
c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -840,7 +843,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
break;
}
case AV_CODEC_ID_ADPCM_IMA_ISS:
- for (channel = 0; channel < avctx->channels; channel++) {
+ for (channel = 0; channel < channels; channel++) {
cs = &c->status[channel];
cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -875,7 +878,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
break;
case AV_CODEC_ID_ADPCM_IMA_WS:
if (c->vqa_version == 3) {
- for (channel = 0; channel < avctx->channels; channel++) {
+ for (channel = 0; channel < channels; channel++) {
int16_t *smp = samples_p[channel];
for (n = nb_samples / 2; n > 0; n--) {
@@ -886,12 +889,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
}
} else {
for (n = nb_samples / 2; n > 0; n--) {
- for (channel = 0; channel < avctx->channels; channel++) {
+ for (channel = 0; channel < channels; channel++) {
int v = bytestream2_get_byteu(&gb);
*samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
}
- samples += avctx->channels;
+ samples += channels;
}
}
bytestream2_seek(&gb, 0, SEEK_END);
@@ -900,12 +903,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
{
int16_t *out0 = samples_p[0];
int16_t *out1 = samples_p[1];
- int samples_per_block = 28 * (3 - avctx->channels) * 4;
+ int samples_per_block = 28 * (3 - channels) * 4;
int sample_offset = 0;
while (bytestream2_get_bytes_left(&gb) >= 128) {
if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
&c->status[0], &c->status[1],
- avctx->channels, sample_offset)) < 0)
+ channels, sample_offset)) < 0)
return ret;
bytestream2_skipu(&gb, 128);
sample_offset += samples_per_block;
@@ -993,7 +996,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
{
int coeff[2][2], shift[2];
- for(channel = 0; channel < avctx->channels; channel++) {
+ for(channel = 0; channel < channels; channel++) {
int byte = bytestream2_get_byteu(&gb);
for (i=0; i<2; i++)
coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
@@ -1005,7 +1008,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
byte[0] = bytestream2_get_byteu(&gb);
if (st) byte[1] = bytestream2_get_byteu(&gb);
for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
- for(channel = 0; channel < avctx->channels; channel++) {
+ for(channel = 0; channel < channels; channel++) {
int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];
sample = (sample +
c->status[channel].sample1 * coeff[channel][0] +
@@ -1035,12 +1038,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
int count = 0;
int offsets[6];
- for (channel=0; channel<avctx->channels; channel++)
+ for (channel = 0; channel < channels; channel++)
offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
bytestream2_get_le32(&gb)) +
- (avctx->channels + 1) * 4;
+ (channels + 1) * 4;
- for (channel=0; channel<avctx->channels; channel++) {
+ for (channel = 0; channel < channels; channel++) {
bytestream2_seek(&gb, offsets[channel], SEEK_SET);
samplesC = samples_p[channel];
@@ -1101,7 +1104,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
break;
}
case AV_CODEC_ID_ADPCM_EA_XAS:
- for (channel=0; channel<avctx->channels; channel++) {
+ for (channel = 0; channel < channels; channel++) {
int coeff[2][4], shift[4];
int16_t *s = samples_p[channel];
for (n = 0; n < 4; n++, s += 32) {
diff --git a/libavcodec/adpcmenc.c b/libavcodec/adpcmenc.c
index 0757624aef..3acc35bbaa 100644
--- a/libavcodec/adpcmenc.c
+++ b/libavcodec/adpcmenc.c
@@ -64,11 +64,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
uint8_t *extradata;
int i;
int ret = AVERROR(ENOMEM);
-
- if (avctx->channels > 2) {
- av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n");
- return AVERROR(EINVAL);
- }
+ int channels = avctx->ch_layout.nb_channels;
if (avctx->trellis && (unsigned)avctx->trellis > 16U) {
av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n");
@@ -94,21 +90,21 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
case AV_CODEC_ID_ADPCM_IMA_WAV:
/* each 16 bits sample gives one nibble
and we have 4 bytes per channel overhead */
- avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 /
- (4 * avctx->channels) + 1;
+ avctx->frame_size = (BLKSIZE - 4 * channels) * 8 /
+ (4 * channels) + 1;
/* seems frame_size isn't taken into account...
have to buffer the samples :-( */
avctx->block_align = BLKSIZE;
break;
case AV_CODEC_ID_ADPCM_IMA_QT:
avctx->frame_size = 64;
- avctx->block_align = 34 * avctx->channels;
+ avctx->block_align = 34 * channels;
break;
case AV_CODEC_ID_ADPCM_MS:
/* each 16 bits sample gives one nibble
and we have 7 bytes per channel overhead */
- avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 /
- avctx->channels + 2;
+ avctx->frame_size = (BLKSIZE - 7 * channels) * 2 /
+ channels + 2;
avctx->block_align = BLKSIZE;
if (!(avctx->extradata = av_malloc(32 + AV_INPUT_BUFFER_PADDING_SIZE)))
goto error;
@@ -122,7 +118,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx)
}
break;
case AV_CODEC_ID_ADPCM_YAMAHA:
- avctx->frame_size = BLKSIZE * 2 / avctx->channels;
+ avctx->frame_size = BLKSIZE * 2 / channels;
avctx->block_align = BLKSIZE;
break;
case AV_CODEC_ID_ADPCM_SWF:
@@ -474,13 +470,14 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
uint8_t *dst;
ADPCMEncodeContext *c = avctx->priv_data;
uint8_t *buf;
+ int channels = avctx->ch_layout.nb_channels;
samples = (const int16_t *)frame->data[0];
samples_p = (int16_t **)frame->extended_data;
- st = avctx->channels == 2;
+ st = channels == 2;
if (avctx->codec_id == AV_CODEC_ID_ADPCM_SWF)
- pkt_size = (2 + avctx->channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8;
+ pkt_size = (2 + channels * (22 + 4 * (frame->nb_samples - 1)) + 7) / 8;
else
pkt_size = avctx->block_align;
if ((ret = ff_alloc_packet(avpkt, pkt_size))) {
@@ -496,7 +493,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
blocks = (frame->nb_samples - 1) / 8;
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
ADPCMChannelStatus *status = &c->status[ch];
status->prev_sample = samples_p[ch][0];
/* status->step_index = 0;
@@ -508,14 +505,14 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
/* stereo: 4 bytes (8 samples) for left, 4 bytes for right */
if (avctx->trellis > 0) {
- FF_ALLOC_OR_GOTO(avctx, buf, avctx->channels * blocks * 8, error);
- for (ch = 0; ch < avctx->channels; ch++) {
+ FF_ALLOC_OR_GOTO(avctx, buf, channels * blocks * 8, error);
+ for (ch = 0; ch < channels; ch++) {
adpcm_compress_trellis(avctx, &samples_p[ch][1],
buf + ch * blocks * 8, &c->status[ch],
blocks * 8, 1);
}
for (i = 0; i < blocks; i++) {
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
uint8_t *buf1 = buf + ch * blocks * 8 + i * 8;
for (j = 0; j < 8; j += 2)
*dst++ = buf1[j] | (buf1[j + 1] << 4);
@@ -524,7 +521,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
av_free(buf);
} else {
for (i = 0; i < blocks; i++) {
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
ADPCMChannelStatus *status = &c->status[ch];
const int16_t *smp = &samples_p[ch][1 + i * 8];
for (j = 0; j < 8; j += 2) {
@@ -542,7 +539,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
PutBitContext pb;
init_put_bits(&pb, dst, pkt_size * 8);
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
ADPCMChannelStatus *status = &c->status[ch];
put_bits(&pb, 9, (status->prev_sample & 0xFFFF) >> 7);
put_bits(&pb, 7, status->step_index);
@@ -578,7 +575,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
put_bits(&pb, 2, 2); // set 4-bit flash adpcm format
// init the encoder state
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
// clip step so it fits 6 bits
c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63);
put_sbits(&pb, 16, samples[i]);
@@ -588,23 +585,23 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (avctx->trellis > 0) {
FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error);
- adpcm_compress_trellis(avctx, samples + avctx->channels, buf,
- &c->status[0], n, avctx->channels);
- if (avctx->channels == 2)
- adpcm_compress_trellis(avctx, samples + avctx->channels + 1,
+ adpcm_compress_trellis(avctx, samples + channels, buf,
+ &c->status[0], n, channels);
+ if (channels == 2)
+ adpcm_compress_trellis(avctx, samples + channels + 1,
buf + n, &c->status[1], n,
- avctx->channels);
+ channels);
for (i = 0; i < n; i++) {
put_bits(&pb, 4, buf[i]);
- if (avctx->channels == 2)
+ if (channels == 2)
put_bits(&pb, 4, buf[n + i]);
}
av_free(buf);
} else {
for (i = 1; i < frame->nb_samples; i++) {
put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0],
- samples[avctx->channels * i]));
- if (avctx->channels == 2)
+ samples[channels * i]));
+ if (channels == 2)
put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1],
samples[2 * i + 1]));
}
@@ -613,45 +610,45 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
break;
}
case AV_CODEC_ID_ADPCM_MS:
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
int predictor = 0;
*dst++ = predictor;
c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor];
c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor];
}
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
if (c->status[i].idelta < 16)
c->status[i].idelta = 16;
bytestream_put_le16(&dst, c->status[i].idelta);
}
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < channels; i++)
c->status[i].sample2= *samples++;
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
c->status[i].sample1 = *samples++;
bytestream_put_le16(&dst, c->status[i].sample1);
}
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < channels; i++)
bytestream_put_le16(&dst, c->status[i].sample2);
if (avctx->trellis > 0) {
- n = avctx->block_align - 7 * avctx->channels;
+ n = avctx->block_align - 7 * channels;
FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error);
- if (avctx->channels == 1) {
+ if (channels == 1) {
adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
- avctx->channels);
+ channels);
for (i = 0; i < n; i += 2)
*dst++ = (buf[i] << 4) | buf[i + 1];
} else {
adpcm_compress_trellis(avctx, samples, buf,
- &c->status[0], n, avctx->channels);
+ &c->status[0], n, channels);
adpcm_compress_trellis(avctx, samples + 1, buf + n,
- &c->status[1], n, avctx->channels);
+ &c->status[1], n, channels);
for (i = 0; i < n; i++)
*dst++ = (buf[i] << 4) | buf[n + i];
}
av_free(buf);
} else {
- for (i = 7 * avctx->channels; i < avctx->block_align; i++) {
+ for (i = 7 * channels; i < avctx->block_align; i++) {
int nibble;
nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++) << 4;
nibble |= adpcm_ms_compress_sample(&c->status[st], *samples++);
@@ -664,22 +661,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
if (avctx->trellis > 0) {
FF_ALLOC_OR_GOTO(avctx, buf, 2 * n * 2, error);
n *= 2;
- if (avctx->channels == 1) {
+ if (channels == 1) {
adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
- avctx->channels);
+ channels);
for (i = 0; i < n; i += 2)
*dst++ = buf[i] | (buf[i + 1] << 4);
} else {
adpcm_compress_trellis(avctx, samples, buf,
- &c->status[0], n, avctx->channels);
+ &c->status[0], n, channels);
adpcm_compress_trellis(avctx, samples + 1, buf + n,
- &c->status[1], n, avctx->channels);
+ &c->status[1], n, channels);
for (i = 0; i < n; i++)
*dst++ = buf[i] | (buf[n + i] << 4);
}
av_free(buf);
} else
- for (n *= avctx->channels; n > 0; n--) {
+ for (n *= channels; n > 0; n--) {
int nibble;
nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++);
nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4;
@@ -705,6 +702,12 @@ static const enum AVSampleFormat sample_fmts_p[] = {
AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE
};
+static const AVChannelLayout ch_layouts[] = {
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ { 0 },
+};
+
#define ADPCM_ENCODER(id_, name_, sample_fmts_, long_name_) \
AVCodec ff_ ## name_ ## _encoder = { \
.name = #name_, \
@@ -716,6 +719,7 @@ AVCodec ff_ ## name_ ## _encoder = { \
.encode2 = adpcm_encode_frame, \
.close = adpcm_encode_close, \
.sample_fmts = sample_fmts_, \
+ .ch_layouts = ch_layouts, \
}
ADPCM_ENCODER(AV_CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, sample_fmts_p, "ADPCM IMA QuickTime");
diff --git a/libavcodec/adx.c b/libavcodec/adx.c
index d941d7b89c..4042d10343 100644
--- a/libavcodec/adx.c
+++ b/libavcodec/adx.c
@@ -38,7 +38,7 @@ void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff)
int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
int bufsize, int *header_size, int *coeff)
{
- int offset, cutoff;
+ int offset, cutoff, channels;
if (bufsize < 24)
return AVERROR_INVALIDDATA;
@@ -58,18 +58,24 @@ int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf,
}
/* channels */
- avctx->channels = buf[7];
- if (avctx->channels <= 0 || avctx->channels > 2)
+ channels = buf[7];
+ if (channels <= 0 || channels > 2)
return AVERROR_INVALIDDATA;
+ if (avctx->ch_layout.nb_channels != channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ avctx->ch_layout.nb_channels = channels;
+ }
+
/* sample rate */
avctx->sample_rate = AV_RB32(buf + 8);
if (avctx->sample_rate < 1 ||
- avctx->sample_rate > INT_MAX / (avctx->channels * BLOCK_SIZE * 8))
+ avctx->sample_rate > INT_MAX / (channels * BLOCK_SIZE * 8))
return AVERROR_INVALIDDATA;
/* bit rate */
- avctx->bit_rate = avctx->sample_rate * avctx->channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
+ avctx->bit_rate = avctx->sample_rate * channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES;
/* LPC coefficients */
if (coeff) {
diff --git a/libavcodec/adxdec.c b/libavcodec/adxdec.c
index 86aaade846..9ab1314e17 100644
--- a/libavcodec/adxdec.c
+++ b/libavcodec/adxdec.c
@@ -47,7 +47,7 @@ static av_cold int adx_decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
return AVERROR_INVALIDDATA;
}
- c->channels = avctx->channels;
+ c->channels = avctx->ch_layout.nb_channels;
c->header_parsed = 1;
}
@@ -116,7 +116,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n");
return AVERROR_INVALIDDATA;
}
- c->channels = avctx->channels;
+ c->channels = avctx->ch_layout.nb_channels;
c->header_parsed = 1;
if (buf_size < header_size)
return AVERROR_INVALIDDATA;
@@ -131,7 +131,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data,
/* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF
packet */
- if (!num_blocks || buf_size % (BLOCK_SIZE * avctx->channels)) {
+ if (!num_blocks || buf_size % (BLOCK_SIZE * c->channels)) {
if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) {
c->eof = 1;
*got_frame_ptr = 0;
diff --git a/libavcodec/adxenc.c b/libavcodec/adxenc.c
index e730811744..a822b7b6f1 100644
--- a/libavcodec/adxenc.c
+++ b/libavcodec/adxenc.c
@@ -93,7 +93,7 @@ static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize)
bytestream_put_byte(&buf, 3); /* encoding */
bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */
bytestream_put_byte(&buf, 4); /* sample size */
- bytestream_put_byte(&buf, avctx->channels); /* channels */
+ bytestream_put_byte(&buf, avctx->ch_layout.nb_channels); /* channels */
bytestream_put_be32(&buf, avctx->sample_rate); /* sample rate */
bytestream_put_be32(&buf, 0); /* total sample count */
bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */
@@ -111,7 +111,7 @@ static av_cold int adx_encode_init(AVCodecContext *avctx)
{
ADXContext *c = avctx->priv_data;
- if (avctx->channels > 2) {
+ if (avctx->ch_layout.nb_channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR(EINVAL);
}
@@ -130,9 +130,10 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
ADXContext *c = avctx->priv_data;
const int16_t *samples = (const int16_t *)frame->data[0];
uint8_t *dst;
+ int channels = avctx->ch_layout.nb_channels;
int ch, out_size, ret;
- out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE;
+ out_size = BLOCK_SIZE * channels + !c->header_parsed * HEADER_SIZE;
if ((ret = ff_alloc_packet(avpkt, out_size)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
return ret;
@@ -149,8 +150,8 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
c->header_parsed = 1;
}
- for (ch = 0; ch < avctx->channels; ch++) {
- adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels);
+ for (ch = 0; ch < channels; ch++) {
+ adx_encode(c, dst, samples + ch, &c->prev[ch], channels);
dst += BLOCK_SIZE;
}
diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 0f1c59e486..c6466bcf47 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -559,21 +559,17 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
}
avctx->bits_per_raw_sample = alac->sample_size;
- if (alac->channels < 1) {
+ if (alac->channels < 1 || alac->channels > ALAC_MAX_CHANNELS) {
av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
- alac->channels = avctx->channels;
- } else {
- if (alac->channels > ALAC_MAX_CHANNELS)
- alac->channels = avctx->channels;
- else
- avctx->channels = alac->channels;
+ alac->channels = avctx->ch_layout.nb_channels;
}
- if (avctx->channels > ALAC_MAX_CHANNELS) {
- avpriv_report_missing_feature(avctx, "Channel count %d",
- avctx->channels);
+ if (alac->channels > ALAC_MAX_CHANNELS) {
+ av_log(avctx, AV_LOG_ERROR, "Unsupported channel count: %d\n",
+ alac->channels);
return AVERROR_PATCHWELCOME;
}
- avctx->channel_layout = ff_alac_channel_layouts[alac->channels - 1];
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = ff_alac_ch_layouts[alac->channels - 1];
if ((ret = allocate_buffers(alac)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");
diff --git a/libavcodec/alac_data.c b/libavcodec/alac_data.c
index 9e131199b1..542768b01b 100644
--- a/libavcodec/alac_data.c
+++ b/libavcodec/alac_data.c
@@ -44,6 +44,18 @@ const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = {
0
};
+const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1] = {
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ AV_CHANNEL_LAYOUT_SURROUND,
+ AV_CHANNEL_LAYOUT_4POINT0,
+ AV_CHANNEL_LAYOUT_5POINT0_BACK,
+ AV_CHANNEL_LAYOUT_5POINT1_BACK,
+ AV_CHANNEL_LAYOUT_6POINT1_BACK,
+ AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
+ { 0 }
+};
+
const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5] = {
{ TYPE_SCE, },
{ TYPE_CPE, },
diff --git a/libavcodec/alac_data.h b/libavcodec/alac_data.h
index ebb1f33a93..9e354091c2 100644
--- a/libavcodec/alac_data.h
+++ b/libavcodec/alac_data.h
@@ -23,6 +23,8 @@
#include <stdint.h>
+#include "libavutil/channel_layout.h"
+
enum AlacRawDataBlockType {
/* At the moment, only SCE, CPE, LFE, and END are recognized. */
TYPE_SCE,
@@ -39,7 +41,11 @@ enum AlacRawDataBlockType {
extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS];
+extern const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1];
+
+#if FF_API_OLD_CHANNEL_LAYOUT
extern const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1];
+#endif
extern const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5];
diff --git a/libavcodec/alacenc.c b/libavcodec/alacenc.c
index d921fa124c..0d0ba66d16 100644
--- a/libavcodec/alacenc.c
+++ b/libavcodec/alacenc.c
@@ -447,14 +447,15 @@ static int write_frame(AlacEncodeContext *s, AVPacket *avpkt,
uint8_t * const *samples)
{
PutBitContext *pb = &s->pbctx;
- const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[s->avctx->channels - 1];
- const uint8_t *ch_map = ff_alac_channel_layout_offsets[s->avctx->channels - 1];
+ int channels = s->avctx->ch_layout.nb_channels;
+ const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[channels - 1];
+ const uint8_t *ch_map = ff_alac_channel_layout_offsets[channels - 1];
int ch, element, sce, cpe;
init_put_bits(pb, avpkt->data, avpkt->size);
ch = element = sce = cpe = 0;
- while (ch < s->avctx->channels) {
+ while (ch < channels) {
if (ch_elements[element] == TYPE_CPE) {
write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]],
samples[ch_map[ch + 1]]);
@@ -519,7 +520,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
s->rc.rice_modifier = 4;
s->max_coded_frame_size = get_max_frame_size(avctx->frame_size,
- avctx->channels,
+ avctx->ch_layout.nb_channels,
avctx->bits_per_raw_sample);
avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
@@ -534,10 +535,10 @@ static av_cold int alac_encode_init(AVCodecContext *avctx)
AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c'));
AV_WB32(alac_extradata+12, avctx->frame_size);
AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample);
- AV_WB8 (alac_extradata+21, avctx->channels);
+ AV_WB8 (alac_extradata+21, avctx->ch_layout.nb_channels);
AV_WB32(alac_extradata+24, s->max_coded_frame_size);
AV_WB32(alac_extradata+28,
- avctx->sample_rate * avctx->channels * avctx->bits_per_raw_sample); // average bitrate
+ avctx->sample_rate * avctx->ch_layout.nb_channels * avctx->bits_per_raw_sample); // average bitrate
AV_WB32(alac_extradata+32, avctx->sample_rate);
// Set relevant extradata fields
@@ -606,7 +607,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
s->frame_size = frame->nb_samples;
if (frame->nb_samples < DEFAULT_FRAME_SIZE)
- max_frame_size = get_max_frame_size(s->frame_size, avctx->channels,
+ max_frame_size = get_max_frame_size(s->frame_size, avctx->ch_layout.nb_channels,
avctx->bits_per_raw_sample);
else
max_frame_size = s->max_coded_frame_size;
@@ -666,7 +667,12 @@ AVCodec ff_alac_encoder = {
.encode2 = alac_encode_frame,
.close = alac_encode_close,
.capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME,
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
.channel_layouts = ff_alac_channel_layouts,
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ .ch_layouts = ff_alac_ch_layouts,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
AV_SAMPLE_FMT_S16P,
AV_SAMPLE_FMT_NONE },
diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c
index 5f09a9d4b9..1e8440b8af 100644
--- a/libavcodec/alsdec.c
+++ b/libavcodec/alsdec.c
@@ -307,7 +307,13 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
avctx->sample_rate = m4ac.sample_rate;
bitstream_skip(&bc, 32); // sample rate already known
sconf->samples = bitstream_read(&bc, 32);
- avctx->channels = m4ac.channels;
+
+ if (avctx->ch_layout.nb_channels != m4ac.channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ avctx->ch_layout.nb_channels = m4ac.channels;
+ }
+
bitstream_skip(&bc, 16); // number of channels already known
bitstream_skip(&bc, 3); // skip file_type
sconf->resolution = bitstream_read(&bc, 3);
@@ -342,20 +348,20 @@ static av_cold int read_specific_config(ALSDecContext *ctx)
// read channel config
if (sconf->chan_config)
sconf->chan_config_info = bitstream_read(&bc, 16);
- // TODO: use this to set avctx->channel_layout
+ // TODO: use this to set avctx->ch_layout
// read channel sorting
- if (sconf->chan_sort && avctx->channels > 1) {
- int chan_pos_bits = av_ceil_log2(avctx->channels);
- int bits_needed = avctx->channels * chan_pos_bits + 7;
+ if (sconf->chan_sort && m4ac.channels > 1) {
+ int chan_pos_bits = av_ceil_log2(m4ac.channels);
+ int bits_needed = m4ac.channels * chan_pos_bits + 7;
if (bitstream_bits_left(&bc) < bits_needed)
return AVERROR_INVALIDDATA;
- if (!(sconf->chan_pos = av_malloc(avctx->channels * sizeof(*sconf->chan_pos))))
+ if (!(sconf->chan_pos = av_malloc(m4ac.channels * sizeof(*sconf->chan_pos))))
return AVERROR(ENOMEM);
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < m4ac.channels; i++)
sconf->chan_pos[i] = bitstream_read(&bc, chan_pos_bits);
bitstream_align(&bc);
@@ -1176,7 +1182,7 @@ static int read_channel_data(ALSDecContext *ctx, ALSChannelData *cd, int c)
{
BitstreamContext *bc = &ctx->bc;
ALSChannelData *current = cd;
- unsigned int channels = ctx->avctx->channels;
+ unsigned int channels = ctx->avctx->ch_layout.nb_channels;
int entries = 0;
while (entries < channels && !(current->stop_flag = bitstream_read_bit(bc))) {
@@ -1225,7 +1231,7 @@ static int revert_channel_correlation(ALSDecContext *ctx, ALSBlockData *bd,
{
ALSChannelData *ch = cd[c];
unsigned int dep = 0;
- unsigned int channels = ctx->avctx->channels;
+ unsigned int channels = ctx->avctx->ch_layout.nb_channels;
unsigned int channel_size = ctx->sconf.frame_length + ctx->sconf.max_order;
if (reverted[c])
@@ -1332,6 +1338,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
unsigned int div_blocks[32]; ///< block sizes.
unsigned int c;
unsigned int js_blocks[2];
+ int channels = avctx->ch_layout.nb_channels;
uint32_t bs_info = 0;
int ret;
@@ -1347,7 +1354,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
if (!sconf->mc_coding || ctx->js_switch) {
int independent_bs = !sconf->joint_stereo;
- for (c = 0; c < avctx->channels; c++) {
+ for (c = 0; c < channels; c++) {
js_blocks[0] = 0;
js_blocks[1] = 0;
@@ -1360,7 +1367,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
independent_bs = 2;
// if this is the last channel, it has to be decoded independently
- if (c == avctx->channels - 1)
+ if (c == channels - 1)
independent_bs = 1;
if (independent_bs) {
@@ -1388,13 +1395,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
int *reverted_channels = ctx->reverted_channels;
unsigned int offset = 0;
- for (c = 0; c < avctx->channels; c++)
+ for (c = 0; c < channels; c++)
if (ctx->chan_data[c] < ctx->chan_data_buffer) {
av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data!\n");
return AVERROR_INVALIDDATA;
}
- memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);
+ memset(reverted_channels, 0, sizeof(*reverted_channels) * channels);
bd.ra_block = ra_frame;
bd.prev_raw_samples = ctx->prev_raw_samples;
@@ -1410,7 +1417,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
continue;
}
- for (c = 0; c < avctx->channels; c++) {
+ for (c = 0; c < channels; c++) {
bd.const_block = ctx->const_block + c;
bd.shift_lsbs = ctx->shift_lsbs + c;
bd.opt_order = ctx->opt_order + c;
@@ -1429,13 +1436,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
return ret;
}
- for (c = 0; c < avctx->channels; c++) {
+ for (c = 0; c < channels; c++) {
ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,
reverted_channels, offset, c);
if (ret < 0)
return ret;
}
- for (c = 0; c < avctx->channels; c++) {
+ for (c = 0; c < channels; c++) {
bd.const_block = ctx->const_block + c;
bd.shift_lsbs = ctx->shift_lsbs + c;
bd.opt_order = ctx->opt_order + c;
@@ -1450,13 +1457,13 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)
return ret;
}
- memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));
+ memset(reverted_channels, 0, channels * sizeof(*reverted_channels));
offset += div_blocks[b];
bd.ra_block = 0;
}
// store carryover raw samples
- for (c = 0; c < avctx->channels; c++)
+ for (c = 0; c < channels; c++)
memmove(ctx->raw_samples[c] - sconf->max_order,
ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,
sizeof(*ctx->raw_samples[c]) * sconf->max_order);
@@ -1479,6 +1486,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
const uint8_t *buffer = avpkt->data;
int buffer_size = avpkt->size;
int invalid_frame, ret;
+ int channels = avctx->ch_layout.nb_channels;
unsigned int c, sample, ra_frame, bytes_read, shift;
bitstream_init8(&ctx->bc, buffer, buffer_size);
@@ -1516,7 +1524,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
int##bps##_t *dest = (int##bps##_t*)frame->data[0]; \
shift = bps - ctx->avctx->bits_per_raw_sample; \
for (sample = 0; sample < ctx->cur_frame_length; sample++) \
- for (c = 0; c < avctx->channels; c++) \
+ for (c = 0; c < channels; c++) \
*dest++ = ctx->raw_samples[c][sample] << shift; \
}
@@ -1534,7 +1542,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
int32_t *src = (int32_t *)frame->data[0];
for (sample = 0;
- sample < ctx->cur_frame_length * avctx->channels;
+ sample < ctx->cur_frame_length * channels;
sample++) {
int32_t v;
@@ -1555,13 +1563,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
int16_t *src = (int16_t*) frame->data[0];
int16_t *dest = (int16_t*) ctx->crc_buffer;
for (sample = 0;
- sample < ctx->cur_frame_length * avctx->channels;
+ sample < ctx->cur_frame_length * channels;
sample++)
*dest++ = av_bswap16(src[sample]);
} else {
ctx->bdsp.bswap_buf((uint32_t *) ctx->crc_buffer,
(uint32_t *) frame->data[0],
- ctx->cur_frame_length * avctx->channels);
+ ctx->cur_frame_length * channels);
}
crc_source = ctx->crc_buffer;
} else {
@@ -1569,7 +1577,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
}
ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source,
- ctx->cur_frame_length * avctx->channels *
+ ctx->cur_frame_length * channels *
av_get_bytes_per_sample(avctx->sample_fmt));
}
@@ -1634,6 +1642,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
unsigned int c;
unsigned int channel_size;
int num_buffers, ret;
+ int channels = avctx->ch_layout.nb_channels;
ALSDecContext *ctx = avctx->priv_data;
ALSSpecificConfig *sconf = &ctx->sconf;
ctx->avctx = avctx;
@@ -1682,7 +1691,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
(avctx->sample_rate >= 192000);
// allocate quantized parcor coefficient buffer
- num_buffers = sconf->mc_coding ? avctx->channels : 1;
+ num_buffers = sconf->mc_coding ? channels : 1;
ctx->quant_cof = av_malloc(sizeof(*ctx->quant_cof) * num_buffers);
ctx->lpc_cof = av_malloc(sizeof(*ctx->lpc_cof) * num_buffers);
@@ -1756,8 +1765,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
channel_size = sconf->frame_length + sconf->max_order;
ctx->prev_raw_samples = av_malloc (sizeof(*ctx->prev_raw_samples) * sconf->max_order);
- ctx->raw_buffer = av_mallocz(sizeof(*ctx-> raw_buffer) * avctx->channels * channel_size);
- ctx->raw_samples = av_malloc (sizeof(*ctx-> raw_samples) * avctx->channels);
+ ctx->raw_buffer = av_mallocz(sizeof(*ctx-> raw_buffer) * channels * channel_size);
+ ctx->raw_samples = av_malloc (sizeof(*ctx-> raw_samples) * channels);
// allocate previous raw sample buffer
if (!ctx->prev_raw_samples || !ctx->raw_buffer|| !ctx->raw_samples) {
@@ -1768,7 +1777,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
// assign raw samples buffers
ctx->raw_samples[0] = ctx->raw_buffer + sconf->max_order;
- for (c = 1; c < avctx->channels; c++)
+ for (c = 1; c < channels; c++)
ctx->raw_samples[c] = ctx->raw_samples[c - 1] + channel_size;
// allocate crc buffer
@@ -1776,7 +1785,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
(avctx->err_recognition & AV_EF_CRCCHECK)) {
ctx->crc_buffer = av_malloc(sizeof(*ctx->crc_buffer) *
ctx->cur_frame_length *
- avctx->channels *
+ channels *
av_get_bytes_per_sample(avctx->sample_fmt));
if (!ctx->crc_buffer) {
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
diff --git a/libavcodec/amrnbdec.c b/libavcodec/amrnbdec.c
index e2b5641c23..cf5ca0073a 100644
--- a/libavcodec/amrnbdec.c
+++ b/libavcodec/amrnbdec.c
@@ -155,13 +155,13 @@ static av_cold int amrnb_decode_init(AVCodecContext *avctx)
AMRContext *p = avctx->priv_data;
int i;
- if (avctx->channels > 1) {
+ if (avctx->ch_layout.nb_channels > 1) {
avpriv_report_missing_feature(avctx, "multi-channel AMR");
return AVERROR_PATCHWELCOME;
}
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
diff --git a/libavcodec/amrwbdec.c b/libavcodec/amrwbdec.c
index f1fbcc09ea..586be847c6 100644
--- a/libavcodec/amrwbdec.c
+++ b/libavcodec/amrwbdec.c
@@ -91,13 +91,13 @@ static av_cold int amrwb_decode_init(AVCodecContext *avctx)
AMRWBContext *ctx = avctx->priv_data;
int i;
- if (avctx->channels > 1) {
+ if (avctx->ch_layout.nb_channels > 1) {
avpriv_report_missing_feature(avctx, "multi-channel AMR");
return AVERROR_PATCHWELCOME;
}
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_rate = 16000;
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index da45e85e51..96f3154c5a 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -229,13 +229,14 @@ static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, const int16_t *v2,
static av_cold int ape_decode_init(AVCodecContext *avctx)
{
APEContext *s = avctx->priv_data;
+ int channels = avctx->ch_layout.nb_channels;
int i;
if (avctx->extradata_size != 6) {
av_log(avctx, AV_LOG_ERROR, "Incorrect extradata\n");
return AVERROR(EINVAL);
}
- if (avctx->channels > 2) {
+ if (channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo is supported\n");
return AVERROR(EINVAL);
}
@@ -256,7 +257,7 @@ static av_cold int ape_decode_init(AVCodecContext *avctx)
return AVERROR_PATCHWELCOME;
}
s->avctx = avctx;
- s->channels = avctx->channels;
+ s->channels = channels;
s->fileversion = AV_RL16(avctx->extradata);
s->compression_level = AV_RL16(avctx->extradata + 2);
s->flags = AV_RL16(avctx->extradata + 4);
@@ -316,7 +317,9 @@ static av_cold int ape_decode_init(AVCodecContext *avctx)
ff_apedsp_init_x86(&s->adsp);
ff_bswapdsp_init(&s->bdsp);
- avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
return 0;
filter_alloc_fail:
diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c
index 52d43e2c94..fa56b7578e 100644
--- a/libavcodec/atrac1.c
+++ b/libavcodec/atrac1.c
@@ -278,11 +278,12 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
AT1Ctx *q = avctx->priv_data;
+ int channels = avctx->ch_layout.nb_channels;
int ch, ret;
BitstreamContext bc;
- if (buf_size < 212 * avctx->channels) {
+ if (buf_size < 212 * channels) {
av_log(avctx, AV_LOG_ERROR, "Not enough data to decode!\n");
return AVERROR_INVALIDDATA;
}
@@ -294,7 +295,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
return ret;
}
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
AT1SUCtx* su = &q->SUs[ch];
bitstream_init8(&bc, &buf[212 * ch], 212);
@@ -335,13 +336,14 @@ static av_cold int atrac1_decode_end(AVCodecContext * avctx)
static av_cold int atrac1_decode_init(AVCodecContext *avctx)
{
AT1Ctx *q = avctx->priv_data;
+ int channels = avctx->ch_layout.nb_channels;
int ret;
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
- if (avctx->channels < 1 || avctx->channels > AT1_MAX_CHANNELS) {
+ if (channels < 1 || channels > AT1_MAX_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n",
- avctx->channels);
+ channels);
return AVERROR(EINVAL);
}
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index d0661c83fc..5b15bf833e 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -642,6 +642,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
ATRAC3Context *q = avctx->priv_data;
int ret, i;
uint8_t *ptr1;
+ int channels = avctx->ch_layout.nb_channels;
if (q->coding_mode == JOINT_STEREO) {
/* channel coupling mode */
@@ -704,11 +705,11 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
} else {
/* normal stereo mode or mono */
/* Decode the channel sound units. */
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
/* Set the bitstream reader at the start of a channel sound unit. */
bitstream_init8(&q->bc,
- databuf + i * avctx->block_align / avctx->channels,
- avctx->block_align / avctx->channels);
+ databuf + i * avctx->block_align / channels,
+ avctx->block_align / channels);
ret = decode_channel_sound_unit(q, &q->bc, &q->units[i],
out_samples[i], i, q->coding_mode);
@@ -718,7 +719,7 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf,
}
/* Apply the iQMF synthesis filter. */
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
float *p1 = out_samples[i];
float *p2 = p1 + 256;
float *p3 = p2 + 256;
@@ -797,8 +798,9 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
int version, delay, samples_per_frame, frame_factor;
const uint8_t *edata_ptr = avctx->extradata;
ATRAC3Context *q = avctx->priv_data;
+ int channels = avctx->ch_layout.nb_channels;
- if (avctx->channels <= 0 || avctx->channels > 2) {
+ if (channels <= 0 || channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n");
return AVERROR(EINVAL);
}
@@ -817,18 +819,18 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
bytestream_get_le16(&edata_ptr)); // Unknown always 0
/* setup */
- samples_per_frame = SAMPLES_PER_FRAME * avctx->channels;
+ samples_per_frame = SAMPLES_PER_FRAME * channels;
version = 4;
delay = 0x88E;
q->coding_mode = q->coding_mode ? JOINT_STEREO : STEREO;
q->scrambled_stream = 0;
- if (avctx->block_align != 96 * avctx->channels * frame_factor &&
- avctx->block_align != 152 * avctx->channels * frame_factor &&
- avctx->block_align != 192 * avctx->channels * frame_factor) {
+ if (avctx->block_align != 96 * channels * frame_factor &&
+ avctx->block_align != 152 * channels * frame_factor &&
+ avctx->block_align != 192 * channels * frame_factor) {
av_log(avctx, AV_LOG_ERROR, "Unknown frame/channel/frame_factor "
"configuration %d/%d/%d\n", avctx->block_align,
- avctx->channels, frame_factor);
+ channels, frame_factor);
return AVERROR_INVALIDDATA;
}
} else if (avctx->extradata_size == 10) {
@@ -868,7 +870,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
if (q->coding_mode == STEREO)
av_log(avctx, AV_LOG_DEBUG, "Normal stereo detected.\n");
else if (q->coding_mode == JOINT_STEREO) {
- if (avctx->channels != 2)
+ if (channels != 2)
return AVERROR_INVALIDDATA;
av_log(avctx, AV_LOG_DEBUG, "Joint stereo detected.\n");
} else {
@@ -911,7 +913,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx)
ff_atrac_init_gain_compensation(&q->gainc_ctx, 4, 3);
avpriv_float_dsp_init(&q->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
- q->units = av_mallocz(sizeof(*q->units) * avctx->channels);
+ q->units = av_mallocz(sizeof(*q->units) * channels);
if (!q->units) {
atrac3_decode_close(avctx);
return AVERROR(ENOMEM);
diff --git a/libavcodec/atrac3plusdec.c b/libavcodec/atrac3plusdec.c
index 17774d5657..9a3941a582 100644
--- a/libavcodec/atrac3plusdec.c
+++ b/libavcodec/atrac3plusdec.c
@@ -63,7 +63,6 @@ typedef struct ATRAC3PContext {
int num_channel_blocks; ///< number of channel blocks
uint8_t channel_blocks[5]; ///< channel configuration descriptor
- uint64_t my_channel_layout; ///< current channel layout
} ATRAC3PContext;
static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
@@ -76,36 +75,36 @@ static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
static av_cold int set_channel_params(ATRAC3PContext *ctx,
AVCodecContext *avctx)
{
+ int channels = avctx->ch_layout.nb_channels;
memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
- switch (avctx->channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ switch (channels) {
case 1:
- if (avctx->channel_layout != AV_CH_FRONT_LEFT)
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
-
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
ctx->num_channel_blocks = 1;
ctx->channel_blocks[0] = CH_UNIT_MONO;
break;
case 2:
- avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
ctx->num_channel_blocks = 1;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
break;
case 3:
- avctx->channel_layout = AV_CH_LAYOUT_SURROUND;
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND;
ctx->num_channel_blocks = 2;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
break;
case 4:
- avctx->channel_layout = AV_CH_LAYOUT_4POINT0;
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
ctx->num_channel_blocks = 3;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
ctx->channel_blocks[2] = CH_UNIT_MONO;
break;
case 6:
- avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK;
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK;
ctx->num_channel_blocks = 4;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
@@ -113,7 +112,7 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx,
ctx->channel_blocks[3] = CH_UNIT_MONO;
break;
case 7:
- avctx->channel_layout = AV_CH_LAYOUT_6POINT1_BACK;
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1_BACK;
ctx->num_channel_blocks = 5;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
@@ -122,7 +121,7 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx,
ctx->channel_blocks[4] = CH_UNIT_MONO;
break;
case 8:
- avctx->channel_layout = AV_CH_LAYOUT_7POINT1;
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1;
ctx->num_channel_blocks = 5;
ctx->channel_blocks[0] = CH_UNIT_STEREO;
ctx->channel_blocks[1] = CH_UNIT_MONO;
@@ -132,7 +131,7 @@ static av_cold int set_channel_params(ATRAC3PContext *ctx,
break;
default:
av_log(avctx, AV_LOG_ERROR,
- "Unsupported channel count: %d!\n", avctx->channels);
+ "Unsupported channel count: %d!\n", channels);
return AVERROR_INVALIDDATA;
}
@@ -163,8 +162,6 @@ static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
if ((ret = set_channel_params(ctx, avctx)) < 0)
return ret;
- ctx->my_channel_layout = avctx->channel_layout;
-
ctx->ch_units = av_mallocz(sizeof(*ctx->ch_units) *
ctx->num_channel_blocks);
if (!ctx->ch_units) {
diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index 51fb6c83ce..5a0448b573 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -73,6 +73,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
int sample_rate_half;
int i;
int frame_len_bits;
+ int channels = avctx->ch_layout.nb_channels;
/* determine frame length */
if (avctx->sample_rate < 22050) {
@@ -83,24 +84,24 @@ static av_cold int decode_init(AVCodecContext *avctx)
frame_len_bits = 11;
}
- if (avctx->channels > MAX_CHANNELS) {
- av_log(avctx, AV_LOG_ERROR, "too many channels: %d\n", avctx->channels);
+ if (channels > MAX_CHANNELS) {
+ av_log(avctx, AV_LOG_ERROR, "too many channels: %d\n", channels);
return -1;
}
- avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
- AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
s->version_b = avctx->extradata && avctx->extradata[3] == 'b';
if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) {
// audio is already interleaved for the RDFT format variant
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
- sample_rate *= avctx->channels;
+ sample_rate *= channels;
s->channels = 1;
if (!s->version_b)
- frame_len_bits += av_log2(avctx->channels);
+ frame_len_bits += av_log2(channels);
} else {
- s->channels = avctx->channels;
+ s->channels = channels;
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
}
@@ -334,7 +335,7 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
av_packet_unref(s->pkt);
}
- frame->nb_samples = s->block_size / avctx->channels;
+ frame->nb_samples = s->block_size / avctx->ch_layout.nb_channels;
return 0;
fail:
diff --git a/libavcodec/bmvaudio.c b/libavcodec/bmvaudio.c
index 8b4bd784a1..d65064f0e9 100644
--- a/libavcodec/bmvaudio.c
+++ b/libavcodec/bmvaudio.c
@@ -31,8 +31,8 @@ static const int bmv_aud_mults[16] = {
static av_cold int bmv_aud_decode_init(AVCodecContext *avctx)
{
- avctx->channels = 2;
- avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
diff --git a/libavcodec/cngdec.c b/libavcodec/cngdec.c
index 482ef94a32..2cdb701b07 100644
--- a/libavcodec/cngdec.c
+++ b/libavcodec/cngdec.c
@@ -54,7 +54,8 @@ static av_cold int cng_decode_init(AVCodecContext *avctx)
CNGContext *p = avctx->priv_data;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- avctx->channels = 1;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_rate = 8000;
p->order = 12;
diff --git a/libavcodec/cngenc.c b/libavcodec/cngenc.c
index 98f3c4e91a..95092607ff 100644
--- a/libavcodec/cngenc.c
+++ b/libavcodec/cngenc.c
@@ -47,11 +47,6 @@ static av_cold int cng_encode_init(AVCodecContext *avctx)
CNGContext *p = avctx->priv_data;
int ret;
- if (avctx->channels != 1) {
- av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
- return AVERROR(EINVAL);
- }
-
avctx->frame_size = 640;
p->order = 10;
if ((ret = ff_lpc_init(&p->lpc, avctx->frame_size, p->order, FF_LPC_TYPE_LEVINSON)) < 0)
@@ -113,4 +108,5 @@ AVCodec ff_comfortnoise_encoder = {
.close = cng_encode_close,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_NONE },
+ .ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } },
};
diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index bd8ad1d1da..66c93fbaab 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -1023,7 +1023,7 @@ static void dump_cook_context(COOKContext *q)
PRINT("js_vlc_bits", q->subpacket[0].js_vlc_bits);
}
ff_dlog(q->avctx, "COOKContext\n");
- PRINT("nb_channels", q->avctx->channels);
+ PRINT("nb_channels", q->avctx->ch_layout.nb_channels);
PRINT("bit_rate", q->avctx->bit_rate);
PRINT("sample_rate", q->avctx->sample_rate);
PRINT("samples_per_channel", q->subpacket[0].samples_per_channel);
@@ -1048,6 +1048,8 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
unsigned int channel_mask = 0;
int samples_per_frame;
int ret;
+ int channels = avctx->ch_layout.nb_channels;
+
q->avctx = avctx;
/* Take care of the codec specific extradata. */
@@ -1060,7 +1062,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
bytestream2_init(&gb, avctx->extradata, avctx->extradata_size);
/* Take data from the AVCodecContext (RM container). */
- if (!avctx->channels) {
+ if (!channels) {
av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
return AVERROR_INVALIDDATA;
}
@@ -1081,7 +1083,7 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
q->subpacket[s].js_vlc_bits = bytestream2_get_be16(&gb);
/* Initialize extradata related variables. */
- q->subpacket[s].samples_per_channel = samples_per_frame / avctx->channels;
+ q->subpacket[s].samples_per_channel = samples_per_frame / channels;
q->subpacket[s].bits_per_subpacket = avctx->block_align * 8;
/* Initialize default data states. */
@@ -1096,21 +1098,21 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
q->subpacket[s].joint_stereo = 0;
switch (q->subpacket[s].cookversion) {
case MONO:
- if (avctx->channels != 1) {
+ if (channels != 1) {
avpriv_request_sample(avctx, "Container channels != 1");
return AVERROR_PATCHWELCOME;
}
av_log(avctx, AV_LOG_DEBUG, "MONO\n");
break;
case STEREO:
- if (avctx->channels != 1) {
+ if (channels != 1) {
q->subpacket[s].bits_per_subpdiv = 1;
q->subpacket[s].num_channels = 2;
}
av_log(avctx, AV_LOG_DEBUG, "STEREO\n");
break;
case JOINT_STEREO:
- if (avctx->channels != 2) {
+ if (channels != 2) {
avpriv_request_sample(avctx, "Container channels != 2");
return AVERROR_PATCHWELCOME;
}
@@ -1131,8 +1133,9 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
case MC_COOK:
av_log(avctx, AV_LOG_DEBUG, "MULTI_CHANNEL\n");
channel_mask |= q->subpacket[s].channel_mask = bytestream2_get_be32(&gb);
+ av_channel_layout_from_mask(&avctx->ch_layout, q->subpacket[s].channel_mask);
- if (av_get_channel_layout_nb_channels(q->subpacket[s].channel_mask) > 1) {
+ if (avctx->ch_layout.nb_channels > 1) {
q->subpacket[s].total_subbands = q->subpacket[s].subbands +
q->subpacket[s].js_subband_start;
q->subpacket[s].joint_stereo = 1;
@@ -1238,10 +1241,11 @@ static av_cold int cook_decode_init(AVCodecContext *avctx)
}
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
+ av_channel_layout_uninit(&avctx->ch_layout);
if (channel_mask)
- avctx->channel_layout = channel_mask;
+ av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
else
- avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+ av_channel_layout_default(&avctx->ch_layout, channels);
#ifdef DEBUG
dump_cook_context(q);
diff --git a/libavcodec/cook_parser.c b/libavcodec/cook_parser.c
index f140e90461..4e7b037dda 100644
--- a/libavcodec/cook_parser.c
+++ b/libavcodec/cook_parser.c
@@ -42,8 +42,8 @@ static int cook_parse(AVCodecParserContext *s1, AVCodecContext *avctx,
if (s->duration)
s1->duration = s->duration;
- else if (avctx->extradata && avctx->extradata_size >= 8 && avctx->channels)
- s->duration = AV_RB16(avctx->extradata + 4) / avctx->channels;
+ else if (avctx->extradata && avctx->extradata_size >= 8 && avctx->ch_layout.nb_channels)
+ s->duration = AV_RB16(avctx->extradata + 4) / avctx->ch_layout.nb_channels;
/* always return the full packet. this parser isn't doing any splitting or
combining, only setting packet duration */
diff --git a/libavcodec/dca.h b/libavcodec/dca.h
index 787a9c74de..873d7152e8 100644
--- a/libavcodec/dca.h
+++ b/libavcodec/dca.h
@@ -286,6 +286,8 @@ typedef struct DCAContext {
DCADSPContext dcadsp;
QMF64_table *qmf64_table;
FmtConvertContext fmt_conv;
+
+ AVChannelLayout downmix_layout;
} DCAContext;
extern av_export const uint32_t avpriv_dca_sample_rates[16];
diff --git a/libavcodec/dca_xll.c b/libavcodec/dca_xll.c
index 5d76793fbb..8fcae31336 100644
--- a/libavcodec/dca_xll.c
+++ b/libavcodec/dca_xll.c
@@ -448,7 +448,7 @@ int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame)
* other parameters from the previous segment. */
int use_seg_state_code_param;
XllChSetSubHeader *chset = &s->xll_chsets[chset_i];
- if (in_channel >= s->avctx->channels)
+ if (in_channel >= s->avctx->ch_layout.nb_channels)
/* FIXME: Could go directly to next segment */
goto next_chset;
@@ -673,7 +673,7 @@ int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame)
out_channel = out_channel ? out_channel - 1 : 2;
out_channel += in_channel;
- if (out_channel >= s->avctx->channels)
+ if (out_channel >= s->avctx->ch_layout.nb_channels)
continue;
out = (float *) frame->extended_data[out_channel];
@@ -717,7 +717,7 @@ int ff_dca_xll_decode_audio(DCAContext *s, AVFrame *frame)
mix_buf[j] *= coeff;
for (row = 0;
- row < chset->channels && in_channel + row < s->avctx->channels;
+ row < chset->channels && in_channel + row < s->avctx->ch_layout.nb_channels;
row++)
if (col[row + 1]) {
const float *new_channel =
diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index 9c1f878239..7cde57f8a7 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -1269,10 +1269,13 @@ static int set_channel_layout(AVCodecContext *avctx, int channels)
int i;
if (s->amode < 16) {
- avctx->channel_layout = dca_core_channel_layout[s->amode];
+ static const AVChannelLayout stereo = AV_CHANNEL_LAYOUT_STEREO;
+ uint64_t mask = dca_core_channel_layout[s->amode];
if (s->audio_header.prim_channels + !!s->lfe > 2 &&
- avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
+ !av_channel_layout_compare(&s->downmix_layout, &stereo)) {
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+
/*
* Neither the core's auxiliary data nor our default tables contain
* downmix coefficients for the additional channel coded in the XCh
@@ -1282,9 +1285,9 @@ static int set_channel_layout(AVCodecContext *avctx, int channels)
}
if (s->xch_present && !s->xch_disable) {
- avctx->channel_layout |= AV_CH_BACK_CENTER;
+ mask |= AV_CH_BACK_CENTER;
if (s->lfe) {
- avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
+ mask |= AV_CH_LOW_FREQUENCY;
s->channel_order_tab = ff_dca_channel_reorder_lfe_xch[s->amode];
} else {
s->channel_order_tab = ff_dca_channel_reorder_nolfe_xch[s->amode];
@@ -1293,7 +1296,7 @@ static int set_channel_layout(AVCodecContext *avctx, int channels)
channels = num_core_channels + !!s->lfe;
s->xch_present = 0; /* disable further xch processing */
if (s->lfe) {
- avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
+ mask |= AV_CH_LOW_FREQUENCY;
s->channel_order_tab = ff_dca_channel_reorder_lfe[s->amode];
} else
s->channel_order_tab = ff_dca_channel_reorder_nolfe[s->amode];
@@ -1307,10 +1310,10 @@ static int set_channel_layout(AVCodecContext *avctx, int channels)
return AVERROR_INVALIDDATA;
if (num_core_channels + !!s->lfe > 2 &&
- avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
+ !av_channel_layout_compare(&s->downmix_layout, &stereo)) {
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
channels = 2;
s->output = s->audio_header.prim_channels == 2 ? s->amode : DCA_STEREO;
- avctx->channel_layout = AV_CH_LAYOUT_STEREO;
/* Stereo downmix coefficients
*
@@ -1352,6 +1355,8 @@ static int set_channel_layout(AVCodecContext *avctx, int channels)
}
ff_dlog(s->avctx, "\n");
}
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_from_mask(&avctx->ch_layout, mask);
} else {
av_log(avctx, AV_LOG_ERROR, "Nonstandard configuration %d !\n", s->amode);
return AVERROR_INVALIDDATA;
@@ -1379,6 +1384,8 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
int upsample = 0;
int downmix;
+ static const AVChannelLayout stereo = AV_CHANNEL_LAYOUT_STEREO;
+
s->exss_ext_mask = 0;
s->xch_present = 0;
@@ -1420,7 +1427,6 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
ret = set_channel_layout(avctx, channels);
if (ret < 0)
return ret;
- avctx->channels = channels;
/* get output buffer */
frame->nb_samples = 256 * (s->sample_blocks / SAMPLES_PER_SUBBAND);
@@ -1451,15 +1457,15 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
/* If downmixing to stereo, don't decode additional channels.
* FIXME: Using the xch_disable flag for this doesn't seem right. */
if (!s->xch_disable)
- avctx->channels += s->xll_channels - s->xll_residual_channels;
+ channels += s->xll_channels - s->xll_residual_channels;
}
}
- /* FIXME: This is an ugly hack, to just revert to the default
- * layout if we have additional channels. Need to convert the XLL
- * channel masks to libav channel_layout mask. */
- if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels)
- avctx->channel_layout = 0;
+ if (avctx->ch_layout.nb_channels != channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ avctx->ch_layout.nb_channels = channels;
+ }
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
@@ -1468,7 +1474,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
samples_flt = (float **) frame->extended_data;
/* allocate buffer for extra channels if downmixing */
- if (avctx->channels < full_channels) {
+ if (avctx->ch_layout.nb_channels < full_channels) {
ret = av_samples_get_buffer_size(NULL, full_channels - channels,
frame->nb_samples,
avctx->sample_fmt, 0);
@@ -1489,7 +1495,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
}
downmix = s->audio_header.prim_channels > 2 &&
- avctx->request_channel_layout == AV_CH_LAYOUT_STEREO;
+ !av_channel_layout_compare(&s->downmix_layout, &stereo);
/* filter to get final output */
for (i = 0; i < (s->sample_blocks / SAMPLES_PER_SUBBAND); i++) {
@@ -1546,6 +1552,7 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
static av_cold int dca_decode_init(AVCodecContext *avctx)
{
DCAContext *s = avctx->priv_data;
+ static const AVChannelLayout stereo = AV_CHANNEL_LAYOUT_STEREO;
s->avctx = avctx;
dca_init_vlcs();
@@ -1559,9 +1566,17 @@ static av_cold int dca_decode_init(AVCodecContext *avctx)
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
/* allow downmixing to stereo */
- if (avctx->channels > 2 &&
- avctx->request_channel_layout == AV_CH_LAYOUT_STEREO)
- avctx->channels = 2;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+ if (avctx->request_channel_layout)
+ av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout);
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ if (avctx->ch_layout.nb_channels > 2 &&
+ !av_channel_layout_compare(&s->downmix_layout, &stereo)) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+ }
return 0;
}
@@ -1579,6 +1594,7 @@ static av_cold int dca_decode_end(AVCodecContext *avctx)
static const AVOption options[] = {
{ "disable_xch", "disable decoding of the XCh extension", offsetof(DCAContext, xch_disable), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM },
{ "disable_xll", "disable decoding of the XLL extension", offsetof(DCAContext, xll_disable), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM },
+ { "downmix", "Request a specific channel layout from the decoder", offsetof(DCAContext, downmix_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.str = NULL}, .flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM },
{ NULL },
};
diff --git a/libavcodec/dpcm.c b/libavcodec/dpcm.c
index 7567643d45..20560b4281 100644
--- a/libavcodec/dpcm.c
+++ b/libavcodec/dpcm.c
@@ -117,7 +117,7 @@ static av_cold int dpcm_decode_init(AVCodecContext *avctx)
DPCMContext *s = avctx->priv_data;
int i;
- if (avctx->channels < 1 || avctx->channels > 2) {
+ if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) {
av_log(avctx, AV_LOG_INFO, "invalid number of channels\n");
return AVERROR(EINVAL);
}
@@ -175,7 +175,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
int out = 0, ret;
int predictor[2];
int ch = 0;
- int stereo = avctx->channels - 1;
+ int stereo = avctx->ch_layout.nb_channels - 1;
int16_t *output_samples, *samples_end;
GetByteContext gb;
@@ -189,10 +189,10 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
out = buf_size - 8;
break;
case AV_CODEC_ID_INTERPLAY_DPCM:
- out = buf_size - 6 - avctx->channels;
+ out = buf_size - 6 - avctx->ch_layout.nb_channels;
break;
case AV_CODEC_ID_XAN_DPCM:
- out = buf_size - 2 * avctx->channels;
+ out = buf_size - 2 * avctx->ch_layout.nb_channels;
break;
case AV_CODEC_ID_SOL_DPCM:
if (avctx->codec_tag != 3)
@@ -207,7 +207,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
}
/* get output buffer */
- frame->nb_samples = out / avctx->channels;
+ frame->nb_samples = out / avctx->ch_layout.nb_channels;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
@@ -241,7 +241,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
case AV_CODEC_ID_INTERPLAY_DPCM:
bytestream2_skipu(&gb, 6); /* skip over the stream mask and stream length */
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
*output_samples++ = predictor[ch];
}
@@ -261,7 +261,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data,
{
int shift[2] = { 4, 4 };
- for (ch = 0; ch < avctx->channels; ch++)
+ for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
predictor[ch] = sign_extend(bytestream2_get_le16u(&gb), 16);
ch = 0;
diff --git a/libavcodec/dsicinaudio.c b/libavcodec/dsicinaudio.c
index e0fecbeb03..421a379029 100644
--- a/libavcodec/dsicinaudio.c
+++ b/libavcodec/dsicinaudio.c
@@ -80,8 +80,8 @@ static av_cold int cinaudio_decode_init(AVCodecContext *avctx)
cin->initial_decode_frame = 1;
cin->delta = 0;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
return 0;
}
diff --git a/libavcodec/dss_sp.c b/libavcodec/dss_sp.c
index 4fe784c055..239a235d7e 100644
--- a/libavcodec/dss_sp.c
+++ b/libavcodec/dss_sp.c
@@ -289,10 +289,10 @@ static const int32_t dss_sp_sinc[67] = {
static av_cold int dss_sp_decode_init(AVCodecContext *avctx)
{
DssSpContext *p = avctx->priv_data;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- avctx->channels = 1;
avctx->sample_rate = 11025;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
memset(p->history, 0, sizeof(p->history));
p->pulse_dec_mode = 1;
diff --git a/libavcodec/flac.c b/libavcodec/flac.c
index 3e51fdeb98..eb9051ab50 100644
--- a/libavcodec/flac.c
+++ b/libavcodec/flac.c
@@ -29,15 +29,15 @@
static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
-static const uint64_t flac_channel_layouts[8] = {
- AV_CH_LAYOUT_MONO,
- AV_CH_LAYOUT_STEREO,
- AV_CH_LAYOUT_SURROUND,
- AV_CH_LAYOUT_QUAD,
- AV_CH_LAYOUT_5POINT0,
- AV_CH_LAYOUT_5POINT1,
- AV_CH_LAYOUT_6POINT1,
- AV_CH_LAYOUT_7POINT1
+static const AVChannelLayout flac_channel_layouts[8] = {
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ AV_CHANNEL_LAYOUT_SURROUND,
+ AV_CHANNEL_LAYOUT_QUAD,
+ AV_CHANNEL_LAYOUT_5POINT0,
+ AV_CHANNEL_LAYOUT_5POINT1,
+ AV_CHANNEL_LAYOUT_6POINT1,
+ AV_CHANNEL_LAYOUT_7POINT1
};
static int64_t get_utf8(GetBitContext *gb)
@@ -193,12 +193,17 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx,
return 1;
}
-void ff_flac_set_channel_layout(AVCodecContext *avctx)
+void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels)
{
- if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
- avctx->channel_layout = flac_channel_layouts[avctx->channels - 1];
+ if (channels == avctx->ch_layout.nb_channels)
+ return;
+
+ av_channel_layout_uninit(&avctx->ch_layout);
+ if (channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
+ avctx->ch_layout = flac_channel_layouts[channels - 1];
else
- avctx->channel_layout = 0;
+ avctx->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
+ .nb_channels = channels };
}
void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
@@ -222,13 +227,9 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
s->channels = get_bits(&gb, 3) + 1;
s->bps = get_bits(&gb, 5) + 1;
- avctx->channels = s->channels;
avctx->sample_rate = s->samplerate;
avctx->bits_per_raw_sample = s->bps;
-
- if (!avctx->channel_layout ||
- av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels)
- ff_flac_set_channel_layout(avctx);
+ ff_flac_set_channel_layout(avctx, s->channels);
s->samples = get_bits_long(&gb, 32) << 4;
s->samples |= get_bits(&gb, 4);
diff --git a/libavcodec/flac.h b/libavcodec/flac.h
index 3229682047..4ffdc3500a 100644
--- a/libavcodec/flac.h
+++ b/libavcodec/flac.h
@@ -137,7 +137,7 @@ int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
FLACFrameInfo *fi, int log_level_offset);
-void ff_flac_set_channel_layout(AVCodecContext *avctx);
+void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels);
/**
* Parse the metadata block parameters from the header.
diff --git a/libavcodec/flac_parser.c b/libavcodec/flac_parser.c
index cb394f2bdb..34f5d52354 100644
--- a/libavcodec/flac_parser.c
+++ b/libavcodec/flac_parser.c
@@ -458,11 +458,8 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf,
check_header_mismatch(fpc, header, child, 0);
}
- if (header->fi.channels != fpc->avctx->channels ||
- !fpc->avctx->channel_layout) {
- fpc->avctx->channels = header->fi.channels;
- ff_flac_set_channel_layout(fpc->avctx);
- }
+ ff_flac_set_channel_layout(fpc->avctx, header->fi.channels);
+
fpc->avctx->sample_rate = header->fi.samplerate;
fpc->pc->duration = header->fi.blocksize;
*poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,
diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c
index 78be2adab3..8b2f780ff0 100644
--- a/libavcodec/flacdec.c
+++ b/libavcodec/flacdec.c
@@ -408,15 +408,15 @@ static int decode_frame(FLACContext *s)
}
if (s->channels && fi.channels != s->channels && s->got_streaminfo) {
- s->channels = s->avctx->channels = fi.channels;
- ff_flac_set_channel_layout(s->avctx);
+ s->channels = fi.channels;
+ ff_flac_set_channel_layout(s->avctx, s->channels);
ret = allocate_buffers(s);
if (ret < 0)
return ret;
}
- s->channels = s->avctx->channels = fi.channels;
- if (!s->avctx->channel_layout)
- ff_flac_set_channel_layout(s->avctx);
+ s->channels = fi.channels;
+ if (!s->avctx->ch_layout.nb_channels)
+ ff_flac_set_channel_layout(s->avctx, s->channels);
s->ch_mode = fi.ch_mode;
if (!s->bps && !fi.bps) {
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
index 2745b17a1c..cd02500807 100644
--- a/libavcodec/flacenc.c
+++ b/libavcodec/flacenc.c
@@ -231,7 +231,7 @@ static av_cold void dprint_compression_options(FlacEncodeContext *s)
static av_cold int flac_encode_init(AVCodecContext *avctx)
{
int freq = avctx->sample_rate;
- int channels = avctx->channels;
+ int channels = avctx->ch_layout.nb_channels;
FlacEncodeContext *s = avctx->priv_data;
int i, level, ret;
uint8_t *streaminfo;
diff --git a/libavcodec/g722dec.c b/libavcodec/g722dec.c
index 07af0a082a..e08ea22591 100644
--- a/libavcodec/g722dec.c
+++ b/libavcodec/g722dec.c
@@ -60,8 +60,8 @@ static av_cold int g722_decode_init(AVCodecContext * avctx)
{
G722Context *c = avctx->priv_data;
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
c->band[0].scale_factor = 8;
diff --git a/libavcodec/g722enc.c b/libavcodec/g722enc.c
index 545825b057..34bdbbd51d 100644
--- a/libavcodec/g722enc.c
+++ b/libavcodec/g722enc.c
@@ -60,11 +60,6 @@ static av_cold int g722_encode_init(AVCodecContext * avctx)
G722Context *c = avctx->priv_data;
int ret;
- if (avctx->channels != 1) {
- av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n");
- return AVERROR_INVALIDDATA;
- }
-
c->band[0].scale_factor = 8;
c->band[1].scale_factor = 2;
c->prev_samples_pos = 22;
@@ -393,4 +388,7 @@ AVCodec ff_adpcm_g722_encoder = {
.capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_NONE },
+ .ch_layouts = (const AVChannelLayout[]){
+ AV_CHANNEL_LAYOUT_MONO, { 0 }
+ },
};
diff --git a/libavcodec/g723_1dec.c b/libavcodec/g723_1dec.c
index 0cb5ba70c5..4ec5555d4d 100644
--- a/libavcodec/g723_1dec.c
+++ b/libavcodec/g723_1dec.c
@@ -43,10 +43,10 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
{
G723_1_Context *p = avctx->priv_data;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- avctx->channels = 1;
avctx->sample_rate = 8000;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
p->pf_gain = 1 << 12;
memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(*p->prev_lsp));
diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c
index 82f5cecfa2..c8d296dea5 100644
--- a/libavcodec/g723_1enc.c
+++ b/libavcodec/g723_1enc.c
@@ -49,11 +49,6 @@ static av_cold int g723_1_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if (avctx->channels != 1) {
- av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
- return AVERROR(EINVAL);
- }
-
if (avctx->bit_rate == 6300) {
p->cur_rate = RATE_6300;
} else if (avctx->bit_rate == 5300) {
@@ -1200,4 +1195,7 @@ AVCodec ff_g723_1_encoder = {
.sample_fmts = (const enum AVSampleFormat[]) {
AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
},
+ .ch_layouts = (const AVChannelLayout[]){
+ AV_CHANNEL_LAYOUT_MONO, { 0 }
+ },
};
diff --git a/libavcodec/g726.c b/libavcodec/g726.c
index dab038f50c..112c29a13a 100644
--- a/libavcodec/g726.c
+++ b/libavcodec/g726.c
@@ -321,7 +321,7 @@ static av_cold int g726_encode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- if(avctx->channels != 1){
+ if (avctx->ch_layout.nb_channels != 1) {
av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n");
return AVERROR(EINVAL);
}
@@ -407,8 +407,8 @@ static av_cold int g726_decode_init(AVCodecContext *avctx)
{
G726Context* c = avctx->priv_data;
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
c->code_size = avctx->bits_per_coded_sample;
if (c->code_size < 2 || c->code_size > 5) {
diff --git a/libavcodec/gsmdec.c b/libavcodec/gsmdec.c
index 0205fafad0..036917b679 100644
--- a/libavcodec/gsmdec.c
+++ b/libavcodec/gsmdec.c
@@ -35,8 +35,8 @@
static av_cold int gsm_init(AVCodecContext *avctx)
{
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
if (!avctx->sample_rate)
avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index 100e6f8941..9eef41b86e 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -180,15 +180,17 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
IMCContext *q = avctx->priv_data;
double r1, r2;
- if (avctx->codec_id == AV_CODEC_ID_IMC)
- avctx->channels = 1;
+ if (avctx->codec_id == AV_CODEC_ID_IMC) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
+ }
- if (avctx->channels > 2) {
+ if (avctx->ch_layout.nb_channels > 2) {
avpriv_request_sample(avctx, "Number of channels > 2");
return AVERROR_PATCHWELCOME;
}
- for (j = 0; j < avctx->channels; j++) {
+ for (j = 0; j < avctx->ch_layout.nb_channels; j++) {
q->chctx[j].decoder_reset = 1;
for (i = 0; i < BANDS; i++)
@@ -250,8 +252,6 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
ff_bswapdsp_init(&q->bdsp);
avpriv_float_dsp_init(&q->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
- avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
- : AV_CH_LAYOUT_STEREO;
return 0;
}
@@ -983,7 +983,7 @@ static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags));
- imc_imdct256(q, chctx, avctx->channels);
+ imc_imdct256(q, chctx, avctx->ch_layout.nb_channels);
return 0;
}
@@ -1000,7 +1000,7 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data,
LOCAL_ALIGNED_16(uint16_t, buf16, [(IMC_BLOCK_SIZE + AV_INPUT_BUFFER_PADDING_SIZE) / 2]);
- if (buf_size < IMC_BLOCK_SIZE * avctx->channels) {
+ if (buf_size < IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_ERROR, "frame too small!\n");
return AVERROR_INVALIDDATA;
}
@@ -1012,7 +1012,7 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data,
return ret;
}
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
q->out_samples = (float *)frame->extended_data[i];
q->bdsp.bswap16_buf(buf16, (const uint16_t *) buf, IMC_BLOCK_SIZE / 2);
@@ -1025,14 +1025,14 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data,
return ret;
}
- if (avctx->channels == 2) {
+ if (avctx->ch_layout.nb_channels == 2) {
q->fdsp.butterflies_float((float *)frame->extended_data[0],
(float *)frame->extended_data[1], COEFFS);
}
*got_frame_ptr = 1;
- return IMC_BLOCK_SIZE * avctx->channels;
+ return IMC_BLOCK_SIZE * avctx->ch_layout.nb_channels;
}
diff --git a/libavcodec/libdcadec.c b/libavcodec/libdcadec.c
index b88f80763b..c276a5f8f1 100644
--- a/libavcodec/libdcadec.c
+++ b/libavcodec/libdcadec.c
@@ -75,8 +75,8 @@ static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR_UNKNOWN;
}
- avctx->channels = av_get_channel_layout_nb_channels(channel_mask);
- avctx->channel_layout = channel_mask;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
avctx->sample_rate = sample_rate;
if (bits_per_sample == 16)
@@ -128,7 +128,7 @@ static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
if (frame->format == AV_SAMPLE_FMT_S16P) {
int16_t *plane = (int16_t *)frame->extended_data[i];
for (k = 0; k < nsamples; k++)
diff --git a/libavcodec/libfdk-aacdec.c b/libavcodec/libfdk-aacdec.c
index aa30f93ef6..6a77e90392 100644
--- a/libavcodec/libfdk-aacdec.c
+++ b/libavcodec/libfdk-aacdec.c
@@ -50,6 +50,7 @@ typedef struct FDKAACDecContext {
int drc_heavy;
int drc_cut;
int level_limit;
+ AVChannelLayout downmix_layout;
} FDKAACDecContext;
@@ -75,6 +76,7 @@ static const AVOption fdk_aac_dec_options[] = {
#ifdef AACDECODER_LIB_VL0
{ "level_limit", "Signal level limiting", OFFSET(level_limit), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, 1, AD },
#endif
+ { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.str = NULL}, .flags = AD },
{ NULL }
};
@@ -181,17 +183,15 @@ static int get_stream_info(AVCodecContext *avctx)
ch_error = 1;
}
}
- if (!ch_error &&
- av_get_channel_layout_nb_channels(ch_layout) != info->numChannels) {
+
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_from_mask(&avctx->ch_layout, ch_layout);
+ if (!ch_error && avctx->ch_layout.nb_channels != info->numChannels) {
av_log(avctx, AV_LOG_WARNING, "unsupported channel configuration\n");
ch_error = 1;
}
if (ch_error)
- avctx->channel_layout = 0;
- else
- avctx->channel_layout = ch_layout;
-
- avctx->channels = info->numChannels;
+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
return 0;
}
@@ -233,11 +233,19 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
return AVERROR_UNKNOWN;
}
- if (avctx->request_channel_layout > 0 &&
- avctx->request_channel_layout != AV_CH_LAYOUT_NATIVE) {
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+ if (avctx->request_channel_layout) {
+ av_channel_layout_uninit(&s->downmix_layout);
+ av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout);
+ }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ if (s->downmix_layout.nb_channels > 0 &&
+ s->downmix_layout.order != AV_CHANNEL_ORDER_NATIVE) {
int downmix_channels = -1;
- switch (avctx->request_channel_layout) {
+ switch (s->downmix_layout.u.mask) {
case AV_CH_LAYOUT_STEREO:
case AV_CH_LAYOUT_STEREO_DOWNMIX:
downmix_channels = 2;
@@ -246,7 +254,7 @@ static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)
downmix_channels = 1;
break;
default:
- av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n");
+ av_log(avctx, AV_LOG_WARNING, "Invalid downmix option\n");
break;
}
@@ -349,7 +357,7 @@ static int fdk_aac_decode_frame(AVCodecContext *avctx, void *data,
goto end;
}
memcpy(frame->extended_data[0], s->decoder_buffer,
- avctx->channels * avctx->frame_size *
+ avctx->ch_layout.nb_channels * avctx->frame_size *
av_get_bytes_per_sample(avctx->sample_fmt));
*got_frame_ptr = 1;
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 03879bbf5a..f92c14d65f 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -114,7 +114,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
int aot = FF_PROFILE_AAC_LOW + 1;
int sce = 0, cpe = 0;
- if ((err = aacEncOpen(&s->handle, 0, avctx->channels)) != AACENC_OK) {
+ if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) {
av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
aac_get_error(err));
goto error;
@@ -145,7 +145,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
goto error;
}
- switch (avctx->channels) {
+ switch (avctx->ch_layout.nb_channels) {
case 1: mode = MODE_1; sce = 1; cpe = 0; break;
case 2: mode = MODE_2; sce = 0; cpe = 1; break;
case 3: mode = MODE_1_2; sce = 1; cpe = 1; break;
@@ -158,7 +158,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
case 8:
sce = 2;
cpe = 3;
- if (avctx->channel_layout == AV_CH_LAYOUT_7POINT1) {
+ if (avctx->ch_layout.u.mask == AV_CH_LAYOUT_7POINT1) {
mode = MODE_7_1_REAR_SURROUND;
} else {
// MODE_1_2_2_2_1 and MODE_7_1_FRONT_CENTER use the same channel layout
@@ -168,7 +168,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
#endif
default:
av_log(avctx, AV_LOG_ERROR,
- "Unsupported number of channels %d\n", avctx->channels);
+ "Unsupported number of channels %d\n", avctx->ch_layout.nb_channels);
goto error;
}
@@ -329,10 +329,10 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
in_args.numInSamples = -1;
} else {
in_ptr = frame->data[0];
- in_buffer_size = 2 * avctx->channels * frame->nb_samples;
+ in_buffer_size = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
in_buffer_element_size = 2;
- in_args.numInSamples = avctx->channels * frame->nb_samples;
+ in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples;
in_buf.numBufs = 1;
in_buf.bufs = &in_ptr;
in_buf.bufferIdentifiers = &in_buffer_identifier;
@@ -345,7 +345,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
/* The maximum packet size is 6144 bits aka 768 bytes per channel. */
- if ((ret = ff_alloc_packet(avpkt, FFMAX(8192, 768 * avctx->channels)))) {
+ if ((ret = ff_alloc_packet(avpkt, FFMAX(8192, 768 * avctx->ch_layout.nb_channels)))) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
return ret;
}
@@ -394,6 +394,7 @@ static const AVCodecDefault aac_encode_defaults[] = {
{ NULL }
};
+#if FF_API_OLD_CHANNEL_LAYOUT
static const uint64_t aac_channel_layout[] = {
AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
@@ -407,6 +408,21 @@ static const uint64_t aac_channel_layout[] = {
#endif
0,
};
+#endif /* FF_API_OLD_CHANNEL_LAYOUT */
+
+static const AVChannelLayout aac_ch_layouts[16] = {
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ AV_CHANNEL_LAYOUT_SURROUND,
+ AV_CHANNEL_LAYOUT_4POINT0,
+ AV_CHANNEL_LAYOUT_5POINT0_BACK,
+ AV_CHANNEL_LAYOUT_5POINT1_BACK,
+#ifdef AACENCODER_LIB_VL0
+ AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
+ AV_CHANNEL_LAYOUT_7POINT1,
+#endif
+ { 0 },
+};
static const int aac_sample_rates[] = {
96000, 88200, 64000, 48000, 44100, 32000,
@@ -429,5 +445,10 @@ AVCodec ff_libfdk_aac_encoder = {
.defaults = aac_encode_defaults,
.profiles = profiles,
.supported_samplerates = aac_sample_rates,
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
.channel_layouts = aac_channel_layout,
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ .ch_layouts = aac_ch_layouts,
};
diff --git a/libavcodec/libgsmdec.c b/libavcodec/libgsmdec.c
index 4c21ff6728..0f6962fa1e 100644
--- a/libavcodec/libgsmdec.c
+++ b/libavcodec/libgsmdec.c
@@ -48,8 +48,8 @@ typedef struct LibGSMDecodeContext {
static av_cold int libgsm_decode_init(AVCodecContext *avctx) {
LibGSMDecodeContext *s = avctx->priv_data;
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
diff --git a/libavcodec/libgsmenc.c b/libavcodec/libgsmenc.c
index 8f51321d46..048baeef35 100644
--- a/libavcodec/libgsmenc.c
+++ b/libavcodec/libgsmenc.c
@@ -41,9 +41,9 @@
#include "gsm.h"
static av_cold int libgsm_encode_init(AVCodecContext *avctx) {
- if (avctx->channels > 1) {
+ if (avctx->ch_layout.nb_channels > 1) {
av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n",
- avctx->channels);
+ avctx->ch_layout.nb_channels);
return -1;
}
diff --git a/libavcodec/libilbc.c b/libavcodec/libilbc.c
index 80b69a562c..8131a25da6 100644
--- a/libavcodec/libilbc.c
+++ b/libavcodec/libilbc.c
@@ -69,8 +69,8 @@ static av_cold int ilbc_decode_init(AVCodecContext *avctx)
WebRtcIlbcfix_InitDecode(&s->decoder, mode, s->enhance);
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_rate = 8000;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
diff --git a/libavcodec/libopencore-amr.c b/libavcodec/libopencore-amr.c
index 8200f6719c..4f47483545 100644
--- a/libavcodec/libopencore-amr.c
+++ b/libavcodec/libopencore-amr.c
@@ -35,13 +35,13 @@ static int amr_decode_fix_avctx(AVCodecContext *avctx)
avctx->sample_rate = 8000 * is_amr_wb;
- if (avctx->channels > 1) {
+ if (avctx->ch_layout.nb_channels > 1) {
avpriv_report_missing_feature(avctx, "multi-channel AMR");
return AVERROR_PATCHWELCOME;
}
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
}
@@ -199,7 +199,7 @@ static av_cold int amr_nb_encode_init(AVCodecContext *avctx)
return AVERROR(ENOSYS);
}
- if (avctx->channels != 1) {
+ if (avctx->ch_layout.nb_channels != 1) {
av_log(avctx, AV_LOG_ERROR, "Only mono supported\n");
return AVERROR(ENOSYS);
}
diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index 781635615c..0c31d3a182 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -41,58 +41,52 @@ static av_cold int libopus_decode_init(AVCodecContext *avc)
struct libopus_context *opus = avc->priv_data;
int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
-
- if (avc->channels <= 0) {
- av_log(avc, AV_LOG_WARNING,
- "Invalid number of channels %d, defaulting to stereo\n", avc->channels);
- avc->channels = 2;
- }
-
- avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->channels == 1) ? 1 : 2;
- if (avc->channels <= 0) {
- av_log(avc, AV_LOG_WARNING,
- "Invalid number of channels %d, defaulting to stereo\n", avc->channels);
- avc->channels = 2;
- }
+ int channels = avc->ch_layout.nb_channels;
avc->sample_rate = 48000;
avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
- avc->channel_layout = avc->channels > 8 ? 0 :
- ff_vorbis_channel_layouts[avc->channels - 1];
+
+ if (channels <= 0) {
+ av_log(avc, AV_LOG_ERROR, "Invalid channel count.\n");
+ return AVERROR(EINVAL);
+ } else if (channels < 8) {
+ av_channel_layout_uninit(&avc->ch_layout);
+ avc->ch_layout = ff_vorbis_ch_layouts[channels - 1];
+ }
if (avc->extradata_size >= OPUS_HEAD_SIZE) {
gain_db = sign_extend(AV_RL16(avc->extradata + 16), 16);
channel_map = AV_RL8 (avc->extradata + 18);
}
- if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + avc->channels) {
+ if (avc->extradata_size >= OPUS_HEAD_SIZE + 2 + channels) {
nb_streams = avc->extradata[OPUS_HEAD_SIZE + 0];
nb_coupled = avc->extradata[OPUS_HEAD_SIZE + 1];
- if (nb_streams + nb_coupled != avc->channels)
+ if (nb_streams + nb_coupled != channels)
av_log(avc, AV_LOG_WARNING, "Inconsistent channel mapping.\n");
mapping = avc->extradata + OPUS_HEAD_SIZE + 2;
} else {
- if (avc->channels > 2 || channel_map) {
+ if (channels > 2 || channel_map) {
av_log(avc, AV_LOG_ERROR,
- "No channel mapping for %d channels.\n", avc->channels);
+ "No channel mapping for %d channels.\n", channels);
return AVERROR(EINVAL);
}
nb_streams = 1;
- nb_coupled = avc->channels > 1;
+ nb_coupled = channels > 1;
mapping = mapping_arr;
}
- if (avc->channels > 2 && avc->channels <= 8) {
- const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];
+ if (channels > 2 && channels <= 8) {
+ const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[channels - 1];
int ch;
/* Remap channels from Vorbis order to libav order */
- for (ch = 0; ch < avc->channels; ch++)
+ for (ch = 0; ch < channels; ch++)
mapping_arr[ch] = mapping[vorbis_offset[ch]];
mapping = mapping_arr;
}
- opus->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
+ opus->dec = opus_multistream_decoder_create(avc->sample_rate, channels,
nb_streams, nb_coupled,
mapping, &ret);
if (!opus->dec) {
diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 500e58c85e..cdae1af64d 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -82,7 +82,7 @@ static void libopus_write_header(AVCodecContext *avctx, int stream_count,
const uint8_t *channel_mapping)
{
uint8_t *p = avctx->extradata;
- int channels = avctx->channels;
+ int channels = avctx->ch_layout.nb_channels;
bytestream_put_buffer(&p, "OpusHead", 8);
bytestream_put_byte(&p, 1); /* Version */
@@ -152,21 +152,22 @@ static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc,
static int av_cold libopus_encode_init(AVCodecContext *avctx)
{
LibopusEncContext *opus = avctx->priv_data;
+ int channels = avctx->ch_layout.nb_channels;
const uint8_t *channel_mapping;
OpusMSEncoder *enc;
int ret = OPUS_OK;
int coupled_stream_count, header_size, frame_size;
- coupled_stream_count = opus_coupled_streams[avctx->channels - 1];
- opus->stream_count = avctx->channels - coupled_stream_count;
- channel_mapping = libav_libopus_channel_map[avctx->channels - 1];
+ coupled_stream_count = opus_coupled_streams[channels - 1];
+ opus->stream_count = channels - coupled_stream_count;
+ channel_mapping = libav_libopus_channel_map[channels - 1];
/* FIXME: Opus can handle up to 255 channels. However, the mapping for
* anything greater than 8 is undefined. */
- if (avctx->channels > 8) {
+ if (channels > 8) {
avpriv_report_missing_feature(avctx,
"Undefined channel layout for %d channels",
- avctx->channels);
+ channels);
return AVERROR_PATCHWELCOME;
}
if (!avctx->bit_rate) {
@@ -177,10 +178,10 @@ static int av_cold libopus_encode_init(AVCodecContext *avctx)
"No bit rate set. Defaulting to %d bps.\n", avctx->bit_rate);
}
- if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * avctx->channels) {
+ if (avctx->bit_rate < 500 || avctx->bit_rate > 256000 * channels) {
av_log(avctx, AV_LOG_ERROR, "The bit rate %d bps is unsupported. "
"Please choose a value between 500 and %d.\n", avctx->bit_rate,
- 256000 * avctx->channels);
+ 256000 * channels);
return AVERROR(EINVAL);
}
@@ -245,7 +246,7 @@ static int av_cold libopus_encode_init(AVCodecContext *avctx)
}
}
- enc = opus_multistream_encoder_create(avctx->sample_rate, avctx->channels,
+ enc = opus_multistream_encoder_create(avctx->sample_rate, channels,
opus->stream_count,
coupled_stream_count,
channel_mapping,
@@ -262,7 +263,7 @@ static int av_cold libopus_encode_init(AVCodecContext *avctx)
goto fail;
}
- header_size = 19 + (avctx->channels > 2 ? 2 + avctx->channels : 0);
+ header_size = 19 + (channels > 2 ? 2 + channels : 0);
avctx->extradata = av_malloc(header_size + AV_INPUT_BUFFER_PADDING_SIZE);
if (!avctx->extradata) {
av_log(avctx, AV_LOG_ERROR, "Failed to allocate extradata.\n");
@@ -271,7 +272,7 @@ static int av_cold libopus_encode_init(AVCodecContext *avctx)
}
avctx->extradata_size = header_size;
- opus->samples = av_mallocz(frame_size * avctx->channels *
+ opus->samples = av_mallocz(frame_size * channels *
av_get_bytes_per_sample(avctx->sample_fmt));
if (!opus->samples) {
av_log(avctx, AV_LOG_ERROR, "Failed to allocate samples buffer.\n");
@@ -286,7 +287,7 @@ static int av_cold libopus_encode_init(AVCodecContext *avctx)
opus_strerror(ret));
libopus_write_header(avctx, opus->stream_count, coupled_stream_count,
- opus_vorbis_channel_map[avctx->channels - 1]);
+ opus_vorbis_channel_map[channels - 1]);
ff_af_queue_init(avctx, &opus->afq);
@@ -304,7 +305,7 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
const AVFrame *frame, int *got_packet_ptr)
{
LibopusEncContext *opus = avctx->priv_data;
- const int sample_size = avctx->channels *
+ const int sample_size = avctx->ch_layout.nb_channels *
av_get_bytes_per_sample(avctx->sample_fmt);
uint8_t *audio;
int ret;
@@ -418,7 +419,12 @@ AVCodec ff_libopus_encoder = {
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_FLT,
AV_SAMPLE_FMT_NONE },
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
.channel_layouts = ff_vorbis_channel_layouts,
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ .ch_layouts = ff_vorbis_ch_layouts,
.supported_samplerates = libopus_sample_rates,
.priv_class = &libopus_class,
.defaults = libopus_defaults,
diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c
index 949a9344c1..f3af4be50f 100644
--- a/libavcodec/libspeexdec.c
+++ b/libavcodec/libspeexdec.c
@@ -41,6 +41,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
LibSpeexContext *s = avctx->priv_data;
const SpeexMode *mode;
SpeexHeader *header = NULL;
+ int channels;
int spx_mode;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
@@ -51,10 +52,11 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_WARNING, "Invalid Speex header\n");
}
if (header) {
- avctx->channels = header->nb_channels;
+ channels = header->nb_channels;
spx_mode = header->mode;
speex_header_free(header);
} else {
+ channels = avctx->ch_layout.nb_channels;
switch (avctx->sample_rate) {
case 8000: spx_mode = 0; break;
case 16000: spx_mode = 1; break;
@@ -76,14 +78,14 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
avctx->sample_rate = 8000 << spx_mode;
s->frame_size = 160 << spx_mode;
- if (avctx->channels < 1 || avctx->channels > 2) {
+ if (channels < 1 || channels > 2) {
/* libspeex can handle mono or stereo if initialized as stereo */
av_log(avctx, AV_LOG_ERROR, "Invalid channel count: %d.\n"
- "Decoding as stereo.\n", avctx->channels);
- avctx->channels = 2;
+ "Decoding as stereo.\n", channels);
+ channels = 2;
}
- avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
- AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
speex_bits_init(&s->bits);
s->dec_state = speex_decoder_init(mode);
@@ -92,7 +94,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
return -1;
}
- if (avctx->channels == 2) {
+ if (channels == 2) {
SpeexCallback callback;
callback.callback_id = SPEEX_INBAND_STEREO;
callback.func = speex_std_stereo_request_handler;
@@ -144,7 +146,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
return AVERROR_INVALIDDATA;
}
- if (avctx->channels == 2)
+ if (avctx->ch_layout.nb_channels == 2)
speex_decode_stereo_int(output, s->frame_size, &s->stereo);
*got_frame_ptr = 1;
diff --git a/libavcodec/mace.c b/libavcodec/mace.c
index c6eddc05da..30ab57f3ac 100644
--- a/libavcodec/mace.c
+++ b/libavcodec/mace.c
@@ -226,7 +226,7 @@ static void chomp6(ChannelData *chd, int16_t *output, uint8_t val, int tab_idx)
static av_cold int mace_decode_init(AVCodecContext * avctx)
{
- if (avctx->channels > 2 || avctx->channels < 1)
+ if (avctx->ch_layout.nb_channels > 2 || avctx->ch_layout.nb_channels < 1)
return AVERROR(EINVAL);
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
@@ -239,26 +239,27 @@ static int mace_decode_frame(AVCodecContext *avctx, void *data,
AVFrame *frame = data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
+ int channels = avctx->ch_layout.nb_channels;
int16_t **samples;
MACEContext *ctx = avctx->priv_data;
int i, j, k, l, ret;
int is_mace3 = (avctx->codec_id == AV_CODEC_ID_MACE3);
/* get output buffer */
- frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels;
+ frame->nb_samples = 3 * (buf_size << (1 - is_mace3)) / channels;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
samples = (int16_t **)frame->extended_data;
- for(i = 0; i < avctx->channels; i++) {
+ for(i = 0; i < channels; i++) {
int16_t *output = samples[i];
- for (j=0; j < buf_size / (avctx->channels << is_mace3); j++)
+ for (j=0; j < buf_size / (channels << is_mace3); j++)
for (k=0; k < (1 << is_mace3); k++) {
uint8_t pkt = buf[(i << is_mace3) +
- (j*avctx->channels << is_mace3) + k];
+ (j * channels << is_mace3) + k];
uint8_t val[2][3] = {{pkt >> 5, (pkt >> 3) & 3, pkt & 7 },
{pkt & 7 , (pkt >> 3) & 3, pkt >> 5}};
diff --git a/libavcodec/metasound.c b/libavcodec/metasound.c
index 4cd9051dbd..b58e3087f4 100644
--- a/libavcodec/metasound.c
+++ b/libavcodec/metasound.c
@@ -65,8 +65,9 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
const float *shape, float *speech)
{
const TwinVQModeTab *mtab = tctx->mtab;
+ int channels = tctx->avctx->ch_layout.nb_channels;
int isampf = tctx->avctx->sample_rate / 1000;
- int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels);
+ int ibps = tctx->avctx->bit_rate / (1000 * channels);
int width;
float ratio = (float)mtab->size / isampf;
@@ -75,7 +76,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
float pgain_base, pgain_step, ppc_gain;
- if (tctx->avctx->channels == 1) {
+ if (channels == 1) {
min_period = log2(ratio * 0.2);
max_period = min_period + log2(6);
} else {
@@ -85,7 +86,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
period_range = max_period - min_period;
period = min_period + period_coef * period_range /
((1 << mtab->ppc_period_bit) - 1);
- if (tctx->avctx->channels == 1)
+ if (channels == 1)
period = powf(2.0, period);
else
period = (int)(period * 400 + 0.5) / 400.0;
@@ -103,7 +104,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
if (isampf == 22 && ibps == 32)
width = (int)((2.0 / period + 1) * width + 0.5);
- pgain_base = tctx->avctx->channels == 2 ? 25000.0 : 20000.0;
+ pgain_base = channels == 2 ? 25000.0 : 20000.0;
pgain_step = pgain_base / ((1 << mtab->pgain_bit) - 1);
ppc_gain = 1.0 / 8192 *
twinvq_mulawinv(pgain_step * g_coef + pgain_step / 2,
@@ -123,8 +124,9 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist,
int bark_n_coef = mtab->fmode[ftype].bark_n_coef;
int fw_cb_len = mtab->fmode[ftype].bark_env_size / bark_n_coef;
int idx = 0;
+ int channels = tctx->avctx->ch_layout.nb_channels;
- if (tctx->avctx->channels == 1)
+ if (channels == 1)
val = 0.5;
for (i = 0; i < fw_cb_len; i++)
for (j = 0; j < bark_n_coef; j++, idx++) {
@@ -132,7 +134,7 @@ static void dec_bark_env(TwinVQContext *tctx, const uint8_t *in, int use_hist,
(1.0 / 2048);
float st;
- if (tctx->avctx->channels == 1)
+ if (channels == 1)
st = use_hist ?
tmp2 + val * hist[idx] + 1.0 : tmp2 + 1.0;
else
@@ -167,7 +169,7 @@ static int metasound_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
{
TwinVQFrameData *bits;
const TwinVQModeTab *mtab = tctx->mtab;
- int channels = tctx->avctx->channels;
+ int channels = tctx->avctx->ch_layout.nb_channels;
int sub;
BitstreamContext bc;
int i, j, k;
@@ -275,6 +277,7 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
TwinVQContext *tctx = avctx->priv_data;
uint32_t tag;
const MetasoundProps *props = codec_props;
+ int channels;
if (!avctx->extradata || avctx->extradata_size < 16) {
av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
@@ -290,7 +293,7 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
}
if (props->tag == tag) {
avctx->sample_rate = props->sample_rate;
- avctx->channels = props->channels;
+ channels = props->channels;
avctx->bit_rate = props->bit_rate * 1000;
isampf = avctx->sample_rate / 1000;
break;
@@ -298,17 +301,17 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
props++;
}
- if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
+ if (channels <= 0 || channels > TWINVQ_CHANNELS_MAX) {
av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
- avctx->channels);
+ channels);
return AVERROR_INVALIDDATA;
}
- avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
- : AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
- ibps = avctx->bit_rate / (1000 * avctx->channels);
+ ibps = avctx->bit_rate / (1000 * channels);
- switch ((avctx->channels << 16) + (isampf << 8) + ibps) {
+ switch ((channels << 16) + (isampf << 8) + ibps) {
case (1 << 16) + ( 8 << 8) + 6:
tctx->mtab = &ff_metasound_mode0806;
break;
diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index bff6258cba..a7d6bba5bd 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -40,11 +40,6 @@ static const uint8_t mlp_quants[16] = {
0, 0, 0, 0, 0, 0, 0, 0,
};
-static const uint8_t mlp_channels[32] = {
- 1, 2, 3, 4, 3, 4, 5, 3, 4, 5, 4, 5, 6, 4, 5, 4,
- 5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
static const uint64_t mlp_layout[32] = {
AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
@@ -70,11 +65,6 @@ static const uint64_t mlp_layout[32] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
-static const uint8_t thd_chancount[13] = {
-// LR C LFE LRs LRvh LRc LRrs Cs Ts LRsd LRw Cvh LFE2
- 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1
-};
-
static const uint64_t thd_layout[13] = {
AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT, // LR
AV_CH_FRONT_CENTER, // C
@@ -99,16 +89,6 @@ static int mlp_samplerate(int in)
return (in & 8 ? 44100 : 48000) << (in & 7) ;
}
-static int truehd_channels(int chanmap)
-{
- int channels = 0, i;
-
- for (i = 0; i < 13; i++)
- channels += thd_chancount[i] * ((chanmap >> i) & 1);
-
- return channels;
-}
-
static uint64_t truehd_layout(int chanmap)
{
int i;
@@ -179,7 +159,6 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, BitstreamContext *bc)
bitstream_skip(bc, 11);
channel_arrangement = bitstream_read(bc, 5);
- mh->channels_mlp = mlp_channels[channel_arrangement];
mh->channel_layout_mlp = mlp_layout[channel_arrangement];
} else if (mh->stream_type == 0xba) {
mh->group1_bits = 24; // TODO: Is this information actually conveyed anywhere?
@@ -195,13 +174,11 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, BitstreamContext *bc)
mh->channel_modifier_thd_stream1 = bitstream_read(bc, 2);
channel_arrangement = bitstream_read(bc, 5);
- mh->channels_thd_stream1 = truehd_channels(channel_arrangement);
mh->channel_layout_thd_stream1 = truehd_layout(channel_arrangement);
mh->channel_modifier_thd_stream2 = bitstream_read(bc, 2);
channel_arrangement = bitstream_read(bc, 13);
- mh->channels_thd_stream2 = truehd_channels(channel_arrangement);
mh->channel_layout_thd_stream2 = truehd_layout(channel_arrangement);
} else
return AVERROR_INVALIDDATA;
@@ -346,16 +323,13 @@ static int mlp_parse(AVCodecParserContext *s,
if (mh.stream_type == 0xbb) {
/* MLP stream */
- avctx->channels = mh.channels_mlp;
- avctx->channel_layout = mh.channel_layout_mlp;
+ av_channel_layout_from_mask(&avctx->ch_layout, mh.channel_layout_mlp);
} else { /* mh.stream_type == 0xba */
/* TrueHD stream */
- if (!mh.channels_thd_stream2) {
- avctx->channels = mh.channels_thd_stream1;
- avctx->channel_layout = mh.channel_layout_thd_stream1;
+ if (!mh.channel_layout_thd_stream2) {
+ av_channel_layout_from_mask(&avctx->ch_layout, mh.channel_layout_thd_stream1);
} else {
- avctx->channels = mh.channels_thd_stream2;
- avctx->channel_layout = mh.channel_layout_thd_stream2;
+ av_channel_layout_from_mask(&avctx->ch_layout, mh.channel_layout_thd_stream2);
}
}
diff --git a/libavcodec/mlp_parser.h b/libavcodec/mlp_parser.h
index 871b96db20..5cca73f26f 100644
--- a/libavcodec/mlp_parser.h
+++ b/libavcodec/mlp_parser.h
@@ -28,6 +28,7 @@
#define AVCODEC_MLP_PARSER_H
#include "bitstream.h"
+#include "libavutil/channel_layout.h"
typedef struct MLPHeaderInfo
{
@@ -44,9 +45,6 @@ typedef struct MLPHeaderInfo
int channel_modifier_thd_stream1; ///< Channel modifier for substream 1 of TrueHD streams ("6-channel presentation")
int channel_modifier_thd_stream2; ///< Channel modifier for substream 2 of TrueHD streams ("8-channel presentation")
- int channels_mlp; ///< Channel count for MLP streams
- int channels_thd_stream1; ///< Channel count for substream 1 of TrueHD streams ("6-channel presentation")
- int channels_thd_stream2; ///< Channel count for substream 2 of TrueHD streams ("8-channel presentation")
uint64_t channel_layout_mlp; ///< Channel layout for MLP streams
uint64_t channel_layout_thd_stream1; ///< Channel layout for substream 1 of TrueHD streams ("6-channel presentation")
uint64_t channel_layout_thd_stream2; ///< Channel layout for substream 2 of TrueHD streams ("8-channel presentation")
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index b377fd7e2b..2b75ad61df 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -30,6 +30,7 @@
#include "libavutil/intreadwrite.h"
#include "libavutil/channel_layout.h"
#include "libavutil/crc.h"
+#include "libavutil/opt.h"
#include "avcodec.h"
#include "bitstream.h"
@@ -129,6 +130,7 @@ typedef struct SubStream {
} SubStream;
typedef struct MLPDecodeContext {
+ const AVClass *class;
AVCodecContext *avctx;
/// Current access unit being read has a major sync.
@@ -161,41 +163,14 @@ typedef struct MLPDecodeContext {
int32_t sample_buffer[MAX_BLOCKSIZE][MAX_CHANNELS];
MLPDSPContext dsp;
+ AVChannelLayout downmix_layout;
} MLPDecodeContext;
-static const uint64_t thd_channel_order[] = {
- AV_CH_FRONT_LEFT, AV_CH_FRONT_RIGHT, // LR
- AV_CH_FRONT_CENTER, // C
- AV_CH_LOW_FREQUENCY, // LFE
- AV_CH_SIDE_LEFT, AV_CH_SIDE_RIGHT, // LRs
- AV_CH_TOP_FRONT_LEFT, AV_CH_TOP_FRONT_RIGHT, // LRvh
- AV_CH_FRONT_LEFT_OF_CENTER, AV_CH_FRONT_RIGHT_OF_CENTER, // LRc
- AV_CH_BACK_LEFT, AV_CH_BACK_RIGHT, // LRrs
- AV_CH_BACK_CENTER, // Cs
- AV_CH_TOP_CENTER, // Ts
- AV_CH_SURROUND_DIRECT_LEFT, AV_CH_SURROUND_DIRECT_RIGHT, // LRsd
- AV_CH_WIDE_LEFT, AV_CH_WIDE_RIGHT, // LRw
- AV_CH_TOP_FRONT_CENTER, // Cvh
- AV_CH_LOW_FREQUENCY_2, // LFE2
-};
-
-static int mlp_channel_layout_subset(uint64_t channel_layout, uint64_t mask)
-{
- return channel_layout && ((channel_layout & mask) == channel_layout);
-}
-
-static uint64_t thd_channel_layout_extract_channel(uint64_t channel_layout,
- int index)
+static int mlp_channel_layout_subset(AVChannelLayout *ch_layout, uint64_t mask)
{
- int i;
-
- if (av_get_channel_layout_nb_channels(channel_layout) <= index)
- return 0;
-
- for (i = 0; i < FF_ARRAY_ELEMS(thd_channel_order); i++)
- if (channel_layout & thd_channel_order[i] && !index--)
- return thd_channel_order[i];
- return 0;
+ return av_channel_layout_check(ch_layout) &&
+ av_channel_layout_subset(ch_layout, mask) ==
+ av_channel_layout_subset(ch_layout, UINT64_MAX);
}
static VLC huff_vlc[3];
@@ -288,6 +263,14 @@ static av_cold int mlp_decode_init(AVCodecContext *avctx)
m->substream[substr].lossless_check_data = 0xffffffff;
ff_mlpdsp_init(&m->dsp);
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+ if (avctx->request_channel_layout) {
+ av_channel_layout_uninit(&m->downmix_layout);
+ av_channel_layout_from_mask(&m->downmix_layout, avctx->request_channel_layout);
+ }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
return 0;
}
@@ -517,7 +500,7 @@ static int read_restart_header(MLPDecodeContext *m, BitstreamContext *bc,
s->max_channel = max_channel;
s->max_matrix_channel = max_matrix_channel;
- if (mlp_channel_layout_subset(m->avctx->request_channel_layout, s->mask) &&
+ if (mlp_channel_layout_subset(&m->downmix_layout, s->mask) &&
m->max_decoded_substream > substr) {
av_log(m->avctx, AV_LOG_DEBUG,
"Extracting %d-channel downmix (0x%"PRIx64") from substream %d. "
@@ -549,10 +532,12 @@ static int read_restart_header(MLPDecodeContext *m, BitstreamContext *bc,
for (ch = 0; ch <= s->max_matrix_channel; ch++) {
int ch_assign = bitstream_read(bc, 6);
if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) {
- uint64_t channel = thd_channel_layout_extract_channel(s->mask,
- ch_assign);
- ch_assign = av_get_channel_layout_channel_index(s->mask,
- channel);
+ AVChannelLayout ch_layout = { 0 };
+ enum AVChannel channel;
+
+ av_channel_layout_from_mask(&ch_layout, s->mask);
+ channel = av_channel_layout_get_channel(&ch_layout, ch_assign);
+ ch_assign = av_channel_layout_channel_index(&ch_layout, channel);
}
if (ch_assign < 0 || ch_assign > s->max_matrix_channel) {
avpriv_request_sample(m->avctx,
@@ -592,14 +577,21 @@ static int read_restart_header(MLPDecodeContext *m, BitstreamContext *bc,
}
if (substr == m->max_decoded_substream) {
- m->avctx->channels = s->max_matrix_channel + 1;
- m->avctx->channel_layout = s->mask;
+ av_channel_layout_uninit(&m->avctx->ch_layout);
+ av_channel_layout_from_mask(&m->avctx->ch_layout, s->mask);
m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign,
s->output_shift,
s->max_matrix_channel,
m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
}
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+ m->avctx->channel_layout = m->avctx->ch_layout.u.mask;
+ m->avctx->channels = m->avctx->ch_layout.nb_channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
return 0;
}
@@ -1039,7 +1031,7 @@ static int output_data(MLPDecodeContext *m, unsigned int substr,
int ret;
int is32 = (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32);
- if (m->avctx->channels != s->max_matrix_channel + 1) {
+ if (m->avctx->ch_layout.nb_channels != s->max_matrix_channel + 1) {
av_log(m->avctx, AV_LOG_ERROR, "channel count mismatch\n");
return AVERROR_INVALIDDATA;
}
@@ -1273,24 +1265,48 @@ error:
return AVERROR_INVALIDDATA;
}
+#define OFFSET(x) offsetof(MLPDecodeContext, x)
+#define A AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption options[] = {
+ { "downmix", "Request a specific channel layout from the decoder",
+ OFFSET(downmix_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.str = NULL}, .flags = A },
+ { NULL },
+};
+
+static const AVClass mlpdec_class = {
+ .class_name = "MLP decoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_mlp_decoder = {
.name = "mlp",
.long_name = NULL_IF_CONFIG_SMALL("MLP (Meridian Lossless Packing)"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_MLP,
.priv_data_size = sizeof(MLPDecodeContext),
+ .priv_class = &mlpdec_class,
.init = mlp_decode_init,
.decode = read_access_unit,
.capabilities = AV_CODEC_CAP_DR1,
};
#if CONFIG_TRUEHD_DECODER
+static const AVClass thddec_class = {
+ .class_name = "TrueHD decoder",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVCodec ff_truehd_decoder = {
.name = "truehd",
.long_name = NULL_IF_CONFIG_SMALL("TrueHD"),
.type = AVMEDIA_TYPE_AUDIO,
.id = AV_CODEC_ID_TRUEHD,
.priv_data_size = sizeof(MLPDecodeContext),
+ .priv_class = &thddec_class,
.init = mlp_decode_init,
.decode = read_access_unit,
.capabilities = AV_CODEC_CAP_DR1,
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index ebc3f5293b..a0e2b2aa57 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -65,8 +65,8 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
static VLC_TYPE quant_tables[7224][2];
/* Musepack SV7 is always stereo */
- if (avctx->channels != 2) {
- avpriv_request_sample(avctx, "%d channels", avctx->channels);
+ if (avctx->ch_layout.nb_channels != 2) {
+ avpriv_request_sample(avctx, "%d channels", avctx->ch_layout.nb_channels);
return AVERROR_PATCHWELCOME;
}
@@ -97,7 +97,8 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
c->frames_to_skip = 0;
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
- avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
if(vlc_initialized) return 0;
av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index 649eb02e2e..affa240028 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -137,7 +137,8 @@ static av_cold int mpc8_decode_init(AVCodecContext * avctx)
c->frames = 1 << (bitstream_read(&bc, 3) * 2);
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
- avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
if(vlc_initialized) return 0;
av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
@@ -406,7 +407,7 @@ static int mpc8_decode_frame(AVCodecContext * avctx, void *data,
ff_mpc_dequantize_and_synth(c, maxband - 1,
(int16_t **)frame->extended_data,
- avctx->channels);
+ avctx->ch_layout.nb_channels);
c->cur_frame++;
diff --git a/libavcodec/mpegaudio_parser.c b/libavcodec/mpegaudio_parser.c
index c44c02417c..1da244789f 100644
--- a/libavcodec/mpegaudio_parser.c
+++ b/libavcodec/mpegaudio_parser.c
@@ -80,7 +80,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
if (s->header_count > 0) {
avctx->sample_rate= sr;
- avctx->channels = channels;
+ av_channel_layout_default(&avctx->ch_layout, channels);
s1->duration = frame_size;
if (s->no_bitrate || !avctx->bit_rate) {
s->no_bitrate = 1;
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index e9ea65eed1..b636e26ed5 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -1636,8 +1636,8 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
return AVERROR_INVALIDDATA;
}
/* update codec info */
- avctx->channels = s->nb_channels;
- avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, s->nb_channels);
if (!avctx->bit_rate)
avctx->bit_rate = s->bit_rate;
@@ -1707,8 +1707,9 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
}
/* update codec info */
avctx->sample_rate = s->sample_rate;
- avctx->channels = s->nb_channels;
- avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = s->nb_channels == 1 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO
+ : (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
if (!avctx->bit_rate)
avctx->bit_rate = s->bit_rate;
@@ -1760,15 +1761,15 @@ static const uint8_t chan_offset[8][5] = {
};
/* mp3on4 channel layouts */
-static const int16_t chan_layout[8] = {
- 0,
- AV_CH_LAYOUT_MONO,
- AV_CH_LAYOUT_STEREO,
- AV_CH_LAYOUT_SURROUND,
- AV_CH_LAYOUT_4POINT0,
- AV_CH_LAYOUT_5POINT0,
- AV_CH_LAYOUT_5POINT1,
- AV_CH_LAYOUT_7POINT1
+static const AVChannelLayout chan_layout[8] = {
+ { 0 },
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ AV_CHANNEL_LAYOUT_SURROUND,
+ AV_CHANNEL_LAYOUT_4POINT0,
+ AV_CHANNEL_LAYOUT_5POINT0,
+ AV_CHANNEL_LAYOUT_5POINT1,
+ AV_CHANNEL_LAYOUT_7POINT1
};
static av_cold int decode_close_mp3on4(AVCodecContext * avctx)
@@ -1802,8 +1803,8 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
}
s->frames = mp3Frames[cfg.chan_config];
s->coff = chan_offset[cfg.chan_config];
- avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
- avctx->channel_layout = chan_layout[cfg.chan_config];
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = chan_layout[cfg.chan_config];
if (cfg.sample_rate < 16000)
s->syncword = 0xffe00000;
@@ -1900,8 +1901,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
if (ret < 0) // Bad header, discard block
break;
- if (ch + m->nb_channels > avctx->channels ||
- s->coff[fr] + m->nb_channels > avctx->channels) {
+ if (ch + m->nb_channels > avctx->ch_layout.nb_channels ||
+ s->coff[fr] + m->nb_channels > avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
"channel count\n");
return AVERROR_INVALIDDATA;
@@ -1925,7 +1926,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
/* update codec info */
avctx->sample_rate = s->mp3decctx[0]->sample_rate;
- frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT));
+ frame->nb_samples = out_size / (avctx->ch_layout.nb_channels * sizeof(OUT_INT));
*got_frame_ptr = 1;
return buf_size;
diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c
index 2be8b7fd4c..72099d2b9b 100644
--- a/libavcodec/mpegaudioenc.c
+++ b/libavcodec/mpegaudioenc.c
@@ -73,7 +73,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
MpegAudioContext *s = avctx->priv_data;
int freq = avctx->sample_rate;
int bitrate = avctx->bit_rate;
- int channels = avctx->channels;
+ int channels = avctx->ch_layout.nb_channels;
int i, v, table;
float a;
@@ -760,8 +760,17 @@ AVCodec ff_mp2_encoder = {
.supported_samplerates = (const int[]){
44100, 48000, 32000, 22050, 24000, 16000, 0
},
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
.channel_layouts = (const uint64_t[]){ AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
0 },
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ .ch_layouts = (const AVChannelLayout[]){
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ { 0 },
+ },
.defaults = mp2_defaults,
};
diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c
index 8d9af5fff6..0fb0d7c7d2 100644
--- a/libavcodec/nellymoserdec.c
+++ b/libavcodec/nellymoserdec.c
@@ -130,8 +130,8 @@ static av_cold int decode_init(AVCodecContext * avctx) {
if (!ff_sine_128[127])
ff_init_ff_sine_windows(7);
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
return 0;
}
diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c
index 9d120816e0..948d928d7e 100644
--- a/libavcodec/nellymoserenc.c
+++ b/libavcodec/nellymoserenc.c
@@ -151,11 +151,6 @@ static av_cold int encode_init(AVCodecContext *avctx)
NellyMoserEncodeContext *s = avctx->priv_data;
int i, ret;
- if (avctx->channels != 1) {
- av_log(avctx, AV_LOG_ERROR, "Nellymoser supports only 1 channel\n");
- return AVERROR(EINVAL);
- }
-
if (avctx->sample_rate != 8000 && avctx->sample_rate != 16000 &&
avctx->sample_rate != 11025 &&
avctx->sample_rate != 22050 && avctx->sample_rate != 44100 &&
@@ -418,4 +413,5 @@ AVCodec ff_nellymoser_encoder = {
.capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT,
AV_SAMPLE_FMT_NONE },
+ .ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } },
};
diff --git a/libavcodec/on2avc.c b/libavcodec/on2avc.c
index 39ae1178f1..d543e5ba3f 100644
--- a/libavcodec/on2avc.c
+++ b/libavcodec/on2avc.c
@@ -801,6 +801,7 @@ static int on2avc_decode_subframe(On2AVCContext *c, const uint8_t *buf,
{
BitstreamContext bc;
int i, ret;
+ int channels = c->avctx->ch_layout.nb_channels;
bitstream_init8(&bc, buf, buf_size);
if (bitstream_read_bit(&bc)) {
@@ -809,7 +810,7 @@ static int on2avc_decode_subframe(On2AVCContext *c, const uint8_t *buf,
}
c->prev_window_type = c->window_type;
c->window_type = bitstream_read(&bc, 3);
- if (c->window_type >= WINDOW_TYPE_EXT4 && c->avctx->channels == 1) {
+ if (c->window_type >= WINDOW_TYPE_EXT4 && channels == 1) {
av_log(c->avctx, AV_LOG_ERROR, "stereo mode window for mono audio\n");
return AVERROR_INVALIDDATA;
}
@@ -824,13 +825,13 @@ static int on2avc_decode_subframe(On2AVCContext *c, const uint8_t *buf,
c->grouping[i] = !bitstream_read_bit(&bc);
on2avc_read_ms_info(c, &bc);
- for (i = 0; i < c->avctx->channels; i++)
+ for (i = 0; i < channels; i++)
if ((ret = on2avc_read_channel_data(c, &bc, i)) < 0)
return AVERROR_INVALIDDATA;
- if (c->avctx->channels == 2 && c->ms_present)
+ if (channels == 2 && c->ms_present)
on2avc_apply_ms(c);
if (c->window_type < WINDOW_TYPE_EXT4) {
- for (i = 0; i < c->avctx->channels; i++)
+ for (i = 0; i < channels; i++)
on2avc_reconstruct_channel(c, i, dst, offset);
} else {
on2avc_reconstruct_stereo(c, dst, offset);
@@ -917,19 +918,17 @@ static av_cold int on2avc_decode_init(AVCodecContext *avctx)
c->avctx = avctx;
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
- avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
- : AV_CH_LAYOUT_MONO;
c->is_av500 = (avctx->codec_tag == 0x500);
- if (c->is_av500 && avctx->channels == 2) {
+ if (c->is_av500 && avctx->ch_layout.nb_channels == 2) {
av_log(avctx, AV_LOG_ERROR, "0x500 version should be mono\n");
return AVERROR_INVALIDDATA;
}
- if (avctx->channels > 2) {
+ if (avctx->ch_layout.nb_channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Only 1 or 2 channels are supported.\n");
return AVERROR(EINVAL);
}
- if (avctx->channels == 2)
+ if (avctx->ch_layout.nb_channels == 2)
av_log(avctx, AV_LOG_WARNING,
"Stereo mode support is not good, patch is welcome\n");
@@ -938,7 +937,7 @@ static av_cold int on2avc_decode_init(AVCodecContext *avctx)
for (; i < 128; i++)
c->scale_tab[i] = ceil(pow(10.0, i * 0.1) * 0.5);
- if (avctx->sample_rate < 32000 || avctx->channels == 1)
+ if (avctx->sample_rate < 32000 || avctx->ch_layout.nb_channels == 1)
memcpy(c->long_win, ff_on2avc_window_long_24000,
1024 * sizeof(*c->long_win));
else
diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index 8e896dd5d4..308d104212 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -295,11 +295,12 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
const uint8_t *extradata, *channel_map;
int extradata_size;
- int version, channels, map_type, streams, stereo_streams, i, j;
+ int channels = avctx->ch_layout.nb_channels;
+ int version, map_type, streams, stereo_streams, i, j;
uint64_t layout;
if (!avctx->extradata) {
- if (avctx->channels > 2) {
+ if (channels > 2) {
av_log(avctx, AV_LOG_ERROR,
"Multichannel configuration without extradata.\n");
return AVERROR(EINVAL);
@@ -325,7 +326,7 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
avctx->delay = AV_RL16(extradata + 10);
- channels = avctx->extradata ? extradata[9] : (avctx->channels == 1) ? 1 : 2;
+ channels = avctx->extradata ? extradata[9] : (channels == 1) ? 1 : 2;
if (!channels) {
av_log(avctx, AV_LOG_ERROR, "Zero channel count specified in the extadata\n");
return AVERROR_INVALIDDATA;
@@ -368,7 +369,7 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
"Channel mapping 1 is only specified for up to 8 channels\n");
return AVERROR_INVALIDDATA;
}
- layout = ff_vorbis_channel_layouts[channels - 1];
+ layout = ff_vorbis_ch_layouts[channels - 1].u.mask;
channel_reorder = channel_reorder_vorbis;
} else
layout = 0;
@@ -414,8 +415,11 @@ av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
}
}
- avctx->channels = channels;
- avctx->channel_layout = layout;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ if (layout)
+ av_channel_layout_from_mask(&avctx->ch_layout, layout);
+ else
+ av_channel_layout_default(&avctx->ch_layout, channels);
s->nb_streams = streams;
s->nb_stereo_streams = stereo_streams;
diff --git a/libavcodec/opusdec.c b/libavcodec/opusdec.c
index 163f0d5ed5..4a3088beca 100644
--- a/libavcodec/opusdec.c
+++ b/libavcodec/opusdec.c
@@ -494,7 +494,7 @@ static int opus_decode_packet(AVCodecContext *avctx, void *data,
frame->nb_samples = 0;
memset(c->out, 0, c->nb_streams * 2 * sizeof(*c->out));
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
ChannelMap *map = &c->channel_maps[i];
if (!map->copy)
c->out[2 * map->stream_idx + map->channel_idx] = (float*)frame->extended_data[i];
@@ -575,7 +575,7 @@ static int opus_decode_packet(AVCodecContext *avctx, void *data,
}
}
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
ChannelMap *map = &c->channel_maps[i];
/* handle copied channels */
@@ -687,7 +687,7 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
for (i = 0; i < c->nb_streams; i++) {
OpusStreamContext *s = &c->streams[i];
- uint64_t layout;
+ AVChannelLayout ch_layout = { 0 };
s->output_channels = (i < c->nb_stereo_streams) ? 2 : 1;
@@ -705,11 +705,12 @@ static av_cold int opus_decode_init(AVCodecContext *avctx)
if (!s->avr)
goto fail;
- layout = (s->output_channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
+ av_channel_layout_from_mask(&ch_layout, (s->output_channels == 1) ? AV_CH_LAYOUT_MONO
+ : AV_CH_LAYOUT_STEREO);
+ av_opt_set_channel_layout(s->avr, "in_ch_layout", &ch_layout, 0);
+ av_opt_set_channel_layout(s->avr, "out_ch_layout", &ch_layout, 0);
av_opt_set_int(s->avr, "in_sample_fmt", avctx->sample_fmt, 0);
av_opt_set_int(s->avr, "out_sample_fmt", avctx->sample_fmt, 0);
- av_opt_set_int(s->avr, "in_channel_layout", layout, 0);
- av_opt_set_int(s->avr, "out_channel_layout", layout, 0);
av_opt_set_int(s->avr, "out_sample_rate", avctx->sample_rate, 0);
ret = ff_silk_init(avctx, &s->silk, s->output_channels);
diff --git a/libavcodec/pafaudio.c b/libavcodec/pafaudio.c
index c83e7f5cfc..4df5d4874f 100644
--- a/libavcodec/pafaudio.c
+++ b/libavcodec/pafaudio.c
@@ -30,12 +30,13 @@
static av_cold int paf_audio_init(AVCodecContext *avctx)
{
- if (avctx->channels != 2) {
+ if (avctx->ch_layout.nb_channels != 2) {
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
return AVERROR_INVALIDDATA;
}
- avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
diff --git a/libavcodec/pcm-bluray.c b/libavcodec/pcm-bluray.c
index 51fcd2d007..1878fe59b2 100644
--- a/libavcodec/pcm-bluray.c
+++ b/libavcodec/pcm-bluray.c
@@ -54,14 +54,12 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
const uint8_t *header)
{
static const uint8_t bits_per_samples[4] = { 0, 16, 20, 24 };
- static const uint32_t channel_layouts[16] = {
- 0, AV_CH_LAYOUT_MONO, 0, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_SURROUND,
- AV_CH_LAYOUT_2_1, AV_CH_LAYOUT_4POINT0, AV_CH_LAYOUT_2_2,
- AV_CH_LAYOUT_5POINT0, AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_7POINT0,
- AV_CH_LAYOUT_7POINT1, 0, 0, 0, 0
- };
- static const uint8_t channels[16] = {
- 0, 1, 0, 2, 3, 3, 4, 4, 5, 6, 7, 8, 0, 0, 0, 0
+ static const AVChannelLayout channel_layouts[16] = {
+ { 0 }, AV_CHANNEL_LAYOUT_MONO, { 0 },
+ AV_CHANNEL_LAYOUT_STEREO, AV_CHANNEL_LAYOUT_SURROUND, AV_CHANNEL_LAYOUT_2_1,
+ AV_CHANNEL_LAYOUT_4POINT0, AV_CHANNEL_LAYOUT_2_2, AV_CHANNEL_LAYOUT_5POINT0,
+ AV_CHANNEL_LAYOUT_5POINT1, AV_CHANNEL_LAYOUT_7POINT0, AV_CHANNEL_LAYOUT_7POINT1,
+ { 0 }, { 0 }, { 0 }, { 0 },
};
uint8_t channel_layout = header[2] >> 4;
@@ -103,21 +101,21 @@ static int pcm_bluray_parse_header(AVCodecContext *avctx,
* differ from the actual meaningful number, e.g. mono audio still has two
* channels, one being empty.
*/
- avctx->channel_layout = channel_layouts[channel_layout];
- avctx->channels = channels[channel_layout];
- if (!avctx->channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = channel_layouts[channel_layout];
+ if (!avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_ERROR, "reserved channel configuration (%d)\n",
channel_layout);
return AVERROR_INVALIDDATA;
}
- avctx->bit_rate = FFALIGN(avctx->channels, 2) * avctx->sample_rate *
+ avctx->bit_rate = FFALIGN(avctx->ch_layout.nb_channels, 2) * avctx->sample_rate *
avctx->bits_per_coded_sample;
if (avctx->debug & FF_DEBUG_PICT_INFO)
ff_dlog(avctx,
"pcm_bluray_parse_header: %d channels, %d bits per sample, %d Hz, %d bit/s\n",
- avctx->channels, avctx->bits_per_coded_sample,
+ avctx->ch_layout.nb_channels, avctx->bits_per_coded_sample,
avctx->sample_rate, avctx->bit_rate);
return 0;
}
@@ -147,7 +145,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
bytestream2_init(&gb, src, buf_size);
/* There's always an even number of channels in the source */
- num_source_channels = FFALIGN(avctx->channels, 2);
+ num_source_channels = FFALIGN(avctx->ch_layout.nb_channels, 2);
sample_size = (num_source_channels *
(avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3;
samples = buf_size / sample_size;
@@ -162,7 +160,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
dst32 = (int32_t *)frame->data[0];
if (samples) {
- switch (avctx->channel_layout) {
+ switch (avctx->ch_layout.u.mask) {
/* cases with same number of source and coded channels */
case AV_CH_LAYOUT_STEREO:
case AV_CH_LAYOUT_4POINT0:
@@ -190,10 +188,10 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) {
do {
#if HAVE_BIGENDIAN
- bytestream2_get_buffer(&gb, dst16, avctx->channels * 2);
- dst16 += avctx->channels;
+ bytestream2_get_buffer(&gb, dst16, avctx->ch_layout.nb_channels * 2);
+ dst16 += avctx->ch_layout.nb_channels;
#else
- channel = avctx->channels;
+ channel = avctx->ch_layout.nb_channels;
do {
*dst16++ = bytestream2_get_be16u(&gb);
} while (--channel);
@@ -202,7 +200,7 @@ static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data,
} while (--samples);
} else {
do {
- channel = avctx->channels;
+ channel = avctx->ch_layout.nb_channels;
do {
*dst32++ = bytestream2_get_be24u(&gb) << 8;
} while (--channel);
diff --git a/libavcodec/pcm-dvd.c b/libavcodec/pcm-dvd.c
index 62aacf829a..98254f846a 100644
--- a/libavcodec/pcm-dvd.c
+++ b/libavcodec/pcm-dvd.c
@@ -65,6 +65,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
static const uint32_t frequencies[4] = { 48000, 96000, 44100, 32000 };
PCMDVDContext *s = avctx->priv_data;
int header_int = (header[0] & 0xe0) | (header[1] << 8) | (header[2] << 16);
+ int channels;
/* early exit if the header didn't change apart from the frame number */
if (s->last_header == header_int)
@@ -96,9 +97,12 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
avctx->sample_rate = frequencies[header[1] >> 4 & 3];
/* get the number of channels */
- avctx->channels = 1 + (header[1] & 7);
+ channels = 1 + (header[1] & 7);
+
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
/* calculate the bitrate */
- avctx->bit_rate = avctx->channels *
+ avctx->bit_rate = channels *
avctx->sample_rate *
avctx->bits_per_coded_sample;
@@ -107,15 +111,15 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
* needed to complete a set of samples for each channel. */
if (avctx->bits_per_coded_sample == 16) {
s->samples_per_block = 1;
- s->block_size = avctx->channels * 2;
+ s->block_size = channels * 2;
} else {
- switch (avctx->channels) {
+ switch (channels) {
case 1:
case 2:
case 4:
/* one group has all the samples needed */
s->block_size = 4 * avctx->bits_per_coded_sample / 8;
- s->samples_per_block = 4 / avctx->channels;
+ s->samples_per_block = 4 / channels;
s->groups_per_block = 1;
break;
case 8:
@@ -125,11 +129,11 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
s->groups_per_block = 2;
break;
default:
- /* need avctx->channels groups */
- s->block_size = 4 * avctx->channels *
+ /* need channels groups */
+ s->block_size = 4 * channels *
avctx->bits_per_coded_sample / 8;
s->samples_per_block = 4;
- s->groups_per_block = avctx->channels;
+ s->groups_per_block = channels;
break;
}
}
@@ -137,7 +141,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
if (avctx->debug & FF_DEBUG_PICT_INFO)
ff_dlog(avctx,
"pcm_dvd_parse_header: %d channels, %d bits per sample, %d Hz, %d bit/s\n",
- avctx->channels, avctx->bits_per_coded_sample,
+ channels, avctx->bits_per_coded_sample,
avctx->sample_rate, avctx->bit_rate);
s->last_header = header_int;
@@ -162,7 +166,7 @@ static void *pcm_dvd_decode_samples(AVCodecContext *avctx, const uint8_t *src,
bytestream2_get_buffer(&gb, dst16, blocks * s->block_size);
dst16 += blocks * s->block_size / 2;
#else
- int samples = blocks * avctx->channels;
+ int samples = blocks * avctx->ch_layout.nb_channels;
do {
*dst16++ = bytestream2_get_be16u(&gb);
} while (--samples);
diff --git a/libavcodec/pcm.c b/libavcodec/pcm.c
index 959c50b279..792f00a74c 100644
--- a/libavcodec/pcm.c
+++ b/libavcodec/pcm.c
@@ -46,7 +46,7 @@ static av_cold int pcm_encode_init(AVCodecContext *avctx)
}
avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id);
- avctx->block_align = avctx->channels * avctx->bits_per_coded_sample / 8;
+ avctx->block_align = avctx->ch_layout.nb_channels * avctx->bits_per_coded_sample / 8;
avctx->bit_rate = avctx->block_align * avctx->sample_rate * 8;
return 0;
@@ -83,7 +83,7 @@ static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
const uint32_t *samples_uint32_t;
sample_size = av_get_bits_per_sample(avctx->codec->id) / 8;
- n = frame->nb_samples * avctx->channels;
+ n = frame->nb_samples * avctx->ch_layout.nb_channels;
samples = (const short *)frame->data[0];
if ((ret = ff_alloc_packet(avpkt, n * sample_size))) {
@@ -197,7 +197,7 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
PCMDecode *s = avctx->priv_data;
int i;
- if (avctx->channels <= 0) {
+ if (avctx->ch_layout.nb_channels <= 0) {
av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n");
return AVERROR(EINVAL);
}
@@ -244,8 +244,8 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
{ \
int n2; \
- n /= avctx->channels; \
- for (c = 0; c < avctx->channels; c++) { \
+ n /= channels; \
+ for (c = 0; c < channels; c++) { \
samples = frame->extended_data[c]; \
n2 = n; \
DECODE(size, endian, src, samples, n2, 0, 0) \
@@ -254,8 +254,8 @@ static av_cold int pcm_decode_init(AVCodecContext *avctx)
#else
#define DECODE_PLANAR(size, endian, src, dst, n, shift, offset) \
{ \
- n /= avctx->channels; \
- for (c = 0; c < avctx->channels; c++) { \
+ n /= channels; \
+ for (c = 0; c < channels; c++) { \
samples = frame->extended_data[c]; \
memcpy(samples, src, n * size / 8); \
src += n * size / 8; \
@@ -270,6 +270,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
int buf_size = avpkt->size;
PCMDecode *s = avctx->priv_data;
AVFrame *frame = data;
+ int channels = avctx->ch_layout.nb_channels;
int sample_size, c, n, ret, samples_per_block;
uint8_t *samples;
int32_t *dst_int32_t;
@@ -289,7 +290,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
return AVERROR(EINVAL);
}
- n = avctx->channels * sample_size;
+ n = channels * sample_size;
if (n && buf_size % n) {
if (buf_size < n) {
@@ -302,7 +303,7 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
n = buf_size / sample_size;
/* get output buffer */
- frame->nb_samples = n * samples_per_block / avctx->channels;
+ frame->nb_samples = n * samples_per_block / channels;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
@@ -411,8 +412,8 @@ static int pcm_decode_frame(AVCodecContext *avctx, void *data,
case AV_CODEC_ID_PCM_LXF:
{
int i;
- n /= avctx->channels;
- for (c = 0; c < avctx->channels; c++) {
+ n /= channels;
+ for (c = 0; c < channels; c++) {
dst_int32_t = (int32_t *)frame->extended_data[c];
for (i = 0; i < n; i++) {
// extract low 20 bits and expand to 32 bits
diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c
index 5179ede083..01f4fd2b6a 100644
--- a/libavcodec/psymodel.c
+++ b/libavcodec/psymodel.c
@@ -35,7 +35,7 @@ av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
int i, j, k = 0;
ctx->avctx = avctx;
- ctx->ch = av_mallocz(sizeof(ctx->ch[0]) * avctx->channels * 2);
+ ctx->ch = av_mallocz(sizeof(ctx->ch[0]) * avctx->ch_layout.nb_channels * 2);
ctx->group = av_mallocz(sizeof(ctx->group[0]) * num_groups);
ctx->bands = av_malloc (sizeof(ctx->bands[0]) * num_lens);
ctx->num_bands = av_malloc (sizeof(ctx->num_bands[0]) * num_lens);
@@ -116,12 +116,12 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av
FF_FILTER_MODE_LOWPASS, FILT_ORDER,
cutoff_coeff, 0.0, 0.0);
if (ctx->fcoeffs) {
- ctx->fstate = av_mallocz(sizeof(ctx->fstate[0]) * avctx->channels);
+ ctx->fstate = av_mallocz(sizeof(ctx->fstate[0]) * avctx->ch_layout.nb_channels);
if (!ctx->fstate) {
av_free(ctx);
return NULL;
}
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++)
ctx->fstate[i] = ff_iir_filter_init_state(FILT_ORDER);
}
return ctx;
@@ -144,7 +144,7 @@ av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
int i;
ff_iir_filter_free_coeffs(ctx->fcoeffs);
if (ctx->fstate)
- for (i = 0; i < ctx->avctx->channels; i++)
+ for (i = 0; i < ctx->avctx->ch_layout.nb_channels; i++)
ff_iir_filter_free_state(ctx->fstate[i]);
av_freep(&ctx->fstate);
av_free(ctx);
diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index 83be57a427..4d82e623e0 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -90,8 +90,8 @@ static av_cold int qcelp_decode_init(AVCodecContext *avctx)
QCELPContext *q = avctx->priv_data;
int i;
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
for (i = 0; i < 10; i++)
diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 668e513a66..7dca4863a5 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -1811,12 +1811,12 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
extradata += 8;
- avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata);
+ s->nb_channels = s->channels = AV_RB32(extradata);
extradata += 4;
if (s->channels <= 0 || s->channels > MPA_MAX_CHANNELS)
return AVERROR_INVALIDDATA;
- avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO :
- AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, s->channels);
avctx->sample_rate = AV_RB32(extradata);
extradata += 4;
diff --git a/libavcodec/ra144dec.c b/libavcodec/ra144dec.c
index 05165bf2e4..95b9a9445e 100644
--- a/libavcodec/ra144dec.c
+++ b/libavcodec/ra144dec.c
@@ -39,8 +39,8 @@ static av_cold int ra144_decode_init(AVCodecContext * avctx)
ractx->lpc_coef[0] = ractx->lpc_tables[0];
ractx->lpc_coef[1] = ractx->lpc_tables[1];
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
return 0;
diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c
index 678e6684ba..c60fb7d466 100644
--- a/libavcodec/ra144enc.c
+++ b/libavcodec/ra144enc.c
@@ -50,11 +50,6 @@ static av_cold int ra144_encode_init(AVCodecContext * avctx)
RA144Context *ractx;
int ret;
- if (avctx->channels != 1) {
- av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n",
- avctx->channels);
- return -1;
- }
avctx->frame_size = NBLOCKS * BLOCKSIZE;
avctx->initial_padding = avctx->frame_size;
avctx->bit_rate = 8000;
@@ -556,4 +551,5 @@ AVCodec ff_ra_144_encoder = {
.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SMALL_LAST_FRAME,
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_NONE },
+ .ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO, { 0 } },
};
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index c457d0c710..0058f2bef1 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -64,8 +64,8 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx)
{
RA288Context *ractx = avctx->priv_data;
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
avpriv_float_dsp_init(&ractx->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
diff --git a/libavcodec/ralf.c b/libavcodec/ralf.c
index 1003b10c11..7597eb36db 100644
--- a/libavcodec/ralf.c
+++ b/libavcodec/ralf.c
@@ -130,7 +130,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
{
RALFContext *ctx = avctx->priv_data;
int i, j, k;
- int ret;
+ int ret, channels;
if (avctx->extradata_size < 24 || memcmp(avctx->extradata, "LSD:", 4)) {
av_log(avctx, AV_LOG_ERROR, "Extradata is not groovy, dude\n");
@@ -143,17 +143,17 @@ static av_cold int decode_init(AVCodecContext *avctx)
return AVERROR_PATCHWELCOME;
}
- avctx->channels = AV_RB16(avctx->extradata + 8);
+ channels = AV_RB16(avctx->extradata + 8);
avctx->sample_rate = AV_RB32(avctx->extradata + 12);
- if (avctx->channels < 1 || avctx->channels > 2
+ if (channels < 1 || channels > 2
|| avctx->sample_rate < 8000 || avctx->sample_rate > 96000) {
av_log(avctx, AV_LOG_ERROR, "Invalid coding parameters %d Hz %d ch\n",
- avctx->sample_rate, avctx->channels);
+ avctx->sample_rate, channels);
return AVERROR_INVALIDDATA;
}
avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
- avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
- : AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
ctx->max_frame_size = AV_RB32(avctx->extradata + 16);
if (ctx->max_frame_size > (1 << 20) || !ctx->max_frame_size) {
@@ -357,7 +357,7 @@ static int decode_block(AVCodecContext *avctx, BitstreamContext *bc,
return AVERROR_INVALIDDATA;
}
- if (avctx->channels > 1)
+ if (avctx->ch_layout.nb_channels > 1)
dmode = bitstream_read(bc, 2) + 1;
else
dmode = 0;
@@ -367,7 +367,7 @@ static int decode_block(AVCodecContext *avctx, BitstreamContext *bc,
bits[0] = 16;
bits[1] = (mode[1] == 2) ? 17 : 16;
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
if ((ret = decode_channel(ctx, bc, ch, len, mode[ch], bits[ch])) < 0)
return ret;
if (ctx->filter_params > 1 && ctx->filter_params != FILTER_RAW) {
diff --git a/libavcodec/roqaudioenc.c b/libavcodec/roqaudioenc.c
index f687f5cd9d..eb81d621a3 100644
--- a/libavcodec/roqaudioenc.c
+++ b/libavcodec/roqaudioenc.c
@@ -53,9 +53,10 @@ static av_cold int roq_dpcm_encode_close(AVCodecContext *avctx)
static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
{
ROQDPCMContext *context = avctx->priv_data;
+ int channels = avctx->ch_layout.nb_channels;
int ret;
- if (avctx->channels > 2) {
+ if (channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n");
return AVERROR(EINVAL);
}
@@ -65,10 +66,10 @@ static av_cold int roq_dpcm_encode_init(AVCodecContext *avctx)
}
avctx->frame_size = ROQ_FRAME_SIZE;
- avctx->bit_rate = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * avctx->channels) *
+ avctx->bit_rate = (ROQ_HEADER_SIZE + ROQ_FRAME_SIZE * channels) *
(22050 / ROQ_FRAME_SIZE) * 8;
- context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * avctx->channels *
+ context->frame_buffer = av_malloc(8 * ROQ_FRAME_SIZE * channels *
sizeof(*context->frame_buffer));
if (!context->frame_buffer) {
ret = AVERROR(ENOMEM);
@@ -128,17 +129,18 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
{
int i, stereo, data_size, ret;
const int16_t *in = frame ? (const int16_t *)frame->data[0] : NULL;
+ int channels = avctx->ch_layout.nb_channels;
uint8_t *out;
ROQDPCMContext *context = avctx->priv_data;
- stereo = (avctx->channels == 2);
+ stereo = (channels == 2);
if (!in && context->input_frames >= 8)
return 0;
if (in && context->input_frames < 8) {
- memcpy(&context->frame_buffer[context->buffered_samples * avctx->channels],
- in, avctx->frame_size * avctx->channels * sizeof(*in));
+ memcpy(&context->frame_buffer[context->buffered_samples * channels],
+ in, avctx->frame_size * channels * sizeof(*in));
context->buffered_samples += avctx->frame_size;
if (context->input_frames == 0)
context->first_pts = frame->pts;
@@ -156,9 +158,9 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
}
if (context->input_frames == 7)
- data_size = avctx->channels * context->buffered_samples;
+ data_size = channels * context->buffered_samples;
else
- data_size = avctx->channels * avctx->frame_size;
+ data_size = channels * avctx->frame_size;
if ((ret = ff_alloc_packet(avpkt, ROQ_HEADER_SIZE + data_size))) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
@@ -181,7 +183,7 @@ static int roq_dpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
*out++ = dpcm_predict(&context->lastSample[i & 1], *in++);
avpkt->pts = context->input_frames <= 7 ? context->first_pts : frame->pts;
- avpkt->duration = data_size / avctx->channels;
+ avpkt->duration = data_size / channels;
context->input_frames++;
if (!in)
diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index 635f697b5c..08e561f95d 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -65,11 +65,15 @@ static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf,
else
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
- avctx->channels = channels;
+ if (avctx->ch_layout.nb_channels != channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ avctx->ch_layout.nb_channels = channels;
+ }
avctx->sample_rate = 48000;
- avctx->bit_rate = 48000 * avctx->channels * (avctx->bits_per_coded_sample + 4) +
+ avctx->bit_rate = 48000 * channels * (avctx->bits_per_coded_sample + 4) +
32 * (48000 / (buf_size * 8 /
- (avctx->channels *
+ (channels *
(avctx->bits_per_coded_sample + 4))));
return frame_size;
@@ -92,13 +96,14 @@ static int s302m_decode_frame(AVCodecContext *avctx, void *data,
/* get output buffer */
block_size = (avctx->bits_per_coded_sample + 4) / 4;
- frame->nb_samples = 2 * (buf_size / block_size) / avctx->channels;
+ frame->nb_samples = 2 * (buf_size / block_size) /
+ avctx->ch_layout.nb_channels;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
- buf_size = (frame->nb_samples * avctx->channels / 2) * block_size;
+ buf_size = (frame->nb_samples * avctx->ch_layout.nb_channels / 2) * block_size;
if (avctx->bits_per_coded_sample == 24) {
uint32_t *o = (uint32_t *)frame->data[0];
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c
index e040b9cfed..21baf175ab 100644
--- a/libavcodec/shorten.c
+++ b/libavcodec/shorten.c
@@ -354,7 +354,11 @@ static int read_header(ShortenContext *s)
s->channels = 0;
return AVERROR_INVALIDDATA;
}
- s->avctx->channels = s->channels;
+ if (s->avctx->ch_layout.nb_channels != s->channels) {
+ av_channel_layout_uninit(&s->avctx->ch_layout);
+ s->avctx->ch_layout.nb_channels = s->channels;
+ s->avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ }
/* get blocksize if version > 0 */
if (s->version > 0) {
diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
index 5d2bdbdcba..a31b6f93dd 100644
--- a/libavcodec/sipr.c
+++ b/libavcodec/sipr.c
@@ -512,8 +512,8 @@ static av_cold int sipr_decoder_init(AVCodecContext * avctx)
for (i = 0; i < 4; i++)
ctx->energy_history[i] = -14;
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
return 0;
diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 0e057a1c2a..e3f746710a 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -583,11 +583,13 @@ static av_cold int decode_init(AVCodecContext *avctx)
static av_cold int smka_decode_init(AVCodecContext *avctx)
{
- if (avctx->channels < 1 || avctx->channels > 2) {
+ int channels = avctx->ch_layout.nb_channels;
+ if (channels < 1 || channels > 2) {
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
return AVERROR_INVALIDDATA;
}
- avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16;
return 0;
@@ -627,9 +629,10 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data,
*got_frame_ptr = 0;
return 1;
}
+
stereo = bitstream_read_bit(&bc);
bits = bitstream_read_bit(&bc);
- if (stereo ^ (avctx->channels != 1)) {
+ if (stereo ^ (avctx->ch_layout.nb_channels != 1)) {
av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
return AVERROR_INVALIDDATA;
}
@@ -644,7 +647,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data,
}
/* get output buffer */
- frame->nb_samples = unp_size / (avctx->channels * (bits + 1));
+ frame->nb_samples = unp_size / (avctx->ch_layout.nb_channels * (bits + 1));
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
diff --git a/libavcodec/takdec.c b/libavcodec/takdec.c
index 11c04f4ff4..ad7c176b62 100644
--- a/libavcodec/takdec.c
+++ b/libavcodec/takdec.c
@@ -737,9 +737,13 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
avctx->sample_rate = s->ti.sample_rate;
set_sample_rate_params(avctx);
}
- if (s->ti.ch_layout)
- avctx->channel_layout = s->ti.ch_layout;
- avctx->channels = s->ti.channels;
+
+ av_channel_layout_uninit(&avctx->ch_layout);
+ if (s->ti.ch_layout) {
+ av_channel_layout_from_mask(&avctx->ch_layout, s->ti.ch_layout);
+ } else {
+ av_channel_layout_default(&avctx->ch_layout, s->ti.channels);
+ }
s->nb_samples = s->ti.last_frame_samples ? s->ti.last_frame_samples
: s->ti.frame_samples;
@@ -749,7 +753,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
return ret;
if (avctx->bits_per_coded_sample <= 16) {
- int buf_size = av_samples_get_buffer_size(NULL, avctx->channels,
+ int buf_size = av_samples_get_buffer_size(NULL, s->ti.channels,
s->nb_samples,
AV_SAMPLE_FMT_S32P, 0);
if (buf_size < 0)
@@ -758,28 +762,28 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
if (!s->decode_buffer)
return AVERROR(ENOMEM);
ret = av_samples_fill_arrays((uint8_t **)s->decoded, NULL,
- s->decode_buffer, avctx->channels,
+ s->decode_buffer, s->ti.channels,
s->nb_samples, AV_SAMPLE_FMT_S32P, 0);
if (ret < 0)
return ret;
} else {
- for (chan = 0; chan < avctx->channels; chan++)
+ for (chan = 0; chan < s->ti.channels; chan++)
s->decoded[chan] = (int32_t *)frame->extended_data[chan];
}
if (s->nb_samples < 16) {
- for (chan = 0; chan < avctx->channels; chan++) {
+ for (chan = 0; chan < s->ti.channels; chan++) {
int32_t *decoded = s->decoded[chan];
for (i = 0; i < s->nb_samples; i++)
decoded[i] = bitstream_read_signed(bc, avctx->bits_per_coded_sample);
}
} else {
if (s->ti.codec == TAK_CODEC_MONO_STEREO) {
- for (chan = 0; chan < avctx->channels; chan++)
+ for (chan = 0; chan < s->ti.channels; chan++)
if (ret = decode_channel(s, chan))
return ret;
- if (avctx->channels == 2) {
+ if (avctx->ch_layout.nb_channels == 2) {
if (bitstream_read_bit(bc)) {
// some kind of subframe length, but it seems to be unused
bitstream_skip(bc, 6);
@@ -794,13 +798,13 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
int ch_mask = 0;
chan = bitstream_read(bc, 4) + 1;
- if (chan > avctx->channels)
+ if (chan > s->ti.channels)
return AVERROR_INVALIDDATA;
for (i = 0; i < chan; i++) {
int nbit = bitstream_read(bc, 4);
- if (nbit >= avctx->channels)
+ if (nbit >= s->ti.channels)
return AVERROR_INVALIDDATA;
if (ch_mask & 1 << nbit)
@@ -810,10 +814,10 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
if (s->mcdparams[i].present) {
s->mcdparams[i].index = bitstream_read(bc, 2);
s->mcdparams[i].chan2 = bitstream_read(bc, 4);
- if (s->mcdparams[i].chan2 >= avctx->channels) {
+ if (s->mcdparams[i].chan2 >= avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_ERROR,
"invalid channel 2 (%d) for %d channel(s)\n",
- s->mcdparams[i].chan2, avctx->channels);
+ s->mcdparams[i].chan2, avctx->ch_layout.nb_channels);
return AVERROR_INVALIDDATA;
}
if (s->mcdparams[i].index == 1) {
@@ -831,7 +835,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
ch_mask |= 1 << nbit;
}
} else {
- chan = avctx->channels;
+ chan = s->ti.channels;
for (i = 0; i < chan; i++) {
s->mcdparams[i].present = 0;
s->mcdparams[i].chan1 = i;
@@ -857,7 +861,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
}
}
- for (chan = 0; chan < avctx->channels; chan++) {
+ for (chan = 0; chan < s->ti.channels; chan++) {
int32_t *decoded = s->decoded[chan];
if (s->lpc_mode[chan])
@@ -888,7 +892,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
/* convert to output buffer */
switch (avctx->sample_fmt) {
case AV_SAMPLE_FMT_U8P:
- for (chan = 0; chan < avctx->channels; chan++) {
+ for (chan = 0; chan < s->ti.channels; chan++) {
uint8_t *samples = (uint8_t *)frame->extended_data[chan];
int32_t *decoded = s->decoded[chan];
for (i = 0; i < s->nb_samples; i++)
@@ -896,7 +900,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
}
break;
case AV_SAMPLE_FMT_S16P:
- for (chan = 0; chan < avctx->channels; chan++) {
+ for (chan = 0; chan < s->ti.channels; chan++) {
int16_t *samples = (int16_t *)frame->extended_data[chan];
int32_t *decoded = s->decoded[chan];
for (i = 0; i < s->nb_samples; i++)
@@ -904,7 +908,7 @@ static int tak_decode_frame(AVCodecContext *avctx, void *data,
}
break;
case AV_SAMPLE_FMT_S32P:
- for (chan = 0; chan < avctx->channels; chan++) {
+ for (chan = 0; chan < s->ti.channels; chan++) {
int32_t *samples = (int32_t *)frame->extended_data[chan];
for (i = 0; i < s->nb_samples; i++)
samples[i] <<= 8;
diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c
index 6b9afaedda..0512918fd8 100644
--- a/libavcodec/truespeech.c
+++ b/libavcodec/truespeech.c
@@ -64,12 +64,13 @@ static av_cold int truespeech_decode_init(AVCodecContext * avctx)
{
TSContext *c = avctx->priv_data;
- if (avctx->channels != 1) {
- avpriv_request_sample(avctx, "Channel count %d", avctx->channels);
+ if (avctx->ch_layout.nb_channels != 1) {
+ avpriv_request_sample(avctx, "Channel count %d", avctx->ch_layout.nb_channels);
return AVERROR_PATCHWELCOME;
}
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
ff_bswapdsp_init(&c->bdsp);
diff --git a/libavcodec/tta.c b/libavcodec/tta.c
index db5e094a2e..0f2b425a3c 100644
--- a/libavcodec/tta.c
+++ b/libavcodec/tta.c
@@ -216,9 +216,16 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
avpriv_report_missing_feature(s->avctx, "Encrypted TTA");
return AVERROR_PATCHWELCOME;
}
- avctx->channels =
- s->channels = bitstream_read(&s->bc, 16);
+
+ s->channels = bitstream_read(&s->bc, 16);
+ if (avctx->ch_layout.nb_channels != s->channels) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ avctx->ch_layout.nb_channels = s->channels;
+ }
+
avctx->bits_per_coded_sample = bitstream_read(&s->bc, 16);
+
s->bps = (avctx->bits_per_coded_sample + 7) / 8;
avctx->sample_rate = bitstream_read(&s->bc, 32);
s->data_length = bitstream_read(&s->bc, 32);
@@ -258,7 +265,7 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
(s->last_frame_length ? 1 : 0);
av_log(s->avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d block: %d\n",
- s->format, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate,
+ s->format, s->channels, avctx->bits_per_coded_sample, avctx->sample_rate,
avctx->block_align);
av_log(s->avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n",
s->data_length, s->frame_length, s->last_frame_length, total_frames);
@@ -285,7 +292,7 @@ static av_cold int tta_decode_init(AVCodecContext * avctx)
if (!s->decode_buffer)
return AVERROR(ENOMEM);
}
- s->ch_ctx = av_malloc(avctx->channels * sizeof(*s->ch_ctx));
+ s->ch_ctx = av_malloc(s->channels * sizeof(*s->ch_ctx));
if (!s->ch_ctx) {
av_freep(&s->decode_buffer);
return AVERROR(ENOMEM);
diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c
index 940def45f5..c19bb1f66c 100644
--- a/libavcodec/twinvq.c
+++ b/libavcodec/twinvq.c
@@ -217,17 +217,18 @@ static void dec_gain(TwinVQContext *tctx,
const TwinVQModeTab *mtab = tctx->mtab;
const TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame];
int i, j;
+ int channels = tctx->avctx->ch_layout.nb_channels;
int sub = mtab->fmode[ftype].sub;
float step = TWINVQ_AMP_MAX / ((1 << TWINVQ_GAIN_BITS) - 1);
float sub_step = TWINVQ_SUB_AMP_MAX / ((1 << TWINVQ_SUB_GAIN_BITS) - 1);
if (ftype == TWINVQ_FT_LONG) {
- for (i = 0; i < tctx->avctx->channels; i++)
+ for (i = 0; i < channels; i++)
out[i] = (1.0 / (1 << 13)) *
twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
TWINVQ_AMP_MAX, TWINVQ_MULAW_MU);
} else {
- for (i = 0; i < tctx->avctx->channels; i++) {
+ for (i = 0; i < channels; i++) {
float val = (1.0 / (1 << 23)) *
twinvq_mulawinv(step * 0.5 + step * bits->gain_bits[i],
TWINVQ_AMP_MAX, TWINVQ_MULAW_MU);
@@ -380,10 +381,11 @@ static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype,
{
const TwinVQModeTab *mtab = tctx->mtab;
float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0];
+ int channels = tctx->avctx->ch_layout.nb_channels;
int size1, size2, i;
float *out1, *out2;
- for (i = 0; i < tctx->avctx->channels; i++)
+ for (i = 0; i < channels; i++)
imdct_and_window(tctx, ftype, wtype,
tctx->spectrum + i * mtab->size,
prev_buf + 2 * i * mtab->size,
@@ -399,7 +401,7 @@ static void imdct_output(TwinVQContext *tctx, enum TwinVQFrameType ftype,
memcpy(out1, prev_buf, size1 * sizeof(*out1));
memcpy(out1 + size1, tctx->curr_frame, size2 * sizeof(*out1));
- if (tctx->avctx->channels == 2) {
+ if (channels == 2) {
out2 = &out[1][0] + offset;
memcpy(out2, &prev_buf[2 * mtab->size],
size1 * sizeof(*out2));
@@ -414,7 +416,7 @@ static void read_and_decode_spectrum(TwinVQContext *tctx, float *out,
{
const TwinVQModeTab *mtab = tctx->mtab;
TwinVQFrameData *bits = &tctx->bits[tctx->cur_frame];
- int channels = tctx->avctx->channels;
+ int channels = tctx->avctx->ch_layout.nb_channels;
int sub = mtab->fmode[ftype].sub;
int block_size = mtab->size / sub;
float gain[TWINVQ_CHANNELS_MAX * TWINVQ_SUBBLOCKS_MAX];
@@ -538,7 +540,7 @@ static av_cold int init_mdct_win(TwinVQContext *tctx)
const TwinVQModeTab *mtab = tctx->mtab;
int size_s = mtab->size / mtab->fmode[TWINVQ_FT_SHORT].sub;
int size_m = mtab->size / mtab->fmode[TWINVQ_FT_MEDIUM].sub;
- int channels = tctx->avctx->channels;
+ int channels = tctx->avctx->ch_layout.nb_channels;
float norm = channels == 1 ? 2.0 : 1.0;
for (i = 0; i < 3; i++) {
@@ -657,10 +659,10 @@ static av_cold void construct_perm_table(TwinVQContext *tctx,
int16_t *tmp_perm = (int16_t *)tctx->tmp_buf;
if (ftype == TWINVQ_FT_PPC) {
- size = tctx->avctx->channels;
+ size = tctx->avctx->ch_layout.nb_channels;
block_size = mtab->ppc_shape_len;
} else {
- size = tctx->avctx->channels * mtab->fmode[ftype].sub;
+ size = tctx->avctx->ch_layout.nb_channels * mtab->fmode[ftype].sub;
block_size = mtab->size / mtab->fmode[ftype].sub;
}
@@ -678,7 +680,7 @@ static av_cold void construct_perm_table(TwinVQContext *tctx,
static av_cold void init_bitstream_params(TwinVQContext *tctx)
{
const TwinVQModeTab *mtab = tctx->mtab;
- int n_ch = tctx->avctx->channels;
+ int n_ch = tctx->avctx->ch_layout.nb_channels;
int total_fr_bits = tctx->avctx->bit_rate * mtab->size /
tctx->avctx->sample_rate;
diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c
index 8981d95408..5bebf4e218 100644
--- a/libavcodec/twinvqdec.c
+++ b/libavcodec/twinvqdec.c
@@ -181,7 +181,7 @@ static void decode_ppc(TwinVQContext *tctx, int period_coef, int g_coef,
{
const TwinVQModeTab *mtab = tctx->mtab;
int isampf = tctx->avctx->sample_rate / 1000;
- int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->channels);
+ int ibps = tctx->avctx->bit_rate / (1000 * tctx->avctx->ch_layout.nb_channels);
int min_period = ROUNDED_DIV(40 * 2 * mtab->size, isampf);
int max_period = ROUNDED_DIV(40 * 2 * mtab->size * 6, isampf);
int period_range = max_period - min_period;
@@ -254,7 +254,7 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
{
TwinVQFrameData *bits = &tctx->bits[0];
const TwinVQModeTab *mtab = tctx->mtab;
- int channels = tctx->avctx->channels;
+ int channels = tctx->avctx->ch_layout.nb_channels;
int sub;
BitstreamContext bc;
int i, j, k;
@@ -317,14 +317,14 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
static av_cold int twinvq_decode_init(AVCodecContext *avctx)
{
- int isampf, ibps;
+ int isampf, ibps, channels;
TwinVQContext *tctx = avctx->priv_data;
if (!avctx->extradata || avctx->extradata_size < 12) {
av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
return AVERROR_INVALIDDATA;
}
- avctx->channels = AV_RB32(avctx->extradata) + 1;
+ channels = AV_RB32(avctx->extradata) + 1;
avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000;
isampf = AV_RB32(avctx->extradata + 8);
@@ -347,15 +347,15 @@ static av_cold int twinvq_decode_init(AVCodecContext *avctx)
break;
}
- if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
+ if (channels <= 0 || channels > TWINVQ_CHANNELS_MAX) {
av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
- avctx->channels);
+ channels);
return -1;
}
- avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
- : AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
- ibps = avctx->bit_rate / (1000 * avctx->channels);
+ ibps = avctx->bit_rate / (1000 * channels);
if (ibps < 8 || ibps > 48) {
av_log(avctx, AV_LOG_ERROR, "Bad bitrate per channel value %d\n", ibps);
return AVERROR_INVALIDDATA;
diff --git a/libavcodec/vima.c b/libavcodec/vima.c
index 0db18972a2..4935835ea2 100644
--- a/libavcodec/vima.c
+++ b/libavcodec/vima.c
@@ -146,9 +146,8 @@ static int decode_frame(AVCodecContext *avctx, void *data,
channel_hint[0] = ~channel_hint[0];
channels = 2;
}
- avctx->channels = channels;
- avctx->channel_layout = (channels == 2) ? AV_CH_LAYOUT_STEREO
- : AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels);
pcm_data[0] = bitstream_read_signed(&bc, 16);
if (channels > 1) {
channel_hint[1] = bitstream_read_signed(&bc, 8);
diff --git a/libavcodec/vmdaudio.c b/libavcodec/vmdaudio.c
index 9e02ba7633..d6a6a6309f 100644
--- a/libavcodec/vmdaudio.c
+++ b/libavcodec/vmdaudio.c
@@ -69,8 +69,9 @@ static const uint16_t vmdaudio_table[128] = {
static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
{
VmdAudioContext *s = avctx->priv_data;
+ int channels = avctx->ch_layout.nb_channels;
- if (avctx->channels < 1 || avctx->channels > 2) {
+ if (channels < 1 || channels > 2) {
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
return AVERROR(EINVAL);
}
@@ -79,8 +80,8 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
- avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
- AV_CH_LAYOUT_STEREO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, channels == 1);
if (avctx->bits_per_coded_sample == 16)
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
@@ -88,11 +89,11 @@ static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
avctx->sample_fmt = AV_SAMPLE_FMT_U8;
s->out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
- s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2);
+ s->chunk_size = avctx->block_align + channels * (s->out_bps == 2);
av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
"block align = %d, sample rate = %d\n",
- avctx->channels, avctx->bits_per_coded_sample, avctx->block_align,
+ channels, avctx->bits_per_coded_sample, avctx->block_align,
avctx->sample_rate);
return 0;
@@ -139,6 +140,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
int ret;
uint8_t *output_samples_u8;
int16_t *output_samples_s16;
+ int channels = avctx->ch_layout.nb_channels;
if (buf_size < 16) {
av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
@@ -178,8 +180,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
buf_size = audio_chunks * s->chunk_size;
/* get output buffer */
- frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) /
- avctx->channels;
+ frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) / channels;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
@@ -190,7 +191,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
/* decode silent chunks */
if (silent_chunks > 0) {
int silent_size = FFMIN(avctx->block_align * silent_chunks,
- frame->nb_samples * avctx->channels);
+ frame->nb_samples * channels);
if (s->out_bps == 2) {
memset(output_samples_s16, 0x00, silent_size * 2);
output_samples_s16 += silent_size;
@@ -202,11 +203,10 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
/* decode audio chunks */
if (audio_chunks > 0) {
- buf_end = buf + (buf_size & ~(avctx->channels > 1));
+ buf_end = buf + (buf_size & ~(channels > 1));
while (buf + s->chunk_size <= buf_end) {
if (s->out_bps == 2) {
- decode_audio_s16(output_samples_s16, buf, s->chunk_size,
- avctx->channels);
+ decode_audio_s16(output_samples_s16, buf, s->chunk_size, channels);
output_samples_s16 += avctx->block_align;
} else {
memcpy(output_samples_u8, buf, s->chunk_size);
diff --git a/libavcodec/vorbis.h b/libavcodec/vorbis.h
index 5ae20ac243..c085be12fe 100644
--- a/libavcodec/vorbis.h
+++ b/libavcodec/vorbis.h
@@ -23,11 +23,16 @@
#include "avcodec.h"
+#include "libavutil/channel_layout.h"
+
extern const float ff_vorbis_floor1_inverse_db_table[256];
extern const float * const ff_vorbis_vwin[8];
extern const uint8_t ff_vorbis_channel_layout_offsets[8][8];
extern const uint8_t ff_vorbis_encoding_channel_layout_offsets[8][8];
+#if FF_API_OLD_CHANNEL_LAYOUT
extern const uint64_t ff_vorbis_channel_layouts[9];
+#endif
+extern const AVChannelLayout ff_vorbis_ch_layouts[9];
typedef struct vorbis_floor1_entry {
uint16_t x;
diff --git a/libavcodec/vorbis_data.c b/libavcodec/vorbis_data.c
index bafb77b1e8..1b3736764c 100644
--- a/libavcodec/vorbis_data.c
+++ b/libavcodec/vorbis_data.c
@@ -44,6 +44,7 @@ const uint8_t ff_vorbis_encoding_channel_layout_offsets[8][8] = {
{ 0, 2, 1, 6, 7, 4, 5, 3 },
};
+#if FF_API_OLD_CHANNEL_LAYOUT
const uint64_t ff_vorbis_channel_layouts[9] = {
AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
@@ -55,6 +56,23 @@ const uint64_t ff_vorbis_channel_layouts[9] = {
AV_CH_LAYOUT_7POINT1,
0
};
+#endif
+
+const AVChannelLayout ff_vorbis_ch_layouts[9] = {
+ AV_CHANNEL_LAYOUT_MONO,
+ AV_CHANNEL_LAYOUT_STEREO,
+ AV_CHANNEL_LAYOUT_SURROUND,
+ AV_CHANNEL_LAYOUT_QUAD,
+ AV_CHANNEL_LAYOUT_5POINT0_BACK,
+ AV_CHANNEL_LAYOUT_5POINT1_BACK,
+ {
+ .nb_channels = 7,
+ .order = AV_CHANNEL_ORDER_NATIVE,
+ .u.mask = AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_CENTER,
+ },
+ AV_CHANNEL_LAYOUT_7POINT1,
+ { 0 },
+};
DECLARE_ALIGNED(16, static const float, vwin64)[32] = {
0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
index cc0f6f4a3e..c0a550fe27 100644
--- a/libavcodec/vorbisdec.c
+++ b/libavcodec/vorbisdec.c
@@ -696,7 +696,7 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
res_setup->partition_size = get_bits(gb, 24) + 1;
/* Validations to prevent a buffer overflow later. */
if (res_setup->begin>res_setup->end ||
- res_setup->end > (res_setup->type == 2 ? vc->avctx->channels : 1) * vc->blocksize[1] / 2 ||
+ res_setup->end > (res_setup->type == 2 ? vc->audio_channels : 1) * vc->blocksize[1] / 2 ||
(res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) {
av_log(vc->avctx, AV_LOG_ERROR,
"partition out of bounds: type, begin, end, size, blocksize: %"PRIu16", %"PRIu32", %"PRIu32", %u, %"PRIu32"\n",
@@ -1055,12 +1055,13 @@ static av_cold int vorbis_decode_init(AVCodecContext *avctx)
return ret;
}
- if (vc->audio_channels > 8)
- avctx->channel_layout = 0;
- else
- avctx->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
+ av_channel_layout_uninit(&avctx->ch_layout);
+ if (vc->audio_channels > 8) {
+ avctx->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
+ .nb_channels = vc->audio_channels };
+ } else
+ avctx->ch_layout = ff_vorbis_ch_layouts[vc->audio_channels - 1];
- avctx->channels = vc->audio_channels;
avctx->sample_rate = vc->audio_samplerate;
return 0;
@@ -1772,7 +1773,12 @@ AVCodec ff_vorbis_decoder = {
.decode = vorbis_decode_frame,
.flush = vorbis_decode_flush,
.capabilities = AV_CODEC_CAP_DR1,
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
.channel_layouts = ff_vorbis_channel_layouts,
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ .ch_layouts = ff_vorbis_ch_layouts,
.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
AV_SAMPLE_FMT_NONE },
};
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 35bdd57fb1..ae77278c68 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -244,7 +244,7 @@ static int create_vorbis_context(vorbis_enc_context *venc,
vorbis_enc_mapping *mc;
int i, book, ret;
- venc->channels = avctx->channels;
+ venc->channels = avctx->ch_layout.nb_channels;
venc->sample_rate = avctx->sample_rate;
venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
@@ -1169,7 +1169,7 @@ static av_cold int vorbis_encode_init(AVCodecContext *avctx)
vorbis_enc_context *venc = avctx->priv_data;
int ret;
- if (avctx->channels != 2) {
+ if (avctx->ch_layout.nb_channels != 2) {
av_log(avctx, AV_LOG_ERROR, "Current Libav Vorbis encoder only supports 2 channels.\n");
return -1;
}
diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c
index 66430b90e3..8cb217f695 100644
--- a/libavcodec/wavpack.c
+++ b/libavcodec/wavpack.c
@@ -1037,8 +1037,6 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
default:
av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
size);
- chan = avctx->channels;
- chmask = avctx->channel_layout;
}
break;
case WP_ID_SAMPLE_RATE:
@@ -1104,14 +1102,13 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
avctx->sample_rate = wv_rates[sr];
if (multiblock) {
- if (chan)
- avctx->channels = chan;
- if (chmask)
- avctx->channel_layout = chmask;
+ if (chmask) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_from_mask(&avctx->ch_layout, chmask);
+ }
} else {
- avctx->channels = s->stereo ? 2 : 1;
- avctx->channel_layout = s->stereo ? AV_CH_LAYOUT_STEREO :
- AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_default(&avctx->ch_layout, s->stereo + 1);
}
/* get output buffer */
@@ -1122,7 +1119,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
}
}
- if (wc->ch_offset + s->stereo >= avctx->channels) {
+ if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
return (avctx->err_recognition & AV_EF_EXPLODE) ? AVERROR_INVALIDDATA : 0;
}
@@ -1214,7 +1211,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
buf_size -= frame_size;
}
- if (s->ch_offset != avctx->channels) {
+ if (s->ch_offset != avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
return AVERROR_INVALIDDATA;
}
diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index 697b41b0aa..be81ea6197 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -87,10 +87,10 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
volatile float bps;
int sample_rate1;
int coef_vlc_table;
+ int channels = avctx->ch_layout.nb_channels;
if (avctx->sample_rate <= 0 || avctx->sample_rate > 50000 ||
- avctx->channels <= 0 || avctx->channels > 2 ||
- avctx->bit_rate <= 0)
+ channels <= 0 || channels > 2 || avctx->bit_rate <= 0)
return -1;
avpriv_float_dsp_init(&s->fdsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
@@ -111,7 +111,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
if (s->use_variable_block_len) {
int nb_max, nb;
nb = ((flags2 >> 3) & 3) + 1;
- if ((avctx->bit_rate / avctx->channels) >= 32000)
+ if ((avctx->bit_rate / channels) >= 32000)
nb += 2;
nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
if (nb > nb_max)
@@ -139,14 +139,13 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
sample_rate1 = 8000;
}
- bps = (float) avctx->bit_rate /
- (float) (avctx->channels * avctx->sample_rate);
+ bps = (float) avctx->bit_rate / (float) (channels * avctx->sample_rate);
s->byte_offset_bits = av_log2((int) (bps * s->frame_len / 8.0 + 0.5)) + 2;
/* compute high frequency value and choose if noise coding should
* be activated */
bps1 = bps;
- if (avctx->channels == 2)
+ if (channels == 2)
bps1 = bps * 1.6;
if (sample_rate1 == 44100) {
if (bps1 >= 0.61)
@@ -184,7 +183,7 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
}
ff_dlog(s->avctx, "flags2=0x%x\n", flags2);
ff_dlog(s->avctx, "version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
- s->version, avctx->channels, avctx->sample_rate, avctx->bit_rate,
+ s->version, channels, avctx->sample_rate, avctx->bit_rate,
avctx->block_align);
ff_dlog(s->avctx, "bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
bps, bps1, high_freq, s->byte_offset_bits);
diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index fcbac931f9..7222ebae70 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -425,6 +425,7 @@ static int wma_decode_block(WMACodecContext *s)
int nb_coefs[MAX_CHANNELS];
float mdct_norm;
FFTContext *mdct;
+ int channels = s->avctx->ch_layout.nb_channels;
#ifdef TRACE
ff_tlog(s->avctx, "***decode_block: %d:%d\n",
@@ -480,10 +481,10 @@ static int wma_decode_block(WMACodecContext *s)
return -1;
}
- if (s->avctx->channels == 2)
+ if (channels == 2)
s->ms_stereo = bitstream_read_bit(&s->bc);
v = 0;
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
a = bitstream_read_bit(&s->bc);
s->channel_coded[ch] = a;
v |= a;
@@ -510,12 +511,12 @@ static int wma_decode_block(WMACodecContext *s)
/* compute number of coefficients */
n = s->coefs_end[bsize] - s->coefs_start;
- for (ch = 0; ch < s->avctx->channels; ch++)
+ for (ch = 0; ch < channels; ch++)
nb_coefs[ch] = n;
/* complex coding */
if (s->use_noise_coding) {
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
int i, n, a;
n = s->exponent_high_sizes[bsize];
@@ -528,7 +529,7 @@ static int wma_decode_block(WMACodecContext *s)
}
}
}
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
int i, n, val, code;
@@ -558,7 +559,7 @@ static int wma_decode_block(WMACodecContext *s)
/* exponents can be reused in short blocks. */
if ((s->block_len_bits == s->frame_len_bits) || bitstream_read_bit(&s->bc)) {
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
if (s->use_exp_vlc) {
if (decode_exp_vlc(s, ch) < 0)
@@ -572,7 +573,7 @@ static int wma_decode_block(WMACodecContext *s)
}
/* parse spectral coefficients : just RLE encoding */
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
int tindex;
WMACoef *ptr = &s->coefs1[ch][0];
@@ -586,7 +587,7 @@ static int wma_decode_block(WMACodecContext *s)
0, ptr, 0, nb_coefs[ch],
s->block_len, s->frame_len_bits, coef_nb_bits);
}
- if (s->version == 1 && s->avctx->channels >= 2)
+ if (s->version == 1 && channels >= 2)
bitstream_align(&s->bc);
}
@@ -599,7 +600,7 @@ static int wma_decode_block(WMACodecContext *s)
}
/* finally compute the MDCT coefficients */
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
WMACoef *coefs1;
float *coefs, *exponents, mult, mult1, noise;
@@ -700,7 +701,7 @@ static int wma_decode_block(WMACodecContext *s)
}
#ifdef TRACE
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
@@ -724,7 +725,7 @@ static int wma_decode_block(WMACodecContext *s)
next:
mdct = &s->mdct_ctx[bsize];
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
int n4, index;
n4 = s->block_len / 2;
@@ -769,7 +770,7 @@ static int wma_decode_frame(WMACodecContext *s, float **samples,
break;
}
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
/* copy current block to output */
memcpy(samples[ch] + samples_offset, s->frame_out[ch],
s->frame_len * sizeof(*s->frame_out[ch]));
diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
index 800c000bfe..af4db67f87 100644
--- a/libavcodec/wmaenc.c
+++ b/libavcodec/wmaenc.c
@@ -37,10 +37,10 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->avctx = avctx;
- if (avctx->channels > MAX_CHANNELS) {
+ if (avctx->ch_layout.nb_channels > MAX_CHANNELS) {
av_log(avctx, AV_LOG_ERROR,
"too many channels: got %i, need %i or fewer",
- avctx->channels, MAX_CHANNELS);
+ avctx->ch_layout.nb_channels, MAX_CHANNELS);
return AVERROR(EINVAL);
}
@@ -81,7 +81,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->use_exp_vlc = flags2 & 0x0001;
s->use_bit_reservoir = flags2 & 0x0002;
s->use_variable_block_len = flags2 & 0x0004;
- if (avctx->channels == 2)
+ if (avctx->ch_layout.nb_channels == 2)
s->ms_stereo = 1;
ff_wma_init(avctx, flags2);
@@ -113,7 +113,7 @@ static void apply_window_and_mdct(AVCodecContext *avctx, const AVFrame *frame)
int window_len = 1 << s->block_len_bits;
float n = 2.0 * 32768.0 / window_len;
- for (ch = 0; ch < avctx->channels; ch++) {
+ for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
memcpy(s->output, s->frame_out[ch], window_len * sizeof(*s->output));
s->fdsp.vector_fmul_scalar(s->frame_out[ch], audio[ch], n, len);
s->fdsp.vector_fmul_reverse(&s->output[window_len], s->frame_out[ch],
@@ -180,6 +180,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
int v, bsize, ch, coef_nb_bits, parse_exponents;
float mdct_norm;
int nb_coefs[MAX_CHANNELS];
+ int channels = s->avctx->ch_layout.nb_channels;
static const int fixed_exp[25] = {
20, 20, 20, 20, 20,
20, 20, 20, 20, 20,
@@ -204,7 +205,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
// FIXME factor
v = s->coefs_end[bsize] - s->coefs_start;
- for (ch = 0; ch < s->avctx->channels; ch++)
+ for (ch = 0; ch < channels; ch++)
nb_coefs[ch] = v;
{
int n4 = s->block_len / 2;
@@ -213,17 +214,17 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
mdct_norm *= sqrt(n4);
}
- if (s->avctx->channels == 2)
+ if (channels == 2)
put_bits(&s->pb, 1, !!s->ms_stereo);
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
// FIXME only set channel_coded when needed, instead of always
s->channel_coded[ch] = 1;
if (s->channel_coded[ch])
init_exp(s, ch, fixed_exp);
}
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
WMACoef *coefs1;
float *coefs, *exponents, mult;
@@ -251,7 +252,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
}
v = 0;
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
int a = s->channel_coded[ch];
put_bits(&s->pb, 1, a);
v |= a;
@@ -267,7 +268,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
coef_nb_bits = ff_wma_total_gain_to_bits(total_gain);
if (s->use_noise_coding) {
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
int i, n;
n = s->exponent_high_sizes[bsize];
@@ -285,7 +286,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
put_bits(&s->pb, 1, parse_exponents);
if (parse_exponents) {
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
if (s->use_exp_vlc) {
encode_exp_vlc(s, ch, fixed_exp);
@@ -298,7 +299,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
} else
assert(0); // FIXME not implemented
- for (ch = 0; ch < s->avctx->channels; ch++) {
+ for (ch = 0; ch < channels; ch++) {
if (s->channel_coded[ch]) {
int run, tindex;
WMACoef *ptr, *eptr;
@@ -337,7 +338,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1],
s->coef_vlcs[tindex]->huffcodes[1]);
}
- if (s->version == 1 && s->avctx->channels >= 2)
+ if (s->version == 1 && channels >= 2)
avpriv_align_put_bits(&s->pb);
}
return 0;
diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c
index b8299874d3..fc83f5ed55 100644
--- a/libavcodec/wmalosslessdec.c
+++ b/libavcodec/wmalosslessdec.c
@@ -221,8 +221,19 @@ static av_cold int decode_init(AVCodecContext *avctx)
3, s->decode_flags);
av_assert0(s->samples_per_frame <= WMALL_BLOCK_MAX_SIZE);
+ if (channel_mask) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
+ }
+ if (avctx->ch_layout.nb_channels > WMALL_MAX_CHANNELS) {
+ avpriv_request_sample(avctx,
+ "More than %d channels", WMALL_MAX_CHANNELS);
+ return AVERROR_PATCHWELCOME;
+ }
+ s->num_channels = avctx->ch_layout.nb_channels;
+
/* init previous block len */
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < s->num_channels; i++)
s->channel[i].prev_block_len = s->samples_per_frame;
/* subframe info */
@@ -241,33 +252,14 @@ static av_cold int decode_init(AVCodecContext *avctx)
return AVERROR_INVALIDDATA;
}
- s->num_channels = avctx->channels;
-
/* extract lfe channel position */
- s->lfe_channel = -1;
-
- if (channel_mask & 8) {
- unsigned int mask;
- for (mask = 1; mask < 16; mask <<= 1)
- if (channel_mask & mask)
- ++s->lfe_channel;
- }
-
- if (s->num_channels < 0) {
- av_log(avctx, AV_LOG_ERROR, "invalid number of channels %"PRId8"\n",
- s->num_channels);
- return AVERROR_INVALIDDATA;
- } else if (s->num_channels > WMALL_MAX_CHANNELS) {
- avpriv_request_sample(avctx,
- "More than %d channels", WMALL_MAX_CHANNELS);
- return AVERROR_PATCHWELCOME;
- }
+ s->lfe_channel = av_channel_layout_channel_index(&avctx->ch_layout,
+ AV_CHAN_LOW_FREQUENCY);
s->frame = av_frame_alloc();
if (!s->frame)
return AVERROR(ENOMEM);
- avctx->channel_layout = channel_mask;
return 0;
}
diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 4eaeed610e..1f6f1e627d 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -248,7 +248,7 @@ static av_cold void dump_context(WMAProDecodeCtx *s)
PRINT("log2 frame size", s->log2_frame_size);
PRINT("max num subframes", s->max_num_subframes);
PRINT("len prefix", s->len_prefix);
- PRINT("num channels", s->avctx->channels);
+ PRINT("num channels", s->avctx->ch_layout.nb_channels);
}
/**
@@ -351,30 +351,24 @@ static av_cold int decode_init(AVCodecContext *avctx)
return AVERROR_INVALIDDATA;
}
- if (avctx->channels < 0) {
- av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n",
- avctx->channels);
- return AVERROR_INVALIDDATA;
- } else if (avctx->channels > WMAPRO_MAX_CHANNELS) {
+ if (channel_mask) {
+ av_channel_layout_uninit(&avctx->ch_layout);
+ av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
+ }
+ if (avctx->ch_layout.nb_channels > WMAPRO_MAX_CHANNELS) {
avpriv_request_sample(avctx,
"More than %d channels", WMAPRO_MAX_CHANNELS);
return AVERROR_PATCHWELCOME;
}
+
/** init previous block len */
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++)
s->channel[i].prev_block_len = s->samples_per_frame;
/** extract lfe channel position */
- s->lfe_channel = -1;
-
- if (channel_mask & 8) {
- unsigned int mask;
- for (mask = 1; mask < 16; mask <<= 1) {
- if (channel_mask & mask)
- ++s->lfe_channel;
- }
- }
+ s->lfe_channel = av_channel_layout_channel_index(&avctx->ch_layout,
+ AV_CHAN_LOW_FREQUENCY);
INIT_VLC_STATIC(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE,
scale_huffbits, 1, 1,
@@ -474,8 +468,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
if (avctx->debug & FF_DEBUG_BITSTREAM)
dump_context(s);
- avctx->channel_layout = channel_mask;
-
return 0;
}
@@ -538,7 +530,7 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
{
uint16_t num_samples[WMAPRO_MAX_CHANNELS] = { 0 };/**< sum of samples for all currently known subframes of a channel */
uint8_t contains_subframe[WMAPRO_MAX_CHANNELS]; /**< flag indicating if a channel contains the current subframe */
- int channels_for_cur_subframe = s->avctx->channels; /**< number of channels that contain the current subframe */
+ int channels_for_cur_subframe = s->avctx->ch_layout.nb_channels; /**< number of channels that contain the current subframe */
int fixed_channel_layout = 0; /**< flag indicating that all channels use the same subframe offsets and sizes */
int min_channel_len = 0; /**< smallest sum of samples (channels with this length will be processed first) */
int c;
@@ -550,7 +542,7 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
*/
/** reset tiling information */
- for (c = 0; c < s->avctx->channels; c++)
+ for (c = 0; c < s->avctx->ch_layout.nb_channels; c++)
s->channel[c].num_subframes = 0;
if (s->max_num_subframes == 1 || bitstream_read_bit(&s->bc))
@@ -561,7 +553,7 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
int subframe_len;
/** check which channels contain the subframe */
- for (c = 0; c < s->avctx->channels; c++) {
+ for (c = 0; c < s->avctx->ch_layout.nb_channels; c++) {
if (num_samples[c] == min_channel_len) {
if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
(min_channel_len == s->samples_per_frame - s->min_samples_per_subframe))
@@ -578,7 +570,7 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
/** add subframes to the individual channels and find new min_channel_len */
min_channel_len += subframe_len;
- for (c = 0; c < s->avctx->channels; c++) {
+ for (c = 0; c < s->avctx->ch_layout.nb_channels; c++) {
WMAProChannelCtx* chan = &s->channel[c];
if (contains_subframe[c]) {
@@ -605,7 +597,7 @@ static int decode_tilehdr(WMAProDecodeCtx *s)
}
} while (min_channel_len < s->samples_per_frame);
- for (c = 0; c < s->avctx->channels; c++) {
+ for (c = 0; c < s->avctx->ch_layout.nb_channels; c++) {
int i;
int offset = 0;
for (i = 0; i < s->channel[c].num_subframes; i++) {
@@ -631,8 +623,8 @@ static void decode_decorrelation_matrix(WMAProDecodeCtx *s,
int i;
int offset = 0;
int8_t rotation_offset[WMAPRO_MAX_CHANNELS * WMAPRO_MAX_CHANNELS];
- memset(chgroup->decorrelation_matrix, 0, s->avctx->channels *
- s->avctx->channels * sizeof(*chgroup->decorrelation_matrix));
+ memset(chgroup->decorrelation_matrix, 0, s->avctx->ch_layout.nb_channels *
+ s->avctx->ch_layout.nb_channels * sizeof(*chgroup->decorrelation_matrix));
for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++)
rotation_offset[i] = bitstream_read(&s->bc, 6);
@@ -685,7 +677,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
/** in the one channel case channel transforms are pointless */
s->num_chgroups = 0;
- if (s->avctx->channels > 1) {
+ if (s->avctx->ch_layout.nb_channels > 1) {
int remaining_channels = s->channels_for_cur_subframe;
if (bitstream_read_bit(&s->bc)) {
@@ -732,7 +724,7 @@ static int decode_channel_transform(WMAProDecodeCtx* s)
}
} else {
chgroup->transform = 1;
- if (s->avctx->channels == 2) {
+ if (s->avctx->ch_layout.nb_channels == 2) {
chgroup->decorrelation_matrix[0] = 1.0;
chgroup->decorrelation_matrix[1] = -1.0;
chgroup->decorrelation_matrix[2] = 1.0;
@@ -1021,7 +1013,7 @@ static void inverse_channel_transform(WMAProDecodeCtx *s)
(*ch)[y] = sum;
}
}
- } else if (s->avctx->channels == 2) {
+ } else if (s->avctx->ch_layout.nb_channels == 2) {
int len = FFMIN(sfb[1], s->subframe_len) - sfb[0];
s->fdsp.vector_fmul_scalar(ch_data[0] + sfb[0],
ch_data[0] + sfb[0],
@@ -1074,7 +1066,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
int offset = s->samples_per_frame;
int subframe_len = s->samples_per_frame;
int i;
- int total_samples = s->samples_per_frame * s->avctx->channels;
+ int total_samples = s->samples_per_frame * s->avctx->ch_layout.nb_channels;
int transmit_coeffs = 0;
int cur_subwoofer_cutoff;
@@ -1084,7 +1076,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
== the next block of the channel with the smallest number of
decoded samples
*/
- for (i = 0; i < s->avctx->channels; i++) {
+ for (i = 0; i < s->avctx->ch_layout.nb_channels; i++) {
s->channel[i].grouped = 0;
if (offset > s->channel[i].decoded_samples) {
offset = s->channel[i].decoded_samples;
@@ -1098,7 +1090,7 @@ static int decode_subframe(WMAProDecodeCtx *s)
/** get a list of all channels that contain the estimated block */
s->channels_for_cur_subframe = 0;
- for (i = 0; i < s->avctx->channels; i++) {
+ for (i = 0; i < s->avctx->ch_layout.nb_channels; i++) {
const int cur_subframe = s->channel[i].cur_subframe;
/** subtract already processed samples */
total_samples -= s->channel[i].decoded_samples;
@@ -1328,9 +1320,9 @@ static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
}
/** read postproc transform */
- if (s->avctx->channels > 1 && bitstream_read_bit(bc)) {
+ if (s->avctx->ch_layout.nb_channels > 1 && bitstream_read_bit(bc)) {
if (bitstream_read_bit(bc)) {
- for (i = 0; i < avctx->channels * avctx->channels; i++)
+ for (i = 0; i < avctx->ch_layout.nb_channels * avctx->ch_layout.nb_channels; i++)
bitstream_skip(bc, 4);
}
}
@@ -1365,7 +1357,7 @@ static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
/** reset subframe states */
s->parsed_all_subframes = 0;
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
s->channel[i].decoded_samples = 0;
s->channel[i].cur_subframe = 0;
s->channel[i].reuse_sf = 0;
@@ -1388,11 +1380,11 @@ static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
}
/** copy samples to the output buffer */
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++)
memcpy(frame->extended_data[i], s->channel[i].out,
s->samples_per_frame * sizeof(*s->channel[i].out));
- for (i = 0; i < avctx->channels; i++) {
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
/** reuse second half of the IMDCT output for the next frame */
memcpy(&s->channel[i].out[0],
&s->channel[i].out[s->samples_per_frame],
@@ -1633,7 +1625,7 @@ static void flush(AVCodecContext *avctx)
int i;
/** reset output buffer as a part of it is used during the windowing of a
new frame */
- for (i = 0; i < avctx->channels; i++)
+ for (i = 0; i < avctx->ch_layout.nb_channels; i++)
memset(s->channel[i].out, 0, s->samples_per_frame *
sizeof(*s->channel[i].out));
s->packet_loss = 1;
diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index 8c7ec7b3d6..94e081af9d 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -445,8 +445,8 @@ static av_cold int wmavoice_decode_init(AVCodecContext *ctx)
2 * (s->block_conv_table[1] - 2 * s->min_pitch_val);
s->block_pitch_nbits = av_ceil_log2(s->block_pitch_range);
- ctx->channels = 1;
- ctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&ctx->ch_layout);
+ ctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
ctx->sample_fmt = AV_SAMPLE_FMT_FLT;
return 0;
diff --git a/libavcodec/ws-snd1.c b/libavcodec/ws-snd1.c
index 11b7289185..453a28d1ee 100644
--- a/libavcodec/ws-snd1.c
+++ b/libavcodec/ws-snd1.c
@@ -43,8 +43,8 @@ static const int8_t ws_adpcm_4bit[] = {
static av_cold int ws_snd_decode_init(AVCodecContext *avctx)
{
- avctx->channels = 1;
- avctx->channel_layout = AV_CH_LAYOUT_MONO;
+ av_channel_layout_uninit(&avctx->ch_layout);
+ avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
avctx->sample_fmt = AV_SAMPLE_FMT_U8;
return 0;
diff --git a/tests/fate/lossless-audio.mak b/tests/fate/lossless-audio.mak
index b4eadda648..6832fbf804 100644
--- a/tests/fate/lossless-audio.mak
+++ b/tests/fate/lossless-audio.mak
@@ -17,7 +17,7 @@ fate-lossless-tak: REF = a28d4e5f2192057f7d4bece870f40bd0
FATE_TRUEHD = fate-lossless-truehd-5.1 fate-lossless-truehd-5.1-downmix-2.0
fate-lossless-truehd-5.1: CMD = md5 -f truehd -i $(TARGET_SAMPLES)/lossless-audio/truehd_5.1.raw -f s32le
-fate-lossless-truehd-5.1-downmix-2.0: CMD = md5 -f truehd -request_channel_layout 2 -i $(TARGET_SAMPLES)/lossless-audio/truehd_5.1.raw -f s32le
+fate-lossless-truehd-5.1-downmix-2.0: CMD = md5 -f truehd -downmix stereo -i $(TARGET_SAMPLES)/lossless-audio/truehd_5.1.raw -f s32le
fate-lossless-truehd: $(FATE_TRUEHD)
FATE_SAMPLES_AVCONV-$(call DEMDEC, TRUEHD, TRUEHD) += $(FATE_TRUEHD)
--
2.13.1