fftools/cmdutils: include OPT_PERFILE in OPT_OFFSET

And analogously OPT_OFFSET in OPT_SPEC. Previously the inclusion would
be implicit and required all code to remember this.
This commit is contained in:
Anton Khirnov 2023-12-17 11:47:33 +01:00
parent 66fcfc0009
commit 2f1bc3b424
3 changed files with 22 additions and 19 deletions

View file

@ -237,13 +237,13 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt,
{ {
/* new-style options contain an offset into optctx, old-style address of /* new-style options contain an offset into optctx, old-style address of
* a global var*/ * a global var*/
void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ? void *dst = po->flags & OPT_FLAG_OFFSET ?
(uint8_t *)optctx + po->u.off : po->u.dst_ptr; (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
int *dstcount; int *dstcount;
double num; double num;
int ret; int ret;
if (po->flags & OPT_SPEC) { if (po->flags & OPT_FLAG_SPEC) {
SpecifierOpt **so = dst; SpecifierOpt **so = dst;
char *p = strchr(opt, ':'); char *p = strchr(opt, ':');
char *str; char *str;
@ -660,7 +660,7 @@ static int finish_group(OptionParseContext *octx, int group_idx,
static int add_opt(OptionParseContext *octx, const OptionDef *opt, static int add_opt(OptionParseContext *octx, const OptionDef *opt,
const char *key, const char *val) const char *key, const char *val)
{ {
int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET)); int global = !(opt->flags & OPT_PERFILE);
OptionGroup *g = global ? &octx->global_opts : &octx->cur_group; OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
int ret; int ret;

View file

@ -135,17 +135,22 @@ typedef struct OptionDef {
#define OPT_AUDIO (1 << 4) #define OPT_AUDIO (1 << 4)
#define OPT_SUBTITLE (1 << 5) #define OPT_SUBTITLE (1 << 5)
#define OPT_DATA (1 << 6) #define OPT_DATA (1 << 6)
/* The option is per-file (currently ffmpeg-only). Implied by OPT_OFFSET or /* The option is per-file (currently ffmpeg-only). At least one of OPT_INPUT or
* OPT_SPEC. At least one of OPT_INPUT or OPT_OUTPUT must be set when this flag * OPT_OUTPUT must be set when this flag is in use.
* is in use.
*/ */
#define OPT_PERFILE (1 << 7) #define OPT_PERFILE (1 << 7)
/* Option is specified as an offset in a passed optctx */
#define OPT_OFFSET (1 << 8) /* Option is specified as an offset in a passed optctx.
/* Option is to be stored in an array of SpecifierOpt. Implies OPT_OFFSET. * Always use as OPT_OFFSET in option definitions. */
#define OPT_FLAG_OFFSET (1 << 8)
#define OPT_OFFSET (OPT_FLAG_OFFSET | OPT_PERFILE)
/* Option is to be stored in an array of SpecifierOpt.
Next element after the offset is an int containing element count in the Next element after the offset is an int containing element count in the
array. */ array.
#define OPT_SPEC (1 << 9) Always use as OPT_SPEC in option definitions. */
#define OPT_FLAG_SPEC (1 << 9)
#define OPT_SPEC (OPT_FLAG_SPEC | OPT_OFFSET)
/* ffmpeg-only - specifies whether an OPT_PERFILE option applies to input, /* ffmpeg-only - specifies whether an OPT_PERFILE option applies to input,
* output, or both. */ * output, or both. */
#define OPT_INPUT (1 << 10) #define OPT_INPUT (1 << 10)

View file

@ -109,7 +109,7 @@ static void uninit_options(OptionsContext *o)
while (po->name) { while (po->name) {
void *dst = (uint8_t*)o + po->u.off; void *dst = (uint8_t*)o + po->u.off;
if (po->flags & OPT_SPEC) { if (po->flags & OPT_FLAG_SPEC) {
SpecifierOpt **so = dst; SpecifierOpt **so = dst;
int i, *count = (int*)(so + 1); int i, *count = (int*)(so + 1);
for (i = 0; i < *count; i++) { for (i = 0; i < *count; i++) {
@ -119,7 +119,7 @@ static void uninit_options(OptionsContext *o)
} }
av_freep(so); av_freep(so);
*count = 0; *count = 0;
} else if (po->flags & OPT_OFFSET && po->type == OPT_TYPE_STRING) } else if (po->flags & OPT_FLAG_OFFSET && po->type == OPT_TYPE_STRING)
av_freep(dst); av_freep(dst);
po++; po++;
} }
@ -1181,8 +1181,6 @@ static int opt_filter_complex_script(void *optctx, const char *opt, const char *
void show_help_default(const char *opt, const char *arg) void show_help_default(const char *opt, const char *arg)
{ {
/* per-file options have at least one of those set */
const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
int show_advanced = 0, show_avoptions = 0; int show_advanced = 0, show_avoptions = 0;
if (opt && *opt) { if (opt && *opt) {
@ -1209,17 +1207,17 @@ void show_help_default(const char *opt, const char *arg)
show_help_options(options, "Global options (affect whole program " show_help_options(options, "Global options (affect whole program "
"instead of just one file):", "instead of just one file):",
0, per_file | OPT_EXIT | OPT_EXPERT, 0); 0, OPT_PERFILE | OPT_EXIT | OPT_EXPERT, 0);
if (show_advanced) if (show_advanced)
show_help_options(options, "Advanced global options:", OPT_EXPERT, show_help_options(options, "Advanced global options:", OPT_EXPERT,
per_file | OPT_EXIT, 0); OPT_PERFILE | OPT_EXIT, 0);
show_help_options(options, "Per-file main options:", 0, show_help_options(options, "Per-file main options:", 0,
OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE | OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE |
OPT_EXIT, per_file); OPT_EXIT, OPT_PERFILE);
if (show_advanced) if (show_advanced)
show_help_options(options, "Advanced per-file options:", show_help_options(options, "Advanced per-file options:",
OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file); OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, OPT_PERFILE);
show_help_options(options, "Video options:", show_help_options(options, "Video options:",
OPT_VIDEO, OPT_EXPERT | OPT_AUDIO, 0); OPT_VIDEO, OPT_EXPERT | OPT_AUDIO, 0);