summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-14 15:44:11 +0200
committerwm4 <wm4@nowhere>2013-07-14 15:52:32 +0200
commit4b1ce17e238bcc1bb531d4572f6a3ccb3fb05bf0 (patch)
treeced89f73fc73bc7ccd163fda2b9965bcf82f9dc3
parent38ce8250914fa79d482a6321a330733cf251dfdd (diff)
downloadmpv-4b1ce17e238bcc1bb531d4572f6a3ccb3fb05bf0.tar.bz2
mpv-4b1ce17e238bcc1bb531d4572f6a3ccb3fb05bf0.tar.xz
input: never wait if there are new events in the input queue
Move the reading loop from read_all_fd_events to read_events. If got_new_events is set when calling read_events, don't actually wait and set the timeout to 0. (Note that not waiting is sort of transparent to the caller: the caller is just supposed to execute the event loop again, and then it will actually wait. mplayer.c handles this correctly.) This might reduce latency with some input sources.
-rw-r--r--core/input/input.c42
1 files changed, 20 insertions, 22 deletions
diff --git a/core/input/input.c b/core/input/input.c
index de4158e272..47005fdf83 100644
--- a/core/input/input.c
+++ b/core/input/input.c
@@ -1664,31 +1664,29 @@ static void read_events(struct input_ctx *ictx, int time)
time = FFMIN(time, ictx->ar_delay);
}
time = FFMAX(time, 0);
- ictx->got_new_events = false;
- remove_dead_fds(ictx);
- if (time) {
- for (int i = 0; i < ictx->num_fds; i++) {
- if (!ictx->fds[i].select)
- read_fd(ictx, &ictx->fds[i]);
+
+ while (1) {
+ if (ictx->got_new_events)
+ time = 0;
+ ictx->got_new_events = false;
+
+ remove_dead_fds(ictx);
+
+ if (time) {
+ for (int i = 0; i < ictx->num_fds; i++) {
+ if (!ictx->fds[i].select)
+ read_fd(ictx, &ictx->fds[i]);
+ }
}
- }
- if (ictx->got_new_events)
- time = 0;
- input_wait_read(ictx, time);
-}
+ if (ictx->got_new_events)
+ time = 0;
-/* To support blocking file descriptors we don't loop the read over
- * every source until it's known to be empty. Instead we use this wrapper
- * to run select() again.
- */
-static void read_all_fd_events(struct input_ctx *ictx, int time)
-{
- while (1) {
- read_events(ictx, time);
+ input_wait_read(ictx, time);
+
+ // Read until all input FDs are empty
if (!ictx->got_new_events)
- return;
- time = 0;
+ break;
}
}
@@ -1698,7 +1696,7 @@ static void read_all_events(struct input_ctx *ictx, int time)
#ifdef CONFIG_COCOA
cocoa_check_events();
#endif
- read_all_fd_events(ictx, time);
+ read_events(ictx, time);
}
int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd)