-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2007 Elliot Fairweather
- * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007-2008 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* Xavier Claessens <xclaesse@gmail.com>
*/
-#include "config.h"
+#include <string.h>
-#include <libtelepathy/tp-chan-type-streamed-media-gen.h>
-#include <libtelepathy/tp-helpers.h>
-#include <libtelepathy/tp-conn.h>
-
-#include <libmissioncontrol/mission-control.h>
+#include <telepathy-glib/proxy-subclass.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/interfaces.h>
#include "empathy-tp-call.h"
-#include "empathy-tp-group.h"
+#include "empathy-tp-contact-factory.h"
#include "empathy-utils.h"
+
+#define DEBUG_FLAG EMPATHY_DEBUG_TP
#include "empathy-debug.h"
-#include "empathy-enum-types.h"
-#include "tp-stream-engine-gen.h"
-
-#define DEBUG_DOMAIN "TpCall"
-
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_TP_CALL, EmpathyTpCallPriv))
-
-#define STREAM_ENGINE_BUS_NAME "org.freedesktop.Telepathy.StreamEngine"
-#define STREAM_ENGINE_OBJECT_PATH "/org/freedesktop/Telepathy/StreamEngine"
-#define STREAM_ENGINE_INTERFACE "org.freedesktop.Telepathy.StreamEngine"
-#define CHANNEL_HANDLER_INTERFACE "org.freedesktop.Telepathy.ChannelHandler"
-
-typedef struct _EmpathyTpCallPriv EmpathyTpCallPriv;
-
-struct _EmpathyTpCallPriv {
- TpChan *tp_chan;
- DBusGProxy *streamed_iface;
- DBusGProxy *se_ch_proxy;
- DBusGProxy *se_proxy;
- McAccount *account;
- EmpathyTpGroup *group;
- EmpathyContact *contact;
- EmpathyTpCallStatus status;
- gboolean is_incoming;
- guint audio_stream;
- guint video_stream;
-};
-static void empathy_tp_call_class_init (EmpathyTpCallClass *klass);
-static void empathy_tp_call_init (EmpathyTpCall *call);
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpCall)
+typedef struct
+{
+ gboolean dispose_has_run;
+ TpChannel *channel;
+ EmpathyContact *contact;
+ gboolean is_incoming;
+ guint status;
-enum {
- PROP_0,
- PROP_ACCOUNT,
- PROP_TP_CHAN,
- PROP_STATUS
-};
+ EmpathyTpCallStream *audio;
+ EmpathyTpCallStream *video;
+} EmpathyTpCallPriv;
-enum {
- DESTROY,
- LAST_SIGNAL
+enum
+{
+ PROP_0,
+ PROP_CHANNEL,
+ PROP_CONTACT,
+ PROP_IS_INCOMING,
+ PROP_STATUS,
+ PROP_AUDIO_STREAM,
+ PROP_VIDEO_STREAM
};
-static guint signals[LAST_SIGNAL];
-
G_DEFINE_TYPE (EmpathyTpCall, empathy_tp_call, G_TYPE_OBJECT)
static void
-tp_call_set_status (EmpathyTpCall *call,
- EmpathyTpCallStatus status)
+tp_call_add_stream (EmpathyTpCall *call,
+ guint stream_id,
+ guint contact_handle,
+ guint stream_type,
+ guint stream_state,
+ guint stream_direction)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- priv->status = status;
- g_object_notify (G_OBJECT (call), "status");
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ switch (stream_type)
+ {
+ case TP_MEDIA_STREAM_TYPE_AUDIO:
+ DEBUG ("Audio stream - id: %d, state: %d, direction: %d",
+ stream_id, stream_state, stream_direction);
+ priv->audio->exists = TRUE;
+ priv->audio->id = stream_id;
+ priv->audio->state = stream_state;
+ priv->audio->direction = stream_direction;
+ g_object_notify (G_OBJECT (call), "audio-stream");
+ break;
+ case TP_MEDIA_STREAM_TYPE_VIDEO:
+ DEBUG ("Video stream - id: %d, state: %d, direction: %d",
+ stream_id, stream_state, stream_direction);
+ priv->video->exists = TRUE;
+ priv->video->id = stream_id;
+ priv->video->state = stream_state;
+ priv->video->direction = stream_direction;
+ g_object_notify (G_OBJECT (call), "video-stream");
+ break;
+ default:
+ DEBUG ("Unknown stream type: %d", stream_type);
+ }
}
static void
-tp_call_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+tp_call_stream_added_cb (TpChannel *channel,
+ guint stream_id,
+ guint contact_handle,
+ guint stream_type,
+ gpointer user_data,
+ GObject *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (object);
-
- switch (prop_id) {
- case PROP_ACCOUNT:
- priv->account = g_object_ref (g_value_get_object (value));
- break;
- case PROP_TP_CHAN:
- priv->tp_chan = g_object_ref (g_value_get_object (value));
- break;
- case PROP_STATUS:
- tp_call_set_status (EMPATHY_TP_CALL (object),
- g_value_get_enum (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ DEBUG ("Stream added - stream id: %d, contact handle: %d, stream type: %d",
+ stream_id, contact_handle, stream_type);
+
+ tp_call_add_stream (EMPATHY_TP_CALL (call), stream_id, contact_handle,
+ stream_type, TP_MEDIA_STREAM_STATE_DISCONNECTED,
+ TP_MEDIA_STREAM_DIRECTION_NONE);
}
static void
-tp_call_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+tp_call_stream_removed_cb (TpChannel *channel,
+ guint stream_id,
+ gpointer user_data,
+ GObject *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (object);
-
- switch (prop_id) {
- case PROP_ACCOUNT:
- g_value_set_object (value, priv->account);
- break;
- case PROP_TP_CHAN:
- g_value_set_object (value, priv->tp_chan);
- break;
- case PROP_STATUS:
- g_value_set_enum (value, priv->status);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ DEBUG ("Stream removed - stream id: %d", stream_id);
+
+ if (stream_id == priv->audio->id)
+ {
+ priv->audio->exists = FALSE;
+ g_object_notify (call, "audio-stream");
+ }
+ else if (stream_id == priv->video->id)
+ {
+ priv->video->exists = FALSE;
+ g_object_notify (call, "video-stream");
+ }
}
static void
-tp_call_destroy_cb (TpChan *call_chan,
- EmpathyTpCall *call)
+tp_call_stream_state_changed_cb (TpChannel *proxy,
+ guint stream_id,
+ guint stream_state,
+ gpointer user_data,
+ GObject *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- empathy_debug (DEBUG_DOMAIN, "Channel Closed or CM crashed");
-
- g_object_unref (priv->tp_chan);
- priv->tp_chan = NULL;
- priv->streamed_iface = NULL;
-
- g_signal_emit (call, signals[DESTROY], 0);
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ DEBUG ("Stream state changed - stream id: %d, state state: %d",
+ stream_id, stream_state);
+
+ if (stream_id == priv->audio->id)
+ {
+ priv->audio->state = stream_state;
+ g_object_notify (call, "audio-stream");
+ }
+ else if (stream_id == priv->video->id)
+ {
+ priv->video->state = stream_state;
+ g_object_notify (call, "video-stream");
+ }
}
static void
-tp_call_closed_cb (TpChan *call_chan,
- EmpathyTpCall *call)
+tp_call_stream_direction_changed_cb (TpChannel *channel,
+ guint stream_id,
+ guint stream_direction,
+ guint pending_flags,
+ gpointer user_data,
+ GObject *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- /* The channel is closed, do just like if the proxy was destroyed */
- g_signal_handlers_disconnect_by_func (priv->tp_chan,
- tp_call_destroy_cb,
- call);
- tp_call_destroy_cb (call_chan, call);
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ DEBUG ("Stream direction changed - stream: %d, direction: %d",
+ stream_id, stream_direction);
+
+ if (stream_id == priv->audio->id)
+ {
+ priv->audio->direction = stream_direction;
+ g_object_notify (call, "audio-stream");
+ }
+ else if (stream_id == priv->video->id)
+ {
+ priv->video->direction = stream_direction;
+ g_object_notify (call, "video-stream");
+ }
}
static void
-tp_call_stream_added_cb (DBusGProxy *streamed_iface,
- guint stream_id,
- guint contact_handle,
- guint stream_type,
- EmpathyTpCall *call)
+tp_call_request_streams_cb (TpChannel *channel,
+ const GPtrArray *streams,
+ const GError *error,
+ gpointer user_data,
+ GObject *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- empathy_debug (DEBUG_DOMAIN, "Stream added: id=%d, stream_type=%d",
- stream_id, stream_type);
-
- switch (stream_type) {
- case TP_MEDIA_STREAM_TYPE_AUDIO:
- priv->audio_stream = stream_id;
- break;
- case TP_MEDIA_STREAM_TYPE_VIDEO:
- priv->video_stream = stream_id;
- break;
- default:
- empathy_debug (DEBUG_DOMAIN, "Unknown stream type: %d", stream_type);
- }
+ guint i;
+
+ if (error)
+ {
+ DEBUG ("Error requesting streams: %s", error->message);
+ return;
+ }
+
+ for (i = 0; i < streams->len; i++)
+ {
+ GValueArray *values;
+ guint stream_id;
+ guint contact_handle;
+ guint stream_type;
+ guint stream_state;
+ guint stream_direction;
+
+ values = g_ptr_array_index (streams, i);
+ stream_id = g_value_get_uint (g_value_array_get_nth (values, 0));
+ contact_handle = g_value_get_uint (g_value_array_get_nth (values, 1));
+ stream_type = g_value_get_uint (g_value_array_get_nth (values, 2));
+ stream_state = g_value_get_uint (g_value_array_get_nth (values, 3));
+ stream_direction = g_value_get_uint (g_value_array_get_nth (values, 4));
+
+ tp_call_add_stream (EMPATHY_TP_CALL (call), stream_id, contact_handle,
+ stream_type, stream_state, stream_direction);
+ }
}
+static void
+tp_call_request_streams_for_capabilities (EmpathyTpCall *call,
+ EmpathyCapabilities capabilities)
+{
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+ GArray *stream_types;
+ guint handle;
+ guint stream_type;
+
+ if (capabilities == EMPATHY_CAPABILITIES_UNKNOWN)
+ capabilities = EMPATHY_CAPABILITIES_AUDIO | EMPATHY_CAPABILITIES_VIDEO;
+
+ DEBUG ("Requesting new stream for capabilities %d",
+ capabilities);
+
+ stream_types = g_array_new (FALSE, FALSE, sizeof (guint));
+ handle = empathy_contact_get_handle (priv->contact);
+
+ if (capabilities & EMPATHY_CAPABILITIES_AUDIO)
+ {
+ stream_type = TP_MEDIA_STREAM_TYPE_AUDIO;
+ g_array_append_val (stream_types, stream_type);
+ }
+ if (capabilities & EMPATHY_CAPABILITIES_VIDEO)
+ {
+ stream_type = TP_MEDIA_STREAM_TYPE_VIDEO;
+ g_array_append_val (stream_types, stream_type);
+ }
+
+ tp_cli_channel_type_streamed_media_call_request_streams (priv->channel, -1,
+ handle, stream_types, tp_call_request_streams_cb, NULL, NULL,
+ G_OBJECT (call));
+
+ g_array_free (stream_types, TRUE);
+}
static void
-tp_call_stream_removed_cb (DBusGProxy *streamed_iface,
- guint stream_id,
- EmpathyTpCall *call)
+tp_call_got_contact_cb (EmpathyTpContactFactory *factory,
+ EmpathyContact *contact,
+ const GError *error,
+ gpointer user_data,
+ GObject *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ if (error)
+ {
+ DEBUG ("Error: %s", error->message);
+ return;
+ }
+
+ priv->contact = g_object_ref (contact);
+ priv->is_incoming = TRUE;
+ priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
+ g_object_notify (G_OBJECT (call), "is-incoming");
+ g_object_notify (G_OBJECT (call), "contact");
+ g_object_notify (G_OBJECT (call), "status");
+}
- empathy_debug (DEBUG_DOMAIN, "Stream removed: %d", stream_id);
+static void
+tp_call_update_status (EmpathyTpCall *call)
+{
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+ TpHandle self_handle;
+ const TpIntSet *set;
+ TpIntSetIter iter;
+
+ g_object_ref (call);
+
+ self_handle = tp_channel_group_get_self_handle (priv->channel);
+ set = tp_channel_group_get_members (priv->channel);
+ tp_intset_iter_init (&iter, set);
+ while (tp_intset_iter_next (&iter))
+ {
+ if (priv->contact == NULL && iter.element != self_handle)
+ {
+ EmpathyTpContactFactory *factory;
+ TpConnection *connection;
+
+ /* We found the remote contact */
+ connection = tp_channel_borrow_connection (priv->channel);
+ factory = empathy_tp_contact_factory_dup_singleton (connection);
+ empathy_tp_contact_factory_get_from_handle (factory, iter.element,
+ tp_call_got_contact_cb, NULL, NULL, G_OBJECT (call));
+ g_object_unref (factory);
+ }
+
+ if (priv->status == EMPATHY_TP_CALL_STATUS_PENDING &&
+ ((priv->is_incoming && iter.element == self_handle) ||
+ (!priv->is_incoming && iter.element != self_handle)))
+ {
+ priv->status = EMPATHY_TP_CALL_STATUS_ACCEPTED;
+ g_object_notify (G_OBJECT (call), "status");
+ }
+ }
+
+ g_object_unref (call);
+}
- if (stream_id == priv->audio_stream) {
- priv->audio_stream = 0;
- }
- else if (stream_id == priv->video_stream) {
- priv->video_stream = 0;
- }
+void
+empathy_tp_call_to (EmpathyTpCall *call, EmpathyContact *contact)
+{
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ priv->contact = g_object_ref (contact);
+ priv->is_incoming = FALSE;
+ priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
+ 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);
}
static void
-tp_call_list_streams_cb (DBusGProxy *proxy,
- GPtrArray *streams,
- GError *error,
- gpointer user_data)
+tp_call_channel_invalidated_cb (TpChannel *channel,
+ GQuark domain,
+ gint code,
+ gchar *message,
+ EmpathyTpCall *call)
{
- guint i;
-
- if (error) {
- empathy_debug (DEBUG_DOMAIN, "Failed to list streams: %s",
- error->message);
- return;
- }
-
- for (i = 0; i < streams->len; i++) {
- GValueArray *values;
- guint stream_id;
- guint contact_handle;
- guint stream_type;
-
- values = g_ptr_array_index (streams, i);
- stream_id = g_value_get_uint (g_value_array_get_nth (values, 0));
- contact_handle = g_value_get_uint (g_value_array_get_nth (values, 1));
- stream_type = g_value_get_uint (g_value_array_get_nth (values, 2));
-
- tp_call_stream_added_cb (proxy,
- stream_id,
- contact_handle,
- stream_type,
- user_data);
- }
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ DEBUG ("Channel invalidated: %s", message);
+ priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
+ g_object_notify (G_OBJECT (call), "status");
}
static void
-tp_call_member_added_cb (EmpathyTpGroup *group,
- EmpathyContact *contact,
- EmpathyContact *actor,
- guint reason,
- const gchar *message,
- EmpathyTpCall *call)
+tp_call_async_cb (TpProxy *proxy,
+ const GError *error,
+ gpointer user_data,
+ GObject *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- empathy_debug (DEBUG_DOMAIN, "Members added %s (%d)",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact));
-
- if (!priv->contact) {
- if (!empathy_contact_is_user (contact)) {
- priv->is_incoming = TRUE;
- priv->contact = g_object_ref (contact);
- tp_call_set_status (call, EMPATHY_TP_CALL_STATUS_RINGING);
- }
- return;
- }
-
- /* We already have the other contact, that means we now have 2 members,
- * so we can start the call */
- tp_call_set_status (call, EMPATHY_TP_CALL_STATUS_RUNNING);
+ if (error)
+ DEBUG ("Error %s: %s", (gchar*) user_data, error->message);
}
+static GObject *
+tp_call_constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *object;
+ EmpathyTpCall *call;
+ EmpathyTpCallPriv *priv;
+
+ object = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type,
+ n_construct_params, construct_params);
+
+ call = EMPATHY_TP_CALL (object);
+ priv = GET_PRIV (call);
+
+ /* Setup streamed media channel */
+ g_signal_connect (priv->channel, "invalidated",
+ G_CALLBACK (tp_call_channel_invalidated_cb), call);
+ tp_cli_channel_type_streamed_media_connect_to_stream_added (priv->channel,
+ tp_call_stream_added_cb, NULL, NULL, G_OBJECT (call), NULL);
+ tp_cli_channel_type_streamed_media_connect_to_stream_removed (priv->channel,
+ tp_call_stream_removed_cb, NULL, NULL, G_OBJECT (call), NULL);
+ tp_cli_channel_type_streamed_media_connect_to_stream_state_changed (priv->channel,
+ 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_call_list_streams (priv->channel, -1,
+ tp_call_request_streams_cb, NULL, NULL, G_OBJECT (call));
+
+ /* Update status when members changes */
+ tp_call_update_status (call);
+ g_signal_connect_swapped (priv->channel, "group-members-changed",
+ G_CALLBACK (tp_call_update_status), call);
+
+ return object;
+}
static void
-tp_call_remote_pending_cb (EmpathyTpGroup *group,
- EmpathyContact *contact,
- EmpathyContact *actor,
- guint reason,
- const gchar *message,
- EmpathyTpCall *call)
+tp_call_dispose (GObject *object)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
+ EmpathyTpCallPriv *priv = GET_PRIV (object);
+
+ DEBUG ("Disposing: %p, %d", object, priv->dispose_has_run);
+
+ if (priv->dispose_has_run)
+ return;
+
+ priv->dispose_has_run = TRUE;
+
+ if (priv->channel != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (priv->channel,
+ tp_call_channel_invalidated_cb, object);
- empathy_debug (DEBUG_DOMAIN, "Remote pending: %s (%d)",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact));
+ g_object_unref (priv->channel);
+ priv->channel = NULL;
+ }
- if (!priv->contact) {
- priv->is_incoming = FALSE;
- priv->contact = g_object_ref (contact);
- tp_call_set_status (call, EMPATHY_TP_CALL_STATUS_RINGING);
- }
+ if (priv->contact != NULL)
+ g_object_unref (priv->contact);
+
+ if (G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose)
+ G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose (object);
}
static void
-tp_call_async_cb (DBusGProxy *proxy,
- GError *error,
- gpointer user_data)
+tp_call_finalize (GObject *object)
{
- if (error) {
- empathy_debug (DEBUG_DOMAIN, "Failed to %s: %s",
- user_data,
- error->message);
- }
+ 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 GObject *
-tp_call_constructor (GType type,
- guint n_props,
- GObjectConstructParam *props)
+static void
+tp_call_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GObject *call;
- EmpathyTpCallPriv *priv;
- TpConn *tp_conn;
- MissionControl *mc;
-
- call = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type, n_props, props);
- priv = GET_PRIV (call);
-
- priv->group = empathy_tp_group_new (priv->account, priv->tp_chan);
- priv->streamed_iface = tp_chan_get_interface (priv->tp_chan,
- TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
-
- /* Connect signals */
- dbus_g_proxy_connect_signal (priv->streamed_iface, "StreamAdded",
- G_CALLBACK (tp_call_stream_added_cb),
- call, NULL);
- dbus_g_proxy_connect_signal (priv->streamed_iface, "StreamRemoved",
- G_CALLBACK (tp_call_stream_removed_cb),
- call, NULL);
- dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->tp_chan), "Closed",
- G_CALLBACK (tp_call_closed_cb),
- call, NULL);
- g_signal_connect (priv->tp_chan, "destroy",
- G_CALLBACK (tp_call_destroy_cb),
- call);
- g_signal_connect (priv->group, "member-added",
- G_CALLBACK (tp_call_member_added_cb),
- call);
- g_signal_connect (priv->group, "remote-pending",
- G_CALLBACK (tp_call_remote_pending_cb),
- call);
-
- /* Start stream engine */
- mc = empathy_mission_control_new ();
- tp_conn = mission_control_get_connection (mc, priv->account, NULL);
- priv->se_ch_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
- STREAM_ENGINE_BUS_NAME,
- STREAM_ENGINE_OBJECT_PATH,
- CHANNEL_HANDLER_INTERFACE);
- priv->se_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
- STREAM_ENGINE_BUS_NAME,
- STREAM_ENGINE_OBJECT_PATH,
- STREAM_ENGINE_INTERFACE);
- org_freedesktop_Telepathy_ChannelHandler_handle_channel_async (priv->se_ch_proxy,
- dbus_g_proxy_get_bus_name (DBUS_G_PROXY (tp_conn)),
- dbus_g_proxy_get_path (DBUS_G_PROXY (tp_conn)),
- priv->tp_chan->type,
- dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan)),
- priv->tp_chan->handle_type,
- priv->tp_chan->handle,
- tp_call_async_cb,
- "handle channel");
- g_object_unref (tp_conn);
- g_object_unref (mc);
-
- /* Get streams */
- tp_chan_type_streamed_media_list_streams_async (priv->streamed_iface,
- tp_call_list_streams_cb,
- call);
-
- return call;
+ EmpathyTpCallPriv *priv = GET_PRIV (object);
+
+ switch (prop_id)
+ {
+ case PROP_CHANNEL:
+ priv->channel = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
-tp_call_finalize (GObject *object)
+tp_call_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EmpathyTpCallPriv *priv = GET_PRIV (object);
-
- empathy_debug (DEBUG_DOMAIN, "Finalizing: %p", object);
-
- if (priv->tp_chan) {
- GError *error = NULL;
-
- g_signal_handlers_disconnect_by_func (priv->tp_chan,
- tp_call_destroy_cb,
- object);
- empathy_debug (DEBUG_DOMAIN, "Closing channel...");
- if (!tp_chan_close (DBUS_G_PROXY (priv->tp_chan), &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Error closing text channel: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- }
- g_object_unref (priv->tp_chan);
- }
-
- g_object_unref (priv->group);
- g_object_unref (priv->contact);
- g_object_unref (priv->account);
- g_object_unref (priv->se_ch_proxy);
- g_object_unref (priv->se_proxy);
-
- G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize (object);
+ EmpathyTpCallPriv *priv = GET_PRIV (object);
+
+ switch (prop_id)
+ {
+ case PROP_CHANNEL:
+ g_value_set_object (value, priv->channel);
+ break;
+ case PROP_CONTACT:
+ g_value_set_object (value, priv->contact);
+ break;
+ case PROP_IS_INCOMING:
+ g_value_set_boolean (value, priv->is_incoming);
+ break;
+ case PROP_STATUS:
+ g_value_set_uint (value, priv->status);
+ break;
+ case PROP_AUDIO_STREAM:
+ g_value_set_pointer (value, priv->audio);
+ break;
+ case PROP_VIDEO_STREAM:
+ g_value_set_pointer (value, priv->video);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
empathy_tp_call_class_init (EmpathyTpCallClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructor = tp_call_constructor;
- object_class->finalize = tp_call_finalize;
- object_class->set_property = tp_call_set_property;
- object_class->get_property = tp_call_get_property;
-
- /* Construct-only properties */
- g_object_class_install_property (object_class,
- PROP_ACCOUNT,
- g_param_spec_object ("account",
- "channel Account",
- "The account associated with the channel",
- MC_TYPE_ACCOUNT,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (object_class,
- PROP_TP_CHAN,
- g_param_spec_object ("tp-chan",
- "telepathy channel",
- "The media channel for the call",
- TELEPATHY_CHAN_TYPE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
-
- /* Normal properties */
- g_object_class_install_property (object_class,
- PROP_STATUS,
- g_param_spec_enum ("status",
- "call status",
- "The status of the call",
- EMPATHY_TYPE_TP_CALL_STATUS,
- EMPATHY_TP_CALL_STATUS_PREPARING,
- G_PARAM_READABLE));
-
- /* Signals */
- signals[DESTROY] =
- g_signal_new ("destroy",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
-
- g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
+ 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;
+
+ g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
+
+ g_object_class_install_property (object_class, PROP_CHANNEL,
+ g_param_spec_object ("channel", "channel", "channel",
+ TP_TYPE_CHANNEL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (object_class, PROP_CONTACT,
+ g_param_spec_object ("contact", "Call contact", "Call contact",
+ EMPATHY_TYPE_CONTACT,
+ G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (object_class, PROP_IS_INCOMING,
+ g_param_spec_boolean ("is-incoming", "Is media stream incoming",
+ "Is media stream incoming", FALSE, G_PARAM_READABLE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (object_class, PROP_STATUS,
+ g_param_spec_uint ("status", "Call status",
+ "Call status", 0, 255, 0, G_PARAM_READABLE | G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (object_class, PROP_AUDIO_STREAM,
+ g_param_spec_pointer ("audio-stream", "Audio stream data",
+ "Audio stream data",
+ G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ g_object_class_install_property (object_class, PROP_VIDEO_STREAM,
+ g_param_spec_pointer ("video-stream", "Video stream data",
+ "Video stream data",
+ G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
}
static void
empathy_tp_call_init (EmpathyTpCall *call)
{
+ EmpathyTpCallPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (call,
+ EMPATHY_TYPE_TP_CALL, EmpathyTpCallPriv);
+
+ call->priv = priv;
+ priv->status = EMPATHY_TP_CALL_STATUS_READYING;
+ priv->contact = NULL;
+ priv->audio = g_slice_new0 (EmpathyTpCallStream);
+ priv->video = g_slice_new0 (EmpathyTpCallStream);
+ priv->audio->exists = FALSE;
+ priv->video->exists = FALSE;
}
EmpathyTpCall *
-empathy_tp_call_new (McAccount *account, TpChan *channel)
+empathy_tp_call_new (TpChannel *channel)
{
- return g_object_new (EMPATHY_TYPE_TP_CALL,
- "account", account,
- "tp_chan", channel,
- NULL);
-}
+ g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
-gboolean
-empathy_tp_call_is_incoming (EmpathyTpCall *call)
-{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- return priv->is_incoming;
+ return g_object_new (EMPATHY_TYPE_TP_CALL,
+ "channel", channel,
+ NULL);
}
-EmpathyTpCallStatus
-empathy_tp_call_get_status (EmpathyTpCall *call)
+void
+empathy_tp_call_accept_incoming_call (EmpathyTpCall *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+ TpHandle self_handle;
+ GArray handles = {(gchar *) &self_handle, 1};
- return priv->status;
-}
+ g_return_if_fail (EMPATHY_IS_TP_CALL (call));
+ g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_PENDING);
+ g_return_if_fail (priv->is_incoming);
-EmpathyContact *
-empathy_tp_call_get_contact (EmpathyTpCall *call)
-{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
+ DEBUG ("Accepting incoming call");
- return priv->contact;
+ self_handle = tp_channel_group_get_self_handle (priv->channel);
+ tp_cli_channel_interface_group_call_add_members (priv->channel, -1,
+ &handles, NULL, NULL, NULL, NULL, NULL);
}
void
-empathy_tp_call_accept (EmpathyTpCall *call)
+empathy_tp_call_close (EmpathyTpCall *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
- EmpathyContact *contact;
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
- contact = empathy_tp_group_get_self_contact (priv->group);
- empathy_tp_group_add_member (priv->group, contact, "");
-}
+ g_return_if_fail (EMPATHY_IS_TP_CALL (call));
-void
-empathy_tp_call_invite (EmpathyTpCall *call,
- EmpathyContact *contact)
-{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
+ if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
+ return;
- empathy_tp_group_add_member (priv->group, contact, "you're welcome");
-}
+ DEBUG ("Closing channel");
-void
-empathy_tp_call_request_streams (EmpathyTpCall *call,
- gboolean audio,
- gboolean video)
-{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
- GArray *stream_types;
- guint handle;
- guint type;
-
- empathy_debug (DEBUG_DOMAIN, "Requesting streams for audio=%s video=%s",
- audio ? "Yes" : "No",
- video ? "Yes" : "No");
-
- stream_types = g_array_new (FALSE, FALSE, sizeof (guint));
- if (audio) {
- type = TP_MEDIA_STREAM_TYPE_AUDIO;
- g_array_append_val (stream_types, type);
- }
- if (video) {
- type = TP_MEDIA_STREAM_TYPE_VIDEO;
- g_array_append_val (stream_types, type);
- }
-
- handle = empathy_contact_get_handle (priv->contact);
- tp_chan_type_streamed_media_request_streams_async (priv->streamed_iface,
- handle,
- stream_types,
- tp_call_list_streams_cb,
- call);
-
- g_array_free (stream_types, TRUE);
+ 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");
}
void
-empathy_tp_call_send_video (EmpathyTpCall *call,
- gboolean send)
+empathy_tp_call_request_video_stream_direction (EmpathyTpCall *call,
+ gboolean is_sending)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
- guint new_direction;
-
- if (!priv->video_stream) {
- return;
- }
-
- if (send) {
- new_direction = TP_MEDIA_STREAM_DIRECTION_BIDIRECTIONAL;
- } else {
- new_direction = TP_MEDIA_STREAM_DIRECTION_RECEIVE;
- }
-
- tp_chan_type_streamed_media_request_stream_direction_async (priv->streamed_iface,
- priv->video_stream,
- new_direction,
- tp_call_async_cb,
- "request stream direction");
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+ guint new_direction;
+
+ g_return_if_fail (EMPATHY_IS_TP_CALL (call));
+ g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
+
+ DEBUG ("Requesting video stream direction - is_sending: %d", is_sending);
+
+ if (!priv->video->exists)
+ {
+ if (is_sending)
+ tp_call_request_streams_for_capabilities (call,
+ EMPATHY_CAPABILITIES_VIDEO);
+ return;
+ }
+
+ if (is_sending)
+ new_direction = priv->video->direction | TP_MEDIA_STREAM_DIRECTION_SEND;
+ else
+ new_direction = priv->video->direction & ~TP_MEDIA_STREAM_DIRECTION_SEND;
+
+ tp_cli_channel_type_streamed_media_call_request_stream_direction (priv->channel,
+ -1, priv->video->id, new_direction,
+ (tp_cli_channel_type_streamed_media_callback_for_request_stream_direction)
+ tp_call_async_cb, NULL, NULL, G_OBJECT (call));
}
void
-empathy_tp_call_add_preview_window (EmpathyTpCall *call,
- guint socket_id)
+empathy_tp_call_start_tone (EmpathyTpCall *call, TpDTMFEvent event)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
- org_freedesktop_Telepathy_StreamEngine_add_preview_window_async (priv->se_proxy,
- socket_id,
- tp_call_async_cb,
- "add preview window");
-}
+ g_return_if_fail (EMPATHY_IS_TP_CALL (call));
+ g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
-void
-empathy_tp_call_remove_preview_window (EmpathyTpCall *call,
- guint socket_id)
-{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
+ if (!priv->audio->exists)
+ return;
- org_freedesktop_Telepathy_StreamEngine_remove_preview_window_async (priv->se_proxy,
- socket_id,
- tp_call_async_cb,
- "remove preview window");
+ tp_cli_channel_interface_dtmf_call_start_tone (priv->channel, -1,
+ priv->audio->id, event,
+ (tp_cli_channel_interface_dtmf_callback_for_start_tone) tp_call_async_cb,
+ "starting tone", NULL, G_OBJECT (call));
}
void
-empathy_tp_call_set_output_window (EmpathyTpCall *call,
- guint socket_id)
+empathy_tp_call_stop_tone (EmpathyTpCall *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- org_freedesktop_Telepathy_StreamEngine_set_output_window_async (priv->se_proxy,
- dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan)),
- priv->video_stream,
- socket_id,
- tp_call_async_cb,
- "set output window");
-}
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
-void
-empathy_tp_call_set_output_volume (EmpathyTpCall *call,
- guint volume)
-{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- org_freedesktop_Telepathy_StreamEngine_set_output_volume_async (priv->se_proxy,
- dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan)),
- priv->audio_stream,
- volume,
- tp_call_async_cb,
- "set output volume");
-}
+ g_return_if_fail (EMPATHY_IS_TP_CALL (call));
+ g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
+ if (!priv->audio->exists)
+ return;
-void
-empathy_tp_call_mute_output (EmpathyTpCall *call,
- gboolean is_muted)
-{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- org_freedesktop_Telepathy_StreamEngine_mute_output_async (priv->se_proxy,
- dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan)),
- priv->audio_stream,
- is_muted,
- tp_call_async_cb,
- "mute output");
+ tp_cli_channel_interface_dtmf_call_stop_tone (priv->channel, -1,
+ priv->audio->id,
+ (tp_cli_channel_interface_dtmf_callback_for_stop_tone) tp_call_async_cb,
+ "stoping tone", NULL, G_OBJECT (call));
}
-
-void
-empathy_tp_call_mute_input (EmpathyTpCall *call,
- gboolean is_muted)
+gboolean
+empathy_tp_call_has_dtmf (EmpathyTpCall *call)
{
- EmpathyTpCallPriv *priv = GET_PRIV (call);
-
- org_freedesktop_Telepathy_StreamEngine_mute_input_async (priv->se_proxy,
- dbus_g_proxy_get_path (DBUS_G_PROXY (priv->tp_chan)),
- priv->audio_stream,
- is_muted,
- tp_call_async_cb,
- "mute output");
+ EmpathyTpCallPriv *priv = GET_PRIV (call);
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
+
+ return tp_proxy_has_interface_by_id (priv->channel,
+ TP_IFACE_QUARK_CHANNEL_INTERFACE_DTMF);
}