[vlc-commits] [Git][videolan/vlc][master] clock: check master points validity

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Sep 15 04:16:10 UTC 2022



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
96cc32c5 by Thomas Guillem at 2022-09-15T03:49:41+00:00
clock: check master points validity

Check that system and stream are increasing and check that the coeff is
arround 1.0.

In case of invalid update, reset the clock (moving average reset to
1.0) and update starting the current point (that triggered the warning).

We assume that the previous points were bad and not the current.

- - - - -


1 changed file:

- src/clock/clock.c


Changes:

=====================================
src/clock/clock.c
=====================================
@@ -29,6 +29,8 @@
 #include "clock.h"
 #include "clock_internal.h"
 
+#define COEFF_THRESHOLD 0.2 /* between 0.8 and 1.2 */
+
 struct vlc_clock_main_t
 {
     struct vlc_logger *logger;
@@ -144,11 +146,36 @@ static vlc_tick_t vlc_clock_master_update(vlc_clock_t *clock,
             if (rate == main_clock->rate)
             {
                 /* We have a reference so we can update coeff */
-                double instant_coeff = (system_now - main_clock->last.system)
-                                     / (double)(ts - main_clock->last.stream)
-                                     * rate;
-                AvgUpdate(&main_clock->coeff_avg, instant_coeff);
-                main_clock->coeff = AvgGet(&main_clock->coeff_avg);
+                vlc_tick_t system_diff = system_now - main_clock->last.system;
+                vlc_tick_t stream_diff = ts - main_clock->last.stream;
+
+                double instant_coeff = system_diff / (double) stream_diff * rate;
+
+                /* System and stream ts should be incrementing */
+                if (system_diff < 0 || stream_diff < 0)
+                {
+                    vlc_warning(main_clock->logger, "resetting master clock: "
+                                "decreasing ts: system: %"PRId64 ", stream: %" PRId64,
+                                system_diff, stream_diff);
+                    /* Reset and continue (calculate the offset from the
+                     * current point) */
+                    vlc_clock_main_reset(main_clock);
+                }
+                /* The instant coeff should always be around 1.0 */
+                else if (instant_coeff > 1.0 + COEFF_THRESHOLD
+                      || instant_coeff < 1.0 - COEFF_THRESHOLD)
+                {
+                    vlc_warning(main_clock->logger, "resetting master clock: "
+                                "coefficient too unstable: %f", instant_coeff);
+                    /* Reset and continue (calculate the offset from the
+                     * current point) */
+                    vlc_clock_main_reset(main_clock);
+                }
+                else
+                {
+                    AvgUpdate(&main_clock->coeff_avg, instant_coeff);
+                    main_clock->coeff = AvgGet(&main_clock->coeff_avg);
+                }
             }
         }
         else



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/96cc32c529002b1dd9f21afc86df1bb15adee818

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/96cc32c529002b1dd9f21afc86df1bb15adee818
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list