]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-call-handler.c
Merge branch 'sasl'
[empathy.git] / libempathy / empathy-call-handler.c
index 1f9ab7213feb2b1aaafb5df300733fdbeeee833d..dc734b2e5337047301260334ede3698433b05c0f 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <telepathy-glib/account-channel-request.h>
 #include <telepathy-glib/util.h>
 #include <telepathy-glib/interfaces.h>
 
 
 #include "empathy-call-handler.h"
 #include "empathy-call-factory.h"
-#include "empathy-dispatcher.h"
 #include "empathy-marshal.h"
 #include "empathy-utils.h"
 
+#define DEBUG_FLAG EMPATHY_DEBUG_VOIP
+#include <libempathy/empathy-debug.h>
+
 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
 
 /* signal enum */
@@ -44,6 +47,7 @@ enum {
   REQUEST_RESOURCE,
   CLOSED,
   STREAM_CLOSED,
+  CANDIDATES_CHANGED,
   LAST_SIGNAL
 };
 
@@ -54,7 +58,15 @@ enum {
   PROP_GST_BUS,
   PROP_CONTACT,
   PROP_INITIAL_AUDIO,
-  PROP_INITIAL_VIDEO
+  PROP_INITIAL_VIDEO,
+  PROP_SEND_AUDIO_CODEC,
+  PROP_SEND_VIDEO_CODEC,
+  PROP_RECV_AUDIO_CODECS,
+  PROP_RECV_VIDEO_CODECS,
+  PROP_AUDIO_REMOTE_CANDIDATE,
+  PROP_VIDEO_REMOTE_CANDIDATE,
+  PROP_AUDIO_LOCAL_CANDIDATE,
+  PROP_VIDEO_LOCAL_CANDIDATE,
 };
 
 /* private structure */
@@ -66,6 +78,15 @@ typedef struct {
   TfChannel *tfchannel;
   gboolean initial_audio;
   gboolean initial_video;
+
+  FsCodec *send_audio_codec;
+  FsCodec *send_video_codec;
+  GList *recv_audio_codecs;
+  GList *recv_video_codecs;
+  FsCandidate *audio_remote_candidate;
+  FsCandidate *video_remote_candidate;
+  FsCandidate *audio_local_candidate;
+  FsCandidate *video_local_candidate;
 } EmpathyCallHandlerPriv;
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
@@ -106,7 +127,17 @@ empathy_call_handler_dispose (GObject *object)
 static void
 empathy_call_handler_finalize (GObject *object)
 {
-  /* free any data held directly by the object here */
+  EmpathyCallHandlerPriv *priv = GET_PRIV (object);
+
+  fs_codec_destroy (priv->send_audio_codec);
+  fs_codec_destroy (priv->send_video_codec);
+  fs_codec_list_destroy (priv->recv_audio_codecs);
+  fs_codec_list_destroy (priv->recv_video_codecs);
+  fs_candidate_destroy (priv->audio_remote_candidate);
+  fs_candidate_destroy (priv->video_remote_candidate);
+  fs_candidate_destroy (priv->audio_local_candidate);
+  fs_candidate_destroy (priv->video_local_candidate);
+
   if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize)
     G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
 }
@@ -176,6 +207,30 @@ empathy_call_handler_get_property (GObject *object,
       case PROP_INITIAL_VIDEO:
         g_value_set_boolean (value, priv->initial_video);
         break;
+      case PROP_SEND_AUDIO_CODEC:
+        g_value_set_boxed (value, priv->send_audio_codec);
+        break;
+      case PROP_SEND_VIDEO_CODEC:
+        g_value_set_boxed (value, priv->send_video_codec);
+        break;
+      case PROP_RECV_AUDIO_CODECS:
+        g_value_set_boxed (value, priv->recv_audio_codecs);
+        break;
+      case PROP_RECV_VIDEO_CODECS:
+        g_value_set_boxed (value, priv->recv_video_codecs);
+        break;
+      case PROP_AUDIO_REMOTE_CANDIDATE:
+        g_value_set_boxed (value, priv->audio_remote_candidate);
+        break;
+      case PROP_VIDEO_REMOTE_CANDIDATE:
+        g_value_set_boxed (value, priv->video_remote_candidate);
+        break;
+      case PROP_AUDIO_LOCAL_CANDIDATE:
+        g_value_set_boxed (value, priv->audio_local_candidate);
+        break;
+      case PROP_VIDEO_LOCAL_CANDIDATE:
+        g_value_set_boxed (value, priv->video_local_candidate);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -222,6 +277,66 @@ empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
   g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
     param_spec);
 
