Commit e739998a authored by Wim Taymans's avatar Wim Taymans
Browse files

udpsrc: add property to enable port reuse

parent ed80c183
...@@ -145,6 +145,7 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", ...@@ -145,6 +145,7 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
#define UDP_DEFAULT_CLOSEFD TRUE #define UDP_DEFAULT_CLOSEFD TRUE
#define UDP_DEFAULT_SOCK -1 #define UDP_DEFAULT_SOCK -1
#define UDP_DEFAULT_AUTO_MULTICAST TRUE #define UDP_DEFAULT_AUTO_MULTICAST TRUE
#define UDP_DEFAULT_REUSE TRUE
enum enum
{ {
...@@ -162,6 +163,7 @@ enum ...@@ -162,6 +163,7 @@ enum
PROP_CLOSEFD, PROP_CLOSEFD,
PROP_SOCK, PROP_SOCK,
PROP_AUTO_MULTICAST, PROP_AUTO_MULTICAST,
PROP_REUSE,
PROP_LAST PROP_LAST
}; };
...@@ -291,6 +293,9 @@ gst_udpsrc_class_init (GstUDPSrcClass * klass) ...@@ -291,6 +293,9 @@ gst_udpsrc_class_init (GstUDPSrcClass * klass)
g_param_spec_boolean ("auto-multicast", "Auto Multicast", g_param_spec_boolean ("auto-multicast", "Auto Multicast",
"Automatically join/leave multicast groups", "Automatically join/leave multicast groups",
UDP_DEFAULT_AUTO_MULTICAST, G_PARAM_READWRITE)); UDP_DEFAULT_AUTO_MULTICAST, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_REUSE,
g_param_spec_boolean ("reuse", "Reuse", "Enable reuse of the port",
UDP_DEFAULT_REUSE, G_PARAM_READWRITE));
gstbasesrc_class->start = gst_udpsrc_start; gstbasesrc_class->start = gst_udpsrc_start;
gstbasesrc_class->stop = gst_udpsrc_stop; gstbasesrc_class->stop = gst_udpsrc_stop;
...@@ -318,6 +323,7 @@ gst_udpsrc_init (GstUDPSrc * udpsrc, GstUDPSrcClass * g_class) ...@@ -318,6 +323,7 @@ gst_udpsrc_init (GstUDPSrc * udpsrc, GstUDPSrcClass * g_class)
udpsrc->externalfd = (udpsrc->sockfd != -1); udpsrc->externalfd = (udpsrc->sockfd != -1);
udpsrc->auto_multicast = UDP_DEFAULT_AUTO_MULTICAST; udpsrc->auto_multicast = UDP_DEFAULT_AUTO_MULTICAST;
udpsrc->sock.fd = UDP_DEFAULT_SOCK; udpsrc->sock.fd = UDP_DEFAULT_SOCK;
udpsrc->reuse = UDP_DEFAULT_REUSE;
/* configure basesrc to be a live source */ /* configure basesrc to be a live source */
gst_base_src_set_live (GST_BASE_SRC (udpsrc), TRUE); gst_base_src_set_live (GST_BASE_SRC (udpsrc), TRUE);
...@@ -693,6 +699,9 @@ gst_udpsrc_set_property (GObject * object, guint prop_id, const GValue * value, ...@@ -693,6 +699,9 @@ gst_udpsrc_set_property (GObject * object, guint prop_id, const GValue * value,
case PROP_AUTO_MULTICAST: case PROP_AUTO_MULTICAST:
udpsrc->auto_multicast = g_value_get_boolean (value); udpsrc->auto_multicast = g_value_get_boolean (value);
break; break;
case PROP_REUSE:
udpsrc->reuse = g_value_get_boolean (value);
break;
default: default:
break; break;
} }
...@@ -741,6 +750,9 @@ gst_udpsrc_get_property (GObject * object, guint prop_id, GValue * value, ...@@ -741,6 +750,9 @@ gst_udpsrc_get_property (GObject * object, guint prop_id, GValue * value,
case PROP_AUTO_MULTICAST: case PROP_AUTO_MULTICAST:
g_value_set_boolean (value, udpsrc->auto_multicast); g_value_set_boolean (value, udpsrc->auto_multicast);
break; break;
case PROP_REUSE:
g_value_set_boolean (value, udpsrc->reuse);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -782,7 +794,8 @@ gst_udpsrc_start (GstBaseSrc * bsrc) ...@@ -782,7 +794,8 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
GST_DEBUG_OBJECT (src, "got socket %d", src->sock.fd); GST_DEBUG_OBJECT (src, "got socket %d", src->sock.fd);
reuse = 1; GST_DEBUG_OBJECT (src, "setting reuse %d", src->reuse);
reuse = src->reuse ? 1 : 0;
if ((ret = if ((ret =
setsockopt (src->sock.fd, SOL_SOCKET, SO_REUSEADDR, &reuse, setsockopt (src->sock.fd, SOL_SOCKET, SO_REUSEADDR, &reuse,
sizeof (reuse))) < 0) sizeof (reuse))) < 0)
......
...@@ -63,6 +63,7 @@ struct _GstUDPSrc { ...@@ -63,6 +63,7 @@ struct _GstUDPSrc {
int sockfd; int sockfd;
gboolean closefd; gboolean closefd;
gboolean auto_multicast; gboolean auto_multicast;
gboolean reuse;
/* our sockets */ /* our sockets */
GstPollFD sock; GstPollFD sock;
......
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