1 /* RTP Retransmission sender element for GStreamer
5 * Copyright (C) 2013 Collabora Ltd.
6 * @author Julien Isorce <julien.isorce@collabora.co.uk>
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.
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.
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.
25 * SECTION:element-rtprtxsend
27 * See #GstRtpRtxReceive for examples
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
43 #include <gst/rtp/gstrtpbuffer.h>
47 #include "gstrtprtxsend.h"
49 GST_DEBUG_CATEGORY_STATIC (gst_rtp_rtx_send_debug);
50 #define GST_CAT_DEFAULT gst_rtp_rtx_send_debug
52 #define DEFAULT_RTX_PAYLOAD_TYPE 0
53 #define DEFAULT_MAX_SIZE_TIME 0
54 #define DEFAULT_MAX_SIZE_PACKETS 100
60 PROP_PAYLOAD_TYPE_MAP,
62 PROP_MAX_SIZE_PACKETS,
63 PROP_NUM_RTX_REQUESTS,
68 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
71 GST_STATIC_CAPS ("application/x-rtp")
74 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
77 GST_STATIC_CAPS ("application/x-rtp")
80 static gboolean gst_rtp_rtx_send_src_event (GstPad * pad, GstObject * parent,
82 static gboolean gst_rtp_rtx_send_sink_event (GstPad * pad, GstObject * parent,
84 static GstFlowReturn gst_rtp_rtx_send_chain (GstPad * pad, GstObject * parent,
87 static GstStateChangeReturn gst_rtp_rtx_send_change_state (GstElement *
88 element, GstStateChange transition);
90 static void gst_rtp_rtx_send_set_property (GObject * object, guint prop_id,
91 const GValue * value, GParamSpec * pspec);
92 static void gst_rtp_rtx_send_get_property (GObject * object, guint prop_id,
93 GValue * value, GParamSpec * pspec);
94 static void gst_rtp_rtx_send_finalize (GObject * object);
96 G_DEFINE_TYPE (GstRtpRtxSend, gst_rtp_rtx_send, GST_TYPE_ELEMENT);
106 buffer_queue_item_free (BufferQueueItem * item)
108 gst_buffer_unref (item->buffer);
109 g_slice_free (BufferQueueItem, item);
118 /* history of rtp packets */
123 ssrc_rtx_data_new (guint32 rtx_ssrc)
125 SSRCRtxData *data = g_slice_new0 (SSRCRtxData);
127 data->rtx_ssrc = rtx_ssrc;
128 data->next_seqnum = g_random_int_range (0, G_MAXUINT16);
129 data->queue = g_sequence_new ((GDestroyNotify) buffer_queue_item_free);
135 ssrc_rtx_data_free (SSRCRtxData * data)
137 g_sequence_free (data->queue);
138 g_slice_free (SSRCRtxData, data);
142 gst_rtp_rtx_send_class_init (GstRtpRtxSendClass * klass)
144 GObjectClass *gobject_class;
145 GstElementClass *gstelement_class;
147 gobject_class = (GObjectClass *) klass;
148 gstelement_class = (GstElementClass *) klass;
150 gobject_class->get_property = gst_rtp_rtx_send_get_property;
151 gobject_class->set_property = gst_rtp_rtx_send_set_property;
152 gobject_class->finalize = gst_rtp_rtx_send_finalize;
154 g_object_class_install_property (gobject_class, PROP_SSRC_MAP,
155 g_param_spec_boxed ("ssrc-map", "SSRC Map",
156 "Map of SSRCs to their retransmission SSRCs for SSRC-multiplexed mode"
157 " (default = random)", GST_TYPE_STRUCTURE,
158 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
160 g_object_class_install_property (gobject_class, PROP_PAYLOAD_TYPE_MAP,
161 g_param_spec_boxed ("payload-type-map", "Payload Type Map",
162 "Map of original payload types to their retransmission payload types",
163 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
165 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_TIME,
166 g_param_spec_uint ("max-size-time", "Max Size Time",
167 "Amount of ms to queue (0 = unlimited)", 0, G_MAXUINT,
168 DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
170 g_object_class_install_property (gobject_class, PROP_MAX_SIZE_PACKETS,
171 g_param_spec_uint ("max-size-packets", "Max Size Packets",
172 "Amount of packets to queue (0 = unlimited)", 0, G_MAXINT16,
173 DEFAULT_MAX_SIZE_PACKETS,
174 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
176 g_object_class_install_property (gobject_class, PROP_NUM_RTX_REQUESTS,
177 g_param_spec_uint ("num-rtx-requests", "Num RTX Requests",
178 "Number of retransmission events received", 0, G_MAXUINT,
179 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
181 g_object_class_install_property (gobject_class, PROP_NUM_RTX_PACKETS,
182 g_param_spec_uint ("num-rtx-packets", "Num RTX Packets",
183 " Number of retransmission packets sent", 0, G_MAXUINT,
184 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
186 gst_element_class_add_pad_template (gstelement_class,
187 gst_static_pad_template_get (&src_factory));
188 gst_element_class_add_pad_template (gstelement_class,
189 gst_static_pad_template_get (&sink_factory));
191 gst_element_class_set_static_metadata (gstelement_class,
192 "RTP Retransmission Sender", "Codec",
193 "Retransmit RTP packets when needed, according to RFC4588",
194 "Julien Isorce <julien.isorce@collabora.co.uk>");
196 gstelement_class->change_state =
197 GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_change_state);
201 gst_rtp_rtx_send_reset (GstRtpRtxSend * rtx)
203 GST_OBJECT_LOCK (rtx);
204 g_queue_foreach (rtx->pending, (GFunc) gst_buffer_unref, NULL);
205 g_queue_clear (rtx->pending);
206 g_hash_table_remove_all (rtx->ssrc_data);
207 g_hash_table_remove_all (rtx->rtx_ssrcs);
208 rtx->num_rtx_requests = 0;
209 rtx->num_rtx_packets = 0;
210 GST_OBJECT_UNLOCK (rtx);
214 gst_rtp_rtx_send_finalize (GObject * object)
216 GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
218 g_hash_table_unref (rtx->ssrc_data);
219 g_hash_table_unref (rtx->rtx_ssrcs);
220 if (rtx->external_ssrc_map)
221 gst_structure_free (rtx->external_ssrc_map);
222 g_hash_table_unref (rtx->rtx_pt_map);
223 if (rtx->rtx_pt_map_structure)
224 gst_structure_free (rtx->rtx_pt_map_structure);
225 g_queue_free_full (rtx->pending, (GDestroyNotify) gst_buffer_unref);
227 G_OBJECT_CLASS (gst_rtp_rtx_send_parent_class)->finalize (object);
231 gst_rtp_rtx_send_init (GstRtpRtxSend * rtx)
233 GstElementClass *klass = GST_ELEMENT_GET_CLASS (rtx);
236 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
238 GST_PAD_SET_PROXY_CAPS (rtx->srcpad);
239 GST_PAD_SET_PROXY_ALLOCATION (rtx->srcpad);
240 gst_pad_set_event_function (rtx->srcpad,
241 GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_src_event));
242 gst_element_add_pad (GST_ELEMENT (rtx), rtx->srcpad);
245 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
247 GST_PAD_SET_PROXY_CAPS (rtx->sinkpad);
248 GST_PAD_SET_PROXY_ALLOCATION (rtx->sinkpad);
249 gst_pad_set_event_function (rtx->sinkpad,
250 GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_sink_event));
251 gst_pad_set_chain_function (rtx->sinkpad,
252 GST_DEBUG_FUNCPTR (gst_rtp_rtx_send_chain));
253 gst_element_add_pad (GST_ELEMENT (rtx), rtx->sinkpad);
255 rtx->pending = g_queue_new ();
256 rtx->ssrc_data = g_hash_table_new_full (g_direct_hash, g_direct_equal,
257 NULL, (GDestroyNotify) ssrc_rtx_data_free);
258 rtx->rtx_ssrcs = g_hash_table_new (g_direct_hash, g_direct_equal);
259 rtx->rtx_pt_map = g_hash_table_new (g_direct_hash, g_direct_equal);
261 rtx->max_size_time = DEFAULT_MAX_SIZE_TIME;
262 rtx->max_size_packets = DEFAULT_MAX_SIZE_PACKETS;
266 gst_rtp_rtx_send_choose_ssrc (GstRtpRtxSend * rtx, guint32 choice,
267 gboolean consider_choice)
269 guint32 ssrc = consider_choice ? choice : g_random_int ();
271 /* make sure to be different than any other */
272 while (g_hash_table_contains (rtx->ssrc_data, GUINT_TO_POINTER (ssrc)) ||
273 g_hash_table_contains (rtx->rtx_ssrcs, GUINT_TO_POINTER (ssrc))) {
274 ssrc = g_random_int ();
281 gst_rtp_rtx_send_get_ssrc_data (GstRtpRtxSend * rtx, guint32 ssrc)
285 gboolean consider = FALSE;
287 if (G_UNLIKELY (!g_hash_table_contains (rtx->ssrc_data,
288 GUINT_TO_POINTER (ssrc)))) {
289 if (rtx->external_ssrc_map) {
291 ssrc_str = g_strdup_printf ("%" G_GUINT32_FORMAT, ssrc);
292 consider = gst_structure_get_uint (rtx->external_ssrc_map, ssrc_str,
296 rtx_ssrc = gst_rtp_rtx_send_choose_ssrc (rtx, rtx_ssrc, consider);
297 data = ssrc_rtx_data_new (rtx_ssrc);
298 g_hash_table_insert (rtx->ssrc_data, GUINT_TO_POINTER (ssrc), data);
299 g_hash_table_insert (rtx->rtx_ssrcs, GUINT_TO_POINTER (rtx_ssrc),
300 GUINT_TO_POINTER (ssrc));
302 data = g_hash_table_lookup (rtx->ssrc_data, GUINT_TO_POINTER (ssrc));
308 buffer_queue_items_cmp (BufferQueueItem * a, BufferQueueItem * b,
311 /* gst_rtp_buffer_compare_seqnum returns the opposite of what we want,
312 * it returns negative when seqnum1 > seqnum2 and we want negative
313 * when b > a, i.e. a is smaller, so it comes first in the sequence */
314 return gst_rtp_buffer_compare_seqnum (b->seqnum, a->seqnum);
318 gst_rtp_rtx_send_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
320 GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
323 switch (GST_EVENT_TYPE (event)) {
324 case GST_EVENT_CUSTOM_UPSTREAM:
326 const GstStructure *s = gst_event_get_structure (event);
328 /* This event usually comes from the downstream gstrtpsession */
329 if (gst_structure_has_name (s, "GstRTPRetransmissionRequest")) {
333 /* retrieve seqnum of the packet that need to be restransmisted */
334 if (!gst_structure_get_uint (s, "seqnum", &seqnum))
337 /* retrieve ssrc of the packet that need to be restransmisted */
338 if (!gst_structure_get_uint (s, "ssrc", &ssrc))
341 GST_DEBUG_OBJECT (rtx,
342 "request seqnum: %" G_GUINT32_FORMAT ", ssrc: %" G_GUINT32_FORMAT,
345 GST_OBJECT_LOCK (rtx);
346 /* check if request is for us */
347 if (g_hash_table_contains (rtx->ssrc_data, GUINT_TO_POINTER (ssrc))) {
350 BufferQueueItem search_item;
352 /* update statistics */
353 ++rtx->num_rtx_requests;
355 data = gst_rtp_rtx_send_get_ssrc_data (rtx, ssrc);
357 search_item.seqnum = seqnum;
358 iter = g_sequence_lookup (data->queue, &search_item,
359 (GCompareDataFunc) buffer_queue_items_cmp, NULL);
361 BufferQueueItem *item = g_sequence_get (iter);
362 GST_DEBUG_OBJECT (rtx, "found %" G_GUINT16_FORMAT, item->seqnum);
363 g_queue_push_tail (rtx->pending, gst_buffer_ref (item->buffer));
366 GST_OBJECT_UNLOCK (rtx);
368 gst_event_unref (event);
371 /* This event usually comes from the downstream gstrtpsession */
372 } else if (gst_structure_has_name (s, "GstRTPCollision")) {
375 if (!gst_structure_get_uint (s, "ssrc", &ssrc))
378 GST_DEBUG_OBJECT (rtx, "collision ssrc: %" G_GUINT32_FORMAT, ssrc);
380 GST_OBJECT_LOCK (rtx);
382 /* choose another ssrc for our retransmited stream */
383 if (g_hash_table_contains (rtx->rtx_ssrcs, GUINT_TO_POINTER (ssrc))) {
387 master_ssrc = GPOINTER_TO_UINT (g_hash_table_lookup (rtx->rtx_ssrcs,
388 GUINT_TO_POINTER (ssrc)));
389 data = gst_rtp_rtx_send_get_ssrc_data (rtx, master_ssrc);
391 /* change rtx_ssrc and update the reverse map */
392 data->rtx_ssrc = gst_rtp_rtx_send_choose_ssrc (rtx, 0, FALSE);
393 g_hash_table_remove (rtx->rtx_ssrcs, GUINT_TO_POINTER (ssrc));
394 g_hash_table_insert (rtx->rtx_ssrcs,
395 GUINT_TO_POINTER (data->rtx_ssrc),
396 GUINT_TO_POINTER (master_ssrc));
398 GST_OBJECT_UNLOCK (rtx);
400 /* no need to forward to payloader because we make sure to have
403 gst_event_unref (event);
406 /* if master ssrc has collided, remove it from our data, as it
407 * is not going to be used any longer */
408 if (g_hash_table_contains (rtx->ssrc_data, GUINT_TO_POINTER (ssrc))) {
410 data = gst_rtp_rtx_send_get_ssrc_data (rtx, ssrc);
411 g_hash_table_remove (rtx->rtx_ssrcs,
412 GUINT_TO_POINTER (data->rtx_ssrc));
413 g_hash_table_remove (rtx->ssrc_data, GUINT_TO_POINTER (ssrc));
416 GST_OBJECT_UNLOCK (rtx);
418 /* forward event to payloader in case collided ssrc is
420 res = gst_pad_event_default (pad, parent, event);
423 res = gst_pad_event_default (pad, parent, event);
428 res = gst_pad_event_default (pad, parent, event);
435 gst_rtp_rtx_send_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
437 GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
439 switch (GST_EVENT_TYPE (event)) {
447 gst_event_parse_caps (event, &caps);
448 g_assert (gst_caps_is_fixed (caps));
450 s = gst_caps_get_structure (caps, 0);
451 gst_structure_get_uint (s, "ssrc", &ssrc);
452 data = gst_rtp_rtx_send_get_ssrc_data (rtx, ssrc);
453 gst_structure_get_int (s, "clock-rate", &data->clock_rate);
455 GST_DEBUG_OBJECT (rtx, "got clock-rate from caps: %d for ssrc: %u",
456 data->clock_rate, ssrc);
463 return gst_pad_event_default (pad, parent, event);
466 /* like rtp_jitter_buffer_get_ts_diff() */
468 gst_rtp_rtx_send_get_ts_diff (SSRCRtxData * data)
470 guint64 high_ts, low_ts;
471 BufferQueueItem *high_buf, *low_buf;
475 g_sequence_get (g_sequence_iter_prev (g_sequence_get_end_iter
477 low_buf = g_sequence_get (g_sequence_get_begin_iter (data->queue));
479 if (!high_buf || !low_buf || high_buf == low_buf)
482 high_ts = high_buf->timestamp;
483 low_ts = low_buf->timestamp;
485 /* it needs to work if ts wraps */
486 if (high_ts >= low_ts) {
487 result = (guint32) (high_ts - low_ts);
489 result = (guint32) (high_ts + G_MAXUINT32 + 1 - low_ts);
492 /* return value in ms instead of clock ticks */
493 return (guint32) gst_util_uint64_scale_int (result, 1000, data->clock_rate);
496 /* Copy fixed header and extension. Add OSN before to copy payload
497 * Copy memory to avoid to manually copy each rtp buffer field.
500 _gst_rtp_rtx_buffer_new (GstRtpRtxSend * rtx, GstBuffer * buffer)
502 GstMemory *mem = NULL;
503 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
504 GstRTPBuffer new_rtp = GST_RTP_BUFFER_INIT;
505 GstBuffer *new_buffer = gst_buffer_new ();
507 guint payload_len = 0;
513 gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp);
515 /* get needed data from GstRtpRtxSend */
516 ssrc = gst_rtp_buffer_get_ssrc (&rtp);
517 data = gst_rtp_rtx_send_get_ssrc_data (rtx, ssrc);
518 ssrc = data->rtx_ssrc;
519 seqnum = data->next_seqnum++;
520 fmtp = GPOINTER_TO_UINT (g_hash_table_lookup (rtx->rtx_pt_map,
521 GUINT_TO_POINTER (gst_rtp_buffer_get_payload_type (&rtp))));
523 GST_DEBUG_OBJECT (rtx,
524 "retransmit seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT,
527 /* gst_rtp_buffer_map does not map the payload so do it now */
528 gst_rtp_buffer_get_payload (&rtp);
530 /* If payload type is not set through SDP/property then
531 * just bump the value */
533 fmtp = gst_rtp_buffer_get_payload_type (&rtp) + 1;
535 /* copy fixed header */
536 mem = gst_memory_copy (rtp.map[0].memory, 0, rtp.size[0]);
537 gst_buffer_append_memory (new_buffer, mem);
539 /* copy extension if any */
541 mem = gst_memory_copy (rtp.map[1].memory, 0, rtp.size[1]);
542 gst_buffer_append_memory (new_buffer, mem);
545 /* copy payload and add OSN just before */
546 payload_len = 2 + rtp.size[2];
547 mem = gst_allocator_alloc (NULL, payload_len, NULL);
549 gst_memory_map (mem, &map, GST_MAP_WRITE);
550 GST_WRITE_UINT16_BE (map.data, gst_rtp_buffer_get_seq (&rtp));
552 memcpy (map.data + 2, rtp.data[2], rtp.size[2]);
553 gst_memory_unmap (mem, &map);
554 gst_buffer_append_memory (new_buffer, mem);
556 /* everything needed is copied */
557 gst_rtp_buffer_unmap (&rtp);
559 /* set ssrc, seqnum and fmtp */
560 gst_rtp_buffer_map (new_buffer, GST_MAP_WRITE, &new_rtp);
561 gst_rtp_buffer_set_ssrc (&new_rtp, ssrc);
562 gst_rtp_buffer_set_seq (&new_rtp, seqnum);
563 gst_rtp_buffer_set_payload_type (&new_rtp, fmtp);
564 /* RFC 4588: let other elements do the padding, as normal */
565 gst_rtp_buffer_set_padding (&new_rtp, FALSE);
566 gst_rtp_buffer_unmap (&new_rtp);
571 /* push pending retransmission packet.
572 * it constructs rtx packet from original packets */
574 do_push (GstBuffer * buffer, GstRtpRtxSend * rtx)
576 gst_pad_push (rtx->srcpad, _gst_rtp_rtx_buffer_new (rtx, buffer));
580 gst_rtp_rtx_send_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
582 GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
583 GstFlowReturn ret = GST_FLOW_ERROR;
584 GQueue *pending = NULL;
585 GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
586 BufferQueueItem *item;
590 guint32 ssrc, rtptime;
592 /* read the information we want from the buffer */
593 gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp);
594 seqnum = gst_rtp_buffer_get_seq (&rtp);
595 payload_type = gst_rtp_buffer_get_payload_type (&rtp);
596 ssrc = gst_rtp_buffer_get_ssrc (&rtp);
597 rtptime = gst_rtp_buffer_get_timestamp (&rtp);
598 gst_rtp_buffer_unmap (&rtp);
600 GST_OBJECT_LOCK (rtx);
602 /* do not store the buffer if it's payload type is unknown */
603 if (g_hash_table_contains (rtx->rtx_pt_map, GUINT_TO_POINTER (payload_type))) {
604 data = gst_rtp_rtx_send_get_ssrc_data (rtx, ssrc);
606 /* add current rtp buffer to queue history */
607 item = g_slice_new0 (BufferQueueItem);
608 item->seqnum = seqnum;
609 item->timestamp = rtptime;
610 item->buffer = gst_buffer_ref (buffer);
611 g_sequence_append (data->queue, item);
613 /* remove oldest packets from history if they are too many */
614 if (rtx->max_size_packets) {
615 while (g_sequence_get_length (data->queue) > rtx->max_size_packets)
616 g_sequence_remove (g_sequence_get_begin_iter (data->queue));
618 if (rtx->max_size_time) {
619 while (gst_rtp_rtx_send_get_ts_diff (data) > rtx->max_size_time)
620 g_sequence_remove (g_sequence_get_begin_iter (data->queue));
624 /* within lock, get packets that have to be retransmited */
625 if (g_queue_get_length (rtx->pending) > 0) {
626 pending = rtx->pending;
627 rtx->pending = g_queue_new ();
629 /* update statistics - assume we will succeed to retransmit those packets */
630 rtx->num_rtx_packets += g_queue_get_length (pending);
633 /* no need to hold the lock to push rtx packets */
634 GST_OBJECT_UNLOCK (rtx);
636 /* retransmit requested packets */
638 g_queue_foreach (pending, (GFunc) do_push, rtx);
639 g_queue_free_full (pending, (GDestroyNotify) gst_buffer_unref);
643 "push seqnum: %" G_GUINT16_FORMAT ", ssrc: %" G_GUINT32_FORMAT, seqnum,
646 /* push current rtp packet */
647 ret = gst_pad_push (rtx->srcpad, buffer);
653 gst_rtp_rtx_send_get_property (GObject * object,
654 guint prop_id, GValue * value, GParamSpec * pspec)
656 GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
659 case PROP_PAYLOAD_TYPE_MAP:
660 GST_OBJECT_LOCK (rtx);
661 g_value_set_boxed (value, rtx->rtx_pt_map_structure);
662 GST_OBJECT_UNLOCK (rtx);
664 case PROP_MAX_SIZE_TIME:
665 GST_OBJECT_LOCK (rtx);
666 g_value_set_uint (value, rtx->max_size_time);
667 GST_OBJECT_UNLOCK (rtx);
669 case PROP_MAX_SIZE_PACKETS:
670 GST_OBJECT_LOCK (rtx);
671 g_value_set_uint (value, rtx->max_size_packets);
672 GST_OBJECT_UNLOCK (rtx);
674 case PROP_NUM_RTX_REQUESTS:
675 GST_OBJECT_LOCK (rtx);
676 g_value_set_uint (value, rtx->num_rtx_requests);
677 GST_OBJECT_UNLOCK (rtx);
679 case PROP_NUM_RTX_PACKETS:
680 GST_OBJECT_LOCK (rtx);
681 g_value_set_uint (value, rtx->num_rtx_packets);
682 GST_OBJECT_UNLOCK (rtx);
685 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
691 structure_to_hash_table (GQuark field_id, const GValue * value, gpointer hash)
693 const gchar *field_str;
697 field_str = g_quark_to_string (field_id);
698 field_uint = atoi (field_str);
699 value_uint = g_value_get_uint (value);
700 g_hash_table_insert ((GHashTable *) hash, GUINT_TO_POINTER (field_uint),
701 GUINT_TO_POINTER (value_uint));
707 gst_rtp_rtx_send_set_property (GObject * object,
708 guint prop_id, const GValue * value, GParamSpec * pspec)
710 GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
714 GST_OBJECT_LOCK (rtx);
715 if (rtx->external_ssrc_map)
716 gst_structure_free (rtx->external_ssrc_map);
717 rtx->external_ssrc_map = g_value_dup_boxed (value);
718 GST_OBJECT_UNLOCK (rtx);
720 case PROP_PAYLOAD_TYPE_MAP:
721 GST_OBJECT_LOCK (rtx);
722 if (rtx->rtx_pt_map_structure)
723 gst_structure_free (rtx->rtx_pt_map_structure);
724 rtx->rtx_pt_map_structure = g_value_dup_boxed (value);
725 g_hash_table_remove_all (rtx->rtx_pt_map);
726 gst_structure_foreach (rtx->rtx_pt_map_structure, structure_to_hash_table,
728 GST_OBJECT_UNLOCK (rtx);
730 case PROP_MAX_SIZE_TIME:
731 GST_OBJECT_LOCK (rtx);
732 rtx->max_size_time = g_value_get_uint (value);
733 GST_OBJECT_UNLOCK (rtx);
735 case PROP_MAX_SIZE_PACKETS:
736 GST_OBJECT_LOCK (rtx);
737 rtx->max_size_packets = g_value_get_uint (value);
738 GST_OBJECT_UNLOCK (rtx);
741 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
746 static GstStateChangeReturn
747 gst_rtp_rtx_send_change_state (GstElement * element, GstStateChange transition)
749 GstStateChangeReturn ret;
752 rtx = GST_RTP_RTX_SEND (element);
754 switch (transition) {
760 GST_ELEMENT_CLASS (gst_rtp_rtx_send_parent_class)->change_state (element,
763 switch (transition) {
764 case GST_STATE_CHANGE_PAUSED_TO_READY:
765 gst_rtp_rtx_send_reset (rtx);
775 gst_rtp_rtx_send_plugin_init (GstPlugin * plugin)
777 GST_DEBUG_CATEGORY_INIT (gst_rtp_rtx_send_debug, "rtprtxsend", 0,
778 "rtp retransmission sender");
780 return gst_element_register (plugin, "rtprtxsend", GST_RANK_NONE,
781 GST_TYPE_RTP_RTX_SEND);