+  param_spec = g_param_spec_boxed ("send-audio-codec",
+    "send audio codec", "Codec used to encode the outgoing video stream",
+    FS_TYPE_CODEC,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
+    param_spec);
+
+  param_spec = g_param_spec_boxed ("send-video-codec",
+    "send video codec", "Codec used to encode the outgoing video stream",
+    FS_TYPE_CODEC,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
+    param_spec);
+
+  param_spec = g_param_spec_boxed ("recv-audio-codecs",
+    "recvs audio codec", "Codecs used to decode the incoming audio stream",
+    FS_TYPE_CODEC_LIST,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
+    param_spec);
+
+  param_spec = g_param_spec_boxed ("recv-video-codecs",
+    "recvs video codec", "Codecs used to decode the incoming video stream",
+    FS_TYPE_CODEC_LIST,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
+    param_spec);
+
+  param_spec = g_param_spec_boxed ("audio-remote-candidate",
+    "audio remote candidate",
+    "Remote candidate used for the audio stream",
+    FS_TYPE_CANDIDATE,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class,
+      PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
+
+  param_spec = g_param_spec_boxed ("video-remote-candidate",
+    "video remote candidate",
+    "Remote candidate used for the video stream",
+    FS_TYPE_CANDIDATE,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class,
+      PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
+
+  param_spec = g_param_spec_boxed ("audio-local-candidate",
+    "audio local candidate",
+    "Local candidate used for the audio stream",
+    FS_TYPE_CANDIDATE,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class,
+      PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
+
+  param_spec = g_param_spec_boxed ("video-local-candidate",
+    "video local candidate",
+    "Local candidate used for the video stream",
+    FS_TYPE_CANDIDATE,
+    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class,
+      PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
+
   signals[CONFERENCE_ADDED] =
     g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
       G_SIGNAL_RUN_LAST, 0, NULL, NULL,
@@ -262,6 +377,12 @@ empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
       G_SIGNAL_RUN_LAST, 0, NULL, NULL,
       g_cclosure_marshal_VOID__OBJECT,
       G_TYPE_NONE, 1, TF_TYPE_STREAM);
+
+  signals[CANDIDATES_CHANGED] =
+    g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
+      G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+      g_cclosure_marshal_VOID__UINT,
+      G_TYPE_NONE, 1, G_TYPE_UINT);
 }
 
 /**
@@ -288,15 +409,183 @@ empathy_call_handler_new_for_channel (EmpathyTpCall *call)
     NULL));
 }
 
+static void
+update_sending_codec (EmpathyCallHandler *self,
+    FsCodec *codec,
+    FsSession *session)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+  FsMediaType type;
+
+  if (codec == NULL || session == NULL)
+    return;
+
+  g_object_get (session, "media-type", &type, NULL);
+
+  if (type == FS_MEDIA_TYPE_AUDIO)
+    {
+      priv->send_audio_codec = fs_codec_copy (codec);
+      g_object_notify (G_OBJECT (self), "send-audio-codec");
+    }
+  else if (type == FS_MEDIA_TYPE_VIDEO)
+    {
+      priv->send_video_codec = fs_codec_copy (codec);
+      g_object_notify (G_OBJECT (self), "send-video-codec");
+    }
+}
+
+static void
+update_receiving_codec (EmpathyCallHandler *self,
+    GList *codecs,
+    FsStream *stream)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+  FsSession *session;
+  FsMediaType type;
+
+  if (codecs == NULL || stream == NULL)
+    return;
+
+  g_object_get (stream, "session", &session, NULL);
+  if (session == NULL)
+    return;
+
+  g_object_get (session, "media-type", &type, NULL);
+
+  if (type == FS_MEDIA_TYPE_AUDIO)
+    {
+      priv->recv_audio_codecs = fs_codec_list_copy (codecs);
+      g_object_notify (G_OBJECT (self), "recv-audio-codecs");
+    }
+  else if (type == FS_MEDIA_TYPE_VIDEO)
+    {
+      priv->recv_video_codecs = fs_codec_list_copy (codecs);
+      g_object_notify (G_OBJECT (self), "recv-video-codecs");
+    }
+
+  g_object_unref (session);
+}
+
+static void
+update_candidates (EmpathyCallHandler *self,
+    FsCandidate *remote_candidate,
+    FsCandidate *local_candidate,
+    FsStream *stream)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+  FsSession *session;
+  FsMediaType type;
+
+  if (stream == NULL)
+    return;
+
+  g_object_get (stream, "session", &session, NULL);
+  if (session == NULL)
+    return;
+
+  g_object_get (session, "media-type", &type, NULL);
+
+  if (type == FS_MEDIA_TYPE_AUDIO)
+    {
+      if (remote_candidate != NULL)
+        {
+          fs_candidate_destroy (priv->audio_remote_candidate);
+          priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
+          g_object_notify (G_OBJECT (self), "audio-remote-candidate");
+        }
+
+      if (local_candidate != NULL)
+        {
+          fs_candidate_destroy (priv->audio_local_candidate);
+          priv->audio_local_candidate = fs_candidate_copy (local_candidate);
+          g_object_notify (G_OBJECT (self), "audio-local-candidate");
+        }
+
+      g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
+          FS_MEDIA_TYPE_AUDIO);
+    }
+  else if (type == FS_MEDIA_TYPE_VIDEO)
+    {
+      if (remote_candidate != NULL)
+        {
+          fs_candidate_destroy (priv->video_remote_candidate);
+          priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
+          g_object_notify (G_OBJECT (self), "video-remote-candidate");
+        }
+
+      if (local_candidate != NULL)
+        {
+          fs_candidate_destroy (priv->video_local_candidate);
+          priv->video_local_candidate = fs_candidate_copy (local_candidate);
+          g_object_notify (G_OBJECT (self), "video-local-candidate");
+        }
+
+      g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
+          FS_MEDIA_TYPE_VIDEO);
+    }
+
+  g_object_unref (session);
+}
+
 void
 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
   GstBus *bus, GstMessage *message)
 {
   EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
+  const GstStructure *s = gst_message_get_structure (message);
 
   if (priv->tfchannel == NULL)
     return;
 
+  if (s != NULL &&
+      gst_structure_has_name (s, "farsight-send-codec-changed"))
+    {
+      const GValue *val;
+      FsCodec *codec;
+      FsSession *session;
+
+      val = gst_structure_get_value (s, "codec");
+      codec = g_value_get_boxed (val);
+
+      val = gst_structure_get_value (s, "session");
+      session = g_value_get_object (val);
+
+      update_sending_codec (handler, codec, session);
+    }
+  else if (s != NULL &&
+      gst_structure_has_name (s, "farsight-recv-codecs-changed"))
+    {
+      const GValue *val;
+      GList *codecs;
+      FsStream *stream;
+
+      val = gst_structure_get_value (s, "codecs");
+      codecs = g_value_get_boxed (val);
+
+      val = gst_structure_get_value (s, "stream");
+      stream = g_value_get_object (val);
+
+      update_receiving_codec (handler, codecs, stream);
+    }
+  else if (s != NULL &&
+      gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
+    {
+      const GValue *val;
+      FsCandidate *remote_candidate, *local_candidate;
+      FsStream *stream;
+
+      val = gst_structure_get_value (s, "remote-candidate");
+      remote_candidate = g_value_get_boxed (val);
+
+      val = gst_structure_get_value (s, "local-candidate");
+      local_candidate = g_value_get_boxed (val);
+
+      val = gst_structure_get_value (s, "stream");
+      stream = g_value_get_object (val);
+
+      update_candidates (handler, remote_candidate, local_candidate, stream);
+    }
+
   tf_channel_bus_message (priv->tfchannel, message);
 }
 
@@ -367,6 +656,10 @@ empathy_call_handler_tf_channel_stream_created_cb (TfChannel *tfchannel,
   guint media_type;
   GstPad *spad;
   gboolean retval;
+  FsStream *fs_stream;
+  GList *codecs;
+  FsSession *session;
+  FsCodec *codec;
 
   g_signal_connect (stream, "src-pad-added",
       G_CALLBACK (empathy_call_handler_tf_stream_src_pad_added_cb), handler);
@@ -386,7 +679,25 @@ empathy_call_handler_tf_channel_stream_created_cb (TfChannel *tfchannel,
       tf_stream_error (stream, TP_MEDIA_STREAM_ERROR_MEDIA_ERROR,
           "Could not link source");
 
-  gst_object_unref (spad);
+ /* Get sending codec */
+ g_object_get (stream, "farsight-session", &session, NULL);
+ g_object_get (session, "current-send-codec", &codec, NULL);
+
+ update_sending_codec (handler, codec, session);
+
+ tp_clear_object (&session);
+ tp_clear_object (&codec);
+
+ /* Get receiving codec */
+ g_object_get (stream, "farsight-stream", &fs_stream, NULL);
+ g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
+
+ update_receiving_codec (handler, codecs, fs_stream);
+
+ fs_codec_list_destroy (codecs);
+ tp_clear_object (&fs_stream);
+
+ gst_object_unref (spad);
 }
 
 static void
