summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-09-17 22:27:12 -0500
committerDudemanguy <random342@airmail.cc>2023-10-10 19:10:55 +0000
commit5d44cf93df47046c779fc4da68a09812a2ce4004 (patch)
tree07f9fca72a897210f2fb0682773a0cef4efb456f /osdep
parentba4b408b8bdc2aa0059abaaffe8b16f28aec480b (diff)
downloadmpv-5d44cf93df47046c779fc4da68a09812a2ce4004.tar.bz2
mpv-5d44cf93df47046c779fc4da68a09812a2ce4004.tar.xz
vo: use mp_poll wrapper in wait_events when applicable
On linux, several platforms poll for events over a fd. This has ms accuracy, but mpv's timer is in ns now so lots of precision is lost. We can use an mp_poll wrapper to use ppoll instead which takes a timespec directly with nanosecond precision. On systems without ppoll this falls back to old poll behavior. On wayland, we don't actually use this because ppoll completely messes up the event loop for some unknown reason.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/poll_wrapper.c11
-rw-r--r--osdep/poll_wrapper.h5
2 files changed, 16 insertions, 0 deletions
diff --git a/osdep/poll_wrapper.c b/osdep/poll_wrapper.c
index e4ad0f698a..48a66d2cd1 100644
--- a/osdep/poll_wrapper.c
+++ b/osdep/poll_wrapper.c
@@ -20,9 +20,20 @@
#include <sys/select.h>
#include <stdio.h>
+#include "config.h"
#include "poll_wrapper.h"
+#include "timer.h"
+int mp_poll(struct pollfd *fds, int nfds, int64_t timeout_ns)
+{
+#if HAVE_PPOLL
+ struct timespec ts = mp_time_ns_to_realtime(timeout_ns);
+ return ppoll(fds, nfds, &ts, NULL);
+#endif
+ return poll(fds, nfds, timeout_ns / 1e6);
+}
+
// poll shim that supports device files on macOS.
int polldev(struct pollfd fds[], nfds_t nfds, int timeout)
{
diff --git a/osdep/poll_wrapper.h b/osdep/poll_wrapper.h
index 8593c1e77c..b359ed39a0 100644
--- a/osdep/poll_wrapper.h
+++ b/osdep/poll_wrapper.h
@@ -1,7 +1,12 @@
#pragma once
#include <poll.h>
+#include <stdint.h>
// Behaves like poll(3) but works for device files on macOS.
// Only supports POLLIN and POLLOUT.
int polldev(struct pollfd fds[], nfds_t nfds, int timeout);
+
+// Generic polling wrapper. It will try and use higher resolution
+// polling (ppoll) if available.
+int mp_poll(struct pollfd *fds, int nfds, int64_t timeout_ns);