Mercurial > mplayer.hg
annotate fifo.c @ 14802:63b1cc62fc9b
MEncoder multiple files patch by Oded Shimon (ods15)
Seems to work, or at least not to cause problems with existing
functionality (encoding single files).
Please test and report bugs, if there are any!
author | rfelker |
---|---|
date | Fri, 25 Feb 2005 02:32:29 +0000 |
parents | 3d3f3cc8494a |
children | 32c3d5e3a682 |
rev | line source |
---|---|
9831 | 1 |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
2 #if 0 |
113 | 3 |
4 // keyboard: | |
5 static int keyb_fifo_put=-1; | |
6 static int keyb_fifo_get=-1; | |
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 | 20 static void make_pipe(int* pr,int* pw){ |
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 | 23 *pr=temp[0]; |
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 | 26 } |
27 | |
28 void mplayer_put_key(int code){ | |
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 | 33 } |
9831 | 34 |
35 #else | |
36 | |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
37 int key_fifo_size = 10; |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
38 static int *key_fifo_data = NULL; |
9831 | 39 static int key_fifo_read=0; |
40 static int key_fifo_write=0; | |
41 | |
42 void mplayer_put_key(int code){ | |
43 // printf("mplayer_put_key(%d)\n",code); | |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
44 if (key_fifo_data == NULL) |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
45 key_fifo_data = malloc(key_fifo_size * sizeof(int)); |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
46 if(((key_fifo_write+1)%key_fifo_size)==key_fifo_read) return; // FIFO FULL!! |
9831 | 47 key_fifo_data[key_fifo_write]=code; |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
48 key_fifo_write=(key_fifo_write+1)%key_fifo_size; |
9831 | 49 } |
50 | |
51 int mplayer_get_key(int fd){ | |
52 int key; | |
53 // printf("mplayer_get_key(%d)\n",fd); | |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
54 if (key_fifo_data == NULL) |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
55 return MP_INPUT_NOTHING; |
9831 | 56 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING; |
57 key=key_fifo_data[key_fifo_read]; | |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
58 key_fifo_read=(key_fifo_read+1)%key_fifo_size; |
9831 | 59 // printf("mplayer_get_key => %d\n",key); |
60 return key; | |
61 } | |
62 | |
63 #endif | |
64 |