Initialize Tizen 2.3
[framework/multimedia/gst-plugins-base0.10.git] / gst-libs / gst / rtp / gstbasertpdepayload.c
1 /* GStreamer
2  * Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
3  * Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
4  *
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.
9  *
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.
14  *
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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * SECTION:gstbasertpdepayload
23  * @short_description: Base class for RTP depayloader
24  *
25  * Provides a base class for RTP depayloaders
26  */
27
28 #include "gstbasertpdepayload.h"
29
30 #ifdef GST_DISABLE_DEPRECATED
31 #define QUEUE_LOCK_INIT(base)   (g_static_rec_mutex_init(&base->queuelock))
32 #define QUEUE_LOCK_FREE(base)   (g_static_rec_mutex_free(&base->queuelock))
33 #define QUEUE_LOCK(base)        (g_static_rec_mutex_lock(&base->queuelock))
34 #define QUEUE_UNLOCK(base)      (g_static_rec_mutex_unlock(&base->queuelock))
35 #else
36 /* otherwise it's already been defined in the header (FIXME 0.11)*/
37 #endif
38
39 GST_DEBUG_CATEGORY_STATIC (basertpdepayload_debug);
40 #define GST_CAT_DEFAULT (basertpdepayload_debug)
41
42 #define GST_BASE_RTP_DEPAYLOAD_GET_PRIVATE(obj)  \
43    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_BASE_RTP_DEPAYLOAD, GstBaseRTPDepayloadPrivate))
44
45 struct _GstBaseRTPDepayloadPrivate
46 {
47   GstClockTime npt_start;
48   GstClockTime npt_stop;
49   gdouble play_speed;
50   gdouble play_scale;
51
52   gboolean discont;
53   GstClockTime timestamp;
54   GstClockTime duration;
55
56   guint32 next_seqnum;
57
58   gboolean negotiated;
59 };
60
61 /* Filter signals and args */
62 enum
63 {
64   /* FILL ME */
65   LAST_SIGNAL
66 };
67
68 #define DEFAULT_QUEUE_DELAY     0
69
70 enum
71 {
72   PROP_0,
73   PROP_QUEUE_DELAY,
74   PROP_LAST
75 };
76
77 static void gst_base_rtp_depayload_finalize (GObject * object);
78 static void gst_base_rtp_depayload_set_property (GObject * object,
79     guint prop_id, const GValue * value, GParamSpec * pspec);
80 static void gst_base_rtp_depayload_get_property (GObject * object,
81     guint prop_id, GValue * value, GParamSpec * pspec);
82
83 static gboolean gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps);
84 static GstFlowReturn gst_base_rtp_depayload_chain (GstPad * pad,
85     GstBuffer * in);
86 static gboolean gst_base_rtp_depayload_handle_sink_event (GstPad * pad,
87     GstEvent * event);
88
89 static GstStateChangeReturn gst_base_rtp_depayload_change_state (GstElement *
90     element, GstStateChange transition);
91
92 static void gst_base_rtp_depayload_set_gst_timestamp
93     (GstBaseRTPDepayload * filter, guint32 rtptime, GstBuffer * buf);
94 static gboolean gst_base_rtp_depayload_packet_lost (GstBaseRTPDepayload *
95     filter, GstEvent * event);
96 static gboolean gst_base_rtp_depayload_handle_event (GstBaseRTPDepayload *
97     filter, GstEvent * event);
98
99 GST_BOILERPLATE (GstBaseRTPDepayload, gst_base_rtp_depayload, GstElement,
100     GST_TYPE_ELEMENT);
101
102 static void
103 gst_base_rtp_depayload_base_init (gpointer klass)
104 {
105   /*GstElementClass *element_class = GST_ELEMENT_CLASS (klass); */
106 }
107
108 static void
109 gst_base_rtp_depayload_class_init (GstBaseRTPDepayloadClass * klass)
110 {
111   GObjectClass *gobject_class;
112   GstElementClass *gstelement_class;
113
114   gobject_class = G_OBJECT_CLASS (klass);
115   gstelement_class = (GstElementClass *) klass;
116   parent_class = g_type_class_peek_parent (klass);
117
118   g_type_class_add_private (klass, sizeof (GstBaseRTPDepayloadPrivate));
119
120   gobject_class->finalize = gst_base_rtp_depayload_finalize;
121   gobject_class->set_property = gst_base_rtp_depayload_set_property;
122   gobject_class->get_property = gst_base_rtp_depayload_get_property;
123
124   /**
125    * GstBaseRTPDepayload::queue-delay
126    *
127    * Control the amount of packets to buffer.
128    *
129    * Deprecated: Use a jitterbuffer or RTP session manager to delay packet
130    * playback. This property has no effect anymore since 0.10.15.
131    */
132 #ifndef GST_REMOVE_DEPRECATED
133   g_object_class_install_property (gobject_class, PROP_QUEUE_DELAY,
134       g_param_spec_uint ("queue-delay", "Queue Delay",
135           "Amount of ms to queue/buffer, deprecated", 0, G_MAXUINT,
136           DEFAULT_QUEUE_DELAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
137 #endif
138
139   gstelement_class->change_state = gst_base_rtp_depayload_change_state;
140
141   klass->set_gst_timestamp = gst_base_rtp_depayload_set_gst_timestamp;
142   klass->packet_lost = gst_base_rtp_depayload_packet_lost;
143   klass->handle_event = gst_base_rtp_depayload_handle_event;
144
145   GST_DEBUG_CATEGORY_INIT (basertpdepayload_debug, "basertpdepayload", 0,
146       "Base class for RTP Depayloaders");
147 }
148
149 static void
150 gst_base_rtp_depayload_init (GstBaseRTPDepayload * filter,
151     GstBaseRTPDepayloadClass * klass)
152 {
153   GstPadTemplate *pad_template;
154   GstBaseRTPDepayloadPrivate *priv;
155
156   priv = GST_BASE_RTP_DEPAYLOAD_GET_PRIVATE (filter);
157   filter->priv = priv;
158
159   GST_DEBUG_OBJECT (filter, "init");
160
161   pad_template =
162       gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "sink");
163   g_return_if_fail (pad_template != NULL);
164   filter->sinkpad = gst_pad_new_from_template (pad_template, "sink");
165   gst_pad_set_setcaps_function (filter->sinkpad,
166       gst_base_rtp_depayload_setcaps);
167   gst_pad_set_chain_function (filter->sinkpad, gst_base_rtp_depayload_chain);
168   gst_pad_set_event_function (filter->sinkpad,
169       gst_base_rtp_depayload_handle_sink_event);
170   gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
171
172   pad_template =
173       gst_element_class_get_pad_template (GST_ELEMENT_CLASS (klass), "src");
174   g_return_if_fail (pad_template != NULL);
175   filter->srcpad = gst_pad_new_from_template (pad_template, "src");
176   gst_pad_use_fixed_caps (filter->srcpad);
177   gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
178
179   filter->queue = g_queue_new ();
180   filter->queue_delay = DEFAULT_QUEUE_DELAY;
181
182   gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
183 }
184
185 static void
186 gst_base_rtp_depayload_finalize (GObject * object)
187 {
188   GstBaseRTPDepayload *filter = GST_BASE_RTP_DEPAYLOAD (object);
189
190   g_queue_free (filter->queue);
191
192   G_OBJECT_CLASS (parent_class)->finalize (object);
193 }
194
195 static gboolean
196 gst_base_rtp_depayload_setcaps (GstPad * pad, GstCaps * caps)
197 {
198   GstBaseRTPDepayload *filter;
199   GstBaseRTPDepayloadClass *bclass;
200   GstBaseRTPDepayloadPrivate *priv;
201   gboolean res;
202   GstStructure *caps_struct;
203   const GValue *value;
204
205   filter = GST_BASE_RTP_DEPAYLOAD (gst_pad_get_parent (pad));
206   priv = filter->priv;
207
208   bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
209
210   GST_DEBUG_OBJECT (filter, "Set caps");
211
212   caps_struct = gst_caps_get_structure (caps, 0);
213
214   /* get other values for newsegment */
215   value = gst_structure_get_value (caps_struct, "npt-start");
216   if (value && G_VALUE_HOLDS_UINT64 (value))
217     priv->npt_start = g_value_get_uint64 (value);
218   else
219     priv->npt_start = 0;
220   GST_DEBUG_OBJECT (filter, "NPT start %" G_GUINT64_FORMAT, priv->npt_start);
221
222   value = gst_structure_get_value (caps_struct, "npt-stop");
223   if (value && G_VALUE_HOLDS_UINT64 (value))
224     priv->npt_stop = g_value_get_uint64 (value);
225   else
226     priv->npt_stop = -1;
227
228   GST_DEBUG_OBJECT (filter, "NPT stop %" G_GUINT64_FORMAT, priv->npt_stop);
229
230   value = gst_structure_get_value (caps_struct, "play-speed");
231   if (value && G_VALUE_HOLDS_DOUBLE (value))
232     priv->play_speed = g_value_get_double (value);
233   else
234     priv->play_speed = 1.0;
235
236   value = gst_structure_get_value (caps_struct, "play-scale");
237   if (value && G_VALUE_HOLDS_DOUBLE (value))
238     priv->play_scale = g_value_get_double (value);
239   else
240     priv->play_scale = 1.0;
241
242   if (bclass->set_caps) {
243     res = bclass->set_caps (filter, caps);
244     if (!res) {
245       GST_WARNING_OBJECT (filter, "Subclass rejected caps %" GST_PTR_FORMAT,
246           caps);
247     }
248   } else {
249     res = TRUE;
250   }
251
252   priv->negotiated = res;
253
254   gst_object_unref (filter);
255
256   return res;
257 }
258
259 static GstFlowReturn
260 gst_base_rtp_depayload_chain (GstPad * pad, GstBuffer * in)
261 {
262   GstBaseRTPDepayload *filter;
263   GstBaseRTPDepayloadPrivate *priv;
264   GstBaseRTPDepayloadClass *bclass;
265   GstFlowReturn ret = GST_FLOW_OK;
266   GstBuffer *out_buf;
267   GstClockTime timestamp;
268   guint16 seqnum;
269   guint32 rtptime;
270   gboolean discont;
271   gint gap;
272
273   filter = GST_BASE_RTP_DEPAYLOAD (GST_OBJECT_PARENT (pad));
274   priv = filter->priv;
275
276   /* we must have a setcaps first */
277   if (G_UNLIKELY (!priv->negotiated))
278     goto not_negotiated;
279
280   /* we must validate, it's possible that this element is plugged right after a
281    * network receiver and we don't want to operate on invalid data */
282   if (G_UNLIKELY (!gst_rtp_buffer_validate (in)))
283     goto invalid_buffer;
284
285   if (!priv->discont)
286     priv->discont = GST_BUFFER_IS_DISCONT (in);
287
288   timestamp = GST_BUFFER_TIMESTAMP (in);
289   /* convert to running_time and save the timestamp, this is the timestamp
290    * we put on outgoing buffers. */
291   timestamp = gst_segment_to_running_time (&filter->segment, GST_FORMAT_TIME,
292       timestamp);
293   priv->timestamp = timestamp;
294   priv->duration = GST_BUFFER_DURATION (in);
295
296   seqnum = gst_rtp_buffer_get_seq (in);
297   rtptime = gst_rtp_buffer_get_timestamp (in);
298   discont = FALSE;
299
300   GST_LOG_OBJECT (filter, "discont %d, seqnum %u, rtptime %u, timestamp %"
301       GST_TIME_FORMAT, priv->discont, seqnum, rtptime,
302       GST_TIME_ARGS (timestamp));
303
304   /* Check seqnum. This is a very simple check that makes sure that the seqnums
305    * are striclty increasing, dropping anything that is out of the ordinary. We
306    * can only do this when the next_seqnum is known. */
307   if (G_LIKELY (priv->next_seqnum != -1)) {
308     gap = gst_rtp_buffer_compare_seqnum (seqnum, priv->next_seqnum);
309
310     /* if we have no gap, all is fine */
311     if (G_UNLIKELY (gap != 0)) {
312       GST_LOG_OBJECT (filter, "got packet %u, expected %u, gap %d", seqnum,
313           priv->next_seqnum, gap);
314       if (gap < 0) {
315         /* seqnum > next_seqnum, we are missing some packets, this is always a
316          * DISCONT. */
317         GST_LOG_OBJECT (filter, "%d missing packets", gap);
318         discont = TRUE;
319       } else {
320         /* seqnum < next_seqnum, we have seen this packet before or the sender
321          * could be restarted. If the packet is not too old, we throw it away as
322          * a duplicate, otherwise we mark discont and continue. 100 misordered
323          * packets is a good threshold. See also RFC 4737. */
324         if (gap < 100)
325           goto dropping;
326
327         GST_LOG_OBJECT (filter,
328             "%d > 100, packet too old, sender likely restarted", gap);
329         discont = TRUE;
330       }
331     }
332   }
333   priv->next_seqnum = (seqnum + 1) & 0xffff;
334
335   if (G_UNLIKELY (discont && !priv->discont)) {
336     GST_LOG_OBJECT (filter, "mark DISCONT on input buffer");
337     /* we detected a seqnum discont but the buffer was not flagged with a discont,
338      * set the discont flag so that the subclass can throw away old data. */
339     priv->discont = TRUE;
340     in = gst_buffer_make_metadata_writable (in);
341     GST_BUFFER_FLAG_SET (in, GST_BUFFER_FLAG_DISCONT);
342   }
343
344   bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
345
346   if (G_UNLIKELY (bclass->process == NULL))
347     goto no_process;
348
349   /* let's send it out to processing */
350   out_buf = bclass->process (filter, in);
351   if (out_buf) {
352     /* we pass rtptime as backward compatibility, in reality, the incomming
353      * buffer timestamp is always applied to the outgoing packet. */
354     ret = gst_base_rtp_depayload_push_ts (filter, rtptime, out_buf);
355   }
356   gst_buffer_unref (in);
357
358   return ret;
359
360   /* ERRORS */
361 not_negotiated:
362   {
363     /* this is not fatal but should be filtered earlier */
364     if (GST_BUFFER_CAPS (in) == NULL) {
365       GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
366           ("No RTP format was negotiated."),
367           ("Input buffers need to have RTP caps set on them. This is usually "
368               "achieved by setting the 'caps' property of the upstream source "
369               "element (often udpsrc or appsrc), or by putting a capsfilter "
370               "element before the depayloader and setting the 'caps' property "
371               "on that. Also see http://cgit.freedesktop.org/gstreamer/"
372               "gst-plugins-good/tree/gst/rtp/README"));
373     } else {
374       GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
375           ("No RTP format was negotiated."),
376           ("RTP caps on input buffer were rejected, most likely because they "
377               "were incomplete or contained wrong values. Check the debug log "
378               "for more information."));
379     }
380     gst_buffer_unref (in);
381     return GST_FLOW_NOT_NEGOTIATED;
382   }
383 invalid_buffer:
384   {
385     /* this is not fatal but should be filtered earlier */
386     GST_ELEMENT_WARNING (filter, STREAM, DECODE, (NULL),
387         ("Received invalid RTP payload, dropping"));
388     gst_buffer_unref (in);
389     return GST_FLOW_OK;
390   }
391 dropping:
392   {
393     GST_WARNING_OBJECT (filter, "%d <= 100, dropping old packet", gap);
394     gst_buffer_unref (in);
395     return GST_FLOW_OK;
396   }
397 no_process:
398   {
399     /* this is not fatal but should be filtered earlier */
400     GST_ELEMENT_ERROR (filter, STREAM, NOT_IMPLEMENTED, (NULL),
401         ("The subclass does not have a process method"));
402     gst_buffer_unref (in);
403     return GST_FLOW_ERROR;
404   }
405 }
406
407 static gboolean
408 gst_base_rtp_depayload_handle_event (GstBaseRTPDepayload * filter,
409     GstEvent * event)
410 {
411   gboolean res = TRUE;
412   gboolean forward = TRUE;
413
414   switch (GST_EVENT_TYPE (event)) {
415     case GST_EVENT_FLUSH_STOP:
416       gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
417       filter->need_newsegment = TRUE;
418       filter->priv->next_seqnum = -1;
419       break;
420     case GST_EVENT_NEWSEGMENT:
421     {
422       gboolean update;
423       gdouble rate;
424       GstFormat fmt;
425       gint64 start, stop, position;
426
427       gst_event_parse_new_segment (event, &update, &rate, &fmt, &start, &stop,
428           &position);
429
430       gst_segment_set_newsegment (&filter->segment, update, rate, fmt,
431           start, stop, position);
432
433       /* don't pass the event downstream, we generate our own segment including
434        * the NTP time and other things we receive in caps */
435       forward = FALSE;
436       break;
437     }
438     case GST_EVENT_CUSTOM_DOWNSTREAM:
439     {
440       GstBaseRTPDepayloadClass *bclass;
441
442       bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
443
444       if (gst_event_has_name (event, "GstRTPPacketLost")) {
445         /* we get this event from the jitterbuffer when it considers a packet as
446          * being lost. We send it to our packet_lost vmethod. The default
447          * implementation will make time progress by pushing out a NEWSEGMENT
448          * update event. Subclasses can override and to one of the following:
449          *  - Adjust timestamp/duration to something more accurate before
450          *    calling the parent (default) packet_lost method.
451          *  - do some more advanced error concealing on the already received
452          *    (fragmented) packets.
453          *  - ignore the packet lost.
454          */
455         if (bclass->packet_lost)
456           res = bclass->packet_lost (filter, event);
457         forward = FALSE;
458       }
459       break;
460     }
461     default:
462       break;
463   }
464
465   if (forward)
466     res = gst_pad_push_event (filter->srcpad, event);
467   else
468     gst_event_unref (event);
469
470   return res;
471 }
472
473 static gboolean
474 gst_base_rtp_depayload_handle_sink_event (GstPad * pad, GstEvent * event)
475 {
476   gboolean res = FALSE;
477   GstBaseRTPDepayload *filter;
478   GstBaseRTPDepayloadClass *bclass;
479
480   filter = GST_BASE_RTP_DEPAYLOAD (gst_pad_get_parent (pad));
481   if (G_UNLIKELY (filter == NULL)) {
482     gst_event_unref (event);
483     return FALSE;
484   }
485
486   bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
487   if (bclass->handle_event)
488     res = bclass->handle_event (filter, event);
489   else
490     gst_event_unref (event);
491
492   gst_object_unref (filter);
493   return res;
494 }
495
496 static GstEvent *
497 create_segment_event (GstBaseRTPDepayload * filter, gboolean update,
498     GstClockTime position)
499 {
500   GstEvent *event;
501   GstClockTime stop;
502   GstBaseRTPDepayloadPrivate *priv;
503
504   priv = filter->priv;
505
506   if (priv->npt_stop != -1)
507     stop = priv->npt_stop - priv->npt_start;
508   else
509     stop = -1;
510
511   event = gst_event_new_new_segment_full (update, priv->play_speed,
512       priv->play_scale, GST_FORMAT_TIME, position, stop,
513       position + priv->npt_start);
514
515   return event;
516 }
517
518 typedef struct
519 {
520   GstBaseRTPDepayload *depayload;
521   GstBaseRTPDepayloadClass *bclass;
522   GstCaps *caps;
523   gboolean do_ts;
524   gboolean rtptime;
525 } HeaderData;
526
527 static GstBufferListItem
528 set_headers (GstBuffer ** buffer, guint group, guint idx, HeaderData * data)
529 {
530   GstBaseRTPDepayload *depayload = data->depayload;
531
532   *buffer = gst_buffer_make_metadata_writable (*buffer);
533   gst_buffer_set_caps (*buffer, data->caps);
534
535   /* set the timestamp if we must and can */
536   if (data->bclass->set_gst_timestamp && data->do_ts)
537     data->bclass->set_gst_timestamp (depayload, data->rtptime, *buffer);
538
539   if (G_UNLIKELY (depayload->priv->discont)) {
540     GST_LOG_OBJECT (depayload, "Marking DISCONT on output buffer");
541     GST_BUFFER_FLAG_SET (*buffer, GST_BUFFER_FLAG_DISCONT);
542     depayload->priv->discont = FALSE;
543   }
544
545   return GST_BUFFER_LIST_SKIP_GROUP;
546 }
547
548 static GstFlowReturn
549 gst_base_rtp_depayload_prepare_push (GstBaseRTPDepayload * filter,
550     gboolean do_ts, guint32 rtptime, gboolean is_list, gpointer obj)
551 {
552   HeaderData data;
553
554   data.depayload = filter;
555   data.caps = GST_PAD_CAPS (filter->srcpad);
556   data.rtptime = rtptime;
557   data.do_ts = do_ts;
558   data.bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
559
560   if (is_list) {
561     GstBufferList **blist = obj;
562     gst_buffer_list_foreach (*blist, (GstBufferListFunc) set_headers, &data);
563   } else {
564     GstBuffer **buf = obj;
565     set_headers (buf, 0, 0, &data);
566   }
567
568   /* if this is the first buffer send a NEWSEGMENT */
569   if (G_UNLIKELY (filter->need_newsegment)) {
570     GstEvent *event;
571
572     event = create_segment_event (filter, FALSE, 0);
573
574     gst_pad_push_event (filter->srcpad, event);
575
576     filter->need_newsegment = FALSE;
577     GST_DEBUG_OBJECT (filter, "Pushed newsegment event on this first buffer");
578   }
579
580   return GST_FLOW_OK;
581 }
582
583 /**
584  * gst_base_rtp_depayload_push_ts:
585  * @filter: a #GstBaseRTPDepayload
586  * @timestamp: an RTP timestamp to apply
587  * @out_buf: a #GstBuffer
588  *
589  * Push @out_buf to the peer of @filter. This function takes ownership of
590  * @out_buf.
591  *
592  * Unlike gst_base_rtp_depayload_push(), this function will by default apply
593  * the last incomming timestamp on the outgoing buffer when it didn't have a
594  * timestamp already. The set_get_timestamp vmethod can be overwritten to change
595  * this behaviour (and take, for example, @timestamp into account).
596  *
597  * Returns: a #GstFlowReturn.
598  */
599 GstFlowReturn
600 gst_base_rtp_depayload_push_ts (GstBaseRTPDepayload * filter, guint32 timestamp,
601     GstBuffer * out_buf)
602 {
603   GstFlowReturn res;
604
605   res =
606       gst_base_rtp_depayload_prepare_push (filter, TRUE, timestamp, FALSE,
607       &out_buf);
608
609   if (G_LIKELY (res == GST_FLOW_OK))
610     res = gst_pad_push (filter->srcpad, out_buf);
611   else
612     gst_buffer_unref (out_buf);
613
614   return res;
615 }
616
617 /**
618  * gst_base_rtp_depayload_push:
619  * @filter: a #GstBaseRTPDepayload
620  * @out_buf: a #GstBuffer
621  *
622  * Push @out_buf to the peer of @filter. This function takes ownership of
623  * @out_buf.
624  *
625  * Unlike gst_base_rtp_depayload_push_ts(), this function will not apply
626  * any timestamp on the outgoing buffer. Subclasses should therefore timestamp
627  * outgoing buffers themselves.
628  *
629  * Returns: a #GstFlowReturn.
630  */
631 GstFlowReturn
632 gst_base_rtp_depayload_push (GstBaseRTPDepayload * filter, GstBuffer * out_buf)
633 {
634   GstFlowReturn res;
635
636   res = gst_base_rtp_depayload_prepare_push (filter, FALSE, 0, FALSE, &out_buf);
637
638   if (G_LIKELY (res == GST_FLOW_OK))
639     res = gst_pad_push (filter->srcpad, out_buf);
640   else
641     gst_buffer_unref (out_buf);
642
643   return res;
644 }
645
646 /**
647  * gst_base_rtp_depayload_push_list:
648  * @filter: a #GstBaseRTPDepayload
649  * @out_list: a #GstBufferList
650  *
651  * Push @out_list to the peer of @filter. This function takes ownership of
652  * @out_list.
653  *
654  * Returns: a #GstFlowReturn.
655  *
656  * Since: 0.10.32
657  */
658 GstFlowReturn
659 gst_base_rtp_depayload_push_list (GstBaseRTPDepayload * filter,
660     GstBufferList * out_list)
661 {
662   GstFlowReturn res;
663
664   res = gst_base_rtp_depayload_prepare_push (filter, TRUE, 0, TRUE, &out_list);
665
666   if (G_LIKELY (res == GST_FLOW_OK))
667     res = gst_pad_push_list (filter->srcpad, out_list);
668   else
669     gst_buffer_list_unref (out_list);
670
671   return res;
672 }
673
674 /* convert the PacketLost event form a jitterbuffer to a segment update.
675  * subclasses can override this.  */
676 static gboolean
677 gst_base_rtp_depayload_packet_lost (GstBaseRTPDepayload * filter,
678     GstEvent * event)
679 {
680   GstClockTime timestamp, duration, position;
681   GstEvent *sevent;
682   const GstStructure *s;
683
684   s = gst_event_get_structure (event);
685
686   /* first start by parsing the timestamp and duration */
687   timestamp = -1;
688   duration = -1;
689
690   gst_structure_get_clock_time (s, "timestamp", &timestamp);
691   gst_structure_get_clock_time (s, "duration", &duration);
692
693   position = timestamp;
694   if (duration != -1)
695     position += duration;
696
697   /* update the current segment with the elapsed time */
698   sevent = create_segment_event (filter, TRUE, position);
699
700   return gst_pad_push_event (filter->srcpad, sevent);
701 }
702
703 static void
704 gst_base_rtp_depayload_set_gst_timestamp (GstBaseRTPDepayload * filter,
705     guint32 rtptime, GstBuffer * buf)
706 {
707   GstBaseRTPDepayloadPrivate *priv;
708   GstClockTime timestamp, duration;
709
710   priv = filter->priv;
711
712   timestamp = GST_BUFFER_TIMESTAMP (buf);
713   duration = GST_BUFFER_DURATION (buf);
714
715   /* apply last incomming timestamp and duration to outgoing buffer if
716    * not otherwise set. */
717   if (!GST_CLOCK_TIME_IS_VALID (timestamp))
718     GST_BUFFER_TIMESTAMP (buf) = priv->timestamp;
719   if (!GST_CLOCK_TIME_IS_VALID (duration))
720     GST_BUFFER_DURATION (buf) = priv->duration;
721 }
722
723 static GstStateChangeReturn
724 gst_base_rtp_depayload_change_state (GstElement * element,
725     GstStateChange transition)
726 {
727   GstBaseRTPDepayload *filter;
728   GstBaseRTPDepayloadPrivate *priv;
729   GstStateChangeReturn ret;
730
731   filter = GST_BASE_RTP_DEPAYLOAD (element);
732   priv = filter->priv;
733
734   switch (transition) {
735     case GST_STATE_CHANGE_NULL_TO_READY:
736       break;
737     case GST_STATE_CHANGE_READY_TO_PAUSED:
738       filter->need_newsegment = TRUE;
739       priv->npt_start = 0;
740       priv->npt_stop = -1;
741       priv->play_speed = 1.0;
742       priv->play_scale = 1.0;
743       priv->next_seqnum = -1;
744       priv->negotiated = FALSE;
745       priv->discont = FALSE;
746       break;
747     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
748       break;
749     default:
750       break;
751   }
752
753   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
754
755   switch (transition) {
756     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
757       break;
758     case GST_STATE_CHANGE_PAUSED_TO_READY:
759       break;
760     case GST_STATE_CHANGE_READY_TO_NULL:
761       break;
762     default:
763       break;
764   }
765   return ret;
766 }
767
768 static void
769 gst_base_rtp_depayload_set_property (GObject * object, guint prop_id,
770     const GValue * value, GParamSpec * pspec)
771 {
772   GstBaseRTPDepayload *filter;
773
774   filter = GST_BASE_RTP_DEPAYLOAD (object);
775
776   switch (prop_id) {
777     case PROP_QUEUE_DELAY:
778       filter->queue_delay = g_value_get_uint (value);
779       break;
780     default:
781       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
782       break;
783   }
784 }
785
786 static void
787 gst_base_rtp_depayload_get_property (GObject * object, guint prop_id,
788     GValue * value, GParamSpec * pspec)
789 {
790   GstBaseRTPDepayload *filter;
791
792   filter = GST_BASE_RTP_DEPAYLOAD (object);
793
794   switch (prop_id) {
795     case PROP_QUEUE_DELAY:
796       g_value_set_uint (value, filter->queue_delay);
797       break;
798     default:
799       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
800       break;
801   }
802 }