[FFmpeg-devel] [PATCH v1] avutil/time: fix av_usleep() inaccurate on Windows
gaojiangjie at live.com
gaojiangjie at live.com
Wed Jan 27 05:45:16 EET 2021
From: Jiangjie Gao <gaojiangjie at live.com>
---
libavutil/time.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
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);
--
2.27.0.windows.1
More information about the ffmpeg-devel
mailing list