From 4d4b82217126de3160299b3aefba1f6941623d30 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 18 Dec 2013 15:03:08 +0100 Subject: terminal: abstract terminal color handling Instead of making msg.c an ifdef hell for unix vs. windows code, move the code to separate functions defined in terminal-unix.c/terminal- win.c. Drop the code that selects random colors for --msgmodule prefixes. --- common/msg.c | 100 +++----------------------------------------------- osdep/terminal-unix.c | 22 ++++++++++- osdep/terminal-win.c | 48 +++++++++++++++++++++--- osdep/terminal.h | 14 +++++-- player/main.c | 2 +- 5 files changed, 81 insertions(+), 105 deletions(-) diff --git a/common/msg.c b/common/msg.c index e80f6fcf16..c88be847e5 100644 --- a/common/msg.c +++ b/common/msg.c @@ -30,10 +30,6 @@ #include "osdep/terminal.h" #include "osdep/io.h" -#ifndef __MINGW32__ -#include -#endif - #include "common/msg.h" bool mp_msg_stdout_in_use = 0; @@ -60,27 +56,6 @@ static struct mp_log *legacy_logs[MSGT_MAX]; /* maximum message length of mp_msg */ #define MSGSIZE_MAX 6144 -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#include -#define hSTDOUT GetStdHandle(STD_OUTPUT_HANDLE) -#define hSTDERR GetStdHandle(STD_ERROR_HANDLE) -static short stdoutAttrs = 0; -static const unsigned char ansi2win32[10] = { - 0, - FOREGROUND_RED, - FOREGROUND_GREEN, - FOREGROUND_GREEN | FOREGROUND_RED, - FOREGROUND_BLUE, - FOREGROUND_BLUE | FOREGROUND_RED, - FOREGROUND_BLUE | FOREGROUND_GREEN, - FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED, - FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED, - FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED -}; -#endif - int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized to -2 int mp_msg_level_all = MSGL_STATUS; int verbose = 0; @@ -93,16 +68,6 @@ static int mp_msg_docolor(void) { } static void mp_msg_do_init(void){ -#ifdef _WIN32 - CONSOLE_SCREEN_BUFFER_INFO cinfo; - DWORD cmode = 0; - GetConsoleMode(hSTDOUT, &cmode); - cmode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); - SetConsoleMode(hSTDOUT, cmode); - SetConsoleMode(hSTDERR, cmode); - GetConsoleScreenBufferInfo(hSTDOUT, &cinfo); - stdoutAttrs = cinfo.wAttributes; -#endif int i; char *env = getenv("MPV_VERBOSE"); if (env) @@ -114,13 +79,11 @@ static void mp_msg_do_init(void){ int mp_msg_test(int mod, int lev) { -#ifndef __MINGW32__ if (lev == MSGL_STATUS) { // skip status line output if stderr is a tty but in background - if (isatty(2) && tcgetpgrp(2) != getpgrp()) + if (terminal_in_background()) return false; } -#endif return lev <= (mp_msg_levels[mod] == -2 ? mp_msg_level_all + verbose : mp_msg_levels[mod]); } @@ -133,54 +96,8 @@ static void set_msg_color(FILE* stream, int lev) { static const int v_colors[10] = {9, 1, 3, 3, -1, -1, 2, 8, 8, 8}; int c = v_colors[lev]; -#ifdef MP_ANNOY_ME - /* that's only a silly color test */ - { - int c; - static int flag = 1; - if (flag) - for(c = 0; c < 24; c++) - printf("\033[%d;3%dm*** COLOR TEST %d ***\n", c>7, c&7, c); - flag = 0; - } -#endif if (mp_msg_docolor()) - { -#if defined(_WIN32) && !defined(__CYGWIN__) - HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT; - if (c == -1) - c = 7; - SetConsoleTextAttribute(wstream, ansi2win32[c] | FOREGROUND_INTENSITY); -#else - if (c == -1) { - fprintf(stream, "\033[0m"); - } else { - fprintf(stream, "\033[%d;3%dm", c >> 3, c & 7); - } -#endif - } -} - -static void print_msg_module(FILE* stream, struct mp_log *log) -{ - int mod = log->legacy_mod; - int c2 = (mod + 1) % 15 + 1; - -#ifdef _WIN32 - HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT; - if (mp_msg_docolor()) - SetConsoleTextAttribute(wstream, ansi2win32[c2&7] | FOREGROUND_INTENSITY); - fprintf(stream, "%9s", log->verbose_prefix); - if (mp_msg_docolor()) - SetConsoleTextAttribute(wstream, stdoutAttrs); -#else - if (mp_msg_docolor()) - fprintf(stream, "\033[%d;3%dm", c2 >> 3, c2 & 7); - fprintf(stream, "%9s", log->verbose_prefix); - if (mp_msg_docolor()) - fprintf(stream, "\033[0;37m"); -#endif - fprintf(stream, ": "); + terminal_set_foreground_color(stream, c); } static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, @@ -208,8 +125,8 @@ static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, set_msg_color(stream, lev); if (header) { if (mp_msg_module) { - print_msg_module(stream, log); - set_msg_color(stream, lev); + fprintf(stream, "%9s", log->verbose_prefix); + fprintf(stream, ": "); } else if (lev >= MSGL_V || verbose) { fprintf(stream, "[%s] ", log->verbose_prefix); } else if (log->prefix) { @@ -223,14 +140,7 @@ static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, fprintf(stream, "%s", tmp); if (mp_msg_docolor()) - { -#ifdef _WIN32 - HANDLE *wstream = lev <= MSGL_WARN ? hSTDERR : hSTDOUT; - SetConsoleTextAttribute(wstream, stdoutAttrs); -#else - fprintf(stream, "\033[0m"); -#endif - } + terminal_set_foreground_color(stream, -1); fflush(stream); } diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index 050b97b9d1..f61cb5e367 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -227,7 +227,7 @@ static void termcap_add_extra_f_keys(void) { #endif -int load_termcap(char *termtype){ +static int load_termcap(char *termtype){ #if HAVE_TERMINFO || HAVE_TERMCAP #if HAVE_TERMINFO @@ -578,3 +578,23 @@ void getch2_disable(void){ getch2_enabled = 0; } + +bool terminal_in_background(void) +{ + return isatty(2) && tcgetpgrp(2) != getpgrp(); +} + +void terminal_set_foreground_color(FILE *stream, int c) +{ + if (c == -1) { + fprintf(stream, "\033[0m"); + } else { + fprintf(stream, "\033[%d;3%dm", c >> 3, c & 7); + } +} + +int terminal_init(void) +{ + load_termcap(NULL); + return 0; +} diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c index a56d1a409c..cee2ab395a 100644 --- a/osdep/terminal-win.c +++ b/osdep/terminal-win.c @@ -28,10 +28,25 @@ #include #include #include +#include #include "input/keycodes.h" #include "input/input.h" #include "terminal.h" +#define hSTDOUT GetStdHandle(STD_OUTPUT_HANDLE) +#define hSTDERR GetStdHandle(STD_ERROR_HANDLE) +static short stdoutAttrs = 0; +static const unsigned char ansi2win32[8] = { + 0, + FOREGROUND_RED, + FOREGROUND_GREEN, + FOREGROUND_GREEN | FOREGROUND_RED, + FOREGROUND_BLUE, + FOREGROUND_BLUE | FOREGROUND_RED, + FOREGROUND_BLUE | FOREGROUND_GREEN, + FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED, +}; + int mp_input_slave_cmd_func(int fd, char *dest, int size) { DWORD retval; @@ -64,11 +79,6 @@ void get_screen_size(void) } } -int load_termcap(char *termtype) -{ - return 0; -} - static HANDLE in; static int getch2_status = 0; @@ -192,3 +202,31 @@ void getch2_disable(void) return; // already disabled / never enabled getch2_status = 0; } + +bool terminal_in_background(void) +{ + return false; +} + +void terminal_set_foreground_color(FILE *stream, int c) +{ + HANDLE *wstream = stream == stderr ? hSTDERR : hSTDOUT; + if (c < 0 || c >= 8) { // reset or invalid + SetConsoleTextAttribute(wstream, stdoutAttrs); + } else { + SetConsoleTextAttribute(wstream, ansi2win32[c] | FOREGROUND_INTENSITY); + } +} + +int terminal_init(void) +{ + CONSOLE_SCREEN_BUFFER_INFO cinfo; + DWORD cmode = 0; + GetConsoleMode(hSTDOUT, &cmode); + cmode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT); + SetConsoleMode(hSTDOUT, cmode); + SetConsoleMode(hSTDERR, cmode); + GetConsoleScreenBufferInfo(hSTDOUT, &cinfo); + stdoutAttrs = cinfo.wAttributes; + return 0; +} diff --git a/osdep/terminal.h b/osdep/terminal.h index 76cedd9928..fe4d5e32d5 100644 --- a/osdep/terminal.h +++ b/osdep/terminal.h @@ -25,6 +25,7 @@ #define MPLAYER_GETCH2_H #include +#include /* Screen size. Initialized by load_termcap() and get_screen_size() */ extern int screen_width; @@ -33,12 +34,19 @@ extern int screen_height; /* Termcap code to erase to end of line */ extern char * erase_to_end_of_line; +/* Global initialization for terminal output. */ +int terminal_init(void); + +/* Return whether the process has been backgrounded. */ +bool terminal_in_background(void); + +/* Set ANSI text foreground color. c is [-1, 7], where 0-7 are colors, and + * -1 means reset to default. stream is either stdout or stderr. */ +void terminal_set_foreground_color(FILE *stream, int c); + /* Get screen-size using IOCTL call. */ void get_screen_size(void); -/* Load key definitions from the TERMCAP database. 'termtype' can be NULL */ -int load_termcap(char *termtype); - /* Initialize getch2 */ void getch2_enable(void); void getch2_disable(void); diff --git a/player/main.c b/player/main.c index a1d56df5f0..7f578a2c4b 100644 --- a/player/main.c +++ b/player/main.c @@ -264,7 +264,7 @@ static void osdep_preinit(int *p_argc, char ***p_argv) SetErrorMode(0x8003); #endif - load_termcap(NULL); // load key-codes + terminal_init(); mp_time_init(); } -- cgit v1.2.3 From 78292058ccf3fb827c9acc8ab3f616fa78a7a1e5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 18 Dec 2013 15:13:38 +0100 Subject: terminal: remove separate formatting for --msgmodule Instead, --msgmodule uses the same formatting as -v. --- common/msg.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/common/msg.c b/common/msg.c index c88be847e5..49a94ba7b5 100644 --- a/common/msg.c +++ b/common/msg.c @@ -124,10 +124,7 @@ static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, set_msg_color(stream, lev); if (header) { - if (mp_msg_module) { - fprintf(stream, "%9s", log->verbose_prefix); - fprintf(stream, ": "); - } else if (lev >= MSGL_V || verbose) { + if (lev >= MSGL_V || verbose || mp_msg_module) { fprintf(stream, "[%s] ", log->verbose_prefix); } else if (log->prefix) { fprintf(stream, "[%s] ", log->prefix); -- cgit v1.2.3 From 591a6722d29ca21e8bb62dbd01792590e8548dec Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 18 Dec 2013 15:43:31 +0100 Subject: msg: change hack to silence command line pre-parse error messages mp_msg_levels[] will go away. --- common/msg.c | 3 +++ common/msg.h | 2 +- options/parse_commandline.c | 7 ++----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/msg.c b/common/msg.c index 49a94ba7b5..9ef20226f6 100644 --- a/common/msg.c +++ b/common/msg.c @@ -59,6 +59,7 @@ static struct mp_log *legacy_logs[MSGT_MAX]; int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized to -2 int mp_msg_level_all = MSGL_STATUS; int verbose = 0; +bool mp_msg_mute; int mp_msg_color = 1; int mp_msg_module = 0; int mp_msg_cancolor = 0; @@ -79,6 +80,8 @@ static void mp_msg_do_init(void){ int mp_msg_test(int mod, int lev) { + if (mp_msg_mute) + return false; if (lev == MSGL_STATUS) { // skip status line output if stderr is a tty but in background if (terminal_in_background()) diff --git a/common/msg.h b/common/msg.h index 8466e7e2b6..c564df9e4f 100644 --- a/common/msg.h +++ b/common/msg.h @@ -28,8 +28,8 @@ struct mp_log; -// defined in mplayer.c extern int verbose; +extern bool mp_msg_mute; // verbosity elevel: diff --git a/options/parse_commandline.c b/options/parse_commandline.c index 182844ccc9..eaa7f4f162 100644 --- a/options/parse_commandline.c +++ b/options/parse_commandline.c @@ -265,8 +265,6 @@ err_out: return ret; } -extern int mp_msg_levels[]; - /* Parse some command line options early before main parsing. * --no-config prevents reading configuration files (otherwise done before * command line parsing), and --really-quiet suppresses messages printed @@ -275,8 +273,7 @@ extern int mp_msg_levels[]; void m_config_preparse_command_line(m_config_t *config, int argc, char **argv) { // Hack to shut up parser error messages - int msg_lvl_backup = mp_msg_levels[MSGT_CFGPARSER]; - mp_msg_levels[MSGT_CFGPARSER] = -11; + mp_msg_mute = true; struct parse_state p = {config, argc, argv}; while (split_opt_silent(&p) == 0) { @@ -290,5 +287,5 @@ void m_config_preparse_command_line(m_config_t *config, int argc, char **argv) } } - mp_msg_levels[MSGT_CFGPARSER] = msg_lvl_backup; + mp_msg_mute = false; } -- cgit v1.2.3 From 5162c2709ee9bfce15750fa47744861c50351ae5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 18 Dec 2013 16:55:10 +0100 Subject: msg: cosmetic changes In particular, condense the legacy MSGT_ defines and move them to the end of the file. --- common/msg.c | 42 ++++++++------- common/msg.h | 169 +++++++++++++++++++++++------------------------------------ 2 files changed, 87 insertions(+), 124 deletions(-) diff --git a/common/msg.c b/common/msg.c index 9ef20226f6..9c90512798 100644 --- a/common/msg.c +++ b/common/msg.c @@ -25,14 +25,14 @@ #include "talloc.h" -#include "config.h" #include "common/global.h" #include "osdep/terminal.h" #include "osdep/io.h" #include "common/msg.h" -bool mp_msg_stdout_in_use = 0; +/* maximum message length of mp_msg */ +#define MSGSIZE_MAX 6144 struct mp_log_root { /* This should, at some point, contain all mp_msg related state, instead @@ -53,20 +53,19 @@ struct mp_log { static bool initialized; static struct mp_log *legacy_logs[MSGT_MAX]; -/* maximum message length of mp_msg */ -#define MSGSIZE_MAX 6144 - +bool mp_msg_stdout_in_use; int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized to -2 int mp_msg_level_all = MSGL_STATUS; -int verbose = 0; +int verbose; bool mp_msg_mute; int mp_msg_color = 1; -int mp_msg_module = 0; -int mp_msg_cancolor = 0; +int mp_msg_module; +int mp_msg_cancolor; -static int mp_msg_docolor(void) { - return mp_msg_cancolor && mp_msg_color; -} +// indicate if last line printed ended with \n or \r +static int header = 1; +// indicates if last line printed was a status line +static int statusline; static void mp_msg_do_init(void){ int i; @@ -95,12 +94,16 @@ bool mp_msg_test_log(struct mp_log *log, int lev) return mp_msg_test(log->legacy_mod, lev); } +static int mp_msg_docolor(void) +{ + return mp_msg_cancolor && mp_msg_color; +} + static void set_msg_color(FILE* stream, int lev) { static const int v_colors[10] = {9, 1, 3, 3, -1, -1, 2, 8, 8, 8}; - int c = v_colors[lev]; if (mp_msg_docolor()) - terminal_set_foreground_color(stream, c); + terminal_set_foreground_color(stream, v_colors[lev]); } static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, @@ -109,14 +112,13 @@ static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, char tmp[MSGSIZE_MAX]; FILE *stream = (mp_msg_stdout_in_use || (lev == MSGL_STATUS)) ? stderr : stdout; - static int header = 1; - // indicates if last line printed was a status line - static int statusline; - if (!mp_msg_test_log(log, lev)) return; // do not display + if (!mp_msg_test_log(log, lev)) + return; // do not display + vsnprintf(tmp, MSGSIZE_MAX, format, va); - tmp[MSGSIZE_MAX-2] = '\n'; - tmp[MSGSIZE_MAX-1] = 0; + tmp[MSGSIZE_MAX - 2] = '\n'; + tmp[MSGSIZE_MAX - 1] = 0; /* A status line is normally intended to be overwritten by the next * status line, and does not end with a '\n'. If we're printing a normal @@ -135,7 +137,7 @@ static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, } size_t len = strlen(tmp); - header = len && (tmp[len-1] == '\n' || tmp[len-1] == '\r'); + header = len && (tmp[len - 1] == '\n' || tmp[len - 1] == '\r'); fprintf(stream, "%s", tmp); diff --git a/common/msg.h b/common/msg.h index c564df9e4f..8533b19887 100644 --- a/common/msg.h +++ b/common/msg.h @@ -30,149 +30,110 @@ struct mp_log; extern int verbose; extern bool mp_msg_mute; +extern bool mp_msg_stdout_in_use; -// verbosity elevel: - -/* Only messages level MSGL_FATAL-MSGL_STATUS should be translated, - * messages level MSGL_V and above should not be translated. */ - -#define MSGL_FATAL 0 // will exit/abort +// Verbosity levels. +#define MSGL_FATAL 0 // will exit/abort (note: msg.c doesn't exit or abort) #define MSGL_ERR 1 // continues #define MSGL_WARN 2 // only warning -#define MSGL_HINT 3 // short help message +#define MSGL_HINT 3 // (to be phased out) #define MSGL_INFO 4 // -quiet -#define MSGL_STATUS 5 // v=0 -#define MSGL_V 6 // v=1 -#define MSGL_DBG2 7 // v=2 -#define MSGL_DBG3 8 // v=3 -#define MSGL_DBG4 9 // v=4 -#define MSGL_DBG5 10 // v=5 +#define MSGL_STATUS 5 // exclusively for the playback status line +#define MSGL_V 6 // -v +#define MSGL_DBG2 7 // -v -v +#define MSGL_DBG3 8 // ... +#define MSGL_DBG4 9 // .... +#define MSGL_DBG5 10 // ..... -#define MSGL_FIXME 1 // for conversions from printf where the appropriate MSGL is not known; set equal to ERR for obtrusiveness -#define MSGT_FIXME 0 // for conversions from printf where the appropriate MSGT is not known; set equal to GLOBAL for obtrusiveness +struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, + const char *name); -// code/module: +void mp_msg_log(struct mp_log *log, int lev, const char *format, ...) + PRINTF_ATTRIBUTE(3, 4); -#define MSGT_GLOBAL 0 // common player stuff errors -#define MSGT_CPLAYER 1 // console player (mplayer.c) +// Convenience macros, typically called with a pointer to a context struct +// as first argument, which has a "struct mp_log log;" member. + +#define MP_MSG(obj, lev, ...) mp_msg_log((obj)->log, lev, __VA_ARGS__) +#define MP_MSGT(obj, lev, ...) mp_msgt_log((obj)->log, lev, __VA_ARGS__) + +#define MP_FATAL(obj, ...) MP_MSG(obj, MSGL_FATAL, __VA_ARGS__) +#define MP_ERR(obj, ...) MP_MSG(obj, MSGL_ERR, __VA_ARGS__) +#define MP_WARN(obj, ...) MP_MSG(obj, MSGL_WARN, __VA_ARGS__) +#define MP_INFO(obj, ...) MP_MSG(obj, MSGL_INFO, __VA_ARGS__) +#define MP_VERBOSE(obj, ...) MP_MSG(obj, MSGL_V, __VA_ARGS__) +#define MP_DBG(obj, ...) MP_MSG(obj, MSGL_DBG2, __VA_ARGS__) +#define MP_TRACE(obj, ...) MP_MSG(obj, MSGL_DBG5, __VA_ARGS__) + +#define mp_fatal(log, ...) mp_msg_log(log, MSGL_FATAL, __VA_ARGS__) +#define mp_err(log, ...) mp_msg_log(log, MSGL_ERR, __VA_ARGS__) +#define mp_warn(log, ...) mp_msg_log(log, MSGL_WARN, __VA_ARGS__) +#define mp_info(log, ...) mp_msg_log(log, MSGL_INFO, __VA_ARGS__) +#define mp_verbose(log, ...) mp_msg_log(log, MSGL_V, __VA_ARGS__) +#define mp_dbg(log, ...) mp_msg_log(log, MSGL_DBG2, __VA_ARGS__) +#define mp_trace(log, ...) mp_msg_log(log, MSGL_DBG5, __VA_ARGS__) + +struct mpv_global; +void mp_msg_init(struct mpv_global *global); +void mp_msg_uninit(struct mpv_global *global); + +struct mpv_global *mp_log_get_global(struct mp_log *log); -#define MSGT_VO 3 // libvo -#define MSGT_AO 4 // libao +// --- Legacy +// Note: using mp_msg_log or the MP_ERR/... macros is preferred. +int mp_msg_test(int mod, int lev); +bool mp_msg_test_log(struct mp_log *log, int lev); +void mp_msg_va(int mod, int lev, const char *format, va_list va); +void mp_msg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4); + +#define MSGL_FIXME 1 // for conversions from printf where the appropriate MSGL is not known; set equal to ERR for obtrusiveness +#define MSGT_FIXME 0 // for conversions from printf where the appropriate MSGT is not known; set equal to GLOBAL for +#define MSGT_GLOBAL 0 // common player stuff errors +#define MSGT_CPLAYER 1 // console player (mplayer.c) +#define MSGT_VO 3 // libvo +#define MSGT_AO 4 // libao #define MSGT_DEMUXER 5 // demuxer.c (general stuff) #define MSGT_DS 6 // demux stream (add/read packet etc) #define MSGT_DEMUX 7 // fileformat-specific stuff (demux_*.c) #define MSGT_HEADER 8 // fileformat-specific header (*header.c) - #define MSGT_AVSYNC 9 // mplayer.c timer stuff #define MSGT_AUTOQ 10 // mplayer.c auto-quality stuff - #define MSGT_CFGPARSER 11 // cfgparser.c - #define MSGT_DECAUDIO 12 // av decoder #define MSGT_DECVIDEO 13 - -#define MSGT_SEEK 14 // seeking code -#define MSGT_WIN32 15 // win32 dll stuff -#define MSGT_OPEN 16 // open.c (stream opening) -#define MSGT_DVD 17 // open.c (DVD init/read/seek) - -#define MSGT_PARSEES 18 // parse_es.c (mpeg stream parser) -#define MSGT_LIRC 19 // lirc_mp.c and input lirc driver - +#define MSGT_SEEK 14 // seeking code +#define MSGT_WIN32 15 // win32 dll stuff +#define MSGT_OPEN 16 // open.c (stream opening) +#define MSGT_DVD 17 // open.c (DVD init/read/seek) +#define MSGT_PARSEES 18 // parse_es.c (mpeg stream parser) +#define MSGT_LIRC 19 // lirc_mp.c and input lirc driver #define MSGT_STREAM 20 // stream.c -#define MSGT_CACHE 21 // cache2.c - +#define MSGT_CACHE 21 // cache2.c #define MSGT_ENCODE 22 // now encode_lavc.c - -#define MSGT_XACODEC 23 // XAnim codecs - -#define MSGT_TV 24 // TV input subsystem - -#define MSGT_OSDEP 25 // OS-dependent parts - -#define MSGT_SPUDEC 26 // spudec.c - +#define MSGT_XACODEC 23 // XAnim codecs +#define MSGT_TV 24 // TV input subsystem +#define MSGT_OSDEP 25 // OS-dependent parts +#define MSGT_SPUDEC 26 // spudec.c #define MSGT_PLAYTREE 27 // Playtree handeling (playtree.c, playtreeparser.c) - #define MSGT_INPUT 28 - #define MSGT_VFILTER 29 - #define MSGT_OSD 30 - #define MSGT_NETWORK 31 - #define MSGT_CPUDETECT 32 - #define MSGT_CODECCFG 33 - #define MSGT_SWS 34 - #define MSGT_VOBSUB 35 #define MSGT_SUBREADER 36 - #define MSGT_AFILTER 37 // Audio filter messages - #define MSGT_NETST 38 // Netstream - #define MSGT_MUXER 39 // muxer layer - #define MSGT_IDENTIFY 41 // -identify output - #define MSGT_RADIO 42 - #define MSGT_ASS 43 // libass messages - #define MSGT_LOADER 44 // dll loader messages - #define MSGT_STATUSLINE 45 // playback/encoding status line - #define MSGT_TELETEXT 46 // Teletext decoder - #define MSGT_MAX 47 -int mp_msg_test(int mod, int lev); -bool mp_msg_test_log(struct mp_log *log, int lev); - -// Note: using mp_msg_log or the MP_ERR/... macros is preferred. -void mp_msg_va(int mod, int lev, const char *format, va_list va); -void mp_msg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4); - -struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, - const char *name); - -void mp_msg_log(struct mp_log *log, int lev, const char *format, ...) - PRINTF_ATTRIBUTE(3, 4); - -// Convenience macros, typically called with a pointer to a context struct -// as first argument, which has a "struct mp_log log;" member. - -#define MP_MSG(obj, lev, ...) mp_msg_log((obj)->log, lev, __VA_ARGS__) -#define MP_MSGT(obj, lev, ...) mp_msgt_log((obj)->log, lev, __VA_ARGS__) - -#define MP_FATAL(obj, ...) MP_MSG(obj, MSGL_FATAL, __VA_ARGS__) -#define MP_ERR(obj, ...) MP_MSG(obj, MSGL_ERR, __VA_ARGS__) -#define MP_WARN(obj, ...) MP_MSG(obj, MSGL_WARN, __VA_ARGS__) -#define MP_INFO(obj, ...) MP_MSG(obj, MSGL_INFO, __VA_ARGS__) -#define MP_VERBOSE(obj, ...) MP_MSG(obj, MSGL_V, __VA_ARGS__) -#define MP_DBG(obj, ...) MP_MSG(obj, MSGL_DBG2, __VA_ARGS__) -#define MP_TRACE(obj, ...) MP_MSG(obj, MSGL_DBG5, __VA_ARGS__) - -#define mp_fatal(log, ...) mp_msg_log(log, MSGL_FATAL, __VA_ARGS__) -#define mp_err(log, ...) mp_msg_log(log, MSGL_ERR, __VA_ARGS__) -#define mp_warn(log, ...) mp_msg_log(log, MSGL_WARN, __VA_ARGS__) -#define mp_info(log, ...) mp_msg_log(log, MSGL_INFO, __VA_ARGS__) -#define mp_verbose(log, ...) mp_msg_log(log, MSGL_V, __VA_ARGS__) -#define mp_dbg(log, ...) mp_msg_log(log, MSGL_DBG2, __VA_ARGS__) -#define mp_trace(log, ...) mp_msg_log(log, MSGL_DBG5, __VA_ARGS__) - -struct mpv_global; -void mp_msg_init(struct mpv_global *global); -void mp_msg_uninit(struct mpv_global *global); - -struct mpv_global *mp_log_get_global(struct mp_log *log); - -extern bool mp_msg_stdout_in_use; - #endif /* MPLAYER_MP_MSG_H */ -- cgit v1.2.3 From 6a8fc3f5e38f93c36d18ad8407d4f3f345d893db Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 18 Dec 2013 19:04:30 +0100 Subject: msg: change --msglevel, reduce legacy glue Basically, reimplement --msglevel. Instead of making the new msg code use the legacy code, make the legacy code use the reimplemented functionality. The handling of the deprecated --identify switch changes. It temporarily stops working; this will be fixed in later commits. The actual sub-options syntax (like --msglevel-vo=...) goes away, but I bet nobody knew about this or used this anyway. --- DOCS/man/en/changes.rst | 1 + DOCS/man/en/options.rst | 28 +++++----- common/msg.c | 137 +++++++++++++++++++++++++++++++++++++++--------- common/msg.h | 12 ++++- options/m_option.c | 41 +++++++++++++++ options/m_option.h | 2 +- options/options.c | 104 ++---------------------------------- options/options.h | 2 + player/main.c | 3 ++ 9 files changed, 190 insertions(+), 140 deletions(-) diff --git a/DOCS/man/en/changes.rst b/DOCS/man/en/changes.rst index e15d6bb87f..0ea78512bd 100644 --- a/DOCS/man/en/changes.rst +++ b/DOCS/man/en/changes.rst @@ -179,6 +179,7 @@ Command Line Switches ``-panscanrange`` ``--video-zoom``, ``--video-pan-x/y`` ``-pp ...`` ``'--vf=pp=[...]'`` ``-pphelp`` ``--vf=pp:help`` + ``-identify`` ``--msglevel=identify=trace`` =========================== ======================================== .. note:: diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 9e7f55da2b..8c3e87abc7 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1345,7 +1345,9 @@ OPTIONS Control verbosity directly for each module. The ``all`` module changes the verbosity of all the modules not explicitly specified on the command line. - See ``--msglevel=help`` for a list of all modules. + Run mpv with ``--msglevel=all=trace`` to see all messages mpv outputs. You + can use the module names printed in the output (prefixed to each line in + ``[...]``) to limit the output to interesting modules. .. note:: @@ -1356,17 +1358,19 @@ OPTIONS Available levels: - :-1: complete silence - :0: fatal messages only - :1: error messages - :2: warning messages - :3: short hints - :4: informational messages - :5: status messages (default) - :6: verbose messages - :7: debug level 2 - :8: debug level 3 - :9: debug level 4 + :no: complete silence + :fatal: fatal messages only + :error: error messages + :warn: warning messages + :info: informational messages + :status: status messages (default) + :v: verbose messages + :debug: debug messages + :trace: very noisy debug messages + + One special case is the ``identify`` module name. This is silenced by + default, and can be set to ``trace`` level to enable the remains of the + code once enabled with the ``-identify`` option. ``--msgmodule`` Prepend module name in front of each console message. diff --git a/common/msg.c b/common/msg.c index 9c90512798..390794b4cd 100644 --- a/common/msg.c +++ b/common/msg.c @@ -22,10 +22,15 @@ #include #include #include +#include #include "talloc.h" +#include "bstr/bstr.h" +#include "compat/atomics.h" +#include "common/common.h" #include "common/global.h" +#include "options/options.h" #include "osdep/terminal.h" #include "osdep/io.h" @@ -40,24 +45,32 @@ struct mp_log_root { * control the terminal, which is global anyway). But for now, there is * not much. */ struct mpv_global *global; + char *msglevels; // protected by mp_msg_lock + /* This is incremented every time the msglevels must be reloaded. + * (This is perhaps better than maintaining a globally accessible and + * synchronized mp_log tree.) */ + int64_t reload_counter; }; struct mp_log { struct mp_log_root *root; const char *prefix; const char *verbose_prefix; - int legacy_mod; + int level; + int64_t reload_counter; }; +// Protects some (not all) state in mp_log_root +static pthread_mutex_t mp_msg_lock = PTHREAD_MUTEX_INITIALIZER; + // should not exist static bool initialized; static struct mp_log *legacy_logs[MSGT_MAX]; bool mp_msg_stdout_in_use; -int mp_msg_levels[MSGT_MAX]; // verbose level of this module. initialized to -2 -int mp_msg_level_all = MSGL_STATUS; int verbose; bool mp_msg_mute; +int mp_smode; int mp_msg_color = 1; int mp_msg_module; int mp_msg_cancolor; @@ -67,31 +80,57 @@ static int header = 1; // indicates if last line printed was a status line static int statusline; -static void mp_msg_do_init(void){ - int i; +static const struct mp_log null_log = {0}; +struct mp_log *const mp_null_log = (struct mp_log *)&null_log; + +static void mp_msg_do_init(void) +{ char *env = getenv("MPV_VERBOSE"); if (env) verbose = atoi(env); - for(i=0;ilevel = MSGL_STATUS + verbose; // default log level + // Stupid exception for the remains of -identify + if (match_mod(log->verbose_prefix, bstr0("identify"))) + log->level = -1; + bstr s = bstr0(log->root->msglevels); + bstr mod; + int level; + while (mp_msg_split_msglevel(&s, &mod, &level) > 0) { + if (match_mod(log->verbose_prefix, mod)) + log->level = level; + } + log->reload_counter = log->root->reload_counter; + pthread_mutex_unlock(&mp_msg_lock); +} + +bool mp_msg_test_log(struct mp_log *log, int lev) +{ + if (mp_msg_mute || !log->root) return false; if (lev == MSGL_STATUS) { // skip status line output if stderr is a tty but in background if (terminal_in_background()) return false; } - return lev <= (mp_msg_levels[mod] == -2 ? mp_msg_level_all + verbose : mp_msg_levels[mod]); -} - -bool mp_msg_test_log(struct mp_log *log, int lev) -{ - return mp_msg_test(log->legacy_mod, lev); + mp_memory_barrier(); + if (log->reload_counter != log->root->reload_counter) + update_loglevel(log); + return lev <= log->level || (mp_smode && lev == MSGL_SMODE); } static int mp_msg_docolor(void) @@ -101,13 +140,12 @@ static int mp_msg_docolor(void) static void set_msg_color(FILE* stream, int lev) { - static const int v_colors[10] = {9, 1, 3, 3, -1, -1, 2, 8, 8, 8}; + static const int v_colors[] = {9, 1, 3, 3, -1, -1, 2, 8, 8, 8, 9}; if (mp_msg_docolor()) terminal_set_foreground_color(stream, v_colors[lev]); } -static void mp_msg_log_va(struct mp_log *log, int lev, const char *format, - va_list va) +void mp_msg_log_va(struct mp_log *log, int lev, const char *format, va_list va) { char tmp[MSGSIZE_MAX]; FILE *stream = @@ -161,6 +199,13 @@ void mp_msg(int mod, int lev, const char *format, ...) va_end(va); } +int mp_msg_test(int mod, int lev) +{ + assert(initialized); + assert(mod >= 0 && mod < MSGT_MAX); + return mp_msg_test_log(legacy_logs[mod], lev); +} + // legacy names static const char *module_text[MSGT_MAX] = { "global", @@ -224,6 +269,8 @@ struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, assert(parent); assert(name); struct mp_log *log = talloc_zero(talloc_ctx, struct mp_log); + if (!parent->root) + return log; // same as null_log log->root = parent->root; if (name[0] == '!') { name = &name[1]; @@ -242,13 +289,6 @@ struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, log->prefix = NULL; if (!log->verbose_prefix[0]) log->verbose_prefix = "global"; - log->legacy_mod = parent->legacy_mod; - for (int n = 0; n < MSGT_MAX; n++) { - if (module_text[n] && strcmp(name, module_text[n]) == 0) { - log->legacy_mod = n; - break; - } - } return log; } @@ -259,6 +299,7 @@ void mp_msg_init(struct mpv_global *global) struct mp_log_root *root = talloc_zero(NULL, struct mp_log_root); root->global = global; + root->reload_counter = 1; struct mp_log dummy = { .root = root }; struct mp_log *log = mp_log_new(root, &dummy, ""); @@ -278,6 +319,17 @@ struct mpv_global *mp_log_get_global(struct mp_log *log) return log->root->global; } +void mp_msg_update_msglevels(struct mpv_global *global) +{ + struct mp_log_root *root = global->log->root; + pthread_mutex_lock(&mp_msg_lock); + talloc_free(root->msglevels); + root->msglevels = talloc_strdup(root, global->opts->msglevels); + mp_atomic_add_and_fetch(&root->reload_counter, 1); + mp_memory_barrier(); + pthread_mutex_unlock(&mp_msg_lock); +} + void mp_msg_uninit(struct mpv_global *global) { talloc_free(global->log->root); @@ -292,3 +344,38 @@ void mp_msg_log(struct mp_log *log, int lev, const char *format, ...) mp_msg_log_va(log, lev, format, va); va_end(va); } + +static const char *level_names[] = { + [MSGL_FATAL] = "fatal", + [MSGL_ERR] = "error", + [MSGL_WARN] = "warn", + [MSGL_INFO] = "info", + [MSGL_STATUS] = "status", + [MSGL_V] = "v", + [MSGL_DBG2] = "debug", + [MSGL_DBG5] = "trace", +}; + +int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level) +{ + if (s->len == 0) + return 0; + bstr elem, rest; + bstr_split_tok(*s, ":", &elem, &rest); + bstr mod, level; + if (!bstr_split_tok(elem, "=", &mod, &level) || mod.len == 0) + return -1; + int ilevel = -1; + for (int n = 0; n < MP_ARRAY_SIZE(level_names); n++) { + if (level_names[n] && bstr_equals0(level, level_names[n])) { + ilevel = n; + break; + } + } + if (ilevel < 0 && !bstr_equals0(level, "no")) + return -1; + *s = rest; + *out_mod = mod; + *out_level = ilevel; + return 1; +} diff --git a/common/msg.h b/common/msg.h index 8533b19887..d970d71f60 100644 --- a/common/msg.h +++ b/common/msg.h @@ -31,6 +31,10 @@ struct mp_log; extern int verbose; extern bool mp_msg_mute; extern bool mp_msg_stdout_in_use; +extern int mp_smode; // slave mode compatibility glue + +// A mp_log instance that never outputs anything. +extern struct mp_log *const mp_null_log; // Verbosity levels. #define MSGL_FATAL 0 // will exit/abort (note: msg.c doesn't exit or abort) @@ -44,18 +48,19 @@ extern bool mp_msg_stdout_in_use; #define MSGL_DBG3 8 // ... #define MSGL_DBG4 9 // .... #define MSGL_DBG5 10 // ..... +#define MSGL_SMODE 11 // old slave mode (-identify) struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent, const char *name); void mp_msg_log(struct mp_log *log, int lev, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); +void mp_msg_log_va(struct mp_log *log, int lev, const char *format, va_list va); // Convenience macros, typically called with a pointer to a context struct // as first argument, which has a "struct mp_log log;" member. #define MP_MSG(obj, lev, ...) mp_msg_log((obj)->log, lev, __VA_ARGS__) -#define MP_MSGT(obj, lev, ...) mp_msgt_log((obj)->log, lev, __VA_ARGS__) #define MP_FATAL(obj, ...) MP_MSG(obj, MSGL_FATAL, __VA_ARGS__) #define MP_ERR(obj, ...) MP_MSG(obj, MSGL_ERR, __VA_ARGS__) @@ -64,6 +69,7 @@ void mp_msg_log(struct mp_log *log, int lev, const char *format, ...) #define MP_VERBOSE(obj, ...) MP_MSG(obj, MSGL_V, __VA_ARGS__) #define MP_DBG(obj, ...) MP_MSG(obj, MSGL_DBG2, __VA_ARGS__) #define MP_TRACE(obj, ...) MP_MSG(obj, MSGL_DBG5, __VA_ARGS__) +#define MP_SMODE(obj, ...) MP_MSG(obj, MSGL_SMODE, __VA_ARGS__) #define mp_fatal(log, ...) mp_msg_log(log, MSGL_FATAL, __VA_ARGS__) #define mp_err(log, ...) mp_msg_log(log, MSGL_ERR, __VA_ARGS__) @@ -76,9 +82,13 @@ void mp_msg_log(struct mp_log *log, int lev, const char *format, ...) struct mpv_global; void mp_msg_init(struct mpv_global *global); void mp_msg_uninit(struct mpv_global *global); +void mp_msg_update_msglevels(struct mpv_global *global); struct mpv_global *mp_log_get_global(struct mp_log *log); +struct bstr; +int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level); + // --- Legacy // Note: using mp_msg_log or the MP_ERR/... macros is preferred. diff --git a/options/m_option.c b/options/m_option.c index ba020f5375..32301b5ec3 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1332,6 +1332,47 @@ const m_option_type_t m_option_type_subconfig_struct = { .parse = parse_subconf, }; +#undef VAL +#define VAL(x) (*(char **)(x)) + +static int parse_msglevels(const m_option_t *opt, struct bstr name, + struct bstr param, void *dst) +{ + if (param.start == NULL) + return M_OPT_MISSING_PARAM; + + bstr s = param; + while (1) { + int res = mp_msg_split_msglevel(&s, &(bstr){0}, &(int){0}); + if (res == 0) + break; + if (res < 0) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, + "Invalid syntax: %.*s\n", BSTR_P(s)); + return M_OPT_INVALID; + } + } + + if (dst) { + talloc_free(VAL(dst)); + VAL(dst) = bstrdup0(NULL, param); + } + + return 1; +} + +const m_option_type_t m_option_type_msglevels = { + .name = "Output verbosity levels", + .size = sizeof(char *), + .flags = M_OPT_TYPE_DYNAMIC, + .parse = parse_msglevels, + .print = print_str, + .copy = copy_str, + .free = free_str, +}; + +#undef VAL + static int parse_color(const m_option_t *opt, struct bstr name, struct bstr param, void *dst) { diff --git a/options/m_option.h b/options/m_option.h index 8e3e958c63..bea7a4376a 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -48,7 +48,7 @@ extern const m_option_type_t m_option_type_string_list; extern const m_option_type_t m_option_type_time; extern const m_option_type_t m_option_type_rel_time; extern const m_option_type_t m_option_type_choice; - +extern const m_option_type_t m_option_type_msglevels; extern const m_option_type_t m_option_type_print; extern const m_option_type_t m_option_type_print_func; extern const m_option_type_t m_option_type_print_func_param; diff --git a/options/options.c b/options/options.c index d828df6179..fdb54ff115 100644 --- a/options/options.c +++ b/options/options.c @@ -190,105 +190,6 @@ static const m_option_t mfopts_conf[]={ {NULL, NULL, 0, 0, 0, 0, NULL} }; -extern int mp_msg_levels[MSGT_MAX]; -extern int mp_msg_level_all; - -static const m_option_t msgl_config[]={ - { "all", &mp_msg_level_all, CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL}, - - { "global", &mp_msg_levels[MSGT_GLOBAL], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "cplayer", &mp_msg_levels[MSGT_CPLAYER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "vo", &mp_msg_levels[MSGT_VO], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "ao", &mp_msg_levels[MSGT_AO], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "demuxer", &mp_msg_levels[MSGT_DEMUXER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "ds", &mp_msg_levels[MSGT_DS], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "demux", &mp_msg_levels[MSGT_DEMUX], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "header", &mp_msg_levels[MSGT_HEADER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "avsync", &mp_msg_levels[MSGT_AVSYNC], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "autoq", &mp_msg_levels[MSGT_AUTOQ], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "cfgparser", &mp_msg_levels[MSGT_CFGPARSER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "decaudio", &mp_msg_levels[MSGT_DECAUDIO], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "decvideo", &mp_msg_levels[MSGT_DECVIDEO], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "seek", &mp_msg_levels[MSGT_SEEK], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "win32", &mp_msg_levels[MSGT_WIN32], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "open", &mp_msg_levels[MSGT_OPEN], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "dvd", &mp_msg_levels[MSGT_DVD], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "parsees", &mp_msg_levels[MSGT_PARSEES], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "lirc", &mp_msg_levels[MSGT_LIRC], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "stream", &mp_msg_levels[MSGT_STREAM], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "cache", &mp_msg_levels[MSGT_CACHE], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "encode", &mp_msg_levels[MSGT_ENCODE], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "xacodec", &mp_msg_levels[MSGT_XACODEC], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "tv", &mp_msg_levels[MSGT_TV], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "radio", &mp_msg_levels[MSGT_RADIO], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "osdep", &mp_msg_levels[MSGT_OSDEP], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "spudec", &mp_msg_levels[MSGT_SPUDEC], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "playtree", &mp_msg_levels[MSGT_PLAYTREE], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "input", &mp_msg_levels[MSGT_INPUT], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "vfilter", &mp_msg_levels[MSGT_VFILTER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "osd", &mp_msg_levels[MSGT_OSD], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "network", &mp_msg_levels[MSGT_NETWORK], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "cpudetect", &mp_msg_levels[MSGT_CPUDETECT], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "codeccfg", &mp_msg_levels[MSGT_CODECCFG], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "sws", &mp_msg_levels[MSGT_SWS], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "vobsub", &mp_msg_levels[MSGT_VOBSUB], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "subreader", &mp_msg_levels[MSGT_SUBREADER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "afilter", &mp_msg_levels[MSGT_AFILTER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "netst", &mp_msg_levels[MSGT_NETST], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "muxer", &mp_msg_levels[MSGT_MUXER], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "identify", &mp_msg_levels[MSGT_IDENTIFY], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "ass", &mp_msg_levels[MSGT_ASS], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "statusline", &mp_msg_levels[MSGT_STATUSLINE], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - { "fixme", &mp_msg_levels[MSGT_FIXME], CONF_TYPE_INT, CONF_RANGE, -1, 9, NULL }, - {"help", "Available msg modules:\n" - " global - common player errors/information\n" - " cplayer - console player (mplayer.c)\n" - " vo - libvo\n" - " ao - libao\n" - " demuxer - demuxer.c (general stuff)\n" - " ds - demux stream (add/read packet etc)\n" - " demux - fileformat-specific stuff (demux_*.c)\n" - " header - fileformat-specific header (*header.c)\n" - " avsync - mplayer.c timer stuff\n" - " autoq - mplayer.c auto-quality stuff\n" - " cfgparser - cfgparser.c\n" - " decaudio - av decoder\n" - " decvideo\n" - " seek - seeking code\n" - " win32 - win32 dll stuff\n" - " open - open.c (stream opening)\n" - " dvd - open.c (DVD init/read/seek)\n" - " parsees - parse_es.c (mpeg stream parser)\n" - " lirc - lirc_mp.c and input lirc driver\n" - " stream - stream.c\n" - " cache - cache2.c\n" - " encode - encode_lavc.c and associated vo/ao drivers\n" - " xacodec - XAnim codecs\n" - " tv - TV input subsystem\n" - " osdep - OS-dependent parts\n" - " spudec - spudec.c\n" - " playtree - Playtree handling (playtree.c, playtreeparser.c)\n" - " input\n" - " vfilter\n" - " osd\n" - " network\n" - " cpudetect\n" - " codeccfg\n" - " sws\n" - " vobsub\n" - " subreader\n" - " afilter - Audio filter messages\n" - " netst - Netstream\n" - " muxer - muxer layer\n" - " identify - identify output\n" - " ass - libass messages\n" - " statusline - playback/encoding status line\n" - " fixme - messages not yet fixed to map to module\n" - "\n", CONF_TYPE_PRINT, CONF_GLOBAL | CONF_NOCFG, 0, 0, NULL}, - {NULL, NULL, 0, 0, 0, 0, NULL} - -}; - #if HAVE_TV static const m_option_t tvscan_conf[]={ {"autostart", &stream_tv_defaults.scan, CONF_TYPE_FLAG, 0, 0, 1, NULL}, @@ -336,7 +237,8 @@ const m_option_t mp_opts[] = { // ------------------------- common options -------------------- OPT_FLAG("quiet", quiet, CONF_GLOBAL), {"really-quiet", &verbose, CONF_TYPE_STORE, CONF_GLOBAL|CONF_PRE_PARSE, 0, -10, NULL}, - {"msglevel", (void *) msgl_config, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL}, + OPT_GENERAL(char*, "msglevel", msglevels, CONF_GLOBAL|CONF_PRE_PARSE, + .type = &m_option_type_msglevels), {"msgcolor", &mp_msg_color, CONF_TYPE_FLAG, CONF_GLOBAL | CONF_PRE_PARSE, 0, 1, NULL}, {"msgmodule", &mp_msg_module, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL}, #if HAVE_PRIORITY @@ -730,7 +632,7 @@ const m_option_t mp_opts[] = { {"", (void *) mp_input_opts, CONF_TYPE_SUBCONFIG}, OPT_FLAG("list-properties", list_properties, CONF_GLOBAL), - {"identify", &mp_msg_levels[MSGT_IDENTIFY], CONF_TYPE_FLAG, CONF_GLOBAL, 0, MSGL_V, NULL}, + {"identify", &mp_smode, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL}, {"help", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, {"h", (void *) mp_help_text, CONF_TYPE_PRINT, CONF_NOCFG|CONF_GLOBAL, 0, 0, NULL}, {"version", (void *)print_version_opt, CONF_TYPE_PRINT_FUNC, CONF_NOCFG|CONF_GLOBAL|M_OPT_PRE_PARSE}, diff --git a/options/options.h b/options/options.h index d8f1d46488..b99c5d2746 100644 --- a/options/options.h +++ b/options/options.h @@ -44,6 +44,8 @@ typedef struct mp_vo_opts { } mp_vo_opts; typedef struct MPOpts { + char *msglevels; + char **reset_options; char **lua_files; int lua_load_osc; diff --git a/player/main.c b/player/main.c index 7f578a2c4b..acff77f94d 100644 --- a/player/main.c +++ b/player/main.c @@ -338,6 +338,7 @@ static int mpv_main(int argc, char *argv[]) // Preparse the command line m_config_preparse_command_line(mpctx->mconfig, argc, argv); + mp_msg_update_msglevels(mpctx->global); mp_print_version(false); @@ -354,6 +355,8 @@ static int mpv_main(int argc, char *argv[]) } } + mp_msg_update_msglevels(mpctx->global); + if (handle_help_options(mpctx)) exit_player(mpctx, EXIT_NONE); -- cgit v1.2.3 From e9e68fc399ed2805b43dff8f355142804e55c38c Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 20 Dec 2013 21:07:10 +0100 Subject: msg: use a global lock to synchronize printing We have certain race conditions coming from doing multiple fprintf() calls (setting up colors etc.). I'm not sure whether it would be worth changing to code such that we do only one fprintf() call (and assume this synchronizes access), but considering it would be hard to do (Windows compatibility, ...), and that stdio uses per FILE locks anyway, this is simpler and probably not less efficient. Also, there's no problem handling the weird statusline special case this way. Note that mp_msg_* calls which are silent won't acquire the lock, and acquiring the lock happens on actual output only (which is slow and serialized anyway). --- common/msg.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/common/msg.c b/common/msg.c index 390794b4cd..6d4e374a24 100644 --- a/common/msg.c +++ b/common/msg.c @@ -147,13 +147,14 @@ static void set_msg_color(FILE* stream, int lev) void mp_msg_log_va(struct mp_log *log, int lev, const char *format, va_list va) { - char tmp[MSGSIZE_MAX]; - FILE *stream = - (mp_msg_stdout_in_use || (lev == MSGL_STATUS)) ? stderr : stdout; - if (!mp_msg_test_log(log, lev)) return; // do not display + pthread_mutex_lock(&mp_msg_lock); + + FILE *stream = (mp_msg_stdout_in_use || lev == MSGL_STATUS) ? stderr : stdout; + + char tmp[MSGSIZE_MAX]; vsnprintf(tmp, MSGSIZE_MAX, format, va); tmp[MSGSIZE_MAX - 2] = '\n'; tmp[MSGSIZE_MAX - 1] = 0; @@ -182,6 +183,8 @@ void mp_msg_log_va(struct mp_log *log, int lev, const char *format, va_list va) if (mp_msg_docolor()) terminal_set_foreground_color(stream, -1); fflush(stream); + + pthread_mutex_unlock(&mp_msg_lock); } void mp_msg_va(int mod, int lev, const char *format, va_list va) -- cgit v1.2.3 From ad05e76c57820eb93a21f8e4185f36f58ec2c1fc Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 20 Dec 2013 21:07:16 +0100 Subject: msg: handle vsnprintf errors I don't know under which circumstances this can error (other than a broken format string). It seems it won't return an error code on I/O errors, so maybe broken format strings are the only case. Either way, don't continue if an error is returned. --- common/msg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/msg.c b/common/msg.c index 6d4e374a24..926d9f06fc 100644 --- a/common/msg.c +++ b/common/msg.c @@ -155,7 +155,8 @@ void mp_msg_log_va(struct mp_log *log, int lev, const char *format, va_list va) FILE *stream = (mp_msg_stdout_in_use || lev == MSGL_STATUS) ? stderr : stdout; char tmp[MSGSIZE_MAX]; - vsnprintf(tmp, MSGSIZE_MAX, format, va); + if (vsnprintf(tmp, MSGSIZE_MAX, format, va) < 0) + snprintf(tmp, MSGSIZE_MAX, "[fprintf error]\n"); tmp[MSGSIZE_MAX - 2] = '\n'; tmp[MSGSIZE_MAX - 1] = 0; -- cgit v1.2.3 From fdceef6cc5f11ecd86f5cb6d213e82fe9fa8b66b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 17:36:56 +0100 Subject: ao_alsa: don't set ALSA message callback This could output additional, potentially useful error messages. But the callback is global and not library-safe, and would require us to add additional state. Remove it, because it's obviously too much of a pain. Also, it seems ALSA prints stuff to stderr anyway. --- audio/out/ao_alsa.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index a65b9b05ec..f4884f077c 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -80,25 +80,6 @@ struct priv { static float get_delay(struct ao *ao); static void uninit(struct ao *ao, bool immed); -static void alsa_error_handler(const char *file, int line, const char *function, - int err, const char *format, ...) -{ - char tmp[0xc00]; - va_list va; - - va_start(va, format); - vsnprintf(tmp, sizeof tmp, format, va); - va_end(va); - - if (err) { - mp_msg(MSGT_AO, MSGL_ERR, "alsa-lib: %s:%i:(%s) %s: %s\n", - file, line, function, tmp, snd_strerror(err)); - } else { - mp_msg(MSGT_AO, MSGL_ERR, "alsa-lib: %s:%i:(%s) %s\n", - file, line, function, tmp); - } -} - /* to set/get/query special features/parameters */ static int control(struct ao *ao, enum aocontrol cmd, void *arg) { @@ -401,7 +382,6 @@ static int init(struct ao *ao) p->can_pause = 1; MP_VERBOSE(ao, "using ALSA version: %s\n", snd_asoundlib_version()); - snd_lib_error_set_handler(alsa_error_handler); int open_mode = p->cfg_block ? 0 : SND_PCM_NONBLOCK; //modes = 0, SND_PCM_NONBLOCK, SND_PCM_ASYNC @@ -573,7 +553,6 @@ static void uninit(struct ao *ao, bool immed) alsa_error: p->alsa = NULL; - snd_lib_error_set_handler(NULL); } static void audio_pause(struct ao *ao) -- cgit v1.2.3 From 877303aaa9111fc56a8e5edbeb439699acfe44c0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 17:39:40 +0100 Subject: x11: don't set global error handler This has similar problems as the ALSA message callback, though in theory we could use the Display handle to find the right mpv instance from the global callback. It still wouldn't work if another library happens to set the error handler at the same time. There doesn't seem much of an advantage overriding the error handler (though it used to be required), so remove it. --- video/out/x11_common.c | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/video/out/x11_common.c b/video/out/x11_common.c index a042bd0968..55a11e81b3 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -219,25 +219,6 @@ static void vo_set_cursor_hidden(struct vo *vo, bool cursor_hidden) } } -static int x11_errorhandler(Display *display, XErrorEvent *event) -{ - char msg[60]; - - XGetErrorText(display, event->error_code, (char *) &msg, sizeof(msg)); - - mp_msg(MSGT_VO, MSGL_ERR, "X11 error: %s\n", msg); - - mp_msg(MSGT_VO, MSGL_V, - "Type: %x, display: %p, resourceid: %lx, serial: %lx\n", - event->type, event->display, event->resourceid, event->serial); - mp_msg(MSGT_VO, MSGL_V, - "Error code: %x, request code: %x, minor code: %x\n", - event->error_code, event->request_code, event->minor_code); - -// abort(); - return 0; -} - struct fstype { int type; const char *sym; @@ -477,8 +458,6 @@ int vo_x11_init(struct vo *vo) }; vo->x11 = x11; - XSetErrorHandler(x11_errorhandler); - dispName = XDisplayName(NULL); MP_VERBOSE(x11, "X11 opening display: %s\n", dispName); @@ -710,7 +689,6 @@ void vo_x11_uninit(struct vo *vo) MP_VERBOSE(x11, "uninit ...\n"); if (x11->xim) XCloseIM(x11->xim); - XSetErrorHandler(NULL); XCloseDisplay(x11->display); talloc_free(x11); -- cgit v1.2.3 From 426ebbae5ff578923a83a4395ff499f0348f7dcc Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 17:43:25 +0100 Subject: video/filter: mp_msg conversions --- player/video.c | 2 +- video/filter/vf.c | 45 +++++++++++++++++++++--------------------- video/filter/vf.h | 7 +++++-- video/filter/vf_crop.c | 4 ++-- video/filter/vf_delogo.c | 36 +++++++++++++++++---------------- video/filter/vf_divtc.c | 32 ++++++++++++------------------ video/filter/vf_dlopen.c | 23 +++++++++------------ video/filter/vf_eq.c | 4 +++- video/filter/vf_expand.c | 2 +- video/filter/vf_gradfun.c | 2 +- video/filter/vf_lavfi.c | 10 +++++----- video/filter/vf_phase.c | 18 ++++++++--------- video/filter/vf_pullup.c | 2 +- video/filter/vf_scale.c | 17 ++++++---------- video/filter/vf_softpulldown.c | 5 ++--- video/filter/vf_stereo3d.c | 11 ++++------- video/filter/vf_unsharp.c | 5 ----- 17 files changed, 103 insertions(+), 122 deletions(-) diff --git a/player/video.c b/player/video.c index 0c7d399322..518c771238 100644 --- a/player/video.c +++ b/player/video.c @@ -105,7 +105,7 @@ static void recreate_video_filters(struct MPContext *mpctx) assert(d_video); vf_destroy(d_video->vfilter); - d_video->vfilter = vf_new(opts); + d_video->vfilter = vf_new(mpctx->global); d_video->vfilter->hwdec = &d_video->hwdec_info; vf_append_filter_list(d_video->vfilter, opts->vf_settings); diff --git a/video/filter/vf.c b/video/filter/vf.c index 77a86501ad..c2d4be6e63 100644 --- a/video/filter/vf.c +++ b/video/filter/vf.c @@ -26,6 +26,7 @@ #include "config.h" +#include "common/global.h" #include "common/msg.h" #include "options/m_option.h" #include "options/m_config.h" @@ -194,29 +195,29 @@ static int vf_default_query_format(struct vf_instance *vf, unsigned int fmt) return vf_next_query_format(vf, fmt); } -static void print_fmt(int msglevel, struct mp_image_params *p) +static void print_fmt(struct mp_log *log, int msglevel, struct mp_image_params *p) { if (p && p->imgfmt) { - mp_msg(MSGT_VFILTER, msglevel, "%dx%d", p->w, p->h); + mp_msg_log(log, msglevel, "%dx%d", p->w, p->h); if (p->w != p->d_w || p->h != p->d_h) - mp_msg(MSGT_VFILTER, msglevel, "->%dx%d", p->d_w, p->d_h); - mp_msg(MSGT_VFILTER, msglevel, " %s", mp_imgfmt_to_name(p->imgfmt)); - mp_msg(MSGT_VFILTER, msglevel, " %s/%s", mp_csp_names[p->colorspace], - mp_csp_levels_names[p->colorlevels]); + mp_msg_log(log, msglevel, "->%dx%d", p->d_w, p->d_h); + mp_msg_log(log, msglevel, " %s", mp_imgfmt_to_name(p->imgfmt)); + mp_msg_log(log, msglevel, " %s/%s", mp_csp_names[p->colorspace], + mp_csp_levels_names[p->colorlevels]); } else { - mp_msg(MSGT_VFILTER, msglevel, "???"); + mp_msg_log(log, msglevel, "???"); } } void vf_print_filter_chain(struct vf_chain *c, int msglevel) { - if (!mp_msg_test(MSGT_VFILTER, msglevel)) + if (!mp_msg_test_log(c->log, msglevel)) return; for (vf_instance_t *f = c->first; f; f = f->next) { - mp_msg(MSGT_VFILTER, msglevel, " [%s] ", f->info->name); - print_fmt(msglevel, &f->fmt_out); - mp_msg(MSGT_VFILTER, msglevel, "\n"); + mp_msg_log(c->log, msglevel, " [%s] ", f->info->name); + print_fmt(c->log, msglevel, &f->fmt_out); + mp_msg_log(c->log, msglevel, "\n"); } } @@ -225,14 +226,13 @@ static struct vf_instance *vf_open(struct vf_chain *c, const char *name, { struct m_obj_desc desc; if (!m_obj_list_find(&desc, &vf_obj_list, bstr0(name))) { - mp_msg(MSGT_VFILTER, MSGL_ERR, - "Couldn't find video filter '%s'.\n", name); + MP_ERR(c, "Couldn't find video filter '%s'.\n", name); return NULL; } vf_instance_t *vf = talloc_zero(NULL, struct vf_instance); *vf = (vf_instance_t) { .info = desc.p, - .opts = c->opts, + .log = mp_log_new(vf, c->log, name), .hwdec = c->hwdec, .query_format = vf_default_query_format, .out_pool = talloc_steal(vf, mp_image_pool_new(16)), @@ -249,7 +249,7 @@ static struct vf_instance *vf_open(struct vf_chain *c, const char *name, return vf; error: - mp_msg(MSGT_VFILTER, MSGL_ERR, "Creating filter '%s' failed.\n", name); + MP_ERR(c, "Creating filter '%s' failed.\n", name); talloc_free(vf); return NULL; } @@ -266,8 +266,7 @@ static vf_instance_t *vf_open_filter(struct vf_chain *c, const char *name, p += sprintf(str, "%s", name); for (i = 0; args && args[2 * i]; i++) p += sprintf(p, " %s=%s", args[2 * i], args[2 * i + 1]); - mp_msg(MSGT_VFILTER, MSGL_INFO, "%s[%s]\n", - "Opening video filter: ", str); + MP_INFO(c, "Opening video filter: [%s]\n", str); return vf_open(c, name, args); } @@ -437,7 +436,7 @@ static void update_formats(struct vf_chain *c, struct vf_instance *vf, // If there are output formats, but no input formats (meaning the // filters after vf work, but vf can't output any format the filters // after it accept), try to insert a conversion filter. - mp_msg(MSGT_VFILTER, MSGL_INFO, "Using conversion filter.\n"); + MP_INFO(c, "Using conversion filter.\n"); struct vf_instance *conv = vf_open(c, "scale", NULL); if (conv) { conv->next = vf->next; @@ -507,8 +506,8 @@ int vf_reconfig(struct vf_chain *c, const struct mp_image_params *params) c->initialized = r < 0 ? -1 : 1; int loglevel = r < 0 ? MSGL_WARN : MSGL_V; if (r == -2) - mp_msg(MSGT_VFILTER, MSGL_ERR, "Image formats incompatible.\n"); - mp_msg(MSGT_VFILTER, loglevel, "Video filter chain:\n"); + MP_ERR(c, "Image formats incompatible.\n"); + mp_msg_log(c->log, loglevel, "Video filter chain:\n"); vf_print_filter_chain(c, loglevel); return r; } @@ -548,11 +547,13 @@ static int output_query_format(struct vf_instance *vf, unsigned int fmt) return 0; } -struct vf_chain *vf_new(struct MPOpts *opts) +struct vf_chain *vf_new(struct mpv_global *global) { struct vf_chain *c = talloc_ptrtype(NULL, c); *c = (struct vf_chain){ - .opts = opts, + .opts = global->opts, + .log = mp_log_new(c, global->log, "!vf"), + .global = global, }; static const struct vf_info in = { .name = "in" }; c->first = talloc(c, struct vf_instance); diff --git a/video/filter/vf.h b/video/filter/vf.h index 96f4aaef7e..4b27160ba3 100644 --- a/video/filter/vf.h +++ b/video/filter/vf.h @@ -27,6 +27,7 @@ #include "video/vfcap.h" struct MPOpts; +struct mpv_global; struct vf_instance; struct vf_priv_s; struct m_obj_settings; @@ -79,7 +80,7 @@ typedef struct vf_instance { struct mp_image_pool *out_pool; struct vf_priv_s *priv; - struct MPOpts *opts; + struct mp_log *log; struct mp_hwdec_info *hwdec; struct mp_image **out_queued; @@ -100,7 +101,9 @@ struct vf_chain { struct mp_image_params output_params; uint8_t allowed_output_formats[IMGFMT_END - IMGFMT_START]; + struct mp_log *log; struct MPOpts *opts; + struct mpv_global *global; struct mp_hwdec_info *hwdec; }; @@ -122,7 +125,7 @@ enum vf_ctrl { VFCTRL_SET_OSD_OBJ, }; -struct vf_chain *vf_new(struct MPOpts *opts); +struct vf_chain *vf_new(struct mpv_global *global); void vf_destroy(struct vf_chain *c); int vf_reconfig(struct vf_chain *c, const struct mp_image_params *params); int vf_control_any(struct vf_chain *c, int cmd, void *arg); diff --git a/video/filter/vf_crop.c b/video/filter/vf_crop.c index cd286910ab..186c710d9f 100644 --- a/video/filter/vf_crop.c +++ b/video/filter/vf_crop.c @@ -59,7 +59,7 @@ static int config(struct vf_instance *vf, // check: if(vf->priv->crop_w+vf->priv->crop_x>width || vf->priv->crop_h+vf->priv->crop_y>height){ - mp_msg(MSGT_VFILTER, MSGL_WARN, "[CROP] Bad position/width/height - cropped area outside of the original!\n"); + MP_WARN(vf, "[CROP] Bad position/width/height - cropped area outside of the original!\n"); return 0; } vf_rescale_dsize(&d_width, &d_height, width, height, @@ -86,7 +86,7 @@ static int vf_open(vf_instance_t *vf){ vf->config=config; vf->filter=filter; vf->query_format=query_format; - mp_msg(MSGT_VFILTER, MSGL_INFO, "Crop: %d x %d, %d ; %d\n", + MP_INFO(vf, "Crop: %d x %d, %d ; %d\n", vf->priv->crop_w, vf->priv->crop_h, vf->priv->crop_x, diff --git a/video/filter/vf_delogo.c b/video/filter/vf_delogo.c index d1e7ea1c4a..e5840800cc 100644 --- a/video/filter/vf_delogo.c +++ b/video/filter/vf_delogo.c @@ -60,8 +60,9 @@ static struct vf_priv_s { * Adjust the coordinates to suit the band width * Also print a notice in verbose mode */ -static void fix_band(struct vf_priv_s *p) +static void fix_band(struct vf_instance *vf) { + struct vf_priv_s *p = vf->priv; if (p->band < 0) { p->band = 4; p->show = 1; @@ -70,12 +71,13 @@ static void fix_band(struct vf_priv_s *p) p->lh += p->band*2; p->xoff -= p->band; p->yoff -= p->band; - mp_msg(MSGT_VFILTER, MSGL_V, "delogo: %d x %d, %d x %d, band = %d\n", + MP_VERBOSE(vf, "delogo: %d x %d, %d x %d, band = %d\n", p->xoff, p->yoff, p->lw, p->lh, p->band); } -static void update_sub(struct vf_priv_s *p, double pts) +static void update_sub(str