From d8d42b44fc717c695af59c14213d54885088ea37 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 19:45:42 +0100 Subject: m_option, m_config: mp_msg conversions Always pass around mp_log contexts in the option parser code. This of course affects all users of this API as well. In stream.c, pass a mp_null_log, because we can't do it properly yet. This will be fixed later. --- audio/chmap.c | 16 +-- audio/chmap.h | 4 +- audio/filter/af.c | 2 +- audio/out/ao.c | 2 +- common/av_log.c | 27 ++-- common/av_log.h | 3 +- input/input.c | 12 +- options/m_config.c | 91 +++++++------- options/m_config.h | 10 +- options/m_option.c | 339 +++++++++++++++++++++++--------------------------- options/m_option.h | 18 ++- options/m_property.c | 2 +- options/options.c | 6 +- player/command.c | 3 +- player/core.h | 2 +- player/main.c | 26 ++-- stream/stream.c | 2 +- video/filter/vf.c | 2 +- video/out/vo.c | 2 +- video/out/vo_opengl.c | 3 +- 20 files changed, 275 insertions(+), 297 deletions(-) diff --git a/audio/chmap.c b/audio/chmap.c index ce301b6565..a67c4e1c70 100644 --- a/audio/chmap.c +++ b/audio/chmap.c @@ -471,19 +471,19 @@ bool mp_chmap_from_str(struct mp_chmap *dst, bstr src) return true; } -void mp_chmap_print_help(int msgt, int msgl) +void mp_chmap_print_help(struct mp_log *log) { - mp_msg(msgt, msgl, "Speakers:\n"); + mp_info(log, "Speakers:\n"); for (int n = 0; n < MP_SPEAKER_ID_COUNT; n++) { if (speaker_names[n][0]) - mp_msg(msgt, msgl, " %-16s (%s)\n", - speaker_names[n][0], speaker_names[n][1]); + mp_info(log, " %-16s (%s)\n", + speaker_names[n][0], speaker_names[n][1]); } - mp_msg(msgt, msgl, "Standard layouts:\n"); + mp_info(log, "Standard layouts:\n"); for (int n = 0; std_layout_names[n][0]; n++) { - mp_msg(msgt, msgl, " %-16s (%s)\n", - std_layout_names[n][0], std_layout_names[n][1]); + mp_info(log, " %-16s (%s)\n", + std_layout_names[n][0], std_layout_names[n][1]); } for (int n = 0; n < MP_NUM_CHANNELS; n++) - mp_msg(msgt, msgl, " unknown%d\n", n); + mp_info(log, " unknown%d\n", n); } diff --git a/audio/chmap.h b/audio/chmap.h index ca1e6c2508..306382db5a 100644 --- a/audio/chmap.h +++ b/audio/chmap.h @@ -121,7 +121,9 @@ void mp_chmap_get_reorder(int dst[MP_NUM_CHANNELS], const struct mp_chmap *from, char *mp_chmap_to_str(const struct mp_chmap *src); bool mp_chmap_from_str(struct mp_chmap *dst, bstr src); -void mp_chmap_print_help(int msgt, int msgl); + +struct mp_log; +void mp_chmap_print_help(struct mp_log *log); // Use these to avoid chaos in case lavc's definition should diverge from MS. #define mp_chmap_to_waveext mp_chmap_to_lavc diff --git a/audio/filter/af.c b/audio/filter/af.c index 3eebd8b385..92ed2ad63e 100644 --- a/audio/filter/af.c +++ b/audio/filter/af.c @@ -205,7 +205,7 @@ static struct af_instance *af_create(struct af_stream *s, char *name, .data = talloc_zero(af, struct mp_audio), .log = mp_log_new(af, s->log, name), }; - struct m_config *config = m_config_from_obj_desc(af, &desc); + struct m_config *config = m_config_from_obj_desc(af, s->log, &desc); if (m_config_apply_defaults(config, name, s->opts->af_defs) < 0) goto error; if (m_config_set_obj_params(config, args) < 0) diff --git a/audio/out/ao.c b/audio/out/ao.c index ab2b15b031..7aea6239d2 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -149,7 +149,7 @@ static struct ao *ao_create(bool probing, struct mpv_global *global, }; if (ao->driver->encode != !!ao->encode_lavc_ctx) goto error; - struct m_config *config = m_config_from_obj_desc(ao, &desc); + struct m_config *config = m_config_from_obj_desc(ao, ao->log, &desc); if (m_config_apply_defaults(config, name, global->opts->ao_defs) < 0) goto error; if (m_config_set_obj_params(config, args) < 0) diff --git a/common/av_log.c b/common/av_log.c index ba47500572..b007062d1e 100644 --- a/common/av_log.c +++ b/common/av_log.c @@ -147,30 +147,31 @@ void init_libav(void) } #define V(x) (x)>>16, (x)>>8 & 255, (x) & 255 -static void print_version(int v, char *name, unsigned buildv, unsigned runv) +static void print_version(struct mp_log *log, int v, char *name, + unsigned buildv, unsigned runv) { - mp_msg(MSGT_CPLAYER, v, " %-15s %d.%d.%d", name, V(buildv)); + mp_msg_log(log, v, " %-15s %d.%d.%d", name, V(buildv)); if (buildv != runv) - mp_msg(MSGT_CPLAYER, v, " (runtime %d.%d.%d)", V(runv)); - mp_msg(MSGT_CPLAYER, v, "\n"); + mp_msg_log(log, v, " (runtime %d.%d.%d)", V(runv)); + mp_msg_log(log, v, "\n"); } #undef V -void print_libav_versions(int v) +void print_libav_versions(struct mp_log *log, int v) { - mp_msg(MSGT_CPLAYER, v, "%s library versions:\n", LIB_PREFIX); + mp_msg_log(log, v, "%s library versions:\n", LIB_PREFIX); - print_version(v, "libavutil", LIBAVUTIL_VERSION_INT, avutil_version()); - print_version(v, "libavcodec", LIBAVCODEC_VERSION_INT, avcodec_version()); - print_version(v, "libavformat", LIBAVFORMAT_VERSION_INT, avformat_version()); - print_version(v, "libswscale", LIBSWSCALE_VERSION_INT, swscale_version()); + print_version(log, v, "libavutil", LIBAVUTIL_VERSION_INT, avutil_version()); + print_version(log, v, "libavcodec", LIBAVCODEC_VERSION_INT, avcodec_version()); + print_version(log, v, "libavformat", LIBAVFORMAT_VERSION_INT, avformat_version()); + print_version(log, v, "libswscale", LIBSWSCALE_VERSION_INT, swscale_version()); #if HAVE_LIBAVFILTER - print_version(v, "libavfilter", LIBAVFILTER_VERSION_INT, avfilter_version()); + print_version(log, v, "libavfilter", LIBAVFILTER_VERSION_INT, avfilter_version()); #endif #if HAVE_LIBAVRESAMPLE - print_version(v, "libavresample", LIBAVRESAMPLE_VERSION_INT, avresample_version()); + print_version(log, v, "libavresample", LIBAVRESAMPLE_VERSION_INT, avresample_version()); #endif #if HAVE_LIBSWRESAMPLE - print_version(v, "libswresample", LIBSWRESAMPLE_VERSION_INT, swresample_version()); + print_version(log, v, "libswresample", LIBSWRESAMPLE_VERSION_INT, swresample_version()); #endif } diff --git a/common/av_log.h b/common/av_log.h index d5c57b0aeb..e941220a11 100644 --- a/common/av_log.h +++ b/common/av_log.h @@ -1,2 +1,3 @@ void init_libav(void); -void print_libav_versions(int v); +struct mp_log; +void print_libav_versions(struct mp_log *log, int v); diff --git a/input/input.c b/input/input.c index d0eac2529c..8dd8e76bd8 100644 --- a/input/input.c +++ b/input/input.c @@ -105,8 +105,8 @@ struct key_name { #define OARG_INT(def) OPT_INT(ARG(i), 0, OPTDEF_INT(def)) #define OARG_CHOICE(def, c) OPT_CHOICE(ARG(i), 0, c, OPTDEF_INT(def)) -static int parse_cycle_dir(const struct m_option *opt, struct bstr name, - struct bstr param, void *dst); +static int parse_cycle_dir(struct mp_log *log, const struct m_option *opt, + struct bstr name, struct bstr param, void *dst); static const struct m_option_type m_option_type_cycle_dir = { .name = "up|down", .parse = parse_cycle_dir, @@ -813,8 +813,8 @@ void mp_input_rm_key_fd(struct input_ctx *ictx, int fd) input_unlock(ictx); } -static int parse_cycle_dir(const struct m_option *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_cycle_dir(struct mp_log *log, const struct m_option *opt, + struct bstr name, struct bstr param, void *dst) { double val; if (bstrcmp0(param, "up") == 0) { @@ -822,7 +822,7 @@ static int parse_cycle_dir(const struct m_option *opt, struct bstr name, } else if (bstrcmp0(param, "down") == 0) { val = -1; } else { - return m_option_type_double.parse(opt, name, param, dst); + return m_option_type_double.parse(log, opt, name, param, dst); } *(double *)dst = val; return 1; @@ -1041,7 +1041,7 @@ static struct mp_cmd *parse_cmd(struct parse_ctx *ctx, int def_flags) struct mp_cmd_arg *cmdarg = &cmd->args[cmd->nargs]; cmdarg->type = opt; cmd->nargs++; - r = m_option_parse(opt, bstr0(cmd->name), cur_token, &cmdarg->v); + r = m_option_parse(ctx->log, opt, bstr0(cmd->name), cur_token, &cmdarg->v); if (r < 0) { MP_ERR(ctx, "Command %s: argument %d can't be parsed: %s.\n", cmd->name, i + 1, m_option_strerror(r)); diff --git a/options/m_config.c b/options/m_config.c index 2b873e765c..0fc99b0257 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -75,20 +75,18 @@ static int parse_profile(struct m_config *config, const struct m_option *opt, if (!bstrcmp0(param, "help")) { struct m_profile *p; if (!config->profiles) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, - "No profiles have been defined.\n"); + MP_INFO(config, "No profiles have been defined.\n"); return M_OPT_EXIT - 1; } - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available profiles:\n"); + MP_INFO(config, "Available profiles:\n"); for (p = config->profiles; p; p = p->next) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\t%s\t%s\n", p->name, - p->desc ? p->desc : ""); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + MP_INFO(config, "\t%s\t%s\n", p->name, p->desc ? p->desc : ""); + MP_INFO(config, "\n"); return M_OPT_EXIT - 1; } char **list = NULL; - int r = m_option_type_string_list.parse(opt, name, param, &list); + int r = m_option_type_string_list.parse(config->log, opt, name, param, &list); if (r < 0) return r; if (!list || !list[0]) @@ -96,8 +94,7 @@ static int parse_profile(struct m_config *config, const struct m_option *opt, for (int i = 0; list[i]; i++) { struct m_profile *p = m_config_get_profile0(config, list[i]); if (!p) { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Unknown profile '%s'.\n", - list[i]); + MP_WARN(config, "Unknown profile '%s'.\n", list[i]); r = M_OPT_INVALID; } else if (set) m_config_set_profile(config, p, flags); @@ -113,12 +110,11 @@ static int show_profile(struct m_config *config, bstr param) if (!param.len) return M_OPT_MISSING_PARAM; if (!(p = m_config_get_profile(config, param))) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown profile '%.*s'.\n", - BSTR_P(param)); + MP_ERR(config, "Unknown profile '%.*s'.\n", BSTR_P(param)); return M_OPT_EXIT - 1; } if (!config->profile_depth) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Profile %s: %s\n", p->name, + MP_INFO(config, "Profile %s: %s\n", p->name, p->desc ? p->desc : ""); config->profile_depth++; for (i = 0; i < p->num_opts; i++) { @@ -127,8 +123,7 @@ static int show_profile(struct m_config *config, bstr param) spc[j] = ' '; spc[config->profile_depth] = '\0'; - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s%s=%s\n", spc, - p->opts[2 * i], p->opts[2 * i + 1]); + MP_INFO(config, "%s%s=%s\n", spc, p->opts[2 * i], p->opts[2 * i + 1]); if (config->profile_depth < MAX_PROFILE_DEPTH && !strcmp(p->opts[2*i], "profile")) { @@ -149,7 +144,7 @@ static int show_profile(struct m_config *config, bstr param) } config->profile_depth--; if (!config->profile_depth) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + MP_INFO(config, "\n"); return M_OPT_EXIT - 1; } @@ -187,13 +182,13 @@ static void config_destroy(void *p) m_option_free(config->opts[n].opt, config->opts[n].data); } -struct m_config *m_config_new(void *talloc_ctx, size_t size, - const void *defaults, +struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, + size_t size, const void *defaults, const struct m_option *options) { struct m_config *config = talloc(talloc_ctx, struct m_config); talloc_set_destructor(config, config_destroy); - *config = (struct m_config) {0}; + *config = (struct m_config) {.log = log}; // size==0 means a dummy object is created if (size) { config->optstruct = talloc_zero_size(config, size); @@ -205,18 +200,19 @@ struct m_config *m_config_new(void *talloc_ctx, size_t size, return config; } -struct m_config *m_config_from_obj_desc(void *talloc_ctx, +struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mp_log *log, struct m_obj_desc *desc) { - return m_config_new(talloc_ctx, desc->priv_size, desc->priv_defaults, + return m_config_new(talloc_ctx, log, desc->priv_size, desc->priv_defaults, desc->options); } // Like m_config_from_obj_desc(), but don't allocate option struct. struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, + struct mp_log *log, struct m_obj_desc *desc) { - return m_config_new(talloc_ctx, 0, desc->priv_defaults, desc->options); + return m_config_new(talloc_ctx, log, 0, desc->priv_defaults, desc->options); } int m_config_set_obj_params(struct m_config *conf, char **args) @@ -284,7 +280,7 @@ void m_config_backup_opt(struct m_config *config, const char *opt) if (co) { ensure_backup(config, co); } else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s not found.\n", opt); + MP_ERR(config, "Option %s not found.\n", opt); } } @@ -496,15 +492,13 @@ static int m_config_parse_option(struct m_config *config, struct bstr name, // Check if this option isn't forbidden in the current mode if ((flags & M_SETOPT_FROM_CONFIG_FILE) && (co->opt->flags & M_OPT_NOCFG)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option can't be used in a config file.\n", + MP_ERR(config, "The %.*s option can't be used in a config file.\n", BSTR_P(name)); return M_OPT_INVALID; } if (flags & M_SETOPT_BACKUP) { if (co->opt->flags & M_OPT_GLOBAL) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option is global and can't be set per-file.\n", + MP_ERR(config, "The %.*s option is global and can't be set per-file.\n", BSTR_P(name)); return M_OPT_INVALID; } @@ -529,7 +523,8 @@ static int m_config_parse_option(struct m_config *config, struct bstr name, return parse_subopts(config, (char *)co->name, prefix, param, flags); } - int r = m_option_parse(co->opt, name, param, set ? co->data : NULL); + int r = m_option_parse(config->log, co->opt, name, param, + set ? co->data : NULL); if (r >= 0 && set && (flags & M_SETOPT_FROM_CMDLINE)) { co->is_set_from_cmdline = true; @@ -551,7 +546,7 @@ static int parse_subopts(struct m_config *config, char *name, char *prefix, { char **lst = NULL; // Split the argument into child options - int r = m_option_type_subconfig.parse(NULL, bstr0(""), param, &lst); + int r = m_option_type_subconfig.parse(config->log, NULL, bstr0(""), param, &lst); if (r < 0) return r; // Parse the child options @@ -563,9 +558,8 @@ static int parse_subopts(struct m_config *config, char *name, char *prefix, r = m_config_parse_option(config,bstr0(n), bstr0(lst[2 * i + 1]), flags); if (r < 0) { if (r > M_OPT_EXIT) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Error parsing suboption %s/%s (%s)\n", - name, lst[2 * i], m_option_strerror(r)); + MP_ERR(config, "Error parsing suboption %s/%s (%s)\n", + name, lst[2 * i], m_option_strerror(r)); r = M_OPT_INVALID; } break; @@ -582,8 +576,8 @@ int m_config_parse_suboptions(struct m_config *config, char *name, return 0; int r = parse_subopts(config, name, "", bstr0(subopts), 0); if (r < 0 && r > M_OPT_EXIT) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error parsing suboption %s (%s)\n", - name, m_option_strerror(r)); + MP_ERR(config, "Error parsing suboption %s (%s)\n", + name, m_option_strerror(r)); r = M_OPT_INVALID; } return r; @@ -594,8 +588,8 @@ int m_config_set_option_ext(struct m_config *config, struct bstr name, { int r = m_config_parse_option(config, name, param, flags); if (r < 0 && r > M_OPT_EXIT) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Error parsing option %.*s (%s)\n", - BSTR_P(name), m_option_strerror(r)); + MP_ERR(config, "Error parsing option %.*s (%s)\n", + BSTR_P(name), m_option_strerror(r)); r = M_OPT_INVALID; } return r; @@ -633,7 +627,7 @@ void m_config_print_option_list(const struct m_config *config) int count = 0; const char *prefix = config->is_toplevel ? "--" : ""; - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Options:\n\n"); + MP_INFO(config, "Options:\n\n"); for (int i = 0; i < config->num_opts; i++) { struct m_config_option *co = &config->opts[i]; const struct m_option *opt = co->opt; @@ -641,16 +635,16 @@ void m_config_print_option_list(const struct m_config *config) continue; if (co->is_generated) continue; - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s%-30.30s", prefix, co->name); + MP_INFO(config, " %s%-30.30s", prefix, co->name); if (opt->type == &m_option_type_choice) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " Choices:"); + MP_INFO(config, " Choices:"); struct m_opt_choice_alternatives *alt = opt->priv; for (int n = 0; alt[n].name; n++) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", alt[n].name); + MP_INFO(config, " %s", alt[n].name); if (opt->flags & (M_OPT_MIN | M_OPT_MAX)) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (or an integer)"); + MP_INFO(config, " (or an integer)"); } else { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", co->opt->type->name); + MP_INFO(config, " %s", co->opt->type->name); } if (opt->flags & (M_OPT_MIN | M_OPT_MAX)) { snprintf(min, sizeof(min), "any"); @@ -659,23 +653,23 @@ void m_config_print_option_list(const struct m_config *config) snprintf(min, sizeof(min), "%.14g", opt->min); if (opt->flags & M_OPT_MAX) snprintf(max, sizeof(max), "%.14g", opt->max); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (%s to %s)", min, max); + MP_INFO(config, " (%s to %s)", min, max); } char *def = NULL; if (co->default_data) def = m_option_print(co->opt, co->default_data); if (def) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " (default: %s)", def); + MP_INFO(config, " (default: %s)", def); talloc_free(def); } if (opt->flags & CONF_GLOBAL) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [global]"); + MP_INFO(config, " [global]"); if (opt->flags & CONF_NOCFG) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " [nocfg]"); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + MP_INFO(config, " [nocfg]"); + MP_INFO(config, "\n"); count++; } - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\nTotal: %d options\n", count); + MP_INFO(config, "\nTotal: %d options\n", count); } struct m_profile *m_config_get_profile(const struct m_config *config, bstr name) @@ -731,8 +725,7 @@ void m_config_set_profile(struct m_config *config, struct m_profile *p, int flags) { if (config->profile_depth > MAX_PROFILE_DEPTH) { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, - "WARNING: Profile inclusion too deep.\n"); + MP_WARN(config, "WARNING: Profile inclusion too deep.\n"); return; } config->profile_depth++; diff --git a/options/m_config.h b/options/m_config.h index 829fa90ba7..2624f45edf 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -34,6 +34,7 @@ struct m_option_type; struct m_sub_options; struct m_obj_desc; struct m_obj_settings; +struct mp_log; // Config option struct m_config_option { @@ -48,6 +49,8 @@ struct m_config_option { // Config object /** \ingroup Config */ typedef struct m_config { + struct mp_log *log; + // Registered options. struct m_config_option *opts; // all options, even suboptions int num_opts; @@ -77,14 +80,15 @@ typedef struct m_config { // and a corresponding option switch or sub-option field. // suboptinit: if not NULL, initialize the suboption string (used for presets) // Note that the m_config object will keep pointers to defaults and options. -struct m_config *m_config_new(void *talloc_ctx, size_t size, - const void *defaults, +struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, + size_t size, const void *defaults, const struct m_option *options); -struct m_config *m_config_from_obj_desc(void *talloc_ctx, +struct m_config *m_config_from_obj_desc(void *talloc_ctx, struct mp_log *log, struct m_obj_desc *desc); struct m_config *m_config_from_obj_desc_noalloc(void *talloc_ctx, + struct mp_log *log, struct m_obj_desc *desc); int m_config_set_obj_params(struct m_config *conf, char **args); diff --git a/options/m_option.c b/options/m_option.c index 32301b5ec3..69d8ba0376 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -117,8 +117,8 @@ static int clamp_flag(const m_option_t *opt, void *val) return M_OPT_OUT_OF_RANGE; } -static int parse_flag(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_flag(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len) { if (!bstrcmp0(param, "yes")) { @@ -131,8 +131,7 @@ static int parse_flag(const m_option_t *opt, struct bstr name, VAL(dst) = opt->min; return 1; } - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid parameter for %.*s flag: %.*s\n", + mp_err(log, "Invalid parameter for %.*s flag: %.*s\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; } else { @@ -173,16 +172,15 @@ const m_option_type_t m_option_type_flag = { // Single-value, write-only flag -static int parse_store(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_store(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0 || bstrcmp0(param, "yes") == 0) { if (dst) VAL(dst) = opt->max; return 0; } else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid parameter for %.*s flag: %.*s\n", + mp_err(log, "Invalid parameter for %.*s flag: %.*s\n", BSTR_P(name), BSTR_P(param)); return M_OPT_DISALLOW_PARAM; } @@ -202,16 +200,15 @@ const m_option_type_t m_option_type_store = { #undef VAL #define VAL(x) (*(float *)(x)) -static int parse_store_float(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_store_float(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0 || bstrcmp0(param, "yes") == 0) { if (dst) VAL(dst) = opt->max; return 0; } else { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid parameter for %.*s flag: %.*s\n", + mp_err(log, "Invalid parameter for %.*s flag: %.*s\n", BSTR_P(name), BSTR_P(param)); return M_OPT_DISALLOW_PARAM; } @@ -246,8 +243,8 @@ static int clamp_longlong(const m_option_t *opt, void *val) return r; } -static int parse_longlong(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_longlong(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0) return M_OPT_MISSING_PARAM; @@ -257,22 +254,19 @@ static int parse_longlong(const m_option_t *opt, struct bstr name, if (rest.len) tmp_int = bstrtoll(param, &rest, 0); if (rest.len) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be an integer: %.*s\n", + mp_err(log, "The %.*s option must be an integer: %.*s\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; } if ((opt->flags & M_OPT_MIN) && (tmp_int < opt->min)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be >= %d: %.*s\n", + mp_err(log, "The %.*s option must be >= %d: %.*s\n", BSTR_P(name), (int) opt->min, BSTR_P(param)); return M_OPT_OUT_OF_RANGE; } if ((opt->flags & M_OPT_MAX) && (tmp_int > opt->max)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be <= %d: %.*s\n", + mp_err(log, "The %.*s option must be <= %d: %.*s\n", BSTR_P(name), (int) opt->max, BSTR_P(param)); return M_OPT_OUT_OF_RANGE; } @@ -299,21 +293,21 @@ static int clamp_int64(const m_option_t *opt, void *val) return r; } -static int parse_int(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_int(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { long long tmp; - int r = parse_longlong(opt, name, param, &tmp); + int r = parse_longlong(log, opt, name, param, &tmp); if (r >= 0 && dst) *(int *)dst = tmp; return r; } -static int parse_int64(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_int64(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { long long tmp; - int r = parse_longlong(opt, name, param, &tmp); + int r = parse_longlong(log, opt, name, param, &tmp); if (r >= 0 && dst) *(int64_t *)dst = tmp; return r; @@ -395,8 +389,8 @@ const m_option_type_t m_option_type_int64 = { .clamp = clamp_int64, }; -static int parse_intpair(const struct m_option *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_intpair(struct mp_log *log, const struct m_option *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0) return M_OPT_MISSING_PARAM; @@ -425,7 +419,7 @@ static int parse_intpair(const struct m_option *opt, struct bstr name, return 1; bad: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid integer range " + mp_err(log, "Invalid integer range " "specification for option %.*s: %.*s\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; @@ -453,8 +447,8 @@ static int clamp_choice(const m_option_t *opt, void *val) return M_OPT_INVALID; } -static int parse_choice(const struct m_option *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_choice(struct mp_log *log, const struct m_option *opt, + struct bstr name, struct bstr param, void *dst) { struct m_opt_choice_alternatives *alt = opt->priv; for ( ; alt->name; alt++) @@ -465,21 +459,20 @@ static int parse_choice(const struct m_option *opt, struct bstr name, return M_OPT_MISSING_PARAM; if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) { long long val; - if (parse_longlong(opt, name, param, &val) == 1) { + if (parse_longlong(log, opt, name, param, &val) == 1) { if (dst) *(int *)dst = val; return 1; } } - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid value for option %.*s: %.*s\n", + mp_err(log, "Invalid value for option %.*s: %.*s\n", BSTR_P(name), BSTR_P(param)); - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Valid values are:"); + mp_err(log, "Valid values are:"); for (alt = opt->priv; alt->name; alt++) - mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %s", alt->name); + mp_err(log, " %s", alt->name); if ((opt->flags & M_OPT_MIN) && (opt->flags & M_OPT_MAX)) - mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %g-%g", opt->min, opt->max); - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "\n"); + mp_err(log, " %g-%g", opt->min, opt->max); + mp_err(log, "\n"); return M_OPT_INVALID; } if (dst) @@ -598,8 +591,8 @@ static int clamp_double(const m_option_t *opt, void *val) return r; } -static int parse_double(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_double(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0) return M_OPT_MISSING_PARAM; @@ -611,8 +604,7 @@ static int parse_double(const m_option_t *opt, struct bstr name, tmp_float /= bstrtod(rest, &rest); if (rest.len) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be a floating point number or a " + mp_err(log, "The %.*s option must be a floating point number or a " "ratio (numerator[:/]denominator): %.*s\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; @@ -620,23 +612,20 @@ static int parse_double(const m_option_t *opt, struct bstr name, if (opt->flags & M_OPT_MIN) if (tmp_float < opt->min) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be >= %f: %.*s\n", + mp_err(log, "The %.*s option must be >= %f: %.*s\n", BSTR_P(name), opt->min, BSTR_P(param)); return M_OPT_OUT_OF_RANGE; } if (opt->flags & M_OPT_MAX) if (tmp_float > opt->max) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be <= %f: %.*s\n", + mp_err(log, "The %.*s option must be <= %f: %.*s\n", BSTR_P(name), opt->max, BSTR_P(param)); return M_OPT_OUT_OF_RANGE; } if (!isfinite(tmp_float)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "The %.*s option must be a finite number: %.*s\n", + mp_err(log, "The %.*s option must be a finite number: %.*s\n", BSTR_P(name), BSTR_P(param)); return M_OPT_OUT_OF_RANGE; } @@ -703,11 +692,11 @@ static int clamp_float(const m_option_t *opt, void *val) return r; } -static int parse_float(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_float(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { double tmp; - int r = parse_double(opt, name, param, &tmp); + int r = parse_double(log, opt, name, param, &tmp); if (r == 1 && dst) VAL(dst) = tmp; return r; @@ -799,8 +788,8 @@ static int clamp_str(const m_option_t *opt, void *val) return 0; } -static int parse_str(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_str(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { int r = 1; void *tmp = talloc_new(NULL); @@ -820,8 +809,7 @@ static int parse_str(const m_option_t *opt, struct bstr name, if (opt->flags & M_OPT_PARSE_ESCAPES) { char *res = unescape_string(tmp, param); if (!res) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Parameter has broken escapes: %.*s\n", BSTR_P(param)); + mp_err(log, "Parameter has broken escapes: %.*s\n", BSTR_P(param)); r = M_OPT_INVALID; goto exit; } @@ -829,16 +817,14 @@ static int parse_str(const m_option_t *opt, struct bstr name, } if ((opt->flags & M_OPT_MIN) && (param.len < opt->min)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Parameter must be >= %d chars: %.*s\n", + mp_err(log, "Parameter must be >= %d chars: %.*s\n", (int) opt->min, BSTR_P(param)); r = M_OPT_OUT_OF_RANGE; goto exit; } if ((opt->flags & M_OPT_MAX) && (param.len > opt->max)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Parameter must be <= %d chars: %.*s\n", + mp_err(log, "Parameter must be <= %d chars: %.*s\n", (int) opt->max, BSTR_P(param)); r = M_OPT_OUT_OF_RANGE; goto exit; @@ -942,7 +928,7 @@ static int str_list_add(char **add, int n, void *dst, int pre) return 1; } -static int str_list_del(char **del, int n, void *dst) +static int str_list_del(struct mp_log *log, char **del, int n, void *dst) { char **lst, *ep; int i, ln, s; @@ -959,14 +945,13 @@ static int str_list_del(char **del, int n, void *dst) for (i = 0; del[i] != NULL; i++) { idx = strtol(del[i], &ep, 0); if (*ep) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid index: %s\n", del[i]); + mp_err(log, "Invalid index: %s\n", del[i]); talloc_free(del[i]); continue; } talloc_free(del[i]); if (idx < 0 || idx >= ln) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Index %ld is out of range.\n", idx); + mp_err(log, "Index %ld is out of range.\n", idx); continue; } else if (!lst[idx]) continue; @@ -1016,8 +1001,8 @@ static struct bstr get_nextsep(struct bstr *ptr, char sep, bool modify) return bstr_splice(orig, 0, str.start - orig.start); } -static int parse_str_list(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_str_list(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { char **res; int op = OP_NONE; @@ -1088,7 +1073,7 @@ static int parse_str_list(const m_option_t *opt, struct bstr name, case OP_PRE: return str_list_add(res, n, dst, 1); case OP_DEL: - return str_list_del(res, n, dst); + return str_list_del(log, res, n, dst); } if (VAL(dst)) @@ -1165,16 +1150,16 @@ const m_option_type_t m_option_type_string_list = { /////////////////// Print -static int parse_print(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_print(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (opt->type == CONF_TYPE_PRINT) { const char *msg = opt->p; - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "%s", msg); + mp_info(log, "%s", msg); } else { char *name0 = bstrdup0(NULL, name); char *param0 = bstrdup0(NULL, param); - int r = ((m_opt_func_full_t) opt->p)(opt, name0, param0); + int r = ((m_opt_func_full_t) opt->p)(log, opt, name0, param0); talloc_free(name0); talloc_free(param0); return r; @@ -1211,7 +1196,8 @@ const m_option_type_t m_option_type_print_func = { // Read s sub-option name, or a positional sub-opt value. // Return 0 on succes, M_OPT_ error code otherwise. // optname is for error reporting. -static int read_subparam(bstr optname, bstr *str, bstr *out_subparam) +static int read_subparam(struct mp_log *log, bstr optname, + bstr *str, bstr *out_subparam) { bstr p = *str; bstr subparam = {0}; @@ -1221,24 +1207,21 @@ static int read_subparam(bstr optname, bstr *str, bstr *out_subparam) subparam = bstr_splice(p, 0, optlen); p = bstr_cut(p, optlen); if (!bstr_startswith0(p, "\"")) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Terminating '\"' missing for '%.*s'\n", + mp_err(log, "Terminating '\"' missing for '%.*s'\n", BSTR_P(optname)); return M_OPT_INVALID; } p = bstr_cut(p, 1); } else if (bstr_eatstart0(&p, "[")) { if (!bstr_split_tok(p, "]", &subparam, &p)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Terminating ']' missing for '%.*s'\n", + mp_err(log, "Terminating ']' missing for '%.*s'\n", BSTR_P(optname)); return M_OPT_INVALID; } } else if (bstr_eatstart0(&p, "%")) { int optlen = bstrtoll(p, &p, 0); if (!bstr_startswith0(p, "%") || (optlen > p.len - 1)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid length %d for '%.*s'\n", + mp_err(log, "Invalid length %d for '%.*s'\n", optlen, BSTR_P(optname)); return M_OPT_INVALID; } @@ -1261,16 +1244,17 @@ static int read_subparam(bstr optname, bstr *str, bstr *out_subparam) // On success, set *out_name and *out_val, and advance *str // out_val.start is NULL if there was no parameter. // optname is for error reporting. -static int split_subconf(bstr optname, bstr *str, bstr *out_name, bstr *out_val) +static int split_subconf(struct mp_log *log, bstr optname, bstr *str, + bstr *out_name, bstr *out_val) { bstr p = *str; bstr subparam = {0}; bstr subopt; - int r = read_subparam(optname, &p, &subopt); + int r = read_subparam(log, optname, &p, &subopt); if (r < 0) return r; if (bstr_eatstart0(&p, "=")) { - r = read_subparam(subopt, &p, &subparam); + r = read_subparam(log, subopt, &p, &subparam); if (r < 0) return r; } @@ -1280,8 +1264,8 @@ static int split_subconf(bstr optname, bstr *str, bstr *out_name, bstr *out_val) return 0; } -static int parse_subconf(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_subconf(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { int nr = 0; char **lst = NULL; @@ -1293,14 +1277,13 @@ static int parse_subconf(const m_option_t *opt, struct bstr name, while (p.len) { bstr subopt, subparam; - int r = split_subconf(name, &p, &subopt, &subparam); + int r = split_subconf(log, name, &p, &subopt, &subparam); if (r < 0) return r; if (bstr_startswith0(p, ":")) p = bstr_cut(p, 1); else if (p.len > 0) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Incorrect termination for '%.*s'\n", BSTR_P(subopt)); + mp_err(log, "Incorrect termination for '%.*s'\n", BSTR_P(subopt)); return M_OPT_INVALID; } @@ -1335,8 +1318,8 @@ const m_option_type_t m_option_type_subconfig_struct = { #undef VAL #define VAL(x) (*(char **)(x)) -static int parse_msglevels(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_msglevels(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.start == NULL) return M_OPT_MISSING_PARAM; @@ -1347,8 +1330,7 @@ static int parse_msglevels(const m_option_t *opt, struct bstr name, if (res == 0) break; if (res < 0) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid syntax: %.*s\n", BSTR_P(s)); + mp_err(log, "Invalid syntax: %.*s\n", BSTR_P(s)); return M_OPT_INVALID; } } @@ -1373,8 +1355,8 @@ const m_option_type_t m_option_type_msglevels = { #undef VAL -static int parse_color(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_color(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0) return M_OPT_MISSING_PARAM; @@ -1406,11 +1388,9 @@ static int parse_color(const m_option_t *opt, struct bstr name, return 1; error: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: invalid color: '%.*s'\n", + mp_err(log, "Option %.*s: invalid color: '%.*s'\n", BSTR_P(name), BSTR_P(param)); - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Valid colors must be in the form #RRRGGBB or #AARRGGBB (in hex)\n"); + mp_err(log, "Valid colors must be in the form #RRRGGBB or #AARRGGBB (in hex)\n"); return M_OPT_INVALID; } @@ -1539,8 +1519,8 @@ void m_geometry_apply(int *xpos, int *ypos, int *widw, int *widh, } } -static int parse_geometry(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_geometry(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { struct m_geometry gm; if (!parse_geometry_str(&gm, param)) @@ -1552,10 +1532,9 @@ static int parse_geometry(const m_option_t *opt, struct bstr name, return 1; error: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: invalid geometry: '%.*s'\n", + mp_err(log, "Option %.*s: invalid geometry: '%.*s'\n", BSTR_P(name), BSTR_P(param)); - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Valid format: [W[%%][xH[%%]]][{+-}X[%%]{+-}Y[%%]] | [X[%%]:Y[%%]]\n"); + mp_err(log, "Valid format: [W[%%][xH[%%]]][{+-}X[%%]{+-}Y[%%]] | [X[%%]:Y[%%]]\n"); return M_OPT_INVALID; } @@ -1566,8 +1545,8 @@ const m_option_type_t m_option_type_geometry = { .copy = copy_opt, }; -static int parse_size_box(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_size_box(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { struct m_geometry gm; if (!parse_geometry_str(&gm, param)) @@ -1582,10 +1561,9 @@ static int parse_size_box(const m_option_t *opt, struct bstr name, return 1; error: - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: invalid size: '%.*s'\n", + mp_err(log, "Option %.*s: invalid size: '%.*s'\n", BSTR_P(name), BSTR_P(param)); - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Valid format: W[%%][xH[%%]] or empty string\n"); + mp_err(log, "Valid format: W[%%][xH[%%]] or empty string\n"); return M_OPT_INVALID; } @@ -1599,24 +1577,23 @@ const m_option_type_t m_option_type_size_box = { #include "video/img_format.h" -static int parse_imgfmt(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_imgfmt(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0) return M_OPT_MISSING_PARAM; if (!bstrcmp0(param, "help")) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:"); + mp_info(log, "Available formats:"); for (int i = 0; mp_imgfmt_list[i].name; i++) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", mp_imgfmt_list[i].name); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + mp_info(log, " %s", mp_imgfmt_list[i].name); + mp_info(log, "\n"); return M_OPT_EXIT - 1; } unsigned int fmt = mp_imgfmt_from_name(param, true); if (!fmt) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: unknown format name: '%.*s'\n", + mp_err(log, "Option %.*s: unknown format name: '%.*s'\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; } @@ -1635,8 +1612,8 @@ const m_option_type_t m_option_type_imgfmt = { .copy = copy_opt, }; -static int parse_fourcc(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_fourcc(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0) return M_OPT_MISSING_PARAM; @@ -1650,8 +1627,7 @@ static int parse_fourcc(const m_option_t *opt, struct bstr name, bstr rest; value = bstrtoll(param, &rest, 16); if (rest.len != 0) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: invalid FourCC: '%.*s'\n", + mp_err(log, "Option %.*s: invalid FourCC: '%.*s'\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; } @@ -1672,24 +1648,23 @@ const m_option_type_t m_option_type_fourcc = { #include "audio/format.h" -static int parse_afmt(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_afmt(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { if (param.len == 0) return M_OPT_MISSING_PARAM; if (!bstrcmp0(param, "help")) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available formats:"); + mp_info(log, "Available formats:"); for (int i = 0; af_fmtstr_table[i].name; i++) - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %s", af_fmtstr_table[i].name); - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + mp_info(log, " %s", af_fmtstr_table[i].name); + mp_info(log, "\n"); return M_OPT_EXIT - 1; } int fmt = af_str2fmt_short(param); if (!fmt) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: unknown format name: '%.*s'\n", + mp_err(log, "Option %.*s: unknown format name: '%.*s'\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; } @@ -1710,14 +1685,14 @@ const m_option_type_t m_option_type_afmt = { #include "audio/chmap.h" -static int parse_chmap(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_chmap(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { // min>0: at least min channels, min=0: empty ok, min=-1: invalid ok int min_ch = (opt->flags & M_OPT_MIN) ? opt->min : 1; if (bstr_equals0(param, "help")) { - mp_chmap_print_help(MSGT_CFGPARSER, MSGL_INFO); + mp_chmap_print_help(log); return M_OPT_EXIT - 1; } @@ -1726,16 +1701,14 @@ static int parse_chmap(const m_option_t *opt, struct bstr name, struct mp_chmap res = {0}; if (!mp_chmap_from_str(&res, param)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Error parsing channel layout: %.*s\n", BSTR_P(param)); + mp_err(log, "Error parsing channel layout: %.*s\n", BSTR_P(param)); return M_OPT_INVALID; } if ((min_ch > 0 && !mp_chmap_is_valid(&res)) || (min_ch >= 0 && mp_chmap_is_empty(&res))) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Invalid channel layout: %.*s\n", BSTR_P(param)); + mp_err(log, "Invalid channel layout: %.*s\n", BSTR_P(param)); return M_OPT_INVALID; } @@ -1773,8 +1746,8 @@ static int parse_timestring(struct bstr str, double *time, char endchar) } -static int parse_time(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_time(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { double time; @@ -1782,7 +1755,7 @@ static int parse_time(const m_option_t *opt, struct bstr name, return M_OPT_MISSING_PARAM; if (!parse_timestring(param, &time, 0)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: invalid time: '%.*s'\n", + mp_err(log, "Option %.*s: invalid time: '%.*s'\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; } @@ -1811,8 +1784,8 @@ const m_option_type_t m_option_type_time = { // Relative time -static int parse_rel_time(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_rel_time(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { struct m_rel_time t = {0}; @@ -1847,8 +1820,7 @@ static int parse_rel_time(const m_option_t *opt, struct bstr name, goto out; } - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: invalid time or position: '%.*s'\n", + mp_err(log, "Option %.*s: invalid time or position: '%.*s'\n", BSTR_P(name), BSTR_P(param)); return M_OPT_INVALID; @@ -1893,9 +1865,7 @@ bool m_obj_list_find(struct m_obj_desc *dst, const struct m_obj_list *l, } else { // Assume it's deprecated in this case. // Also, it's used by the VO code only, so whatever. - mp_msg(MSGT_CFGPARSER, MSGL_WARN, - "Driver '%s' has been replaced with '%s'!\n", - aname, alias); + dst->replaced_name = aname; } return true; } @@ -2052,9 +2022,9 @@ static void copy_obj_settings_list(const m_option_t *opt, void *dst, // Consider -vf a=b=c:d=e. This verifies "b"="c" and "d"="e" and that the // option names/values are correct. Try to determine whether an option // without '=' sets a flag, or whether it's a positional argument. -static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config, - bstr name, bstr val, int flags, int *nold, - bstr *out_name, bstr *out_val) +static int get_obj_param(struct mp_log *log, bstr opt_name, bstr obj_name, + struct m_config *config, bstr name, bstr val, + int flags, int *nold, bstr *out_name, bstr *out_val) { int r; @@ -2068,13 +2038,12 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config, r = m_config_set_option_ext(config, name, val, flags); if (r < 0) { if (r == M_OPT_UNKNOWN) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: %.*s doesn't have a %.*s parameter.\n", + mp_err(log, "Option %.*s: %.*s doesn't have a %.*s parameter.\n", BSTR_P(opt_name), BSTR_P(obj_name), BSTR_P(name)); return M_OPT_UNKNOWN; } if (r > M_OPT_EXIT) - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: " + mp_err(log, "Option %.*s: " "Error while parsing %.*s parameter %.*s (%.*s)\n", BSTR_P(opt_name), BSTR_P(obj_name), BSTR_P(name), BSTR_P(val)); @@ -2092,7 +2061,7 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config, } const char *opt = m_config_get_positional_option(config, *nold); if (!opt) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: %.*s has only %d " + mp_err(log, "Option %.*s: %.*s has only %d " "params, so you can't give more than %d unnamed params.\n", BSTR_P(opt_name), BSTR_P(obj_name), *nold, *nold); return M_OPT_OUT_OF_RANGE; @@ -2100,7 +2069,7 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config, r = m_config_set_option_ext(config, bstr0(opt), val, flags); if (r < 0) { if (r > M_OPT_EXIT) - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: " + mp_err(log, "Option %.*s: " "Error while parsing %.*s parameter %s (%.*s)\n", BSTR_P(opt_name), BSTR_P(obj_name), opt, BSTR_P(val)); return r; @@ -2118,10 +2087,11 @@ static int get_obj_param(bstr opt_name, bstr obj_name, struct m_config *config, // If config is NULL, all parameters are accepted without checking. // _ret set to NULL can be used for checking-only. // flags can contain any M_SETOPT_* flag. -static int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name, - struct bstr *pstr, struct m_config *config, - int flags, void (*print_help_fn)(void), - char ***ret) +// desc is optional. +static int m_obj_parse_sub_config(struct mp_log *log, struct bstr opt_name, + struct bstr name, struct bstr *pstr, + struct m_config *config, int flags, + struct m_obj_desc *desc, char ***ret) { int nold = 0; char **args = NULL; @@ -2136,12 +2106,12 @@ static int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name, while (pstr->len > 0) { bstr fname, fval; - r = split_subconf(opt_name, pstr, &fname, &fval); + r = split_subconf(log, opt_name, pstr, &fname, &fval); if (r < 0) goto exit; if (bstr_equals0(fname, "help")) goto print_help; - r = get_obj_param(opt_name, name, config, fname, fval, flags, &nold, + r = get_obj_param(log, opt_name, name, config, fname, fval, flags, &nold, &fname, &fval); if (r < 0) goto exit; @@ -2171,11 +2141,11 @@ static int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name, print_help: ; if (config) { - if (print_help_fn) - print_help_fn(); + if (desc->print_help) + desc->print_help(); m_config_print_option_list(config); } else { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, "Option %.*s doesn't exist.\n", + mp_warn(log, "Option %.*s doesn't exist.\n", BSTR_P(opt_name)); } r = M_OPT_EXIT - 1; @@ -2189,8 +2159,8 @@ exit: #define NAMECH "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" // Parse one item, e.g. -vf a=b:c:d,e=f:g => parse a=b:c:d into "a" and "b:c:d" -static int parse_obj_settings(struct bstr opt, struct bstr *pstr, - const struct m_obj_list *list, +static int parse_obj_settings(struct mp_log *log, struct bstr opt, + struct bstr *pstr, const struct m_obj_list *list, m_obj_settings_t **_ret) { int r; @@ -2200,8 +2170,7 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr, if (bstr_eatstart0(pstr, "@")) { if (!bstr_split_tok(*pstr, ":", &label, pstr)) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: ':' expected after label.\n", BSTR_P(opt)); + mp_err(log, "Option %.*s: ':' expected after label.\n", BSTR_P(opt)); return M_OPT_INVALID; } } @@ -2215,9 +2184,13 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr, has_param = true; bool skip = false; - if (!m_obj_list_find(&desc, list, str)) { + if (m_obj_list_find(&desc, list, str)) { + if (desc.replaced_name) + mp_warn(log, "Driver '%s' has been replaced with '%s'!\n", + desc.name, desc.replaced_name); + } else { if (!list->allow_unknown_entries) { - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: %.*s doesn't exist.\n", + mp_err(log, "Option %.*s: %.*s doesn't exist.\n", BSTR_P(opt), BSTR_P(str)); return M_OPT_INVALID; } @@ -2226,9 +2199,9 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr, } if (_ret && desc.init_options) { - struct m_config *config = m_config_from_obj_desc_noalloc(NULL, &desc); + struct m_config *config = m_config_from_obj_desc_noalloc(NULL, log, &desc); bstr s = bstr0(desc.init_options); - m_obj_parse_sub_config(opt, str, &s, config, + m_obj_parse_sub_config(log, opt, str, &s, config, M_SETOPT_CHECK_ONLY, NULL, &plist); assert(s.len == 0); talloc_free(config); @@ -2237,9 +2210,9 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr, if (has_param) { struct m_config *config = NULL; if (!skip) - config = m_config_from_obj_desc_noalloc(NULL, &desc); - r = m_obj_parse_sub_config(opt, str, pstr, config, - M_SETOPT_CHECK_ONLY, desc.print_help, + config = m_config_from_obj_desc_noalloc(NULL, log, &desc); + r = m_obj_parse_sub_config(log, opt, str, pstr, config, + M_SETOPT_CHECK_ONLY, &desc, _ret ? &plist : NULL); talloc_free(config); if (r < 0) @@ -2259,8 +2232,8 @@ static int parse_obj_settings(struct bstr opt, struct bstr *pstr, // Parse a single entry for -vf-del (return 0 if not applicable) // mark_del is bounded by the number of items in dst -static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param, - void *dst, bool *mark_del) +static int parse_obj_settings_del(struct mp_log *log, struct bstr opt_name, + struct bstr *param, void *dst, bool *mark_del) { bstr s = *param; if (bstr_eatstart0(&s, "@")) { @@ -2276,8 +2249,7 @@ static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param, if (label_index >= 0) { mark_del[label_index] = true; } else { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, - "Option %.*s: item label @%.*s not found.\n", + mp_warn(log, "Option %.*s: item label @%.*s not found.\n", BSTR_P(opt_name), BSTR_P(label)); } } @@ -2298,8 +2270,7 @@ static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param, if (id >= 0 && id < num) { mark_del[id] = true; } else { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, - "Option %.*s: Index %lld is out of range.\n", + mp_warn(log, "Option %.*s: Index %lld is out of range.\n", BSTR_P(opt_name), id); } } @@ -2308,8 +2279,8 @@ static int parse_obj_settings_del(struct bstr opt_name, struct bstr *param, return 1; } -static int parse_obj_settings_list(const m_option_t *opt, struct bstr name, - struct bstr param, void *dst) +static int parse_obj_settings_list(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst) { int len = strlen(opt->name); m_obj_settings_t *res = NULL; @@ -2338,8 +2309,7 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name, char prefix[len]; strncpy(prefix, opt->name, len - 1); prefix[len - 1] = '\0'; - mp_msg(MSGT_CFGPARSER, MSGL_ERR, - "Option %.*s: unknown postfix %.*s\n" + mp_err(log, "Option %.*s: unknown postfix %.*s\n" "Supported postfixes are:\n" " %s-set\n" " Overwrite the old list with the given list\n\n" @@ -2360,17 +2330,17 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name, } if (!bstrcmp0(param, "help")) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "Available %s:\n", ol->description); + mp_info(log, "Available %s:\n", ol->description); for (int n = 0; ; n++) { struct m_obj_desc desc; if (!ol->get_desc(&desc, n)) break; if (!desc.hidden) { - mp_msg(MSGT_CFGPARSER, MSGL_INFO, " %-15s: %s\n", + mp_info(log, " %-15s: %s\n", desc.name, desc.description); } } - mp_msg(MSGT_CFGPARSER, MSGL_INFO, "\n"); + mp_info(log, "\n"); return M_OPT_EXIT - 1; } @@ -2388,9 +2358,9 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name, while (param.len > 0) { int r = 0; if (op == OP_DEL) - r = parse_obj_settings_del(name, ¶m, dst, mark_del); + r = parse_obj_settings_del(log, name, ¶m, dst, mark_del); if (r == 0) { - r = parse_obj_settings(name, ¶m, ol, dst ? &res : NULL); + r = parse_obj_settings(log, name, ¶m, ol, dst ? &res : NULL); } if (r < 0) return r; @@ -2460,8 +2430,7 @@ static int parse_obj_settings_list(const m_option_t *opt, struct bstr name, for (int n = 0; res && res[n].name; n++) { int found = obj_settings_find_by_content(list, &res[n]); if (found < 0) { - mp_msg(MSGT_CFGPARSER, MSGL_WARN, - "Option %.*s: Item not found\n", BSTR_P(name)); + mp_warn(log, "Option %.*s: Item not found\n", BSTR_P(name)); } else { obj_settings_list_del_at(&list, found); } diff --git a/options/m_option.h b/options/m_option.h index bea7a4376a..5abe605e95 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -31,6 +31,7 @@ typedef struct m_option_type m_option_type_t; typedef struct m_option m_option_t; struct m_config; +struct mp_log; ///////////////////////////// Options types declarations //////////////////// @@ -63,7 +64,8 @@ extern const m_option_type_t m_option_type_size_box; extern const m_option_type_t m_option_type_chmap; // Callback used by m_option_type_print_func options. -typedef int (*m_opt_func_full_t)(const m_option_t *, const char *, const char *); +typedef int (*m_opt_func_full_t)(struct mp_log *log, const m_option_t *, + const char *, const char *); enum m_rel_time_type { REL_TIME_NONE, @@ -113,6 +115,9 @@ struct m_obj_desc { bool hidden; // Callback to print custom help if "help" is passed void (*print_help)(void); + // Set by m_obj_list_find(). If the requested name is an old alias, this + // is set to the old name (while the name field uses the new name). + const char *replaced_name; }; // Extra definition needed for \ref m_option_type_obj_settings_list options. @@ -224,6 +229,7 @@ struct m_option_type { // Parse the data from a string. /** It is the only required function, all others can be NULL. * + * \param log for outputting parser error or help messages * \param opt The option that is parsed. * \param name The full option name. * \param param The parameter to parse. @@ -233,8 +239,8 @@ struct m_option_type { * \return On error a negative value is returned, on success the number * of arguments consumed. For details see \ref OptionParserReturn. */ - int (*parse)(const m_option_t *opt, struct bstr name, struct bstr param, - void *dst); + int (*parse)(struct mp_log *log, const m_option_t *opt, + struct bstr name, struct bstr param, void *dst); // Print back a value in string form. /** \param opt The option to print. @@ -439,10 +445,10 @@ char *m_option_strerror(int code); const m_option_t