gstrtpsink.c 21.1 KB
Newer Older
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* GStreamer
 * Copyright (C) <2018> Marc Leeman <marc.leeman@gmail.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., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

/**
 * SECTION: gstrtsinkp
 * @title: GstRtpSink
 * @short description: element with Uri interface to stream RTP data to
 * the network.
 *
 * RTP (RFC 3550) is a protocol to stream media over the network while
 * retaining the timing information and providing enough information to
 * reconstruct the correct timing domain by the receiver.
 *
 * The RTP data port should be even, while the RTCP port should be
 * odd. The URI that is entered defines the data port, the RTCP port will
 * be allocated to the next port.
 *
 * This element hooks up the correct sockets to support both RTP as the
 * accompanying RTCP layer.
 *
 * This Bin handles streaming RTP payloaded data on the network.
 *
 * This element also implements the URI scheme `rtp://` allowing to send
 * data on the network by bins that allow use the URI to determine the sink.
 * The RTP URI handler also allows setting properties through the URI query.
 */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gio/gio.h>

#include "gstrtpsink.h"
#include "gstrtp-utils.h"

GST_DEBUG_CATEGORY_STATIC (gst_rtp_sink_debug);
#define GST_CAT_DEFAULT gst_rtp_sink_debug

#define DEFAULT_PROP_TTL              64
#define DEFAULT_PROP_TTL_MC           1

58
59
60
#define DEFAULT_PROP_ADDRESS          "0.0.0.0"
#define DEFAULT_PROP_PORT             5004
#define DEFAULT_PROP_URI              "rtp://"DEFAULT_PROP_ADDRESS":"G_STRINGIFY(DEFAULT_PROP_PORT)
61
#define DEFAULT_PROP_MULTICAST_IFACE  NULL
62

63
64
65
66
67
enum
{
  PROP_0,

  PROP_URI,
68
69
  PROP_ADDRESS,
  PROP_PORT,
70
71
  PROP_TTL,
  PROP_TTL_MC,
72
  PROP_MULTICAST_IFACE,
73
74
75
76
77
78
79
80
81
82
83

  PROP_LAST
};

static void gst_rtp_sink_uri_handler_init (gpointer g_iface,
    gpointer iface_data);

#define gst_rtp_sink_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstRtpSink, gst_rtp_sink, GST_TYPE_BIN,
    G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_rtp_sink_uri_handler_init);
    GST_DEBUG_CATEGORY_INIT (gst_rtp_sink_debug, "rtpsink", 0, "RTP Sink"));
84
85
GST_ELEMENT_REGISTER_DEFINE (rtpsink, "rtpsink", GST_RANK_PRIMARY + 1,
    GST_TYPE_RTP_SINK);
86
87
88
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

#define GST_RTP_SINK_GET_LOCK(obj) (&((GstRtpSink*)(obj))->lock)
#define GST_RTP_SINK_LOCK(obj) (g_mutex_lock (GST_RTP_SINK_GET_LOCK(obj)))
#define GST_RTP_SINK_UNLOCK(obj) (g_mutex_unlock (GST_RTP_SINK_GET_LOCK(obj)))

static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink_%u",
    GST_PAD_SINK,
    GST_PAD_REQUEST,
    GST_STATIC_CAPS ("application/x-rtp"));

static GstStateChangeReturn
gst_rtp_sink_change_state (GstElement * element, GstStateChange transition);

