Mercurial > mplayer.hg
annotate fifo.c @ 7176:42222161de9b
2*10l to me
author | arpi |
---|---|
date | Fri, 30 Aug 2002 20:59:21 +0000 |
parents | 16576e05b93a |
children | 44198b2f42db |
rev | line source |
---|---|
113 | 1 |
2 // keyboard: | |
3 static int keyb_fifo_put=-1; | |
4 static int keyb_fifo_get=-1; | |
5 | |
6 static void make_pipe(int* pr,int* pw){ | |
7 int temp[2]; | |
8 if(pipe(temp)!=0) printf("Cannot make PIPE!\n"); | |
9 *pr=temp[0]; | |
10 *pw=temp[1]; | |
11 } | |
12 | |
13 static inline int my_write(int fd,unsigned char* mem,int len){ | |
14 int total=0; | |
15 int len2; | |
16 while(len>0){ | |
17 len2=write(fd,mem+total,len); if(len2<=0) break; | |
18 total+=len2;len-=len2; | |
19 // printf("%d bytes received, %d left\n",len2,len); | |
20 } | |
21 return total; | |
22 } | |
23 | |
24 static inline int my_read(int fd,unsigned char* mem,int len){ | |
25 int total=0; | |
26 int len2; | |
27 while(len>0){ | |
28 len2=read(fd,mem+total,len); if(len2<=0) break; | |
29 total+=len2;len-=len2; | |
30 // printf("%d bytes received, %d left\n",len2,len); | |
31 } | |
32 return total; | |
33 } | |
34 | |
35 | |
36 void send_cmd(int fd,int cmd){ | |
37 int fifo_cmd=cmd; | |
38 write(fd,&fifo_cmd,4); | |
39 // fflush(control_fifo); | |
40 } | |
41 | |
42 | |
43 void mplayer_put_key(int code){ | |
44 fd_set rfds; | |
45 struct timeval tv; | |
46 | |
47 /* Watch stdin (fd 0) to see when it has input. */ | |
48 FD_ZERO(&rfds); | |
49 FD_SET(keyb_fifo_put, &rfds); | |
50 tv.tv_sec = 0; | |
51 tv.tv_usec = 0; | |
52 | |
53 //retval = select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv); | |
3014
16576e05b93a
Profiling fix by Artur Skawina <skawina@geocities.com>
atmos4
parents:
113
diff
changeset
|
54 if(select(keyb_fifo_put+1, NULL, &rfds, NULL, &tv)>0){ |
113 | 55 write(keyb_fifo_put,&code,4); |
56 // printf("*** key event %d sent ***\n",code); | |
57 } else { | |
58 // printf("*** key event dropped (FIFO is full) ***\n"); | |
59 } | |
60 } | |
61 | |
62 int mplayer_get_key(){ | |
63 fd_set rfds; | |
64 struct timeval tv; | |
65 int code=-1; | |
66 | |
67 /* Watch stdin (fd 0) to see when it has input. */ | |
68 FD_ZERO(&rfds); | |
69 FD_SET(keyb_fifo_get, &rfds); | |
70 tv.tv_sec = 0; | |
71 tv.tv_usec = 0; | |
72 | |
73 //retval = select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv); | |
3014
16576e05b93a
Profiling fix by Artur Skawina <skawina@geocities.com>
atmos4
parents:
113
diff
changeset
|
74 if(select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv)>0){ |
113 | 75 read(keyb_fifo_get,&code,4); |
76 // printf("*** key event %d read ***\n",code); | |
77 } | |
78 return code; | |
79 } | |
80 |