[telepathy-gabble/master] Add a name argument to the jingle session

Sjoerd Simons sjoerd.simons at collabora.co.uk
Tue Dec 29 05:35:22 PST 2009


Allow other bits of code to suggest a name when creating a new content
in a jingle session. Also default audio/video streams to have respectively
Audio/Video as their default names. In case of content naming colisions
suffix the suggested/default name with _%d to prevent confusing clients that
think content names are unique.
---
 src/call-channel.c                           |    2 +-
 src/jingle-session.c                         |   32 ++++++++++++++++---------
 src/jingle-session.h                         |    7 ++++-
 src/media-channel.c                          |    2 +-
 tests/twisted/jingle/call-state.py           |    2 +-
 tests/twisted/jingle/jingletest.py           |    4 +-
 tests/twisted/jingle/test-outgoing-iceudp.py |    4 +-
 7 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/call-channel.c b/src/call-channel.c
index df9ed1e..8cfaab4 100644
--- a/src/call-channel.c
+++ b/src/call-channel.c
@@ -713,7 +713,7 @@ call_channel_create_content (GabbleCallChannel *self,
     content_ns, priv->transport_ns);
 
   c = gabble_jingle_session_add_content (priv->session,
-      type, content_ns, priv->transport_ns);
+      type, name, content_ns, priv->transport_ns);
 
   g_assert (c != NULL);
 
