rtpsession: Only suggest our internal ssrc if it's not a random one and was selected as internal ssrc

https://bugzilla.gnome.org/show_bug.cgi?id=749581
This commit is contained in:
Sebastian Dröge 2015-06-05 16:43:08 +02:00
parent 0e5631c5c0
commit d650a310da
3 changed files with 29 additions and 12 deletions

View file

@ -344,7 +344,7 @@ on_ssrc_collision (RTPSession * session, RTPSource * src, GstRtpSession * sess)
/* if there is no source using the suggested ssrc, most probably because /* if there is no source using the suggested ssrc, most probably because
* this ssrc has just collided, suggest upstream to use it */ * this ssrc has just collided, suggest upstream to use it */
suggested_ssrc = rtp_session_suggest_ssrc (session); suggested_ssrc = rtp_session_suggest_ssrc (session, NULL);
internal_src = rtp_session_get_source_by_ssrc (session, suggested_ssrc); internal_src = rtp_session_get_source_by_ssrc (session, suggested_ssrc);
if (!internal_src) if (!internal_src)
gst_structure_set (structure, "suggested-ssrc", G_TYPE_UINT, gst_structure_set (structure, "suggested-ssrc", G_TYPE_UINT,
@ -2007,18 +2007,26 @@ gst_rtp_session_getcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
GstCaps *result; GstCaps *result;
GstStructure *s1, *s2; GstStructure *s1, *s2;
guint ssrc; guint ssrc;
gboolean is_random;
priv = rtpsession->priv; priv = rtpsession->priv;
ssrc = rtp_session_suggest_ssrc (priv->session); ssrc = rtp_session_suggest_ssrc (priv->session, &is_random);
/* we can basically accept anything but we prefer to receive packets with our /* we can basically accept anything but we prefer to receive packets with our
* internal SSRC so that we don't have to patch it. Create a structure with * internal SSRC so that we don't have to patch it. Create a structure with
* the SSRC and another one without. */ * the SSRC and another one without.
s1 = gst_structure_new ("application/x-rtp", "ssrc", G_TYPE_UINT, ssrc, NULL); * Only do this if the session actually decided on an ssrc already,
s2 = gst_structure_new_empty ("application/x-rtp"); * otherwise we give upstream the opportunity to select an ssrc itself */
if (!is_random) {
s1 = gst_structure_new ("application/x-rtp", "ssrc", G_TYPE_UINT, ssrc,
NULL);
s2 = gst_structure_new_empty ("application/x-rtp");
result = gst_caps_new_full (s1, s2, NULL); result = gst_caps_new_full (s1, s2, NULL);
} else {
result = gst_caps_new_empty_simple ("application/x-rtp");
}
if (filter) { if (filter) {
GstCaps *caps = result; GstCaps *caps = result;

View file

@ -569,6 +569,7 @@ rtp_session_init (RTPSession * sess)
/* this is the SSRC we suggest */ /* this is the SSRC we suggest */
sess->suggested_ssrc = rtp_session_create_new_ssrc (sess); sess->suggested_ssrc = rtp_session_create_new_ssrc (sess);
sess->internal_ssrc_set = FALSE;
sess->first_rtcp = TRUE; sess->first_rtcp = TRUE;
sess->next_rtcp_check_time = GST_CLOCK_TIME_NONE; sess->next_rtcp_check_time = GST_CLOCK_TIME_NONE;
@ -666,6 +667,7 @@ rtp_session_set_property (GObject * object, guint prop_id,
case PROP_INTERNAL_SSRC: case PROP_INTERNAL_SSRC:
RTP_SESSION_LOCK (sess); RTP_SESSION_LOCK (sess);
sess->suggested_ssrc = g_value_get_uint (value); sess->suggested_ssrc = g_value_get_uint (value);
sess->internal_ssrc_set = TRUE;
RTP_SESSION_UNLOCK (sess); RTP_SESSION_UNLOCK (sess);
if (sess->callbacks.reconfigure) if (sess->callbacks.reconfigure)
sess->callbacks.reconfigure (sess, sess->reconfigure_user_data); sess->callbacks.reconfigure (sess, sess->reconfigure_user_data);
@ -744,7 +746,7 @@ rtp_session_get_property (GObject * object, guint prop_id,
switch (prop_id) { switch (prop_id) {
case PROP_INTERNAL_SSRC: case PROP_INTERNAL_SSRC:
g_value_set_uint (value, rtp_session_suggest_ssrc (sess)); g_value_set_uint (value, rtp_session_suggest_ssrc (sess, NULL));
break; break;
case PROP_INTERNAL_SOURCE: case PROP_INTERNAL_SOURCE:
/* FIXME, return a random source */ /* FIXME, return a random source */
@ -1413,8 +1415,10 @@ check_collision (RTPSession * sess, RTPSource * source,
/* mark the source BYE */ /* mark the source BYE */
rtp_source_mark_bye (source, "SSRC Collision"); rtp_source_mark_bye (source, "SSRC Collision");
/* if we were suggesting this SSRC, change to something else */ /* if we were suggesting this SSRC, change to something else */
if (sess->suggested_ssrc == ssrc) if (sess->suggested_ssrc == ssrc) {
sess->suggested_ssrc = rtp_session_create_new_ssrc (sess); sess->suggested_ssrc = rtp_session_create_new_ssrc (sess);
sess->internal_ssrc_set = TRUE;
}
on_ssrc_collision (sess, source); on_ssrc_collision (sess, source);
@ -1522,8 +1526,6 @@ add_source (RTPSession * sess, RTPSource * src)
sess->stats.active_sources++; sess->stats.active_sources++;
if (src->internal) { if (src->internal) {
sess->stats.internal_sources++; sess->stats.internal_sources++;
if (sess->suggested_ssrc != src->ssrc)
sess->suggested_ssrc = src->ssrc;
} }
/* update point-to-point status */ /* update point-to-point status */
@ -1633,13 +1635,14 @@ obtain_internal_source (RTPSession * sess, guint32 ssrc, gboolean * created,
/** /**
* rtp_session_suggest_ssrc: * rtp_session_suggest_ssrc:
* @sess: a #RTPSession * @sess: a #RTPSession
* @is_random: if the suggested ssrc is random
* *
* Suggest an unused SSRC in @sess. * Suggest an unused SSRC in @sess.
* *
* Returns: a free unused SSRC * Returns: a free unused SSRC
*/ */
guint32 guint32
rtp_session_suggest_ssrc (RTPSession * sess) rtp_session_suggest_ssrc (RTPSession * sess, gboolean * is_random)
{ {
guint32 result; guint32 result;
@ -1647,6 +1650,8 @@ rtp_session_suggest_ssrc (RTPSession * sess)
RTP_SESSION_LOCK (sess); RTP_SESSION_LOCK (sess);
result = sess->suggested_ssrc; result = sess->suggested_ssrc;
if (is_random)
*is_random = !sess->internal_ssrc_set;
RTP_SESSION_UNLOCK (sess); RTP_SESSION_UNLOCK (sess);
return result; return result;
@ -2738,6 +2743,8 @@ rtp_session_update_send_caps (RTPSession * sess, GstCaps * caps)
RTP_SESSION_LOCK (sess); RTP_SESSION_LOCK (sess);
source = obtain_internal_source (sess, ssrc, &created, GST_CLOCK_TIME_NONE); source = obtain_internal_source (sess, ssrc, &created, GST_CLOCK_TIME_NONE);
sess->suggested_ssrc = ssrc;
sess->internal_ssrc_set = TRUE;
if (source) { if (source) {
rtp_source_update_caps (source, caps); rtp_source_update_caps (source, caps);
g_object_unref (source); g_object_unref (source);
@ -3800,6 +3807,7 @@ rtp_session_on_timeout (RTPSession * sess, GstClockTime current_time,
source = obtain_internal_source (sess, sess->suggested_ssrc, &created, source = obtain_internal_source (sess, sess->suggested_ssrc, &created,
current_time); current_time);
sess->internal_ssrc_set = TRUE;
g_object_unref (source); g_object_unref (source);
} }

View file

@ -230,6 +230,7 @@ struct _RTPSession {
guint rtcp_rs_bandwidth; guint rtcp_rs_bandwidth;
guint32 suggested_ssrc; guint32 suggested_ssrc;
gboolean internal_ssrc_set;
/* for sender/receiver counting */ /* for sender/receiver counting */
guint32 key; guint32 key;
@ -347,7 +348,7 @@ GstStructure * rtp_session_get_sdes_struct (RTPSession *sess);
void rtp_session_set_sdes_struct (RTPSession *sess, const GstStructure *sdes); void rtp_session_set_sdes_struct (RTPSession *sess, const GstStructure *sdes);
/* handling sources */ /* handling sources */
guint32 rtp_session_suggest_ssrc (RTPSession *sess); guint32 rtp_session_suggest_ssrc (RTPSession *sess, gboolean *is_random);
gboolean rtp_session_add_source (RTPSession *sess, RTPSource *src); gboolean rtp_session_add_source (RTPSession *sess, RTPSource *src);
guint rtp_session_get_num_sources (RTPSession *sess); guint rtp_session_get_num_sources (RTPSession *sess);