annotate fifo.c @ 14009:1c2b471136b3

*** empty log message ***
author jheryan
date Mon, 22 Nov 2004 08:43:48 +0000
parents 8b810ed6e543
children 3d3f3cc8494a
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
13872
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
8 static void set_nonblock_flag(int fd) {
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
9 int oldflags;
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
10
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
11 oldflags = fcntl(fd, F_GETFL, 0);
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
12 if (oldflags != -1) {
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
13 if (fcntl(keyb_fifo_put, F_SETFL, oldflags | O_NONBLOCK) != -1) {
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
14 return;
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
15 }
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
16 }
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
17 mp_msg(MSGT_INPUT,MSGL_ERR,"Cannot set nonblocking mode for fd %d!\n", fd);
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
18 }
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
19
113
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
20 static void make_pipe(int* pr,int* pw){
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
21 int temp[2];
13699
11b249ef87b0 printf --> mp_msg by the Wanderer <inverseparadox at comcast dot net>
diego
parents: 9831
diff changeset
22 if(pipe(temp)!=0) mp_msg(MSGT_FIXME, MSGL_FIXME, MSGTR_CannotMakePipe);
113
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
23 *pr=temp[0];
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
24 *pw=temp[1];
13872
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
25 set_nonblock_flag(temp[1]);
113
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
26 }
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
27
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
28 void mplayer_put_key(int code){
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
29
13872
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
30 if( write(keyb_fifo_put,&code,4) != 4 ){
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
31 mp_msg(MSGT_INPUT,MSGL_ERR,"*** key event dropped (FIFO is full) ***\n");
8b810ed6e543 fix "stuck mouse button" by setting O_NONBLOCK, instead of using select() to check write() blocking on pipe.
iive
parents: 13699
diff changeset
32 }
113
f6f8f53b75ad common FIFO code moved to fifo.c
arpi_esp
parents:
diff changeset
33 }
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
34
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
35 #else
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
36
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
37 #define KEY_FIFO_SIZE 1024
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
38 static int key_fifo_data[KEY_FIFO_SIZE];
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
39 static int key_fifo_read=0;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
40 static int key_fifo_write=0;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
41
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
42 void mplayer_put_key(int code){
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
43 // printf("mplayer_put_key(%d)\n",code);
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
44 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
45 key_fifo_data[key_fifo_write]=code;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
46 key_fifo_write=(key_fifo_write+1)%KEY_FIFO_SIZE;
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
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
49 int mplayer_get_key(int fd){
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
50 int key;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
51 // printf("mplayer_get_key(%d)\n",fd);
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
52 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
53 key=key_fifo_data[key_fifo_read];
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
54 key_fifo_read=(key_fifo_read+1)%KEY_FIFO_SIZE;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
55 // printf("mplayer_get_key => %d\n",key);
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
56 return key;
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
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
59 #endif
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
60