2 * Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
3 * Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:gstrtpbasedepayload
23 * @short_description: Base class for RTP depayloader
25 * Provides a base class for RTP depayloaders
28 #include "gstrtpbasedepayload.h"
30 GST_DEBUG_CATEGORY_STATIC (rtpbasedepayload_debug);
31 #define GST_CAT_DEFAULT (rtpbasedepayload_debug)
33 #define GST_RTP_BASE_DEPAYLOAD_GET_PRIVATE(obj) \
34 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_RTP_BASE_DEPAYLOAD, GstRTPBaseDepayloadPrivate))
36 struct _GstRTPBaseDepayloadPrivate
38 GstClockTime npt_start;
39 GstClockTime npt_stop;
47 GstClockTime duration;
56 GstEvent *segment_event;
59 /* Filter signals and args */
73 static void gst_rtp_base_depayload_finalize (GObject * object);
74 static void gst_rtp_base_depayload_set_property (GObject * object,
75 guint prop_id, const GValue * value, GParamSpec * pspec);
76 static void gst_rtp_base_depayload_get_property (GObject * object,
77 guint prop_id, GValue * value, GParamSpec * pspec);
79 static GstFlowReturn gst_rtp_base_depayload_chain (GstPad * pad,
80 GstObject * parent, GstBuffer * in);
81 static GstFlowReturn gst_rtp_base_depayload_chain_list (GstPad * pad,
82 GstObject * parent, GstBufferList * list);
83 static gboolean gst_rtp_base_depayload_handle_sink_event (GstPad * pad,
84 GstObject * parent, GstEvent * event);
86 static GstStateChangeReturn gst_rtp_base_depayload_change_state (GstElement *
87 element, GstStateChange transition);
89 static gboolean gst_rtp_base_depayload_packet_lost (GstRTPBaseDepayload *
90 filter, GstEvent * event);
91 static gboolean gst_rtp_base_depayload_handle_event (GstRTPBaseDepayload *
92 filter, GstEvent * event);
94 static GstElementClass *parent_class = NULL;
95 static void gst_rtp_base_depayload_class_init (GstRTPBaseDepayloadClass *
97 static void gst_rtp_base_depayload_init (GstRTPBaseDepayload * rtpbasepayload,
98 GstRTPBaseDepayloadClass * klass);
99 static GstEvent *create_segment_event (GstRTPBaseDepayload * filter,
100 guint rtptime, GstClockTime position);
103 gst_rtp_base_depayload_get_type (void)
105 static GType rtp_base_depayload_type = 0;
107 if (g_once_init_enter ((gsize *) & rtp_base_depayload_type)) {
108 static const GTypeInfo rtp_base_depayload_info = {
109 sizeof (GstRTPBaseDepayloadClass),
112 (GClassInitFunc) gst_rtp_base_depayload_class_init,
115 sizeof (GstRTPBaseDepayload),
117 (GInstanceInitFunc) gst_rtp_base_depayload_init,
120 g_once_init_leave ((gsize *) & rtp_base_depayload_type,
121 g_type_register_static (GST_TYPE_ELEMENT, "GstRTPBaseDepayload",
122 &rtp_base_depayload_info, G_TYPE_FLAG_ABSTRACT));
124 return rtp_base_depayload_type;
128 gst_rtp_base_depayload_class_init (GstRTPBaseDepayloadClass * klass)
130 GObjectClass *gobject_class;
131 GstElementClass *gstelement_class;
133 gobject_class = G_OBJECT_CLASS (klass);
134 gstelement_class = (GstElementClass *) klass;
135 parent_class = g_type_class_peek_parent (klass);
137 g_type_class_add_private (klass, sizeof (GstRTPBaseDepayloadPrivate));
139 gobject_class->finalize = gst_rtp_base_depayload_finalize;
140 gobject_class->set_property = gst_rtp_base_depayload_set_property;
141 gobject_class->get_property = gst_rtp_base_depayload_get_property;
145 * GstRTPBaseDepayload:stats:
147 * Various depayloader statistics retrieved atomically (and are therefore
148 * synchroized with each other). This property return a GstStructure named
149 * application/x-rtp-depayload-stats containing the following fields relating to
150 * the last processed buffer and current state of the stream being depayloaded:
154 * <term>clock-rate</term>
155 * <listitem><para>#G_TYPE_UINT, clock-rate of the
156 * stream</para></listitem>
159 * <term>npt-start</term>
160 * <listitem><para>#G_TYPE_UINT64, time of playback start
164 * <term>npt-stop</term>
165 * <listitem><para>#G_TYPE_UINT64, time of playback stop
169 * <term>play-speed</term>
170 * <listitem><para>#G_TYPE_DOUBLE, the playback speed
174 * <term>play-scale</term>
175 * <listitem><para>#G_TYPE_DOUBLE, the playback scale
179 * <term>running-time-dts</term>
180 * <listitem><para>#G_TYPE_UINT64, the last running-time of the
185 * <term>running-time-pts</term>
186 * <listitem><para>#G_TYPE_UINT64, the last running-time of the
191 * <term>seqnum</term>
192 * <listitem><para>#G_TYPE_UINT, the last seen seqnum
196 * <term>timestamp</term>
197 * <listitem><para>#G_TYPE_UINT, the last seen RTP timestamp
202 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_STATS,
203 g_param_spec_boxed ("stats", "Statistics", "Various statistics",
204 GST_TYPE_STRUCTURE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
206 gstelement_class->change_state = gst_rtp_base_depayload_change_state;
208 klass->packet_lost = gst_rtp_base_depayload_packet_lost;
209 klass->handle_event = gst_rtp_base_depayload_handle_event;
211 GST_DEBUG_CATEGORY_INIT (rtpbasedepayload_debug, "rtpbasedepayload", 0,
212 "Base class for RTP Depayloaders");
216 gst_rtp_base_depayload_init (GstRTPBaseDepayload * filter,
217 GstRTPBaseDepayloadClass * klass)
219 GstPadTemplate *pad_template;
220 GstRTPBaseDepayloadPrivate *priv;
222 priv = GST_RTP_BASE_DEPAYLOAD_GET_PRIVATE (filter);
225 GST_DEBUG_OBJECT (filter, "init");
228 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
229 g_return_if_fail (pad_template != NULL);
230 filter->sinkpad = gst_pad_new_from_template (pad_template, "sink");
231 gst_pad_set_chain_function (filter->sinkpad, gst_rtp_base_depayload_chain);
232 gst_pad_set_chain_list_function (filter->sinkpad,
233 gst_rtp_base_depayload_chain_list);
234 gst_pad_set_event_function (filter->sinkpad,
235 gst_rtp_base_depayload_handle_sink_event);
236 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
239 gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
240 g_return_if_fail (pad_template != NULL);
241 filter->srcpad = gst_pad_new_from_template (pad_template, "src");
242 gst_pad_use_fixed_caps (filter->srcpad);
243 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
247 priv->play_speed = 1.0;
248 priv->play_scale = 1.0;
249 priv->clock_base = -1;
254 gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
258 gst_rtp_base_depayload_finalize (GObject * object)
260 G_OBJECT_CLASS (parent_class)->finalize (object);
264 gst_rtp_base_depayload_setcaps (GstRTPBaseDepayload * filter, GstCaps * caps)
266 GstRTPBaseDepayloadClass *bclass;
267 GstRTPBaseDepayloadPrivate *priv;
269 GstStructure *caps_struct;
274 bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
276 GST_DEBUG_OBJECT (filter, "Set caps %" GST_PTR_FORMAT, caps);
278 if (priv->last_caps) {
279 if (gst_caps_is_equal (priv->last_caps, caps)) {
281 goto caps_not_changed;
283 gst_caps_unref (priv->last_caps);
284 priv->last_caps = NULL;
288 caps_struct = gst_caps_get_structure (caps, 0);
290 /* get other values for newsegment */
291 value = gst_structure_get_value (caps_struct, "npt-start");
292 if (value && G_VALUE_HOLDS_UINT64 (value))
293 priv->npt_start = g_value_get_uint64 (value);
296 GST_DEBUG_OBJECT (filter, "NPT start %" G_GUINT64_FORMAT, priv->npt_start);
298 value = gst_structure_get_value (caps_struct, "npt-stop");
299 if (value && G_VALUE_HOLDS_UINT64 (value))
300 priv->npt_stop = g_value_get_uint64 (value);
304 GST_DEBUG_OBJECT (filter, "NPT stop %" G_GUINT64_FORMAT, priv->npt_stop);
306 value = gst_structure_get_value (caps_struct, "play-speed");
307 if (value && G_VALUE_HOLDS_DOUBLE (value))
308 priv->play_speed = g_value_get_double (value);
310 priv->play_speed = 1.0;
312 value = gst_structure_get_value (caps_struct, "play-scale");
313 if (value && G_VALUE_HOLDS_DOUBLE (value))
314 priv->play_scale = g_value_get_double (value);
316 priv->play_scale = 1.0;
318 value = gst_structure_get_value (caps_struct, "clock-base");
319 if (value && G_VALUE_HOLDS_UINT (value))
320 priv->clock_base = g_value_get_uint (value);
322 priv->clock_base = -1;
324 if (bclass->set_caps) {
325 res = bclass->set_caps (filter, caps);
327 GST_WARNING_OBJECT (filter, "Subclass rejected caps %" GST_PTR_FORMAT,
334 priv->negotiated = res;
336 if (priv->negotiated)
337 priv->last_caps = gst_caps_ref (caps);
343 GST_DEBUG_OBJECT (filter, "Caps did not change");
349 gst_rtp_base_depayload_handle_buffer (GstRTPBaseDepayload * filter,
350 GstRTPBaseDepayloadClass * bclass, GstBuffer * in)
352 GstBuffer *(*process_rtp_packet_func) (GstRTPBaseDepayload * base,
353 GstRTPBuffer * rtp_buffer);
354 GstBuffer *(*process_func) (GstRTPBaseDepayload * base, GstBuffer * in);
355 GstRTPBaseDepayloadPrivate *priv;
356 GstFlowReturn ret = GST_FLOW_OK;
358 GstClockTime pts, dts;
361 gboolean discont, buf_discont;
363 GstRTPBuffer rtp = { NULL };
367 process_func = bclass->process;
368 process_rtp_packet_func = bclass->process_rtp_packet;
370 /* we must have a setcaps first */
371 if (G_UNLIKELY (!priv->negotiated))
374 if (G_UNLIKELY (!gst_rtp_buffer_map (in, GST_MAP_READ, &rtp)))
377 buf_discont = GST_BUFFER_IS_DISCONT (in);
379 pts = GST_BUFFER_PTS (in);
380 dts = GST_BUFFER_DTS (in);
381 /* convert to running_time and save the timestamp, this is the timestamp
382 * we put on outgoing buffers. */
383 pts = gst_segment_to_running_time (&filter->segment, GST_FORMAT_TIME, pts);
384 dts = gst_segment_to_running_time (&filter->segment, GST_FORMAT_TIME, dts);
387 priv->duration = GST_BUFFER_DURATION (in);
389 seqnum = gst_rtp_buffer_get_seq (&rtp);
390 rtptime = gst_rtp_buffer_get_timestamp (&rtp);
392 priv->last_seqnum = seqnum;
393 priv->last_rtptime = rtptime;
395 discont = buf_discont;
397 GST_LOG_OBJECT (filter, "discont %d, seqnum %u, rtptime %u, pts %"
398 GST_TIME_FORMAT ", dts %" GST_TIME_FORMAT, buf_discont, seqnum, rtptime,
399 GST_TIME_ARGS (pts), GST_TIME_ARGS (dts));
401 /* Check seqnum. This is a very simple check that makes sure that the seqnums
402 * are strictly increasing, dropping anything that is out of the ordinary. We
403 * can only do this when the next_seqnum is known. */
404 if (G_LIKELY (priv->next_seqnum != -1)) {
405 gap = gst_rtp_buffer_compare_seqnum (seqnum, priv->next_seqnum);
407 /* if we have no gap, all is fine */
408 if (G_UNLIKELY (gap != 0)) {
409 GST_LOG_OBJECT (filter, "got packet %u, expected %u, gap %d", seqnum,
410 priv->next_seqnum, gap);
412 /* seqnum > next_seqnum, we are missing some packets, this is always a
414 GST_LOG_OBJECT (filter, "%d missing packets", gap);
417 /* seqnum < next_seqnum, we have seen this packet before or the sender
418 * could be restarted. If the packet is not too old, we throw it away as
419 * a duplicate, otherwise we mark discont and continue. 100 misordered
420 * packets is a good threshold. See also RFC 4737. */
424 GST_LOG_OBJECT (filter,
425 "%d > 100, packet too old, sender likely restarted", gap);
430 priv->next_seqnum = (seqnum + 1) & 0xffff;
432 if (G_UNLIKELY (discont)) {
433 priv->discont = TRUE;
435 /* we detected a seqnum discont but the buffer was not flagged with a discont,
436 * set the discont flag so that the subclass can throw away old data. */
437 GST_LOG_OBJECT (filter, "mark DISCONT on input buffer");
438 in = gst_buffer_make_writable (in);
439 GST_BUFFER_FLAG_SET (in, GST_BUFFER_FLAG_DISCONT);
443 /* prepare segment event if needed */
444 if (filter->need_newsegment) {
445 priv->segment_event = create_segment_event (filter, rtptime,
446 GST_BUFFER_PTS (in));
447 filter->need_newsegment = FALSE;
450 if (process_rtp_packet_func != NULL) {
451 out_buf = process_rtp_packet_func (filter, &rtp);
452 gst_rtp_buffer_unmap (&rtp);
453 } else if (process_func != NULL) {
454 gst_rtp_buffer_unmap (&rtp);
455 out_buf = process_func (filter, in);
460 /* let's send it out to processing */
462 ret = gst_rtp_base_depayload_push (filter, out_buf);
470 /* this is not fatal but should be filtered earlier */
471 GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
472 ("No RTP format was negotiated."),
473 ("Input buffers need to have RTP caps set on them. This is usually "
474 "achieved by setting the 'caps' property of the upstream source "
475 "element (often udpsrc or appsrc), or by putting a capsfilter "
476 "element before the depayloader and setting the 'caps' property "
477 "on that. Also see http://cgit.freedesktop.org/gstreamer/"
478 "gst-plugins-good/tree/gst/rtp/README"));
479 return GST_FLOW_NOT_NEGOTIATED;
483 /* this is not fatal but should be filtered earlier */
484 GST_ELEMENT_WARNING (filter, STREAM, DECODE, (NULL),
485 ("Received invalid RTP payload, dropping"));
490 gst_rtp_buffer_unmap (&rtp);
491 GST_WARNING_OBJECT (filter, "%d <= 100, dropping old packet", gap);
496 gst_rtp_buffer_unmap (&rtp);
497 /* this is not fatal but should be filtered earlier */
498 GST_ELEMENT_ERROR (filter, STREAM, NOT_IMPLEMENTED, (NULL),
499 ("The subclass does not have a process or process_rtp_packet method"));
500 return GST_FLOW_ERROR;
505 gst_rtp_base_depayload_chain (GstPad * pad, GstObject * parent, GstBuffer * in)
507 GstRTPBaseDepayloadClass *bclass;
508 GstRTPBaseDepayload *basedepay;
509 GstFlowReturn flow_ret;
511 basedepay = GST_RTP_BASE_DEPAYLOAD_CAST (parent);
513 bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (basedepay);
515 flow_ret = gst_rtp_base_depayload_handle_buffer (basedepay, bclass, in);
517 gst_buffer_unref (in);
523 gst_rtp_base_depayload_chain_list (GstPad * pad, GstObject * parent,
524 GstBufferList * list)
526 GstRTPBaseDepayloadClass *bclass;
527 GstRTPBaseDepayload *basedepay;
528 GstFlowReturn flow_ret;
532 basedepay = GST_RTP_BASE_DEPAYLOAD_CAST (parent);
534 bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (basedepay);
536 flow_ret = GST_FLOW_OK;
538 /* chain each buffer in list individually */
539 len = gst_buffer_list_length (list);
544 for (i = 0; i < len; i++) {
545 buffer = gst_buffer_list_get (list, i);
547 /* Should we fix up any missing timestamps for list buffers here
548 * (e.g. set to first or previous timestamp in list) or just assume
549 * the's a jitterbuffer that will have done that for us? */
550 flow_ret = gst_rtp_base_depayload_handle_buffer (basedepay, bclass, buffer);
551 if (flow_ret != GST_FLOW_OK)
557 gst_buffer_list_unref (list);
563 gst_rtp_base_depayload_handle_event (GstRTPBaseDepayload * filter,
567 gboolean forward = TRUE;
569 switch (GST_EVENT_TYPE (event)) {
570 case GST_EVENT_FLUSH_STOP:
571 gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
572 filter->need_newsegment = TRUE;
573 filter->priv->next_seqnum = -1;
574 gst_event_replace (&filter->priv->segment_event, NULL);
580 gst_event_parse_caps (event, &caps);
582 res = gst_rtp_base_depayload_setcaps (filter, caps);
586 case GST_EVENT_SEGMENT:
588 gst_event_copy_segment (event, &filter->segment);
589 /* don't pass the event downstream, we generate our own segment including
590 * the NTP time and other things we receive in caps */
594 case GST_EVENT_CUSTOM_DOWNSTREAM:
596 GstRTPBaseDepayloadClass *bclass;
598 bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
600 if (gst_event_has_name (event, "GstRTPPacketLost")) {
601 /* we get this event from the jitterbuffer when it considers a packet as
602 * being lost. We send it to our packet_lost vmethod. The default
603 * implementation will make time progress by pushing out a GAP event.
604 * Subclasses can override and do one of the following:
605 * - Adjust timestamp/duration to something more accurate before
606 * calling the parent (default) packet_lost method.
607 * - do some more advanced error concealing on the already received
608 * (fragmented) packets.
609 * - ignore the packet lost.
611 if (bclass->packet_lost)
612 res = bclass->packet_lost (filter, event);
622 res = gst_pad_push_event (filter->srcpad, event);
624 gst_event_unref (event);
630 gst_rtp_base_depayload_handle_sink_event (GstPad * pad, GstObject * parent,
633 gboolean res = FALSE;
634 GstRTPBaseDepayload *filter;
635 GstRTPBaseDepayloadClass *bclass;
637 filter = GST_RTP_BASE_DEPAYLOAD (parent);
638 bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
639 if (bclass->handle_event)
640 res = bclass->handle_event (filter, event);
642 gst_event_unref (event);
648 create_segment_event (GstRTPBaseDepayload * filter, guint rtptime,
649 GstClockTime position)
652 GstClockTime start, stop, running_time;
653 GstRTPBaseDepayloadPrivate *priv;
658 /* determining the start of the segment */
659 start = filter->segment.start;
660 if (priv->clock_base != -1 && position != -1) {
661 GstClockTime exttime, gap;
663 exttime = priv->clock_base;
664 gst_rtp_buffer_ext_timestamp (&exttime, rtptime);
665 gap = gst_util_uint64_scale_int (exttime - priv->clock_base,
666 filter->clock_rate, GST_SECOND);
668 /* account for lost packets */
669 if (position > gap) {
670 GST_DEBUG_OBJECT (filter,
671 "Found gap of %" GST_TIME_FORMAT ", adjusting start: %"
672 GST_TIME_FORMAT " = %" GST_TIME_FORMAT " - %" GST_TIME_FORMAT,
673 GST_TIME_ARGS (gap), GST_TIME_ARGS (position - gap),
674 GST_TIME_ARGS (position), GST_TIME_ARGS (gap));
675 start = position - gap;
679 /* determining the stop of the segment */
680 stop = filter->segment.stop;
681 if (priv->npt_stop != -1)
682 stop = start + (priv->npt_stop - priv->npt_start);
687 running_time = gst_segment_to_running_time (&filter->segment,
688 GST_FORMAT_TIME, start);
690 gst_segment_init (&segment, GST_FORMAT_TIME);
691 segment.rate = priv->play_speed;
692 segment.applied_rate = priv->play_scale;
693 segment.start = start;
695 segment.time = priv->npt_start;
696 segment.position = position;
697 segment.base = running_time;
699 GST_DEBUG_OBJECT (filter, "Creating segment event %" GST_SEGMENT_FORMAT,
701 event = gst_event_new_segment (&segment);
708 GstRTPBaseDepayload *depayload;
709 GstRTPBaseDepayloadClass *bclass;
713 set_headers (GstBuffer ** buffer, guint idx, HeaderData * data)
715 GstRTPBaseDepayload *depayload = data->depayload;
716 GstRTPBaseDepayloadPrivate *priv = depayload->priv;
717 GstClockTime pts, dts, duration;
719 *buffer = gst_buffer_make_writable (*buffer);
721 pts = GST_BUFFER_PTS (*buffer);
722 dts = GST_BUFFER_DTS (*buffer);
723 duration = GST_BUFFER_DURATION (*buffer);
725 /* apply last incomming timestamp and duration to outgoing buffer if
726 * not otherwise set. */
727 if (!GST_CLOCK_TIME_IS_VALID (pts))
728 GST_BUFFER_PTS (*buffer) = priv->pts;
729 if (!GST_CLOCK_TIME_IS_VALID (dts))
730 GST_BUFFER_DTS (*buffer) = priv->dts;
731 if (!GST_CLOCK_TIME_IS_VALID (duration))
732 GST_BUFFER_DURATION (*buffer) = priv->duration;
734 if (G_UNLIKELY (depayload->priv->discont)) {
735 GST_LOG_OBJECT (depayload, "Marking DISCONT on output buffer");
736 GST_BUFFER_FLAG_SET (*buffer, GST_BUFFER_FLAG_DISCONT);
737 depayload->priv->discont = FALSE;
740 /* make sure we only set the timestamp on the first packet */
741 priv->pts = GST_CLOCK_TIME_NONE;
742 priv->dts = GST_CLOCK_TIME_NONE;
743 priv->duration = GST_CLOCK_TIME_NONE;
749 gst_rtp_base_depayload_prepare_push (GstRTPBaseDepayload * filter,
750 gboolean is_list, gpointer obj)
754 data.depayload = filter;
755 data.bclass = GST_RTP_BASE_DEPAYLOAD_GET_CLASS (filter);
758 GstBufferList **blist = obj;
759 gst_buffer_list_foreach (*blist, (GstBufferListFunc) set_headers, &data);
761 GstBuffer **buf = obj;
762 set_headers (buf, 0, &data);
765 /* if this is the first buffer send a NEWSEGMENT */
766 if (G_UNLIKELY (filter->priv->segment_event)) {
767 gst_pad_push_event (filter->srcpad, filter->priv->segment_event);
768 filter->priv->segment_event = NULL;
769 GST_DEBUG_OBJECT (filter, "Pushed newsegment event on this first buffer");
776 * gst_rtp_base_depayload_push:
777 * @filter: a #GstRTPBaseDepayload
778 * @out_buf: a #GstBuffer
780 * Push @out_buf to the peer of @filter. This function takes ownership of
783 * This function will by default apply the last incomming timestamp on
784 * the outgoing buffer when it didn't have a timestamp already.
786 * Returns: a #GstFlowReturn.
789 gst_rtp_base_depayload_push (GstRTPBaseDepayload * filter, GstBuffer * out_buf)
793 res = gst_rtp_base_depayload_prepare_push (filter, FALSE, &out_buf);
795 if (G_LIKELY (res == GST_FLOW_OK))
796 res = gst_pad_push (filter->srcpad, out_buf);
798 gst_buffer_unref (out_buf);
804 * gst_rtp_base_depayload_push_list:
805 * @filter: a #GstRTPBaseDepayload
806 * @out_list: a #GstBufferList
808 * Push @out_list to the peer of @filter. This function takes ownership of
811 * Returns: a #GstFlowReturn.
814 gst_rtp_base_depayload_push_list (GstRTPBaseDepayload * filter,
815 GstBufferList * out_list)
819 res = gst_rtp_base_depayload_prepare_push (filter, TRUE, &out_list);
821 if (G_LIKELY (res == GST_FLOW_OK))
822 res = gst_pad_push_list (filter->srcpad, out_list);
824 gst_buffer_list_unref (out_list);
829 /* convert the PacketLost event from a jitterbuffer to a GAP event.
830 * subclasses can override this. */
832 gst_rtp_base_depayload_packet_lost (GstRTPBaseDepayload * filter,
835 GstClockTime timestamp, duration;
837 const GstStructure *s;
839 s = gst_event_get_structure (event);
841 /* first start by parsing the timestamp and duration */
845 gst_structure_get_clock_time (s, "timestamp", ×tamp);
846 gst_structure_get_clock_time (s, "duration", &duration);
849 sevent = gst_event_new_gap (timestamp, duration);
851 return gst_pad_push_event (filter->srcpad, sevent);
854 static GstStateChangeReturn
855 gst_rtp_base_depayload_change_state (GstElement * element,
856 GstStateChange transition)
858 GstRTPBaseDepayload *filter;
859 GstRTPBaseDepayloadPrivate *priv;
860 GstStateChangeReturn ret;
862 filter = GST_RTP_BASE_DEPAYLOAD (element);
865 switch (transition) {
866 case GST_STATE_CHANGE_NULL_TO_READY:
868 case GST_STATE_CHANGE_READY_TO_PAUSED:
869 filter->need_newsegment = TRUE;
872 priv->play_speed = 1.0;
873 priv->play_scale = 1.0;
874 priv->clock_base = -1;
875 priv->next_seqnum = -1;
876 priv->negotiated = FALSE;
877 priv->discont = FALSE;
879 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
885 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
887 switch (transition) {
888 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
890 case GST_STATE_CHANGE_PAUSED_TO_READY:
891 gst_caps_replace (&priv->last_caps, NULL);
892 gst_event_replace (&priv->segment_event, NULL);
894 case GST_STATE_CHANGE_READY_TO_NULL:
902 static GstStructure *
903 gst_rtp_base_depayload_create_stats (GstRTPBaseDepayload * depayload)
905 GstRTPBaseDepayloadPrivate *priv;
908 priv = depayload->priv;
910 s = gst_structure_new ("application/x-rtp-depayload-stats",
911 "clock_rate", G_TYPE_UINT, depayload->clock_rate,
912 "npt-start", G_TYPE_UINT64, priv->npt_start,
913 "npt-stop", G_TYPE_UINT64, priv->npt_stop,
914 "play-speed", G_TYPE_DOUBLE, priv->play_speed,
915 "play-scale", G_TYPE_DOUBLE, priv->play_scale,
916 "running-time-dts", G_TYPE_UINT64, priv->dts,
917 "running-time-pts", G_TYPE_UINT64, priv->pts,
918 "seqnum", G_TYPE_UINT, (guint) priv->last_seqnum,
919 "timestamp", G_TYPE_UINT, (guint) priv->last_rtptime, NULL);
926 gst_rtp_base_depayload_set_property (GObject * object, guint prop_id,
927 const GValue * value, GParamSpec * pspec)
931 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
937 gst_rtp_base_depayload_get_property (GObject * object, guint prop_id,
938 GValue * value, GParamSpec * pspec)
940 GstRTPBaseDepayload *depayload;
942 depayload = GST_RTP_BASE_DEPAYLOAD (object);
946 g_value_take_boxed (value,
947 gst_rtp_base_depayload_create_stats (depayload));
950 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);