2013-08-12 14:15:54 +00:00
|
|
|
/* RTP Retransmission queue element for GStreamer
|
|
|
|
*
|
|
|
|
* gstrtprtxqueue.c:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-rtprtxqueue
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: rtprtxqueue
|
2017-03-20 10:03:29 +00:00
|
|
|
*
|
|
|
|
* rtprtxqueue maintains a queue of transmitted RTP packets, up to a
|
2019-05-25 14:56:32 +00:00
|
|
|
* configurable limit (see #GstRTPRtxQueue:max-size-time,
|
|
|
|
* #GstRTPRtxQueue:max-size-packets), and retransmits them upon request
|
2017-03-20 10:03:29 +00:00
|
|
|
* from the downstream rtpsession (GstRTPRetransmissionRequest event).
|
|
|
|
*
|
|
|
|
* This element is similar to rtprtxsend, but it has differences:
|
|
|
|
* - Retransmission from rtprtxqueue is not RFC 4588 compliant. The
|
|
|
|
* retransmitted packets have the same ssrc and payload type as the original
|
|
|
|
* stream.
|
|
|
|
* - As a side-effect of the above, rtprtxqueue does not require the use of
|
|
|
|
* rtprtxreceive on the receiving end. rtpjitterbuffer alone is able to
|
|
|
|
* reconstruct the stream.
|
|
|
|
* - Retransmission from rtprtxqueue happens as soon as the next regular flow
|
|
|
|
* packet is chained, while rtprtxsend retransmits as soon as the retransmission
|
|
|
|
* event is received, using a helper thread.
|
|
|
|
* - rtprtxqueue can be used with rtpbin without the need of hooking to its
|
|
|
|
* #GstRtpBin::request-aux-sender signal, which means it can be used with
|
|
|
|
* rtpbin using gst-launch.
|
|
|
|
*
|
|
|
|
* See also #GstRtpRtxSend, #GstRtpRtxReceive
|
|
|
|
*
|
|
|
|
* # Example pipelines
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2017-03-20 10:03:29 +00:00
|
|
|
* |[
|
|
|
|
* gst-launch-1.0 rtpbin name=b rtp-profile=avpf \
|
|
|
|
* audiotestsrc is-live=true ! opusenc ! rtpopuspay pt=96 ! rtprtxqueue ! b.send_rtp_sink_0 \
|
|
|
|
* b.send_rtp_src_0 ! identity drop-probability=0.01 ! udpsink host="127.0.0.1" port=5000 \
|
|
|
|
* udpsrc port=5001 ! b.recv_rtcp_sink_0 \
|
|
|
|
* b.send_rtcp_src_0 ! udpsink host="127.0.0.1" port=5002 sync=false async=false
|
2018-10-22 09:39:24 +00:00
|
|
|
* ]|
|
|
|
|
* Sender pipeline
|
|
|
|
*
|
2017-03-20 10:03:29 +00:00
|
|
|
* |[
|
|
|
|
* gst-launch-1.0 rtpbin name=b rtp-profile=avpf do-retransmission=true \
|
|
|
|
* udpsrc port=5000 caps="application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)OPUS,payload=(int)96" ! \
|
|
|
|
* b.recv_rtp_sink_0 \
|
|
|
|
* b. ! rtpopusdepay ! opusdec ! audioconvert ! audioresample ! autoaudiosink \
|
|
|
|
* udpsrc port=5002 ! b.recv_rtcp_sink_0 \
|
|
|
|
* b.send_rtcp_src_0 ! udpsink host="127.0.0.1" port=5001 sync=false async=false
|
2018-10-22 09:39:24 +00:00
|
|
|
* ]|
|
|
|
|
* Receiver pipeline
|
2013-08-12 14:15:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/rtp/gstrtpbuffer.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstrtprtxqueue.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_rtp_rtx_queue_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_rtp_rtx_queue_debug
|
|
|
|
|
2013-08-23 13:47:25 +00:00
|
|
|
#define DEFAULT_MAX_SIZE_TIME 0
|
|
|
|
#define DEFAULT_MAX_SIZE_PACKETS 100
|
|
|
|
|
2013-08-12 14:15:54 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2013-08-23 13:47:25 +00:00
|
|
|
PROP_MAX_SIZE_TIME,
|
2017-01-11 17:52:28 +00:00
|
|
|
PROP_MAX_SIZE_PACKETS,
|
|
|
|
PROP_REQUESTS,
|
|
|
|
PROP_FULFILLED_REQUESTS,
|
2013-08-12 14:15:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-rtp")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-rtp")
|
|
|
|
);
|
|
|
|
|
|
|
|
static gboolean gst_rtp_rtx_queue_src_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2017-04-04 14:33:31 +00:00
|
|
|
static gboolean gst_rtp_rtx_queue_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2013-08-12 14:15:54 +00:00
|
|
|
static GstFlowReturn gst_rtp_rtx_queue_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buffer);
|
2015-03-19 10:39:38 +00:00
|
|
|
static GstFlowReturn gst_rtp_rtx_queue_chain_list (GstPad * pad,
|
|
|
|
GstObject * parent, GstBufferList * list);
|
2013-08-12 14:15:54 +00:00
|
|
|
|
|
|
|
static GstStateChangeReturn gst_rtp_rtx_queue_change_state (GstElement *
|
|
|
|
element, GstStateChange transition);
|
|
|
|
|
|
|
|
static void gst_rtp_rtx_queue_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtp_rtx_queue_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_rtp_rtx_queue_finalize (GObject * object);
|
|
|
|
|
2021-02-16 13:24:33 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstRTPRtxQueue, gst_rtp_rtx_queue, GST_TYPE_ELEMENT,
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_rtp_rtx_queue_debug, "rtprtxqueue", 0,
|
|
|
|
"rtp retransmission queue"));
|
|
|
|
GST_ELEMENT_REGISTER_DEFINE (rtprtxqueue, "rtprtxqueue", GST_RANK_NONE,
|
|
|
|
GST_TYPE_RTP_RTX_QUEUE);
|
2013-08-12 14:15:54 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_rtx_queue_class_init (GstRTPRtxQueueClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
2013-08-23 13:47:25 +00:00
|
|
|
gobject_class->get_property = gst_rtp_rtx_queue_get_property;
|
|
|
|
gobject_class->set_property = gst_rtp_rtx_queue_set_property;
|
|
|
|
gobject_class->finalize = gst_rtp_rtx_queue_finalize;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_SIZE_TIME,
|
|
|
|
g_param_spec_uint ("max-size-time", "Max Size Times",
|
|
|
|
"Amount of ms to queue (0 = unlimited)", 0, G_MAXUINT,
|
|
|
|
DEFAULT_MAX_SIZE_TIME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_MAX_SIZE_PACKETS,
|
|
|
|
g_param_spec_uint ("max-size-packets", "Max Size Packets",
|
|
|
|
"Amount of packets to queue (0 = unlimited)", 0, G_MAXUINT,
|
|
|
|
DEFAULT_MAX_SIZE_PACKETS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2017-01-11 17:52:28 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_REQUESTS,
|
|
|
|
g_param_spec_uint ("requests", "Requests",
|
|
|
|
"Total number of retransmission requests", 0, G_MAXUINT,
|
|
|
|
0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_FULFILLED_REQUESTS,
|
|
|
|
g_param_spec_uint ("fulfilled-requests", "Fulfilled Requests",
|
|
|
|
"Number of fulfilled retransmission requests", 0, G_MAXUINT,
|
|
|
|
0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &src_factory);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &sink_factory);
|
2013-08-12 14:15:54 +00:00
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
|
|
|
"RTP Retransmission Queue", "Codec",
|
|
|
|
"Keep RTP packets in a queue for retransmission",
|
|
|
|
"Wim Taymans <wim.taymans@gmail.com>");
|
|
|
|
|
|
|
|
gstelement_class->change_state =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_rtx_queue_change_state);
|
|
|
|
}
|
|
|
|
|
2013-08-21 14:53:59 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_rtx_queue_reset (GstRTPRtxQueue * rtx, gboolean full)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&rtx->lock);
|
|
|
|
g_queue_foreach (rtx->queue, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_queue_clear (rtx->queue);
|
|
|
|
g_list_foreach (rtx->pending, (GFunc) gst_buffer_unref, NULL);
|
|
|
|
g_list_free (rtx->pending);
|
|
|
|
rtx->pending = NULL;
|
2017-01-11 17:52:28 +00:00
|
|
|
rtx->n_requests = 0;
|
|
|
|
rtx->n_fulfilled_requests = 0;
|
2013-08-21 14:53:59 +00:00
|
|
|
g_mutex_unlock (&rtx->lock);
|
|
|
|
}
|
|
|
|
|
2013-08-12 14:15:54 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_rtx_queue_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstRTPRtxQueue *rtx = GST_RTP_RTX_QUEUE (object);
|
|
|
|
|
2013-08-21 14:53:59 +00:00
|
|
|
gst_rtp_rtx_queue_reset (rtx, TRUE);
|
2013-08-12 14:15:54 +00:00
|
|
|
g_queue_free (rtx->queue);
|
2013-08-21 14:53:59 +00:00
|
|
|
g_mutex_clear (&rtx->lock);
|
2013-08-12 14:15:54 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_rtp_rtx_queue_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_rtx_queue_init (GstRTPRtxQueue * rtx)
|
|
|
|
{
|
|
|
|
GstElementClass *klass = GST_ELEMENT_GET_CLASS (rtx);
|
|
|
|
|
|
|
|
rtx->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
|
|
|
"src"), "src");
|
|
|
|
GST_PAD_SET_PROXY_CAPS (rtx->srcpad);
|
|
|
|
GST_PAD_SET_PROXY_ALLOCATION (rtx->srcpad);
|
|
|
|
gst_pad_set_event_function (rtx->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_rtx_queue_src_event));
|
|
|
|
gst_element_add_pad (GST_ELEMENT (rtx), rtx->srcpad);
|
|
|
|
|
|
|
|
rtx->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
|
|
|
|
"sink"), "sink");
|
|
|
|
GST_PAD_SET_PROXY_CAPS (rtx->sinkpad);
|
|
|
|
GST_PAD_SET_PROXY_ALLOCATION (rtx->sinkpad);
|
2017-04-04 14:33:31 +00:00
|
|
|
gst_pad_set_event_function (rtx->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_rtx_queue_sink_event));
|
2013-08-12 14:15:54 +00:00
|
|
|
gst_pad_set_chain_function (rtx->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_rtx_queue_chain));
|
2015-03-19 10:39:38 +00:00
|
|
|
gst_pad_set_chain_list_function (rtx->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_rtp_rtx_queue_chain_list));
|
2013-08-12 14:15:54 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (rtx), rtx->sinkpad);
|
|
|
|
|
|
|
|
rtx->queue = g_queue_new ();
|
2013-08-21 14:53:59 +00:00
|
|
|
g_mutex_init (&rtx->lock);
|
2013-08-23 13:47:25 +00:00
|
|
|
|
|
|
|
rtx->max_size_time = DEFAULT_MAX_SIZE_TIME;
|
|
|
|
rtx->max_size_packets = DEFAULT_MAX_SIZE_PACKETS;
|
2013-08-12 14:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstRTPRtxQueue *rtx;
|
|
|
|
guint seqnum;
|
2013-08-21 14:53:59 +00:00
|
|
|
gboolean found;
|
2013-08-12 14:15:54 +00:00
|
|
|
} RTXData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
push_seqnum (GstBuffer * buffer, RTXData * data)
|
|
|
|
{
|
|
|
|
GstRTPRtxQueue *rtx = data->rtx;
|
|
|
|
GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
|
|
|
|
guint16 seqnum;
|
|
|
|
|
2013-08-21 14:53:59 +00:00
|
|
|
if (data->found)
|
|
|
|
return;
|
|
|
|
|
2017-04-04 14:33:31 +00:00
|
|
|
if (!GST_IS_BUFFER (buffer) ||
|
|
|
|
!gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtpbuffer))
|
2013-08-12 14:15:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
seqnum = gst_rtp_buffer_get_seq (&rtpbuffer);
|
|
|
|
gst_rtp_buffer_unmap (&rtpbuffer);
|
|
|
|
|
|
|
|
if (seqnum == data->seqnum) {
|
2013-08-21 14:53:59 +00:00
|
|
|
data->found = TRUE;
|
|
|
|
GST_DEBUG_OBJECT (rtx, "found %d", seqnum);
|
|
|
|
rtx->pending = g_list_prepend (rtx->pending, gst_buffer_ref (buffer));
|
2013-08-12 14:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_rtp_rtx_queue_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstRTPRtxQueue *rtx = GST_RTP_RTX_QUEUE (parent);
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CUSTOM_UPSTREAM:
|
|
|
|
{
|
|
|
|
const GstStructure *s;
|
|
|
|
|
|
|
|
s = gst_event_get_structure (event);
|
|
|
|
if (gst_structure_has_name (s, "GstRTPRetransmissionRequest")) {
|
|
|
|
guint seqnum;
|
|
|
|
RTXData data;
|
|
|
|
|
|
|
|
if (!gst_structure_get_uint (s, "seqnum", &seqnum))
|
|
|
|
seqnum = -1;
|
|
|
|
|
2013-08-21 14:53:59 +00:00
|
|
|
GST_DEBUG_OBJECT (rtx, "request %d", seqnum);
|
|
|
|
|
|
|
|
g_mutex_lock (&rtx->lock);
|
2013-08-12 14:15:54 +00:00
|
|
|
data.rtx = rtx;
|
|
|
|
data.seqnum = seqnum;
|
2013-08-21 14:53:59 +00:00
|
|
|
data.found = FALSE;
|
2017-01-11 17:52:28 +00:00
|
|
|
rtx->n_requests += 1;
|
2013-08-12 14:15:54 +00:00
|
|
|
g_queue_foreach (rtx->queue, (GFunc) push_seqnum, &data);
|
2013-08-21 14:53:59 +00:00
|
|
|
g_mutex_unlock (&rtx->lock);
|
|
|
|
|
2013-08-12 14:15:54 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
res = TRUE;
|
|
|
|
} else {
|
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-04-04 14:33:31 +00:00
|
|
|
static gboolean
|
|
|
|
gst_rtp_rtx_queue_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
|
|
|
{
|
|
|
|
GstRTPRtxQueue *rtx = GST_RTP_RTX_QUEUE (parent);
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEGMENT:
|
|
|
|
{
|
|
|
|
g_mutex_lock (&rtx->lock);
|
|
|
|
gst_event_copy_segment (event, &rtx->head_segment);
|
|
|
|
g_queue_push_head (rtx->queue, gst_event_ref (event));
|
|
|
|
g_mutex_unlock (&rtx->lock);
|
|
|
|
/* fall through */
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-08-21 14:53:59 +00:00
|
|
|
static void
|
|
|
|
do_push (GstBuffer * buffer, GstRTPRtxQueue * rtx)
|
|
|
|
{
|
2017-01-11 17:52:28 +00:00
|
|
|
rtx->n_fulfilled_requests += 1;
|
2013-08-21 14:53:59 +00:00
|
|
|
gst_pad_push (rtx->srcpad, buffer);
|
|
|
|
}
|
|
|
|
|
2017-04-04 14:33:31 +00:00
|
|
|
static guint32
|
|
|
|
get_ts_diff (GstRTPRtxQueue * rtx)
|
|
|
|
{
|
|
|
|
GstClockTime high_ts, low_ts;
|
|
|
|
GstClockTimeDiff result;
|
|
|
|
GstBuffer *high_buf, *low_buf;
|
|
|
|
|
|
|
|
high_buf = g_queue_peek_head (rtx->queue);
|
|
|
|
|
|
|
|
while (GST_IS_EVENT ((low_buf = g_queue_peek_tail (rtx->queue)))) {
|
|
|
|
GstEvent *event = g_queue_pop_tail (rtx->queue);
|
|
|
|
gst_event_copy_segment (event, &rtx->tail_segment);
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!high_buf || !low_buf || high_buf == low_buf)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
high_ts = GST_BUFFER_TIMESTAMP (high_buf);
|
|
|
|
low_ts = GST_BUFFER_TIMESTAMP (low_buf);
|
|
|
|
|
|
|
|
high_ts = gst_segment_to_running_time (&rtx->head_segment, GST_FORMAT_TIME,
|
|
|
|
high_ts);
|
|
|
|
low_ts = gst_segment_to_running_time (&rtx->tail_segment, GST_FORMAT_TIME,
|
|
|
|
low_ts);
|
|
|
|
|
|
|
|
result = high_ts - low_ts;
|
|
|
|
|
|
|
|
/* return value in ms instead of ns */
|
|
|
|
return (guint32) gst_util_uint64_scale_int (result, 1, GST_MSECOND);
|
|
|
|
}
|
|
|
|
|
2015-03-19 10:39:38 +00:00
|
|
|
/* Must be called with rtx->lock */
|
|
|
|
static void
|
|
|
|
shrink_queue (GstRTPRtxQueue * rtx)
|
|
|
|
{
|
|
|
|
if (rtx->max_size_packets) {
|
|
|
|
while (g_queue_get_length (rtx->queue) > rtx->max_size_packets)
|
|
|
|
gst_buffer_unref (g_queue_pop_tail (rtx->queue));
|
|
|
|
}
|
2017-04-04 14:33:31 +00:00
|
|
|
if (rtx->max_size_time) {
|
|
|
|
while (get_ts_diff (rtx) > rtx->max_size_time)
|
|
|
|
gst_buffer_unref (g_queue_pop_tail (rtx->queue));
|
|
|
|
}
|
2015-03-19 10:39:38 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 14:15:54 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_rtp_rtx_queue_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstRTPRtxQueue *rtx;
|
|
|
|
GstFlowReturn ret;
|
2013-08-21 14:53:59 +00:00
|
|
|
GList *pending;
|
2013-08-12 14:15:54 +00:00
|
|
|
|
|
|
|
rtx = GST_RTP_RTX_QUEUE (parent);
|
|
|
|
|
2013-08-21 14:53:59 +00:00
|
|
|
g_mutex_lock (&rtx->lock);
|
2013-08-12 14:15:54 +00:00
|
|
|
g_queue_push_head (rtx->queue, gst_buffer_ref (buffer));
|
2015-03-19 10:39:38 +00:00
|
|
|
shrink_queue (rtx);
|
2013-08-23 13:47:25 +00:00
|
|
|
|
2013-08-21 14:53:59 +00:00
|
|
|
pending = rtx->pending;
|
|
|
|
rtx->pending = NULL;
|
|
|
|
g_mutex_unlock (&rtx->lock);
|
|
|
|
|
2015-06-19 12:50:59 +00:00
|
|
|
pending = g_list_reverse (pending);
|
2013-08-21 14:53:59 +00:00
|
|
|
g_list_foreach (pending, (GFunc) do_push, rtx);
|
|
|
|
g_list_free (pending);
|
2013-08-12 14:15:54 +00:00
|
|
|
|
|
|
|
ret = gst_pad_push (rtx->srcpad, buffer);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-19 10:39:38 +00:00
|
|
|
static gboolean
|
|
|
|
push_to_queue (GstBuffer ** buffer, guint idx, gpointer user_data)
|
|
|
|
{
|
|
|
|
GQueue *queue = user_data;
|
|
|
|
|
|
|
|
g_queue_push_head (queue, gst_buffer_ref (*buffer));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_rtp_rtx_queue_chain_list (GstPad * pad, GstObject * parent,
|
|
|
|
GstBufferList * list)
|
|
|
|
{
|
|
|
|
GstRTPRtxQueue *rtx;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
GList *pending;
|
|
|
|
|
|
|
|
rtx = GST_RTP_RTX_QUEUE (parent);
|
|
|
|
|
|
|
|
g_mutex_lock (&rtx->lock);
|
|
|
|
gst_buffer_list_foreach (list, push_to_queue, rtx->queue);
|
|
|
|
shrink_queue (rtx);
|
|
|
|
|
|
|
|
pending = rtx->pending;
|
|
|
|
rtx->pending = NULL;
|
|
|
|
g_mutex_unlock (&rtx->lock);
|
|
|
|
|
2015-06-19 12:50:59 +00:00
|
|
|
pending = g_list_reverse (pending);
|
2015-03-19 10:39:38 +00:00
|
|
|
g_list_foreach (pending, (GFunc) do_push, rtx);
|
|
|
|
g_list_free (pending);
|
|
|
|
|
|
|
|
ret = gst_pad_push_list (rtx->srcpad, list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-08-12 14:15:54 +00:00
|
|
|
static void
|
|
|
|
gst_rtp_rtx_queue_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-08-23 13:47:25 +00:00
|
|
|
GstRTPRtxQueue *rtx = GST_RTP_RTX_QUEUE (object);
|
|
|
|
|
2013-08-12 14:15:54 +00:00
|
|
|
switch (prop_id) {
|
2013-08-23 13:47:25 +00:00
|
|
|
case PROP_MAX_SIZE_TIME:
|
|
|
|
g_value_set_uint (value, rtx->max_size_time);
|
|
|
|
break;
|
|
|
|
case PROP_MAX_SIZE_PACKETS:
|
|
|
|
g_value_set_uint (value, rtx->max_size_packets);
|
|
|
|
break;
|
2017-01-11 17:52:28 +00:00
|
|
|
case PROP_REQUESTS:
|
|
|
|
g_value_set_uint (value, rtx->n_requests);
|
|
|
|
break;
|
|
|
|
case PROP_FULFILLED_REQUESTS:
|
|
|
|
g_value_set_uint (value, rtx->n_fulfilled_requests);
|
|
|
|
break;
|
2013-08-12 14:15:54 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_rtp_rtx_queue_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-08-23 13:47:25 +00:00
|
|
|
GstRTPRtxQueue *rtx = GST_RTP_RTX_QUEUE (object);
|
|
|
|
|
2013-08-12 14:15:54 +00:00
|
|
|
switch (prop_id) {
|
2013-08-23 13:47:25 +00:00
|
|
|
case PROP_MAX_SIZE_TIME:
|
|
|
|
rtx->max_size_time = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_MAX_SIZE_PACKETS:
|
|
|
|
rtx->max_size_packets = g_value_get_uint (value);
|
|
|
|
break;
|
2013-08-12 14:15:54 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_rtp_rtx_queue_change_state (GstElement * element, GstStateChange transition)
|
|
|
|
{
|
|
|
|
GstStateChangeReturn ret;
|
2013-08-21 14:53:59 +00:00
|
|
|
GstRTPRtxQueue *rtx;
|
|
|
|
|
|
|
|
rtx = GST_RTP_RTX_QUEUE (element);
|
2013-08-12 14:15:54 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret =
|
|
|
|
GST_ELEMENT_CLASS (gst_rtp_rtx_queue_parent_class)->change_state (element,
|
|
|
|
transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
2013-08-21 14:53:59 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
|
|
gst_rtp_rtx_queue_reset (rtx, TRUE);
|
|
|
|
break;
|
2013-08-12 14:15:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|