Initial port from telepathy-stream-engine to telepathy-farsight
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 3 Feb 2009 09:02:36 +0000 (09:02 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Tue, 3 Feb 2009 09:02:36 +0000 (09:02 +0000)
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
svn path=/trunk/; revision=2380

configure.ac
docs/libempathy/Makefile.am
extensions/Makefile.am
extensions/Stream_Engine.xml [deleted file]
extensions/misc.xml
libempathy/empathy-tp-call.c
src/empathy-call-window.c
src/empathy.c

index f92e07d22f26cb19743df751bf167b6f6cdec75c..c5f912e5a3d54a04ef8bed2133ff52b888554a1e 100644 (file)
@@ -94,6 +94,7 @@ PKG_CHECK_MODULES(LIBEMPATHY,
    libmissioncontrol >= $MISSION_CONTROL_REQUIRED
    gio-2.0 >= $GLIB_REQUIRED
    gio-unix-2.0 >= $GLIB_REQUIRED
+   telepathy-farsight
 ])
 
 PKG_CHECK_MODULES(EMPATHY,
@@ -109,6 +110,7 @@ PKG_CHECK_MODULES(EMPATHY,
    libglade-2.0 >= $LIBGLADE_REQUIRED
    libebook-1.2
    libcanberra-gtk >= 0.4
+   gstreamer-0.10
 ])
 
 PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED)
index 7cf0108c2e85b98d5374b5ad38db6940aaa67d5c..3c7b99eede35b34cd4553bf547b210bbbe46f882 100644 (file)
@@ -22,7 +22,6 @@ IGNORE_HFILES=                                \
        empathy-filter-glue.h           \
        empathy-debug.h                 \
        empathy-marshal.h               \
-       tp-stream-engine-gen.h          \
        stamp-empathy-enum-types.h      \
        empathy-chandler-glue.h         \
        $(NULL)
index 408445fb81f8ec777caeb4a29f0674df9e2effcd..20657bba7ec8f6668615c2ea16dafd3570a3765e 100644 (file)
@@ -11,7 +11,6 @@ EXTRA_DIST = \
     generic-types.xml \
     misc.xml \
     Channel_Handler.xml \
-    Stream_Engine.xml \
     Tube_Handler.xml \
     Channel_Type_File_Transfer.xml \
     Channel_Interface_Tube.xml \
diff --git a/extensions/Stream_Engine.xml b/extensions/Stream_Engine.xml
deleted file mode 100644 (file)
index 89c9a24..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-<?xml version="1.0" ?>
-<node name="/Stream_Engine" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
-  <tp:copyright>Copyright (C) 2008 Collabora Limited</tp:copyright>
-  <tp:license xmlns="http://www.w3.org/1999/xhtml">
-    <p>This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.</p>
-
-<p>This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Library General Public License for more details.</p>
-
-<p>You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</p>
-  </tp:license>
-  <interface name="org.freedesktop.Telepathy.StreamEngine">
-    <method name="SetOutputVolume">
-      <arg direction="in" type="o" name="channel_path" />
-      <arg direction="in" type="u" name="stream_id" />
-      <arg direction="in" type="u" name="volume" />
-    </method>
-    <method name="MuteInput">
-      <arg direction="in" type="o" name="channel_path" />
-      <arg direction="in" type="u" name="stream_id" />
-      <arg direction="in" type="b" name="mute_state" />
-    </method>
-    <method name="MuteOutput">
-      <arg direction="in" type="o" name="channel_path" />
-      <arg direction="in" type="u" name="stream_id" />
-      <arg direction="in" type="b" name="mute_state" />
-    </method>
-    <method name="SetOutputWindow">
-      <arg direction="in" type="o" name="channel_path" />
-      <arg direction="in" type="u" name="stream_id" />
-      <arg direction="in" type="u" name="window" />
-    </method>
-    <method name="AddPreviewWindow">
-      <arg direction="in" type="u" name="window" />
-    </method>
-    <method name="RemovePreviewWindow">
-      <arg direction="in" type="u" name="window" />
-    </method>
-    <signal name="Receiving">
-      <arg type="o" name="channel_path" />
-      <arg type="u" name="stream_id" />
-      <arg type="b" name="state" />
-    </signal>
-    <signal name="StreamStateChanged">
-      <arg type="o" name="channel_path" />
-      <arg type="u" name="stream_id" />
-      <arg type="u" name="state" />
-      <arg type="u" name="direction" />
-    </signal>
-    <method name="Shutdown">
-    </method>
-  </interface>
-</node>
index fc96eff892c32c2c936412ee3d9d60bf78ac5686..e79caead2ee14be594b011d6895ed84b6824f3d6 100644 (file)
@@ -4,7 +4,6 @@
 
 <tp:title>Misc extensions for Empathy</tp:title>
 
