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];
87 G_DEFINE_TYPE (EmpathyTpCall, empathy_tp_call, G_TYPE_OBJECT)
90 tp_call_stream_state_changed_cb (DBusGProxy *channel,
95 EmpathyTpCallPriv *priv = GET_PRIV (call);
97 empathy_debug (DEBUG_DOMAIN,
98 "Stream state changed - stream id: %d, state state: %d",
99 stream_id, stream_state);
101 if (stream_id == priv->audio->id)
103 priv->audio->state = stream_state;
105 else if (stream_id == priv->video->id)
107 priv->video->state = stream_state;
110 g_signal_emit_by_name (call, "status-changed");
114 tp_call_identify_streams (EmpathyTpCall *call)
116 EmpathyTpCallPriv *priv = GET_PRIV (call);
117 GPtrArray *stream_infos;
118 DBusGProxy *streamed_iface;
119 GError *error = NULL;
122 empathy_debug (DEBUG_DOMAIN, "Identifying audio/video streams");
124 streamed_iface = tp_chan_get_interface (priv->channel,
125 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
127 if (!tp_chan_type_streamed_media_list_streams (streamed_iface, &stream_infos,
130 empathy_debug (DEBUG_DOMAIN, "Couldn't list audio/video streams: %s",
132 g_clear_error (&error);
136 for (i = 0; i < stream_infos->len; i++)
143 guint stream_direction;
145 values = g_ptr_array_index (stream_infos, i);
146 stream_id = g_value_get_uint (g_value_array_get_nth (values, 0));
147 stream_handle = g_value_get_uint (g_value_array_get_nth (values, 1));
148 stream_type = g_value_get_uint (g_value_array_get_nth (values, 2));
149 stream_state = g_value_get_uint (g_value_array_get_nth (values, 3));
150 stream_direction = g_value_get_uint (g_value_array_get_nth (values, 4));
154 case TP_MEDIA_STREAM_TYPE_AUDIO:
155 empathy_debug (DEBUG_DOMAIN,
156 "Audio stream - id: %d, state: %d, direction: %d",
157 stream_id, stream_state, stream_direction);
158 priv->audio->exists = TRUE;
159 priv->audio->id = stream_id;
160 priv->audio->state = stream_state;
161 priv->audio->direction = stream_direction;
163 case TP_MEDIA_STREAM_TYPE_VIDEO:
164 empathy_debug (DEBUG_DOMAIN,
165 "Video stream - id: %d, state: %d, direction: %d",
166 stream_id, stream_state, stream_direction);
167 priv->video->exists = TRUE;
168 priv->video->id = stream_id;
169 priv->video->state = stream_state;
170 priv->video->direction = stream_direction;
173 empathy_debug (DEBUG_DOMAIN, "Unknown stream type: %d",
177 g_value_array_free (values);
182 tp_call_stream_added_cb (DBusGProxy *channel,
184 guint contact_handle,
188 empathy_debug (DEBUG_DOMAIN,
189 "Stream added - stream id: %d, contact handle: %d, stream type: %d",
190 stream_id, contact_handle, stream_type);
192 tp_call_identify_streams (call);
197 tp_call_stream_removed_cb (DBusGProxy *channel,
201 EmpathyTpCallPriv *priv = GET_PRIV (call);
203 empathy_debug (DEBUG_DOMAIN, "Stream removed - stream id: %d", stream_id);
205 if (stream_id == priv->audio->id)
207 priv->audio->exists = FALSE;
209 else if (stream_id == priv->video->id)
211 priv->video->exists = FALSE;
216 tp_call_channel_closed_cb (TpChan *channel,
219 EmpathyTpCallPriv *priv = GET_PRIV (call);
220 DBusGProxy *streamed_iface;
221 DBusGProxy *group_iface;
223 empathy_debug (DEBUG_DOMAIN, "Channel closed");
225 priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
226 g_signal_emit_by_name (call, "status-changed");
228 streamed_iface = tp_chan_get_interface (priv->channel,
229 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
230 group_iface = tp_chan_get_interface (priv->channel,
231 TELEPATHY_CHAN_IFACE_GROUP_QUARK);
233 dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->channel), "Closed",
234 G_CALLBACK (tp_call_channel_closed_cb), (gpointer) call);
235 dbus_g_proxy_disconnect_signal (streamed_iface, "StreamStateChanged",
236 G_CALLBACK (tp_call_stream_state_changed_cb), (gpointer) call);
237 dbus_g_proxy_disconnect_signal (streamed_iface, "StreamAdded",
238 G_CALLBACK (tp_call_stream_added_cb), (gpointer) call);
239 dbus_g_proxy_disconnect_signal (streamed_iface, "StreamRemoved",
240 G_CALLBACK (tp_call_stream_removed_cb), (gpointer) call);
244 tp_call_stream_direction_changed_cb (DBusGProxy *channel,
246 guint stream_direction,
250 EmpathyTpCallPriv *priv = GET_PRIV (call);
252 empathy_debug (DEBUG_DOMAIN,
253 "Stream direction changed - stream: %d, direction: %d",
254 stream_id, stream_direction);
256 if (stream_id == priv->audio->id)
258 priv->audio->direction = stream_direction;
260 else if (stream_id == priv->video->id)
262 priv->video->direction = stream_direction;
264 if (stream_direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE)
266 empathy_debug (DEBUG_DOMAIN, "RECEIVING");
267 g_signal_emit_by_name (call, "receiving-video", TRUE);
271 empathy_debug (DEBUG_DOMAIN, "NOT RECEIVING");
272 g_signal_emit_by_name (call, "receiving-video", FALSE);
275 if (stream_direction & TP_MEDIA_STREAM_DIRECTION_SEND)
277 empathy_debug (DEBUG_DOMAIN, "SENDING");
278 g_signal_emit_by_name (call, "sending-video", TRUE);
282 empathy_debug (DEBUG_DOMAIN, "NOT SENDING");
283 g_signal_emit_by_name (call, "sending-video", FALSE);
289 tp_call_request_streams_for_capabilities (EmpathyTpCall *call,
290 EmpathyCapabilities capabilities)
292 EmpathyTpCallPriv *priv = GET_PRIV (call);
293 DBusGProxy *streamed_iface;
294 GArray *stream_types;
297 GError *error = NULL;
299 empathy_debug (DEBUG_DOMAIN, "Requesting new stream for capabilities %d",
302 streamed_iface = tp_chan_get_interface (priv->channel,
303 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
304 stream_types = g_array_new (FALSE, FALSE, sizeof (guint));
305 handle = empathy_contact_get_handle (priv->contact);
307 if (capabilities & EMPATHY_CAPABILITIES_AUDIO)
309 stream_type = TP_MEDIA_STREAM_TYPE_AUDIO;
310 g_array_append_val (stream_types, stream_type);
312 if (capabilities & EMPATHY_CAPABILITIES_VIDEO)
314 stream_type = TP_MEDIA_STREAM_TYPE_VIDEO;
315 g_array_append_val (stream_types, stream_type);
318 if (!tp_chan_type_streamed_media_request_streams (streamed_iface, handle,
319 stream_types, NULL, &error))
321 empathy_debug (DEBUG_DOMAIN, "Couldn't request new stream: %s",
323 g_clear_error (&error);
326 g_array_free (stream_types, TRUE);
330 tp_call_request_streams_capabilities_cb (EmpathyContact *contact,
331 GParamSpec *property,
334 EmpathyTpCall *call = EMPATHY_TP_CALL (user_data);
336 g_signal_handlers_disconnect_by_func (contact,
337 tp_call_request_streams_capabilities_cb,
340 tp_call_request_streams_for_capabilities (call,
341 empathy_contact_get_capabilities (contact));
345 tp_call_request_streams (EmpathyTpCall *call)
347 EmpathyTpCallPriv *priv = GET_PRIV (call);
348 EmpathyCapabilities capabilities;
349 DBusGProxy *capabilities_iface;
351 empathy_debug (DEBUG_DOMAIN,
352 "Requesting appropriate audio/video streams from contact");
355 /* FIXME: SIP don't have capabilities interface but we know it supports
356 * only audio and not video. */
357 capabilities_iface = tp_conn_get_interface (priv->connection,
358 TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES);
359 if (!capabilities_iface)
361 capabilities = EMPATHY_CAPABILITIES_AUDIO;
365 capabilities = empathy_contact_get_capabilities (priv->contact);
366 if (capabilities == EMPATHY_CAPABILITIES_UNKNOWN)
368 g_signal_connect (priv->contact, "notify::capabilities",
369 G_CALLBACK (tp_call_request_streams_capabilities_cb), call);
374 tp_call_request_streams_for_capabilities (call, capabilities);
378 tp_call_is_ready (EmpathyTpCall *call)
380 EmpathyTpCallPriv *priv = GET_PRIV (call);
381 EmpathyContact *self_contact;
383 GList *local_pendings;
384 GList *remote_pendings;
386 if (priv->status > EMPATHY_TP_CALL_STATUS_READYING)
389 members = empathy_tp_group_get_members (priv->group);
393 self_contact = empathy_tp_group_get_self_contact (priv->group);
394 local_pendings = empathy_tp_group_get_local_pendings (priv->group);
395 remote_pendings = empathy_tp_group_get_remote_pendings (priv->group);
397 if (local_pendings &&
398 empathy_contact_equal (EMPATHY_CONTACT (((EmpathyPendingInfo *)
399 local_pendings->data)->member), self_contact))
401 empathy_debug (DEBUG_DOMAIN,
402 "Incoming call is ready - %p",
403 ((EmpathyPendingInfo *) local_pendings->data)->member);
404 priv->is_incoming = TRUE;
405 priv->contact = g_object_ref (members->data);
407 else if (remote_pendings &&
408 empathy_contact_equal (EMPATHY_CONTACT (members->data), self_contact))
410 empathy_debug (DEBUG_DOMAIN,
411 "Outgoing call is ready - %p", remote_pendings->data);
412 priv->is_incoming = FALSE;
413 priv->contact = g_object_ref (remote_pendings->data);
414 tp_call_request_streams (call);
417 g_object_unref (self_contact);
418 g_list_foreach (members, (GFunc) g_object_unref, NULL);
419 g_list_free (members);
420 g_list_foreach (local_pendings, (GFunc) empathy_pending_info_free, NULL);
421 g_list_free (local_pendings);
422 g_list_foreach (remote_pendings, (GFunc) g_object_unref, NULL);
423 g_list_free (remote_pendings);
427 priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
428 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
433 tp_call_member_added_cb (EmpathyTpGroup *group,
434 EmpathyContact *contact,
435 EmpathyContact *actor,
437 const gchar *message,
440 EmpathyTpCallPriv *priv = GET_PRIV (call);
442 empathy_debug (DEBUG_DOMAIN, "New member added callback %p", contact);
443 tp_call_is_ready (call);
445 if (priv->status == EMPATHY_TP_CALL_STATUS_PENDING)
447 if ((priv->is_incoming &&
448 !empathy_contact_equal (contact, priv->contact))
449 || (!priv->is_incoming &&
450 empathy_contact_equal (contact, priv->contact)))
452 priv->status = EMPATHY_TP_CALL_STATUS_ACCEPTED;
453 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
459 tp_call_local_pending_cb (EmpathyTpGroup *group,
460 EmpathyContact *contact,
461 EmpathyContact *actor,
463 const gchar *message,
466 empathy_debug (DEBUG_DOMAIN, "New local pending added callback %p", contact);
467 tp_call_is_ready (call);
471 tp_call_remote_pending_cb (EmpathyTpGroup *group,
472 EmpathyContact *contact,
473 EmpathyContact *actor,
475 const gchar *message,
478 empathy_debug (DEBUG_DOMAIN, "New remote pending added callback %p", contact);
479 tp_call_is_ready (call);
483 tp_call_async_cb (TpProxy *proxy,
490 empathy_debug (DEBUG_DOMAIN, "Error %s: %s",
491 user_data, error->message);
496 tp_call_invalidated_cb (TpProxy *stream_engine,
502 empathy_debug (DEBUG_DOMAIN, "Stream engine proxy invalidated: %s",
504 empathy_tp_call_close_channel (call);
508 tp_call_watch_name_owner_cb (TpDBusDaemon *daemon,
510 const gchar *new_owner,
513 if (G_STR_EMPTY (new_owner))
515 empathy_debug (DEBUG_DOMAIN, "Stream engine falled off the bus");
516 empathy_tp_call_close_channel (call);
521 tp_call_start_stream_engine (EmpathyTpCall *call)
523 EmpathyTpCallPriv *priv = GET_PRIV (call);
525 empathy_debug (DEBUG_DOMAIN, "Revving up the stream engine");
527 priv->stream_engine = g_object_new (TP_TYPE_PROXY,
528 "bus-name", STREAM_ENGINE_BUS_NAME,
529 "dbus-connection", tp_get_bus (),
530 "object-path", STREAM_ENGINE_OBJECT_PATH,
532 tp_proxy_add_interface_by_id (priv->stream_engine,
533 EMP_IFACE_QUARK_STREAM_ENGINE);
534 tp_proxy_add_interface_by_id (priv->stream_engine,
535 EMP_IFACE_QUARK_CHANNEL_HANDLER);
537 g_signal_connect (priv->stream_engine, "invalidated",
538 G_CALLBACK (tp_call_invalidated_cb),
541 /* FIXME: dbus daemon should be unique */
542 priv->dbus_daemon = tp_dbus_daemon_new (tp_get_bus ());
543 tp_dbus_daemon_watch_name_owner (priv->dbus_daemon, STREAM_ENGINE_BUS_NAME,
544 tp_call_watch_name_owner_cb,
547 emp_cli_channel_handler_call_handle_channel (priv->stream_engine, -1,
548 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->connection)),
549 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->connection)),
551 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
552 priv->channel->handle_type, priv->channel->handle,
554 "calling handle channel", NULL,
559 tp_call_constructor (GType type,
560 guint n_construct_params,
561 GObjectConstructParam *construct_params)
565 EmpathyTpCallPriv *priv;
566 DBusGProxy *streamed_iface;
570 object = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type,
571 n_construct_params, construct_params);
573 call = EMPATHY_TP_CALL (object);
574 priv = GET_PRIV (call);
576 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->channel), "Closed",
577 G_CALLBACK (tp_call_channel_closed_cb), (gpointer) call, NULL);
579 streamed_iface = tp_chan_get_interface (priv->channel,
580 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
581 dbus_g_proxy_connect_signal (streamed_iface, "StreamStateChanged",
582 G_CALLBACK (tp_call_stream_state_changed_cb),
583 (gpointer) call, NULL);
584 dbus_g_proxy_connect_signal (streamed_iface, "StreamDirectionChanged",
585 G_CALLBACK (tp_call_stream_direction_changed_cb),
586 (gpointer) call, NULL);
587 dbus_g_proxy_connect_signal (streamed_iface, "StreamAdded",
588 G_CALLBACK (tp_call_stream_added_cb), (gpointer) call, NULL);
589 dbus_g_proxy_connect_signal (streamed_iface, "StreamRemoved",
590 G_CALLBACK (tp_call_stream_removed_cb), (gpointer) call, NULL);
592 mc = empathy_mission_control_new ();
593 account = mission_control_get_account_for_connection (mc, priv->connection,
595 priv->group = empathy_tp_group_new (account, priv->channel);
598 g_signal_connect (G_OBJECT (priv->group), "member-added",
599 G_CALLBACK (tp_call_member_added_cb), (gpointer) call);
600 g_signal_connect (G_OBJECT (priv->group), "local-pending",
601 G_CALLBACK (tp_call_local_pending_cb), (gpointer) call);
602 g_signal_connect (G_OBJECT (priv->group), "remote-pending",
603 G_CALLBACK (tp_call_remote_pending_cb), (gpointer) call);
605 tp_call_start_stream_engine (call);
606 /* FIXME: unnecessary for outgoing? */
607 tp_call_identify_streams (call);
613 tp_call_finalize (GObject *object)
615 EmpathyTpCallPriv *priv = GET_PRIV (object);
617 empathy_debug (DEBUG_DOMAIN, "Finalizing: %p", object);
619 g_slice_free (EmpathyTpCallStream, priv->audio);
620 g_slice_free (EmpathyTpCallStream, priv->video);
621 g_object_unref (priv->group);
623 if (priv->connection != NULL)
624 g_object_unref (priv->connection);
626 if (priv->channel != NULL)
627 g_object_unref (priv->channel);
629 if (priv->stream_engine != NULL)
630 g_object_unref (priv->stream_engine);
632 if (priv->contact != NULL)
633 g_object_unref (priv->contact);
635 if (priv->dbus_daemon != NULL)
637 tp_dbus_daemon_cancel_name_owner_watch (priv->dbus_daemon,
638 STREAM_ENGINE_BUS_NAME,
639 tp_call_watch_name_owner_cb,
641 g_object_unref (priv->dbus_daemon);
644 (G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize) (object);
648 tp_call_set_property (GObject *object,
653 EmpathyTpCallPriv *priv = GET_PRIV (object);
657 case PROP_CONNECTION:
658 priv->connection = g_value_dup_object (value);
661 priv->channel = g_value_dup_object (value);
664 /* FIXME should this one be writable in the first place ? */
665 g_assert (priv->contact == NULL);
666 priv->contact = g_value_dup_object (value);
668 case PROP_IS_INCOMING:
669 priv->is_incoming = g_value_get_boolean (value);
672 priv->status = g_value_get_uint (value);
674 case PROP_AUDIO_STREAM:
675 priv->audio = g_value_get_pointer (value);
677 case PROP_VIDEO_STREAM:
678 priv->video = g_value_get_pointer (value);
681 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
688 tp_call_get_property (GObject *object,
693 EmpathyTpCallPriv *priv = GET_PRIV (object);
697 case PROP_CONNECTION:
698 g_value_set_object (value, priv->connection);
701 g_value_set_object (value, priv->channel);
704 g_value_set_object (value, priv->contact);
706 case PROP_IS_INCOMING:
707 g_value_set_boolean (value, priv->is_incoming);
710 g_value_set_uint (value, priv->status);
712 case PROP_AUDIO_STREAM:
713 g_value_set_pointer (value, priv->audio);
715 case PROP_VIDEO_STREAM:
716 g_value_set_pointer (value, priv->video);
719 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
725 empathy_tp_call_class_init (EmpathyTpCallClass *klass)
727 GObjectClass *object_class = G_OBJECT_CLASS (klass);
731 object_class->constructor = tp_call_constructor;
732 object_class->finalize = tp_call_finalize;
733 object_class->set_property = tp_call_set_property;
734 object_class->get_property = tp_call_get_property;
736 g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
738 signals[STATUS_CHANGED_SIGNAL] =
739 g_signal_new ("status-changed", G_TYPE_FROM_CLASS (klass),
740 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
742 signals[RECEIVING_VIDEO_SIGNAL] =
743 g_signal_new ("receiving-video", G_TYPE_FROM_CLASS (klass),
744 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
745 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
746 signals[SENDING_VIDEO_SIGNAL] =
747 g_signal_new ("sending-video", G_TYPE_FROM_CLASS (klass),
748 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
749 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
751 g_object_class_install_property (object_class, PROP_CONNECTION,
752 g_param_spec_object ("connection", "connection", "connection",
754 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
755 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
756 g_object_class_install_property (object_class, PROP_CHANNEL,
757 g_param_spec_object ("channel", "channel", "channel",
759 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
760 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
761 g_object_class_install_property (object_class, PROP_CONTACT,
762 g_param_spec_object ("contact", "Call contact", "Call contact",
763 EMPATHY_TYPE_CONTACT,
764 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
765 g_object_class_install_property (object_class, PROP_IS_INCOMING,
766 g_param_spec_boolean ("is-incoming", "Is media stream incoming",
767 "Is media stream incoming", FALSE, G_PARAM_READABLE |
768 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
769 g_object_class_install_property (object_class, PROP_STATUS,
770 g_param_spec_uint ("status", "Call status",
771 "Call status", 0, 255, 0, G_PARAM_READABLE | G_PARAM_STATIC_NICK |
772 G_PARAM_STATIC_BLURB));
773 g_object_class_install_property (object_class, PROP_AUDIO_STREAM,
774 g_param_spec_pointer ("audio-stream", "Audio stream data",
776 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
777 g_object_class_install_property (object_class, PROP_VIDEO_STREAM,
778 g_param_spec_pointer ("video-stream", "Video stream data",
780 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
784 empathy_tp_call_init (EmpathyTpCall *call)
786 EmpathyTpCallPriv *priv = GET_PRIV (call);
788 priv->status = EMPATHY_TP_CALL_STATUS_READYING;
789 priv->contact = NULL;
790 priv->audio = g_slice_new0 (EmpathyTpCallStream);
791 priv->video = g_slice_new0 (EmpathyTpCallStream);
792 priv->audio->exists = FALSE;
793 priv->video->exists = FALSE;
797 empathy_tp_call_new (TpConn *connection, TpChan *channel)
799 return g_object_new (EMPATHY_TYPE_TP_CALL,
800 "connection", connection,
806 empathy_tp_call_accept_incoming_call (EmpathyTpCall *call)
808 EmpathyTpCallPriv *priv = GET_PRIV (call);
809 GList *local_pendings;
811 empathy_debug (DEBUG_DOMAIN, "Accepting incoming call");
813 local_pendings = empathy_tp_group_get_local_pendings (priv->group);
815 empathy_tp_group_add_member (priv->group, EMPATHY_CONTACT
816 (((EmpathyPendingInfo *) local_pendings->data)->member), NULL);
818 g_list_foreach (local_pendings, (GFunc) empathy_pending_info_free, NULL);
819 g_list_free (local_pendings);
823 empathy_tp_call_request_video_stream_direction (EmpathyTpCall *call,
826 EmpathyTpCallPriv *priv = GET_PRIV (call);
827 DBusGProxy *streamed_iface;
829 GError *error = NULL;
831 empathy_debug (DEBUG_DOMAIN,
832 "Requesting video stream direction - is_sending: %d", is_sending);
834 if (!priv->video->exists)
836 tp_call_request_streams_for_capabilities (call, EMPATHY_CAPABILITIES_VIDEO);
840 streamed_iface = tp_chan_get_interface (priv->channel,
841 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
845 new_direction = priv->video->direction | TP_MEDIA_STREAM_DIRECTION_SEND;
849 new_direction = priv->video->direction & ~TP_MEDIA_STREAM_DIRECTION_SEND;
852 if (!tp_chan_type_streamed_media_request_stream_direction (streamed_iface,
853 priv->video->id, new_direction, &error))
855 empathy_debug (DEBUG_DOMAIN,
856 "Couldn't request video stream direction: %s", error->message);
857 g_clear_error (&error);
862 empathy_tp_call_close_channel (EmpathyTpCall *call)
864 EmpathyTpCallPriv *priv = GET_PRIV (call);
865 GError *error = NULL;
867 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
870 empathy_debug (DEBUG_DOMAIN, "Closing channel");
872 if (!tp_chan_close (DBUS_G_PROXY (priv->channel), &error))
874 empathy_debug (DEBUG_DOMAIN, "Error closing channel: %s",
875 error ? error->message : "No error given");
876 g_clear_error (&error);
879 priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
883 empathy_tp_call_add_preview_video (EmpathyTpCall *call,
884 guint preview_video_socket_id)
886 EmpathyTpCallPriv *priv = GET_PRIV (call);
888 empathy_debug (DEBUG_DOMAIN, "Adding preview video");
890 emp_cli_stream_engine_call_add_preview_window (priv->stream_engine, -1,
891 preview_video_socket_id,
893 "adding preview window", NULL,
898 empathy_tp_call_remove_preview_video (EmpathyTpCall *call,
899 guint preview_video_socket_id)
901 EmpathyTpCallPriv *priv = GET_PRIV (call);
903 empathy_debug (DEBUG_DOMAIN, "Removing preview video");
905 emp_cli_stream_engine_call_remove_preview_window (priv->stream_engine, -1,
906 preview_video_socket_id,
908 "removing preview window", NULL,
913 empathy_tp_call_add_output_video (EmpathyTpCall *call,
914 guint output_video_socket_id)
916 EmpathyTpCallPriv *priv = GET_PRIV (call);
918 empathy_debug (DEBUG_DOMAIN, "Adding output video - socket: %d",
919 output_video_socket_id);
921 emp_cli_stream_engine_call_set_output_window (priv->stream_engine, -1,
922 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
923 priv->video->id, output_video_socket_id,
925 "setting output window", NULL,
930 empathy_tp_call_set_output_volume (EmpathyTpCall *call,
933 EmpathyTpCallPriv *priv = GET_PRIV (call);
935 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
938 empathy_debug (DEBUG_DOMAIN, "Setting output volume: %d", volume);
940 emp_cli_stream_engine_call_set_output_volume (priv->stream_engine, -1,
941 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
942 priv->audio->id, volume,
944 "setting output volume", NULL,
949 empathy_tp_call_mute_output (EmpathyTpCall *call,
952 EmpathyTpCallPriv *priv = GET_PRIV (call);
954 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
957 empathy_debug (DEBUG_DOMAIN, "Setting output mute: %d", is_muted);
959 emp_cli_stream_engine_call_mute_output (priv->stream_engine, -1,
960 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
961 priv->audio->id, is_muted,
963 "muting output", NULL,
968 empathy_tp_call_mute_input (EmpathyTpCall *call,
971 EmpathyTpCallPriv *priv = GET_PRIV (call);
973 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
976 empathy_debug (DEBUG_DOMAIN, "Setting input mute: %d", is_muted);
978 emp_cli_stream_engine_call_mute_input (priv->stream_engine, -1,
979 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
980 priv->audio->id, is_muted,
982 "muting input", NULL,