static void
gst_rtp_sink_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec)
{
  GstRtpSink *self = GST_RTP_SINK (object);

  switch (prop_id) {
    case PROP_URI:{
      GstUri *uri = NULL;

      GST_RTP_SINK_LOCK (object);
      uri = gst_uri_from_string (g_value_get_string (value));
      if (uri == NULL)
        break;

      if (self->uri)
        gst_uri_unref (self->uri);
      self->uri = uri;

      gst_rtp_utils_set_properties_from_uri_query (G_OBJECT (self), self->uri);
119
120
121
122

      g_object_set (self, "address", gst_uri_get_host (self->uri), NULL);
      g_object_set (self, "port", gst_uri_get_port (self->uri), NULL);

123
124
125
      GST_RTP_SINK_UNLOCK (object);
      break;
    }
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
    case PROP_ADDRESS:
      gst_uri_set_host (self->uri, g_value_get_string (value));
      g_object_set_property (G_OBJECT (self->rtp_sink), "host", value);
      g_object_set_property (G_OBJECT (self->rtcp_sink), "host", value);
      break;

    case PROP_PORT:{
      guint port = g_value_get_uint (value);

      /* According to RFC 3550, 11, RTCP receiver port should be even
       * number and RTCP port should be the RTP port + 1 */
      if (port & 0x1)
        GST_WARNING_OBJECT (self,
            "Port %u is odd, this is not standard (see RFC 3550).", port);

      gst_uri_set_port (self->uri, port);
      g_object_set (self->rtp_sink, "port", port, NULL);
      g_object_set (self->rtcp_sink, "port", port + 1, NULL);
      break;
    }
146
147
    case PROP_TTL:
      self->ttl = g_value_get_int (value);
148
149
      g_object_set (self->rtp_sink, "ttl", self->ttl, NULL);
      g_object_set (self->rtcp_sink, "ttl", self->ttl, NULL);
150
151
152
      break;
    case PROP_TTL_MC:
      self->ttl_mc = g_value_get_int (value);
153
154
      g_object_set (self->rtp_sink, "ttl-mc", self->ttl_mc, NULL);
      g_object_set (self->rtcp_sink, "ttl-mc", self->ttl_mc, NULL);
155
      break;
156
157
158
159
160
161
162
163
    case PROP_MULTICAST_IFACE:
      g_free (self->multi_iface);

      if (g_value_get_string (value) == NULL)
        self->multi_iface = g_strdup (DEFAULT_PROP_MULTICAST_IFACE);
      else
        self->multi_iface = g_value_dup_string (value);
      break;
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
gst_rtp_sink_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec)
{
  GstRtpSink *self = GST_RTP_SINK (object);

  switch (prop_id) {
    case PROP_URI:
      GST_RTP_SINK_LOCK (object);
      if (self->uri)
        g_value_take_string (value, gst_uri_to_string (self->uri));
      else
        g_value_set_string (value, NULL);
      GST_RTP_SINK_UNLOCK (object);
      break;
185
186
187
188
189
190
    case PROP_ADDRESS:
      g_value_set_string (value, gst_uri_get_host (self->uri));
      break;
    case PROP_PORT:
      g_value_set_uint (value, gst_uri_get_port (self->uri));
      break;
191
192
193
194
195
196
    case PROP_TTL:
      g_value_set_int (value, self->ttl);
      break;
    case PROP_TTL_MC:
      g_value_set_int (value, self->ttl_mc);
      break;
197
198
199
    case PROP_MULTICAST_IFACE:
      g_value_set_string (value, self->multi_iface);
      break;
200
201
202
203
204
205
206
207
208
209
210
211
212
213
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}

static void
gst_rtp_sink_finalize (GObject * gobject)
{
  GstRtpSink *self = GST_RTP_SINK (gobject);

  if (self->uri)
    gst_uri_unref (self->uri);

214
215
  g_free (self->multi_iface);

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
  g_mutex_clear (&self->lock);
  G_OBJECT_CLASS (parent_class)->finalize (gobject);
}

static gboolean
gst_rtp_sink_setup_elements (GstRtpSink * self)
{
  /*GstPad *pad; */
  gchar name[48];

  /* pads are all named */
  g_snprintf (name, 48, "send_rtp_src_%u", GST_ELEMENT (self)->numpads);
  gst_element_link_pads (self->rtpbin, name, self->funnel_rtp, "sink_%u");

  g_snprintf (name, 48, "send_rtcp_src_%u", GST_ELEMENT (self)->numpads);
  gst_element_link_pads (self->rtpbin, name, self->funnel_rtcp, "sink_%u");

  g_snprintf (name, 48, "recv_rtcp_sink_%u", GST_ELEMENT (self)->numpads);
  gst_element_link_pads (self->rtcp_src, "src", self->rtpbin, name);

  return TRUE;
}

static GstPad *
gst_rtp_sink_request_new_pad (GstElement * element,
    GstPadTemplate * templ, const gchar * name, const GstCaps * caps)
{
  GstRtpSink *self = GST_RTP_SINK (element);
244
  GstPad *rpad, *pad = NULL;
245
246
247
248
249
250
251
252
253
254
255

  if (self->rtpbin == NULL) {
    GST_ELEMENT_ERROR (self, CORE, MISSING_PLUGIN, (NULL),
        ("%s", "rtpbin element is not available"));
    return NULL;
  }

  if (gst_rtp_sink_setup_elements (self) == FALSE)
    return NULL;

  GST_RTP_SINK_LOCK (self);
256
257
258
259
260
261
  rpad = gst_element_request_pad_simple (self->rtpbin, "send_rtp_sink_%u");
  if (rpad) {
    pad = gst_ghost_pad_new (GST_PAD_NAME (rpad), rpad);
    gst_element_add_pad (element, pad);
    gst_clear_object (&rpad);
  }
262
263
  GST_RTP_SINK_UNLOCK (self);

264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
  g_return_val_if_fail (pad != NULL, NULL);


  return pad;
}

static void
gst_rtp_sink_release_pad (GstElement * element, GstPad * pad)
{
  GstRtpSink *self = GST_RTP_SINK (element);
  GstPad *rpad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));

  GST_RTP_SINK_LOCK (self);
  gst_element_release_request_pad (self->rtpbin, rpad);
  gst_object_unref (rpad);

  gst_pad_set_active (pad, FALSE);
  gst_element_remove_pad (GST_ELEMENT (self), pad);

  GST_RTP_SINK_UNLOCK (self);
}

