diff options
author | wm4 <wm4@nowhere> | 2016-09-20 00:59:54 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-09-20 01:24:27 +0200 |
commit | fb67db8b72a329fd017409338d6742c773ce85bf (patch) | |
tree | ff0a6dc6d6ba554d9ecf867147bc1bbd0d663a15 /player | |
parent | bf5c97a6c38352d492020cd5d6c7563c709bca9d (diff) | |
download | mpv-fb67db8b72a329fd017409338d6742c773ce85bf.tar.bz2 mpv-fb67db8b72a329fd017409338d6742c773ce85bf.tar.xz |
player: make --osc/--ytdl settable during playback
Setting the osc or ytdl properties will now load/unload the associated
scripts. (For ytdl this does not mean the currently played URL will be
reloaded.)
Also add a changelog entry for this, which also covers the preceding
work for --terminal.
Diffstat (limited to 'player')
-rw-r--r-- | player/command.c | 3 | ||||
-rw-r--r-- | player/core.h | 1 | ||||
-rw-r--r-- | player/scripting.c | 36 |
3 files changed, 36 insertions, 4 deletions
diff --git a/player/command.c b/player/command.c index d6c0f9cf08..d5d95602a6 100644 --- a/player/command.c +++ b/player/command.c @@ -5603,6 +5603,9 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags) osd_changed(mpctx->osd); mp_wakeup_core(mpctx); } + + if (flags & UPDATE_BUILTIN_SCRIPTS) + mp_load_builtin_scripts(mpctx); } void mp_notify_property(struct MPContext *mpctx, const char *property) diff --git a/player/core.h b/player/core.h index df2df834fa..d67a9d62ad 100644 --- a/player/core.h +++ b/player/core.h @@ -549,6 +549,7 @@ struct mp_scripting { int (*load)(struct mpv_handle *client, const char *filename); }; void mp_load_scripts(struct MPContext *mpctx); +void mp_load_builtin_scripts(struct MPContext *mpctx); // sub.c void reset_subtitle_state(struct MPContext *mpctx); diff --git a/player/scripting.c b/player/scripting.c index afa567ca6a..b6ba69ac07 100644 --- a/player/scripting.c +++ b/player/scripting.c @@ -176,13 +176,41 @@ static char **list_script_files(void *talloc_ctx, char *path) return files; } +static void load_builtin_script(struct MPContext *mpctx, bool enable, + const char *fname) +{ + void *tmp = talloc_new(NULL); + // (The name doesn't have to match if there were conflicts with other + // scripts, so this is on best-effort basis.) + char *name = script_name_from_filename(tmp, fname); + if (enable != mp_client_exists(mpctx, name)) { + if (enable) { + mp_load_script(mpctx, fname); + } else { + // Try to unload it by sending a shutdown event. Wait until it has + // terminated, or re-enabling the script could be racy (because it'd + // recognize a still-terminating script as "loaded"). + while (mp_client_exists(mpctx, name)) { + if (mp_client_send_event(mpctx, name, MPV_EVENT_SHUTDOWN, NULL) < 0) + break; + mp_idle(mpctx); + } + mp_wakeup_core(mpctx); // avoid lost wakeups during waiting + } + } + talloc_free(tmp); +} + +void mp_load_builtin_scripts(struct MPContext *mpctx) +{ + load_builtin_script(mpctx, mpctx->opts->lua_load_osc, "@osc.lua"); + load_builtin_script(mpctx, mpctx->opts->lua_load_ytdl, "@ytdl_hook.lua"); +} + void mp_load_scripts(struct MPContext *mpctx) { // Load scripts from options - if (mpctx->opts->lua_load_osc) - mp_load_script(mpctx, "@osc.lua"); - if (mpctx->opts->lua_load_ytdl) - mp_load_script(mpctx, "@ytdl_hook.lua"); + mp_load_builtin_scripts(mpctx); char **files = mpctx->opts->script_files; for (int n = 0; files && files[n]; n++) { if (files[n][0]) |