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);
154 g_print ("\nGot %d EmpathyContacts\n\n", n_contacts);
157 g_warning ("Failed to get %d EmpathyContacts: %s",
158 n_failed, error->message);
160 priv->members = g_array_sized_new (FALSE, TRUE,
161 sizeof (EmpathyContact *), n_contacts);
163 for (i = 0; i < n_contacts; i++)
164 g_object_ref (contacts[i]);
166 g_array_append_vals (priv->members, contacts, n_contacts);
168 g_object_notify (G_OBJECT (self), "members");
172 on_members_changed_cb (TpyCallChannel *call,
174 EmpathyCallHandler *self)
176 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
183 g_print ("\non_members_changed!\n\n");
187 g_print ("\nmembers is null!\n\n");
191 n_handles = g_hash_table_size (members);
192 g_print ("\nn_handles: %d\n\n", n_handles);
196 handles = g_new0 (TpHandle, n_handles);
198 g_hash_table_iter_init (&iter, members);
199 while (g_hash_table_iter_next (&iter, &key, &value))
200 handles[i++] = GPOINTER_TO_UINT (key);
202 empathy_tp_contact_factory_get_from_handles (
203 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
206 NULL, NULL, G_OBJECT (self));
212 empathy_call_handler_constructed (GObject *object)
214 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
215 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
216 // GHashTable *members;
218 g_signal_connect (priv->call, "members-changed",
219 G_CALLBACK (on_members_changed_cb), object);
222 g_object_get (priv->call, "members", &members, NULL);
225 on_members_changed_cb (priv->call, members, self);
230 empathy_call_handler_set_property (GObject *object,
231 guint property_id, const GValue *value, GParamSpec *pspec)
233 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
238 priv->contact = g_value_dup_object (value);
241 priv->members = g_value_get_boxed (value);
243 case PROP_CALL_CHANNEL:
244 priv->call = g_value_dup_object (value);
246 case PROP_INITIAL_AUDIO:
247 priv->initial_audio = g_value_get_boolean (value);
249 case PROP_INITIAL_VIDEO:
250 priv->initial_video = g_value_get_boolean (value);
253 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
258 empathy_call_handler_get_property (GObject *object,
259 guint property_id, GValue *value, GParamSpec *pspec)
261 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
266 g_value_set_object (value, priv->contact);
269 g_value_set_boxed (value, priv->members);
271 case PROP_CALL_CHANNEL:
272 g_value_set_object (value, priv->call);
274 case PROP_INITIAL_AUDIO:
275 g_value_set_boolean (value, priv->initial_audio);
277 case PROP_INITIAL_VIDEO:
278 g_value_set_boolean (value, priv->initial_video);
280 case PROP_SEND_AUDIO_CODEC:
281 g_value_set_boxed (value, priv->send_audio_codec);
283 case PROP_SEND_VIDEO_CODEC:
284 g_value_set_boxed (value, priv->send_video_codec);
286 case PROP_RECV_AUDIO_CODECS:
287 g_value_set_boxed (value, priv->recv_audio_codecs);
289 case PROP_RECV_VIDEO_CODECS:
290 g_value_set_boxed (value, priv->recv_video_codecs);
292 case PROP_AUDIO_REMOTE_CANDIDATE:
293 g_value_set_boxed (value, priv->audio_remote_candidate);
295 case PROP_VIDEO_REMOTE_CANDIDATE:
296 g_value_set_boxed (value, priv->video_remote_candidate);
298 case PROP_AUDIO_LOCAL_CANDIDATE:
299 g_value_set_boxed (value, priv->audio_local_candidate);
301 case PROP_VIDEO_LOCAL_CANDIDATE:
302 g_value_set_boxed (value, priv->video_local_candidate);
305 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
311 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
313 GObjectClass *object_class = G_OBJECT_CLASS (klass);
314 GParamSpec *param_spec;
316 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
318 object_class->constructed = empathy_call_handler_constructed;
319 object_class->set_property = empathy_call_handler_set_property;
320 object_class->get_property = empathy_call_handler_get_property;
321 object_class->dispose = empathy_call_handler_dispose;
322 object_class->finalize = empathy_call_handler_finalize;
324 param_spec = g_param_spec_object ("target-contact",
325 "TargetContact", "The contact",
326 EMPATHY_TYPE_CONTACT,
327 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
328 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
330 param_spec = g_param_spec_boxed ("members",
331 "call members", "The call participants",
333 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
334 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
336 param_spec = g_param_spec_object ("call-channel",
337 "call channel", "The call channel",
338 TPY_TYPE_CALL_CHANNEL,
339 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
340 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
342 param_spec = g_param_spec_boolean ("initial-audio",
343 "initial-audio", "Whether the call should start with audio",
345 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
346 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
349 param_spec = g_param_spec_boolean ("initial-video",
350 "initial-video", "Whether the call should start with video",
352 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
353 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
356 param_spec = g_param_spec_boxed ("send-audio-codec",
357 "send audio codec", "Codec used to encode the outgoing video stream",
359 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
360 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
363 param_spec = g_param_spec_boxed ("send-video-codec",
364 "send video codec", "Codec used to encode the outgoing video stream",
366 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
367 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
370 param_spec = g_param_spec_boxed ("recv-audio-codecs",
371 "recvs audio codec", "Codecs used to decode the incoming audio stream",
373 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
374 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
377 param_spec = g_param_spec_boxed ("recv-video-codecs",
378 "recvs video codec", "Codecs used to decode the incoming video stream",
380 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
381 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
384 param_spec = g_param_spec_boxed ("audio-remote-candidate",
385 "audio remote candidate",
386 "Remote candidate used for the audio stream",
388 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
389 g_object_class_install_property (object_class,
390 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
392 param_spec = g_param_spec_boxed ("video-remote-candidate",
393 "video remote candidate",
394 "Remote candidate used for the video stream",
396 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
397 g_object_class_install_property (object_class,
398 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
400 param_spec = g_param_spec_boxed ("audio-local-candidate",
401 "audio local candidate",
402 "Local candidate used for the audio stream",
404 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
405 g_object_class_install_property (object_class,
406 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
408 param_spec = g_param_spec_boxed ("video-local-candidate",
409 "video local candidate",
410 "Local candidate used for the video stream",
412 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
413 g_object_class_install_property (object_class,
414 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
416 signals[CONFERENCE_ADDED] =
417 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
418 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
419 g_cclosure_marshal_VOID__OBJECT,
421 1, FS_TYPE_CONFERENCE);
423 signals[CONFERENCE_REMOVED] =
424 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
425 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
426 g_cclosure_marshal_VOID__OBJECT,
428 1, FS_TYPE_CONFERENCE);
430 signals[SRC_PAD_ADDED] =
431 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
432 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
433 _src_marshal_BOOLEAN__OBJECT_UINT,
435 2, GST_TYPE_PAD, G_TYPE_UINT);
437 signals[SINK_PAD_ADDED] =
438 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
439 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
440 _src_marshal_BOOLEAN__OBJECT_UINT,
442 2, GST_TYPE_PAD, G_TYPE_UINT);
444 signals[SINK_PAD_REMOVED] =
445 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
446 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
447 _src_marshal_BOOLEAN__OBJECT_UINT,
449 2, GST_TYPE_PAD, G_TYPE_UINT);
452 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
453 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
454 g_cclosure_marshal_VOID__VOID,
458 signals[CANDIDATES_CHANGED] =
459 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
460 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
461 g_cclosure_marshal_VOID__UINT,
462 G_TYPE_NONE, 1, G_TYPE_UINT);
466 empathy_call_handler_new_for_channel (TpyCallChannel *call,
467 EmpathyContact *contact)
469 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
470 "call-channel", call,
471 "initial-video", tpy_call_channel_has_initial_video (call),
472 "target-contact", contact,
477 update_sending_codec (EmpathyCallHandler *self,
481 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
484 if (codec == NULL || session == NULL)
487 g_object_get (session, "media-type", &type, NULL);
489 if (type == FS_MEDIA_TYPE_AUDIO)
491 priv->send_audio_codec = fs_codec_copy (codec);
492 g_object_notify (G_OBJECT (self), "send-audio-codec");
494 else if (type == FS_MEDIA_TYPE_VIDEO)
496 priv->send_video_codec = fs_codec_copy (codec);
497 g_object_notify (G_OBJECT (self), "send-video-codec");
502 update_receiving_codec (EmpathyCallHandler *self,
506 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
510 if (codecs == NULL || stream == NULL)
513 g_object_get (stream, "session", &session, NULL);
517 g_object_get (session, "media-type", &type, NULL);
519 if (type == FS_MEDIA_TYPE_AUDIO)
521 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
522 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
524 else if (type == FS_MEDIA_TYPE_VIDEO)
526 priv->recv_video_codecs = fs_codec_list_copy (codecs);
527 g_object_notify (G_OBJECT (self), "recv-video-codecs");
530 g_object_unref (session);
534 update_candidates (EmpathyCallHandler *self,
535 FsCandidate *remote_candidate,
536 FsCandidate *local_candidate,
539 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
546 g_object_get (stream, "session", &session, NULL);
550 g_object_get (session, "media-type", &type, NULL);
552 if (type == FS_MEDIA_TYPE_AUDIO)
554 if (remote_candidate != NULL)
556 fs_candidate_destroy (priv->audio_remote_candidate);
557 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
558 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
561 if (local_candidate != NULL)
563 fs_candidate_destroy (priv->audio_local_candidate);
564 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
565 g_object_notify (G_OBJECT (self), "audio-local-candidate");
568 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
569 FS_MEDIA_TYPE_AUDIO);
571 else if (type == FS_MEDIA_TYPE_VIDEO)
573 if (remote_candidate != NULL)
575 fs_candidate_destroy (priv->video_remote_candidate);
576 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
577 g_object_notify (G_OBJECT (self), "video-remote-candidate");
580 if (local_candidate != NULL)
582 fs_candidate_destroy (priv->video_local_candidate);
583 priv->video_local_candidate = fs_candidate_copy (local_candidate);
584 g_object_notify (G_OBJECT (self), "video-local-candidate");
587 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
588 FS_MEDIA_TYPE_VIDEO);
591 g_object_unref (session);
595 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
596 GstBus *bus, GstMessage *message)
598 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
599 const GstStructure *s = gst_message_get_structure (message);
601 if (priv->tfchannel == NULL)
605 gst_structure_has_name (s, "farsight-send-codec-changed"))
611 g_print ("empathy_call_handler_bus_message: farsight-send-codec-changed\n");
613 val = gst_structure_get_value (s, "codec");
614 codec = g_value_get_boxed (val);
616 val = gst_structure_get_value (s, "session");
617 session = g_value_get_object (val);
619 update_sending_codec (handler, codec, session);
621 else if (s != NULL &&
622 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
628 g_print ("empathy_call_handler_bus_message: farsight-recv-codecs-changed\n");
630 val = gst_structure_get_value (s, "codecs");
631 codecs = g_value_get_boxed (val);
633 val = gst_structure_get_value (s, "stream");
634 stream = g_value_get_object (val);
636 update_receiving_codec (handler, codecs, stream);
638 else if (s != NULL &&
639 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
642 FsCandidate *remote_candidate, *local_candidate;
645 g_print ("empathy_call_handler_bus_message: farsight-new-active-candidate-pair\n");
647 val = gst_structure_get_value (s, "remote-candidate");
648 remote_candidate = g_value_get_boxed (val);
650 val = gst_structure_get_value (s, "local-candidate");
651 local_candidate = g_value_get_boxed (val);
653 val = gst_structure_get_value (s, "stream");
654 stream = g_value_get_object (val);
656 update_candidates (handler, remote_candidate, local_candidate, stream);
659 tf_channel_bus_message (priv->tfchannel, message);
663 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
664 GstElement *conference,
665 EmpathyCallHandler *self)
667 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
672 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
673 FsConference *conference,
674 EmpathyCallHandler *self)
676 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
677 GST_ELEMENT (conference));
681 src_pad_added_error_idle (gpointer data)
683 TfContent *content = data;
685 tf_content_error (content, 0 /* FIXME */,
686 "Could not link sink", NULL);
687 g_object_unref (content);
693 on_tf_content_src_pad_added_cb (TfContent *content,
698 EmpathyCallHandler *handler)
703 g_object_get (content, "media-type", &media_type, NULL);
705 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
706 pad, media_type, &retval);
709 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
713 on_tf_channel_content_added_cb (TfChannel *tfchannel,
715 EmpathyCallHandler *handler)
720 // FsStream *fs_stream;
725 g_signal_connect (content, "src-pad-added",
726 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
728 g_signal_connect (content, "start-sending",
729 G_CALLBACK (on_tf_content_start_sending_cb), handler);
730 g_signal_connect (content, "stop-sending",
731 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
734 g_object_get (content, "media-type", &mtype,
735 "sink-pad", &spad, NULL);
737 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
738 spad, mtype, &retval);
741 tf_content_error (content, 0 /* FIXME */,
742 "Could not link source", NULL);
744 /* Get sending codec */
745 g_object_get (content, "fs-session", &session, NULL);
746 g_object_get (session, "current-send-codec", &codec, NULL);
748 update_sending_codec (handler, codec, session);
750 tp_clear_object (&session);
751 tp_clear_object (&codec);
753 /* Get receiving codec */
755 g_object_get (content, "fs-stream", &fs_stream, NULL);
756 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
758 update_receiving_codec (handler, codecs, fs_stream);
760 fs_codec_list_destroy (codecs);
761 tp_clear_object (&fs_stream);
764 gst_object_unref (spad);
768 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
770 EmpathyCallHandler *handler)
776 g_print ("removing content\n");
778 g_object_get (content, "media-type", &mtype,
779 "sink-pad", &spad, NULL);
781 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
782 spad, mtype, &retval);
786 g_warning ("Could not remove content!");
788 tf_content_error (content, 0 /* FIXME */,
789 "Could not link source", NULL);
794 on_tf_channel_closed_cb (TfChannel *tfchannel,
795 EmpathyCallHandler *handler)
797 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
801 on_tf_channel_ready (GObject *source,
802 GAsyncResult *result,
805 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
806 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
807 GError *error = NULL;
809 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
810 G_ASYNC_INITABLE (source), result, NULL));
812 if (priv->tfchannel == NULL)
814 g_warning ("Failed to create Farstream channel: %s", error->message);
815 g_error_free (error);
819 /* Set up the telepathy farstream channel */
820 g_signal_connect (priv->tfchannel, "closed",
821 G_CALLBACK (on_tf_channel_closed_cb), self);
822 g_signal_connect (priv->tfchannel, "fs-conference-added",
823 G_CALLBACK (on_tf_channel_conference_added_cb), self);
824 g_signal_connect (priv->tfchannel, "fs-conference-removed",
825 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
826 g_signal_connect (priv->tfchannel, "content-added",
827 G_CALLBACK (on_tf_channel_content_added_cb), self);
828 g_signal_connect (priv->tfchannel, "content-removed",
829 G_CALLBACK (on_tf_channel_content_removed_cb), self);
833 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
835 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
837 tf_channel_new_async (TP_CHANNEL (priv->call),
838 on_tf_channel_ready, self);
843 empathy_call_handler_request_cb (GObject *source,
844 GAsyncResult *result,
847 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
848 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
850 GError *error = NULL;
851 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
853 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
854 result, NULL, &error);
857 DEBUG ("Failed to create the channel: %s", error->message);
858 g_error_free (error);
862 if (!TPY_IS_CALL_CHANNEL (channel))
864 DEBUG ("The channel is not a Call channel!");
868 priv->call = TPY_CALL_CHANNEL (channel);
870 g_object_notify (G_OBJECT (self), "call-channel");
872 empathy_call_handler_start_tpfs (self);
877 on_call_accepted_cb (GObject *source_object,
881 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
882 GError *error = NULL;
884 if (!tpy_call_channel_accept_finish (call, res, &error))
886 g_warning ("could not accept Call: %s", error->message);
887 g_error_free (error);
892 empathy_call_handler_start_call (EmpathyCallHandler *handler,
895 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
896 /*TpAccountChannelRequest *req;
898 GHashTable *request;*/
900 if (priv->call != NULL)
902 empathy_call_handler_start_tpfs (handler);
903 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
908 g_warning ("No Call channel!");
912 /* No TpyCallChannel (we are redialing). Request a new call channel */
913 g_assert (priv->contact != NULL);
915 account = empathy_contact_get_account (priv->contact);
916 request = empathy_call_create_call_request (priv->contact,
917 priv->initial_audio, priv->initial_video);
919 req = tp_account_channel_request_new (account, request, timestamp);
921 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
922 empathy_call_handler_request_cb, handler);
924 g_object_unref (req);
925 g_hash_table_unref (request);
930 * empathy_call_handler_stop_call:
931 * @handler: an #EmpathyCallHandler
933 * Closes the #EmpathyCallHandler's call and frees its resources.
936 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
938 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
940 if (priv->call != NULL)
942 tpy_call_channel_hangup_async (priv->call,
943 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
945 tp_channel_close_async (TP_CHANNEL (priv->call),
947 tp_clear_object (&priv->call);
948 tp_clear_object (&priv->tfchannel);
953 * empathy_call_handler_has_initial_video:
954 * @handler: an #EmpathyCallHandler
956 * Return %TRUE if the call managed by this #EmpathyCallHandler was
957 * created with video enabled
959 * Return value: %TRUE if the call was created as a video conversation.
962 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
964 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
966 return priv->initial_video;
970 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
972 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
974 return priv->send_audio_codec;
978 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
980 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
982 return priv->send_video_codec;
986 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
988 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
990 return priv->recv_audio_codecs;
994 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
996 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
998 return priv->recv_video_codecs;
1002 empathy_call_handler_get_audio_remote_candidate (
1003 EmpathyCallHandler *self)
1005 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1007 return priv->audio_remote_candidate;
1011 empathy_call_handler_get_audio_local_candidate (
1012 EmpathyCallHandler *self)
1014 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1016 return priv->audio_local_candidate;
1020 empathy_call_handler_get_video_remote_candidate (
1021 EmpathyCallHandler *self)
1023 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1025 return priv->video_remote_candidate;
1029 empathy_call_handler_get_video_local_candidate (
1030 EmpathyCallHandler *self)
1032 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1034 return priv->video_local_candidate;