decklink: reset calculation of gst_decklink_video_src_update_time_mapping on no_signa...
authorWojciech Kapsa <wojciech.kapsa@medvc.eu>
Fri, 7 Oct 2022 06:30:05 +0000 (08:30 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 10 Oct 2022 08:13:30 +0000 (08:13 +0000)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3132>

subprojects/gst-plugins-bad/sys/decklink/gstdecklinkvideosrc.cpp
subprojects/gst-plugins-bad/sys/decklink/gstdecklinkvideosrc.h

index e3df97c..863e1f4 100644 (file)
@@ -155,6 +155,8 @@ GST_DEBUG_CATEGORY_STATIC (gst_decklink_video_src_debug);
 #define ABSDIFF(x, y) ( (x) > (y) ? ((x) - (y)) : ((y) - (x)) )
 #endif
 
+#define NO_SIGNL_RESET_COUNT (10)
+
 enum
 {
   PROP_0,
@@ -698,6 +700,23 @@ gst_decklink_video_src_start (GstDecklinkVideoSrc * self)
 }
 
 static void
+gst_decklink_reset_time_mapping(GstDecklinkVideoSrc * self)
+{
+    self->window_fill = 0;
+    self->window_filled = FALSE;
+    self->window_skip = 1;
+    self->window_skip_count = 0;
+    self->current_time_mapping.xbase = 0;
+    self->current_time_mapping.b = 0;
+    self->current_time_mapping.num = 1;
+    self->current_time_mapping.den = 1;
+    self->next_time_mapping.xbase = 0;
+    self->next_time_mapping.b = 0;
+    self->next_time_mapping.num = 1;
+    self->next_time_mapping.den = 1;
+}
+
+static void
 gst_decklink_video_src_update_time_mapping (GstDecklinkVideoSrc * self,
     GstClockTime capture_time, GstClockTime stream_time)
 {
@@ -837,6 +856,9 @@ gst_decklink_video_src_got_frame (GstElement * element,
     return;
   }
 
+  if (no_signal)
+    self->no_signal_count++;
+
   if (self->drop_no_signal_frames && no_signal) {
     CaptureFrame f;
     memset (&f, 0, sizeof (f));
@@ -849,6 +871,13 @@ gst_decklink_video_src_got_frame (GstElement * element,
     return;
   }
 
+  if (!no_signal) {
+    if (self->no_signal_count > NO_SIGNL_RESET_COUNT) {
+      gst_decklink_reset_time_mapping(self);
+    }
+    self->no_signal_count = 0;
+  }
+
   gst_decklink_video_src_update_time_mapping (self, capture_time, stream_time);
   if (self->output_stream_time) {
     timestamp = stream_time;
@@ -1736,4 +1765,4 @@ gst_decklink_video_src_change_state (GstElement * element,
 out:
 
   return ret;
-}
+}
\ No newline at end of file
index 03c455a..f43e838 100644 (file)
@@ -70,6 +70,7 @@ struct _GstDecklinkVideoSrc
   guint64 processed;
   guint64 dropped;
   guint64 first_stream_time;
+  guint64 no_signal_count;
 
   GstVideoInfo info;
   GstDecklinkVideoFormat video_format;