diff mbox series

[FFmpeg-devel,04/22] lavc/encode: improve input sample rate validation

Message ID 20230707094847.25324-4-anton@khirnov.net
State Accepted
Commit 39206c5e581f5020fe47adf463a759b0f39186d8
Headers show
Series [FFmpeg-devel,01/22] lavc/encode: print separate messages for unknown and unsupported formats | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov July 7, 2023, 9:48 a.m. UTC
Reject zero sample rates in addition to negative ones and describe them
as 'invalid' rather than 'unsupported'.
---
 libavcodec/encode.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index ba91dcc31e..9a279d9842 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -634,6 +634,11 @@  static int encode_preinit_audio(AVCodecContext *avctx)
                avctx->sample_fmt);
         return AVERROR(EINVAL);
     }
+    if (avctx->sample_rate <= 0) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid audio sample rate: %d\n",
+               avctx->sample_rate);
+        return AVERROR(EINVAL);
+    }
 
     if (c->sample_fmts) {
         for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
@@ -662,11 +667,6 @@  static int encode_preinit_audio(AVCodecContext *avctx)
             return AVERROR(EINVAL);
         }
     }
-    if (avctx->sample_rate < 0) {
-        av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
-                avctx->sample_rate);
-        return AVERROR(EINVAL);
-    }
     if (c->ch_layouts) {
         for (i = 0; c->ch_layouts[i].nb_channels; i++) {
             if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i]))