From 5699ada939bec5a1317d4a7d1fb6e0afd70fad7e Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Fri, 21 Aug 2020 03:02:40 +0200 Subject: [PATCH] rtsp-stream: preroll on gap events This allows negotiating a SDP with all streams present, but only start sending packets at some later point in time Part-of: --- gst/rtsp-server/rtsp-stream.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/gst/rtsp-server/rtsp-stream.c b/gst/rtsp-server/rtsp-stream.c index 7ef3511a72..fecb1839f7 100644 --- a/gst/rtsp-server/rtsp-stream.c +++ b/gst/rtsp-server/rtsp-stream.c @@ -5179,35 +5179,47 @@ pad_blocking (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) GstRTSPStreamPrivate *priv; GstRTSPStream *stream; GstBuffer *buffer = NULL; + GstPadProbeReturn ret = GST_PAD_PROBE_OK; stream = user_data; priv = stream->priv; - GST_DEBUG_OBJECT (pad, "now blocking"); - g_mutex_lock (&priv->lock); - priv->blocking = TRUE; if ((info->type & GST_PAD_PROBE_TYPE_BUFFER)) { buffer = gst_pad_probe_info_get_buffer (info); + priv->position = GST_BUFFER_TIMESTAMP (buffer); } else if ((info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST)) { GstBufferList *list = gst_pad_probe_info_get_buffer_list (info); buffer = gst_buffer_list_get (list, 0); + priv->position = GST_BUFFER_TIMESTAMP (buffer); + } else if ((info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM)) { + if (GST_EVENT_TYPE (info->data) == GST_EVENT_GAP) { + gst_event_parse_gap (info->data, &priv->position, NULL); + } else { + ret = GST_PAD_PROBE_PASS; + g_mutex_unlock (&priv->lock); + goto done; + } } else { g_assert_not_reached (); } - g_assert (buffer); - priv->position = GST_BUFFER_TIMESTAMP (buffer); - GST_DEBUG_OBJECT (stream, "buffer position: %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); + priv->blocking = TRUE; + + GST_DEBUG_OBJECT (pad, "Now blocking"); + + GST_DEBUG_OBJECT (stream, "position: %" GST_TIME_FORMAT, + GST_TIME_ARGS (priv->position)); + g_mutex_unlock (&priv->lock); gst_element_post_message (priv->payloader, gst_message_new_element (GST_OBJECT_CAST (priv->payloader), gst_structure_new_empty ("GstRTSPStreamBlocking"))); - return GST_PAD_PROBE_OK; +done: + return ret; } static void @@ -5233,7 +5245,8 @@ set_blocked (GstRTSPStream * stream, gboolean blocked) priv->blocking = FALSE; priv->blocked_id[i] = gst_pad_add_probe (priv->send_src[i], GST_PAD_PROBE_TYPE_BLOCK | GST_PAD_PROBE_TYPE_BUFFER | - GST_PAD_PROBE_TYPE_BUFFER_LIST, pad_blocking, + GST_PAD_PROBE_TYPE_BUFFER_LIST | + GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, pad_blocking, g_object_ref (stream), g_object_unref); } }