rtsp-stream: Only create RTP sending/receiving rtpbin pads if needed

Adding them when not needed will start some logic inside rtpbin that might be
problematic. Also if e.g. for a sender media we suddenly receive RTP data, we
would start up a rtpjitterbuffer and behave in weird ways.

We still set up the UDP sources for RTP receiving for a sender media to be
able to receive any packets sent by the client for NAT traversal. They will
all go to a fakesink though.

Having an rtpjitterbuffer in the media pipeline will cause the pipeline to be
NO_PREROLL, which will cause deadlocks when seeking the media as it will never
receive ASYNC_DONE after a seek.

https://bugzilla.gnome.org/show_bug.cgi?id=758319
This commit is contained in:
Sebastian Dröge 2015-11-19 15:01:16 +02:00
parent cdc0849dfe
commit 61772cb326

View file

@ -2117,32 +2117,33 @@ gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
(GCallback) request_pt_map, stream);
}
/* get pads from the RTP session element for sending and receiving
* RTP/RTCP*/
if (priv->srcpad) {
/* get a pad for sending RTP */
name = g_strdup_printf ("send_rtp_sink_%u", idx);
priv->send_rtp_sink = gst_element_get_request_pad (rtpbin, name);
g_free (name);
if (priv->srcpad) {
/* link the RTP pad to the session manager, it should not really fail unless
* this is not really an RTP pad */
ret = gst_pad_link (priv->srcpad, priv->send_rtp_sink);
if (ret != GST_PAD_LINK_OK)
goto link_failed;
name = g_strdup_printf ("send_rtp_src_%u", idx);
priv->send_src[0] = gst_element_get_static_pad (rtpbin, name);
g_free (name);
} else {
/* Need to connect our sinkpad from here */
g_signal_connect (rtpbin, "pad-added", (GCallback) pad_added, stream);
/* EOS */
g_signal_connect (rtpbin, "on-npt-stop", (GCallback) on_npt_stop, stream);
}
/* get pads from the RTP session element for sending and receiving
* RTP/RTCP*/
name = g_strdup_printf ("send_rtp_src_%u", idx);
priv->send_src[0] = gst_element_get_static_pad (rtpbin, name);
g_free (name);
name = g_strdup_printf ("recv_rtp_sink_%u", idx);
priv->recv_sink[0] = gst_element_get_request_pad (rtpbin, name);
g_free (name);
}
name = g_strdup_printf ("send_rtcp_src_%u", idx);
priv->send_src[1] = gst_element_get_request_pad (rtpbin, name);
@ -2193,6 +2194,10 @@ gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
* When only UDP is allowed, we skip the tee, queue and appsink and link the
* udpsink directly to the session.
*/
/* Only link the RTP send src if we're going to send RTP, link
* the RTCP send src always */
if (priv->srcpad || i == 1) {
/* add udpsink */
gst_bin_add (bin, priv->udpsink[i]);
sinkpad = gst_element_get_static_pad (priv->udpsink[i], "sink");
@ -2209,7 +2214,8 @@ gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
priv->udpqueue[i] = gst_element_factory_make ("queue", NULL);
g_object_set (priv->udpqueue[i], "max-size-buffers",
1, "max-size-bytes", 0, "max-size-time", G_GINT64_CONSTANT (0), NULL);
1, "max-size-bytes", 0, "max-size-time", G_GINT64_CONSTANT (0),
NULL);
gst_bin_add (bin, priv->udpqueue[i]);
/* link tee to udpqueue */
teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
@ -2226,7 +2232,8 @@ gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
/* make queue */
priv->appqueue[i] = gst_element_factory_make ("queue", NULL);
g_object_set (priv->appqueue[i], "max-size-buffers",
1, "max-size-bytes", 0, "max-size-time", G_GINT64_CONSTANT (0), NULL);
1, "max-size-bytes", 0, "max-size-time", G_GINT64_CONSTANT (0),
NULL);
gst_bin_add (bin, priv->appqueue[i]);
/* and link to tee */
teepad = gst_element_get_request_pad (priv->tee[i], "src_%u");
@ -2253,7 +2260,11 @@ gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
gst_pad_link (priv->send_src[i], sinkpad);
}
gst_object_unref (sinkpad);
}
/* Only connect recv RTP sink if we expect to receive RTP. Connect recv
* RTCP sink always */
if (priv->sinkpad || i == 1) {
/* For the receiver we create this bit of pipeline for both
* RTP and RTCP. We receive RTP/RTCP on appsrc and udpsrc
* and it is all funneled into the rtpbin receive pad.
@ -2321,29 +2332,32 @@ gst_rtsp_stream_join_bin (GstRTSPStream * stream, GstBin * bin,
gst_object_unref (pad);
gst_object_unref (selpad);
}
}
/* check if we need to set to a special state */
if (state != GST_STATE_NULL) {
if (priv->udpsink[i])
if (priv->udpsink[i] && (priv->srcpad || i == 1))
gst_element_set_state (priv->udpsink[i], state);
if (priv->appsink[i])
if (priv->appsink[i] && (priv->srcpad || i == 1))
gst_element_set_state (priv->appsink[i], state);
if (priv->appqueue[i])
if (priv->appqueue[i] && (priv->srcpad || i == 1))
gst_element_set_state (priv->appqueue[i], state);
if (priv->udpqueue[i])
if (priv->udpqueue[i] && (priv->srcpad || i == 1))
gst_element_set_state (priv->udpqueue[i], state);
if (priv->tee[i])
if (priv->tee[i] && (priv->srcpad || i == 1))
gst_element_set_state (priv->tee[i], state);
if (priv->funnel[i])
if (priv->funnel[i] && (priv->sinkpad || i == 1))
gst_element_set_state (priv->funnel[i], state);
if (priv->appsrc[i])
if (priv->appsrc[i] && (priv->sinkpad || i == 1))
gst_element_set_state (priv->appsrc[i], state);
}
}
if (priv->srcpad) {
/* be notified of caps changes */
priv->caps_sig = g_signal_connect (priv->send_src[0], "notify::caps",
(GCallback) caps_notify, stream);
}
priv->is_joined = TRUE;
g_mutex_unlock (&priv->lock);
@ -2411,15 +2425,16 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
if (priv->srcpad) {
gst_pad_unlink (priv->srcpad, priv->send_rtp_sink);
g_signal_handler_disconnect (priv->send_src[0], priv->caps_sig);
gst_element_release_request_pad (rtpbin, priv->send_rtp_sink);
gst_object_unref (priv->send_rtp_sink);
priv->send_rtp_sink = NULL;
} else if (priv->recv_rtp_src) {
gst_pad_unlink (priv->recv_rtp_src, priv->sinkpad);
gst_object_unref (priv->recv_rtp_src);
priv->recv_rtp_src = NULL;
}
g_signal_handler_disconnect (priv->send_src[0], priv->caps_sig);
gst_element_release_request_pad (rtpbin, priv->send_rtp_sink);
gst_object_unref (priv->send_rtp_sink);
priv->send_rtp_sink = NULL;
for (i = 0; i < 2; i++) {
if (priv->udpsink[i])
@ -2436,7 +2451,7 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
gst_element_set_state (priv->funnel[i], GST_STATE_NULL);
if (priv->appsrc[i])
gst_element_set_state (priv->appsrc[i], GST_STATE_NULL);
if (priv->udpsrc_v4[i]) {
if (priv->udpsrc_v4[i] && (priv->sinkpad || i == 1)) {
/* and set udpsrc to NULL now before removing */
gst_element_set_locked_state (priv->udpsrc_v4[i], FALSE);
gst_element_set_state (priv->udpsrc_v4[i], GST_STATE_NULL);
@ -2444,7 +2459,7 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
* pads when they finalize */
gst_bin_remove (bin, priv->udpsrc_v4[i]);
}
if (priv->udpsrc_v6[i]) {
if (priv->udpsrc_v6[i] && (priv->sinkpad || i == 1)) {
gst_element_set_locked_state (priv->udpsrc_v6[i], FALSE);
gst_element_set_state (priv->udpsrc_v6[i], GST_STATE_NULL);
gst_bin_remove (bin, priv->udpsrc_v6[i]);
@ -2461,24 +2476,26 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
gst_bin_remove (bin, s->udpsrc[i]);
}
if (priv->udpsink[i])
if (priv->udpsink[i] && (priv->srcpad || i == 1))
gst_bin_remove (bin, priv->udpsink[i]);
if (priv->appsrc[i])
if (priv->appsrc[i] && (priv->sinkpad || i == 1))
gst_bin_remove (bin, priv->appsrc[i]);
if (priv->appsink[i])
if (priv->appsink[i] && (priv->srcpad || i == 1))
gst_bin_remove (bin, priv->appsink[i]);
if (priv->appqueue[i])
if (priv->appqueue[i] && (priv->srcpad || i == 1))
gst_bin_remove (bin, priv->appqueue[i]);
if (priv->udpqueue[i])
if (priv->udpqueue[i] && (priv->srcpad || i == 1))
gst_bin_remove (bin, priv->udpqueue[i]);
if (priv->tee[i])
if (priv->tee[i] && (priv->srcpad || i == 1))
gst_bin_remove (bin, priv->tee[i]);
if (priv->funnel[i])
if (priv->funnel[i] && (priv->sinkpad || i == 1))
gst_bin_remove (bin, priv->funnel[i]);
if (priv->sinkpad || i == 1) {
gst_element_release_request_pad (rtpbin, priv->recv_sink[i]);
gst_object_unref (priv->recv_sink[i]);
priv->recv_sink[i] = NULL;
}
priv->udpsrc_v4[i] = NULL;
priv->udpsrc_v6[i] = NULL;
@ -2498,8 +2515,10 @@ gst_rtsp_stream_leave_bin (GstRTSPStream * stream, GstBin * bin,
g_list_free (priv->transport_sources);
priv->transport_sources = NULL;
if (priv->srcpad) {
gst_object_unref (priv->send_src[0]);
priv->send_src[0] = NULL;
}
gst_element_release_request_pad (rtpbin, priv->send_src[1]);
gst_object_unref (priv->send_src[1]);