decklinkvideosink: Consider pipeline latency, render delay and ts offset when schedul...
authorSebastian Dröge <sebastian@centricular.com>
Mon, 7 Sep 2015 10:36:19 +0000 (13:36 +0300)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 9 Sep 2015 13:58:45 +0000 (16:58 +0300)
Without this, we will schedule all frames too late in live pipelines.

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

sys/decklink/gstdecklinkvideosink.cpp

index 9a7c6d4..6a701a3 100644 (file)
@@ -416,6 +416,7 @@ gst_decklink_video_sink_prepare (GstBaseSink * bsink, GstBuffer * buffer)
   HRESULT ret;
   GstClockTime timestamp, duration;
   GstClockTime running_time, running_time_duration;
+  GstClockTime latency, render_delay, ts_offset;
   gint i;
 
   GST_DEBUG_OBJECT (self, "Preparing buffer %p", buffer);
@@ -439,6 +440,28 @@ gst_decklink_video_sink_prepare (GstBaseSink * bsink, GstBuffer * buffer)
       gst_segment_to_running_time (&GST_BASE_SINK_CAST (self)->segment,
       GST_FORMAT_TIME, timestamp + duration) - running_time;
 
+  /* See gst_base_sink_adjust_time() */
+  latency = gst_base_sink_get_latency (bsink);
+  render_delay = gst_base_sink_get_render_delay (bsink);
+  ts_offset = gst_base_sink_get_ts_offset (bsink);
+
+  running_time += latency;
+
+  if (ts_offset < 0) {
+    ts_offset = -ts_offset;
+    if (ts_offset < running_time)
+      running_time -= ts_offset;
+    else
+      running_time = 0;
+  } else {
+    running_time += ts_offset;
+  }
+
+  if (running_time > render_delay)
+    running_time -= render_delay;
+  else
+    running_time = 0;
+
   ret = self->output->output->CreateVideoFrame (self->info.width,
       self->info.height, self->info.stride[0], bmdFormat8BitYUV,
       bmdFrameFlagDefault, &frame);