gst/rtpmanager/gstrtpbin.c: Fix memleak. Fixes #484990.
[platform/upstream/gst-plugins-good.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  * <para>
79  * <programlisting>
80  * gst-launch gstrtpbin name=rtpbin \
81  *         v4l2src ! ffmpegcolorspace ! ffenc_h263 ! rtph263ppay ! rtpbin.send_rtp_sink_0 \
82  *                   rtpbin.send_rtp_src_0 ! udpsink port=5000                            \
83  *                   rtpbin.send_rtcp_src_0 ! udpsink port=5001 sync=false async=false    \
84  *                   udpsrc port=5005 ! rtpbin.recv_rtcp_sink_0                           \
85  *         audiotestsrc ! amrnbenc ! rtpamrpay ! rtpbin.send_rtp_sink_1                   \
86  *                   rtpbin.send_rtp_src_1 ! udpsink port=5002                            \
87  *                   rtpbin.send_rtcp_src_1 ! udpsink port=5003 sync=false async=false    \
88  *                   udpsrc port=5007 ! rtpbin.recv_rtcp_sink_1
89  * </programlisting>
90  * Encode and payload H263 video captured from a v4l2src. Encode and payload AMR
91  * audio generated from audiotestsrc. The video is sent to session 0 in rtpbin
92  * and the audio is sent to session 1. Video packets are sent on UDP port 5000
93  * and audio packets on port 5002. The video RTCP packets for session 0 are sent
94  * on port 5001 and the audio RTCP packets for session 0 are sent on port 5003.
95  * RTCP packets for session 0 are received on port 5005 and RTCP for session 1
96  * is received on port 5007. Since RTCP packets from the sender should be sent
97  * as soon as possible and do not participate in preroll, sync=false and 
98  * async=false is configured on udpsink
99  * </para>
100  * <para>
101  * <programlisting>
102  *  gst-launch -v gstrtpbin name=rtpbin                                          \
103  *     udpsrc caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H263-1998" \
104  *             port=5000 ! rtpbin.recv_rtp_sink_0                                \
105  *         rtpbin. ! rtph263pdepay ! ffdec_h263 ! xvimagesink                    \
106  *      udpsrc port=5001 ! rtpbin.recv_rtcp_sink_0                               \
107  *      rtpbin.send_rtcp_src_0 ! udpsink port=5005 sync=false async=false        \
108  *     udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1" \
109  *             port=5002 ! rtpbin.recv_rtp_sink_1                                \
110  *         rtpbin. ! rtpamrdepay ! amrnbdec ! alsasink                           \
111  *      udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1                               \
112  *      rtpbin.send_rtcp_src_1 ! udpsink port=5007 sync=false async=false
113  * </programlisting>
114  * Receive H263 on port 5000, send it through rtpbin in session 0, depayload,
115  * decode and display the video.
116  * Receive AMR on port 5002, send it through rtpbin in session 1, depayload,
117  * decode and play the audio.
118  * Receive server RTCP packets for session 0 on port 5001 and RTCP packets for
119  * session 1 on port 5003. These packets will be used for session management and
120  * synchronisation.
121  * Send RTCP reports for session 0 on port 5005 and RTCP reports for session 1
122  * on port 5007.
123  * </para>
124  * </refsect2>
125  *
126  * Last reviewed on 2007-08-30 (0.10.6)
127  */
128
129 #ifdef HAVE_CONFIG_H
130 #include "config.h"
131 #endif
132 #include <string.h>
133
134 #include <gst/rtp/gstrtpbuffer.h>
135 #include <gst/rtp/gstrtcpbuffer.h>
136
137 #include "gstrtpbin-marshal.h"
138 #include "gstrtpbin.h"
139
140 GST_DEBUG_CATEGORY_STATIC (gst_rtp_bin_debug);
141 #define GST_CAT_DEFAULT gst_rtp_bin_debug
142
143 /* elementfactory information */
144 static const GstElementDetails rtpbin_details = GST_ELEMENT_DETAILS ("RTP Bin",
145     "Filter/Network/RTP",
146     "Implement an RTP bin",
147     "Wim Taymans <wim@fluendo.com>");
148
149 /* sink pads */
150 static GstStaticPadTemplate rtpbin_recv_rtp_sink_template =
151 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%d",
152     GST_PAD_SINK,
153     GST_PAD_REQUEST,
154     GST_STATIC_CAPS ("application/x-rtp")
155     );
156
157 static GstStaticPadTemplate rtpbin_recv_rtcp_sink_template =
158 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%d",
159     GST_PAD_SINK,
160     GST_PAD_REQUEST,
161     GST_STATIC_CAPS ("application/x-rtcp")
162     );
163
164 static GstStaticPadTemplate rtpbin_send_rtp_sink_template =
165 GST_STATIC_PAD_TEMPLATE ("send_rtp_sink_%d",
166     GST_PAD_SINK,
167     GST_PAD_REQUEST,
168     GST_STATIC_CAPS ("application/x-rtp")
169     );
170
171 /* src pads */
172 static GstStaticPadTemplate rtpbin_recv_rtp_src_template =
173 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src_%d_%d_%d",
174     GST_PAD_SRC,
175     GST_PAD_SOMETIMES,
176     GST_STATIC_CAPS ("application/x-rtp")
177     );
178
179 static GstStaticPadTemplate rtpbin_send_rtcp_src_template =
180 GST_STATIC_PAD_TEMPLATE ("send_rtcp_src_%d",
181     GST_PAD_SRC,
182     GST_PAD_REQUEST,
183     GST_STATIC_CAPS ("application/x-rtcp")
184     );
185
186 static GstStaticPadTemplate rtpbin_send_rtp_src_template =
187 GST_STATIC_PAD_TEMPLATE ("send_rtp_src_%d",
188     GST_PAD_SRC,
189     GST_PAD_SOMETIMES,
190     GST_STATIC_CAPS ("application/x-rtp")
191     );
192
193 /* padtemplate for the internal pad */
194 static GstStaticPadTemplate rtpbin_sync_sink_template =
195 GST_STATIC_PAD_TEMPLATE ("sink_%d",
196     GST_PAD_SINK,
197     GST_PAD_SOMETIMES,
198     GST_STATIC_CAPS ("application/x-rtcp")
199     );
200
201 #define GST_RTP_BIN_GET_PRIVATE(obj)  \
202    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTP_BIN, GstRtpBinPrivate))
203
204 #define GST_RTP_BIN_LOCK(bin)   g_mutex_lock ((bin)->priv->bin_lock)
205 #define GST_RTP_BIN_UNLOCK(bin) g_mutex_unlock ((bin)->priv->bin_lock)
206
207 struct _GstRtpBinPrivate
208 {
209   GMutex *bin_lock;
210
211   GstClockTime ntp_ns_base;
212 };
213
214 /* signals and args */
215 enum
216 {
217   SIGNAL_REQUEST_PT_MAP,
218   SIGNAL_CLEAR_PT_MAP,
219
220   SIGNAL_ON_NEW_SSRC,
221   SIGNAL_ON_SSRC_COLLISION,
222   SIGNAL_ON_SSRC_VALIDATED,
223   SIGNAL_ON_SSRC_ACTIVE,
224   SIGNAL_ON_BYE_SSRC,
225   SIGNAL_ON_BYE_TIMEOUT,
226   SIGNAL_ON_TIMEOUT,
227   LAST_SIGNAL
228 };
229
230 #define DEFAULT_LATENCY_MS      200
231
232 enum
233 {
234   PROP_0,
235   PROP_LATENCY
236 };
237
238 /* helper objects */
239 typedef struct _GstRtpBinSession GstRtpBinSession;
240 typedef struct _GstRtpBinStream GstRtpBinStream;
241 typedef struct _GstRtpBinClient GstRtpBinClient;
242
243 static guint gst_rtp_bin_signals[LAST_SIGNAL] = { 0 };
244
245 static GstCaps *pt_map_requested (GstElement * element, guint pt,
246     GstRtpBinSession * session);
247
248 static void free_stream (GstRtpBinStream * stream);
249
250 /* Manages the RTP stream for one SSRC.
251  *
252  * We pipe the stream (comming from the SSRC demuxer) into a jitterbuffer.
253  * If we see an SDES RTCP packet that links multiple SSRCs together based on a
254  * common CNAME, we create a GstRtpBinClient structure to group the SSRCs
255  * together (see below).
256  */
257 struct _GstRtpBinStream
258 {
259   /* the SSRC of this stream */
260   guint32 ssrc;
261
262   /* parent bin */
263   GstRtpBin *bin;
264
265   /* the session this SSRC belongs to */
266   GstRtpBinSession *session;
267
268   /* the jitterbuffer of the SSRC */
269   GstElement *buffer;
270
271   /* the PT demuxer of the SSRC */
272   GstElement *demux;
273   gulong demux_newpad_sig;
274   gulong demux_ptreq_sig;
275
276   /* the internal pad we use to get RTCP sync messages */
277   GstPad *sync_pad;
278   gboolean have_sync;
279   guint64 last_unix;
280   guint64 last_extrtptime;
281
282   /* mapping to local RTP and NTP time */
283   guint64 local_rtp;
284   guint64 local_unix;
285   gint64 unix_delta;
286
287   /* for lip-sync */
288   guint64 clock_base;
289   gint clock_rate;
290   gint64 ts_offset;
291   gint64 prev_ts_offset;
292 };
293
294 #define GST_RTP_SESSION_LOCK(sess)   g_mutex_lock ((sess)->lock)
295 #define GST_RTP_SESSION_UNLOCK(sess) g_mutex_unlock ((sess)->lock)
296
297 /* Manages the receiving end of the packets.
298  *
299  * There is one such structure for each RTP session (audio/video/...).
300  * We get the RTP/RTCP packets and stuff them into the session manager. From
301  * there they are pushed into an SSRC demuxer that splits the stream based on
302  * SSRC. Each of the SSRC streams go into their own jitterbuffer (managed with
303  * the GstRtpBinStream above).
304  */
305 struct _GstRtpBinSession
306 {
307   /* session id */
308   gint id;
309   /* the parent bin */
310   GstRtpBin *bin;
311   /* the session element */
312   GstElement *session;
313   /* the SSRC demuxer */
314   GstElement *demux;
315   gulong demux_newpad_sig;
316
317   GMutex *lock;
318
319   /* list of GstRtpBinStream */
320   GSList *streams;
321
322   /* mapping of payload type to caps */
323   GHashTable *ptmap;
324
325   /* the pads of the session */
326   GstPad *recv_rtp_sink;
327   GstPad *recv_rtp_src;
328   GstPad *recv_rtcp_sink;
329   GstPad *sync_src;
330   GstPad *send_rtp_sink;
331   GstPad *send_rtp_src;
332   GstPad *send_rtcp_src;
333 };
334
335 /* Manages the RTP streams that come from one client and should therefore be
336  * synchronized.
337  */
338 struct _GstRtpBinClient
339 {
340   /* the common CNAME for the streams */
341   gchar *cname;
342   guint cname_len;
343
344   /* the streams */
345   guint nstreams;
346   GSList *streams;
347
348   gint64 min_delta;
349 };
350
351 /* find a session with the given id. Must be called with RTP_BIN_LOCK */
352 static GstRtpBinSession *
353 find_session_by_id (GstRtpBin * rtpbin, gint id)
354 {
355   GSList *walk;
356
357   for (walk = rtpbin->sessions; walk; walk = g_slist_next (walk)) {
358     GstRtpBinSession *sess = (GstRtpBinSession *) walk->data;
359
360     if (sess->id == id)
361       return sess;
362   }
363   return NULL;
364 }
365
366 static void
367 on_new_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
368 {
369   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC], 0,
370       sess->id, ssrc);
371 }
372
373 static void
374 on_ssrc_collision (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
375 {
376   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION], 0,
377       sess->id, ssrc);
378 }
379
380 static void
381 on_ssrc_validated (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
382 {
383   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
384       sess->id, ssrc);
385 }
386
387 static void
388 on_ssrc_active (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
389 {
390   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE], 0,
391       sess->id, ssrc);
392 }
393
394 static void
395 on_bye_ssrc (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
396 {
397   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC], 0,
398       sess->id, ssrc);
399 }
400
401 static void
402 on_bye_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
403 {
404   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT], 0,
405       sess->id, ssrc);
406 }
407
408 static void
409 on_timeout (GstElement * session, guint32 ssrc, GstRtpBinSession * sess)
410 {
411   g_signal_emit (sess->bin, gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT], 0,
412       sess->id, ssrc);
413 }
414
415 /* create a session with the given id.  Must be called with RTP_BIN_LOCK */
416 static GstRtpBinSession *
417 create_session (GstRtpBin * rtpbin, gint id)
418 {
419   GstRtpBinSession *sess;
420   GstElement *session, *demux;
421
422   if (!(session = gst_element_factory_make ("gstrtpsession", NULL)))
423     goto no_session;
424
425   if (!(demux = gst_element_factory_make ("gstrtpssrcdemux", NULL)))
426     goto no_demux;
427
428   sess = g_new0 (GstRtpBinSession, 1);
429   sess->lock = g_mutex_new ();
430   sess->id = id;
431   sess->bin = rtpbin;
432   sess->session = session;
433   sess->demux = demux;
434   sess->ptmap = g_hash_table_new (NULL, NULL);
435   rtpbin->sessions = g_slist_prepend (rtpbin->sessions, sess);
436
437   /* set NTP base or new session */
438   g_object_set (session, "ntp-ns-base", rtpbin->priv->ntp_ns_base, NULL);
439
440   /* provide clock_rate to the session manager when needed */
441   g_signal_connect (session, "request-pt-map",
442       (GCallback) pt_map_requested, sess);
443
444   g_signal_connect (sess->session, "on-new-ssrc",
445       (GCallback) on_new_ssrc, sess);
446   g_signal_connect (sess->session, "on-ssrc-collision",
447       (GCallback) on_ssrc_collision, sess);
448   g_signal_connect (sess->session, "on-ssrc-validated",
449       (GCallback) on_ssrc_validated, sess);
450   g_signal_connect (sess->session, "on-ssrc-active",
451       (GCallback) on_ssrc_active, sess);
452   g_signal_connect (sess->session, "on-bye-ssrc",
453       (GCallback) on_bye_ssrc, sess);
454   g_signal_connect (sess->session, "on-bye-timeout",
455       (GCallback) on_bye_timeout, sess);
456   g_signal_connect (sess->session, "on-timeout", (GCallback) on_timeout, sess);
457
458   gst_bin_add (GST_BIN_CAST (rtpbin), session);
459   gst_element_set_state (session, GST_STATE_PLAYING);
460   gst_bin_add (GST_BIN_CAST (rtpbin), demux);
461   gst_element_set_state (demux, GST_STATE_PLAYING);
462
463   return sess;
464
465   /* ERRORS */
466 no_session:
467   {
468     g_warning ("gstrtpbin: could not create gstrtpsession element");
469     return NULL;
470   }
471 no_demux:
472   {
473     gst_object_unref (session);
474     g_warning ("gstrtpbin: could not create gstrtpssrcdemux element");
475     return NULL;
476   }
477 }
478
479 static void
480 free_session (GstRtpBinSession * sess)
481 {
482   GstRtpBin *bin;
483
484   bin = sess->bin;
485
486   gst_element_set_state (sess->session, GST_STATE_NULL);
487   gst_element_set_state (sess->demux, GST_STATE_NULL);
488
489   gst_bin_remove (GST_BIN_CAST (bin), sess->session);
490   gst_bin_remove (GST_BIN_CAST (bin), sess->demux);
491
492   g_slist_foreach (sess->streams, (GFunc) free_stream, NULL);
493   g_slist_free (sess->streams);
494
495   g_mutex_free (sess->lock);
496   g_hash_table_destroy (sess->ptmap);
497
498   bin->sessions = g_slist_remove (bin->sessions, sess);
499
500   g_free (sess);
501 }
502
503 #if 0
504 static GstRtpBinStream *
505 find_stream_by_ssrc (GstRtpBinSession * session, guint32 ssrc)
506 {
507   GSList *walk;
508
509   for (walk = session->streams; walk; walk = g_slist_next (walk)) {
510     GstRtpBinStream *stream = (GstRtpBinStream *) walk->data;
511
512     if (stream->ssrc == ssrc)
513       return stream;
514   }
515   return NULL;
516 }
517 #endif
518
519 /* get the payload type caps for the specific payload @pt in @session */
520 static GstCaps *
521 get_pt_map (GstRtpBinSession * session, guint pt)
522 {
523   GstCaps *caps = NULL;
524   GstRtpBin *bin;
525   GValue ret = { 0 };
526   GValue args[3] = { {0}, {0}, {0} };
527
528   GST_DEBUG ("searching pt %d in cache", pt);
529
530   GST_RTP_SESSION_LOCK (session);
531
532   /* first look in the cache */
533   caps = g_hash_table_lookup (session->ptmap, GINT_TO_POINTER (pt));
534   if (caps)
535     goto done;
536
537   bin = session->bin;
538
539   GST_DEBUG ("emiting signal for pt %d in session %d", pt, session->id);
540
541   /* not in cache, send signal to request caps */
542   g_value_init (&args[0], GST_TYPE_ELEMENT);
543   g_value_set_object (&args[0], bin);
544   g_value_init (&args[1], G_TYPE_UINT);
545   g_value_set_uint (&args[1], session->id);
546   g_value_init (&args[2], G_TYPE_UINT);
547   g_value_set_uint (&args[2], pt);
548
549   g_value_init (&ret, GST_TYPE_CAPS);
550   g_value_set_boxed (&ret, NULL);
551
552   g_signal_emitv (args, gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP], 0, &ret);
553
554   caps = (GstCaps *) g_value_get_boxed (&ret);
555   if (!caps)
556     goto no_caps;
557
558   GST_DEBUG ("caching pt %d as %" GST_PTR_FORMAT, pt, caps);
559
560   /* store in cache */
561   g_hash_table_insert (session->ptmap, GINT_TO_POINTER (pt), caps);
562
563 done:
564   gst_caps_ref (caps);
565   GST_RTP_SESSION_UNLOCK (session);
566
567   return caps;
568
569   /* ERRORS */
570 no_caps:
571   {
572     GST_RTP_SESSION_UNLOCK (session);
573     GST_DEBUG ("no pt map could be obtained");
574     return NULL;
575   }
576 }
577
578 static gboolean
579 return_true (gpointer key, gpointer value, gpointer user_data)
580 {
581   return TRUE;
582 }
583
584 static void
585 gst_rtp_bin_clear_pt_map (GstRtpBin * bin)
586 {
587   GSList *sessions, *streams;
588
589   GST_RTP_BIN_LOCK (bin);
590   GST_DEBUG_OBJECT (bin, "clearing pt map");
591   for (sessions = bin->sessions; sessions; sessions = g_slist_next (sessions)) {
592     GstRtpBinSession *session = (GstRtpBinSession *) sessions->data;
593
594     GST_DEBUG_OBJECT (bin, "clearing session %p", session);
595     g_signal_emit_by_name (session->session, "clear-pt-map", NULL);
596
597     GST_RTP_SESSION_LOCK (session);
598     g_hash_table_foreach_remove (session->ptmap, return_true, NULL);
599
600     for (streams = session->streams; streams; streams = g_slist_next (streams)) {
601       GstRtpBinStream *stream = (GstRtpBinStream *) streams->data;
602
603       GST_DEBUG_OBJECT (bin, "clearing stream %p", stream);
604       g_signal_emit_by_name (stream->buffer, "clear-pt-map", NULL);
605       g_signal_emit_by_name (stream->demux, "clear-pt-map", NULL);
606     }
607     GST_RTP_SESSION_UNLOCK (session);
608   }
609   GST_RTP_BIN_UNLOCK (bin);
610 }
611
612 static GstRtpBinClient *
613 get_client (GstRtpBin * bin, guint8 len, guint8 * data, gboolean * created)
614 {
615   GstRtpBinClient *result = NULL;
616   GSList *walk;
617
618   for (walk = bin->clients; walk; walk = g_slist_next (walk)) {
619     GstRtpBinClient *client = (GstRtpBinClient *) walk->data;
620
621     if (len != client->cname_len)
622       continue;
623
624     if (!strncmp ((gchar *) data, client->cname, client->cname_len)) {
625       GST_DEBUG_OBJECT (bin, "found existing client %p with CNAME %s", client,
626           client->cname);
627       result = client;
628       break;
629     }
630   }
631
632   /* nothing found, create one */
633   if (result == NULL) {
634     result = g_new0 (GstRtpBinClient, 1);
635     result->cname = g_strndup ((gchar *) data, len);
636     result->cname_len = len;
637     result->min_delta = G_MAXINT64;
638     bin->clients = g_slist_prepend (bin->clients, result);
639     GST_DEBUG_OBJECT (bin, "created new client %p with CNAME %s", result,
640         result->cname);
641   }
642   return result;
643 }
644
645 static void
646 free_client (GstRtpBinClient * client)
647 {
648   g_free (client->cname);
649   g_free (client);
650 }
651
652 /* associate a stream to the given CNAME. This will make sure all streams for
653  * that CNAME are synchronized together. */
654 static void
655 gst_rtp_bin_associate (GstRtpBin * bin, GstRtpBinStream * stream, guint8 len,
656     guint8 * data)
657 {
658   GstRtpBinClient *client;
659   gboolean created;
660   GSList *walk;
661
662   /* first find or create the CNAME */
663   client = get_client (bin, len, data, &created);
664
665   /* find stream in the client */
666   for (walk = client->streams; walk; walk = g_slist_next (walk)) {
667     GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
668
669     if (ostream == stream)
670       break;
671   }
672   /* not found, add it to the list */
673   if (walk == NULL) {
674     GST_DEBUG_OBJECT (bin,
675         "new association of SSRC %08x with client %p with CNAME %s",
676         stream->ssrc, client, client->cname);
677     client->streams = g_slist_prepend (client->streams, stream);
678     client->nstreams++;
679   } else {
680     GST_DEBUG_OBJECT (bin,
681         "found association of SSRC %08x with client %p with CNAME %s",
682         stream->ssrc, client, client->cname);
683   }
684
685   /* we can only continue if we know the local clock-base and clock-rate */
686   if (stream->clock_base == -1)
687     goto no_clock_base;
688   if (stream->clock_rate <= 0)
689     goto no_clock_rate;
690
691   /* map last RTP time to local timeline using our clock-base */
692   stream->local_rtp = stream->last_extrtptime - stream->clock_base;
693
694   GST_DEBUG_OBJECT (bin,
695       "base %" G_GUINT64_FORMAT ", extrtptime %" G_GUINT64_FORMAT
696       ", local RTP %" G_GUINT64_FORMAT ", clock-rate %d", stream->clock_base,
697       stream->last_extrtptime, stream->local_rtp, stream->clock_rate);
698
699   /* calculate local NTP time in gstreamer timestamp */
700   stream->local_unix =
701       gst_util_uint64_scale_int (stream->local_rtp, GST_SECOND,
702       stream->clock_rate);
703   /* calculate delta between server and receiver */
704   stream->unix_delta = stream->last_unix - stream->local_unix;
705
706   GST_DEBUG_OBJECT (bin,
707       "local UNIX %" G_GUINT64_FORMAT ", remote UNIX %" G_GUINT64_FORMAT
708       ", delta %" G_GINT64_FORMAT, stream->local_unix, stream->last_unix,
709       stream->unix_delta);
710
711   /* recalc inter stream playout offset, but only if there are more than one
712    * stream. */
713   if (client->nstreams > 1) {
714     gint64 min;
715
716     /* calculate the min of all deltas */
717     min = G_MAXINT64;
718     for (walk = client->streams; walk; walk = g_slist_next (walk)) {
719       GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
720
721       if (ostream->unix_delta < min)
722         min = ostream->unix_delta;
723     }
724
725     GST_DEBUG_OBJECT (bin, "client %p min delta %" G_GINT64_FORMAT, client,
726         min);
727
728     /* calculate offsets for each stream */
729     for (walk = client->streams; walk; walk = g_slist_next (walk)) {
730       GstRtpBinStream *ostream = (GstRtpBinStream *) walk->data;
731
732       ostream->ts_offset = ostream->unix_delta - min;
733
734       /* delta changed, see how much */
735       if (ostream->prev_ts_offset != ostream->ts_offset) {
736         gint64 diff;
737
738         if (ostream->prev_ts_offset > ostream->ts_offset)
739           diff = ostream->prev_ts_offset - ostream->ts_offset;
740         else
741           diff = ostream->ts_offset - ostream->prev_ts_offset;
742
743         /* only change diff when it changed more than 1 millisecond. This
744          * compensates for rounding errors in NTP to RTP timestamp
745          * conversions */
746         if (diff > GST_MSECOND)
747           g_object_set (ostream->buffer, "ts-offset", ostream->ts_offset, NULL);
748
749         ostream->prev_ts_offset = ostream->ts_offset;
750       }
751       GST_DEBUG_OBJECT (bin, "stream SSRC %08x, delta %" G_GINT64_FORMAT,
752           ostream->ssrc, ostream->ts_offset);
753     }
754   }
755   return;
756
757 no_clock_base:
758   {
759     GST_WARNING_OBJECT (bin, "we have no clock-base");
760     return;
761   }
762 no_clock_rate:
763   {
764     GST_WARNING_OBJECT (bin, "we have no clock-rate");
765     return;
766   }
767 }
768
769 #define GST_RTCP_BUFFER_FOR_PACKETS(b,buffer,packet) \
770   for ((b) = gst_rtcp_buffer_get_first_packet ((buffer), (packet)); (b); \
771           (b) = gst_rtcp_packet_move_to_next ((packet)))
772
773 #define GST_RTCP_SDES_FOR_ITEMS(b,packet) \
774   for ((b) = gst_rtcp_packet_sdes_first_item ((packet)); (b); \
775           (b) = gst_rtcp_packet_sdes_next_item ((packet)))
776
777 #define GST_RTCP_SDES_FOR_ENTRIES(b,packet) \
778   for ((b) = gst_rtcp_packet_sdes_first_entry ((packet)); (b); \
779           (b) = gst_rtcp_packet_sdes_next_entry ((packet)))
780
781 static GstFlowReturn
782 gst_rtp_bin_sync_chain (GstPad * pad, GstBuffer * buffer)
783 {
784   GstFlowReturn ret = GST_FLOW_OK;
785   GstRtpBinStream *stream;
786   GstRtpBin *bin;
787   GstRTCPPacket packet;
788   guint32 ssrc;
789   guint64 ntptime;
790   guint32 rtptime;
791   gboolean have_sr, have_sdes;
792   gboolean more;
793
794   stream = gst_pad_get_element_private (pad);
795   bin = stream->bin;
796
797   GST_DEBUG_OBJECT (bin, "received sync packet");
798
799   if (!gst_rtcp_buffer_validate (buffer))
800     goto invalid_rtcp;
801
802   have_sr = FALSE;
803   have_sdes = FALSE;
804   GST_RTCP_BUFFER_FOR_PACKETS (more, buffer, &packet) {
805     /* first packet must be SR or RR or else the validate would have failed */
806     switch (gst_rtcp_packet_get_type (&packet)) {
807       case GST_RTCP_TYPE_SR:
808         /* only parse first. There is only supposed to be one SR in the packet
809          * but we will deal with malformed packets gracefully */
810         if (have_sr)
811           break;
812         /* get NTP and RTP times */
813         gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, &rtptime,
814             NULL, NULL);
815
816         GST_DEBUG_OBJECT (bin, "received sync packet from SSRC %08x", ssrc);
817         /* ignore SR that is not ours */
818         if (ssrc != stream->ssrc)
819           continue;
820
821         have_sr = TRUE;
822
823         /* store values in the stream */
824         stream->have_sync = TRUE;
825         stream->last_unix = gst_rtcp_ntp_to_unix (ntptime);
826         /* use extended timestamp */
827         gst_rtp_buffer_ext_timestamp (&stream->last_extrtptime, rtptime);
828         break;
829       case GST_RTCP_TYPE_SDES:
830       {
831         gboolean more_items, more_entries;
832
833         /* only deal with first SDES, there is only supposed to be one SDES in
834          * the RTCP packet but we deal with bad packets gracefully. Also bail
835          * out if we have not seen an SR item yet. */
836         if (have_sdes || !have_sr)
837           break;
838
839         GST_RTCP_SDES_FOR_ITEMS (more_items, &packet) {
840           /* skip items that are not about the SSRC of the sender */
841           if (gst_rtcp_packet_sdes_get_ssrc (&packet) != ssrc)
842             continue;
843
844           /* find the CNAME entry */
845           GST_RTCP_SDES_FOR_ENTRIES (more_entries, &packet) {
846             GstRTCPSDESType type;
847             guint8 len;
848             guint8 *data;
849
850             gst_rtcp_packet_sdes_get_entry (&packet, &type, &len, &data);
851
852             if (type == GST_RTCP_SDES_CNAME) {
853               stream->clock_base = GST_BUFFER_OFFSET (buffer);
854               /* associate the stream to CNAME */
855               gst_rtp_bin_associate (bin, stream, len, data);
856             }
857           }
858         }
859         have_sdes = TRUE;
860         break;
861       }
862       default:
863         /* we can ignore these packets */
864         break;
865     }
866   }
867
868   gst_buffer_unref (buffer);
869
870   return ret;
871
872   /* ERRORS */
873 invalid_rtcp:
874   {
875     /* this is fatal and should be filtered earlier */
876     GST_ELEMENT_ERROR (bin, STREAM, DECODE, (NULL),
877         ("invalid RTCP packet received"));
878     gst_buffer_unref (buffer);
879     return GST_FLOW_ERROR;
880   }
881 }
882
883 /* create a new stream with @ssrc in @session. Must be called with
884  * RTP_SESSION_LOCK. */
885 static GstRtpBinStream *
886 create_stream (GstRtpBinSession * session, guint32 ssrc)
887 {
888   GstElement *buffer, *demux;
889   GstRtpBinStream *stream;
890   GstPadTemplate *templ;
891   gchar *padname;
892
893   if (!(buffer = gst_element_factory_make ("gstrtpjitterbuffer", NULL)))
894     goto no_jitterbuffer;
895
896   if (!(demux = gst_element_factory_make ("gstrtpptdemux", NULL)))
897     goto no_demux;
898
899   stream = g_new0 (GstRtpBinStream, 1);
900   stream->ssrc = ssrc;
901   stream->bin = session->bin;
902   stream->session = session;
903   stream->buffer = buffer;
904   stream->demux = demux;
905   stream->last_extrtptime = -1;
906   stream->have_sync = FALSE;
907   session->streams = g_slist_prepend (session->streams, stream);
908
909   /* make an internal sinkpad for RTCP sync packets. Take ownership of the
910    * pad. We will link this pad later. */
911   padname = g_strdup_printf ("sync_%d", ssrc);
912   templ = gst_static_pad_template_get (&rtpbin_sync_sink_template);
913   stream->sync_pad = gst_pad_new_from_template (templ, padname);
914   gst_object_unref (templ);
915   g_free (padname);
916   gst_object_ref (stream->sync_pad);
917   gst_object_sink (stream->sync_pad);
918   gst_pad_set_element_private (stream->sync_pad, stream);
919   gst_pad_set_chain_function (stream->sync_pad, gst_rtp_bin_sync_chain);
920   gst_pad_set_active (stream->sync_pad, TRUE);
921
922   /* provide clock_rate to the jitterbuffer when needed */
923   g_signal_connect (buffer, "request-pt-map",
924       (GCallback) pt_map_requested, session);
925
926   /* configure latency */
927   g_object_set (buffer, "latency", session->bin->latency, NULL);
928
929   gst_bin_add (GST_BIN_CAST (session->bin), buffer);
930   gst_element_set_state (buffer, GST_STATE_PLAYING);
931   gst_bin_add (GST_BIN_CAST (session->bin), demux);
932   gst_element_set_state (demux, GST_STATE_PLAYING);
933
934   /* link stuff */
935   gst_element_link (buffer, demux);
936
937   return stream;
938
939   /* ERRORS */
940 no_jitterbuffer:
941   {
942     g_warning ("gstrtpbin: could not create gstrtpjitterbuffer element");
943     return NULL;
944   }
945 no_demux:
946   {
947     gst_object_unref (buffer);
948     g_warning ("gstrtpbin: could not create gstrtpptdemux element");
949     return NULL;
950   }
951 }
952
953 static void
954 free_stream (GstRtpBinStream * stream)
955 {
956   GstRtpBinSession *session;
957
958   session = stream->session;
959
960   gst_element_set_state (stream->buffer, GST_STATE_NULL);
961   gst_element_set_state (stream->demux, GST_STATE_NULL);
962
963   gst_bin_remove (GST_BIN_CAST (session->bin), stream->buffer);
964   gst_bin_remove (GST_BIN_CAST (session->bin), stream->demux);
965
966   gst_object_unref (stream->sync_pad);
967
968   session->streams = g_slist_remove (session->streams, stream);
969
970   g_free (stream);
971 }
972
973 /* GObject vmethods */
974 static void gst_rtp_bin_dispose (GObject * object);
975 static void gst_rtp_bin_finalize (GObject * object);
976 static void gst_rtp_bin_set_property (GObject * object, guint prop_id,
977     const GValue * value, GParamSpec * pspec);
978 static void gst_rtp_bin_get_property (GObject * object, guint prop_id,
979     GValue * value, GParamSpec * pspec);
980
981 /* GstElement vmethods */
982 static GstClock *gst_rtp_bin_provide_clock (GstElement * element);
983 static GstStateChangeReturn gst_rtp_bin_change_state (GstElement * element,
984     GstStateChange transition);
985 static GstPad *gst_rtp_bin_request_new_pad (GstElement * element,
986     GstPadTemplate * templ, const gchar * name);
987 static void gst_rtp_bin_release_pad (GstElement * element, GstPad * pad);
988 static void gst_rtp_bin_clear_pt_map (GstRtpBin * bin);
989
990 GST_BOILERPLATE (GstRtpBin, gst_rtp_bin, GstBin, GST_TYPE_BIN);
991
992 static void
993 gst_rtp_bin_base_init (gpointer klass)
994 {
995   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
996
997   /* sink pads */
998   gst_element_class_add_pad_template (element_class,
999       gst_static_pad_template_get (&rtpbin_recv_rtp_sink_template));
1000   gst_element_class_add_pad_template (element_class,
1001       gst_static_pad_template_get (&rtpbin_recv_rtcp_sink_template));
1002   gst_element_class_add_pad_template (element_class,
1003       gst_static_pad_template_get (&rtpbin_send_rtp_sink_template));
1004
1005   /* src pads */
1006   gst_element_class_add_pad_template (element_class,
1007       gst_static_pad_template_get (&rtpbin_recv_rtp_src_template));
1008   gst_element_class_add_pad_template (element_class,
1009       gst_static_pad_template_get (&rtpbin_send_rtcp_src_template));
1010   gst_element_class_add_pad_template (element_class,
1011       gst_static_pad_template_get (&rtpbin_send_rtp_src_template));
1012
1013   gst_element_class_set_details (element_class, &rtpbin_details);
1014 }
1015
1016 static void
1017 gst_rtp_bin_class_init (GstRtpBinClass * klass)
1018 {
1019   GObjectClass *gobject_class;
1020   GstElementClass *gstelement_class;
1021
1022   gobject_class = (GObjectClass *) klass;
1023   gstelement_class = (GstElementClass *) klass;
1024
1025   g_type_class_add_private (klass, sizeof (GstRtpBinPrivate));
1026
1027   gobject_class->dispose = gst_rtp_bin_dispose;
1028   gobject_class->finalize = gst_rtp_bin_finalize;
1029   gobject_class->set_property = gst_rtp_bin_set_property;
1030   gobject_class->get_property = gst_rtp_bin_get_property;
1031
1032   g_object_class_install_property (gobject_class, PROP_LATENCY,
1033       g_param_spec_uint ("latency", "Buffer latency in ms",
1034           "Default amount of ms to buffer in the jitterbuffers", 0,
1035           G_MAXUINT, DEFAULT_LATENCY_MS, G_PARAM_READWRITE));
1036
1037   /**
1038    * GstRtpBin::request-pt-map:
1039    * @rtpbin: the object which received the signal
1040    * @session: the session
1041    * @pt: the pt
1042    *
1043    * Request the payload type as #GstCaps for @pt in @session.
1044    */
1045   gst_rtp_bin_signals[SIGNAL_REQUEST_PT_MAP] =
1046       g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
1047       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, request_pt_map),
1048       NULL, NULL, gst_rtp_bin_marshal_BOXED__UINT_UINT, GST_TYPE_CAPS, 2,
1049       G_TYPE_UINT, G_TYPE_UINT);
1050   /**
1051    * GstRtpBin::clear-pt-map:
1052    * @rtpbin: the object which received the signal
1053    *
1054    * Clear all previously cached pt-mapping obtained with
1055    * GstRtpBin::request-pt-map.
1056    */
1057   gst_rtp_bin_signals[SIGNAL_CLEAR_PT_MAP] =
1058       g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
1059       G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstRtpBinClass,
1060           clear_pt_map), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
1061       0, G_TYPE_NONE);
1062
1063   /**
1064    * GstRtpBin::on-new-ssrc:
1065    * @rtpbin: the object which received the signal
1066    * @session: the session
1067    * @ssrc: the SSRC 
1068    *
1069    * Notify of a new SSRC that entered @session.
1070    */
1071   gst_rtp_bin_signals[SIGNAL_ON_NEW_SSRC] =
1072       g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
1073       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_new_ssrc),
1074       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
1075       G_TYPE_UINT, G_TYPE_UINT);
1076   /**
1077    * GstRtpBin::on-ssrc_collision:
1078    * @rtpbin: the object which received the signal
1079    * @session: the session
1080    * @ssrc: the SSRC 
1081    *
1082    * Notify when we have an SSRC collision
1083    */
1084   gst_rtp_bin_signals[SIGNAL_ON_SSRC_COLLISION] =
1085       g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
1086       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_collision),
1087       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
1088       G_TYPE_UINT, G_TYPE_UINT);
1089   /**
1090    * GstRtpBin::on-ssrc_validated:
1091    * @rtpbin: the object which received the signal
1092    * @session: the session
1093    * @ssrc: the SSRC 
1094    *
1095    * Notify of a new SSRC that became validated.
1096    */
1097   gst_rtp_bin_signals[SIGNAL_ON_SSRC_VALIDATED] =
1098       g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
1099       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_validated),
1100       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
1101       G_TYPE_UINT, G_TYPE_UINT);
1102   /**
1103    * GstRtpBin::on-ssrc_active:
1104    * @rtpbin: the object which received the signal
1105    * @session: the session
1106    * @ssrc: the SSRC
1107    *
1108    * Notify of a SSRC that is active, i.e., sending RTCP.
1109    */
1110   gst_rtp_bin_signals[SIGNAL_ON_SSRC_ACTIVE] =
1111       g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
1112       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_ssrc_active),
1113       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
1114       G_TYPE_UINT, G_TYPE_UINT);
1115
1116   /**
1117    * GstRtpBin::on-bye-ssrc:
1118    * @rtpbin: the object which received the signal
1119    * @session: the session
1120    * @ssrc: the SSRC 
1121    *
1122    * Notify of an SSRC that became inactive because of a BYE packet.
1123    */
1124   gst_rtp_bin_signals[SIGNAL_ON_BYE_SSRC] =
1125       g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
1126       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_ssrc),
1127       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
1128       G_TYPE_UINT, G_TYPE_UINT);
1129   /**
1130    * GstRtpBin::on-bye-timeout:
1131    * @rtpbin: the object which received the signal
1132    * @session: the session
1133    * @ssrc: the SSRC 
1134    *
1135    * Notify of an SSRC that has timed out because of BYE
1136    */
1137   gst_rtp_bin_signals[SIGNAL_ON_BYE_TIMEOUT] =
1138       g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
1139       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_bye_timeout),
1140       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
1141       G_TYPE_UINT, G_TYPE_UINT);
1142   /**
1143    * GstRtpBin::on-timeout:
1144    * @rtpbin: the object which received the signal
1145    * @session: the session
1146    * @ssrc: the SSRC 
1147    *
1148    * Notify of an SSRC that has timed out
1149    */
1150   gst_rtp_bin_signals[SIGNAL_ON_TIMEOUT] =
1151       g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
1152       G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRtpBinClass, on_timeout),
1153       NULL, NULL, gst_rtp_bin_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
1154       G_TYPE_UINT, G_TYPE_UINT);
1155
1156   gstelement_class->provide_clock =
1157       GST_DEBUG_FUNCPTR (gst_rtp_bin_provide_clock);
1158   gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_bin_change_state);
1159   gstelement_class->request_new_pad =
1160       GST_DEBUG_FUNCPTR (gst_rtp_bin_request_new_pad);
1161   gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_bin_release_pad);
1162
1163   klass->clear_pt_map = GST_DEBUG_FUNCPTR (gst_rtp_bin_clear_pt_map);
1164
1165   GST_DEBUG_CATEGORY_INIT (gst_rtp_bin_debug, "rtpbin", 0, "RTP bin");
1166 }
1167
1168 static void
1169 gst_rtp_bin_init (GstRtpBin * rtpbin, GstRtpBinClass * klass)
1170 {
1171   rtpbin->priv = GST_RTP_BIN_GET_PRIVATE (rtpbin);
1172   rtpbin->priv->bin_lock = g_mutex_new ();
1173   rtpbin->provided_clock = gst_system_clock_obtain ();
1174   rtpbin->latency = DEFAULT_LATENCY_MS;
1175 }
1176
1177 static void
1178 gst_rtp_bin_dispose (GObject * object)
1179 {
1180   GstRtpBin *rtpbin;
1181
1182   rtpbin = GST_RTP_BIN (object);
1183
1184   g_slist_foreach (rtpbin->sessions, (GFunc) free_session, NULL);
1185   g_slist_free (rtpbin->sessions);
1186   rtpbin->sessions = NULL;
1187   g_slist_foreach (rtpbin->clients, (GFunc) free_client, NULL);
1188   g_slist_free (rtpbin->clients);
1189   rtpbin->clients = NULL;
1190
1191   G_OBJECT_CLASS (parent_class)->dispose (object);
1192 }
1193
1194 static void
1195 gst_rtp_bin_finalize (GObject * object)
1196 {
1197   GstRtpBin *rtpbin;
1198
1199   rtpbin = GST_RTP_BIN (object);
1200
1201   g_mutex_free (rtpbin->priv->bin_lock);
1202   gst_object_unref (rtpbin->provided_clock);
1203
1204   G_OBJECT_CLASS (parent_class)->finalize (object);
1205 }
1206
1207 static void
1208 gst_rtp_bin_set_property (GObject * object, guint prop_id,
1209     const GValue * value, GParamSpec * pspec)
1210 {
1211   GstRtpBin *rtpbin;
1212
1213   rtpbin = GST_RTP_BIN (object);
1214
1215   switch (prop_id) {
1216     case PROP_LATENCY:
1217       GST_RTP_BIN_LOCK (rtpbin);
1218       rtpbin->latency = g_value_get_uint (value);
1219       GST_RTP_BIN_UNLOCK (rtpbin);
1220       break;
1221     default:
1222       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1223       break;
1224   }
1225 }
1226
1227 static void
1228 gst_rtp_bin_get_property (GObject * object, guint prop_id,
1229     GValue * value, GParamSpec * pspec)
1230 {
1231   GstRtpBin *rtpbin;
1232
1233   rtpbin = GST_RTP_BIN (object);
1234
1235   switch (prop_id) {
1236     case PROP_LATENCY:
1237       GST_RTP_BIN_LOCK (rtpbin);
1238       g_value_set_uint (value, rtpbin->latency);
1239       GST_RTP_BIN_UNLOCK (rtpbin);
1240       break;
1241     default:
1242       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1243       break;
1244   }
1245 }
1246
1247 static GstClock *
1248 gst_rtp_bin_provide_clock (GstElement * element)
1249 {
1250   GstRtpBin *rtpbin;
1251
1252   rtpbin = GST_RTP_BIN (element);
1253
1254   return GST_CLOCK_CAST (gst_object_ref (rtpbin->provided_clock));
1255 }
1256
1257 static void
1258 calc_ntp_ns_base (GstRtpBin * bin)
1259 {
1260   GstClockTime now;
1261   GTimeVal current;
1262   GSList *walk;
1263
1264   /* get the current time and convert it to NTP time in nanoseconds */
1265   g_get_current_time (&current);
1266   now = GST_TIMEVAL_TO_TIME (current);
1267   now += (2208988800LL * GST_SECOND);
1268
1269   GST_RTP_BIN_LOCK (bin);
1270   bin->priv->ntp_ns_base = now;
1271   for (walk = bin->sessions; walk; walk = g_slist_next (walk)) {
1272     GstRtpBinSession *session = (GstRtpBinSession *) walk->data;
1273
1274     g_object_set (session->session, "ntp-ns-base", now, NULL);
1275   }
1276   GST_RTP_BIN_UNLOCK (bin);
1277
1278   return;
1279 }
1280
1281 static GstStateChangeReturn
1282 gst_rtp_bin_change_state (GstElement * element, GstStateChange transition)
1283 {
1284   GstStateChangeReturn res;
1285   GstRtpBin *rtpbin;
1286
1287   rtpbin = GST_RTP_BIN (element);
1288
1289   switch (transition) {
1290     case GST_STATE_CHANGE_NULL_TO_READY:
1291       break;
1292     case GST_STATE_CHANGE_READY_TO_PAUSED:
1293       break;
1294     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
1295       calc_ntp_ns_base (rtpbin);
1296       break;
1297     default:
1298       break;
1299   }
1300
1301   res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1302
1303   switch (transition) {
1304     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1305       break;
1306     case GST_STATE_CHANGE_PAUSED_TO_READY:
1307       break;
1308     case GST_STATE_CHANGE_READY_TO_NULL:
1309       break;
1310     default:
1311       break;
1312   }
1313   return res;
1314 }
1315
1316 /* a new pad (SSRC) was created in @session */
1317 static void
1318 new_payload_found (GstElement * element, guint pt, GstPad * pad,
1319     GstRtpBinStream * stream)
1320 {
1321   GstRtpBin *rtpbin;
1322   GstElementClass *klass;
1323   GstPadTemplate *templ;
1324   gchar *padname;
1325   GstPad *gpad;
1326
1327   rtpbin = stream->bin;
1328
1329   GST_DEBUG ("new payload pad %d", pt);
1330
1331   /* ghost the pad to the parent */
1332   klass = GST_ELEMENT_GET_CLASS (rtpbin);
1333   templ = gst_element_class_get_pad_template (klass, "recv_rtp_src_%d_%d_%d");
1334   padname = g_strdup_printf ("recv_rtp_src_%d_%u_%d",
1335       stream->session->id, stream->ssrc, pt);
1336   gpad = gst_ghost_pad_new_from_template (padname, pad, templ);
1337   g_free (padname);
1338
1339   gst_pad_set_caps (gpad, GST_PAD_CAPS (pad));
1340   gst_pad_set_active (gpad, TRUE);
1341   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), gpad);
1342 }
1343
1344 static GstCaps *
1345 pt_map_requested (GstElement * element, guint pt, GstRtpBinSession * session)
1346 {
1347   GstRtpBin *rtpbin;
1348   GstCaps *caps;
1349
1350   rtpbin = session->bin;
1351
1352   GST_DEBUG_OBJECT (rtpbin, "payload map requested for pt %d in session %d", pt,
1353       session->id);
1354
1355   caps = get_pt_map (session, pt);
1356   if (!caps)
1357     goto no_caps;
1358
1359   return caps;
1360
1361   /* ERRORS */
1362 no_caps:
1363   {
1364     GST_DEBUG_OBJECT (rtpbin, "could not get caps");
1365     return NULL;
1366   }
1367 }
1368
1369 /* emited when caps changed for the session */
1370 static void
1371 caps_changed (GstPad * pad, GParamSpec * pspec, GstRtpBinSession * session)
1372 {
1373   GstRtpBin *bin;
1374   GstCaps *caps;
1375   gint payload;
1376   const GstStructure *s;
1377
1378   bin = session->bin;
1379
1380   g_object_get (pad, "caps", &caps, NULL);
1381
1382   if (caps == NULL)
1383     return;
1384
1385   GST_DEBUG_OBJECT (bin, "got caps %" GST_PTR_FORMAT, caps);
1386
1387   s = gst_caps_get_structure (caps, 0);
1388
1389   /* get payload, finish when it's not there */
1390   if (!gst_structure_get_int (s, "payload", &payload))
1391     return;
1392
1393   GST_RTP_SESSION_LOCK (session);
1394   GST_DEBUG_OBJECT (bin, "insert caps for payload %d", payload);
1395   g_hash_table_insert (session->ptmap, GINT_TO_POINTER (payload), caps);
1396   GST_RTP_SESSION_UNLOCK (session);
1397 }
1398
1399 /* a new pad (SSRC) was created in @session */
1400 static void
1401 new_ssrc_pad_found (GstElement * element, guint ssrc, GstPad * pad,
1402     GstRtpBinSession * session)
1403 {
1404   GstRtpBinStream *stream;
1405   GstPad *sinkpad, *srcpad;
1406   gchar *padname;
1407   GstCaps *caps;
1408
1409   GST_DEBUG_OBJECT (session->bin, "new SSRC pad %08x", ssrc);
1410
1411   GST_RTP_SESSION_LOCK (session);
1412
1413   /* create new stream */
1414   stream = create_stream (session, ssrc);
1415   if (!stream)
1416     goto no_stream;
1417
1418   /* get the caps of the pad, we need the clock-rate and base_time if any. */
1419   if ((caps = gst_pad_get_caps (pad))) {
1420     const GstStructure *s;
1421     guint val;
1422
1423     GST_DEBUG_OBJECT (session->bin, "pad has caps %" GST_PTR_FORMAT, caps);
1424
1425     s = gst_caps_get_structure (caps, 0);
1426
1427     if (!gst_structure_get_int (s, "clock-rate", &stream->clock_rate))
1428       stream->clock_rate = -1;
1429
1430     if (gst_structure_get_uint (s, "clock-base", &val))
1431       stream->clock_base = val;
1432     else
1433       stream->clock_base = -1;
1434   }
1435
1436   /* get pad and link */
1437   GST_DEBUG_OBJECT (session->bin, "linking jitterbuffer");
1438   padname = g_strdup_printf ("src_%d", ssrc);
1439   srcpad = gst_element_get_pad (element, padname);
1440   g_free (padname);
1441   sinkpad = gst_element_get_static_pad (stream->buffer, "sink");
1442   gst_pad_link (srcpad, sinkpad);
1443   gst_object_unref (sinkpad);
1444
1445   /* get the RTCP sync pad */
1446   GST_DEBUG_OBJECT (session->bin, "linking sync pad");
1447   padname = g_strdup_printf ("rtcp_src_%d", ssrc);
1448   srcpad = gst_element_get_pad (element, padname);
1449   g_free (padname);
1450   gst_pad_link (srcpad, stream->sync_pad);
1451   gst_object_unref (srcpad);
1452
1453   /* connect to the new-pad signal of the payload demuxer, this will expose the
1454    * new pad by ghosting it. */
1455   stream->demux_newpad_sig = g_signal_connect (stream->demux,
1456       "new-payload-type", (GCallback) new_payload_found, stream);
1457   /* connect to the request-pt-map signal. This signal will be emited by the
1458    * demuxer so that it can apply a proper caps on the buffers for the
1459    * depayloaders. */
1460   stream->demux_ptreq_sig = g_signal_connect (stream->demux,
1461       "request-pt-map", (GCallback) pt_map_requested, session);
1462
1463   GST_RTP_SESSION_UNLOCK (session);
1464
1465   return;
1466
1467   /* ERRORS */
1468 no_stream:
1469   {
1470     GST_RTP_SESSION_UNLOCK (session);
1471     GST_DEBUG_OBJECT (session->bin, "could not create stream");
1472     return;
1473   }
1474 }
1475
1476 /* Create a pad for receiving RTP for the session in @name. Must be called with
1477  * RTP_BIN_LOCK.
1478  */
1479 static GstPad *
1480 create_recv_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
1481 {
1482   GstPad *result, *sinkdpad;
1483   guint sessid;
1484   GstRtpBinSession *session;
1485   GstPadLinkReturn lres;
1486
1487   /* first get the session number */
1488   if (name == NULL || sscanf (name, "recv_rtp_sink_%d", &sessid) != 1)
1489     goto no_name;
1490
1491   GST_DEBUG_OBJECT (rtpbin, "finding session %d", sessid);
1492
1493   /* get or create session */
1494   session = find_session_by_id (rtpbin, sessid);
1495   if (!session) {
1496     GST_DEBUG_OBJECT (rtpbin, "creating session %d", sessid);
1497     /* create session now */
1498     session = create_session (rtpbin, sessid);
1499     if (session == NULL)
1500       goto create_error;
1501   }
1502
1503   /* check if pad was requested */
1504   if (session->recv_rtp_sink != NULL)
1505     goto existed;
1506
1507   GST_DEBUG_OBJECT (rtpbin, "getting RTP sink pad");
1508   /* get recv_rtp pad and store */
1509   session->recv_rtp_sink =
1510       gst_element_get_request_pad (session->session, "recv_rtp_sink");
1511   if (session->recv_rtp_sink == NULL)
1512     goto pad_failed;
1513
1514   g_signal_connect (session->recv_rtp_sink, "notify::caps",
1515       (GCallback) caps_changed, session);
1516
1517   GST_DEBUG_OBJECT (rtpbin, "getting RTP src pad");
1518   /* get srcpad, link to SSRCDemux */
1519   session->recv_rtp_src =
1520       gst_element_get_static_pad (session->session, "recv_rtp_src");
1521   if (session->recv_rtp_src == NULL)
1522     goto pad_failed;
1523
1524   GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTP sink pad");
1525   sinkdpad = gst_element_get_static_pad (session->demux, "sink");
1526   GST_DEBUG_OBJECT (rtpbin, "linking demuxer RTP sink pad");
1527   lres = gst_pad_link (session->recv_rtp_src, sinkdpad);
1528   gst_object_unref (sinkdpad);
1529   if (lres != GST_PAD_LINK_OK)
1530     goto link_failed;
1531
1532   /* connect to the new-ssrc-pad signal of the SSRC demuxer */
1533   session->demux_newpad_sig = g_signal_connect (session->demux,
1534       "new-ssrc-pad", (GCallback) new_ssrc_pad_found, session);
1535
1536   GST_DEBUG_OBJECT (rtpbin, "ghosting session sink pad");
1537   result =
1538       gst_ghost_pad_new_from_template (name, session->recv_rtp_sink, templ);
1539   gst_pad_set_active (result, TRUE);
1540   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
1541
1542   return result;
1543
1544   /* ERRORS */
1545 no_name:
1546   {
1547     g_warning ("gstrtpbin: invalid name given");
1548     return NULL;
1549   }
1550 create_error:
1551   {
1552     /* create_session already warned */
1553     return NULL;
1554   }
1555 existed:
1556   {
1557     g_warning ("gstrtpbin: recv_rtp pad already requested for session %d",
1558         sessid);
1559     return NULL;
1560   }
1561 pad_failed:
1562   {
1563     g_warning ("gstrtpbin: failed to get session pad");
1564     return NULL;
1565   }
1566 link_failed:
1567   {
1568     g_warning ("gstrtpbin: failed to link pads");
1569     return NULL;
1570   }
1571 }
1572
1573 /* Create a pad for receiving RTCP for the session in @name. Must be called with
1574  * RTP_BIN_LOCK.
1575  */
1576 static GstPad *
1577 create_recv_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ,
1578     const gchar * name)
1579 {
1580   GstPad *result;
1581   guint sessid;
1582   GstRtpBinSession *session;
1583   GstPad *sinkdpad;
1584   GstPadLinkReturn lres;
1585
1586   /* first get the session number */
1587   if (name == NULL || sscanf (name, "recv_rtcp_sink_%d", &sessid) != 1)
1588     goto no_name;
1589
1590   GST_DEBUG_OBJECT (rtpbin, "finding session %d", sessid);
1591
1592   /* get or create the session */
1593   session = find_session_by_id (rtpbin, sessid);
1594   if (!session) {
1595     GST_DEBUG_OBJECT (rtpbin, "creating session %d", sessid);
1596     /* create session now */
1597     session = create_session (rtpbin, sessid);
1598     if (session == NULL)
1599       goto create_error;
1600   }
1601
1602   /* check if pad was requested */
1603   if (session->recv_rtcp_sink != NULL)
1604     goto existed;
1605
1606   /* get recv_rtp pad and store */
1607   GST_DEBUG_OBJECT (rtpbin, "getting RTCP sink pad");
1608   session->recv_rtcp_sink =
1609       gst_element_get_request_pad (session->session, "recv_rtcp_sink");
1610   if (session->recv_rtcp_sink == NULL)
1611     goto pad_failed;
1612
1613   /* get srcpad, link to SSRCDemux */
1614   GST_DEBUG_OBJECT (rtpbin, "getting sync src pad");
1615   session->sync_src = gst_element_get_static_pad (session->session, "sync_src");
1616   if (session->sync_src == NULL)
1617     goto pad_failed;
1618
1619   GST_DEBUG_OBJECT (rtpbin, "getting demuxer RTCP sink pad");
1620   sinkdpad = gst_element_get_static_pad (session->demux, "rtcp_sink");
1621   lres = gst_pad_link (session->sync_src, sinkdpad);
1622   gst_object_unref (sinkdpad);
1623   if (lres != GST_PAD_LINK_OK)
1624     goto link_failed;
1625
1626   result =
1627       gst_ghost_pad_new_from_template (name, session->recv_rtcp_sink, templ);
1628   gst_pad_set_active (result, TRUE);
1629   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
1630
1631   return result;
1632
1633   /* ERRORS */
1634 no_name:
1635   {
1636     g_warning ("gstrtpbin: invalid name given");
1637     return NULL;
1638   }
1639 create_error:
1640   {
1641     /* create_session already warned */
1642     return NULL;
1643   }
1644 existed:
1645   {
1646     g_warning ("gstrtpbin: recv_rtcp pad already requested for session %d",
1647         sessid);
1648     return NULL;
1649   }
1650 pad_failed:
1651   {
1652     g_warning ("gstrtpbin: failed to get session pad");
1653     return NULL;
1654   }
1655 link_failed:
1656   {
1657     g_warning ("gstrtpbin: failed to link pads");
1658     return NULL;
1659   }
1660 }
1661
1662 /* Create a pad for sending RTP for the session in @name. Must be called with
1663  * RTP_BIN_LOCK.
1664  */
1665 static GstPad *
1666 create_send_rtp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
1667 {
1668   GstPad *result, *srcghost;
1669   gchar *gname;
1670   guint sessid;
1671   GstRtpBinSession *session;
1672   GstElementClass *klass;
1673
1674   /* first get the session number */
1675   if (name == NULL || sscanf (name, "send_rtp_sink_%d", &sessid) != 1)
1676     goto no_name;
1677
1678   /* get or create session */
1679   session = find_session_by_id (rtpbin, sessid);
1680   if (!session) {
1681     /* create session now */
1682     session = create_session (rtpbin, sessid);
1683     if (session == NULL)
1684       goto create_error;
1685   }
1686
1687   /* check if pad was requested */
1688   if (session->send_rtp_sink != NULL)
1689     goto existed;
1690
1691   /* get send_rtp pad and store */
1692   session->send_rtp_sink =
1693       gst_element_get_request_pad (session->session, "send_rtp_sink");
1694   if (session->send_rtp_sink == NULL)
1695     goto pad_failed;
1696
1697   result =
1698       gst_ghost_pad_new_from_template (name, session->send_rtp_sink, templ);
1699   gst_pad_set_active (result, TRUE);
1700   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
1701
1702   /* get srcpad */
1703   session->send_rtp_src =
1704       gst_element_get_static_pad (session->session, "send_rtp_src");
1705   if (session->send_rtp_src == NULL)
1706     goto no_srcpad;
1707
1708   /* ghost the new source pad */
1709   klass = GST_ELEMENT_GET_CLASS (rtpbin);
1710   gname = g_strdup_printf ("send_rtp_src_%d", sessid);
1711   templ = gst_element_class_get_pad_template (klass, "send_rtp_src_%d");
1712   srcghost =
1713       gst_ghost_pad_new_from_template (gname, session->send_rtp_src, templ);
1714   gst_pad_set_active (srcghost, TRUE);
1715   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), srcghost);
1716   g_free (gname);
1717
1718   return result;
1719
1720   /* ERRORS */
1721 no_name:
1722   {
1723     g_warning ("gstrtpbin: invalid name given");
1724     return NULL;
1725   }
1726 create_error:
1727   {
1728     /* create_session already warned */
1729     return NULL;
1730   }
1731 existed:
1732   {
1733     g_warning ("gstrtpbin: send_rtp pad already requested for session %d",
1734         sessid);
1735     return NULL;
1736   }
1737 pad_failed:
1738   {
1739     g_warning ("gstrtpbin: failed to get session pad for session %d", sessid);
1740     return NULL;
1741   }
1742 no_srcpad:
1743   {
1744     g_warning ("gstrtpbin: failed to get rtp source pad for session %d",
1745         sessid);
1746     return NULL;
1747   }
1748 }
1749
1750 /* Create a pad for sending RTCP for the session in @name. Must be called with
1751  * RTP_BIN_LOCK.
1752  */
1753 static GstPad *
1754 create_rtcp (GstRtpBin * rtpbin, GstPadTemplate * templ, const gchar * name)
1755 {
1756   GstPad *result;
1757   guint sessid;
1758   GstRtpBinSession *session;
1759
1760   /* first get the session number */
1761   if (name == NULL || sscanf (name, "send_rtcp_src_%d", &sessid) != 1)
1762     goto no_name;
1763
1764   /* get or create session */
1765   session = find_session_by_id (rtpbin, sessid);
1766   if (!session)
1767     goto no_session;
1768
1769   /* check if pad was requested */
1770   if (session->send_rtcp_src != NULL)
1771     goto existed;
1772
1773   /* get rtcp_src pad and store */
1774   session->send_rtcp_src =
1775       gst_element_get_request_pad (session->session, "send_rtcp_src");
1776   if (session->send_rtcp_src == NULL)
1777     goto pad_failed;
1778
1779   result =
1780       gst_ghost_pad_new_from_template (name, session->send_rtcp_src, templ);
1781   gst_pad_set_active (result, TRUE);
1782   gst_element_add_pad (GST_ELEMENT_CAST (rtpbin), result);
1783
1784   return result;
1785
1786   /* ERRORS */
1787 no_name:
1788   {
1789     g_warning ("gstrtpbin: invalid name given");
1790     return NULL;
1791   }
1792 no_session:
1793   {
1794     g_warning ("gstrtpbin: session with id %d does not exist", sessid);
1795     return NULL;
1796   }
1797 existed:
1798   {
1799     g_warning ("gstrtpbin: send_rtcp_src pad already requested for session %d",
1800         sessid);
1801     return NULL;
1802   }
1803 pad_failed:
1804   {
1805     g_warning ("gstrtpbin: failed to get rtcp pad for session %d", sessid);
1806     return NULL;
1807   }
1808 }
1809
1810 /* 
1811  */
1812 static GstPad *
1813 gst_rtp_bin_request_new_pad (GstElement * element,
1814     GstPadTemplate * templ, const gchar * name)
1815 {
1816   GstRtpBin *rtpbin;
1817   GstElementClass *klass;
1818   GstPad *result;
1819
1820   g_return_val_if_fail (templ != NULL, NULL);
1821   g_return_val_if_fail (GST_IS_RTP_BIN (element), NULL);
1822
1823   rtpbin = GST_RTP_BIN (element);
1824   klass = GST_ELEMENT_GET_CLASS (element);
1825
1826   GST_RTP_BIN_LOCK (rtpbin);
1827
1828   /* figure out the template */
1829   if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink_%d")) {
1830     result = create_recv_rtp (rtpbin, templ, name);
1831   } else if (templ == gst_element_class_get_pad_template (klass,
1832           "recv_rtcp_sink_%d")) {
1833     result = create_recv_rtcp (rtpbin, templ, name);
1834   } else if (templ == gst_element_class_get_pad_template (klass,
1835           "send_rtp_sink_%d")) {
1836     result = create_send_rtp (rtpbin, templ, name);
1837   } else if (templ == gst_element_class_get_pad_template (klass,
1838           "send_rtcp_src_%d")) {
1839     result = create_rtcp (rtpbin, templ, name);
1840   } else
1841     goto wrong_template;
1842
1843   GST_RTP_BIN_UNLOCK (rtpbin);
1844
1845   return result;
1846
1847   /* ERRORS */
1848 wrong_template:
1849   {
1850     GST_RTP_BIN_UNLOCK (rtpbin);
1851     g_warning ("gstrtpbin: this is not our template");
1852     return NULL;
1853   }
1854 }
1855
1856 static void
1857 gst_rtp_bin_release_pad (GstElement * element, GstPad * pad)
1858 {
1859 }