-<xi:include href="Stream_Engine.xml"/>
 <xi:include href="Channel_Handler.xml"/>
 <xi:include href="Tube_Handler.xml"/>
 <xi:include href="Channel_Type_File_Transfer.xml"/>
index c8b96fed26e0e727eb09ac657ccb204312c29b02..41f573fd261486d5cb5315576a2e3c1d434dc3f5 100644 (file)
 #include <telepathy-glib/proxy-subclass.h>
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/interfaces.h>
+#include <telepathy-farsight/channel.h>
+#include <telepathy-farsight/stream.h>
 
-#include <extensions/extensions.h>
+#include <gst/gst.h>
 
 #include "empathy-tp-call.h"
 #include "empathy-contact-factory.h"
 #define DEBUG_FLAG EMPATHY_DEBUG_TP
 #include "empathy-debug.h"
 
-#define STREAM_ENGINE_BUS_NAME "org.freedesktop.Telepathy.StreamEngine"
-#define STREAM_ENGINE_OBJECT_PATH "/org/freedesktop/Telepathy/StreamEngine"
-
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpCall)
 typedef struct
 {
+  gboolean dispose_has_run;
   TpChannel *channel;
-  TpProxy *stream_engine;
-  TpDBusDaemon *dbus_daemon;
+  TfChannel *tfchannel;
   EmpathyContact *contact;
   gboolean is_incoming;
   guint status;
-  gboolean stream_engine_running;
+
+  GstElement *pipeline;
 
   EmpathyTpCallStream *audio;
   EmpathyTpCallStream *video;
@@ -370,90 +370,131 @@ tp_call_async_cb (TpProxy *proxy,
 }
 
 static void
-tp_call_stream_engine_invalidated_cb (TpProxy       *stream_engine,
-                                     GQuark         domain,
-                                     gint           code,
-                                     gchar         *message,
-                                     EmpathyTpCall *call)
+tp_call_close_channel (EmpathyTpCall *call)
+{
+  EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+  if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
+      return;
+
+  DEBUG ("Closing channel");
+
+  tp_cli_channel_call_close (priv->channel, -1,
+      NULL, NULL, NULL, NULL);
+
+  priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
+  g_object_notify (G_OBJECT (call), "status");
+}
+
+static gboolean
+tp_call_pipeline_bus_watch (GstBus *bus, GstMessage *message,
+  gpointer user_data)
+{
+  EmpathyTpCall *call = EMPATHY_TP_CALL (user_data);
+  EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+  g_assert (priv->tfchannel != NULL);
+
+  tf_channel_bus_message (priv->tfchannel, message);
+
+  return TRUE;
+}
+
+static void
+tp_call_tf_channel_session_created_cb (TfChannel *tfchannel,
+  FsConference *conference, FsParticipant *participant, EmpathyTpCall *call)
 {
-  DEBUG ("Stream engine proxy invalidated: %s", message);
-  empathy_tp_call_close (call);
+  EmpathyTpCallPriv *priv = GET_PRIV (call);
+  GstBus *bus;
+
+  g_assert (priv->pipeline == NULL);
+
+  priv->pipeline = gst_pipeline_new ("call-pipeline");
+
+  bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
+  gst_bus_add_watch (bus, tp_call_pipeline_bus_watch, call);
+  gst_object_unref (bus);
+
+  gst_bin_add ( GST_BIN (priv->pipeline), GST_ELEMENT (conference));
+  gst_element_set_state ( GST_ELEMENT(priv->pipeline), GST_STATE_PLAYING);
 }
 
 static void
-tp_call_stream_engine_watch_name_owner_cb (TpDBusDaemon *daemon,
-                                          const gchar *name,
-                                          const gchar *new_owner,
-                                          gpointer call)
+tp_call_tf_stream_src_pad_added_cb (TfStream *stream, GstPad   *pad,
+  FsCodec  *codec, EmpathyTpCall  *call)
 {
   EmpathyTpCallPriv *priv = GET_PRIV (call);
+  guint media_type;
+  GstElement *sink;
+  GstPad *spad;
+
+  g_object_get (stream, "media-type", &media_type, NULL);
 
-  /* EMP_STR_EMPTY(new_owner) means either stream-engine has not started yet or
-   * has crashed. We want to close the channel if stream-engine has crashed.
-   * */
-  DEBUG ("Watch SE: name='%s' SE running='%s' new_owner='%s'",
-      name, priv->stream_engine_running ? "yes" : "no",
-      new_owner ? new_owner : "none");
-  if (priv->stream_engine_running && EMP_STR_EMPTY (new_owner))
+  switch (media_type)
     {
-      DEBUG ("Stream engine falled off the bus");
-      empathy_tp_call_close (call);
-      return;
+      case TP_MEDIA_STREAM_TYPE_AUDIO:
+        sink = gst_element_factory_make ("gconfaudiosink", NULL);
+        break;
+      case TP_MEDIA_STREAM_TYPE_VIDEO:
+        sink = gst_element_factory_make ("gconfvideosink", NULL);
+        break;
+      default:
+        g_assert_not_reached();
     }
 
-  priv->stream_engine_running = !EMP_STR_EMPTY (new_owner);
+  gst_bin_add ( GST_BIN (priv->pipeline), sink);
+  gst_element_set_state (sink, GST_STATE_PLAYING);
+
+  spad = gst_element_get_static_pad (sink, "sink");
+  gst_pad_link (pad, spad);
+  gst_object_unref (spad);
+}
+
+
+static gboolean
+tp_call_tf_stream_request_resource_cb (TfStream *stream,
+  guint direction, EmpathyTpCall *call)
+{
+  return TRUE;
 }
 
 static void
-tp_call_stream_engine_handle_channel (EmpathyTpCall *call)
+tp_call_tf_channel_stream_created_cb (TfChannel *tfchannel, TfStream *stream,
+  EmpathyTpCall *call)
 {
   EmpathyTpCallPriv *priv = GET_PRIV (call);
-  gchar *channel_type;
-  gchar *object_path;
-  guint handle_type;
-  guint handle;
-  TpProxy *connection;
-
-  DEBUG ("Revving up the stream engine");
-
-  priv->stream_engine = g_object_new (TP_TYPE_PROXY,
-      "bus-name", STREAM_ENGINE_BUS_NAME,
-      "dbus-connection", tp_get_bus (),
-      "object-path", STREAM_ENGINE_OBJECT_PATH,
-       NULL);
-  tp_proxy_add_interface_by_id (priv->stream_engine,
-      EMP_IFACE_QUARK_STREAM_ENGINE);
-  tp_proxy_add_interface_by_id (priv->stream_engine,
-      EMP_IFACE_QUARK_CHANNEL_HANDLER);
-
-  g_signal_connect (priv->stream_engine, "invalidated",
-      G_CALLBACK (tp_call_stream_engine_invalidated_cb),
-      call);
-  
-  /* FIXME: dbus daemon should be unique */
-  priv->dbus_daemon = tp_dbus_daemon_new (tp_get_bus ());
-  tp_dbus_daemon_watch_name_owner (priv->dbus_daemon, STREAM_ENGINE_BUS_NAME,
-      tp_call_stream_engine_watch_name_owner_cb,
-      call, NULL);
-
-  g_object_get (priv->channel,
-      "connection", &connection,
-      "channel-type", &channel_type,
-      "object-path", &object_path,
-      "handle_type", &handle_type,
-      "handle", &handle,
-      NULL);
+  guint media_type;
+  GstElement *src;
+  GstPad *pad, *spad;
+
+  g_signal_connect (stream, "src-pad-added",
+      G_CALLBACK (tp_call_tf_stream_src_pad_added_cb), call);
+  g_signal_connect (stream, "request-resource",
+      G_CALLBACK (tp_call_tf_stream_request_resource_cb), call);
+
 
-  emp_cli_channel_handler_call_handle_channel (priv->stream_engine, -1,
-        connection->bus_name,
-        connection->object_path,
-        channel_type, object_path, handle_type, handle,
-        tp_call_async_cb, "calling handle channel", NULL,
-        G_OBJECT (call));
+  g_object_get (stream, "media-type", &media_type,
+    "sink-pad", &spad, NULL);
 
-  g_object_unref (connection);
-  g_free (channel_type);
-  g_free (object_path);
+  switch (media_type)
+    {
+      case TP_MEDIA_STREAM_TYPE_AUDIO:
+        src = gst_element_factory_make ("gconfaudiosrc", NULL);
+        break;
+      case TP_MEDIA_STREAM_TYPE_VIDEO:
+        src = gst_element_factory_make ("gconfvideosrc", NULL);
+        break;
+      default:
+        g_assert_not_reached();
+    }
+
+  gst_bin_add (GST_BIN (priv->pipeline), src);
+
+  pad = gst_element_get_static_pad (src, "src");
+  gst_pad_link (pad, spad);
+  gst_object_unref (spad);
+
+  gst_element_set_state (src, GST_STATE_PLAYING);
 }
 
 static GObject *
@@ -490,18 +531,27 @@ tp_call_constructor (GType type,
   g_signal_connect (priv->channel, "group-members-changed",
       G_CALLBACK (tp_call_members_changed_cb), call);
 
-  /* Start stream engine */
-  tp_call_stream_engine_handle_channel (call);
+
+  /* Set up the telepathy farsight channel */
+  priv->tfchannel = tf_channel_new (priv->channel);
+  g_signal_connect (priv->tfchannel, "session-created",
+      G_CALLBACK (tp_call_tf_channel_session_created_cb), call);
+  g_signal_connect (priv->tfchannel, "stream-created",
+      G_CALLBACK (tp_call_tf_channel_stream_created_cb), call);
 
   return object;
 }
-
 static void
-tp_call_finalize (GObject *object)
+tp_call_dispose (GObject *object)
 {
   EmpathyTpCallPriv *priv = GET_PRIV (object);
 
-  DEBUG ("Finalizing: %p", object);
+  DEBUG ("Disposing: %p, %d", object, priv->dispose_has_run);
+
+  if (priv->dispose_has_run)
+    return;
+
+  priv->dispose_has_run = TRUE;
 
   g_slice_free (EmpathyTpCallStream, priv->audio);
   g_slice_free (EmpathyTpCallStream, priv->video);
@@ -515,29 +565,40 @@ tp_call_finalize (GObject *object)
       priv->channel = NULL;
     }
 
-  if (priv->stream_engine != NULL)
+  if (priv->pipeline != NULL)
     {
-      g_signal_handlers_disconnect_by_func (priv->stream_engine,
-          tp_call_stream_engine_invalidated_cb, object);
-      g_object_unref (priv->stream_engine);
+      gst_element_set_state (priv->pipeline, GST_STATE_NULL);
+      gst_object_unref (priv->pipeline);
+      priv->pipeline = NULL;
+    }
+
+  if (priv->tfchannel != NULL)
+    {
+      g_object_unref (priv->tfchannel);
+      priv->tfchannel = NULL;
     }
 
   if (priv->contact != NULL)
       g_object_unref (priv->contact);
 
-  if (priv->dbus_daemon != NULL)
-    {
-      tp_dbus_daemon_cancel_name_owner_watch (priv->dbus_daemon,
-          STREAM_ENGINE_BUS_NAME,
-          tp_call_stream_engine_watch_name_owner_cb,
-          object);
-      g_object_unref (priv->dbus_daemon);
-    }
+  if (G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose)
+    G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose (object);
+}
+
+static void
+tp_call_finalize (GObject *object)
+{
+  EmpathyTpCallPriv *priv = GET_PRIV (object);
+
+  DEBUG ("Finalizing: %p", object);
+
+  g_slice_free (EmpathyTpCallStream, priv->audio);
+  g_slice_free (EmpathyTpCallStream, priv->video);
 
   (G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize) (object);
 }
 
