From e99393520e3da548d1a4e398ba7ce24e24e0dc5c Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Fri, 7 Oct 2022 11:46:29 -0300 Subject: [PATCH] videorate: Do not close segment when getting a same segment twice Part-of: --- .../gst-plugins-base/gst/videorate/gstvideorate.c | 69 +++++++++++----------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/subprojects/gst-plugins-base/gst/videorate/gstvideorate.c b/subprojects/gst-plugins-base/gst/videorate/gstvideorate.c index bf3fbb8..c41b6fa 100644 --- a/subprojects/gst-plugins-base/gst/videorate/gstvideorate.c +++ b/subprojects/gst-plugins-base/gst/videorate/gstvideorate.c @@ -961,40 +961,49 @@ gst_video_rate_sink_event (GstBaseTransform * trans, GstEvent * event) if (segment.format != GST_FORMAT_TIME) goto format_error; - rolled_back_caps = - gst_video_rate_rollback_to_prev_caps_if_needed (videorate); + segment.start = (gint64) (segment.start / videorate->rate); + segment.position = (gint64) (segment.position / videorate->rate); + if (GST_CLOCK_TIME_IS_VALID (segment.stop)) + segment.stop = (gint64) (segment.stop / videorate->rate); + segment.time = (gint64) (segment.time / videorate->rate); - /* close up the previous segment, if appropriate */ - if (videorate->prevbuf) { - /* fill up to the end of current segment */ - gint count = gst_video_rate_duplicate_to_close_segment (videorate); - if (count > 1) { - videorate->dup += count - 1; - if (!videorate->silent) - gst_video_rate_notify_duplicate (videorate); + + if (!gst_segment_is_equal (&segment, &videorate->segment)) { + rolled_back_caps = + gst_video_rate_rollback_to_prev_caps_if_needed (videorate); + + /* close up the previous segment, if appropriate */ + if (videorate->prevbuf) { + /* fill up to the end of current segment */ + gint count = gst_video_rate_duplicate_to_close_segment (videorate); + if (count > 1) { + videorate->dup += count - 1; + if (!videorate->silent) + gst_video_rate_notify_duplicate (videorate); + } + /* clean up for the new one; _chain will resume from the new start */ + gst_video_rate_swap_prev (videorate, NULL, 0); } - /* clean up for the new one; _chain will resume from the new start */ - gst_video_rate_swap_prev (videorate, NULL, 0); - } - if (rolled_back_caps) { - GST_DEBUG_OBJECT (videorate, - "Resetting rolled back caps %" GST_PTR_FORMAT, rolled_back_caps); - if (!gst_pad_send_event (GST_BASE_TRANSFORM_SINK_PAD (videorate), - gst_event_new_caps (rolled_back_caps) - )) { + if (rolled_back_caps) { + GST_DEBUG_OBJECT (videorate, + "Resetting rolled back caps %" GST_PTR_FORMAT, rolled_back_caps); + if (!gst_pad_send_event (GST_BASE_TRANSFORM_SINK_PAD (videorate), + gst_event_new_caps (rolled_back_caps) + )) { - GST_WARNING_OBJECT (videorate, "Could not resend caps after closing " - " segment"); + GST_WARNING_OBJECT (videorate, + "Could not resend caps after closing " " segment"); - GST_ELEMENT_ERROR (videorate, CORE, NEGOTIATION, - ("Could not resend caps after closing segment"), (NULL)); - gst_caps_unref (rolled_back_caps); + GST_ELEMENT_ERROR (videorate, CORE, NEGOTIATION, + ("Could not resend caps after closing segment"), (NULL)); + gst_caps_unref (rolled_back_caps); - return FALSE; - } + return FALSE; + } - gst_caps_unref (rolled_back_caps); + gst_caps_unref (rolled_back_caps); + } } videorate->base_ts = 0; @@ -1003,12 +1012,6 @@ gst_video_rate_sink_event (GstBaseTransform * trans, GstEvent * event) /* We just want to update the accumulated stream_time */ - segment.start = (gint64) (segment.start / videorate->rate); - segment.position = (gint64) (segment.position / videorate->rate); - if (GST_CLOCK_TIME_IS_VALID (segment.stop)) - segment.stop = (gint64) (segment.stop / videorate->rate); - segment.time = (gint64) (segment.time / videorate->rate); - gst_segment_copy_into (&segment, &videorate->segment); GST_DEBUG_OBJECT (videorate, "updated segment: %" GST_SEGMENT_FORMAT, &videorate->segment); -- 2.7.4