Mercurial > mplayer.hg
annotate lirc_mp.c @ 1149:6a0f937b52e6
- new config option -lircconfig (config file for lirc)
- new config option -(no)double (disable/enable doublebuffering in libvo)
author | acki2 |
---|---|
date | Sun, 17 Jun 2001 20:38:02 +0000 |
parents | b9d7b6c84290 |
children | 37d6e98cb645 |
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" | |
15 #ifdef HAVE_LIRC | |
16 | |
17 // start of LIRC support | |
18 | |
19 #include <lirc/lirc_client.h> | |
20 #include <errno.h> | |
21 #include <stdio.h> | |
22 #include <sys/ioctl.h> | |
23 #include <string.h> | |
24 #include <fcntl.h> | |
25 #include "linux/keycodes.h" | |
26 | |
27 // global stuff ---------------------------------------------------- | |
28 | |
29 static struct lirc_config *lirc_config; | |
30 static int lirc_is_setup = 0; | |
1149
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
31 char *lirc_configfile = NULL; |
1 | 32 |
33 // setup routine --------------------------------------------------- | |
34 | |
35 void lirc_mp_setup(void){ | |
36 | |
37 int lirc_flags; | |
38 int lirc_sock; | |
39 | |
40 printf("Setting up lirc support...\n"); | |
41 if((lirc_sock=lirc_init("mplayer_lirc",1))==-1){ | |
42 printf("Failed opening lirc support!\n"); | |
43 printf("You won't be able to use your remote control\n"); | |
44 return; | |
45 } | |
46 | |
47 fcntl(lirc_sock,F_SETOWN,getpid()); | |
48 lirc_flags=fcntl(lirc_sock,F_GETFL,0); | |
49 if(lirc_flags!=-1) | |
50 { | |
51 fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK); | |
52 }else{ | |
53 lirc_deinit(); | |
54 printf("Something's wrong with the lirc socket: %s\n", | |
55 strerror(errno)); | |
56 printf("You won't be able to use your remote control\n"); | |
57 return; | |
58 } | |
59 | |
60 | |
1149
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
61 if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){ |
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
62 printf("Failed to read config file %s !\n", |
6a0f937b52e6
- new config option -lircconfig (config file for lirc)
acki2
parents:
593
diff
changeset
|
63 lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile); |
1 | 64 printf("You won't be able to use your remote control\n"); |
65 lirc_deinit(); | |
66 return; | |
67 } | |
68 printf("LIRC init was successful.\n"); | |
69 lirc_is_setup = 1; | |
70 } | |
71 | |
72 // cleanup routine ------------------------------------------- | |
73 | |
74 void lirc_mp_cleanup(void){ | |
75 if(lirc_is_setup != 0){ | |
76 printf("Cleaning up lirc stuff.\n"); | |
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'}, |
104 {"OSD", 'o'} | |
1 | 105 }; |
106 | |
107 char *code; | |
108 char *c; | |
109 int ret; | |
110 int i; | |
111 int retval = 0; | |
112 | |
113 if( lirc_is_setup == 0)return 0; | |
114 | |
115 if(lirc_config == NULL ){ | |
116 // do some cleanupstuff like freeing memory or the like | |
117 // (if we ever should do it the right way and loop over all | |
118 // all strings delivered by lirc_code2char() ) | |
119 }else{ | |
120 | |
121 if(lirc_nextcode(&code)==0){ | |
122 if(code!=NULL){ | |
123 // this should be a while loop | |
124 // but we would have to introduce state since we need to keep | |
125 // code | |
126 if((ret=lirc_code2char(lirc_config,code,&c))==0 && c!=NULL){ | |
127 fprintf(stderr, "LIRC: Got string \"%s\"",c); | |
128 for(i=0; i< (sizeof(lirc_cmd)/sizeof(struct lirc_cmd)); i++){ | |
129 if(!(strcmp(lirc_cmd[i].lc_lirccmd, c))){ | |
130 retval = lirc_cmd[i].mplayer_cmd; | |
131 break; | |
132 } | |
133 | |
134 } | |
135 } | |
136 free(code); | |
137 if(ret==-1){ | |
138 printf("LIRC: lirc_code2char() returned an error!\n"); | |
139 } | |
140 } | |
141 } | |
142 } | |
143 return retval; | |
144 } | |
145 | |
146 // end lirc support | |
147 | |
148 #endif // HAVE_LIRC | |
149 |