From: Zhao Zhili <zhiliz...@tencent.com>

---
 libavresample/options.c |  6 +++---
 libavresample/utils.c   | 13 +++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/libavresample/options.c b/libavresample/options.c
index 5f08cd7e52..cdab98c357 100644
--- a/libavresample/options.c
+++ b/libavresample/options.c
@@ -37,12 +37,12 @@
 
 static const AVOption avresample_options[] = {
     { "in_channel_layout",      "Input Channel Layout",     
OFFSET(in_channel_layout),      AV_OPT_TYPE_INT64,  { .i64 = 0              }, 
INT64_MIN,            INT64_MAX,              PARAM },
-    { "in_sample_fmt",          "Input Sample Format",      
OFFSET(in_sample_fmt),          AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_S16 
}, AV_SAMPLE_FMT_U8,     AV_SAMPLE_FMT_NB-1,     PARAM },
+    { "in_sample_fmt",          "Input Sample Format",      
OFFSET(in_sample_fmt),          AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_S16 
}, AV_SAMPLE_FMT_U8,  INT_MAX,                PARAM },
     { "in_sample_rate",         "Input Sample Rate",        
OFFSET(in_sample_rate),         AV_OPT_TYPE_INT,    { .i64 = 48000          }, 
1,                    INT_MAX,                PARAM },
     { "out_channel_layout",     "Output Channel Layout",    
OFFSET(out_channel_layout),     AV_OPT_TYPE_INT64,  { .i64 = 0              }, 
INT64_MIN,            INT64_MAX,              PARAM },
-    { "out_sample_fmt",         "Output Sample Format",     
OFFSET(out_sample_fmt),         AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_S16 
}, AV_SAMPLE_FMT_U8,     AV_SAMPLE_FMT_NB-1,     PARAM },
+    { "out_sample_fmt",         "Output Sample Format",     
OFFSET(out_sample_fmt),         AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_S16 
}, AV_SAMPLE_FMT_U8,  INT_MAX,                PARAM },
     { "out_sample_rate",        "Output Sample Rate",       
OFFSET(out_sample_rate),        AV_OPT_TYPE_INT,    { .i64 = 48000          }, 
1,                    INT_MAX,                PARAM },
-    { "internal_sample_fmt",    "Internal Sample Format",   
OFFSET(internal_sample_fmt),    AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_NONE 
}, AV_SAMPLE_FMT_NONE,   AV_SAMPLE_FMT_NB-1,     PARAM, "internal_sample_fmt" },
+    { "internal_sample_fmt",    "Internal Sample Format",   
OFFSET(internal_sample_fmt),    AV_OPT_TYPE_INT,    { .i64 = AV_SAMPLE_FMT_NONE 
}, AV_SAMPLE_FMT_NONE,   INT_MAX,     PARAM, "internal_sample_fmt" },
         {"u8" ,  "8-bit unsigned integer",        0, AV_OPT_TYPE_CONST, {.i64 
= AV_SAMPLE_FMT_U8   }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
         {"s16",  "16-bit signed integer",         0, AV_OPT_TYPE_CONST, {.i64 
= AV_SAMPLE_FMT_S16  }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
         {"s32",  "32-bit signed integer",         0, AV_OPT_TYPE_CONST, {.i64 
= AV_SAMPLE_FMT_S32  }, INT_MIN, INT_MAX, PARAM, "internal_sample_fmt"},
diff --git a/libavresample/utils.c b/libavresample/utils.c
index b4fb906556..0fbb28641d 100644
--- a/libavresample/utils.c
+++ b/libavresample/utils.c
@@ -42,6 +42,19 @@ int avresample_open(AVAudioResampleContext *avr)
         return AVERROR(EINVAL);
     }
 
+#define check_format(fmt, option_name)                                   \
+    if (!av_get_sample_fmt_name(fmt)) {                                  \
+        av_log(avr, AV_LOG_ERROR, "%s sample format %d not supported\n", \
+                option_name, fmt);                                       \
+        return AVERROR(EINVAL);                                          \
+    }
+
+    check_format(avr->in_sample_fmt, "Input")
+    check_format(avr->out_sample_fmt, "Out")
+    check_format(avr->internal_sample_fmt, "Internal")
+
+#undef check_format
+
     /* set channel mixing parameters */
     avr->in_channels = 
av_get_channel_layout_nb_channels(avr->in_channel_layout);
     if (avr->in_channels <= 0 || avr->in_channels > AVRESAMPLE_MAX_CHANNELS) {
-- 
2.22.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to