summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-12-29 17:19:25 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-01-02 14:27:37 -0800
commit6aad532aa39481a8100910612fad039dd75236b9 (patch)
tree53c790d6c66917e66039c25a13cdf27f90bbf0d9 /player/command.c
parent3bf7df4a5e1f46248c78e9e596cd8dab6ff57356 (diff)
downloadmpv-6aad532aa39481a8100910612fad039dd75236b9.tar.bz2
mpv-6aad532aa39481a8100910612fad039dd75236b9.tar.xz
options: move most subtitle and OSD rendering options to sub structs
Remove them from the big MPOpts struct and move them to their sub structs. In the places where their fields are used, create a private copy of the structs, instead of accessing the semi-deprecated global option struct instance (mpv_global.opts) directly. This actually makes accessing these options finally thread-safe. They weren't even if they should have for years. (Including some potential for undefined behavior when e.g. the OSD font was changed at runtime.) This is mostly transparent. All options get moved around, but most users of the options just need to access a different struct (changing sd.opts to a different type changes a lot of uses, for example). One thing which has to be considered and could cause potential regressions is that the new option copies must be explicitly updated. sub_update_opts() takes care of this for example. Another thing is that writing to the option structs manually won't work, because the changes won't be propagated to other copies. Apparently the only affected case is the implementation of the sub-step command, which tries to change sub_delay. Handle this one explicitly (osd_changed() doesn't need to be called anymore, because changing the option triggers UPDATE_OSD, and updates the OSD as a consequence). The way the option value is propagated is rather hacky, but for now this will do.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/player/command.c b/player/command.c
index 61d47a2319..48206f527d 100644
--- a/player/command.c
+++ b/player/command.c
@@ -3040,7 +3040,7 @@ static int mp_property_sub_delay(void *ctx, struct m_property *prop,
struct MPOpts *opts = mpctx->opts;
switch (action) {
case M_PROPERTY_PRINT:
- *(char **)arg = format_delay(opts->sub_delay);
+ *(char **)arg = format_delay(opts->subs_rend->sub_delay);
return M_PROPERTY_OK;
}
return mp_property_generic_option(mpctx, prop, action, arg);
@@ -3053,7 +3053,8 @@ static int mp_property_sub_speed(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
if (action == M_PROPERTY_PRINT) {
- *(char **)arg = talloc_asprintf(NULL, "%4.1f%%", 100 * opts->sub_speed);
+ *(char **)arg =
+ talloc_asprintf(NULL, "%4.1f%%", 100 * opts->subs_rend->sub_speed);
return M_PROPERTY_OK;
}
return mp_property_generic_option(mpctx, prop, action, arg);
@@ -3065,7 +3066,7 @@ static int mp_property_sub_pos(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
struct MPOpts *opts = mpctx->opts;
if (action == M_PROPERTY_PRINT) {
- *(char **)arg = talloc_asprintf(NULL, "%d/100", opts->sub_pos);
+ *(char **)arg = talloc_asprintf(NULL, "%d/100", opts->subs_rend->sub_pos);
return M_PROPERTY_OK;
}
return mp_property_generic_option(mpctx, prop, action, arg);
@@ -5080,8 +5081,9 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
a[1] = cmd->args[0].v.i;
if (sub_control(sub, SD_CTRL_SUB_STEP, a) > 0) {
if (cmd->id == MP_CMD_SUB_STEP) {
- opts->sub_delay -= a[0] - refpts;
- osd_changed(mpctx->osd);
+ opts->subs_rend->sub_delay -= a[0] - refpts;
+ m_config_notify_change_opt_ptr(mpctx->mconfig,
+ &opts->subs_rend->sub_delay);
show_property_osd(mpctx, "sub-delay", on_osd);
} else {
// We can easily get stuck by failing to seek to the video
@@ -5765,13 +5767,13 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags)
recreate_auto_filters(mpctx);
if (flags & UPDATE_OSD) {
- osd_changed(mpctx->osd);
for (int n = 0; n < NUM_PTRACKS; n++) {
struct track *track = mpctx->current_track[n][STREAM_SUB];
struct dec_sub *sub = track ? track->d_sub : NULL;
if (sub)
- sub_control(track->d_sub, SD_CTRL_UPDATE_SPEED, NULL);
+ sub_update_opts(track->d_sub);
}
+ osd_changed(mpctx->osd);
mp_wakeup_core(mpctx);
}