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:04:41 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
#include "gsttcpsrc.h"
|
2003-07-25 09:04:41 +00:00
|
|
|
#include <unistd.h>
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
#define TCP_DEFAULT_PORT 4953
|
|
|
|
|
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstElementDetails gst_tcpsrc_details =
|
|
|
|
GST_ELEMENT_DETAILS ("TCP packet receiver",
|
|
|
|
"Source/Network",
|
|
|
|
"Receive data over the network via TCP",
|
|
|
|
"Zeeshan Ali <zak147@yahoo.com>");
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
/* TCPSrc signals and args */
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-07-17 23:04:46 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-07-17 23:04:46 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_PORT,
|
2004-05-21 22:39:30 +00:00
|
|
|
ARG_CONTROL
|
2003-08-12 09:59:19 +00:00
|
|
|
/* ARG_SOCKET_OPTIONS,*/
|
2004-05-21 22:39:30 +00:00
|
|
|
/* FILL ME */
|
2003-07-17 23:04:46 +00:00
|
|
|
};
|
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
#define GST_TYPE_TCPSRC_CONTROL (gst_tcpsrc_control_get_type())
|
|
|
|
static GType
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_control_get_type (void)
|
|
|
|
{
|
2003-07-18 00:22:37 +00:00
|
|
|
static GType tcpsrc_control_type = 0;
|
|
|
|
static GEnumValue tcpsrc_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 (!tcpsrc_control_type) {
|
2004-03-14 22:34:34 +00:00
|
|
|
tcpsrc_control_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_enum_register_static ("GstTCPSrcControl", tcpsrc_control);
|
2003-07-18 00:22:37 +00:00
|
|
|
}
|
|
|
|
return tcpsrc_control_type;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_tcpsrc_base_init (gpointer g_class);
|
|
|
|
static void gst_tcpsrc_class_init (GstTCPSrc * klass);
|
|
|
|
static void gst_tcpsrc_init (GstTCPSrc * tcpsrc);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstData *gst_tcpsrc_get (GstPad * pad);
|
|
|
|
static GstElementStateReturn gst_tcpsrc_change_state (GstElement * element);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static void gst_tcpsrc_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_tcpsrc_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_tcpsrc_set_clock (GstElement * element, GstClock * clock);
|
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_tcpsrc_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_tcpsrc_get_type (void)
|
|
|
|
{
|
|
|
|
static GType tcpsrc_type = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (!tcpsrc_type) {
|
|
|
|
static const GTypeInfo tcpsrc_info = {
|
2004-03-14 22:34:34 +00:00
|
|
|
sizeof (GstTCPSrcClass),
|
2003-11-02 21:55:15 +00:00
|
|
|
gst_tcpsrc_base_init,
|
2003-07-17 23:04:46 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:34 +00:00
|
|
|
(GClassInitFunc) gst_tcpsrc_class_init,
|
2003-07-17 23:04:46 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:34 +00:00
|
|
|
sizeof (GstTCPSrc),
|
2003-07-17 23:04:46 +00:00
|
|
|
0,
|
2004-03-14 22:34:34 +00:00
|
|
|
(GInstanceInitFunc) gst_tcpsrc_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
|
|
|
tcpsrc_type =
|
2004-03-15 19:32:28 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstTCPSrc", &tcpsrc_info, 0);
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
return tcpsrc_type;
|
|
|
|
}
|
|
|
|
|
2003-11-02 21:55:15 +00:00
|
|
|
static void
|
|
|
|
gst_tcpsrc_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_tcpsrc_details);
|
|
|
|
}
|
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_class_init (GstTCPSrc * 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_PORT,
|
2004-03-14 22:34:34 +00:00
|
|
|
g_param_spec_int ("port", "port", "The port to receive the packets from",
|
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_TCPSRC_CONTROL, CONTROL_TCP, G_PARAM_READWRITE));
|
2003-08-12 09:59:19 +00:00
|
|
|
/*
|
2003-08-07 17:56:09 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SOCKET_OPTIONS,
|
|
|
|
g_param_spec_boolean ("socketop", "socketop", "Enable or disable socket options REUSEADDR and KEEPALIVE",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
2003-08-12 09:59:19 +00:00
|
|
|
*/
|
2003-07-17 23:04:46 +00:00
|
|
|
gobject_class->set_property = gst_tcpsrc_set_property;
|
|
|
|
gobject_class->get_property = gst_tcpsrc_get_property;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_tcpsrc_change_state;
|
|
|
|
gstelement_class->set_clock = gst_tcpsrc_set_clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_set_clock (GstElement * element, GstClock * clock)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSrc *tcpsrc;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
tcpsrc = GST_TCPSRC (element);
|
|
|
|
|
|
|
|
tcpsrc->clock = clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_init (GstTCPSrc * tcpsrc)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
/* create the src and src pads */
|
|
|
|
tcpsrc->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (tcpsrc), tcpsrc->srcpad);
|
|
|
|
gst_pad_set_get_function (tcpsrc->srcpad, gst_tcpsrc_get);
|
|
|
|
|
|
|
|
tcpsrc->port = TCP_DEFAULT_PORT;
|
2003-07-18 00:22:37 +00:00
|
|
|
tcpsrc->control = CONTROL_TCP;
|
2003-07-17 23:04:46 +00:00
|
|
|
tcpsrc->clock = NULL;
|
|
|
|
tcpsrc->sock = -1;
|
|
|
|
tcpsrc->control_sock = -1;
|
2003-08-05 10:24:06 +00:00
|
|
|
tcpsrc->client_sock = -1;
|
2004-03-14 22:34:34 +00:00
|
|
|
/*tcpsrc->socket_options = FALSE; */
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
GST_FLAG_UNSET (tcpsrc, GST_TCPSRC_OPEN);
|
|
|
|
GST_FLAG_SET (tcpsrc, GST_TCPSRC_1ST_BUF);
|
|
|
|
GST_FLAG_UNSET (tcpsrc, GST_TCPSRC_CONNECTED);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
static GstData *
|
|
|
|
gst_tcpsrc_get (GstPad * pad)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSrc *tcpsrc;
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
socklen_t len;
|
|
|
|
gint numbytes;
|
|
|
|
fd_set read_fds;
|
|
|
|
guint max_sock;
|
2004-04-20 23:03:28 +00:00
|
|
|
|
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2003-07-17 23:04:46 +00:00
|
|
|
int ret, client_sock;
|
2004-04-20 23:03:28 +00:00
|
|
|
#endif
|
2003-07-17 23:04:46 +00:00
|
|
|
struct sockaddr client_addr;
|
|
|
|
|
|
|
|
g_return_val_if_fail (pad != NULL, NULL);
|
|
|
|
g_return_val_if_fail (GST_IS_PAD (pad), NULL);
|
|
|
|
|
|
|
|
tcpsrc = GST_TCPSRC (GST_OBJECT_PARENT (pad));
|
|
|
|
|
|
|
|
FD_ZERO (&read_fds);
|
|
|
|
FD_SET (tcpsrc->sock, &read_fds);
|
2003-07-18 00:22:37 +00:00
|
|
|
|
2003-08-05 10:24:06 +00:00
|
|
|
max_sock = tcpsrc->sock;
|
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
if (tcpsrc->control_sock >= 0) {
|
|
|
|
FD_SET (tcpsrc->control_sock, &read_fds);
|
2004-03-14 22:34:34 +00:00
|
|
|
max_sock = MAX (tcpsrc->sock, tcpsrc->control_sock);
|
2003-07-18 00:22:37 +00:00
|
|
|
}
|
2003-08-05 10:24:06 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
/* Add to FD_SET client socket, when connection has been established */
|
|
|
|
if (tcpsrc->client_sock >= 0) {
|
|
|
|
FD_SET (tcpsrc->client_sock, &read_fds);
|
|
|
|
max_sock = MAX (tcpsrc->client_sock, max_sock);
|
2003-08-05 10:24:06 +00:00
|
|
|
}
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
|
|
|
|
if (select (max_sock + 1, &read_fds, NULL, NULL, NULL) > 0) {
|
|
|
|
if ((tcpsrc->control_sock != -1)
|
2004-03-15 19:32:28 +00:00
|
|
|
&& FD_ISSET (tcpsrc->control_sock, &read_fds)) {
|
2004-03-14 22:34:34 +00:00
|
|
|
guchar *buf = NULL;
|
2004-04-20 23:03:28 +00:00
|
|
|
|
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2003-07-17 23:04:46 +00:00
|
|
|
xmlDocPtr doc;
|
|
|
|
GstCaps *caps;
|
2004-04-20 23:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
switch (tcpsrc->control) {
|
2004-03-15 19:32:28 +00:00
|
|
|
case CONTROL_TCP:
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
#ifndef GST_DISABLE_LOADSAVE
|
2004-03-15 19:32:28 +00:00
|
|
|
buf = g_malloc (1024 * 10);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
len = sizeof (struct sockaddr);
|
|
|
|
client_sock = accept (tcpsrc->control_sock, &client_addr, &len);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
if (client_sock <= 0) {
|
|
|
|
perror ("control_sock accept");
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
else if ((ret = read (client_sock, buf, 1024 * 10)) <= 0) {
|
|
|
|
perror ("control_sock read");
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
else {
|
|
|
|
buf[ret] = '\0';
|
|
|
|
doc = xmlParseMemory (buf, ret);
|
|
|
|
caps = gst_caps_load_thyself (doc->xmlRootNode);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
/* foward the connect, we don't signal back the result here... */
|
|
|
|
gst_pad_try_set_caps (tcpsrc->srcpad, caps);
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
g_free (buf);
|
2003-07-17 23:04:46 +00:00
|
|
|
#endif
|
2004-03-15 19:32:28 +00:00
|
|
|
break;
|
|
|
|
case CONTROL_NONE:
|
|
|
|
default:
|
|
|
|
g_free (buf);
|
|
|
|
return NULL;
|
|
|
|
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
|
|
|
outbuf = NULL;
|
2004-03-14 22:34:34 +00:00
|
|
|
} else {
|
2003-07-17 23:04:46 +00:00
|
|
|
outbuf = gst_buffer_new ();
|
|
|
|
GST_BUFFER_DATA (outbuf) = g_malloc (24000);
|
|
|
|
GST_BUFFER_SIZE (outbuf) = 24000;
|
|
|
|
|
|
|
|
if (GST_FLAG_IS_SET (tcpsrc, GST_TCPSRC_1ST_BUF)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
if (tcpsrc->clock) {
|
|
|
|
GstClockTime current_time;
|
|
|
|
GstEvent *discont;
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
current_time = gst_clock_get_time (tcpsrc->clock);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = current_time;
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
|
|
|
current_time, NULL);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
gst_pad_push (tcpsrc->srcpad, GST_DATA (discont));
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_FLAG_UNSET (tcpsrc, GST_TCPSRC_1ST_BUF);
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
else {
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = GST_CLOCK_TIME_NONE;
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
if (!GST_FLAG_IS_SET (tcpsrc, GST_TCPSRC_CONNECTED)) {
|
2004-03-15 19:32:28 +00:00
|
|
|
tcpsrc->client_sock = accept (tcpsrc->sock, &client_addr, &len);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
if (tcpsrc->client_sock <= 0) {
|
|
|
|
perror ("accept");
|
|
|
|
}
|
2003-07-17 23:04:46 +00:00
|
|
|
|
2004-03-15 19:32:28 +00:00
|
|
|
else {
|
|
|
|
GST_FLAG_SET (tcpsrc, GST_TCPSRC_CONNECTED);
|
|
|
|
}
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
numbytes =
|
2004-03-15 19:32:28 +00:00
|
|
|
read (tcpsrc->client_sock, GST_BUFFER_DATA (outbuf),
|
|
|
|
GST_BUFFER_SIZE (outbuf));
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
if (numbytes > 0) {
|
2004-03-15 19:32:28 +00:00
|
|
|
GST_BUFFER_SIZE (outbuf) = numbytes;
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
else {
|
2004-03-15 19:32:28 +00:00
|
|
|
if (numbytes == -1) {
|
|
|
|
perror ("read");
|
|
|
|
} else
|
|
|
|
g_print ("End of Stream reached\n");
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
outbuf = NULL;
|
|
|
|
close (tcpsrc->client_sock);
|
|
|
|
tcpsrc->client_sock = -1;
|
|
|
|
GST_FLAG_UNSET (tcpsrc, GST_TCPSRC_CONNECTED);
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
else {
|
|
|
|
perror ("select");
|
|
|
|
outbuf = NULL;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-10-08 16:08:22 +00:00
|
|
|
return GST_DATA (outbuf);
|
2003-07-17 23:04:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSrc *tcpsrc;
|
|
|
|
|
|
|
|
/* 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_TCPSRC (object));
|
|
|
|
tcpsrc = GST_TCPSRC (object);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_PORT:
|
2004-03-14 22:34:34 +00:00
|
|
|
tcpsrc->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
|
|
|
tcpsrc->control = g_value_get_enum (value);
|
2003-07-18 00:22:37 +00:00
|
|
|
break;
|
2003-08-12 09:59:19 +00:00
|
|
|
/* case ARG_SOCKET_OPTIONS:
|
2003-08-07 17:56:09 +00:00
|
|
|
tcpsrc->socket_options = g_value_get_boolean(value);
|
2003-08-12 09:59:19 +00:00
|
|
|
break; */
|
2003-07-17 23:04:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
GstTCPSrc *tcpsrc;
|
|
|
|
|
|
|
|
/* 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_TCPSRC (object));
|
|
|
|
tcpsrc = GST_TCPSRC (object);
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_PORT:
|
|
|
|
g_value_set_int (value, tcpsrc->port);
|
|
|
|
break;
|
2003-07-18 00:22:37 +00:00
|
|
|
case ARG_CONTROL:
|
|
|
|
g_value_set_enum (value, tcpsrc->control);
|
|
|
|
break;
|
2003-08-12 09:59:19 +00:00
|
|
|
/* case ARG_SOCKET_OPTIONS:
|
2003-08-07 17:56:09 +00:00
|
|
|
g_value_set_boolean(value,tcpsrc->socket_options);
|
2003-08-12 09:59:19 +00:00
|
|
|
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_tcpsrc_init_receive (GstTCPSrc * src)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
2004-03-14 22:34:34 +00:00
|
|
|
guint val = 0;
|
|
|
|
|
2004-02-02 20:09:09 +00:00
|
|
|
memset (&src->myaddr, 0, sizeof (src->myaddr));
|
2004-03-15 19:32:28 +00:00
|
|
|
src->myaddr.sin_family = AF_INET; /* host byte order */
|
|
|
|
src->myaddr.sin_port = htons (src->port); /* short, network byte order */
|
2003-07-17 23:04:46 +00:00
|
|
|
src->myaddr.sin_addr.s_addr = INADDR_ANY;
|
|
|
|
|
|
|
|
if ((src->sock = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
|
2004-03-14 22:34:34 +00:00
|
|
|
perror ("stream_socket");
|
2003-07-17 23:04:46 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-08-07 17:56:09 +00:00
|
|
|
|
2003-08-12 09:59:19 +00:00
|
|
|
/* if (src->socket_options)
|
|
|
|
{*/
|
2004-03-14 22:34:34 +00:00
|
|
|
g_print ("Socket Options SO_REUSEADDR, SO_KEEPALIVE\n");
|
|
|
|
/* Sock Options */
|
2003-08-07 17:56:09 +00:00
|
|
|
val = 1;
|
2004-03-14 22:34:34 +00:00
|
|
|
/* allow local address reuse */
|
|
|
|
if (setsockopt (src->sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof (int)) < 0)
|
|
|
|
perror ("setsockopt()");
|
2003-08-07 17:56:09 +00:00
|
|
|
val = 1;
|
2004-03-14 22:34:34 +00:00
|
|
|
/* periodically test if connection still alive */
|
|
|
|
if (setsockopt (src->sock, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof (int)) < 0)
|
|
|
|
perror ("setsockopt()");
|
2003-08-07 17:56:09 +00:00
|
|
|
/* Sock Options */
|
2003-08-12 09:59:19 +00:00
|
|
|
/* } */
|
2003-08-07 17:56:09 +00:00
|
|
|
|
2004-03-14 22:34:34 +00:00
|
|
|
if (bind (src->sock, (struct sockaddr *) &src->myaddr,
|
2004-03-15 19:32:28 +00:00
|
|
|
sizeof (src->myaddr)) == -1) {
|
2004-03-14 22:34:34 +00:00
|
|
|
perror ("stream_sock bind");
|
2003-07-17 23:04:46 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listen (src->sock, 5) == -1) {
|
2004-03-14 22:34:34 +00:00
|
|
|
perror ("stream_sock listen");
|
2003-07-17 23:04:46 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
fcntl (src->sock, F_SETFL, O_NONBLOCK);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-18 00:22:37 +00:00
|
|
|
switch (src->control) {
|
|
|
|
case CONTROL_TCP:
|
2004-03-14 22:34:34 +00:00
|
|
|
if ((src->control_sock = socket (AF_INET, SOCK_STREAM, 0)) == -1) {
|
2004-03-15 19:32:28 +00:00
|
|
|
perror ("control_socket");
|
|
|
|
return FALSE;
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
src->myaddr.sin_port = htons (src->port + 1);
|
|
|
|
if (bind (src->control_sock, (struct sockaddr *) &src->myaddr,
|
2004-03-15 19:32:28 +00:00
|
|
|
sizeof (src->myaddr)) == -1) {
|
|
|
|
perror ("control bind");
|
|
|
|
return FALSE;
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (listen (src->control_sock, 5) == -1) {
|
2004-03-15 19:32:28 +00:00
|
|
|
perror ("control listen");
|
|
|
|
return FALSE;
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fcntl (src->control_sock, F_SETFL, O_NONBLOCK);
|
2003-07-18 00:22:37 +00:00
|
|
|
case CONTROL_NONE:
|
2004-03-14 22:34:34 +00:00
|
|
|
GST_FLAG_SET (src, GST_TCPSRC_OPEN);
|
|
|
|
return TRUE;
|
|
|
|
break;
|
2003-07-18 00:22:37 +00:00
|
|
|
default:
|
2004-03-14 22:34:34 +00:00
|
|
|
return FALSE;
|
|
|
|
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
|
|
|
GST_FLAG_SET (src, GST_TCPSRC_OPEN);
|
2004-03-14 22:34:34 +00:00
|
|
|
|
2003-07-17 23:04:46 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_close (GstTCPSrc * src)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
if (src->sock != -1) {
|
|
|
|
close (src->sock);
|
|
|
|
src->sock = -1;
|
|
|
|
}
|
|
|
|
if (src->control_sock != -1) {
|
|
|
|
close (src->control_sock);
|
|
|
|
src->control_sock = -1;
|
|
|
|
}
|
2003-08-05 10:24:06 +00:00
|
|
|
if (src->client_sock != -1) {
|
2004-03-14 22:34:34 +00:00
|
|
|
close (src->client_sock);
|
2003-08-05 10:24:06 +00:00
|
|
|
src->client_sock = -1;
|
2004-03-14 22:34:34 +00:00
|
|
|
}
|
2003-07-17 23:04:46 +00:00
|
|
|
|
|
|
|
GST_FLAG_UNSET (src, GST_TCPSRC_OPEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:34 +00:00
|
|
|
gst_tcpsrc_change_state (GstElement * element)
|
2003-07-17 23:04:46 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_TCPSRC (element), GST_STATE_FAILURE);
|
|
|
|
|
|
|
|
if (GST_STATE_PENDING (element) == GST_STATE_NULL) {
|
|
|
|
if (GST_FLAG_IS_SET (element, GST_TCPSRC_OPEN))
|
|
|
|
gst_tcpsrc_close (GST_TCPSRC (element));
|
|
|
|
} else {
|
|
|
|
if (!GST_FLAG_IS_SET (element, GST_TCPSRC_OPEN)) {
|
|
|
|
if (!gst_tcpsrc_init_receive (GST_TCPSRC (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;
|
|
|
|
}
|