2 * Copyright (C) <2006> 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.
27 #include <gst/base/gstbitreader.h>
28 #include <gst/rtp/gstrtpbuffer.h>
29 #include <gst/pbutils/pbutils.h>
30 #include <gst/video/video.h>
31 #include "gstrtpelements.h"
32 #include "gstrtph264depay.h"
33 #include "gstrtputils.h"
35 GST_DEBUG_CATEGORY_STATIC (rtph264depay_debug);
36 #define GST_CAT_DEFAULT (rtph264depay_debug)
38 /* This is what we'll default to when downstream hasn't
39 * expressed a restriction or preference via caps */
40 #define DEFAULT_BYTE_STREAM TRUE
41 #define DEFAULT_ACCESS_UNIT FALSE
42 #define DEFAULT_WAIT_FOR_KEYFRAME FALSE
43 #define DEFAULT_REQUEST_KEYFRAME FALSE
48 PROP_WAIT_FOR_KEYFRAME,
49 PROP_REQUEST_KEYFRAME,
53 /* 3 zero bytes syncword */
54 static const guint8 sync_bytes[] = { 0, 0, 0, 1 };
56 static GstStaticPadTemplate gst_rtp_h264_depay_src_template =
57 GST_STATIC_PAD_TEMPLATE ("src",
60 GST_STATIC_CAPS ("video/x-h264, "
61 "stream-format = (string) avc, alignment = (string) au; "
63 "stream-format = (string) byte-stream, alignment = (string) { nal, au }")
66 static GstStaticPadTemplate gst_rtp_h264_depay_sink_template =
67 GST_STATIC_PAD_TEMPLATE ("sink",
70 GST_STATIC_CAPS ("application/x-rtp, "
71 "media = (string) \"video\", "
72 "clock-rate = (int) 90000, " "encoding-name = (string) \"H264\"")
73 /* optional parameters */
74 /* "profile-level-id = (string) ANY, " */
75 /* "max-mbps = (string) ANY, " */
76 /* "max-fs = (string) ANY, " */
77 /* "max-cpb = (string) ANY, " */
78 /* "max-dpb = (string) ANY, " */
79 /* "max-br = (string) ANY, " */
80 /* "redundant-pic-cap = (string) { \"0\", \"1\" }, " */
81 /* "sprop-parameter-sets = (string) ANY, " */
82 /* "parameter-add = (string) { \"0\", \"1\" }, " */
83 /* "packetization-mode = (string) { \"0\", \"1\", \"2\" }, " */
84 /* "sprop-interleaving-depth = (string) ANY, " */
85 /* "sprop-deint-buf-req = (string) ANY, " */
86 /* "deint-buf-cap = (string) ANY, " */
87 /* "sprop-init-buf-time = (string) ANY, " */
88 /* "sprop-max-don-diff = (string) ANY, " */
89 /* "max-rcmd-nalu-size = (string) ANY " */
92 #define gst_rtp_h264_depay_parent_class parent_class
93 G_DEFINE_TYPE_WITH_CODE (GstRtpH264Depay, gst_rtp_h264_depay,
94 GST_TYPE_RTP_BASE_DEPAYLOAD, GST_DEBUG_CATEGORY_INIT (rtph264depay_debug,
95 "rtph264depay", 0, "H264 Video RTP Depayloader"));
96 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtph264depay, "rtph264depay",
97 GST_RANK_SECONDARY, GST_TYPE_RTP_H264_DEPAY, rtp_element_init (plugin));
99 static void gst_rtp_h264_depay_finalize (GObject * object);
101 static GstStateChangeReturn gst_rtp_h264_depay_change_state (GstElement *
102 element, GstStateChange transition);
104 static GstBuffer *gst_rtp_h264_depay_process (GstRTPBaseDepayload * depayload,
106 static gboolean gst_rtp_h264_depay_setcaps (GstRTPBaseDepayload * filter,
108 static gboolean gst_rtp_h264_depay_handle_event (GstRTPBaseDepayload * depay,
110 static GstBuffer *gst_rtp_h264_complete_au (GstRtpH264Depay * rtph264depay,
111 GstClockTime * out_timestamp, gboolean * out_keyframe);
112 static void gst_rtp_h264_depay_push (GstRtpH264Depay * rtph264depay,
113 GstBuffer * outbuf, gboolean keyframe, GstClockTime timestamp,
117 gst_rtp_h264_depay_set_property (GObject * object, guint prop_id,
118 const GValue * value, GParamSpec * pspec)
120 GstRtpH264Depay *self = GST_RTP_H264_DEPAY (object);
123 case PROP_WAIT_FOR_KEYFRAME:
124 self->wait_for_keyframe = g_value_get_boolean (value);
126 case PROP_REQUEST_KEYFRAME:
127 self->request_keyframe = g_value_get_boolean (value);
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 gst_rtp_h264_depay_get_property (GObject * object, guint prop_id,
137 GValue * value, GParamSpec * pspec)
139 GstRtpH264Depay *self = GST_RTP_H264_DEPAY (object);
142 case PROP_WAIT_FOR_KEYFRAME:
143 g_value_set_boolean (value, self->wait_for_keyframe);
145 case PROP_REQUEST_KEYFRAME:
146 g_value_set_boolean (value, self->request_keyframe);
149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
155 gst_rtp_h264_depay_class_init (GstRtpH264DepayClass * klass)
157 GObjectClass *gobject_class;
158 GstElementClass *gstelement_class;
159 GstRTPBaseDepayloadClass *gstrtpbasedepayload_class;
161 gobject_class = (GObjectClass *) klass;
162 gstelement_class = (GstElementClass *) klass;
163 gstrtpbasedepayload_class = (GstRTPBaseDepayloadClass *) klass;
165 gobject_class->finalize = gst_rtp_h264_depay_finalize;
166 gobject_class->set_property = gst_rtp_h264_depay_set_property;
167 gobject_class->get_property = gst_rtp_h264_depay_get_property;
170 * GstRtpH264Depay:wait-for-keyframe:
172 * Wait for the next keyframe after packet loss,
173 * meaningful only when outputting access units
177 g_object_class_install_property (gobject_class, PROP_WAIT_FOR_KEYFRAME,
178 g_param_spec_boolean ("wait-for-keyframe", "Wait for Keyframe",
179 "Wait for the next keyframe after packet loss, meaningful only when "
180 "outputting access units",
181 DEFAULT_WAIT_FOR_KEYFRAME,
182 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
185 * GstRtpH264Depay:request-keyframe:
187 * Request new keyframe when packet loss is detected
191 g_object_class_install_property (gobject_class, PROP_REQUEST_KEYFRAME,
192 g_param_spec_boolean ("request-keyframe", "Request Keyframe",
193 "Request new keyframe when packet loss is detected",
194 DEFAULT_REQUEST_KEYFRAME,
195 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
197 gst_element_class_add_static_pad_template (gstelement_class,
198 &gst_rtp_h264_depay_src_template);
199 gst_element_class_add_static_pad_template (gstelement_class,
200 &gst_rtp_h264_depay_sink_template);
202 gst_element_class_set_static_metadata (gstelement_class,
203 "RTP H264 depayloader", "Codec/Depayloader/Network/RTP",
204 "Extracts H264 video from RTP packets (RFC 3984)",
205 "Wim Taymans <wim.taymans@gmail.com>");
206 gstelement_class->change_state = gst_rtp_h264_depay_change_state;
208 gstrtpbasedepayload_class->process_rtp_packet = gst_rtp_h264_depay_process;
209 gstrtpbasedepayload_class->set_caps = gst_rtp_h264_depay_setcaps;
210 gstrtpbasedepayload_class->handle_event = gst_rtp_h264_depay_handle_event;
214 gst_rtp_h264_depay_init (GstRtpH264Depay * rtph264depay)
216 rtph264depay->adapter = gst_adapter_new ();
217 rtph264depay->picture_adapter = gst_adapter_new ();
218 rtph264depay->byte_stream = DEFAULT_BYTE_STREAM;
219 rtph264depay->merge = DEFAULT_ACCESS_UNIT;
220 rtph264depay->sps = g_ptr_array_new_with_free_func (
221 (GDestroyNotify) gst_buffer_unref);
222 rtph264depay->pps = g_ptr_array_new_with_free_func (
223 (GDestroyNotify) gst_buffer_unref);
224 rtph264depay->wait_for_keyframe = DEFAULT_WAIT_FOR_KEYFRAME;
225 rtph264depay->request_keyframe = DEFAULT_REQUEST_KEYFRAME;
229 gst_rtp_h264_depay_reset (GstRtpH264Depay * rtph264depay, gboolean hard)
231 gst_adapter_clear (rtph264depay->adapter);
232 rtph264depay->wait_start = TRUE;
233 rtph264depay->waiting_for_keyframe = rtph264depay->wait_for_keyframe;
234 gst_adapter_clear (rtph264depay->picture_adapter);
235 rtph264depay->picture_start = FALSE;
236 rtph264depay->last_keyframe = FALSE;
237 rtph264depay->last_ts = 0;
238 rtph264depay->current_fu_type = 0;
239 rtph264depay->new_codec_data = FALSE;
240 g_ptr_array_set_size (rtph264depay->sps, 0);
241 g_ptr_array_set_size (rtph264depay->pps, 0);
244 if (rtph264depay->allocator != NULL) {
245 gst_object_unref (rtph264depay->allocator);
246 rtph264depay->allocator = NULL;
248 gst_allocation_params_init (&rtph264depay->params);
253 gst_rtp_h264_depay_drain (GstRtpH264Depay * rtph264depay)
255 GstClockTime timestamp;
259 if (!rtph264depay->picture_start)
262 outbuf = gst_rtp_h264_complete_au (rtph264depay, ×tamp, &keyframe);
264 gst_rtp_h264_depay_push (rtph264depay, outbuf, keyframe, timestamp, FALSE);
268 gst_rtp_h264_depay_finalize (GObject * object)
270 GstRtpH264Depay *rtph264depay;
272 rtph264depay = GST_RTP_H264_DEPAY (object);
274 if (rtph264depay->codec_data)
275 gst_buffer_unref (rtph264depay->codec_data);
277 g_object_unref (rtph264depay->adapter);
278 g_object_unref (rtph264depay->picture_adapter);
280 g_ptr_array_free (rtph264depay->sps, TRUE);
281 g_ptr_array_free (rtph264depay->pps, TRUE);
283 G_OBJECT_CLASS (parent_class)->finalize (object);
287 gst_rtp_h264_depay_negotiate (GstRtpH264Depay * rtph264depay)
290 gint byte_stream = -1;
294 gst_pad_get_allowed_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (rtph264depay));
296 GST_DEBUG_OBJECT (rtph264depay, "allowed caps: %" GST_PTR_FORMAT, caps);
299 if (gst_caps_get_size (caps) > 0) {
300 GstStructure *s = gst_caps_get_structure (caps, 0);
301 const gchar *str = NULL;
303 if ((str = gst_structure_get_string (s, "stream-format"))) {
304 if (strcmp (str, "avc") == 0) {
306 } else if (strcmp (str, "byte-stream") == 0) {
309 GST_DEBUG_OBJECT (rtph264depay, "unknown stream-format: %s", str);
313 if ((str = gst_structure_get_string (s, "alignment"))) {
314 if (strcmp (str, "au") == 0) {
316 } else if (strcmp (str, "nal") == 0) {
319 GST_DEBUG_OBJECT (rtph264depay, "unknown alignment: %s", str);
323 gst_caps_unref (caps);
326 if (byte_stream != -1) {
327 GST_DEBUG_OBJECT (rtph264depay, "downstream requires byte-stream %d",
329 rtph264depay->byte_stream = byte_stream;
331 GST_DEBUG_OBJECT (rtph264depay, "defaulting to byte-stream %d",
332 DEFAULT_BYTE_STREAM);
333 rtph264depay->byte_stream = DEFAULT_BYTE_STREAM;
336 GST_DEBUG_OBJECT (rtph264depay, "downstream requires merge %d", merge);
337 rtph264depay->merge = merge;
339 GST_DEBUG_OBJECT (rtph264depay, "defaulting to merge %d",
340 DEFAULT_ACCESS_UNIT);
341 rtph264depay->merge = DEFAULT_ACCESS_UNIT;
346 parse_sps (GstMapInfo * map, guint32 * sps_id)
348 GstBitReader br = GST_BIT_READER_INIT (map->data + 4,
354 if (!gst_rtp_read_golomb (&br, sps_id))
361 parse_pps (GstMapInfo * map, guint32 * sps_id, guint32 * pps_id)
363 GstBitReader br = GST_BIT_READER_INIT (map->data + 1,
369 if (!gst_rtp_read_golomb (&br, pps_id))
371 if (!gst_rtp_read_golomb (&br, sps_id))
378 gst_rtp_h264_depay_set_output_caps (GstRtpH264Depay * rtph264depay,
381 GstAllocationParams params;
382 GstAllocator *allocator = NULL;
386 gst_allocation_params_init (¶ms);
388 srcpad = GST_RTP_BASE_DEPAYLOAD_SRCPAD (rtph264depay);
389 res = gst_pad_set_caps (srcpad, caps);
393 query = gst_query_new_allocation (caps, TRUE);
394 if (!gst_pad_peer_query (srcpad, query)) {
395 GST_DEBUG_OBJECT (rtph264depay, "downstream ALLOCATION query failed");
398 if (gst_query_get_n_allocation_params (query) > 0) {
399 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
402 gst_query_unref (query);
405 if (rtph264depay->allocator)
406 gst_object_unref (rtph264depay->allocator);
408 rtph264depay->allocator = allocator;
409 rtph264depay->params = params;
415 gst_rtp_h264_set_src_caps (GstRtpH264Depay * rtph264depay)
422 if (!rtph264depay->byte_stream &&
423 (!rtph264depay->new_codec_data ||
424 rtph264depay->sps->len == 0 || rtph264depay->pps->len == 0))
427 srccaps = gst_caps_new_simple ("video/x-h264",
428 "stream-format", G_TYPE_STRING,
429 rtph264depay->byte_stream ? "byte-stream" : "avc",
430 "alignment", G_TYPE_STRING, rtph264depay->merge ? "au" : "nal", NULL);
432 if (!rtph264depay->byte_stream) {
433 GstBuffer *codec_data;
439 guint i, first_sps, num_sps, first_pps, num_pps;
441 guchar profile_compat = G_MAXUINT8;
443 /* start with 7 bytes header */
445 /* count sps & pps */
446 for (i = 0; i < rtph264depay->sps->len; i++)
447 len += 2 + gst_buffer_get_size (g_ptr_array_index (rtph264depay->sps, i));
448 for (i = 0; i < rtph264depay->pps->len; i++)
449 len += 2 + gst_buffer_get_size (g_ptr_array_index (rtph264depay->pps, i));
451 codec_data = gst_buffer_new_and_alloc (len);
452 gst_buffer_map (codec_data, &map, GST_MAP_READWRITE);
455 /* 8 bits version == 1 */
458 /* According to: ISO/IEC 14496-15:2004(E) section 5.2.4.1
459 * The level is the max level of all SPSes
460 * A profile compat bit can only be set if all SPSes include that bit
462 for (i = 0; i < rtph264depay->sps->len; i++) {
463 gst_buffer_map (g_ptr_array_index (rtph264depay->sps, i), &nalmap,
465 profile_compat &= nalmap.data[2];
466 level = MAX (level, nalmap.data[3]);
467 gst_buffer_unmap (g_ptr_array_index (rtph264depay->sps, i), &nalmap);
470 /* Assume all SPSes use the same profile, so extract from the first SPS */
471 gst_buffer_map (g_ptr_array_index (rtph264depay->sps, 0), &nalmap,
473 *data++ = nalmap.data[1];
474 gst_buffer_unmap (g_ptr_array_index (rtph264depay->sps, 0), &nalmap);
475 *data++ = profile_compat;
478 /* 6 bits reserved | 2 bits lengthSizeMinusOn */
481 if (rtph264depay->sps->len > 31) {
482 GST_WARNING_OBJECT (rtph264depay,
483 "Too many SPS to put in codec_data. Sending the most recent 31");
485 first_sps = rtph264depay->sps->len - 31;
487 num_sps = rtph264depay->sps->len;
491 /* 3 bits reserved | 5 bits numOfSequenceParameterSets */
492 *data++ = 0xe0 | (num_sps & 0x1f);
495 for (i = first_sps; i < rtph264depay->sps->len; i++) {
496 gst_buffer_map (g_ptr_array_index (rtph264depay->sps, i), &nalmap,
499 GST_DEBUG_OBJECT (rtph264depay, "copy SPS %d of length %u", i,
500 (guint) nalmap.size);
501 GST_WRITE_UINT16_BE (data, nalmap.size);
503 memcpy (data, nalmap.data, nalmap.size);
505 gst_buffer_unmap (g_ptr_array_index (rtph264depay->sps, i), &nalmap);
508 if (rtph264depay->pps->len > 255) {
509 GST_WARNING_OBJECT (rtph264depay,
510 "Too many PPS to put in codec_data. Sending the most recent 255");
512 first_pps = rtph264depay->pps->len - 255;
514 num_pps = rtph264depay->pps->len;
518 /* 8 bits numOfPictureParameterSets */
522 for (i = first_pps; i < rtph264depay->pps->len; i++) {
523 gst_buffer_map (g_ptr_array_index (rtph264depay->pps, i), &nalmap,
526 GST_DEBUG_OBJECT (rtph264depay, "copy PPS %d of length %u", i,
527 (guint) nalmap.size);
528 GST_WRITE_UINT16_BE (data, nalmap.size);
530 memcpy (data, nalmap.data, nalmap.size);
532 gst_buffer_unmap (g_ptr_array_index (rtph264depay->pps, i), &nalmap);
535 new_size = data - map.data;
536 gst_buffer_unmap (codec_data, &map);
537 gst_buffer_set_size (codec_data, new_size);
539 gst_caps_set_simple (srccaps,
540 "codec_data", GST_TYPE_BUFFER, codec_data, NULL);
541 gst_buffer_unref (codec_data);
544 /* Set profile a level from SPS */
547 GstBuffer *max_level_sps = NULL;
551 /* Get the SPS with the highest level. We assume
552 * all SPS have the same profile */
553 for (i = 0; i < rtph264depay->sps->len; i++) {
554 gst_buffer_map (g_ptr_array_index (rtph264depay->sps, i), &nalmap,
556 if (level == 0 || level < nalmap.data[3]) {
557 max_level_sps = g_ptr_array_index (rtph264depay->sps, i);
558 level = nalmap.data[3];
560 gst_buffer_unmap (g_ptr_array_index (rtph264depay->sps, i), &nalmap);
564 gst_buffer_map (max_level_sps, &nalmap, GST_MAP_READ);
565 gst_codec_utils_h264_caps_set_level_and_profile (srccaps, nalmap.data + 1,
567 gst_buffer_unmap (max_level_sps, &nalmap);
571 srcpad = GST_RTP_BASE_DEPAYLOAD_SRCPAD (rtph264depay);
573 old_caps = gst_pad_get_current_caps (srcpad);
575 if (old_caps == NULL || !gst_caps_is_equal (srccaps, old_caps)) {
576 res = gst_rtp_h264_depay_set_output_caps (rtph264depay, srccaps);
579 gst_clear_caps (&old_caps);
580 gst_caps_unref (srccaps);
582 /* Insert SPS and PPS into the stream on next opportunity (if bytestream) */
583 if (rtph264depay->byte_stream
584 && (rtph264depay->sps->len > 0 || rtph264depay->pps->len > 0)) {
586 GstBuffer *codec_data;
591 for (i = 0; i < rtph264depay->sps->len; i++) {
592 len += 4 + gst_buffer_get_size (g_ptr_array_index (rtph264depay->sps, i));
595 for (i = 0; i < rtph264depay->pps->len; i++) {
596 len += 4 + gst_buffer_get_size (g_ptr_array_index (rtph264depay->pps, i));
599 codec_data = gst_buffer_new_and_alloc (len);
600 gst_buffer_map (codec_data, &map, GST_MAP_WRITE);
603 for (i = 0; i < rtph264depay->sps->len; i++) {
604 GstBuffer *sps_buf = g_ptr_array_index (rtph264depay->sps, i);
605 guint sps_size = gst_buffer_get_size (sps_buf);
607 if (rtph264depay->byte_stream)
608 memcpy (data, sync_bytes, sizeof (sync_bytes));
610 GST_WRITE_UINT32_BE (data, sps_size);
611 gst_buffer_extract (sps_buf, 0, data + 4, -1);
612 data += 4 + sps_size;
615 for (i = 0; i < rtph264depay->pps->len; i++) {
616 GstBuffer *pps_buf = g_ptr_array_index (rtph264depay->pps, i);
617 guint pps_size = gst_buffer_get_size (pps_buf);
619 if (rtph264depay->byte_stream)
620 memcpy (data, sync_bytes, sizeof (sync_bytes));
622 GST_WRITE_UINT32_BE (data, pps_size);
623 gst_buffer_extract (pps_buf, 0, data + 4, -1);
624 data += 4 + pps_size;
627 gst_buffer_unmap (codec_data, &map);
628 if (rtph264depay->codec_data)
629 gst_buffer_unref (rtph264depay->codec_data);
630 rtph264depay->codec_data = codec_data;
634 rtph264depay->new_codec_data = FALSE;
640 gst_rtp_h264_add_sps_pps (GstElement * rtph264, GPtrArray * sps_array,
641 GPtrArray * pps_array, GstBuffer * nal)
647 gst_buffer_map (nal, &map, GST_MAP_READ);
649 type = map.data[0] & 0x1f;
654 if (!parse_sps (&map, &sps_id)) {
655 GST_WARNING_OBJECT (rtph264, "Invalid SPS,"
656 " can't parse seq_parameter_set_id");
660 for (i = 0; i < sps_array->len; i++) {
661 GstBuffer *sps = g_ptr_array_index (sps_array, i);
665 gst_buffer_map (sps, &spsmap, GST_MAP_READ);
666 parse_sps (&spsmap, &tmp_sps_id);
668 if (sps_id == tmp_sps_id) {
669 /* If this is already the most recent SPS and unchanged, nothing to do */
670 if (i == (sps_array->len - 1) && map.size == spsmap.size &&
671 memcmp (map.data, spsmap.data, spsmap.size) == 0) {
672 GST_LOG_OBJECT (rtph264,
673 "Unchanged SPS %u already most recent, not updating", sps_id);
674 gst_buffer_unmap (sps, &spsmap);
677 gst_buffer_unmap (sps, &spsmap);
678 g_ptr_array_remove_index (sps_array, i);
679 g_ptr_array_add (sps_array, nal);
680 GST_LOG_OBJECT (rtph264, "Modified SPS %u, replacing", sps_id);
684 gst_buffer_unmap (sps, &spsmap);
686 GST_LOG_OBJECT (rtph264, "Adding new SPS %u", sps_id);
687 g_ptr_array_add (sps_array, nal);
688 } else if (type == 8) {
692 if (!parse_pps (&map, &sps_id, &pps_id)) {
693 GST_WARNING_OBJECT (rtph264, "Invalid PPS,"
694 " can't parse seq_parameter_set_id or pic_parameter_set_id");
698 for (i = 0; i < pps_array->len; i++) {
699 GstBuffer *pps = g_ptr_array_index (pps_array, i);
705 gst_buffer_map (pps, &ppsmap, GST_MAP_READ);
706 parse_pps (&ppsmap, &tmp_sps_id, &tmp_pps_id);
708 if (pps_id == tmp_pps_id) {
709 /* If this is already the most recent PPS and unchanged, nothing to do */
710 if (i == (pps_array->len - 1) && map.size == ppsmap.size &&
711 memcmp (map.data, ppsmap.data, ppsmap.size) == 0) {
712 GST_LOG_OBJECT (rtph264,
713 "Unchanged PPS %u:%u already most recent, not updating", sps_id,
715 gst_buffer_unmap (pps, &ppsmap);
718 gst_buffer_unmap (pps, &ppsmap);
719 g_ptr_array_remove_index (pps_array, i);
720 g_ptr_array_add (pps_array, nal);
721 GST_LOG_OBJECT (rtph264, "Modified PPS %u:%u, replacing",
726 gst_buffer_unmap (pps, &ppsmap);
728 GST_LOG_OBJECT (rtph264, "Adding new PPS %u:%i", sps_id, pps_id);
729 g_ptr_array_add (pps_array, nal);
735 gst_buffer_unmap (nal, &map);
740 gst_buffer_unmap (nal, &map);
741 gst_buffer_unref (nal);
748 gst_rtp_h264_depay_add_sps_pps (GstRtpH264Depay * rtph264depay, GstBuffer * nal)
750 if (gst_rtp_h264_add_sps_pps (GST_ELEMENT (rtph264depay),
751 rtph264depay->sps, rtph264depay->pps, nal))
752 rtph264depay->new_codec_data = TRUE;
756 gst_rtp_h264_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
759 GstStructure *structure = gst_caps_get_structure (caps, 0);
760 GstRtpH264Depay *rtph264depay;
762 GstBuffer *codec_data;
766 rtph264depay = GST_RTP_H264_DEPAY (depayload);
768 if (!gst_structure_get_int (structure, "clock-rate", &clock_rate))
770 depayload->clock_rate = clock_rate;
772 /* Base64 encoded, comma separated config NALs */
773 ps = gst_structure_get_string (structure, "sprop-parameter-sets");
775 /* negotiate with downstream w.r.t. output format and alignment */
776 gst_rtp_h264_depay_negotiate (rtph264depay);
778 if (rtph264depay->byte_stream && ps != NULL) {
779 /* for bytestream we only need the parameter sets but we don't error out
780 * when they are not there, we assume they are in the stream. */
785 params = g_strsplit (ps, ",", 0);
787 /* count total number of bytes in base64. Also include the sync bytes in
788 * front of the params. */
790 for (i = 0; params[i]; i++) {
791 len += strlen (params[i]);
792 len += sizeof (sync_bytes);
794 /* we seriously overshoot the length, but it's fine. */
795 codec_data = gst_buffer_new_and_alloc (len);
797 gst_buffer_map (codec_data, &map, GST_MAP_WRITE);
800 for (i = 0; params[i]; i++) {
804 GST_DEBUG_OBJECT (depayload, "decoding param %d (%s)", i, params[i]);
805 memcpy (ptr, sync_bytes, sizeof (sync_bytes));
806 ptr += sizeof (sync_bytes);
808 g_base64_decode_step (params[i], strlen (params[i]), ptr, &state,
810 GST_DEBUG_OBJECT (depayload, "decoded %d bytes", len);
811 total += len + sizeof (sync_bytes);
814 gst_buffer_unmap (codec_data, &map);
815 gst_buffer_resize (codec_data, 0, total);
818 /* keep the codec_data, we need to send it as the first buffer. We cannot
819 * push it in the adapter because the adapter might be flushed on discont.
821 if (rtph264depay->codec_data)
822 gst_buffer_unref (rtph264depay->codec_data);
823 rtph264depay->codec_data = codec_data;
824 } else if (!rtph264depay->byte_stream) {
829 goto incomplete_caps;
831 params = g_strsplit (ps, ",", 0);
833 GST_DEBUG_OBJECT (depayload, "we have %d params", g_strv_length (params));
835 /* start with 7 bytes header */
836 for (i = 0; params[i]; i++) {
843 nal_len = strlen (params[i]);
845 GST_WARNING_OBJECT (depayload, "empty param '%s' (#%d)", params[i], i);
848 nal = gst_buffer_new_and_alloc (nal_len);
849 gst_buffer_map (nal, &nalmap, GST_MAP_READWRITE);
852 g_base64_decode_step (params[i], nal_len, nalmap.data, &state, &save);
854 GST_DEBUG_OBJECT (depayload, "adding param %d as %s", i,
855 ((nalmap.data[0] & 0x1f) == 7) ? "SPS" : "PPS");
857 gst_buffer_unmap (nal, &nalmap);
858 gst_buffer_set_size (nal, nal_len);
860 gst_rtp_h264_depay_add_sps_pps (rtph264depay, nal);
864 if (rtph264depay->sps->len == 0 || rtph264depay->pps->len == 0)
865 goto incomplete_caps;
868 return gst_rtp_h264_set_src_caps (rtph264depay);
873 GST_DEBUG_OBJECT (depayload, "we have incomplete caps,"
874 " doing setcaps later");
880 gst_rtp_h264_depay_allocate_output_buffer (GstRtpH264Depay * depay, gsize size)
882 GstBuffer *buffer = NULL;
884 g_return_val_if_fail (size > 0, NULL);
886 GST_LOG_OBJECT (depay, "want output buffer of %u bytes", (guint) size);
888 buffer = gst_buffer_new_allocate (depay->allocator, size, &depay->params);
889 if (buffer == NULL) {
890 GST_INFO_OBJECT (depay, "couldn't allocate output buffer");
891 buffer = gst_buffer_new_allocate (NULL, size, NULL);
898 gst_rtp_h264_complete_au (GstRtpH264Depay * rtph264depay,
899 GstClockTime * out_timestamp, gboolean * out_keyframe)
904 guint outsize, offset = 0;
905 gint b, n_bufs, m, n_mem;
907 /* we had a picture in the adapter and we completed it */
908 GST_DEBUG_OBJECT (rtph264depay, "taking completed AU");
909 outsize = gst_adapter_available (rtph264depay->picture_adapter);
911 outbuf = gst_rtp_h264_depay_allocate_output_buffer (rtph264depay, outsize);
916 if (!gst_buffer_map (outbuf, &outmap, GST_MAP_WRITE))
919 list = gst_adapter_take_buffer_list (rtph264depay->picture_adapter, outsize);
921 n_bufs = gst_buffer_list_length (list);
922 for (b = 0; b < n_bufs; ++b) {
923 GstBuffer *buf = gst_buffer_list_get (list, b);
925 n_mem = gst_buffer_n_memory (buf);
926 for (m = 0; m < n_mem; ++m) {
927 GstMemory *mem = gst_buffer_peek_memory (buf, m);
928 gsize mem_size = gst_memory_get_sizes (mem, NULL, NULL);
931 if (gst_memory_map (mem, &mem_map, GST_MAP_READ)) {
932 memcpy (outmap.data + offset, mem_map.data, mem_size);
933 gst_memory_unmap (mem, &mem_map);
935 memset (outmap.data + offset, 0, mem_size);
940 gst_rtp_copy_video_meta (rtph264depay, outbuf, buf);
942 gst_buffer_list_unref (list);
943 gst_buffer_unmap (outbuf, &outmap);
945 *out_timestamp = rtph264depay->last_ts;
946 *out_keyframe = rtph264depay->last_keyframe;
948 rtph264depay->last_keyframe = FALSE;
949 rtph264depay->picture_start = FALSE;
955 gst_rtp_h264_depay_push (GstRtpH264Depay * rtph264depay, GstBuffer * outbuf,
956 gboolean keyframe, GstClockTime timestamp, gboolean marker)
958 /* prepend codec_data */
959 if (rtph264depay->codec_data) {
960 GST_DEBUG_OBJECT (rtph264depay, "prepending codec_data");
961 gst_rtp_copy_video_meta (rtph264depay, rtph264depay->codec_data, outbuf);
962 outbuf = gst_buffer_append (rtph264depay->codec_data, outbuf);
963 rtph264depay->codec_data = NULL;
966 outbuf = gst_buffer_make_writable (outbuf);
968 gst_rtp_drop_non_video_meta (rtph264depay, outbuf);
970 GST_BUFFER_PTS (outbuf) = timestamp;
973 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
975 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
978 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_MARKER);
980 gst_rtp_base_depayload_push (GST_RTP_BASE_DEPAYLOAD (rtph264depay), outbuf);
983 /* SPS/PPS/IDR considered key, all others DELTA;
984 * so downstream waiting for keyframe can pick up at SPS/PPS/IDR */
985 #define NAL_TYPE_IS_KEY(nt) (((nt) == 5) || ((nt) == 7) || ((nt) == 8))
988 gst_rtp_h264_depay_handle_nal (GstRtpH264Depay * rtph264depay, GstBuffer * nal,
989 GstClockTime in_timestamp, gboolean marker)
991 GstRTPBaseDepayload *depayload = GST_RTP_BASE_DEPAYLOAD (rtph264depay);
994 GstBuffer *outbuf = NULL;
995 GstClockTime out_timestamp;
996 gboolean keyframe, out_keyframe;
998 gst_buffer_map (nal, &map, GST_MAP_READ);
999 if (G_UNLIKELY (map.size < 5))
1002 nal_type = map.data[4] & 0x1f;
1003 GST_DEBUG_OBJECT (rtph264depay, "handle NAL type %d", nal_type);
1005 keyframe = NAL_TYPE_IS_KEY (nal_type);
1007 out_keyframe = keyframe;
1008 out_timestamp = in_timestamp;
1010 if (!rtph264depay->byte_stream) {
1011 if (nal_type == 7 || nal_type == 8) {
1012 gst_rtp_h264_depay_add_sps_pps (rtph264depay,
1013 gst_buffer_copy_region (nal, GST_BUFFER_COPY_ALL,
1014 4, gst_buffer_get_size (nal) - 4));
1015 gst_buffer_unmap (nal, &map);
1016 gst_buffer_unref (nal);
1018 } else if (rtph264depay->sps->len == 0 || rtph264depay->pps->len == 0) {
1019 /* Down push down any buffer in non-bytestream mode if the SPS/PPS haven't
1022 gst_pad_push_event (GST_RTP_BASE_DEPAYLOAD_SINKPAD (depayload),
1023 gst_event_new_custom (GST_EVENT_CUSTOM_UPSTREAM,
1024 gst_structure_new ("GstForceKeyUnit",
1025 "all-headers", G_TYPE_BOOLEAN, TRUE, NULL)));
1026 gst_buffer_unmap (nal, &map);
1027 gst_buffer_unref (nal);
1031 if (rtph264depay->new_codec_data &&
1032 rtph264depay->sps->len > 0 && rtph264depay->pps->len > 0)
1033 gst_rtp_h264_set_src_caps (rtph264depay);
1037 if (rtph264depay->merge) {
1038 gboolean start = FALSE, complete = FALSE;
1040 /* consider a coded slices (IDR or not) to start a picture,
1041 * (so ending the previous one) if first_mb_in_slice == 0
1042 * (non-0 is part of previous one) */
1043 /* NOTE this is not entirely according to Access Unit specs in 7.4.1.2.4,
1044 * but in practice it works in sane cases, needs not much parsing,
1045 * and also works with broken frame_num in NAL (where spec-wise would fail) */
1046 /* FIXME: this code isn't correct for interlaced content as AUs should be
1047 * constructed with pairs of fields and the guess here will just push out
1048 * AUs with a single field in it */
1049 if (nal_type == 1 || nal_type == 2 || nal_type == 5) {
1050 /* we have a picture start */
1052 if (map.data[5] & 0x80) {
1053 /* first_mb_in_slice == 0 completes a picture */
1056 } else if (nal_type >= 6 && nal_type <= 9) {
1057 /* SEI, SPS, PPS, AU terminate picture */
1060 GST_DEBUG_OBJECT (depayload, "start %d, complete %d", start, complete);
1062 /* marker bit isn't mandatory so in the following code we try to guess
1063 * an AU boundary by detecting a new picture start */
1065 if (complete && rtph264depay->picture_start)
1066 outbuf = gst_rtp_h264_complete_au (rtph264depay, &out_timestamp,
1069 /* add to adapter */
1070 gst_buffer_unmap (nal, &map);
1072 if (!rtph264depay->picture_start && start && out_keyframe)
1073 rtph264depay->waiting_for_keyframe = FALSE;
1075 GST_DEBUG_OBJECT (depayload, "adding NAL to picture adapter");
1076 gst_adapter_push (rtph264depay->picture_adapter, nal);
1077 rtph264depay->last_ts = in_timestamp;
1078 rtph264depay->last_keyframe |= keyframe;
1079 rtph264depay->picture_start |= start;
1082 outbuf = gst_rtp_h264_complete_au (rtph264depay, &out_timestamp,
1085 /* no merge, output is input nal */
1086 GST_DEBUG_OBJECT (depayload, "using NAL as output");
1088 gst_buffer_unmap (nal, &map);
1092 if (!rtph264depay->waiting_for_keyframe) {
1093 gst_rtp_h264_depay_push (rtph264depay, outbuf, out_keyframe,
1094 out_timestamp, marker);
1096 GST_LOG_OBJECT (depayload,
1097 "Dropping %" GST_PTR_FORMAT ", we are waiting for a keyframe",
1099 gst_buffer_unref (outbuf);
1108 GST_WARNING_OBJECT (depayload, "dropping short NAL");
1109 gst_buffer_unmap (nal, &map);
1110 gst_buffer_unref (nal);
1116 gst_rtp_h264_finish_fragmentation_unit (GstRtpH264Depay * rtph264depay)
1122 outsize = gst_adapter_available (rtph264depay->adapter);
1123 outbuf = gst_adapter_take_buffer (rtph264depay->adapter, outsize);
1125 gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
1126 GST_DEBUG_OBJECT (rtph264depay, "output %d bytes", outsize);
1128 if (rtph264depay->byte_stream) {
1129 memcpy (map.data, sync_bytes, sizeof (sync_bytes));
1132 map.data[0] = (outsize >> 24);
1133 map.data[1] = (outsize >> 16);
1134 map.data[2] = (outsize >> 8);
1135 map.data[3] = (outsize);
1137 gst_buffer_unmap (outbuf, &map);
1139 rtph264depay->current_fu_type = 0;
1141 gst_rtp_h264_depay_handle_nal (rtph264depay, outbuf,
1142 rtph264depay->fu_timestamp, rtph264depay->fu_marker);
1146 gst_rtp_h264_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
1148 GstRtpH264Depay *rtph264depay;
1149 GstBuffer *outbuf = NULL;
1150 guint8 nal_unit_type;
1152 rtph264depay = GST_RTP_H264_DEPAY (depayload);
1154 if (!rtph264depay->merge)
1155 rtph264depay->waiting_for_keyframe = FALSE;
1157 /* flush remaining data on discont */
1158 if (GST_BUFFER_IS_DISCONT (rtp->buffer)) {
1159 gst_adapter_clear (rtph264depay->adapter);
1160 rtph264depay->wait_start = TRUE;
1161 rtph264depay->current_fu_type = 0;
1162 rtph264depay->last_fu_seqnum = 0;
1164 if (rtph264depay->merge && rtph264depay->wait_for_keyframe) {
1165 rtph264depay->waiting_for_keyframe = TRUE;
1169 if (rtph264depay->request_keyframe)
1170 gst_pad_push_event (GST_RTP_BASE_DEPAYLOAD_SINKPAD (depayload),
1171 gst_video_event_new_upstream_force_key_unit (GST_CLOCK_TIME_NONE,
1181 guint outsize, nalu_size;
1182 GstClockTime timestamp;
1185 timestamp = GST_BUFFER_PTS (rtp->buffer);
1187 payload_len = gst_rtp_buffer_get_payload_len (rtp);
1188 payload = gst_rtp_buffer_get_payload (rtp);
1189 marker = gst_rtp_buffer_get_marker (rtp);
1191 GST_DEBUG_OBJECT (rtph264depay, "receiving %d bytes", payload_len);
1193 if (payload_len == 0)
1196 /* +---------------+
1204 nal_ref_idc = (payload[0] & 0x60) >> 5;
1205 nal_unit_type = payload[0] & 0x1f;
1207 /* at least one byte header with type */
1210 GST_DEBUG_OBJECT (rtph264depay, "NRI %d, Type %d %s", nal_ref_idc,
1211 nal_unit_type, marker ? "marker" : "");
1213 /* If FU unit was being processed, but the current nal is of a different
1214 * type. Assume that the remote payloader is buggy (didn't set the end bit
1215 * when the FU ended) and send out what we gathered thusfar */
1216 if (G_UNLIKELY (rtph264depay->current_fu_type != 0 &&
1217 nal_unit_type != rtph264depay->current_fu_type))
1218 gst_rtp_h264_finish_fragmentation_unit (rtph264depay);
1220 switch (nal_unit_type) {
1225 goto undefined_type;
1227 /* STAP-B Single-time aggregation packet 5.7.1 */
1228 /* 2 byte extra header for DON */
1234 payload += header_len;
1235 payload_len -= header_len;
1237 rtph264depay->wait_start = FALSE;
1240 /* STAP-A Single-time aggregation packet 5.7.1 */
1241 while (payload_len > 2) {
1242 gboolean last = FALSE;
1245 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
1246 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1248 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1250 nalu_size = (payload[0] << 8) | payload[1];
1252 /* don't include nalu_size */
1253 if (nalu_size > (payload_len - 2))
1254 nalu_size = payload_len - 2;
1256 outsize = nalu_size + sizeof (sync_bytes);
1257 outbuf = gst_buffer_new_and_alloc (outsize);
1259 gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
1260 if (rtph264depay->byte_stream) {
1261 memcpy (map.data, sync_bytes, sizeof (sync_bytes));
1263 map.data[0] = map.data[1] = 0;
1264 map.data[2] = payload[0];
1265 map.data[3] = payload[1];
1268 /* strip NALU size */
1272 memcpy (map.data + sizeof (sync_bytes), payload, nalu_size);
1273 gst_buffer_unmap (outbuf, &map);
1275 gst_rtp_copy_video_meta (rtph264depay, outbuf, rtp->buffer);
1277 if (payload_len - nalu_size <= 2)
1280 gst_rtp_h264_depay_handle_nal (rtph264depay, outbuf, timestamp,
1283 payload += nalu_size;
1284 payload_len -= nalu_size;
1289 /* MTAP16 Multi-time aggregation packet 5.7.2 */
1291 /* fallthrough, not implemented */
1293 /* MTAP24 Multi-time aggregation packet 5.7.2 */
1295 goto not_implemented;
1300 /* FU-A Fragmentation unit 5.8 */
1301 /* FU-B Fragmentation unit 5.8 */
1304 /* +---------------+
1310 * R is reserved and always 0
1312 S = (payload[1] & 0x80) == 0x80;
1313 E = (payload[1] & 0x40) == 0x40;
1315 GST_DEBUG_OBJECT (rtph264depay, "S %d, E %d", S, E);
1317 if (rtph264depay->wait_start && !S)
1321 /* NAL unit starts here */
1324 /* If a new FU unit started, while still processing an older one.
1325 * Assume that the remote payloader is buggy (doesn't set the end
1326 * bit) and send out what we've gathered thusfar */
1327 if (G_UNLIKELY (rtph264depay->current_fu_type != 0))
1328 gst_rtp_h264_finish_fragmentation_unit (rtph264depay);
1330 rtph264depay->current_fu_type = nal_unit_type;
1331 rtph264depay->fu_timestamp = timestamp;
1332 rtph264depay->last_fu_seqnum = gst_rtp_buffer_get_seq (rtp);
1334 rtph264depay->wait_start = FALSE;
1336 /* reconstruct NAL header */
1337 nal_header = (payload[0] & 0xe0) | (payload[1] & 0x1f);
1339 /* strip type header, keep FU header, we'll reuse it to reconstruct
1340 * the NAL header. */
1344 nalu_size = payload_len;
1345 outsize = nalu_size + sizeof (sync_bytes);
1346 outbuf = gst_buffer_new_and_alloc (outsize);
1348 gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
1349 memcpy (map.data + sizeof (sync_bytes), payload, nalu_size);
1350 map.data[sizeof (sync_bytes)] = nal_header;
1351 gst_buffer_unmap (outbuf, &map);
1353 gst_rtp_copy_video_meta (rtph264depay, outbuf, rtp->buffer);
1355 GST_DEBUG_OBJECT (rtph264depay, "queueing %d bytes", outsize);
1357 /* and assemble in the adapter */
1358 gst_adapter_push (rtph264depay->adapter, outbuf);
1360 if (rtph264depay->current_fu_type == 0) {
1361 /* previous FU packet missing start bit? */
1362 GST_WARNING_OBJECT (rtph264depay, "missing FU start bit on an "
1363 "earlier packet. Dropping.");
1364 gst_adapter_clear (rtph264depay->adapter);
1367 if (gst_rtp_buffer_compare_seqnum (rtph264depay->last_fu_seqnum,
1368 gst_rtp_buffer_get_seq (rtp)) != 1) {
1369 /* jump in sequence numbers within an FU is cause for discarding */
1370 GST_WARNING_OBJECT (rtph264depay, "Jump in sequence numbers from "
1371 "%u to %u within Fragmentation Unit. Data was lost, dropping "
1372 "stored.", rtph264depay->last_fu_seqnum,
1373 gst_rtp_buffer_get_seq (rtp));
1374 gst_adapter_clear (rtph264depay->adapter);
1377 rtph264depay->last_fu_seqnum = gst_rtp_buffer_get_seq (rtp);
1379 /* strip off FU indicator and FU header bytes */
1383 outsize = payload_len;
1384 outbuf = gst_buffer_new_and_alloc (outsize);
1385 gst_buffer_fill (outbuf, 0, payload, outsize);
1387 gst_rtp_copy_video_meta (rtph264depay, outbuf, rtp->buffer);
1389 GST_DEBUG_OBJECT (rtph264depay, "queueing %d bytes", outsize);
1391 /* and assemble in the adapter */
1392 gst_adapter_push (rtph264depay->adapter, outbuf);
1396 rtph264depay->fu_marker = marker;
1398 /* if NAL unit ends, flush the adapter */
1400 gst_rtp_h264_finish_fragmentation_unit (rtph264depay);
1405 rtph264depay->wait_start = FALSE;
1407 /* 1-23 NAL unit Single NAL unit packet per H.264 5.6 */
1408 /* the entire payload is the output buffer */
1409 nalu_size = payload_len;
1410 outsize = nalu_size + sizeof (sync_bytes);
1411 outbuf = gst_buffer_new_and_alloc (outsize);
1413 gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
1414 if (rtph264depay->byte_stream) {
1415 memcpy (map.data, sync_bytes, sizeof (sync_bytes));
1417 map.data[0] = map.data[1] = 0;
1418 map.data[2] = nalu_size >> 8;
1419 map.data[3] = nalu_size & 0xff;
1421 memcpy (map.data + sizeof (sync_bytes), payload, nalu_size);
1422 gst_buffer_unmap (outbuf, &map);
1424 gst_rtp_copy_video_meta (rtph264depay, outbuf, rtp->buffer);
1426 gst_rtp_h264_depay_handle_nal (rtph264depay, outbuf, timestamp, marker);
1437 GST_DEBUG_OBJECT (rtph264depay, "empty packet");
1442 GST_ELEMENT_WARNING (rtph264depay, STREAM, DECODE,
1443 (NULL), ("Undefined packet type"));
1448 GST_DEBUG_OBJECT (rtph264depay, "waiting for start");
1453 GST_ELEMENT_ERROR (rtph264depay, STREAM, FORMAT,
1454 (NULL), ("NAL unit type %d not supported yet", nal_unit_type));
1460 gst_rtp_h264_depay_handle_event (GstRTPBaseDepayload * depay, GstEvent * event)
1462 GstRtpH264Depay *rtph264depay;
1464 rtph264depay = GST_RTP_H264_DEPAY (depay);
1466 switch (GST_EVENT_TYPE (event)) {
1467 case GST_EVENT_FLUSH_STOP:
1468 gst_rtp_h264_depay_reset (rtph264depay, FALSE);
1471 gst_rtp_h264_depay_drain (rtph264depay);
1478 GST_RTP_BASE_DEPAYLOAD_CLASS (parent_class)->handle_event (depay, event);
1481 static GstStateChangeReturn
1482 gst_rtp_h264_depay_change_state (GstElement * element,
1483 GstStateChange transition)
1485 GstRtpH264Depay *rtph264depay;
1486 GstStateChangeReturn ret;
1488 rtph264depay = GST_RTP_H264_DEPAY (element);
1490 switch (transition) {
1491 case GST_STATE_CHANGE_NULL_TO_READY:
1493 case GST_STATE_CHANGE_READY_TO_PAUSED:
1494 gst_rtp_h264_depay_reset (rtph264depay, TRUE);
1500 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1502 switch (transition) {
1503 case GST_STATE_CHANGE_PAUSED_TO_READY:
1504 gst_rtp_h264_depay_reset (rtph264depay, TRUE);
1506 case GST_STATE_CHANGE_READY_TO_NULL: