2003-07-17 23:04:46 +00:00
|
|
|
/* GStreamer
|
|
|
|
* 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-07-25 09:08:00 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-07-17 23:04:46 +00:00
|
|
|
#include "gsttcpsink.h"
|
|
|
|
|
|
|
|
#define TCP_DEFAULT_HOST "localhost"
|
|
|
|
#define TCP_DEFAULT_PORT 4953
|
|
|
|
|
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstElementDetails gst_tcpsink_details =
|
|
|
|
GST_ELEMENT_DETAILS ("TCP packet sender",
|
|
|
|
"Sink/Network",
|
|
|
|
"Send data over the network via TCP",
|
|
|
|
"Zeeshan Ali <zak147@yahoo.com>");
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
/* TCPSink signals and args */
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-07-17 23:04:46 +00:00
|
|
|
FRAME_ENCODED,
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-07-17 23:04:46 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_HOST,
|
|
|
|
ARG_PORT,
|
2003-07-25 09:08:00 +00:00
|
|
|
ARG_CONTROL,
|
|
|
|
ARG_MTU
|
2004-03-14 22:34:34 +00:00
|
|
|
/* FILL ME */
|
2003-07-17 23:04:46 +00:00
|
|
|
};
|
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
#define GST_TYPE_TCPSINK_CONTROL (gst_tcpsink_control_get_type())
|
|
|
|
static GType
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_control_get_type (void)
|
|
|
|
{
|
2003-07-18 00:22:37 +00:00
|
|
|
static GType tcpsink_control_type = 0;
|
|
|
|
static GEnumValue tcpsink_control[] = {
|
|
|
|
{CONTROL_NONE, "1", "none"},
|
|
|
|
{CONTROL_TCP, "2", "tcp"},
|
|
|
|
{CONTROL_ZERO, NULL, NULL}
|
|
|
|
};
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
if (!tcpsink_control_type) {
|
2004-03-14 22:34:34 +00:00
|
|
|
tcpsink_control_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_enum_register_static ("GstTCPSinkControl", tcpsink_control);
|
2003-07-18 00:22:37 +00:00
|
|
|
}
|
|
|
|
return tcpsink_control_type;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_tcpsink_base_init (gpointer g_class);
|
|
|
|
static void gst_tcpsink_class_init (GstTCPSink * klass);
|
|
|
|
static void gst_tcpsink_init (GstTCPSink * tcpsink);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_tcpsink_set_clock (GstElement * element, GstClock * clock);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_tcpsink_chain (GstPad * pad, GstData * _data);
|
|
|
|
static GstElementStateReturn gst_tcpsink_change_state (GstElement * element);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_tcpsink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_tcpsink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
/*static guint gst_tcpsink_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_tcpsink_get_type (void)
|
|
|
|
{
|
|
|
|
static GType tcpsink_type = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (!tcpsink_type) {
|
|
|
|
static const GTypeInfo tcpsink_info = {
|
2004-03-14 22:34:34 +00:00
|
|
|
sizeof (GstTCPSinkClass),
|
2003-11-02 21:55:15 +00:00
|
|
|
gst_tcpsink_base_init,
|
2003-07-17 23:04:46 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:34 +00:00
|
|
|
(GClassInitFunc) gst_tcpsink_class_init,
|
2003-07-17 23:04:46 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:34 +00:00
|
|
|
sizeof (GstTCPSink),
|
2003-07-17 23:04:46 +00:00
|
|
|
0,
|
2004-03-14 22:34:34 +00:00
|
|
|
(GInstanceInitFunc) gst_tcpsink_init,
|
2003-07-17 23:04:46 +00:00
|
|
|
NULL
|
|
|
|
};
|
2004-03-15 19:32:28 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
tcpsink_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstTCPSink", &tcpsink_info,
|
|
|
|
0);
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
return tcpsink_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 21:55:15 +00:00
|
|
|
static void
|
|
|
|
gst_tcpsink_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_tcpsink_details);
|
|
|
|
}
|
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_class_init (GstTCPSink * klass)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2003-07-17 23:04:46 +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:34 +00:00
|
|
|
g_param_spec_string ("host", "host", "The host/IP to send the packets to",
|
2004-03-15 19:32:28 +00:00
|
|
|
TCP_DEFAULT_HOST, G_PARAM_READWRITE));
|
2003-07-17 23:04:46 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_PORT,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_int ("port", "port", "The port to send the packets to",
|
2004-03-15 19:32:28 +00:00
|
|
|
0, 32768, TCP_DEFAULT_PORT, G_PARAM_READWRITE));
|
2003-07-18 00:22:37 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_CONTROL,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_enum ("control", "control", "The type of control",
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_TYPE_TCPSINK_CONTROL, CONTROL_TCP, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (gobject_class, ARG_MTU, g_param_spec_int ("mtu", "mtu", "mtu", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
|
2003-07-17 23:04:46 +00:00
|
|
|
gobject_class->set_property = gst_tcpsink_set_property;
|
|
|
|
gobject_class->get_property = gst_tcpsink_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_tcpsink_change_state;
|
|
|
|
gstelement_class->set_clock = gst_tcpsink_set_clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_sink_link (GstPad * pad, const GstCaps * caps)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSink *tcpsink;
|
2004-04-20 23:03:28 +00:00
|
|
|
|
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2003-07-17 23:04:46 +00:00
|
|
|
struct sockaddr_in serv_addr;
|
|
|
|
struct in_addr addr;
|
|
|
|
struct hostent *he;
|
|
|
|
int fd;
|
|
|
|
FILE *f;
|
|
|
|
xmlDocPtr doc;
|
2004-04-20 23:03:28 +00:00
|
|
|
#endif
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
tcpsink = GST_TCPSINK (gst_pad_get_parent (pad));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
switch (tcpsink->control) {
|
2004-04-20 23:03:28 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2003-07-18 00:22:37 +00:00
|
|
|
case CONTROL_TCP:
|
2004-03-14 22:34:34 +00:00
|
|
|
memset (&serv_addr, 0, sizeof (serv_addr));
|
|
|
|
|
|
|
|
/* if its an IP address */
|
|
|
|
if (inet_aton (tcpsink->host, &addr)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
memmove (&(serv_addr.sin_addr), &addr, sizeof (struct in_addr));
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we dont need to lookup for localhost */
|
|
|
|
else if (strcmp (tcpsink->host, TCP_DEFAULT_HOST) == 0) {
|
2004-03-15 19:32:28 +00:00
|
|
|
if (inet_aton ("127.0.0.1", &addr)) {
|
|
|
|
memmove (&(serv_addr.sin_addr), &addr, sizeof (struct in_addr));
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if its a hostname */
|
|
|
|
else if ((he = gethostbyname (tcpsink->host))) {
|
2004-03-15 19:32:28 +00:00
|
|
|
memmove (&(serv_addr.sin_addr), he->h_addr, he->h_length);
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2004-03-15 19:32:28 +00:00
|
|
|
perror ("hostname lookup error?");
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
serv_addr.sin_family = AF_INET;
|
|
|
|
serv_addr.sin_port = htons (tcpsink->port + 1);
|
|
|
|
|
|
|
|
doc = xmlNewDoc ("1.0");
|
|
|
|
doc->xmlRootNode = xmlNewDocNode (doc, NULL, "NewCaps", NULL);
|
|
|
|
|
|
|
|
gst_caps_save_thyself (caps, doc->xmlRootNode);
|
|
|
|
|
|
|
|
if ((fd = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
|
2004-03-15 19:32:28 +00:00
|
|
|
perror ("socket");
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (connect (fd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) != 0) {
|
2004-03-15 19:32:28 +00:00
|
|
|
g_printerr ("tcpsink: connect to %s port %d failed: %s\n",
|
|
|
|
tcpsink->host, tcpsink->port + 1, g_strerror (errno));
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
f = fdopen (dup (fd), "wb");
|
|
|
|
|
|
|
|
xmlDocDump (f, doc);
|
|
|
|
fclose (f);
|
|
|
|
close (fd);
|
|
|
|
break;
|
2004-04-20 23:03:28 +00:00
|
|
|
|
|
|
|
#endif
|
2003-07-18 00:22:37 +00:00
|
|
|
case CONTROL_NONE:
|
2004-03-14 22:34:34 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
|
|
|
break;
|
2003-07-18 00:22:37 +00:00
|
|
|
default:
|
2004-03-14 22:34:34 +00:00
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
break;
|
2003-07-18 00:22:37 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
return GST_PAD_LINK_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_set_clock (GstElement * element, GstClock * clock)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSink *tcpsink;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
tcpsink = GST_TCPSINK (element);
|
|
|
|
|
|
|
|
tcpsink->clock = clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_init (GstTCPSink * tcpsink)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
/* create the sink and src pads */
|
|
|
|
tcpsink->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (tcpsink), tcpsink->sinkpad);
|
|
|
|
gst_pad_set_chain_function (tcpsink->sinkpad, gst_tcpsink_chain);
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_pad_set_link_function (tcpsink->sinkpad, gst_tcpsink_sink_link);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
tcpsink->host = g_strdup (TCP_DEFAULT_HOST);
|
|
|
|
tcpsink->port = TCP_DEFAULT_PORT;
|
2003-07-18 00:22:37 +00:00
|
|
|
tcpsink->control = CONTROL_TCP;
|
2003-07-25 09:08:00 +00:00
|
|
|
/* should support as minimum 576 for IPV4 and 1500 for IPV6 */
|
|
|
|
tcpsink->mtu = 1500;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
tcpsink->clock = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_chain (GstPad * pad, GstData * _data)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
2003-10-08 16:08:22 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2003-07-17 23:04:46 +00:00
|
|
|
GstTCPSink *tcpsink;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
|
|
|
tcpsink = GST_TCPSINK (GST_OBJECT_PARENT (pad));
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-01-14 00:53:52 +00:00
|
|
|
if (tcpsink->clock && GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
|
|
|
|
gst_element_wait (GST_ELEMENT (tcpsink), GST_BUFFER_TIMESTAMP (buf));
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
if (write (tcpsink->sock, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)) <= 0) {
|
|
|
|
perror ("write");
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_buffer_unref (buf);
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSink *tcpsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_return_if_fail (GST_IS_TCPSINK (object));
|
|
|
|
tcpsink = GST_TCPSINK (object);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_HOST:
|
2004-03-14 22:34:34 +00:00
|
|
|
if (tcpsink->host != NULL)
|
2004-03-15 19:32:28 +00:00
|
|
|
g_free (tcpsink->host);
|
2003-07-17 23:04:46 +00:00
|
|
|
if (g_value_get_string (value) == NULL)
|
2004-03-15 19:32:28 +00:00
|
|
|
tcpsink->host = NULL;
|
2003-07-17 23:04:46 +00:00
|
|
|
else
|
2004-03-15 19:32:28 +00:00
|
|
|
tcpsink->host = g_strdup (g_value_get_string (value));
|
2003-07-17 23:04:46 +00:00
|
|
|
break;
|
|
|
|
case ARG_PORT:
|
2004-03-14 22:34:34 +00:00
|
|
|
tcpsink->port = g_value_get_int (value);
|
2003-07-17 23:04:46 +00:00
|
|
|
break;
|
2003-07-18 00:22:37 +00:00
|
|
|
case ARG_CONTROL:
|
2004-03-14 22:34:34 +00:00
|
|
|
tcpsink->control = g_value_get_enum (value);
|
2003-07-18 00:22:37 +00:00
|
|
|
break;
|
2003-07-25 09:08:00 +00:00
|
|
|
case ARG_MTU:
|
2004-03-14 22:34:34 +00:00
|
|
|
tcpsink->mtu = g_value_get_int (value);
|
|
|
|
break;
|
2003-07-17 23:04:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSink *tcpsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2004-03-14 22:34:34 +00:00
|
|
|
g_return_if_fail (GST_IS_TCPSINK (object));
|
|
|
|
tcpsink = GST_TCPSINK (object);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_HOST:
|
|
|
|
g_value_set_string (value, tcpsink->host);
|
|
|
|
break;
|
|
|
|
case ARG_PORT:
|
|
|
|
g_value_set_int (value, tcpsink->port);
|
|
|
|
break;
|
2003-07-18 00:22:37 +00:00
|
|
|
case ARG_CONTROL:
|
|
|
|
g_value_set_enum (value, tcpsink->control);
|
|
|
|
break;
|
2003-07-25 09:08:00 +00:00
|
|
|
case ARG_MTU:
|
|
|
|
g_value_set_int (value, tcpsink->mtu);
|
|
|
|
break;
|
2003-07-17 23:04:46 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* create a socket for sending to remote machine */
|
|
|
|
static gboolean
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_init_send (GstTCPSink * sink)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
struct hostent *he;
|
|
|
|
struct in_addr addr;
|
|
|
|
|
2004-02-02 20:09:09 +00:00
|
|
|
memset (&sink->theiraddr, 0, sizeof (sink->theiraddr));
|
2004-03-15 19:32:28 +00:00
|
|
|
sink->theiraddr.sin_family = AF_INET; /* host byte order */
|
|
|
|
sink->theiraddr.sin_port = htons (sink->port); /* short, network byte order */
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
/* if its an IP address */
|
|
|
|
if (inet_aton (sink->host, &addr)) {
|
|
|
|
memmove (&(sink->theiraddr.sin_addr), &addr, sizeof (struct in_addr));
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
/* we dont need to lookup for localhost */
|
|
|
|
else if (strcmp (sink->host, TCP_DEFAULT_HOST) == 0) {
|
|
|
|
if (inet_aton ("127.0.0.1", &addr)) {
|
|
|
|
memmove (&(sink->theiraddr.sin_addr), &addr, sizeof (struct in_addr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if its a hostname */
|
|
|
|
else if ((he = gethostbyname (sink->host))) {
|
|
|
|
memmove (&(sink->theiraddr.sin_addr), he->h_addr, he->h_length);
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
else {
|
2004-03-14 22:34:34 +00:00
|
|
|
perror ("hostname lookup error?");
|
|
|
|
return FALSE;
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((sink->sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
|
2004-03-14 22:34:34 +00:00
|
|
|
perror ("socket");
|
|
|
|
return FALSE;
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (connect (sink->sock, (struct sockaddr *) &(sink->theiraddr),
|
2004-03-15 19:32:28 +00:00
|
|
|
sizeof (sink->theiraddr)) != 0) {
|
2004-03-14 22:34:34 +00:00
|
|
|
perror ("stream connect");
|
|
|
|
return FALSE;
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
GST_FLAG_SET (sink, GST_TCPSINK_OPEN);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_close (GstTCPSink * sink)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
close (sink->sock);
|
|
|
|
|
|
|
|
GST_FLAG_UNSET (sink, GST_TCPSINK_OPEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsink_change_state (GstElement * element)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_TCPSINK (element), GST_STATE_FAILURE);
|
|
|
|
|
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_TCPSINK_OPEN))
|
|
|
|
gst_tcpsink_close (GST_TCPSINK (element));
|
|
|
|
} else {
|
|
|
|
if (!GST_FLAG_IS_SET (element, GST_TCPSINK_OPEN)) {
|
|
|
|
if (!gst_tcpsink_init_send (GST_TCPSINK (element)))
|
2004-03-15 19:32:28 +00:00
|
|
|
return GST_STATE_FAILURE;
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|