From a1443518e0e6dfbfe8ffca15fe520ba463ac72c5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 10 Jan 2020 11:40:54 +0200 Subject: [PATCH] timecodestamper: Clean up old LTC timecodes on LTC discontinuity We might have some old timecodes that are in the future now and have to drop those to make sure that our queue is correctly ordered and we don't have multiple timecodes for the same running time. --- gst/timecode/gsttimecodestamper.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/gst/timecode/gsttimecodestamper.c b/gst/timecode/gsttimecodestamper.c index f122e29..900c23f 100644 --- a/gst/timecode/gsttimecodestamper.c +++ b/gst/timecode/gsttimecodestamper.c @@ -1659,8 +1659,8 @@ gst_timecodestamper_ltcpad_chain (GstPad * pad, if (!timecodestamper->stream_align) { timecodestamper->stream_align = - gst_audio_stream_align_new (timecodestamper->ainfo.rate, GST_SECOND, - 40 * GST_MSECOND); + gst_audio_stream_align_new (timecodestamper->ainfo.rate, + 500 * GST_MSECOND, 20 * GST_MSECOND); } discont = @@ -1669,8 +1669,11 @@ gst_timecodestamper_ltcpad_chain (GstPad * pad, ×tamp, &duration, NULL); if (discont) { - if (timecodestamper->ltc_dec) + if (timecodestamper->ltc_dec) { + GST_WARNING_OBJECT (timecodestamper, "Got discont at %" GST_TIME_FORMAT, + GST_TIME_ARGS (timestamp)); ltc_decoder_queue_flush (timecodestamper->ltc_dec); + } timecodestamper->ltc_total = 0; } @@ -1750,8 +1753,26 @@ gst_timecodestamper_ltcpad_chain (GstPad * pad, 0, 0, timecodestamper->ltc_daily_jam, 0, stc.hours, stc.mins, stc.secs, stc.frame, 0); - g_queue_push_tail (&timecodestamper->ltc_current_tcs, - g_steal_pointer (<c_tc)); + /* If we have a discontinuity it might happen that we're getting + * timecodes that are in the past relative to timecodes we already have + * in our queue. We have to get rid of all the timecodes that are in the + * future now. */ + if (discont) { + TimestampedTimecode *tmp; + + while ((tmp = g_queue_peek_tail (&timecodestamper->ltc_current_tcs)) && + tmp->running_time >= ltc_running_time) { + gst_video_time_code_clear (&tmp->timecode); + g_free (tmp); + g_queue_pop_tail (&timecodestamper->ltc_current_tcs); + } + + g_queue_push_tail (&timecodestamper->ltc_current_tcs, + g_steal_pointer (<c_tc)); + } else { + g_queue_push_tail (&timecodestamper->ltc_current_tcs, + g_steal_pointer (<c_tc)); + } } } -- 2.7.4