rtsp-stream: fixed segmenation fault in _get_server_port()

Calling function gst_rtsp_stream_get_server_port() results in
segmenation fault in the RTP/RTSP/TCP case.
Port that the server will use to receive RTCP makes only
sense in the UDP case, however the function should handle
the TCP case in a nicer way.

https://bugzilla.gnome.org/show_bug.cgi?id=776345
This commit is contained in:
Patricia Muscalu 2017-01-09 14:12:05 +01:00 committed by Sebastian Dröge
parent b27e7c6b5b
commit f47e6ab9f6
2 changed files with 49 additions and 2 deletions

View file

@ -1525,15 +1525,20 @@ gst_rtsp_stream_get_server_port (GstRTSPStream * stream,
priv = stream->priv; priv = stream->priv;
g_return_if_fail (priv->joined_bin != NULL); g_return_if_fail (priv->joined_bin != NULL);
if (server_port) {
server_port->min = 0;
server_port->max = 0;
}
g_mutex_lock (&priv->lock); g_mutex_lock (&priv->lock);
if (family == G_SOCKET_FAMILY_IPV4) { if (family == G_SOCKET_FAMILY_IPV4 && priv->server_addr_v4) {
if (server_port) { if (server_port) {
server_port->min = priv->server_addr_v4->port; server_port->min = priv->server_addr_v4->port;
server_port->max = server_port->max =
priv->server_addr_v4->port + priv->server_addr_v4->n_ports - 1; priv->server_addr_v4->port + priv->server_addr_v4->n_ports - 1;
} }
} else { } else {
if (server_port) { if (server_port && priv->server_addr_v6) {
server_port->min = priv->server_addr_v6->port; server_port->min = priv->server_addr_v6->port;
server_port->max = server_port->max =
priv->server_addr_v6->port + priv->server_addr_v6->n_ports - 1; priv->server_addr_v6->port + priv->server_addr_v6->n_ports - 1;

View file

@ -385,6 +385,47 @@ GST_START_TEST (test_allocate_udp_ports_client_settings)
GST_END_TEST; GST_END_TEST;
GST_START_TEST (test_tcp_transport)
{
GstPad *srcpad;
GstElement *pay;
GstRTSPStream *stream;
GstBin *bin;
GstElement *rtpbin;
GstRTSPRange server_port;
srcpad = gst_pad_new ("testsrcpad", GST_PAD_SRC);
fail_unless (srcpad != NULL);
gst_pad_set_active (srcpad, TRUE);
pay = gst_element_factory_make ("rtpgstpay", "testpayloader");
fail_unless (pay != NULL);
stream = gst_rtsp_stream_new (0, pay, srcpad);
fail_unless (stream != NULL);
gst_object_unref (pay);
gst_object_unref (srcpad);
rtpbin = gst_element_factory_make ("rtpbin", "testrtpbin");
fail_unless (rtpbin != NULL);
bin = GST_BIN (gst_bin_new ("testbin"));
fail_unless (bin != NULL);
fail_unless (gst_bin_add (bin, rtpbin));
/* TCP transport */
gst_rtsp_stream_set_protocols (stream, GST_RTSP_LOWER_TRANS_TCP);
fail_unless (gst_rtsp_stream_join_bin (stream, bin, rtpbin, GST_STATE_NULL));
/* port that the server will use to receive RTCP makes only sense in the UDP
* case so verify that the received server port is 0 in the TCP case */
gst_rtsp_stream_get_server_port (stream, &server_port, G_SOCKET_FAMILY_IPV4);
fail_unless_equals_int (server_port.min, 0);
fail_unless_equals_int (server_port.max, 0);
fail_unless (gst_rtsp_stream_leave_bin (stream, bin, rtpbin));
gst_object_unref (bin);
gst_object_unref (stream);
}
GST_END_TEST;
static Suite * static Suite *
rtspstream_suite (void) rtspstream_suite (void)
{ {
@ -398,6 +439,7 @@ rtspstream_suite (void)
tcase_add_test (tc, test_multicast_address_and_unicast_udp); tcase_add_test (tc, test_multicast_address_and_unicast_udp);
tcase_add_test (tc, test_allocate_udp_ports_multicast); tcase_add_test (tc, test_allocate_udp_ports_multicast);
tcase_add_test (tc, test_allocate_udp_ports_client_settings); tcase_add_test (tc, test_allocate_udp_ports_client_settings);
tcase_add_test (tc, test_tcp_transport);
return s; return s;
} }