diff mbox series

[FFmpeg-devel,v1] avutil/time: fix av_usleep() inaccurate on Windows

Message ID ME3P282MB18127E3698AF403A3A4E39DBC7BB0@ME3P282MB1812.AUSP282.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,v1] avutil/time: fix av_usleep() inaccurate on Windows | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

gaojiangjie@live.com Jan. 27, 2021, 3:45 a.m. UTC
From: Jiangjie Gao <gaojiangjie@live.com>

---
 libavutil/time.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavutil/time.c b/libavutil/time.c
index 740afc4785..dd04870983 100644
--- a/libavutil/time.c
+++ b/libavutil/time.c
@@ -90,7 +90,16 @@  int av_usleep(unsigned usec)
 #elif HAVE_USLEEP
     return usleep(usec);
 #elif HAVE_SLEEP
-    Sleep(usec / 1000);
+    if (usec > 10000) {
+        Sleep(usec / 1000);
+    } else {
+        LARGE_INTEGER t;
+        t.QuadPart = -(10 * (LONGLONG)usec);
+        HANDLE timer = CreateWaitableTimer(NULL, TRUE, NULL);
+        SetWaitableTimer(timer, &t, 0, NULL, NULL, 0);
+        WaitForSingleObject(timer, INFINITE);
+        CloseHandle(timer);
+    }
     return 0;
 #else
     return AVERROR(ENOSYS);