diff --git a/src/jingle-session.c b/src/jingle-session.c
index a9d5851..e7c7f39 100644
--- a/src/jingle-session.c
+++ b/src/jingle-session.c
@@ -759,7 +759,8 @@ create_content (GabbleJingleSession *sess, GType content_type,
   GabbleJingleContent *c;
   GHashTable *contents;
 
-  DEBUG ("session creating new content type, conn == %p, jf == %p", priv->conn, priv->conn->jingle_factory);
+  DEBUG ("session creating new content name %s, type %d, conn %p, jf %p",
+    name, type, priv->conn, priv->conn->jingle_factory);
 
   /* FIXME: media-type is introduced by GabbleJingleMediaRTP, not by the
    * superclass, so this call is unsafe in the general case */
@@ -2108,24 +2109,31 @@ gabble_jingle_session_remove_content (GabbleJingleSession *sess,
 }
 
 GabbleJingleContent *
-gabble_jingle_session_add_content (GabbleJingleSession *sess, JingleMediaType mtype,
-    const gchar *content_ns, const gchar *transport_ns)
+gabble_jingle_session_add_content (GabbleJingleSession *sess,
+    JingleMediaType mtype,
+    const gchar *name,
+    const gchar *content_ns,
+    const gchar *transport_ns)
 {
   GabbleJingleSessionPrivate *priv = sess->priv;
   GabbleJingleContent *c;
   GType content_type;
-  gchar *name = NULL;
   GHashTable *contents = priv->local_initiator ? priv->initiator_contents
       : priv->responder_contents;
   guint id = g_hash_table_size (contents) + 1;
+  gchar *cname = NULL;
+
+  if (name == NULL || *name == '\0')
+     name = (mtype == JINGLE_MEDIA_TYPE_AUDIO ?  "Audio" : "Video");
+
+  cname = g_strdup (name);
 
-  do
+  while (g_hash_table_lookup (priv->initiator_contents, cname) != NULL
+      || g_hash_table_lookup (priv->responder_contents, cname) != NULL)
     {
-      g_free (name);
-      name = g_strdup_printf ("stream%d", id++);
+      g_free (cname);
+      cname = g_strdup_printf ("%s_%d", name, id++);
     }
-  while (g_hash_table_lookup (priv->initiator_contents, name) != NULL
-      && g_hash_table_lookup (priv->responder_contents, name) != NULL);
 
   content_type = gabble_jingle_factory_lookup_content_type (
       priv->conn->jingle_factory, content_ns);
@@ -2133,12 +2141,12 @@ gabble_jingle_session_add_content (GabbleJingleSession *sess, JingleMediaType mt
   g_assert (content_type != 0);
 
   c = create_content (sess, content_type, mtype,
-      content_ns, transport_ns, name, NULL, NULL);
+      content_ns, transport_ns, cname, NULL, NULL);
 
   /* The new content better have ended up in the set we thought it would... */
-  g_assert (g_hash_table_lookup (contents, name) != NULL);
+  g_assert (g_hash_table_lookup (contents, cname) != NULL);
 
-  g_free (name);
+  g_free (cname);
 
   return c;
 }
diff --git a/src/jingle-session.h b/src/jingle-session.h
index 4dd735f..628a7b9 100644
--- a/src/jingle-session.h
+++ b/src/jingle-session.h
@@ -102,8 +102,11 @@ void gabble_jingle_session_remove_content (GabbleJingleSession *sess,
     GabbleJingleContent *c);
 
 GabbleJingleContent *
-gabble_jingle_session_add_content (GabbleJingleSession *sess, JingleMediaType mtype,
-    const gchar *content_ns, const gchar *transport_ns);
+gabble_jingle_session_add_content (GabbleJingleSession *sess,
+    JingleMediaType mtype,
+    const char *name,
+    const gchar *content_ns,
+    const gchar *transport_ns);
 
 GType gabble_jingle_session_get_content_type (GabbleJingleSession *);
 GList *gabble_jingle_session_get_contents (GabbleJingleSession *sess);
diff --git a/src/media-channel.c b/src/media-channel.c
index 33b2fef..0097bd6 100644
--- a/src/media-channel.c
+++ b/src/media-channel.c
@@ -1636,7 +1636,7 @@ _gabble_media_channel_request_contents (GabbleMediaChannel *chan,
       c = gabble_jingle_session_add_content (priv->session,
           media_type == TP_MEDIA_STREAM_TYPE_AUDIO ?
             JINGLE_MEDIA_TYPE_AUDIO : JINGLE_MEDIA_TYPE_VIDEO,
-            content_ns, transport_ns);
+            NULL, content_ns, transport_ns);
 
       /* The stream is created in "new-content" callback, and appended to
        * priv->streams. This is now guaranteed to happen asynchronously (adding
diff --git a/tests/twisted/jingle/call-state.py b/tests/twisted/jingle/call-state.py
index b75fd02..b7dead7 100644
--- a/tests/twisted/jingle/call-state.py
+++ b/tests/twisted/jingle/call-state.py
@@ -254,7 +254,7 @@ def test(jp, q, bus, conn, stream):
     node = jp.SetIq(jt.peer, jt.jid, [
         jp.Jingle(jt.sid, jt.jid, 'session-info', [
             ('mute', ns.JINGLE_RTP_INFO_1,
-             {'name': 'stream1', 'creator': 'initiator'}, []) ]) ])
+             {'name': 'Audio', 'creator': 'initiator'}, []) ]) ])
     stream.send(jp.xml(node))
 
     forbidden = [
diff --git a/tests/twisted/jingle/jingletest.py b/tests/twisted/jingle/jingletest.py
index ca84deb..e557a89 100644
--- a/tests/twisted/jingle/jingletest.py
+++ b/tests/twisted/jingle/jingletest.py
@@ -190,11 +190,11 @@ class JingleTest:
 
         iq, jingle = self._jingle_stanza('session-accept')
 
-        jingle.addChild(self.create_content_node('stream1', 'audio',
+        jingle.addChild(self.create_content_node('Audio', 'audio',
             self.audio_codecs))
 
         if with_video:
-            jingle.addChild(self.create_content_node('stream2', 'video',
+            jingle.addChild(self.create_content_node('Video', 'video',
                 self.video_codecs))
 
         self.stream.send(iq.toXml())
diff --git a/tests/twisted/jingle/test-outgoing-iceudp.py b/tests/twisted/jingle/test-outgoing-iceudp.py
index 209d6c5..8805391 100644
--- a/tests/twisted/jingle/test-outgoing-iceudp.py
+++ b/tests/twisted/jingle/test-outgoing-iceudp.py
@@ -101,7 +101,7 @@ def worker(jp, q, bus, conn, stream):
 
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'transport-info', [
-            jp.Content('stream1', 'initiator', 'both', [
+            jp.Content('Audio', 'initiator', 'both', [
                 transport]) ]) ])
     stream.send(jp.xml(node))
 
@@ -128,7 +128,7 @@ def worker(jp, q, bus, conn, stream):
     # This is what pidgin does.
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'session-accept', [
-            jp.Content('stream1', 'initiator', 'both', [
+            jp.Content('Audio', 'initiator', 'both', [
                 jp.Description('audio', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-- 
1.5.6.5




More information about the telepathy-commits mailing list