annotate input/lirc.c @ 4457:49dcbd03436d

Optimize DirectShow decoding with vidix
author nick
date Fri, 01 Feb 2002 10:01:56 +0000
parents 5105f5da01d6
children c619a7271690
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4432
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
1
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
2 #include "../config.h"
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
3
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
4 #ifdef HAVE_LIRC
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
5
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
6 #include <lirc/lirc_client.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
7 #include <errno.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
8 #include <stdio.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
9 #include <sys/ioctl.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
10 #include <string.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
11 #include <fcntl.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
12 #include <unistd.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
13 #include <signal.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
14 #include <sys/types.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
15 #include <sys/wait.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
16 #include <stdlib.h>
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
17
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
18
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
19 #include "../mp_msg.h"
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
20 #include "../help_mp.h"
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
21
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
22 static struct lirc_config *lirc_config;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
23 extern char *lirc_configfile;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
24
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
25 static int child_pid=0;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
26
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
27 static void
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
28 mp_input_lirc_process_quit(int sig);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
29
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
30 static void
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
31 mp_input_lirc_process(int mp_fd);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
32
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
33
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
34 int
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
35 mp_input_lirc_init(void) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
36 int lirc_flags;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
37 int lirc_sock;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
38 int p[2];
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
39
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
40 mp_msg(MSGT_LIRC,MSGL_INFO,MSGTR_SettingUpLIRC);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
41 if((lirc_sock=lirc_init("mplayer",1))==-1){
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
42 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCopenfailed MSGTR_LIRCdisabled);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
43 return -1;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
44 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
45
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
46 #if 0
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
47 fcntl(lirc_sock,F_SETOWN,getpid());
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
48 lirc_flags=fcntl(lirc_sock,F_GETFL,0);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
49 if(lirc_flags!=-1) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
50 fcntl(lirc_sock,F_SETFL,lirc_flags|O_NONBLOCK);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
51 } else {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
52 lirc_deinit();
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
53 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCsocketerr MSGTR_LIRCdisabled,strerror(errno));
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
54 return -1;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
55 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
56 #endif
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
57
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
58
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
59 if(lirc_readconfig( lirc_configfile,&lirc_config,NULL )!=0 ){
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
60 mp_msg(MSGT_LIRC,MSGL_ERR,MSGTR_LIRCcfgerr MSGTR_LIRCdisabled,
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
61 lirc_configfile == NULL ? "~/.lircrc" : lirc_configfile);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
62 lirc_deinit();
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
63 return -1;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
64 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
65
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
66 if(pipe(p) != 0) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
67 mp_msg(MSGT_LIRC,MSGL_ERR,"Can't create lirc pipe : %s\n",strerror(errno));
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
68 lirc_deinit();
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
69 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
70
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
71 child_pid = fork();
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
72
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
73 if(child_pid < 0) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
74 mp_msg(MSGT_LIRC,MSGL_ERR,"Can't fork lirc subprocess : %s\n",strerror(errno));
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
75 lirc_deinit();
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
76 close(p[0]);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
77 close(p[1]);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
78 return -1;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
79 } else if(child_pid == 0) {// setup child process
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
80 close(p[0]);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
81 // put some signal handlers
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
82 signal(SIGINT,mp_input_lirc_process_quit);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
83 signal(SIGHUP,mp_input_lirc_process_quit);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
84 signal(SIGQUIT,mp_input_lirc_process_quit);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
85 // start the process
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
86 mp_input_lirc_process(p[1]);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
87 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
88
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
89 // free unuseful ressources in parent process
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
90 lirc_freeconfig(lirc_config);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
91 close(p[1]);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
92
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
93 mp_msg(MSGT_LIRC,MSGL_V,"NEW LIRC init was successful.\n");
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
94
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
95 return p[0];
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
96 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
97
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
98 static void
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
99 mp_input_lirc_process_quit(int sig) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
100 lirc_freeconfig(lirc_config);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
101 lirc_deinit();
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
102 exit(sig > 0 ? 0 : -1);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
103 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
104
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
105 static void
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
106 mp_input_lirc_process(int mp_fd) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
107 char *cmd,*code;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
108 int ret;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
109
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
110 while(lirc_nextcode(&code)==0) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
111 if(code==NULL)
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
112 continue;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
113 while((ret=lirc_code2char(lirc_config,code,&cmd))==0 && cmd!=NULL) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
114 int len = strlen(cmd)+1;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
115 char buf[len];
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
116 int w=0;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
117 strcpy(buf,cmd);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
118 buf[len-1] = '\n';
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
119 while(w < len) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
120 int r = write(mp_fd,buf,len-w);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
121 if(r < 0) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
122 if(errno == EINTR)
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
123 continue;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
124 mp_msg(MSGT_LIRC,MSGL_V,"LIRC subprocess can't write in input pipe : %s\n",
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
125 strerror(errno));
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
126 mp_input_lirc_process_quit(-1);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
127 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
128 w += r;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
129 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
130 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
131 free(code);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
132 if(ret==-1)
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
133 break;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
134 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
135 mp_input_lirc_process_quit(-1);
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
136 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
137
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
138 void
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
139 mp_input_lirc_uninit(void) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
140 if( kill(child_pid,SIGQUIT) != 0) {
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
141 mp_msg(MSGT_LIRC,MSGL_V,"LIRC can't kill subprocess %d : %s\n",
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
142 child_pid,strerror(errno));
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
143 return;
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
144 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
145
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
146 if(waitpid(child_pid,NULL,0) < 0)
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
147 mp_msg(MSGT_LIRC,MSGL_V,"LIRC error while waiting subprocess %d : %s\n",
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
148 child_pid,strerror(errno));
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
149
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
150 }
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
151
5105f5da01d6 Added lirc support in input
albeu
parents:
diff changeset
152 #endif