[telepathy-gabble/master] Update incoming <hold/>, etc. to match current XEP-0167

Will Thompson will.thompson at collabora.co.uk
Wed May 20 10:32:31 PDT 2009


<hold/> and <mute/> and <ringing/> are now orthogonal, so saying a
stream is muted doesn't mean it's unheld; thus, I had to change the test
case.
---
 src/jingle-media-rtp.c             |   37 ++++++++++++++++++++++------------
 src/media-channel-hold.c           |   39 +++++++++++++++++------------------
 src/media-stream.c                 |    2 +-
 tests/twisted/jingle/call-state.py |   21 ++++++++++++-------
 4 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/src/jingle-media-rtp.c b/src/jingle-media-rtp.c
index c7acbf3..ab89096 100644
--- a/src/jingle-media-rtp.c
+++ b/src/jingle-media-rtp.c
@@ -829,7 +829,7 @@ gabble_jingle_media_rtp_handle_info (GabbleJingleContent *content,
   const gchar *elt = lm_message_node_get_name (payload);
   const gchar *name_attr = lm_message_node_get_attribute (payload, "name");
   const gchar *content_name = gabble_jingle_content_get_name (content);
-  JingleRtpRemoteState new_state;
+  JingleRtpRemoteState state = self->priv->remote_state;
 
   if (tp_strdiff (ns, NS_JINGLE_RTP_INFO))
     {
@@ -839,26 +839,37 @@ gabble_jingle_media_rtp_handle_info (GabbleJingleContent *content,
 
   *handled = TRUE;
 
-  /* The XEP only says active and mute can have name="". */
   if (!tp_strdiff (elt, "active"))
     {
-      if (name_attr != NULL && tp_strdiff (name_attr, content_name))
-        return TRUE;
-      new_state = JINGLE_RTP_REMOTE_STATE_ACTIVE;
+      /* Clear all states, we're active */
+      state = JINGLE_RTP_REMOTE_STATE_ACTIVE;
     }
   else if (!tp_strdiff (elt, "ringing"))
     {
-      new_state = JINGLE_RTP_REMOTE_STATE_RINGING;
+      state |= JINGLE_RTP_REMOTE_STATE_RINGING;
     }
   else if (!tp_strdiff (elt, "hold"))
     {
-      new_state = JINGLE_RTP_REMOTE_STATE_HOLD;
+      state |= JINGLE_RTP_REMOTE_STATE_HOLD;
     }
+  else if (!tp_strdiff (elt, "unhold"))
+    {
+      state &= ~JINGLE_RTP_REMOTE_STATE_HOLD;
+    }
+  /* XEP-0178 says that only <mute/> and <unmute/> can have a name='' attribute. */
   else if (!tp_strdiff (elt, "mute"))
     {
       if (name_attr != NULL && tp_strdiff (name_attr, content_name))
         return TRUE;
-      new_state = JINGLE_RTP_REMOTE_STATE_MUTE;
+
+      state |= JINGLE_RTP_REMOTE_STATE_MUTE;
+    }
+  else if (!tp_strdiff (elt, "unmute"))
+    {
+      if (name_attr != NULL && tp_strdiff (name_attr, content_name))
+        return TRUE;
+
+      state &= ~JINGLE_RTP_REMOTE_STATE_MUTE;
     }
   else
     {
@@ -867,16 +878,16 @@ gabble_jingle_media_rtp_handle_info (GabbleJingleContent *content,
       return FALSE;
     }
 
-  if (new_state != self->priv->remote_state)
+  if (state != self->priv->remote_state)
     {
-      DEBUG ("moving from remote state %u to %u (%s)", self->priv->remote_state,
-          new_state, elt);
-      self->priv->remote_state = new_state;
+      DEBUG ("moving from remote state %u to %u (due to <%s/>)",
+          self->priv->remote_state, state, elt);
+      self->priv->remote_state = state;
       g_object_notify ((GObject *) self, "remote-state");
     }
   else
     {
-      DEBUG ("already in state %u (%s)", new_state, elt);
+      DEBUG ("already in state %u (<%s/> had no effect)", state, elt);
     }
 
   return TRUE;
diff --git a/src/media-channel-hold.c b/src/media-channel-hold.c
index 509a9c3..2a9215b 100644
--- a/src/media-channel-hold.c
+++ b/src/media-channel-hold.c
@@ -293,19 +293,18 @@ gabble_media_channel_hold_iface_init (gpointer g_iface,
 static TpChannelCallStateFlags
 jingle_remote_state_to_csf (JingleRtpRemoteState state)
 {
-  switch (state)
-    {
-    case JINGLE_RTP_REMOTE_STATE_ACTIVE:
-    /* FIXME: we should be able to expose <mute/> through CallState */
-    case JINGLE_RTP_REMOTE_STATE_MUTE:
-      return 0;
-    case JINGLE_RTP_REMOTE_STATE_RINGING:
-      return TP_CHANNEL_CALL_STATE_RINGING;
-    case JINGLE_RTP_REMOTE_STATE_HOLD:
-      return TP_CHANNEL_CALL_STATE_HELD;
-    default:
-      g_assert_not_reached ();
-    }
+  TpChannelCallStateFlags ret = 0;
+
+  if (state & JINGLE_RTP_REMOTE_STATE_MUTE)
+    DEBUG ("FIXME: we should be able to expose <mute/> through CallState");
+
+  if (state & JINGLE_RTP_REMOTE_STATE_RINGING)
+    ret |= TP_CHANNEL_CALL_STATE_RINGING;
+
+  if (state & JINGLE_RTP_REMOTE_STATE_HOLD)
+    ret |= TP_CHANNEL_CALL_STATE_HELD;
+
+  return ret;
 }
 
 
@@ -327,18 +326,18 @@ remote_state_changed_cb (GabbleJingleMediaRtp *rtp,
       return;
     }
 
-  if (state > priv->remote_state)
+  if ((state & priv->remote_state) == priv->remote_state)
     {
-      /* If this content's state is "more held" than the current aggregated level,
-       * move up to it.
+      /* state has a superset of the flags in the current aggregated level, add
+       * the new flags.
        */
-      DEBUG ("%u is more held than %u, moving up", state, priv->remote_state);
+      DEBUG ("%u is a superset of %u", state, priv->remote_state);
       priv->remote_state = state;
     }
   else
     {
       /* This content is now less held than the current aggregated level; we
-       * need to recalculate the highest hold level and see if it's changed.
+       * need to recalculate the combined hold level and see if it's changed.
        */
       guint i = 0;
 
@@ -351,8 +350,8 @@ remote_state_changed_cb (GabbleJingleMediaRtp *rtp,
                 g_ptr_array_index (priv->streams, i));
           JingleRtpRemoteState s = gabble_jingle_media_rtp_get_remote_state (c);
 
-          state = MAX (state, s);
-          DEBUG ("%p in state %u; high water mark %u", c, s, state);
+          state |= s;
+          DEBUG ("%p in state %u; combined flags so far are %u", c, s, state);
         }
 
       if (priv->remote_state == state)
diff --git a/src/media-stream.c b/src/media-stream.c
index 71367db..2a2c0ef 100644
--- a/src/media-stream.c
+++ b/src/media-stream.c
@@ -1603,7 +1603,7 @@ remote_state_changed_cb (GabbleJingleMediaRtp *rtp,
   JingleRtpRemoteState state = gabble_jingle_media_rtp_get_remote_state (rtp);
   gboolean old_hold = priv->on_hold;
 
-  priv->on_hold = (state == JINGLE_RTP_REMOTE_STATE_HOLD);
+  priv->on_hold = (state & JINGLE_RTP_REMOTE_STATE_HOLD);
 
   if (old_hold != priv->on_hold)
     push_sending (stream);
diff --git a/tests/twisted/jingle/call-state.py b/tests/twisted/jingle/call-state.py
index 48baae5..cbf7420 100644
--- a/tests/twisted/jingle/call-state.py
+++ b/tests/twisted/jingle/call-state.py
@@ -7,7 +7,7 @@ from twisted.words.xish import xpath
 
 from gabbletest import make_result_iq
 from servicetest import (
-    wrap_channel, make_channel_proxy, EventPattern, tp_path_prefix)
+    wrap_channel, make_channel_proxy, EventPattern, tp_path_prefix, sync_dbus)
 import ns
 import constants as cs
 
@@ -195,25 +195,30 @@ def test(jp, q, bus, conn, stream):
     call_states = chan.CallState.GetCallStates()
     assert call_states == { handle: cs.CALL_STATE_HELD }, call_states
 
-    # Now the other person sets the audio stream to mute. Gabble should expose
-    # this as the call being active again (since we can't represent mute yet!)
-    # and tell s-e to start sending audio again.
+    # Now the other person sets the audio stream to mute. We can't represent
+    # mute yet, but Gabble shouldn't take this to mean the call is active, as
+    # one stream being muted doesn't change the fact that the call's on hold.
     # FIXME: hardcoded stream id
     node = jp.SetIq(jt.peer, jt.jid, [
         jp.Jingle(jt.sid, jt.jid, 'session-info', [
             ('mute', ns.JINGLE_RTP_INFO_1, {'name': 'stream1'}, []) ]) ])
     stream.send(jp.xml(node))
 
-    q.expect_many(
-        EventPattern('stream-iq', iq_type='result', iq_id=node[2]['id']),
+    forbidden = [
         EventPattern('dbus-signal', signal='SetStreamSending', args=[True],
             path=audio_path_suffix),
         EventPattern('dbus-signal', signal='CallStateChanged',
             args=[ handle, 0 ]),
-        )
+            ]
+    q.forbid_events(forbidden)
+
+    q.expect('stream-iq', iq_type='result', iq_id=node[2]['id'])
 
     call_states = chan.CallState.GetCallStates()
-    assert call_states == { handle: 0 } or call_states == {}, call_states
+    assert call_states == { handle: cs.CALL_STATE_HELD }, call_states
+
+    sync_dbus(bus, q, conn)
+    q.unforbid_events(forbidden)
 
     # That'll do, pig.
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list