[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[334] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-11-12 09:03:40
|
Revision: 334 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=334&view=rev Author: nickols_k Date: 2012-11-12 09:03:29 +0000 (Mon, 12 Nov 2012) Log Message: ----------- use improved input2 formally: input v2.5 Modified Paths: -------------- mplayerxp/cfg-mplayerxp.h mplayerxp/fifo.c mplayerxp/fifo.h mplayerxp/input2/input.c mplayerxp/input2/input.h mplayerxp/input2/joystick.c mplayerxp/input2/joystick.h mplayerxp/input2/lirc.c mplayerxp/input2/lirc.h mplayerxp/mplayerxp.c mplayerxp/mplayerxp.h Modified: mplayerxp/cfg-mplayerxp.h =================================================================== --- mplayerxp/cfg-mplayerxp.h 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/cfg-mplayerxp.h 2012-11-12 09:03:29 UTC (rev 334) @@ -268,8 +268,6 @@ {"vc", &mp_conf.video_codec, CONF_TYPE_STRING, 0, 0, 0, "forces usage of specified video-decoder"}, /*UD*/ {"verbose", &mp_conf.verbose, CONF_TYPE_INT, CONF_RANGE|CONF_GLOBAL, 0, 100, "verbose output"}, {"v", cfg_inc_verbose, CONF_TYPE_FUNC, CONF_GLOBAL|CONF_NOSAVE, 0, 0, "verbose output (more -v means more verbosity)"}, - {"slave", &mp_conf.slave_mode, CONF_TYPE_FLAG,CONF_GLOBAL , 0, 1, "turns MPlayerXP into slave mode as a backend for other programs"}, - {"use-stdin", &mp_conf.use_stdin, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, "forces reading of keyboard codes from STDIN instead of terminal's console"}, {"msgfilter", &mp_conf.msg_filter, CONF_TYPE_INT, CONF_RANGE, 0, 0xFFFFFFFF, "specifies filter for verbosed messages"}, {"core", &xpcore_config, CONF_TYPE_SUBCONFIG, 0, 0, 0, "XP-core related options" }, Modified: mplayerxp/fifo.c =================================================================== --- mplayerxp/fifo.c 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/fifo.c 2012-11-12 09:03:29 UTC (rev 334) @@ -2,82 +2,8 @@ #include "fifo.h" #include "osdep/mplib.h" -#ifndef min -#define min(a,b) ((a)<(b)?(a):(b)) -#endif +static inline int min(int a,int b) { return (a<b)?a:b; }; -// keyboard: -int keyb_fifo_put=-1; -int keyb_fifo_get=-1; - -void __FASTCALL__ fifo_make_pipe(int* pr,int* pw){ - int temp[2]; - if(pipe(temp)!=0) MSG_ERR("Cannot make PIPE!\n"); - *pr=temp[0]; - *pw=temp[1]; -} - -static inline int __FASTCALL__ my_write(int fd,unsigned char* mem,int len){ - int total=0; - int len2; - while(len>0){ - len2=write(fd,mem+total,len); if(len2<=0) break; - total+=len2;len-=len2; - } - return total; -} - -static inline int __FASTCALL__ my_read(int fd,unsigned char* mem,int len){ - int total=0; - int len2; - while(len>0){ - len2=read(fd,mem+total,len); if(len2<=0) break; - total+=len2;len-=len2; - } - return total; -} - -static void __FASTCALL__ send_cmd(int fd,int cmd){ - int fifo_cmd=cmd; - write(fd,&fifo_cmd,4); -// fflush(control_fifo); -} - - -void mplayer_put_key(int code){ - fd_set rfds; - struct timeval tv; - - /* Watch stdin (fd 0) to see when it has input. */ - FD_ZERO(&rfds); - FD_SET(keyb_fifo_put, &rfds); - tv.tv_sec = 0; - tv.tv_usec = 0; - - //retval = select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv); - if(select(keyb_fifo_put+1, NULL, &rfds, NULL, &tv)>0){ - write(keyb_fifo_put,&code,4); - } -} - -int mplayer_get_key(void){ - fd_set rfds; - struct timeval tv; - int code=-1; - - /* Watch stdin (fd 0) to see when it has input. */ - FD_ZERO(&rfds); - FD_SET(keyb_fifo_get, &rfds); - tv.tv_sec = 0; - tv.tv_usec = 0; - - //retval = select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv); - if(select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv)>0){ - read(keyb_fifo_get,&code,4); - } - return code; -} - /* === Circular Buffer FIFO support === */ CBFifoBuffer *cb_fifo_alloc(unsigned int size) Modified: mplayerxp/fifo.h =================================================================== --- mplayerxp/fifo.h 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/fifo.h 2012-11-12 09:03:29 UTC (rev 334) @@ -11,12 +11,8 @@ #include <string.h> #include <unistd.h> -// keyboard: -extern int keyb_fifo_put; -extern int keyb_fifo_get; +// Note: this suff really is used by ao_jack only -extern void __FASTCALL__ fifo_make_pipe(int* pr,int* pw); - typedef struct CBFifoBuffer { uint8_t *buffer; uint8_t *rptr, *wptr, *end; Modified: mplayerxp/input2/input.c =================================================================== --- mplayerxp/input2/input.c 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/input2/input.c 2012-11-12 09:03:29 UTC (rev 334) @@ -1,4 +1,4 @@ -#include "../mp_config.h" +#include "mp_config.h" #include <stdlib.h> #include <string.h> @@ -54,7 +54,7 @@ #define CMD_QUEUE_SIZE 100 typedef struct mp_input_fd { - int fd; + any_t* opaque; any_t* read_func; mp_close_func_t close_func; int flags; @@ -91,8 +91,8 @@ unsigned int last_ar; int in_file_fd; + int tim; //for getch2 char key_str[12]; - int joystick_fd; }priv_t; typedef struct input_conf_s { @@ -438,19 +438,19 @@ { NULL, NULL, 0, 0, 0, 0, NULL} }; -static int mp_input_default_key_func(int fd); -static int mp_input_default_cmd_func(int fd,char* buf, int l); +static int mp_input_default_key_func(any_t* fd); +static int mp_input_default_cmd_func(any_t* fd,char* buf, int l); static char* mp_input_get_key_name(any_t*,int key); -MPXP_Rc mp_input_add_cmd_fd(any_t* handle,int fd, int sel, mp_cmd_func_t read_func, mp_close_func_t close_func) { +static MPXP_Rc mp_input_add_cmd_fd(any_t* handle,any_t* opaque, int sel, mp_cmd_func_t read_func, mp_close_func_t close_func) { priv_t* priv = (priv_t*)handle; if(priv->num_cmd_fd == MP_MAX_CMD_FD) { - MSG_ERR("Too much command fd, unable to register fd %d\n",fd); + MSG_ERR("Too much command fd, unable to register fd\n"); return MPXP_False; } memset(&priv->cmd_fds[priv->num_cmd_fd],0,sizeof(mp_input_fd_t)); - priv->cmd_fds[priv->num_cmd_fd].fd = fd; + priv->cmd_fds[priv->num_cmd_fd].opaque = opaque; priv->cmd_fds[priv->num_cmd_fd].read_func = read_func ? read_func : mp_input_default_cmd_func; priv->cmd_fds[priv->num_cmd_fd].close_func = close_func; if(!sel) priv->cmd_fds[priv->num_cmd_fd].flags = MP_FD_NO_SELECT; @@ -459,42 +459,42 @@ return MPXP_Ok; } -void mp_input_rm_cmd_fd(any_t* handle,int fd) { +static void mp_input_rm_cmd_fd(any_t* handle,any_t* fd) { priv_t* priv = (priv_t*)handle; unsigned int i; for(i = 0; i < priv->num_cmd_fd; i++) { - if(priv->cmd_fds[i].fd == fd) break; + if(priv->cmd_fds[i].opaque == fd) break; } if(i == priv->num_cmd_fd) return; - if(priv->cmd_fds[i].close_func) priv->cmd_fds[i].close_func(priv->cmd_fds[i].fd); + if(priv->cmd_fds[i].close_func) priv->cmd_fds[i].close_func(priv->cmd_fds[i].opaque); if(priv->cmd_fds[i].buffer) mp_free(priv->cmd_fds[i].buffer); - if(i + 1 < priv->num_cmd_fd) memmove(&priv->cmd_fds[i],&priv->cmd_fds[i+1],(priv->num_cmd_fd - i - 1)*sizeof(mp_input_fd_t)); + if(i + 1 < priv->num_cmd_fd) memmove(&priv->cmd_fds[i],&priv->cmd_fds[i+1],(priv->num_cmd_fd-i-1)*sizeof(mp_input_fd_t)); priv->num_cmd_fd--; } -void mp_input_rm_key_fd(any_t* handle,int fd) { +static void mp_input_rm_key_fd(any_t* handle,any_t* fd) { priv_t* priv = (priv_t*)handle; unsigned int i; for(i = 0; i < priv->num_key_fd; i++) { - if(priv->key_fds[i].fd == fd) break; + if(priv->key_fds[i].opaque == fd) break; } if(i == priv->num_key_fd) return; - if(priv->key_fds[i].close_func) priv->key_fds[i].close_func(priv->key_fds[i].fd); - if(i + 1 < priv->num_key_fd) memmove(&priv->key_fds[i],&priv->key_fds[i+1],(priv->num_key_fd - i - 1)*sizeof(mp_input_fd_t)); + if(priv->key_fds[i].close_func) priv->key_fds[i].close_func(priv->key_fds[i].opaque); + if(i + 1 < priv->num_key_fd) memmove(&priv->key_fds[i],&priv->key_fds[i+1],(priv->num_key_fd-i-1)*sizeof(mp_input_fd_t)); priv->num_key_fd--; } -MPXP_Rc mp_input_add_key_fd(any_t* handle,int fd, int sel, mp_key_func_t read_func, mp_close_func_t close_func) { +static MPXP_Rc mp_input_add_key_fd(any_t* handle,any_t* opaque, int sel, mp_key_func_t read_func, mp_close_func_t close_func) { priv_t* priv = (priv_t*)handle; if(priv->num_key_fd == MP_MAX_KEY_FD) { - MSG_ERR("Too much key fd, unable to register fd %d\n",fd); + MSG_ERR("Too much key fd, unable to register fd\n"); return MPXP_False; } memset(&priv->key_fds[priv->num_key_fd],0,sizeof(mp_input_fd_t)); - priv->key_fds[priv->num_key_fd].fd = fd; + priv->key_fds[priv->num_key_fd].opaque = opaque; priv->key_fds[priv->num_key_fd].read_func = read_func ? read_func : mp_input_default_key_func; priv->key_fds[priv->num_key_fd].close_func = close_func; if(!sel) priv->key_fds[priv->num_key_fd].flags |= MP_FD_NO_SELECT; @@ -614,15 +614,21 @@ return cmd; } -static int mp_input_default_key_func(int fd) { +static int mp_input_default_key_func(any_t* fd) { + priv_t* priv = (priv_t*)fd; int r,code=0; unsigned int l; l = 0; - while(l < sizeof(int)) { - r = read(fd,(&code)+l,sizeof(int)-l); - if(r <= 0) break; - l +=r; - } + if(priv->in_file_fd == 0) { // stdin is handled by getch2 + code = getch2(priv->tim); + if(code < 0) code = MP_INPUT_NOTHING; + } else + fcntl(priv->in_file_fd,F_SETFL,fcntl(priv->in_file_fd,F_GETFL)|O_NONBLOCK); + while(l < sizeof(int)) { + r = read(priv->in_file_fd,(&code)+l,sizeof(int)-l); + if(r <= 0) break; + l +=r; + } return code; } @@ -639,14 +645,14 @@ } // Get some data if needed/possible - while( !(mp_fd->flags & MP_FD_GOT_CMD) && !(mp_fd->flags & 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); + while( !(mp_fd->flags & MP_FD_GOT_CMD) && !(mp_fd->flags & MP_FD_EOF) && (mp_fd->size-mp_fd->pos>1)) { + int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->opaque,mp_fd->buffer+mp_fd->pos,mp_fd->size-1-mp_fd->pos); // Error ? if(r < 0) { switch(r) { case MP_INPUT_ERROR: case MP_INPUT_DEAD: - MSG_ERR("Error while reading cmd fd %d : %s\n",mp_fd->fd,strerror(errno)); + MSG_ERR("Error while reading cmd fd: %s\n",strerror(errno)); case MP_INPUT_NOTHING: return r; } // EOF ? @@ -668,7 +674,7 @@ if(!end) { // If buffer is full we must drop all until the next \n if(mp_fd->size - mp_fd->pos <= 1) { - MSG_ERR("Cmd buffer of fd %d is full : dropping content\n",mp_fd->fd); + MSG_ERR("Cmd buffer is full: dropping content\n"); mp_fd->pos = 0; mp_fd->flags |= MP_FD_DROP; } @@ -695,9 +701,11 @@ else return MP_INPUT_NOTHING; } -static int mp_input_default_cmd_func(int fd,char* buf, int l) { +static int mp_input_default_cmd_func(any_t* fd,char* buf, int l) { + priv_t* priv=(priv_t*)fd; + fcntl(priv->in_file_fd,F_SETFL,fcntl(priv->in_file_fd,F_GETFL)|O_NONBLOCK); while(1) { - int r = read(fd,buf,l); + int r = read(priv->in_file_fd,buf,l); // Error ? if(r < 0) { if(errno == EINTR) continue; @@ -740,12 +748,11 @@ return binds[j].cmd; } -static mp_cmd_t* mp_input_get_cmd_from_keys(any_t* handle,int n,int* keys, int paused) { +mp_cmd_t* mp_input_get_cmd_from_keys(any_t* handle,int n,int* keys) { priv_t* priv = (priv_t*)handle; char* cmd = NULL; mp_cmd_t* ret; - UNUSED(paused); if(priv->cmd_binds) cmd = mp_input_find_bind_for_key(priv->cmd_binds,n,keys); if(cmd == NULL) cmd = mp_input_find_bind_for_key(def_cmd_binds,n,keys); if(cmd == NULL) { @@ -771,81 +778,39 @@ static int mp_input_read_key_code(any_t* handle,int tim) { priv_t* priv = (priv_t*)handle; -#ifndef HAVE_NO_POSIX_SELECT - fd_set fds; - struct timeval tv,*time_val; -#endif - int i,n=0,max_fd = 0; - static int last_loop = 0; + int n=0; + unsigned i; if(priv->num_key_fd == 0) return MP_INPUT_NOTHING; -#ifndef HAVE_NO_POSIX_SELECT - FD_ZERO(&fds); -#endif // Remove fd marked as dead and build the fd_set // n == number of fd's to be select() checked for(i = 0; (unsigned int)i < priv->num_key_fd; i++) { if( (priv->key_fds[i].flags & MP_FD_DEAD) ) { - mp_input_rm_key_fd(priv,priv->key_fds[i].fd); + mp_input_rm_key_fd(priv,priv->key_fds[i].opaque); i--; continue; } else if(priv->key_fds[i].flags & MP_FD_NO_SELECT) continue; - if(priv->key_fds[i].fd > max_fd) max_fd = priv->key_fds[i].fd; -#ifndef HAVE_NO_POSIX_SELECT - FD_SET(priv->key_fds[i].fd,&fds); -#endif n++; } if(priv->num_key_fd == 0) return MP_INPUT_NOTHING; -#ifndef HAVE_NO_POSIX_SELECT - // if we have fd's without MP_FD_NO_SELECT flag, call select(): - if(n>0){ - if(tim >= 0 ) { - tv.tv_sec=tim/1000; - tv.tv_usec = (tim%1000)*1000; - time_val = &tv; - } else time_val = NULL; - while(1) { - if(select(max_fd+1,&fds,NULL,NULL,time_val) < 0) { - if(errno == EINTR) continue; - MSG_ERR("Select error : %s\n",strerror(errno)); - } - break; - } - } -#endif - for(i = last_loop + 1 ; i != last_loop ; i++) { + for(i = 0; i < priv->num_key_fd; i++) { int code = -1; - // This is to check all fd in turn - if((unsigned int)i >= priv->num_key_fd) { - i = -1; - last_loop++; - last_loop %= (priv->num_key_fd+1); - continue; - } -#ifndef HAVE_NO_POSIX_SELECT - // No input from this fd - if(! (priv->key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(priv->key_fds[i].fd,&fds)) - continue; -#endif - if(priv->key_fds[i].fd == 0) { // stdin is handled by getch2 - code = getch2(tim); - if(code < 0) code = MP_INPUT_NOTHING; - } else code = ((mp_key_func_t)priv->key_fds[i].read_func)(priv->key_fds[i].fd); + priv->tim = tim; + code = ((mp_key_func_t)priv->key_fds[i].read_func)(priv->key_fds[i].opaque); if(code >= 0) return code; - if(code == MP_INPUT_ERROR) MSG_ERR("Error on key input fd %d\n",priv->key_fds[i].fd); + if(code == MP_INPUT_ERROR) MSG_ERR("Error on key input fd\n"); else if(code == MP_INPUT_DEAD) { - MSG_ERR("Dead key input on fd %d\n",priv->key_fds[i].fd); - priv->key_fds[i].flags |= MP_FD_DEAD; + MSG_ERR("Dead key input on fd\n"); + mp_input_rm_key_fd(priv,priv->key_fds[i].opaque); } } return MP_INPUT_NOTHING; } -static mp_cmd_t* mp_input_read_keys(any_t*handle,int tim,int paused) { +static mp_cmd_t* mp_input_read_keys(any_t*handle,int tim) { priv_t* priv = (priv_t*)handle; int code = mp_input_read_key_code(priv,tim); unsigned int j; @@ -896,7 +861,7 @@ priv->last_key_down = 1; } // We ignore key from last combination - ret = priv->last_key_down ? mp_input_get_cmd_from_keys(priv,priv->num_key_down,priv->key_down,paused) : NULL; + ret = priv->last_key_down ? mp_input_get_cmd_from_keys(priv,priv->num_key_down,priv->key_down):NULL; // Remove the key if(j+1 < priv->num_key_down) memmove(&priv->key_down[j],&priv->key_down[j+1],(priv->num_key_down-(j+1))*sizeof(int)); priv->num_key_down--; @@ -914,7 +879,7 @@ unsigned int t = GetTimer(); // First time : wait delay if(priv->ar_state == 0 && (t - priv->last_key_down) >= libinput_conf.ar_delay*1000) { - priv->ar_cmd = mp_input_get_cmd_from_keys(priv,priv->num_key_down,priv->key_down,paused); + priv->ar_cmd = mp_input_get_cmd_from_keys(priv,priv->num_key_down,priv->key_down); if(!priv->ar_cmd) { priv->ar_state = -1; return NULL; @@ -931,68 +896,30 @@ return NULL; } -static mp_cmd_t* mp_input_read_cmds(any_t* handle,int tim) { +static mp_cmd_t* mp_input_read_cmds(any_t* handle) { priv_t* priv = (priv_t*)handle; -#ifndef HAVE_NO_POSIX_SELECT - fd_set fds; - struct timeval tv,*time_val; -#endif - int i,n = 0,max_fd = 0,got_cmd = 0; + int i,n = 0,got_cmd = 0; mp_cmd_t* ret; static int last_loop = 0; if(priv->num_cmd_fd == 0) return NULL; -#ifndef HAVE_NO_POSIX_SELECT - FD_ZERO(&fds); -#endif for(i = 0; (unsigned int)i < priv->num_cmd_fd ; i++) { - if( (priv->cmd_fds[i].flags & MP_FD_DEAD) || (priv->cmd_fds[i].flags & MP_FD_EOF) ) { - mp_input_rm_cmd_fd(priv,priv->cmd_fds[i].fd); + if(priv->cmd_fds[i].flags&MP_FD_EOF) { + mp_input_rm_cmd_fd(priv,priv->cmd_fds[i].opaque); i--; continue; } else if(priv->cmd_fds[i].flags & MP_FD_NO_SELECT) continue; if(priv->cmd_fds[i].flags & MP_FD_GOT_CMD) got_cmd = 1; - if(priv->cmd_fds[i].fd > max_fd) max_fd = priv->cmd_fds[i].fd; -#ifndef HAVE_NO_POSIX_SELECT - FD_SET(priv->cmd_fds[i].fd,&fds); -#endif n++; } if(priv->num_cmd_fd == 0) return NULL; -#ifndef HAVE_NO_POSIX_SELECT - if(tim >= 0) { - tv.tv_sec=tim/1000; - tv.tv_usec = (tim%1000)*1000; - time_val = &tv; - } else time_val = NULL; - while(n > 0) { - if((i = select(max_fd+1,&fds,NULL,NULL,time_val)) <= 0) { - if(i < 0) { - if(errno == EINTR) continue; - MSG_ERR("Select error : %s\n",strerror(errno)); - } - if(!got_cmd) return NULL; - } - break; - } -#endif - for(i = last_loop + 1; i != last_loop ; i++) { + for(i = 0; i < priv->num_cmd_fd; i++) { int r = 0; char* cmd; - if((unsigned int)i >= priv->num_cmd_fd) { - i = -1; - last_loop++; - last_loop %= (priv->num_cmd_fd+1); - continue; - } -#ifndef HAVE_NO_POSIX_SELECT - if(!(priv->cmd_fds[i].flags&MP_FD_NO_SELECT) && !FD_ISSET(priv->cmd_fds[i].fd,&fds) && !(priv->cmd_fds[i].flags & MP_FD_GOT_CMD)) - continue; -#endif r = mp_input_read_cmd(&priv->cmd_fds[i],&cmd); if(r < 0) { - if(r == MP_INPUT_ERROR) MSG_ERR("Error on cmd fd %d\n",priv->cmd_fds[i].fd); + if(r == MP_INPUT_ERROR) MSG_ERR("Error on cmd fd\n"); else if(r == MP_INPUT_DEAD) priv->cmd_fds[i].flags |= MP_FD_DEAD; continue; } @@ -1040,17 +967,13 @@ mp_cmd_filter_t* cf; int from_queue; - while(1) { - from_queue = 1; - ret = mp_input_get_queued_cmd(priv,peek_only); - if(ret) break; + from_queue = 1; + ret = mp_input_get_queued_cmd(priv,peek_only); + if(!ret) { from_queue = 0; - ret = mp_input_read_keys(priv,tim,paused); - if(ret) break; - ret = mp_input_read_cmds(priv,tim); - break; + ret = mp_input_read_keys(priv,tim); + if(!ret) ret = mp_input_read_cmds(priv); } - if(!ret) return NULL; for(cf = priv->cmd_filters ; cf ; cf = cf->next) { @@ -1341,16 +1264,17 @@ } #ifdef HAVE_JOYSTICK if(libinput_conf.use_joystick) { - priv->joystick_fd = mp_input_joystick_init(libinput_conf.js_dev); - if(priv->joystick_fd<=0) MSG_ERR("Can't init input joystick with using: %s\n",libinput_conf.js_dev); - else mp_input_add_key_fd(priv,priv->joystick_fd,1,mp_input_joystick_read,(mp_close_func_t)close); + any_t* joystick_fd; + joystick_fd = mp_input_joystick_open(libinput_conf.js_dev); + if(!joystick_fd) MSG_ERR("Can't init input joystick with using: %s\n",libinput_conf.js_dev); + else mp_input_add_key_fd(priv,joystick_fd,1,mp_input_joystick_read,(mp_close_func_t)mp_input_joystick_close); } #endif #ifdef HAVE_LIRC if(libinput_conf.use_lirc) { - int fd = mp_input_lirc_init(); - if(fd > 0) mp_input_add_cmd_fd(fd,0,mp_input_lirc_read,mp_input_lirc_close); + any_t* lirc_fd = mp_input_lirc_init(); + if(fd > 0) mp_input_add_cmd_fd(priv,lirc_fd,0,mp_input_lirc_read_cmd,mp_input_lirc_close); } #endif @@ -1364,10 +1288,14 @@ struct stat st; if(stat(libinput_conf.in_file,&st)) MSG_ERR("Can't stat %s: %s\n",libinput_conf.in_file,strerror(errno)); else { - priv->in_file_fd = open(libinput_conf.in_file,S_ISFIFO(st.st_mode) ? O_RDWR : O_RDONLY); - if(priv->in_file_fd >= 0) mp_input_add_cmd_fd(priv,priv->in_file_fd,1,NULL,(mp_close_func_t)close); + priv->in_file_fd = open(libinput_conf.in_file,(S_ISFIFO(st.st_mode)?O_RDWR:O_RDONLY)|O_NONBLOCK); + if(priv->in_file_fd >= 0) mp_input_add_cmd_fd(priv,priv,1,NULL,(mp_close_func_t)close); else MSG_ERR("Can't open %s: %s\n",libinput_conf.in_file,strerror(errno)); } + } else { + priv->in_file_fd = 0; + getch2_enable(); // prepare stdin for hotkeys... + mp_input_add_cmd_fd(priv,priv,1,NULL,(mp_close_func_t)close); } } @@ -1376,11 +1304,11 @@ unsigned int i; for(i=0; i < priv->num_key_fd; i++) { - if(priv->key_fds[i].close_func) priv->key_fds[i].close_func(priv->key_fds[i].fd); + if(priv->key_fds[i].close_func) priv->key_fds[i].close_func(priv->key_fds[i].opaque); } for(i=0; i < priv->num_cmd_fd; i++) { - if(priv->cmd_fds[i].close_func) priv->cmd_fds[i].close_func(priv->cmd_fds[i].fd); + if(priv->cmd_fds[i].close_func) priv->cmd_fds[i].close_func(priv->cmd_fds[i].opaque); } if(priv->cmd_binds) { @@ -1391,6 +1319,7 @@ mp_free(priv->cmd_binds); priv->cmd_binds=NULL; } + if(priv->in_file_fd==0) getch2_disable(); } any_t* mp_input_open(void) { Modified: mplayerxp/input2/input.h =================================================================== --- mplayerxp/input2/input.h 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/input2/input.h 2012-11-12 09:03:29 UTC (rev 334) @@ -136,32 +136,14 @@ // These typedefs are for the drivers. They are the functions used to retrive // the next key code or command. -typedef int (*mp_key_func_t)(int fd); // These functions should return the key code or one of the error code -typedef int (*mp_cmd_func_t)(int fd,char* dest,int size); // These functions should act like read but they must use our error code (if needed ;-) -typedef void (*mp_close_func_t)(int fd); // These are used to close the driver +typedef int (*mp_key_func_t)(any_t* ctx); // These functions should return the key code or one of the error code +typedef int (*mp_cmd_func_t)(any_t* ctx,char* dest,int size); // These functions should act like read but they must use our error code (if needed ;-) +typedef void (*mp_close_func_t)(any_t* ctx); // These are used to close the driver typedef int (*mp_input_cmd_filter)(mp_cmd_t* cmd, int paused, any_t* ctx); // Should return 1 if the command was processed extern void (*mp_input_key_cb)(int code); // Set this to grab all incoming key code -// This function add a new key driver. -// The first arg is a file descriptor (use a negative value if you don't use any fd) -// The second arg tell if we use select on the fd to know if something is avaible. -// The third arg is optional. If null a default function wich read an int from the -// fd will be used. -// The last arg can be NULL if nothing is needed to close the driver. The close -// function can be used -extern MPXP_Rc mp_input_add_cmd_fd(any_t* handle,int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func); - -// This remove a cmd driver, you usally don't need to use it -extern void mp_input_rm_cmd_fd(any_t* handle,int fd); - -// The args are the sames as for the keys drivers. If you don't use any valid fd you MUST -// give a read_func. -extern MPXP_Rc mp_input_add_key_fd(any_t*handle,int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func); - -// As for the cmd one you usally don't need this function -extern void mp_input_rm_key_fd(any_t* handle,int fd); - +extern mp_cmd_t* mp_input_get_cmd_from_keys(any_t* handle,int n,int* keys); // This function can be used to reput a command in the system. It's used by libmpdemux // when it perform a blocking operation to resend the command it received to the main // loop. Modified: mplayerxp/input2/joystick.c =================================================================== --- mplayerxp/input2/joystick.c 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/input2/joystick.c 2012-11-12 09:03:29 UTC (rev 334) @@ -1,10 +1,9 @@ +#include "mp_config.h" -#include "../mp_config.h" - #ifdef HAVE_JOYSTICK - #include "joystick.h" #include "input.h" +#include "osdep/mplib.h" #include <stdlib.h> #include <stdio.h> @@ -23,32 +22,34 @@ #define JS_DEV "/dev/input/js0" #endif -#ifdef TARGET_LINUX - #include <linux/joystick.h> -int axis[10]; -int btns = 0; +typedef struct priv_s { + int axis[10]; + int btns; + int fd; +}priv_t; #include "in_msg.h" -int mp_input_joystick_init(const char* dev) { - int fd,l=0; +any_t* mp_input_joystick_open(const char* dev) { + int l=0; int inited = 0; struct js_event ev; + priv_t* priv=mp_mallocz(sizeof(priv_t)); MSG_INFO("Opening joystick device %s\n",dev ? dev : JS_DEV); - fd = open( dev ? dev : JS_DEV , O_RDONLY | O_NONBLOCK ); - if(fd < 0) { + if((priv->fd=open(dev?dev:JS_DEV,O_RDONLY|O_NONBLOCK))<0) { MSG_ERR("Can't open joystick device %s : %s\n",dev ? dev : JS_DEV,strerror(errno)); - return -1; + mp_free(priv); + return NULL; } while(! inited) { l = 0; while((unsigned int)l < sizeof(struct js_event)) { - int r = read(fd,((char*)&ev)+l,sizeof(struct js_event)-l); + int r = read(priv->fd,((char*)&ev)+l,sizeof(struct js_event)-l); if(r < 0) { if(errno == EINTR) continue; else if(errno == EAGAIN) { @@ -56,8 +57,9 @@ break; } MSG_ERR("Error while reading joystick device : %s\n",strerror(errno)); - close(fd); - return -1; + close(priv->fd); + mp_free(priv); + return NULL; } l += r; } @@ -66,18 +68,25 @@ break; } ev.type &= ~JS_EVENT_INIT; - if(ev.type == JS_EVENT_BUTTON) btns |= (ev.value << ev.number); - if(ev.type == JS_EVENT_AXIS) axis[ev.number] = ev.value; + if(ev.type == JS_EVENT_BUTTON) priv->btns |= (ev.value << ev.number); + if(ev.type == JS_EVENT_AXIS) priv->axis[ev.number] = ev.value; } - return fd; + return priv; } -int mp_input_joystick_read(int fd) { +void mp_input_joystick_close(any_t* ctx) { + priv_t* priv = (priv_t*)ctx; + close(priv->fd); + mp_free(priv); +} + +int mp_input_joystick_read(any_t* ctx) { + priv_t* priv = (priv_t*)ctx; struct js_event ev; int l=0; while((unsigned int)l < sizeof(struct js_event)) { - int r = read(fd,&ev+l,sizeof(struct js_event)-l); + int r = read(priv->fd,&ev+l,sizeof(struct js_event)-l); if(r <= 0) { if(errno == EINTR) continue; else if(errno == EAGAIN) return MP_INPUT_NOTHING; @@ -97,34 +106,34 @@ MSG_WARN("Joystick : warning init event, we have lost sync with driver\n"); ev.type &= ~JS_EVENT_INIT; if(ev.type == JS_EVENT_BUTTON) { - int s = (btns >> ev.number) & 1; + int s = (priv->btns >> ev.number) & 1; if(s == ev.value) // State is the same : ignore return MP_INPUT_NOTHING; } if(ev.type == JS_EVENT_AXIS) { - if( ( axis[ev.number] == 1 && ev.value > JOY_AXIS_DELTA) || - (axis[ev.number] == -1 && ev.value < -JOY_AXIS_DELTA) || - (axis[ev.number] == 0 && ev.value >= -JOY_AXIS_DELTA && ev.value <= JOY_AXIS_DELTA)) + if( (priv->axis[ev.number] == 1 && ev.value > JOY_AXIS_DELTA) || + (priv->axis[ev.number] == -1 && ev.value < -JOY_AXIS_DELTA) || + (priv->axis[ev.number] == 0 && ev.value >= -JOY_AXIS_DELTA && ev.value <= JOY_AXIS_DELTA)) // State is the same : ignore return MP_INPUT_NOTHING; } } if(ev.type & JS_EVENT_BUTTON) { - btns &= ~(1 << ev.number); - btns |= (ev.value << ev.number); + priv->btns &= ~(1 << ev.number); + priv->btns |= (ev.value << ev.number); if(ev.value == 1) return ((JOY_BTN0+ev.number) | MP_KEY_DOWN); else return (JOY_BTN0+ev.number); } else if(ev.type & JS_EVENT_AXIS) { - if(ev.value < -JOY_AXIS_DELTA && axis[ev.number] != -1) { - axis[ev.number] = -1; + if(ev.value < -JOY_AXIS_DELTA && priv->axis[ev.number] != -1) { + priv->axis[ev.number] = -1; return (JOY_AXIS0_MINUS+(2*ev.number)) | MP_KEY_DOWN; - } else if(ev.value > JOY_AXIS_DELTA && axis[ev.number] != 1) { - axis[ev.number] = 1; + } else if(ev.value > JOY_AXIS_DELTA && priv->axis[ev.number] != 1) { + priv->axis[ev.number] = 1; return (JOY_AXIS0_PLUS+(2*ev.number)) | MP_KEY_DOWN; - } else if(ev.value <= JOY_AXIS_DELTA && ev.value >= -JOY_AXIS_DELTA && axis[ev.number] != 0) { - int r = axis[ev.number] == 1 ? JOY_AXIS0_PLUS+(2*ev.number) : JOY_AXIS0_MINUS+(2*ev.number); - axis[ev.number] = 0; + } else if(ev.value <= JOY_AXIS_DELTA && ev.value >= -JOY_AXIS_DELTA && priv->axis[ev.number] != 0) { + int r = priv->axis[ev.number] == 1 ? JOY_AXIS0_PLUS+(2*ev.number) : JOY_AXIS0_MINUS+(2*ev.number); + priv->axis[ev.number] = 0; return r; } else return MP_INPUT_NOTHING; @@ -134,13 +143,8 @@ } return MP_INPUT_NOTHING; } - #else - -// dummy function - -int mp_input_joystick_init(const char* dev) { return -1; } -int mp_input_joystick_read(int fd) { return MP_INPUT_NOTHING; } - +any_t* mp_input_joystick_open(const char* dev) { UNUNSED(dev); return NULL; } +void mp_input_joystick_close(any_t* ctx) { UNUSED(ctx); } +int mp_input_joystick_read(any_t* ctx) { UNUSED(ctx); return MP_INPUT_NOTHING; } #endif -#endif Modified: mplayerxp/input2/joystick.h =================================================================== --- mplayerxp/input2/joystick.h 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/input2/joystick.h 2012-11-12 09:03:29 UTC (rev 334) @@ -38,6 +38,7 @@ JOY_BTN9 =(JOY_BTN_BASE+9) }; -extern int mp_input_joystick_init(const char* dev); -extern int mp_input_joystick_read(int fd); +extern any_t* mp_input_joystick_open(const char* dev); +extern void mp_input_joystick_close(any_t* ctx); +extern int mp_input_joystick_read(any_t* ctx); #endif Modified: mplayerxp/input2/lirc.c =================================================================== --- mplayerxp/input2/lirc.c 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/input2/lirc.c 2012-11-12 09:03:29 UTC (rev 334) @@ -19,47 +19,53 @@ static struct lirc_config *lirc_config; char *lirc_configfile; -static char* cmd_buf = NULL; +typedef struct priv_s { + int lirc_sock; + char* cmd_buf; +}priv_t; -int mp_input_lirc_init(void) { - int lirc_sock; +any_t* mp_input_lirc_init(void) { + priv_t* priv=mp_mallocz(sizeof(priv_t)); MSG_INFO(MSGTR_SettingUpLIRC); - if((lirc_sock=lirc_init("mplayer",1))==-1){ + if((priv->lirc_sock=lirc_init("mplayer",1))==-1){ MSG_ERR(MSGTR_LIRCopenfailed MSGTR_LIRCdisabled); - return -1; + mo_free(priv); + return NULL; } if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ MSG_ERR(MSGTR_LIRCcfgerr MSGTR_LIRCdisabled, lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); lirc_deinit(); - return -1; + mp_free(priv); + return NULL; } - return lirc_sock; + return priv; } -int mp_input_lirc_read(int fd,char* dest, int s) { +int mp_input_lirc_read(any_t* ctx,char* dest, int s) { + priv_t* priv = (priv_t*)ctx; fd_set fds; struct timeval tv; int r,cl = 0; char *code = NULL,*c = NULL; // We have something in the buffer return it - if(cmd_buf != NULL) { - int l = strlen(cmd_buf), w = l > s ? s : l; - memcpy(dest,cmd_buf,w); + if(priv->cmd_buf != NULL) { + int l = strlen(priv->cmd_buf), w = l > s ? s : l; + memcpy(dest,priv->cmd_buf,w); l -= w; - if(l > 0) memmove(cmd_buf,&cmd_buf[w],l+1); + if(l > 0) memmove(priv->cmd_buf,&cmd_buf[w],l+1); else { - mp_free(cmd_buf); - cmd_buf = NULL; + mp_free(priv->cmd_buf); + priv->cmd_buf = NULL; } return w; } // Nothing in the buffer, pool the lirc fd FD_ZERO(&fds); - FD_SET(fd,&fds); + FD_SET(priv->lirc_sock,&fds); memset(&tv,0,sizeof(tv)); while((r = select(fd+1,&fds,NULL,NULL,&tv)) <= 0) { if(r < 0) { @@ -81,28 +87,30 @@ while((r = lirc_code2char(lirc_config,code,&c))==0 && c!=NULL) { int l = strlen(c); if(l <= 0) continue; - cmd_buf = mp_realloc(cmd_buf,cl+l+2); - memcpy(&cmd_buf[cl],c,l); + priv->cmd_buf = mp_realloc(priv->cmd_buf,cl+l+2); + memcpy(&priv->cmd_buf[cl],c,l); cl += l+1; - cmd_buf[cl-1] = '\n'; - cmd_buf[cl] = '\0'; + priv->cmd_buf[cl-1] = '\n'; + priv->cmd_buf[cl] = '\0'; } mp_free(code); if(r < 0) return MP_INPUT_DEAD; - else if(cmd_buf) // return the first command in the buffer - return mp_input_lirc_read(fd,dest,s); + else if(priv->cmd_buf) // return the first command in the buffer + return mp_input_lirc_read(priv->lirc_sock,dest,s); else return MP_INPUT_NOTHING; } -void mp_input_lirc_close(int fd) { - if(cmd_buf) { - mp_free(cmd_buf); - cmd_buf = NULL; +void mp_input_lirc_close(any_t* ctx) { + priv_t* priv = (priv_t*)ctx; + if(priv->cmd_buf) { + mp_free(priv->cmd_buf); + priv->cmd_buf = NULL; } lirc_freeconfig(lirc_config); lirc_deinit(); + mp_free(priv); } #endif Modified: mplayerxp/input2/lirc.h =================================================================== --- mplayerxp/input2/lirc.h 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/input2/lirc.h 2012-11-12 09:03:29 UTC (rev 334) @@ -1,7 +1,7 @@ #ifndef __LIRC_H_INCLUDED #define __LIRC_H_INCLUDED 1 -extern int mp_input_lirc_init(void); -extern int mp_input_lirc_read(int fd,char* dest, int s); -extern void mp_input_lirc_close(int fd); +extern any_t* mp_input_lirc_open(void); +extern int mp_input_lirc_read_cmd(any_t* ctx,char* dest, int s); +extern void mp_input_lirc_close(any_t* ctx); #endif Modified: mplayerxp/mplayerxp.c =================================================================== --- mplayerxp/mplayerxp.c 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/mplayerxp.c 2012-11-12 09:03:29 UTC (rev 334) @@ -108,7 +108,7 @@ #define INITED_VO 0x00000001 #define INITED_AO 0x00000002 -#define INITED_GETCH2 0x00000004 +#define INITED_RESERVED 0x00000004 #define INITED_LIRC 0x00000008 #define INITED_SPUDEC 0x00000010 #define INITED_STREAM 0x00000020 @@ -311,13 +311,6 @@ ao_data=NULL; } - if(mask&INITED_GETCH2){ - priv->inited_flags&=~INITED_GETCH2; - MP_UNIT("uninit_getch2"); - // restore terminal: - getch2_disable(); - } - if(mask&INITED_DEMUXER){ priv->inited_flags&=~INITED_DEMUXER; MP_UNIT("free_priv->demuxer"); @@ -825,19 +818,20 @@ #ifdef HAVE_TERMCAP load_termcap(NULL); // load key-codes #endif - fifo_make_pipe(&keyb_fifo_get,&keyb_fifo_put); /* Init input system */ MP_UNIT("init_input"); priv->libinput=mp_input_open(); - if(keyb_fifo_get > 0) - mp_input_add_key_fd(priv->libinput,keyb_fifo_get,1,NULL,NULL); - if(mp_conf.slave_mode) - mp_input_add_cmd_fd(priv->libinput,0,1,NULL,NULL); - else if(!mp_conf.use_stdin) - mp_input_add_key_fd(priv->libinput,0,1,NULL,NULL); priv->inited_flags|=INITED_INPUT; } +void mplayer_put_key(int code){ + priv_t*priv=mp_data->priv; + mp_cmd_t* cmd; + cmd=mp_input_get_cmd_from_keys(priv->libinput,1,&code); + mp_input_queue_cmd(priv->libinput,cmd); +} + + static void mpxp_init_osd(void) { // check font #ifdef USE_OSD @@ -1742,13 +1736,6 @@ // ******************* Now, let's see the per-file stuff ******************** play_next_file: - // We must enable getch2 here to be able to interrupt network connection - // or cache filling - if(!mp_conf.use_stdin && !mp_conf.slave_mode){ - getch2_enable(); // prepare stdin for hotkeys... - priv->inited_flags|=INITED_GETCH2; - } - ao_subdevice=mpxp_init_output_subsystems(); if(filename) MSG_OK(MSGTR_Playing, filename); @@ -2019,7 +2006,6 @@ eof |= xp_core->audio->eof; /*========================== UPDATE TIMERS ============================*/ MP_UNIT("Update timers"); - if(sh_video && input_state.need_repaint) goto repaint; if(sh_audio) eof = xp_core->audio->eof; if(sh_video) eof|=dae_played_eof(xp_core->video); if(!sh_video) { @@ -2027,11 +2013,9 @@ else mpxp_print_audio_status(); } usleep(250000); -//read_input: if(sh_video) vo_check_events(vo_data); -repaint: #ifdef USE_OSD - if((mpxp_paint_osd(&osd.visible,&in_pause))!=0) goto repaint; + while((mpxp_paint_osd(&osd.visible,&in_pause))!=0); #endif //================= Keyboard events, SEEKing ==================== Modified: mplayerxp/mplayerxp.h =================================================================== --- mplayerxp/mplayerxp.h 2012-11-11 18:04:17 UTC (rev 333) +++ mplayerxp/mplayerxp.h 2012-11-12 09:03:29 UTC (rev 334) @@ -9,8 +9,6 @@ int has_video; int has_audio; int has_dvdsub; - int use_stdin; - int slave_mode; uint32_t msg_filter; int test_av; int malloc_debug; @@ -123,5 +121,4 @@ extern void __exit_sighandler(void); extern void mplayer_put_key(int code); -extern int mplayer_get_key(void); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |