[vlc-devel] [PATCH 17/17] player: timer: send more update points during startup

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


Since points may be irregular during startup (now that they can be feed
from the input).
---
 src/player/player.h      |  3 +++
 src/player/timer.c       | 22 ++++++++++++++++++----
 test/src/player/player.c |  5 ++++-
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/player/player.h b/src/player/player.h
index 6dcc61ac558..9969b104094 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -29,6 +29,8 @@
 
 #include "input/input_internal.h"
 
+#define VLC_PLAYER_TIMER_UPDATE_COUNT_MIN 10
+
 struct vlc_player_track_priv
 {
     struct vlc_player_track t;
@@ -171,6 +173,7 @@ struct vlc_player_timer_id
     vlc_tick_t period;
     vlc_tick_t last_update_date;
     vlc_tick_t last_ts;
+    uint64_t   update_count;
 
     union
     {
diff --git a/src/player/timer.c b/src/player/timer.c
index 4ee870c76e2..3af475ed6f8 100644
--- a/src/player/timer.c
+++ b/src/player/timer.c
@@ -55,17 +55,28 @@ vlc_player_SendTimerSourceUpdates(vlc_player_t *player,
     {
         /* Respect refresh delay of the timer. Don't update when the ts point
          * decrease. It can happen for a very short time when switching clock
-         * sources (from input to master ES). */
+         * sources (from input to master ES). Send all update points at the
+         * beginning (point->update_count < VLC_PLAYER_TIMER_UPDATE_COUNT_MIN)
+         * since update points may be irregular during startup. Then, don't
+         * send update points more than one time per period (point->system_date
+         * - timer->last_update_date >= timer->period). */
         if (point->ts > timer->last_ts
          && (force_update || timer->period == VLC_TICK_INVALID
           || timer->last_update_date == VLC_TICK_INVALID
           || point->system_date == INT64_MAX /* always update when paused */
-          || point->system_date - timer->last_update_date >= timer->period))
+          || point->system_date - timer->last_update_date >= timer->period
+          || timer->update_count < VLC_PLAYER_TIMER_UPDATE_COUNT_MIN))
         {
             timer->cbs->on_update(point, timer->data);
             timer->last_ts = point->ts;
-            timer->last_update_date = point->system_date == INT64_MAX ?
-                                      VLC_TICK_INVALID : point->system_date;
+
+            if (point->system_date == INT64_MAX)
+                timer->last_update_date = VLC_TICK_INVALID;
+            else
+            {
+                timer->last_update_date = point->system_date;
+                timer->update_count++;
+            }
         }
     }
 }
@@ -228,6 +239,7 @@ vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
     vlc_list_foreach(timer, &bestsource->listeners, node)
     {
         timer->last_ts = timer->last_update_date = VLC_TICK_INVALID;
+        timer->update_count = 0;
         timer->cbs->on_discontinuity(system_date, timer->data);
     }
 
@@ -435,6 +447,7 @@ vlc_player_AddTimer(vlc_player_t *player, vlc_tick_t min_period,
         return NULL;
     timer->period = min_period;
     timer->last_ts = timer->last_update_date = VLC_TICK_INVALID;
+    timer->update_count = 0;
     timer->cbs = cbs;
     timer->data = data;
 
@@ -457,6 +470,7 @@ vlc_player_AddSmpteTimer(vlc_player_t *player,
         return NULL;
     timer->period = VLC_TICK_INVALID;
     timer->last_ts = timer->last_update_date = VLC_TICK_INVALID;
+    timer->update_count = 0;
     timer->smpte_cbs = cbs;
     timer->data = data;
 
diff --git a/test/src/player/player.c b/test/src/player/player.c
index 30f53ee8cd3..48b6a58c4ab 100644
--- a/test/src/player/player.c
+++ b/test/src/player/player.c
@@ -2348,9 +2348,12 @@ test_timers_playback(struct ctx *ctx, struct timer_state timers[],
             {
                 if (i == 1)
                     assert(prev_report->point.system_date == INT64_MAX);
-                else
+                else if (i > 10 /* VLC_PLAYER_TIMER_UPDATE_COUNT_MIN */)
+                {
+                    assert(MAX_UPDATE_COUNT > 10);
                     assert(report->point.system_date - prev_report->point.system_date
                            >= timer->delay);
+                }
             }
         }
     }
-- 
2.30.0



More information about the vlc-devel mailing list