diff options
author | Patricia Muscalu <patricia@axis.com> | 2015-11-20 15:34:43 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2016-02-23 17:05:15 +0200 |
commit | c0cadc6ec3a4b81506d6cc19f72cc9be1f91f064 (patch) | |
tree | c738540505bb4d5634191691ae47a0824ab41198 | |
parent | b26c16c82414e62f1d83209d695d411a155cf2cd (diff) |
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
-rw-r--r-- | gst/rtsp-server/rtsp-stream.c | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/gst/rtsp-server/rtsp-stream.c b/gst/rtsp-server/rtsp-stream.c index 54ae71b..f305ea5 100644 --- a/gst/rtsp-server/rtsp-stream.c +++ b/gst/rtsp-server/rtsp-stream.c @@ -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 alloc_ports_one_family (GstRTSPStream * stream, GSocketFamily family, GstElement * udpsrc_out[2], GstRTSPRange * server_port_out, GstRTSPAddress ** server_addr_out) { GstRTSPStreamPrivate *priv = stream->priv; - GstStateChangeReturn ret; - GstElement *udpsrc0, *udpsrc1; GSocket *rtp_socket = NULL; GSocket *rtcp_socket; gint tmp_rtp, tmp_rtcp; @@ -1125,8 +1162,6 @@ alloc_ports_one_family (GstRTSPStream * stream, GSocketFamily family, GstRTSPAddressPool * pool; pool = priv->pool; - udpsrc0 = NULL; - udpsrc1 = NULL; count = 0; /* Start with random port */ @@ -1221,25 +1256,12 @@ again: g_clear_object (&inetaddr); - udpsrc0 = gst_element_factory_make ("udpsrc", NULL); - udpsrc1 = gst_element_factory_make ("udpsrc", NULL); - - if (udpsrc0 == NULL || udpsrc1 == NULL) + if (!create_and_configure_udpsources_one_family (udpsrc_out, rtp_socket, + rtcp_socket, family)) goto no_udp_protocol; - g_object_set (G_OBJECT (udpsrc0), "socket", rtp_socket, NULL); - g_object_set (G_OBJECT (udpsrc1), "socket", rtcp_socket, 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); + g_object_get (G_OBJECT (udpsrc_out[0]), "port", &rtpport, NULL); + g_object_get (G_OBJECT (udpsrc_out[1]), "port", &rtcpport, NULL); /* this should not happen... */ if (rtpport != tmp_rtp || rtcpport != tmp_rtcp) @@ -1251,11 +1273,6 @@ again: /* set RTP and RTCP sockets */ 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->max = rtcpport; @@ -1284,20 +1301,8 @@ socket_error: { goto cleanup; } -element_error: - { - goto 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) g_object_unref (inetaddr); g_list_free_full (rejected_addresses, |