mirror of
https://github.com/mpv-player/mpv
synced 2025-04-11 04:01:31 +00:00
input: Move command filedescriptor list to context struct
This commit is contained in:
parent
423b95bf5c
commit
a5fdd8f6f9
@ -569,6 +569,9 @@ struct input_ctx {
|
|||||||
mp_input_fd_t key_fds[MP_MAX_KEY_FD];
|
mp_input_fd_t key_fds[MP_MAX_KEY_FD];
|
||||||
unsigned int num_key_fd;
|
unsigned int num_key_fd;
|
||||||
|
|
||||||
|
mp_input_fd_t cmd_fds[MP_MAX_CMD_FD];
|
||||||
|
unsigned int num_cmd_fd;
|
||||||
|
|
||||||
mp_cmd_t *cmd_queue[CMD_QUEUE_SIZE];
|
mp_cmd_t *cmd_queue[CMD_QUEUE_SIZE];
|
||||||
unsigned int cmd_queue_length, cmd_queue_start, cmd_queue_end;
|
unsigned int cmd_queue_length, cmd_queue_start, cmd_queue_end;
|
||||||
};
|
};
|
||||||
@ -581,9 +584,6 @@ int (*mp_input_key_cb)(int code) = NULL;
|
|||||||
|
|
||||||
int async_quit_request;
|
int async_quit_request;
|
||||||
|
|
||||||
static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD];
|
|
||||||
static unsigned int num_cmd_fd = 0;
|
|
||||||
|
|
||||||
static unsigned int ar_delay = 100, ar_rate = 8;
|
static unsigned int ar_delay = 100, ar_rate = 8;
|
||||||
|
|
||||||
static int use_joystick = 1, use_lirc = 1, use_lircc = 1;
|
static int use_joystick = 1, use_lirc = 1, use_lircc = 1;
|
||||||
@ -629,9 +629,10 @@ static int default_cmd_func(int fd,char* buf, int l);
|
|||||||
static char *get_key_name(int key, char buffer[12]);
|
static char *get_key_name(int key, char buffer[12]);
|
||||||
|
|
||||||
|
|
||||||
int
|
int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
|
||||||
mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func) {
|
mp_cmd_func_t read_func, mp_close_func_t close_func)
|
||||||
if(num_cmd_fd == MP_MAX_CMD_FD) {
|
{
|
||||||
|
if (ictx->num_cmd_fd == MP_MAX_CMD_FD) {
|
||||||
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyCmdFds,fd);
|
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyCmdFds,fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -640,35 +641,37 @@ mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_fds[num_cmd_fd] = (struct mp_input_fd){
|
ictx->cmd_fds[ictx->num_cmd_fd] = (struct mp_input_fd){
|
||||||
.fd = fd,
|
.fd = fd,
|
||||||
.read_func.cmd = read_func ? read_func : default_cmd_func,
|
.read_func.cmd = read_func ? read_func : default_cmd_func,
|
||||||
.close_func = close_func,
|
.close_func = close_func,
|
||||||
.no_select = !select
|
.no_select = !select
|
||||||
};
|
};
|
||||||
num_cmd_fd++;
|
ictx->num_cmd_fd++;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mp_input_rm_cmd_fd(struct input_ctx *ictx, int fd)
|
||||||
mp_input_rm_cmd_fd(int fd) {
|
{
|
||||||
|
struct mp_input_fd *cmd_fds = ictx->cmd_fds;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for(i = 0; i < num_cmd_fd; i++) {
|
for (i = 0; i < ictx->num_cmd_fd; i++) {
|
||||||
if(cmd_fds[i].fd == fd)
|
if(cmd_fds[i].fd == fd)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(i == num_cmd_fd)
|
if (i == ictx->num_cmd_fd)
|
||||||
return;
|
return;
|
||||||
if(cmd_fds[i].close_func)
|
if(cmd_fds[i].close_func)
|
||||||
cmd_fds[i].close_func(cmd_fds[i].fd);
|
cmd_fds[i].close_func(cmd_fds[i].fd);
|
||||||
if(cmd_fds[i].buffer)
|
if(cmd_fds[i].buffer)
|
||||||
free(cmd_fds[i].buffer);
|
free(cmd_fds[i].buffer);
|
||||||
|
|
||||||
if(i + 1 < num_cmd_fd)
|
if (i + 1 < ictx->num_cmd_fd)
|
||||||
memmove(&cmd_fds[i],&cmd_fds[i+1],(num_cmd_fd - i - 1)*sizeof(mp_input_fd_t));
|
memmove(&cmd_fds[i], &cmd_fds[i+1],
|
||||||
num_cmd_fd--;
|
(ictx->num_cmd_fd - i - 1) * sizeof(mp_input_fd_t));
|
||||||
|
ictx->num_cmd_fd--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_input_rm_key_fd(struct input_ctx *ictx, int fd)
|
void mp_input_rm_key_fd(struct input_ctx *ictx, int fd)
|
||||||
@ -1174,14 +1177,15 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused)
|
|||||||
int i;
|
int i;
|
||||||
int got_cmd = 0;
|
int got_cmd = 0;
|
||||||
struct mp_input_fd *key_fds = ictx->key_fds;
|
struct mp_input_fd *key_fds = ictx->key_fds;
|
||||||
|
struct mp_input_fd *cmd_fds = ictx->cmd_fds;
|
||||||
for (i = 0; i < ictx->num_key_fd; i++)
|
for (i = 0; i < ictx->num_key_fd; i++)
|
||||||
if (key_fds[i].dead) {
|
if (key_fds[i].dead) {
|
||||||
mp_input_rm_key_fd(ictx, key_fds[i].fd);
|
mp_input_rm_key_fd(ictx, key_fds[i].fd);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
for (i = 0; i < num_cmd_fd; i++)
|
for (i = 0; i < ictx->num_cmd_fd; i++)
|
||||||
if (cmd_fds[i].dead || cmd_fds[i].eof) {
|
if (cmd_fds[i].dead || cmd_fds[i].eof) {
|
||||||
mp_input_rm_cmd_fd(cmd_fds[i].fd);
|
mp_input_rm_cmd_fd(ictx, cmd_fds[i].fd);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
else if (cmd_fds[i].got_cmd)
|
else if (cmd_fds[i].got_cmd)
|
||||||
@ -1199,7 +1203,7 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused)
|
|||||||
FD_SET(key_fds[i].fd, &fds);
|
FD_SET(key_fds[i].fd, &fds);
|
||||||
num_fd++;
|
num_fd++;
|
||||||
}
|
}
|
||||||
for (i = 0; i < num_cmd_fd; i++) {
|
for (i = 0; i < ictx->num_cmd_fd; i++) {
|
||||||
if (cmd_fds[i].no_select)
|
if (cmd_fds[i].no_select)
|
||||||
continue;
|
continue;
|
||||||
if (cmd_fds[i].fd > max_fd)
|
if (cmd_fds[i].fd > max_fd)
|
||||||
@ -1255,7 +1259,7 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused)
|
|||||||
if (autorepeat_cmd)
|
if (autorepeat_cmd)
|
||||||
return autorepeat_cmd;
|
return autorepeat_cmd;
|
||||||
|
|
||||||
for (i = 0; i < num_cmd_fd; i++) {
|
for (i = 0; i < ictx->num_cmd_fd; i++) {
|
||||||
#ifdef HAVE_POSIX_SELECT
|
#ifdef HAVE_POSIX_SELECT
|
||||||
if (!cmd_fds[i].no_select && !FD_ISSET(cmd_fds[i].fd, &fds) &&
|
if (!cmd_fds[i].no_select && !FD_ISSET(cmd_fds[i].fd, &fds) &&
|
||||||
!cmd_fds[i].got_cmd)
|
!cmd_fds[i].got_cmd)
|
||||||
@ -1737,7 +1741,8 @@ struct input_ctx *mp_input_init(int use_gui)
|
|||||||
if(use_lirc) {
|
if(use_lirc) {
|
||||||
int fd = mp_input_lirc_init();
|
int fd = mp_input_lirc_init();
|
||||||
if(fd > 0)
|
if(fd > 0)
|
||||||
mp_input_add_cmd_fd(fd,0,mp_input_lirc_read,mp_input_lirc_close);
|
mp_input_add_cmd_fd(ictx, fd, 0, mp_input_lirc_read,
|
||||||
|
mp_input_lirc_close);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1745,7 +1750,7 @@ struct input_ctx *mp_input_init(int use_gui)
|
|||||||
if(use_lircc) {
|
if(use_lircc) {
|
||||||
int fd = lircc_init("mplayer", NULL);
|
int fd = lircc_init("mplayer", NULL);
|
||||||
if(fd >= 0)
|
if(fd >= 0)
|
||||||
mp_input_add_cmd_fd(fd,1,NULL,(mp_close_func_t)lircc_cleanup);
|
mp_input_add_cmd_fd(ictx, fd, 1, NULL, (mp_close_func_t)lircc_cleanup);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1766,7 +1771,8 @@ struct input_ctx *mp_input_init(int use_gui)
|
|||||||
else {
|
else {
|
||||||
int in_file_fd = open(in_file,S_ISFIFO(st.st_mode) ? O_RDWR : O_RDONLY);
|
int in_file_fd = open(in_file,S_ISFIFO(st.st_mode) ? O_RDWR : O_RDONLY);
|
||||||
if(in_file_fd >= 0)
|
if(in_file_fd >= 0)
|
||||||
mp_input_add_cmd_fd(in_file_fd,1,NULL,(mp_close_func_t)close);
|
mp_input_add_cmd_fd(ictx, in_file_fd, 1, NULL,
|
||||||
|
(mp_close_func_t)close);
|
||||||
else
|
else
|
||||||
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantOpenFile,in_file,strerror(errno));
|
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantOpenFile,in_file,strerror(errno));
|
||||||
}
|
}
|
||||||
@ -1786,9 +1792,9 @@ void mp_input_uninit(struct input_ctx *ictx)
|
|||||||
ictx->key_fds[i].close_func(ictx->key_fds[i].fd);
|
ictx->key_fds[i].close_func(ictx->key_fds[i].fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i=0; i < num_cmd_fd; i++) {
|
for (i = 0; i < ictx->num_cmd_fd; i++) {
|
||||||
if(cmd_fds[i].close_func)
|
if (ictx->cmd_fds[i].close_func)
|
||||||
cmd_fds[i].close_func(cmd_fds[i].fd);
|
ictx->cmd_fds[i].close_func(ictx->cmd_fds[i].fd);
|
||||||
}
|
}
|
||||||
talloc_free(ictx);
|
talloc_free(ictx);
|
||||||
}
|
}
|
||||||
|
@ -216,12 +216,11 @@ typedef int (*mp_input_cmd_filter)(mp_cmd_t* cmd, int paused, void* ctx);
|
|||||||
// fd will be used.
|
// fd will be used.
|
||||||
// The last arg can be NULL if nothing is needed to close the driver. The close
|
// The last arg can be NULL if nothing is needed to close the driver. The close
|
||||||
// function can be used
|
// function can be used
|
||||||
int
|
int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
|
||||||
mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func);
|
mp_cmd_func_t read_func, mp_close_func_t close_func);
|
||||||
|
|
||||||
// This removes a cmd driver, you usually don't need to use it.
|
// This removes a cmd driver, you usually don't need to use it.
|
||||||
void
|
void mp_input_rm_cmd_fd(struct input_ctx *ictx, int fd);
|
||||||
mp_input_rm_cmd_fd(int fd);
|
|
||||||
|
|
||||||
// The args are the same as for the key's drivers. If you don't use any valid fd you MUST
|
// The args are the same as for the key's drivers. If you don't use any valid fd you MUST
|
||||||
// give a read_func.
|
// give a read_func.
|
||||||
|
@ -2875,7 +2875,7 @@ current_module = "init_input";
|
|||||||
mpctx->input = mp_input_init(use_gui);
|
mpctx->input = mp_input_init(use_gui);
|
||||||
mp_input_add_key_fd(mpctx->input, -1,0,mplayer_get_key,NULL, mpctx->key_fifo);
|
mp_input_add_key_fd(mpctx->input, -1,0,mplayer_get_key,NULL, mpctx->key_fifo);
|
||||||
if(slave_mode)
|
if(slave_mode)
|
||||||
mp_input_add_cmd_fd(0,USE_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL);
|
mp_input_add_cmd_fd(mpctx->input, 0,USE_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL);
|
||||||
else if(!noconsolecontrols)
|
else if(!noconsolecontrols)
|
||||||
mp_input_add_key_fd(mpctx->input, 0, 1, read_keys, NULL, mpctx->key_fifo);
|
mp_input_add_key_fd(mpctx->input, 0, 1, read_keys, NULL, mpctx->key_fifo);
|
||||||
// Set the libstream interrupt callback
|
// Set the libstream interrupt callback
|
||||||
|
Loading…
Reference in New Issue
Block a user