2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-22 23:27:31 +00:00
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:27:31 +00:00
|
|
|
#include "gstudpsink.h"
|
|
|
|
|
|
|
|
#define UDP_DEFAULT_HOST "localhost"
|
|
|
|
#define UDP_DEFAULT_PORT 4951
|
2002-11-16 18:55:43 +00:00
|
|
|
#define UDP_DEFAULT_CONTROL 1
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
|
|
|
GstElementDetails gst_udpsink_details = {
|
|
|
|
"UDP packet sender",
|
2002-04-20 21:42:51 +00:00
|
|
|
"Sink/Network",
|
2002-09-18 19:02:51 +00:00
|
|
|
"LGPL",
|
2002-09-29 18:12:19 +00:00
|
|
|
"Send data over the network via UDP",
|
2001-12-22 23:27:31 +00:00
|
|
|
VERSION,
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
"(C) 2001",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* UDPSink signals and args */
|
|
|
|
enum {
|
|
|
|
FRAME_ENCODED,
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_HOST,
|
|
|
|
ARG_PORT,
|
2002-12-20 21:38:35 +00:00
|
|
|
ARG_CONTROL,
|
|
|
|
ARG_MTU
|
2001-12-22 23:27:31 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2002-11-16 18:55:43 +00:00
|
|
|
#define GST_TYPE_UDPSINK_CONTROL (gst_udpsink_control_get_type())
|
|
|
|
static GType
|
|
|
|
gst_udpsink_control_get_type(void) {
|
|
|
|
static GType udpsink_control_type = 0;
|
|
|
|
static GEnumValue udpsink_control[] = {
|
|
|
|
{CONTROL_NONE, "1", "none"},
|
|
|
|
{CONTROL_UDP, "2", "udp"},
|
|
|
|
{CONTROL_TCP, "3", "tcp"},
|
|
|
|
{CONTROL_ZERO, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!udpsink_control_type) {
|
|
|
|
udpsink_control_type = g_enum_register_static("GstUDPSinkControl", udpsink_control);
|
|
|
|
}
|
|
|
|
return udpsink_control_type;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void gst_udpsink_class_init (GstUDPSink *klass);
|
|
|
|
static void gst_udpsink_init (GstUDPSink *udpsink);
|
|
|
|
|
2002-11-27 20:54:43 +00:00
|
|
|
static void gst_udpsink_set_clock (GstElement *element, GstClock *clock);
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void gst_udpsink_chain (GstPad *pad,GstBuffer *buf);
|
|
|
|
static GstElementStateReturn gst_udpsink_change_state (GstElement *element);
|
|
|
|
|
|
|
|
static void gst_udpsink_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_udpsink_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-03-19 04:10:05 +00:00
|
|
|
/*static guint gst_udpsink_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_udpsink_get_type (void)
|
|
|
|
{
|
|
|
|
static GType udpsink_type = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (!udpsink_type) {
|
|
|
|
static const GTypeInfo udpsink_info = {
|
|
|
|
sizeof(GstUDPSinkClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_udpsink_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstUDPSink),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_udpsink_init,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
udpsink_type = g_type_register_static (GST_TYPE_ELEMENT, "GstUDPSink", &udpsink_info, 0);
|
|
|
|
}
|
|
|
|
return udpsink_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_udpsink_class_init (GstUDPSink *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstelement_class = (GstElementClass*) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HOST,
|
2003-06-09 23:13:40 +00:00
|
|
|
g_param_spec_string ("host", "host",
|
|
|
|
"The host/IP/Multicast group to send the packets to",
|
2001-12-22 23:27:31 +00:00
|
|
|
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",
|
|
|
|
0, 32768, UDP_DEFAULT_PORT, G_PARAM_READWRITE));
|
2002-11-16 18:55:43 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_CONTROL,
|
|
|
|
g_param_spec_enum ("control", "control", "The type of control",
|
|
|
|
GST_TYPE_UDPSINK_CONTROL, CONTROL_UDP, G_PARAM_READWRITE));
|
2002-12-20 21:38:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_MTU,
|
2003-08-07 11:18:57 +00:00
|
|
|
g_param_spec_int ("mtu", "mtu", "maximun transmit unit", G_MININT, G_MAXINT,
|
2002-12-20 21:38:35 +00:00
|
|
|
0, G_PARAM_READWRITE)); /* CHECKME */
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_udpsink_set_property;
|
|
|
|
gobject_class->get_property = gst_udpsink_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_udpsink_change_state;
|
2002-11-27 20:54:43 +00:00
|
|
|
gstelement_class->set_clock = gst_udpsink_set_clock;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-10 13:38:32 +00:00
|
|
|
static GstPadLinkReturn
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_udpsink_sinkconnect (GstPad *pad, GstCaps *caps)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
|
|
|
struct sockaddr_in serv_addr;
|
|
|
|
struct hostent *serverhost;
|
|
|
|
int fd;
|
|
|
|
FILE *f;
|
2002-11-16 18:55:43 +00:00
|
|
|
guint bc_val;
|
2001-12-22 23:27:31 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
|
|
|
xmlDocPtr doc;
|
2002-11-16 18:55:43 +00:00
|
|
|
xmlChar *buf;
|
|
|
|
int buf_size;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
udpsink = GST_UDPSINK (gst_pad_get_parent (pad));
|
2002-11-16 18:55:43 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
memset(&serv_addr, 0, sizeof(serv_addr));
|
2002-11-16 18:55:43 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
/* its a name rather than an ipnum */
|
|
|
|
serverhost = gethostbyname(udpsink->host);
|
|
|
|
if (serverhost == (struct hostent *)0) {
|
2002-11-16 18:55:43 +00:00
|
|
|
perror("gethostbyname");
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2002-11-16 18:55:43 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length);
|
|
|
|
|
|
|
|
serv_addr.sin_family = AF_INET;
|
2002-11-16 18:55:43 +00:00
|
|
|
serv_addr.sin_port = htons(udpsink->port+1);
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
doc = xmlNewDoc ("1.0");
|
|
|
|
doc->xmlRootNode = xmlNewDocNode (doc, NULL, "NewCaps", NULL);
|
|
|
|
|
|
|
|
gst_caps_save_thyself (caps, doc->xmlRootNode);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2002-11-16 18:55:43 +00:00
|
|
|
switch (udpsink->control) {
|
|
|
|
case CONTROL_UDP:
|
|
|
|
if ((fd = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
|
|
|
|
perror("socket");
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-11-16 18:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We can only do broadcast in udp */
|
|
|
|
bc_val = 1;
|
|
|
|
setsockopt (fd,SOL_SOCKET, SO_BROADCAST, &bc_val, sizeof (bc_val));
|
|
|
|
|
|
|
|
xmlDocDumpMemory(doc, &buf, &buf_size);
|
|
|
|
|
|
|
|
if (sendto (fd, buf, buf_size, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
|
|
|
|
{
|
|
|
|
perror("sending");
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-11-16 18:55:43 +00:00
|
|
|
}
|
|
|
|
close (fd);
|
|
|
|
break;
|
|
|
|
case CONTROL_TCP:
|
|
|
|
if ((fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
|
|
|
|
perror("socket");
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-11-16 18:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) {
|
|
|
|
g_printerr ("udpsink: connect to %s port %d failed: %s\n",
|
|
|
|
udpsink->host, udpsink->port, g_strerror(errno));
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-11-16 18:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
f = fdopen (dup (fd), "wb");
|
|
|
|
|
|
|
|
xmlDocDump(f, doc);
|
|
|
|
fclose (f);
|
|
|
|
close (fd);
|
|
|
|
break;
|
|
|
|
case CONTROL_NONE:
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2002-11-16 18:55:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
2002-11-16 18:55:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-10 10:22:25 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2002-11-08 01:29:11 +00:00
|
|
|
static void
|
|
|
|
gst_udpsink_set_clock (GstElement *element, GstClock *clock)
|
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
|
|
|
|
|
|
|
udpsink = GST_UDPSINK (element);
|
|
|
|
|
|
|
|
udpsink->clock = clock;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void
|
|
|
|
gst_udpsink_init (GstUDPSink *udpsink)
|
|
|
|
{
|
|
|
|
/* create the sink and src pads */
|
|
|
|
udpsink->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (udpsink), udpsink->sinkpad);
|
|
|
|
gst_pad_set_chain_function (udpsink->sinkpad, gst_udpsink_chain);
|
2003-01-10 10:22:25 +00:00
|
|
|
gst_pad_set_link_function (udpsink->sinkpad, gst_udpsink_sinkconnect);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
udpsink->host = g_strdup (UDP_DEFAULT_HOST);
|
|
|
|
udpsink->port = UDP_DEFAULT_PORT;
|
2002-11-16 18:55:43 +00:00
|
|
|
udpsink->control = CONTROL_UDP;
|
2002-12-20 21:38:35 +00:00
|
|
|
udpsink->mtu = 1024;
|
2002-11-08 01:29:11 +00:00
|
|
|
|
|
|
|
udpsink->clock = NULL;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_udpsink_chain (GstPad *pad, GstBuffer *buf)
|
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
2003-08-07 11:18:57 +00:00
|
|
|
guint tolen, i;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
|
|
|
udpsink = GST_UDPSINK (GST_OBJECT_PARENT (pad));
|
2002-11-08 01:29:11 +00:00
|
|
|
|
|
|
|
if (udpsink->clock) {
|
2002-12-27 23:00:36 +00:00
|
|
|
GstClockID id = gst_clock_new_single_shot_id (udpsink->clock, GST_BUFFER_TIMESTAMP (buf));
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("udpsink: clock wait: %" G_GUINT64_FORMAT "\n", GST_BUFFER_TIMESTAMP (buf));
|
2002-12-27 23:00:36 +00:00
|
|
|
gst_element_clock_wait (GST_ELEMENT (udpsink), id, NULL);
|
|
|
|
gst_clock_id_free (id);
|
2002-11-08 01:29:11 +00:00
|
|
|
}
|
2002-12-20 21:38:35 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
tolen = sizeof(udpsink->theiraddr);
|
2002-12-20 21:38:35 +00:00
|
|
|
|
2003-08-07 11:18:57 +00:00
|
|
|
/*
|
2003-02-10 22:10:46 +00:00
|
|
|
if (sendto (udpsink->sock, GST_BUFFER_DATA (buf),
|
|
|
|
GST_BUFFER_SIZE (buf), 0, (struct sockaddr *) &udpsink->theiraddr,
|
|
|
|
tolen) == -1) {
|
|
|
|
perror("sending");
|
|
|
|
}
|
2003-08-07 11:18:57 +00:00
|
|
|
*/
|
|
|
|
/* MTU */
|
|
|
|
for (i = 0; i < GST_BUFFER_SIZE (buf); i += udpsink->mtu) {
|
2002-12-20 21:38:35 +00:00
|
|
|
if (GST_BUFFER_SIZE (buf) - i > udpsink->mtu) {
|
|
|
|
if (sendto (udpsink->sock, GST_BUFFER_DATA (buf) + i,
|
|
|
|
udpsink->mtu, 0, (struct sockaddr *) &udpsink->theiraddr,
|
|
|
|
tolen) == -1) {
|
|
|
|
perror("sending");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (sendto (udpsink->sock, GST_BUFFER_DATA (buf) + i,
|
|
|
|
GST_BUFFER_SIZE (buf) -i, 0,
|
|
|
|
(struct sockaddr *) &udpsink->theiraddr, tolen) == -1) {
|
|
|
|
perror("sending");
|
|
|
|
}
|
|
|
|
}
|
2003-08-07 11:18:57 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
gst_buffer_unref(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_udpsink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_UDPSINK(object));
|
|
|
|
udpsink = GST_UDPSINK(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_HOST:
|
|
|
|
if (udpsink->host != NULL) g_free(udpsink->host);
|
|
|
|
if (g_value_get_string (value) == NULL)
|
|
|
|
udpsink->host = NULL;
|
|
|
|
else
|
|
|
|
udpsink->host = g_strdup (g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case ARG_PORT:
|
|
|
|
udpsink->port = g_value_get_int (value);
|
|
|
|
break;
|
2002-11-16 18:55:43 +00:00
|
|
|
case ARG_CONTROL:
|
|
|
|
udpsink->control = g_value_get_enum (value);
|
|
|
|
break;
|
2002-12-20 21:38:35 +00:00
|
|
|
case ARG_MTU:
|
|
|
|
udpsink->mtu = g_value_get_int (value);
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_udpsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_UDPSINK(object));
|
|
|
|
udpsink = GST_UDPSINK(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_HOST:
|
|
|
|
g_value_set_string (value, udpsink->host);
|
|
|
|
break;
|
|
|
|
case ARG_PORT:
|
|
|
|
g_value_set_int (value, udpsink->port);
|
|
|
|
break;
|
2002-11-16 18:55:43 +00:00
|
|
|
case ARG_CONTROL:
|
|
|
|
g_value_set_enum (value, udpsink->control);
|
|
|
|
break;
|
2002-12-20 21:38:35 +00:00
|
|
|
case ARG_MTU:
|
|
|
|
g_value_set_int (value, udpsink->mtu);
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-19 04:10:05 +00:00
|
|
|
/* create a socket for sending to remote machine */
|
2001-12-22 23:27:31 +00:00
|
|
|
static gboolean
|
|
|
|
gst_udpsink_init_send (GstUDPSink *sink)
|
|
|
|
{
|
|
|
|
struct hostent *he;
|
2003-05-22 19:38:14 +00:00
|
|
|
struct in_addr addr;
|
2002-11-16 18:55:43 +00:00
|
|
|
guint bc_val;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
bzero (&sink->theiraddr, sizeof (sink->theiraddr));
|
2002-03-19 04:10:05 +00:00
|
|
|
sink->theiraddr.sin_family = AF_INET; /* host byte order */
|
2003-05-22 19:38:14 +00:00
|
|
|
sink->theiraddr.sin_port = htons (sink->port); /* short, network byte order */
|
|
|
|
|
|
|
|
/* if its an IP address */
|
|
|
|
if (inet_aton (sink->host, &addr)) {
|
2003-06-09 23:13:40 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
2003-05-22 19:38:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we dont need to lookup for localhost */
|
2003-06-09 21:30:40 +00:00
|
|
|
else if (strcmp (sink->host, UDP_DEFAULT_HOST) == 0 &&
|
|
|
|
inet_aton ("127.0.0.1", &addr)) {
|
|
|
|
sink->theiraddr.sin_addr =
|
2003-06-09 23:13:40 +00:00
|
|
|
*((struct in_addr *) &addr);
|
2003-05-22 19:38:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if its a hostname */
|
|
|
|
else if ((he = gethostbyname (sink->host))) {
|
|
|
|
sink->theiraddr.sin_addr = *((struct in_addr *) he->h_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
perror("hostname lookup error?");
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((sink->sock = socket (AF_INET, SOCK_DGRAM, 0)) == -1) {
|
2002-11-16 18:55:43 +00:00
|
|
|
perror("socket");
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2002-11-16 18:55:43 +00:00
|
|
|
bc_val = 1;
|
|
|
|
setsockopt (sink->sock, SOL_SOCKET, SO_BROADCAST, &bc_val, sizeof (bc_val));
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
GST_FLAG_SET (sink, GST_UDPSINK_OPEN);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_udpsink_close (GstUDPSink *sink)
|
|
|
|
{
|
|
|
|
close (sink->sock);
|
|
|
|
|
|
|
|
GST_FLAG_UNSET (sink, GST_UDPSINK_OPEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_udpsink_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_UDPSINK (element), GST_STATE_FAILURE);
|
|
|
|
|
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_UDPSINK_OPEN))
|
|
|
|
gst_udpsink_close (GST_UDPSINK (element));
|
|
|
|
} else {
|
|
|
|
if (!GST_FLAG_IS_SET (element, GST_UDPSINK_OPEN)) {
|
|
|
|
if (!gst_udpsink_init_send (GST_UDPSINK (element)))
|
|
|
|
return GST_STATE_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|