Real rstp:// streaming support, ported from xine
[mplayer/greg.git] / fifo.c
blobba803eb0e9ea4831e063554edaabcc71a5036a18
2 #ifndef HAVE_NO_POSIX_SELECT
4 // keyboard:
5 static int keyb_fifo_put=-1;
6 static int keyb_fifo_get=-1;
8 static void make_pipe(int* pr,int* pw){
9 int temp[2];
10 if(pipe(temp)!=0) printf("Cannot make PIPE!\n");
11 *pr=temp[0];
12 *pw=temp[1];
15 void mplayer_put_key(int code){
16 fd_set rfds;
17 struct timeval tv;
19 /* Watch stdin (fd 0) to see when it has input. */
20 FD_ZERO(&rfds);
21 FD_SET(keyb_fifo_put, &rfds);
22 tv.tv_sec = 0;
23 tv.tv_usec = 0;
25 //retval = select(keyb_fifo_put+1, &rfds, NULL, NULL, &tv);
26 if(select(keyb_fifo_put+1, NULL, &rfds, NULL, &tv)>0){
27 write(keyb_fifo_put,&code,4);
28 // printf("*** key event %d sent ***\n",code);
29 } else {
30 // printf("*** key event dropped (FIFO is full) ***\n");
34 #else
36 #define KEY_FIFO_SIZE 1024
37 static int key_fifo_data[KEY_FIFO_SIZE];
38 static int key_fifo_read=0;
39 static int key_fifo_write=0;
41 void mplayer_put_key(int code){
42 // printf("mplayer_put_key(%d)\n",code);
43 if(((key_fifo_write+1)%KEY_FIFO_SIZE)==key_fifo_read) return; // FIFO FULL!!
44 key_fifo_data[key_fifo_write]=code;
45 key_fifo_write=(key_fifo_write+1)%KEY_FIFO_SIZE;
48 int mplayer_get_key(int fd){
49 int key;
50 // printf("mplayer_get_key(%d)\n",fd);
51 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
52 key=key_fifo_data[key_fifo_read];
53 key_fifo_read=(key_fifo_read+1)%KEY_FIFO_SIZE;
54 // printf("mplayer_get_key => %d\n",key);
55 return key;
58 #endif