Add support for VDPAU video out, including hardware decoding.
[mplayer/glamo.git] / mp_fifo.c
blob5d0159dfd8ee4c3fd9df2cb1ce961048397d7277
1 #include <stdlib.h>
2 #include "osdep/timer.h"
3 #include "input/input.h"
4 #include "input/mouse.h"
7 int key_fifo_size = 7;
8 static int *key_fifo_data = NULL;
9 static int key_fifo_read=0;
10 static int key_fifo_write=0;
12 static void mplayer_put_key_internal(int code){
13 int fifo_free = key_fifo_read - key_fifo_write - 1;
14 if (fifo_free < 0) fifo_free += key_fifo_size;
15 // printf("mplayer_put_key(%d)\n",code);
16 if (key_fifo_data == NULL)
17 key_fifo_data = malloc(key_fifo_size * sizeof(int));
18 if(!fifo_free) return; // FIFO FULL!!
19 // reserve some space for key release events to avoid stuck keys
20 if((code & MP_KEY_DOWN) && fifo_free < (key_fifo_size >> 1))
21 return;
22 key_fifo_data[key_fifo_write]=code;
23 key_fifo_write=(key_fifo_write+1)%key_fifo_size;
26 int mplayer_get_key(int fd){
27 int key;
28 // printf("mplayer_get_key(%d)\n",fd);
29 if (key_fifo_data == NULL)
30 return MP_INPUT_NOTHING;
31 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
32 key=key_fifo_data[key_fifo_read];
33 key_fifo_read=(key_fifo_read+1)%key_fifo_size;
34 // printf("mplayer_get_key => %d\n",key);
35 return key;
39 unsigned doubleclick_time = 300;
41 static void put_double(int code) {
42 if (code >= MOUSE_BTN0 && code <= MOUSE_BTN9)
43 mplayer_put_key_internal(code - MOUSE_BTN0 + MOUSE_BTN0_DBL);
46 void mplayer_put_key(int code) {
47 static unsigned last_key_time[2];
48 static int last_key[2];
49 unsigned now = GetTimerMS();
50 // ignore system-doubleclick if we generate these events ourselves
51 if (doubleclick_time &&
52 (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL &&
53 (code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL)
54 return;
55 mplayer_put_key_internal(code);
56 if (code & MP_KEY_DOWN) {
57 code &= ~MP_KEY_DOWN;
58 last_key[1] = last_key[0];
59 last_key[0] = code;
60 last_key_time[1] = last_key_time[0];
61 last_key_time[0] = now;
62 if (last_key[1] == code &&
63 now - last_key_time[1] < doubleclick_time)
64 put_double(code);
65 return;
67 if (last_key[0] == code && last_key[1] == code &&
68 now - last_key_time[1] < doubleclick_time)
69 put_double(code);