From 3064a065af742113b0cfea874b4cf0da6c419b89 Mon Sep 17 00:00:00 2001 From: Marianna Smidth Buschle Date: Wed, 4 Aug 2021 14:22:09 +0200 Subject: [PATCH 1/4] Fix restart-ts for multiple listeners Fix invalid PTS/DTS for the case where there are multiple listeners with different stream-sync settings: fx one with restart-ts and the other with passthrough-ts. The restart-ts branch was invalidating the PTS and DTS which would also affect the other branch since the buffer wasn't ensured as writable. --- gst/interpipe/gstinterpipesrc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gst/interpipe/gstinterpipesrc.c b/gst/interpipe/gstinterpipesrc.c index 4d16267..632024b 100644 --- a/gst/interpipe/gstinterpipesrc.c +++ b/gst/interpipe/gstinterpipesrc.c @@ -671,6 +671,7 @@ gst_inter_pipe_src_push_buffer (GstInterPipeIListener * iface, GST_TIME_ARGS (GST_BUFFER_PTS (buffer))); } else if (GST_INTER_PIPE_SRC_RESTART_TIMESTAMP == src->stream_sync) { /* Remove the incoming timestamp to be generated according this basetime */ + buffer = gst_buffer_make_writable (buffer); GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE; GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE; } From 4d78cbaa0e8238b6edcb757ee5ccf687afe077a4 Mon Sep 17 00:00:00 2001 From: Marianna Smidth Buschle Date: Fri, 6 Aug 2021 11:01:27 +0200 Subject: [PATCH 2/4] Fix event queue handling Send all queued events with "timestamp < buffer timestamp" instead of just the 1st one before sending the buffer. Only the 1st event of the event queue with "timestamp < buffer timestamp" was being send before the buffer. But there could be several events in the queue that should sent before the buffer. Fixes https://github.com/RidgeRun/gst-interpipe/issues/96 The segment event was not being handled properly when using x264enc + mpegtsmux together with interpipesrc/sink. Which was causing 2 segment to be delivered to the mpegtsmux: 1st one generated by the interpipesrc (starting from zero) because no segment existed. 2nd coming from the x264 encoder (correcting the 1000 hours offset added by the encoder). The 1st segment resulted in all subsequent DTS being seen as invalid (backwards) by the muxer. This happened because the event queue contained the following: stream-start, segment, tag, tag, tag. All with timestamp 0. But only the stream-start was sent, then the 1st buffer, then the segment. Which caused the DTS issues. --- gst/interpipe/gstinterpipesrc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gst/interpipe/gstinterpipesrc.c b/gst/interpipe/gstinterpipesrc.c index 632024b..7b785f3 100644 --- a/gst/interpipe/gstinterpipesrc.c +++ b/gst/interpipe/gstinterpipesrc.c @@ -473,13 +473,14 @@ gst_inter_pipe_src_create (GstBaseSrc * base, guint64 offset, guint size, "Dequeue buffer %p with timestamp (PTS) %" GST_TIME_FORMAT, *buf, GST_TIME_ARGS (GST_BUFFER_PTS (*buf))); - if (!g_queue_is_empty (src->pending_serial_events)) { + while (!g_queue_is_empty (src->pending_serial_events)) { guint curr_bytes; /*Pending Serial Events Queue */ serial_event = g_queue_peek_head (src->pending_serial_events); GST_DEBUG_OBJECT (src, - "Got event with timestamp %" GST_TIME_FORMAT, + "Got event %s with timestamp %" GST_TIME_FORMAT, + GST_EVENT_TYPE_NAME (serial_event), GST_TIME_ARGS (GST_EVENT_TIMESTAMP (serial_event))); curr_bytes = gst_app_src_get_current_level_bytes (GST_APP_SRC (src)); @@ -495,6 +496,7 @@ gst_inter_pipe_src_create (GstBaseSrc * base, guint64 offset, guint size, GST_DEBUG_OBJECT (src, "Event %s timestamp is greater than the " "buffer timestamp, can't send serial event yet", GST_EVENT_TYPE_NAME (serial_event)); + break; } } From b261bf631eff793bdd941cd3069f268558f55fe9 Mon Sep 17 00:00:00 2001 From: Marianna Smidth Buschle Date: Mon, 9 Aug 2021 14:26:23 +0200 Subject: [PATCH 3/4] Fix segment handling in interpipesrc It was missing something like what is done in appsrc->create(): https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/blob/master/gst-libs/gst/app/gstappsrc.c#L1676 Related to https://github.com/RidgeRun/gst-interpipe/issues/96 --- gst/interpipe/gstinterpipesrc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gst/interpipe/gstinterpipesrc.c b/gst/interpipe/gstinterpipesrc.c index 7b785f3..2e712ed 100644 --- a/gst/interpipe/gstinterpipesrc.c +++ b/gst/interpipe/gstinterpipesrc.c @@ -491,7 +491,22 @@ gst_inter_pipe_src_create (GstBaseSrc * base, guint64 offset, guint size, GST_EVENT_TYPE_NAME (serial_event)); serial_event = g_queue_pop_head (src->pending_serial_events); - gst_pad_push_event (srcpad, serial_event); + + if (GST_EVENT_TYPE (serial_event) == GST_EVENT_SEGMENT) { + const GstSegment *segment = NULL; + + gst_event_parse_segment (serial_event, &segment); + g_assert (segment != NULL); + + GST_DEBUG_OBJECT (src, + "Update new segment %" GST_PTR_FORMAT, serial_event); + if (!gst_base_src_new_segment (base, segment)) { + GST_ERROR_OBJECT (src, + "Couldn't set new segment %" GST_PTR_FORMAT, serial_event); + } + } else { + gst_pad_push_event (srcpad, serial_event); + } } else { GST_DEBUG_OBJECT (src, "Event %s timestamp is greater than the " "buffer timestamp, can't send serial event yet", From ccbcb49f2893de4164530aec3e2f3d7a3dea0036 Mon Sep 17 00:00:00 2001 From: Marianna Smidth Buschle Date: Tue, 10 Aug 2021 14:10:50 +0200 Subject: [PATCH 4/4] Fix event timestamp calculation Prevent negative values --- gst/interpipe/gstinterpipesrc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gst/interpipe/gstinterpipesrc.c b/gst/interpipe/gstinterpipesrc.c index 2e712ed..c2bce9d 100644 --- a/gst/interpipe/gstinterpipesrc.c +++ b/gst/interpipe/gstinterpipesrc.c @@ -737,8 +737,11 @@ gst_inter_pipe_src_push_event (GstInterPipeIListener * iface, GstEvent * event, srcbasetime = gst_element_get_base_time (GST_ELEMENT (appsrc)); if (srcbasetime > basetime) { - GST_EVENT_TIMESTAMP (event) = - GST_EVENT_TIMESTAMP (event) - (srcbasetime - basetime); + if (GST_EVENT_TIMESTAMP (event) > (srcbasetime - basetime)) + GST_EVENT_TIMESTAMP (event) = + GST_EVENT_TIMESTAMP (event) - (srcbasetime - basetime); + else + GST_EVENT_TIMESTAMP (event) = 0; } else { GST_EVENT_TIMESTAMP (event) = GST_EVENT_TIMESTAMP (event) + (basetime - srcbasetime);