summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--audio/out/ao_wasapi_utils.c6
-rw-r--r--osdep/timer-darwin.c5
-rw-r--r--osdep/timer-linux.c8
-rw-r--r--osdep/timer-win2.c12
-rw-r--r--osdep/timer.h6
-rw-r--r--video/out/opengl/hwdec_dxva2egl.c6
-rw-r--r--video/out/vo_null.c8
-rw-r--r--video/out/vo_x11.c2
-rw-r--r--video/out/vo_xv.c2
9 files changed, 27 insertions, 28 deletions
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index 07c7ddb43f..6c5bfb3ab1 100644
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -945,7 +945,7 @@ bool wasapi_thread_init(struct ao *ao)
{
struct wasapi_state *state = ao->priv;
MP_DBG(ao, "Init wasapi thread\n");
- int64_t retry_wait = 1;
+ int64_t retry_wait = 1000;
bool align_hack = false;
HRESULT hr;
@@ -1028,13 +1028,13 @@ retry:
goto retry;
case AUDCLNT_E_DEVICE_IN_USE:
case AUDCLNT_E_DEVICE_INVALIDATED:
- if (retry_wait > 8) {
+ if (retry_wait > 8000) {
MP_FATAL(ao, "Bad device retry failed\n");
return false;
}
wasapi_thread_uninit(ao);
MP_WARN(ao, "Retrying in %"PRId64" us\n", retry_wait);
- mp_sleep_us(retry_wait);
+ mp_sleep_ns(retry_wait);
retry_wait *= 2;
goto retry;
}
diff --git a/osdep/timer-darwin.c b/osdep/timer-darwin.c
index a114d0d727..bb8a9b4324 100644
--- a/osdep/timer-darwin.c
+++ b/osdep/timer-darwin.c
@@ -28,10 +28,9 @@
static double timebase_ratio_ns;
-void mp_sleep_us(int64_t us)
+void mp_sleep_ns(int64_t ns)
{
- uint64_t deadline = us * 1e3 / timebase_ratio_ns + mach_absolute_time();
-
+ uint64_t deadline = ns / timebase_ratio_ns + mach_absolute_time();
mach_wait_until(deadline);
}
diff --git a/osdep/timer-linux.c b/osdep/timer-linux.c
index 0289233695..ff4b137cb2 100644
--- a/osdep/timer-linux.c
+++ b/osdep/timer-linux.c
@@ -22,13 +22,13 @@
#include <time.h>
#include "timer.h"
-void mp_sleep_us(int64_t us)
+void mp_sleep_ns(int64_t ns)
{
- if (us < 0)
+ if (ns < 0)
return;
struct timespec ts;
- ts.tv_sec = us / 1000000;
- ts.tv_nsec = (us % 1000000) * 1000;
+ ts.tv_sec = ns / UINT64_C(1000000000);
+ ts.tv_nsec = ns % UINT64_C(1000000000);
nanosleep(&ts, NULL);
}
diff --git a/osdep/timer-win2.c b/osdep/timer-win2.c
index dd7a42f0d1..db4c39d7ef 100644
--- a/osdep/timer-win2.c
+++ b/osdep/timer-win2.c
@@ -52,17 +52,17 @@ void mp_end_hires_timers(int res_ms)
#endif
}
-void mp_sleep_us(int64_t us)
+void mp_sleep_ns(int64_t ns)
{
- if (us < 0)
+ if (ns < 0)
return;
// Sleep(0) won't sleep for one clocktick as the unix usleep
// instead it will only make the thread ready
// it may take some time until it actually starts to run again
- if (us < 1000)
- us = 1000;
- int hrt = mp_start_hires_timers(us / 1000);
- Sleep(us / 1000);
+ if (ns < 1e6)
+ ns = 1e6;
+ int hrt = mp_start_hires_timers(ns / 1e6);
+ Sleep(ns / 1e6);
mp_end_hires_timers(hrt);
}
diff --git a/osdep/timer.h b/osdep/timer.h
index d76ad16129..b273cb405e 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -29,7 +29,7 @@ int64_t mp_time_us(void);
// Return time in nanoseconds. Never wraps. Never returns 0 or negative values.
int64_t mp_time_ns(void);
-// Return time in seconds. Can have down to 1 microsecond resolution, but will
+// Return time in seconds. Can have down to 1 nanosecond resolution, but will
// be much worse when casted to float.
double mp_time_sec(void);
@@ -37,8 +37,8 @@ double mp_time_sec(void);
void mp_raw_time_init(void);
uint64_t mp_raw_time_ns(void);
-// Sleep in microseconds.
-void mp_sleep_us(int64_t us);
+// Sleep in nanoseconds.
+void mp_sleep_ns(int64_t ns);
#ifdef _WIN32
// returns: timer resolution in ms if needed and started successfully, else 0
diff --git a/video/out/opengl/hwdec_dxva2egl.c b/video/out/opengl/hwdec_dxva2egl.c
index d870d982cd..0ca10ef7af 100644
--- a/video/out/opengl/hwdec_dxva2egl.c
+++ b/video/out/opengl/hwdec_dxva2egl.c
@@ -343,7 +343,7 @@ static int mapper_map(struct ra_hwdec_mapper *mapper)
// of the above StretchRect. Timeout of 8ms is required to reliably
// render 4k on Intel Haswell, Ivybridge and Cherry Trail Atom.
const int max_retries = 8;
- const int64_t wait_us = 1000;
+ const int64_t wait_ns = 1e6;
int retries = 0;
while (true) {
hr = IDirect3DQuery9_GetData(p->query9, NULL, 0, D3DGETDATA_FLUSH);
@@ -353,10 +353,10 @@ static int mapper_map(struct ra_hwdec_mapper *mapper)
} else if (hr == S_FALSE) {
if (++retries > max_retries) {
MP_VERBOSE(mapper, "Failed to flush frame after %lld ms\n",
- (long long)(wait_us * max_retries) / 1000);
+ (long long)(wait_ns * max_retries) / 1e6);
break;
}
- mp_sleep_us(wait_us);
+ mp_sleep_ns(wait_ns);
} else {
break;
}
diff --git a/video/out/vo_null.c b/video/out/vo_null.c
index 2aa46f785f..0c49062e23 100644
--- a/video/out/vo_null.c
+++ b/video/out/vo_null.c
@@ -40,14 +40,14 @@ static void flip_page(struct vo *vo)
{
struct priv *p = vo->priv;
if (p->cfg_fps) {
- int64_t ft = 1e6 / p->cfg_fps;
- int64_t prev_vsync = mp_time_us() / ft;
+ int64_t ft = 1e9 / p->cfg_fps;
+ int64_t prev_vsync = mp_time_ns() / ft;
int64_t target_time = (prev_vsync + 1) * ft;
for (;;) {
- int64_t now = mp_time_us();
+ int64_t now = mp_time_ns();
if (now >= target_time)
break;
- mp_sleep_us(target_time - now);
+ mp_sleep_ns(target_time - now);
}
}
}
diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c
index 9775b23948..1087fc249e 100644
--- a/video/out/vo_x11.c
+++ b/video/out/vo_x11.c
@@ -299,7 +299,7 @@ static void wait_for_completion(struct vo *vo, int max_outstanding)
" for XShm completion events...\n");
ctx->Shm_Warned_Slow = 1;
}
- mp_sleep_us(1000);
+ mp_sleep_ns(1e6);
vo_x11_check_events(vo);
}
}
diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c
index 22bce03770..cffd3a797f 100644
--- a/video/out/vo_xv.c
+++ b/video/out/vo_xv.c
@@ -670,7 +670,7 @@ static void wait_for_completion(struct vo *vo, int max_outstanding)
" for XShm completion events...\n");
ctx->Shm_Warned_Slow = 1;
}
- mp_sleep_us(1000);
+ mp_sleep_ns(1e6);
vo_x11_check_events(vo);
}
}