[Telepathy-commits] [telepathy-glib/master] ExampleCallableMediaStream: simulate the streams becoming connected

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Mar 13 09:30:27 PDT 2009


---
 examples/cm/callable/media-channel.c |   32 ++++++++++++++++++++++
 examples/cm/callable/media-stream.c  |   48 +++++++++++++++++++++++++++++++--
 examples/cm/callable/media-stream.h  |    1 +
 3 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/examples/cm/callable/media-channel.c b/examples/cm/callable/media-channel.c
index 853b20d..10b70fb 100644
--- a/examples/cm/callable/media-channel.c
+++ b/examples/cm/callable/media-channel.c
@@ -803,11 +803,29 @@ stream_direction_changed_cb (ExampleCallableMediaStream *stream,
       direction, pending);
 }
 
+static void
+stream_state_changed_cb (ExampleCallableMediaStream *stream,
+                         GParamSpec *spec G_GNUC_UNUSED,
+                         ExampleCallableMediaChannel *self)
+{
+  guint id, state;
+
+  g_object_get (stream,
+      "id", &id,
+      "state", &state,
+      NULL);
+
+  tp_svc_channel_type_streamed_media_emit_stream_state_changed (self, id,
+      state);
+}
+
 static gboolean
 simulate_contact_answered_cb (gpointer p)
 {
   ExampleCallableMediaChannel *self = p;
   TpIntSet *peer_set;
+  GHashTableIter iter;
+  gpointer v;
 
   /* if the call has been cancelled while we were waiting for the
    * contact to answer, do nothing */
@@ -832,6 +850,13 @@ simulate_contact_answered_cb (gpointer p)
       TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
   tp_intset_destroy (peer_set);
 
+  g_hash_table_iter_init (&iter, self->priv->streams);
+
+  while (g_hash_table_iter_next (&iter, NULL, &v))
+    {
+      example_callable_media_stream_connect (v);
+    }
+
   return FALSE;
 }
 
@@ -936,9 +961,16 @@ media_request_streams (TpSvcChannelTypeStreamedMedia *iface,
 
       g_signal_connect (stream, "removed", G_CALLBACK (stream_removed_cb),
           self);
+      g_signal_connect (stream, "notify::state",
+          G_CALLBACK (stream_state_changed_cb), self);
       g_signal_connect (stream, "direction-changed",
           G_CALLBACK (stream_direction_changed_cb), self);
 
+      if (self->priv->progress == PROGRESS_ACTIVE)
+        {
+          example_callable_media_stream_connect (stream);
+        }
+
       g_object_get (stream,
           "stream-info", &info,
           NULL);
diff --git a/examples/cm/callable/media-stream.c b/examples/cm/callable/media-stream.c
index 605bd04..e3dff22 100644
--- a/examples/cm/callable/media-stream.c
+++ b/examples/cm/callable/media-stream.c
@@ -66,7 +66,12 @@ struct _ExampleCallableMediaStreamPrivate
   TpMediaStreamState state;
   TpMediaStreamDirection direction;
   TpMediaStreamPendingSend pending_send;
+
   gulong call_terminated_id;
+
+  guint connected_event_id;
+
+  unsigned removed : 1;
 };
 
 static void
@@ -217,6 +222,8 @@ dispose (GObject *object)
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       self->priv->conn, TP_HANDLE_TYPE_CONTACT);
 
+  example_callable_media_stream_close (self);
+
   if (self->priv->handle != 0)
     {
       tp_handle_unref (contact_repo, self->priv->handle);
@@ -323,10 +330,20 @@ example_callable_media_stream_class_init (ExampleCallableMediaStreamClass *klass
 void
 example_callable_media_stream_close (ExampleCallableMediaStream *self)
 {
-  g_message ("Sending to server: Closing stream %u",
-      self->priv->id);
+  if (!self->priv->removed)
+    {
+      self->priv->removed = TRUE;
 
-  g_signal_emit (self, signals[SIGNAL_REMOVED], 0);
+      g_message ("Sending to server: Closing stream %u",
+          self->priv->id);
+
+      g_signal_emit (self, signals[SIGNAL_REMOVED], 0);
+
+      if (self->priv->connected_event_id != 0)
+        {
+          g_source_remove (self->priv->connected_event_id);
+        }
+    }
 }
 
 gboolean
@@ -412,3 +429,28 @@ example_callable_media_stream_change_direction (
 
   return TRUE;
 }
+
+static gboolean
+simulate_stream_connected_cb (gpointer p)
+{
+  ExampleCallableMediaStream *self = EXAMPLE_CALLABLE_MEDIA_STREAM (p);
+
+  g_message ("MEDIA: stream connected");
+  self->priv->state = TP_MEDIA_STREAM_STATE_CONNECTED;
+  g_object_notify ((GObject *) self, "state");
+
+  return FALSE;
+}
+
+void
+example_callable_media_stream_connect (ExampleCallableMediaStream *self)
+{
+
+  /* if already trying to connect, do nothing */
+  if (self->priv->connected_event_id != 0)
+    return;
+
+  /* simulate it taking a short time to connect */
+  self->priv->connected_event_id = g_timeout_add (1000,
+      simulate_stream_connected_cb, self);
+}
diff --git a/examples/cm/callable/media-stream.h b/examples/cm/callable/media-stream.h
index 4f1a508..09d1a8e 100644
--- a/examples/cm/callable/media-stream.h
+++ b/examples/cm/callable/media-stream.h
@@ -71,6 +71,7 @@ void example_callable_media_stream_close (ExampleCallableMediaStream *self);
 gboolean example_callable_media_stream_change_direction (
     ExampleCallableMediaStream *self, TpMediaStreamDirection direction,
     GError **error);
+void example_callable_media_stream_connect (ExampleCallableMediaStream *self);
 
 G_END_DECLS
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list