gsttcpclientsrc.c 12.2 KB
Newer Older
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/* GStreamer
 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
 *
 * 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.
 */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gst/gst-i18n-plugin.h>
#include "gsttcp.h"
#include "gsttcpclientsrc.h"
#include <string.h>             /* memset */
#include <unistd.h>
#include <arpa/inet.h>
32 33 34 35 36
#include <fcntl.h>


/* control stuff stolen from fdsrc */
#define CONTROL_STOP            'S'     /* stop the select call */
37 38 39
#define CONTROL_SOCKETS(o)      o->control_fds
#define WRITE_SOCKET(o)         o->control_fds[1]
#define READ_SOCKET(o)          o->control_fds[0]
40

41
#define SEND_COMMAND(o, command)          \
42 43
G_STMT_START {                              \
  unsigned char c; c = command;             \
44
  write (WRITE_SOCKET(o), &c, 1);         \
45 46
} G_STMT_END

47
#define READ_COMMAND(o, command, res)        \
48
G_STMT_START {                                 \
49
  res = read(READ_SOCKET(o), &command, 1);   \
50
} G_STMT_END
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
51

52

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
53 54 55 56 57
GST_DEBUG_CATEGORY (tcpclientsrc_debug);
#define GST_CAT_DEFAULT tcpclientsrc_debug

#define MAX_READ_SIZE			4 * 1024

58

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
59
static GstElementDetails gst_tcp_client_src_details =
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
60 61 62 63 64
GST_ELEMENT_DETAILS ("TCP Client source",
    "Source/Network",
    "Receive data as a client over the network via TCP",
    "Thomas Vander Stichele <thomas at apestaart dot org>");

Wim Taymans's avatar
Wim Taymans committed
65 66 67 68 69
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS_ANY);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
70 71 72

enum
{
73 74 75 76
  PROP_0,
  PROP_HOST,
  PROP_PORT,
  PROP_PROTOCOL
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
77 78
};

79

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
80
GST_BOILERPLATE (GstTCPClientSrc, gst_tcp_client_src, GstPushSrc,
81 82 83
    GST_TYPE_PUSH_SRC);


Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
84
static void gst_tcp_client_src_finalize (GObject * gobject);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
85

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
86
static GstCaps *gst_tcp_client_src_getcaps (GstBaseSrc * psrc);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
87

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
88
static GstFlowReturn gst_tcp_client_src_create (GstPushSrc * psrc,
Wim Taymans's avatar
Wim Taymans committed
89
    GstBuffer ** outbuf);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
90 91 92
static gboolean gst_tcp_client_src_stop (GstBaseSrc * bsrc);
static gboolean gst_tcp_client_src_start (GstBaseSrc * bsrc);
static gboolean gst_tcp_client_src_unlock (GstBaseSrc * bsrc);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
93

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
94
static void gst_tcp_client_src_set_property (GObject * object, guint prop_id,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
95
    const GValue * value, GParamSpec * pspec);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
96
static void gst_tcp_client_src_get_property (GObject * object, guint prop_id,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
97 98 99 100
    GValue * value, GParamSpec * pspec);


static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
101
gst_tcp_client_src_base_init (gpointer g_class)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
102 103 104
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);

Wim Taymans's avatar
Wim Taymans committed
105 106 107
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&srctemplate));

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
108
  gst_element_class_set_details (element_class, &gst_tcp_client_src_details);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
109 110 111
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
112
gst_tcp_client_src_class_init (GstTCPClientSrcClass * klass)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
113 114
{
  GObjectClass *gobject_class;
Wim Taymans's avatar
Wim Taymans committed
115
  GstBaseSrcClass *gstbasesrc_class;
116
  GstPushSrcClass *gstpush_src_class;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
117 118

  gobject_class = (GObjectClass *) klass;
Wim Taymans's avatar
Wim Taymans committed
119
  gstbasesrc_class = (GstBaseSrcClass *) klass;
120
  gstpush_src_class = (GstPushSrcClass *) klass;
Wim Taymans's avatar
Wim Taymans committed
121

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
122 123 124
  gobject_class->set_property = gst_tcp_client_src_set_property;
  gobject_class->get_property = gst_tcp_client_src_get_property;
  gobject_class->finalize = gst_tcp_client_src_finalize;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
125

126
  g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_HOST,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
127 128 129
      g_param_spec_string ("host", "Host",
          "The host IP address to receive packets from", TCP_DEFAULT_HOST,
          G_PARAM_READWRITE));
