diff options
author | Martin Vignali <martin.vignali@gmail.com> | 2018-12-02 23:36:24 +0300 |
---|---|---|
committer | Martin Vignali <martin.vignali@gmail.com> | 2018-12-04 17:17:21 +0300 |
commit | e53901ba5ec3284b8d5882df47cbd8d888279220 (patch) | |
tree | ed13959abca4c509f2dd8f7b9767f772c077bea4 /libavcodec/utils.c | |
parent | aae7e009b3a91031c4f71141450431384f4b0380 (diff) |
avcodec/utils : add ff_int_from_list_or_default func
to check valid value, or return default_value
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index c4c64a6ca4..2fa811d499 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -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; +} |