diff options
Diffstat (limited to 'player')
-rw-r--r-- | player/client.c | 29 | ||||
-rw-r--r-- | player/loadfile.c | 3 | ||||
-rw-r--r-- | player/main.c | 1 |
3 files changed, 26 insertions, 7 deletions
diff --git a/player/client.c b/player/client.c index 3a1d204ce8..bc9785d04c 100644 --- a/player/client.c +++ b/player/client.c @@ -144,6 +144,7 @@ struct mpv_handle { bool fuzzy_initialized; // see scripting.c wait_loaded() bool is_weak; // can not keep core alive on its own struct mp_log_buffer *messages; + int messages_level; }; static bool gen_log_message_event(struct mpv_handle *ctx); @@ -1703,29 +1704,43 @@ static void msg_wakeup(void *p) wakeup_client(ctx); } +// Undocumented: if min_level starts with "silent:", then log messages are not +// returned to the API user, but are stored until logging is enabled normally +// again by calling this without "silent:". (Using a different level will +// flush it, though.) int mpv_request_log_messages(mpv_handle *ctx, const char *min_level) { + bstr blevel = bstr0(min_level); + bool silent = bstr_eatstart0(&blevel, "silent:"); + int level = -1; for (int n = 0; n < MSGL_MAX + 1; n++) { - if (mp_log_levels[n] && strcmp(min_level, mp_log_levels[n]) == 0) { + if (mp_log_levels[n] && bstr_equals0(blevel, mp_log_levels[n])) { level = n; break; } } - if (strcmp(min_level, "terminal-default") == 0) + if (bstr_equals0(blevel, "terminal-default")) level = MP_LOG_BUFFER_MSGL_TERM; if (level < 0 && strcmp(min_level, "no") != 0) return MPV_ERROR_INVALID_PARAMETER; pthread_mutex_lock(&ctx->lock); - mp_msg_log_buffer_destroy(ctx->messages); - ctx->messages = NULL; + if (level < 0 || level != ctx->messages_level) { + mp_msg_log_buffer_destroy(ctx->messages); + ctx->messages = NULL; + } if (level >= 0) { - int size = level >= MSGL_V ? 10000 : 1000; - ctx->messages = mp_msg_log_buffer_new(ctx->mpctx->global, size, level, - msg_wakeup, ctx); + if (!ctx->messages) { + int size = level >= MSGL_V ? 10000 : 1000; + ctx->messages = mp_msg_log_buffer_new(ctx->mpctx->global, size, + level, msg_wakeup, ctx); + ctx->messages_level = level; + } + mp_msg_log_buffer_set_silent(ctx->messages, silent); } + wakeup_client(ctx); pthread_mutex_unlock(&ctx->lock); return 0; } diff --git a/player/loadfile.c b/player/loadfile.c index 09b7167f60..9d515b2012 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -35,6 +35,7 @@ #include "client.h" #include "common/msg.h" +#include "common/msg_control.h" #include "common/global.h" #include "options/path.h" #include "options/m_config.h" @@ -1766,6 +1767,8 @@ void mp_play_files(struct MPContext *mpctx) mp_wakeup_core(mpctx); // avoid lost wakeups during waiting MP_VERBOSE(mpctx, "Done loading scripts.\n"); } + // After above is finished; but even if it's skipped. + mp_msg_set_early_logging(mpctx->global, false); prepare_playlist(mpctx, mpctx->playlist); diff --git a/player/main.c b/player/main.c index b6c9e1085d..d633871399 100644 --- a/player/main.c +++ b/player/main.c @@ -345,6 +345,7 @@ int mp_initialize(struct MPContext *mpctx, char **options) } mp_init_paths(mpctx->global, opts); + mp_msg_set_early_logging(mpctx->global, true); mp_update_logging(mpctx, true); if (options) { |