gstmultiudpsink.c 19.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* GStreamer
 * Copyright (C) <2005> Wim Taymans <wim@fluendo.com>
 *
 * 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.
 */

20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * SECTION:element-multiupdsink
 * @see_also: udpsink, multifdsink
 *
 * <refsect2>
 * <para>
 * multiudpsink is a network sink that sends UDP packets to multiple
 * clients.
 * It can be combined with rtp payload encoders to implement RTP streaming.
 * </para>
 * </refsect2>
 */

33
34
35
36
37
38
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstudp-marshal.h"
#include "gstmultiudpsink.h"

39
GST_DEBUG_CATEGORY_STATIC (multiudpsink_debug);
40
41
42
43
44
45
46
47
#define GST_CAT_DEFAULT (multiudpsink_debug)

static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS_ANY);

/* elementfactory information */
48
static const GstElementDetails gst_multiudpsink_details =
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
GST_ELEMENT_DETAILS ("UDP packet sender",
    "Sink/Network",
    "Send data over the network via UDP",
    "Wim Taymans <wim@fluendo.com>");

/* MultiUDPSink signals and args */
enum
{
  /* methods */
  SIGNAL_ADD,
  SIGNAL_REMOVE,
  SIGNAL_CLEAR,
  SIGNAL_GET_STATS,

  /* signals */
  SIGNAL_CLIENT_ADDED,
  SIGNAL_CLIENT_REMOVED,

  /* FILL ME */
  LAST_SIGNAL
};

enum
{
  PROP_0,
74
75
76
  PROP_BYTES_TO_SERVE,
  PROP_BYTES_SERVED,

77
78
79
80
  /* FILL ME */
};

static void gst_multiudpsink_base_init (gpointer g_class);
81
static void gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass);
82
83
84
85
86
static void gst_multiudpsink_init (GstMultiUDPSink * udpsink);
static void gst_multiudpsink_finalize (GObject * object);

static GstFlowReturn gst_multiudpsink_render (GstBaseSink * sink,
    GstBuffer * buffer);
87
88
static GstStateChangeReturn gst_multiudpsink_change_state (GstElement *
    element, GstStateChange transition);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

static void gst_multiudpsink_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec);
static void gst_multiudpsink_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec);

static GstElementClass *parent_class = NULL;

static guint gst_multiudpsink_signals[LAST_SIGNAL] = { 0 };

GType
gst_multiudpsink_get_type (void)
{
  static GType multiudpsink_type = 0;

  if (!multiudpsink_type) {
    static const GTypeInfo multiudpsink_info = {
      sizeof (GstMultiUDPSinkClass),
      gst_multiudpsink_base_init,
      NULL,
      (GClassInitFunc) gst_multiudpsink_class_init,
      NULL,
      NULL,
      sizeof (GstMultiUDPSink),
      0,
      (GInstanceInitFunc) gst_multiudpsink_init,
      NULL
    };

    multiudpsink_type =
119
        g_type_register_static (GST_TYPE_BASE_SINK, "GstMultiUDPSink",
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
        &multiudpsink_info, 0);
  }
  return multiudpsink_type;
}

static void
gst_multiudpsink_base_init (gpointer g_class)
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);

  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&sink_template));

  gst_element_class_set_details (element_class, &gst_multiudpsink_details);
}

static void
137
gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
138
139
140
141
142
143
144
145
146
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;
  GstBaseSinkClass *gstbasesink_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;
  gstbasesink_class = (GstBaseSinkClass *) klass;

147
  parent_class = g_type_class_peek_parent (klass);
148
149
150
151
152

  gobject_class->set_property = gst_multiudpsink_set_property;
  gobject_class->get_property = gst_multiudpsink_get_property;
  gobject_class->finalize = gst_multiudpsink_finalize;

153
154
155
156
157
  /**
   * GstMultiUDPSink::add:
   * @gstmultiudpsink: the sink on which the signal is emitted
   * @host: the hostname/IP address of the client to add
   * @port: the port of the client to add
158
159
160
   *
   * Add a client with destination @host and @port to the list of
   * clients.
161
   */
162
163
164
165
166
  gst_multiudpsink_signals[SIGNAL_ADD] =
      g_signal_new ("add", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
      G_STRUCT_OFFSET (GstMultiUDPSinkClass, add),
      NULL, NULL, gst_udp_marshal_VOID__STRING_INT, G_TYPE_NONE, 2,
      G_TYPE_STRING, G_TYPE_INT);
