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 */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_udpsink_details =
|
|
|
|
GST_ELEMENT_DETAILS ("UDP packet sender",
|
|
|
|
"Sink/Network",
|
|
|
|
"Send data over the network via UDP",
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>");
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* UDPSink signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:27:31 +00:00
|
|
|
FRAME_ENCODED,
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-22 23:27:31 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_HOST,
|
|
|
|
ARG_PORT,
|
2002-12-20 21:38:35 +00:00
|
|
|
ARG_CONTROL,
|
|
|
|
ARG_MTU
|
2004-03-14 22:34:33 +00:00
|
|
|
/* FILL ME */
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
|
|
|
|
2002-11-16 18:55:43 +00:00
|
|
|
#define GST_TYPE_UDPSINK_CONTROL (gst_udpsink_control_get_type())
|
|
|
|
static GType
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_control_get_type (void)
|
|
|
|
{
|
2002-11-16 18:55:43 +00:00
|
|
|
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},
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2002-11-16 18:55:43 +00:00
|
|
|
if (!udpsink_control_type) {
|
2004-03-14 22:34:33 +00:00
|
|
|
udpsink_control_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_enum_register_static ("GstUDPSinkControl", udpsink_control);
|
2002-11-16 18:55:43 +00:00
|
|
|
}
|
|
|
|
return udpsink_control_type;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_udpsink_base_init (gpointer g_class);
|
|
|
|
static void gst_udpsink_class_init (GstUDPSink * klass);
|
|
|
|
static void gst_udpsink_init (GstUDPSink * udpsink);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_udpsink_set_clock (GstElement * element, GstClock * clock);
|
2002-11-27 20:54:43 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_udpsink_chain (GstPad * pad, GstData * _data);
|
|
|
|
static GstElementStateReturn gst_udpsink_change_state (GstElement * element);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
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);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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 = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstUDPSinkClass),
|
2003-11-02 22:34:11 +00:00
|
|
|
gst_udpsink_base_init,
|
2001-12-22 23:27:31 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_udpsink_class_init,
|
2001-12-22 23:27:31 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstUDPSink),
|
2001-12-22 23:27:31 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_udpsink_init,
|
2001-12-22 23:27:31 +00:00
|
|
|
NULL
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
udpsink_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstUDPSink", &udpsink_info,
|
|
|
|
0);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
return udpsink_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 22:34:11 +00:00
|
|
|
static void
|
|
|
|
gst_udpsink_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_udpsink_details);
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_class_init (GstUDPSink * klass)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HOST,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_string ("host", "host",
|
2004-03-15 19:32:27 +00:00
|
|
|
"The host/IP/Multicast group to send the packets to",
|
|
|
|
UDP_DEFAULT_HOST, G_PARAM_READWRITE));
|
2001-12-22 23:27:31 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PORT,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_int ("port", "port", "The port to send the packets to",
|
2004-03-15 19:32:27 +00:00
|
|
|
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,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_enum ("control", "control", "The type of control",
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_UDPSINK_CONTROL, CONTROL_UDP, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (gobject_class, ARG_MTU, g_param_spec_int ("mtu", "mtu", "maximun transmit unit", G_MININT, G_MAXINT, 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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_sink_link (GstPad * pad, const 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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
memset (&serv_addr, 0, sizeof (serv_addr));
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
/* its a name rather than an ipnum */
|
2004-03-14 22:34:33 +00:00
|
|
|
serverhost = gethostbyname (udpsink->host);
|
|
|
|
if (serverhost == (struct hostent *) 0) {
|
|
|
|
perror ("gethostbyname");
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
memmove (&serv_addr.sin_addr, serverhost->h_addr, serverhost->h_length);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
serv_addr.sin_family = AF_INET;
|
2004-03-14 22:34:33 +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:
|
2004-03-14 22:34:33 +00:00
|
|
|
if ((fd = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
|
2004-03-15 19:32:27 +00:00
|
|
|
perror ("socket");
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:33 +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,
|
2004-03-15 19:32:27 +00:00
|
|
|
sizeof (serv_addr)) == -1) {
|
|
|
|
perror ("sending");
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
close (fd);
|
|
|
|
break;
|
2002-11-16 18:55:43 +00:00
|
|
|
case CONTROL_TCP:
|
2004-03-14 22:34:33 +00:00
|
|
|
if ((fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
|
2004-03-15 19:32:27 +00:00
|
|
|
perror ("socket");
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (connect (fd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) != 0) {
|
2004-03-15 19:32:27 +00:00
|
|
|
g_printerr ("udpsink: connect to %s port %d failed: %s\n",
|
|
|
|
udpsink->host, udpsink->port, g_strerror (errno));
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
f = fdopen (dup (fd), "wb");
|
|
|
|
|
|
|
|
xmlDocDump (f, doc);
|
|
|
|
fclose (f);
|
|
|
|
close (fd);
|
|
|
|
break;
|
2002-11-16 18:55:43 +00:00
|
|
|
case CONTROL_NONE:
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
|
|
|
break;
|
2002-11-16 18:55:43 +00:00
|
|
|
default:
|
2004-03-14 22:34:33 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
break;
|
2002-11-16 18:55:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
2004-03-14 22:34:33 +00:00
|
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_set_clock (GstElement * element, GstClock * clock)
|
2002-11-08 01:29:11 +00:00
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-11-08 01:29:11 +00:00
|
|
|
udpsink = GST_UDPSINK (element);
|
|
|
|
|
|
|
|
udpsink->clock = clock;
|
|
|
|
}
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_init (GstUDPSink * udpsink)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
/* 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-12-22 01:47:09 +00:00
|
|
|
gst_pad_set_link_function (udpsink->sinkpad, gst_udpsink_sink_link);
|
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;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2002-11-08 01:29:11 +00:00
|
|
|
udpsink->clock = NULL;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_chain (GstPad * pad, GstData * _data)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2003-10-08 16:08:18 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2001-12-22 23:27:31 +00:00
|
|
|
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));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-01-14 00:53:52 +00:00
|
|
|
if (udpsink->clock && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
|
|
|
|
gst_element_wait (GST_ELEMENT (udpsink), GST_BUFFER_TIMESTAMP (buf));
|
2002-11-08 01:29:11 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
tolen = sizeof (udpsink->theiraddr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (sendto (udpsink->sock, GST_BUFFER_DATA (buf),
|
|
|
|
GST_BUFFER_SIZE (buf), 0, (struct sockaddr *) &udpsink->theiraddr,
|
|
|
|
tolen) == -1) {
|
|
|
|
perror("sending");
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
/* MTU */
|
2003-08-07 11:18:57 +00:00
|
|
|
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) {
|
2004-03-14 22:34:33 +00:00
|
|
|
if (sendto (udpsink->sock, GST_BUFFER_DATA (buf) + i,
|
2004-03-15 19:32:27 +00:00
|
|
|
udpsink->mtu, 0, (struct sockaddr *) &udpsink->theiraddr,
|
|
|
|
tolen) == -1) {
|
|
|
|
perror ("sending");
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sendto (udpsink->sock, GST_BUFFER_DATA (buf) + i,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_SIZE (buf) - i, 0,
|
|
|
|
(struct sockaddr *) &udpsink->theiraddr, tolen) == -1) {
|
|
|
|
perror ("sending");
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2002-12-20 21:38:35 +00:00
|
|
|
}
|
2003-08-07 11:18:57 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_buffer_unref (buf);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_UDPSINK (object));
|
|
|
|
udpsink = GST_UDPSINK (object);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_HOST:
|
2004-03-14 22:34:33 +00:00
|
|
|
if (udpsink->host != NULL)
|
2004-03-15 19:32:27 +00:00
|
|
|
g_free (udpsink->host);
|
2001-12-22 23:27:31 +00:00
|
|
|
if (g_value_get_string (value) == NULL)
|
2004-03-15 19:32:27 +00:00
|
|
|
udpsink->host = NULL;
|
2001-12-22 23:27:31 +00:00
|
|
|
else
|
2004-03-15 19:32:27 +00:00
|
|
|
udpsink->host = g_strdup (g_value_get_string (value));
|
2001-12-22 23:27:31 +00:00
|
|
|
break;
|
|
|
|
case ARG_PORT:
|
2004-03-14 22:34:33 +00:00
|
|
|
udpsink->port = g_value_get_int (value);
|
2001-12-22 23:27:31 +00:00
|
|
|
break;
|
2002-11-16 18:55:43 +00:00
|
|
|
case ARG_CONTROL:
|
2004-03-14 22:34:33 +00:00
|
|
|
udpsink->control = g_value_get_enum (value);
|
2002-11-16 18:55:43 +00:00
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GstUDPSink *udpsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (GST_IS_UDPSINK (object));
|
|
|
|
udpsink = GST_UDPSINK (object);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
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
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_init_send (GstUDPSink * sink)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2004-02-02 20:09:09 +00:00
|
|
|
memset (&sink->theiraddr, 0, sizeof (sink->theiraddr));
|
2004-03-15 19:32:27 +00:00
|
|
|
sink->theiraddr.sin_family = AF_INET; /* host byte order */
|
|
|
|
sink->theiraddr.sin_port = htons (sink->port); /* short, network byte order */
|
2003-05-22 19:38:14 +00:00
|
|
|
|
|
|
|
/* 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) {
|
2004-03-14 22:34:33 +00:00
|
|
|
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,
|
2004-03-15 19:32:27 +00:00
|
|
|
sizeof (sink->multi_addr));
|
2003-06-09 23:13:40 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-09 23:13:40 +00:00
|
|
|
else {
|
2004-03-14 22:34:33 +00:00
|
|
|
sink->theiraddr.sin_addr = *((struct in_addr *) &addr);
|
2003-06-09 23:13:40 +00:00
|
|
|
}
|
2003-05-22 19:38:14 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-05-22 19:38:14 +00:00
|
|
|
/* we dont need to lookup for localhost */
|
2004-03-14 22:34:33 +00:00
|
|
|
else if (strcmp (sink->host, UDP_DEFAULT_HOST) == 0 &&
|
|
|
|
inet_aton ("127.0.0.1", &addr)) {
|
|
|
|
sink->theiraddr.sin_addr = *((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);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-05-22 19:38:14 +00:00
|
|
|
else {
|
2004-03-14 22:34:33 +00:00
|
|
|
perror ("hostname lookup error?");
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((sink->sock = socket (AF_INET, SOCK_DGRAM, 0)) == -1) {
|
2004-03-14 22:34:33 +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));
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
GST_FLAG_SET (sink, GST_UDPSINK_OPEN);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_close (GstUDPSink * sink)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
close (sink->sock);
|
|
|
|
|
|
|
|
GST_FLAG_UNSET (sink, GST_UDPSINK_OPEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_udpsink_change_state (GstElement * element)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
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)))
|
2004-03-15 19:32:27 +00:00
|
|
|
return GST_STATE_FAILURE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|