Skip to content

Commit

Permalink
timer: remove microsecond timer functions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dudemanguy committed Oct 16, 2023
1 parent bb036c6 commit 8f432b2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 33 deletions.
22 changes: 0 additions & 22 deletions osdep/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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};
Expand Down
10 changes: 0 additions & 10 deletions osdep/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion player/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8f432b2

Please sign in to comment.