diff options
-rw-r--r-- | input/ar.c | 4 | ||||
-rw-r--r-- | input/ar.h | 2 | ||||
-rw-r--r-- | input/input.c | 51 | ||||
-rw-r--r-- | input/input.h | 8 | ||||
-rw-r--r-- | input/joystick.c | 2 | ||||
-rw-r--r-- | input/joystick.h | 2 | ||||
-rw-r--r-- | libvo/vo_xv.c | 11 | ||||
-rw-r--r-- | mp_fifo.c | 3 | ||||
-rw-r--r-- | mp_fifo.h | 2 | ||||
-rw-r--r-- | mplayer.c | 7 |
10 files changed, 29 insertions, 63 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 5d11f71ed4..e539358a33 100644 --- a/input/input.c +++ b/input/input.c @@ -512,7 +512,6 @@ typedef struct mp_input_fd { 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; @@ -669,7 +668,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; @@ -683,41 +684,14 @@ mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t .fd = fd, .read_func = read_func, .close_func = close_func, - .no_select = !select - }; - num_key_fd++; - - return 1; -} - -int -mp_input_add_event_fd(int fd, void (*read_func)(void *ctx), void *ctx) -{ - 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; - } - - key_fds[num_key_fd] = (struct mp_input_fd){ - .fd = fd, - .read_func = read_func, + .no_select = !select, .ctx = ctx, - .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; @@ -1226,17 +1200,8 @@ static mp_cmd_t *read_events(int time, int paused) continue; #endif - int code; - if (key_fds[i].no_readfunc_retval) { // getch2 handler special-cased for now - ((void (*)(void *))key_fds[i].read_func)(key_fds[i].ctx); - 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 = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].ctx, + key_fds[i].fd); if (code >= 0) { mp_cmd_t *ret = interpret_key(code, paused); if (ret) @@ -1730,7 +1695,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 @@ -1755,7 +1720,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 27c1bdb83f..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 *ctx), void *ctx); - -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 */ diff --git a/libvo/vo_xv.c b/libvo/vo_xv.c index 041ae6a275..885bd0f7f1 100644 --- a/libvo/vo_xv.c +++ b/libvo/vo_xv.c @@ -44,6 +44,7 @@ Buffer allocation: #include "subopt-helper.h" #include "input/input.h" +#include "mp_fifo.h" #ifdef HAVE_NEW_GUI #include "gui/interface.h" @@ -710,14 +711,15 @@ static void uninit(struct vo *vo) vo_vm_close(vo); #endif if (ctx->event_fd_registered) - mp_input_rm_event_fd(ConnectionNumber(vo->x11->display)); + mp_input_rm_key_fd(ConnectionNumber(vo->x11->display)); // uninit() shouldn't get called unless initialization went past vo_init() vo_x11_uninit(vo); } -static void x11_fd_callback(void *ctx) +static int x11_fd_callback(void *ctx, int fd) { - return check_events(ctx); + check_events(ctx); + return mplayer_get_key(NULL, 0); } static int preinit(struct vo *vo, const char *arg) @@ -841,7 +843,8 @@ static int preinit(struct vo *vo, const char *arg) ctx->fo = XvListImageFormats(x11->display, x11->xv_port, (int *) &ctx->formats); - mp_input_add_event_fd(ConnectionNumber(x11->display), x11_fd_callback, vo); + mp_input_add_key_fd(ConnectionNumber(x11->display), 1, x11_fd_callback, + NULL, vo); ctx->event_fd_registered = 1; return 0; @@ -23,7 +23,8 @@ static void mplayer_put_key_internal(int code){ key_fifo_write=(key_fifo_write+1)%key_fifo_size; } -int mplayer_get_key(int fd){ +int mplayer_get_key(void *ctx, int fd) +{ int key; // printf("mplayer_get_key(%d)\n",fd); if (key_fifo_data == NULL) @@ -1,7 +1,7 @@ #ifndef MPLAYER_MP_FIFO_H #define MPLAYER_MP_FIFO_H -int mplayer_get_key(int fd); +int mplayer_get_key(void *ctx, int fd); void mplayer_put_key(int code); #endif /* MPLAYER_MP_FIFO_H */ @@ -2534,9 +2534,10 @@ static int seek(MPContext *mpctx, double amount, int style) } -static void read_keys(void *ctx) +static int read_keys(void *ctx, int fd) { getch2(); + return mplayer_get_key(NULL, 0); } @@ -2874,11 +2875,11 @@ if(!codecs_file || !parse_codec_cfg(codecs_file)){ // Init input system current_module = "init_input"; mp_input_init(use_gui); - mp_input_add_key_fd(-1,0,mplayer_get_key,NULL); + mp_input_add_key_fd(-1,0,mplayer_get_key,NULL, NULL); if(slave_mode) mp_input_add_cmd_fd(0,USE_SELECT,MP_INPUT_SLAVE_CMD_FUNC,NULL); else if(!noconsolecontrols) - mp_input_add_event_fd(0, read_keys, NULL); + mp_input_add_key_fd(0, 1, read_keys, NULL, NULL); // Set the libstream interrupt callback stream_set_interrupt_callback(mp_input_check_interrupt); |