1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-07 11:13:41 +02:00

avcodec/ac3dec: add downmix support for mono and stereo for eac3 7.1

This commit is contained in:
Paul B Mahol 2022-09-20 17:07:15 +02:00
parent 0744782de3
commit acbb2777e2

View File

@ -183,6 +183,33 @@ static av_cold void ac3_tables_init(void)
#endif #endif
} }
static void ac3_downmix(AVCodecContext *avctx)
{
AC3DecodeContext *s = avctx->priv_data;
const AVChannelLayout mono = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
/* allow downmixing to stereo or mono */
#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 (avctx->ch_layout.nb_channels > 1 &&
!av_channel_layout_compare(&s->downmix_layout, &mono)) {
av_channel_layout_uninit(&avctx->ch_layout);
avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
} else 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;
}
s->downmixed = 1;
}
/** /**
* AVCodec initialization * AVCodec initialization
*/ */
@ -190,8 +217,6 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
{ {
static AVOnce init_static_once = AV_ONCE_INIT; static AVOnce init_static_once = AV_ONCE_INIT;
AC3DecodeContext *s = avctx->priv_data; AC3DecodeContext *s = avctx->priv_data;
const AVChannelLayout mono = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
const AVChannelLayout stereo = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
int i, ret; int i, ret;
s->avctx = avctx; s->avctx = avctx;
@ -219,25 +244,7 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx)
else else
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
/* allow downmixing to stereo or mono */ ac3_downmix(avctx);
#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 (avctx->ch_layout.nb_channels > 1 &&
!av_channel_layout_compare(&s->downmix_layout, &mono)) {
av_channel_layout_uninit(&avctx->ch_layout);
avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
} else 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;
}
s->downmixed = 1;
for (i = 0; i < AC3_MAX_CHANNELS; i++) { for (i = 0; i < AC3_MAX_CHANNELS; i++) {
s->xcfptr[i] = s->transform_coeffs[i]; s->xcfptr[i] = s->transform_coeffs[i];
@ -1751,7 +1758,7 @@ skip:
if (index < 0) if (index < 0)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
if (extend >= channel_map_size) if (extend >= channel_map_size)
return AVERROR_INVALIDDATA; break;
extended_channel_map[index] = offset + channel_map[extend++]; extended_channel_map[index] = offset + channel_map[extend++];
} else { } else {
@ -1763,7 +1770,7 @@ skip:
if (index < 0) if (index < 0)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
if (extend >= channel_map_size) if (extend >= channel_map_size)
return AVERROR_INVALIDDATA; break;
extended_channel_map[index] = offset + channel_map[extend++]; extended_channel_map[index] = offset + channel_map[extend++];
} }
@ -1771,6 +1778,8 @@ skip:
} }
} }
} }
ac3_downmix(avctx);
} }
/* get output buffer */ /* get output buffer */