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
26 #include <telepathy-glib/account-channel-request.h>
27 #include <telepathy-glib/util.h>
28 #include <telepathy-glib/interfaces.h>
30 #include <telepathy-farstream/telepathy-farstream.h>
32 #include <libempathy/empathy-utils.h>
33 #include <libempathy/empathy-tp-contact-factory.h>
35 #include <libempathy-gtk/empathy-call-utils.h>
37 #include "empathy-call-handler.h"
39 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
40 #include <libempathy/empathy-debug.h>
42 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
59 static guint signals[LAST_SIGNAL] = {0};
62 PROP_CALL_CHANNEL = 1,
67 PROP_SEND_AUDIO_CODEC,
68 PROP_SEND_VIDEO_CODEC,
69 PROP_RECV_AUDIO_CODECS,
70 PROP_RECV_VIDEO_CODECS,
71 PROP_AUDIO_REMOTE_CANDIDATE,
72 PROP_VIDEO_REMOTE_CANDIDATE,
73 PROP_AUDIO_LOCAL_CANDIDATE,
74 PROP_VIDEO_LOCAL_CANDIDATE,
77 /* private structure */
79 struct _EmpathyCallHandlerPriv {
82 EmpathyContact *contact;
84 gboolean initial_audio;
85 gboolean initial_video;
87 FsCodec *send_audio_codec;
88 FsCodec *send_video_codec;
89 GList *recv_audio_codecs;
90 GList *recv_video_codecs;
91 FsCandidate *audio_remote_candidate;
92 FsCandidate *video_remote_candidate;
93 FsCandidate *audio_local_candidate;
94 FsCandidate *video_local_candidate;
95 gboolean accept_when_initialised;
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 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
113 empathy_call_handler_finalize (GObject *object)
115 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
117 fs_codec_destroy (priv->send_audio_codec);
118 fs_codec_destroy (priv->send_video_codec);
119 fs_codec_list_destroy (priv->recv_audio_codecs);
120 fs_codec_list_destroy (priv->recv_video_codecs);
121 fs_candidate_destroy (priv->audio_remote_candidate);
122 fs_candidate_destroy (priv->video_remote_candidate);
123 fs_candidate_destroy (priv->audio_local_candidate);
124 fs_candidate_destroy (priv->video_local_candidate);
126 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
130 empathy_call_handler_init (EmpathyCallHandler *obj)
132 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
133 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
139 on_call_accepted_cb (GObject *source_object,
143 TpCallChannel *call = TP_CALL_CHANNEL (source_object);
144 GError *error = NULL;
146 if (!tp_call_channel_accept_finish (call, res, &error))
148 g_warning ("could not accept Call: %s", error->message);
149 g_error_free (error);
154 on_call_invalidated_cb (TpCallChannel *call,
158 EmpathyCallHandler *self)
160 EmpathyCallHandlerPriv *priv = self->priv;
162 if (priv->call == call)
164 /* Invalidated unexpectedly? Fake call ending */
165 g_signal_emit (self, signals[STATE_CHANGED], 0,
166 TP_CALL_STATE_ENDED, NULL);
167 priv->accept_when_initialised = FALSE;
168 tp_clear_object (&priv->call);
169 tp_clear_object (&priv->tfchannel);
174 on_call_state_changed_cb (TpCallChannel *call,
177 TpCallStateReason *reason,
179 EmpathyCallHandler *handler)
181 EmpathyCallHandlerPriv *priv = handler->priv;
183 g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
184 reason->dbus_reason);
186 if (state == TP_CALL_STATE_INITIALISED &&
187 priv->accept_when_initialised)
189 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
190 priv->accept_when_initialised = FALSE;
193 if (state == TP_CALL_STATE_ENDED)
195 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
196 priv->accept_when_initialised = FALSE;
197 tp_clear_object (&priv->call);
198 tp_clear_object (&priv->tfchannel);
203 empathy_call_handler_set_property (GObject *object,
204 guint property_id, const GValue *value, GParamSpec *pspec)
206 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
211 priv->contact = g_value_dup_object (value);
213 case PROP_CALL_CHANNEL:
214 g_return_if_fail (priv->call == NULL);
216 priv->call = g_value_dup_object (value);
218 tp_g_signal_connect_object (priv->call, "state-changed",
219 G_CALLBACK (on_call_state_changed_cb), object, 0);
220 tp_g_signal_connect_object (priv->call, "invalidated",
221 G_CALLBACK (on_call_invalidated_cb), object, 0);
223 case PROP_INITIAL_AUDIO:
224 priv->initial_audio = g_value_get_boolean (value);
226 case PROP_INITIAL_VIDEO:
227 priv->initial_video = g_value_get_boolean (value);
230 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
235 empathy_call_handler_get_property (GObject *object,
236 guint property_id, GValue *value, GParamSpec *pspec)
238 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
243 g_value_set_object (value, priv->contact);
245 case PROP_CALL_CHANNEL:
246 g_value_set_object (value, priv->call);
248 case PROP_INITIAL_AUDIO:
249 g_value_set_boolean (value, priv->initial_audio);
251 case PROP_INITIAL_VIDEO:
252 g_value_set_boolean (value, priv->initial_video);
254 case PROP_SEND_AUDIO_CODEC:
255 g_value_set_boxed (value, priv->send_audio_codec);
257 case PROP_SEND_VIDEO_CODEC:
258 g_value_set_boxed (value, priv->send_video_codec);
260 case PROP_RECV_AUDIO_CODECS:
261 g_value_set_boxed (value, priv->recv_audio_codecs);
263 case PROP_RECV_VIDEO_CODECS:
264 g_value_set_boxed (value, priv->recv_video_codecs);
266 case PROP_AUDIO_REMOTE_CANDIDATE:
267 g_value_set_boxed (value, priv->audio_remote_candidate);
269 case PROP_VIDEO_REMOTE_CANDIDATE:
270 g_value_set_boxed (value, priv->video_remote_candidate);
272 case PROP_AUDIO_LOCAL_CANDIDATE:
273 g_value_set_boxed (value, priv->audio_local_candidate);
275 case PROP_VIDEO_LOCAL_CANDIDATE:
276 g_value_set_boxed (value, priv->video_local_candidate);
279 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
285 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
287 GObjectClass *object_class = G_OBJECT_CLASS (klass);
288 GParamSpec *param_spec;
290 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
292 object_class->set_property = empathy_call_handler_set_property;
293 object_class->get_property = empathy_call_handler_get_property;
294 object_class->dispose = empathy_call_handler_dispose;
295 object_class->finalize = empathy_call_handler_finalize;
297 param_spec = g_param_spec_object ("target-contact",
298 "TargetContact", "The contact",
299 EMPATHY_TYPE_CONTACT,
300 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
301 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
303 param_spec = g_param_spec_object ("call-channel",
304 "call channel", "The call channel",
305 TP_TYPE_CALL_CHANNEL,
306 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
307 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
309 param_spec = g_param_spec_boolean ("initial-audio",
310 "initial-audio", "Whether the call should start with audio",
312 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
313 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
316 param_spec = g_param_spec_boolean ("initial-video",
317 "initial-video", "Whether the call should start with video",
319 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
320 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
323 param_spec = g_param_spec_boxed ("send-audio-codec",
324 "send audio codec", "Codec used to encode the outgoing video stream",
326 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
327 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
330 param_spec = g_param_spec_boxed ("send-video-codec",
331 "send video codec", "Codec used to encode the outgoing video stream",
333 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
334 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
337 param_spec = g_param_spec_boxed ("recv-audio-codecs",
338 "recvs audio codec", "Codecs used to decode the incoming audio stream",
340 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
341 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
344 param_spec = g_param_spec_boxed ("recv-video-codecs",
345 "recvs video codec", "Codecs used to decode the incoming video stream",
347 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
348 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
351 param_spec = g_param_spec_boxed ("audio-remote-candidate",
352 "audio remote candidate",
353 "Remote candidate used for the audio stream",
355 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
356 g_object_class_install_property (object_class,
357 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
359 param_spec = g_param_spec_boxed ("video-remote-candidate",
360 "video remote candidate",
361 "Remote candidate used for the video stream",
363 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
364 g_object_class_install_property (object_class,
365 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
367 param_spec = g_param_spec_boxed ("audio-local-candidate",
368 "audio local candidate",
369 "Local candidate used for the audio stream",
371 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
372 g_object_class_install_property (object_class,
373 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
375 param_spec = g_param_spec_boxed ("video-local-candidate",
376 "video local candidate",
377 "Local candidate used for the video stream",
379 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
380 g_object_class_install_property (object_class,
381 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
383 signals[CONFERENCE_ADDED] =
384 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
385 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
386 g_cclosure_marshal_generic,
388 1, FS_TYPE_CONFERENCE);
390 signals[CONFERENCE_REMOVED] =
391 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
392 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
393 g_cclosure_marshal_generic,
395 1, FS_TYPE_CONFERENCE);
397 signals[SRC_PAD_ADDED] =
398 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
399 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
400 g_cclosure_marshal_generic,
402 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
404 signals[CONTENT_ADDED] =
405 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
406 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
407 g_cclosure_marshal_generic,
411 signals[CONTENT_REMOVED] =
412 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
413 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
414 g_cclosure_marshal_generic,
419 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
420 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
421 g_cclosure_marshal_generic,
425 signals[CANDIDATES_CHANGED] =
426 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
427 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
428 g_cclosure_marshal_generic,
429 G_TYPE_NONE, 1, G_TYPE_UINT);
431 signals[STATE_CHANGED] =
432 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
433 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
434 g_cclosure_marshal_generic,
435 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
437 signals[FRAMERATE_CHANGED] =
438 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
439 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
440 g_cclosure_marshal_generic,
441 G_TYPE_NONE, 1, G_TYPE_UINT);
443 signals[RESOLUTION_CHANGED] =
444 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
445 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
446 g_cclosure_marshal_generic,
448 2, G_TYPE_UINT, G_TYPE_UINT);
452 empathy_call_handler_new_for_channel (TpCallChannel *call,
453 EmpathyContact *contact)
455 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
456 "call-channel", call,
457 "initial-video", tp_call_channel_has_initial_video (call, NULL),
458 "target-contact", contact,
463 update_sending_codec (EmpathyCallHandler *self,
467 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
470 if (codec == NULL || session == NULL)
473 g_object_get (session, "media-type", &type, NULL);
475 if (type == FS_MEDIA_TYPE_AUDIO)
477 priv->send_audio_codec = fs_codec_copy (codec);
478 g_object_notify (G_OBJECT (self), "send-audio-codec");
480 else if (type == FS_MEDIA_TYPE_VIDEO)
482 priv->send_video_codec = fs_codec_copy (codec);
483 g_object_notify (G_OBJECT (self), "send-video-codec");
488 update_receiving_codec (EmpathyCallHandler *self,
492 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
496 if (codecs == NULL || stream == NULL)
499 g_object_get (stream, "session", &session, NULL);
503 g_object_get (session, "media-type", &type, NULL);
505 if (type == FS_MEDIA_TYPE_AUDIO)
507 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
508 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
510 else if (type == FS_MEDIA_TYPE_VIDEO)
512 priv->recv_video_codecs = fs_codec_list_copy (codecs);
513 g_object_notify (G_OBJECT (self), "recv-video-codecs");
516 g_object_unref (session);
520 update_candidates (EmpathyCallHandler *self,
521 FsCandidate *remote_candidate,
522 FsCandidate *local_candidate,
525 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
532 g_object_get (stream, "session", &session, NULL);
536 g_object_get (session, "media-type", &type, NULL);
538 if (type == FS_MEDIA_TYPE_AUDIO)
540 if (remote_candidate != NULL)
542 fs_candidate_destroy (priv->audio_remote_candidate);
543 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
544 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
547 if (local_candidate != NULL)
549 fs_candidate_destroy (priv->audio_local_candidate);
550 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
551 g_object_notify (G_OBJECT (self), "audio-local-candidate");
554 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
555 FS_MEDIA_TYPE_AUDIO);
557 else if (type == FS_MEDIA_TYPE_VIDEO)
559 if (remote_candidate != NULL)
561 fs_candidate_destroy (priv->video_remote_candidate);
562 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
563 g_object_notify (G_OBJECT (self), "video-remote-candidate");
566 if (local_candidate != NULL)
568 fs_candidate_destroy (priv->video_local_candidate);
569 priv->video_local_candidate = fs_candidate_copy (local_candidate);
570 g_object_notify (G_OBJECT (self), "video-local-candidate");
573 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
574 FS_MEDIA_TYPE_VIDEO);
577 g_object_unref (session);
581 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
582 GstBus *bus, GstMessage *message)
584 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
585 const GstStructure *s = gst_message_get_structure (message);
587 if (priv->tfchannel == NULL)
591 gst_structure_has_name (s, "farsight-send-codec-changed"))
597 DEBUG ("farsight-send-codec-changed");
599 val = gst_structure_get_value (s, "codec");
600 codec = g_value_get_boxed (val);
602 val = gst_structure_get_value (s, "session");
603 session = g_value_get_object (val);
605 update_sending_codec (handler, codec, session);
607 else if (s != NULL &&
608 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
614 DEBUG ("farsight-recv-codecs-changed");
616 val = gst_structure_get_value (s, "codecs");
617 codecs = g_value_get_boxed (val);
619 val = gst_structure_get_value (s, "stream");
620 stream = g_value_get_object (val);
622 update_receiving_codec (handler, codecs, stream);
624 else if (s != NULL &&
625 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
628 FsCandidate *remote_candidate, *local_candidate;
631 DEBUG ("farsight-new-active-candidate-pair");
633 val = gst_structure_get_value (s, "remote-candidate");
634 remote_candidate = g_value_get_boxed (val);
636 val = gst_structure_get_value (s, "local-candidate");
637 local_candidate = g_value_get_boxed (val);
639 val = gst_structure_get_value (s, "stream");
640 stream = g_value_get_object (val);
642 update_candidates (handler, remote_candidate, local_candidate, stream);
645 tf_channel_bus_message (priv->tfchannel, message);
649 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
650 GstElement *conference,
651 EmpathyCallHandler *self)
653 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
658 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
659 FsConference *conference,
660 EmpathyCallHandler *self)
662 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
663 GST_ELEMENT (conference));
667 src_pad_added_error_idle (gpointer data)
669 TfContent *content = data;
671 tf_content_error_literal (content, "Could not link sink");
672 g_object_unref (content);
678 on_tf_content_src_pad_added_cb (TfContent *content,
683 EmpathyCallHandler *handler)
687 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
688 content, pad, &retval);
691 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
695 on_tf_content_framerate_changed (TfContent *content,
697 EmpathyCallHandler *handler)
701 g_object_get (content, "framerate", &framerate, NULL);
704 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
709 on_tf_content_resolution_changed (TfContent *content,
712 EmpathyCallHandler *handler)
714 if (width > 0 && height > 0)
715 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
720 on_tf_channel_content_added_cb (TfChannel *tfchannel,
722 EmpathyCallHandler *handler)
726 // FsStream *fs_stream;
731 g_signal_connect (content, "src-pad-added",
732 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
734 g_signal_connect (content, "start-sending",
735 G_CALLBACK (on_tf_content_start_sending_cb), handler);
736 g_signal_connect (content, "stop-sending",
737 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
740 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
744 tf_content_error_literal (content, "Could not link source");
746 /* Get sending codec */
747 g_object_get (content, "fs-session", &session, NULL);
748 g_object_get (session, "current-send-codec", &codec, NULL);
750 update_sending_codec (handler, codec, session);
752 tp_clear_object (&session);
753 tp_clear_object (&codec);
755 /* Get receiving codec */
757 g_object_get (content, "fs-stream", &fs_stream, NULL);
758 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
760 update_receiving_codec (handler, codecs, fs_stream);
762 fs_codec_list_destroy (codecs);
763 tp_clear_object (&fs_stream);
766 g_object_get (content, "media-type", &mtype, NULL);
768 if (mtype == FS_MEDIA_TYPE_VIDEO)
770 guint framerate, width, height;
772 g_signal_connect (content, "notify::framerate",
773 G_CALLBACK (on_tf_content_framerate_changed),
776 g_signal_connect (content, "resolution-changed",
777 G_CALLBACK (on_tf_content_resolution_changed),
780 g_object_get (content,
781 "framerate", &framerate,
787 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
790 if (width > 0 && height > 0)
791 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
797 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
799 EmpathyCallHandler *handler)
803 DEBUG ("removing content");
805 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
810 g_warning ("Could not remove content!");
812 tf_content_error_literal (content, "Could not link source");
817 on_tf_channel_closed_cb (TfChannel *tfchannel,
818 EmpathyCallHandler *handler)
820 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
824 on_tf_channel_ready (GObject *source,
825 GAsyncResult *result,
828 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
829 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
830 GError *error = NULL;
832 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
833 G_ASYNC_INITABLE (source), result, NULL));
835 if (priv->tfchannel == NULL)
837 g_warning ("Failed to create Farstream channel: %s", error->message);
838 g_error_free (error);
842 /* Set up the telepathy farstream channel */
843 g_signal_connect (priv->tfchannel, "closed",
844 G_CALLBACK (on_tf_channel_closed_cb), self);
845 g_signal_connect (priv->tfchannel, "fs-conference-added",
846 G_CALLBACK (on_tf_channel_conference_added_cb), self);
847 g_signal_connect (priv->tfchannel, "fs-conference-removed",
848 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
849 g_signal_connect (priv->tfchannel, "content-added",
850 G_CALLBACK (on_tf_channel_content_added_cb), self);
851 g_signal_connect (priv->tfchannel, "content-removed",
852 G_CALLBACK (on_tf_channel_content_removed_cb), self);
856 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
858 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
860 tf_channel_new_async (TP_CHANNEL (priv->call),
861 on_tf_channel_ready, self);
865 empathy_call_handler_request_cb (GObject *source,
866 GAsyncResult *result,
869 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
870 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
872 GError *error = NULL;
873 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
875 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
876 result, NULL, &error);
879 DEBUG ("Failed to create the channel: %s", error->message);
880 g_error_free (error);
884 if (!TP_IS_CALL_CHANNEL (channel))
886 DEBUG ("The channel is not a Call channel!");
890 priv->call = TP_CALL_CHANNEL (channel);
891 tp_g_signal_connect_object (priv->call, "state-changed",
892 G_CALLBACK (on_call_state_changed_cb), self, 0);
893 tp_g_signal_connect_object (priv->call, "invalidated",
894 G_CALLBACK (on_call_invalidated_cb), self, 0);
896 g_object_notify (G_OBJECT (self), "call-channel");
898 empathy_call_handler_start_tpfs (self);
899 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
903 empathy_call_handler_start_call (EmpathyCallHandler *handler,
906 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
907 TpAccountChannelRequest *req;
911 if (priv->call != NULL)
913 empathy_call_handler_start_tpfs (handler);
915 if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
917 /* accept outgoing channels immediately */
918 tp_call_channel_accept_async (priv->call,
919 on_call_accepted_cb, NULL);
923 /* accepting incoming channels when they are INITIALISED */
924 if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
925 TP_CALL_STATE_INITIALISED)
926 tp_call_channel_accept_async (priv->call,
927 on_call_accepted_cb, NULL);
929 priv->accept_when_initialised = TRUE;
935 /* No TpCallChannel (we are redialing). Request a new call channel */
936 g_assert (priv->contact != NULL);
938 account = empathy_contact_get_account (priv->contact);
939 request = empathy_call_create_call_request (
940 empathy_contact_get_id (priv->contact),
941 priv->initial_audio, priv->initial_video);
943 req = tp_account_channel_request_new (account, request, timestamp);
945 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
946 empathy_call_handler_request_cb, handler);
948 g_object_unref (req);
949 g_hash_table_unref (request);
953 * empathy_call_handler_stop_call:
954 * @handler: an #EmpathyCallHandler
956 * Closes the #EmpathyCallHandler's call and frees its resources.
959 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
961 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
963 if (priv->call != NULL)
965 tp_call_channel_hangup_async (priv->call,
966 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
972 * empathy_call_handler_has_initial_video:
973 * @handler: an #EmpathyCallHandler
975 * Return %TRUE if the call managed by this #EmpathyCallHandler was
976 * created with video enabled
978 * Return value: %TRUE if the call was created as a video conversation.
981 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
983 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
985 return priv->initial_video;
989 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
991 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
993 return priv->send_audio_codec;
997 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
999 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1001 return priv->send_video_codec;
1005 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1007 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1009 return priv->recv_audio_codecs;
1013 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1015 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1017 return priv->recv_video_codecs;
1021 empathy_call_handler_get_audio_remote_candidate (
1022 EmpathyCallHandler *self)
1024 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1026 return priv->audio_remote_candidate;
1030 empathy_call_handler_get_audio_local_candidate (
1031 EmpathyCallHandler *self)
1033 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1035 return priv->audio_local_candidate;
1039 empathy_call_handler_get_video_remote_candidate (
1040 EmpathyCallHandler *self)
1042 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1044 return priv->video_remote_candidate;
1048 empathy_call_handler_get_video_local_candidate (
1049 EmpathyCallHandler *self)
1051 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1053 return priv->video_local_candidate;
1057 empathy_call_handler_get_contact (EmpathyCallHandler *self)
1059 return self->priv->contact;