parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HOST,
- g_param_spec_string ("host", "host", "The host/IP to send the packets to",
+ g_param_spec_string ("host", "host",
+ "The host/IP/Multicast group to send the packets to",
UDP_DEFAULT_HOST, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PORT,
g_param_spec_int ("port", "port", "The port to send the packets to",
/* if its an IP address */
if (inet_aton (sink->host, &addr)) {
- sink->theiraddr.sin_addr =
- *((struct in_addr *) g_memdup (&addr, sizeof (addr)));
+ /* check if its a multicast address */
+ if ((ntohl (addr.s_addr) & 0xe0000000) == 0xe0000000) {
+ sink->multi_addr.imr_multiaddr.s_addr = addr.s_addr;
+ sink->multi_addr.imr_interface.s_addr = INADDR_ANY;
+
+ sink->theiraddr.sin_addr = sink->multi_addr.imr_multiaddr;
+
+ /* Joining the multicast group */
+ setsockopt (sink->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &sink->multi_addr, sizeof(sink->multi_addr));
+ }
+
+ else {
+ sink->theiraddr.sin_addr =
+ *((struct in_addr *) &addr);
+ }
}
/* we dont need to lookup for localhost */
else if (strcmp (sink->host, UDP_DEFAULT_HOST) == 0 &&
inet_aton ("127.0.0.1", &addr)) {
sink->theiraddr.sin_addr =
- *((struct in_addr *) g_memdup (&addr, sizeof (addr)));
+ *((struct in_addr *) &addr);
}
/* if its a hostname */
#include "gstudpsrc.h"
-#define UDP_DEFAULT_PORT 4951
+#define UDP_DEFAULT_PORT 4951
+#define UDP_DEFAULT_MULTICAST_GROUP "0.0.0.0"
/* elementfactory information */
GstElementDetails gst_udpsrc_details = {
enum {
ARG_0,
ARG_PORT,
- ARG_CONTROL
+ ARG_CONTROL,
+ ARG_MULTICAST_GROUP
/* FILL ME */
};
g_object_class_install_property (gobject_class, ARG_CONTROL,
g_param_spec_enum ("control", "control", "The type of control",
GST_TYPE_UDPSRC_CONTROL, CONTROL_UDP, G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, ARG_MULTICAST_GROUP,
+ g_param_spec_string ("multicast_group", "multicast_group",
+ "The Address of multicast group to join",
+ UDP_DEFAULT_MULTICAST_GROUP, G_PARAM_READWRITE));
gobject_class->set_property = gst_udpsrc_set_property;
gobject_class->get_property = gst_udpsrc_get_property;
udpsrc->clock = NULL;
udpsrc->sock = -1;
udpsrc->control_sock = -1;
+ udpsrc->multi_group = g_strdup (UDP_DEFAULT_MULTICAST_GROUP);
udpsrc->first_buf = TRUE;
}
case ARG_PORT:
udpsrc->port = g_value_get_int (value);
break;
+ case ARG_MULTICAST_GROUP:
+ g_free(udpsrc->multi_group);
+
+ if (g_value_get_string (value) == NULL)
+ udpsrc->multi_group = g_strdup (UDP_DEFAULT_MULTICAST_GROUP);
+ else
+ udpsrc->multi_group = g_strdup (g_value_get_string (value));
+
+ break;
case ARG_CONTROL:
udpsrc->control = g_value_get_enum (value);
break;
case ARG_PORT:
g_value_set_int (value, udpsrc->port);
break;
+ case ARG_MULTICAST_GROUP:
+ g_value_set_string (value, udpsrc->multi_group);
+ break;
case ARG_CONTROL:
g_value_set_enum (value, udpsrc->control);
break;
return FALSE;
}
+ if (inet_aton (src->multi_group, &(src->multi_addr.imr_multiaddr))) {
+ if (src->multi_addr.imr_multiaddr.s_addr) {
+ src->multi_addr.imr_interface.s_addr = INADDR_ANY;
+ setsockopt (src->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &src->multi_addr, sizeof(src->multi_addr));
+ }
+ }
+
bc_val = 1;
setsockopt (src->sock, SOL_SOCKET, SO_BROADCAST, &bc_val, sizeof (bc_val));
- src->myaddr.sin_port = htons (src->port+1); /* short, network byte order */
+ src->myaddr.sin_port = htons (src->port+1);
switch (src->control) {
case CONTROL_TCP: