From 83a0c73dc078bb61bfdf6b476f436230bf4cd1dd Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 5 Mar 2010 13:47:33 +0100 Subject: [PATCH] multicast: always configure loop and ttl Also configure TTL and loop parameters when we add a client after initializing the sender. --- gst/udp/gstmultiudpsink.c | 123 +++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 55 deletions(-) diff --git a/gst/udp/gstmultiudpsink.c b/gst/udp/gstmultiudpsink.c index 54c2e4b..e828b6a 100644 --- a/gst/udp/gstmultiudpsink.c +++ b/gst/udp/gstmultiudpsink.c @@ -754,6 +754,67 @@ gst_multiudpsink_get_property (GObject * object, guint prop_id, GValue * value, } } +static gboolean +gst_multiudpsink_configure_client (GstMultiUDPSink * sink, + GstUDPClient * client) +{ + GST_DEBUG_OBJECT (sink, "configuring client %p", client); + + if (gst_udp_is_multicast (&client->theiraddr)) { + GST_DEBUG_OBJECT (sink, "we have a multicast client %p", client); + if (sink->auto_multicast) { + GST_DEBUG_OBJECT (sink, "autojoining group"); + if (gst_udp_join_group (*(client->sock), &client->theiraddr, NULL) + != 0) + goto join_group_failed; + } + GST_DEBUG_OBJECT (sink, "setting loop to %d", sink->loop); + if (gst_udp_set_loop (sink->sock, sink->loop) != 0) + goto loop_failed; + GST_DEBUG_OBJECT (sink, "setting ttl to %d", sink->ttl_mc); + if (gst_udp_set_ttl (sink->sock, sink->ttl_mc, TRUE) != 0) + goto ttl_failed; + } else { + GST_DEBUG_OBJECT (sink, "setting unicast ttl to %d", sink->ttl); + if (gst_udp_set_ttl (sink->sock, sink->ttl, FALSE) != 0) + goto ttl_failed; + } + return TRUE; + + /* ERRORS */ +join_group_failed: + { + gchar *errormessage = socket_last_error_message (); + int errorcode = socket_last_error_code (); + CLOSE_IF_REQUESTED (sink); + GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL), + ("Could not join multicast group (%d): %s", errorcode, errormessage)); + g_free (errormessage); + return FALSE; + } +ttl_failed: + { + gchar *errormessage = socket_last_error_message (); + int errorcode = socket_last_error_code (); + CLOSE_IF_REQUESTED (sink); + GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL), + ("Could not set TTL socket option (%d): %s", errorcode, errormessage)); + g_free (errormessage); + return FALSE; + } +loop_failed: + { + gchar *errormessage = socket_last_error_message (); + int errorcode = socket_last_error_code (); + CLOSE_IF_REQUESTED (sink); + GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL), + ("Could not set loopback socket option (%d): %s", + errorcode, errormessage)); + g_free (errormessage); + return FALSE; + } +} + /* create a socket for sending to remote machine */ static gboolean gst_multiudpsink_init_send (GstMultiUDPSink * sink) @@ -763,13 +824,16 @@ gst_multiudpsink_init_send (GstMultiUDPSink * sink) GstUDPClient *client; if (sink->sockfd == -1) { + GST_DEBUG_OBJECT (sink, "creating sockets"); /* create sender socket try IP6, fall back to IP4 */ if ((sink->sock = socket (AF_INET6, SOCK_DGRAM, 0)) == -1) if ((sink->sock = socket (AF_INET, SOCK_DGRAM, 0)) == -1) goto no_socket; + GST_DEBUG_OBJECT (sink, "have socket"); sink->externalfd = FALSE; } else { + GST_DEBUG_OBJECT (sink, "using configured socket"); /* we use the configured socket */ sink->sock = sink->sockfd; sink->externalfd = TRUE; @@ -789,20 +853,9 @@ gst_multiudpsink_init_send (GstMultiUDPSink * sink) set also ttl and multicast loopback delivery appropriately */ for (clients = sink->clients; clients; clients = g_list_next (clients)) { client = (GstUDPClient *) clients->data; - if (gst_udp_is_multicast (&client->theiraddr)) { - if (sink->auto_multicast) { - if (gst_udp_join_group (*(client->sock), &client->theiraddr, NULL) - != 0) - goto join_group_failed; - } - if (gst_udp_set_loop (sink->sock, sink->loop) != 0) - goto loop_failed; - if (gst_udp_set_ttl (sink->sock, sink->ttl_mc, TRUE) != 0) - goto ttl_failed; - } else { - if (gst_udp_set_ttl (sink->sock, sink->ttl, FALSE) != 0) - goto ttl_failed; - } + + if (!gst_multiudpsink_configure_client (sink, client)) + return FALSE; } return TRUE; @@ -827,37 +880,6 @@ no_broadcast: g_free (errormessage); return FALSE; } -join_group_failed: - { - gchar *errormessage = socket_last_error_message (); - int errorcode = socket_last_error_code (); - CLOSE_IF_REQUESTED (sink); - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL), - ("Could not join multicast group (%d): %s", errorcode, errormessage)); - g_free (errormessage); - return FALSE; - } -ttl_failed: - { - gchar *errormessage = socket_last_error_message (); - int errorcode = socket_last_error_code (); - CLOSE_IF_REQUESTED (sink); - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL), - ("Could not set TTL socket option (%d): %s", errorcode, errormessage)); - g_free (errormessage); - return FALSE; - } -loop_failed: - { - gchar *errormessage = socket_last_error_message (); - int errorcode = socket_last_error_code (); - CLOSE_IF_REQUESTED (sink); - GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL), - ("Could not set loopback socket option (%d): %s", - errorcode, errormessage)); - g_free (errormessage); - return FALSE; - } } static void @@ -886,16 +908,7 @@ gst_multiudpsink_add_internal (GstMultiUDPSink * sink, const gchar * host, client->connect_time = GST_TIMEVAL_TO_TIME (now); if (*client->sock > 0) { - /* check if its a multicast address */ - if (gst_udp_is_multicast (&client->theiraddr)) { - GST_DEBUG_OBJECT (sink, "multicast address detected"); - if (sink->auto_multicast) { - GST_DEBUG_OBJECT (sink, "joining multicast group"); - gst_udp_join_group (*(client->sock), &client->theiraddr, NULL); - } - } else { - GST_DEBUG_OBJECT (sink, "normal address detected"); - } + gst_multiudpsink_configure_client (sink, client); } if (lock) -- 2.7.4