From d34041569e71fc9bd772354e94dc9d16061072a5 Mon Sep 17 00:00:00 2001 From: arpi_esp Date: Sat, 24 Feb 2001 20:28:24 +0000 Subject: Initial revision git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2 b3059339-0415-0410-9bf9-f77b7e298cf2 --- lirc_mp.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 lirc_mp.c (limited to 'lirc_mp.c') diff --git a/lirc_mp.c b/lirc_mp.c new file mode 100644 index 0000000000..7ab91c06cd --- /dev/null +++ b/lirc_mp.c @@ -0,0 +1,143 @@ +/* + + lirc support for MPLayer (see www.lirc.org) + + v0.1 + + written 15/2/2001 by Andreas Ackermann (acki@acki-netz.de) + + file comes without warranty and all + +*/ + +// hack, will be remove later when ./configure fixed... +#include "config.h" +#ifdef HAVE_LIRC + +// start of LIRC support + +#include +#include +#include +#include +#include +#include +#include "linux/keycodes.h" + +// global stuff ---------------------------------------------------- + +static struct lirc_config *lirc_config; +static int lirc_is_setup = 0; + +// setup routine --------------------------------------------------- + +void lirc_mp_setup(void){ + + int lirc_flags; + int lirc_sock; + + printf("Setting up lirc support...\n"); + if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){ + printf("Failed opening lirc support!\n"); + printf("You won't be able to use your remote control\n"); + return; + } + + fcntl(lirc_sock,F_SETOWN,getpid()); + lirc_flags=fcntl(lirc_sock,F_GETFL,0); + if(lirc_flags!=-1) + { + fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK); + }else{ + lirc_deinit(); + printf("Something's wrong with the lirc socket: %s\n", + strerror(errno)); + printf("You won't be able to use your remote control\n"); + return; + } + + + if(lirc_readconfig( NULL,&lirc_config,NULL )!=0 ){ + printf("Failed to read standard config (~/.lircrc)!\n" ); + printf("You won't be able to use your remote control\n"); + lirc_deinit(); + return; + } + printf("LIRC init was successful.\n"); + lirc_is_setup = 1; +} + +// cleanup routine ------------------------------------------- + +void lirc_mp_cleanup(void){ + if(lirc_is_setup != 0){ + printf("Cleaning up lirc stuff.\n"); + lirc_mp_getinput(NULL); + lirc_freeconfig(lirc_config); + lirc_deinit(); + lirc_is_setup = 0; + } +} + +// get some events ------------------------------------------- + + +struct lirc_cmd { + unsigned char *lc_lirccmd; + int mplayer_cmd; +}; + +int lirc_mp_getinput(){ + + static struct lirc_cmd lirc_cmd[] = { + {"QUIT", KEY_ESC}, + {"FWD" , KEY_RIGHT}, + {"FFWD" , KEY_UP}, + {"RWND" , KEY_LEFT}, + {"FRWND" , KEY_DOWN}, + {"PAUSE", 'p'} + }; + + char *code; + char *c; + int ret; + int i; + int retval = 0; + + if( lirc_is_setup == 0)return 0; + + if(lirc_config == NULL ){ + // do some cleanupstuff like freeing memory or the like + // (if we ever should do it the right way and loop over all + // all strings delivered by lirc_code2char() ) + }else{ + + if(lirc_nextcode(&code)==0){ + if(code!=NULL){ + // this should be a while loop + // but we would have to introduce state since we need to keep + // code + if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){ + fprintf(stderr, "LIRC: Got string \"%s\"",c); + for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){ + if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){ + retval = lirc_cmd[i].mplayer_cmd; + break; + } + + } + } + free(code); + if(ret==-1){ + printf("LIRC: lirc_code2char() returned an error!\n"); + } + } + } + } + return retval; +} + +// end lirc support + +#endif // HAVE_LIRC + -- cgit v1.2.3