summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2024-03-01 17:38:35 -0600
committerDudemanguy <random342@airmail.cc>2024-03-21 14:48:53 +0000
commit91489c946689763c36e4d720d6048037252818f7 (patch)
treed6dcbf5aa8d09f8ff6c572b52ff56114704bcf0e /player/command.c
parent46a35e2edc1905a9cbe4674f454ef056a6d1eef4 (diff)
downloadmpv-91489c946689763c36e4d720d6048037252818f7.tar.bz2
mpv-91489c946689763c36e4d720d6048037252818f7.tar.xz
options: add --input-commands option
Basically a simple way to perform any command/property action from the command line. This takes the exact same syntax as input.conf but not including the key naturally. Potentially useful for weird properties that don't map well to options (like ao-volume). Fixes #12353.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index b5f9ad8065..ed4def2813 100644
--- a/player/command.c
+++ b/player/command.c
@@ -94,6 +94,8 @@ struct command_ctx {
char **warned_deprecated;
int num_warned_deprecated;
+ bool command_opts_processed;
+
struct overlay *overlays;
int num_overlays;
// One of these is in use by the OSD; the other one exists so that the
@@ -7161,6 +7163,27 @@ void handle_command_updates(struct MPContext *mpctx)
// Depends on polling demuxer wakeup callback notifications.
cache_dump_poll(mpctx);
+
+ // Potentially run the commands now (idle) instead of waiting for a file to load.
+ if (mpctx->stop_play == PT_STOP)
+ run_command_opts(mpctx);
+}
+
+void run_command_opts(struct MPContext *mpctx)
+{
+ struct MPOpts *opts = mpctx->opts;
+ struct command_ctx *ctx = mpctx->command_ctx;
+
+ if (!opts->input_commands || ctx->command_opts_processed)
+ return;
+
+ // Take easy way out and add these to the input queue.
+ for (int i = 0; opts->input_commands[i]; i++) {
+ struct mp_cmd *cmd = mp_input_parse_cmd(mpctx->input, bstr0(opts->input_commands[i]),
+ "the command line");
+ mp_input_queue_cmd(mpctx->input, cmd);
+ }
+ ctx->command_opts_processed = true;
}
void mp_notify(struct MPContext *mpctx, int event, void *arg)
@@ -7299,6 +7322,11 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
vo_control(mpctx->video_out, VOCTRL_EXTERNAL_RESIZE, NULL);
}
+ if (opt_ptr == &opts->input_commands) {
+ mpctx->command_ctx->command_opts_processed = false;
+ run_command_opts(mpctx);
+ }
+
if (opt_ptr == &opts->playback_speed) {
update_playback_speed(mpctx);
mp_wakeup_core(mpctx);