2 * empathy-call-handler.c - Source for EmpathyCallHandler
3 * Copyright (C) 2008-2009 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <telepathy-glib/account-channel-request.h>
26 #include <telepathy-glib/util.h>
27 #include <telepathy-glib/interfaces.h>
29 #include <telepathy-yell/telepathy-yell.h>
31 #include <telepathy-farstream/telepathy-farstream.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-tp-contact-factory.h>
36 #include "empathy-call-handler.h"
37 #include "empathy-call-factory.h"
38 #include "src-marshal.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
41 #include <libempathy/empathy-debug.h>
43 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
57 static guint signals[LAST_SIGNAL] = {0};
60 PROP_CALL_CHANNEL = 1,
66 PROP_SEND_AUDIO_CODEC,
67 PROP_SEND_VIDEO_CODEC,
68 PROP_RECV_AUDIO_CODECS,
69 PROP_RECV_VIDEO_CODECS,
70 PROP_AUDIO_REMOTE_CANDIDATE,
71 PROP_VIDEO_REMOTE_CANDIDATE,
72 PROP_AUDIO_LOCAL_CANDIDATE,
73 PROP_VIDEO_LOCAL_CANDIDATE,
76 /* private structure */
81 EmpathyContact *contact;
82 /* GArray of TpContacts */
85 gboolean initial_audio;
86 gboolean initial_video;
88 FsCodec *send_audio_codec;
89 FsCodec *send_video_codec;
90 GList *recv_audio_codecs;
91 GList *recv_video_codecs;
92 FsCandidate *audio_remote_candidate;
93 FsCandidate *video_remote_candidate;
94 FsCandidate *audio_local_candidate;
95 FsCandidate *video_local_candidate;
96 } EmpathyCallHandlerPriv;
98 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
101 empathy_call_handler_dispose (GObject *object)
103 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
105 tp_clear_object (&priv->tfchannel);
106 tp_clear_object (&priv->call);
107 tp_clear_object (&priv->contact);
109 tp_clear_pointer (&priv->members, g_array_unref);
111 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
115 empathy_call_handler_finalize (GObject *object)
117 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
119 fs_codec_destroy (priv->send_audio_codec);
120 fs_codec_destroy (priv->send_video_codec);
121 fs_codec_list_destroy (priv->recv_audio_codecs);
122 fs_codec_list_destroy (priv->recv_video_codecs);
123 fs_candidate_destroy (priv->audio_remote_candidate);
124 fs_candidate_destroy (priv->video_remote_candidate);
125 fs_candidate_destroy (priv->audio_local_candidate);
126 fs_candidate_destroy (priv->video_local_candidate);
128 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
132 empathy_call_handler_init (EmpathyCallHandler *obj)
134 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
135 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
141 on_get_contacts_cb (TpConnection *connection,
143 EmpathyContact * const * contacts,
145 const TpHandle *failed,
148 GObject *weak_object)
150 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (weak_object);
151 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
155 g_warning ("Failed to get %d EmpathyContacts: %s",
156 n_failed, error->message);
158 priv->members = g_array_sized_new (FALSE, TRUE,
159 sizeof (EmpathyContact *), n_contacts);
161 for (i = 0; i < n_contacts; i++)
162 g_object_ref (contacts[i]);
164 g_array_append_vals (priv->members, contacts, n_contacts);
166 g_object_notify (G_OBJECT (self), "members");
170 on_call_state_changed_cb (TpyCallChannel *call,
173 const GValueArray *call_state_reason,
174 GHashTable *call_state_details,
175 EmpathyCallHandler *handler)
177 if (state == TPY_CALL_STATE_ENDED)
178 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
182 on_members_changed_cb (TpyCallChannel *call,
184 EmpathyCallHandler *self)
186 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
196 n_handles = g_hash_table_size (members);
200 handles = g_new0 (TpHandle, n_handles);
202 g_hash_table_iter_init (&iter, members);
203 while (g_hash_table_iter_next (&iter, &key, &value))
204 handles[i++] = GPOINTER_TO_UINT (key);
206 empathy_tp_contact_factory_get_from_handles (
207 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
210 NULL, NULL, G_OBJECT (self));
216 empathy_call_handler_constructed (GObject *object)
218 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
219 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
220 // GHashTable *members;
222 g_signal_connect (priv->call, "members-changed",
223 G_CALLBACK (on_members_changed_cb), object);
226 g_object_get (priv->call, "members", &members, NULL);
229 on_members_changed_cb (priv->call, members, self);
234 empathy_call_handler_set_property (GObject *object,
235 guint property_id, const GValue *value, GParamSpec *pspec)
237 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
242 priv->contact = g_value_dup_object (value);
245 priv->members = g_value_get_boxed (value);
247 case PROP_CALL_CHANNEL:
248 g_return_if_fail (priv->call == NULL);
250 priv->call = g_value_dup_object (value);
252 tp_g_signal_connect_object (priv->call, "state-changed",
253 G_CALLBACK (on_call_state_changed_cb), object, 0);
255 case PROP_INITIAL_AUDIO:
256 priv->initial_audio = g_value_get_boolean (value);
258 case PROP_INITIAL_VIDEO:
259 priv->initial_video = g_value_get_boolean (value);
262 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
267 empathy_call_handler_get_property (GObject *object,
268 guint property_id, GValue *value, GParamSpec *pspec)
270 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
275 g_value_set_object (value, priv->contact);
278 g_value_set_boxed (value, priv->members);
280 case PROP_CALL_CHANNEL:
281 g_value_set_object (value, priv->call);
283 case PROP_INITIAL_AUDIO:
284 g_value_set_boolean (value, priv->initial_audio);
286 case PROP_INITIAL_VIDEO:
287 g_value_set_boolean (value, priv->initial_video);
289 case PROP_SEND_AUDIO_CODEC:
290 g_value_set_boxed (value, priv->send_audio_codec);
292 case PROP_SEND_VIDEO_CODEC:
293 g_value_set_boxed (value, priv->send_video_codec);
295 case PROP_RECV_AUDIO_CODECS:
296 g_value_set_boxed (value, priv->recv_audio_codecs);
298 case PROP_RECV_VIDEO_CODECS:
299 g_value_set_boxed (value, priv->recv_video_codecs);
301 case PROP_AUDIO_REMOTE_CANDIDATE:
302 g_value_set_boxed (value, priv->audio_remote_candidate);
304 case PROP_VIDEO_REMOTE_CANDIDATE:
305 g_value_set_boxed (value, priv->video_remote_candidate);
307 case PROP_AUDIO_LOCAL_CANDIDATE:
308 g_value_set_boxed (value, priv->audio_local_candidate);
310 case PROP_VIDEO_LOCAL_CANDIDATE:
311 g_value_set_boxed (value, priv->video_local_candidate);
314 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
320 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
322 GObjectClass *object_class = G_OBJECT_CLASS (klass);
323 GParamSpec *param_spec;
325 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
327 object_class->constructed = empathy_call_handler_constructed;
328 object_class->set_property = empathy_call_handler_set_property;
329 object_class->get_property = empathy_call_handler_get_property;
330 object_class->dispose = empathy_call_handler_dispose;
331 object_class->finalize = empathy_call_handler_finalize;
333 param_spec = g_param_spec_object ("target-contact",
334 "TargetContact", "The contact",
335 EMPATHY_TYPE_CONTACT,
336 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
337 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
339 param_spec = g_param_spec_boxed ("members",
340 "call members", "The call participants",
342 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
343 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
345 param_spec = g_param_spec_object ("call-channel",
346 "call channel", "The call channel",
347 TPY_TYPE_CALL_CHANNEL,
348 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
349 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
351 param_spec = g_param_spec_boolean ("initial-audio",
352 "initial-audio", "Whether the call should start with audio",
354 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
355 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
358 param_spec = g_param_spec_boolean ("initial-video",
359 "initial-video", "Whether the call should start with video",
361 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
362 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
365 param_spec = g_param_spec_boxed ("send-audio-codec",
366 "send audio codec", "Codec used to encode the outgoing video stream",
368 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
369 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
372 param_spec = g_param_spec_boxed ("send-video-codec",
373 "send video codec", "Codec used to encode the outgoing video stream",
375 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
376 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
379 param_spec = g_param_spec_boxed ("recv-audio-codecs",
380 "recvs audio codec", "Codecs used to decode the incoming audio stream",
382 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
383 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
386 param_spec = g_param_spec_boxed ("recv-video-codecs",
387 "recvs video codec", "Codecs used to decode the incoming video stream",
389 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
390 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
393 param_spec = g_param_spec_boxed ("audio-remote-candidate",
394 "audio remote candidate",
395 "Remote candidate used for the audio stream",
397 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
398 g_object_class_install_property (object_class,
399 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
401 param_spec = g_param_spec_boxed ("video-remote-candidate",
402 "video remote candidate",
403 "Remote candidate used for the video stream",
405 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
406 g_object_class_install_property (object_class,
407 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
409 param_spec = g_param_spec_boxed ("audio-local-candidate",
410 "audio local candidate",
411 "Local candidate used for the audio stream",
413 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
414 g_object_class_install_property (object_class,
415 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
417 param_spec = g_param_spec_boxed ("video-local-candidate",
418 "video local candidate",
419 "Local candidate used for the video stream",
421 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
422 g_object_class_install_property (object_class,
423 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
425 signals[CONFERENCE_ADDED] =
426 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
427 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
428 g_cclosure_marshal_VOID__OBJECT,
430 1, FS_TYPE_CONFERENCE);
432 signals[CONFERENCE_REMOVED] =
433 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
434 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
435 g_cclosure_marshal_VOID__OBJECT,
437 1, FS_TYPE_CONFERENCE);
439 signals[SRC_PAD_ADDED] =
440 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
441 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
442 _src_marshal_BOOLEAN__OBJECT_UINT,
444 2, GST_TYPE_PAD, G_TYPE_UINT);
446 signals[SINK_PAD_ADDED] =
447 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
448 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
449 _src_marshal_BOOLEAN__OBJECT_UINT,
451 2, GST_TYPE_PAD, G_TYPE_UINT);
453 signals[SINK_PAD_REMOVED] =
454 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
455 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
456 _src_marshal_BOOLEAN__OBJECT_UINT,
458 2, GST_TYPE_PAD, G_TYPE_UINT);
461 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
462 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
463 g_cclosure_marshal_VOID__VOID,
467 signals[CANDIDATES_CHANGED] =
468 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
469 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
470 g_cclosure_marshal_VOID__UINT,
471 G_TYPE_NONE, 1, G_TYPE_UINT);
475 empathy_call_handler_new_for_channel (TpyCallChannel *call,
476 EmpathyContact *contact)
478 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
479 "call-channel", call,
480 "initial-video", tpy_call_channel_has_initial_video (call),
481 "target-contact", contact,
486 update_sending_codec (EmpathyCallHandler *self,
490 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
493 if (codec == NULL || session == NULL)
496 g_object_get (session, "media-type", &type, NULL);
498 if (type == FS_MEDIA_TYPE_AUDIO)
500 priv->send_audio_codec = fs_codec_copy (codec);
501 g_object_notify (G_OBJECT (self), "send-audio-codec");
503 else if (type == FS_MEDIA_TYPE_VIDEO)
505 priv->send_video_codec = fs_codec_copy (codec);
506 g_object_notify (G_OBJECT (self), "send-video-codec");
511 update_receiving_codec (EmpathyCallHandler *self,
515 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
519 if (codecs == NULL || stream == NULL)
522 g_object_get (stream, "session", &session, NULL);
526 g_object_get (session, "media-type", &type, NULL);
528 if (type == FS_MEDIA_TYPE_AUDIO)
530 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
531 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
533 else if (type == FS_MEDIA_TYPE_VIDEO)
535 priv->recv_video_codecs = fs_codec_list_copy (codecs);
536 g_object_notify (G_OBJECT (self), "recv-video-codecs");
539 g_object_unref (session);
543 update_candidates (EmpathyCallHandler *self,
544 FsCandidate *remote_candidate,
545 FsCandidate *local_candidate,
548 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
555 g_object_get (stream, "session", &session, NULL);
559 g_object_get (session, "media-type", &type, NULL);
561 if (type == FS_MEDIA_TYPE_AUDIO)
563 if (remote_candidate != NULL)
565 fs_candidate_destroy (priv->audio_remote_candidate);
566 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
567 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
570 if (local_candidate != NULL)
572 fs_candidate_destroy (priv->audio_local_candidate);
573 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
574 g_object_notify (G_OBJECT (self), "audio-local-candidate");
577 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
578 FS_MEDIA_TYPE_AUDIO);
580 else if (type == FS_MEDIA_TYPE_VIDEO)
582 if (remote_candidate != NULL)
584 fs_candidate_destroy (priv->video_remote_candidate);
585 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
586 g_object_notify (G_OBJECT (self), "video-remote-candidate");
589 if (local_candidate != NULL)
591 fs_candidate_destroy (priv->video_local_candidate);
592 priv->video_local_candidate = fs_candidate_copy (local_candidate);
593 g_object_notify (G_OBJECT (self), "video-local-candidate");
596 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
597 FS_MEDIA_TYPE_VIDEO);
600 g_object_unref (session);
604 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
605 GstBus *bus, GstMessage *message)
607 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
608 const GstStructure *s = gst_message_get_structure (message);
610 if (priv->tfchannel == NULL)
614 gst_structure_has_name (s, "farsight-send-codec-changed"))
620 g_print ("empathy_call_handler_bus_message: farsight-send-codec-changed\n");
622 val = gst_structure_get_value (s, "codec");
623 codec = g_value_get_boxed (val);
625 val = gst_structure_get_value (s, "session");
626 session = g_value_get_object (val);
628 update_sending_codec (handler, codec, session);
630 else if (s != NULL &&
631 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
637 g_print ("empathy_call_handler_bus_message: farsight-recv-codecs-changed\n");
639 val = gst_structure_get_value (s, "codecs");
640 codecs = g_value_get_boxed (val);
642 val = gst_structure_get_value (s, "stream");
643 stream = g_value_get_object (val);
645 update_receiving_codec (handler, codecs, stream);
647 else if (s != NULL &&
648 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
651 FsCandidate *remote_candidate, *local_candidate;
654 g_print ("empathy_call_handler_bus_message: farsight-new-active-candidate-pair\n");
656 val = gst_structure_get_value (s, "remote-candidate");
657 remote_candidate = g_value_get_boxed (val);
659 val = gst_structure_get_value (s, "local-candidate");
660 local_candidate = g_value_get_boxed (val);
662 val = gst_structure_get_value (s, "stream");
663 stream = g_value_get_object (val);
665 update_candidates (handler, remote_candidate, local_candidate, stream);
668 tf_channel_bus_message (priv->tfchannel, message);
672 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
673 GstElement *conference,
674 EmpathyCallHandler *self)
676 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
681 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
682 FsConference *conference,
683 EmpathyCallHandler *self)
685 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
686 GST_ELEMENT (conference));
690 src_pad_added_error_idle (gpointer data)
692 TfContent *content = data;
694 tf_content_error (content, 0 /* FIXME */,
695 "Could not link sink", NULL);
696 g_object_unref (content);
702 on_tf_content_src_pad_added_cb (TfContent *content,
707 EmpathyCallHandler *handler)
712 g_object_get (content, "media-type", &media_type, NULL);
714 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
715 pad, media_type, &retval);
718 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
722 on_tf_channel_content_added_cb (TfChannel *tfchannel,
724 EmpathyCallHandler *handler)
729 // FsStream *fs_stream;
734 g_signal_connect (content, "src-pad-added",
735 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
737 g_signal_connect (content, "start-sending",
738 G_CALLBACK (on_tf_content_start_sending_cb), handler);
739 g_signal_connect (content, "stop-sending",
740 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
743 g_object_get (content, "media-type", &mtype,
744 "sink-pad", &spad, NULL);
746 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
747 spad, mtype, &retval);
750 tf_content_error (content, 0 /* FIXME */,
751 "Could not link source", NULL);
753 /* Get sending codec */
754 g_object_get (content, "fs-session", &session, NULL);
755 g_object_get (session, "current-send-codec", &codec, NULL);
757 update_sending_codec (handler, codec, session);
759 tp_clear_object (&session);
760 tp_clear_object (&codec);
762 /* Get receiving codec */
764 g_object_get (content, "fs-stream", &fs_stream, NULL);
765 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
767 update_receiving_codec (handler, codecs, fs_stream);
769 fs_codec_list_destroy (codecs);
770 tp_clear_object (&fs_stream);
773 gst_object_unref (spad);
777 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
779 EmpathyCallHandler *handler)
785 g_print ("removing content\n");
787 g_object_get (content, "media-type", &mtype,
788 "sink-pad", &spad, NULL);
790 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
791 spad, mtype, &retval);
795 g_warning ("Could not remove content!");
797 tf_content_error (content, 0 /* FIXME */,
798 "Could not link source", NULL);
803 on_tf_channel_closed_cb (TfChannel *tfchannel,
804 EmpathyCallHandler *handler)
806 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
810 on_tf_channel_ready (GObject *source,
811 GAsyncResult *result,
814 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
815 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
816 GError *error = NULL;
818 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
819 G_ASYNC_INITABLE (source), result, NULL));
821 if (priv->tfchannel == NULL)
823 g_warning ("Failed to create Farstream channel: %s", error->message);
824 g_error_free (error);
828 /* Set up the telepathy farstream channel */
829 g_signal_connect (priv->tfchannel, "closed",
830 G_CALLBACK (on_tf_channel_closed_cb), self);
831 g_signal_connect (priv->tfchannel, "fs-conference-added",
832 G_CALLBACK (on_tf_channel_conference_added_cb), self);
833 g_signal_connect (priv->tfchannel, "fs-conference-removed",
834 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
835 g_signal_connect (priv->tfchannel, "content-added",
836 G_CALLBACK (on_tf_channel_content_added_cb), self);
837 g_signal_connect (priv->tfchannel, "content-removed",
838 G_CALLBACK (on_tf_channel_content_removed_cb), self);
842 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
844 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
846 tf_channel_new_async (TP_CHANNEL (priv->call),
847 on_tf_channel_ready, self);
852 empathy_call_handler_request_cb (GObject *source,
853 GAsyncResult *result,
856 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
857 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
859 GError *error = NULL;
860 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
862 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
863 result, NULL, &error);
866 DEBUG ("Failed to create the channel: %s", error->message);
867 g_error_free (error);
871 if (!TPY_IS_CALL_CHANNEL (channel))
873 DEBUG ("The channel is not a Call channel!");
877 priv->call = TPY_CALL_CHANNEL (channel);
879 g_object_notify (G_OBJECT (self), "call-channel");
881 empathy_call_handler_start_tpfs (self);
886 on_call_accepted_cb (GObject *source_object,
890 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
891 GError *error = NULL;
893 if (!tpy_call_channel_accept_finish (call, res, &error))
895 g_warning ("could not accept Call: %s", error->message);
896 g_error_free (error);
901 empathy_call_handler_start_call (EmpathyCallHandler *handler,
904 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
905 /*TpAccountChannelRequest *req;
907 GHashTable *request;*/
909 if (priv->call != NULL)
911 empathy_call_handler_start_tpfs (handler);
912 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
917 g_warning ("No Call channel!");
921 /* No TpyCallChannel (we are redialing). Request a new call channel */
922 g_assert (priv->contact != NULL);
924 account = empathy_contact_get_account (priv->contact);
925 request = empathy_call_create_call_request (priv->contact,
926 priv->initial_audio, priv->initial_video);
928 req = tp_account_channel_request_new (account, request, timestamp);
930 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
931 empathy_call_handler_request_cb, handler);
933 g_object_unref (req);
934 g_hash_table_unref (request);
939 * empathy_call_handler_stop_call:
940 * @handler: an #EmpathyCallHandler
942 * Closes the #EmpathyCallHandler's call and frees its resources.
945 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
947 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
949 if (priv->call != NULL)
951 tpy_call_channel_hangup_async (priv->call,
952 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
954 tp_channel_close_async (TP_CHANNEL (priv->call),
956 tp_clear_object (&priv->call);
957 tp_clear_object (&priv->tfchannel);
962 * empathy_call_handler_has_initial_video:
963 * @handler: an #EmpathyCallHandler
965 * Return %TRUE if the call managed by this #EmpathyCallHandler was
966 * created with video enabled
968 * Return value: %TRUE if the call was created as a video conversation.
971 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
973 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
975 return priv->initial_video;
979 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
981 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
983 return priv->send_audio_codec;
987 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
989 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
991 return priv->send_video_codec;
995 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
997 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
999 return priv->recv_audio_codecs;
1003 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1005 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1007 return priv->recv_video_codecs;
1011 empathy_call_handler_get_audio_remote_candidate (
1012 EmpathyCallHandler *self)
1014 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1016 return priv->audio_remote_candidate;
1020 empathy_call_handler_get_audio_local_candidate (
1021 EmpathyCallHandler *self)
1023 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1025 return priv->audio_local_candidate;
1029 empathy_call_handler_get_video_remote_candidate (
1030 EmpathyCallHandler *self)
1032 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1034 return priv->video_remote_candidate;
1038 empathy_call_handler_get_video_local_candidate (
1039 EmpathyCallHandler *self)
1041 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1043 return priv->video_local_candidate;