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.
This commit is contained in:
Sebastian Dröge 2015-11-17 12:39:05 +02:00
parent d842ff288a
commit ffd3b391c8
2 changed files with 17 additions and 1 deletions

View file

@ -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 */

View file

@ -60,6 +60,7 @@ struct _GstUDPSrc {
gboolean close_socket;
gboolean auto_multicast;
gboolean reuse;
gboolean loop;
/* stats */
guint max_size;