diff options
Diffstat (limited to 'options/m_option.h')
-rw-r--r-- | options/m_option.h | 91 |
1 files changed, 69 insertions, 22 deletions
diff --git a/options/m_option.h b/options/m_option.h index afd86eaf96..4c3385876c 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -25,6 +25,7 @@ #include "misc/bstr.h" #include "audio/chmap.h" +#include "common/common.h" // m_option allows to parse, print and copy data of various types. @@ -66,6 +67,7 @@ extern const m_option_type_t m_option_type_channels; extern const m_option_type_t m_option_type_aspect; extern const m_option_type_t m_option_type_obj_settings_list; extern const m_option_type_t m_option_type_node; +extern const m_option_type_t m_option_type_rect; // Used internally by m_config.c extern const m_option_type_t m_option_type_alias; @@ -103,6 +105,7 @@ struct m_geometry { void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh, int scrw, int scrh, struct m_geometry *gm); +void m_rect_apply(struct mp_rect *rc, int w, int h, struct m_geometry *gm); struct m_channels { bool set : 1; @@ -145,9 +148,6 @@ struct m_obj_list { const char *aliases[5][2]; // Allow a trailing ",", which adds an entry with name="" bool allow_trailer; - // Allow unknown entries, for which a dummy entry is inserted, and whose - // options are skipped and ignored. - bool allow_unknown_entries; // Callback to test whether an unknown entry should be allowed. (This can // be useful if adding them as explicit entries is too much work.) bool (*check_unknown_entry)(const char *name); @@ -189,9 +189,20 @@ struct m_opt_choice_alternatives { const char *m_opt_choice_str(const struct m_opt_choice_alternatives *choices, int value); -// For OPT_STRING_VALIDATE(). Behaves like m_option_type.parse(). -typedef int (*m_opt_string_validate_fn)(struct mp_log *log, const m_option_t *opt, - struct bstr name, struct bstr param); +typedef int (*m_opt_generic_validate_fn)(struct mp_log *log, const m_option_t *opt, + struct bstr name, void *value); + +#define OPT_FUNC(name) name +#define OPT_FUNC_IN(name, suffix) name ## _ ## suffix +#define OPT_VALIDATE_FUNC(func, value_type, suffix) \ +int OPT_FUNC(func)(struct mp_log *log, const m_option_t *opt, \ + struct bstr name, value_type value); \ +static inline int OPT_FUNC_IN(func, suffix)(struct mp_log *log, const m_option_t *opt, \ + struct bstr name, void *value) { \ + return OPT_FUNC(func)(log, opt, name, value); \ +} \ +int OPT_FUNC(func)(struct mp_log *log, const m_option_t *opt, \ + struct bstr name, value_type value) // m_option.priv points to this if OPT_SUBSTRUCT is used struct m_sub_options { @@ -209,6 +220,7 @@ struct m_sub_options { bool (*get_sub_options)(int index, const struct m_sub_options **sub); }; +#define CONF_TYPE_BOOL (&m_option_type_bool) #define CONF_TYPE_FLAG (&m_option_type_flag) #define CONF_TYPE_INT (&m_option_type_int) #define CONF_TYPE_INT64 (&m_option_type_int64) @@ -249,6 +261,11 @@ union m_option_value { struct m_channels channels; }; +// Keep fully zeroed instance of m_option_value to use as a default value, before +// any specific union member is used. C standard says that `= {0}` activates and +// initializes only the first member of the union, leaving padding bits undefined. +static const union m_option_value m_option_value_default; + //////////////////////////////////////////////////////////////////////////// struct m_option_action { @@ -270,6 +287,9 @@ struct m_option_type { // Parse the data from a string. /** It is the only required function, all others can be NULL. + * Generally should not be called directly outside of the options module, + * but instead through \ref m_option_parse which calls additional option + * specific callbacks during the process. * * \param log for outputting parser error or help messages * \param opt The option that is parsed. @@ -364,6 +384,9 @@ struct m_option { // See \ref OptionFlags. unsigned int flags; + // Always force an option update even if the written value does not change. + bool force_update; + int offset; // Most numeric types restrict the range to [min, max] if min<max (this @@ -384,6 +407,12 @@ struct m_option { // Print a warning when this option is used (for options with no direct // replacement.) const char *deprecation_message; + + // Optional function that validates a param value for this option. + m_opt_generic_validate_fn validate; + + // Optional function that displays help. Will replace type-specific help. + int (*help)(struct mp_log *log, const m_option_t *opt, struct bstr name); }; char *format_file_size(int64_t size); @@ -420,7 +449,9 @@ char *format_file_size(int64_t size); #define UPDATE_HWDEC (1 << 20) // --hwdec #define UPDATE_DVB_PROG (1 << 21) // some --dvbin-... #define UPDATE_SUB_HARD (1 << 22) // subtitle opts. that need full reinit -#define UPDATE_OPT_LAST (1 << 22) +#define UPDATE_SUB_EXTS (1 << 23) // update internal list of sub exts +#define UPDATE_VIDEO (1 << 24) // force redraw if needed +#define UPDATE_OPT_LAST (1 << 24) // All bits between _FIRST and _LAST (inclusive) #define UPDATE_OPTS_MASK \ @@ -435,6 +466,9 @@ char *format_file_size(int64_t size); // type channels: disallow "auto" (still accept ""), limit list to at most 1 item. #define M_OPT_CHANNELS_LIMITED (1 << 27) +// type_float/type_double: controls if pretty print should trim trailing zeros +#define M_OPT_FIXED_LEN_PRINT (1 << 28) + // Like M_OPT_TYPE_OPTIONAL_PARAM. #define M_OPT_OPTIONAL_PARAM (1 << 30) @@ -490,12 +524,13 @@ char *format_file_size(int64_t size); char *m_option_strerror(int code); -// Helper to parse options, see \ref m_option_type::parse. -static inline int m_option_parse(struct mp_log *log, const m_option_t *opt, - struct bstr name, struct bstr param, void *dst) -{ - return opt->type->parse(log, opt, name, param, dst); -} +// Base function to parse options. Includes calling help and validation +// callbacks. Only when this functionality is for some reason required to not +// happen should the parse function pointer be utilized by itself. +// +// See \ref m_option_type::parse. +int m_option_parse(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst); // Helper to print options, see \ref m_option_type::print. static inline char *m_option_print(const m_option_t *opt, const void *val_ptr) @@ -507,12 +542,16 @@ static inline char *m_option_print(const m_option_t *opt, const void *val_ptr) } static inline char *m_option_pretty_print(const m_option_t *opt, - const void *val_ptr) + const void *val_ptr, + bool fixed_len) { + m_option_t o = *opt; + if (fixed_len) + o.flags |= M_OPT_FIXED_LEN_PRINT; if (opt->type->pretty_print) - return opt->type->pretty_print(opt, val_ptr); + return opt->type->pretty_print(&o, val_ptr); else - return m_option_print(opt, val_ptr); + return m_option_print(&o, val_ptr); } // Helper around \ref m_option_type::copy. @@ -588,14 +627,11 @@ extern const char m_option_path_separator; #define OPTDEF_FLOAT(f) .defval = (void *)&(const float){f} #define OPTDEF_DOUBLE(d) .defval = (void *)&(const double){d} -#define M_RANGE(a, b) .min = (a), .max = (b) +#define M_RANGE(a, b) .min = (double) (a), .max = (double) (b) #define OPT_BOOL(field) \ OPT_TYPED_FIELD(m_option_type_bool, bool, field) -#define OPT_FLAG(field) \ - OPT_TYPED_FIELD(m_option_type_flag, int, field) - #define OPT_INT(field) \ OPT_TYPED_FIELD(m_option_type_int, int, field) @@ -642,6 +678,9 @@ extern const char m_option_path_separator; #define OPT_SIZE_BOX(field) \ OPT_TYPED_FIELD(m_option_type_size_box, struct m_geometry, field) +#define OPT_RECT(field) \ + OPT_TYPED_FIELD(m_option_type_rect, struct m_geometry, field) + #define OPT_TRACKCHOICE(field) \ OPT_CHOICE(field, {"no", -2}, {"auto", -1}), \ M_RANGE(0, 8190) @@ -650,7 +689,7 @@ extern const char m_option_path_separator; OPT_TYPED_FIELD(m_option_type_msglevels, char **, field) #define OPT_ASPECT(field) \ - OPT_TYPED_FIELD(m_option_type_aspect, float, field) + OPT_TYPED_FIELD(m_option_type_aspect, double, field) #define OPT_IMAGEFORMAT(field) \ OPT_TYPED_FIELD(m_option_type_imgfmt, int, field) @@ -661,9 +700,17 @@ extern const char m_option_path_separator; #define OPT_CHANNELS(field) \ OPT_TYPED_FIELD(m_option_type_channels, struct m_channels, field) +#define OPT_INT_VALIDATE_FUNC(func) OPT_VALIDATE_FUNC(func, const int *, int) + +#define OPT_INT_VALIDATE(field, validate_fn) \ + OPT_TYPED_FIELD(m_option_type_int, int, field), \ + .validate = OPT_FUNC_IN(validate_fn, int) + +#define OPT_STRING_VALIDATE_FUNC(func) OPT_VALIDATE_FUNC(func, const char **, str) + #define OPT_STRING_VALIDATE(field, validate_fn) \ OPT_TYPED_FIELD(m_option_type_string, char*, field), \ - .priv = MP_EXPECT_TYPE(m_opt_string_validate_fn, validate_fn) + .validate = OPT_FUNC_IN(validate_fn, str) #define M_CHOICES(...) \ .priv = (void *)&(const struct m_opt_choice_alternatives[]){ __VA_ARGS__, {0}} |