rtprtxsend: use a realistic limit for the value of max-size-packets
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / gstrtprtxsend.c
1 /* RTP Retransmission sender element for GStreamer
2  *
3  * gstrtprtxsend.c:
4  *
5  * Copyright (C) 2013 Collabora Ltd.
6  *   @author Julien Isorce <julien.isorce@collabora.co.uk>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 /**
25  * SECTION:element-rtprtxsend
26  *
27  * See #GstRtpRtxReceive for examples
28  * 
29  * The purpose of the sender RTX object is to keep a history of RTP packets up
30  * to a configurable limit (max-size-time or max-size-packets). It will listen
31  * for upstream custom retransmission events (GstRTPRetransmissionRequest) that
32  * comes from downstream (#GstRtpSession). When receiving a request it will
33  * look up the requested seqnum in its list of stored packets. If the packet
34  * is available, it will create a RTX packet according to RFC 4588 and send
35  * this as an auxiliary stream. RTX is SSRC-multiplexed
36  */
37
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
41
42 #include <gst/gst.h>
43 #include <gst/rtp/gstrtpbuffer.h>
44 #include <string.h>
45
46 #include "gstrtprtxsend.h"
47
48 GST_DEBUG_CATEGORY_STATIC (gst_rtp_rtx_send_debug);
49 #define GST_CAT_DEFAULT gst_rtp_rtx_send_debug
50
51 #define DEFAULT_RTX_PAYLOAD_TYPE 0
52 #define DEFAULT_MAX_SIZE_TIME    0
53 #define DEFAULT_MAX_SIZE_PACKETS 100
54
55 enum
56 {
57   PROP_0,
58   PROP_RTX_PAYLOAD_TYPE,
59   PROP_MAX_SIZE_TIME,
60   PROP_MAX_SIZE_PACKETS,
61   PROP_NUM_RTX_REQUESTS,
62   PROP_NUM_RTX_PACKETS,
63   PROP_LAST
64 };
65
66 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
67     GST_PAD_SRC,
68     GST_PAD_ALWAYS,
69     GST_STATIC_CAPS ("application/x-rtp")
70     );
71
72 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
73     GST_PAD_SINK,
74     GST_PAD_ALWAYS,
75     GST_STATIC_CAPS ("application/x-rtp")
76     );
77
78 static gboolean gst_rtp_rtx_send_src_event (GstPad * pad, GstObject * parent,
79     GstEvent * event);
80 static gboolean gst_rtp_rtx_send_sink_event (GstPad * pad, GstObject * parent,
81     GstEvent * event);
82 static GstFlowReturn gst_rtp_rtx_send_chain (GstPad * pad, GstObject * parent,
83     GstBuffer * buffer);
84
85 static GstStateChangeReturn gst_rtp_rtx_send_change_state (GstElement *
86     element, GstStateChange transition);
87
88 static void gst_rtp_rtx_send_set_property (GObject * object, guint prop_id,
89     const GValue * value, GParamSpec * pspec);
90 static void gst_rtp_rtx_send_get_property (GObject * object, guint prop_id,
91     GValue * value, GParamSpec * pspec);
92 static void gst_rtp_rtx_send_finalize (GObject * object);
93
94 G_DEFINE_TYPE (GstRtpRtxSend, gst_rtp_rtx_send, GST_TYPE_ELEMENT);
95
96 typedef struct
97 {
98   guint16 seqnum;
99   guint32 timestamp;
100   GstBuffer *buffer;
101 } BufferQueueItem;
102
103 static void
104 buffer_queue_item_free (BufferQueueItem * item)
105 {
106   gst_buffer_unref (item->buffer);
107   g_free (item);
108 }
109
110 static void
111 gst_rtp_rtx_send_class_init (GstRtpRtxSendClass * klass)
112 {
113   GObjectClass *gobject_class;
114   GstElementClass *gstelement_class;
115
116   gobject_class = (GObjectClass *) klass;
117   gstelement_class = (GstElementClass *) klass;
118
119   gobject_class->get_property = gst_rtp_rtx_send_get_property;
120   gobject_class->set_property = gst_rtp_rtx_send_set_property;
121   gobject_class->finalize = gst_rtp_rtx_send_finalize;
122
123   g_object_class_install_property (gobject_class, PROP_RTX_PAYLOAD_TYPE,
124       g_param_spec_uint ("rtx-payload-type", "RTX Payload Type",
125           "Payload type of the retransmission stream (fmtp in SDP)", 0,
126           G_MAXUINT, DEFAULT_RTX_PAYLOAD_TYPE,
127           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
128
129   g_object_class_install_property (gobject_class, PROP_MAX_SIZE_TIME,
130       g_param_spec_uint ("max-size-time", "Max Size Time",
131           "Amount of ms to queue (0 = unlimited)", 0, G_MAXUINT,
132           DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
133
134   g_object_class_install_property (gobject_class, PROP_MAX_SIZE_PACKETS,
135       g_param_spec_uint ("max-size-packets", "Max Size Packets",
136           "Amount of packets to queue (0 = unlimited)", 0, G_MAXINT16,
137           DEFAULT_MAX_SIZE_PACKETS,
138           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
139
140   g_object_class_install_property (gobject_class, PROP_NUM_RTX_REQUESTS,
141       g_param_spec_uint ("num-rtx-requests", "Num RTX Requests",
142           "Number of retransmission events received", 0, G_MAXUINT,
143           0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
144
145   g_object_class_install_property (gobject_class, PROP_NUM_RTX_PACKETS,
146       g_param_spec_uint ("num-rtx-packets", "Num RTX Packets",
147           " Number of retransmission packets sent", 0, G_MAXUINT,
148           0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
149
150   gst_element_class_add_pad_template (gstelement_class,
151       gst_static_pad_template_get (&src_factory));
152   gst_element_class_add_pad_template (gstelement_class,
153       gst_static_pad_template_get (&sink_factory));
154
155   gst_element_class_set_static_metadata (gstelement_class,
156       "RTP Retransmission Sender", "Codec",
157       "Retransmit RTP packets when needed, according to RFC4588",
158       "Julien Isorce <julien.isorce@collabora.co.uk>");
159
160   gstelement_class->change_state =
161       GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_change_state);
162 }
163
164 static void
165 gst_rtp_rtx_send_reset (GstRtpRtxSend * rtx, gboolean full)
166 {
167   g_mutex_lock (&rtx->lock);
168   g_sequence_remove_range (g_sequence_get_begin_iter (rtx->queue),
169       g_sequence_get_end_iter (rtx->queue));
170   g_queue_foreach (rtx->pending, (GFunc) gst_buffer_unref, NULL);
171   g_queue_clear (rtx->pending);
172   rtx->master_ssrc = 0;
173   rtx->next_seqnum = g_random_int_range (0, G_MAXUINT16);
174   rtx->rtx_ssrc = g_random_int ();
175   rtx->num_rtx_requests = 0;
176   rtx->num_rtx_packets = 0;
177   g_mutex_unlock (&rtx->lock);
178 }
179
180 static void
181 gst_rtp_rtx_send_finalize (GObject * object)
182 {
183   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
184
185   gst_rtp_rtx_send_reset (rtx, TRUE);
186   g_sequence_free (rtx->queue);
187   g_queue_free (rtx->pending);
188   g_mutex_clear (&rtx->lock);
189
190   G_OBJECT_CLASS (gst_rtp_rtx_send_parent_class)->finalize (object);
191 }
192
193 static void
194 gst_rtp_rtx_send_init (GstRtpRtxSend * rtx)
195 {
196   GstElementClass *klass = GST_ELEMENT_GET_CLASS (rtx);
197
198   rtx->srcpad =
199       gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
200           "src"), "src");
201   GST_PAD_SET_PROXY_CAPS (rtx->srcpad);
202   GST_PAD_SET_PROXY_ALLOCATION (rtx->srcpad);
203   gst_pad_set_event_function (rtx->srcpad,
204       GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_src_event));
205   gst_element_add_pad (GST_ELEMENT (rtx), rtx->srcpad);
206
207   rtx->sinkpad =
208       gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
209           "sink"), "sink");
210   GST_PAD_SET_PROXY_CAPS (rtx->sinkpad);
211   GST_PAD_SET_PROXY_ALLOCATION (rtx->sinkpad);
212   gst_pad_set_event_function (rtx->sinkpad,
213       GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_sink_event));
214   gst_pad_set_chain_function (rtx->sinkpad,
215       GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_chain));
216   gst_element_add_pad (GST_ELEMENT (rtx), rtx->sinkpad);
217
218   rtx->queue = g_sequence_new ((GDestroyNotify) buffer_queue_item_free);
219   rtx->pending = g_queue_new ();
220   g_mutex_init (&rtx->lock);
221
222   rtx->next_seqnum = g_random_int_range (0, G_MAXUINT16);
223   rtx->rtx_ssrc = g_random_int ();
224
225   rtx->max_size_time = DEFAULT_MAX_SIZE_TIME;
226   rtx->max_size_packets = DEFAULT_MAX_SIZE_PACKETS;
227 }
228
229 static guint32
230 choose_ssrc (GstRtpRtxSend * rtx)
231 {
232   guint32 ssrc;
233
234   while (TRUE) {
235     ssrc = g_random_int ();
236
237     /* make sure to be different than master */
238     if (ssrc != rtx->master_ssrc)
239       break;
240   }
241   return ssrc;
242 }
243
244 static gint
245 buffer_queue_items_cmp (BufferQueueItem * a, BufferQueueItem * b,
246     gpointer user_data)
247 {
248   /* gst_rtp_buffer_compare_seqnum returns the opposite of what we want,
249    * it returns negative when seqnum1 > seqnum2 and we want negative
250    * when b > a, i.e. a is smaller, so it comes first in the sequence */
251   return gst_rtp_buffer_compare_seqnum (b->seqnum, a->seqnum);
252 }
253
254 static gboolean
255 gst_rtp_rtx_send_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
256 {
257   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
258   gboolean res;
259
260   switch (GST_EVENT_TYPE (event)) {
261     case GST_EVENT_CUSTOM_UPSTREAM:
262     {
263       const GstStructure *s = gst_event_get_structure (event);
264
265       /* This event usually comes from the downstream gstrtpsession */
266       if (gst_structure_has_name (s, "GstRTPRetransmissionRequest")) {
267         guint32 seqnum = 0;
268         guint ssrc = 0;
269
270         /* retrieve seqnum of the packet that need to be restransmisted */
271         if (!gst_structure_get_uint (s, "seqnum", &seqnum))
272           seqnum = -1;
273
274         /* retrieve ssrc of the packet that need to be restransmisted */
275         if (!gst_structure_get_uint (s, "ssrc", &ssrc))
276           ssrc = -1;
277
278         GST_DEBUG_OBJECT (rtx,
279             "request seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT,
280             seqnum, ssrc);
281
282         g_mutex_lock (&rtx->lock);
283         /* check if request is for us */
284         if (rtx->master_ssrc == ssrc) {
285           GSequenceIter *iter;
286           BufferQueueItem search_item;
287
288           /* update statistics */
289           ++rtx->num_rtx_requests;
290
291           search_item.seqnum = seqnum;
292           iter = g_sequence_lookup (rtx->queue, &search_item,
293               (GCompareDataFunc) buffer_queue_items_cmp, NULL);
294           if (iter) {
295             BufferQueueItem *item = g_sequence_get (iter);
296             GST_DEBUG_OBJECT (rtx, "found %" G_GUINT16_FORMAT, item->seqnum);
297             g_queue_push_tail (rtx->pending, gst_buffer_ref (item->buffer));
298           }
299         }
300         g_mutex_unlock (&rtx->lock);
301
302         gst_event_unref (event);
303         res = TRUE;
304
305         /* This event usually comes from the downstream gstrtpsession */
306       } else if (gst_structure_has_name (s, "GstRTPCollision")) {
307         guint ssrc = 0;
308
309         if (!gst_structure_get_uint (s, "ssrc", &ssrc))
310           ssrc = -1;
311
312         GST_DEBUG_OBJECT (rtx, "collision ssrc: %" G_GUINT32_FORMAT, ssrc);
313
314         g_mutex_lock (&rtx->lock);
315
316         /* choose another ssrc for our retransmited stream */
317         if (ssrc == rtx->rtx_ssrc) {
318           rtx->rtx_ssrc = choose_ssrc (rtx);
319
320           /* clear buffers we already saved */
321           g_sequence_remove_range (g_sequence_get_begin_iter (rtx->queue),
322               g_sequence_get_end_iter (rtx->queue));
323
324           /* clear buffers that are about to be retransmited */
325           g_queue_foreach (rtx->pending, (GFunc) gst_buffer_unref, NULL);
326           g_queue_clear (rtx->pending);
327
328           g_mutex_unlock (&rtx->lock);
329
330           /* no need to forward to payloader because we make sure to have
331            * a different ssrc
332            */
333           gst_event_unref (event);
334           res = TRUE;
335         } else {
336           g_mutex_unlock (&rtx->lock);
337
338           /* forward event to payloader in case collided ssrc is
339            * master stream */
340           res = gst_pad_event_default (pad, parent, event);
341         }
342       } else {
343         res = gst_pad_event_default (pad, parent, event);
344       }
345       break;
346     }
347     default:
348       res = gst_pad_event_default (pad, parent, event);
349       break;
350   }
351   return res;
352 }
353
354 static gboolean
355 gst_rtp_rtx_send_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
356 {
357   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
358
359   switch (GST_EVENT_TYPE (event)) {
360     case GST_EVENT_CAPS:
361     {
362       GstCaps *caps;
363       GstStructure *s;
364
365       gst_event_parse_caps (event, &caps);
366       g_assert (gst_caps_is_fixed (caps));
367
368       s = gst_caps_get_structure (caps, 0);
369       gst_structure_get_int (s, "clock-rate", &rtx->clock_rate);
370
371       GST_DEBUG_OBJECT (rtx, "got clock-rate from caps: %d", rtx->clock_rate);
372
373       break;
374     }
375     default:
376       break;
377   }
378   return gst_pad_event_default (pad, parent, event);
379 }
380
381 /* like rtp_jitter_buffer_get_ts_diff() */
382 static guint32
383 gst_rtp_rtx_send_get_ts_diff (GstRtpRtxSend * self)
384 {
385   guint64 high_ts, low_ts;
386   BufferQueueItem *high_buf, *low_buf;
387   guint32 result;
388
389   high_buf =
390       g_sequence_get (g_sequence_iter_prev (g_sequence_get_end_iter
391           (self->queue)));
392   low_buf = g_sequence_get (g_sequence_get_begin_iter (self->queue));
393
394   if (!high_buf || !low_buf || high_buf == low_buf)
395     return 0;
396
397   high_ts = high_buf->timestamp;
398   low_ts = low_buf->timestamp;
399
400   /* it needs to work if ts wraps */
401   if (high_ts >= low_ts) {
402     result = (guint32) (high_ts - low_ts);
403   } else {
404     result = (guint32) (high_ts + G_MAXUINT32 + 1 - low_ts);
405   }
406
407   /* return value in ms instead of clock ticks */
408   return (guint32) gst_util_uint64_scale_int (result, 1000, self->clock_rate);
409 }
410
411 /* Copy fixed header and extension. Add OSN before to copy payload
412  * Copy memory to avoid to manually copy each rtp buffer field.
413  */
414 static GstBuffer *
415 _gst_rtp_rtx_buffer_new (GstBuffer * buffer, guint32 ssrc, guint16 seqnum,
416     guint8 fmtp)
417 {
418   GstMemory *mem = NULL;
419   GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
420   GstRTPBuffer new_rtp = GST_RTP_BUFFER_INIT;
421   GstBuffer *new_buffer = gst_buffer_new ();
422   GstMapInfo map;
423   guint payload_len = 0;
424
425   gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp);
426
427   /* gst_rtp_buffer_map does not map the payload so do it now */
428   gst_rtp_buffer_get_payload (&rtp);
429
430   /* If payload type is not set through SDP/property then
431    * just bump the value */
432   if (fmtp < 96)
433     fmtp = gst_rtp_buffer_get_payload_type (&rtp) + 1;
434
435   /* copy fixed header */
436   mem = gst_memory_copy (rtp.map[0].memory, 0, rtp.size[0]);
437   gst_buffer_append_memory (new_buffer, mem);
438
439   /* copy extension if any */
440   if (rtp.size[1]) {
441     mem = gst_memory_copy (rtp.map[1].memory, 0, rtp.size[1]);
442     gst_buffer_append_memory (new_buffer, mem);
443   }
444
445   /* copy payload and add OSN just before */
446   payload_len = 2 + rtp.size[2];
447   mem = gst_allocator_alloc (NULL, payload_len, NULL);
448
449   gst_memory_map (mem, &map, GST_MAP_WRITE);
450   GST_WRITE_UINT16_BE (map.data, gst_rtp_buffer_get_seq (&rtp));
451   if (rtp.size[2])
452     memcpy (map.data + 2, rtp.data[2], rtp.size[2]);
453   gst_memory_unmap (mem, &map);
454   gst_buffer_append_memory (new_buffer, mem);
455
456   /* everything needed is copied */
457   gst_rtp_buffer_unmap (&rtp);
458
459   /* set ssrc, seqnum and fmtp */
460   gst_rtp_buffer_map (new_buffer, GST_MAP_WRITE, &new_rtp);
461   gst_rtp_buffer_set_ssrc (&new_rtp, ssrc);
462   gst_rtp_buffer_set_seq (&new_rtp, seqnum);
463   gst_rtp_buffer_set_payload_type (&new_rtp, fmtp);
464   /* RFC 4588: let other elements do the padding, as normal */
465   gst_rtp_buffer_set_padding (&new_rtp, FALSE);
466   gst_rtp_buffer_unmap (&new_rtp);
467
468   return new_buffer;
469 }
470
471 /* push pending retransmission packet.
472  * it constructs rtx packet from original paclets */
473 static void
474 do_push (GstBuffer * buffer, GstRtpRtxSend * rtx)
475 {
476   /* RFC4588 two streams multiplexed by sending them in the same session using
477    * different SSRC values, i.e., SSRC-multiplexing.  */
478   GST_DEBUG_OBJECT (rtx,
479       "retransmit seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT,
480       rtx->next_seqnum, rtx->rtx_ssrc);
481   gst_pad_push (rtx->srcpad, _gst_rtp_rtx_buffer_new (buffer, rtx->rtx_ssrc,
482           rtx->next_seqnum++, rtx->rtx_payload_type));
483 }
484
485 static GstFlowReturn
486 gst_rtp_rtx_send_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
487 {
488   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
489   GstFlowReturn ret = GST_FLOW_ERROR;
490   GQueue *pending = NULL;
491   GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
492   BufferQueueItem *item;
493   guint16 seqnum;
494   guint32 ssrc, rtptime;
495
496   rtx = GST_RTP_RTX_SEND (parent);
497
498   /* read the information we want from the buffer */
499   gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp);
500   seqnum = gst_rtp_buffer_get_seq (&rtp);
501   ssrc = gst_rtp_buffer_get_ssrc (&rtp);
502   rtptime = gst_rtp_buffer_get_timestamp (&rtp);
503   gst_rtp_buffer_unmap (&rtp);
504
505   g_mutex_lock (&rtx->lock);
506
507   /* retrieve master stream ssrc */
508   rtx->master_ssrc = ssrc;
509   /* check if our initial aux ssrc is equal to master */
510   if (rtx->rtx_ssrc == rtx->master_ssrc)
511     choose_ssrc (rtx);
512
513   /* add current rtp buffer to queue history */
514   item = g_new0 (BufferQueueItem, 1);
515   item->seqnum = seqnum;
516   item->timestamp = rtptime;
517   item->buffer = gst_buffer_ref (buffer);
518   g_sequence_append (rtx->queue, item);
519
520   /* remove oldest packets from history if they are too many */
521   if (rtx->max_size_packets) {
522     while (g_sequence_get_length (rtx->queue) > rtx->max_size_packets)
523       g_sequence_remove (g_sequence_get_begin_iter (rtx->queue));
524   }
525   if (rtx->max_size_time) {
526     while (gst_rtp_rtx_send_get_ts_diff (rtx) > rtx->max_size_time)
527       g_sequence_remove (g_sequence_get_begin_iter (rtx->queue));
528   }
529
530   /* within lock, get packets that have to be retransmited */
531   if (g_queue_get_length (rtx->pending) > 0) {
532     pending = rtx->pending;
533     rtx->pending = g_queue_new ();
534
535     /* update statistics - assume we will succeed to retransmit those packets */
536     rtx->num_rtx_packets += g_queue_get_length (pending);
537   }
538
539   /* transfer payload type while holding the lock */
540   rtx->rtx_payload_type = rtx->rtx_payload_type_pending;
541
542   /* no need to hold the lock to push rtx packets */
543   g_mutex_unlock (&rtx->lock);
544
545   /* retransmit requested packets */
546   if (pending) {
547     g_queue_foreach (pending, (GFunc) do_push, rtx);
548     g_queue_free_full (pending, (GDestroyNotify) gst_buffer_unref);
549   }
550
551   GST_LOG_OBJECT (rtx,
552       "push seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT, seqnum,
553       rtx->master_ssrc);
554
555   /* push current rtp packet */
556   ret = gst_pad_push (rtx->srcpad, buffer);
557
558   return ret;
559 }
560
561 static void
562 gst_rtp_rtx_send_get_property (GObject * object,
563     guint prop_id, GValue * value, GParamSpec * pspec)
564 {
565   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
566
567   switch (prop_id) {
568     case PROP_RTX_PAYLOAD_TYPE:
569       g_mutex_lock (&rtx->lock);
570       g_value_set_uint (value, rtx->rtx_payload_type_pending);
571       g_mutex_unlock (&rtx->lock);
572       break;
573     case PROP_MAX_SIZE_TIME:
574       g_mutex_lock (&rtx->lock);
575       g_value_set_uint (value, rtx->max_size_time);
576       g_mutex_unlock (&rtx->lock);
577       break;
578     case PROP_MAX_SIZE_PACKETS:
579       g_mutex_lock (&rtx->lock);
580       g_value_set_uint (value, rtx->max_size_packets);
581       g_mutex_unlock (&rtx->lock);
582       break;
583     case PROP_NUM_RTX_REQUESTS:
584       g_mutex_lock (&rtx->lock);
585       g_value_set_uint (value, rtx->num_rtx_requests);
586       g_mutex_unlock (&rtx->lock);
587       break;
588     case PROP_NUM_RTX_PACKETS:
589       g_mutex_lock (&rtx->lock);
590       g_value_set_uint (value, rtx->num_rtx_packets);
591       g_mutex_unlock (&rtx->lock);
592       break;
593     default:
594       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
595       break;
596   }
597 }
598
599 static void
600 gst_rtp_rtx_send_set_property (GObject * object,
601     guint prop_id, const GValue * value, GParamSpec * pspec)
602 {
603   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
604
605   switch (prop_id) {
606     case PROP_RTX_PAYLOAD_TYPE:
607       g_mutex_lock (&rtx->lock);
608       rtx->rtx_payload_type_pending = g_value_get_uint (value);
609       g_mutex_unlock (&rtx->lock);
610       break;
611     case PROP_MAX_SIZE_TIME:
612       g_mutex_lock (&rtx->lock);
613       rtx->max_size_time = g_value_get_uint (value);
614       g_mutex_unlock (&rtx->lock);
615       break;
616     case PROP_MAX_SIZE_PACKETS:
617       g_mutex_lock (&rtx->lock);
618       rtx->max_size_packets = g_value_get_uint (value);
619       g_mutex_unlock (&rtx->lock);
620       break;
621     default:
622       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
623       break;
624   }
625 }
626
627 static GstStateChangeReturn
628 gst_rtp_rtx_send_change_state (GstElement * element, GstStateChange transition)
629 {
630   GstStateChangeReturn ret;
631   GstRtpRtxSend *rtx;
632
633   rtx = GST_RTP_RTX_SEND (element);
634
635   switch (transition) {
636     default:
637       break;
638   }
639
640   ret =
641       GST_ELEMENT_CLASS (gst_rtp_rtx_send_parent_class)->change_state (element,
642       transition);
643
644   switch (transition) {
645     case GST_STATE_CHANGE_PAUSED_TO_READY:
646       gst_rtp_rtx_send_reset (rtx, TRUE);
647       break;
648     default:
649       break;
650   }
651
652   return ret;
653 }
654
655 gboolean
656 gst_rtp_rtx_send_plugin_init (GstPlugin * plugin)
657 {
658   GST_DEBUG_CATEGORY_INIT (gst_rtp_rtx_send_debug, "rtprtxsend", 0,
659       "rtp retransmission sender");
660
661   return gst_element_register (plugin, "rtprtxsend", GST_RANK_NONE,
662       GST_TYPE_RTP_RTX_SEND);
663 }