aboutsummaryrefslogtreecommitdiffstats
path: root/fftools/cmdutils.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-08-06 11:11:41 +0200
committerAnton Khirnov <anton@khirnov.net>2024-08-13 10:28:54 +0200
commite218bde9f9e3b41d89921ed475065da88b5c0b83 (patch)
tree980673bab7299aee20f9548f00d7180e84cec165 /fftools/cmdutils.c
parent82085a3e0a5a2d167dc51628678f7374dc53060e (diff)
downloadffmpeg-e218bde9f9e3b41d89921ed475065da88b5c0b83.tar.gz
fftools/ffmpeg: replace MATCH_PER_STREAM_OPT(.., str, ..) with a function
This has multiple advantages: * The macro has multiple parameters that often have similar or identical values, yet very different meanings (one is the name of the OptionsContext member where the parsed options are stored, the other the name of the variable into which the result is written); this change makes each of these explicit. * The macro returns on failure, which may cause leaks - this was the reason for adding MATCH_PER_STREAM_OPT_CLEAN(), also ost_add() currently leaks encoder_opts. The new function returns failure to its caller, which decides how to deal with it. While that adds a lot of error checks/forwards for now, those will be reduced in following commits. * new code is type- and const- correct Invocations of MATCH_PER_STREAM_OPT() with other types will be converted in following commits.
Diffstat (limited to 'fftools/cmdutils.c')
-rw-r--r--fftools/cmdutils.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 9b18cf5e4d..6286fd87f7 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -246,6 +246,8 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
(uint8_t *)optctx + po->u.off : po->u.dst_ptr;
char *arg_allocated = NULL;
+ enum OptionType so_type = po->type;
+
SpecifierOptList *sol = NULL;
double num;
int ret = 0;
@@ -310,6 +312,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
goto finish;
*(int *)dst = num;
+ so_type = OPT_TYPE_INT;
} else if (po->type == OPT_TYPE_INT64) {
ret = parse_number(opt, arg, OPT_TYPE_INT64, INT64_MIN, (double)INT64_MAX, &num);
if (ret < 0)
@@ -323,6 +326,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
opt, arg);
goto finish;
}
+ so_type = OPT_TYPE_INT64;
} else if (po->type == OPT_TYPE_FLOAT) {
ret = parse_number(opt, arg, OPT_TYPE_FLOAT, -INFINITY, INFINITY, &num);
if (ret < 0)
@@ -352,7 +356,7 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
}
if (sol) {
- sol->type = po->type;
+ sol->type = so_type;
sol->opt_canon = (po->flags & OPT_HAS_CANON) ?
find_option(defs, po->u1.name_canon) : po;
}