annotate fifo.c @ 10448:091fc3a26c00

Small correction and port to XML.
author diego
date Sun, 20 Jul 2003 14:50:31 +0000
parents 0397b461f0fb
children 11b249ef87b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
1
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
2 #ifndef HAVE_NO_POSIX_SELECT
113
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
3
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
4 // keyboard:
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
5 static int keyb_fifo_put=-1;
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
6 static int keyb_fifo_get=-1;
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
7
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
8 static void make_pipe(int* pr,int* pw){
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
9 int temp[2];
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
10 if(pipe(temp)!=0) printf("Cannot make PIPE!\n");
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
11 *pr=temp[0];
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
12 *pw=temp[1];
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
13 }
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
14
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
15 void mplayer_put_key(int code){
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
16 fd_set rfds;
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
17 struct timeval tv;
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
18
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
19 /* Watch stdin (fd 0) to see when it has input. */
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
20 FD_ZERO(&rfds);
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
21 FD_SET(keyb_fifo_put, &rfds);
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
22 tv.tv_sec = 0;
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
23 tv.tv_usec = 0;
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
24
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
25 //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
26 if(select(keyb_fifo_put+1, NULL, &rfds, NULL, &tv)>0){
113
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
27 write(keyb_fifo_put,&code,4);
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
28 // printf("*** key event %d sent ***\n",code);
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
29 } else {
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
30 // printf("*** key event dropped (FIFO is full) ***\n");
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
31 }
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
32 }
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
33
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
34 #else
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
35
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
36 #define KEY_FIFO_SIZE 1024
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
37 static int key_fifo_data[KEY_FIFO_SIZE];
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
38 static int key_fifo_read=0;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
39 static int key_fifo_write=0;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
40
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
41 void mplayer_put_key(int code){
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
42 // printf("mplayer_put_key(%d)\n",code);
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
43 if(((key_fifo_write+1)%KEY_FIFO_SIZE)==key_fifo_read) return; // FIFO FULL!!
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
44 key_fifo_data[key_fifo_write]=code;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
45 key_fifo_write=(key_fifo_write+1)%KEY_FIFO_SIZE;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
46 }
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
47
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
48 int mplayer_get_key(int fd){
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
49 int key;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
50 // printf("mplayer_get_key(%d)\n",fd);
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
51 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
52 key=key_fifo_data[key_fifo_read];
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
53 key_fifo_read=(key_fifo_read+1)%KEY_FIFO_SIZE;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
54 // printf("mplayer_get_key => %d\n",key);
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
55 return key;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
56 }
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
57
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
58 #endif
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
59