From 5173900ed42074c1cf53d4eef622d5a1241d0325 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 15 Dec 2013 23:35:36 +0100 Subject: input: move some command flags into a bitfield --- mpvcore/input/input.c | 58 +++++++++++++++++++++++------------------------- mpvcore/input/input.h | 13 +++++++---- mpvcore/player/command.c | 27 ++++++++++------------ 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/mpvcore/input/input.c b/mpvcore/input/input.c index c7081e6514..2aa2a8ef36 100644 --- a/mpvcore/input/input.c +++ b/mpvcore/input/input.c @@ -918,14 +918,30 @@ error: return false; } +struct flag { + const char *name; + unsigned int remove, add; +}; + +static const struct flag cmd_flags[] = { + {"pausing", MP_PAUSING_FLAGS, MP_PAUSING}, + {"pausing-toggle", MP_PAUSING_FLAGS, MP_PAUSING_TOGGLE}, + {"no-osd", MP_ON_OSD_FLAGS, MP_ON_OSD_NO}, + {"osd-bar", MP_ON_OSD_FLAGS, MP_ON_OSD_BAR}, + {"osd-msg", MP_ON_OSD_FLAGS, MP_ON_OSD_MSG}, + {"osd-msg-bar", MP_ON_OSD_FLAGS, MP_ON_OSD_MSG | MP_ON_OSD_BAR}, + {"osd-auto", MP_ON_OSD_FLAGS, MP_ON_OSD_AUTO}, + {"expand-properties", 0, MP_EXPAND_PROPERTIES}, + {"raw", MP_EXPAND_PROPERTIES, 0}, + {0} +}; + // If dest is non-NULL when calling this function, append the command to the // list formed by dest->queue_next, otherwise just set *dest = new_cmd; static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str, const char *loc) { - int pausing = 0; - int on_osd = MP_ON_OSD_AUTO; - bool raw_args = false; + int def_flags = MP_ON_OSD_AUTO | MP_EXPAND_PROPERTIES; struct mp_cmd *cmd = NULL; bstr start = str; void *tmp = talloc_new(NULL); @@ -947,31 +963,15 @@ static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str, } while (1) { - if (eat_token(&str, "pausing")) { - pausing = 1; - } else if (eat_token(&str, "pausing_keep")) { - pausing = 2; - } else if (eat_token(&str, "pausing_toggle")) { - pausing = 3; - } else if (eat_token(&str, "pausing_keep_force")) { - pausing = 4; - } else if (eat_token(&str, "no-osd")) { - on_osd = MP_ON_OSD_NO; - } else if (eat_token(&str, "osd-bar")) { - on_osd = MP_ON_OSD_BAR; - } else if (eat_token(&str, "osd-msg")) { - on_osd = MP_ON_OSD_MSG; - } else if (eat_token(&str, "osd-msg-bar")) { - on_osd = MP_ON_OSD_MSG | MP_ON_OSD_BAR; - } else if (eat_token(&str, "osd-auto")) { - // default - } else if (eat_token(&str, "raw")) { - raw_args = true; - } else if (eat_token(&str, "expand-properties")) { - // default - } else { - break; + for (int n = 0; cmd_flags[n].name; n++) { + if (eat_token(&str, cmd_flags[n].name)) { + def_flags &= ~cmd_flags[n].remove; + def_flags |= cmd_flags[n].add; + goto cont; + } } + break; + cont: ; } int cmd_idx = 0; @@ -991,9 +991,7 @@ static int parse_cmd(struct input_ctx *ictx, struct mp_cmd **dest, bstr str, *cmd = (struct mp_cmd) { .name = (char *)cmd_def->name, .id = cmd_def->id, - .pausing = pausing, - .on_osd = on_osd, - .raw_args = raw_args, + .flags = def_flags, .scale = 1, .def = cmd_def, }; diff --git a/mpvcore/input/input.h b/mpvcore/input/input.h index 13b86d227e..1698c9cf9f 100644 --- a/mpvcore/input/input.h +++ b/mpvcore/input/input.h @@ -114,11 +114,18 @@ enum mp_command_type { // Key FIFO was full - release events may be lost, zero button-down status #define MP_INPUT_RELEASE_ALL -5 -enum mp_on_osd { +enum mp_cmd_flags { MP_ON_OSD_NO = 0, // prefer not using OSD MP_ON_OSD_AUTO = 1, // use default behavior of the specific command MP_ON_OSD_BAR = 2, // force a bar, if applicable MP_ON_OSD_MSG = 4, // force a message, if applicable + MP_EXPAND_PROPERTIES = 8, // expand strings as properties + MP_PAUSING = 16, // pause after running command + MP_PAUSING_TOGGLE = 32, // toggle pause after running command + + MP_ON_OSD_FLAGS = MP_ON_OSD_NO | MP_ON_OSD_AUTO | + MP_ON_OSD_BAR | MP_ON_OSD_MSG, + MP_PAUSING_FLAGS = MP_PAUSING | MP_PAUSING_TOGGLE, }; enum mp_input_section_flags { @@ -150,9 +157,7 @@ typedef struct mp_cmd { char *name; struct mp_cmd_arg args[MP_CMD_MAX_ARGS]; int nargs; - int pausing; - bool raw_args; - enum mp_on_osd on_osd; + int flags; // mp_cmd_flags bitfield bstr original; char *input_section; bool key_up_follows; diff --git a/mpvcore/player/command.c b/mpvcore/player/command.c index 05285e0111..8849e76a4e 100644 --- a/mpvcore/player/command.c +++ b/mpvcore/player/command.c @@ -2110,8 +2110,7 @@ static struct property_osd_display { {0} }; -static void show_property_osd(MPContext *mpctx, const char *pname, - enum mp_on_osd osd_mode) +static void show_property_osd(MPContext *mpctx, const char *pname, int osd_mode) { struct MPOpts *opts = mpctx->opts; struct m_option prop = {0}; @@ -2492,13 +2491,14 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) struct command_ctx *cmdctx = mpctx->command_ctx; struct MPOpts *opts = mpctx->opts; int osd_duration = opts->osd_duration; - bool auto_osd = cmd->on_osd == MP_ON_OSD_AUTO; - bool msg_osd = auto_osd || (cmd->on_osd & MP_ON_OSD_MSG); - bool bar_osd = auto_osd || (cmd->on_osd & MP_ON_OSD_BAR); + int on_osd = cmd->flags & MP_ON_OSD_FLAGS; + bool auto_osd = on_osd == MP_ON_OSD_AUTO; + bool msg_osd = auto_osd || (on_osd & MP_ON_OSD_MSG); + bool bar_osd = auto_osd || (on_osd & MP_ON_OSD_BAR); bool msg_or_nobar_osd = msg_osd && !(auto_osd && opts->osd_bar_visible); int osdl = msg_osd ? 1 : OSD_LEVEL_INVISIBLE; - if (!cmd->raw_args) { + if (cmd->flags & MP_EXPAND_PROPERTIES) { for (int n = 0; n < cmd->nargs; n++) { if (cmd->args[n].type->type == CONF_TYPE_STRING) { cmd->args[n].v.s = @@ -2552,7 +2552,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_SET_STRING, cmd->args[1].v.s, mpctx); if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) { - show_property_osd(mpctx, cmd->args[0].v.s, cmd->on_osd); + show_property_osd(mpctx, cmd->args[0].v.s, on_osd); } else if (r == M_PROPERTY_UNKNOWN) { set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration, "Unknown property: '%s'", cmd->args[0].v.s); @@ -2582,7 +2582,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) } int r = mp_property_do(property, M_PROPERTY_SWITCH, &s, mpctx); if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) { - show_property_osd(mpctx, property, cmd->on_osd); + show_property_osd(mpctx, property, on_osd); } else if (r == M_PROPERTY_UNKNOWN) { set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration, "Unknown property: '%s'", property); @@ -2600,7 +2600,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) int r = mp_property_multiply(property, f, mpctx); if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) { - show_property_osd(mpctx, property, cmd->on_osd); + show_property_osd(mpctx, property, on_osd); } else if (r == M_PROPERTY_UNKNOWN) { set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration, "Unknown property: '%s'", property); @@ -2633,7 +2633,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) char *value = args[first + next]; int r = mp_property_do(property, M_PROPERTY_SET_STRING, value, mpctx); if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) { - show_property_osd(mpctx, property, cmd->on_osd); + show_property_osd(mpctx, property, on_osd); } else if (r == M_PROPERTY_UNKNOWN) { set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration, "Unknown property: '%s'", property); @@ -3148,16 +3148,13 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) "Received unknown cmd %s\n", cmd->name); } - switch (cmd->pausing) { - case 1: // "pausing" + if (cmd->flags & MP_PAUSING) pause_player(mpctx); - break; - case 3: // "pausing_toggle" + if (cmd->flags & MP_PAUSING_TOGGLE) { if (opts->pause) unpause_player(mpctx); else pause_player(mpctx); - break; } } -- cgit v1.2.3