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;
60 gboolean stream_engine_started;
62 EmpathyTpCallStream *audio;
63 EmpathyTpCallStream *video;
68 STATUS_CHANGED_SIGNAL,
69 RECEIVING_VIDEO_SIGNAL,
86 static guint signals[LAST_SIGNAL];
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);
396 GList *local_pendings;
397 GList *remote_pendings;
399 if (priv->status > EMPATHY_TP_CALL_STATUS_READYING)
402 members = empathy_tp_group_get_members (priv->group);
406 local_pendings = empathy_tp_group_get_local_pendings (priv->group);
407 remote_pendings = empathy_tp_group_get_remote_pendings (priv->group);
409 if (local_pendings &&
410 empathy_contact_is_user (((EmpathyPendingInfo *) local_pendings->data)->member))
412 empathy_debug (DEBUG_DOMAIN,
413 "Incoming call is ready - %p",
414 ((EmpathyPendingInfo *) local_pendings->data)->member);
415 priv->is_incoming = TRUE;
416 priv->contact = g_object_ref (members->data);
418 else if (remote_pendings && empathy_contact_is_user (members->data))
420 empathy_debug (DEBUG_DOMAIN,
421 "Outgoing call is ready - %p", remote_pendings->data);
422 priv->is_incoming = FALSE;
423 priv->contact = g_object_ref (remote_pendings->data);
424 tp_call_request_streams (call);
427 g_list_foreach (members, (GFunc) g_object_unref, NULL);
428 g_list_free (members);
429 g_list_foreach (local_pendings, (GFunc) empathy_pending_info_free, NULL);
430 g_list_free (local_pendings);
431 g_list_foreach (remote_pendings, (GFunc) g_object_unref, NULL);
432 g_list_free (remote_pendings);
436 priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
437 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
442 tp_call_member_added_cb (EmpathyTpGroup *group,
443 EmpathyContact *contact,
444 EmpathyContact *actor,
446 const gchar *message,
449 EmpathyTpCallPriv *priv = GET_PRIV (call);
451 empathy_debug (DEBUG_DOMAIN, "New member added callback %p", contact);
452 tp_call_is_ready (call);
454 if (priv->status == EMPATHY_TP_CALL_STATUS_PENDING)
456 if ((priv->is_incoming && contact != priv->contact) ||
457 (!priv->is_incoming && contact == priv->contact))
459 priv->status = EMPATHY_TP_CALL_STATUS_ACCEPTED;
460 g_signal_emit (call, signals[STATUS_CHANGED_SIGNAL], 0);
466 tp_call_local_pending_cb (EmpathyTpGroup *group,
467 EmpathyContact *contact,
468 EmpathyContact *actor,
470 const gchar *message,
473 empathy_debug (DEBUG_DOMAIN, "New local pending added callback %p", contact);
474 tp_call_is_ready (call);
478 tp_call_remote_pending_cb (EmpathyTpGroup *group,
479 EmpathyContact *contact,
480 EmpathyContact *actor,
482 const gchar *message,
485 empathy_debug (DEBUG_DOMAIN, "New remote pending added callback %p", contact);
486 tp_call_is_ready (call);
490 tp_call_async_cb (TpProxy *proxy,
497 empathy_debug (DEBUG_DOMAIN, "Error %s: %s",
498 user_data, error->message);
503 tp_call_invalidated_cb (TpProxy *stream_engine,
509 empathy_debug (DEBUG_DOMAIN, "Stream engine proxy invalidated: %s",
511 empathy_tp_call_close_channel (call);
515 tp_call_watch_name_owner_cb (TpDBusDaemon *daemon,
517 const gchar *new_owner,
520 EmpathyTpCallPriv *priv = GET_PRIV (call);
522 /* G_STR_EMPTY(new_owner) means either stream-engine has not started yet or
523 * has crashed. We want to close the channel if stream-engine has crashed.
525 empathy_debug (DEBUG_DOMAIN,
526 "Watch SE: name='%s' SE started='%s' new_owner='%s'",
527 name, priv->stream_engine_started ? "yes" : "no",
528 new_owner ? new_owner : "none");
529 if (priv->stream_engine_started && G_STR_EMPTY (new_owner))
531 empathy_debug (DEBUG_DOMAIN, "Stream engine falled off the bus");
532 empathy_tp_call_close_channel (call);
534 priv->stream_engine_started = ! G_STR_EMPTY (new_owner);
538 tp_call_start_stream_engine (EmpathyTpCall *call)
540 EmpathyTpCallPriv *priv = GET_PRIV (call);
542 empathy_debug (DEBUG_DOMAIN, "Revving up the stream engine");
544 priv->stream_engine = g_object_new (TP_TYPE_PROXY,
545 "bus-name", STREAM_ENGINE_BUS_NAME,
546 "dbus-connection", tp_get_bus (),
547 "object-path", STREAM_ENGINE_OBJECT_PATH,
549 tp_proxy_add_interface_by_id (priv->stream_engine,
550 EMP_IFACE_QUARK_STREAM_ENGINE);
551 tp_proxy_add_interface_by_id (priv->stream_engine,
552 EMP_IFACE_QUARK_CHANNEL_HANDLER);
554 g_signal_connect (priv->stream_engine, "invalidated",
555 G_CALLBACK (tp_call_invalidated_cb),
558 /* FIXME: dbus daemon should be unique */
559 priv->dbus_daemon = tp_dbus_daemon_new (tp_get_bus ());
560 tp_dbus_daemon_watch_name_owner (priv->dbus_daemon, STREAM_ENGINE_BUS_NAME,
561 tp_call_watch_name_owner_cb,
564 emp_cli_channel_handler_call_handle_channel (priv->stream_engine, -1,
565 dbus_g_proxy_get_bus_name (DBUS_G_PROXY (priv->connection)),
566 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->connection)),
568 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
569 priv->channel->handle_type, priv->channel->handle,
571 "calling handle channel", NULL,
576 tp_call_constructor (GType type,
577 guint n_construct_params,
578 GObjectConstructParam *construct_params)
582 EmpathyTpCallPriv *priv;
583 DBusGProxy *streamed_iface;
587 object = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type,
588 n_construct_params, construct_params);
590 call = EMPATHY_TP_CALL (object);
591 priv = GET_PRIV (call);
593 dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->channel), "Closed",
594 G_CALLBACK (tp_call_channel_closed_cb), (gpointer) call, NULL);
596 streamed_iface = tp_chan_get_interface (priv->channel,
597 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
598 dbus_g_proxy_connect_signal (streamed_iface, "StreamStateChanged",
599 G_CALLBACK (tp_call_stream_state_changed_cb),
600 (gpointer) call, NULL);
601 dbus_g_proxy_connect_signal (streamed_iface, "StreamDirectionChanged",
602 G_CALLBACK (tp_call_stream_direction_changed_cb),
603 (gpointer) call, NULL);
604 dbus_g_proxy_connect_signal (streamed_iface, "StreamAdded",
605 G_CALLBACK (tp_call_stream_added_cb), (gpointer) call, NULL);
606 dbus_g_proxy_connect_signal (streamed_iface, "StreamRemoved",
607 G_CALLBACK (tp_call_stream_removed_cb), (gpointer) call, NULL);
609 mc = empathy_mission_control_new ();
610 account = mission_control_get_account_for_connection (mc, priv->connection,
612 priv->group = empathy_tp_group_new (account, priv->channel);
615 g_signal_connect (G_OBJECT (priv->group), "member-added",
616 G_CALLBACK (tp_call_member_added_cb), (gpointer) call);
617 g_signal_connect (G_OBJECT (priv->group), "local-pending",
618 G_CALLBACK (tp_call_local_pending_cb), (gpointer) call);
619 g_signal_connect (G_OBJECT (priv->group), "remote-pending",
620 G_CALLBACK (tp_call_remote_pending_cb), (gpointer) call);
622 tp_call_start_stream_engine (call);
623 /* FIXME: unnecessary for outgoing? */
624 tp_call_identify_streams (call);
630 tp_call_finalize (GObject *object)
632 EmpathyTpCallPriv *priv = GET_PRIV (object);
634 empathy_debug (DEBUG_DOMAIN, "Finalizing: %p", object);
636 g_slice_free (EmpathyTpCallStream, priv->audio);
637 g_slice_free (EmpathyTpCallStream, priv->video);
638 g_object_unref (priv->group);
640 if (priv->connection != NULL)
641 g_object_unref (priv->connection);
643 if (priv->channel != NULL)
644 g_object_unref (priv->channel);
646 if (priv->stream_engine != NULL)
647 g_object_unref (priv->stream_engine);
649 if (priv->contact != NULL)
650 g_object_unref (priv->contact);
652 if (priv->dbus_daemon != NULL)
654 tp_dbus_daemon_cancel_name_owner_watch (priv->dbus_daemon,
655 STREAM_ENGINE_BUS_NAME,
656 tp_call_watch_name_owner_cb,
658 g_object_unref (priv->dbus_daemon);
661 (G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize) (object);
665 tp_call_set_property (GObject *object,
670 EmpathyTpCallPriv *priv = GET_PRIV (object);
674 case PROP_CONNECTION:
675 priv->connection = g_value_dup_object (value);
678 priv->channel = g_value_dup_object (value);
681 /* FIXME should this one be writable in the first place ? */
682 g_assert (priv->contact == NULL);
683 priv->contact = g_value_dup_object (value);
685 case PROP_IS_INCOMING:
686 priv->is_incoming = g_value_get_boolean (value);
689 priv->status = g_value_get_uint (value);
691 case PROP_AUDIO_STREAM:
692 priv->audio = g_value_get_pointer (value);
694 case PROP_VIDEO_STREAM:
695 priv->video = g_value_get_pointer (value);
698 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
705 tp_call_get_property (GObject *object,
710 EmpathyTpCallPriv *priv = GET_PRIV (object);
714 case PROP_CONNECTION:
715 g_value_set_object (value, priv->connection);
718 g_value_set_object (value, priv->channel);
721 g_value_set_object (value, priv->contact);
723 case PROP_IS_INCOMING:
724 g_value_set_boolean (value, priv->is_incoming);
727 g_value_set_uint (value, priv->status);
729 case PROP_AUDIO_STREAM:
730 g_value_set_pointer (value, priv->audio);
732 case PROP_VIDEO_STREAM:
733 g_value_set_pointer (value, priv->video);
736 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
742 empathy_tp_call_class_init (EmpathyTpCallClass *klass)
744 GObjectClass *object_class = G_OBJECT_CLASS (klass);
748 object_class->constructor = tp_call_constructor;
749 object_class->finalize = tp_call_finalize;
750 object_class->set_property = tp_call_set_property;
751 object_class->get_property = tp_call_get_property;
753 g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
755 signals[STATUS_CHANGED_SIGNAL] =
756 g_signal_new ("status-changed", G_TYPE_FROM_CLASS (klass),
757 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
759 signals[RECEIVING_VIDEO_SIGNAL] =
760 g_signal_new ("receiving-video", G_TYPE_FROM_CLASS (klass),
761 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
762 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
763 signals[SENDING_VIDEO_SIGNAL] =
764 g_signal_new ("sending-video", G_TYPE_FROM_CLASS (klass),
765 G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
766 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
768 g_object_class_install_property (object_class, PROP_CONNECTION,
769 g_param_spec_object ("connection", "connection", "connection",
771 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
772 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
773 g_object_class_install_property (object_class, PROP_CHANNEL,
774 g_param_spec_object ("channel", "channel", "channel",
776 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
777 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
778 g_object_class_install_property (object_class, PROP_CONTACT,
779 g_param_spec_object ("contact", "Call contact", "Call contact",
780 EMPATHY_TYPE_CONTACT,
781 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
782 g_object_class_install_property (object_class, PROP_IS_INCOMING,
783 g_param_spec_boolean ("is-incoming", "Is media stream incoming",
784 "Is media stream incoming", FALSE, G_PARAM_READABLE |
785 G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
786 g_object_class_install_property (object_class, PROP_STATUS,
787 g_param_spec_uint ("status", "Call status",
788 "Call status", 0, 255, 0, G_PARAM_READABLE | G_PARAM_STATIC_NICK |
789 G_PARAM_STATIC_BLURB));
790 g_object_class_install_property (object_class, PROP_AUDIO_STREAM,
791 g_param_spec_pointer ("audio-stream", "Audio stream data",
793 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
794 g_object_class_install_property (object_class, PROP_VIDEO_STREAM,
795 g_param_spec_pointer ("video-stream", "Video stream data",
797 G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
801 empathy_tp_call_init (EmpathyTpCall *call)
803 EmpathyTpCallPriv *priv = GET_PRIV (call);
805 priv->status = EMPATHY_TP_CALL_STATUS_READYING;
806 priv->contact = NULL;
807 priv->stream_engine_started = FALSE;
808 priv->audio = g_slice_new0 (EmpathyTpCallStream);
809 priv->video = g_slice_new0 (EmpathyTpCallStream);
810 priv->audio->exists = FALSE;
811 priv->video->exists = FALSE;
815 empathy_tp_call_new (TpConn *connection, TpChan *channel)
817 return g_object_new (EMPATHY_TYPE_TP_CALL,
818 "connection", connection,
824 empathy_tp_call_accept_incoming_call (EmpathyTpCall *call)
826 EmpathyTpCallPriv *priv = GET_PRIV (call);
827 EmpathyContact *self_contact;
829 empathy_debug (DEBUG_DOMAIN, "Accepting incoming call");
831 self_contact = empathy_tp_group_get_self_contact (priv->group);
832 empathy_tp_group_add_member (priv->group, self_contact, NULL);
833 g_object_unref (self_contact);
837 empathy_tp_call_request_video_stream_direction (EmpathyTpCall *call,
840 EmpathyTpCallPriv *priv = GET_PRIV (call);
841 DBusGProxy *streamed_iface;
843 GError *error = NULL;
845 empathy_debug (DEBUG_DOMAIN,
846 "Requesting video stream direction - is_sending: %d", is_sending);
848 if (!priv->video->exists)
850 tp_call_request_streams_for_capabilities (call, EMPATHY_CAPABILITIES_VIDEO);
854 streamed_iface = tp_chan_get_interface (priv->channel,
855 TELEPATHY_CHAN_IFACE_STREAMED_QUARK);
859 new_direction = priv->video->direction | TP_MEDIA_STREAM_DIRECTION_SEND;
863 new_direction = priv->video->direction & ~TP_MEDIA_STREAM_DIRECTION_SEND;
866 if (!tp_chan_type_streamed_media_request_stream_direction (streamed_iface,
867 priv->video->id, new_direction, &error))
869 empathy_debug (DEBUG_DOMAIN,
870 "Couldn't request video stream direction: %s", error->message);
871 g_clear_error (&error);
876 empathy_tp_call_close_channel (EmpathyTpCall *call)
878 EmpathyTpCallPriv *priv = GET_PRIV (call);
879 GError *error = NULL;
881 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
884 empathy_debug (DEBUG_DOMAIN, "Closing channel");
886 if (!tp_chan_close (DBUS_G_PROXY (priv->channel), &error))
888 empathy_debug (DEBUG_DOMAIN, "Error closing channel: %s",
889 error ? error->message : "No error given");
890 g_clear_error (&error);
893 priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
897 empathy_tp_call_add_preview_video (EmpathyTpCall *call,
898 guint preview_video_socket_id)
900 EmpathyTpCallPriv *priv = GET_PRIV (call);
902 empathy_debug (DEBUG_DOMAIN, "Adding preview video");
904 emp_cli_stream_engine_call_add_preview_window (priv->stream_engine, -1,
905 preview_video_socket_id,
907 "adding preview window", NULL,
912 empathy_tp_call_remove_preview_video (EmpathyTpCall *call,
913 guint preview_video_socket_id)
915 EmpathyTpCallPriv *priv = GET_PRIV (call);
917 empathy_debug (DEBUG_DOMAIN, "Removing preview video");
919 emp_cli_stream_engine_call_remove_preview_window (priv->stream_engine, -1,
920 preview_video_socket_id,
922 "removing preview window", NULL,
927 empathy_tp_call_add_output_video (EmpathyTpCall *call,
928 guint output_video_socket_id)
930 EmpathyTpCallPriv *priv = GET_PRIV (call);
932 empathy_debug (DEBUG_DOMAIN, "Adding output video - socket: %d",
933 output_video_socket_id);
935 emp_cli_stream_engine_call_set_output_window (priv->stream_engine, -1,
936 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
937 priv->video->id, output_video_socket_id,
939 "setting output window", NULL,
944 empathy_tp_call_set_output_volume (EmpathyTpCall *call,
947 EmpathyTpCallPriv *priv = GET_PRIV (call);
949 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
952 empathy_debug (DEBUG_DOMAIN, "Setting output volume: %d", volume);
954 emp_cli_stream_engine_call_set_output_volume (priv->stream_engine, -1,
955 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
956 priv->audio->id, volume,
958 "setting output volume", NULL,
963 empathy_tp_call_mute_output (EmpathyTpCall *call,
966 EmpathyTpCallPriv *priv = GET_PRIV (call);
968 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
971 empathy_debug (DEBUG_DOMAIN, "Setting output mute: %d", is_muted);
973 emp_cli_stream_engine_call_mute_output (priv->stream_engine, -1,
974 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
975 priv->audio->id, is_muted,
977 "muting output", NULL,
982 empathy_tp_call_mute_input (EmpathyTpCall *call,
985 EmpathyTpCallPriv *priv = GET_PRIV (call);
987 if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
990 empathy_debug (DEBUG_DOMAIN, "Setting input mute: %d", is_muted);
992 emp_cli_stream_engine_call_mute_input (priv->stream_engine, -1,
993 dbus_g_proxy_get_path (DBUS_G_PROXY (priv->channel)),
994 priv->audio->id, is_muted,
996 "muting input", NULL,