2 * Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.com>
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.
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.
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.
20 * Unless otherwise indicated, Source Code is licensed under MIT license.
21 * See further explanation attached in License Statement (distributed in the file
24 * Permission is hereby granted, free of charge, to any person obtaining a copy of
25 * this software and associated documentation files (the "Software"), to deal in
26 * the Software without restriction, including without limitation the rights to
27 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28 * of the Software, and to permit persons to whom the Software is furnished to do
29 * so, subject to the following conditions:
31 * The above copyright notice and this permission notice shall be included in all
32 * copies or substantial portions of the Software.
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42 /* Element-Checklist-Version: 5 */
45 * SECTION:element-rtpdec
47 * A simple RTP session manager used internally by rtspsrc.
49 * Last reviewed on 2006-06-20 (0.10.4)
52 /* #define HAVE_RTCP */
54 #include <gst/rtp/gstrtpbuffer.h>
57 #include <gst/rtp/gstrtcpbuffer.h>
60 #include "gstrtpdec.h"
63 GST_DEBUG_CATEGORY_STATIC (rtpdec_debug);
64 #define GST_CAT_DEFAULT (rtpdec_debug)
66 /* elementfactory information */
67 static const GstElementDetails rtpdec_details =
68 GST_ELEMENT_DETAILS ("RTP Decoder",
69 "Codec/Parser/Network",
70 "Accepts raw RTP and RTCP packets and sends them forward",
71 "Wim Taymans <wim@fluendo.com>");
73 /* GstRTPDec signals and args */
76 SIGNAL_REQUEST_PT_MAP,
80 SIGNAL_ON_SSRC_COLLISION,
81 SIGNAL_ON_SSRC_VALIDATED,
83 SIGNAL_ON_BYE_TIMEOUT,
88 #define DEFAULT_LATENCY_MS 200
96 static GstStaticPadTemplate gst_rtp_dec_recv_rtp_sink_template =
97 GST_STATIC_PAD_TEMPLATE ("recv_rtp_sink_%d",
100 GST_STATIC_CAPS ("application/x-rtp")
103 static GstStaticPadTemplate gst_rtp_dec_recv_rtcp_sink_template =
104 GST_STATIC_PAD_TEMPLATE ("recv_rtcp_sink_%d",
107 GST_STATIC_CAPS ("application/x-rtcp")
110 static GstStaticPadTemplate gst_rtp_dec_recv_rtp_src_template =
111 GST_STATIC_PAD_TEMPLATE ("recv_rtp_src_%d_%d_%d",
114 GST_STATIC_CAPS ("application/x-rtp")
117 static GstStaticPadTemplate gst_rtp_dec_rtcp_src_template =
118 GST_STATIC_PAD_TEMPLATE ("rtcp_src_%d",
121 GST_STATIC_CAPS ("application/x-rtcp")
124 static void gst_rtp_dec_finalize (GObject * object);
125 static void gst_rtp_dec_set_property (GObject * object,
126 guint prop_id, const GValue * value, GParamSpec * pspec);
127 static void gst_rtp_dec_get_property (GObject * object,
128 guint prop_id, GValue * value, GParamSpec * pspec);
130 static GstClock *gst_rtp_dec_provide_clock (GstElement * element);
131 static GstStateChangeReturn gst_rtp_dec_change_state (GstElement * element,
132 GstStateChange transition);
133 static GstPad *gst_rtp_dec_request_new_pad (GstElement * element,
134 GstPadTemplate * templ, const gchar * name);
135 static void gst_rtp_dec_release_pad (GstElement * element, GstPad * pad);
137 static GstFlowReturn gst_rtp_dec_chain_rtp (GstPad * pad, GstBuffer * buffer);
138 static GstFlowReturn gst_rtp_dec_chain_rtcp (GstPad * pad, GstBuffer * buffer);
141 /* Manages the receiving end of the packets.
143 * There is one such structure for each RTP session (audio/video/...).
144 * We get the RTP/RTCP packets and stuff them into the session manager.
146 struct _GstRTPDecSession
154 /* we only support one ssrc and one pt */
159 /* the pads of the session */
160 GstPad *recv_rtp_sink;
161 GstPad *recv_rtp_src;
162 GstPad *recv_rtcp_sink;
166 /* find a session with the given id */
167 static GstRTPDecSession *
168 find_session_by_id (GstRTPDec * rtpdec, gint id)
172 for (walk = rtpdec->sessions; walk; walk = g_slist_next (walk)) {
173 GstRTPDecSession *sess = (GstRTPDecSession *) walk->data;
181 /* create a session with the given id */
182 static GstRTPDecSession *
183 create_session (GstRTPDec * rtpdec, gint id)
185 GstRTPDecSession *sess;
187 sess = g_new0 (GstRTPDecSession, 1);
190 rtpdec->sessions = g_slist_prepend (rtpdec->sessions, sess);
196 free_session (GstRTPDecSession * session)
201 static guint gst_rtp_dec_signals[LAST_SIGNAL] = { 0 };
203 GST_BOILERPLATE (GstRTPDec, gst_rtp_dec, GstElement, GST_TYPE_ELEMENT);
206 gst_rtp_dec_base_init (gpointer klass)
208 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
211 gst_element_class_add_pad_template (element_class,
212 gst_static_pad_template_get (&gst_rtp_dec_recv_rtp_sink_template));
213 gst_element_class_add_pad_template (element_class,
214 gst_static_pad_template_get (&gst_rtp_dec_recv_rtcp_sink_template));
216 gst_element_class_add_pad_template (element_class,
217 gst_static_pad_template_get (&gst_rtp_dec_recv_rtp_src_template));
218 gst_element_class_add_pad_template (element_class,
219 gst_static_pad_template_get (&gst_rtp_dec_rtcp_src_template));
221 gst_element_class_set_details (element_class, &rtpdec_details);
224 /* BOXED:UINT,UINT */
225 #define g_marshal_value_peek_uint(v) g_value_get_uint (v)
228 gst_rtp_dec_marshal_BOXED__UINT_UINT (GClosure * closure,
229 GValue * return_value,
230 guint n_param_values,
231 const GValue * param_values,
232 gpointer invocation_hint, gpointer marshal_data)
234 typedef gpointer (*GMarshalFunc_BOXED__UINT_UINT) (gpointer data1,
235 guint arg_1, guint arg_2, gpointer data2);
236 register GMarshalFunc_BOXED__UINT_UINT callback;
237 register GCClosure *cc = (GCClosure *) closure;
238 register gpointer data1, data2;
241 g_return_if_fail (return_value != NULL);
242 g_return_if_fail (n_param_values == 3);
244 if (G_CCLOSURE_SWAP_DATA (closure)) {
245 data1 = closure->data;
246 data2 = g_value_peek_pointer (param_values + 0);
248 data1 = g_value_peek_pointer (param_values + 0);
249 data2 = closure->data;
252 (GMarshalFunc_BOXED__UINT_UINT) (marshal_data ? marshal_data :
255 v_return = callback (data1,
256 g_marshal_value_peek_uint (param_values + 1),
257 g_marshal_value_peek_uint (param_values + 2), data2);
259 g_value_take_boxed (return_value, v_return);
263 gst_rtp_dec_marshal_VOID__UINT_UINT (GClosure * closure,
264 GValue * return_value,
265 guint n_param_values,
266 const GValue * param_values,
267 gpointer invocation_hint, gpointer marshal_data)
269 typedef void (*GMarshalFunc_VOID__UINT_UINT) (gpointer data1,
270 guint arg_1, guint arg_2, gpointer data2);
271 register GMarshalFunc_VOID__UINT_UINT callback;
272 register GCClosure *cc = (GCClosure *) closure;
273 register gpointer data1, data2;
275 g_return_if_fail (n_param_values == 3);
277 if (G_CCLOSURE_SWAP_DATA (closure)) {
278 data1 = closure->data;
279 data2 = g_value_peek_pointer (param_values + 0);
281 data1 = g_value_peek_pointer (param_values + 0);
282 data2 = closure->data;
285 (GMarshalFunc_VOID__UINT_UINT) (marshal_data ? marshal_data :
289 g_marshal_value_peek_uint (param_values + 1),
290 g_marshal_value_peek_uint (param_values + 2), data2);
294 gst_rtp_dec_class_init (GstRTPDecClass * g_class)
296 GObjectClass *gobject_class;
297 GstElementClass *gstelement_class;
298 GstRTPDecClass *klass;
300 klass = (GstRTPDecClass *) g_class;
301 gobject_class = (GObjectClass *) klass;
302 gstelement_class = (GstElementClass *) klass;
304 gobject_class->finalize = gst_rtp_dec_finalize;
305 gobject_class->set_property = gst_rtp_dec_set_property;
306 gobject_class->get_property = gst_rtp_dec_get_property;
308 g_object_class_install_property (gobject_class, PROP_LATENCY,
309 g_param_spec_uint ("latency", "Buffer latency in ms",
310 "Amount of ms to buffer", 0, G_MAXUINT, DEFAULT_LATENCY_MS,
314 * GstRTPDec::request-pt-map:
315 * @rtpdec: the object which received the signal
316 * @session: the session
319 * Request the payload type as #GstCaps for @pt in @session.
321 gst_rtp_dec_signals[SIGNAL_REQUEST_PT_MAP] =
322 g_signal_new ("request-pt-map", G_TYPE_FROM_CLASS (klass),
323 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, request_pt_map),
324 NULL, NULL, gst_rtp_dec_marshal_BOXED__UINT_UINT, GST_TYPE_CAPS, 2,
325 G_TYPE_UINT, G_TYPE_UINT);
327 gst_rtp_dec_signals[SIGNAL_CLEAR_PT_MAP] =
328 g_signal_new ("clear-pt-map", G_TYPE_FROM_CLASS (klass),
329 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, clear_pt_map),
330 NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
333 * GstRTPDec::on-new-ssrc:
334 * @rtpbin: the object which received the signal
335 * @session: the session
338 * Notify of a new SSRC that entered @session.
340 gst_rtp_dec_signals[SIGNAL_ON_NEW_SSRC] =
341 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
342 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, on_new_ssrc),
343 NULL, NULL, gst_rtp_dec_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
344 G_TYPE_UINT, G_TYPE_UINT);
346 * GstRTPDec::on-ssrc_collision:
347 * @rtpbin: the object which received the signal
348 * @session: the session
351 * Notify when we have an SSRC collision
353 gst_rtp_dec_signals[SIGNAL_ON_SSRC_COLLISION] =
354 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
355 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, on_ssrc_collision),
356 NULL, NULL, gst_rtp_dec_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
357 G_TYPE_UINT, G_TYPE_UINT);
359 * GstRTPDec::on-ssrc_validated:
360 * @rtpbin: the object which received the signal
361 * @session: the session
364 * Notify of a new SSRC that became validated.
366 gst_rtp_dec_signals[SIGNAL_ON_SSRC_VALIDATED] =
367 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
368 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, on_ssrc_validated),
369 NULL, NULL, gst_rtp_dec_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
370 G_TYPE_UINT, G_TYPE_UINT);
373 * GstRTPDec::on-bye-ssrc:
374 * @rtpbin: the object which received the signal
375 * @session: the session
378 * Notify of an SSRC that became inactive because of a BYE packet.
380 gst_rtp_dec_signals[SIGNAL_ON_BYE_SSRC] =
381 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
382 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, on_bye_ssrc),
383 NULL, NULL, gst_rtp_dec_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
384 G_TYPE_UINT, G_TYPE_UINT);
386 * GstRTPDec::on-bye-timeout:
387 * @rtpbin: the object which received the signal
388 * @session: the session
391 * Notify of an SSRC that has timed out because of BYE
393 gst_rtp_dec_signals[SIGNAL_ON_BYE_TIMEOUT] =
394 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
395 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, on_bye_timeout),
396 NULL, NULL, gst_rtp_dec_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
397 G_TYPE_UINT, G_TYPE_UINT);
399 * GstRTPDec::on-timeout:
400 * @rtpbin: the object which received the signal
401 * @session: the session
404 * Notify of an SSRC that has timed out
406 gst_rtp_dec_signals[SIGNAL_ON_TIMEOUT] =
407 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
408 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRTPDecClass, on_timeout),
409 NULL, NULL, gst_rtp_dec_marshal_VOID__UINT_UINT, G_TYPE_NONE, 2,
410 G_TYPE_UINT, G_TYPE_UINT);
413 gstelement_class->provide_clock =
414 GST_DEBUG_FUNCPTR (gst_rtp_dec_provide_clock);
415 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_dec_change_state);
416 gstelement_class->request_new_pad =
417 GST_DEBUG_FUNCPTR (gst_rtp_dec_request_new_pad);
418 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_dec_release_pad);
420 GST_DEBUG_CATEGORY_INIT (rtpdec_debug, "rtpdec", 0, "RTP decoder");
424 gst_rtp_dec_init (GstRTPDec * rtpdec, GstRTPDecClass * klass)
426 rtpdec->provided_clock = gst_system_clock_obtain ();
427 rtpdec->latency = DEFAULT_LATENCY_MS;
431 gst_rtp_dec_finalize (GObject * object)
435 rtpdec = GST_RTP_DEC (object);
437 g_slist_foreach (rtpdec->sessions, (GFunc) free_session, NULL);
438 g_slist_free (rtpdec->sessions);
440 G_OBJECT_CLASS (parent_class)->finalize (object);
444 gst_rtp_dec_query_src (GstPad * pad, GstQuery * query)
448 switch (GST_QUERY_TYPE (query)) {
449 case GST_QUERY_LATENCY:
451 /* we pretend to be live with a 3 second latency */
452 gst_query_set_latency (query, TRUE, 3 * GST_SECOND, -1);
457 res = gst_pad_query_default (pad, query);
464 gst_rtp_dec_chain_rtp (GstPad * pad, GstBuffer * buffer)
468 GstRTPDecSession *session;
472 rtpdec = GST_RTP_DEC (GST_PAD_PARENT (pad));
474 GST_DEBUG_OBJECT (rtpdec, "got rtp packet");
476 if (!gst_rtp_buffer_validate (buffer))
479 ssrc = gst_rtp_buffer_get_ssrc (buffer);
480 pt = gst_rtp_buffer_get_payload_type (buffer);
482 GST_DEBUG_OBJECT (rtpdec, "SSRC %08x, PT %d", ssrc, pt);
485 session = gst_pad_get_element_private (pad);
487 /* see if we have the pad */
488 if (!session->active) {
489 GstPadTemplate *templ;
490 GstElementClass *klass;
494 GValue args[3] = { {0}
499 GST_DEBUG_OBJECT (rtpdec, "creating stream");
501 session->ssrc = ssrc;
505 g_value_init (&args[0], GST_TYPE_ELEMENT);
506 g_value_set_object (&args[0], rtpdec);
507 g_value_init (&args[1], G_TYPE_UINT);
508 g_value_set_uint (&args[1], session->id);
509 g_value_init (&args[2], G_TYPE_UINT);
510 g_value_set_uint (&args[2], pt);
512 g_value_init (&ret, GST_TYPE_CAPS);
513 g_value_set_boxed (&ret, NULL);
515 g_signal_emitv (args, gst_rtp_dec_signals[SIGNAL_REQUEST_PT_MAP], 0, &ret);
517 caps = (GstCaps *) g_value_get_boxed (&ret);
519 name = g_strdup_printf ("recv_rtp_src_%d_%u_%d", session->id, ssrc, pt);
520 klass = GST_ELEMENT_GET_CLASS (rtpdec);
521 templ = gst_element_class_get_pad_template (klass, "recv_rtp_src_%d_%d_%d");
522 session->recv_rtp_src = gst_pad_new_from_template (templ, name);
525 gst_pad_set_caps (session->recv_rtp_src, caps);
527 gst_pad_set_element_private (session->recv_rtp_src, session);
528 gst_pad_set_query_function (session->recv_rtp_src, gst_rtp_dec_query_src);
529 gst_pad_set_active (session->recv_rtp_src, TRUE);
530 gst_element_add_pad (GST_ELEMENT_CAST (rtpdec), session->recv_rtp_src);
532 session->active = TRUE;
535 gst_buffer_set_caps (buffer, GST_PAD_CAPS (session->recv_rtp_src));
537 res = gst_pad_push (session->recv_rtp_src, buffer);
543 GST_ELEMENT_WARNING (rtpdec, STREAM, DECODE, (NULL),
544 ("RTP packet did not validate, dropping"));
545 gst_buffer_unref (buffer);
551 gst_rtp_dec_chain_rtcp (GstPad * pad, GstBuffer * buffer)
557 GstRTCPPacket packet;
561 src = GST_RTP_DEC (GST_PAD_PARENT (pad));
563 GST_DEBUG_OBJECT (src, "got rtcp packet");
566 valid = gst_rtcp_buffer_validate (buffer);
570 /* position on first packet */
571 more = gst_rtcp_buffer_get_first_packet (buffer, &packet);
573 switch (gst_rtcp_packet_get_type (&packet)) {
574 case GST_RTCP_TYPE_SR:
576 guint32 ssrc, rtptime, packet_count, octet_count;
580 gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, &rtptime,
581 &packet_count, &octet_count);
583 GST_DEBUG_OBJECT (src,
584 "got SR packet: SSRC %08x, NTP %" G_GUINT64_FORMAT
585 ", RTP %u, PC %u, OC %u", ssrc, ntptime, rtptime, packet_count,
588 count = gst_rtcp_packet_get_rb_count (&packet);
589 for (i = 0; i < count; i++) {
590 guint32 ssrc, exthighestseq, jitter, lsr, dlsr;
594 gst_rtcp_packet_get_rb (&packet, i, &ssrc, &fractionlost,
595 &packetslost, &exthighestseq, &jitter, &lsr, &dlsr);
597 GST_DEBUG_OBJECT (src, "got RB packet %d: SSRC %08x, FL %u"
598 ", PL %u, HS %u, JITTER %u, LSR %u, DLSR %u", ssrc, fractionlost,
599 packetslost, exthighestseq, jitter, lsr, dlsr);
603 case GST_RTCP_TYPE_RR:
608 ssrc = gst_rtcp_packet_rr_get_ssrc (&packet);
610 GST_DEBUG_OBJECT (src, "got RR packet: SSRC %08x", ssrc);
612 count = gst_rtcp_packet_get_rb_count (&packet);
613 for (i = 0; i < count; i++) {
614 guint32 ssrc, exthighestseq, jitter, lsr, dlsr;
618 gst_rtcp_packet_get_rb (&packet, i, &ssrc, &fractionlost,
619 &packetslost, &exthighestseq, &jitter, &lsr, &dlsr);
621 GST_DEBUG_OBJECT (src, "got RB packet %d: SSRC %08x, FL %u"
622 ", PL %u, HS %u, JITTER %u, LSR %u, DLSR %u", ssrc, fractionlost,
623 packetslost, exthighestseq, jitter, lsr, dlsr);
627 case GST_RTCP_TYPE_SDES:
630 gboolean more_chunks, more_items;
632 chunks = gst_rtcp_packet_sdes_get_chunk_count (&packet);
633 GST_DEBUG_OBJECT (src, "got SDES packet with %d chunks", chunks);
635 more_chunks = gst_rtcp_packet_sdes_first_chunk (&packet);
637 while (more_chunks) {
640 ssrc = gst_rtcp_packet_sdes_get_ssrc (&packet);
642 GST_DEBUG_OBJECT (src, "chunk %d, SSRC %08x", i, ssrc);
644 more_items = gst_rtcp_packet_sdes_first_item (&packet);
647 GstRTCPSDESType type;
651 gst_rtcp_packet_sdes_get_item (&packet, &type, &len, &data);
653 GST_DEBUG_OBJECT (src, "item %d, type %d, len %d, data %s", j,
656 more_items = gst_rtcp_packet_sdes_next_item (&packet);
659 more_chunks = gst_rtcp_packet_sdes_next_chunk (&packet);
664 case GST_RTCP_TYPE_BYE:
669 reason = gst_rtcp_packet_bye_get_reason (&packet);
670 GST_DEBUG_OBJECT (src, "got BYE packet (reason: %s)",
671 GST_STR_NULL (reason));
674 count = gst_rtcp_packet_bye_get_ssrc_count (&packet);
675 for (i = 0; i < count; i++) {
679 ssrc = gst_rtcp_packet_bye_get_nth_ssrc (&packet, i);
681 GST_DEBUG_OBJECT (src, "SSRC: %08x", ssrc);
685 case GST_RTCP_TYPE_APP:
686 GST_DEBUG_OBJECT (src, "got APP packet");
689 GST_WARNING_OBJECT (src, "got unknown RTCP packet");
692 more = gst_rtcp_packet_move_to_next (&packet);
694 gst_buffer_unref (buffer);
699 GST_WARNING_OBJECT (src, "got invalid RTCP packet");
700 gst_buffer_unref (buffer);
704 gst_buffer_unref (buffer);
710 gst_rtp_dec_set_property (GObject * object, guint prop_id,
711 const GValue * value, GParamSpec * pspec)
715 src = GST_RTP_DEC (object);
719 src->latency = g_value_get_uint (value);
722 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
728 gst_rtp_dec_get_property (GObject * object, guint prop_id, GValue * value,
733 src = GST_RTP_DEC (object);
737 g_value_set_uint (value, src->latency);
740 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
746 gst_rtp_dec_provide_clock (GstElement * element)
750 rtpdec = GST_RTP_DEC (element);
752 return GST_CLOCK_CAST (gst_object_ref (rtpdec->provided_clock));
755 static GstStateChangeReturn
756 gst_rtp_dec_change_state (GstElement * element, GstStateChange transition)
758 GstStateChangeReturn ret;
760 switch (transition) {
765 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
767 switch (transition) {
768 case GST_STATE_CHANGE_READY_TO_PAUSED:
769 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
770 /* we're NO_PREROLL when going to PAUSED */
771 ret = GST_STATE_CHANGE_NO_PREROLL;
780 /* Create a pad for receiving RTP for the session in @name
783 create_recv_rtp (GstRTPDec * rtpdec, GstPadTemplate * templ, const gchar * name)
786 GstRTPDecSession *session;
788 /* first get the session number */
789 if (name == NULL || sscanf (name, "recv_rtp_sink_%d", &sessid) != 1)
792 GST_DEBUG_OBJECT (rtpdec, "finding session %d", sessid);
794 /* get or create session */
795 session = find_session_by_id (rtpdec, sessid);
797 GST_DEBUG_OBJECT (rtpdec, "creating session %d", sessid);
798 /* create session now */
799 session = create_session (rtpdec, sessid);
803 /* check if pad was requested */
804 if (session->recv_rtp_sink != NULL)
807 GST_DEBUG_OBJECT (rtpdec, "getting RTP sink pad");
809 session->recv_rtp_sink = gst_pad_new_from_template (templ, name);
810 gst_pad_set_element_private (session->recv_rtp_sink, session);
811 gst_pad_set_chain_function (session->recv_rtp_sink, gst_rtp_dec_chain_rtp);
812 gst_pad_set_active (session->recv_rtp_sink, TRUE);
813 gst_element_add_pad (GST_ELEMENT_CAST (rtpdec), session->recv_rtp_sink);
815 return session->recv_rtp_sink;
820 g_warning ("rtpdec: invalid name given");
825 /* create_session already warned */
830 g_warning ("rtpdec: recv_rtp pad already requested for session %d", sessid);
835 /* Create a pad for receiving RTCP for the session in @name
838 create_recv_rtcp (GstRTPDec * rtpdec, GstPadTemplate * templ,
842 GstRTPDecSession *session;
844 /* first get the session number */
845 if (name == NULL || sscanf (name, "recv_rtcp_sink_%d", &sessid) != 1)
848 GST_DEBUG_OBJECT (rtpdec, "finding session %d", sessid);
850 /* get the session, it must exist or we error */
851 session = find_session_by_id (rtpdec, sessid);
855 /* check if pad was requested */
856 if (session->recv_rtcp_sink != NULL)
859 GST_DEBUG_OBJECT (rtpdec, "getting RTCP sink pad");
861 session->recv_rtcp_sink = gst_pad_new_from_template (templ, name);
862 gst_pad_set_element_private (session->recv_rtp_sink, session);
863 gst_pad_set_chain_function (session->recv_rtcp_sink, gst_rtp_dec_chain_rtcp);
864 gst_pad_set_active (session->recv_rtcp_sink, TRUE);
865 gst_element_add_pad (GST_ELEMENT_CAST (rtpdec), session->recv_rtcp_sink);
867 return session->recv_rtcp_sink;
872 g_warning ("rtpdec: invalid name given");
877 g_warning ("rtpdec: no session with id %d", sessid);
882 g_warning ("rtpdec: recv_rtcp pad already requested for session %d",
888 /* Create a pad for sending RTCP for the session in @name
891 create_rtcp (GstRTPDec * rtpdec, GstPadTemplate * templ, const gchar * name)
894 GstRTPDecSession *session;
896 /* first get the session number */
897 if (name == NULL || sscanf (name, "rtcp_src_%d", &sessid) != 1)
900 /* get or create session */
901 session = find_session_by_id (rtpdec, sessid);
905 /* check if pad was requested */
906 if (session->rtcp_src != NULL)
909 session->rtcp_src = gst_pad_new_from_template (templ, name);
910 gst_pad_set_active (session->rtcp_src, TRUE);
911 gst_element_add_pad (GST_ELEMENT_CAST (rtpdec), session->rtcp_src);
913 return session->rtcp_src;
918 g_warning ("rtpdec: invalid name given");
923 g_warning ("rtpdec: session with id %d does not exist", sessid);
928 g_warning ("rtpdec: rtcp_src pad already requested for session %d", sessid);
936 gst_rtp_dec_request_new_pad (GstElement * element,
937 GstPadTemplate * templ, const gchar * name)
940 GstElementClass *klass;
943 g_return_val_if_fail (templ != NULL, NULL);
944 g_return_val_if_fail (GST_IS_RTP_DEC (element), NULL);
946 rtpdec = GST_RTP_DEC (element);
947 klass = GST_ELEMENT_GET_CLASS (element);
949 /* figure out the template */
950 if (templ == gst_element_class_get_pad_template (klass, "recv_rtp_sink_%d")) {
951 result = create_recv_rtp (rtpdec, templ, name);
952 } else if (templ == gst_element_class_get_pad_template (klass,
953 "recv_rtcp_sink_%d")) {
954 result = create_recv_rtcp (rtpdec, templ, name);
955 } else if (templ == gst_element_class_get_pad_template (klass, "rtcp_src_%d")) {
956 result = create_rtcp (rtpdec, templ, name);
965 g_warning ("rtpdec: this is not our template");
971 gst_rtp_dec_release_pad (GstElement * element, GstPad * pad)