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>
This commit is contained in:
committed by
James Almer
parent
972586344a
commit
eb81c946c1
@@ -71,20 +71,20 @@ static const uint16_t vmdaudio_table[128] = {
|
|||||||
static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
|
static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
VmdAudioContext *s = avctx->priv_data;
|
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");
|
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
if (avctx->block_align < 1 || avctx->block_align % avctx->channels ||
|
if (avctx->block_align < 1 || avctx->block_align % channels ||
|
||||||
avctx->block_align > INT_MAX - avctx->channels
|
avctx->block_align > INT_MAX - channels) {
|
||||||
) {
|
|
||||||
av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
|
av_log(avctx, AV_LOG_ERROR, "invalid block align\n");
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
|
av_channel_layout_uninit(&avctx->ch_layout);
|
||||||
AV_CH_LAYOUT_STEREO;
|
av_channel_layout_default(&avctx->ch_layout, channels == 1);
|
||||||
|
|
||||||
if (avctx->bits_per_coded_sample == 16)
|
if (avctx->bits_per_coded_sample == 16)
|
||||||
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
|
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;
|
avctx->sample_fmt = AV_SAMPLE_FMT_U8;
|
||||||
s->out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
|
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, "
|
av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, "
|
||||||
"block align = %d, sample rate = %d\n",
|
"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);
|
avctx->sample_rate);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -143,6 +143,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
int ret;
|
int ret;
|
||||||
uint8_t *output_samples_u8;
|
uint8_t *output_samples_u8;
|
||||||
int16_t *output_samples_s16;
|
int16_t *output_samples_s16;
|
||||||
|
int channels = avctx->ch_layout.nb_channels;
|
||||||
|
|
||||||
if (buf_size < 16) {
|
if (buf_size < 16) {
|
||||||
av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
|
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 */
|
/* get output buffer */
|
||||||
frame->nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) /
|
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)
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
output_samples_u8 = frame->data[0];
|
output_samples_u8 = frame->data[0];
|
||||||
@@ -195,7 +196,7 @@ static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
/* decode silent chunks */
|
/* decode silent chunks */
|
||||||
if (silent_chunks > 0) {
|
if (silent_chunks > 0) {
|
||||||
int silent_size = avctx->block_align * silent_chunks;
|
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) {
|
if (s->out_bps == 2) {
|
||||||
memset(output_samples_s16, 0x00, silent_size * 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 */
|
/* decode audio chunks */
|
||||||
if (audio_chunks > 0) {
|
if (audio_chunks > 0) {
|
||||||
buf_end = buf + buf_size;
|
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) {
|
while (buf_end - buf >= s->chunk_size) {
|
||||||
if (s->out_bps == 2) {
|
if (s->out_bps == 2) {
|
||||||
decode_audio_s16(output_samples_s16, buf, s->chunk_size,
|
decode_audio_s16(output_samples_s16, buf, s->chunk_size, channels);
|
||||||
avctx->channels);
|
|
||||||
output_samples_s16 += avctx->block_align;
|
output_samples_s16 += avctx->block_align;
|
||||||
} else {
|
} else {
|
||||||
memcpy(output_samples_u8, buf, s->chunk_size);
|
memcpy(output_samples_u8, buf, s->chunk_size);
|
||||||
|
Reference in New Issue
Block a user