5 static int keyb_fifo_put
=-1;
6 static int keyb_fifo_get
=-1;
8 static void set_nonblock_flag(int fd
) {
11 oldflags
= fcntl(fd
, F_GETFL
, 0);
13 if (fcntl(keyb_fifo_put
, F_SETFL
, oldflags
| O_NONBLOCK
) != -1) {
17 mp_msg(MSGT_INPUT
,MSGL_ERR
,"Cannot set nonblocking mode for fd %d!\n", fd
);
20 static void make_pipe(int* pr
,int* pw
){
22 if(pipe(temp
)!=0) mp_msg(MSGT_FIXME
, MSGL_FIXME
, MSGTR_CannotMakePipe
);
25 set_nonblock_flag(temp
[1]);
28 void mplayer_put_key(int code
){
30 if( write(keyb_fifo_put
,&code
,4) != 4 ){
31 mp_msg(MSGT_INPUT
,MSGL_ERR
,"*** key event dropped (FIFO is full) ***\n");
37 int key_fifo_size
= 10;
38 static int *key_fifo_data
= NULL
;
39 static int key_fifo_read
=0;
40 static int key_fifo_write
=0;
42 void mplayer_put_key(int code
){
43 // printf("mplayer_put_key(%d)\n",code);
44 if (key_fifo_data
== NULL
)
45 key_fifo_data
= malloc(key_fifo_size
* sizeof(int));
46 if(((key_fifo_write
+1)%key_fifo_size
)==key_fifo_read
) return; // FIFO FULL!!
47 key_fifo_data
[key_fifo_write
]=code
;
48 key_fifo_write
=(key_fifo_write
+1)%key_fifo_size
;
51 int mplayer_get_key(int fd
){
53 // printf("mplayer_get_key(%d)\n",fd);
54 if (key_fifo_data
== NULL
)
55 return MP_INPUT_NOTHING
;
56 if(key_fifo_write
==key_fifo_read
) return MP_INPUT_NOTHING
;
57 key
=key_fifo_data
[key_fifo_read
];
58 key_fifo_read
=(key_fifo_read
+1)%key_fifo_size
;
59 // printf("mplayer_get_key => %d\n",key);