]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-tp-call.c
add myself to AUTHORS
[empathy.git] / libempathy / empathy-tp-call.c
index a5c0003c56741182ad665d9292d61a811899fd9e..6d0941c396d47115cb8b78b9b942576dfc2c644c 100644 (file)
@@ -29,6 +29,7 @@
 #include "empathy-tp-call.h"
 #include "empathy-tp-contact-factory.h"
 #include "empathy-utils.h"
+#include "empathy-marshal.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_TP
 #include "empathy-debug.h"
@@ -46,6 +47,15 @@ typedef struct
   EmpathyTpCallStream *video;
 } EmpathyTpCallPriv;
 
+/* signal enum */
+enum {
+  AUDIO_STREAM_ERROR,
+  VIDEO_STREAM_ERROR,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = {0};
+
 enum
 {
   PROP_0,
@@ -317,9 +327,13 @@ tp_call_update_status (EmpathyTpCall *call)
 }
 
 void
-empathy_tp_call_to (EmpathyTpCall *call, EmpathyContact *contact)
+empathy_tp_call_to (EmpathyTpCall *call, EmpathyContact *contact,
+  gboolean audio, gboolean video)
 {
   EmpathyTpCallPriv *priv = GET_PRIV (call);
+  EmpathyCapabilities capabilities = 0;
+
+  g_assert (audio || video);
 
   priv->contact = g_object_ref (contact);
   priv->is_incoming = FALSE;
@@ -327,7 +341,13 @@ empathy_tp_call_to (EmpathyTpCall *call, EmpathyContact *contact)
   g_object_notify (G_OBJECT (call), "is-incoming");
   g_object_notify (G_OBJECT (call), "contact");
   g_object_notify (G_OBJECT (call), "status");
-  tp_call_request_streams_for_capabilities (call, EMPATHY_CAPABILITIES_AUDIO);
+
+  if (video)
+    capabilities |= EMPATHY_CAPABILITIES_VIDEO;
+  if (audio)
+    capabilities |= EMPATHY_CAPABILITIES_AUDIO;
+
+  tp_call_request_streams_for_capabilities (call, capabilities);
 }
 
 static void
@@ -351,7 +371,35 @@ tp_call_async_cb (TpProxy *proxy,
                   GObject *call)
 {
   if (error)
-      DEBUG ("Error %s: %s", (gchar*) user_data, error->message);
+      DEBUG ("Error %s: %s", (gchar *) user_data, error->message);
+}
+
+static void
+tp_call_stream_error_cb (TpChannel *channel,
+    guint stream_id,
+    guint error_code,
+    const gchar *msg,
+    gpointer user_data,
+    GObject *call)
+{
+  EmpathyTpCall *self = EMPATHY_TP_CALL (call);
+  EmpathyTpCallPriv *priv = GET_PRIV (self);
+
+  DEBUG ("Stream error on stream %u: %s (code: %u)", stream_id, msg,
+      error_code);
+
+  if (priv->audio->id == stream_id)
+    {
+      g_signal_emit (call, signals[AUDIO_STREAM_ERROR], 0, error_code, msg);
+    }
+  else if (priv->video->id == stream_id)
+    {
+      g_signal_emit (call, signals[VIDEO_STREAM_ERROR], 0, error_code, msg);
+    }
+  else
+    {
+      DEBUG ("Unknown stream id: %u", stream_id);
+    }
 }
 
 static GObject *
@@ -380,6 +428,8 @@ tp_call_constructor (GType type,
       tp_call_stream_state_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
   tp_cli_channel_type_streamed_media_connect_to_stream_direction_changed (priv->channel,
       tp_call_stream_direction_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
+  tp_cli_channel_type_streamed_media_connect_to_stream_error (priv->channel,
+      tp_call_stream_error_cb, NULL, NULL, G_OBJECT (call), NULL);
   tp_cli_channel_type_streamed_media_call_list_streams (priv->channel, -1,
       tp_call_request_streams_cb, NULL, NULL, G_OBJECT (call));
 
@@ -522,6 +572,24 @@ empathy_tp_call_class_init (EmpathyTpCallClass *klass)
       g_param_spec_pointer ("video-stream", "Video stream data",
       "Video stream data",
       G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+  signals[AUDIO_STREAM_ERROR] =
+    g_signal_new ("audio-stream-error",
+      G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0,
+      NULL, NULL,
+      _empathy_marshal_VOID__UINT_STRING,
+      G_TYPE_NONE,
+      2, G_TYPE_UINT, G_TYPE_STRING);
+
+  signals[VIDEO_STREAM_ERROR] =
+    g_signal_new ("video-stream-error",
+      G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0,
+      NULL, NULL,
+      _empathy_marshal_VOID__UINT_STRING,
+      G_TYPE_NONE,
+      2, G_TYPE_UINT, G_TYPE_STRING);
 }
 
 static void
@@ -662,3 +730,67 @@ empathy_tp_call_has_dtmf (EmpathyTpCall *call)
       TP_IFACE_QUARK_CHANNEL_INTERFACE_DTMF);
 }
 
+/**
+ * empathy_tp_call_is_receiving_video:
+ * @call: the call
+ *
+ * Indicates if the call is receiving video or not.
+ *
+ * Returns: %TRUE if the call is currently receiving video, %FALSE otherwise.
+ */
+gboolean
+empathy_tp_call_is_receiving_video (EmpathyTpCall *call)
+{
+  EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+  g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
+
+  if (!priv->video->exists)
+    return FALSE;
+
+  return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE ?
+      TRUE : FALSE;
+}
+
+/**
+ * empathy_tp_call_is_sending_video:
+ * @call: the call
+ *
+ * Indicates if the call is sending video or not.
+ *
+ * Returns: %TRUE if the call is currently sending video, %FALSE otherwise.
+ */
+gboolean
+empathy_tp_call_is_sending_video (EmpathyTpCall *call)
+{
+  EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+  g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
+
+  if (!priv->video->exists)
+    return FALSE;
+
+  return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_SEND ?
+      TRUE : FALSE;
+}
+
+const gchar *
+empathy_tp_call_get_connection_manager (EmpathyTpCall *self)
+{
+  EmpathyTpCallPriv *priv = GET_PRIV (self);
+  TpConnection *conn;
+  TpAccount *account;
+
+  if (priv->channel == NULL)
+    return NULL;
+
+  conn = tp_channel_borrow_connection (priv->channel);
+  if (conn == NULL)
+    return NULL;
+
+  account = empathy_get_account_for_connection (conn);
+  if (account == NULL)
+    return NULL;
+
+  return tp_account_get_connection_manager (account);
+}