diff options
author | wm4 <wm4@nowhere> | 2020-03-14 21:28:01 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-03-18 19:52:01 +0100 |
commit | 26f4f18c0629998a9b91e94722d166866d8b80a3 (patch) | |
tree | 16d4891d241d528f63ee99f0017530bba7b3dc8b /filters | |
parent | cdd6eb0994bc6aeb8aeb0326e5d8c61c06eb38eb (diff) | |
download | mpv-26f4f18c0629998a9b91e94722d166866d8b80a3.tar.bz2 mpv-26f4f18c0629998a9b91e94722d166866d8b80a3.tar.xz |
options: change option macros and all option declarations
Change all OPT_* macros such that they don't define the entire m_option
initializer, and instead expand only to a part of it, which sets certain
fields. This requires changing almost every option declaration, because
they all use these macros. A declaration now always starts with
{"name", ...
followed by designated initializers only (possibly wrapped in macros).
The OPT_* macros now initialize the .offset and .type fields only,
sometimes also .priv and others.
I think this change makes the option macros less tricky. The old code
had to stuff everything into macro arguments (and attempted to allow
setting arbitrary fields by letting the user pass designated
initializers in the vararg parts). Some of this was made messy due to
C99 and C11 not allowing 0-sized varargs with ',' removal. It's also
possible that this change is pointless, other than cosmetic preferences.
Not too happy about some things. For example, the OPT_CHOICE()
indentation I applied looks a bit ugly.
Much of this change was done with regex search&replace, but some places
required manual editing. In particular, code in "obscure" areas (which I
didn't include in compilation) might be broken now.
In wayland_common.c the author of some option declarations confused the
flags parameter with the default value (though the default value was
also properly set below). I fixed this with this change.
Diffstat (limited to 'filters')
-rw-r--r-- | filters/f_decoder_wrapper.c | 41 | ||||
-rw-r--r-- | filters/f_lavfi.c | 22 | ||||
-rw-r--r-- | filters/f_swresample.c | 15 |
3 files changed, 40 insertions, 38 deletions
diff --git a/filters/f_decoder_wrapper.c b/filters/f_decoder_wrapper.c index 6b297b671f..b49ec921c1 100644 --- a/filters/f_decoder_wrapper.c +++ b/filters/f_decoder_wrapper.c @@ -63,10 +63,10 @@ struct dec_queue_opts { #define OPT_BASE_STRUCT struct dec_queue_opts static const struct m_option dec_queue_opts_list[] = { - OPT_FLAG("enable", use_queue, 0), - OPT_DOUBLE("max-secs", max_duration, 0, .min = 0, .max = DBL_MAX), - OPT_BYTE_SIZE("max-bytes", max_bytes, 0, 0, (size_t)-1), - OPT_INT64("max-samples", max_samples, 0, .min = 0, .max = DBL_MAX), + {"enable", OPT_FLAG(use_queue)}, + {"max-secs", OPT_DOUBLE(max_duration), M_RANGE(0, DBL_MAX)}, + {"max-bytes", OPT_BYTE_SIZE(max_bytes), M_RANGE(0, (size_t)-1)}, + {"max-samples", OPT_INT64(max_samples), M_RANGE(0, DBL_MAX)}, {0} }; @@ -115,21 +115,24 @@ static int decoder_list_opt(struct mp_log *log, const m_option_t *opt, const struct m_sub_options dec_wrapper_conf = { .opts = (const struct m_option[]){ - OPT_FLAG("correct-pts", correct_pts, 0), - OPT_DOUBLE("fps", force_fps, 0, .min = 0, .max = DBL_MAX), - OPT_STRING_VALIDATE("ad", audio_decoders, 0, decoder_list_opt), - OPT_STRING_VALIDATE("vd", video_decoders, 0, decoder_list_opt), - OPT_STRING_VALIDATE("audio-spdif", audio_spdif, 0, decoder_list_opt), - OPT_CHOICE_OR_INT("video-rotate", video_rotate, UPDATE_IMGPAR, 0, 359, - ({"no", -1})), - OPT_ASPECT("video-aspect-override", movie_aspect, - UPDATE_IMGPAR, .min = -1, .max = 10), - OPT_CHOICE("video-aspect-method", aspect_method, UPDATE_IMGPAR, - ({"bitstream", 1}, {"container", 2})), - OPT_SUBSTRUCT("vd-queue", vdec_queue_opts, vdec_queue_conf, 0), - OPT_SUBSTRUCT("ad-queue", adec_queue_opts, adec_queue_conf, 0), - OPT_BYTE_SIZE("video-reversal-buffer", video_reverse_size, 0, 0, (size_t)-1), - OPT_BYTE_SIZE("audio-reversal-buffer", audio_reverse_size, 0, 0, (size_t)-1), + {"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)}, + {"video-rotate", OPT_CHOICE(video_rotate, {"no", -1}), + .flags = UPDATE_IMGPAR, M_RANGE(0, 359)}, + {"video-aspect-override", OPT_ASPECT(movie_aspect), + .flags = UPDATE_IMGPAR, M_RANGE(-1, 10)}, + {"video-aspect-method", OPT_CHOICE(aspect_method, + {"bitstream", 1}, {"container", 2}), + .flags = UPDATE_IMGPAR}, + {"vd-queue", OPT_SUBSTRUCT(vdec_queue_opts, vdec_queue_conf)}, + {"ad-queue", OPT_SUBSTRUCT(adec_queue_opts, adec_queue_conf)}, + {"video-reversal-buffer", OPT_BYTE_SIZE(video_reverse_size), + M_RANGE(0, (size_t)-1)}, + {"audio-reversal-buffer", OPT_BYTE_SIZE(audio_reverse_size), + M_RANGE(0, (size_t)-1)}, {0} }, .size = sizeof(struct dec_wrapper_opts), diff --git a/filters/f_lavfi.c b/filters/f_lavfi.c index 2e612d14fc..9e64215f39 100644 --- a/filters/f_lavfi.c +++ b/filters/f_lavfi.c @@ -1091,9 +1091,9 @@ const struct mp_user_filter_entry af_lavfi = { .name = "lavfi", .priv_size = sizeof(OPT_BASE_STRUCT), .options = (const m_option_t[]){ - OPT_STRING("graph", graph, 0), - OPT_FLAG("fix-pts", fix_pts, 0), - OPT_KEYVALUELIST("o", avopts, 0), + {"graph", OPT_STRING(graph)}, + {"fix-pts", OPT_FLAG(fix_pts)}, + {"o", OPT_KEYVALUELIST(avopts)}, {0} }, .priv_defaults = &(const OPT_BASE_STRUCT){ @@ -1110,9 +1110,9 @@ const struct mp_user_filter_entry af_lavfi_bridge = { .name = "lavfi-bridge", .priv_size = sizeof(OPT_BASE_STRUCT), .options = (const m_option_t[]){ - OPT_STRING("name", filter_name, 0), - OPT_KEYVALUELIST("opts", filter_opts, 0), - OPT_KEYVALUELIST("o", avopts, 0), + {"name", OPT_STRING(filter_name)}, + {"opts", OPT_KEYVALUELIST(filter_opts)}, + {"o", OPT_KEYVALUELIST(avopts)}, {0} }, .priv_defaults = &(const OPT_BASE_STRUCT){ @@ -1130,8 +1130,8 @@ const struct mp_user_filter_entry vf_lavfi = { .name = "lavfi", .priv_size = sizeof(OPT_BASE_STRUCT), .options = (const m_option_t[]){ - OPT_STRING("graph", graph, 0), - OPT_KEYVALUELIST("o", avopts, 0), + {"graph", OPT_STRING(graph)}, + {"o", OPT_KEYVALUELIST(avopts)}, {0} }, .priv_defaults = &(const OPT_BASE_STRUCT){ @@ -1148,9 +1148,9 @@ const struct mp_user_filter_entry vf_lavfi_bridge = { .name = "lavfi-bridge", .priv_size = sizeof(OPT_BASE_STRUCT), .options = (const m_option_t[]){ - OPT_STRING("name", filter_name, 0), - OPT_KEYVALUELIST("opts", filter_opts, 0), - OPT_KEYVALUELIST("o", avopts, 0), + {"name", OPT_STRING(filter_name)}, + {"opts", OPT_KEYVALUELIST(filter_opts)}, + {"o", OPT_KEYVALUELIST(avopts)}, {0} }, .priv_defaults = &(const OPT_BASE_STRUCT){ diff --git a/filters/f_swresample.c b/filters/f_swresample.c index 0197ca9662..4f26d82a59 100644 --- a/filters/f_swresample.c +++ b/filters/f_swresample.c @@ -71,14 +71,13 @@ struct priv { #define OPT_BASE_STRUCT struct mp_resample_opts const struct m_sub_options resample_conf = { .opts = (const m_option_t[]) { - OPT_INTRANGE("audio-resample-filter-size", filter_size, 0, 0, 32), - OPT_INTRANGE("audio-resample-phase-shift", phase_shift, 0, 0, 30), - OPT_FLAG("audio-resample-linear", linear, 0), - OPT_DOUBLE("audio-resample-cutoff", cutoff, 0, - .min = 0, .max = 1), - OPT_FLAG("audio-normalize-downmix", normalize, 0), - OPT_DOUBLE("audio-resample-max-output-size", max_output_frame_size, 0), - OPT_KEYVALUELIST("audio-swresample-o", avopts, 0), + {"audio-resample-filter-size", OPT_INT(filter_size), M_RANGE(0, 32)}, + {"audio-resample-phase-shift", OPT_INT(phase_shift), M_RANGE(0, 30)}, + {"audio-resample-linear", OPT_FLAG(linear)}, + {"audio-resample-cutoff", OPT_DOUBLE(cutoff), M_RANGE(0, 1)}, + {"audio-normalize-downmix", OPT_FLAG(normalize)}, + {"audio-resample-max-output-size", OPT_DOUBLE(max_output_frame_size)}, + {"audio-swresample-o", OPT_KEYVALUELIST(avopts)}, {0} }, .size = sizeof(struct mp_resample_opts), |