2 * Copyright (C) 2007 Elliot Fairweather
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
22 #include <dbus/dbus-glib.h>
24 #include <libtelepathy/tp-chan-type-streamed-media-gen.h>
25 #include <libtelepathy/tp-connmgr.h>
26 #include <libtelepathy/tp-helpers.h>
27 #include <telepathy-glib/proxy-subclass.h>
28 #include <telepathy-glib/dbus.h>
30 #include <libmissioncontrol/mc-account.h>
32 #include <extensions/extensions.h>
33 #include <libempathy/empathy-contact-factory.h>
34 #include <libempathy/empathy-debug.h>
35 #include <libempathy/empathy-tp-group.h>
36 #include <libempathy/empathy-utils.h>
38 #include "empathy-tp-call.h"
40 #define DEBUG_DOMAIN "TpCall"
42 #define GET_PRIV(object) (G_TYPE_INSTANCE_GET_PRIVATE \
43 ((object), EMPATHY_TYPE_TP_CALL, EmpathyTpCallPriv))
45 #define STREAM_ENGINE_BUS_NAME "org.freedesktop.Telepathy.StreamEngine"
46 #define STREAM_ENGINE_OBJECT_PATH "/org/freedesktop/Telepathy/StreamEngine"
48 typedef struct _EmpathyTpCallPriv EmpathyTpCallPriv;
50 struct _EmpathyTpCallPriv
54 TpProxy *stream_engine;
55 TpDBusDaemon *dbus_daemon;
56 EmpathyTpGroup *group;
57 EmpathyContact *contact;
61 EmpathyTpCallStream *audio;
62 EmpathyTpCallStream *video;
67 STATUS_CHANGED_SIGNAL,
68 RECEIVING_VIDEO_SIGNAL,
85 static guint signals[LAST_SIGNAL];
86 static gchar *stream_engine_owner = NULL;
88 G_DEFINE_TYPE (EmpathyTpCall, empathy_tp_call, G_TYPE_OBJECT)
91 tp_call_stream_state_changed_cb (DBusGProxy *channel,
96 EmpathyTpCallPriv *priv = GET_PRIV (call);
98 empathy_debug (DEBUG_DOMAIN,
99 "Stream state changed - stream id: %d, state state: %d",
100 stream_id, stream_state);
102 if (stream_id == priv->audio->id)
104 priv->audio->state = stream_state;
106 else if (stream_id == priv->video->id)
108 priv->video->state = stream_state;
109 if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTED)
111 if (priv->video->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE)
113 empathy_debug (DEBUG_DOMAIN, "RECEIVING");
114 g_signal_emit (call, signals[RECEIVING_VIDEO_SIGNAL], 0, TRUE);
116 if (priv->video->direction & TP_MEDIA_STREAM_DIRECTION_SEND)
118 empathy_debug (DEBUG_DOMAIN, "SENDING");
119 g_signal_emit (call, signals[SENDING_VIDEO_SIGNAL], 0, TRUE);
124 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
128 tp_call_identify_streams (EmpathyTpCall *call)
130 EmpathyTpCallPriv *priv = GET_PRIV (call);
131 GPtrArray *stream_infos;
132 DBusGProxy *streamed_iface;
133 GError *error = NULL;
136 empathy_debug (DEBUG_DOMAIN, "Identifying audio/video streams");
138 streamed_iface = tp_chan_get_interface (priv->channel,
139 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
141 if (!tp_chan_type_streamed_media_list_streams (streamed_iface, &stream_infos,
144 empathy_debug (DEBUG_DOMAIN, "Couldn't list audio/video streams: %s",
146 g_clear_error (&error);
150 for (i = 0; i < stream_infos->len; i++)
157 guint stream_direction;
159 values = g_ptr_array_index (stream_infos, i);
160 stream_id = g_value_get_uint (g_value_array_get_nth (values, 0));
161 stream_handle = g_value_get_uint (g_value_array_get_nth (values, 1));
162 stream_type = g_value_get_uint (g_value_array_get_nth (values, 2));
163 stream_state = g_value_get_uint (g_value_array_get_nth (values, 3));
164 stream_direction = g_value_get_uint (g_value_array_get_nth (values, 4));
168 case TP_MEDIA_STREAM_TYPE_AUDIO:
169 empathy_debug (DEBUG_DOMAIN,
170 "Audio stream - id: %d, state: %d, direction: %d",
171 stream_id, stream_state, stream_direction);
172 priv->audio->exists = TRUE;
173 priv->audio->id = stream_id;
174 priv->audio->state = stream_state;
175 priv->audio->direction = stream_direction;
177 case TP_MEDIA_STREAM_TYPE_VIDEO:
178 empathy_debug (DEBUG_DOMAIN,
179 "Video stream - id: %d, state: %d, direction: %d",
180 stream_id, stream_state, stream_direction);
181 priv->video->exists = TRUE;
182 priv->video->id = stream_id;
183 priv->video->state = stream_state;
184 priv->video->direction = stream_direction;
187 empathy_debug (DEBUG_DOMAIN, "Unknown stream type: %d",
191 g_value_array_free (values);
196 tp_call_stream_added_cb (DBusGProxy *channel,
198 guint contact_handle,
202 empathy_debug (DEBUG_DOMAIN,
203 "Stream added - stream id: %d, contact handle: %d, stream type: %d",
204 stream_id, contact_handle, stream_type);
206 tp_call_identify_streams (call);
211 tp_call_stream_removed_cb (DBusGProxy *channel,
215 EmpathyTpCallPriv *priv = GET_PRIV (call);
217 empathy_debug (DEBUG_DOMAIN, "Stream removed - stream id: %d", stream_id);
219 if (stream_id == priv->audio->id)
221 priv->audio->exists = FALSE;
223 else if (stream_id == priv->video->id)
225 priv->video->exists = FALSE;
230 tp_call_channel_closed_cb (TpChan *channel,
233 EmpathyTpCallPriv *priv = GET_PRIV (call);
234 DBusGProxy *streamed_iface;
235 DBusGProxy *group_iface;
237 empathy_debug (DEBUG_DOMAIN, "Channel closed");
239 priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
240 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
242 streamed_iface = tp_chan_get_interface (priv->channel,
243 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
244 group_iface = tp_chan_get_interface (priv->channel,
245 TELEPATHY_CHAN_IFACE_GROUP_QUARK);
247 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->channel), "Closed",
248 G_CALLBACK (tp_call_channel_closed_cb), (gpointer) call);
249 dbus_g_proxy_disconnect_signal (streamed_iface, "StreamStateChanged",
250 G_CALLBACK (tp_call_stream_state_changed_cb), (gpointer) call);
251 dbus_g_proxy_disconnect_signal (streamed_iface, "StreamAdded",
252 G_CALLBACK (tp_call_stream_added_cb), (gpointer) call);
253 dbus_g_proxy_disconnect_signal (streamed_iface, "StreamRemoved",
254 G_CALLBACK (tp_call_stream_removed_cb), (gpointer) call);
258 tp_call_stream_direction_changed_cb (DBusGProxy *channel,
260 guint stream_direction,
264 EmpathyTpCallPriv *priv = GET_PRIV (call);
266 empathy_debug (DEBUG_DOMAIN,
267 "Stream direction changed - stream: %d, direction: %d",
268 stream_id, stream_direction);
270 if (stream_id == priv->audio->id)
272 priv->audio->direction = stream_direction;
274 else if (stream_id == priv->video->id)
276 priv->video->direction = stream_direction;
278 if (stream_direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE)
280 empathy_debug (DEBUG_DOMAIN, "RECEIVING");
281 g_signal_emit (call, signals[RECEIVING_VIDEO_SIGNAL], 0, TRUE);
285 empathy_debug (DEBUG_DOMAIN, "NOT RECEIVING");
286 g_signal_emit (call, signals[RECEIVING_VIDEO_SIGNAL], 0, FALSE);
289 if (stream_direction & TP_MEDIA_STREAM_DIRECTION_SEND)
291 empathy_debug (DEBUG_DOMAIN, "SENDING");
292 g_signal_emit (call, signals[SENDING_VIDEO_SIGNAL], 0, TRUE);
296 empathy_debug (DEBUG_DOMAIN, "NOT SENDING");
297 g_signal_emit (call, signals[SENDING_VIDEO_SIGNAL], 0, FALSE);
303 tp_call_request_streams_for_capabilities (EmpathyTpCall *call,
304 EmpathyCapabilities capabilities)
306 EmpathyTpCallPriv *priv = GET_PRIV (call);
307 DBusGProxy *streamed_iface;
308 GArray *stream_types;
311 GError *error = NULL;
313 empathy_debug (DEBUG_DOMAIN, "Requesting new stream for capabilities %d",
316 streamed_iface = tp_chan_get_interface (priv->channel,
317 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
318 stream_types = g_array_new (FALSE, FALSE, sizeof (guint));
319 handle = empathy_contact_get_handle (priv->contact);
321 if (capabilities & EMPATHY_CAPABILITIES_AUDIO)
323 stream_type = TP_MEDIA_STREAM_TYPE_AUDIO;
324 g_array_append_val (stream_types, stream_type);
326 if (capabilities & EMPATHY_CAPABILITIES_VIDEO)
328 stream_type = TP_MEDIA_STREAM_TYPE_VIDEO;
329 g_array_append_val (stream_types, stream_type);
332 if (!tp_chan_type_streamed_media_request_streams (streamed_iface, handle,
333 stream_types, NULL, &error))
335 empathy_debug (DEBUG_DOMAIN, "Couldn't request new stream: %s",
337 g_clear_error (&error);
340 g_array_free (stream_types, TRUE);
344 tp_call_request_streams_capabilities_cb (EmpathyContact *contact,
345 GParamSpec *property,
348 EmpathyTpCall *call = EMPATHY_TP_CALL (user_data);
350 g_signal_handlers_disconnect_by_func (contact,
351 tp_call_request_streams_capabilities_cb,
354 tp_call_request_streams_for_capabilities (call,
355 empathy_contact_get_capabilities (contact));
359 tp_call_request_streams (EmpathyTpCall *call)
361 EmpathyTpCallPriv *priv = GET_PRIV (call);
362 EmpathyCapabilities capabilities;
363 DBusGProxy *capabilities_iface;
365 empathy_debug (DEBUG_DOMAIN,
366 "Requesting appropriate audio/video streams from contact");
369 /* FIXME: SIP don't have capabilities interface but we know it supports
370 * only audio and not video. */
371 capabilities_iface = tp_conn_get_interface (priv->connection,
372 TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES);
373 if (!capabilities_iface)
375 capabilities = EMPATHY_CAPABILITIES_AUDIO;
379 capabilities = empathy_contact_get_capabilities (priv->contact);
380 if (capabilities == EMPATHY_CAPABILITIES_UNKNOWN)
382 g_signal_connect (priv->contact, "notify::capabilities",
383 G_CALLBACK (tp_call_request_streams_capabilities_cb), call);
388 tp_call_request_streams_for_capabilities (call, capabilities);
392 tp_call_is_ready (EmpathyTpCall *call)
394 EmpathyTpCallPriv *priv = GET_PRIV (call);
395 EmpathyContact *self_contact;
397 GList *local_pendings;
398 GList *remote_pendings;
400 if (priv->status > EMPATHY_TP_CALL_STATUS_READYING)
403 members = empathy_tp_group_get_members (priv->group);
407 self_contact = empathy_tp_group_get_self_contact (priv->group);
408 local_pendings = empathy_tp_group_get_local_pendings (priv->group);
409 remote_pendings = empathy_tp_group_get_remote_pendings (priv->group);
411 if (local_pendings &&
412 empathy_contact_equal (EMPATHY_CONTACT (((EmpathyPendingInfo *)
413 local_pendings->data)->member), self_contact))
415 empathy_debug (DEBUG_DOMAIN,
416 "Incoming call is ready - %p",
417 ((EmpathyPendingInfo *) local_pendings->data)->member);
418 priv->is_incoming = TRUE;
419 priv->contact = g_object_ref (members->data);
421 else if (remote_pendings &&
422 empathy_contact_equal (EMPATHY_CONTACT (members->data), self_contact))
424 empathy_debug (DEBUG_DOMAIN,
425 "Outgoing call is ready - %p", remote_pendings->data);
426 priv->is_incoming = FALSE;
427 priv->contact = g_object_ref (remote_pendings->data);
428 tp_call_request_streams (call);
431 g_object_unref (self_contact);
432 g_list_foreach (members, (GFunc) g_object_unref, NULL);
433 g_list_free (members);
434 g_list_foreach (local_pendings, (GFunc) empathy_pending_info_free, NULL);
435 g_list_free (local_pendings);
436 g_list_foreach (remote_pendings, (GFunc) g_object_unref, NULL);
437 g_list_free (remote_pendings);
441 priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
442 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
447 tp_call_member_added_cb (EmpathyTpGroup *group,
448 EmpathyContact *contact,
449 EmpathyContact *actor,
451 const gchar *message,
454 EmpathyTpCallPriv *priv = GET_PRIV (call);
456 empathy_debug (DEBUG_DOMAIN, "New member added callback %p", contact);
457 tp_call_is_ready (call);
459 if (priv->status == EMPATHY_TP_CALL_STATUS_PENDING)
461 if ((priv->is_incoming &&
462 !empathy_contact_equal (contact, priv->contact))
463 || (!priv->is_incoming &&
464 empathy_contact_equal (contact, priv->contact)))
466 priv->status = EMPATHY_TP_CALL_STATUS_ACCEPTED;
467 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
473 tp_call_local_pending_cb (EmpathyTpGroup *group,
474 EmpathyContact *contact,
475 EmpathyContact *actor,
477 const gchar *message,
480 empathy_debug (DEBUG_DOMAIN, "New local pending added callback %p", contact);
481 tp_call_is_ready (call);
485 tp_call_remote_pending_cb (EmpathyTpGroup *group,
486 EmpathyContact *contact,
487 EmpathyContact *actor,
489 const gchar *message,
492 empathy_debug (DEBUG_DOMAIN, "New remote pending added callback %p", contact);
493 tp_call_is_ready (call);
497 tp_call_async_cb (TpProxy *proxy,
504 empathy_debug (DEBUG_DOMAIN, "Error %s: %s",
505 user_data, error->message);
510 tp_call_invalidated_cb (TpProxy *stream_engine,
516 empathy_debug (DEBUG_DOMAIN, "Stream engine proxy invalidated: %s",
518 empathy_tp_call_close_channel (call);
522 tp_call_watch_name_owner_cb (TpDBusDaemon *daemon,
524 const gchar *new_owner,
527 /* G_STR_EMPTY(new_owner) means either stream-engine has not started yet or
528 * has crashed. We want to close the channel if stream-engine has crashed.
530 empathy_debug (DEBUG_DOMAIN, "Watch SE: name='%s' old_owner='%s' new_owner='%s'",
531 name, stream_engine_owner ? stream_engine_owner : "none",
532 new_owner ? new_owner : "none");
533 if (! G_STR_EMPTY(stream_engine_owner) &&
534 G_STR_EMPTY (new_owner))
536 empathy_debug (DEBUG_DOMAIN, "Stream engine falled off the bus");
537 empathy_tp_call_close_channel (call);
539 g_free(stream_engine_owner);
540 stream_engine_owner = g_strdup(new_owner);
544 tp_call_start_stream_engine (EmpathyTpCall *call)
546 EmpathyTpCallPriv *priv = GET_PRIV (call);
548 empathy_debug (DEBUG_DOMAIN, "Revving up the stream engine");
550 priv->stream_engine = g_object_new (TP_TYPE_PROXY,
551 "bus-name", STREAM_ENGINE_BUS_NAME,
552 "dbus-connection", tp_get_bus (),
553 "object-path", STREAM_ENGINE_OBJECT_PATH,
555 tp_proxy_add_interface_by_id (priv->stream_engine,
556 EMP_IFACE_QUARK_STREAM_ENGINE);
557 tp_proxy_add_interface_by_id (priv->stream_engine,
558 EMP_IFACE_QUARK_CHANNEL_HANDLER);
560 g_signal_connect (priv->stream_engine, "invalidated",
561 G_CALLBACK (tp_call_invalidated_cb),
564 /* FIXME: dbus daemon should be unique */
565 priv->dbus_daemon = tp_dbus_daemon_new (tp_get_bus ());
566 tp_dbus_daemon_watch_name_owner (priv->dbus_daemon, STREAM_ENGINE_BUS_NAME,
567 tp_call_watch_name_owner_cb,
570 emp_cli_channel_handler_call_handle_channel (priv->stream_engine, -1,
571 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->connection)),
572 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->connection)),
574 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
575 priv->channel->handle_type, priv->channel->handle,
577 "calling handle channel", NULL,
582 tp_call_constructor (GType type,
583 guint n_construct_params,
584 GObjectConstructParam *construct_params)
588 EmpathyTpCallPriv *priv;
589 DBusGProxy *streamed_iface;
593 object = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type,
594 n_construct_params, construct_params);
596 call = EMPATHY_TP_CALL (object);
597 priv = GET_PRIV (call);
599 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->channel), "Closed",
600 G_CALLBACK (tp_call_channel_closed_cb), (gpointer) call, NULL);
602 streamed_iface = tp_chan_get_interface (priv->channel,
603 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
604 dbus_g_proxy_connect_signal (streamed_iface, "StreamStateChanged",
605 G_CALLBACK (tp_call_stream_state_changed_cb),
606 (gpointer) call, NULL);
607 dbus_g_proxy_connect_signal (streamed_iface, "StreamDirectionChanged",
608 G_CALLBACK (tp_call_stream_direction_changed_cb),
609 (gpointer) call, NULL);
610 dbus_g_proxy_connect_signal (streamed_iface, "StreamAdded",
611 G_CALLBACK (tp_call_stream_added_cb), (gpointer) call, NULL);
612 dbus_g_proxy_connect_signal (streamed_iface, "StreamRemoved",
613 G_CALLBACK (tp_call_stream_removed_cb), (gpointer) call, NULL);
615 mc = empathy_mission_control_new ();
616 account = mission_control_get_account_for_connection (mc, priv->connection,
618 priv->group = empathy_tp_group_new (account, priv->channel);
621 g_signal_connect (G_OBJECT (priv->group), "member-added",
622 G_CALLBACK (tp_call_member_added_cb), (gpointer) call);
623 g_signal_connect (G_OBJECT (priv->group), "local-pending",
624 G_CALLBACK (tp_call_local_pending_cb), (gpointer) call);
625 g_signal_connect (G_OBJECT (priv->group), "remote-pending",
626 G_CALLBACK (tp_call_remote_pending_cb), (gpointer) call);
628 tp_call_start_stream_engine (call);
629 /* FIXME: unnecessary for outgoing? */
630 tp_call_identify_streams (call);
636 tp_call_finalize (GObject *object)
638 EmpathyTpCallPriv *priv = GET_PRIV (object);
640 empathy_debug (DEBUG_DOMAIN, "Finalizing: %p", object);
642 g_slice_free (EmpathyTpCallStream, priv->audio);
643 g_slice_free (EmpathyTpCallStream, priv->video);
644 g_object_unref (priv->group);
646 if (priv->connection != NULL)
647 g_object_unref (priv->connection);
649 if (priv->channel != NULL)
650 g_object_unref (priv->channel);
652 if (priv->stream_engine != NULL)
653 g_object_unref (priv->stream_engine);
655 if (priv->contact != NULL)
656 g_object_unref (priv->contact);
658 if (priv->dbus_daemon != NULL)
660 tp_dbus_daemon_cancel_name_owner_watch (priv->dbus_daemon,
661 STREAM_ENGINE_BUS_NAME,
662 tp_call_watch_name_owner_cb,
664 g_object_unref (priv->dbus_daemon);
667 g_free(stream_engine_owner);
669 (G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize) (object);
673 tp_call_set_property (GObject *object,
678 EmpathyTpCallPriv *priv = GET_PRIV (object);
682 case PROP_CONNECTION:
683 priv->connection = g_value_dup_object (value);
686 priv->channel = g_value_dup_object (value);
689 /* FIXME should this one be writable in the first place ? */
690 g_assert (priv->contact == NULL);
691 priv->contact = g_value_dup_object (value);
693 case PROP_IS_INCOMING:
694 priv->is_incoming = g_value_get_boolean (value);
697 priv->status = g_value_get_uint (value);
699 case PROP_AUDIO_STREAM:
700 priv->audio = g_value_get_pointer (value);
702 case PROP_VIDEO_STREAM:
703 priv->video = g_value_get_pointer (value);
706 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
713 tp_call_get_property (GObject *object,
718 EmpathyTpCallPriv *priv = GET_PRIV (object);
722 case PROP_CONNECTION:
723 g_value_set_object (value, priv->connection);
726 g_value_set_object (value, priv->channel);
729 g_value_set_object (value, priv->contact);
731 case PROP_IS_INCOMING:
732 g_value_set_boolean (value, priv->is_incoming);
735 g_value_set_uint (value, priv->status);
737 case PROP_AUDIO_STREAM:
738 g_value_set_pointer (value, priv->audio);
740 case PROP_VIDEO_STREAM:
741 g_value_set_pointer (value, priv->video);
744 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
750 empathy_tp_call_class_init (EmpathyTpCallClass *klass)
752 GObjectClass *object_class = G_OBJECT_CLASS (klass);
756 object_class->constructor = tp_call_constructor;
757 object_class->finalize = tp_call_finalize;
758 object_class->set_property = tp_call_set_property;
759 object_class->get_property = tp_call_get_property;
761 g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
763 signals[STATUS_CHANGED_SIGNAL] =
764 g_signal_new ("status-changed", G_TYPE_FROM_CLASS (klass),
765 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
767 signals[RECEIVING_VIDEO_SIGNAL] =
768 g_signal_new ("receiving-video", G_TYPE_FROM_CLASS (klass),
769 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
770 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
771 signals[SENDING_VIDEO_SIGNAL] =
772 g_signal_new ("sending-video", G_TYPE_FROM_CLASS (klass),
773 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
774 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
776 g_object_class_install_property (object_class, PROP_CONNECTION,
777 g_param_spec_object ("connection", "connection", "connection",
779 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
780 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
781 g_object_class_install_property (object_class, PROP_CHANNEL,
782 g_param_spec_object ("channel", "channel", "channel",
784 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
785 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
786 g_object_class_install_property (object_class, PROP_CONTACT,
787 g_param_spec_object ("contact", "Call contact", "Call contact",
788 EMPATHY_TYPE_CONTACT,
789 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
790 g_object_class_install_property (object_class, PROP_IS_INCOMING,
791 g_param_spec_boolean ("is-incoming", "Is media stream incoming",
792 "Is media stream incoming", FALSE, G_PARAM_READABLE |
793 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
794 g_object_class_install_property (object_class, PROP_STATUS,
795 g_param_spec_uint ("status", "Call status",
796 "Call status", 0, 255, 0, G_PARAM_READABLE | G_PARAM_STATIC_NICK |
797 G_PARAM_STATIC_BLURB));
798 g_object_class_install_property (object_class, PROP_AUDIO_STREAM,
799 g_param_spec_pointer ("audio-stream", "Audio stream data",
801 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
802 g_object_class_install_property (object_class, PROP_VIDEO_STREAM,
803 g_param_spec_pointer ("video-stream", "Video stream data",
805 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
809 empathy_tp_call_init (EmpathyTpCall *call)
811 EmpathyTpCallPriv *priv = GET_PRIV (call);
813 priv->status = EMPATHY_TP_CALL_STATUS_READYING;
814 priv->contact = NULL;
815 priv->audio = g_slice_new0 (EmpathyTpCallStream);
816 priv->video = g_slice_new0 (EmpathyTpCallStream);
817 priv->audio->exists = FALSE;
818 priv->video->exists = FALSE;
822 empathy_tp_call_new (TpConn *connection, TpChan *channel)
824 return g_object_new (EMPATHY_TYPE_TP_CALL,
825 "connection", connection,
831 empathy_tp_call_accept_incoming_call (EmpathyTpCall *call)
833 EmpathyTpCallPriv *priv = GET_PRIV (call);
834 GList *local_pendings;
836 empathy_debug (DEBUG_DOMAIN, "Accepting incoming call");
838 local_pendings = empathy_tp_group_get_local_pendings (priv->group);
840 empathy_tp_group_add_member (priv->group, EMPATHY_CONTACT
841 (((EmpathyPendingInfo *) local_pendings->data)->member), NULL);
843 g_list_foreach (local_pendings, (GFunc) empathy_pending_info_free, NULL);
844 g_list_free (local_pendings);
848 empathy_tp_call_request_video_stream_direction (EmpathyTpCall *call,
851 EmpathyTpCallPriv *priv = GET_PRIV (call);
852 DBusGProxy *streamed_iface;
854 GError *error = NULL;
856 empathy_debug (DEBUG_DOMAIN,
857 "Requesting video stream direction - is_sending: %d", is_sending);
859 if (!priv->video->exists)
861 tp_call_request_streams_for_capabilities (call, EMPATHY_CAPABILITIES_VIDEO);
865 streamed_iface = tp_chan_get_interface (priv->channel,
866 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
870 new_direction = priv->video->direction | TP_MEDIA_STREAM_DIRECTION_SEND;
874 new_direction = priv->video->direction & ~TP_MEDIA_STREAM_DIRECTION_SEND;
877 if (!tp_chan_type_streamed_media_request_stream_direction (streamed_iface,
878 priv->video->id, new_direction, &error))
880 empathy_debug (DEBUG_DOMAIN,
881 "Couldn't request video stream direction: %s", error->message);
882 g_clear_error (&error);
887 empathy_tp_call_close_channel (EmpathyTpCall *call)
889 EmpathyTpCallPriv *priv = GET_PRIV (call);
890 GError *error = NULL;
892 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
895 empathy_debug (DEBUG_DOMAIN, "Closing channel");
897 if (!tp_chan_close (DBUS_G_PROXY (priv->channel), &error))
899 empathy_debug (DEBUG_DOMAIN, "Error closing channel: %s",
900 error ? error->message : "No error given");
901 g_clear_error (&error);
904 priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
908 empathy_tp_call_add_preview_video (EmpathyTpCall *call,
909 guint preview_video_socket_id)
911 EmpathyTpCallPriv *priv = GET_PRIV (call);
913 empathy_debug (DEBUG_DOMAIN, "Adding preview video");
915 emp_cli_stream_engine_call_add_preview_window (priv->stream_engine, -1,
916 preview_video_socket_id,
918 "adding preview window", NULL,
923 empathy_tp_call_remove_preview_video (EmpathyTpCall *call,
924 guint preview_video_socket_id)
926 EmpathyTpCallPriv *priv = GET_PRIV (call);
928 empathy_debug (DEBUG_DOMAIN, "Removing preview video");
930 emp_cli_stream_engine_call_remove_preview_window (priv->stream_engine, -1,
931 preview_video_socket_id,
933 "removing preview window", NULL,
938 empathy_tp_call_add_output_video (EmpathyTpCall *call,
939 guint output_video_socket_id)
941 EmpathyTpCallPriv *priv = GET_PRIV (call);
943 empathy_debug (DEBUG_DOMAIN, "Adding output video - socket: %d",
944 output_video_socket_id);
946 emp_cli_stream_engine_call_set_output_window (priv->stream_engine, -1,
947 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
948 priv->video->id, output_video_socket_id,
950 "setting output window", NULL,
955 empathy_tp_call_set_output_volume (EmpathyTpCall *call,
958 EmpathyTpCallPriv *priv = GET_PRIV (call);
960 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
963 empathy_debug (DEBUG_DOMAIN, "Setting output volume: %d", volume);
965 emp_cli_stream_engine_call_set_output_volume (priv->stream_engine, -1,
966 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
967 priv->audio->id, volume,
969 "setting output volume", NULL,
974 empathy_tp_call_mute_output (EmpathyTpCall *call,
977 EmpathyTpCallPriv *priv = GET_PRIV (call);
979 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
982 empathy_debug (DEBUG_DOMAIN, "Setting output mute: %d", is_muted);
984 emp_cli_stream_engine_call_mute_output (priv->stream_engine, -1,
985 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
986 priv->audio->id, is_muted,
988 "muting output", NULL,
993 empathy_tp_call_mute_input (EmpathyTpCall *call,
996 EmpathyTpCallPriv *priv = GET_PRIV (call);
998 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
1001 empathy_debug (DEBUG_DOMAIN, "Setting input mute: %d", is_muted);
1003 emp_cli_stream_engine_call_mute_input (priv->stream_engine, -1,
1004 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
1005 priv->audio->id, is_muted,
1007 "muting input", NULL,