decklinkvideosink: Keep track of the time when we went to PLAYING for the external...
authorSebastian Dröge <sebastian@centricular.com>
Wed, 14 Jan 2015 14:54:28 +0000 (15:54 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 14 Jan 2015 15:00:54 +0000 (16:00 +0100)
Otherwise we're adding an offset of the time the pipeline was in PLAYING
already to the running time when converting it to our internal clock.

sys/decklink/gstdecklinkvideosink.cpp
sys/decklink/gstdecklinkvideosink.h

index 8c9c73f9428ed71d0ec944385f9cf3462d2eae01..69f8f3a6989bf2796e356368d1316f8491690089 100644 (file)
@@ -209,12 +209,12 @@ convert_to_internal_clock (GstDecklinkVideoSink * self,
     gst_clock_get_calibration (self->output->clock, &internal, &external,
         &rate_n, &rate_d);
 
-    if (rate_n != rate_d) {
+    if (rate_n != rate_d && self->internal_base_time != GST_CLOCK_TIME_NONE) {
       GstClockTime external_timestamp = *timestamp;
 
       // Convert to the running time corresponding to both clock times
       internal -= self->internal_base_time;
-      external -= gst_element_get_base_time (GST_ELEMENT_CAST (self));
+      external -= self->external_base_time;
 
       // Get the difference in the external time, note
       // that the running time is external time.
@@ -568,6 +568,8 @@ gst_decklink_video_sink_change_state (GstElement * element,
             (NULL), ("Failed to stop scheduled playback: 0x%08x", res));
         ret = GST_STATE_CHANGE_FAILURE;
       }
+      self->internal_base_time = GST_CLOCK_TIME_NONE;
+      self->external_base_time = GST_CLOCK_TIME_NONE;
       break;
     }
     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:{
@@ -584,8 +586,16 @@ gst_decklink_video_sink_change_state (GstElement * element,
       if (start_time == GST_CLOCK_TIME_NONE)
         start_time = 0;
 
+      // Current times of internal and external clock when we go to
+      // playing. We need this to convert the pipeline running time
+      // to the running time of the hardware
+      //
+      // We can't use the normal base time for the external clock
+      // because we might go to PLAYING later than the pipeline
       self->internal_base_time =
           gst_clock_get_internal_time (self->output->clock);
+      self->external_base_time =
+          gst_clock_get_internal_time (GST_ELEMENT_CLOCK (self));
 
       convert_to_internal_clock (self, &start_time, NULL);
 
index 6052feb5a78b488404c3799828cb880c0cdc1b0d..16b2fbb3fe498f0bca7448d16e0176de21bb60e3 100644 (file)
@@ -55,6 +55,7 @@ struct _GstDecklinkVideoSink
   GstVideoInfo info;
 
   GstClockTime internal_base_time;
+  GstClockTime external_base_time;
 
   GstDecklinkOutput *output;
 };