4 #include <lirc/lirc_client.h>
17 static struct lirc_config
*lirc_config
;
18 char *lirc_configfile
;
20 static char* cmd_buf
= NULL
;
23 mp_input_lirc_init(void) {
26 mp_msg(MSGT_LIRC
,MSGL_V
,MSGTR_SettingUpLIRC
);
27 if((lirc_sock
=lirc_init("mplayer",1))==-1){
28 mp_msg(MSGT_LIRC
,MSGL_ERR
,MSGTR_LIRCopenfailed
);
32 if(lirc_readconfig( lirc_configfile
,&lirc_config
,NULL
)!=0 ){
33 mp_msg(MSGT_LIRC
,MSGL_ERR
,MSGTR_LIRCcfgerr
,
34 lirc_configfile
== NULL
? "~/.lircrc" : lirc_configfile
);
42 int mp_input_lirc_read(int fd
,char* dest
, int s
) {
46 char *code
= NULL
,*c
= NULL
;
48 // We have something in the buffer return it
50 int l
= strlen(cmd_buf
), w
= l
> s
? s
: l
;
51 memcpy(dest
,cmd_buf
,w
);
54 memmove(cmd_buf
,&cmd_buf
[w
],l
+1);
62 // Nothing in the buffer, pool the lirc fd
65 memset(&tv
,0,sizeof(tv
));
66 while((r
= select(fd
+1,&fds
,NULL
,NULL
,&tv
)) <= 0) {
70 mp_msg(MSGT_INPUT
,MSGL_ERR
,"Select error : %s\n",strerror(errno
));
71 return MP_INPUT_ERROR
;
73 return MP_INPUT_NOTHING
;
76 // There's something to read
77 if(lirc_nextcode(&code
) != 0) {
78 mp_msg(MSGT_INPUT
,MSGL_ERR
,"Lirc error :(\n");
82 if(!code
) return MP_INPUT_NOTHING
;
84 // We put all cmds in a single buffer separated by \n
85 while((r
= lirc_code2char(lirc_config
,code
,&c
))==0 && c
!=NULL
) {
89 cmd_buf
= realloc(cmd_buf
,cl
+l
+2);
90 memcpy(&cmd_buf
[cl
],c
,l
);
100 else if(cmd_buf
) // return the first command in the buffer
101 return mp_input_lirc_read(fd
,dest
,s
);
103 return MP_INPUT_RETRY
;
108 mp_input_lirc_close(int fd
) {
113 lirc_freeconfig(lirc_config
);