annotate mp_fifo.c @ 27195:5eb532ff5793

Remove unnecessary function keyword from shell script function declarations, it is a bashism.
author diego
date Mon, 07 Jul 2008 06:30:24 +0000
parents 98eaf29b5dee
children c1a3f1bbba26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22823
98eaf29b5dee Code cleanup: don't include a .c file in mplayer.c and fix a few
rathann
parents: 22313
diff changeset
1 #include <stdlib.h>
98eaf29b5dee Code cleanup: don't include a .c file in mplayer.c and fix a few
rathann
parents: 22313
diff changeset
2 #include "osdep/timer.h"
98eaf29b5dee Code cleanup: don't include a .c file in mplayer.c and fix a few
rathann
parents: 22313
diff changeset
3 #include "input/input.h"
21941
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
4 #include "input/mouse.h"
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
5
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
6
22131
934010b90043 Reserve half of fifo for key release events to help avoiding stop buttons
reimar
parents: 21964
diff changeset
7 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
8 static int *key_fifo_data = NULL;
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
9 static int key_fifo_read=0;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
10 static int key_fifo_write=0;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
11
21941
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
12 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
13 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
14 if (fifo_free < 0) fifo_free += key_fifo_size;
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
15 // 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
16 if (key_fifo_data == NULL)
3d3f3cc8494a use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents: 13872
diff changeset
17 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
18 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
19 // 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
20 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
21 return;
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
22 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
23 key_fifo_write=(key_fifo_write+1)%key_fifo_size;
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
24 }
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
25
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
26 int mplayer_get_key(int fd){
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
27 int key;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
28 // 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
29 if (key_fifo_data == NULL)
3d3f3cc8494a use a configurable-size ringbuffer instead of a pipe for buffering key events.
reimar
parents: 13872
diff changeset
30 return MP_INPUT_NOTHING;
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
31 if(key_fifo_write==key_fifo_read) return MP_INPUT_NOTHING;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
32 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
33 key_fifo_read=(key_fifo_read+1)%key_fifo_size;
9831
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
34 // printf("mplayer_get_key => %d\n",key);
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
35 return key;
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
36 }
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
37
0397b461f0fb MINGW32 port and select()less fifocode by Arpi
faust3
parents: 7483
diff changeset
38
22823
98eaf29b5dee Code cleanup: don't include a .c file in mplayer.c and fix a few
rathann
parents: 22313
diff changeset
39 unsigned doubleclick_time = 300;
21941
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
40
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
41 static void put_double(int code) {
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
42 if (code >= MOUSE_BTN0 && code <= MOUSE_BTN9)
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
43 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
44 }
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
45
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
46 void mplayer_put_key(int code) {
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
47 static unsigned last_key_time[2];
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
48 static int last_key[2];
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
49 unsigned now = GetTimerMS();
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
50 // 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
51 if (doubleclick_time &&
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
52 (code & ~MP_KEY_DOWN) >= MOUSE_BTN0_DBL &&
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
53 (code & ~MP_KEY_DOWN) <= MOUSE_BTN9_DBL)
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
54 return;
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
55 mplayer_put_key_internal(code);
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
56 if (code & MP_KEY_DOWN) {
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
57 code &= ~MP_KEY_DOWN;
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
58 last_key[1] = last_key[0];
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
59 last_key[0] = code;
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
60 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
61 last_key_time[0] = now;
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
62 if (last_key[1] == code &&
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
63 now - last_key_time[1] < doubleclick_time)
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
64 put_double(code);
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
65 return;
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
66 }
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
67 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
68 now - last_key_time[1] < doubleclick_time)
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
69 put_double(code);
32c3d5e3a682 Apply ancient double-click patch that nobody cares to comment on.
reimar
parents: 14077
diff changeset
70 }