Mercurial > mplayer.hg
annotate fifo.c @ 22338:434cd072b0d3
Seek to -ss position without first starting audio/video from the start.
Manual seeks no longer shift -endpos position (hopefully no one
considered that a "feature").
author | uau |
---|---|
date | Tue, 27 Feb 2007 01:16:59 +0000 |
parents | 5a5c7529e8a3 |
children |
rev | line source |
---|---|
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
1 #include "input/mouse.h" |
9831 | 2 |
3 | |
22131
934010b90043
Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents:
21964
diff
changeset
|
4 int key_fifo_size = 7; |
14077
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
5 static int *key_fifo_data = NULL; |
9831 | 6 static int key_fifo_read=0; |
7 static int key_fifo_write=0; | |
8 | |
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
9 static void mplayer_put_key_internal(int code){ |
22131
934010b90043
Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents:
21964
diff
changeset
|
10 int fifo_free = key_fifo_read - key_fifo_write - 1; |
934010b90043
Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents:
21964
diff
changeset
|
11 if (fifo_free < 0) fifo_free += key_fifo_size; |
9831 | 12 // 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
|
13 if (key_fifo_data == NULL) |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
14 key_fifo_data = malloc(key_fifo_size * sizeof(int)); |
22131
934010b90043
Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents:
21964
diff
changeset
|
15 if(!fifo_free) return; // FIFO FULL!! |
934010b90043
Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents:
21964
diff
changeset
|
16 // reserve some space for key release events to avoid stuck keys |
934010b90043
Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents:
21964
diff
changeset
|
17 if((code & MP_KEY_DOWN) && fifo_free < (key_fifo_size >> 1)) |
934010b90043
Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents:
21964
diff
changeset
|
18 return; |
9831 | 19 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
|
20 key_fifo_write=(key_fifo_write+1)%key_fifo_size; |
9831 | 21 } |
22 | |
23 int mplayer_get_key(int fd){ | |
24 int key; | |
25 // 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
|
26 if (key_fifo_data == NULL) |
3d3f3cc8494a
use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents:
13872
diff
changeset
|
27 return MP_INPUT_NOTHING; |
9831 | 28 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING; |
29 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
|
30 key_fifo_read=(key_fifo_read+1)%key_fifo_size; |
9831 | 31 // printf("mplayer_get_key => %d\n",key); |
32 return key; | |
33 } | |
34 | |
35 | |
21941
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
36 static unsigned doubleclick_time = 300; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
37 |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
38 static void put_double(int code) { |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
39 if (code >= MOUSE_BTN0 && code <= MOUSE_BTN9) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
40 mplayer_put_key_internal(code - MOUSE_BTN0 + MOUSE_BTN0_DBL); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
41 } |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
42 |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
43 void mplayer_put_key(int code) { |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
44 static unsigned last_key_time[2]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
45 static int last_key[2]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
46 unsigned now = GetTimerMS(); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
47 // ignore system-doubleclick if we generate these events ourselves |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
48 if (doubleclick_time && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
49 (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
50 (code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
51 return; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
52 mplayer_put_key_internal(code); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
53 if (code & MP_KEY_DOWN) { |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
54 code &= ~MP_KEY_DOWN; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
55 last_key[1] = last_key[0]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
56 last_key[0] = code; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
57 last_key_time[1] = last_key_time[0]; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
58 last_key_time[0] = now; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
59 if (last_key[1] == code && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
60 now - last_key_time[1] < doubleclick_time) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
61 put_double(code); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
62 return; |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
63 } |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
64 if (last_key[0] == code && last_key[1] == code && |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
65 now - last_key_time[1] < doubleclick_time) |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
66 put_double(code); |
32c3d5e3a682
Apply ancient double-click patch that nobody cares to comment on.
reimar
parents:
14077
diff
changeset
|
67 } |