avcodec/dcaenc: Simplify channel layout check

ff_encode_preinit() ensures that the channel layout is equivalent
to one of the channel layouts in AVCodec.ch_layout; given that
all of these channel layouts have distinct numbers of channels,
one can therefore uniquely determine the channel layout by
the number of channels.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-09-18 00:14:51 +02:00
parent 66e297fc84
commit ce16d18307
1 changed files with 14 additions and 5 deletions

View File

@ -222,16 +222,25 @@ static int encode_init(AVCodecContext *avctx)
if (ff_dcaadpcm_init(&c->adpcm_ctx))
return AVERROR(ENOMEM);
if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
switch (layout.nb_channels) {
case 1: /* mono */
c->channel_config = 0;
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO))
break;
case 2: /* stereo */
c->channel_config = 2;
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2))
break;
case 4: /* 2.2 */
c->channel_config = 8;
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
break;
case 5: /* 5.0 */
c->channel_config = 9;
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
break;
case 6: /* 5.1 */
c->channel_config = 9;
break;
default:
av_assert1(!"impossible channel layout");
}
if (c->lfe_channel) {
c->fullband_channels--;