]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-call-handler.c
Merge branch 'master' into tp-tube
[empathy.git] / libempathy / empathy-call-handler.c
index 59afe3f9975a591e08a4c4320c85f0ad8ee38c6f..820de6de59592cd6f4ff0a62ccc218ae7ea80110 100644 (file)
@@ -39,6 +39,7 @@ enum {
   CONFERENCE_ADDED,
   SRC_PAD_ADDED,
   SINK_PAD_ADDED,
+  REQUEST_RESOURCE,
   CLOSED,
   LAST_SIGNAL
 };
@@ -197,6 +198,13 @@ empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
       G_TYPE_NONE,
       2, GST_TYPE_PAD, G_TYPE_UINT);
 
+  signals[REQUEST_RESOURCE] =
+    g_signal_new ("request-resource", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0,
+      g_signal_accumulator_true_handled, NULL,
+      _empathy_marshal_BOOLEAN__UINT_UINT,
+      G_TYPE_BOOLEAN, 2, G_TYPE_UINT, G_TYPE_UINT);
+
   signals[CLOSED] =
     g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -257,7 +265,15 @@ static gboolean
 empathy_call_handler_tf_stream_request_resource_cb (TfStream *stream,
   guint direction, EmpathyTpCall *call)
 {
-  return TRUE;
+  gboolean ret;
+  guint media_type;
+
+  g_object_get (G_OBJECT (stream), "media-type", &media_type, NULL);
+
+  g_signal_emit (G_OBJECT (call),
+    signals[REQUEST_RESOURCE], 0, media_type, direction, &ret);
+
+  return ret;
 }
 
 static void
@@ -289,6 +305,56 @@ empathy_call_handler_tf_channel_closed_cb (TfChannel *tfchannel,
   g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
 }
 
+static GList *
+empathy_call_handler_tf_channel_codec_config_get_defaults (FsCodec *codecs)
+{
+  GList *l = NULL;
+  int i;
+
+  for (i = 0; codecs[i].encoding_name != NULL; i++)
+      l = g_list_append (l, fs_codec_copy (codecs + i));
+
+  return l;
+}
+
+static GList *
+empathy_call_handler_tf_channel_codec_config_cb (TfChannel *channel,
+  guint stream_id, FsMediaType media_type, guint direction, gpointer user_data)
+{
+  FsCodec audio_codecs[] = {
+    { FS_CODEC_ID_ANY, "SPEEX", FS_MEDIA_TYPE_AUDIO, 16000, },
+    { FS_CODEC_ID_ANY, "SPEEX", FS_MEDIA_TYPE_AUDIO, 8000, },
+
+    { FS_CODEC_ID_DISABLE, "DV",     FS_MEDIA_TYPE_AUDIO, },
+    { FS_CODEC_ID_DISABLE, "MPA",    FS_MEDIA_TYPE_AUDIO, },
+    { FS_CODEC_ID_DISABLE, "VORBIS", FS_MEDIA_TYPE_AUDIO, },
+    { FS_CODEC_ID_DISABLE, "MP3",    FS_MEDIA_TYPE_AUDIO, },
+    { 0, NULL, 0,}
+  };
+  FsCodec video_codecs[] = {
+    { FS_CODEC_ID_ANY, "H264",   FS_MEDIA_TYPE_VIDEO, },
+    { FS_CODEC_ID_ANY, "THEORA", FS_MEDIA_TYPE_VIDEO, },
+    { FS_CODEC_ID_ANY, "H263",   FS_MEDIA_TYPE_VIDEO, },
+
+    { FS_CODEC_ID_DISABLE, "DV",   FS_MEDIA_TYPE_VIDEO, },
+    { FS_CODEC_ID_DISABLE, "JPEG", FS_MEDIA_TYPE_VIDEO, },
+    { FS_CODEC_ID_DISABLE, "MPV",  FS_MEDIA_TYPE_VIDEO, },
+    { 0, NULL, 0}
+  };
+
+  switch (media_type)
+    {
+      case FS_MEDIA_TYPE_AUDIO:
+        return empathy_call_handler_tf_channel_codec_config_get_defaults
+          (audio_codecs);
+      case FS_MEDIA_TYPE_VIDEO:
+        return empathy_call_handler_tf_channel_codec_config_get_defaults
+          (video_codecs);
+    }
+
+  return NULL;
+}
+
 static void
 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
 {
@@ -308,6 +374,8 @@ empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
       G_CALLBACK (empathy_call_handler_tf_channel_stream_created_cb), self);
   g_signal_connect (priv->tfchannel, "closed",
       G_CALLBACK (empathy_call_handler_tf_channel_closed_cb), self);
+  g_signal_connect (priv->tfchannel, "stream-get-codec-config",
+      G_CALLBACK (empathy_call_handler_tf_channel_codec_config_cb), self);
 
   g_object_unref (channel);
 }
@@ -334,29 +402,37 @@ empathy_call_handler_request_cb (EmpathyDispatchOperation *operation,
   empathy_dispatch_operation_claim (operation);
 }
 
-static void
-empathy_call_handler_contact_ready_cb (EmpathyContact *contact,
-  const GError *error, gpointer user_data, GObject *object)
+void
+empathy_call_handler_start_call (EmpathyCallHandler *handler)
 {
-  EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
-  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
   EmpathyDispatcher *dispatcher;
-  McAccount *account;
+  TpConnection *connection;
   GStrv allowed;
   GValue *value;
-  GHashTable *request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
-      (GDestroyNotify) tp_g_value_slice_free);
+  GHashTable *request;
+
+  if (priv->call != NULL)
+    {
+      empathy_call_handler_start_tpfs (handler);
+      empathy_tp_call_accept_incoming_call (priv->call);
+      return;
+    }
 
   g_assert (priv->contact != NULL);
 
   dispatcher = empathy_dispatcher_dup_singleton ();
-  account = empathy_contact_get_account (priv->contact);
-  allowed = empathy_dispatcher_find_channel_class (dispatcher, account,
+  connection = empathy_contact_get_connection (priv->contact);
+  allowed = empathy_dispatcher_find_channel_class (dispatcher, connection,
     TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT);
 
-  if (!tp_strv_contains ((const gchar * const *)allowed,
+  if (!tp_strv_contains ((const gchar * const *) allowed,
       TP_IFACE_CHANNEL ".TargetHandle"))
-    g_assert_not_reached ();
+    return;
+
+  request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+      (GDestroyNotify) tp_g_value_slice_free);
 
   /* org.freedesktop.Telepathy.Channel.ChannelType */
   value = tp_g_value_slice_new (G_TYPE_STRING);
@@ -373,27 +449,9 @@ empathy_call_handler_contact_ready_cb (EmpathyContact *contact,
   g_value_set_uint (value, empathy_contact_get_handle (priv->contact));
   g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value);
 
-  empathy_dispatcher_create_channel (dispatcher, account,
-    request, empathy_call_handler_request_cb, self);
+  empathy_dispatcher_create_channel (dispatcher, connection,
+    request, empathy_call_handler_request_cb, handler);
 
   g_object_unref (dispatcher);
 }
 
-void
-empathy_call_handler_start_call (EmpathyCallHandler *handler)
-{
-
-  EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
-
-  if (priv->call == NULL)
-    {
-      empathy_contact_call_when_ready (priv->contact,
-        EMPATHY_CONTACT_READY_HANDLE,
-        empathy_call_handler_contact_ready_cb, NULL, NULL, G_OBJECT (handler));
-    }
-  else
-    {
-      empathy_call_handler_start_tpfs (handler);
-      empathy_tp_call_accept_incoming_call (priv->call);
-    }
-}