rtprtxsend: Handle the max_size_time property
[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_MAXUINT,
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_queue_foreach (rtx->queue, (GFunc) buffer_queue_item_free, NULL);
169   g_queue_clear (rtx->queue);
170   g_list_foreach (rtx->pending, (GFunc) gst_buffer_unref, NULL);
171   g_list_free (rtx->pending);
172   rtx->pending = NULL;
173   rtx->master_ssrc = 0;
174   rtx->next_seqnum = g_random_int_range (0, G_MAXUINT16);
175   rtx->rtx_ssrc = g_random_int ();
176   rtx->num_rtx_requests = 0;
177   rtx->num_rtx_packets = 0;
178   g_mutex_unlock (&rtx->lock);
179 }
180
181 static void
182 gst_rtp_rtx_send_finalize (GObject * object)
183 {
184   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
185
186   gst_rtp_rtx_send_reset (rtx, TRUE);
187   g_queue_free (rtx->queue);
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_queue_new ();
219   rtx->pending = NULL;
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 typedef struct
245 {
246   GstRtpRtxSend *rtx;
247   guint seqnum;
248   gboolean found;
249 } RTXData;
250
251 /* traverse queue history and try to find the buffer that the
252  * requested seqnum */
253 static void
254 push_seqnum (BufferQueueItem * item, RTXData * data)
255 {
256   GstRtpRtxSend *rtx = data->rtx;
257
258   if (data->found)
259     return;
260
261   /* data->seqnum comes from the request */
262   if (item->seqnum == data->seqnum) {
263     data->found = TRUE;
264     GST_DEBUG_OBJECT (rtx, "found %" G_GUINT16_FORMAT, item->seqnum);
265     rtx->pending = g_list_prepend (rtx->pending, gst_buffer_ref (item->buffer));
266   }
267 }
268
269 static gboolean
270 gst_rtp_rtx_send_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
271 {
272   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
273   gboolean res;
274
275   switch (GST_EVENT_TYPE (event)) {
276     case GST_EVENT_CUSTOM_UPSTREAM:
277     {
278       const GstStructure *s = gst_event_get_structure (event);
279
280       /* This event usually comes from the downstream gstrtpsession */
281       if (gst_structure_has_name (s, "GstRTPRetransmissionRequest")) {
282         guint32 seqnum = 0;
283         guint ssrc = 0;
284         RTXData data;
285
286         /* retrieve seqnum of the packet that need to be restransmisted */
287         if (!gst_structure_get_uint (s, "seqnum", &seqnum))
288           seqnum = -1;
289
290         /* retrieve ssrc of the packet that need to be restransmisted */
291         if (!gst_structure_get_uint (s, "ssrc", &ssrc))
292           ssrc = -1;
293
294         GST_DEBUG_OBJECT (rtx,
295             "request seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT,
296             seqnum, ssrc);
297
298         g_mutex_lock (&rtx->lock);
299         /* check if request is for us */
300         if (rtx->master_ssrc == ssrc) {
301           ++rtx->num_rtx_requests;
302           data.rtx = rtx;
303           data.seqnum = seqnum;
304           data.found = FALSE;
305           /* TODO do a binary search because rtx->queue is sorted by seq num */
306           g_queue_foreach (rtx->queue, (GFunc) push_seqnum, &data);
307         }
308         g_mutex_unlock (&rtx->lock);
309
310         gst_event_unref (event);
311         res = TRUE;
312
313         /* This event usually comes from the downstream gstrtpsession */
314       } else if (gst_structure_has_name (s, "GstRTPCollision")) {
315         guint ssrc = 0;
316
317         if (!gst_structure_get_uint (s, "ssrc", &ssrc))
318           ssrc = -1;
319
320         GST_DEBUG_OBJECT (rtx, "collision ssrc: %" G_GUINT32_FORMAT, ssrc);
321
322         g_mutex_lock (&rtx->lock);
323
324         /* choose another ssrc for our retransmited stream */
325         if (ssrc == rtx->rtx_ssrc) {
326           rtx->rtx_ssrc = choose_ssrc (rtx);
327
328           /* clear buffers we already saved */
329           g_queue_foreach (rtx->queue, (GFunc) gst_buffer_unref, NULL);
330           g_queue_clear (rtx->queue);
331
332           /* clear buffers that are about to be retransmited */
333           g_list_foreach (rtx->pending, (GFunc) gst_buffer_unref, NULL);
334           g_list_free (rtx->pending);
335           rtx->pending = NULL;
336
337           g_mutex_unlock (&rtx->lock);
338
339           /* no need to forward to payloader because we make sure to have
340            * a different ssrc
341            */
342           gst_event_unref (event);
343           res = TRUE;
344         } else {
345           g_mutex_unlock (&rtx->lock);
346
347           /* forward event to payloader in case collided ssrc is
348            * master stream */
349           res = gst_pad_event_default (pad, parent, event);
350         }
351       } else {
352         res = gst_pad_event_default (pad, parent, event);
353       }
354       break;
355     }
356     default:
357       res = gst_pad_event_default (pad, parent, event);
358       break;
359   }
360   return res;
361 }
362
363 static gboolean
364 gst_rtp_rtx_send_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
365 {
366   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
367
368   switch (GST_EVENT_TYPE (event)) {
369     case GST_EVENT_CAPS:
370     {
371       GstCaps *caps;
372       GstStructure *s;
373
374       gst_event_parse_caps (event, &caps);
375       g_assert (gst_caps_is_fixed (caps));
376
377       s = gst_caps_get_structure (caps, 0);
378       gst_structure_get_int (s, "clock-rate", &rtx->clock_rate);
379
380       GST_DEBUG_OBJECT (rtx, "got clock-rate from caps: %d", rtx->clock_rate);
381
382       break;
383     }
384     default:
385       break;
386   }
387   return gst_pad_event_default (pad, parent, event);
388 }
389
390 /* like rtp_jitter_buffer_get_ts_diff() */
391 static guint32
392 gst_rtp_rtx_send_get_ts_diff (GstRtpRtxSend * self)
393 {
394   guint64 high_ts, low_ts;
395   BufferQueueItem *high_buf, *low_buf;
396   guint32 result;
397
398   high_buf = g_queue_peek_head (self->queue);
399   low_buf = g_queue_peek_tail (self->queue);
400
401   if (!high_buf || !low_buf || high_buf == low_buf)
402     return 0;
403
404   high_ts = high_buf->timestamp;
405   low_ts = low_buf->timestamp;
406
407   /* it needs to work if ts wraps */
408   if (high_ts >= low_ts) {
409     result = (guint32) (high_ts - low_ts);
410   } else {
411     result = (guint32) (high_ts + G_MAXUINT32 + 1 - low_ts);
412   }
413
414   /* return value in ms instead of clock ticks */
415   return (guint32) gst_util_uint64_scale_int (result, 1000, self->clock_rate);
416 }
417
418 /* Copy fixed header and extension. Add OSN before to copy payload
419  * Copy memory to avoid to manually copy each rtp buffer field.
420  */
421 static GstBuffer *
422 _gst_rtp_rtx_buffer_new (GstBuffer * buffer, guint32 ssrc, guint16 seqnum,
423     guint8 fmtp)
424 {
425   GstMemory *mem = NULL;
426   GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
427   GstRTPBuffer new_rtp = GST_RTP_BUFFER_INIT;
428   GstBuffer *new_buffer = gst_buffer_new ();
429   GstMapInfo map;
430   guint payload_len = 0;
431
432   gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp);
433
434   /* gst_rtp_buffer_map does not map the payload so do it now */
435   gst_rtp_buffer_get_payload (&rtp);
436
437   /* If payload type is not set through SDP/property then
438    * just bump the value */
439   if (fmtp < 96)
440     fmtp = gst_rtp_buffer_get_payload_type (&rtp) + 1;
441
442   /* copy fixed header */
443   mem = gst_memory_copy (rtp.map[0].memory, 0, rtp.size[0]);
444   gst_buffer_append_memory (new_buffer, mem);
445
446   /* copy extension if any */
447   if (rtp.size[1]) {
448     mem = gst_memory_copy (rtp.map[1].memory, 0, rtp.size[1]);
449     gst_buffer_append_memory (new_buffer, mem);
450   }
451
452   /* copy payload and add OSN just before */
453   payload_len = 2 + rtp.size[2];
454   mem = gst_allocator_alloc (NULL, payload_len, NULL);
455
456   gst_memory_map (mem, &map, GST_MAP_WRITE);
457   GST_WRITE_UINT16_BE (map.data, gst_rtp_buffer_get_seq (&rtp));
458   if (rtp.size[2])
459     memcpy (map.data + 2, rtp.data[2], rtp.size[2]);
460   gst_memory_unmap (mem, &map);
461   gst_buffer_append_memory (new_buffer, mem);
462
463   /* everything needed is copied */
464   gst_rtp_buffer_unmap (&rtp);
465
466   /* set ssrc, seqnum and fmtp */
467   gst_rtp_buffer_map (new_buffer, GST_MAP_WRITE, &new_rtp);
468   gst_rtp_buffer_set_ssrc (&new_rtp, ssrc);
469   gst_rtp_buffer_set_seq (&new_rtp, seqnum);
470   gst_rtp_buffer_set_payload_type (&new_rtp, fmtp);
471   /* RFC 4588: let other elements do the padding, as normal */
472   gst_rtp_buffer_set_padding (&new_rtp, FALSE);
473   gst_rtp_buffer_unmap (&new_rtp);
474
475   return new_buffer;
476 }
477
478 /* psuh pending retransmission packet.
479  * it constructs rtx packet from original paclets */
480 static void
481 do_push (GstBuffer * buffer, GstRtpRtxSend * rtx)
482 {
483   /* RFC4588 two streams multiplexed by sending them in the same session using
484    * different SSRC values, i.e., SSRC-multiplexing.  */
485   GST_DEBUG_OBJECT (rtx,
486       "retransmit seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT,
487       rtx->next_seqnum, rtx->rtx_ssrc);
488   gst_pad_push (rtx->srcpad, _gst_rtp_rtx_buffer_new (buffer, rtx->rtx_ssrc,
489           rtx->next_seqnum++, rtx->rtx_payload_type));
490 }
491
492 static GstFlowReturn
493 gst_rtp_rtx_send_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
494 {
495   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
496   GstFlowReturn ret = GST_FLOW_ERROR;
497   GList *pending = NULL;
498   GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
499   BufferQueueItem *item;
500   guint16 seqnum;
501   guint32 ssrc, rtptime;
502
503   rtx = GST_RTP_RTX_SEND (parent);
504
505   /* read the information we want from the buffer */
506   gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp);
507   seqnum = gst_rtp_buffer_get_seq (&rtp);
508   ssrc = gst_rtp_buffer_get_ssrc (&rtp);
509   rtptime = gst_rtp_buffer_get_timestamp (&rtp);
510   gst_rtp_buffer_unmap (&rtp);
511
512   g_mutex_lock (&rtx->lock);
513
514   /* retrieve master stream ssrc */
515   rtx->master_ssrc = ssrc;
516   /* check if our initial aux ssrc is equal to master */
517   if (rtx->rtx_ssrc == rtx->master_ssrc)
518     choose_ssrc (rtx);
519
520   /* add current rtp buffer to queue history */
521   item = g_new0 (BufferQueueItem, 1);
522   item->seqnum = seqnum;
523   item->timestamp = rtptime;
524   item->buffer = gst_buffer_ref (buffer);
525   g_queue_push_head (rtx->queue, item);
526
527   /* remove oldest packets from history if they are too many */
528   if (rtx->max_size_packets) {
529     while (g_queue_get_length (rtx->queue) > rtx->max_size_packets)
530       buffer_queue_item_free (g_queue_pop_tail (rtx->queue));
531   }
532   if (rtx->max_size_time) {
533     while (gst_rtp_rtx_send_get_ts_diff (rtx) > rtx->max_size_time)
534       buffer_queue_item_free (g_queue_pop_tail (rtx->queue));
535   }
536
537   /* within lock, get packets that have to be retransmited */
538   pending = rtx->pending;
539   rtx->pending = NULL;
540
541   /* update statistics - assume we will succeed to retransmit those packets */
542   rtx->num_rtx_packets += g_list_length (pending);
543
544   /* transfer payload type while holding the lock */
545   rtx->rtx_payload_type = rtx->rtx_payload_type_pending;
546
547   /* no need to hold the lock to push rtx packets */
548   g_mutex_unlock (&rtx->lock);
549
550   /* retransmit requested packets */
551   g_list_foreach (pending, (GFunc) do_push, rtx);
552   g_list_foreach (pending, (GFunc) gst_buffer_unref, NULL);
553   g_list_free (pending);
554
555   GST_LOG_OBJECT (rtx,
556       "push seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT, seqnum,
557       rtx->master_ssrc);
558
559   /* push current rtp packet */
560   ret = gst_pad_push (rtx->srcpad, buffer);
561
562   return ret;
563 }
564
565 static void
566 gst_rtp_rtx_send_get_property (GObject * object,
567     guint prop_id, GValue * value, GParamSpec * pspec)
568 {
569   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
570
571   switch (prop_id) {
572     case PROP_RTX_PAYLOAD_TYPE:
573       g_mutex_lock (&rtx->lock);
574       g_value_set_uint (value, rtx->rtx_payload_type_pending);
575       g_mutex_unlock (&rtx->lock);
576       break;
577     case PROP_MAX_SIZE_TIME:
578       g_mutex_lock (&rtx->lock);
579       g_value_set_uint (value, rtx->max_size_time);
580       g_mutex_unlock (&rtx->lock);
581       break;
582     case PROP_MAX_SIZE_PACKETS:
583       g_mutex_lock (&rtx->lock);
584       g_value_set_uint (value, rtx->max_size_packets);
585       g_mutex_unlock (&rtx->lock);
586       break;
587     case PROP_NUM_RTX_REQUESTS:
588       g_mutex_lock (&rtx->lock);
589       g_value_set_uint (value, rtx->num_rtx_requests);
590       g_mutex_unlock (&rtx->lock);
591       break;
592     case PROP_NUM_RTX_PACKETS:
593       g_mutex_lock (&rtx->lock);
594       g_value_set_uint (value, rtx->num_rtx_packets);
595       g_mutex_unlock (&rtx->lock);
596       break;
597     default:
598       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
599       break;
600   }
601 }
602
603 static void
604 gst_rtp_rtx_send_set_property (GObject * object,
605     guint prop_id, const GValue * value, GParamSpec * pspec)
606 {
607   GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
608
609   switch (prop_id) {
610     case PROP_RTX_PAYLOAD_TYPE:
611       g_mutex_lock (&rtx->lock);
612       rtx->rtx_payload_type_pending = g_value_get_uint (value);
613       g_mutex_unlock (&rtx->lock);
614       break;
615     case PROP_MAX_SIZE_TIME:
616       g_mutex_lock (&rtx->lock);
617       rtx->max_size_time = g_value_get_uint (value);
618       g_mutex_unlock (&rtx->lock);
619       break;
620     case PROP_MAX_SIZE_PACKETS:
621       g_mutex_lock (&rtx->lock);
622       rtx->max_size_packets = g_value_get_uint (value);
623       g_mutex_unlock (&rtx->lock);
624       break;
625     default:
626       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
627       break;
628   }
629 }
630
631 static GstStateChangeReturn
632 gst_rtp_rtx_send_change_state (GstElement * element, GstStateChange transition)
633 {
634   GstStateChangeReturn ret;
635   GstRtpRtxSend *rtx;
636
637   rtx = GST_RTP_RTX_SEND (element);
638
639   switch (transition) {
640     default:
641       break;
642   }
643
644   ret =
645       GST_ELEMENT_CLASS (gst_rtp_rtx_send_parent_class)->change_state (element,
646       transition);
647
648   switch (transition) {
649     case GST_STATE_CHANGE_PAUSED_TO_READY:
650       gst_rtp_rtx_send_reset (rtx, TRUE);
651       break;
652     default:
653       break;
654   }
655
656   return ret;
657 }
658
659 gboolean
660 gst_rtp_rtx_send_plugin_init (GstPlugin * plugin)
661 {
662   GST_DEBUG_CATEGORY_INIT (gst_rtp_rtx_send_debug, "rtprtxsend", 0,
663       "rtp retransmission sender");
664
665   return gst_element_register (plugin, "rtprtxsend", GST_RANK_NONE,
666       GST_TYPE_RTP_RTX_SEND);
667 }