]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/utils : add ff_int_from_list_or_default func
authorMartin Vignali <martin.vignali@gmail.com>
Sun, 2 Dec 2018 20:36:24 +0000 (21:36 +0100)
committerMartin Vignali <martin.vignali@gmail.com>
Tue, 4 Dec 2018 14:17:21 +0000 (15:17 +0100)
to check valid value, or return default_value

libavcodec/internal.h
libavcodec/utils.c

index 0c2133f0925b3ec3e0dc3c70099de85a8b681195..f2e6f00ace644239f99f7eafbe474a2f3277e3b3 100644 (file)
@@ -404,6 +404,18 @@ int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len,
  */
 int64_t ff_guess_coded_bitrate(AVCodecContext *avctx);
 
+/**
+ * Check if a value is in the list. If not, return the default value
+ *
+ * @param ctx                Context for the log msg
+ * @param val_name           Name of the checked value, for log msg
+ * @param array_valid_values Array of valid int, ended with INT_MAX
+ * @param default_value      Value return if checked value is not in the array
+ * @return                   Value or default_value.
+ */
+int ff_int_from_list_or_default(void *ctx, const char * val_name, int val,
+                                const int * array_valid_values, int default_value);
+
 #if defined(_WIN32) && CONFIG_SHARED && !defined(BUILDING_avcodec)
 #    define av_export_avcodec __declspec(dllimport)
 #else
index c4c64a6ca4405cf72abd3d966e036e95be64527f..2fa811d4991ac374431e091534ab2e53e791b8eb 100644 (file)
@@ -2209,3 +2209,22 @@ int64_t ff_guess_coded_bitrate(AVCodecContext *avctx)
 
     return bitrate;
 }
+
+int ff_int_from_list_or_default(void *ctx, const char * val_name, int val,
+                                const int * array_valid_values, int default_value)
+{
+    int i = 0, ref_val;
+
+    while (1) {
+        ref_val = array_valid_values[i];
+        if (ref_val == INT_MAX)
+            break;
+        if (val == ref_val)
+            return val;
+        i++;
+    }
+    /* val is not a valid value */
+    av_log(ctx, AV_LOG_DEBUG,
+           "%s %d are not supported. Set to default value : %d\n", val_name, val, default_value);
+    return default_value;
+}