130
  g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
131
      g_param_spec_int ("port", "Port", "The port to receive packets from", 0,
132
          TCP_HIGHEST_PORT, TCP_DEFAULT_PORT, G_PARAM_READWRITE));
133
  g_object_class_install_property (gobject_class, PROP_PROTOCOL,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
134
      g_param_spec_enum ("protocol", "Protocol", "The protocol to wrap data in",
135
          GST_TYPE_TCP_PROTOCOL, GST_TCP_PROTOCOL_NONE, G_PARAM_READWRITE));
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
136

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
137 138 139 140
  gstbasesrc_class->get_caps = gst_tcp_client_src_getcaps;
  gstbasesrc_class->start = gst_tcp_client_src_start;
  gstbasesrc_class->stop = gst_tcp_client_src_stop;
  gstbasesrc_class->unlock = gst_tcp_client_src_unlock;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
141

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
142
  gstpush_src_class->create = gst_tcp_client_src_create;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
143 144 145 146 147 148

  GST_DEBUG_CATEGORY_INIT (tcpclientsrc_debug, "tcpclientsrc", 0,
      "TCP Client Source");
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
149
gst_tcp_client_src_init (GstTCPClientSrc * this, GstTCPClientSrcClass * g_class)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
150 151 152 153
{
  this->port = TCP_DEFAULT_PORT;
  this->host = g_strdup (TCP_DEFAULT_HOST);
  this->sock_fd = -1;
154
  this->protocol = GST_TCP_PROTOCOL_NONE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
155
  this->caps = NULL;
Wim Taymans's avatar
Wim Taymans committed
156

157 158 159
  READ_SOCKET (this) = -1;
  WRITE_SOCKET (this) = -1;

Andy Wingo Wingo's avatar
Andy Wingo Wingo committed
160
  gst_base_src_set_live (GST_BASE_SRC (this), TRUE);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
161

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
162
  GST_OBJECT_FLAG_UNSET (this, GST_TCP_CLIENT_SRC_OPEN);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
163 164
}

165
static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
166
gst_tcp_client_src_finalize (GObject * gobject)
167
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
168
  GstTCPClientSrc *this = GST_TCP_CLIENT_SRC (gobject);
169 170 171 172

  g_free (this->host);
}

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
173
static GstCaps *
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
174
gst_tcp_client_src_getcaps (GstBaseSrc * bsrc)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
175 176
{
  GstTCPClientSrc *src;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
177
  GstCaps *caps = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
178

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
179
  src = GST_TCP_CLIENT_SRC (bsrc);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
180

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
181
  if (!GST_OBJECT_FLAG_IS_SET (src, GST_TCP_CLIENT_SRC_OPEN))
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
182 183 184 185 186 187 188 189
    caps = gst_caps_new_any ();
  else if (src->caps)
    caps = gst_caps_copy (src->caps);
  else
    caps = gst_caps_new_any ();
  GST_DEBUG_OBJECT (src, "returning caps %" GST_PTR_FORMAT, caps);
  g_assert (GST_IS_CAPS (caps));
  return caps;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
190 191
}

Wim Taymans's avatar
Wim Taymans committed
192
static GstFlowReturn
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
193
gst_tcp_client_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
194 195
{
  GstTCPClientSrc *src;
Andy Wingo Wingo's avatar
Andy Wingo Wingo committed
196
  GstFlowReturn ret = GST_FLOW_OK;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
197

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
198
  src = GST_TCP_CLIENT_SRC (psrc);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
199

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
200
  if (!GST_OBJECT_FLAG_IS_SET (src, GST_TCP_CLIENT_SRC_OPEN))
Wim Taymans's avatar
Wim Taymans committed
201
    goto wrong_state;
202

Wim Taymans's avatar
Wim Taymans committed
203
  GST_LOG_OBJECT (src, "asked for a buffer");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
204 205 206

  /* read the buffer header if we're using a protocol */
  switch (src->protocol) {
207
    case GST_TCP_PROTOCOL_NONE:
208 209
      ret = gst_tcp_read_buffer (GST_ELEMENT (src), src->sock_fd,
          READ_SOCKET (src), outbuf);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
210
      break;
211

212
    case GST_TCP_PROTOCOL_GDP:
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
      /* get the caps if we're using GDP */
      if (!src->caps_received) {
        GstCaps *caps;

        GST_DEBUG_OBJECT (src, "getting caps through GDP");
        ret = gst_tcp_gdp_read_caps (GST_ELEMENT (src), src->sock_fd,
            READ_SOCKET (src), &caps);

        if (ret != GST_FLOW_OK)
          goto no_caps;

        src->caps_received = TRUE;
        src->caps = caps;
      }

      ret = gst_tcp_gdp_read_buffer (GST_ELEMENT (src), src->sock_fd,
          READ_SOCKET (src), outbuf);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
230 231
      break;
    default:
Wim Taymans's avatar
Wim Taymans committed
232 233
      /* need to assert as buf == NULL */
      g_assert ("Unhandled protocol type");
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
234 235 236
      break;
  }

237 238 239 240 241 242 243 244 245 246 247 248
  if (ret == GST_FLOW_OK) {
    GST_LOG_OBJECT (src,
        "Returning buffer from _get of size %d, ts %"
        GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT
        ", offset %" G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT,
        GST_BUFFER_SIZE (*outbuf),
        GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (*outbuf)),
        GST_TIME_ARGS (GST_BUFFER_DURATION (*outbuf)),
        GST_BUFFER_OFFSET (*outbuf), GST_BUFFER_OFFSET_END (*outbuf));

    gst_buffer_set_caps (*outbuf, src->caps);
  }
