summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-05-07 07:20:32 +0200
committerJames Almer <jamrial@gmail.com>2022-03-15 09:42:45 -0300
commiteb81c946c1888a8d929cc8719f6fd486450e2d0d (patch)
tree58e6b1979f63d571b08e713bc372799b472bfd94
parent972586344a02ad65360bd967b7b7bfd20e0456e4 (diff)
vmdaudio: convert to new channel layout API
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavcodec/vmdaudio.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/libavcodec/vmdaudio.c b/libavcodec/vmdaudio.c
index 53aef660ef..5e04686cb1 100644
--- a/libavcodec/vmdaudio.c
+++ b/libavcodec/vmdaudio.c
@@ -71,20 +71,20 @@ 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);
}
- if (avctx->block_align < 1 || avctx->block_align % avctx->channels ||
- avctx->block_align > INT_MAX - avctx->channels
- ) {
+ if (avctx->block_align < 1 || avctx->block_align % channels ||
+ avctx->block_align > INT_MAX - channels) {
av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
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;
@@ -92,11 +92,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;
@@ -143,6 +143,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");
@@ -186,7 +187,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
/* get output buffer */
frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) /
- avctx->channels;
+ avctx->ch_layout.nb_channels;
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
output_samples_u8 = frame->data[0];
@@ -195,7 +196,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
/* decode silent chunks */
if (silent_chunks > 0) {
int silent_size = avctx->block_align * silent_chunks;
- av_assert0(avctx->block_align * silent_chunks <= frame->nb_samples * avctx->channels);
+ av_assert0(avctx->block_align * silent_chunks <= frame->nb_samples * avctx->ch_layout.nb_channels);
if (s->out_bps == 2) {
memset(output_samples_s16, 0x00, silent_size * 2);
@@ -209,11 +210,10 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
/* decode audio chunks */
if (audio_chunks > 0) {
buf_end = buf + buf_size;
- av_assert0((buf_size & (avctx->channels > 1)) == 0);
+ av_assert0((buf_size & (avctx->ch_layout.nb_channels > 1)) == 0);
while (buf_end - buf >= s->chunk_size) {
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);