FEC elements: document, remove irrelevant properties
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpulpfecdec.c
1 /* GStreamer plugin for forward error correction
2  * Copyright (C) 2017 Pexip
3  *
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.
8  *
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.
13  *
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
17  *
18  * Author: Mikhail Fludkov <misha@pexip.com>
19  */
20
21 /**
22  * SECTION:element-rtpulpfecdec
23  * @short_description: Generic RTP Forward Error Correction (FEC) decoder
24  * @title: rtpulpfecdec
25  *
26  * Generic Forward Error Correction (FEC) decoder for Uneven Level
27  * Protection (ULP) as described in RFC 5109.
28  *
29  * This element will work in combination with an upstream #GstRtpStorage
30  * element and attempt to recover packets declared lost through custom
31  * 'GstRTPPacketLost' events, usually emitted by #GstRtpJitterBuffer.
32  *
33  * As such, this element cannot be usefully used from the command line,
34  * because a reference to the upstream storage object needs to be
35  * provided to it through its #GstRtpUlpFecDec:storage property, example
36  * programs are available at
37  * <https://github.com/sdroege/gstreamer-rs/blob/master/examples/src/bin/rtpfecserver.rs>
38  * and
39  * <https://github.com/sdroege/gstreamer-rs/blob/master/examples/src/bin/rtpfecclient.rs>.
40  *
41  * Additionally, the payload types of the protection packets *must* be
42  * provided to this element via its #GstRtpUlpFecDec:pt property.
43  *
44  * When using #GstRtpBin, this element should be inserted through the
45  * #GstRtpBin::request-fec-decoder signal.
46  *
47  * See also: #GstRtpUlpFecEnc, #GstRtpBin, #GstRtpStorage
48  * Since: 1.14
49  */
50
51 #include <gst/rtp/gstrtpbuffer.h>
52 #include <gst/rtp/gstrtp-enumtypes.h>
53
54 #include "rtpulpfeccommon.h"
55 #include "gstrtpulpfecdec.h"
56
57 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
58     GST_PAD_SINK,
59     GST_PAD_ALWAYS,
60     GST_STATIC_CAPS ("application/x-rtp")
61     );
62
63 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
64     GST_PAD_SRC,
65     GST_PAD_ALWAYS,
66     GST_STATIC_CAPS ("application/x-rtp")
67     );
68
69 enum
70 {
71   PROP_0,
72   PROP_PT,
73   PROP_STORAGE,
74   PROP_RECOVERED,
75   PROP_UNRECOVERED,
76   N_PROPERTIES
77 };
78
79 #define DEFAULT_FEC_PT 0
80
81 static GParamSpec *klass_properties[N_PROPERTIES] = { NULL, };
82
83 GST_DEBUG_CATEGORY (gst_rtp_ulpfec_dec_debug);
84 #define GST_CAT_DEFAULT (gst_rtp_ulpfec_dec_debug)
85
86 G_DEFINE_TYPE (GstRtpUlpFecDec, gst_rtp_ulpfec_dec, GST_TYPE_ELEMENT);
87
88 #define RTP_FEC_MAP_INFO_NTH(dec, data) (&g_array_index (\
89     ((GstRtpUlpFecDec *)dec)->info_arr, \
90     RtpUlpFecMapInfo, \
91     GPOINTER_TO_UINT(data)))
92
93 static gint
94 _compare_fec_map_info (gconstpointer a, gconstpointer b, gpointer userdata)
95 {
96   guint16 aseq =
97       gst_rtp_buffer_get_seq (&RTP_FEC_MAP_INFO_NTH (userdata, a)->rtp);
98   guint16 bseq =
99       gst_rtp_buffer_get_seq (&RTP_FEC_MAP_INFO_NTH (userdata, b)->rtp);
100   return gst_rtp_buffer_compare_seqnum (bseq, aseq);
101 }
102
103 static void
104 gst_rtp_ulpfec_dec_start (GstRtpUlpFecDec * self, GstBufferList * buflist,
105     guint8 fec_pt, guint16 lost_seq)
106 {
107   guint fec_packets = 0;
108
109   g_assert (NULL == self->info_media);
110   g_assert (0 == self->info_fec->len);
111   g_assert (0 == self->info_arr->len);
112
113   g_array_set_size (self->info_arr, gst_buffer_list_length (buflist));
114
115   for (gsize i = 0;
116       i < gst_buffer_list_length (buflist) && !self->lost_packet_from_storage;
117       ++i) {
118     GstBuffer *buffer = gst_buffer_list_get (buflist, i);
119     RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, i);
120
121     if (!rtp_ulpfec_map_info_map (gst_buffer_ref (buffer), info))
122       g_assert_not_reached ();
123
124     if (fec_pt == gst_rtp_buffer_get_payload_type (&info->rtp)) {
125       GST_DEBUG_RTP_PACKET (self, "rtp header (fec)", &info->rtp);
126
127       ++fec_packets;
128       if (rtp_ulpfec_buffer_is_valid (&info->rtp)) {
129         GST_DEBUG_FEC_PACKET (self, &info->rtp);
130         g_ptr_array_add (self->info_fec, GUINT_TO_POINTER (i));
131       }
132     } else {
133       GST_LOG_RTP_PACKET (self, "rtp header (incoming)", &info->rtp);
134
135       if (lost_seq == gst_rtp_buffer_get_seq (&info->rtp)) {
136         GST_DEBUG_OBJECT (self, "Received lost packet from from the storage");
137         g_list_free (self->info_media);
138         self->info_media = NULL;
139         self->lost_packet_from_storage = TRUE;
140       }
141       self->info_media =
142           g_list_insert_sorted_with_data (self->info_media,
143           GUINT_TO_POINTER (i), _compare_fec_map_info, self);
144     }
145   }
146   if (!self->lost_packet_from_storage) {
147     self->fec_packets_received += fec_packets;
148     self->fec_packets_rejected += fec_packets - self->info_fec->len;
149   }
150 }
151
152 static void
153 gst_rtp_ulpfec_dec_stop (GstRtpUlpFecDec * self)
154 {
155   g_array_set_size (self->info_arr, 0);
156   g_ptr_array_set_size (self->info_fec, 0);
157   g_list_free (self->info_media);
158   self->info_media = NULL;
159   self->lost_packet_from_storage = FALSE;
160   self->lost_packet_returned = FALSE;
161 }
162
163 static guint64
164 gst_rtp_ulpfec_dec_get_media_buffers_mask (GstRtpUlpFecDec * self,
165     guint16 fec_seq_base)
166 {
167   guint64 mask = 0;
168   for (GList * it = self->info_media; it; it = it->next) {
169     RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, it->data);
170     mask |=
171         rtp_ulpfec_packet_mask_from_seqnum (gst_rtp_buffer_get_seq (&info->rtp),
172         fec_seq_base, TRUE);
173   }
174   return mask;
175 }
176
177 static gboolean
178 gst_rtp_ulpfec_dec_is_recovered_pt_valid (GstRtpUlpFecDec * self, gint media_pt,
179     guint8 recovered_pt)
180 {
181   if (media_pt == recovered_pt)
182     return TRUE;
183
184   for (GList * it = self->info_media; it; it = it->next) {
185     RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, it->data);
186     if (gst_rtp_buffer_get_payload_type (&info->rtp) == recovered_pt)
187       return TRUE;
188   }
189   return FALSE;
190 }
191
192 static GstBuffer *
193 gst_rtp_ulpfec_dec_recover_from_fec (GstRtpUlpFecDec * self,
194     RtpUlpFecMapInfo * info_fec, guint32 ssrc, gint media_pt, guint16 seq,
195     guint8 * dst_pt)
196 {
197   guint64 fec_mask = rtp_ulpfec_buffer_get_mask (&info_fec->rtp);
198   gboolean fec_mask_long = rtp_ulpfec_buffer_get_fechdr (&info_fec->rtp)->L;
199   guint16 fec_seq_base = rtp_ulpfec_buffer_get_seq_base (&info_fec->rtp);
200   GstBuffer *ret;
201
202   g_array_set_size (self->scratch_buf, 0);
203   rtp_buffer_to_ulpfec_bitstring (&info_fec->rtp, self->scratch_buf, TRUE,
204       fec_mask_long);
205
206   for (GList * it = self->info_media; it; it = it->next) {
207     RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self, it->data);
208     guint64 packet_mask =
209         rtp_ulpfec_packet_mask_from_seqnum (gst_rtp_buffer_get_seq (&info->rtp),
210         fec_seq_base, TRUE);
211
212     if (fec_mask & packet_mask) {
213       fec_mask ^= packet_mask;
214       rtp_buffer_to_ulpfec_bitstring (&info->rtp, self->scratch_buf, FALSE,
215           fec_mask_long);
216     }
217   }
218
219   ret =
220       rtp_ulpfec_bitstring_to_media_rtp_buffer (self->scratch_buf,
221       fec_mask_long, ssrc, seq);
222   if (ret) {
223     /* We are about to put recovered packet back in self->info_media to be able
224      * to reuse it later for recovery of other packets
225      **/
226     gint i = self->info_arr->len;
227     RtpUlpFecMapInfo *info;
228     guint8 recovered_pt;
229
230     g_array_set_size (self->info_arr, self->info_arr->len + 1);
231     info = RTP_FEC_MAP_INFO_NTH (self, i);
232
233     if (!rtp_ulpfec_map_info_map (gst_buffer_ref (ret), info)) {
234       GST_WARNING_OBJECT (self, "Invalid recovered packet");
235       goto recovered_packet_invalid;
236     }
237
238     recovered_pt = gst_rtp_buffer_get_payload_type (&info->rtp);
239     if (!gst_rtp_ulpfec_dec_is_recovered_pt_valid (self, media_pt,
240             recovered_pt)) {
241       GST_WARNING_OBJECT (self,
242           "Recovered packet has unexpected payload type (%u)", recovered_pt);
243       goto recovered_packet_invalid;
244     }
245
246     GST_DEBUG_RTP_PACKET (self, "rtp header (recovered)", &info->rtp);
247     self->info_media =
248         g_list_insert_sorted_with_data (self->info_media, GUINT_TO_POINTER (i),
249         _compare_fec_map_info, self);
250     *dst_pt = recovered_pt;
251   }
252   return ret;
253
254 recovered_packet_invalid:
255   g_array_set_size (self->info_arr, self->info_arr->len - 1);
256   gst_buffer_unref (ret);
257   return NULL;
258 }
259
260 static GstBuffer *
261 gst_rtp_ulpfec_dec_recover_from_storage (GstRtpUlpFecDec * self,
262     guint8 * dst_pt, guint16 * dst_seq)
263 {
264   RtpUlpFecMapInfo *info;
265
266   if (self->lost_packet_returned)
267     return NULL;
268
269   g_assert (g_list_length (self->info_media) == 1);
270
271   info = RTP_FEC_MAP_INFO_NTH (self, self->info_media->data);
272   *dst_seq = gst_rtp_buffer_get_seq (&info->rtp);
273   *dst_pt = gst_rtp_buffer_get_payload_type (&info->rtp);
274   self->lost_packet_returned = TRUE;
275   GST_DEBUG_RTP_PACKET (self, "rtp header (recovered)", &info->rtp);
276   return gst_buffer_ref (info->rtp.buffer);
277 }
278
279 static GstBuffer *
280 gst_rtp_ulpfec_dec_recover (GstRtpUlpFecDec * self, guint32 ssrc, gint media_pt,
281     guint8 * dst_pt, guint16 * dst_seq)
282 {
283   guint64 media_mask = 0;
284   gint media_mask_seq_base = -1;
285
286   if (self->lost_packet_from_storage)
287     return gst_rtp_ulpfec_dec_recover_from_storage (self, dst_pt, dst_seq);
288
289   /* Looking for a FEC packet which can be used for recovery */
290   for (gsize i = 0; i < self->info_fec->len; ++i) {
291     RtpUlpFecMapInfo *info = RTP_FEC_MAP_INFO_NTH (self,
292         g_ptr_array_index (self->info_fec, i));
293     guint16 seq_base = rtp_ulpfec_buffer_get_seq_base (&info->rtp);
294     guint64 fec_mask = rtp_ulpfec_buffer_get_mask (&info->rtp);
295     guint64 missing_packets_mask;
296
297     if (media_mask_seq_base != (gint) seq_base) {
298       media_mask_seq_base = seq_base;
299       media_mask = gst_rtp_ulpfec_dec_get_media_buffers_mask (self, seq_base);
300     }
301
302     /* media_mask has 1s if packet exist.
303      * fec_mask is the mask of protected packets
304      * The statement below excludes existing packets from the protected. So
305      * we are left with 1s only for missing packets which can be recovered
306      * by this FEC packet. */
307     missing_packets_mask = fec_mask & (~media_mask);
308
309     /* Do we have any 1s? Checking if current FEC packet can be used for recovery */
310     if (0 != missing_packets_mask) {
311       guint trailing_zeros = __builtin_ctzll (missing_packets_mask);
312
313       /* Is it the only 1 in the mask? Checking if we lacking single packet in
314        * that case FEC packet can be used for recovery */
315       if (missing_packets_mask == (1ULL << trailing_zeros)) {
316         GstBuffer *ret;
317
318         *dst_seq =
319             seq_base + (RTP_ULPFEC_SEQ_BASE_OFFSET_MAX (TRUE) - trailing_zeros);
320         ret =
321             gst_rtp_ulpfec_dec_recover_from_fec (self, info, ssrc, media_pt,
322             *dst_seq, dst_pt);
323         if (ret)
324           return ret;
325       }
326     }
327   }
328   return NULL;
329 }
330
331 static GstFlowReturn
332 gst_rtp_ulpfec_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
333 {
334   GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (parent);
335
336   if (G_LIKELY (GST_FLOW_OK == self->chain_return_val)) {
337     if (G_UNLIKELY (self->unset_discont_flag)) {
338       self->unset_discont_flag = FALSE;
339       buf = gst_buffer_make_writable (buf);
340       GST_BUFFER_FLAG_UNSET (buf, GST_BUFFER_FLAG_DISCONT);
341     }
342     return gst_pad_push (self->srcpad, buf);
343   }
344
345   gst_buffer_unref (buf);
346   return self->chain_return_val;
347 }
348
349 static gboolean
350 gst_rtp_ulpfec_dec_handle_packet_loss (GstRtpUlpFecDec * self, guint16 seqnum,
351     GstClockTime timestamp, GstClockTime duration)
352 {
353   gint caps_pt = self->have_caps_pt ? self->caps_pt : -1;
354   gboolean ret = TRUE;
355   GstBufferList *buflist =
356       rtp_storage_get_packets_for_recovery (self->storage, self->fec_pt,
357       self->caps_ssrc, seqnum);
358
359   if (buflist) {
360     GstBuffer *recovered_buffer = NULL;
361     guint16 recovered_seq = 0;
362     guint8 recovered_pt = 0;
363
364     gst_rtp_ulpfec_dec_start (self, buflist, self->fec_pt, seqnum);
365
366     while (NULL != (recovered_buffer =
367             gst_rtp_ulpfec_dec_recover (self, self->caps_ssrc, caps_pt,
368                 &recovered_pt, &recovered_seq))) {
369       if (seqnum == recovered_seq) {
370         recovered_buffer = gst_buffer_make_writable (recovered_buffer);
371         GST_BUFFER_PTS (recovered_buffer) = timestamp;
372         /* GST_BUFFER_DURATION (recovered_buffer) = duration;
373          * JB does not set the duration, so we will not too */
374
375         if (!self->lost_packet_from_storage)
376           rtp_storage_put_recovered_packet (self->storage,
377               gst_buffer_ref (recovered_buffer), recovered_pt, self->caps_ssrc,
378               recovered_seq);
379
380         GST_DEBUG_OBJECT (self,
381             "Pushing recovered packet ssrc=0x%08x seq=%u %" GST_PTR_FORMAT,
382             self->caps_ssrc, seqnum, recovered_buffer);
383
384         ret = FALSE;
385         self->unset_discont_flag = TRUE;
386         self->chain_return_val = gst_pad_push (self->srcpad, recovered_buffer);
387         break;
388       }
389
390       rtp_storage_put_recovered_packet (self->storage,
391           recovered_buffer, recovered_pt, self->caps_ssrc, recovered_seq);
392     }
393
394     gst_rtp_ulpfec_dec_stop (self);
395     gst_buffer_list_unref (buflist);
396   }
397
398   GST_DEBUG_OBJECT (self, "Packet lost ssrc=0x%08x seq=%u", self->caps_ssrc,
399       seqnum);
400
401   return ret;
402 }
403
404 static gboolean
405 gst_rtp_ulpfec_dec_handle_sink_event (GstPad * pad, GstObject * parent,
406     GstEvent * event)
407 {
408   GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (parent);
409   gboolean forward = TRUE;
410
411   GST_LOG_OBJECT (self, "Received event %" GST_PTR_FORMAT, event);
412
413   if (GST_FLOW_OK == self->chain_return_val &&
414       GST_EVENT_CUSTOM_DOWNSTREAM == GST_EVENT_TYPE (event) &&
415       gst_event_has_name (event, "GstRTPPacketLost")) {
416     guint seqnum;
417     GstClockTime timestamp, duration;
418
419     g_assert (self->have_caps_ssrc);
420     g_assert (self->storage);
421
422     if (!gst_structure_get (gst_event_get_structure (event),
423             "seqnum", G_TYPE_UINT, &seqnum,
424             "timestamp", G_TYPE_UINT64, &timestamp,
425             "duration", G_TYPE_UINT64, &duration, NULL))
426       g_assert_not_reached ();
427
428     forward =
429         gst_rtp_ulpfec_dec_handle_packet_loss (self, seqnum, timestamp,
430         duration);
431     if (forward)
432       ++self->packets_unrecovered;
433     else
434       ++self->packets_recovered;
435     GST_DEBUG_OBJECT (self, "Unrecovered / Recovered: %lu / %lu",
436         (gulong) self->packets_unrecovered, (gulong) self->packets_recovered);
437   } else if (GST_EVENT_CAPS == GST_EVENT_TYPE (event)) {
438     GstCaps *caps;
439     gboolean have_caps_pt = FALSE;
440     gboolean have_caps_ssrc = FALSE;
441     guint caps_ssrc = 0;
442     gint caps_pt = 0;
443
444     gst_event_parse_caps (event, &caps);
445     have_caps_ssrc =
446         gst_structure_get_uint (gst_caps_get_structure (caps, 0), "ssrc",
447         &caps_ssrc);
448     have_caps_pt =
449         gst_structure_get_int (gst_caps_get_structure (caps, 0), "payload",
450         &caps_pt);
451
452     if (self->have_caps_ssrc != have_caps_ssrc || self->caps_ssrc != caps_ssrc)
453       GST_DEBUG_OBJECT (self, "SSRC changed %u, 0x%08x -> %u, 0x%08x",
454           self->have_caps_ssrc, self->caps_ssrc, have_caps_ssrc, caps_ssrc);
455     if (self->have_caps_pt != have_caps_pt || self->caps_pt != caps_pt)
456       GST_DEBUG_OBJECT (self, "PT changed %u, %u -> %u, %u",
457           self->have_caps_pt, self->caps_pt, have_caps_pt, caps_pt);
458
459     self->have_caps_ssrc = have_caps_ssrc;
460     self->have_caps_pt = have_caps_pt;
461     self->caps_ssrc = caps_ssrc;
462     self->caps_pt = caps_pt;
463   }
464
465   if (forward)
466     return gst_pad_push_event (self->srcpad, event);
467   gst_event_unref (event);
468   return TRUE;
469 }
470
471 static void
472 gst_rtp_ulpfec_dec_init (GstRtpUlpFecDec * self)
473 {
474   self->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
475   self->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
476   GST_PAD_SET_PROXY_CAPS (self->sinkpad);
477   GST_PAD_SET_PROXY_ALLOCATION (self->sinkpad);
478   gst_pad_set_chain_function (self->sinkpad,
479       GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_chain));
480   gst_pad_set_event_function (self->sinkpad,
481       GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_handle_sink_event));
482
483   gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
484   gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
485
486   self->fec_pt = DEFAULT_FEC_PT;
487
488   self->chain_return_val = GST_FLOW_OK;
489   self->have_caps_ssrc = FALSE;
490   self->caps_ssrc = 0;
491   self->info_fec = g_ptr_array_new ();
492   self->info_arr = g_array_new (FALSE, TRUE, sizeof (RtpUlpFecMapInfo));
493   g_array_set_clear_func (self->info_arr,
494       (GDestroyNotify) rtp_ulpfec_map_info_unmap);
495   self->scratch_buf = g_array_new (FALSE, TRUE, sizeof (guint8));
496 }
497
498 static void
499 gst_rtp_ulpfec_dec_dispose (GObject * obj)
500 {
501   GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (obj);
502
503   GST_INFO_OBJECT (self,
504       " ssrc=0x%08x pt=%u"
505       " packets_recovered=%" G_GSIZE_FORMAT
506       " packets_unrecovered=%" G_GSIZE_FORMAT,
507       self->caps_ssrc, self->caps_pt,
508       self->packets_recovered, self->packets_unrecovered);
509
510   if (self->storage)
511     g_object_unref (self->storage);
512
513   g_assert (NULL == self->info_media);
514   g_assert (0 == self->info_fec->len);
515   g_assert (0 == self->info_arr->len);
516
517   if (self->fec_packets_received) {
518     GST_INFO_OBJECT (self,
519         " fec_packets_received=%" G_GSIZE_FORMAT
520         " fec_packets_rejected=%" G_GSIZE_FORMAT
521         " packets_rejected=%" G_GSIZE_FORMAT,
522         self->fec_packets_received,
523         self->fec_packets_rejected, self->packets_rejected);
524   }
525
526   g_ptr_array_free (self->info_fec, TRUE);
527   g_array_free (self->info_arr, TRUE);
528   g_array_free (self->scratch_buf, TRUE);
529
530   G_OBJECT_CLASS (gst_rtp_ulpfec_dec_parent_class)->dispose (obj);
531 }
532
533 static void
534 gst_rtp_ulpfec_dec_set_property (GObject * object, guint prop_id,
535     const GValue * value, GParamSpec * pspec)
536 {
537   GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (object);
538
539   switch (prop_id) {
540     case PROP_PT:
541       self->fec_pt = g_value_get_uint (value);
542       break;
543     case PROP_STORAGE:
544       if (self->storage)
545         g_object_unref (self->storage);
546       self->storage = g_value_get_object (value);
547       if (self->storage)
548         g_object_ref (self->storage);
549       break;
550     default:
551       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
552       break;
553   }
554 }
555
556 static void
557 gst_rtp_ulpfec_dec_get_property (GObject * object, guint prop_id,
558     GValue * value, GParamSpec * pspec)
559 {
560   GstRtpUlpFecDec *self = GST_RTP_ULPFEC_DEC (object);
561
562   switch (prop_id) {
563     case PROP_PT:
564       g_value_set_uint (value, self->fec_pt);
565       break;
566     case PROP_STORAGE:
567       g_value_set_object (value, self->storage);
568       break;
569     case PROP_RECOVERED:
570       g_value_set_uint (value, (guint) self->packets_recovered);
571       break;
572     case PROP_UNRECOVERED:
573       g_value_set_uint (value, (guint) self->packets_unrecovered);
574       break;
575     default:
576       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
577       break;
578   }
579 }
580
581 static void
582 gst_rtp_ulpfec_dec_class_init (GstRtpUlpFecDecClass * klass)
583 {
584   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
585   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
586
587   GST_DEBUG_CATEGORY_INIT (gst_rtp_ulpfec_dec_debug,
588       "rtpulpfecdec", 0, "RTP FEC Decoder");
589
590   gst_element_class_add_pad_template (element_class,
591       gst_static_pad_template_get (&srctemplate));
592   gst_element_class_add_pad_template (element_class,
593       gst_static_pad_template_get (&sinktemplate));
594
595   gst_element_class_set_static_metadata (element_class,
596       "RTP FEC Decoder",
597       "Codec/Depayloader/Network/RTP",
598       "Decodes RTP FEC (RFC5109)", "Mikhail Fludkov <misha@pexip.com>");
599
600   gobject_class->set_property =
601       GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_set_property);
602   gobject_class->get_property =
603       GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_get_property);
604   gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_dispose);
605
606   klass_properties[PROP_PT] = g_param_spec_uint ("pt", "pt",
607       "FEC packets payload type", 0, 127,
608       DEFAULT_FEC_PT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
609   klass_properties[PROP_STORAGE] =
610       g_param_spec_object ("storage", "RTP storage", "RTP storage",
611       G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
612   klass_properties[PROP_RECOVERED] =
613       g_param_spec_uint ("recovered", "recovered",
614       "The number of recovered packets", 0, G_MAXUINT, 0,
615       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
616   klass_properties[PROP_UNRECOVERED] =
617       g_param_spec_uint ("unrecovered", "unrecovered",
618       "The number of unrecovered packets", 0, G_MAXUINT, 0,
619       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
620
621   g_object_class_install_properties (gobject_class, N_PROPERTIES,
622       klass_properties);
623 }