Commit 4c6cecf5 authored by Patricia Muscalu's avatar Patricia Muscalu Committed by Sebastian Dröge

stream: Choose the maximum ttl value provided by multicast clients

The maximum ttl value provided so far by the multicast clients
will be chosen and reported in the response to the current
client request.

Change-Id: I5408646e3b5a0a224d907ae215bdea60c4f1905f

https://bugzilla.gnome.org/show_bug.cgi?id=793441
parent 048e24a7
......@@ -1972,8 +1972,13 @@ default_configure_client_transport (GstRTSPClient * client,
if ((ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) &&
gst_rtsp_auth_check (GST_RTSP_AUTH_CHECK_TRANSPORT_CLIENT_SETTINGS) &&
(ct->destination != NULL))
(ct->destination != NULL)) {
if (!gst_rtsp_stream_verify_mcast_ttl (ctx->stream, ct->ttl))
goto error_ttl;
use_client_settings = TRUE;
}
/* We need to allocate the sockets for both families before starting
* multiudpsink, otherwise multiudpsink won't accept new clients with
......@@ -1990,14 +1995,29 @@ default_configure_client_transport (GstRTSPClient * client,
goto error_allocating_ports;
if (ct->lower_transport == GST_RTSP_LOWER_TRANS_UDP_MCAST) {
/* FIXME: the address has been successfully allocated, however, in
* the use_client_settings case we need to verify that the allocated
* address is the one requested by the client and if this address is
* an allowed destination. Verifying this via the address pool in not
* the proper way as the address pool should only be used for choosing
* the server-selected address/port pairs. */
if (!use_client_settings) {
if (use_client_settings) {
/* FIXME: the address has been successfully allocated, however, in
* the use_client_settings case we need to verify that the allocated
* address is the one requested by the client and if this address is
* an allowed destination. Verifying this via the address pool in not
* the proper way as the address pool should only be used for choosing
* the server-selected address/port pairs. */
GSocket *rtp_socket;
guint ttl;
rtp_socket =
gst_rtsp_stream_get_rtp_multicast_socket (ctx->stream, family);
if (rtp_socket == NULL)
goto no_socket;
ttl = g_socket_get_multicast_ttl (rtp_socket);
g_object_unref (rtp_socket);
if (ct->ttl < ttl) {
/* use the maximum ttl that is requested by multicast clients */
GST_DEBUG ("requested ttl %u, but keeping ttl %u", ct->ttl, ttl);
ct->ttl = ttl;
}
} else {
GstRTSPAddress *addr = NULL;
g_free (ct->destination);
......@@ -2062,6 +2082,12 @@ default_configure_client_transport (GstRTSPClient * client,
return TRUE;
/* ERRORS */
error_ttl:
{
GST_ERROR_OBJECT (client,
"Failed to allocate UDP ports: invalid ttl value");
return FALSE;
}
error_allocating_ports:
{
GST_ERROR_OBJECT (client, "Failed to allocate UDP ports");
......@@ -2072,6 +2098,11 @@ no_address:
GST_ERROR_OBJECT (client, "Failed to acquire address for stream");
return FALSE;
}
no_socket:
{
GST_ERROR_OBJECT (client, "Failed to get UDP socket");
return FALSE;
}
}
static GstRTSPTransport *
......
......@@ -1497,6 +1497,12 @@ again:
g_clear_object (&inetaddr);
if (multicast && (ct->ttl > 0) && (ct->ttl <= priv->max_mcast_ttl)) {
GST_DEBUG ("setting mcast ttl to %d", ct->ttl);
g_socket_set_multicast_ttl (rtp_socket, ct->ttl);
g_socket_set_multicast_ttl (rtcp_socket, ct->ttl);
}
socket_out[0] = rtp_socket;
socket_out[1] = rtcp_socket;
*server_addr_out = addr;
......@@ -2006,6 +2012,29 @@ gst_rtsp_stream_get_max_mcast_ttl (GstRTSPStream * stream)
return ttl;
}
/**
* gst_rtsp_stream_verify_mcast_ttl:
* @stream: a #GstRTSPStream
* @ttl: a requested multicast ttl
*
* Check if the requested multicast ttl value is allowed.
*
* Returns: TRUE if the requested ttl value is allowed.
*
*/
gboolean
gst_rtsp_stream_verify_mcast_ttl (GstRTSPStream * stream, guint ttl)
{
gboolean res = FALSE;
g_mutex_lock (&stream->priv->lock);
if ((ttl > 0) && (ttl <= stream->priv->max_mcast_ttl))
res = TRUE;
g_mutex_unlock (&stream->priv->lock);
return res;
}
/* executed from streaming thread */
static void
caps_notify (GstPad * pad, GParamSpec * unused, GstRTSPStream * stream)
......@@ -4058,7 +4087,6 @@ update_transport (GstRTSPStream * stream, GstRTSPStreamTransport * trans,
if (!check_mcast_part_for_transport (stream, tr))
goto mcast_error;
/* FIXME: Is it ok to set ttl-mc if media is shared? */
if (tr->ttl > 0) {
GST_INFO ("setting ttl-mc %d", tr->ttl);
if (priv->mcast_udpsink[0])
......
......@@ -298,6 +298,9 @@ gboolean gst_rtsp_stream_set_max_mcast_ttl (GstRTSPStream *strea
GST_RTSP_SERVER_API
guint gst_rtsp_stream_get_max_mcast_ttl (GstRTSPStream *stream);
GST_RTSP_SERVER_API
gboolean gst_rtsp_stream_verify_mcast_ttl (GstRTSPStream *stream, guint ttl);
GST_RTSP_SERVER_API
gboolean gst_rtsp_stream_complete_stream (GstRTSPStream * stream, const GstRTSPTransport * transport);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment