From 8f432b2e37bd2d421c21f828e41973710dfb8118 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Wed, 11 Oct 2023 15:19:14 -0500 Subject: [PATCH] timer: remove microsecond timer functions With the previous series of commits, all internal usage has been replaced by the nanosecond functions. There's not really any point in keeping these around anymore plus there are macros for unit conversions now so we can just axe them. It's worth noting that mpv_get_time_us() obviously still needs to work for API reasons, but we can just divide mp_time_ns() by 1000 to get the same thing. --- osdep/timer.c | 22 ---------------------- osdep/timer.h | 10 ---------- player/client.c | 2 +- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/osdep/timer.c b/osdep/timer.c index 3e48329ba2..e939ef5dd5 100644 --- a/osdep/timer.c +++ b/osdep/timer.c @@ -48,11 +48,6 @@ void mp_time_init(void) pthread_once(&timer_init_once, do_timer_init); } -int64_t mp_time_us(void) -{ - return mp_time_ns() / 1000; -} - int64_t mp_time_ns(void) { uint64_t r = mp_raw_time_ns() - raw_time_offset; @@ -66,18 +61,6 @@ double mp_time_sec(void) return mp_time_ns() / 1e9; } -int64_t mp_time_us_add(int64_t time_us, double timeout_sec) -{ - assert(time_us > 0); // mp_time_us() returns strictly positive values - double t = MPCLAMP(timeout_sec * 1e6, -0x1p63, 0x1p63); - int64_t ti = t == 0x1p63 ? INT64_MAX : (int64_t)t; - if (ti > INT64_MAX - time_us) - return INT64_MAX; - if (ti <= -time_us) - return 1; - return time_us + ti; -} - int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec) { assert(time_ns > 0); // mp_time_ns() returns strictly positive values @@ -106,11 +89,6 @@ static int get_realtime(struct timespec *out_ts) } #endif -struct timespec mp_time_us_to_realtime(int64_t time_us) -{ - return mp_time_ns_to_realtime(MPMIN(INT64_MAX / 1000, time_us) * 1000); -} - struct timespec mp_time_ns_to_realtime(int64_t time_ns) { struct timespec ts = {0}; diff --git a/osdep/timer.h b/osdep/timer.h index 3d25055ff0..265e161ef2 100644 --- a/osdep/timer.h +++ b/osdep/timer.h @@ -23,9 +23,6 @@ // Initialize timer, must be called at least once at start. void mp_time_init(void); -// Return time in microseconds. Never wraps. Never returns 0 or negative values. -int64_t mp_time_us(void); - // Return time in nanoseconds. Never wraps. Never returns 0 or negative values. int64_t mp_time_ns(void); @@ -60,17 +57,10 @@ void mp_end_hires_timers(int resolution_ms); #define MP_TIME_NS_TO_MS(ns) ((ns) / (double)1000000) #define MP_TIME_NS_TO_US(ns) ((ns) / (double)1000) -// Add a time in seconds to the given time in microseconds, and return it. -// Takes care of possible overflows. Never returns a negative or 0 time. -int64_t mp_time_us_add(int64_t time_us, double timeout_sec); - // Add a time in seconds to the given time in nanoseconds, and return it. // Takes care of possible overflows. Never returns a negative or 0 time. int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec); -// Convert the mp time in microseconds to a timespec using CLOCK_REALTIME. -struct timespec mp_time_us_to_realtime(int64_t time_us); - // Convert the mp time in nanoseconds to a timespec using CLOCK_REALTIME. struct timespec mp_time_ns_to_realtime(int64_t time_ns); diff --git a/player/client.c b/player/client.c index 7117235852..cd0264e646 100644 --- a/player/client.c +++ b/player/client.c @@ -2136,7 +2136,7 @@ int64_t mpv_get_time_ns(mpv_handle *ctx) int64_t mpv_get_time_us(mpv_handle *ctx) { - return mp_time_us(); + return mp_time_ns() / 1000; } #include "video/out/libmpv.h"