From da4c4d2ebd2473677045b85f923cb14349b1e60d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <kasper93@gmail.com>
Date: Fri, 15 Sep 2023 01:39:35 +0200
Subject: [PATCH] timer: rename mp_time_us_to_timespec to reflect what it
 actually does

---
 demux/demux.c            | 2 +-
 misc/dispatch.c          | 2 +-
 osdep/timer.c            | 6 +++---
 osdep/timer.h            | 2 +-
 player/client.c          | 2 +-
 test/test_utils.c        | 2 +-
 test/test_utils.h        | 2 +-
 video/out/cocoa_common.m | 2 +-
 video/out/vo.c           | 4 ++--
 9 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/demux/demux.c b/demux/demux.c
index 575ccc227d..0e125dc660 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -2557,7 +2557,7 @@ static void *demux_thread(void *pctx)
         if (thread_work(in))
             continue;
         pthread_cond_signal(&in->wakeup);
-        struct timespec until = mp_time_us_to_timespec(in->next_cache_update);
+        struct timespec until = mp_time_us_to_realtime(in->next_cache_update);
         pthread_cond_timedwait(&in->wakeup, &in->lock, &until);
     }
 
diff --git a/misc/dispatch.c b/misc/dispatch.c
index 0c3c574afa..e491b2a9b0 100644
--- a/misc/dispatch.c
+++ b/misc/dispatch.c
@@ -310,7 +310,7 @@ void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout)
                 item->completed = true;
             }
         } else if (queue->wait > 0 && !queue->interrupted) {
-            struct timespec ts = mp_time_us_to_timespec(queue->wait);
+            struct timespec ts = mp_time_us_to_realtime(queue->wait);
             if (pthread_cond_timedwait(&queue->cond, &queue->lock, &ts))
                 queue->wait = 0;
         } else {
diff --git a/osdep/timer.c b/osdep/timer.c
index 8a52823b0f..0943ab3871 100644
--- a/osdep/timer.c
+++ b/osdep/timer.c
@@ -85,7 +85,7 @@ static void get_realtime(struct timespec *out_ts)
 #endif
 }
 
-struct timespec mp_time_us_to_timespec(int64_t time_us)
+struct timespec mp_time_us_to_realtime(int64_t time_us)
 {
     struct timespec ts;
     get_realtime(&ts);
@@ -112,7 +112,7 @@ struct timespec mp_time_us_to_timespec(int64_t time_us)
 
 struct timespec mp_rel_time_to_timespec(double timeout_sec)
 {
-    return mp_time_us_to_timespec(mp_add_timeout(mp_time_us(), timeout_sec));
+    return mp_time_us_to_realtime(mp_add_timeout(mp_time_us(), timeout_sec));
 }
 
 #if 0
@@ -137,7 +137,7 @@ int main(void) {
 #if TEST_SLEEP
         mp_sleep_us(delay);
 #else
-        struct timespec ts = mp_time_us_to_timespec(r + delay);
+        struct timespec ts = mp_time_us_to_realtime(r + delay);
         pthread_cond_timedwait(&cnd, &mtx, &ts);
 #endif
         j = (mp_time_us() - r) - delay;
diff --git a/osdep/timer.h b/osdep/timer.h
index 8cc1d9dc27..b98c275697 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -55,7 +55,7 @@ void mp_end_hires_timers(int resolution_ms);
 int64_t mp_add_timeout(int64_t time_us, double timeout_sec);
 
 // Convert the mp time in microseconds to a timespec using CLOCK_REALTIME.
-struct timespec mp_time_us_to_timespec(int64_t time_us);
+struct timespec mp_time_us_to_realtime(int64_t time_us);
 
 // Convert the relative timeout in seconds to a timespec.
 // The timespec is absolute, using CLOCK_REALTIME.
diff --git a/player/client.c b/player/client.c
index 2a581a6bda..0f3a99f3f6 100644
--- a/player/client.c
+++ b/player/client.c
@@ -363,7 +363,7 @@ static int wait_wakeup(struct mpv_handle *ctx, int64_t end)
     pthread_mutex_unlock(&ctx->lock);
     pthread_mutex_lock(&ctx->wakeup_lock);
     if (!ctx->need_wakeup) {
-        struct timespec ts = mp_time_us_to_timespec(end);
+        struct timespec ts = mp_time_us_to_realtime(end);
         r = pthread_cond_timedwait(&ctx->wakeup, &ctx->wakeup_lock, &ts);
     }
     if (r == 0)
diff --git a/test/test_utils.c b/test/test_utils.c
index 92f083ffbe..b75fe839b1 100644
--- a/test/test_utils.c
+++ b/test/test_utils.c
@@ -111,5 +111,5 @@ void mp_set_avdict(AVDictionary **dict, char **kv) {};
 void mp_add_timeout(void) {};
 void mp_rel_time_to_timespec(void) {};
 void mp_time_us(void) {};
-void mp_time_us_to_timespec(void) {};
+void mp_time_us_to_realtime(void) {};
 #endif
diff --git a/test/test_utils.h b/test/test_utils.h
index b776dedf08..57c2d9c614 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -62,5 +62,5 @@ void mp_set_avdict(AVDictionary **dict, char **kv);
 void mp_add_timeout(void);
 void mp_rel_time_to_timespec(void);
 void mp_time_us(void);
-void mp_time_us_to_timespec(void);
+void mp_time_us_to_realtime(void);
 #endif
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index 5d5a423fe3..0827da6fc9 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -786,7 +786,7 @@ static void vo_cocoa_resize_redraw(struct vo *vo, int width, int height)
 
     // Wait until a new frame with the new size was rendered. For some reason,
     // Cocoa requires this to be done before drawRect() returns.
-    struct timespec e = mp_time_us_to_timespec(mp_add_timeout(mp_time_us(), 0.1));
+    struct timespec e = mp_time_us_to_realtime(mp_add_timeout(mp_time_us(), 0.1));
     while (s->frame_w != width && s->frame_h != height && s->vo_ready) {
         if (pthread_cond_timedwait(&s->wakeup, &s->lock, &e))
             break;
diff --git a/video/out/vo.c b/video/out/vo.c
index 7f57df2fe1..23f75e72d5 100644
--- a/video/out/vo.c
+++ b/video/out/vo.c
@@ -719,7 +719,7 @@ void vo_wait_default(struct vo *vo, int64_t until_time)
 
     pthread_mutex_lock(&in->lock);
     if (!in->need_wakeup) {
-        struct timespec ts = mp_time_us_to_timespec(until_time);
+        struct timespec ts = mp_time_us_to_realtime(until_time);
         pthread_cond_timedwait(&in->wakeup, &in->lock, &ts);
     }
     pthread_mutex_unlock(&in->lock);
@@ -867,7 +867,7 @@ void vo_wait_frame(struct vo *vo)
 static void wait_until(struct vo *vo, int64_t target)
 {
     struct vo_internal *in = vo->in;
-    struct timespec ts = mp_time_us_to_timespec(target);
+    struct timespec ts = mp_time_us_to_realtime(target);
     pthread_mutex_lock(&in->lock);
     while (target > mp_time_us()) {
         if (in->queued_events & VO_EVENT_LIVE_RESIZING)