video: cleanup stereo mode parsing

Use OPT_CHOICE_C() instead of the custom parser. The functionality is
pretty much equivalent.

(On a side note, it seems --video-stereo-mode can't be removed, because
it controls whether to "reduce" stereo video to mono, which is also the
default. In fact I'm not sure how this should be handled at all.)
This commit is contained in:
wm4 2015-04-02 23:54:08 +02:00
parent 19f56e2097
commit 5a2825ec35
7 changed files with 22 additions and 80 deletions

View File

@ -2162,59 +2162,6 @@ const m_option_type_t m_option_type_imgfmt = {
.copy = copy_opt,
};
#include "video/csputils.h"
static int parse_stereo_mode(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_info(log, "Available modes:");
for (int n = 0; n < MP_STEREO3D_COUNT; n++) {
if (mp_stereo3d_names[n])
mp_info(log, " %s\n", mp_stereo3d_names[n]);
}
mp_info(log, " none\n");
return M_OPT_EXIT - 1;
}
int mode = -1;
for (int n = 0; n < MP_STEREO3D_COUNT; n++) {
if (bstr_equals(param, bstr0(mp_stereo3d_names[n]))) {
mode = n;
break;
}
}
if (mode < 0 && !bstr_equals0(param, "none")) {
mp_err(log, "Option %.*s: unknown parameter: '%.*s'\n",
BSTR_P(name), BSTR_P(param));
return M_OPT_INVALID;
}
if (dst)
*((int *)dst) = mode;
return 1;
}
static char *print_stereo_mode(const m_option_t *opt, const void *val)
{
int mode = *(int *)val;
const char *name = mode >= 0 ? MP_STEREO3D_NAME(mode) : "none";
return talloc_strdup(NULL, name);
}
const m_option_type_t m_option_vid_stereo_mode = {
.name = "Stereo 3D mode",
.size = sizeof(int),
.parse = parse_stereo_mode,
.print = print_stereo_mode,
};
static int parse_fourcc(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param, void *dst)
{

View File

@ -57,7 +57,6 @@ extern const m_option_type_t m_option_type_msglevels;
extern const m_option_type_t m_option_type_print_fn;
extern const m_option_type_t m_option_type_subconfig;
extern const m_option_type_t m_option_type_imgfmt;
extern const m_option_type_t m_option_vid_stereo_mode;
extern const m_option_type_t m_option_type_fourcc;
extern const m_option_type_t m_option_type_afmt;
extern const m_option_type_t m_option_type_color;
@ -665,9 +664,6 @@ extern const char m_option_path_separator;
#define OPT_TRACKCHOICE(name, var) \
OPT_CHOICE_OR_INT(name, var, 0, 0, 8190, ({"no", -2}, {"auto", -1}))
#define OPT_VID_STEREO_MODE(...) \
OPT_GENERAL(int, __VA_ARGS__, .type = &m_option_vid_stereo_mode)
#define OPT_STRING_VALIDATE_(optname, varname, flags, validate_fn, ...) \
OPT_GENERAL(char*, optname, varname, flags, __VA_ARGS__, \
.priv = MP_EXPECT_TYPE(m_opt_string_validate_fn, validate_fn))

View File

@ -426,7 +426,7 @@ const m_option_t mp_opts[] = {
OPT_FLAG("force-rgba-osd-rendering", force_rgba_osd, 0),
OPT_CHOICE_OR_INT("video-rotate", video_rotate, 0, 0, 360,
({"no", -1})),
OPT_VID_STEREO_MODE("video-stereo-mode", video_stereo_mode, 0),
OPT_CHOICE_C("video-stereo-mode", video_stereo_mode, 0, mp_stereo3d_names),
OPT_CHOICE_OR_INT("cursor-autohide", cursor_autohide_delay, 0,
0, 30000, ({"no", -1}, {"always", -2})),

View File

@ -159,7 +159,7 @@ static void filter_reconfig(struct MPContext *mpctx,
if (params.stereo_in != params.stereo_out &&
params.stereo_in > 0 && params.stereo_out >= 0)
{
char *to = MP_STEREO3D_NAME(params.stereo_out);
char *to = (char *)MP_STEREO3D_NAME(params.stereo_out);
if (to) {
char *args[] = {"in", "auto", "out", to, NULL, NULL};
if (try_filter(mpctx, params, "stereo3d", "stereo3d", args) < 0)

View File

@ -93,25 +93,24 @@ const struct m_opt_choice_alternatives mp_chroma_names[] = {
};
// The short name _must_ match with what vf_stereo3d accepts (if supported).
// The long name is closer to the Matroska spec (StereoMode element).
// The long name in comments is closer to the Matroska spec (StereoMode element).
// The numeric index matches the Matroska StereoMode value. If you add entries
// that don't match Matroska, make sure demux_mkv.c rejects them properly.
// The long name is unused.
#define E(index, short, long) [index] = short
const char *const mp_stereo3d_names[MP_STEREO3D_COUNT] = {
E(0, "mono", "mono"), // unsupported by vf_stereo3d
E(1, "sbs2l", "side_by_side_left"),
E(2, "ab2r", "top_bottom_right"),
E(3, "ab2l", "top_bottom_left"),
E(4, "checkr", "checkboard_right"), // unsupported by vf_stereo3d
E(5, "checkl", "checkboard_left"), // unsupported by vf_stereo3d
E(6, "irr", "row_interleaved_right"),
E(7, "irl", "row_interleaved_left"),
E(8, "icr", "column_interleaved_right"),// unsupported by vf_stereo3d
E(9, "icl", "column_interleaved_left"), // unsupported by vf_stereo3d
E(10, "arcc", "anaglyph_cyan_red"), // Matroska: unclear which mode
E(11, "sbs2r", "side_by_side_right"),
E(12, "agmc", "anaglyph_green_magenta"), // Matroska: unclear which mode
const struct m_opt_choice_alternatives mp_stereo3d_names[] = {
{"mono", 0},
{"sbs2l", 1}, // "side_by_side_left"
{"ab2r", 2}, // "top_bottom_right"
{"ab2l", 3}, // "top_bottom_left"
{"checkr", 4}, // "checkboard_right" (unsupported by vf_stereo3d)
{"checkl", 5}, // "checkboard_left" (unsupported by vf_stereo3d)
{"irr", 6}, // "row_interleaved_right"
{"irl", 7}, // "row_interleaved_left"
{"icr", 8}, // "column_interleaved_right" (unsupported by vf_stereo3d)
{"icl", 9}, // "column_interleaved_left" (unsupported by vf_stereo3d)
{"arcc", 10}, // "anaglyph_cyan_red" (Matroska: unclear which mode)
{"sbs2r", 11}, // "side_by_side_right"
{"agmc", 12}, // "anaglyph_green_magenta" (Matroska: unclear which mode)
{0}
};
enum mp_csp avcol_spc_to_mp_csp(int avcolorspace)

View File

@ -104,10 +104,10 @@ enum mp_stereo3d_mode {
MP_STEREO3D_COUNT = 13, // 12 is last valid mode
};
extern const char *const mp_stereo3d_names[MP_STEREO3D_COUNT];
extern const struct m_opt_choice_alternatives mp_stereo3d_names[];
#define MP_STEREO3D_NAME(x) m_opt_choice_str(mp_stereo3d_names, x)
#define MP_STEREO3D_NAME(x) \
((x) >= 0 && (x) < MP_STEREO3D_COUNT ? (char *)mp_stereo3d_names[(x)] : NULL)
#define MP_STEREO3D_NAME_DEF(x, def) \
(MP_STEREO3D_NAME(x) ? MP_STEREO3D_NAME(x) : (def))

View File

@ -468,7 +468,7 @@ static const char *rev_map_name(int val)
}
// Extremely stupid; can be dropped when the internal filter is dropped,
// and OPT_VID_STEREO_MODE() can be used instead.
// and OPT_CHOICE_C() can be used instead.
static int opt_to_stereo3dmode(int val)
{
// Find x for rev_map_name(val) == MP_STEREO3D_NAME(x)