From 423b95bf5cc46da5952a907fa565c0c7119724f0 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 30 Apr 2008 13:00:59 +0300 Subject: input: Move cmd_queue to context struct Menu instances now also need a input context pointer to queue commands. --- command.c | 6 ++++-- input/input.c | 40 +++++++++++++++++++++------------------- input/input.h | 5 ++--- libmenu/menu.c | 8 ++++++-- libmenu/menu.h | 4 +++- libmenu/menu_chapsel.c | 4 ++-- libmenu/menu_cmdlist.c | 8 ++++---- libmenu/menu_console.c | 2 +- libmenu/menu_dvbin.c | 4 ++-- libmenu/menu_filesel.c | 4 ++-- libmenu/menu_param.c | 2 +- libmenu/menu_pt.c | 2 +- libvo/vo_macosx.m | 2 +- libvo/w32_common.c | 2 +- libvo/x11_common.c | 3 ++- mplayer.c | 7 ++++--- 16 files changed, 57 insertions(+), 46 deletions(-) diff --git a/command.c b/command.c index 70b924cac2..90df10ac4b 100644 --- a/command.c +++ b/command.c @@ -2864,7 +2864,8 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd) if (mpctx->set_of_sub_pos >= 0) { mpctx->global_sub_pos = -2; subdata = NULL; - mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); + mp_input_queue_cmd(mpctx->input, + mp_input_parse_cmd("sub_select")); } } else if (v < mpctx->set_of_sub_size) { subd = mpctx->set_of_subtitles[v]; @@ -2875,7 +2876,8 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd) if (mpctx->set_of_sub_pos == v) { mpctx->global_sub_pos = -2; subdata = NULL; - mp_input_queue_cmd(mp_input_parse_cmd("sub_select")); + mp_input_queue_cmd(mpctx->input, + mp_input_parse_cmd("sub_select")); } else if (mpctx->set_of_sub_pos > v) { --mpctx->set_of_sub_pos; --mpctx->global_sub_pos; diff --git a/input/input.c b/input/input.c index 33b6f40feb..a9f0775462 100644 --- a/input/input.c +++ b/input/input.c @@ -568,6 +568,9 @@ struct input_ctx { mp_input_fd_t key_fds[MP_MAX_KEY_FD]; unsigned int num_key_fd; + + mp_cmd_t *cmd_queue[CMD_QUEUE_SIZE]; + unsigned int cmd_queue_length, cmd_queue_start, cmd_queue_end; }; @@ -580,8 +583,6 @@ int async_quit_request; static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD]; static unsigned int num_cmd_fd = 0; -static mp_cmd_t* cmd_queue[CMD_QUEUE_SIZE]; -static unsigned int cmd_queue_length = 0,cmd_queue_start = 0, cmd_queue_end = 0; static unsigned int ar_delay = 100, ar_rate = 8; @@ -715,7 +716,8 @@ int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select, return 1; } -int mp_input_parse_and_queue_cmds(const char *str) { +int mp_input_parse_and_queue_cmds(struct input_ctx *ictx, const char *str) +{ int cmd_num = 0; while (*str == '\n' || *str == '\r' || *str == ' ') @@ -727,7 +729,7 @@ int mp_input_parse_and_queue_cmds(const char *str) { av_strlcpy(cmdbuf, str, len+1); cmd = mp_input_parse_cmd(cmdbuf); if (cmd) { - mp_input_queue_cmd(cmd); + mp_input_queue_cmd(ictx, cmd); ++cmd_num; } str += len; @@ -1278,28 +1280,28 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused) } -int -mp_input_queue_cmd(mp_cmd_t* cmd) { - if(!cmd || cmd_queue_length >= CMD_QUEUE_SIZE) +int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t* cmd) +{ + if (!cmd || ictx->cmd_queue_length >= CMD_QUEUE_SIZE) return 0; - cmd_queue[cmd_queue_end] = cmd; - cmd_queue_end = (cmd_queue_end + 1) % CMD_QUEUE_SIZE; - cmd_queue_length++; + ictx->cmd_queue[ictx->cmd_queue_end] = cmd; + ictx->cmd_queue_end = (ictx->cmd_queue_end + 1) % CMD_QUEUE_SIZE; + ictx->cmd_queue_length++; return 1; } -static mp_cmd_t *get_queued_cmd(int peek_only) +static mp_cmd_t *get_queued_cmd(struct input_ctx *ictx, int peek_only) { mp_cmd_t* ret; - if(cmd_queue_length == 0) + if (ictx->cmd_queue_length == 0) return NULL; - ret = cmd_queue[cmd_queue_start]; + ret = ictx->cmd_queue[ictx->cmd_queue_start]; if (!peek_only) { - cmd_queue_length--; - cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE; + ictx->cmd_queue_length--; + ictx->cmd_queue_start = (ictx->cmd_queue_start + 1) % CMD_QUEUE_SIZE; } return ret; @@ -1320,13 +1322,13 @@ mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int paused, return mp_input_parse_cmd("quit 1"); while(1) { from_queue = 1; - ret = get_queued_cmd(peek_only); + ret = get_queued_cmd(ictx, peek_only); if(ret) break; from_queue = 0; ret = read_events(ictx, time, paused); if (!ret) { from_queue = 1; - ret = get_queued_cmd(peek_only); + ret = get_queued_cmd(ictx, peek_only); } break; } @@ -1336,14 +1338,14 @@ mp_cmd_t *mp_input_get_cmd(struct input_ctx *ictx, int time, int paused, if(cf->filter(ret,paused,cf->ctx)) { if (peek_only && from_queue) // The filter ate the cmd, so we remove it from queue - ret = get_queued_cmd(0); + ret = get_queued_cmd(ictx, 0); mp_cmd_free(ret); return NULL; } } if (!from_queue && peek_only) - mp_input_queue_cmd(ret); + mp_input_queue_cmd(ictx, ret); return ret; } diff --git a/input/input.h b/input/input.h index 2e0a198bef..60613373a8 100644 --- a/input/input.h +++ b/input/input.h @@ -238,8 +238,7 @@ int mp_input_get_key_from_name(const char *name); // This function can be used to put a command in the system again. It's used by libmpdemux // when it performs a blocking operation to resend the command it received to the main // loop. -int -mp_input_queue_cmd(mp_cmd_t* cmd); +int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t* cmd); // This function retrieves the next available command waiting no more than time msec. // If pause is true, the next input will always return a pause command. @@ -253,7 +252,7 @@ mp_input_parse_cmd(char* str); * Parse and queue commands separated by '\n'. * @return count of commands new queued. */ -int mp_input_parse_and_queue_cmds(const char *str); +int mp_input_parse_and_queue_cmds(struct input_ctx *ictx, const char *str); /// These filters allow you to process the command before MPlayer. /// If a filter returns a true value mp_input_get_cmd will return NULL. diff --git a/libmenu/menu.c b/libmenu/menu.c index 6d3c6fb83e..0741f05448 100644 --- a/libmenu/menu.c +++ b/libmenu/menu.c @@ -72,6 +72,7 @@ int menu_mouse_pos_updated = 0; static struct MPContext *menu_ctx = NULL; static struct m_config *menu_mconfig = NULL; +static struct input_ctx *menu_input = NULL; static menu_def_t* menu_list = NULL; static int menu_count = 0; static menu_cmd_bindings_t *cmd_bindings = NULL; @@ -214,7 +215,7 @@ static int menu_parse_config(char* buffer, struct m_config *mconfig) #define BUF_MIN 128 #define BUF_MAX BUF_STEP*1024 int menu_init(struct MPContext *mpctx, struct m_config *mconfig, - char* cfg_file) + struct input_ctx *input_ctx, char* cfg_file) { char* buffer = NULL; int bl = BUF_STEP, br = 0; @@ -255,6 +256,7 @@ int menu_init(struct MPContext *mpctx, struct m_config *mconfig, menu_ctx = mpctx; menu_mconfig = mconfig; + menu_input = input_ctx; f = menu_parse_config(buffer, mconfig); free(buffer); return f; @@ -291,7 +293,8 @@ int menu_dflt_read_key(menu_t* menu,int cmd) { for (i = 0; i < bindings->binding_num; ++i) { if (bindings->bindings[i].key == cmd) { if (bindings->bindings[i].cmd) - mp_input_parse_and_queue_cmds(bindings->bindings[i].cmd); + mp_input_parse_and_queue_cmds(menu->input_ctx, + bindings->bindings[i].cmd); return 1; } } @@ -317,6 +320,7 @@ menu_t* menu_open(char *name) { m->priv = m_struct_copy(m->priv_st,menu_list[i].cfg); m->ctx = menu_ctx; m->mconfig = menu_mconfig; + m->input_ctx = menu_input; m->type = &menu_list[i]; if(menu_list[i].type->open(m,menu_list[i].args)) return m; diff --git a/libmenu/menu.h b/libmenu/menu.h index 7b63fad547..3a3f8fd6c3 100644 --- a/libmenu/menu.h +++ b/libmenu/menu.h @@ -14,6 +14,7 @@ struct m_struct_st; struct menu_s { struct MPContext *ctx; struct m_config *mconfig; + struct input_ctx *input_ctx; void (*draw)(menu_t* menu,mp_image_t* mpi); void (*read_cmd)(menu_t* menu,int cmd); int (*read_key)(menu_t* menu,int cmd); @@ -53,7 +54,8 @@ typedef struct menu_info_s { #define MENU_CMD_CLICK 11 /// Global init/uninit -int menu_init(struct MPContext *mpctx, struct m_config *mconfig, char* cfg_file); +int menu_init(struct MPContext *mpctx, struct m_config *mconfig, + struct input_ctx *input_ctx, char* cfg_file); void menu_uninit(void); /// Open a menu defined in the config file diff --git a/libmenu/menu_chapsel.c b/libmenu/menu_chapsel.c index 825524531b..d446147e7a 100644 --- a/libmenu/menu_chapsel.c +++ b/libmenu/menu_chapsel.c @@ -141,9 +141,9 @@ static void read_cmd (menu_t* menu, int cmd) case MENU_CMD_OK: { char cmdbuf[26]; sprintf(cmdbuf, "seek_chapter %d 1", menu->priv->p.current->cid); - mp_input_queue_cmd(mp_input_parse_cmd(cmdbuf)); + mp_input_queue_cmd(menu->input_ctx, mp_input_parse_cmd(cmdbuf)); if (menu->priv->auto_close) - mp_input_queue_cmd(mp_input_parse_cmd("menu hide")); + mp_input_queue_cmd(menu->input_ctx, mp_input_parse_cmd("menu hide")); break; } default: diff --git a/libmenu/menu_cmdlist.c b/libmenu/menu_cmdlist.c index 13025c222c..2c2edf0970 100644 --- a/libmenu/menu_cmdlist.c +++ b/libmenu/menu_cmdlist.c @@ -55,21 +55,21 @@ static void read_cmd(menu_t* menu,int cmd) { switch(cmd) { case MENU_CMD_RIGHT: if(mpriv->p.current->right) { - mp_input_parse_and_queue_cmds(mpriv->p.current->right); + mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->right); break; } // fallback on ok if right is not defined case MENU_CMD_OK: if (mpriv->p.current->ok) - mp_input_parse_and_queue_cmds(mpriv->p.current->ok); + mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->ok); break; case MENU_CMD_LEFT: if(mpriv->p.current->left) { - mp_input_parse_and_queue_cmds(mpriv->p.current->left); + mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->left); break; } // fallback on cancel if left is not defined case MENU_CMD_CANCEL: if(mpriv->p.current->cancel) { - mp_input_parse_and_queue_cmds(mpriv->p.current->cancel); + mp_input_parse_and_queue_cmds(menu->input_ctx, mpriv->p.current->cancel); break; } default: diff --git a/libmenu/menu_console.c b/libmenu/menu_console.c index abc941cdca..4b99412e1e 100644 --- a/libmenu/menu_console.c +++ b/libmenu/menu_console.c @@ -403,7 +403,7 @@ static void read_cmd(menu_t* menu,int cmd) { run_shell_cmd(menu,c->args[0].v.s); break; default: // Send the other commands to mplayer - mp_input_queue_cmd(c); + mp_input_queue_cmd(menu->input_ctx, c); } } return; diff --git a/libmenu/menu_dvbin.c b/libmenu/menu_dvbin.c index f59f55d3ec..5b007afadd 100644 --- a/libmenu/menu_dvbin.c +++ b/libmenu/menu_dvbin.c @@ -215,8 +215,8 @@ static void read_cmd(menu_t* menu, int cmd) if(c) { if(mpriv->auto_close) - mp_input_queue_cmd (mp_input_parse_cmd ("menu hide")); - mp_input_queue_cmd(c); + mp_input_queue_cmd(menu->input_ctx, mp_input_parse_cmd ("menu hide")); + mp_input_queue_cmd(menu->input_ctx, c); } } } diff --git a/libmenu/menu_filesel.c b/libmenu/menu_filesel.c index faad082b64..92d9728658 100644 --- a/libmenu/menu_filesel.c +++ b/libmenu/menu_filesel.c @@ -351,7 +351,7 @@ static void read_cmd(menu_t* menu,int cmd) { char *action = mpriv->p.current->d ? mpriv->dir_action:mpriv->file_action; sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); str = replace_path(action, filename); - mp_input_parse_and_queue_cmds(str); + mp_input_parse_and_queue_cmds(menu->input_ctx, str); if (str != action) free(str); } @@ -362,7 +362,7 @@ static void read_cmd(menu_t* menu,int cmd) { char *str; sprintf(filename,"%s%s",mpriv->dir,mpriv->p.current->p.txt); str = replace_path(action, filename); - mp_input_parse_and_queue_cmds(str); + mp_input_parse_and_queue_cmds(menu->input_ctx, str); if(str != action) free(str); } break; diff --git a/libmenu/menu_param.c b/libmenu/menu_param.c index 6eadf8825d..8afd084b64 100644 --- a/libmenu/menu_param.c +++ b/libmenu/menu_param.c @@ -219,7 +219,7 @@ static void read_cmd(menu_t* menu,int cmd) { char* txt = malloc(10 + strlen(e->menu) + 1); sprintf(txt,"set_menu %s",e->menu); c = mp_input_parse_cmd(txt); - if(c) mp_input_queue_cmd(c); + if(c) mp_input_queue_cmd(menu->input_ctx, c); return; } } diff --git a/libmenu/menu_pt.c b/libmenu/menu_pt.c index 27ce5ae0e3..1728c251a9 100644 --- a/libmenu/menu_pt.c +++ b/libmenu/menu_pt.c @@ -86,7 +86,7 @@ static void read_cmd(menu_t* menu,int cmd) { } c = mp_input_parse_cmd(str); if(c) - mp_input_queue_cmd(c); + mp_input_queue_cmd(menu->input_ctx, c); else mp_msg(MSGT_GLOBAL,MSGL_WARN,MSGTR_LIBMENU_FailedToBuildCommand,str); } break; diff --git a/libvo/vo_macosx.m b/libvo/vo_macosx.m index 93db462461..2fe61dd612 100644 --- a/libvo/vo_macosx.m +++ b/libvo/vo_macosx.m @@ -1009,7 +1009,7 @@ static int control(uint32_t request, void *data) snprintf(cmdstr, sizeof(cmdstr), "set_mouse_pos %i %i", (int)(vo_fs ? p.x : (p.x - textureFrame.origin.x)), (int)(vo_fs ? [self frame].size.height - p.y: (NSMaxY(textureFrame) - p.y))); - mp_input_queue_cmd(mp_input_parse_cmd(cmdstr)); + mp_input_queue_cmd(global_vo->input_ctx, mp_input_parse_cmd(cmdstr)); } } } diff --git a/libvo/w32_common.c b/libvo/w32_common.c index 82cd9c94a1..b45b06cfbc 100644 --- a/libvo/w32_common.c +++ b/libvo/w32_common.c @@ -137,7 +137,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l char cmd_str[40]; snprintf(cmd_str, sizeof(cmd_str), "set_mouse_pos %i %i", GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); - mp_input_queue_cmd(mp_input_parse_cmd(cmd_str)); + mp_input_queue_cmd(global_vo->input_ctx, mp_input_parse_cmd(cmd_str)); } break; case WM_MOUSEWHEEL: diff --git a/libvo/x11_common.c b/libvo/x11_common.c index 85ed754958..ec48f16ff6 100644 --- a/libvo/x11_common.c +++ b/libvo/x11_common.c @@ -1063,7 +1063,8 @@ int vo_x11_check_events(struct vo *vo) { char cmd_str[40]; sprintf(cmd_str,"set_mouse_pos %i %i",Event.xmotion.x, Event.xmotion.y); - mp_input_queue_cmd(mp_input_parse_cmd(cmd_str)); + mp_input_queue_cmd(vo->input_ctx, + mp_input_parse_cmd(cmd_str)); } if (x11->vo_mouse_autohide) diff --git a/mplayer.c b/mplayer.c index 7b64936b6a..05f7492376 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2883,14 +2883,15 @@ stream_set_interrupt_callback(mp_input_check_interrupt, mpctx->input); #ifdef HAVE_MENU if(use_menu) { - if(menu_cfg && menu_init(mpctx, mpctx->mconfig, menu_cfg)) + if(menu_cfg && menu_init(mpctx, mpctx->mconfig, mpctx->input, menu_cfg)) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg); else { menu_cfg = get_path("menu.conf"); - if(menu_init(mpctx, mpctx->mconfig, menu_cfg)) + if(menu_init(mpctx, mpctx->mconfig, mpctx->input, menu_cfg)) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, menu_cfg); else { - if(menu_init(mpctx, mpctx->mconfig, MPLAYER_CONFDIR "/menu.conf")) + if(menu_init(mpctx, mpctx->mconfig, mpctx->input, + MPLAYER_CONFDIR "/menu.conf")) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitialized, MPLAYER_CONFDIR"/menu.conf"); else { mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_MenuInitFailed); -- cgit v1.2.3