2 * Copyright (C) <2005> Wim Taymans <wim.taymans@gmail.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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
26 #include <gst/rtp/gstrtpbuffer.h>
28 #include "gstrtpmp4gdepay.h"
30 GST_DEBUG_CATEGORY_STATIC (rtpmp4gdepay_debug);
31 #define GST_CAT_DEFAULT (rtpmp4gdepay_debug)
33 static GstStaticPadTemplate gst_rtp_mp4g_depay_src_template =
34 GST_STATIC_PAD_TEMPLATE ("src",
37 GST_STATIC_CAPS ("video/mpeg,"
38 "mpegversion=(int) 4,"
39 "systemstream=(boolean)false;"
40 "audio/mpeg," "mpegversion=(int) 4, " "stream-format=(string)raw")
43 static GstStaticPadTemplate gst_rtp_mp4g_depay_sink_template =
44 GST_STATIC_PAD_TEMPLATE ("sink",
47 GST_STATIC_CAPS ("application/x-rtp, "
48 "media = (string) { \"video\", \"audio\", \"application\" }, "
49 "clock-rate = (int) [1, MAX ], "
50 "encoding-name = (string) \"MPEG4-GENERIC\", "
51 /* required string params */
52 /* "streamtype = (string) { \"4\", \"5\" }, " Not set by Wowza 4 = video, 5 = audio */
53 /* "profile-level-id = (string) [1,MAX], " */
54 /* "config = (string) [1,MAX]" */
55 "mode = (string) { \"generic\", \"CELP-cbr\", \"CELP-vbr\", \"AAC-lbr\", \"AAC-hbr\" } "
56 /* Optional general parameters */
57 /* "objecttype = (string) [1,MAX], " */
58 /* "constantsize = (string) [1,MAX], " *//* constant size of each AU */
59 /* "constantduration = (string) [1,MAX], " *//* constant duration of each AU */
60 /* "maxdisplacement = (string) [1,MAX], " */
61 /* "de-interleavebuffersize = (string) [1,MAX], " */
62 /* Optional configuration parameters */
63 /* "sizelength = (string) [1, 32], " */
64 /* "indexlength = (string) [1, 32], " */
65 /* "indexdeltalength = (string) [1, 32], " */
66 /* "ctsdeltalength = (string) [1, 32], " */
67 /* "dtsdeltalength = (string) [1, 32], " */
68 /* "randomaccessindication = (string) {0, 1}, " */
69 /* "streamstateindication = (string) [0, 32], " */
70 /* "auxiliarydatasizelength = (string) [0, 32]" */ )
73 /* simple bitstream parser */
78 gint head; /* bitpos in the cache of next bit */
79 guint64 cache; /* cached bytes */
83 gst_bs_parse_init (GstBsParse * bs, const guint8 * data, guint size)
86 bs->end = data + size;
88 bs->cache = 0xffffffff;
92 gst_bs_parse_read (GstBsParse * bs, guint n)
100 /* fill up the cache if we need to */
101 while (bs->head < n) {
102 if (bs->data >= bs->end) {
103 /* we're at the end, can't produce more than head number of bits */
107 /* shift bytes in cache, moving the head bits of the cache left */
108 bs->cache = (bs->cache << 8) | *bs->data++;
112 /* bring the required bits down and truncate */
113 if ((shift = bs->head - n) > 0)
114 res = bs->cache >> shift;
118 /* mask out required bits */
128 #define gst_rtp_mp4g_depay_parent_class parent_class
129 G_DEFINE_TYPE (GstRtpMP4GDepay, gst_rtp_mp4g_depay,
130 GST_TYPE_RTP_BASE_DEPAYLOAD);
132 static void gst_rtp_mp4g_depay_finalize (GObject * object);
134 static gboolean gst_rtp_mp4g_depay_setcaps (GstRTPBaseDepayload * depayload,
136 static GstBuffer *gst_rtp_mp4g_depay_process (GstRTPBaseDepayload * depayload,
138 static gboolean gst_rtp_mp4g_depay_handle_event (GstRTPBaseDepayload * filter,
141 static GstStateChangeReturn gst_rtp_mp4g_depay_change_state (GstElement *
142 element, GstStateChange transition);
146 gst_rtp_mp4g_depay_class_init (GstRtpMP4GDepayClass * klass)
148 GObjectClass *gobject_class;
149 GstElementClass *gstelement_class;
150 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
152 gobject_class = (GObjectClass *) klass;
153 gstelement_class = (GstElementClass *) klass;
154 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
156 gobject_class->finalize = gst_rtp_mp4g_depay_finalize;
158 gstelement_class->change_state = gst_rtp_mp4g_depay_change_state;
160 gstrtpbasedepayload_class->process = gst_rtp_mp4g_depay_process;
161 gstrtpbasedepayload_class->set_caps = gst_rtp_mp4g_depay_setcaps;
162 gstrtpbasedepayload_class->handle_event = gst_rtp_mp4g_depay_handle_event;
164 gst_element_class_add_pad_template (gstelement_class,
165 gst_static_pad_template_get (&gst_rtp_mp4g_depay_src_template));
166 gst_element_class_add_pad_template (gstelement_class,
167 gst_static_pad_template_get (&gst_rtp_mp4g_depay_sink_template));
169 gst_element_class_set_static_metadata (gstelement_class,
170 "RTP MPEG4 ES depayloader", "Codec/Depayloader/Network/RTP",
171 "Extracts MPEG4 elementary streams from RTP packets (RFC 3640)",
172 "Wim Taymans <wim.taymans@gmail.com>");
174 GST_DEBUG_CATEGORY_INIT (rtpmp4gdepay_debug, "rtpmp4gdepay", 0,
175 "MP4-generic RTP Depayloader");
179 gst_rtp_mp4g_depay_init (GstRtpMP4GDepay * rtpmp4gdepay)
181 rtpmp4gdepay->adapter = gst_adapter_new ();
182 rtpmp4gdepay->packets = g_queue_new ();
186 gst_rtp_mp4g_depay_finalize (GObject * object)
188 GstRtpMP4GDepay *rtpmp4gdepay;
190 rtpmp4gdepay = GST_RTP_MP4G_DEPAY (object);
192 g_object_unref (rtpmp4gdepay->adapter);
193 rtpmp4gdepay->adapter = NULL;
194 g_queue_free (rtpmp4gdepay->packets);
195 rtpmp4gdepay->packets = NULL;
197 G_OBJECT_CLASS (parent_class)->finalize (object);
201 gst_rtp_mp4g_depay_parse_int (GstStructure * structure, const gchar * field,
207 if ((str = gst_structure_get_string (structure, field)))
210 if (gst_structure_get_int (structure, field, &res))
217 gst_rtp_mp4g_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
219 GstStructure *structure;
220 GstRtpMP4GDepay *rtpmp4gdepay;
221 GstCaps *srccaps = NULL;
227 rtpmp4gdepay = GST_RTP_MP4G_DEPAY (depayload);
229 structure = gst_caps_get_structure (caps, 0);
231 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
232 clock_rate = 90000; /* default */
233 depayload->clock_rate = clock_rate;
235 if ((str = gst_structure_get_string (structure, "media"))) {
236 if (strcmp (str, "audio") == 0) {
237 srccaps = gst_caps_new_simple ("audio/mpeg",
238 "mpegversion", G_TYPE_INT, 4, "stream-format", G_TYPE_STRING, "raw",
240 } else if (strcmp (str, "video") == 0) {
241 srccaps = gst_caps_new_simple ("video/mpeg",
242 "mpegversion", G_TYPE_INT, 4,
243 "systemstream", G_TYPE_BOOLEAN, FALSE, NULL);
249 /* these values are optional and have a default value of 0 (no header) */
250 rtpmp4gdepay->sizelength =
251 gst_rtp_mp4g_depay_parse_int (structure, "sizelength", 0);
252 rtpmp4gdepay->indexlength =
253 gst_rtp_mp4g_depay_parse_int (structure, "indexlength", 0);
254 rtpmp4gdepay->indexdeltalength =
255 gst_rtp_mp4g_depay_parse_int (structure, "indexdeltalength", 0);
256 rtpmp4gdepay->ctsdeltalength =
257 gst_rtp_mp4g_depay_parse_int (structure, "ctsdeltalength", 0);
258 rtpmp4gdepay->dtsdeltalength =
259 gst_rtp_mp4g_depay_parse_int (structure, "dtsdeltalength", 0);
261 gst_rtp_mp4g_depay_parse_int (structure, "randomaccessindication", 0);
262 rtpmp4gdepay->randomaccessindication = someint > 0 ? 1 : 0;
263 rtpmp4gdepay->streamstateindication =
264 gst_rtp_mp4g_depay_parse_int (structure, "streamstateindication", 0);
265 rtpmp4gdepay->auxiliarydatasizelength =
266 gst_rtp_mp4g_depay_parse_int (structure, "auxiliarydatasizelength", 0);
267 rtpmp4gdepay->constantSize =
268 gst_rtp_mp4g_depay_parse_int (structure, "constantsize", 0);
269 rtpmp4gdepay->constantDuration =
270 gst_rtp_mp4g_depay_parse_int (structure, "constantduration", 0);
271 rtpmp4gdepay->maxDisplacement =
272 gst_rtp_mp4g_depay_parse_int (structure, "maxdisplacement", 0);
275 /* get config string */
276 if ((str = gst_structure_get_string (structure, "config"))) {
279 g_value_init (&v, GST_TYPE_BUFFER);
280 if (gst_value_deserialize (&v, str)) {
283 buffer = gst_value_get_buffer (&v);
284 gst_caps_set_simple (srccaps,
285 "codec_data", GST_TYPE_BUFFER, buffer, NULL);
288 g_warning ("cannot convert config to buffer");
292 res = gst_pad_set_caps (depayload->srcpad, srccaps);
293 gst_caps_unref (srccaps);
300 GST_DEBUG_OBJECT (rtpmp4gdepay, "Unknown media type");
306 gst_rtp_mp4g_depay_clear_queue (GstRtpMP4GDepay * rtpmp4gdepay)
310 while ((outbuf = g_queue_pop_head (rtpmp4gdepay->packets)))
311 gst_buffer_unref (outbuf);
315 gst_rtp_mp4g_depay_reset (GstRtpMP4GDepay * rtpmp4gdepay)
317 gst_adapter_clear (rtpmp4gdepay->adapter);
318 rtpmp4gdepay->max_AU_index = -1;
319 rtpmp4gdepay->next_AU_index = -1;
320 rtpmp4gdepay->prev_AU_index = -1;
321 rtpmp4gdepay->prev_rtptime = -1;
322 rtpmp4gdepay->last_AU_index = -1;
323 gst_rtp_mp4g_depay_clear_queue (rtpmp4gdepay);
327 gst_rtp_mp4g_depay_flush_queue (GstRtpMP4GDepay * rtpmp4gdepay)
330 gboolean discont = FALSE;
333 while ((outbuf = g_queue_pop_head (rtpmp4gdepay->packets))) {
334 AU_index = GST_BUFFER_OFFSET (outbuf);
336 GST_DEBUG_OBJECT (rtpmp4gdepay, "next available AU_index %u", AU_index);
338 if (rtpmp4gdepay->next_AU_index != AU_index) {
339 GST_DEBUG_OBJECT (rtpmp4gdepay, "discont, expected AU_index %u",
340 rtpmp4gdepay->next_AU_index);
345 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
349 GST_DEBUG_OBJECT (rtpmp4gdepay, "pushing AU_index %u", AU_index);
350 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtpmp4gdepay), outbuf);
351 rtpmp4gdepay->next_AU_index = AU_index + 1;
356 gst_rtp_mp4g_depay_queue (GstRtpMP4GDepay * rtpmp4gdepay, GstBuffer * outbuf)
358 guint AU_index = GST_BUFFER_OFFSET (outbuf);
360 if (rtpmp4gdepay->next_AU_index == -1) {
361 GST_DEBUG_OBJECT (rtpmp4gdepay, "Init AU counter %u", AU_index);
362 rtpmp4gdepay->next_AU_index = AU_index;
365 if (rtpmp4gdepay->next_AU_index == AU_index) {
366 GST_DEBUG_OBJECT (rtpmp4gdepay, "pushing expected AU_index %u", AU_index);
368 /* we received the expected packet, push it and flush as much as we can from
370 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtpmp4gdepay), outbuf);
371 rtpmp4gdepay->next_AU_index++;
373 while ((outbuf = g_queue_peek_head (rtpmp4gdepay->packets))) {
374 AU_index = GST_BUFFER_OFFSET (outbuf);
376 GST_DEBUG_OBJECT (rtpmp4gdepay, "next available AU_index %u", AU_index);
378 if (rtpmp4gdepay->next_AU_index == AU_index) {
379 GST_DEBUG_OBJECT (rtpmp4gdepay, "pushing expected AU_index %u",
381 outbuf = g_queue_pop_head (rtpmp4gdepay->packets);
382 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtpmp4gdepay),
384 rtpmp4gdepay->next_AU_index++;
386 GST_DEBUG_OBJECT (rtpmp4gdepay, "waiting for next AU_index %u",
387 rtpmp4gdepay->next_AU_index);
394 GST_DEBUG_OBJECT (rtpmp4gdepay, "queueing AU_index %u", AU_index);
396 /* loop the list to skip strictly smaller AU_index buffers */
397 for (list = rtpmp4gdepay->packets->head; list; list = g_list_next (list)) {
401 idx = GST_BUFFER_OFFSET (GST_BUFFER_CAST (list->data));
403 /* compare the new seqnum to the one in the buffer */
404 gap = (gint) (idx - AU_index);
406 GST_DEBUG_OBJECT (rtpmp4gdepay, "compare with AU_index %u, gap %d", idx,
409 /* AU_index <= idx, we can stop looking */
410 if (G_LIKELY (gap > 0))
414 g_queue_insert_before (rtpmp4gdepay->packets, list, outbuf);
416 g_queue_push_tail (rtpmp4gdepay->packets, outbuf);
421 gst_rtp_mp4g_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
423 GstRtpMP4GDepay *rtpmp4gdepay;
424 GstBuffer *outbuf = NULL;
425 GstClockTime timestamp;
426 GstRTPBuffer rtp = { NULL };
428 rtpmp4gdepay = GST_RTP_MP4G_DEPAY (depayload);
430 /* flush remaining data on discont */
431 if (GST_BUFFER_IS_DISCONT (buf)) {
432 GST_DEBUG_OBJECT (rtpmp4gdepay, "received DISCONT");
433 gst_adapter_clear (rtpmp4gdepay->adapter);
436 timestamp = GST_BUFFER_TIMESTAMP (buf);
439 gint payload_len, payload_AU;
442 guint AU_headers_len;
443 guint AU_size, AU_index, AU_index_delta, payload_AU_size;
446 gst_rtp_buffer_map (buf, GST_MAP_READ, &rtp);
447 payload_len = gst_rtp_buffer_get_payload_len (&rtp);
448 payload = gst_rtp_buffer_get_payload (&rtp);
450 GST_DEBUG_OBJECT (rtpmp4gdepay, "received payload of %d", payload_len);
452 rtptime = gst_rtp_buffer_get_timestamp (&rtp);
453 M = gst_rtp_buffer_get_marker (&rtp);
455 if (rtpmp4gdepay->sizelength > 0) {
456 gint num_AU_headers, AU_headers_bytes, i;
462 /* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
463 * |AU-headers-length|AU-header|AU-header| |AU-header|padding|
464 * | | (1) | (2) | | (n) * | bits |
465 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- .. -+-+-+-+-+-+-+-+-+-+
467 * The length is 2 bytes and contains the length of the following
468 * AU-headers in bits.
470 AU_headers_len = (payload[0] << 8) | payload[1];
471 AU_headers_bytes = (AU_headers_len + 7) / 8;
472 num_AU_headers = AU_headers_len / 16;
474 GST_DEBUG_OBJECT (rtpmp4gdepay, "AU headers len %d, bytes %d, num %d",
475 AU_headers_len, AU_headers_bytes, num_AU_headers);
481 if (payload_len < AU_headers_bytes)
484 /* skip special headers, point to first payload AU */
485 payload_AU = 2 + AU_headers_bytes;
486 payload_AU_size = payload_len - AU_headers_bytes;
488 if (G_UNLIKELY (rtpmp4gdepay->auxiliarydatasizelength)) {
491 /* point the bitstream parser to the first auxiliary data bit */
492 gst_bs_parse_init (&bs, payload + AU_headers_bytes,
493 payload_len - AU_headers_bytes);
495 gst_bs_parse_read (&bs, rtpmp4gdepay->auxiliarydatasizelength);
496 /* convert to bytes */
497 aux_size = (aux_size + 7) / 8;
498 /* AU data then follows auxiliary data */
499 if (payload_AU_size < aux_size)
501 payload_AU += aux_size;
502 payload_AU_size -= aux_size;
505 /* point the bitstream parser to the first AU header bit */
506 gst_bs_parse_init (&bs, payload, payload_len);
507 AU_index = AU_index_delta = 0;
509 for (i = 0; i < num_AU_headers && payload_AU_size > 0; i++) {
511 * +---------------------------------------+
513 * +---------------------------------------+
514 * | AU-Index / AU-Index-delta |
515 * +---------------------------------------+
517 * +---------------------------------------+
519 * +---------------------------------------+
521 * +---------------------------------------+
523 * +---------------------------------------+
525 * +---------------------------------------+
527 * +---------------------------------------+
529 AU_size = gst_bs_parse_read (&bs, rtpmp4gdepay->sizelength);
531 /* calculate the AU_index, which is only on the first AU of the packet
532 * and the AU_index_delta on the other AUs. This will be used to
533 * reconstruct the AU ordering when interleaving. */
535 AU_index = gst_bs_parse_read (&bs, rtpmp4gdepay->indexlength);
537 GST_DEBUG_OBJECT (rtpmp4gdepay, "AU index %u", AU_index);
539 if (AU_index == 0 && rtpmp4gdepay->prev_AU_index == 0) {
543 /* if we see two consecutive packets with AU_index of 0, we can
544 * assume we have constantDuration packets. Since we don't have
545 * the index we must use the AU duration to calculate the
546 * index. Get the diff between the timestamps first, this can be
547 * positive or negative. */
548 if (rtpmp4gdepay->prev_rtptime <= rtptime)
549 diff = rtptime - rtpmp4gdepay->prev_rtptime;
551 diff = -(rtpmp4gdepay->prev_rtptime - rtptime);
553 /* if no constantDuration was given, make one */
554 if (rtpmp4gdepay->constantDuration != 0) {
555 cd = rtpmp4gdepay->constantDuration;
556 GST_DEBUG_OBJECT (depayload, "using constantDuration %d", cd);
557 } else if (rtpmp4gdepay->prev_AU_num > 0) {
558 /* use number of packets and of previous frame */
559 cd = diff / rtpmp4gdepay->prev_AU_num;
560 GST_DEBUG_OBJECT (depayload, "guessing constantDuration %d", cd);
562 /* assume this frame has the same number of packets as the
564 cd = diff / num_AU_headers;
565 GST_DEBUG_OBJECT (depayload, "guessing constantDuration %d", cd);
569 /* get the number of packets by dividing with the duration */
575 rtpmp4gdepay->last_AU_index += diff;
576 rtpmp4gdepay->prev_AU_index = AU_index;
578 AU_index = rtpmp4gdepay->last_AU_index;
580 GST_DEBUG_OBJECT (rtpmp4gdepay, "diff %d, AU index %u", diff,
583 rtpmp4gdepay->prev_AU_index = AU_index;
584 rtpmp4gdepay->last_AU_index = AU_index;
587 /* keep track of the higest AU_index */
588 if (rtpmp4gdepay->max_AU_index != -1
589 && rtpmp4gdepay->max_AU_index <= AU_index) {
590 GST_DEBUG_OBJECT (rtpmp4gdepay, "new interleave group, flushing");
591 /* a new interleave group started, flush */
592 gst_rtp_mp4g_depay_flush_queue (rtpmp4gdepay);
594 if (G_UNLIKELY (!rtpmp4gdepay->maxDisplacement &&
595 rtpmp4gdepay->max_AU_index != -1
596 && rtpmp4gdepay->max_AU_index >= AU_index)) {
599 /* some broken non-interleaved streams have AU-index jumping around
600 * all over the place, apparently assuming receiver disregards */
601 GST_DEBUG_OBJECT (rtpmp4gdepay, "non-interleaved broken AU indices;"
602 " forcing continuous flush");
603 /* reset AU to avoid repeated DISCONT in such case */
604 outbuf = g_queue_peek_head (rtpmp4gdepay->packets);
605 if (G_LIKELY (outbuf)) {
606 rtpmp4gdepay->next_AU_index = GST_BUFFER_OFFSET (outbuf);
607 gst_rtp_mp4g_depay_flush_queue (rtpmp4gdepay);
609 /* rebase next_AU_index to current rtp's first AU_index */
610 rtpmp4gdepay->next_AU_index = AU_index;
612 rtpmp4gdepay->prev_rtptime = rtptime;
613 rtpmp4gdepay->prev_AU_num = num_AU_headers;
616 gst_bs_parse_read (&bs, rtpmp4gdepay->indexdeltalength);
617 AU_index += AU_index_delta + 1;
619 /* keep track of highest AU_index */
620 if (rtpmp4gdepay->max_AU_index == -1
621 || AU_index > rtpmp4gdepay->max_AU_index)
622 rtpmp4gdepay->max_AU_index = AU_index;
624 /* the presentation time offset, a 2s-complement value, we need this to
625 * calculate the timestamp on the output packet. */
626 if (rtpmp4gdepay->ctsdeltalength > 0) {
627 if (gst_bs_parse_read (&bs, 1))
628 gst_bs_parse_read (&bs, rtpmp4gdepay->ctsdeltalength);
630 /* the decoding time offset, a 2s-complement value */
631 if (rtpmp4gdepay->dtsdeltalength > 0) {
632 if (gst_bs_parse_read (&bs, 1))
633 gst_bs_parse_read (&bs, rtpmp4gdepay->dtsdeltalength);
635 /* RAP-flag to indicate that the AU contains a keyframe */
636 if (rtpmp4gdepay->randomaccessindication)
637 gst_bs_parse_read (&bs, 1);
639 if (rtpmp4gdepay->streamstateindication > 0)
640 gst_bs_parse_read (&bs, rtpmp4gdepay->streamstateindication);
642 GST_DEBUG_OBJECT (rtpmp4gdepay, "size %d, index %d, delta %d", AU_size,
643 AU_index, AU_index_delta);
645 /* fragmented pakets have the AU_size set to the size of the
646 * unfragmented AU. */
647 if (AU_size > payload_AU_size)
648 AU_size = payload_AU_size;
650 /* collect stuff in the adapter, strip header from payload and push in
653 gst_rtp_buffer_get_payload_subbuffer (&rtp, payload_AU, AU_size);
654 gst_adapter_push (rtpmp4gdepay->adapter, outbuf);
659 /* packet is complete, flush */
660 avail = gst_adapter_available (rtpmp4gdepay->adapter);
662 outbuf = gst_adapter_take_buffer (rtpmp4gdepay->adapter, avail);
664 /* copy some of the fields we calculated above on the buffer. We also
665 * copy the AU_index so that we can sort the packets in our queue. */
666 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
667 GST_BUFFER_OFFSET (outbuf) = AU_index;
669 /* make sure we don't use the timestamp again for other AUs in this
673 GST_DEBUG_OBJECT (depayload,
674 "pushing buffer of size %" G_GSIZE_FORMAT,
675 gst_buffer_get_size (outbuf));
677 gst_rtp_mp4g_depay_queue (rtpmp4gdepay, outbuf);
680 payload_AU += AU_size;
681 payload_AU_size -= AU_size;
684 /* push complete buffer in adapter */
685 outbuf = gst_rtp_buffer_get_payload_subbuffer (&rtp, 0, payload_len);
686 gst_adapter_push (rtpmp4gdepay->adapter, outbuf);
688 /* if this was the last packet of the VOP, create and push a buffer */
692 avail = gst_adapter_available (rtpmp4gdepay->adapter);
694 outbuf = gst_adapter_take_buffer (rtpmp4gdepay->adapter, avail);
696 GST_DEBUG ("gst_rtp_mp4g_depay_chain: pushing buffer of size %"
697 G_GSIZE_FORMAT, gst_buffer_get_size (outbuf));
699 gst_rtp_buffer_unmap (&rtp);
705 gst_rtp_buffer_unmap (&rtp);
711 GST_ELEMENT_WARNING (rtpmp4gdepay, STREAM, DECODE,
712 ("Packet payload was too short."), (NULL));
713 gst_rtp_buffer_unmap (&rtp);
719 gst_rtp_mp4g_depay_handle_event (GstRTPBaseDepayload * filter, GstEvent * event)
722 GstRtpMP4GDepay *rtpmp4gdepay;
724 rtpmp4gdepay = GST_RTP_MP4G_DEPAY (filter);
726 switch (GST_EVENT_TYPE (event)) {
727 case GST_EVENT_FLUSH_STOP:
728 gst_rtp_mp4g_depay_reset (rtpmp4gdepay);
735 GST_RTP_BASE_DEPAYLOAD_CLASS (parent_class)->handle_event (filter, event);
740 static GstStateChangeReturn
741 gst_rtp_mp4g_depay_change_state (GstElement * element,
742 GstStateChange transition)
744 GstRtpMP4GDepay *rtpmp4gdepay;
745 GstStateChangeReturn ret;
747 rtpmp4gdepay = GST_RTP_MP4G_DEPAY (element);
749 switch (transition) {
750 case GST_STATE_CHANGE_READY_TO_PAUSED:
751 gst_rtp_mp4g_depay_reset (rtpmp4gdepay);
757 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
759 switch (transition) {
760 case GST_STATE_CHANGE_PAUSED_TO_READY:
761 gst_rtp_mp4g_depay_reset (rtpmp4gdepay);
770 gst_rtp_mp4g_depay_plugin_init (GstPlugin * plugin)
772 return gst_element_register (plugin, "rtpmp4gdepay",
773 GST_RANK_SECONDARY, GST_TYPE_RTP_MP4G_DEPAY);