diff options
author | Anton Khirnov <anton@khirnov.net> | 2024-02-12 08:54:35 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2024-03-08 07:24:50 +0100 |
commit | 85797886fe05eb2a16663d68484bccee1e2e05cd (patch) | |
tree | 09bd6f57b06668940c737d0c1e92110a6d99ecbe /libavutil/opt.c | |
parent | a1be08ba0515b0224f7c433fc471e61013a12ff2 (diff) | |
download | ffmpeg-85797886fe05eb2a16663d68484bccee1e2e05cd.tar.gz |
lavu/opt: factor per-type dispatch out of av_opt_set()
Will be useful in following commits.
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r-- | libavutil/opt.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c index d93e9f564b..c8b949fb65 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -484,13 +484,11 @@ static int set_string_channel_layout(void *obj, const AVOption *o, return av_channel_layout_from_string(channel_layout, val); } -int av_opt_set(void *obj, const char *name, const char *val, int search_flags) +static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, + const char *val, void *dst) { - int ret = 0; - void *dst, *target_obj; - const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); - if (!o || !target_obj) - return AVERROR_OPTION_NOT_FOUND; + int ret; + FF_DISABLE_DEPRECATION_WARNINGS if (!val && (o->type != AV_OPT_TYPE_STRING && o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT && @@ -500,13 +498,6 @@ FF_DISABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); FF_ENABLE_DEPRECATION_WARNINGS - if (o->flags & AV_OPT_FLAG_READONLY) - return AVERROR(EINVAL); - - if (o->flags & AV_OPT_FLAG_DEPRECATED) - av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); - - dst = ((uint8_t *)target_obj) + o->offset; switch (o->type) { case AV_OPT_TYPE_BOOL: return set_string_bool(obj, o, val, dst); @@ -569,6 +560,24 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR(EINVAL); } +int av_opt_set(void *obj, const char *name, const char *val, int search_flags) +{ + void *dst, *target_obj; + const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); + if (!o || !target_obj) + return AVERROR_OPTION_NOT_FOUND; + + if (o->flags & AV_OPT_FLAG_READONLY) + return AVERROR(EINVAL); + + if (o->flags & AV_OPT_FLAG_DEPRECATED) + av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); + + dst = ((uint8_t *)target_obj) + o->offset; + + return opt_set_elem(obj, target_obj, o, val, dst); +} + #define OPT_EVAL_NUMBER(name, opttype, vartype) \ int av_opt_eval_ ## name(void *obj, const AVOption *o, \ const char *val, vartype *name ## _out) \ |