2001-02-24 20:28:24 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
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"
|
2001-09-27 17:03:39 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#ifdef HAVE_LIRC
|
|
|
|
|
2001-09-27 17:03:39 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
// start of LIRC support
|
|
|
|
|
|
|
|
#include <lirc/lirc_client.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include "linux/keycodes.h"
|
|
|
|
|
|
|
|
// global stuff ----------------------------------------------------
|
|
|
|
|
|
|
|
static struct lirc_config *lirc_config;
|
|
|
|
static int lirc_is_setup = 0;
|
2001-06-17 20:38:02 +00:00
|
|
|
char *lirc_configfile = NULL;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
// setup routine ---------------------------------------------------
|
|
|
|
|
|
|
|
void lirc_mp_setup(void){
|
|
|
|
|
|
|
|
int lirc_flags;
|
|
|
|
int lirc_sock;
|
|
|
|
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_LIRC,MSGL_INFO,MSGTR_SettingUpLIRC);
|
2001-02-24 20:28:24 +00:00
|
|
|
if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCopenfailed MSGTR_LIRCdisabled);
|
2001-02-24 20:28:24 +00:00
|
|
|
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();
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCsocketerr MSGTR_LIRCdisabled,strerror(errno));
|
2001-02-24 20:28:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-17 20:38:02 +00:00
|
|
|
if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCcfgerr MSGTR_LIRCdisabled,
|
2001-06-17 20:38:02 +00:00
|
|
|
lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile);
|
2001-02-24 20:28:24 +00:00
|
|
|
lirc_deinit();
|
|
|
|
return;
|
|
|
|
}
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_LIRC,MSGL_V,"LIRC init was successful.\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
lirc_is_setup = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup routine -------------------------------------------
|
|
|
|
|
|
|
|
void lirc_mp_cleanup(void){
|
|
|
|
if(lirc_is_setup != 0){
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_LIRC,MSGL_V,"Cleaning up lirc stuff.\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
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},
|
2001-04-16 00:34:10 +00:00
|
|
|
{"PAUSE", 'p'},
|
|
|
|
{"INCVOL", '*'},
|
|
|
|
{"DECVOL", '/'},
|
2001-04-23 17:17:04 +00:00
|
|
|
{"MASTER", 'm'},
|
2001-06-19 22:16:12 +00:00
|
|
|
{"ASYNC-", '-'},
|
|
|
|
{"ASYNC+", '+'},
|
2001-04-23 17:17:04 +00:00
|
|
|
{"OSD", 'o'}
|
2001-02-24 20:28:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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){
|
2001-09-26 21:35:14 +00:00
|
|
|
mp_msg(MSGT_LIRC,MSGL_V,"LIRC: lirc_code2char() returned an error!\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
// end lirc support
|
|
|
|
|
|
|
|
#endif // HAVE_LIRC
|
|
|
|
|