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);
531 tp_proxy_add_interface_by_id (priv->stream_engine,
532 EMP_IFACE_QUARK_STREAM_ENGINE);
533 tp_proxy_add_interface_by_id (priv->stream_engine,
534 EMP_IFACE_QUARK_CHANNEL_HANDLER);
536 g_signal_connect (priv->stream_engine, "invalidated",
537 G_CALLBACK (tp_call_invalidated_cb),
540 /* FIXME: dbus daemon should be unique */
541 priv->dbus_daemon = tp_dbus_daemon_new (tp_get_bus ());
542 tp_dbus_daemon_watch_name_owner (priv->dbus_daemon, STREAM_ENGINE_BUS_NAME,
543 tp_call_watch_name_owner_cb,
546 emp_cli_channel_handler_call_handle_channel (priv->stream_engine, -1,
547 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->connection)),
548 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->connection)),
550 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
551 priv->channel->handle_type, priv->channel->handle,
553 "calling handle channel", NULL,
558 tp_call_constructor (GType type,
559 guint n_construct_params,
560 GObjectConstructParam *construct_params)
564 EmpathyTpCallPriv *priv;
565 DBusGProxy *streamed_iface;
569 object = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type,
570 n_construct_params, construct_params);
572 call = EMPATHY_TP_CALL (object);
573 priv = GET_PRIV (call);
575 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->channel), "Closed",
576 G_CALLBACK (tp_call_channel_closed_cb), (gpointer) call, NULL);
578 streamed_iface = tp_chan_get_interface (priv->channel,
579 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
580 dbus_g_proxy_connect_signal (streamed_iface, "StreamStateChanged",
581 G_CALLBACK (tp_call_stream_state_changed_cb),
582 (gpointer) call, NULL);
583 dbus_g_proxy_connect_signal (streamed_iface, "StreamDirectionChanged",
584 G_CALLBACK (tp_call_stream_direction_changed_cb),
585 (gpointer) call, NULL);
586 dbus_g_proxy_connect_signal (streamed_iface, "StreamAdded",
587 G_CALLBACK (tp_call_stream_added_cb), (gpointer) call, NULL);
588 dbus_g_proxy_connect_signal (streamed_iface, "StreamRemoved",
589 G_CALLBACK (tp_call_stream_removed_cb), (gpointer) call, NULL);
591 mc = empathy_mission_control_new ();
592 account = mission_control_get_account_for_connection (mc, priv->connection,
594 priv->group = empathy_tp_group_new (account, priv->channel);
597 g_signal_connect (G_OBJECT (priv->group), "member-added",
598 G_CALLBACK (tp_call_member_added_cb), (gpointer) call);
599 g_signal_connect (G_OBJECT (priv->group), "local-pending",
600 G_CALLBACK (tp_call_local_pending_cb), (gpointer) call);
601 g_signal_connect (G_OBJECT (priv->group), "remote-pending",
602 G_CALLBACK (tp_call_remote_pending_cb), (gpointer) call);
604 tp_call_start_stream_engine (call);
605 /* FIXME: unnecessary for outgoing? */
606 tp_call_identify_streams (call);
612 tp_call_finalize (GObject *object)
614 EmpathyTpCallPriv *priv = GET_PRIV (object);
616 empathy_debug (DEBUG_DOMAIN, "Finalizing: %p", object);
618 g_slice_free (EmpathyTpCallStream, priv->audio);
619 g_slice_free (EmpathyTpCallStream, priv->video);
620 g_object_unref (priv->group);
622 if (priv->connection != NULL)
623 g_object_unref (priv->connection);
625 if (priv->channel != NULL)
626 g_object_unref (priv->channel);
628 if (priv->stream_engine != NULL)
629 g_object_unref (priv->stream_engine);
631 if (priv->contact != NULL)
632 g_object_unref (priv->contact);
634 if (priv->dbus_daemon != NULL)
636 tp_dbus_daemon_cancel_name_owner_watch (priv->dbus_daemon,
637 STREAM_ENGINE_BUS_NAME,
638 tp_call_watch_name_owner_cb,
640 g_object_unref (priv->dbus_daemon);
643 (G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize) (object);
647 tp_call_set_property (GObject *object,
652 EmpathyTpCallPriv *priv = GET_PRIV (object);
656 case PROP_CONNECTION:
657 priv->connection = g_value_dup_object (value);
660 priv->channel = g_value_dup_object (value);
663 /* FIXME should this one be writable in the first place ? */
664 g_assert (priv->contact == NULL);
665 priv->contact = g_value_dup_object (value);
667 case PROP_IS_INCOMING:
668 priv->is_incoming = g_value_get_boolean (value);
671 priv->status = g_value_get_uint (value);
673 case PROP_AUDIO_STREAM:
674 priv->audio = g_value_get_pointer (value);
676 case PROP_VIDEO_STREAM:
677 priv->video = g_value_get_pointer (value);
680 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
687 tp_call_get_property (GObject *object,
692 EmpathyTpCallPriv *priv = GET_PRIV (object);
696 case PROP_CONNECTION:
697 g_value_set_object (value, priv->connection);
700 g_value_set_object (value, priv->channel);
703 g_value_set_object (value, priv->contact);
705 case PROP_IS_INCOMING:
706 g_value_set_boolean (value, priv->is_incoming);
709 g_value_set_uint (value, priv->status);
711 case PROP_AUDIO_STREAM:
712 g_value_set_pointer (value, priv->audio);
714 case PROP_VIDEO_STREAM:
715 g_value_set_pointer (value, priv->video);
718 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
724 empathy_tp_call_class_init (EmpathyTpCallClass *klass)
726 GObjectClass *object_class = G_OBJECT_CLASS (klass);
730 object_class->constructor = tp_call_constructor;
731 object_class->finalize = tp_call_finalize;
732 object_class->set_property = tp_call_set_property;
733 object_class->get_property = tp_call_get_property;
735 g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
737 signals[STATUS_CHANGED_SIGNAL] =
738 g_signal_new ("status-changed", G_TYPE_FROM_CLASS (klass),
739 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
741 signals[RECEIVING_VIDEO_SIGNAL] =
742 g_signal_new ("receiving-video", G_TYPE_FROM_CLASS (klass),
743 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
744 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
745 signals[SENDING_VIDEO_SIGNAL] =
746 g_signal_new ("sending-video", G_TYPE_FROM_CLASS (klass),
747 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
748 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
750 g_object_class_install_property (object_class, PROP_CONNECTION,
751 g_param_spec_object ("connection", "connection", "connection",
753 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
754 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
755 g_object_class_install_property (object_class, PROP_CHANNEL,
756 g_param_spec_object ("channel", "channel", "channel",
758 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
759 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
760 g_object_class_install_property (object_class, PROP_CONTACT,
761 g_param_spec_object ("contact", "Call contact", "Call contact",
762 EMPATHY_TYPE_CONTACT,
763 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
764 g_object_class_install_property (object_class, PROP_IS_INCOMING,
765 g_param_spec_boolean ("is-incoming", "Is media stream incoming",
766 "Is media stream incoming", FALSE, G_PARAM_READABLE |
767 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
768 g_object_class_install_property (object_class, PROP_STATUS,
769 g_param_spec_uint ("status", "Call status",
770 "Call status", 0, 255, 0, G_PARAM_READABLE | G_PARAM_STATIC_NICK |
771 G_PARAM_STATIC_BLURB));
772 g_object_class_install_property (object_class, PROP_AUDIO_STREAM,
773 g_param_spec_pointer ("audio-stream", "Audio stream data",
775 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
776 g_object_class_install_property (object_class, PROP_VIDEO_STREAM,
777 g_param_spec_pointer ("video-stream", "Video stream data",
779 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
783 empathy_tp_call_init (EmpathyTpCall *call)
785 EmpathyTpCallPriv *priv = GET_PRIV (call);
787 priv->status = EMPATHY_TP_CALL_STATUS_READYING;
788 priv->contact = NULL;
789 priv->audio = g_slice_new0 (EmpathyTpCallStream);
790 priv->video = g_slice_new0 (EmpathyTpCallStream);
791 priv->audio->exists = FALSE;
792 priv->video->exists = FALSE;
796 empathy_tp_call_new (TpConn *connection, TpChan *channel)
798 return g_object_new (EMPATHY_TYPE_TP_CALL,
799 "connection", connection,
805 empathy_tp_call_accept_incoming_call (EmpathyTpCall *call)
807 EmpathyTpCallPriv *priv = GET_PRIV (call);
808 GList *local_pendings;
810 empathy_debug (DEBUG_DOMAIN, "Accepting incoming call");
812 local_pendings = empathy_tp_group_get_local_pendings (priv->group);
814 empathy_tp_group_add_member (priv->group, EMPATHY_CONTACT
815 (((EmpathyPendingInfo *) local_pendings->data)->member), NULL);
817 g_list_foreach (local_pendings, (GFunc) empathy_pending_info_free, NULL);
818 g_list_free (local_pendings);
822 empathy_tp_call_request_video_stream_direction (EmpathyTpCall *call,
825 EmpathyTpCallPriv *priv = GET_PRIV (call);
826 DBusGProxy *streamed_iface;
828 GError *error = NULL;
830 empathy_debug (DEBUG_DOMAIN,
831 "Requesting video stream direction - is_sending: %d", is_sending);
833 if (!priv->video->exists)
835 tp_call_request_streams_for_capabilities (call, EMPATHY_CAPABILITIES_VIDEO);
839 streamed_iface = tp_chan_get_interface (priv->channel,
840 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
844 new_direction = priv->video->direction | TP_MEDIA_STREAM_DIRECTION_SEND;
848 new_direction = priv->video->direction & ~TP_MEDIA_STREAM_DIRECTION_SEND;
851 if (!tp_chan_type_streamed_media_request_stream_direction (streamed_iface,
852 priv->video->id, new_direction, &error))
854 empathy_debug (DEBUG_DOMAIN,
855 "Couldn't request video stream direction: %s", error->message);
856 g_clear_error (&error);
861 empathy_tp_call_close_channel (EmpathyTpCall *call)
863 EmpathyTpCallPriv *priv = GET_PRIV (call);
864 GError *error = NULL;
866 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
869 empathy_debug (DEBUG_DOMAIN, "Closing channel");
871 if (!tp_chan_close (DBUS_G_PROXY (priv->channel), &error))
873 empathy_debug (DEBUG_DOMAIN, "Error closing channel: %s",
874 error ? error->message : "No error given");
875 g_clear_error (&error);
878 priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
882 empathy_tp_call_add_preview_video (EmpathyTpCall *call,
883 guint preview_video_socket_id)
885 EmpathyTpCallPriv *priv = GET_PRIV (call);
887 empathy_debug (DEBUG_DOMAIN, "Adding preview video");
889 emp_cli_stream_engine_call_add_preview_window (priv->stream_engine, -1,
890 preview_video_socket_id,
892 "adding preview window", NULL,
897 empathy_tp_call_remove_preview_video (EmpathyTpCall *call,
898 guint preview_video_socket_id)
900 EmpathyTpCallPriv *priv = GET_PRIV (call);
902 empathy_debug (DEBUG_DOMAIN, "Removing preview video");
904 emp_cli_stream_engine_call_remove_preview_window (priv->stream_engine, -1,
905 preview_video_socket_id,
907 "removing preview window", NULL,
912 empathy_tp_call_add_output_video (EmpathyTpCall *call,
913 guint output_video_socket_id)
915 EmpathyTpCallPriv *priv = GET_PRIV (call);
917 empathy_debug (DEBUG_DOMAIN, "Adding output video - socket: %d",
918 output_video_socket_id);
920 emp_cli_stream_engine_call_set_output_window (priv->stream_engine, -1,
921 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
922 priv->video->id, output_video_socket_id,
924 "setting output window", NULL,
929 empathy_tp_call_set_output_volume (EmpathyTpCall *call,
932 EmpathyTpCallPriv *priv = GET_PRIV (call);
934 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
937 empathy_debug (DEBUG_DOMAIN, "Setting output volume: %d", volume);
939 emp_cli_stream_engine_call_set_output_volume (priv->stream_engine, -1,
940 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
941 priv->audio->id, volume,
943 "setting output volume", NULL,
948 empathy_tp_call_mute_output (EmpathyTpCall *call,
951 EmpathyTpCallPriv *priv = GET_PRIV (call);
953 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
956 empathy_debug (DEBUG_DOMAIN, "Setting output mute: %d", is_muted);
958 emp_cli_stream_engine_call_mute_output (priv->stream_engine, -1,
959 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
960 priv->audio->id, is_muted,
962 "muting output", NULL,
967 empathy_tp_call_mute_input (EmpathyTpCall *call,
970 EmpathyTpCallPriv *priv = GET_PRIV (call);
972 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
975 empathy_debug (DEBUG_DOMAIN, "Setting input mute: %d", is_muted);
977 emp_cli_stream_engine_call_mute_input (priv->stream_engine, -1,
978 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
979 priv->audio->id, is_muted,
981 "muting input", NULL,