options: remove options-to-property bridge

The previous bunch of commits made this unnecessary, so this should be
a purely internal change with no user impact.

This may or may not open the way to future improvements. Even if not,
at least the property/option interaction should now be much less buggy.
This commit is contained in:
wm4 2019-11-25 20:25:20 +01:00
parent 78bb1586d3
commit 7c6570402b
6 changed files with 6 additions and 85 deletions

View File

@ -814,9 +814,9 @@ static int m_config_handle_special_options(struct m_config *config,
return M_OPT_UNKNOWN;
}
int m_config_set_option_raw_direct(struct m_config *config,
struct m_config_option *co,
void *data, int flags)
int m_config_set_option_raw(struct m_config *config,
struct m_config_option *co,
void *data, int flags)
{
if (!co)
return M_OPT_UNKNOWN;
@ -842,24 +842,6 @@ int m_config_set_option_raw_direct(struct m_config *config,
return 0;
}
int m_config_set_option_raw(struct m_config *config, struct m_config_option *co,
void *data, int flags)
{
if (!co)
return M_OPT_UNKNOWN;
if (config->option_set_callback) {
int r = handle_set_opt_flags(config, co, flags);
if (r <= 1)
return r;
return config->option_set_callback(config->option_set_callback_cb,
co, data, flags);
} else {
return m_config_set_option_raw_direct(config, co, data, flags);
}
}
// Handle CLI exceptions to option handling.
// Used to turn "--no-foo" into "--foo=no".
// It also handles looking up "--vf-add" as "--vf".

View File

@ -71,11 +71,6 @@ typedef struct m_config {
int (*includefunc)(void *ctx, char *filename, int flags);
void *includefunc_ctx;
// Can intercept option write accesses.
int (*option_set_callback)(void *ctx, struct m_config_option *co,
void *data, int flags);
void *option_set_callback_cb;
// Notification after an option was successfully written to.
// Uses flags as set in UPDATE_OPTS_MASK.
void (*option_change_callback)(void *ctx, struct m_config_option *co,
@ -169,12 +164,6 @@ int m_config_set_option_raw(struct m_config *config, struct m_config_option *co,
void m_config_mark_co_flags(struct m_config_option *co, int flags);
// Unlike m_config_set_option_raw() this does not go through the property layer
// via config.option_set_callback.
int m_config_set_option_raw_direct(struct m_config *config,
struct m_config_option *co,
void *data, int flags);
// Convert the mpv_node to raw option data, then call m_config_set_option_raw().
struct mpv_node;
int m_config_set_option_node(struct m_config *config, bstr name,

View File

@ -374,53 +374,6 @@ static char *format_delay(double time)
return talloc_asprintf(NULL, "%d ms", (int)lrint(time * 1000));
}
// Option-property bridge. This is used so that setting options via various
// mechanisms (including command line parsing, config files, per-file options)
// updates state associated with them. For that, they have to go through the
// property layer. (Ideally, this would be the other way around, and there
// would be per-option change handlers instead.)
// Note that the property-option bridge sidesteps this, as we'd get infinite
// recursion.
int mp_on_set_option(void *ctx, struct m_config_option *co, void *data, int flags)
{
struct MPContext *mpctx = ctx;
struct command_ctx *cmd = mpctx->command_ctx;
const char *name = co->name;
// Skip going through mp_property_generic_option (typically), because the
// property implementation is trivial, and can break some obscure features
// like --profile and --include if non-trivial flags are involved (which
// the bridge would drop).
struct m_property *prop = m_property_list_find(cmd->properties, name);
if (prop && prop->is_option)
goto direct_option;
struct m_option type = {0};
int r = mp_property_do_silent(name, M_PROPERTY_GET_TYPE, &type, mpctx);
if (r == M_PROPERTY_UNKNOWN)
goto direct_option; // not mapped as property
if (r != M_PROPERTY_OK)
return M_OPT_INVALID; // shouldn't happen
assert(type.type == co->opt->type);
assert(type.max == co->opt->max);
assert(type.min == co->opt->min);
r = mp_property_do_silent(name, M_PROPERTY_SET, data, mpctx);
if (r != M_PROPERTY_OK)
return M_OPT_INVALID;
// The flags can't be passed through the property layer correctly.
m_config_mark_co_flags(co, flags);
return 0;
direct_option:
mp_notify_property(mpctx, name);
return m_config_set_option_raw_direct(mpctx->mconfig, co, data, flags);
}
// Property-option bridge. (Maps the property to the option with the same name.)
static int mp_property_generic_option(void *ctx, struct m_property *prop,
int action, void *arg)
@ -448,7 +401,7 @@ static int mp_property_generic_option(void *ctx, struct m_property *prop,
m_option_copy(opt->opt, arg, opt->data);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (m_config_set_option_raw_direct(mpctx->mconfig, opt, arg, 0) < 0)
if (m_config_set_option_raw(mpctx->mconfig, opt, arg, 0) < 0)
return M_PROPERTY_ERROR;
return M_PROPERTY_OK;
}
@ -2643,7 +2596,7 @@ skip_warn: ;
return M_PROPERTY_OK;
}
case M_PROPERTY_SET:
if (m_config_set_option_raw_direct(mpctx->mconfig, opt, arg, 0) < 0)
if (m_config_set_option_raw(mpctx->mconfig, opt, arg, 0) < 0)
return M_PROPERTY_ERROR;
return M_PROPERTY_OK;
}

View File

@ -78,7 +78,6 @@ void property_print_help(struct MPContext *mpctx);
int mp_property_do(const char* name, int action, void* val,
struct MPContext *mpctx);
int mp_on_set_option(void *ctx, struct m_config_option *co, void *data, int flags);
void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags);
void mp_notify(struct MPContext *mpctx, int event, void *arg);

View File

@ -378,8 +378,6 @@ int mp_initialize(struct MPContext *mpctx, char **options)
// From this point on, all mpctx members are initialized.
mpctx->initialized = true;
mpctx->mconfig->option_set_callback = mp_on_set_option;
mpctx->mconfig->option_set_callback_cb = mpctx;
mpctx->mconfig->option_change_callback = mp_option_change_callback;
mpctx->mconfig->option_change_callback_ctx = mpctx;
// Run all update handlers.

View File

@ -844,7 +844,7 @@ static void handle_vo_events(struct MPContext *mpctx)
int fs = old_fs;
vo_control(vo, VOCTRL_GET_FULLSCREEN, &fs);
if (old_fs != fs) {
m_config_set_option_raw_direct(mpctx->mconfig,
m_config_set_option_raw(mpctx->mconfig,
m_config_get_co(mpctx->mconfig, bstr0("fullscreen")), &fs, 0);
}
}