summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-11-08 22:49:17 -0600
committerDudemanguy <random342@airmail.cc>2023-11-09 21:31:58 +0000
commit7d86807a5f71989e944269fa430f36f2f32b1d65 (patch)
treedb940e26c2d2971cb3287ab987c89549b89fa78d /osdep
parenta89ba2c7497ca42f5b7e21144d5bf1a8da193654 (diff)
downloadmpv-7d86807a5f71989e944269fa430f36f2f32b1d65.tar.bz2
mpv-7d86807a5f71989e944269fa430f36f2f32b1d65.tar.xz
vo: don't sleep 1ms always when requested time is in the past
Fixes a899e14b which changed clamp from 0 to 1 ms which effectivelly introduced 1ms sleep always, even if requested until_time_ns is in the past and should request 0 timeout. While at it also fix mp_poll wrapper to respect negative timeout which should mean infinite wait. Also keep the 37d6604 behaviour for very short timeouts, but round only the ones > 100us, anything else is 0. Fixes: a899e14b
Diffstat (limited to 'osdep')
-rw-r--r--osdep/poll_wrapper.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/osdep/poll_wrapper.c b/osdep/poll_wrapper.c
index 9f8885fd1c..3fe039b4c1 100644
--- a/osdep/poll_wrapper.c
+++ b/osdep/poll_wrapper.c
@@ -20,6 +20,7 @@
#include <sys/select.h>
#include <stdio.h>
+#include "common/common.h"
#include "config.h"
#include "poll_wrapper.h"
#include "timer.h"
@@ -31,9 +32,15 @@ int mp_poll(struct pollfd *fds, int nfds, int64_t timeout_ns)
struct timespec ts;
ts.tv_sec = timeout_ns / MP_TIME_S_TO_NS(1);
ts.tv_nsec = timeout_ns % MP_TIME_S_TO_NS(1);
- return ppoll(fds, nfds, &ts, NULL);
+ struct timespec *tsp = timeout_ns >= 0 ? &ts : NULL;
+ return ppoll(fds, nfds, tsp, NULL);
#endif
- return poll(fds, nfds, timeout_ns / 1e6);
+ // Round-up to 1ms for short timeouts (100us, 1000us]
+ if (timeout_ns > MP_TIME_US_TO_NS(100))
+ timeout_ns = MPMAX(timeout_ns, MP_TIME_MS_TO_NS(1));
+ if (timeout_ns > 0)
+ timeout_ns /= MP_TIME_MS_TO_NS(1);
+ return poll(fds, nfds, timeout_ns);
}
// poll shim that supports device files on macOS.