From bdd9c2d7dd6c9530a9f93dd70b18d6f955c833f4 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 8 Dec 2024 16:42:40 +0100 Subject: [PATCH 1/3] m_option: group UPDATE and M_OPT constants in an enum Make these more readable by grouping them visually and removing all the #defines. This makes it clear that the M_OPT_TYPE constants are unrelated to these. --- options/m_option.h | 94 +++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 56 deletions(-) diff --git a/options/m_option.h b/options/m_option.h index ed7fc641c26e0..dc71f808f7c35 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -423,62 +423,44 @@ struct m_option { char *format_file_size(int64_t size); -// The following are also part of the M_OPT_* flags, and are used to update -// certain groups of options. -#define UPDATE_TERM (1 << 0) // terminal options -#define UPDATE_SUB_FILT (1 << 1) // subtitle filter options -#define UPDATE_OSD (1 << 2) // related to OSD rendering -#define UPDATE_BUILTIN_SCRIPTS (1 << 3) // osc/ytdl/stats -#define UPDATE_IMGPAR (1 << 4) // video image params overrides -#define UPDATE_INPUT (1 << 5) // mostly --input-* options -#define UPDATE_AUDIO (1 << 6) // --audio-channels etc. -#define UPDATE_PRIORITY (1 << 7) // --priority (Windows-only) -#define UPDATE_SCREENSAVER (1 << 8) // --stop-screensaver -#define UPDATE_VOL (1 << 9) // softvol related options -#define UPDATE_LAVFI_COMPLEX (1 << 10) // --lavfi-complex -#define UPDATE_HWDEC (1 << 11) // --hwdec -#define UPDATE_DVB_PROG (1 << 12) // some --dvbin-... -#define UPDATE_SUB_HARD (1 << 13) // subtitle opts. that need full reinit -#define UPDATE_SUB_EXTS (1 << 14) // update internal list of sub exts -#define UPDATE_VIDEO (1 << 15) // force redraw if needed -#define UPDATE_VO (1 << 16) // reinit the VO -#define UPDATE_CLIPBOARD (1 << 17) // reinit the clipboard -#define UPDATE_OPT_LAST (1 << 17) - -// All bits between of UPDATE_ flags -#define UPDATE_OPTS_MASK ((UPDATE_OPT_LAST << 1) - 1) - -// The option is forbidden in config files. -#define M_OPT_NOCFG (1 << 30) - -// The option should be set during command line pre-parsing -#define M_OPT_PRE_PARSE (1 << 29) - -// The option expects a file name (or a list of file names) -#define M_OPT_FILE (1 << 28) - -// Do not add as property. -#define M_OPT_NOPROP (1 << 27) - -// Enable special semantics for some options when parsing the string "help". -#define M_OPT_HAVE_HELP (1 << 26) - -// type_float/type_double: string "default" is parsed as NaN (and reverse) -#define M_OPT_DEFAULT_NAN (1 << 25) - -// type time: string "no" maps to MP_NOPTS_VALUE (if unset, NOPTS is rejected) -// and -// parsing: "--no-opt" is parsed as "--opt=no" -#define M_OPT_ALLOW_NO (1 << 24) - -// type channels: disallow "auto" (still accept ""), limit list to at most 1 item. -#define M_OPT_CHANNELS_LIMITED (1 << 23) - -// type_float/type_double: controls if pretty print should trim trailing zeros -#define M_OPT_FIXED_LEN_PRINT (1 << 22) - -// Like M_OPT_TYPE_OPTIONAL_PARAM. -#define M_OPT_OPTIONAL_PARAM (1 << 21) +enum option_flags { + // The following are also part of the M_OPT_* flags, and are used to update + // certain groups of options. + UPDATE_TERM = (1 << 0), // terminal options + UPDATE_SUB_FILT = (1 << 1), // subtitle filter options + UPDATE_OSD = (1 << 2), // related to OSD rendering + UPDATE_BUILTIN_SCRIPTS = (1 << 3), // osc/ytdl/stats + UPDATE_IMGPAR = (1 << 4), // video image params overrides + UPDATE_INPUT = (1 << 5), // mostly --input-* options + UPDATE_AUDIO = (1 << 6), // --audio-channels etc. + UPDATE_PRIORITY = (1 << 7), // --priority (Windows-only) + UPDATE_SCREENSAVER = (1 << 8), // --stop-screensaver + UPDATE_VOL = (1 << 9), // softvol related options + UPDATE_LAVFI_COMPLEX = (1 << 10), // --lavfi-complex + UPDATE_HWDEC = (1 << 11), // --hwdec + UPDATE_DVB_PROG = (1 << 12), // some --dvbin-... + UPDATE_SUB_HARD = (1 << 13), // subtitle opts. that need full reinit + UPDATE_SUB_EXTS = (1 << 14), // update internal list of sub exts + UPDATE_VIDEO = (1 << 15), // force redraw if needed + UPDATE_VO = (1 << 16), // reinit the VO + UPDATE_CLIPBOARD = (1 << 17), // reinit the clipboard + UPDATE_OPT_LAST = (1 << 17), + + M_OPT_NOCFG = (1 << 30), // The option is forbidden in config files. + M_OPT_PRE_PARSE = (1 << 29), // The option should be set during command line pre-parsing + M_OPT_FILE = (1 << 28), // The option expects a file name (or a list of file names) + M_OPT_NOPROP = (1 << 27), // Do not add as property. + M_OPT_HAVE_HELP = (1 << 26), // Enable special semantics for some options when parsing the string "help". + + M_OPT_DEFAULT_NAN = (1 << 25), // type_float/type_double: string "default" is parsed as NaN (and reverse) + M_OPT_ALLOW_NO = (1 << 24), // type time: string "no" maps to MP_NOPTS_VALUE (if unset, NOPTS is rejected) + // and parsing: "--no-opt" is parsed as "--opt=no" + M_OPT_CHANNELS_LIMITED = (1 << 23), // type channels: disallow "auto" (still accept ""), limit list to at most 1 item. + M_OPT_FIXED_LEN_PRINT = (1 << 22), // type_float/type_double: controls if pretty print should trim trailing zeros + M_OPT_OPTIONAL_PARAM = (1 << 21), // Like M_OPT_TYPE_OPTIONAL_PARAM. +}; + +#define UPDATE_OPTS_MASK ((UPDATE_OPT_LAST << 1) - 1) static_assert(!(UPDATE_OPTS_MASK & M_OPT_OPTIONAL_PARAM), ""); From e4cc7f23a20495fa8aa630b77e82735299a40740 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 8 Dec 2024 16:44:21 +0100 Subject: [PATCH 2/3] various: upgrade option flags to uint64_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that they will already work after more UPDATE flags are added. change_flags in m_config_core.h was already uint64_t. Co-authored-by: Kacper Michajłow --- options/m_config_frontend.c | 2 +- options/m_config_frontend.h | 2 +- options/m_option.h | 4 ++-- player/command.c | 5 ++--- player/command.h | 2 +- sub/dec_sub.c | 2 +- sub/sd_ass.c | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/options/m_config_frontend.c b/options/m_config_frontend.c index 99d936cfc4fd5..134afa2e8095c 100644 --- a/options/m_config_frontend.c +++ b/options/m_config_frontend.c @@ -383,7 +383,7 @@ const char *m_config_get_positional_option(const struct m_config *config, int p) static int handle_set_opt_flags(struct m_config *config, struct m_config_option *co, int flags) { - int optflags = co->opt->flags; + uint64_t optflags = co->opt->flags; bool set = !(flags & M_SETOPT_CHECK_ONLY); if ((flags & M_SETOPT_PRE_PARSE_ONLY) && !(optflags & M_OPT_PRE_PARSE)) diff --git a/options/m_config_frontend.h b/options/m_config_frontend.h index 10b27206348d8..a5f82837e81f8 100644 --- a/options/m_config_frontend.h +++ b/options/m_config_frontend.h @@ -87,7 +87,7 @@ typedef struct m_config { // m_config_notify_change_opt_ptr(). If false, it's caused either by // m_config_set_option_*() (and similar) calls or external updates. void (*option_change_callback)(void *ctx, struct m_config_option *co, - int flags, bool self_update); + uint64_t flags, bool self_update); void *option_change_callback_ctx; // For the command line parser diff --git a/options/m_option.h b/options/m_option.h index dc71f808f7c35..e11d844c93e8c 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -215,7 +215,7 @@ struct m_sub_options { const void *defaults; // Change flags passed to mp_option_change_callback() if any option that is // directly or indirectly part of this group is changed. - int change_flags; + uint64_t change_flags; // Return further sub-options, for example for optional components. If set, // this is called with increasing index (starting from 0), as long as true // is returned. If true is returned and *sub is set in any of these calls, @@ -385,7 +385,7 @@ struct m_option { const m_option_type_t *type; // See \ref OptionFlags. - unsigned int flags; + uint64_t flags; // Always force an option update even if the written value does not change. bool force_update; diff --git a/player/command.c b/player/command.c index 478970bdad199..a5db12fb6821f 100644 --- a/player/command.c +++ b/player/command.c @@ -7619,7 +7619,7 @@ static void update_track_switch(struct MPContext *mpctx, int order, int type) mp_wakeup_core(mpctx); } -void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, +void mp_option_change_callback(void *ctx, struct m_config_option *co, uint64_t flags, bool self_update) { struct MPContext *mpctx = ctx; @@ -7643,8 +7643,7 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, struct track *track = mpctx->current_track[n][STREAM_SUB]; struct dec_sub *sub = track ? track->d_sub : NULL; if (sub) { - int ret = sub_control(sub, SD_CTRL_UPDATE_OPTS, - (void *)(uintptr_t)flags); + int ret = sub_control(sub, SD_CTRL_UPDATE_OPTS, &flags); if (ret == CONTROL_OK && flags & (UPDATE_SUB_FILT | UPDATE_SUB_HARD)) { sub_redecode_cached_packets(sub); sub_reset(sub); diff --git a/player/command.h b/player/command.h index 48b4518553fda..b56bfb50db9d5 100644 --- a/player/command.h +++ b/player/command.h @@ -80,7 +80,7 @@ void property_print_help(struct MPContext *mpctx); int mp_property_do(const char* name, int action, void* val, struct MPContext *mpctx); -void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, +void mp_option_change_callback(void *ctx, struct m_config_option *co, uint64_t flags, bool self_update); void mp_notify(struct MPContext *mpctx, int event, void *arg); diff --git a/sub/dec_sub.c b/sub/dec_sub.c index ce51fdf8c8e25..fb8a84826e6ae 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -515,7 +515,7 @@ int sub_control(struct dec_sub *sub, enum sd_ctrl cmd, void *arg) break; } case SD_CTRL_UPDATE_OPTS: { - int flags = (uintptr_t)arg; + uint64_t flags = *(uint64_t *)arg; if (m_config_cache_update(sub->opts_cache)) update_subtitle_speed(sub); m_config_cache_update(sub->shared_opts_cache); diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 4f9cd3eb48eeb..8d999933ca7f5 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -1020,7 +1020,7 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) ctx->video_params = *(struct mp_image_params *)arg; return CONTROL_OK; case SD_CTRL_UPDATE_OPTS: { - int flags = (uintptr_t)arg; + uint64_t flags = *(uint64_t *)arg; if (flags & UPDATE_SUB_FILT) { filters_destroy(sd); filters_init(sd); From aba26254fef1adc2fbb222e0f28655b0e531e2d6 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Tue, 31 Dec 2024 11:39:57 +0100 Subject: [PATCH 3/3] m_option: convert option_flags to 64-bit Add UINT64_C() and make them end from 61. This will allow adding more UPDATE flags without changing all option_flags. --- options/m_option.h | 76 +++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/options/m_option.h b/options/m_option.h index e11d844c93e8c..25c03bfae41a1 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -426,38 +426,50 @@ char *format_file_size(int64_t size); enum option_flags { // The following are also part of the M_OPT_* flags, and are used to update // certain groups of options. - UPDATE_TERM = (1 << 0), // terminal options - UPDATE_SUB_FILT = (1 << 1), // subtitle filter options - UPDATE_OSD = (1 << 2), // related to OSD rendering - UPDATE_BUILTIN_SCRIPTS = (1 << 3), // osc/ytdl/stats - UPDATE_IMGPAR = (1 << 4), // video image params overrides - UPDATE_INPUT = (1 << 5), // mostly --input-* options - UPDATE_AUDIO = (1 << 6), // --audio-channels etc. - UPDATE_PRIORITY = (1 << 7), // --priority (Windows-only) - UPDATE_SCREENSAVER = (1 << 8), // --stop-screensaver - UPDATE_VOL = (1 << 9), // softvol related options - UPDATE_LAVFI_COMPLEX = (1 << 10), // --lavfi-complex - UPDATE_HWDEC = (1 << 11), // --hwdec - UPDATE_DVB_PROG = (1 << 12), // some --dvbin-... - UPDATE_SUB_HARD = (1 << 13), // subtitle opts. that need full reinit - UPDATE_SUB_EXTS = (1 << 14), // update internal list of sub exts - UPDATE_VIDEO = (1 << 15), // force redraw if needed - UPDATE_VO = (1 << 16), // reinit the VO - UPDATE_CLIPBOARD = (1 << 17), // reinit the clipboard - UPDATE_OPT_LAST = (1 << 17), - - M_OPT_NOCFG = (1 << 30), // The option is forbidden in config files. - M_OPT_PRE_PARSE = (1 << 29), // The option should be set during command line pre-parsing - M_OPT_FILE = (1 << 28), // The option expects a file name (or a list of file names) - M_OPT_NOPROP = (1 << 27), // Do not add as property. - M_OPT_HAVE_HELP = (1 << 26), // Enable special semantics for some options when parsing the string "help". - - M_OPT_DEFAULT_NAN = (1 << 25), // type_float/type_double: string "default" is parsed as NaN (and reverse) - M_OPT_ALLOW_NO = (1 << 24), // type time: string "no" maps to MP_NOPTS_VALUE (if unset, NOPTS is rejected) - // and parsing: "--no-opt" is parsed as "--opt=no" - M_OPT_CHANNELS_LIMITED = (1 << 23), // type channels: disallow "auto" (still accept ""), limit list to at most 1 item. - M_OPT_FIXED_LEN_PRINT = (1 << 22), // type_float/type_double: controls if pretty print should trim trailing zeros - M_OPT_OPTIONAL_PARAM = (1 << 21), // Like M_OPT_TYPE_OPTIONAL_PARAM. + UPDATE_TERM = (UINT64_C(1) << 0), // terminal options + UPDATE_SUB_FILT = (UINT64_C(1) << 1), // subtitle filter options + UPDATE_OSD = (UINT64_C(1) << 2), // related to OSD rendering + UPDATE_BUILTIN_SCRIPTS = (UINT64_C(1) << 3), // osc/ytdl/stats + UPDATE_IMGPAR = (UINT64_C(1) << 4), // video image params overrides + UPDATE_INPUT = (UINT64_C(1) << 5), // mostly --input-* options + UPDATE_AUDIO = (UINT64_C(1) << 6), // --audio-channels etc. + UPDATE_PRIORITY = (UINT64_C(1) << 7), // --priority (Windows-only) + UPDATE_SCREENSAVER = (UINT64_C(1) << 8), // --stop-screensaver + UPDATE_VOL = (UINT64_C(1) << 9), // softvol related options + UPDATE_LAVFI_COMPLEX = (UINT64_C(1) << 10), // --lavfi-complex + UPDATE_HWDEC = (UINT64_C(1) << 11), // --hwdec + UPDATE_DVB_PROG = (UINT64_C(1) << 12), // some --dvbin-... + UPDATE_SUB_HARD = (UINT64_C(1) << 13), // subtitle opts. that need full reinit + UPDATE_SUB_EXTS = (UINT64_C(1) << 14), // update internal list of sub exts + UPDATE_VIDEO = (UINT64_C(1) << 15), // force redraw if needed + UPDATE_VO = (UINT64_C(1) << 16), // reinit the VO + UPDATE_CLIPBOARD = (UINT64_C(1) << 17), // reinit the clipboard + UPDATE_OPT_LAST = (UINT64_C(1) << 17), + + // The option is forbidden in config files. + M_OPT_NOCFG = (UINT64_C(1) << 61), + // The option should be set during command line pre-parsing + M_OPT_PRE_PARSE = (UINT64_C(1) << 60), + // The option expects a file name (or a list of file names) + M_OPT_FILE = (UINT64_C(1) << 59), + // Do not add as property. + M_OPT_NOPROP = (UINT64_C(1) << 58), + // Enable special semantics for some options when parsing the string "help". + M_OPT_HAVE_HELP = (UINT64_C(1) << 57), + + // type_float/type_double: string "default" is parsed as NaN (and reverse) + M_OPT_DEFAULT_NAN = (UINT64_C(1) << 56), + // type time: string "no" maps to MP_NOPTS_VALUE (if unset, NOPTS is + // rejected) and parsing: "--no-opt" is parsed as "--opt=no" + M_OPT_ALLOW_NO = (UINT64_C(1) << 55), + // type channels: disallow "auto" (still accept ""), limit list to at most 1 + // item. + M_OPT_CHANNELS_LIMITED = (UINT64_C(1) << 54), + // type_float/type_double: controls if pretty print should trim trailing + // zeros + M_OPT_FIXED_LEN_PRINT = (UINT64_C(1) << 53), + // Like M_OPT_TYPE_OPTIONAL_PARAM. + M_OPT_OPTIONAL_PARAM = (UINT64_C(1) << 52), }; #define UPDATE_OPTS_MASK ((UPDATE_OPT_LAST << 1) - 1)