decklink*src: Aggregate dropped frame/packet logging
authorGeorg Lippitsch <glippitsch@toolsonair.com>
Tue, 28 Nov 2017 12:44:18 +0000 (13:44 +0100)
committerSebastian Dröge <sebastian@centricular.com>
Sun, 25 Oct 2020 09:39:05 +0000 (11:39 +0200)
decklink*src currently prints a log entry for every dropped frame and
audio packet. That completely spams the logs.

This change aggregates information about dropped packets and only prints
a message once when dropping starts, and a summary when dropping ends.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/705

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/378>

sys/decklink/gstdecklinkaudiosrc.cpp
sys/decklink/gstdecklinkaudiosrc.h
sys/decklink/gstdecklinkvideosrc.cpp
sys/decklink/gstdecklinkvideosrc.h

index 2fef934c89b233bd28d22dc566d7943472dbaae5..779cbc8a42754d95de77cf8221c6d9f785a1aaea 100644 (file)
@@ -237,6 +237,10 @@ gst_decklink_audio_src_init (GstDecklinkAudioSrc * self)
   self->current_packets =
       gst_queue_array_new_for_struct (sizeof (CapturePacket),
       DEFAULT_BUFFER_SIZE);
+
+  self->skipped_last = 0;
+  self->skip_from_timestamp = GST_CLOCK_TIME_NONE;
+  self->skip_to_timestamp = GST_CLOCK_TIME_NONE;
 }
 
 void
@@ -526,25 +530,31 @@ gst_decklink_audio_src_got_packet (GstElement * element,
   if (!self->flushing) {
     CapturePacket p;
     guint skipped_packets = 0;
-    GstClockTime from_timestamp = GST_CLOCK_TIME_NONE;
-    GstClockTime to_timestamp = GST_CLOCK_TIME_NONE;
 
     while (gst_queue_array_get_length (self->current_packets) >=
         self->buffer_size) {
       CapturePacket *tmp = (CapturePacket *)
           gst_queue_array_pop_head_struct (self->current_packets);
-      if (skipped_packets == 0)
-        from_timestamp = tmp->timestamp;
+      if (skipped_packets == 0 && self->skipped_last == 0)
+        self->skip_from_timestamp = tmp->timestamp;
       skipped_packets++;
-      to_timestamp = tmp->timestamp;
+      self->skip_to_timestamp = tmp->timestamp;
       capture_packet_clear (tmp);
     }
 
-    if (skipped_packets > 0)
+    if (self->skipped_last == 0 && skipped_packets > 0) {
+        GST_WARNING_OBJECT (self, "Starting to drop audio packets");
+    }
+
+    if (skipped_packets == 0 && self->skipped_last > 0) {
       GST_WARNING_OBJECT (self,
           "Dropped %u old packets from %" GST_TIME_FORMAT " to %"
-          GST_TIME_FORMAT, skipped_packets, GST_TIME_ARGS (from_timestamp),
-          GST_TIME_ARGS (to_timestamp));
+          GST_TIME_FORMAT, self->skipped_last,
+          GST_TIME_ARGS (self->skip_from_timestamp),
+          GST_TIME_ARGS (self->skip_to_timestamp));
+      self->skipped_last = 0;
+    }
+    self->skipped_last += skipped_packets;
 
     memset (&p, 0, sizeof (p));
     p.packet = packet;
index 405da7ae5048e1b7c8d32fe80c4558494381aff7..fdb77b622c4b70529ff92ff5086bee180939ad46 100644 (file)
@@ -81,6 +81,10 @@ struct _GstDecklinkAudioSrc
   GstClockTime discont_time;
 
   guint buffer_size;
+
+  guint skipped_last;
+  GstClockTime skip_from_timestamp;
+  GstClockTime skip_to_timestamp;
 };
 
 struct _GstDecklinkAudioSrcClass
index b30f442fabfc149c2ee98ac32336cc0dd371bee3..e6e2989330817cb2a429ad9a4d74a3c0c071aed3 100644 (file)
@@ -408,6 +408,9 @@ gst_decklink_video_src_init (GstDecklinkVideoSrc * self)
   self->window_fill = 0;
   self->window_skip = 1;
   self->window_skip_count = 0;
+  self->skipped_last = 0;
+  self->skip_from_timestamp = GST_CLOCK_TIME_NONE;
+  self->skip_to_timestamp = GST_CLOCK_TIME_NONE;
 
   gst_base_src_set_live (GST_BASE_SRC (self), TRUE);
   gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_TIME);
@@ -837,27 +840,34 @@ gst_decklink_video_src_got_frame (GstElement * element,
     GstVideoTimeCodeFlags flags = GST_VIDEO_TIME_CODE_FLAGS_NONE;
     guint field_count = 0;
     guint skipped_frames = 0;
-    GstClockTime from_timestamp = GST_CLOCK_TIME_NONE;
-    GstClockTime to_timestamp = GST_CLOCK_TIME_NONE;
 
     while (gst_queue_array_get_length (self->current_frames) >=
         self->buffer_size) {
       CaptureFrame *tmp = (CaptureFrame *)
           gst_queue_array_pop_head_struct (self->current_frames);
       if (tmp->frame) {
-        if (skipped_frames == 0)
-          from_timestamp = tmp->timestamp;
+        if (skipped_frames == 0 && self->skipped_last == 0)
+          self->skip_from_timestamp = tmp->timestamp;
         skipped_frames++;
-        to_timestamp = tmp->timestamp;
+        self->skip_to_timestamp = tmp->timestamp;
       }
       capture_frame_clear (tmp);
     }
 
-    if (skipped_frames > 0)
+    if (self->skipped_last == 0 && skipped_frames > 0) {
+      GST_WARNING_OBJECT (self, "Starting to drop frames");
+    }
+
+    if (skipped_frames == 0 && self->skipped_last > 0) {
       GST_WARNING_OBJECT (self,
           "Dropped %u old frames from %" GST_TIME_FORMAT " to %"
-          GST_TIME_FORMAT, skipped_frames, GST_TIME_ARGS (from_timestamp),
-          GST_TIME_ARGS (to_timestamp));
+          GST_TIME_FORMAT, self->skipped_last,
+          GST_TIME_ARGS (self->skip_from_timestamp),
+          GST_TIME_ARGS (self->skip_to_timestamp));
+      self->skipped_last = 0;
+    }
+
+    self->skipped_last += skipped_frames;
 
     memset (&f, 0, sizeof (f));
     f.frame = frame;
index a56d6ca50c1881ace5d0fe512027fe500c2553bf..b4f0e7bbfcabbdec9ef51f566657e5ba5fcc95a6 100644 (file)
@@ -111,6 +111,10 @@ struct _GstDecklinkVideoSrc
   gboolean output_afd_bar;
   gint last_afd_bar_vbi_line;
   gint last_afd_bar_vbi_line_field2;
+
+  guint skipped_last;
+  GstClockTime skip_from_timestamp;
+  GstClockTime skip_to_timestamp;
 };
 
 struct _GstDecklinkVideoSrcClass