-static void 
+static void
 tp_call_set_property (GObject *object,
                       guint prop_id,
                       const GValue *value,
@@ -596,6 +657,7 @@ empathy_tp_call_class_init (EmpathyTpCallClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->constructor = tp_call_constructor;
+  object_class->dispose = tp_call_dispose;
   object_class->finalize = tp_call_finalize;
   object_class->set_property = tp_call_set_property;
   object_class->get_property = tp_call_get_property;
@@ -638,7 +700,6 @@ empathy_tp_call_init (EmpathyTpCall *call)
   call->priv = priv;
   priv->status = EMPATHY_TP_CALL_STATUS_READYING;
   priv->contact = NULL;
-  priv->stream_engine_running = FALSE;
   priv->audio = g_slice_new0 (EmpathyTpCallStream);
   priv->video = g_slice_new0 (EmpathyTpCallStream);
   priv->audio->exists = FALSE;
@@ -727,52 +788,39 @@ void
 empathy_tp_call_add_preview_video (EmpathyTpCall *call,
                                    guint preview_video_socket_id)
 {
-  EmpathyTpCallPriv *priv = GET_PRIV (call);
+  //EmpathyTpCallPriv *priv = GET_PRIV (call);
 
   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
 
   DEBUG ("Adding preview video");
 
-  emp_cli_stream_engine_call_add_preview_window (priv->stream_engine, -1,
-      preview_video_socket_id,
-      tp_call_async_cb,
-      "adding preview window", NULL,
-      G_OBJECT (call));
+  /* FIXME add the preview window */
 }
 
 void
 empathy_tp_call_remove_preview_video (EmpathyTpCall *call,
                                       guint preview_video_socket_id)
 {
-  EmpathyTpCallPriv *priv = GET_PRIV (call);
+  //EmpathyTpCallPriv *priv = GET_PRIV (call);
 
   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
 
   DEBUG ("Removing preview video");
 
-  emp_cli_stream_engine_call_remove_preview_window (priv->stream_engine, -1,
-      preview_video_socket_id,
-      tp_call_async_cb,
-      "removing preview window", NULL,
-      G_OBJECT (call));
+  /* FIXME remove the preview window */
 }
 
 void
 empathy_tp_call_add_output_video (EmpathyTpCall *call,
                                   guint output_video_socket_id)
 {
-  EmpathyTpCallPriv *priv = GET_PRIV (call);
+  //EmpathyTpCallPriv *priv = GET_PRIV (call);
 
   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
 
   DEBUG ("Adding output video - socket: %d", output_video_socket_id);
 
-  emp_cli_stream_engine_call_set_output_window (priv->stream_engine, -1,
-      TP_PROXY (priv->channel)->object_path,
-      priv->video->id, output_video_socket_id,
-      tp_call_async_cb,
-      "setting output window", NULL,
-      G_OBJECT (call));
+  /* FIXME add output window */
 }
 
 void
@@ -786,48 +834,32 @@ empathy_tp_call_set_output_volume (EmpathyTpCall *call,
 
   DEBUG ("Setting output volume: %d", volume);
 
-  emp_cli_stream_engine_call_set_output_volume (priv->stream_engine, -1,
-      TP_PROXY (priv->channel)->object_path,
-      priv->audio->id, volume,
-      tp_call_async_cb,
-      "setting output volume", NULL,
-      G_OBJECT (call));
+  /* FIXME set volume */
 }
 
 void
 empathy_tp_call_mute_output (EmpathyTpCall *call,
                              gboolean is_muted)
 {
-  EmpathyTpCallPriv *priv = GET_PRIV (call);
+  //EmpathyTpCallPriv *priv = GET_PRIV (call);
 
   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
 
   DEBUG ("Setting output mute: %d", is_muted);
-
-  emp_cli_stream_engine_call_mute_output (priv->stream_engine, -1,
-      TP_PROXY (priv->channel)->object_path,
-      priv->audio->id, is_muted,
-      tp_call_async_cb,
-      "muting output", NULL,
-      G_OBJECT (call));
+  /* FIXME mute output */
 }
 
 void
 empathy_tp_call_mute_input (EmpathyTpCall *call,
                             gboolean is_muted)
 {
-  EmpathyTpCallPriv *priv = GET_PRIV (call);
+  //EmpathyTpCallPriv *priv = GET_PRIV (call);
 
   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
 
   DEBUG ("Setting input mute: %d", is_muted);
 
-  emp_cli_stream_engine_call_mute_input (priv->stream_engine, -1,
-      TP_PROXY (priv->channel)->object_path,
-      priv->audio->id, is_muted,
-      tp_call_async_cb,
-      "muting input", NULL,
-      G_OBJECT (call));
+  /* FIXME mute input */
 }
 
 void
index 77f8508667855995e8a33864375c7ea062b51f82..34f5fd202d223d94905a1e7422f8638d48662d41 100644 (file)
@@ -352,6 +352,9 @@ call_window_update (EmpathyCallWindow *window)
   gboolean is_incoming;
   gchar *title;
 
+  if (window->call == NULL)
+    return;
+
   g_object_get (window->call,
       "status", &window->status,
       "audio-stream", &audio_stream,
index b67e698787a8d168d1bc661065a53b8cd762365c..dce928701c87b126a9e5726a4ae2359dedaa2259 100644 (file)
@@ -62,6 +62,8 @@
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include <libempathy/empathy-debug.h>
 
+#include <gst/gst.h>
+
 static BaconMessageConnection *connection = NULL;
 
 static void
@@ -441,6 +443,10 @@ main (int argc, char *argv[])
 
        empathy_gtk_init ();
        g_set_application_name (_(PACKAGE_NAME));
+
+       gst_init (&argc, &argv);
+
+       g_set_application_name (PACKAGE_NAME);
        gtk_window_set_default_icon_name ("empathy");
        textdomain (GETTEXT_PACKAGE);