From 7e366113f75c696ae2b32f5faa5f80ec3fca96b8 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Sat, 18 Dec 2010 01:00:28 +0200 Subject: options: add "choice" option type, use for -pts-association-mode Add a "choice" option type. Options of this type take a string as input and set an int option variable to the value corresponding to the string. The string->int mapping is option-specific and is given in the option definition. Strings not found in the mapping are rejected as invalid option values. Change the option -pts-association-mode to use this new option type and accept values "auto, decoder, sort" instead of "0, 1, 2". The change in accepted values shouldn't cause problems as this option is not appropriate to use in normal user config files. --- DOCS/man/en/mplayer.1 | 9 +++++---- cfg-mplayer.h | 3 ++- m_option.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ m_option.h | 8 ++++++++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1 index 60ee3b9169..a6c103ce25 100644 --- a/DOCS/man/en/mplayer.1 +++ b/DOCS/man/en/mplayer.1 @@ -1076,16 +1076,17 @@ MPlayer will not load or search for video segments from other files, and will also ignore any chapter order specified for the main file. . .TP -.B \-pts\-association\-mode +.B \-pts\-association\-mode auto|decode|sort Select the method used to determine which container packet timestamp corresponds to a particular output frame from the video decoder. +Normally you shouldn't need to change this option. .PD 0 .RSs -.IPs 0 +.IPs auto Try to pick a working mode from the ones below automatically (default) -.IPs 1 +.IPs decoder Use decoder reordering functionality. -.IPs 2 +.IPs sort Maintain a buffer of unused pts values and use the lowest value for the frame. .RE .PD 1 diff --git a/cfg-mplayer.h b/cfg-mplayer.h index be52df881a..3545b77716 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -309,7 +309,8 @@ const m_option_t mplayer_opts[]={ // a-v sync stuff: OPT_MAKE_FLAGS("correct-pts", user_correct_pts, 0), - OPT_INTRANGE("pts-association-mode", user_pts_assoc_mode, 0, 0, 2), + OPT_CHOICE("pts-association-mode", user_pts_assoc_mode, 0, + ({"auto", 0}, {"decoder", 1}, {"sort", 2})), OPT_MAKE_FLAGS("initial-audio-sync", initial_audio_sync, 0), OPT_FLAG_CONSTANTS("noautosync", autosync, 0, 0, -1), OPT_INTRANGE("autosync", autosync, 0, 0, 10000), diff --git a/m_option.c b/m_option.c index daab955614..33c5e95a1b 100644 --- a/m_option.c +++ b/m_option.c @@ -267,6 +267,50 @@ const struct m_option_type m_option_type_intpair = { .set = copy_opt, }; +static int parse_choice(const struct m_option *opt, const char *name, + const char *param, void *dst, int src) +{ + if (param == NULL) + return M_OPT_MISSING_PARAM; + + struct m_opt_choice_alternatives *alt; + for (alt = opt->priv; alt->name; alt++) + if (!strcmp(param, alt->name)) + break; + if (!alt->name) { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Invalid value for option %s: %s\n", + name, param); + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Valid values are:"); + for (alt = opt->priv; alt->name; alt++) + mp_msg(MSGT_CFGPARSER, MSGL_ERR, " %s", alt->name); + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "\n"); + return M_OPT_INVALID; + } + if (dst) + *(int *)dst = alt->value; + + return 1; +} + +static char *print_choice(const m_option_t *opt, const void *val) +{ + int v = *(int *)val; + struct m_opt_choice_alternatives *alt; + for (alt = opt->priv; alt->name; alt++) + if (alt->value == v) + return strdup(alt->name); + abort(); +} + +const struct m_option_type m_option_type_choice = { + .name = "String", // same as arbitrary strings in option list for now + .size = sizeof(int), + .parse = parse_choice, + .print = print_choice, + .save = copy_opt, + .set = copy_opt, +}; + // Float #undef VAL diff --git a/m_option.h b/m_option.h index 26c457e24d..ed2b30de75 100644 --- a/m_option.h +++ b/m_option.h @@ -53,6 +53,7 @@ extern const m_option_type_t m_option_type_string_list; extern const m_option_type_t m_option_type_position; extern const m_option_type_t m_option_type_time; extern const m_option_type_t m_option_type_time_size; +extern const m_option_type_t m_option_type_choice; extern const m_option_type_t m_option_type_print; extern const m_option_type_t m_option_type_print_indirect; @@ -169,6 +170,11 @@ typedef struct { /// Ready made settings to parse a \ref m_span_t with a start-end syntax. extern const m_obj_params_t m_span_params_def; +struct m_opt_choice_alternatives { + char *name; + int value; +}; + // FIXME: backward compatibility #define CONF_TYPE_FLAG (&m_option_type_flag) @@ -543,5 +549,7 @@ int parse_timestring(const char *str, double *time, char endchar); #define OPT_STRING(optname, varname, flags) {optname, NULL, &m_option_type_string, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)} #define OPT_SETTINGSLIST(optname, varname, flags, objlist) {optname, NULL, &m_option_type_obj_settings_list, flags, 0, 0, objlist, 1, offsetof(struct MPOpts, varname)} #define OPT_AUDIOFORMAT(optname, varname, flags) {optname, NULL, &m_option_type_afmt, flags, 0, 0, NULL, 1, offsetof(struct MPOpts, varname)} +#define OPT_HELPER_REMOVEPAREN(...) __VA_ARGS__ +#define OPT_CHOICE(optname, varname, flags, choices) {optname, NULL, &m_option_type_choice, flags, 0, 0, &(const struct m_opt_choice_alternatives[]){OPT_HELPER_REMOVEPAREN choices, {NULL}}, 1, offsetof(struct MPOpts, varname)} #endif /* MPLAYER_M_OPTION_H */ -- cgit v1.2.3