input: Move cmd_queue to context struct

Menu instances now also need a input context pointer to queue commands.
This commit is contained in:
Uoti Urpala 2008-04-30 13:00:59 +03:00
parent f7b608812e
commit 423b95bf5c
16 changed files with 57 additions and 46 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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));
}
}
}

View File

@ -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:

View File

@ -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)

View File

@ -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);