diff options
Diffstat (limited to 'input')
-rw-r--r-- | input/ar.c | 4 | ||||
-rw-r--r-- | input/ar.h | 2 | ||||
-rw-r--r-- | input/input.c | 97 | ||||
-rw-r--r-- | input/input.h | 8 | ||||
-rw-r--r-- | input/joystick.c | 2 | ||||
-rw-r--r-- | input/joystick.h | 2 |
6 files changed, 39 insertions, 76 deletions
diff --git a/input/ar.c b/input/ar.c index 7347b4c326..0f48a50716 100644 --- a/input/ar.c +++ b/input/ar.c @@ -321,7 +321,7 @@ int is_mplayer_front() return 0; } -int mp_input_ar_read(int fd) +int mp_input_ar_read(void *ctx, int fd) { int i, down = 0; int ret = MP_INPUT_NOTHING; @@ -445,7 +445,7 @@ int main(void) } while (1) { - switch ((ret = mp_input_ar_read(0)) & ~MP_KEY_DOWN) { + switch ((ret = mp_input_ar_read(NULL, 0)) & ~MP_KEY_DOWN) { case AR_PLAY: printf(" - AR_PLAY."); break; case AR_PLAY_HOLD: printf(" - AR_PLAY_HOLD."); break; case AR_NEXT: printf(" - AR_NEXT."); break; diff --git a/input/ar.h b/input/ar.h index 836ba089d1..ae763acdad 100644 --- a/input/ar.h +++ b/input/ar.h @@ -36,7 +36,7 @@ #define AR_VDOWN (AR_BASE + 9) int mp_input_ar_init(void); -int mp_input_ar_read(int fd); +int mp_input_ar_read(void *ctx, int fd); void mp_input_ar_close(int fd); #endif /* MPLAYER_AR_H */ diff --git a/input/input.c b/input/input.c index 5d6cc08ed8..c8218c7b00 100644 --- a/input/input.c +++ b/input/input.c @@ -17,7 +17,6 @@ #include <assert.h> #endif #include "mp_fifo.h" -#include "osdep/getch2.h" #include "osdep/keycodes.h" #include "osdep/timer.h" #include "libavutil/avstring.h" @@ -505,14 +504,17 @@ static const mp_cmd_bind_t gui_def_cmd_binds[] = { typedef struct mp_input_fd { int fd; - void* read_func; + union { + mp_key_func_t key; + mp_cmd_func_t cmd; + } read_func; mp_close_func_t close_func; + void *ctx; unsigned eof : 1; unsigned drop : 1; unsigned dead : 1; unsigned got_cmd : 1; unsigned no_select : 1; - unsigned no_readfunc_retval : 1; // These fields are for the cmd fds. char* buffer; int pos,size; @@ -577,7 +579,7 @@ static int mp_input_print_key_list(m_option_t* cfg); static int mp_input_print_cmd_list(m_option_t* cfg); // Our command line options -static m_option_t input_conf[] = { +static const m_option_t input_conf[] = { { "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL }, { "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, { "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL }, @@ -588,7 +590,7 @@ static m_option_t input_conf[] = { { NULL, NULL, 0, 0, 0, 0, NULL} }; -static m_option_t mp_input_opts[] = { +static const m_option_t mp_input_opts[] = { { "input", &input_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL}, { "nojoystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL }, { "joystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL }, @@ -619,11 +621,12 @@ mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t return 0; } - memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t)); - cmd_fds[num_cmd_fd].fd = fd; - cmd_fds[num_cmd_fd].read_func = read_func ? read_func : mp_input_default_cmd_func; - cmd_fds[num_cmd_fd].close_func = close_func; - cmd_fds[num_cmd_fd].no_select = !select; + cmd_fds[num_cmd_fd] = (struct mp_input_fd){ + .fd = fd, + .read_func.cmd = read_func ? read_func : mp_input_default_cmd_func, + .close_func = close_func, + .no_select = !select + }; num_cmd_fd++; return 1; @@ -668,7 +671,9 @@ mp_input_rm_key_fd(int fd) { } int -mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) { +mp_input_add_key_fd(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) { mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd); return 0; @@ -678,43 +683,18 @@ mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t return 0; } - memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t)); - key_fds[num_key_fd].fd = fd; - key_fds[num_key_fd].read_func = read_func; - key_fds[num_key_fd].close_func = close_func; - key_fds[num_key_fd].no_select = !select; + key_fds[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++; return 1; } -int -mp_input_add_event_fd(int fd, void (*read_func)(void)) -{ - if(num_key_fd == MP_MAX_KEY_FD) { - mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd); - return 0; - } - if (fd < 0) { - mp_msg(MSGT_INPUT, MSGL_ERR, "Invalid fd %i in mp_input_add_event_fd", fd); - return 0; - } - - memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t)); - key_fds[num_key_fd].fd = fd; - key_fds[num_key_fd].read_func = read_func; - key_fds[num_key_fd].close_func = NULL; - key_fds[num_key_fd].no_readfunc_retval = 1; - num_key_fd++; - - return 1; -} - -void mp_input_rm_event_fd(int fd) -{ - mp_input_rm_key_fd(fd); -} - int mp_input_parse_and_queue_cmds(const char *str) { int cmd_num = 0; @@ -893,7 +873,8 @@ mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) { // Get some data if needed/possible while (!mp_fd->got_cmd && !mp_fd->eof && (mp_fd->size - mp_fd->pos > 1) ) { - int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->fd,mp_fd->buffer+mp_fd->pos,mp_fd->size - 1 - mp_fd->pos); + int r = mp_fd->read_func.cmd(mp_fd->fd, mp_fd->buffer+mp_fd->pos, + mp_fd->size - 1 - mp_fd->pos); // Error ? if(r < 0) { switch(r) { @@ -1161,10 +1142,6 @@ static mp_cmd_t *read_events(int time, int paused) { int i; int got_cmd = 0; - mp_cmd_t *autorepeat_cmd; -#ifdef HAVE_POSIX_SELECT - fd_set fds; -#endif for (i = 0; i < num_key_fd; i++) if (key_fds[i].dead) { mp_input_rm_key_fd(key_fds[i].fd); @@ -1178,6 +1155,7 @@ static mp_cmd_t *read_events(int time, int paused) else if (cmd_fds[i].got_cmd) got_cmd = 1; #ifdef HAVE_POSIX_SELECT + fd_set fds; FD_ZERO(&fds); if (!got_cmd) { int max_fd = 0, num_fd = 0; @@ -1221,22 +1199,12 @@ static mp_cmd_t *read_events(int time, int paused) for (i = 0; i < num_key_fd; i++) { - int code; #ifdef HAVE_POSIX_SELECT if (!key_fds[i].no_select && !FD_ISSET(key_fds[i].fd, &fds)) continue; #endif - if (key_fds[i].no_readfunc_retval) { // getch2 handler special-cased for now - ((void (*)(void))key_fds[i].read_func)(); - if (cmd_queue_length) - return NULL; - code = mplayer_get_key(0); - if (code < 0) - code = MP_INPUT_NOTHING; - } - else - code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd); + int code = key_fds[i].read_func.key(key_fds[i].ctx, key_fds[i].fd); if (code >= 0) { mp_cmd_t *ret = interpret_key(code, paused); if (ret) @@ -1251,19 +1219,18 @@ static mp_cmd_t *read_events(int time, int paused) key_fds[i].dead = 1; } } - autorepeat_cmd = check_autorepeat(paused); + mp_cmd_t *autorepeat_cmd = check_autorepeat(paused); if (autorepeat_cmd) return autorepeat_cmd; for (i = 0; i < num_cmd_fd; i++) { - char *cmd; - int r; #ifdef HAVE_POSIX_SELECT if (!cmd_fds[i].no_select && !FD_ISSET(cmd_fds[i].fd, &fds) && !cmd_fds[i].got_cmd) continue; #endif - r = mp_input_read_cmd(&cmd_fds[i], &cmd); + char *cmd; + int r = mp_input_read_cmd(&cmd_fds[i], &cmd); if (r >= 0) { mp_cmd_t *ret = mp_input_parse_cmd(cmd); free(cmd); @@ -1731,7 +1698,7 @@ 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); + mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close,NULL); } #endif @@ -1756,7 +1723,7 @@ 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); + mp_input_add_key_fd(-1,0,mp_input_ar_read,mp_input_ar_close, NULL); } #endif diff --git a/input/input.h b/input/input.h index e6381b3e34..4ee0376993 100644 --- a/input/input.h +++ b/input/input.h @@ -206,7 +206,7 @@ typedef struct mp_key_name { // the next key code or command. // These functions should return the key code or one of the error codes -typedef int (*mp_key_func_t)(int fd); +typedef int (*mp_key_func_t)(void *ctx, int fd); // These functions should act like read but they must use our error code (if needed ;-) typedef int (*mp_cmd_func_t)(int fd,char* dest,int size); // These are used to close the driver @@ -234,16 +234,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); +mp_input_add_key_fd(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); -int mp_input_add_event_fd(int fd, void (*read_func)(void)); - -void mp_input_rm_event_fd(int fd); - /// Get input key from its name. int mp_input_get_key_from_name(const char *name); diff --git a/input/joystick.c b/input/joystick.c index ec3720548d..02e00d207f 100644 --- a/input/joystick.c +++ b/input/joystick.c @@ -73,7 +73,7 @@ int mp_input_joystick_init(char* dev) { return fd; } -int mp_input_joystick_read(int fd) { +int mp_input_joystick_read(void *ctx, int fd) { struct js_event ev; int l=0; diff --git a/input/joystick.h b/input/joystick.h index 3a70f7cbd3..b318e9ec14 100644 --- a/input/joystick.h +++ b/input/joystick.h @@ -37,6 +37,6 @@ int mp_input_joystick_init(char* dev); -int mp_input_joystick_read(int fd); +int mp_input_joystick_read(void *ctx, int fd); #endif /* MPLAYER_JOYSTICK_H */ |