diff options
author | Philip Langdale <philipl@overt.org> | 2021-02-20 16:41:44 -0800 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2021-03-28 19:46:27 +0300 |
commit | 3f006eced47b35b7d752fdc19c22a7f39f970975 (patch) | |
tree | 7186f381e317fac2e8cc117d2ff20ab700a3b372 /filters | |
parent | 6265724f3331e3dee8d9ec2b6639def5004a5fa2 (diff) | |
download | mpv-3f006eced47b35b7d752fdc19c22a7f39f970975.tar.bz2 mpv-3f006eced47b35b7d752fdc19c22a7f39f970975.tar.xz |
options: Make validation and help possible for all option types
Today, validation is only possible for string type options. But there's
no particular reason why it needs to be restricted in this way, and
there are potential uses, to allow other options to be validated
without forcing the option to have to reimplement parsing from
scratch.
The first part, simply making the validation function an explicit
field instead of overloading priv is simple enough. But if we only do
that, then the validation function still needs to deal with the raw
pre-parsed string. Instead, we want to allow the value to be parsed
before it is validated. That in turn leads to us having validator
functions that should be type aware. Unfortunately, that means we need
to keep the explicit macro like OPT_STRING_VALIDATE() as a way to
enforce the correct typing of the function. Otherwise, we'd have to
have the validator take a void * and hope the implementation can cast
it correctly.
For help, we don't have this problem, as help doesn't look at the
value.
Then, we turn validators that are really help generators into explicit
help functions and where a validator is help + validation, we split
them into two parts.
I have, however, left functions that need to query information for both
help and validation as single functions to avoid code duplication.
In this change, I have not added an other OPT_FOO_VALIDATE() macros as
they are not needed, but I will add some in a separate change to
illustrate the pattern.
Diffstat (limited to 'filters')
-rw-r--r-- | filters/f_decoder_wrapper.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/filters/f_decoder_wrapper.c b/filters/f_decoder_wrapper.c index 397c3a0a98..9be8743e53 100644 --- a/filters/f_decoder_wrapper.c +++ b/filters/f_decoder_wrapper.c @@ -110,16 +110,19 @@ struct dec_wrapper_opts { int64_t audio_reverse_size; }; -static int decoder_list_opt(struct mp_log *log, const m_option_t *opt, - struct bstr name, struct bstr param); +static int decoder_list_help(struct mp_log *log, const m_option_t *opt, + struct bstr name); const struct m_sub_options dec_wrapper_conf = { .opts = (const struct m_option[]){ {"correct-pts", OPT_FLAG(correct_pts)}, {"fps", OPT_DOUBLE(force_fps), M_RANGE(0, DBL_MAX)}, - {"ad", OPT_STRING_VALIDATE(audio_decoders, decoder_list_opt)}, - {"vd", OPT_STRING_VALIDATE(video_decoders, decoder_list_opt)}, - {"audio-spdif", OPT_STRING_VALIDATE(audio_spdif, decoder_list_opt)}, + {"ad", OPT_STRING(audio_decoders), + .help = decoder_list_help}, + {"vd", OPT_STRING(video_decoders), + .help = decoder_list_help}, + {"audio-spdif", OPT_STRING(audio_spdif), + .help = decoder_list_help}, {"video-rotate", OPT_CHOICE(video_rotate, {"no", -1}), .flags = UPDATE_IMGPAR, M_RANGE(0, 359)}, {"video-aspect-override", OPT_ASPECT(movie_aspect), @@ -232,11 +235,9 @@ struct priv { int dropped_frames; // total frames _probably_ dropped }; -static int decoder_list_opt(struct mp_log *log, const m_option_t *opt, - struct bstr name, struct bstr param) +static int decoder_list_help(struct mp_log *log, const m_option_t *opt, + struct bstr name) { - if (!bstr_equals0(param, "help")) - return 1; if (strcmp(opt->name, "ad") == 0) { struct mp_decoder_list *list = audio_decoder_list(); mp_print_decoders(log, MSGL_INFO, "Audio decoders:", list); |