From 71c76e677a603525eb53fea92cc4b9407139097f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 15 Feb 2017 00:13:30 +0200 Subject: [PATCH] udpsrc: Use IP_MULTICAST_ALL for filtering IPv4 packets if available This goes around the inefficient control message based filtering and does all the filtering kernel-side. Unfortunately this is Linux-only and there is no IPv6 variant of it (yet). --- gst/udp/gstudpsrc.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gst/udp/gstudpsrc.c b/gst/udp/gstudpsrc.c index 1bbb4cb8ea..27045f497c 100644 --- a/gst/udp/gstudpsrc.c +++ b/gst/udp/gstudpsrc.c @@ -856,10 +856,16 @@ gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf) if (!gst_udpsrc_ensure_mem (udpsrc)) goto memory_alloc_error; - /* optimization: use messages only in multicast mode */ + /* optimization: use messages only in multicast mode and + * if we can't let the kernel do the filtering for us */ p_msgs = (g_inet_address_get_is_multicast (g_inet_socket_address_get_address (udpsrc->addr))) ? &msgs : NULL; +#ifdef IP_MULTICAST_ALL + if (g_inet_address_get_family (g_inet_socket_address_get_address + (udpsrc->addr)) == G_SOCKET_FAMILY_IPV4) + p_msgs = NULL; +#endif /* Retrieve sender address unless we've been configured not to do so */ p_saddr = (udpsrc->retrieve_sender_address) ? &saddr : NULL; @@ -1458,7 +1464,14 @@ gst_udpsrc_open (GstUDPSrc * src) if (g_inet_address_get_family (g_inet_socket_address_get_address (src->addr)) == G_SOCKET_FAMILY_IPV4) { -#if defined(IP_PKTINFO) +#if defined(IP_MULTICAST_ALL) + if (!g_socket_set_option (src->used_socket, IPPROTO_IP, IP_MULTICAST_ALL, + 0, &err)) { + GST_WARNING_OBJECT (src, "Failed to disable IP_MULTICAST_ALL: %s", + err->message); + g_clear_error (&err); + } +#elif defined(IP_PKTINFO) if (!g_socket_set_option (src->used_socket, IPPROTO_IP, IP_PKTINFO, TRUE, &err)) { GST_WARNING_OBJECT (src, "Failed to enable IP_PKTINFO: %s",