input: Move key filedescriptor list to context struct

The context variable is now passed to VOs too as it's now needed to
add a callback on the X filedescriptor.
This commit is contained in:
Uoti Urpala 2008-04-30 11:06:55 +03:00
parent 32e52b8fd0
commit bfcb3a7a81
6 changed files with 53 additions and 39 deletions

View File

@ -565,6 +565,9 @@ struct input_ctx {
// The command binds of current section
mp_cmd_bind_t *cmd_binds;
mp_cmd_bind_t *cmd_binds_default;
mp_input_fd_t key_fds[MP_MAX_KEY_FD];
unsigned int num_key_fd;
};
@ -575,8 +578,6 @@ int (*mp_input_key_cb)(int code) = NULL;
int async_quit_request;
static mp_input_fd_t key_fds[MP_MAX_KEY_FD];
static unsigned int num_key_fd = 0;
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];
@ -669,29 +670,31 @@ mp_input_rm_cmd_fd(int fd) {
num_cmd_fd--;
}
void
mp_input_rm_key_fd(int fd) {
void mp_input_rm_key_fd(struct input_ctx *ictx, int fd)
{
struct mp_input_fd *key_fds = ictx->key_fds;
unsigned int i;
for(i = 0; i < num_key_fd; i++) {
for (i = 0; i < ictx->num_key_fd; i++) {
if(key_fds[i].fd == fd)
break;
}
if(i == num_key_fd)
if (i == ictx->num_key_fd)
return;
if(key_fds[i].close_func)
key_fds[i].close_func(key_fds[i].fd);
if(i + 1 < num_key_fd)
memmove(&key_fds[i],&key_fds[i+1],(num_key_fd - i - 1)*sizeof(mp_input_fd_t));
num_key_fd--;
if(i + 1 < ictx->num_key_fd)
memmove(&key_fds[i], &key_fds[i+1],
(ictx->num_key_fd - i - 1) * sizeof(mp_input_fd_t));
ictx->num_key_fd--;
}
int
mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func,
mp_close_func_t close_func, void *ctx)
int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select,
mp_key_func_t read_func, mp_close_func_t close_func,
void *ctx)
{
if(num_key_fd == MP_MAX_KEY_FD) {
if (ictx->num_key_fd == MP_MAX_KEY_FD) {
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd);
return 0;
}
@ -700,14 +703,14 @@ mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func,
return 0;
}
key_fds[num_key_fd] = (struct mp_input_fd){
ictx->key_fds[ictx->num_key_fd] = (struct mp_input_fd){
.fd = fd,
.read_func.key = read_func,
.close_func = close_func,
.no_select = !select,
.ctx = ctx,
};
num_key_fd++;
ictx->num_key_fd++;
return 1;
}
@ -1165,9 +1168,10 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused)
{
int i;
int got_cmd = 0;
for (i = 0; i < num_key_fd; i++)
struct mp_input_fd *key_fds = ictx->key_fds;
for (i = 0; i < ictx->num_key_fd; i++)
if (key_fds[i].dead) {
mp_input_rm_key_fd(key_fds[i].fd);
mp_input_rm_key_fd(ictx, key_fds[i].fd);
i--;
}
for (i = 0; i < num_cmd_fd; i++)
@ -1182,7 +1186,7 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused)
FD_ZERO(&fds);
if (!got_cmd) {
int max_fd = 0, num_fd = 0;
for (i = 0; i < num_key_fd; i++) {
for (i = 0; i < ictx->num_key_fd; i++) {
if (key_fds[i].no_select)
continue;
if (key_fds[i].fd > max_fd)
@ -1221,7 +1225,7 @@ static mp_cmd_t *read_events(struct input_ctx *ictx, int time, int paused)
#endif
for (i = 0; i < num_key_fd; i++) {
for (i = 0; i < ictx->num_key_fd; i++) {
#ifdef HAVE_POSIX_SELECT
if (!key_fds[i].no_select && !FD_ISSET(key_fds[i].fd, &fds))
continue;
@ -1720,7 +1724,8 @@ struct input_ctx *mp_input_init(int use_gui)
if(fd < 0)
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitJoystick);
else
mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close,NULL);
mp_input_add_key_fd(ictx, fd, 1, mp_input_joystick_read,
(mp_close_func_t)close,NULL);
}
#endif
@ -1745,7 +1750,8 @@ struct input_ctx *mp_input_init(int use_gui)
if(mp_input_ar_init() < 0)
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitAppleRemote);
else
mp_input_add_key_fd(-1,0,mp_input_ar_read,mp_input_ar_close, NULL);
mp_input_add_key_fd(ictx, -1, 0, mp_input_ar_read, mp_input_ar_close,
NULL);
}
#endif
@ -1771,9 +1777,9 @@ void mp_input_uninit(struct input_ctx *ictx)
unsigned int i;
for(i=0; i < num_key_fd; i++) {
if(key_fds[i].close_func)
key_fds[i].close_func(key_fds[i].fd);
for (i=0; i < ictx->num_key_fd; i++) {
if (ictx->key_fds[i].close_func)
ictx->key_fds[i].close_func(ictx->key_fds[i].fd);
}
for(i=0; i < num_cmd_fd; i++) {

View File

@ -225,12 +225,12 @@ 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
// give a read_func.
int
mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func, void *ctx);
int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select,
mp_key_func_t read_func, mp_close_func_t close_func,
void *ctx);
// As for the cmd one you usually don't need this function.
void
mp_input_rm_key_fd(int fd);
void mp_input_rm_key_fd(struct input_ctx *ictx, int fd);
/// Get input key from its name.
int mp_input_get_key_from_name(const char *name);

