[telepathy-sofiasip/master] Removed some race conditions in call holding

Mikhail Zabaluev mikhail.zabaluev at nokia.com
Wed Sep 2 10:47:44 PDT 2009


---
 src/sip-media-session.c |   26 ++++++++------------------
 src/sip-media-stream.c  |   19 +++++++++++++++++++
 src/sip-media-stream.h  |    2 ++
 3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/sip-media-session.c b/src/sip-media-session.c
index 427932c..ad6dd32 100644
--- a/src/sip-media-session.c
+++ b/src/sip-media-session.c
@@ -1166,7 +1166,8 @@ priv_initiate_hold (TpsipMediaSession *self,
 
   if (hold)
     {
-      if (priv->hold_state == TP_LOCAL_HOLD_STATE_HELD)
+      if (priv->hold_state == TP_LOCAL_HOLD_STATE_HELD
+          || priv->hold_state == TP_LOCAL_HOLD_STATE_PENDING_HOLD)
         {
           g_message ("redundant hold request");
           return;
@@ -1174,7 +1175,8 @@ priv_initiate_hold (TpsipMediaSession *self,
     }
   else
     {
-      if (priv->hold_state == TP_LOCAL_HOLD_STATE_UNHELD)
+      if (priv->hold_state == TP_LOCAL_HOLD_STATE_UNHELD
+          || priv->hold_state == TP_LOCAL_HOLD_STATE_PENDING_UNHOLD)
         {
           g_message ("redundant unhold request");
           return;
@@ -1185,18 +1187,9 @@ priv_initiate_hold (TpsipMediaSession *self,
   for (i = 0; i < priv->streams->len; i++)
     {
       stream = g_ptr_array_index(priv->streams, i);
-      if (stream != NULL)
-        {
-          gboolean stream_held = FALSE;
-          g_object_get (stream,
-                        "hold-state", &stream_held,
-                        NULL);
-          if ((!stream_held) != (!hold))
-            {
-              tp_svc_media_stream_handler_emit_set_stream_held (stream, hold);
-              stream_hold_requested = TRUE;
-            }
-        }
+      if (stream != NULL
+          && tpsip_media_stream_request_hold_state (stream, hold))
+        stream_hold_requested = TRUE;
     }
 
   if (stream_hold_requested)
@@ -1938,10 +1931,7 @@ priv_stream_hold_state_cb (TpsipMediaStream *stream,
       break;
     default:
       g_message ("unexpected hold state change from a stream");
-
-      /* Try to follow the changes and report the resulting hold state */
-      g_object_get (stream, "hold-state", &hold, NULL);
-      priv->hold_reason = TP_LOCAL_HOLD_STATE_REASON_NONE;
+      return;
     }
 
   /* Check if all streams have reached the desired hold state */
diff --git a/src/sip-media-stream.c b/src/sip-media-stream.c
index 74dae60..135c0f7 100644
--- a/src/sip-media-stream.c
+++ b/src/sip-media-stream.c
@@ -124,6 +124,7 @@ struct _TpsipMediaStreamPrivate
   gboolean push_remote_cands_pending;   /* SetRemoteCandidates emission is pending */
   gboolean push_remote_codecs_pending;  /* SetRemoteCodecs emission is pending */
   gboolean codec_intersect_pending;     /* codec intersection is pending */
+  gboolean requested_hold_state;        /* hold state last requested from the stream handler */
   gboolean dispose_has_run;
 };
 
@@ -841,6 +842,10 @@ static void
 tpsip_media_stream_unhold_failure (TpSvcMediaStreamHandler *self,
                                    DBusGMethodInvocation *context)
 {
+  /* Not doing anything to hold_state or requested_hold_state,
+   * because the session is going to put all streams on hold after getting
+   * the signal below */
+
   g_signal_emit (self, signals[SIG_UNHOLD_FAILURE], 0);
   tp_svc_media_stream_handler_return_from_unhold_failure (context);
 }
@@ -1259,6 +1264,20 @@ tpsip_media_stream_stop_telephony_event  (TpsipMediaStream *self)
         (TpSvcMediaStreamHandler *)self);
 }
 
+gboolean
+tpsip_media_stream_request_hold_state (TpsipMediaStream *self, gboolean hold)
+{
+  TpsipMediaStreamPrivate *priv = TPSIP_MEDIA_STREAM_GET_PRIVATE (self);
+
+  if ((!priv->requested_hold_state) != (!hold))
+    {
+      priv->requested_hold_state = hold;
+      tp_svc_media_stream_handler_emit_set_stream_held (self, hold);
+      return TRUE;
+    }
+  return FALSE;
+}
+
 static void
 priv_generate_sdp (TpsipMediaStream *self)
 {
diff --git a/src/sip-media-stream.h b/src/sip-media-stream.h
index 9e93109..4aaaeb6 100644
--- a/src/sip-media-stream.h
+++ b/src/sip-media-stream.h
@@ -77,6 +77,8 @@ gboolean tpsip_media_stream_is_local_ready (TpsipMediaStream *self);
 gboolean tpsip_media_stream_is_codec_intersect_pending (TpsipMediaStream *self);
 void tpsip_media_stream_start_telephony_event (TpsipMediaStream *self, guchar event);
 void tpsip_media_stream_stop_telephony_event  (TpsipMediaStream *self);
+gboolean tpsip_media_stream_request_hold_state (TpsipMediaStream *self,
+                                                gboolean hold);
 
 guint tpsip_tp_media_type (sdp_media_e sip_mtype);
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list