Wim Taymans's avatar
Wim Taymans committed
249

250
  return ret;
Wim Taymans's avatar
Wim Taymans committed
251 252 253

wrong_state:
  {
254
    GST_DEBUG_OBJECT (src, "connection to closed, cannot read data");
Wim Taymans's avatar
Wim Taymans committed
255 256
    return GST_FLOW_WRONG_STATE;
  }
257 258 259 260 261 262
no_caps:
  {
    GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
        ("Could not read caps through GDP"));
    return ret;
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
263 264 265
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
266
gst_tcp_client_src_set_property (GObject * object, guint prop_id,
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
267 268
    const GValue * value, GParamSpec * pspec)
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
269
  GstTCPClientSrc *tcpclientsrc = GST_TCP_CLIENT_SRC (object);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
270 271

  switch (prop_id) {
272
    case PROP_HOST:
273 274 275 276
      if (!g_value_get_string (value)) {
        g_warning ("host property cannot be NULL");
        break;
      }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
277 278 279
      g_free (tcpclientsrc->host);
      tcpclientsrc->host = g_strdup (g_value_get_string (value));
      break;
280
    case PROP_PORT:
281 282
      tcpclientsrc->port = g_value_get_int (value);
      break;
283
    case PROP_PROTOCOL:
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
284 285
      tcpclientsrc->protocol = g_value_get_enum (value);
      break;
286

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
287 288 289 290 291 292 293
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
294 295
gst_tcp_client_src_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
296
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
297
  GstTCPClientSrc *tcpclientsrc = GST_TCP_CLIENT_SRC (object);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
298 299

  switch (prop_id) {
300
    case PROP_HOST:
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
301 302
      g_value_set_string (value, tcpclientsrc->host);
      break;
303
    case PROP_PORT:
304 305
      g_value_set_int (value, tcpclientsrc->port);
      break;
306
    case PROP_PROTOCOL:
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
307 308 309 310 311 312 313 314 315 316 317
      g_value_set_enum (value, tcpclientsrc->protocol);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

/* create a socket for connecting to remote server */
static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
318
gst_tcp_client_src_start (GstBaseSrc * bsrc)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
319
{
320 321
  int ret;
  gchar *ip;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
322
  GstTCPClientSrc *src = GST_TCP_CLIENT_SRC (bsrc);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
323

324 325 326 327 328 329 330
  /* create the control sockets before anything */
  if (socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (src)) < 0)
    goto socket_pair;

  fcntl (READ_SOCKET (src), F_SETFL, O_NONBLOCK);
  fcntl (WRITE_SOCKET (src), F_SETFL, O_NONBLOCK);

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
331
  /* create receiving client socket */
Wim Taymans's avatar
Wim Taymans committed
332 333 334 335 336 337 338 339
  GST_DEBUG_OBJECT (src, "opening receiving client socket to %s:%d",
      src->host, src->port);

  if ((src->sock_fd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
    goto no_socket;

  GST_DEBUG_OBJECT (src, "opened receiving client socket with fd %d",
      src->sock_fd);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
340
  GST_OBJECT_FLAG_SET (src, GST_TCP_CLIENT_SRC_OPEN);
341

342
  /* look up name if we need to */
Wim Taymans's avatar
Wim Taymans committed
343 344 345 346
  if (!(ip = gst_tcp_host_to_ip (GST_ELEMENT (src), src->host)))
    goto name_resolv;

  GST_DEBUG_OBJECT (src, "IP address for host %s is %s", src->host, ip);
347 348

  /* connect to server */
Wim Taymans's avatar
Wim Taymans committed
349 350 351 352
  memset (&src->server_sin, 0, sizeof (src->server_sin));
  src->server_sin.sin_family = AF_INET; /* network socket */
  src->server_sin.sin_port = htons (src->port); /* on port */
  src->server_sin.sin_addr.s_addr = inet_addr (ip);     /* on host ip */
Wim Taymans's avatar
Wim Taymans committed
353
  g_free (ip);
354

Wim Taymans's avatar
Wim Taymans committed
355 356 357
  GST_DEBUG_OBJECT (src, "connecting to server");
  ret = connect (src->sock_fd, (struct sockaddr *) &src->server_sin,
      sizeof (src->server_sin));
358 359

  if (ret) {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
360
    gst_tcp_client_src_stop (GST_BASE_SRC (src));
361 362
    switch (errno) {
      case ECONNREFUSED:
Wim Taymans's avatar
Wim Taymans committed
363 364
        GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
            (_("Connection to %s:%d refused."), src->host, src->port), (NULL));
365 366 367
        return FALSE;
        break;
      default:
Wim Taymans's avatar
Wim Taymans committed
368 369
        GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL),
            ("connect to %s:%d failed: %s", src->host, src->port,
370 371 372 373 374
                g_strerror (errno)));
        return FALSE;
        break;
    }
  }
375

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
376
  return TRUE;
Wim Taymans's avatar
Wim Taymans committed
377

378
socket_pair:
Wim Taymans's avatar
Wim Taymans committed
379
  {
380 381
    GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL),
        GST_ERROR_SYSTEM);
