Commit fa917da5 authored by Julien Isorce's avatar Julien Isorce Committed by George Kiagiadakis
Browse files

gstrtpbasepayload: regenerate ssrc when receiving GstRTPCollision event

parent feaa33be
......@@ -108,6 +108,10 @@ static gboolean gst_rtp_base_payload_sink_event_default (GstRTPBasePayload *
rtpbasepayload, GstEvent * event);
static gboolean gst_rtp_base_payload_sink_event (GstPad * pad,
GstObject * parent, GstEvent * event);
static gboolean gst_rtp_base_payload_src_event_default (GstRTPBasePayload *
rtpbasepayload, GstEvent * event);
static gboolean gst_rtp_base_payload_src_event (GstPad * pad,
GstObject * parent, GstEvent * event);
static gboolean gst_rtp_base_payload_query_default (GstRTPBasePayload *
rtpbasepayload, GstPad * pad, GstQuery * query);
static gboolean gst_rtp_base_payload_query (GstPad * pad, GstObject * parent,
......@@ -243,6 +247,7 @@ gst_rtp_base_payload_class_init (GstRTPBasePayloadClass * klass)
klass->get_caps = gst_rtp_base_payload_getcaps_default;
klass->sink_event = gst_rtp_base_payload_sink_event_default;
klass->src_event = gst_rtp_base_payload_src_event_default;
klass->query = gst_rtp_base_payload_query_default;
GST_DEBUG_CATEGORY_INIT (rtpbasepayload_debug, "rtpbasepayload", 0,
......@@ -263,6 +268,8 @@ gst_rtp_base_payload_init (GstRTPBasePayload * rtpbasepayload, gpointer g_class)
g_return_if_fail (templ != NULL);
rtpbasepayload->srcpad = gst_pad_new_from_template (templ, "src");
gst_pad_set_event_function (rtpbasepayload->srcpad,
gst_rtp_base_payload_src_event);
gst_element_add_pad (GST_ELEMENT (rtpbasepayload), rtpbasepayload->srcpad);
templ =
......@@ -418,6 +425,78 @@ gst_rtp_base_payload_sink_event (GstPad * pad, GstObject * parent,
return res;
}
static gboolean
gst_rtp_base_payload_src_event_default (GstRTPBasePayload * rtpbasepayload,
GstEvent * event)
{
GstObject *parent = GST_OBJECT_CAST (rtpbasepayload);
gboolean res = FALSE;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_CUSTOM_UPSTREAM:
{
const GstStructure *s = gst_event_get_structure (event);
if (gst_structure_has_name (s, "GstRTPCollision")) {
guint ssrc = 0;
if (!gst_structure_get_uint (s, "ssrc", &ssrc))
ssrc = -1;
GST_DEBUG_OBJECT (rtpbasepayload, "collided ssrc: %" G_GUINT32_FORMAT,
ssrc);
/* choose another ssrc for our retransmited stream */
if (ssrc == rtpbasepayload->current_ssrc) {
GstCaps *caps;
do
rtpbasepayload->current_ssrc = g_random_int ();
while (ssrc == rtpbasepayload->current_ssrc);
caps = gst_pad_get_current_caps (rtpbasepayload->srcpad);
caps = gst_caps_make_writable (caps);
gst_caps_set_simple (caps,
"ssrc", G_TYPE_UINT, rtpbasepayload->current_ssrc, NULL);
res = gst_pad_set_caps (rtpbasepayload->srcpad, caps);
gst_caps_unref (caps);
/* the event was for us */
gst_event_unref (event);
} else {
res = gst_pad_event_default (rtpbasepayload->srcpad, parent, event);
}
} else {
res = gst_pad_event_default (rtpbasepayload->srcpad, parent, event);
}
break;
}
default:
res = gst_pad_event_default (rtpbasepayload->srcpad, parent, event);
break;
}
return res;
}
static gboolean
gst_rtp_base_payload_src_event (GstPad * pad, GstObject * parent,
GstEvent * event)
{
GstRTPBasePayload *rtpbasepayload;
GstRTPBasePayloadClass *rtpbasepayload_class;
gboolean res = FALSE;
rtpbasepayload = GST_RTP_BASE_PAYLOAD (parent);
rtpbasepayload_class = GST_RTP_BASE_PAYLOAD_GET_CLASS (rtpbasepayload);
if (rtpbasepayload_class->src_event)
res = rtpbasepayload_class->src_event (rtpbasepayload, event);
else
gst_event_unref (event);
return res;
}
static gboolean
gst_rtp_base_payload_query_default (GstRTPBasePayload * rtpbasepayload,
GstPad * pad, GstQuery * query)
......@@ -883,8 +962,8 @@ gst_rtp_base_payload_prepare_push (GstRTPBasePayload * payload,
(is_list) ? -1 : gst_buffer_get_size (GST_BUFFER (obj)),
payload->seqnum, data.rtptime, GST_TIME_ARGS (data.pts));
if (g_atomic_int_compare_and_exchange (&payload->priv->
notified_first_timestamp, 1, 0)) {
if (g_atomic_int_compare_and_exchange (&payload->
priv->notified_first_timestamp, 1, 0)) {
g_object_notify (G_OBJECT (payload), "timestamp");
g_object_notify (G_OBJECT (payload), "seqnum");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment