Rename all GstRTPFoo structs to GstRtpFoo so that GST_BOILERPLATE registers a GType...
[platform/upstream/gstreamer.git] / gst / rtpmanager / gstrtpbin.c
1 /* GStreamer
2  * Copyright (C) <2007> Wim Taymans <wim@fluendo.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /**
21  * SECTION:element-gstrtpbin
22  * @short_description: handle media from one RTP bin
23  * @see_also: gstrtpjitterbuffer, gstrtpsession, gstrtpptdemux, gstrtpssrcdemux
24  *
25  * <refsect2>
26  * <para>
27  * RTP bin combines the functions of gstrtpsession, gstrtpssrcdemux, gstrtpjitterbuffer
28  * and gstrtpptdemux in one element. It allows for multiple RTP sessions that will
29  * be synchronized together using RTCP SR packets.
30  * </para>
31  * <para>
32  * gstrtpbin is configured with a number of request pads that define the
33  * functionality that is activated, similar to the gstrtpsession element.
34  * </para>
35  * <para>
36  * To use gstrtpbin as an RTP receiver, request a recv_rtp_sink_%%d pad. The session
37  * number must be specified in the pad name. 
38  * Data received on the recv_rtp_sink_%%d pad will be processed in the gstrtpsession
39  * manager and after being validated forwarded on gstrtpssrcdemuxer element. Each
40  * RTP stream is demuxed based on the SSRC and send to a gstrtpjitterbuffer. After
41  * the packets are released from the jitterbuffer, they will be forwarded to a
42  * gstrtpptdemuxer element. The gstrtpptdemuxer element will demux the packets based
43  * on the payload type and will create a unique pad recv_rtp_src_%%d_%%d_%%d on
44  * gstrtpbin with the session number, SSRC and payload type respectively as the pad
45  * name.
46  * </para>
47  * <para>
48  * To also use gstrtpbin as an RTCP receiver, request a recv_rtcp_sink_%%d pad. The
49  * session number must be specified in the pad name.
50  * </para>
51  * <para>
52  * If you want the session manager to generate and send RTCP packets, request
53  * the send_rtcp_src_%%d pad with the session number in the pad name. Packet pushed
54  * on this pad contain SR/RR RTCP reports that should be sent to all participants
55  * in the session.
56  * </para>
57  * <para>
58  * To use gstrtpbin as a sender, request a send_rtp_sink_%%d pad, which will
59  * automatically create a send_rtp_src_%%d pad. The session number must be specified when
60  * requesting the sink pad. The session manager will modify the
61  * SSRC in the RTP packets to its own SSRC and wil forward the packets on the
62  * send_rtp_src_%%d pad after updating its internal state.
63  * </para>
64  * <para>
65  * The session manager needs the clock-rate of the payload types it is handling
66  * and will signal the GstRtpSession::request-pt-map signal when it needs such a
67  * mapping. One can clear the cached values with the GstRtpSession::clear-pt-map
68  * signal.
69  * </para>
70  * <title>Example pipelines</title>
71  * <para>
72  * <programlisting>
73  * gst-launch udpsrc port=5000 caps="application/x-rtp, ..." ! .recv_rtp_sink_0 \
74  *     gstrtpbin ! rtptheoradepay ! theoradec ! xvimagesink
75  * </programlisting>
76  * Receive RTP data from port 5000 and send to the session 0 in gstrtpbin.
77  * </para>
78  * </refsect2>
79  *
80  * Last reviewed on 2007-05-28 (0.10.5)
81  */
82
83 #ifdef HAVE_CONFIG_H
84 #include "config.h"
85 #endif
86 #include <string.h>
87
88 #include "gstrtpbin-marshal.h"
89 #include "gstrtpbin.h"
90
91 GST_DEBUG_CATEGORY_STATIC (gst_rtp_bin_debug);
92 #define GST_CAT_DEFAULT gst_rtp_bin_debug
93
94
95 /* elementfactory information */
96 static const GstElementDetails rtpbin_details = GST_ELEMENT_DETAILS ("RTP Bin",
97     "Filter/Network/RTP",
98     "Implement an RTP bin",
99     "Wim Taymans <wim@fluendo.com>");
100
101 /* sink pads */
102 static GstStaticPadTemplate rtpbin_recv_rtp_sink_template =
103 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%d",
104     GST_PAD_SINK,
105     GST_PAD_REQUEST,
106     GST_STATIC_CAPS ("application/x-rtp")
107     );
108
109 static GstStaticPadTemplate rtpbin_recv_rtcp_sink_template =
110 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%d",
111     GST_PAD_SINK,
112     GST_PAD_REQUEST,
113     GST_STATIC_CAPS ("application/x-rtcp")
114     );
115
116 static GstStaticPadTemplate rtpbin_send_rtp_sink_template =
117 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink_%d",
118     GST_PAD_SINK,
119     GST_PAD_REQUEST,
120     GST_STATIC_CAPS ("application/x-rtp")
121     );
122
123 /* src pads */
124 static GstStaticPadTemplate rtpbin_recv_rtp_src_template =
125 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src_%d_%d_%d",
126     GST_PAD_SRC,
127     GST_PAD_SOMETIMES,
128     GST_STATIC_CAPS ("application/x-rtp")
129     );
130
131 static GstStaticPadTemplate rtpbin_send_rtcp_src_template =
132 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%d",
133     GST_PAD_SRC,
134     GST_PAD_REQUEST,
135     GST_STATIC_CAPS ("application/x-rtcp")
136     );
137
138 static GstStaticPadTemplate rtpbin_send_rtp_src_template =
139 GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%d",
140     GST_PAD_SRC,
141     GST_PAD_SOMETIMES,
142     GST_STATIC_CAPS ("application/x-rtp")
143     );
144
145 #define GST_RTP_BIN_GET_PRIVATE(obj)  \
146    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTP_BIN, GstRtpBinPrivate))
147
148 #define GST_RTP_BIN_LOCK(bin)   g_mutex_lock ((bin)->priv->bin_lock)
149 #define GST_RTP_BIN_UNLOCK(bin) g_mutex_unlock ((bin)->priv->bin_lock)
150
151 struct _GstRtpBinPrivate
152 {
153   GMutex *bin_lock;
154 };
155
156 /* signals and args */
157 enum
158 {
159   SIGNAL_REQUEST_PT_MAP,
160   SIGNAL_CLEAR_PT_MAP,
161
162   SIGNAL_ON_NEW_SSRC,
163   SIGNAL_ON_SSRC_COLLISION,
164   SIGNAL_ON_SSRC_VALIDATED,
165   SIGNAL_ON_BYE_SSRC,
166   SIGNAL_ON_BYE_TIMEOUT,
167   SIGNAL_ON_TIMEOUT,
168   LAST_SIGNAL
169 };
170
171 #define DEFAULT_LATENCY_MS      200
172
173 enum
174 {
175   PROP_0,
176   PROP_LATENCY
177 };
178
179 /* helper objects */
180 typedef struct _GstRtpBinSession GstRtpBinSession;
181 typedef struct _GstRtpBinStream GstRtpBinStream;
182 typedef struct _GstRtpBinClient GstRtpBinClient;
183
184 static guint gst_rtp_bin_signals[LAST_SIGNAL] = { 0 };
185
186 static GstCaps *pt_map_requested (GstElement * element, guint pt,
187     GstRtpBinSession * session);
188
189 /* Manages the RTP stream for one SSRC.
190  *
191  * We pipe the stream (comming from the SSRC demuxer) into a jitterbuffer.
192  * If we see an SDES RTCP packet that links multiple SSRCs together based on a
193  * common CNAME, we create a GstRtpBinClient structure to group the SSRCs
194  * together (see below).
195  */
196 struct _GstRtpBinStream
197 {
198   /* the SSRC of this stream */
199   guint32 ssrc;
200   /* parent bin */
201   GstRtpBin *bin;
202   /* the session this SSRC belongs to */
203   GstRtpBinSession *session;
204   /* the jitterbuffer of the SSRC */
205   GstElement *buffer;
206   /* the PT demuxer of the SSRC */
207   GstElement *demux;
208   gulong demux_newpad_sig;
209   gulong demux_ptreq_sig;
210 };
211
212 #define GST_RTP_SESSION_LOCK(sess)   g_mutex_lock ((sess)->lock)
213 #define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock ((sess)->lock)
214
215 /* Manages the receiving end of the packets.
216  *
217  * There is one such structure for each RTP session (audio/video/...).
218  * We get the RTP/RTCP packets and stuff them into the session manager. From
219  * there they are pushed into an SSRC demuxer that splits the stream based on
220  * SSRC. Each of the SSRC streams go into their own jitterbuffer (managed with
221  * the GstRtpBinStream above).
222  */
223 struct _GstRtpBinSession
224 {
225   /* session id */
226   gint id;
227   /* the parent bin */
228   GstRtpBin *bin;
229   /* the session element */
230   GstElement *session;
231   /* the SSRC demuxer */
232   GstElement *demux;
233   gulong demux_newpad_sig;
234
235   GMutex *lock;
236
237   /* list of GstRtpBinStream */
238   GSList *streams;
239
240   /* mapping of payload type to caps */
241   GHashTable *ptmap;
242
243   /* the pads of the session */
244   GstPad *recv_rtp_sink;
245   GstPad *recv_rtp_src;
246   GstPad *recv_rtcp_sink;
247   GstPad *recv_rtcp_src;
248   GstPad *send_rtp_sink;
249   GstPad *send_rtp_src;
250   GstPad *send_rtcp_src;
251 };
252
253 /* find a session with the given id. Must be called with RTP_BIN_LOCK */
254 static GstRtpBinSession *
255 find_session_by_id (GstRtpBin * rtpbin, gint id)
256 {
257   GSList *walk;
258
259   for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
260     GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
261
262     if (sess->id == id)
263       return sess;
264   }
265   return NULL;
266 }
267
268 static void
269 on_new_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
270 {
271   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC], 0,
272       sess->id, ssrc);
273 }
274
275 static void
276 on_ssrc_collision (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
277 {
278   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION], 0,
279       sess->id, ssrc);
280 }
281
282 static void
283 on_ssrc_validated (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
284 {
285   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
286       sess->id, ssrc);
287 }
288
289 static void
290 on_bye_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
291 {
292   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC], 0,
293       sess->id, ssrc);
294 }
295
296 static void
297 on_bye_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
298 {
299   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
300       sess->id, ssrc);
301 }
302
303 static void
304 on_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
305 {
306   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT], 0,
307       sess->id, ssrc);
308 }
309
310 /* create a session with the given id.  Must be called with RTP_BIN_LOCK */
311 static GstRtpBinSession *
312 create_session (GstRtpBin * rtpbin, gint id)
313 {
314   GstRtpBinSession *sess;
315   GstElement *session, *demux;
316
317   if (!(session = gst_element_factory_make ("gstrtpsession", NULL)))
318     goto no_session;
319
320   if (!(demux = gst_element_factory_make ("gstrtpssrcdemux", NULL)))
321     goto no_demux;
322
323   sess = g_new0 (GstRtpBinSession, 1);
324   sess->lock = g_mutex_new ();
325   sess->id = id;
326   sess->bin = rtpbin;
327   sess->session = session;
328   sess->demux = demux;
329   sess->ptmap = g_hash_table_new (NULL, NULL);
330   rtpbin->sessions = g_slist_prepend (rtpbin->sessions, sess);
331
332   /* provide clock_rate to the session manager when needed */
333   g_signal_connect (session, "request-pt-map",
334       (GCallback) pt_map_requested, sess);
335
336   g_signal_connect (sess->session, "on-new-ssrc",
337       (GCallback) on_new_ssrc, sess);
338   g_signal_connect (sess->session, "on-ssrc-collision",
339       (GCallback) on_ssrc_collision, sess);
340   g_signal_connect (sess->session, "on-ssrc-validated",
341       (GCallback) on_ssrc_validated, sess);
342   g_signal_connect (sess->session, "on-bye-ssrc",
343       (GCallback) on_bye_ssrc, sess);
344   g_signal_connect (sess->session, "on-bye-timeout",
345       (GCallback) on_bye_timeout, sess);
346   g_signal_connect (sess->session, "on-timeout", (GCallback) on_timeout, sess);
347
348   gst_bin_add (GST_BIN_CAST (rtpbin), session);
349   gst_element_set_state (session, GST_STATE_PLAYING);
350   gst_bin_add (GST_BIN_CAST (rtpbin), demux);
351   gst_element_set_state (demux, GST_STATE_PLAYING);
352
353   return sess;
354
355   /* ERRORS */
356 no_session:
357   {
358     g_warning ("gstrtpbin: could not create gstrtpsession element");
359     return NULL;
360   }
361 no_demux:
362   {
363     gst_object_unref (session);
364     g_warning ("gstrtpbin: could not create gstrtpssrcdemux element");
365     return NULL;
366   }
367 }
368
369 #if 0
370 static GstRtpBinStream *
371 find_stream_by_ssrc (GstRtpBinSession * session, guint32 ssrc)
372 {
373   GSList *walk;
374
375   for (walk = session->streams; walk; walk = g_slist_next (walk)) {
376     GstRtpBinStream *stream = (GstRtpBinStream *) walk->data;
377
378     if (stream->ssrc == ssrc)
379       return stream;
380   }
381   return NULL;
382 }
383 #endif
384
385 /* get the payload type caps for the specific payload @pt in @session */
386 static GstCaps *
387 get_pt_map (GstRtpBinSession * session, guint pt)
388 {
389   GstCaps *caps = NULL;
390   GstRtpBin *bin;
391   GValue ret = { 0 };
392   GValue args[3] = { {0}, {0}, {0} };
393
394   GST_DEBUG ("searching pt %d in cache", pt);
395
396   GST_RTP_SESSION_LOCK (session);
397
398   /* first look in the cache */
399   caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
400   if (caps)
401     goto done;
402
403   bin = session->bin;
404
405   GST_DEBUG ("emiting signal for pt %d in session %d", pt, session->id);
406
407   /* not in cache, send signal to request caps */
408   g_value_init (&args[0], GST_TYPE_ELEMENT);
409   g_value_set_object (&args[0], bin);
410   g_value_init (&args[1], G_TYPE_UINT);
411   g_value_set_uint (&args[1], session->id);
412   g_value_init (&args[2], G_TYPE_UINT);
413   g_value_set_uint (&args[2], pt);
414
415   g_value_init (&ret, GST_TYPE_CAPS);
416   g_value_set_boxed (&ret, NULL);
417
418   g_signal_emitv (args, gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP], 0, &ret);
419
420   caps = (GstCaps *) g_value_get_boxed (&ret);
421   if (!caps)
422     goto no_caps;
423
424   GST_DEBUG ("caching pt %d as %" GST_PTR_FORMAT, pt, caps);
425
426   /* store in cache */
427   g_hash_table_insert (session->ptmap, GINT_TO_POINTER (pt), caps);
428
429 done:
430   GST_RTP_SESSION_UNLOCK (session);
431
432   return caps;
433
434   /* ERRORS */
435 no_caps:
436   {
437     GST_RTP_SESSION_UNLOCK (session);
438     GST_DEBUG ("no pt map could be obtained");
439     return NULL;
440   }
441 }
442
443 static gboolean
444 return_true (gpointer key, gpointer value, gpointer user_data)
445 {
446   return TRUE;
447 }
448
449 static void
450 gst_rtp_bin_clear_pt_map (GstRtpBin * bin)
451 {
452   GSList *walk;
453
454   GST_RTP_BIN_LOCK (bin);
455   for (walk = bin->sessions; walk; walk = g_slist_next (walk)) {
456     GstRtpBinSession *session = (GstRtpBinSession *) walk->data;
457
458     GST_RTP_SESSION_LOCK (session);
459 #if 0
460     /* This requires GLib 2.12 */
461     g_hash_table_remove_all (session->ptmap);
462 #else
463     g_hash_table_foreach_remove (session->ptmap, return_true, NULL);
464 #endif
465     GST_RTP_SESSION_UNLOCK (session);
466   }
467   GST_RTP_BIN_UNLOCK (bin);
468 }
469
470 /* create a new stream with @ssrc in @session. Must be called with
471  * RTP_SESSION_LOCK. */
472 static GstRtpBinStream *
473 create_stream (GstRtpBinSession * session, guint32 ssrc)
474 {
475   GstElement *buffer, *demux;
476   GstRtpBinStream *stream;
477
478   if (!(buffer = gst_element_factory_make ("gstrtpjitterbuffer", NULL)))
479     goto no_jitterbuffer;
480
481   if (!(demux = gst_element_factory_make ("gstrtpptdemux", NULL)))
482     goto no_demux;
483
484   stream = g_new0 (GstRtpBinStream, 1);
485   stream->ssrc = ssrc;
486   stream->bin = session->bin;
487   stream->session = session;
488   stream->buffer = buffer;
489   stream->demux = demux;
490   session->streams = g_slist_prepend (session->streams, stream);
491
492   /* provide clock_rate to the jitterbuffer when needed */
493   g_signal_connect (buffer, "request-pt-map",
494       (GCallback) pt_map_requested, session);
495
496   /* configure latency */
497   g_object_set (buffer, "latency", session->bin->latency, NULL);
498
499   gst_bin_add (GST_BIN_CAST (session->bin), buffer);
500   gst_element_set_state (buffer, GST_STATE_PLAYING);
501   gst_bin_add (GST_BIN_CAST (session->bin), demux);
502   gst_element_set_state (demux, GST_STATE_PLAYING);
503
504   /* link stuff */
505   gst_element_link (buffer, demux);
506
507   return stream;
508
509   /* ERRORS */
510 no_jitterbuffer:
511   {
512     g_warning ("gstrtpbin: could not create gstrtpjitterbuffer element");
513     return NULL;
514   }
515 no_demux:
516   {
517     gst_object_unref (buffer);
518     g_warning ("gstrtpbin: could not create gstrtpptdemux element");
519     return NULL;
520   }
521 }
522
523 /* Manages the RTP streams that come from one client and should therefore be
524  * synchronized.
525  */
526 struct _GstRtpBinClient
527 {
528   /* the common CNAME for the streams */
529   gchar *cname;
530   /* the streams */
531   GSList *streams;
532 };
533
534 /* GObject vmethods */
535 static void gst_rtp_bin_finalize (GObject * object);
536 static void gst_rtp_bin_set_property (GObject * object, guint prop_id,
537     const GValue * value, GParamSpec * pspec);
538 static void gst_rtp_bin_get_property (GObject * object, guint prop_id,
539     GValue * value, GParamSpec * pspec);
540
541 /* GstElement vmethods */
542 static GstClock *gst_rtp_bin_provide_clock (GstElement * element);
543 static GstStateChangeReturn gst_rtp_bin_change_state (GstElement * element,
544     GstStateChange transition);
545 static GstPad *gst_rtp_bin_request_new_pad (GstElement * element,
546     GstPadTemplate * templ, const gchar * name);
547 static void gst_rtp_bin_release_pad (GstElement * element, GstPad * pad);
548 static void gst_rtp_bin_clear_pt_map (GstRtpBin * bin);
549
550 GST_BOILERPLATE (GstRtpBin, gst_rtp_bin, GstBin, GST_TYPE_BIN);
551
552 static void
553 gst_rtp_bin_base_init (gpointer klass)
554 {
555   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
556
557   /* sink pads */
558   gst_element_class_add_pad_template (element_class,
559       gst_static_pad_template_get (&rtpbin_recv_rtp_sink_template));
560   gst_element_class_add_pad_template (element_class,
561       gst_static_pad_template_get (&rtpbin_recv_rtcp_sink_template));
562   gst_element_class_add_pad_template (element_class,
563       gst_static_pad_template_get (&rtpbin_send_rtp_sink_template));
564
565   /* src pads */
566   gst_element_class_add_pad_template (element_class,
567       gst_static_pad_template_get (&rtpbin_recv_rtp_src_template));
568   gst_element_class_add_pad_template (element_class,
569       gst_static_pad_template_get (&rtpbin_send_rtcp_src_template));
570   gst_element_class_add_pad_template (element_class,
571       gst_static_pad_template_get (&rtpbin_send_rtp_src_template));
572
573   gst_element_class_set_details (element_class, &rtpbin_details);
574 }
575
576 static void
577 gst_rtp_bin_class_init (GstRtpBinClass * klass)
578 {
579   GObjectClass *gobject_class;
580   GstElementClass *gstelement_class;
581
582   gobject_class = (GObjectClass *) klass;
583   gstelement_class = (GstElementClass *) klass;
584
585   g_type_class_add_private (klass, sizeof (GstRtpBinPrivate));
586
587   gobject_class->finalize = gst_rtp_bin_finalize;
588   gobject_class->set_property = gst_rtp_bin_set_property;
589   gobject_class->get_property = gst_rtp_bin_get_property;
590
591   g_object_class_install_property (gobject_class, PROP_LATENCY,
592       g_param_spec_uint ("latency", "Buffer latency in ms",
593           "Default amount of ms to buffer in the jitterbuffers", 0,
594           G_MAXUINT, DEFAULT_LATENCY_MS, G_PARAM_READWRITE));
595
596   /**
597    * GstRtpBin::request-pt-map:
598    * @rtpbin: the object which received the signal
599    * @session: the session
600    * @pt: the pt
601    *
602    * Request the payload type as #GstCaps for @pt in @session.
603    */
604   gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP] =
605       g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
606       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, request_pt_map),
607       NULL, NULL, gst_rtp_bin_marshal_BOXED__UINT_UINT, GST_TYPE_CAPS, 2,
608       G_TYPE_UINT, G_TYPE_UINT);
609   /**
610    * GstRtpBin::clear-pt-map:
611    * @rtpbin: the object which received the signal
612    *
613    * Clear all previously cached pt-mapping obtained with
614    * GstRtpBin::request-pt-map.
615    */
616   gst_rtp_bin_signals[SIGNAL_CLEAR_PT_MAP] =
617       g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
618       G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass, clear_pt_map),
619       NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
620
621   /**
622    * GstRtpBin::on-new-ssrc:
623    * @rtpbin: the object which received the signal
624    * @session: the session
625    * @ssrc: the SSRC 
626    *
627    * Notify of a new SSRC that entered @session.
628    */
629   gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC] =
630       g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
631       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_ssrc),
632       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
633       G_TYPE_UINT, G_TYPE_UINT);
634   /**
635    * GstRtpBin::on-ssrc_collision:
636    * @rtpbin: the object which received the signal
637    * @session: the session
638    * @ssrc: the SSRC 
639    *
640    * Notify when we have an SSRC collision
641    */
642   gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION] =
643       g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
644       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_collision),
645       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
646       G_TYPE_UINT, G_TYPE_UINT);
647   /**
648    * GstRtpBin::on-ssrc_validated:
649    * @rtpbin: the object which received the signal
650    * @session: the session
651    * @ssrc: the SSRC 
652    *
653    * Notify of a new SSRC that became validated.
654    */
655   gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED] =
656       g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
657       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_validated),
658       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
659       G_TYPE_UINT, G_TYPE_UINT);
660
661   /**
662    * GstRtpBin::on-bye-ssrc:
663    * @rtpbin: the object which received the signal
664    * @session: the session
665    * @ssrc: the SSRC 
666    *
667    * Notify of an SSRC that became inactive because of a BYE packet.
668    */
669   gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC] =
670       g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
671       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_ssrc),
672       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
673       G_TYPE_UINT, G_TYPE_UINT);
674   /**
675    * GstRtpBin::on-bye-timeout:
676    * @rtpbin: the object which received the signal
677    * @session: the session
678    * @ssrc: the SSRC 
679    *
680    * Notify of an SSRC that has timed out because of BYE
681    */
682   gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT] =
683       g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
684       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_timeout),
685       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
686       G_TYPE_UINT, G_TYPE_UINT);
687   /**
688    * GstRtpBin::on-timeout:
689    * @rtpbin: the object which received the signal
690    * @session: the session
691    * @ssrc: the SSRC 
692    *
693    * Notify of an SSRC that has timed out
694    */
695   gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT] =
696       g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
697       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_timeout),
698       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
699       G_TYPE_UINT, G_TYPE_UINT);
700
701   gstelement_class->provide_clock =
702       GST_DEBUG_FUNCPTR (gst_rtp_bin_provide_clock);
703   gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_bin_change_state);
704   gstelement_class->request_new_pad =
705       GST_DEBUG_FUNCPTR (gst_rtp_bin_request_new_pad);
706   gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_bin_release_pad);
707
708   klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_bin_clear_pt_map);
709
710   GST_DEBUG_CATEGORY_INIT (gst_rtp_bin_debug, "rtpbin", 0, "RTP bin");
711 }
712
713 static void
714 gst_rtp_bin_init (GstRtpBin * rtpbin, GstRtpBinClass * klass)
715 {
716   rtpbin->priv = GST_RTP_BIN_GET_PRIVATE (rtpbin);
717   rtpbin->priv->bin_lock = g_mutex_new ();
718   rtpbin->provided_clock = gst_system_clock_obtain ();
719 }
720
721 static void
722 gst_rtp_bin_finalize (GObject * object)
723 {
724   GstRtpBin *rtpbin;
725
726   rtpbin = GST_RTP_BIN (object);
727
728   g_mutex_free (rtpbin->priv->bin_lock);
729
730   G_OBJECT_CLASS (parent_class)->finalize (object);
731 }
732
733 static void
734 gst_rtp_bin_set_property (GObject * object, guint prop_id,
735     const GValue * value, GParamSpec * pspec)
736 {
737   GstRtpBin *rtpbin;
738
739   rtpbin = GST_RTP_BIN (object);
740
741   switch (prop_id) {
742     case PROP_LATENCY:
743       rtpbin->latency = g_value_get_uint (value);
744       break;
745     default:
746       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
747       break;
748   }
749 }
750
751 static void
752 gst_rtp_bin_get_property (GObject * object, guint prop_id,
753     GValue * value, GParamSpec * pspec)
754 {
755   GstRtpBin *rtpbin;
756
757   rtpbin = GST_RTP_BIN (object);
758
759   switch (prop_id) {
760     case PROP_LATENCY:
761       g_value_set_uint (value, rtpbin->latency);
762       break;
763     default:
764       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
765       break;
766   }
767 }
768
769 static GstClock *
770 gst_rtp_bin_provide_clock (GstElement * element)
771 {
772   GstRtpBin *rtpbin;
773
774   rtpbin = GST_RTP_BIN (element);
775
776   return GST_CLOCK_CAST (gst_object_ref (rtpbin->provided_clock));
777 }
778
779 static GstStateChangeReturn
780 gst_rtp_bin_change_state (GstElement * element, GstStateChange transition)
781 {
782   GstStateChangeReturn res;
783   GstRtpBin *rtpbin;
784
785   rtpbin = GST_RTP_BIN (element);
786
787   switch (transition) {
788     case GST_STATE_CHANGE_NULL_TO_READY:
789       break;
790     case GST_STATE_CHANGE_READY_TO_PAUSED:
791       break;
792     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
793       break;
794     default:
795       break;
796   }
797
798   res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
799
800   switch (transition) {
801     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
802       break;
803     case GST_STATE_CHANGE_PAUSED_TO_READY:
804       break;
805     case GST_STATE_CHANGE_READY_TO_NULL:
806       break;
807     default:
808       break;
809   }
810   return res;
811 }
812
813 /* a new pad (SSRC) was created in @session */
814 static void
815 new_payload_found (GstElement * element, guint pt, GstPad * pad,
816     GstRtpBinStream * stream)
817 {
818   GstRtpBin *rtpbin;
819   GstElementClass *klass;
820   GstPadTemplate *templ;
821   gchar *padname;
822   GstPad *gpad;
823
824   rtpbin = stream->bin;
825
826   GST_DEBUG ("new payload pad %d", pt);
827
828   /* ghost the pad to the parent */
829   klass = GST_ELEMENT_GET_CLASS (rtpbin);
830   templ = gst_element_class_get_pad_template (klass, "recv_rtp_src_%d_%d_%d");
831   padname = g_strdup_printf ("recv_rtp_src_%d_%u_%d",
832       stream->session->id, stream->ssrc, pt);
833   gpad = gst_ghost_pad_new_from_template (padname, pad, templ);
834   g_free (padname);
835
836   gst_pad_set_active (gpad, TRUE);
837   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), gpad);
838 }
839
840 static GstCaps *
841 pt_map_requested (GstElement * element, guint pt, GstRtpBinSession * session)
842 {
843   GstRtpBin *rtpbin;
844   GstCaps *caps;
845
846   rtpbin = session->bin;
847
848   GST_DEBUG_OBJECT (rtpbin, "payload map requested for pt %d in session %d", pt,
849       session->id);
850
851   caps = get_pt_map (session, pt);
852   if (!caps)
853     goto no_caps;
854
855   return caps;
856
857   /* ERRORS */
858 no_caps:
859   {
860     GST_DEBUG_OBJECT (rtpbin, "could not get caps");
861     return NULL;
862   }
863 }
864
865 /* a new pad (SSRC) was created in @session */
866 static void
867 new_ssrc_pad_found (GstElement * element, guint ssrc, GstPad * pad,
868     GstRtpBinSession * session)
869 {
870   GstRtpBinStream *stream;
871   GstPad *sinkpad;
872
873   GST_DEBUG_OBJECT (session->bin, "new SSRC pad %08x", ssrc);
874
875   GST_RTP_SESSION_LOCK (session);
876
877   /* create new stream */
878   stream = create_stream (session, ssrc);
879   if (!stream)
880     goto no_stream;
881
882   /* get pad and link */
883   GST_DEBUG_OBJECT (session->bin, "linking jitterbuffer");
884   sinkpad = gst_element_get_static_pad (stream->buffer, "sink");
885   gst_pad_link (pad, sinkpad);
886   gst_object_unref (sinkpad);
887
888   /* connect to the new-pad signal of the payload demuxer, this will expose the
889    * new pad by ghosting it. */
890   stream->demux_newpad_sig = g_signal_connect (stream->demux,
891       "new-payload-type", (GCallback) new_payload_found, stream);
892   /* connect to the request-pt-map signal. This signal will be emited by the
893    * demuxer so that it can apply a proper caps on the buffers for the
894    * depayloaders. */
895   stream->demux_ptreq_sig = g_signal_connect (stream->demux,
896       "request-pt-map", (GCallback) pt_map_requested, session);
897
898   GST_RTP_SESSION_UNLOCK (session);
899
900   return;
901
902   /* ERRORS */
903 no_stream:
904   {
905     GST_RTP_SESSION_UNLOCK (session);
906     GST_DEBUG ("could not create stream");
907     return;
908   }
909 }
910
911 /* Create a pad for receiving RTP for the session in @name. Must be called with
912  * RTP_BIN_LOCK.
913  */
914 static GstPad *
915 create_recv_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
916 {
917   GstPad *result, *sinkdpad;
918   guint sessid;
919   GstRtpBinSession *session;
920   GstPadLinkReturn lres;
921
922   /* first get the session number */
923   if (name == NULL || sscanf (name, "recv_rtp_sink_%d", &sessid) != 1)
924     goto no_name;
925
926   GST_DEBUG_OBJECT (rtpbin, "finding session %d", sessid);
927
928   /* get or create session */
929   session = find_session_by_id (rtpbin, sessid);
930   if (!session) {
931     GST_DEBUG_OBJECT (rtpbin, "creating session %d", sessid);
932     /* create session now */
933     session = create_session (rtpbin, sessid);
934     if (session == NULL)
935       goto create_error;
936   }
937
938   /* check if pad was requested */
939   if (session->recv_rtp_sink != NULL)
940     goto existed;
941
942   GST_DEBUG_OBJECT (rtpbin, "getting RTP sink pad");
943   /* get recv_rtp pad and store */
944   session->recv_rtp_sink =
945       gst_element_get_request_pad (session->session, "recv_rtp_sink");
946   if (session->recv_rtp_sink == NULL)
947     goto pad_failed;
948
949   GST_DEBUG_OBJECT (rtpbin, "getting RTP src pad");
950   /* get srcpad, link to SSRCDemux */
951   session->recv_rtp_src =
952       gst_element_get_static_pad (session->session, "recv_rtp_src");
953   if (session->recv_rtp_src == NULL)
954     goto pad_failed;
955
956   GST_DEBUG_OBJECT (rtpbin, "getting demuxer sink pad");
957   sinkdpad = gst_element_get_static_pad (session->demux, "sink");
958   lres = gst_pad_link (session->recv_rtp_src, sinkdpad);
959   gst_object_unref (sinkdpad);
960   if (lres != GST_PAD_LINK_OK)
961     goto link_failed;
962
963   /* connect to the new-ssrc-pad signal of the SSRC demuxer */
964   session->demux_newpad_sig = g_signal_connect (session->demux,
965       "new-ssrc-pad", (GCallback) new_ssrc_pad_found, session);
966
967   GST_DEBUG_OBJECT (rtpbin, "ghosting session sink pad");
968   result =
969       gst_ghost_pad_new_from_template (name, session->recv_rtp_sink, templ);
970   gst_pad_set_active (result, TRUE);
971   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
972
973   return result;
974
975   /* ERRORS */
976 no_name:
977   {
978     g_warning ("gstrtpbin: invalid name given");
979     return NULL;
980   }
981 create_error:
982   {
983     /* create_session already warned */
984     return NULL;
985   }
986 existed:
987   {
988     g_warning ("gstrtpbin: recv_rtp pad already requested for session %d",
989         sessid);
990     return NULL;
991   }
992 pad_failed:
993   {
994     g_warning ("gstrtpbin: failed to get session pad");
995     return NULL;
996   }
997 link_failed:
998   {
999     g_warning ("gstrtpbin: failed to link pads");
1000     return NULL;
1001   }
1002 }
1003
1004 /* Create a pad for receiving RTCP for the session in @name. Must be called with
1005  * RTP_BIN_LOCK.
1006  */
1007 static GstPad *
1008 create_recv_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
1009     const gchar * name)
1010 {
1011   GstPad *result;
1012   guint sessid;
1013   GstRtpBinSession *session;
1014
1015 #if 0
1016   GstPad *sinkdpad;
1017   GstPadLinkReturn lres;
1018 #endif
1019
1020   /* first get the session number */
1021   if (name == NULL || sscanf (name, "recv_rtcp_sink_%d", &sessid) != 1)
1022     goto no_name;
1023
1024   GST_DEBUG_OBJECT (rtpbin, "finding session %d", sessid);
1025
1026   /* get or create the session */
1027   session = find_session_by_id (rtpbin, sessid);
1028   if (!session) {
1029     GST_DEBUG_OBJECT (rtpbin, "creating session %d", sessid);
1030     /* create session now */
1031     session = create_session (rtpbin, sessid);
1032     if (session == NULL)
1033       goto create_error;
1034   }
1035
1036   /* check if pad was requested */
1037   if (session->recv_rtcp_sink != NULL)
1038     goto existed;
1039
1040   GST_DEBUG_OBJECT (rtpbin, "getting RTCP sink pad");
1041
1042   /* get recv_rtp pad and store */
1043   session->recv_rtcp_sink =
1044       gst_element_get_request_pad (session->session, "recv_rtcp_sink");
1045   if (session->recv_rtcp_sink == NULL)
1046     goto pad_failed;
1047
1048 #if 0
1049   /* get srcpad, link to SSRCDemux */
1050   GST_DEBUG_OBJECT (rtpbin, "getting sync src pad");
1051   session->recv_rtcp_src =
1052       gst_element_get_static_pad (session->session, "sync_src");
1053   if (session->recv_rtcp_src == NULL)
1054     goto pad_failed;
1055
1056   GST_DEBUG_OBJECT (rtpbin, "linking sync to demux");
1057   sinkdpad = gst_element_get_static_pad (session->demux, "sink");
1058   lres = gst_pad_link (session->recv_rtcp_src, sinkdpad);
1059   gst_object_unref (sinkdpad);
1060   if (lres != GST_PAD_LINK_OK)
1061     goto link_failed;
1062 #endif
1063
1064   result =
1065       gst_ghost_pad_new_from_template (name, session->recv_rtcp_sink, templ);
1066   gst_pad_set_active (result, TRUE);
1067   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
1068
1069   return result;
1070
1071   /* ERRORS */
1072 no_name:
1073   {
1074     g_warning ("gstrtpbin: invalid name given");
1075     return NULL;
1076   }
1077 create_error:
1078   {
1079     /* create_session already warned */
1080     return NULL;
1081   }
1082 existed:
1083   {
1084     g_warning ("gstrtpbin: recv_rtcp pad already requested for session %d",
1085         sessid);
1086     return NULL;
1087   }
1088 pad_failed:
1089   {
1090     g_warning ("gstrtpbin: failed to get session pad");
1091     return NULL;
1092   }
1093 #if 0
1094 link_failed:
1095   {
1096     g_warning ("gstrtpbin: failed to link pads");
1097     return NULL;
1098   }
1099 #endif
1100 }
1101
1102 /* Create a pad for sending RTP for the session in @name. Must be called with
1103  * RTP_BIN_LOCK.
1104  */
1105 static GstPad *
1106 create_send_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
1107 {
1108   GstPad *result, *srcghost;
1109   gchar *gname;
1110   guint sessid;
1111   GstRtpBinSession *session;
1112   GstElementClass *klass;
1113
1114   /* first get the session number */
1115   if (name == NULL || sscanf (name, "send_rtp_sink_%d", &sessid) != 1)
1116     goto no_name;
1117
1118   /* get or create session */
1119   session = find_session_by_id (rtpbin, sessid);
1120   if (!session) {
1121     /* create session now */
1122     session = create_session (rtpbin, sessid);
1123     if (session == NULL)
1124       goto create_error;
1125   }
1126
1127   /* check if pad was requested */
1128   if (session->send_rtp_sink != NULL)
1129     goto existed;
1130
1131   /* get send_rtp pad and store */
1132   session->send_rtp_sink =
1133       gst_element_get_request_pad (session->session, "send_rtp_sink");
1134   if (session->send_rtp_sink == NULL)
1135     goto pad_failed;
1136
1137   result =
1138       gst_ghost_pad_new_from_template (name, session->send_rtp_sink, templ);
1139   gst_pad_set_active (result, TRUE);
1140   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
1141
1142   /* get srcpad */
1143   session->send_rtp_src =
1144       gst_element_get_static_pad (session->session, "send_rtp_src");
1145   if (session->send_rtp_src == NULL)
1146     goto no_srcpad;
1147
1148   /* ghost the new source pad */
1149   klass = GST_ELEMENT_GET_CLASS (rtpbin);
1150   gname = g_strdup_printf ("send_rtp_src_%d", sessid);
1151   templ = gst_element_class_get_pad_template (klass, "send_rtp_src_%d");
1152   srcghost =
1153       gst_ghost_pad_new_from_template (gname, session->send_rtp_src, templ);
1154   gst_pad_set_active (srcghost, TRUE);
1155   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), srcghost);
1156   g_free (gname);
1157
1158   return result;
1159
1160   /* ERRORS */
1161 no_name:
1162   {
1163     g_warning ("gstrtpbin: invalid name given");
1164     return NULL;
1165   }
1166 create_error:
1167   {
1168     /* create_session already warned */
1169     return NULL;
1170   }
1171 existed:
1172   {
1173     g_warning ("gstrtpbin: send_rtp pad already requested for session %d",
1174         sessid);
1175     return NULL;
1176   }
1177 pad_failed:
1178   {
1179     g_warning ("gstrtpbin: failed to get session pad for session %d", sessid);
1180     return NULL;
1181   }
1182 no_srcpad:
1183   {
1184     g_warning ("gstrtpbin: failed to get rtp source pad for session %d",
1185         sessid);
1186     return NULL;
1187   }
1188 }
1189
1190 /* Create a pad for sending RTCP for the session in @name. Must be called with
1191  * RTP_BIN_LOCK.
1192  */
1193 static GstPad *
1194 create_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
1195 {
1196   GstPad *result;
1197   guint sessid;
1198   GstRtpBinSession *session;
1199
1200   /* first get the session number */
1201   if (name == NULL || sscanf (name, "send_rtcp_src_%d", &sessid) != 1)
1202     goto no_name;
1203
1204   /* get or create session */
1205   session = find_session_by_id (rtpbin, sessid);
1206   if (!session)
1207     goto no_session;
1208
1209   /* check if pad was requested */
1210   if (session->send_rtcp_src != NULL)
1211     goto existed;
1212
1213   /* get rtcp_src pad and store */
1214   session->send_rtcp_src =
1215       gst_element_get_request_pad (session->session, "send_rtcp_src");
1216   if (session->send_rtcp_src == NULL)
1217     goto pad_failed;
1218
1219   result =
1220       gst_ghost_pad_new_from_template (name, session->send_rtcp_src, templ);
1221   gst_pad_set_active (result, TRUE);
1222   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
1223
1224   return result;
1225
1226   /* ERRORS */
1227 no_name:
1228   {
1229     g_warning ("gstrtpbin: invalid name given");
1230     return NULL;
1231   }
1232 no_session:
1233   {
1234     g_warning ("gstrtpbin: session with id %d does not exist", sessid);
1235     return NULL;
1236   }
1237 existed:
1238   {
1239     g_warning ("gstrtpbin: send_rtcp_src pad already requested for session %d",
1240         sessid);
1241     return NULL;
1242   }
1243 pad_failed:
1244   {
1245     g_warning ("gstrtpbin: failed to get rtcp pad for session %d", sessid);
1246     return NULL;
1247   }
1248 }
1249
1250 /* 
1251  */
1252 static GstPad *
1253 gst_rtp_bin_request_new_pad (GstElement * element,
1254     GstPadTemplate * templ, const gchar * name)
1255 {
1256   GstRtpBin *rtpbin;
1257   GstElementClass *klass;
1258   GstPad *result;
1259
1260   g_return_val_if_fail (templ != NULL, NULL);
1261   g_return_val_if_fail (GST_IS_RTP_BIN (element), NULL);
1262
1263   rtpbin = GST_RTP_BIN (element);
1264   klass = GST_ELEMENT_GET_CLASS (element);
1265
1266   GST_RTP_BIN_LOCK (rtpbin);
1267
1268   /* figure out the template */
1269   if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink_%d")) {
1270     result = create_recv_rtp (rtpbin, templ, name);
1271   } else if (templ == gst_element_class_get_pad_template (klass,
1272           "recv_rtcp_sink_%d")) {
1273     result = create_recv_rtcp (rtpbin, templ, name);
1274   } else if (templ == gst_element_class_get_pad_template (klass,
1275           "send_rtp_sink_%d")) {
1276     result = create_send_rtp (rtpbin, templ, name);
1277   } else if (templ == gst_element_class_get_pad_template (klass,
1278           "send_rtcp_src_%d")) {
1279     result = create_rtcp (rtpbin, templ, name);
1280   } else
1281     goto wrong_template;
1282
1283   GST_RTP_BIN_UNLOCK (rtpbin);
1284
1285   return result;
1286
1287   /* ERRORS */
1288 wrong_template:
1289   {
1290     GST_RTP_BIN_UNLOCK (rtpbin);
1291     g_warning ("gstrtpbin: this is not our template");
1292     return NULL;
1293   }
1294 }
1295
1296 static void
1297 gst_rtp_bin_release_pad (GstElement * element, GstPad * pad)
1298 {
1299 }