[FFmpeg-devel] [PATCH 02/29] lavu/opt: factor per-type dispatch out of av_opt_set()
Anton Khirnov
anton at khirnov.net
Mon Mar 4 15:06:17 EET 2024
Will be useful in following commits.
---
libavutil/opt.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index dac00478ee..b372c76120 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -494,13 +494,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 &&
@@ -513,13 +511,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);
@@ -599,6 +590,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) \
--
2.43.0
More information about the ffmpeg-devel
mailing list