167
168
169
170
171
  /**
   * GstMultiUDPSink::remove:
   * @gstmultiudpsink: the sink on which the signal is emitted
   * @host: the hostname/IP address of the client to remove
   * @port: the port of the client to remove
172
173
174
   *
   * Remove the client with destination @host and @port from the list of
   * clients.
175
   */
176
177
178
179
180
  gst_multiudpsink_signals[SIGNAL_REMOVE] =
      g_signal_new ("remove", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
      G_STRUCT_OFFSET (GstMultiUDPSinkClass, remove),
      NULL, NULL, gst_udp_marshal_VOID__STRING_INT, G_TYPE_NONE, 2,
      G_TYPE_STRING, G_TYPE_INT);
181
182
183
184
185
186
  /**
   * GstMultiUDPSink::clear:
   * @gstmultiudpsink: the sink on which the signal is emitted
   *
   * Clear the list of clients.
   */
187
188
189
190
  gst_multiudpsink_signals[SIGNAL_CLEAR] =
      g_signal_new ("clear", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
      G_STRUCT_OFFSET (GstMultiUDPSinkClass, clear),
      NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
191
192
193
194
195
196
  /**
   * GstMultiUDPSink::get-stats:
   * @gstmultiudpsink: the sink on which the signal is emitted
   * @host: the hostname/IP address of the client to get stats on
   * @port: the port of the client to get stats on
   *
197
198
199
   * Get the statistics of the client with destination @host and @port.
   *
   * Returns: a GValueArray of uint64: bytes_sent, packets_sent,
200
201
   *           connect_time (in epoch seconds), disconnect_time (in epoch seconds)
   */
202
203
204
205
206
  gst_multiudpsink_signals[SIGNAL_GET_STATS] =
      g_signal_new ("get-stats", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
      G_STRUCT_OFFSET (GstMultiUDPSinkClass, get_stats),
      NULL, NULL, gst_udp_marshal_BOXED__STRING_INT, G_TYPE_VALUE_ARRAY, 2,
      G_TYPE_STRING, G_TYPE_INT);
207
208
209
210
211
  /**
   * GstMultiUDPSink::client-added:
   * @gstmultiudpsink: the sink emitting the signal
   * @host: the hostname/IP address of the added client
   * @port: the port of the added client
212
213
214
   *
   * Signal emited when a new client is added to the list of
   * clients.
215
   */
216
217
218
219
220
  gst_multiudpsink_signals[SIGNAL_CLIENT_ADDED] =
      g_signal_new ("client-added", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstMultiUDPSinkClass, client_added),
      NULL, NULL, gst_udp_marshal_VOID__STRING_INT, G_TYPE_NONE, 2,
      G_TYPE_STRING, G_TYPE_INT);
221
222
223
224
225
  /**
   * GstMultiUDPSink::client-removed:
   * @gstmultiudpsink: the sink emitting the signal
   * @host: the hostname/IP address of the removed client
   * @port: the port of the removed client
226
227
228
   *
   * Signal emited when a client is removed from the list of
   * clients.
229
   */
230
231
232
233
234
235
  gst_multiudpsink_signals[SIGNAL_CLIENT_REMOVED] =
      g_signal_new ("client-removed", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstMultiUDPSinkClass,
          client_removed), NULL, NULL, gst_udp_marshal_VOID__STRING_INT,
      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT);

236
237
238
239
240
241
242
243
244
  g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BYTES_TO_SERVE,
      g_param_spec_uint64 ("bytes-to-serve", "Bytes to serve",
          "Number of bytes received to serve to clients", 0, G_MAXUINT64, 0,
          G_PARAM_READABLE));
  g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BYTES_SERVED,
      g_param_spec_uint64 ("bytes-served", "Bytes served",
          "Total number of bytes send to all clients", 0, G_MAXUINT64, 0,
          G_PARAM_READABLE));

245
246
247
  gstelement_class->change_state = gst_multiudpsink_change_state;

  gstbasesink_class->render = gst_multiudpsink_render;
248
249
250
251
  klass->add = gst_multiudpsink_add;
  klass->remove = gst_multiudpsink_remove;
  klass->clear = gst_multiudpsink_clear;
  klass->get_stats = gst_multiudpsink_get_stats;
252
253
254
255
256
257
258
259

  GST_DEBUG_CATEGORY_INIT (multiudpsink_debug, "multiudpsink", 0, "UDP sink");
}


static void
gst_multiudpsink_init (GstMultiUDPSink * sink)
{
260
261
  WSA_STARTUP (sink);

262
263
264
265
266
267
268
269
270
271
272
273
  sink->client_lock = g_mutex_new ();
}

