[Telepathy-commits] [telepathy-glib/master] ExampleCallableMediaStream: add a method to handle peer-requested direction changes

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Mar 18 07:06:53 PDT 2009


---
 examples/cm/callable/media-stream.c |   96 +++++++++++++++++++++++++++++++++++
 examples/cm/callable/media-stream.h |    3 +
 2 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/examples/cm/callable/media-stream.c b/examples/cm/callable/media-stream.c
index 43f9ccd..a9ada6a 100644
--- a/examples/cm/callable/media-stream.c
+++ b/examples/cm/callable/media-stream.c
@@ -504,3 +504,99 @@ example_callable_media_stream_connect (ExampleCallableMediaStream *self)
   self->priv->connected_event_id = g_timeout_add (self->priv->simulation_delay,
       simulate_stream_connected_cb, self);
 }
+
+void
+example_callable_media_stream_receive_direction_request (
+    ExampleCallableMediaStream *self,
+    TpMediaStreamDirection direction)
+{
+  /* The remote user wants to change the direction of this stream to
+   * @direction. Shall we let him? */
+  gboolean sending =
+    ((self->priv->direction & TP_MEDIA_STREAM_DIRECTION_SEND) != 0);
+  gboolean receiving =
+    ((self->priv->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE) != 0);
+  gboolean send_requested =
+    ((direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE) != 0);
+  gboolean receive_requested =
+    ((direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE) != 0);
+  gboolean pending_remote_send =
+    ((self->priv->pending_send & TP_MEDIA_STREAM_PENDING_REMOTE_SEND) != 0);
+  gboolean pending_local_send =
+    ((self->priv->pending_send & TP_MEDIA_STREAM_PENDING_LOCAL_SEND) != 0);
+  gboolean changed = FALSE;
+
+  if (send_requested)
+    {
+      g_message ("SIGNALLING: receive: Please start sending me stream %u",
+          self->priv->id);
+
+      if (!sending)
+        {
+          /* ask the user for permission */
+          self->priv->pending_send |= TP_MEDIA_STREAM_PENDING_LOCAL_SEND;
+          changed = TRUE;
+        }
+      else
+        {
+          /* nothing to do, we're already sending on that stream */
+        }
+    }
+  else
+    {
+      g_message ("SIGNALLING: receive: Please stop sending me stream %u",
+          self->priv->id);
+      g_message ("SIGNALLING: send: OK, not sending stream %u",
+          self->priv->id);
+
+      if (sending)
+        {
+          g_message ("MEDIA: No longer sending media to peer for stream %u",
+              self->priv->id);
+          self->priv->direction &= ~TP_MEDIA_STREAM_DIRECTION_SEND;
+          changed = TRUE;
+        }
+      else if (pending_local_send)
+        {
+          self->priv->pending_send &= ~TP_MEDIA_STREAM_PENDING_LOCAL_SEND;
+          changed = TRUE;
+        }
+      else
+        {
+          /* nothing to do, we're not sending on that stream anyway */
+        }
+    }
+
+  if (receive_requested)
+    {
+      g_message ("SIGNALLING: receive: I will now send you media on stream %u",
+          self->priv->id);
+
+      if (!receiving)
+        {
+          self->priv->pending_send &= ~TP_MEDIA_STREAM_PENDING_REMOTE_SEND;
+          self->priv->direction |= TP_MEDIA_STREAM_DIRECTION_RECEIVE;
+          changed = TRUE;
+        }
+    }
+  else
+    {
+      if (pending_remote_send)
+        {
+          g_message ("SIGNALLING: receive: No, I refuse to send you media on "
+              "stream %u", self->priv->id);
+          self->priv->pending_send &= ~TP_MEDIA_STREAM_PENDING_REMOTE_SEND;
+          changed = TRUE;
+        }
+      else if (receiving)
+        {
+          g_message ("SIGNALLING: receive: I will no longer send you media on "
+              "stream %u", self->priv->id);
+          self->priv->direction &= ~TP_MEDIA_STREAM_DIRECTION_RECEIVE;
+          changed = TRUE;
+        }
+    }
+
+  if (changed)
+    g_signal_emit (self, signals[SIGNAL_DIRECTION_CHANGED], 0);
+}
diff --git a/examples/cm/callable/media-stream.h b/examples/cm/callable/media-stream.h
index 5f5d916..4cff5b8 100644
--- a/examples/cm/callable/media-stream.h
+++ b/examples/cm/callable/media-stream.h
@@ -78,6 +78,9 @@ void example_callable_media_stream_connect (ExampleCallableMediaStream *self);
 void example_callable_media_stream_simulate_contact_agreed_to_send (
     ExampleCallableMediaStream *self);
 
+void example_callable_media_stream_receive_direction_request (
+    ExampleCallableMediaStream *self, TpMediaStreamDirection direction);
+
 G_END_DECLS
 
 #endif
-- 
1.5.6.5




More information about the telepathy-commits mailing list