mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
rtsp-stream: added function for creating and configuring UDP sources
Code refactoring: create and configure UDP sources in a separate function. https://bugzilla.gnome.org/show_bug.cgi?id=757488
This commit is contained in:
parent
b26c16c824
commit
c0cadc6ec3
1 changed files with 43 additions and 38 deletions
|
@ -1104,14 +1104,51 @@ no_udp_protocol:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* must be called with lock */
|
||||||
|
static gboolean
|
||||||
|
create_and_configure_udpsources_one_family (GstElement * udpsrc_out[2],
|
||||||
|
GSocket * rtp_socket, GSocket * rtcp_socket, GSocketFamily family)
|
||||||
|
{
|
||||||
|
GstStateChangeReturn ret;
|
||||||
|
|
||||||
|
/* we keep these elements, we will further configure them when the
|
||||||
|
* client told us to really use the UDP ports. */
|
||||||
|
udpsrc_out[0] = gst_element_factory_make ("udpsrc", NULL);
|
||||||
|
udpsrc_out[1] = gst_element_factory_make ("udpsrc", NULL);
|
||||||
|
|
||||||
|
if (udpsrc_out[0] == NULL || udpsrc_out[1] == NULL)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
g_object_set (G_OBJECT (udpsrc_out[0]), "socket", rtp_socket, NULL);
|
||||||
|
g_object_set (G_OBJECT (udpsrc_out[1]), "socket", rtcp_socket, NULL);
|
||||||
|
|
||||||
|
ret = gst_element_set_state (udpsrc_out[0], GST_STATE_READY);
|
||||||
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
||||||
|
goto error;
|
||||||
|
ret = gst_element_set_state (udpsrc_out[1], GST_STATE_READY);
|
||||||
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
error:
|
||||||
|
{
|
||||||
|
if (udpsrc_out[0])
|
||||||
|
gst_object_unref (udpsrc_out[0]);
|
||||||
|
if (udpsrc_out[1])
|
||||||
|
gst_object_unref (udpsrc_out[1]);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
alloc_ports_one_family (GstRTSPStream * stream, GSocketFamily family,
|
alloc_ports_one_family (GstRTSPStream * stream, GSocketFamily family,
|
||||||
GstElement * udpsrc_out[2], GstRTSPRange * server_port_out,
|
GstElement * udpsrc_out[2], GstRTSPRange * server_port_out,
|
||||||
GstRTSPAddress ** server_addr_out)
|
GstRTSPAddress ** server_addr_out)
|
||||||
{
|
{
|
||||||
GstRTSPStreamPrivate *priv = stream->priv;
|
GstRTSPStreamPrivate *priv = stream->priv;
|
||||||
GstStateChangeReturn ret;
|
|
||||||
GstElement *udpsrc0, *udpsrc1;
|
|
||||||
GSocket *rtp_socket = NULL;
|
GSocket *rtp_socket = NULL;
|
||||||
GSocket *rtcp_socket;
|
GSocket *rtcp_socket;
|
||||||
gint tmp_rtp, tmp_rtcp;
|
gint tmp_rtp, tmp_rtcp;
|
||||||
|
@ -1125,8 +1162,6 @@ alloc_ports_one_family (GstRTSPStream * stream, GSocketFamily family,
|
||||||
GstRTSPAddressPool * pool;
|
GstRTSPAddressPool * pool;
|
||||||
|
|
||||||
pool = priv->pool;
|
pool = priv->pool;
|
||||||
udpsrc0 = NULL;
|
|
||||||
udpsrc1 = NULL;
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
/* Start with random port */
|
/* Start with random port */
|
||||||
|
@ -1221,25 +1256,12 @@ again:
|
||||||
|
|
||||||
g_clear_object (&inetaddr);
|
g_clear_object (&inetaddr);
|
||||||
|
|
||||||
udpsrc0 = gst_element_factory_make ("udpsrc", NULL);
|
if (!create_and_configure_udpsources_one_family (udpsrc_out, rtp_socket,
|
||||||
udpsrc1 = gst_element_factory_make ("udpsrc", NULL);
|
rtcp_socket, family))
|
||||||
|
|
||||||
if (udpsrc0 == NULL || udpsrc1 == NULL)
|
|
||||||
goto no_udp_protocol;
|
goto no_udp_protocol;
|
||||||
|
|
||||||
g_object_set (G_OBJECT (udpsrc0), "socket", rtp_socket, NULL);
|
g_object_get (G_OBJECT (udpsrc_out[0]), "port", &rtpport, NULL);
|
||||||
g_object_set (G_OBJECT (udpsrc1), "socket", rtcp_socket, NULL);
|
g_object_get (G_OBJECT (udpsrc_out[1]), "port", &rtcpport, NULL);
|
||||||
|
|
||||||
ret = gst_element_set_state (udpsrc0, GST_STATE_READY);
|
|
||||||
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
||||||
goto element_error;
|
|
||||||
ret = gst_element_set_state (udpsrc1, GST_STATE_READY);
|
|
||||||
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
||||||
goto element_error;
|
|
||||||
|
|
||||||
/* all fine, do port check */
|
|
||||||
g_object_get (G_OBJECT (udpsrc0), "port", &rtpport, NULL);
|
|
||||||
g_object_get (G_OBJECT (udpsrc1), "port", &rtcpport, NULL);
|
|
||||||
|
|
||||||
/* this should not happen... */
|
/* this should not happen... */
|
||||||
if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
|
if (rtpport != tmp_rtp || rtcpport != tmp_rtcp)
|
||||||
|
@ -1251,11 +1273,6 @@ again:
|
||||||
/* set RTP and RTCP sockets */
|
/* set RTP and RTCP sockets */
|
||||||
set_sockets_for_udpsinks (stream, rtp_socket, rtcp_socket, family);
|
set_sockets_for_udpsinks (stream, rtp_socket, rtcp_socket, family);
|
||||||
|
|
||||||
/* we keep these elements, we will further configure them when the
|
|
||||||
* client told us to really use the UDP ports. */
|
|
||||||
udpsrc_out[0] = udpsrc0;
|
|
||||||
udpsrc_out[1] = udpsrc1;
|
|
||||||
|
|
||||||
server_port_out->min = rtpport;
|
server_port_out->min = rtpport;
|
||||||
server_port_out->max = rtcpport;
|
server_port_out->max = rtcpport;
|
||||||
|
|
||||||
|
@ -1284,20 +1301,8 @@ socket_error:
|
||||||
{
|
{
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
element_error:
|
|
||||||
{
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
cleanup:
|
cleanup:
|
||||||
{
|
{
|
||||||
if (udpsrc0) {
|
|
||||||
gst_element_set_state (udpsrc0, GST_STATE_NULL);
|
|
||||||
gst_object_unref (udpsrc0);
|
|
||||||
}
|
|
||||||
if (udpsrc1) {
|
|
||||||
gst_element_set_state (udpsrc1, GST_STATE_NULL);
|
|
||||||
gst_object_unref (udpsrc1);
|
|
||||||
}
|
|
||||||
if (inetaddr)
|
if (inetaddr)
|
||||||
g_object_unref (inetaddr);
|
g_object_unref (inetaddr);
|
||||||
g_list_free_full (rejected_addresses,
|
g_list_free_full (rejected_addresses,
|
||||||
|
|
Loading…
Reference in a new issue