static void
gst_multiudpsink_finalize (GObject * object)
{
  GstMultiUDPSink *sink;

  sink = GST_MULTIUDPSINK (object);

  g_mutex_free (sink->client_lock);

274
275
  WSA_CLEANUP (object);

276
277
278
279
280
281
282
  G_OBJECT_CLASS (parent_class)->finalize (object);
}

static GstFlowReturn
gst_multiudpsink_render (GstBaseSink * bsink, GstBuffer * buffer)
{
  GstMultiUDPSink *sink;
283
  gint ret, size, num = 0;
284
285
286
287
288
289
290
291
  guint8 *data;
  GList *clients;

  sink = GST_MULTIUDPSINK (bsink);

  size = GST_BUFFER_SIZE (buffer);
  data = GST_BUFFER_DATA (buffer);

292
293
294
295
  sink->bytes_to_serve += size;

  /* grab lock while iterating and sending to clients, this shuld be
   * fast as UDP never blocks */
296
  g_mutex_lock (sink->client_lock);
297
298
  GST_LOG_OBJECT (bsink, "about to send %d bytes", size);

299
300
301
302
  for (clients = sink->clients; clients; clients = g_list_next (clients)) {
    GstUDPClient *client;

    client = (GstUDPClient *) clients->data;
303
    num++;
304
    GST_LOG_OBJECT (sink, "sending %d bytes to client %p", size, client);
305
306
307
308
309
310
311
312
313

    while (TRUE) {
      ret = sendto (*client->sock, data, size, 0,
          (struct sockaddr *) &client->theiraddr, sizeof (client->theiraddr));

      if (ret < 0) {
        if (errno != EINTR && errno != EAGAIN) {
          goto send_error;
        }
314
315
      } else {
        client->bytes_sent += ret;
316
        client->packets_sent++;
317
        sink->bytes_served += ret;
318
        break;
319
      }
320
321
322
323
    }
  }
  g_mutex_unlock (sink->client_lock);

324
  GST_LOG_OBJECT (sink, "sent %d bytes to %d clients", size, num);
325
326
327

  return GST_FLOW_OK;

328
  /* ERRORS */
329
330
send_error:
  {
331
    /* if sendto returns an error, something is seriously wrong */
332
    g_mutex_unlock (sink->client_lock);
333
334
335
    GST_DEBUG_OBJECT (sink, "got send error %d: %s", errno, g_strerror (errno));
    GST_ELEMENT_ERROR (sink, STREAM, FAILED, (NULL),
        ("Got send error %d: %s", errno, g_strerror (errno)));
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
    return GST_FLOW_ERROR;
  }
}

static void
gst_multiudpsink_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstMultiUDPSink *udpsink;

  udpsink = GST_MULTIUDPSINK (object);

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

