summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2022-05-13 21:15:37 -0500
committerDudemanguy <random342@airmail.cc>2022-05-16 21:10:09 +0000
commitf20dbcd620ace15ff132d49e873adcb0d9527595 (patch)
tree2ffa939c93c139ad2fa147ab01067432c95d9218 /player
parent94677723624fb84756e65c8f1377956667244bc9 (diff)
downloadmpv-f20dbcd620ace15ff132d49e873adcb0d9527595.tar.bz2
mpv-f20dbcd620ace15ff132d49e873adcb0d9527595.tar.xz
player: check for argv before printing help text
Both mpv's main function and the client API use mp_initialize to start up. In general, these work the same however the client API had one slight, unnecessary limitation: you can't start it up with idle=no. In practice, the libmpv profile (used with the client API) sets idle to yes, so it's rarely encountered, but there's no particular reason why this policy needs to be enforced. It turns out that mp_initialize does a quick check to see if there are any entries in the playlist and if idle mode is set. If not, it prints the help message and exits. Basically, it's just the part that handles the terminal message when you type "mpv" with no arguments. Unfortunately with idle=no, the client API also hits this code path, exits prematurely with 1 and thus returns an API error. Fortunately, the fix is very simple. If the client API is used instead of the "normal" mpv executable, then the mp_initialize function gets a NULL for the options argument. When starting mpv from the terminal (when you would want to see the before mentioned help text), there will always be at least an argv[0] (the mpv executable name itself) so we can reliably distinguish between the two. The other case where there could be no argv is if the pseudo-gui profile is used, but this always enforces idle so we don't have to worry about it either. In other words, with this combination of conditions (options, no idle, and no playlist entries), we can be sure this is from a user calling mpv in the terminal with no arguments. Therefore, other cases can be allowed which means client API users can initialize with idle=no. Fixes #10162.
Diffstat (limited to 'player')
-rw-r--r--player/main.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/player/main.c b/player/main.c
index e039f61975..7c1f5d8831 100644
--- a/player/main.c
+++ b/player/main.c
@@ -378,7 +378,9 @@ int mp_initialize(struct MPContext *mpctx, char **options)
return run_tests(mpctx) ? 1 : -1;
#endif
- if (!mpctx->playlist->num_entries && !opts->player_idle_mode) {
+ if (!mpctx->playlist->num_entries && !opts->player_idle_mode &&
+ options)
+ {
// nothing to play
mp_print_version(mpctx->log, true);
MP_INFO(mpctx, "%s", mp_help_text);