[telepathy-gabble/master] React to SupportedCodecs once when necessary.

Will Thompson will.thompson at collabora.co.uk
Thu Apr 30 12:13:30 PDT 2009


For streams that we add, we never need to do anything in response to
SupportedCodecs. For streams that the peer adds, we need to send an
intersection exactly once.

Previously, the latter was mis-implemented as "ignore calls to
SupportedCodecs once the peer has sent us description-info". This worked
fine except when the peer sent description-info before we sent our
intersection.
---
 src/media-stream.c |   66 ++++++++++++++++++++++------------------------------
 1 files changed, 28 insertions(+), 38 deletions(-)

diff --git a/src/media-stream.c b/src/media-stream.c
index 0e7dbe0..cdfd00a 100644
--- a/src/media-stream.c
+++ b/src/media-stream.c
@@ -109,10 +109,10 @@ struct _GabbleMediaStreamPrivate
   GValue native_codecs;     /* intersected codec list */
   GValue native_candidates;
 
-  /* Whether we're updating, as opposed to discovering, remote codecs.
-   * Changes SupportedCodecs/Error to no-ops.
+  /* Whether we're waiting for a codec intersection from the streaming
+   * implementation. If FALSE, SupportedCodecs is a no-op.
    */
-  gboolean updating_remote_codecs;
+  gboolean awaiting_intersection;
 
   GValue remote_codecs;
   GValue remote_candidates;
@@ -228,8 +228,6 @@ gabble_media_stream_init (GabbleMediaStream *self)
       dbus_g_type_specialized_construct (candidate_list_type));
 
   priv->stun_servers = g_ptr_array_sized_new (1);
-
-  priv->updating_remote_codecs = FALSE;
 }
 
 static gboolean
@@ -319,6 +317,10 @@ gabble_media_stream_constructor (GType type, guint n_props,
           MAKE_COMBINED_DIRECTION (TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL,
             0), NULL);
     }
+  else
+    {
+      priv->awaiting_intersection = TRUE;
+    }
 
   return obj;
 }
@@ -790,15 +792,9 @@ gabble_media_stream_error_async (TpSvcMediaStreamHandler *iface,
                                  DBusGMethodInvocation *context)
 {
   GabbleMediaStream *self = GABBLE_MEDIA_STREAM (iface);
-  GabbleMediaStreamPrivate *priv = self->priv;
   GError *error = NULL;
 
-  /* description-info is purely advisory; if the streaming implementation
-   * doesn't like the new codec parameters, we don't want to terminate the
-   * session. So we don't error out the media stream in that case.
-   */
-  if (priv->updating_remote_codecs ||
-      gabble_media_stream_error (self, errno, message, &error))
+  if (gabble_media_stream_error (self, errno, message, &error))
     {
       tp_svc_media_stream_handler_return_from_error (context);
     }
@@ -1242,28 +1238,28 @@ gabble_media_stream_supported_codecs (TpSvcMediaStreamHandler *iface,
 
   DEBUG ("called");
 
-  /* We don't need to do anything in response to the streaming implementation
-   * deciding it likes the new codec paramaters.
-   */
-  if (!priv->updating_remote_codecs)
+  if (priv->awaiting_intersection)
     {
-      if (gabble_jingle_content_is_created_by_us (self->priv->content))
+      if (!pass_local_codecs (self, codecs, &error))
         {
-          DEBUG ("we already sent our codecs, ignoring codec intersection");
+          DEBUG ("failed: %s", error->message);
+
+          dbus_g_method_return_error (context, error);
+          g_error_free (error);
+          return;
         }
-      else
-        {
-          if (!pass_local_codecs (self, codecs, &error))
-            {
-              DEBUG ("failed: %s", error->message);
 
-              dbus_g_method_return_error (context, error);
-              g_error_free (error);
-              return;
-            }
+      priv->awaiting_intersection = FALSE;
 
-          g_signal_emit (self, signals[SUPPORTED_CODECS], 0, codecs);
-        }
+      g_signal_emit (self, signals[SUPPORTED_CODECS], 0, codecs);
+    }
+  else
+    {
+      /* If we created the stream, we don't need to send the intersection. If
+       * we didn't create it, but have already sent the intersection once, we
+       * don't need to send it again.
+       */
+      DEBUG ("we already sent, or don't need to send, our codecs");
     }
 
   tp_svc_media_stream_handler_return_from_supported_codecs (context);
@@ -1341,17 +1337,11 @@ new_remote_codecs_cb (GabbleJingleContent *content,
 
   codecs = g_value_get_boxed (&priv->remote_codecs);
 
-  /* If the codecs have already been set, this means the peer is updating their
-   * parameters. XEP-0167 says that description-info is advisory, so regardless
-   * of whether the streaming implementation calls SupportedCodecs or Error we
-   * don't want to do anything. So, set a flag to indicate that we've entered
-   * this situation.
-   */
   if (codecs->len != 0)
     {
-      priv->updating_remote_codecs = TRUE;
-
-      /* Free the old codec list, and make a new, empty one to fill in. */
+      /* We already had some codecs; let's free the old list and make a new,
+       * empty one to fill in.
+       */
       g_value_reset (&priv->remote_codecs);
       codecs = dbus_g_type_specialized_construct (
           TP_ARRAY_TYPE_MEDIA_STREAM_HANDLER_CODEC_LIST);
-- 
1.5.6.5




More information about the telepathy-commits mailing list