1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-07-11 14:30:22 +02:00

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.
This commit is contained in:
Anton Khirnov
2024-08-06 11:11:41 +02:00
parent 82085a3e0a
commit e218bde9f9
7 changed files with 242 additions and 70 deletions

View File

@ -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;
}