static void
gst_rtp_sink_class_init (GstRtpSinkClass * klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);

  gobject_class->set_property = gst_rtp_sink_set_property;
  gobject_class->get_property = gst_rtp_sink_get_property;
  gobject_class->finalize = gst_rtp_sink_finalize;
  gstelement_class->change_state = gst_rtp_sink_change_state;

  gstelement_class->request_new_pad =
      GST_DEBUG_FUNCPTR (gst_rtp_sink_request_new_pad);
  gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_sink_release_pad);

  /**
   * GstRtpSink:uri:
   *
   * uri to stream RTP to. All GStreamer parameters can be
   * encoded in the URI, this URI format is RFC compliant.
   */
  g_object_class_install_property (gobject_class, PROP_URI,
      g_param_spec_string ("uri", "URI",
          "URI in the form of rtp://host:port?query", DEFAULT_PROP_URI,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
  /**
   * GstRtpSink:address:
   *
   * Address to receive packets from (can be IPv4 or IPv6).
   */
  g_object_class_install_property (gobject_class, PROP_ADDRESS,
      g_param_spec_string ("address", "Address",
          "Address to send packets to (can be IPv4 or IPv6).",
          DEFAULT_PROP_ADDRESS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

  /**
   * GstRtpSink:port:
   *
   * The port to listen to RTP packets, the RTCP port is this value
   * +1. This port must be an even number.
   */
  g_object_class_install_property (gobject_class, PROP_PORT,
      g_param_spec_uint ("port", "Port", "The port RTP packets will be sent, "
          "the RTCP port is this value + 1. This port must be an even number.",
          2, 65534, DEFAULT_PROP_PORT,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT));

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
  /**
   * GstRtpSink:ttl:
   *
   * Set the unicast TTL parameter.
   */
  g_object_class_install_property (gobject_class, PROP_TTL,
      g_param_spec_int ("ttl", "Unicast TTL",
          "Used for setting the unicast TTL parameter",
          0, 255, DEFAULT_PROP_TTL,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

  /**
   * GstRtpSink:ttl-mc:
   *
   * Set the multicast TTL parameter.
   */
  g_object_class_install_property (gobject_class, PROP_TTL_MC,
      g_param_spec_int ("ttl-mc", "Multicast TTL",
          "Used for setting the multicast TTL parameter", 0, 255,
          DEFAULT_PROP_TTL_MC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

355
356
357
358
359
360
361
362
363
364
365
  /* GstRtpSink:multicast-iface:
   *
   * The networkinterface on which to join the multicast group
   */
  g_object_class_install_property (gobject_class, PROP_MULTICAST_IFACE,
      g_param_spec_string ("multicast-iface", "Multicast Interface",
          "The network interface on which to join the multicast group."
          "This allows multiple interfaces separated by comma. (\"eth0,eth1\")",
          DEFAULT_PROP_MULTICAST_IFACE,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
  gst_element_class_add_pad_template (gstelement_class,
      gst_static_pad_template_get (&sink_template));

  gst_element_class_set_static_metadata (gstelement_class,
      "RTP Sink element",
      "Generic/Bin/Sink",
      "Simple RTP sink", "Marc Leeman <marc.leeman@gmail.com>");
}

static void
gst_rtp_sink_rtpbin_element_added_cb (GstBin * element,
    GstElement * new_element, gpointer data)
{
  GstRtpSink *self = GST_RTP_SINK (data);
  GST_INFO_OBJECT (self,
      "Element %" GST_PTR_FORMAT " added element %" GST_PTR_FORMAT ".", element,
      new_element);
}

static void
gst_rtp_sink_rtpbin_pad_added_cb (GstElement * element, GstPad * pad,
    gpointer data)
{
  GstRtpSink *self = GST_RTP_SINK (data);
  GstCaps *caps = gst_pad_query_caps (pad, NULL);
  GstPad *upad;

  /* Expose RTP data pad only */
  GST_INFO_OBJECT (self,
      "Element %" GST_PTR_FORMAT " added pad %" GST_PTR_FORMAT "with caps %"
      GST_PTR_FORMAT ".", element, pad, caps);

  /* Sanity checks */
  if (GST_PAD_DIRECTION (pad) == GST_PAD_SINK) {
    /* Src pad, do not expose */
    gst_caps_unref (caps);
    return;
  }

  if (G_LIKELY (caps)) {
    GstCaps *ref_caps = gst_caps_new_empty_simple ("application/x-rtcp");

    if (gst_caps_can_intersect (caps, ref_caps)) {
      /* SRC RTCP caps, do not expose */
      gst_caps_unref (ref_caps);
      gst_caps_unref (caps);

      return;
    }
    gst_caps_unref (ref_caps);
  } else {
    GST_ERROR_OBJECT (self, "Pad with no caps detected.");
    gst_caps_unref (caps);

    return;
  }
  gst_caps_unref (caps);

  upad = gst_element_get_compatible_pad (self->funnel_rtp, pad, NULL);
  if (upad == NULL) {
    GST_ERROR_OBJECT (self, "No compatible pad found to link pad.");
    gst_caps_unref (caps);

    return;
  }
  GST_INFO_OBJECT (self, "Linking with pad %" GST_PTR_FORMAT ".", upad);
  gst_pad_link (pad, upad);
  gst_object_unref (upad);
}

static void
gst_rtp_sink_rtpbin_pad_removed_cb (GstElement * element, GstPad * pad,
    gpointer data)
{
  GstRtpSink *self = GST_RTP_SINK (data);
  GST_INFO_OBJECT (self,
      "Element %" GST_PTR_FORMAT " removed pad %" GST_PTR_FORMAT ".", element,
      pad);
}

static gboolean
447
gst_rtp_sink_start (GstRtpSink * self)
448
{
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
  GSocket *socket = NULL;
  GInetAddress *iaddr = NULL;
  gchar *remote_addr = NULL;
  GError *error = NULL;

  /* Should not be NULL */
  g_return_val_if_fail (self->uri != NULL, FALSE);

  iaddr = g_inet_address_new_from_string (gst_uri_get_host (self->uri));
  if (!iaddr) {
    GList *results;
    GResolver *resolver = NULL;

    resolver = g_resolver_get_default ();
    results =
        g_resolver_lookup_by_name (resolver, gst_uri_get_host (self->uri), NULL,
        &error);

    if (!results) {
      g_object_unref (resolver);
      goto dns_resolve_failed;
    }

    iaddr = G_INET_ADDRESS (g_object_ref (results->data));

    g_resolver_free_addresses (results);
    g_object_unref (resolver);
476
  }
477
  remote_addr = g_inet_address_to_string (iaddr);
478

479
480
481
  if (g_inet_address_get_is_multicast (iaddr)) {
    g_object_set (self->rtcp_src, "address", remote_addr, "port",
        gst_uri_get_port (self->uri) + 1, NULL);
482
483
484
485
486

    /* set multicast-iface on the udpsrc and udpsink elements */
    g_object_set (self->rtcp_src, "multicast-iface", self->multi_iface, NULL);
    g_object_set (self->rtcp_sink, "multicast-iface", self->multi_iface, NULL);
    g_object_set (self->rtp_sink, "multicast-iface", self->multi_iface, NULL);
487
488
  } else {
    const gchar *any_addr;
489

490
491
492
493
494
495
496
    if (g_inet_address_get_family (iaddr) == G_SOCKET_FAMILY_IPV6)
      any_addr = "::";
    else
      any_addr = "0.0.0.0";

    g_object_set (self->rtcp_src, "address", any_addr, "port", 0, NULL);
  }
497
  g_free (remote_addr);
498
499
500
501
  g_object_unref (iaddr);

  gst_element_set_locked_state (self->rtcp_src, FALSE);
  gst_element_sync_state_with_parent (self->rtcp_src);
502

503
504
505
506
507
508
509
510
  /* share the socket created by the sink */
  g_object_get (self->rtcp_src, "used-socket", &socket, NULL);
  g_object_set (self->rtcp_sink, "socket", socket, "auto-multicast", FALSE,
      "close-socket", FALSE, NULL);
  g_object_unref (socket);

  gst_element_set_locked_state (self->rtcp_sink, FALSE);
  gst_element_sync_state_with_parent (self->rtcp_sink);
511
512

  return TRUE;
513
514
515

dns_resolve_failed:
  GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND,
516
      ("Could not resolve hostname '%s'", gst_uri_get_host (self->uri)),
517
518
519
      ("DNS resolver reported: %s", error->message));
  g_error_free (error);
  return FALSE;
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
}

static GstStateChangeReturn
gst_rtp_sink_change_state (GstElement * element, GstStateChange transition)
{
  GstRtpSink *self = GST_RTP_SINK (element);
  GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;

  GST_DEBUG_OBJECT (self, "changing state: %s => %s",
      gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
      gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));

  switch (transition) {
    case GST_STATE_CHANGE_NULL_TO_READY:
      break;
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      break;
    default:
      break;
  }

  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
  if (ret == GST_STATE_CHANGE_FAILURE)
    return ret;

  switch (transition) {
546
547
548
549
    case GST_STATE_CHANGE_NULL_TO_READY:
      if (gst_rtp_sink_start (self) == FALSE)
        return GST_STATE_CHANGE_FAILURE;
      break;
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
    case GST_STATE_CHANGE_READY_TO_PAUSED:
      break;
    case GST_STATE_CHANGE_PAUSED_TO_READY:
      break;
    default:
      break;
  }

  return ret;
}


static void
gst_rtp_sink_init (GstRtpSink * self)
{
565
566
567
  const gchar *missing_plugin = NULL;
  GstCaps *caps;

568
569
570
571
572
573
574
575
576
577
  self->rtpbin = NULL;
  self->funnel_rtp = NULL;
  self->funnel_rtcp = NULL;
  self->rtp_sink = NULL;
  self->rtcp_src = NULL;
  self->rtcp_sink = NULL;

  self->uri = gst_uri_from_string (DEFAULT_PROP_URI);
  self->ttl = DEFAULT_PROP_TTL;
  self->ttl_mc = DEFAULT_PROP_TTL_MC;
578
  self->multi_iface = g_strdup (DEFAULT_PROP_MULTICAST_IFACE);
579

580
581
582
583
584
585
586
587
  g_mutex_init (&self->lock);

  /* Construct the RTP sender pipeline.
   *
   *           *-> [send_rtp_sink_%u]   --------  [send_rtp_src_%u]  -> udpsink
   *                                   | rtpbin |
   * udpsrc     -> [recv_rtcp_sink_%u]  --------  [send_rtcp_src_%u] -> * udpsink
   */
588
  self->rtpbin = gst_element_factory_make ("rtpbin", "rtp_send_rtpbin0");
589
590
591
592
593
594
595
596
  if (self->rtpbin == NULL) {
    missing_plugin = "rtpmanager";
    goto missing_plugin;
  }

  gst_bin_add (GST_BIN (self), self->rtpbin);

  /* Add rtpbin callbacks to monitor the operation of rtpbin */
597
598
599
600
601
602
  g_signal_connect_object (self->rtpbin, "element-added",
      G_CALLBACK (gst_rtp_sink_rtpbin_element_added_cb), self, 0);
  g_signal_connect_object (self->rtpbin, "pad-added",
      G_CALLBACK (gst_rtp_sink_rtpbin_pad_added_cb), self, 0);
  g_signal_connect_object (self->rtpbin, "pad-removed",
      G_CALLBACK (gst_rtp_sink_rtpbin_pad_removed_cb), self, 0);
603
604
605
606
607

  GST_OBJECT_FLAG_SET (GST_OBJECT (self), GST_ELEMENT_FLAG_SINK);
  gst_bin_set_suppressed_flags (GST_BIN (self),
      GST_ELEMENT_FLAG_SOURCE | GST_ELEMENT_FLAG_SINK);

608
  self->funnel_rtp = gst_element_factory_make ("funnel", "rtp_rtp_funnel0");
609
610
611
612
613
  if (self->funnel_rtp == NULL) {
    missing_plugin = "funnel";
    goto missing_plugin;
  }

614
  self->funnel_rtcp = gst_element_factory_make ("funnel", "rtp_rtcp_funnel0");
615
616
617
618
619
  if (self->funnel_rtcp == NULL) {
    missing_plugin = "funnel";
    goto missing_plugin;
  }

620
  self->rtp_sink = gst_element_factory_make ("udpsink", "rtp_rtp_udpsink0");
621
622
623
624
625
  if (self->rtp_sink == NULL) {
    missing_plugin = "udp";
    goto missing_plugin;
  }

626
  self->rtcp_src = gst_element_factory_make ("udpsrc", "rtp_rtcp_udpsrc0");
627
628
629
630
631
  if (self->rtcp_src == NULL) {
    missing_plugin = "udp";
    goto missing_plugin;
  }

632
  self->rtcp_sink = gst_element_factory_make ("udpsink", "rtp_rtcp_udpsink0");
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
  if (self->rtcp_sink == NULL) {
    missing_plugin = "udp";
    goto missing_plugin;
  }

  gst_bin_add (GST_BIN (self), self->funnel_rtp);
  gst_bin_add (GST_BIN (self), self->funnel_rtcp);

  gst_bin_add (GST_BIN (self), self->rtp_sink);
  gst_bin_add (GST_BIN (self), self->rtcp_src);
  gst_bin_add (GST_BIN (self), self->rtcp_sink);

  gst_element_set_locked_state (self->rtcp_src, TRUE);
  gst_element_set_locked_state (self->rtcp_sink, TRUE);

  /* no need to set address if unicast */
  caps = gst_caps_new_empty_simple ("application/x-rtcp");
  g_object_set (self->rtcp_src, "caps", caps, NULL);
  gst_caps_unref (caps);

  gst_element_link (self->funnel_rtp, self->rtp_sink);
  gst_element_link (self->funnel_rtcp, self->rtcp_sink);

  if (missing_plugin == NULL)
    return;

missing_plugin:
  {
    GST_ERROR_OBJECT (self, "'%s' plugin is missing.", missing_plugin);
    /* Just make our element valid, so we fail cleanly */
    gst_element_add_pad (GST_ELEMENT (self),
        gst_pad_new_from_static_template (&sink_template, "sink_%u"));
  }
666
667
}

668
static GstURIType
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
gst_rtp_sink_uri_get_type (GType type)
{
  return GST_URI_SINK;
}

static const gchar *const *
gst_rtp_sink_uri_get_protocols (GType type)
{
  static const gchar *protocols[] = { (char *) "rtp", NULL };

  return protocols;
}

static gchar *
gst_rtp_sink_uri_get_uri (GstURIHandler * handler)
{
  GstRtpSink *self = (GstRtpSink *) handler;

  return gst_uri_to_string (self->uri);
}

static gboolean
gst_rtp_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri,
    GError ** error)
{
  GstRtpSink *self = (GstRtpSink *) handler;

  g_object_set (G_OBJECT (self), "uri", uri, NULL);

  return TRUE;
}

static void
gst_rtp_sink_uri_handler_init (gpointer g_iface, gpointer iface_data)
{
  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;

  iface->get_type = gst_rtp_sink_uri_get_type;
  iface->get_protocols = gst_rtp_sink_uri_get_protocols;
  iface->get_uri = gst_rtp_sink_uri_get_uri;
  iface->set_uri = gst_rtp_sink_uri_set_uri;
}

/* ex: set tabstop=2 shiftwidth=2 expandtab: */