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.
This commit is contained in:
Uoti Urpala
2010-12-18 10:14:25 +02:00
parent 00c2bafb0a
commit 7e366113f7
4 changed files with 59 additions and 5 deletions
+5 -4
View File
@@ -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 <mode number>
.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
+2 -1
View File
@@ -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),
+44
View File
@@ -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
+8
View File
@@ -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 */