diff mbox series

[FFmpeg-devel,4/6] avcodec/utils: Move decoder channel count check to ff_decode_preinit

Message ID 20210316203100.528950-4-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/6] avcodec/utils: Check earlier for codec id/type mismatch | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 16, 2021, 8:30 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
I actually wonder why this flag is not used for encoders. Several of
them explicitly check for invalid channel values.

 libavcodec/decode.c | 5 +++++
 libavcodec/utils.c  | 8 --------
 2 files changed, 5 insertions(+), 8 deletions(-)

Comments

Anton Khirnov March 20, 2021, 4:13 p.m. UTC | #1
Quoting Andreas Rheinhardt (2021-03-16 21:30:58)
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> I actually wonder why this flag is not used for encoders. Several of
> them explicitly check for invalid channel values.

How would it work? How can the channel count _not_ be provided to an
encoder?
Andreas Rheinhardt March 20, 2021, 5:22 p.m. UTC | #2
Anton Khirnov:
> Quoting Andreas Rheinhardt (2021-03-16 21:30:58)
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
>> ---
>> I actually wonder why this flag is not used for encoders. Several of
>> them explicitly check for invalid channel values.
> 
> How would it work? How can the channel count _not_ be provided to an
> encoder?
> 
Seems you misunderstood my intentions. Or rather: Seems that what I
wrote actually doesn't convey my real intentions (unless you already
know my real intentions, of course). What I meant is: If the
"av_codec_is_decoder(codec)" check is omitted from the original check
and if "Decoder" in the message is replaced by "Codec", then this check
could have been used instead of having some encoders doing checks on
their own.
(I actually didn't even test what happens now with encoders that don't
check for channel_count == 0.)

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index cbd41c8cc8..390147908d 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -2026,6 +2026,11 @@  FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
+    if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && avctx->channels == 0 &&
+        !(avctx->codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF)) {
+        av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n");
+        return AVERROR(EINVAL);
+    }
     if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) {
         av_log(avctx, AV_LOG_WARNING, "The maximum value for lowres supported by the decoder is %d\n",
                avctx->codec->max_lowres);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 7d4ad113df..77f98c951b 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -671,14 +671,6 @@  int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         ret = AVERROR(EINVAL);
         goto free_and_end;
     }
-    if (av_codec_is_decoder(codec) &&
-        codec->type == AVMEDIA_TYPE_AUDIO &&
-        !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF) &&
-        avctx->channels == 0) {
-        av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n");
-        ret = AVERROR(EINVAL);
-        goto free_and_end;
-    }
 
     if (avctx->sample_rate < 0) {
         av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);