[vlc-devel] [PATCH 02/17] clock: allow to return VLC_TICK_INVALID from convert calls

Thomas Guillem thomas at gllm.fr
Mon Feb 15 10:14:57 UTC 2021


For now, when the main clock is reset, vlc_clock_ConvertToSystem() won't
return VLC_TICK_INVALID since it will fallback to
vlc_clock_monotonic_to_system_locked() but this behavior will change in
next commits.
---
 src/clock/clock.c | 17 ++++++++++++++++-
 src/clock/clock.h | 12 ++++++++----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/clock/clock.c b/src/clock/clock.c
index cfbb5eb6f6d..32f6b573632 100644
--- a/src/clock/clock.c
+++ b/src/clock/clock.c
@@ -306,6 +306,8 @@ static vlc_tick_t vlc_clock_slave_update(vlc_clock_t *clock,
     vlc_tick_t computed = clock->to_system_locked(clock, system_now, ts, rate);
 
     vlc_mutex_unlock(&main_clock->lock);
+    if (computed == VLC_TICK_INVALID)
+        return computed;
 
     vlc_clock_on_update(clock, computed, ts, rate, frame_rate, frame_rate_base);
     return computed - system_now;
@@ -349,7 +351,11 @@ void vlc_clock_Wait(vlc_clock_t *clock, vlc_tick_t system_now, vlc_tick_t ts,
         if (main_clock->pause_date != VLC_TICK_INVALID)
             deadline = INT64_MAX;
         else
+        {
             deadline = clock->to_system_locked(clock, system_now, ts, rate);
+            if (deadline == VLC_TICK_INVALID)
+                break;
+        }
         deadline = __MIN(deadline, max_deadline);
 
         if (vlc_cond_timedwait(&main_clock->cond, &main_clock->lock, deadline))
@@ -508,16 +514,25 @@ vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t *clock, vlc_tick_t system_now,
     return system;
 }
 
-void vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock, vlc_tick_t system_now,
+int vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock, vlc_tick_t system_now,
                                     vlc_tick_t *ts_array, size_t ts_count,
                                     double rate)
 {
     vlc_clock_main_t *main_clock = clock->owner;
     vlc_mutex_lock(&main_clock->lock);
     for (size_t i = 0; i < ts_count; ++i)
+    {
         ts_array[i] = clock->to_system_locked(clock, system_now, ts_array[i],
                                               rate);
+        if (ts_array[i] == VLC_TICK_INVALID)
+        {
+            vlc_mutex_unlock(&main_clock->lock);
+            return VLC_EGENERIC;
+        }
+    }
     vlc_mutex_unlock(&main_clock->lock);
+
+    return VLC_SUCCESS;
 }
 
 static void vlc_clock_set_master_callbacks(vlc_clock_t *clock)
diff --git a/src/clock/clock.h b/src/clock/clock.h
index e7373391697..b852af0eb23 100644
--- a/src/clock/clock.h
+++ b/src/clock/clock.h
@@ -168,16 +168,20 @@ void vlc_clock_Wait(vlc_clock_t *clock, vlc_tick_t system_now, vlc_tick_t ts,
 
 /**
  * This function converts a timestamp from stream to system
- * @return the valid system time or INT64_MAX when the clock is paused
+ * @return the valid system time, INT64_MAX when the clock is paused or
+ * VLC_TICK_INVALID when the main clock is reset (the master source is flushed).
  */
 vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t *clock, vlc_tick_t system_now,
                                      vlc_tick_t ts, double rate);
 
 /**
  * This functon converts an array of timestamp from stream to system
+ *
+ * @return VLC_SUCCESS or VLC_EGENERIC if the clock is reset (the master source
+ * is flushed).
  */
-void vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock, vlc_tick_t system_now,
-                                    vlc_tick_t *ts_array, size_t ts_count,
-                                    double rate);
+int vlc_clock_ConvertArrayToSystem(vlc_clock_t *clock, vlc_tick_t system_now,
+                                   vlc_tick_t *ts_array, size_t ts_count,
+                                   double rate);
 
 #endif /*VLC_CLOCK_H*/
-- 
2.30.0



More information about the vlc-devel mailing list