From ffd3b391c8907430dcbabaf0f1e28552b88fa836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 17 Nov 2015 12:39:05 +0200 Subject: [PATCH] udpsrc: Add "loop" property for enabling/disabling multicast loopback On POSIX, IP_MULTICAST_LOOP is a setting for the sender socket. On Windows it is a setting for the receiver socket. As such we will need it on udpsrc too to allow filtering out our own multicast packets. --- gst/udp/gstudpsrc.c | 17 ++++++++++++++++- gst/udp/gstudpsrc.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gst/udp/gstudpsrc.c b/gst/udp/gstudpsrc.c index 8da3585dbf..34aa7e4644 100644 --- a/gst/udp/gstudpsrc.c +++ b/gst/udp/gstudpsrc.c @@ -138,6 +138,7 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", #define UDP_DEFAULT_USED_SOCKET NULL #define UDP_DEFAULT_AUTO_MULTICAST TRUE #define UDP_DEFAULT_REUSE TRUE +#define UDP_DEFAULT_LOOP TRUE enum { @@ -156,7 +157,8 @@ enum PROP_USED_SOCKET, PROP_AUTO_MULTICAST, PROP_REUSE, - PROP_ADDRESS + PROP_ADDRESS, + PROP_LOOP }; static void gst_udpsrc_uri_handler_init (gpointer g_iface, gpointer iface_data); @@ -266,6 +268,11 @@ gst_udpsrc_class_init (GstUDPSrcClass * klass) "Address to receive packets for. This is equivalent to the " "multicast-group property for now", UDP_DEFAULT_MULTICAST_GROUP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, PROP_LOOP, + g_param_spec_boolean ("loop", "Multicast Loopback", + "Used for setting the multicast loop parameter. TRUE = enable," + " FALSE = disable", UDP_DEFAULT_LOOP, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); gst_element_class_add_pad_template (gstelement_class, gst_static_pad_template_get (&src_template)); @@ -305,6 +312,7 @@ gst_udpsrc_init (GstUDPSrc * udpsrc) udpsrc->auto_multicast = UDP_DEFAULT_AUTO_MULTICAST; udpsrc->used_socket = UDP_DEFAULT_USED_SOCKET; udpsrc->reuse = UDP_DEFAULT_REUSE; + udpsrc->loop = UDP_DEFAULT_LOOP; /* configure basesrc to be a live source */ gst_base_src_set_live (GST_BASE_SRC (udpsrc), TRUE); @@ -791,6 +799,9 @@ gst_udpsrc_set_property (GObject * object, guint prop_id, const GValue * value, case PROP_REUSE: udpsrc->reuse = g_value_get_boolean (value); break; + case PROP_LOOP: + udpsrc->loop = g_value_get_boolean (value); + break; default: break; } @@ -845,6 +856,9 @@ gst_udpsrc_get_property (GObject * object, guint prop_id, GValue * value, case PROP_REUSE: g_value_set_boolean (value, udpsrc->reuse); break; + case PROP_LOOP: + g_value_set_boolean (value, udpsrc->loop); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -952,6 +966,7 @@ gst_udpsrc_open (GstUDPSrc * src) goto bind_error; g_object_unref (bind_saddr); + g_socket_set_multicast_loopback (src->used_socket, src->loop); } else { GST_DEBUG_OBJECT (src, "using provided socket %p", src->socket); /* we use the configured socket, try to get some info about it */ diff --git a/gst/udp/gstudpsrc.h b/gst/udp/gstudpsrc.h index 5d7e340dbc..a476483224 100644 --- a/gst/udp/gstudpsrc.h +++ b/gst/udp/gstudpsrc.h @@ -60,6 +60,7 @@ struct _GstUDPSrc { gboolean close_socket; gboolean auto_multicast; gboolean reuse; + gboolean loop; /* stats */ guint max_size;