From 88aca1ef25806c743f6ab95d3eed81ffc032f08d Mon Sep 17 00:00:00 2001 From: reimar Date: Tue, 27 Jan 2009 19:06:50 +0000 Subject: Do not use select n lirc code, instead set the fd non-blocking. select can not work because lirc_nextcode buffers data internally, causing events to be delayed until the next keypress in some cases. Patch by Dennis Vshivkov [jaimor (at) orcon net nz] git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28380 b3059339-0415-0410-9bf9-f77b7e298cf2 --- input/lirc.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'input') diff --git a/input/lirc.c b/input/lirc.c index 4012d5b340..7b9f675c04 100644 --- a/input/lirc.c +++ b/input/lirc.c @@ -20,11 +20,10 @@ #include #include +#include #include #include #include -#include -#include #include #include "mp_msg.h" @@ -39,6 +38,7 @@ static char* cmd_buf = NULL; int mp_input_lirc_init(void) { int lirc_sock; + int mode; mp_msg(MSGT_LIRC,MSGL_V,MSGTR_SettingUpLIRC); if((lirc_sock=lirc_init("mplayer",1))==-1){ @@ -53,12 +53,18 @@ mp_input_lirc_init(void) { return -1; } + mode = fcntl(lirc_sock, F_GETFL); + if (mode < 0 || fcntl(lirc_sock, F_SETFL, mode | O_NONBLOCK) < 0) { + mp_msg(MSGT_LIRC, MSGL_ERR, "setting non-blocking mode failed: %s\n", + strerror(errno)); + lirc_deinit(); + return -1; + } + return lirc_sock; } int mp_input_lirc_read(int fd,char* dest, int s) { - fd_set fds; - struct timeval tv; int r,cl = 0; char *code = NULL,*c = NULL; @@ -77,20 +83,6 @@ int mp_input_lirc_read(int fd,char* dest, int s) { } // Nothing in the buffer, poll the lirc fd - FD_ZERO(&fds); - FD_SET(fd,&fds); - memset(&tv,0,sizeof(tv)); - while((r = select(fd+1,&fds,NULL,NULL,&tv)) <= 0) { - if(r < 0) { - if(errno == EINTR) - continue; - mp_msg(MSGT_INPUT,MSGL_ERR,"Select error : %s\n",strerror(errno)); - return MP_INPUT_ERROR; - } else - return MP_INPUT_NOTHING; - } - - // There's something to read if(lirc_nextcode(&code) != 0) { mp_msg(MSGT_INPUT,MSGL_ERR,"Lirc error :(\n"); return MP_INPUT_DEAD; -- cgit v1.2.3 From 3de8ddabc73aa9f96def1809113eb79efcec17e4 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 30 Jan 2009 15:38:54 +0000 Subject: Fix an MSGT_INPUT to MSGT_LIRC in lirc.c git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28389 b3059339-0415-0410-9bf9-f77b7e298cf2 --- input/lirc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'input') diff --git a/input/lirc.c b/input/lirc.c index 7b9f675c04..17b7364e9e 100644 --- a/input/lirc.c +++ b/input/lirc.c @@ -84,7 +84,7 @@ int mp_input_lirc_read(int fd,char* dest, int s) { // Nothing in the buffer, poll the lirc fd if(lirc_nextcode(&code) != 0) { - mp_msg(MSGT_INPUT,MSGL_ERR,"Lirc error :(\n"); + mp_msg(MSGT_LIRC,MSGL_ERR,"Lirc error :(\n"); return MP_INPUT_DEAD; } -- cgit v1.2.3 From 57ff94b5cdf869298672728b3c5ed8932202ce98 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 30 Jan 2009 15:41:45 +0000 Subject: Move setting of O_NONBLOCK before lirc_readconfig, this avoids a memleak due to not freeing the lirc config on error. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28390 b3059339-0415-0410-9bf9-f77b7e298cf2 --- input/lirc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'input') diff --git a/input/lirc.c b/input/lirc.c index 17b7364e9e..4e60f01182 100644 --- a/input/lirc.c +++ b/input/lirc.c @@ -46,13 +46,6 @@ mp_input_lirc_init(void) { return -1; } - if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ - mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCcfgerr, - lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); - lirc_deinit(); - return -1; - } - mode = fcntl(lirc_sock, F_GETFL); if (mode < 0 || fcntl(lirc_sock, F_SETFL, mode | O_NONBLOCK) < 0) { mp_msg(MSGT_LIRC, MSGL_ERR, "setting non-blocking mode failed: %s\n", @@ -61,6 +54,13 @@ mp_input_lirc_init(void) { return -1; } + if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ + mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCcfgerr, + lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); + lirc_deinit(); + return -1; + } + return lirc_sock; } -- cgit v1.2.3