Wim Taymans's avatar
Wim Taymans committed
382 383
    return FALSE;
  }
384
no_socket:
Wim Taymans's avatar
Wim Taymans committed
385
  {
386
    GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), GST_ERROR_SYSTEM);
Wim Taymans's avatar
Wim Taymans committed
387 388
    return FALSE;
  }
389
name_resolv:
Wim Taymans's avatar
Wim Taymans committed
390
  {
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
391
    gst_tcp_client_src_stop (GST_BASE_SRC (src));
Wim Taymans's avatar
Wim Taymans committed
392 393
    return FALSE;
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
394 395
}

Wim Taymans's avatar
Wim Taymans committed
396 397 398 399
/* close the socket and associated resources
 * unset OPEN flag
 * used both to recover from errors and go to NULL state */
static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
400
gst_tcp_client_src_stop (GstBaseSrc * bsrc)
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
401
{
Wim Taymans's avatar
Wim Taymans committed
402
  GstTCPClientSrc *src;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
403

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
404
  src = GST_TCP_CLIENT_SRC (bsrc);
Wim Taymans's avatar
Wim Taymans committed
405 406 407 408 409

  GST_DEBUG_OBJECT (src, "closing socket");
  if (src->sock_fd != -1) {
    close (src->sock_fd);
    src->sock_fd = -1;
410
  }
Wim Taymans's avatar
Wim Taymans committed
411 412 413 414
  src->caps_received = FALSE;
  if (src->caps) {
    gst_caps_unref (src->caps);
    src->caps = NULL;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
415
  }
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
416
  GST_OBJECT_FLAG_UNSET (src, GST_TCP_CLIENT_SRC_OPEN);
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
417

418 419 420 421 422
  close (READ_SOCKET (src));
  close (WRITE_SOCKET (src));
  READ_SOCKET (src) = -1;
  WRITE_SOCKET (src) = -1;

Wim Taymans's avatar
Wim Taymans committed
423 424
  return TRUE;
}
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
425

426
/* will be called only between calls to start() and stop() */
Wim Taymans's avatar
Wim Taymans committed
427
static gboolean
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
428
gst_tcp_client_src_unlock (GstBaseSrc * bsrc)
Wim Taymans's avatar
Wim Taymans committed
429
{
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
430
  GstTCPClientSrc *src = GST_TCP_CLIENT_SRC (bsrc);
431 432 433

  SEND_COMMAND (src, CONTROL_STOP);

Wim Taymans's avatar
Wim Taymans committed
434
  return TRUE;
Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
435
}