static void
gst_multiudpsink_get_property (GObject * object, guint prop_id, GValue * value,
    GParamSpec * pspec)
{
  GstMultiUDPSink *udpsink;

  udpsink = GST_MULTIUDPSINK (object);

  switch (prop_id) {
364
365
366
367
368
369
370
    case PROP_BYTES_TO_SERVE:
      g_value_set_uint64 (value, udpsink->bytes_to_serve);
      break;
    case PROP_BYTES_SERVED:
      g_value_set_uint64 (value, udpsink->bytes_served);
      break;

371
372
373
374
375
376
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
static void
join_multicast (GstUDPClient * client)
{
  unsigned char ttl = 64;
  unsigned char loop = 1;

  /* Joining the multicast group */
  /* FIXME, can we use multicast and unicast over the same
   * socket? if not, search for socket of this multicast group or
   * create a new one. */
  if (setsockopt (*(client->sock), IPPROTO_IP, IP_ADD_MEMBERSHIP,
          &(client->multi_addr), sizeof (client->multi_addr)) < 0)
    perror ("setsockopt IP_ADD_MEMBERSHIP\n");
  if (setsockopt (*(client->sock), IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
          sizeof (ttl)) < 0)
    perror ("setsockopt IP_MULTICAST_TTL\n");
  if (setsockopt (*(client->sock), IPPROTO_IP, IP_MULTICAST_LOOP, &loop,
          sizeof (loop)) < 0)
    perror ("setsockopt IP_MULTICAST_LOOP\n");
}
397
398
399
400
401
402
403

/* create a socket for sending to remote machine */
static gboolean
gst_multiudpsink_init_send (GstMultiUDPSink * sink)
{
  guint bc_val;
  gint ret;
404
405
  GList *clients;
  GstUDPClient *client;
406
407
408
409
410
411
412
413
414
415
416

  /* create sender socket */
  if ((sink->sock = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
    goto no_socket;

  bc_val = 1;
  if ((ret =
          setsockopt (sink->sock, SOL_SOCKET, SO_BROADCAST, &bc_val,
              sizeof (bc_val))) < 0)
    goto no_broadcast;

417
418
419
  sink->bytes_to_serve = 0;
  sink->bytes_served = 0;

420
  /* look for multicast clients and join multicast groups approptiately */
421

422
423
424
425
426
427
  for (clients = sink->clients; clients; clients = g_list_next (clients)) {
    client = (GstUDPClient *) clients->data;
    if (client->multi_addr.imr_multiaddr.s_addr)
      join_multicast (client);
  }
  return TRUE;
428
429
430
  /* ERRORS */
no_socket:
  {
431
432
    GST_ELEMENT_ERROR (sink, RESOURCE, FAILED, (NULL),
        ("Could not create socket (%d): %s", errno, g_strerror (errno)));
433
434
435
436
    return FALSE;
  }
no_broadcast:
  {
437
438
439
    GST_ELEMENT_ERROR (sink, RESOURCE, SETTINGS, (NULL),
        ("Could not set broadcast socket option (%d): %s", errno,
            g_strerror (errno)));
440
441
442
443
444
445
446
    return FALSE;
  }
}

static void
gst_multiudpsink_close (GstMultiUDPSink * sink)
{
447
  CLOSE_SOCKET (sink->sock);
448
449
450
451
452
453
454
455
}

void
gst_multiudpsink_add (GstMultiUDPSink * sink, const gchar * host, gint port)
{
  struct hostent *he;
  struct in_addr addr;
  GstUDPClient *client;
456
  GTimeVal now;
457

458
  GST_DEBUG_OBJECT (sink, "adding client on host %s, port %d", host, port);
459
460
461
462
463
464
  client = g_new0 (GstUDPClient, 1);
  client->host = g_strdup (host);
  client->port = port;
  client->sock = &sink->sock;

  memset (&client->theiraddr, 0, sizeof (client->theiraddr));
465
  memset (&client->multi_addr, 0, sizeof (client->multi_addr));
466
467
468
  client->theiraddr.sin_family = AF_INET;       /* host byte order */
  client->theiraddr.sin_port = htons (port);    /* short, network byte order */

469
470
471
  g_get_current_time (&now);
  client->connect_time = GST_TIMEVAL_TO_TIME (now);

472
473
474
475
  /* if its an IP address */
  if (inet_aton (host, &addr)) {
    /* check if its a multicast address */
    if ((ntohl (addr.s_addr) & 0xe0000000) == 0xe0000000) {
476
      GST_DEBUG_OBJECT (sink, "multicast address  detected");
477
478
479
      client->multi_addr.imr_multiaddr.s_addr = addr.s_addr;
      client->multi_addr.imr_interface.s_addr = INADDR_ANY;

480
      client->theiraddr.sin_addr = client->multi_addr.imr_multiaddr;
481
482
483
484

    } else {
      client->theiraddr.sin_addr = *((struct in_addr *) &addr);
    }
485
486
487
    /* if init_send has already been called, set sockopts for multicast */
    if (*client->sock > 0)
      join_multicast (client);
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
  }
  /* we dont need to lookup for localhost */
  else if (strcmp (host, "localhost") == 0 && inet_aton ("127.0.0.1", &addr)) {
    client->theiraddr.sin_addr = *((struct in_addr *) &addr);
  }
  /* if its a hostname */
  else if ((he = gethostbyname (host))) {
    client->theiraddr.sin_addr = *((struct in_addr *) he->h_addr);
  } else {
    goto host_error;
  }

  g_mutex_lock (sink->client_lock);
  sink->clients = g_list_prepend (sink->clients, client);
  g_mutex_unlock (sink->client_lock);

504
505
506
  g_signal_emit (G_OBJECT (sink),
      gst_multiudpsink_signals[SIGNAL_CLIENT_ADDED], 0, host, port);

507
508
509
510
511
  return;

  /* ERRORS */
host_error:
  {
512
    GST_WARNING_OBJECT (sink, "hostname lookup error?");
513
514
515
516
517
518
    g_free (client->host);
    g_free (client);
    return;
  }
}

519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
static gint
client_compare (GstUDPClient * a, GstUDPClient * b)
{
  if ((a->port == b->port) && (strcmp (a->host, b->host) == 0))
    return 0;

  return 1;
}

static void
free_client (GstUDPClient * client)
{
  g_free (client->host);
  g_free (client);
}

535
536
537
void
gst_multiudpsink_remove (GstMultiUDPSink * sink, const gchar * host, gint port)
{
538
539
  GList *find;
  GstUDPClient udpclient;
540
541
  GstUDPClient *client;
  GTimeVal now;
542
543
544
545
546
547
548

  udpclient.host = (gchar *) host;
  udpclient.port = port;

  g_mutex_lock (sink->client_lock);
  find = g_list_find_custom (sink->clients, &udpclient,
      (GCompareFunc) client_compare);
549
550
  if (!find)
    goto not_found;
551

552
  GST_DEBUG_OBJECT (sink, "remove client with host %s, port %d", host, port);
553

554
  client = (GstUDPClient *) find->data;
555

556
557
  g_get_current_time (&now);
  client->disconnect_time = GST_TIMEVAL_TO_TIME (now);
558

559
560
561
562
563
  /* Unlock to emit signal before we delete the actual client */
  g_mutex_unlock (sink->client_lock);
  g_signal_emit (G_OBJECT (sink),
      gst_multiudpsink_signals[SIGNAL_CLIENT_REMOVED], 0, host, port);
  g_mutex_lock (sink->client_lock);
564

565
566
567
  sink->clients = g_list_delete_link (sink->clients, find);

  free_client (client);
568
  g_mutex_unlock (sink->client_lock);
569
570
571
572
573
574
575
576
577
578
579

  return;

  /* ERRORS */
not_found:
  {
    g_mutex_unlock (sink->client_lock);
    GST_WARNING_OBJECT (sink, "client at host %s, port %d not found",
        host, port);
    return;
  }
580
581
582
583
584
}

void
gst_multiudpsink_clear (GstMultiUDPSink * sink)
{
585
  GST_DEBUG_OBJECT (sink, "clearing");
586
587
  /* we only need to remove the client structure, there is no additional
   * socket or anything to free for UDP */
588
589
590
591
592
  g_mutex_lock (sink->client_lock);
  g_list_foreach (sink->clients, (GFunc) free_client, sink);
  g_list_free (sink->clients);
  sink->clients = NULL;
  g_mutex_unlock (sink->client_lock);
593
594
595
596
597
598
}

GValueArray *
gst_multiudpsink_get_stats (GstMultiUDPSink * sink, const gchar * host,
    gint port)
{
599
600
601
602
  GstUDPClient *client;
  GValueArray *result = NULL;
  GstUDPClient udpclient;
  GList *find;
603
  GValue value = { 0 };
604
605
606
607
608
609
610
611

  udpclient.host = (gchar *) host;
  udpclient.port = port;

  g_mutex_lock (sink->client_lock);

  find = g_list_find_custom (sink->clients, &udpclient,
      (GCompareFunc) client_compare);
612
613
  if (!find)
    goto not_found;
614

615
  GST_DEBUG_OBJECT (sink, "stats for client with host %s, port %d", host, port);
616

617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
  client = (GstUDPClient *) find->data;

  /* Result is a value array of (bytes_sent, packets_sent,
   * connect_time, disconnect_time), all as uint64 */
  result = g_value_array_new (4);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->bytes_sent);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->packets_sent);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->connect_time);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_value_init (&value, G_TYPE_UINT64);
  g_value_set_uint64 (&value, client->disconnect_time);
  result = g_value_array_append (result, &value);
  g_value_unset (&value);

  g_mutex_unlock (sink->client_lock);
644
645

  return result;
646
647
648
649
650
651
652
653
654
655
656

  /* ERRORS */
not_found:
  {
    g_mutex_unlock (sink->client_lock);
    GST_WARNING_OBJECT (sink, "client with host %s, port %d not found",
        host, port);
    /* Apparently (see comment in gstmultifdsink.c) returning NULL from here may
     * confuse/break python bindings */
    return g_value_array_new (0);
  }
657
658
}

659
660
static GstStateChangeReturn
gst_multiudpsink_change_state (GstElement * element, GstStateChange transition)
661
{
662
  GstStateChangeReturn ret;
663
664
665
666
667
  GstMultiUDPSink *sink;

  sink = GST_MULTIUDPSINK (element);

  switch (transition) {
668
    case GST_STATE_CHANGE_READY_TO_PAUSED:
669
670
671
672
673
674
675
      if (!gst_multiudpsink_init_send (sink))
        goto no_init;
      break;
    default:
      break;
  }

676
  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
677
678

  switch (transition) {
679
    case GST_STATE_CHANGE_PAUSED_TO_READY:
680
681
682
683
684
685
686
687
688
689
      gst_multiudpsink_close (sink);
      break;
    default:
      break;
  }
  return ret;

  /* ERRORS */
no_init:
  {
690
    /* _init_send() posted specific error already */
691
    return GST_STATE_CHANGE_FAILURE;
692
693
  }
}