session: make method to suggest available SSRC
authorWim Taymans <wim.taymans@collabora.co.uk>
Thu, 25 Jul 2013 23:14:04 +0000 (01:14 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 26 Jul 2013 10:17:59 +0000 (12:17 +0200)
Make a method to suggest the best available SSRC. This is the SSRC of the last
created internal source and is used to instruct upstream to produce this
SSRC.

gst/rtpmanager/gstrtpsession.c
gst/rtpmanager/rtpsession.c
gst/rtpmanager/rtpsession.h

index 98912fb..b971fd3 100644 (file)
@@ -1762,6 +1762,7 @@ gst_rtp_session_event_send_rtp_sink (GstPad * pad, GstObject * parent,
        * because we stop sending. */
       ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
       current_time = gst_clock_get_time (rtpsession->priv->sysclock);
+
       GST_DEBUG_OBJECT (rtpsession, "scheduling BYE message");
       rtp_session_mark_all_bye (rtpsession->priv->session, "End Of Stream");
       rtp_session_schedule_bye (rtpsession->priv->session, current_time);
@@ -1826,7 +1827,7 @@ gst_rtp_session_getcaps_send_rtp (GstPad * pad, GstRtpSession * rtpsession,
 
   priv = rtpsession->priv;
 
-  ssrc = rtp_session_get_internal_ssrc (priv->session);
+  ssrc = rtp_session_suggest_ssrc (priv->session);
 
   /* 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
index fffec31..29bf7b6 100644 (file)
@@ -1297,8 +1297,11 @@ add_source (RTPSession * sess, RTPSource * src)
   sess->total_sources++;
   if (RTP_SOURCE_IS_ACTIVE (src))
     sess->stats.active_sources++;
-  if (src->internal)
+  if (src->internal) {
     sess->stats.internal_sources++;
+    if (sess->suggested_ssrc != src->ssrc)
+      sess->suggested_ssrc = src->ssrc;
+  }
 }
 
 /* must be called with the session lock, the returned source needs to be
@@ -1458,6 +1461,28 @@ rtp_session_get_internal_ssrc (RTPSession * sess)
 }
 
 /**
+ * rtp_session_suggest_ssrc:
+ * @sess: a #RTPSession
+ *
+ * Suggest an unused SSRC in @sess.
+ *
+ * Returns: a free unused SSRC
+ */
+guint32
+rtp_session_suggest_ssrc (RTPSession * sess)
+{
+  guint32 result;
+
+  g_return_val_if_fail (RTP_IS_SESSION (sess), 0);
+
+  RTP_SESSION_LOCK (sess);
+  result = sess->suggested_ssrc;
+  RTP_SESSION_UNLOCK (sess);
+
+  return result;
+}
+
+/**
  * rtp_session_add_source:
  * @sess: a #RTPSession
  * @src: #RTPSource to add
index a9d8b65..301b92e 100644 (file)
@@ -199,6 +199,7 @@ struct _RTPSession {
   guint        rtcp_rs_bandwidth;
 
   RTPSource    *source;
+  guint32       suggested_ssrc;
 
   /* for sender/receiver counting */
   guint32       key;
@@ -310,6 +311,7 @@ RTPSource*      rtp_session_get_internal_source    (RTPSession *sess);
 
 void            rtp_session_set_internal_ssrc      (RTPSession *sess, guint32 ssrc);
 guint32         rtp_session_get_internal_ssrc      (RTPSession *sess);
+guint32         rtp_session_suggest_ssrc           (RTPSession *sess);
 
 gboolean        rtp_session_add_source             (RTPSession *sess, RTPSource *src);
 guint           rtp_session_get_num_sources        (RTPSession *sess);