Mercurial > mplayer.hg
annotate lirc_mp.c @ 6856:23221df30608
no need for ioctl.h if not using dvb
author | rfelker |
---|---|
date | Wed, 31 Jul 2002 05:25:57 +0000 |
parents | d25b898c4c44 |
children |
rev | line source |
---|---|
1 | 1 /* |
2 | |
3 lirc support for MPLayer (see www.lirc.org) | |
4 | |
5 v0.1 | |
6 | |
7 written 15/2/2001 by Andreas Ackermann (acki@acki-netz.de) | |
8 | |
9 file comes without warranty and all | |
10 | |
11 */ | |
12 | |
13 // hack, will be remove later when ./configure fixed... | |
14 #include "config.h" | |
1990 | 15 |
4823
d25b898c4c44
Make old and new lirc support independant from each other
albeu
parents:
2122
diff
changeset
|
16 #if defined(HAVE_LIRC) && ! defined (HAVE_NEW_INPUT) |
1 | 17 |
1990 | 18 #include "mp_msg.h" |
19 #include "help_mp.h" | |
20 | |
1 | 21 // start of LIRC support |
22 | |
23 #include <lirc/lirc_client.h> | |
24 #include <errno.h> | |
25 #include <stdio.h> | |
26 #include <sys/ioctl.h> | |
27 #include <string.h> | |
28 #include <fcntl.h> | |
29 #include "linux/keycodes.h" | |
30 | |
31 // global stuff ---------------------------------------------------- | |
32 | |
33 static struct lirc_config *lirc_config; | |
34 static int lirc_is_setup = 0; | |
1149
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
35 char *lirc_configfile = NULL; |
1 | 36 |
37 // setup routine --------------------------------------------------- | |
38 | |
39 void lirc_mp_setup(void){ | |
40 | |
41 int lirc_flags; | |
42 int lirc_sock; | |
43 | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1167
diff
changeset
|
44 mp_msg(MSGT_LIRC,MSGL_INFO,MSGTR_SettingUpLIRC); |
1 | 45 if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1167
diff
changeset
|
46 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCopenfailed MSGTR_LIRCdisabled); |
1 | 47 return; |
48 } | |
49 | |
50 fcntl(lirc_sock,F_SETOWN,getpid()); | |
51 lirc_flags=fcntl(lirc_sock,F_GETFL,0); | |
52 if(lirc_flags!=-1) | |
53 { | |
54 fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK); | |
55 }else{ | |
56 lirc_deinit(); | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1167
diff
changeset
|
57 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCsocketerr MSGTR_LIRCdisabled,strerror(errno)); |
1 | 58 return; |
59 } | |
60 | |
61 | |
1149
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
62 if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1167
diff
changeset
|
63 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCcfgerr MSGTR_LIRCdisabled, |
1149
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
64 lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); |
1 | 65 lirc_deinit(); |
66 return; | |
67 } | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1167
diff
changeset
|
68 mp_msg(MSGT_LIRC,MSGL_V,"LIRC init was successful.\n"); |
1 | 69 lirc_is_setup = 1; |
70 } | |
71 | |
72 // cleanup routine ------------------------------------------- | |
73 | |
74 void lirc_mp_cleanup(void){ | |
75 if(lirc_is_setup != 0){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1167
diff
changeset
|
76 mp_msg(MSGT_LIRC,MSGL_V,"Cleaning up lirc stuff.\n"); |
1 | 77 lirc_mp_getinput(NULL); |
78 lirc_freeconfig(lirc_config); | |
79 lirc_deinit(); | |
80 lirc_is_setup = 0; | |
81 } | |
82 } | |
83 | |
84 // get some events ------------------------------------------- | |
85 | |
86 | |
87 struct lirc_cmd { | |
88 unsigned char *lc_lirccmd; | |
89 int mplayer_cmd; | |
90 }; | |
91 | |
92 int lirc_mp_getinput(){ | |
93 | |
94 static struct lirc_cmd lirc_cmd[] = { | |
95 {"QUIT", KEY_ESC}, | |
96 {"FWD" , KEY_RIGHT}, | |
97 {"FFWD" , KEY_UP}, | |
98 {"RWND" , KEY_LEFT}, | |
99 {"FRWND" , KEY_DOWN}, | |
462 | 100 {"PAUSE", 'p'}, |
101 {"INCVOL", '*'}, | |
102 {"DECVOL", '/'}, | |
593 | 103 {"MASTER", 'm'}, |
1167
37d6e98cb645
ASYNC +- patch applied by Olli Sulopuisto <dst@iki.fi>
arpi_esp
parents:
1149
diff
changeset
|
104 {"ASYNC-", '-'}, |
37d6e98cb645
ASYNC +- patch applied by Olli Sulopuisto <dst@iki.fi>
arpi_esp
parents:
1149
diff
changeset
|
105 {"ASYNC+", '+'}, |
593 | 106 {"OSD", 'o'} |
1 | 107 }; |
108 | |
109 char *code; | |
110 char *c; | |
111 int ret; | |
112 int i; | |
113 int retval = 0; | |
114 | |
115 if( lirc_is_setup == 0)return 0; | |
116 | |
117 if(lirc_config == NULL ){ | |
118 // do some cleanupstuff like freeing memory or the like | |
119 // (if we ever should do it the right way and loop over all | |
120 // all strings delivered by lirc_code2char() ) | |
121 }else{ | |
122 | |
123 if(lirc_nextcode(&code)==0){ | |
124 if(code!=NULL){ | |
125 // this should be a while loop | |
126 // but we would have to introduce state since we need to keep | |
127 // code | |
128 if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){ | |
129 fprintf(stderr, "LIRC: Got string \"%s\"",c); | |
130 for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){ | |
131 if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){ | |
132 retval = lirc_cmd[i].mplayer_cmd; | |
133 break; | |
134 } | |
135 | |
136 } | |
137 } | |
2122
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
138 // the lirc support is "broken by design": (see mailing list discussion) |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
139 // we only accept one command at each call of this subroutine, but the |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
140 // "lirc_code2char()" function should be called in a loop |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
141 // until it reports "empty"... (see lirc documentation) |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
142 // so we need to flush the lirc command queue after we processed one |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
143 // command. of course we report if we really lose a message. |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
144 while((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){ |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
145 fprintf(stderr, "LIRC: lost command \"%s\"",c); |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
146 } |
cc9d4e489a0d
keypress fix by M.Hunold@t-online.de (Michael Hunold)
arpi
parents:
1990
diff
changeset
|
147 |
1 | 148 free(code); |
149 if(ret==-1){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1167
diff
changeset
|
150 mp_msg(MSGT_LIRC,MSGL_V,"LIRC: lirc_code2char() returned an error!\n"); |
1 | 151 } |
152 } | |
153 } | |
154 } | |
155 return retval; | |
156 } | |
157 | |
158 // end lirc support | |
159 | |
160 #endif // HAVE_LIRC | |
161 |