1 /* GStreamer plugin for forward error correction
2 * Copyright (C) 2017 Pexip
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * Author: Mikhail Fludkov <misha@pexip.com>
22 * SECTION:element-rtpulpfecdec
23 * @short_description: Generic RTP Forward Error Correction (FEC) decoder
24 * @title: rtpulpfecdec
26 * Generic Forward Error Correction (FEC) decoder for Uneven Level
27 * Protection (ULP) as described in RFC 5109.
29 * It differs from the RFC in one important way, it multiplexes the
30 * FEC packets in the same sequence number as media packets. This is to be
31 * compatible with libwebrtc as using in Google Chrome and with Microsoft
32 * Lync / Skype for Business.
34 * This element will work in combination with an upstream #GstRtpStorage
35 * element and attempt to recover packets declared lost through custom
36 * 'GstRTPPacketLost' events, usually emitted by #GstRtpJitterBuffer.
38 * If no storage is provided using the #GstRtpUlpFecDec:storage
39 * property, it will try to get it from an element upstream.
41 * Additionally, the payload types of the protection packets *must* be
42 * provided to this element via its #GstRtpUlpFecDec:pt property.
44 * When using #GstRtpBin, this element should be inserted through the
45 * #GstRtpBin::request-fec-decoder signal.
50 * gst-launch-1.0 udpsrc port=8888 caps="application/x-rtp, payload=96, clock-rate=90000" ! rtpstorage size-time=220000000 ! rtpssrcdemux ! application/x-rtp, payload=96, clock-rate=90000, media=video, encoding-name=H264 ! rtpjitterbuffer do-lost=1 latency=200 ! rtpulpfecdec pt=122 ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink
51 * ]| This example will receive a stream with FEC and try to reconstruct the packets.
53 * Example programs are available at
54 * <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/blob/master/examples/src/bin/rtpfecserver.rs>
56 * <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/blob/master/examples/src/bin/rtpfecclient.rs>
58 * See also: #GstRtpUlpFecEnc, #GstRtpBin, #GstRtpStorage
62 #include <gst/rtp/gstrtpbuffer.h>
63 #include <gst/rtp/gstrtp-enumtypes.h>
65 #include "gstrtpelements.h"
66 #include "rtpulpfeccommon.h"
67 #include "gstrtpulpfecdec.h"
69 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
72 GST_STATIC_CAPS ("application/x-rtp")
75 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
78 GST_STATIC_CAPS ("application/x-rtp")
92 #define DEFAULT_FEC_PT 0
93 #define DEFAULT_PASSTHROUGH FALSE
95 static GParamSpec *klass_properties[N_PROPERTIES] = { NULL, };
97 GST_DEBUG_CATEGORY (gst_rtp_ulpfec_dec_debug);
98 #define GST_CAT_DEFAULT (gst_rtp_ulpfec_dec_debug)
100 G_DEFINE_TYPE (GstRtpUlpFecDec, gst_rtp_ulpfec_dec, GST_TYPE_ELEMENT);
101 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (rtpulpfecdec, "rtpulpfecdec",
102 GST_RANK_NONE, GST_TYPE_RTP_ULPFEC_DEC, rtp_element_init (plugin));
104 #define RTP_FEC_MAP_INFO_NTH(dec, data) (&g_array_index (\
105 ((GstRtpUlpFecDec *)dec)->info_arr, \
107 GPOINTER_TO_UINT(data)))
110 _compare_fec_map_info (gconstpointer a, gconstpointer b, gpointer userdata)
113 gst_rtp_buffer_get_seq (&RTP_FEC_MAP_INFO_NTH (userdata, a)->rtp);
115 gst_rtp_buffer_get_seq (&RTP_FEC_MAP_INFO_NTH (userdata, b)->rtp);
116 return gst_rtp_buffer_compare_seqnum (bseq, aseq);
120 gst_rtp_ulpfec_dec_start (GstRtpUlpFecDec * self, GstBufferList * buflist,
121 guint8 fec_pt, guint16 lost_seq)
123 guint fec_packets = 0;
126 g_assert (NULL == self->info_media);
127 g_assert (0 == self->info_fec->len);
128 g_assert (0 == self->info_arr->len);
130 g_array_set_size (self->info_arr, gst_buffer_list_length (buflist));
133 i < gst_buffer_list_length (buflist) && !self->lost_packet_from_storage;
135 GstBuffer *buffer = gst_buffer_list_get (buflist, i);
136 RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, i);
138 if (!rtp_ulpfec_map_info_map (gst_buffer_ref (buffer), info))
139 g_assert_not_reached ();
141 if (fec_pt == gst_rtp_buffer_get_payload_type (&info->rtp)) {
142 GST_DEBUG_RTP_PACKET (self, "rtp header (fec)", &info->rtp);
145 if (rtp_ulpfec_buffer_is_valid (&info->rtp)) {
146 GST_DEBUG_FEC_PACKET (self, &info->rtp);
147 g_ptr_array_add (self->info_fec, GUINT_TO_POINTER (i));
150 GST_LOG_RTP_PACKET (self, "rtp header (incoming)", &info->rtp);
152 if (lost_seq == gst_rtp_buffer_get_seq (&info->rtp)) {
153 GST_DEBUG_OBJECT (self, "Received lost packet from the storage");
154 g_list_free (self->info_media);
155 self->info_media = NULL;
156 self->lost_packet_from_storage = TRUE;
159 g_list_insert_sorted_with_data (self->info_media,
160 GUINT_TO_POINTER (i), _compare_fec_map_info, self);
163 if (!self->lost_packet_from_storage) {
164 self->fec_packets_received += fec_packets;
165 self->fec_packets_rejected += fec_packets - self->info_fec->len;
170 gst_rtp_ulpfec_dec_stop (GstRtpUlpFecDec * self)
172 g_array_set_size (self->info_arr, 0);
173 g_ptr_array_set_size (self->info_fec, 0);
174 g_list_free (self->info_media);
175 self->info_media = NULL;
176 self->lost_packet_from_storage = FALSE;
177 self->lost_packet_returned = FALSE;
181 gst_rtp_ulpfec_dec_get_media_buffers_mask (GstRtpUlpFecDec * self,
182 guint16 fec_seq_base)
187 for (it = self->info_media; it; it = it->next) {
188 RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, it->data);
190 rtp_ulpfec_packet_mask_from_seqnum (gst_rtp_buffer_get_seq (&info->rtp),
197 gst_rtp_ulpfec_dec_is_recovered_pt_valid (GstRtpUlpFecDec * self, gint media_pt,
201 if (media_pt == recovered_pt)
204 for (it = self->info_media; it; it = it->next) {
205 RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, it->data);
206 if (gst_rtp_buffer_get_payload_type (&info->rtp) == recovered_pt)
213 gst_rtp_ulpfec_dec_recover_from_fec (GstRtpUlpFecDec * self,
214 RtpUlpFecMapInfo * info_fec, guint32 ssrc, gint media_pt, guint16 seq,
217 guint64 fec_mask = rtp_ulpfec_buffer_get_mask (&info_fec->rtp);
218 gboolean fec_mask_long = rtp_ulpfec_buffer_get_fechdr (&info_fec->rtp)->L;
219 guint16 fec_seq_base = rtp_ulpfec_buffer_get_seq_base (&info_fec->rtp);
223 g_array_set_size (self->scratch_buf, 0);
224 rtp_buffer_to_ulpfec_bitstring (&info_fec->rtp, self->scratch_buf, TRUE,
227 for (it = self->info_media; it; it = it->next) {
228 RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, it->data);
229 guint64 packet_mask =
230 rtp_ulpfec_packet_mask_from_seqnum (gst_rtp_buffer_get_seq (&info->rtp),
233 if (fec_mask & packet_mask) {
234 fec_mask ^= packet_mask;
235 rtp_buffer_to_ulpfec_bitstring (&info->rtp, self->scratch_buf, FALSE,
241 rtp_ulpfec_bitstring_to_media_rtp_buffer (self->scratch_buf,
242 fec_mask_long, ssrc, seq);
244 /* We are about to put recovered packet back in self->info_media to be able
245 * to reuse it later for recovery of other packets
247 gint i = self->info_arr->len;
248 RtpUlpFecMapInfo *info;
251 g_array_set_size (self->info_arr, self->info_arr->len + 1);
252 info = RTP_FEC_MAP_INFO_NTH (self, i);
254 if (!rtp_ulpfec_map_info_map (gst_buffer_ref (ret), info)) {
255 GST_WARNING_OBJECT (self, "Invalid recovered packet");
256 goto recovered_packet_invalid;
259 recovered_pt = gst_rtp_buffer_get_payload_type (&info->rtp);
260 if (!gst_rtp_ulpfec_dec_is_recovered_pt_valid (self, media_pt,
262 GST_WARNING_OBJECT (self,
263 "Recovered packet has unexpected payload type (%u)", recovered_pt);
264 goto recovered_packet_invalid;
267 GST_DEBUG_RTP_PACKET (self, "rtp header (recovered)", &info->rtp);
269 g_list_insert_sorted_with_data (self->info_media, GUINT_TO_POINTER (i),
270 _compare_fec_map_info, self);
271 *dst_pt = recovered_pt;
275 recovered_packet_invalid:
276 g_array_set_size (self->info_arr, self->info_arr->len - 1);
277 gst_buffer_unref (ret);
282 gst_rtp_ulpfec_dec_recover_from_storage (GstRtpUlpFecDec * self,
283 guint8 * dst_pt, guint16 * dst_seq)
285 RtpUlpFecMapInfo *info;
287 if (self->lost_packet_returned)
290 g_assert (g_list_length (self->info_media) == 1);
292 info = RTP_FEC_MAP_INFO_NTH (self, self->info_media->data);
293 *dst_seq = gst_rtp_buffer_get_seq (&info->rtp);
294 *dst_pt = gst_rtp_buffer_get_payload_type (&info->rtp);
295 self->lost_packet_returned = TRUE;
296 GST_DEBUG_RTP_PACKET (self, "rtp header (recovered)", &info->rtp);
297 return gst_buffer_ref (info->rtp.buffer);
300 /* __has_builtin only works with clang, so test compiler version for gcc */
301 /* Intel compiler and MSVC probably have their own things as well */
302 /* TODO: make sure we use builtin for clang as well */
303 #if defined(__GNUC__) && __GNUC__ >= 4
304 #define rtp_ulpfec_ctz64 __builtin_ctzll
307 rtp_ulpfec_ctz64_inline (guint64 mask)
315 } while (++nth_bit < 64);
317 return -1; /* should not be reached, since mask must not be 0 */
320 #define rtp_ulpfec_ctz64 rtp_ulpfec_ctz64_inline
324 gst_rtp_ulpfec_dec_recover (GstRtpUlpFecDec * self, guint32 ssrc, gint media_pt,
325 guint8 * dst_pt, guint16 * dst_seq)
327 guint64 media_mask = 0;
328 gint media_mask_seq_base = -1;
331 if (self->lost_packet_from_storage)
332 return gst_rtp_ulpfec_dec_recover_from_storage (self, dst_pt, dst_seq);
334 /* Looking for a FEC packet which can be used for recovery */
335 for (i = 0; i < self->info_fec->len; ++i) {
336 RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self,
337 g_ptr_array_index (self->info_fec, i));
338 guint16 seq_base = rtp_ulpfec_buffer_get_seq_base (&info->rtp);
339 guint64 fec_mask = rtp_ulpfec_buffer_get_mask (&info->rtp);
340 guint64 missing_packets_mask;
342 if (media_mask_seq_base != (gint) seq_base) {
343 media_mask_seq_base = seq_base;
344 media_mask = gst_rtp_ulpfec_dec_get_media_buffers_mask (self, seq_base);
347 /* media_mask has 1s if packet exist.
348 * fec_mask is the mask of protected packets
349 * The statement below excludes existing packets from the protected. So
350 * we are left with 1s only for missing packets which can be recovered
351 * by this FEC packet. */
352 missing_packets_mask = fec_mask & (~media_mask);
354 /* Do we have any 1s? Checking if current FEC packet can be used for recovery */
355 if (0 != missing_packets_mask) {
356 guint trailing_zeros = rtp_ulpfec_ctz64 (missing_packets_mask);
358 /* Is it the only 1 in the mask? Checking if we lacking single packet in
359 * that case FEC packet can be used for recovery */
360 if (missing_packets_mask == (G_GUINT64_CONSTANT (1) << trailing_zeros)) {
364 seq_base + (RTP_ULPFEC_SEQ_BASE_OFFSET_MAX (TRUE) - trailing_zeros);
366 gst_rtp_ulpfec_dec_recover_from_fec (self, info, ssrc, media_pt,
377 gst_rtp_ulpfec_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
379 GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (parent);
381 if (G_LIKELY (GST_FLOW_OK == self->chain_return_val)) {
382 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
383 gboolean passthrough;
384 buf = gst_buffer_make_writable (buf);
386 if (G_UNLIKELY (self->unset_discont_flag)) {
387 self->unset_discont_flag = FALSE;
388 GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
391 GST_OBJECT_LOCK (self);
392 if (G_UNLIKELY (self->needs_discont)) {
393 self->needs_discont = FALSE;
394 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
396 passthrough = self->passthrough;
397 GST_OBJECT_UNLOCK (self);
399 gst_rtp_buffer_map (buf, GST_MAP_WRITE, &rtp);
401 self->next_seqnum = gst_rtp_buffer_get_seq (&rtp) + 1;
403 gst_rtp_buffer_set_seq (&rtp, self->next_seqnum++);
405 gst_rtp_buffer_unmap (&rtp);
407 return gst_pad_push (self->srcpad, buf);
410 gst_buffer_unref (buf);
411 return self->chain_return_val;
415 gst_rtp_ulpfec_dec_handle_packet_loss (GstRtpUlpFecDec * self, guint16 seqnum,
416 GstClockTime timestamp, GstClockTime duration)
418 gint caps_pt = self->have_caps_pt ? self->caps_pt : -1;
420 GstBufferList *buflist =
421 rtp_storage_get_packets_for_recovery (self->storage, self->fec_pt,
422 self->caps_ssrc, seqnum);
425 GstBuffer *recovered_buffer = NULL;
426 guint16 recovered_seq = 0;
427 guint8 recovered_pt = 0;
429 gst_rtp_ulpfec_dec_start (self, buflist, self->fec_pt, seqnum);
431 while (NULL != (recovered_buffer =
432 gst_rtp_ulpfec_dec_recover (self, self->caps_ssrc, caps_pt,
433 &recovered_pt, &recovered_seq))) {
434 if (seqnum == recovered_seq) {
435 GstBuffer *sent_buffer;
436 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
438 recovered_buffer = gst_buffer_make_writable (recovered_buffer);
439 GST_BUFFER_PTS (recovered_buffer) = timestamp;
440 /* GST_BUFFER_DURATION (recovered_buffer) = duration;
441 * JB does not set the duration, so we will not too */
443 if (!self->lost_packet_from_storage)
444 rtp_storage_put_recovered_packet (self->storage,
445 recovered_buffer, recovered_pt, self->caps_ssrc, recovered_seq);
447 GST_DEBUG_OBJECT (self,
448 "Pushing recovered packet ssrc=0x%08x seq=%u %" GST_PTR_FORMAT,
449 self->caps_ssrc, seqnum, recovered_buffer);
451 sent_buffer = gst_buffer_copy_deep (recovered_buffer);
453 if (self->lost_packet_from_storage)
454 gst_buffer_unref (recovered_buffer);
456 gst_rtp_buffer_map (sent_buffer, GST_MAP_WRITE, &rtp);
457 gst_rtp_buffer_set_seq (&rtp, self->next_seqnum++);
458 gst_rtp_buffer_unmap (&rtp);
460 GST_OBJECT_LOCK (self);
461 if (G_UNLIKELY (self->needs_discont)) {
462 self->needs_discont = FALSE;
463 GST_BUFFER_FLAG_SET (sent_buffer, GST_BUFFER_FLAG_DISCONT);
465 GST_OBJECT_UNLOCK (self);
468 self->unset_discont_flag = TRUE;
469 self->chain_return_val = gst_pad_push (self->srcpad, sent_buffer);
473 if (!self->lost_packet_from_storage) {
474 rtp_storage_put_recovered_packet (self->storage,
475 recovered_buffer, recovered_pt, self->caps_ssrc, recovered_seq);
477 gst_buffer_unref (recovered_buffer);
481 gst_rtp_ulpfec_dec_stop (self);
482 gst_buffer_list_unref (buflist);
485 GST_DEBUG_OBJECT (self, "Packet lost ssrc=0x%08x seq=%u", self->caps_ssrc,
492 gst_rtp_ulpfec_dec_handle_sink_event (GstPad * pad, GstObject * parent,
495 GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (parent);
496 gboolean forward = TRUE;
498 GST_LOG_OBJECT (self, "Received event %" GST_PTR_FORMAT, event);
500 if (GST_FLOW_OK == self->chain_return_val &&
501 GST_EVENT_CUSTOM_DOWNSTREAM == GST_EVENT_TYPE (event) &&
502 gst_event_has_name (event, "GstRTPPacketLost")) {
504 GstClockTime timestamp, duration;
506 gboolean passthrough;
508 GST_OBJECT_LOCK (self);
509 passthrough = self->passthrough;
510 GST_OBJECT_UNLOCK (self);
513 GST_TRACE_OBJECT (self,
514 "in passthrough mode, ignoring packet loss event");
519 event = gst_event_make_writable (event);
520 s = gst_event_writable_structure (event);
522 g_assert (self->have_caps_ssrc);
524 if (self->storage == NULL) {
525 GstQuery *q = gst_query_new_custom (GST_QUERY_CUSTOM,
526 gst_structure_new_empty ("GstRtpStorage"));
528 if (gst_pad_peer_query (self->sinkpad, q)) {
529 const GstStructure *s = gst_query_get_structure (q);
531 if (gst_structure_has_field_typed (s, "storage", G_TYPE_OBJECT)) {
532 gst_structure_get (s, "storage", G_TYPE_OBJECT, &self->storage, NULL);
538 if (self->storage == NULL) {
539 GST_ELEMENT_WARNING (self, STREAM, FAILED, ("Internal storage not found"),
540 ("You need to add rtpstorage element upstream from rtpulpfecdec."));
544 if (!gst_structure_get (s,
545 "seqnum", G_TYPE_UINT, &seqnum,
546 "timestamp", G_TYPE_UINT64, ×tamp,
547 "duration", G_TYPE_UINT64, &duration, NULL))
548 g_assert_not_reached ();
551 gst_rtp_ulpfec_dec_handle_packet_loss (self, seqnum, timestamp,
555 gst_structure_remove_field (s, "seqnum");
556 gst_structure_set (s, "might-have-been-fec", G_TYPE_BOOLEAN, TRUE, NULL);
557 ++self->packets_unrecovered;
559 ++self->packets_recovered;
562 GST_DEBUG_OBJECT (self, "Unrecovered / Recovered: %lu / %lu",
563 (gulong) self->packets_unrecovered, (gulong) self->packets_recovered);
564 } else if (GST_EVENT_CAPS == GST_EVENT_TYPE (event)) {
566 gboolean have_caps_pt = FALSE;
567 gboolean have_caps_ssrc = FALSE;
571 gst_event_parse_caps (event, &caps);
573 gst_structure_get_uint (gst_caps_get_structure (caps, 0), "ssrc",
576 gst_structure_get_int (gst_caps_get_structure (caps, 0), "payload",
579 if (self->have_caps_ssrc != have_caps_ssrc || self->caps_ssrc != caps_ssrc)
580 GST_DEBUG_OBJECT (self, "SSRC changed %u, 0x%08x -> %u, 0x%08x",
581 self->have_caps_ssrc, self->caps_ssrc, have_caps_ssrc, caps_ssrc);
582 if (self->have_caps_pt != have_caps_pt || self->caps_pt != caps_pt)
583 GST_DEBUG_OBJECT (self, "PT changed %u, %u -> %u, %u",
584 self->have_caps_pt, self->caps_pt, have_caps_pt, caps_pt);
586 self->have_caps_ssrc = have_caps_ssrc;
587 self->have_caps_pt = have_caps_pt;
588 self->caps_ssrc = caps_ssrc;
589 self->caps_pt = caps_pt;
594 return gst_pad_push_event (self->srcpad, event);
595 gst_event_unref (event);
600 gst_rtp_ulpfec_dec_init (GstRtpUlpFecDec * self)
602 self->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
603 self->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
604 GST_PAD_SET_PROXY_CAPS (self->sinkpad);
605 GST_PAD_SET_PROXY_ALLOCATION (self->sinkpad);
606 gst_pad_set_chain_function (self->sinkpad,
607 GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_chain));
608 gst_pad_set_event_function (self->sinkpad,
609 GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_handle_sink_event));
611 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
612 gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
614 self->fec_pt = DEFAULT_FEC_PT;
615 self->passthrough = DEFAULT_PASSTHROUGH;
617 self->next_seqnum = g_random_int_range (0, G_MAXINT16);
619 self->chain_return_val = GST_FLOW_OK;
620 self->have_caps_ssrc = FALSE;
622 self->info_fec = g_ptr_array_new ();
623 self->info_arr = g_array_new (FALSE, TRUE, sizeof (RtpUlpFecMapInfo));
624 g_array_set_clear_func (self->info_arr,
625 (GDestroyNotify) rtp_ulpfec_map_info_unmap);
626 self->scratch_buf = g_array_new (FALSE, TRUE, sizeof (guint8));
630 gst_rtp_ulpfec_dec_dispose (GObject * obj)
632 GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (obj);
634 GST_INFO_OBJECT (self,
636 " packets_recovered=%" G_GSIZE_FORMAT
637 " packets_unrecovered=%" G_GSIZE_FORMAT,
638 self->caps_ssrc, self->caps_pt,
639 self->packets_recovered, self->packets_unrecovered);
642 g_object_unref (self->storage);
644 g_assert (NULL == self->info_media);
645 g_assert (0 == self->info_fec->len);
646 g_assert (0 == self->info_arr->len);
648 if (self->fec_packets_received) {
649 GST_INFO_OBJECT (self,
650 " fec_packets_received=%" G_GSIZE_FORMAT
651 " fec_packets_rejected=%" G_GSIZE_FORMAT
652 " packets_rejected=%" G_GSIZE_FORMAT,
653 self->fec_packets_received,
654 self->fec_packets_rejected, self->packets_rejected);
657 g_ptr_array_free (self->info_fec, TRUE);
658 g_array_free (self->info_arr, TRUE);
659 g_array_free (self->scratch_buf, TRUE);
661 G_OBJECT_CLASS (gst_rtp_ulpfec_dec_parent_class)->dispose (obj);
665 gst_rtp_ulpfec_dec_set_property (GObject * object, guint prop_id,
666 const GValue * value, GParamSpec * pspec)
668 GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (object);
672 self->fec_pt = g_value_get_uint (value);
676 g_object_unref (self->storage);
677 self->storage = g_value_get_object (value);
679 g_object_ref (self->storage);
681 case PROP_PASSTHROUGH:{
682 gboolean newval = g_value_get_boolean (value);
683 GST_OBJECT_LOCK (self);
684 /* if we changing into non-passthrough mode, then the sequence numbers may
685 * be completely different and we need to advertise that with a discont */
686 GST_INFO_OBJECT (self, "passthrough changing from %u to %u",
687 self->passthrough, newval);
688 if (self->passthrough && !newval) {
689 self->needs_discont = TRUE;
691 self->passthrough = newval;
692 GST_OBJECT_UNLOCK (self);
696 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
702 gst_rtp_ulpfec_dec_get_property (GObject * object, guint prop_id,
703 GValue * value, GParamSpec * pspec)
705 GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (object);
709 g_value_set_uint (value, self->fec_pt);
712 g_value_set_object (value, self->storage);
715 g_value_set_uint (value, (guint) self->packets_recovered);
717 case PROP_UNRECOVERED:
718 g_value_set_uint (value, (guint) self->packets_unrecovered);
720 case PROP_PASSTHROUGH:
721 g_value_set_boolean (value, self->passthrough);
724 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
730 gst_rtp_ulpfec_dec_class_init (GstRtpUlpFecDecClass * klass)
732 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
733 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
735 GST_DEBUG_CATEGORY_INIT (gst_rtp_ulpfec_dec_debug,
736 "rtpulpfecdec", 0, "RTP FEC Decoder");
738 gst_element_class_add_pad_template (element_class,
739 gst_static_pad_template_get (&srctemplate));
740 gst_element_class_add_pad_template (element_class,
741 gst_static_pad_template_get (&sinktemplate));
743 gst_element_class_set_static_metadata (element_class,
745 "Codec/Depayloader/Network/RTP",
746 "Decodes RTP FEC (RFC5109)", "Mikhail Fludkov <misha@pexip.com>");
748 gobject_class->set_property =
749 GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_set_property);
750 gobject_class->get_property =
751 GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_get_property);
752 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_dispose);
754 klass_properties[PROP_PT] = g_param_spec_uint ("pt", "pt",
755 "FEC packets payload type", 0, 127,
756 DEFAULT_FEC_PT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
757 klass_properties[PROP_STORAGE] =
758 g_param_spec_object ("storage", "RTP storage", "RTP storage",
759 G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
760 klass_properties[PROP_RECOVERED] =
761 g_param_spec_uint ("recovered", "recovered",
762 "The number of recovered packets", 0, G_MAXUINT, 0,
763 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
764 klass_properties[PROP_UNRECOVERED] =
765 g_param_spec_uint ("unrecovered", "unrecovered",
766 "The number of unrecovered packets", 0, G_MAXUINT, 0,
767 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
769 * GstRtpUlpFecDec:passthrough:
771 * Whether to push data through without any modification. If passthrough is
772 * enabled, then no packets will ever be recovered.
776 klass_properties[PROP_PASSTHROUGH] =
777 g_param_spec_boolean ("passthrough", "Passthrough",
778 "Whether to passthrough all data as-is without modification and "
779 "never attempt to recover packets", DEFAULT_PASSTHROUGH,
780 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
782 g_object_class_install_properties (gobject_class, N_PROPERTIES,
785 g_assert (rtp_ulpfec_ctz64 (G_GUINT64_CONSTANT (0x1)) == 0);
786 g_assert (rtp_ulpfec_ctz64 (G_GUINT64_CONSTANT (0x8000000000000000)) == 63);