decklink: Add a clock epoch that is used as offset whenever restarting the clock
authorSebastian Dröge <sebastian@centricular.com>
Wed, 23 Sep 2015 13:56:26 +0000 (15:56 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 24 Sep 2015 07:32:36 +0000 (09:32 +0200)
Otherwise we're going to return times starting at 0 again after shutting down
an element for a specific input/output and then using it again later.

https://bugzilla.gnome.org/show_bug.cgi?id=755426

sys/decklink/gstdecklink.cpp
sys/decklink/gstdecklink.h
sys/decklink/gstdecklinkvideosink.cpp
sys/decklink/gstdecklinkvideosrc.cpp

index f3ddeb9..eb39bdb 100644 (file)
@@ -885,6 +885,7 @@ gst_decklink_clock_get_internal_time (GstClock * clock)
 
       self->input->clock_last_time = result;
     }
+    result += self->input->clock_epoch;
     g_mutex_unlock (&self->input->lock);
   } else if (self->output != NULL) {
     g_mutex_lock (&self->output->lock);
@@ -924,6 +925,7 @@ gst_decklink_clock_get_internal_time (GstClock * clock)
 
       self->output->clock_last_time = result;
     }
+    result += self->output->clock_epoch;
     g_mutex_unlock (&self->output->lock);
   } else {
     g_assert_not_reached ();
index b601e7c..353769f 100644 (file)
@@ -134,7 +134,7 @@ struct _GstDecklinkOutput {
   IDeckLink *device;
   IDeckLinkOutput *output;
   GstClock *clock;
-  GstClockTime clock_start_time, clock_last_time;
+  GstClockTime clock_start_time, clock_last_time, clock_epoch;
   GstClockTimeDiff clock_offset;
   gboolean started, clock_restart;
 
@@ -162,7 +162,7 @@ struct _GstDecklinkInput {
   IDeckLinkConfiguration *config;
   IDeckLinkAttributes *attributes;
   GstClock *clock;
-  GstClockTime clock_start_time, clock_offset, clock_last_time;
+  GstClockTime clock_start_time, clock_offset, clock_last_time, clock_epoch;
   gboolean started, clock_restart;
 
   /* Everything below protected by mutex */
index e1f520c..c50d09b 100644 (file)
@@ -558,6 +558,7 @@ gst_decklink_video_sink_open (GstBaseSink * bsink)
   self->output->start_scheduled_playback =
       gst_decklink_video_sink_start_scheduled_playback;
   self->output->clock_start_time = GST_CLOCK_TIME_NONE;
+  self->output->clock_epoch += self->output->clock_last_time;
   self->output->clock_last_time = 0;
   self->output->clock_offset = 0;
   g_mutex_unlock (&self->output->lock);
@@ -706,6 +707,7 @@ gst_decklink_video_sink_change_state (GstElement * element,
     case GST_STATE_CHANGE_READY_TO_PAUSED:
       g_mutex_lock (&self->output->lock);
       self->output->clock_start_time = GST_CLOCK_TIME_NONE;
+      self->output->clock_epoch += self->output->clock_last_time;
       self->output->clock_last_time = 0;
       self->output->clock_offset = 0;
       g_mutex_unlock (&self->output->lock);
@@ -746,6 +748,7 @@ gst_decklink_video_sink_change_state (GstElement * element,
       gst_clock_set_calibration (self->output->clock, 0, 0, 1, 1);
       g_mutex_lock (&self->output->lock);
       self->output->clock_start_time = GST_CLOCK_TIME_NONE;
+      self->output->clock_epoch += self->output->clock_last_time;
       self->output->clock_last_time = 0;
       self->output->clock_offset = 0;
       g_mutex_unlock (&self->output->lock);
index f15527b..915393e 100644 (file)
@@ -645,6 +645,7 @@ gst_decklink_video_src_open (GstDecklinkVideoSrc * self)
   self->input->got_video_frame = gst_decklink_video_src_got_frame;
   self->input->start_streams = gst_decklink_video_src_start_streams;
   self->input->clock_start_time = GST_CLOCK_TIME_NONE;
+  self->input->clock_epoch += self->input->clock_last_time;
   self->input->clock_last_time = 0;
   self->input->clock_offset = 0;
   g_mutex_unlock (&self->input->lock);
@@ -752,6 +753,7 @@ gst_decklink_video_src_change_state (GstElement * element,
     case GST_STATE_CHANGE_READY_TO_PAUSED:
       g_mutex_lock (&self->input->lock);
       self->input->clock_start_time = GST_CLOCK_TIME_NONE;
+      self->input->clock_epoch += self->input->clock_last_time;
       self->input->clock_last_time = 0;
       self->input->clock_offset = 0;
       g_mutex_unlock (&self->input->lock);
@@ -790,6 +792,7 @@ gst_decklink_video_src_change_state (GstElement * element,
       gst_clock_set_calibration (self->input->clock, 0, 0, 1, 1);
       g_mutex_lock (&self->input->lock);
       self->input->clock_start_time = GST_CLOCK_TIME_NONE;
+      self->input->clock_epoch += self->input->clock_last_time;
       self->input->clock_last_time = 0;
       self->input->clock_offset = 0;
       g_mutex_unlock (&self->input->lock);