View File

@ -294,11 +294,18 @@ void list_video_out(void)
}
struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
struct mp_fifo *key_fifo)
struct mp_fifo *key_fifo,
struct input_ctx *input_ctx)
{
char **vo_list = opts->video_driver_list;
int i;
struct vo *vo = talloc_ptrtype(NULL, vo);
struct vo initial_values = {
.opts = opts,
.x11 = x11,
.key_fifo = key_fifo,
.input_ctx = input_ctx,
};
// first try the preferred drivers, with their optional subdevice param:
if (vo_list && vo_list[0])
while (vo_list[0][0]) {
@ -317,8 +324,7 @@ struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
const vo_info_t *info = video_driver->info;
if (!strcmp(info->short_name, name)) {
// name matches, try it
*vo = (struct vo){.opts = opts, .x11 = x11,
.key_fifo = key_fifo};
*vo = initial_values;
vo->driver = video_driver;
if (!vo_preinit(vo, vo_subdevice)) {
free(name);
@ -336,7 +342,7 @@ struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
vo_subdevice = NULL;
for (i = 0; video_out_drivers[i]; i++) {
const struct vo_driver *video_driver = video_out_drivers[i];
*vo = (struct vo){.opts = opts, .x11 = x11, key_fifo = key_fifo};
*vo = initial_values;
vo->driver = video_driver;
if (!vo_preinit(vo, vo_subdevice))
return vo; // success!

View File

@ -214,6 +214,7 @@ struct vo {
struct MPOpts *opts;
struct vo_x11_state *x11;
struct mp_fifo *key_fifo;
struct input_ctx *input_ctx;
// requested position/resolution
int dx;
@ -223,7 +224,8 @@ struct vo {
};
struct vo *init_best_video_out(struct MPOpts *opts, struct vo_x11_state *x11,
struct mp_fifo *key_fifo);
struct mp_fifo *key_fifo,
struct input_ctx *input_ctx);
int vo_config(struct vo *vo, uint32_t width, uint32_t height,
uint32_t d_width, uint32_t d_height, uint32_t flags,
char *title, uint32_t format);

View File

@ -711,7 +711,7 @@ static void uninit(struct vo *vo)
vo_vm_close(vo);
#endif
if (ctx->event_fd_registered)
mp_input_rm_key_fd(ConnectionNumber(vo->x11->display));
mp_input_rm_key_fd(vo->input_ctx, ConnectionNumber(vo->x11->display));
// uninit() shouldn't get called unless initialization went past vo_init()
vo_x11_uninit(vo);
}
@ -844,8 +844,8 @@ static int preinit(struct vo *vo, const char *arg)
ctx->fo = XvListImageFormats(x11->display, x11->xv_port, (int *) &ctx->formats);
mp_input_add_key_fd(ConnectionNumber(x11->display), 1, x11_fd_callback,
NULL, vo);
mp_input_add_key_fd(vo->input_ctx, ConnectionNumber(x11->display), 1,
x11_fd_callback, NULL, vo);
ctx->event_fd_registered = 1;
return 0;

View File

@ -2141,7 +2141,7 @@ int reinit_video_chain(struct MPContext *mpctx)
//shouldn't we set dvideo->id=-2 when we fail?
//if((mpctx->video_out->preinit(vo_subdevice))!=0){
if(!(mpctx->video_out=init_best_video_out(opts, mpctx->x11_state, mpctx->key_fifo))){
if(!(mpctx->video_out=init_best_video_out(opts, mpctx->x11_state, mpctx->key_fifo, mpctx->input))){
mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_ErrorInitializingVODevice);
goto err_out;
}
@ -2873,11 +2873,11 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){
// Init input system
current_module = "init_input";
mpctx->input = mp_input_init(use_gui);
mp_input_add_key_fd(-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)
mp_input_add_cmd_fd(0,USE_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL);
else if(!noconsolecontrols)
mp_input_add_key_fd(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
stream_set_interrupt_callback(mp_input_check_interrupt, mpctx->input);