[vlc-devel] [PATCH 1/3] player: refactor UpdateTimerState

Francois Cartegnie fcvlcdev at free.fr
Mon Dec 14 18:51:42 CET 2020


---
 src/player/timer.c | 55 ++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/src/player/timer.c b/src/player/timer.c
index 1be28b22f0..f6db96a0ed 100644
--- a/src/player/timer.c
+++ b/src/player/timer.c
@@ -178,43 +178,46 @@ vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
 {
     vlc_mutex_lock(&player->timer.lock);
 
-    if (state == VLC_PLAYER_TIMER_STATE_DISCONTINUITY)
-    {
-        assert(system_date == VLC_TICK_INVALID);
+    /* Discontinuity is signalled by all output clocks and the input.
+     * discard the event if it was already signalled or not on the good
+     * es_source. */
+    bool notify = false;
+    struct vlc_player_timer_source *bestsource = &player->timer.best_source;
 
-        /* Discontinuity is signalled by all output clocks and the input.
-         * discard the event if it was already signalled or not on the good
-         * es_source. */
-        bool signal_discontinuity = false;
-        for (size_t i = 0; i < VLC_PLAYER_TIMER_TYPE_COUNT; ++i)
-        {
-            struct vlc_player_timer_source *source = &player->timer.sources[i];
-            if (source->es == es_source
-             && source->point.system_date != VLC_TICK_INVALID)
+    switch(state)
+    {
+        case VLC_PLAYER_TIMER_STATE_DISCONTINUITY:
+            assert(system_date == VLC_TICK_INVALID);
+            for (size_t i = 0; i < VLC_PLAYER_TIMER_TYPE_COUNT; ++i)
             {
-                source->point.system_date = VLC_TICK_INVALID;
+                struct vlc_player_timer_source *source = &player->timer.sources[i];
+                if(source->es != es_source)
+                    continue;
                 /* signal discontinuity only on best source */
-                if (i == VLC_PLAYER_TIMER_TYPE_BEST)
-                    signal_discontinuity = true;
+                if(source->point.system_date != VLC_TICK_INVALID)
+                    notify = (bestsource->es == es_source);
+                source->point.system_date = VLC_TICK_INVALID;
             }
-        }
-        if (!signal_discontinuity)
-        {
-            vlc_mutex_unlock(&player->timer.lock);
-            return;
-        }
+            break;
+
+        case VLC_PLAYER_TIMER_STATE_PAUSED:
+        default:
+            assert(state == VLC_PLAYER_TIMER_STATE_PAUSED);
+            notify = true;
+            assert(system_date != VLC_TICK_INVALID);
+            break;
     }
-    else
+
+    if( !notify )
     {
-        assert(state == VLC_PLAYER_TIMER_STATE_PAUSED);
-        assert(system_date != VLC_TICK_INVALID);
+        vlc_mutex_unlock(&player->timer.lock);
+        return;
     }
 
     player->timer.state = state;
 
-    struct vlc_player_timer_source *source = &player->timer.best_source;
     vlc_player_timer_id *timer;
-    vlc_list_foreach(timer, &source->listeners, node)
+    vlc_list_foreach(timer, &bestsource->listeners, node)
     {
         timer->last_update_date = VLC_TICK_INVALID;
         timer->cbs->on_discontinuity(system_date, timer->data);
-- 
2.26.2



More information about the vlc-devel mailing list