gstnetclockclient: signal lost sync if remote time resets
authorDanny Smith <dannys@axis.com>
Wed, 25 Apr 2018 12:30:51 +0000 (14:30 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 7 Dec 2021 13:45:30 +0000 (13:45 +0000)
When detecting the remote time has been reset which may occur if remote
device providing the clock server has been power reset, then clock is
no longer synced. Setting clock state will trigger a signal to client
informing on sync lost making it possibility to take appropriate action.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/975>

subprojects/gstreamer/libs/gst/net/gstnetclientclock.c

index 13ff013..62d840d 100644 (file)
@@ -143,6 +143,7 @@ struct _GstNetClientInternalClock
   GstClockTime rtt_avg;
   GstClockTime minimum_update_interval;
   GstClockTime last_remote_poll_interval;
+  GstClockTime remote_avg_old;
   guint skipped_updates;
   GstClockTime last_rtts[MEDIAN_PRE_FILTERING_WINDOW];
   gint last_rtts_missing;
@@ -229,6 +230,7 @@ gst_net_client_internal_clock_init (GstNetClientInternalClock * self)
   self->last_remote_poll_interval = GST_CLOCK_TIME_NONE;
   self->skipped_updates = 0;
   self->last_rtts_missing = MEDIAN_PRE_FILTERING_WINDOW;
+  self->remote_avg_old = 0;
 }
 
 static void
@@ -519,6 +521,20 @@ gst_net_client_internal_clock_observe_times (GstNetClientInternalClock * self,
       && GST_CLOCK_DIFF (time_before,
           remote_avg) < (GstClockTimeDiff) (max_discont));
 
+  /* Check if new remote_avg is less than before to detect if signal lost
+   * sync due to the remote clock has restarted. Then the new remote time will
+   * be less than the previous time which should not happen if increased in a
+   * monotonic way. Also, only perform this check on a synchronized clock to
+   * avoid startup issues.
+   */
+  if (synched) {
+    if (remote_avg < self->remote_avg_old) {
+      gst_clock_set_synced (GST_CLOCK (self), FALSE);
+    } else {
+      self->remote_avg_old = remote_avg;
+    }
+  }
+
   if (gst_clock_add_observation_unapplied (GST_CLOCK_CAST (self),
           local_avg, remote_avg, &r_squared, &internal_time, &external_time,
           &rate_num, &rate_den)) {