mirror of
https://github.com/mpv-player/mpv
synced 2025-02-21 23:36:58 +00:00
client API: allow multiple mpv instances with terminal=yes
This is simply not allowed, and doing it triggered an assertion. It's still not allowed, because the terminal and related functionality is a global resource, and there doesn't seem to be a sane way to manage the signal handlers. But be a bit nicer, and just the terminal if it's already in use. Note that terminal _output_ happens anyway. This becomes usable with this commit. To facilitate logging-only usage further, also explicitly disable terminal input, so that "terminal=yes" can be used for logging without much interference with other things. (It'll still overwrite some signal handlers, though.)
This commit is contained in:
parent
ef1c7563c5
commit
f984b79720
@ -409,6 +409,7 @@ mpv_handle *mpv_create(void)
|
|||||||
mpv_set_option_string(ctx, "config", "no");
|
mpv_set_option_string(ctx, "config", "no");
|
||||||
mpv_set_option_string(ctx, "idle", "yes");
|
mpv_set_option_string(ctx, "idle", "yes");
|
||||||
mpv_set_option_string(ctx, "terminal", "no");
|
mpv_set_option_string(ctx, "terminal", "no");
|
||||||
|
mpv_set_option_string(ctx, "input-terminal", "no");
|
||||||
mpv_set_option_string(ctx, "osc", "no");
|
mpv_set_option_string(ctx, "osc", "no");
|
||||||
mpv_set_option_string(ctx, "ytdl", "no");
|
mpv_set_option_string(ctx, "ytdl", "no");
|
||||||
mpv_set_option_string(ctx, "input-default-bindings", "no");
|
mpv_set_option_string(ctx, "input-default-bindings", "no");
|
||||||
|
@ -77,12 +77,6 @@
|
|||||||
#include "osdep/macosx_events.h"
|
#include "osdep/macosx_events.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PTW32_STATIC_LIB
|
|
||||||
#include <pthread.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool terminal_initialized;
|
|
||||||
|
|
||||||
enum exit_reason {
|
enum exit_reason {
|
||||||
EXIT_NONE,
|
EXIT_NONE,
|
||||||
EXIT_NORMAL,
|
EXIT_NORMAL,
|
||||||
@ -103,6 +97,19 @@ const char mp_help_text[] =
|
|||||||
" --list-options list all mpv options\n"
|
" --list-options list all mpv options\n"
|
||||||
"\n";
|
"\n";
|
||||||
|
|
||||||
|
static pthread_mutex_t terminal_owner_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
static struct MPContext *terminal_owner;
|
||||||
|
|
||||||
|
static bool cas_terminal_owner(struct MPContext *old, struct MPContext *new)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&terminal_owner_lock);
|
||||||
|
bool r = terminal_owner == old;
|
||||||
|
if (r)
|
||||||
|
terminal_owner = new;
|
||||||
|
pthread_mutex_unlock(&terminal_owner_lock);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
void mp_print_version(struct mp_log *log, int always)
|
void mp_print_version(struct mp_log *log, int always)
|
||||||
{
|
{
|
||||||
int v = always ? MSGL_INFO : MSGL_V;
|
int v = always ? MSGL_INFO : MSGL_V;
|
||||||
@ -147,9 +154,9 @@ void mp_destroy(struct MPContext *mpctx)
|
|||||||
|
|
||||||
osd_free(mpctx->osd);
|
osd_free(mpctx->osd);
|
||||||
|
|
||||||
if (mpctx->opts->use_terminal && terminal_initialized) {
|
if (cas_terminal_owner(mpctx, mpctx)) {
|
||||||
terminal_uninit();
|
terminal_uninit();
|
||||||
terminal_initialized = false;
|
cas_terminal_owner(mpctx, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_dispatch_set_wakeup_fn(mpctx->dispatch, NULL, NULL);
|
mp_dispatch_set_wakeup_fn(mpctx->dispatch, NULL, NULL);
|
||||||
@ -378,11 +385,10 @@ int mp_initialize(struct MPContext *mpctx)
|
|||||||
}
|
}
|
||||||
MP_STATS(mpctx, "start init");
|
MP_STATS(mpctx, "start init");
|
||||||
|
|
||||||
if (mpctx->opts->use_terminal && !terminal_initialized) {
|
if (mpctx->opts->use_terminal && cas_terminal_owner(NULL, mpctx))
|
||||||
terminal_initialized = true;
|
|
||||||
terminal_init();
|
terminal_init();
|
||||||
|
|
||||||
mp_msg_update_msglevels(mpctx->global);
|
mp_msg_update_msglevels(mpctx->global);
|
||||||
}
|
|
||||||
|
|
||||||
if (opts->slave_mode) {
|
if (opts->slave_mode) {
|
||||||
MP_WARN(mpctx, "--slave-broken is deprecated (see manpage).\n");
|
MP_WARN(mpctx, "--slave-broken is deprecated (see manpage).\n");
|
||||||
@ -417,7 +423,7 @@ int mp_initialize(struct MPContext *mpctx)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (opts->use_terminal && opts->consolecontrols && terminal_initialized)
|
if (opts->consolecontrols && cas_terminal_owner(mpctx, mpctx))
|
||||||
terminal_setup_getch(mpctx->input);
|
terminal_setup_getch(mpctx->input);
|
||||||
|
|
||||||
#if !HAVE_LIBASS
|
#if !HAVE_LIBASS
|
||||||
@ -486,10 +492,8 @@ int mpv_main(int argc, char *argv[])
|
|||||||
// Preparse the command line
|
// Preparse the command line
|
||||||
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, argc, argv);
|
m_config_preparse_command_line(mpctx->mconfig, mpctx->global, argc, argv);
|
||||||
|
|
||||||
if (mpctx->opts->use_terminal && !terminal_initialized) {
|
if (mpctx->opts->use_terminal && cas_terminal_owner(NULL, mpctx))
|
||||||
terminal_initialized = true;
|
|
||||||
terminal_init();
|
terminal_init();
|
||||||
}
|
|
||||||
|
|
||||||
mp_msg_update_msglevels(mpctx->global);
|
mp_msg_update_msglevels(mpctx->global);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user