From f8fb72b0d76c465084b989acf77c6cb69c13d658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 27 Jun 2024 09:55:41 +0300 Subject: [PATCH] ajasrc: Drop some frames after signal recovery After signal recovery the capture times for the next frames are simply wrong. Experimentally this affected 2-3 frames and seemed to be related to the buffer fill level after signal recovery, so drop at least 5 frames and up to fill level + 1 frames in this situation. Part-of: --- .../gst-plugins-bad/sys/aja/gstajasrc.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/subprojects/gst-plugins-bad/sys/aja/gstajasrc.cpp b/subprojects/gst-plugins-bad/sys/aja/gstajasrc.cpp index 6ff1d1a618..d91333d2cc 100644 --- a/subprojects/gst-plugins-bad/sys/aja/gstajasrc.cpp +++ b/subprojects/gst-plugins-bad/sys/aja/gstajasrc.cpp @@ -2322,6 +2322,7 @@ static void capture_thread_func(AJAThread *thread, void *data) { bool reset_clock = false; GstClockTime first_frame_time = 0; guint64 first_frame_processed_plus_dropped_minus_buffered = 0; + guint frames_to_drop = 0; g_mutex_lock(&self->queue_lock); restart: @@ -2611,6 +2612,12 @@ restart: g_cond_signal(&self->queue_cond); have_signal = TRUE; reset_clock = true; + + // Drop the next frames after signal recovery as the capture times + // are generally just wrong. + frames_to_drop = MAX(status.acBufferLevel + 1, 5); + GST_TRACE_OBJECT(self, "Dropping %u frames after signal recovery", + frames_to_drop); } iterations_without_frame = 0; @@ -2692,6 +2699,16 @@ restart: continue; } + if (frames_to_drop > 0) { + GST_TRACE_OBJECT(self, "Dropping frame"); + frames_to_drop -= 1; + gst_clear_buffer(&anc_buffer2); + gst_clear_buffer(&anc_buffer); + gst_clear_buffer(&audio_buffer); + gst_clear_buffer(&video_buffer); + continue; + } + const AUTOCIRCULATE_TRANSFER_STATUS &transfer_status = transfer.GetTransferStatus(); const FRAME_STAMP &frame_stamp = transfer_status.GetFrameStamp();