@@ -443,35 +754,45 @@ empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
 }
 
 static void
-empathy_call_handler_request_cb (EmpathyDispatchOperation *operation,
-  const GError *error,
-  gpointer user_data)
+empathy_call_handler_request_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
 {
   EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
   EmpathyCallHandlerPriv *priv = GET_PRIV (self);
   TpChannel *channel;
+  GError *error = NULL;
+  TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
+  TpAccount *account;
 
-  if (error != NULL)
-    return;
+  channel = tp_account_channel_request_create_and_handle_channel_finish (req,
+      result, NULL, &error);
+  if (channel == NULL)
+    {
+      DEBUG ("Failed to create the channel: %s", error->message);
+      g_error_free (error);
+      return;
+    }
 
-  channel = empathy_dispatch_operation_get_channel (operation);
-  g_assert (channel != NULL);
+  account = tp_account_channel_request_get_account (req);
 
-  priv->call = empathy_tp_call_new (channel);
+  priv->call = empathy_tp_call_new (account, channel);
 
   g_object_notify (G_OBJECT (self), "tp-call");
 
   empathy_call_handler_start_tpfs (self);
 
-  empathy_dispatch_operation_claim (operation);
+  g_object_unref (channel);
 }
 
 void
 empathy_call_handler_start_call (EmpathyCallHandler *handler,
     gint64 timestamp)
 {
-
   EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
+  TpAccountChannelRequest *req;
+  TpAccount *account;
+  GHashTable *request;
 
   if (priv->call != NULL)
     {
@@ -484,9 +805,17 @@ empathy_call_handler_start_call (EmpathyCallHandler *handler,
    * will be used to create a new EmpathyTpCall. */
   g_assert (priv->contact != NULL);
 
-  empathy_call_factory_new_call_with_streams (priv->contact,
-      priv->initial_audio, priv->initial_video, timestamp,
+  account = empathy_contact_get_account (priv->contact);
+  request = empathy_call_factory_create_request (priv->contact,
+      priv->initial_audio, priv->initial_video);
+
+  req = tp_account_channel_request_new (account, request, timestamp);
+
+  tp_account_channel_request_create_and_handle_channel_async (req, NULL,
       empathy_call_handler_request_cb, handler);
+
+  g_object_unref (req);
+  g_hash_table_unref (request);
 }
 
 /**
@@ -526,3 +855,70 @@ empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
   return priv->initial_video;
 }
 
+FsCodec *
+empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->send_audio_codec;
+}
+
+FsCodec *
+empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->send_video_codec;
+}
+
+GList *
+empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->recv_audio_codecs;
+}
+
+GList *
+empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->recv_video_codecs;
+}
+
+FsCandidate *
+empathy_call_handler_get_audio_remote_candidate (
+    EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->audio_remote_candidate;
+}
+
+FsCandidate *
+empathy_call_handler_get_audio_local_candidate (
+    EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->audio_local_candidate;
+}
+
+FsCandidate *
+empathy_call_handler_get_video_remote_candidate (
+    EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->video_remote_candidate;
+}
+
+FsCandidate *
+empathy_call_handler_get_video_local_candidate (
+    EmpathyCallHandler *self)
+{
+  EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+  return priv->video_local_candidate;
+}