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-farstream/telepathy-farstream.h>
31 #include <libempathy/empathy-utils.h>
32 #include <libempathy/empathy-tp-contact-factory.h>
34 #include <libempathy-gtk/empathy-call-utils.h>
36 #include "empathy-call-handler.h"
38 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
39 #include <libempathy/empathy-debug.h>
41 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
58 static guint signals[LAST_SIGNAL] = {0};
61 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 */
78 struct _EmpathyCallHandlerPriv {
81 EmpathyContact *contact;
83 gboolean initial_audio;
84 gboolean initial_video;
86 FsCodec *send_audio_codec;
87 FsCodec *send_video_codec;
88 GList *recv_audio_codecs;
89 GList *recv_video_codecs;
90 FsCandidate *audio_remote_candidate;
91 FsCandidate *video_remote_candidate;
92 FsCandidate *audio_local_candidate;
93 FsCandidate *video_local_candidate;
96 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
99 empathy_call_handler_dispose (GObject *object)
101 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
103 tp_clear_object (&priv->tfchannel);
104 tp_clear_object (&priv->call);
105 tp_clear_object (&priv->contact);
107 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
111 empathy_call_handler_finalize (GObject *object)
113 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
115 fs_codec_destroy (priv->send_audio_codec);
116 fs_codec_destroy (priv->send_video_codec);
117 fs_codec_list_destroy (priv->recv_audio_codecs);
118 fs_codec_list_destroy (priv->recv_video_codecs);
119 fs_candidate_destroy (priv->audio_remote_candidate);
120 fs_candidate_destroy (priv->video_remote_candidate);
121 fs_candidate_destroy (priv->audio_local_candidate);
122 fs_candidate_destroy (priv->video_local_candidate);
124 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
128 empathy_call_handler_init (EmpathyCallHandler *obj)
130 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
131 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
137 on_call_invalidated_cb (TpCallChannel *call,
141 EmpathyCallHandler *self)
143 EmpathyCallHandlerPriv *priv = self->priv;
145 if (priv->call == call)
147 /* Invalidated unexpectedly? Fake call ending */
148 g_signal_emit (self, signals[STATE_CHANGED], 0,
149 TP_CALL_STATE_ENDED, NULL);
150 tp_clear_object (&priv->call);
151 tp_clear_object (&priv->tfchannel);
156 on_call_state_changed_cb (TpCallChannel *call,
159 TpCallStateReason *reason,
161 EmpathyCallHandler *handler)
163 EmpathyCallHandlerPriv *priv = handler->priv;
165 g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
166 reason->dbus_reason);
168 if (state == TP_CALL_STATE_ENDED)
170 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
172 tp_clear_object (&priv->call);
173 tp_clear_object (&priv->tfchannel);
178 empathy_call_handler_set_property (GObject *object,
179 guint property_id, const GValue *value, GParamSpec *pspec)
181 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
186 priv->contact = g_value_dup_object (value);
188 case PROP_CALL_CHANNEL:
189 g_return_if_fail (priv->call == NULL);
191 priv->call = g_value_dup_object (value);
193 tp_g_signal_connect_object (priv->call, "state-changed",
194 G_CALLBACK (on_call_state_changed_cb), object, 0);
195 tp_g_signal_connect_object (priv->call, "invalidated",
196 G_CALLBACK (on_call_invalidated_cb), object, 0);
198 case PROP_INITIAL_AUDIO:
199 priv->initial_audio = g_value_get_boolean (value);
201 case PROP_INITIAL_VIDEO:
202 priv->initial_video = g_value_get_boolean (value);
205 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
210 empathy_call_handler_get_property (GObject *object,
211 guint property_id, GValue *value, GParamSpec *pspec)
213 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
218 g_value_set_object (value, priv->contact);
220 case PROP_CALL_CHANNEL:
221 g_value_set_object (value, priv->call);
223 case PROP_INITIAL_AUDIO:
224 g_value_set_boolean (value, priv->initial_audio);
226 case PROP_INITIAL_VIDEO:
227 g_value_set_boolean (value, priv->initial_video);
229 case PROP_SEND_AUDIO_CODEC:
230 g_value_set_boxed (value, priv->send_audio_codec);
232 case PROP_SEND_VIDEO_CODEC:
233 g_value_set_boxed (value, priv->send_video_codec);
235 case PROP_RECV_AUDIO_CODECS:
236 g_value_set_boxed (value, priv->recv_audio_codecs);
238 case PROP_RECV_VIDEO_CODECS:
239 g_value_set_boxed (value, priv->recv_video_codecs);
241 case PROP_AUDIO_REMOTE_CANDIDATE:
242 g_value_set_boxed (value, priv->audio_remote_candidate);
244 case PROP_VIDEO_REMOTE_CANDIDATE:
245 g_value_set_boxed (value, priv->video_remote_candidate);
247 case PROP_AUDIO_LOCAL_CANDIDATE:
248 g_value_set_boxed (value, priv->audio_local_candidate);
250 case PROP_VIDEO_LOCAL_CANDIDATE:
251 g_value_set_boxed (value, priv->video_local_candidate);
254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
260 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
262 GObjectClass *object_class = G_OBJECT_CLASS (klass);
263 GParamSpec *param_spec;
265 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
267 object_class->set_property = empathy_call_handler_set_property;
268 object_class->get_property = empathy_call_handler_get_property;
269 object_class->dispose = empathy_call_handler_dispose;
270 object_class->finalize = empathy_call_handler_finalize;
272 param_spec = g_param_spec_object ("target-contact",
273 "TargetContact", "The contact",
274 EMPATHY_TYPE_CONTACT,
275 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
276 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
278 param_spec = g_param_spec_object ("call-channel",
279 "call channel", "The call channel",
280 TP_TYPE_CALL_CHANNEL,
281 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
282 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
284 param_spec = g_param_spec_boolean ("initial-audio",
285 "initial-audio", "Whether the call should start with audio",
287 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
288 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
291 param_spec = g_param_spec_boolean ("initial-video",
292 "initial-video", "Whether the call should start with video",
294 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
295 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
298 param_spec = g_param_spec_boxed ("send-audio-codec",
299 "send audio codec", "Codec used to encode the outgoing video stream",
301 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
302 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
305 param_spec = g_param_spec_boxed ("send-video-codec",
306 "send video codec", "Codec used to encode the outgoing video stream",
308 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
309 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
312 param_spec = g_param_spec_boxed ("recv-audio-codecs",
313 "recvs audio codec", "Codecs used to decode the incoming audio stream",
315 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
316 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
319 param_spec = g_param_spec_boxed ("recv-video-codecs",
320 "recvs video codec", "Codecs used to decode the incoming video stream",
322 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
323 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
326 param_spec = g_param_spec_boxed ("audio-remote-candidate",
327 "audio remote candidate",
328 "Remote candidate used for the audio stream",
330 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
331 g_object_class_install_property (object_class,
332 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
334 param_spec = g_param_spec_boxed ("video-remote-candidate",
335 "video remote candidate",
336 "Remote candidate used for the video stream",
338 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
339 g_object_class_install_property (object_class,
340 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
342 param_spec = g_param_spec_boxed ("audio-local-candidate",
343 "audio local candidate",
344 "Local candidate used for the audio stream",
346 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
347 g_object_class_install_property (object_class,
348 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
350 param_spec = g_param_spec_boxed ("video-local-candidate",
351 "video local candidate",
352 "Local candidate used for the video stream",
354 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
355 g_object_class_install_property (object_class,
356 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
358 signals[CONFERENCE_ADDED] =
359 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
360 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
361 g_cclosure_marshal_generic,
363 1, FS_TYPE_CONFERENCE);
365 signals[CONFERENCE_REMOVED] =
366 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
367 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
368 g_cclosure_marshal_generic,
370 1, FS_TYPE_CONFERENCE);
372 signals[SRC_PAD_ADDED] =
373 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
374 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
375 g_cclosure_marshal_generic,
377 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
379 signals[CONTENT_ADDED] =
380 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
381 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
382 g_cclosure_marshal_generic,
386 signals[CONTENT_REMOVED] =
387 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
388 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
389 g_cclosure_marshal_generic,
394 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
395 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
396 g_cclosure_marshal_generic,
400 signals[CANDIDATES_CHANGED] =
401 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
402 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
403 g_cclosure_marshal_generic,
404 G_TYPE_NONE, 1, G_TYPE_UINT);
406 signals[STATE_CHANGED] =
407 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
408 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
409 g_cclosure_marshal_generic,
410 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
412 signals[FRAMERATE_CHANGED] =
413 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
414 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
415 g_cclosure_marshal_generic,
416 G_TYPE_NONE, 1, G_TYPE_UINT);
418 signals[RESOLUTION_CHANGED] =
419 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
420 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
421 g_cclosure_marshal_generic,
423 2, G_TYPE_UINT, G_TYPE_UINT);
427 empathy_call_handler_new_for_channel (TpCallChannel *call,
428 EmpathyContact *contact)
430 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
431 "call-channel", call,
432 "initial-video", tp_call_channel_has_initial_video (call, NULL),
433 "target-contact", contact,
438 update_sending_codec (EmpathyCallHandler *self,
442 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
445 if (codec == NULL || session == NULL)
448 g_object_get (session, "media-type", &type, NULL);
450 if (type == FS_MEDIA_TYPE_AUDIO)
452 priv->send_audio_codec = fs_codec_copy (codec);
453 g_object_notify (G_OBJECT (self), "send-audio-codec");
455 else if (type == FS_MEDIA_TYPE_VIDEO)
457 priv->send_video_codec = fs_codec_copy (codec);
458 g_object_notify (G_OBJECT (self), "send-video-codec");
463 update_receiving_codec (EmpathyCallHandler *self,
467 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
471 if (codecs == NULL || stream == NULL)
474 g_object_get (stream, "session", &session, NULL);
478 g_object_get (session, "media-type", &type, NULL);
480 if (type == FS_MEDIA_TYPE_AUDIO)
482 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
483 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
485 else if (type == FS_MEDIA_TYPE_VIDEO)
487 priv->recv_video_codecs = fs_codec_list_copy (codecs);
488 g_object_notify (G_OBJECT (self), "recv-video-codecs");
491 g_object_unref (session);
495 update_candidates (EmpathyCallHandler *self,
496 FsCandidate *remote_candidate,
497 FsCandidate *local_candidate,
500 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
507 g_object_get (stream, "session", &session, NULL);
511 g_object_get (session, "media-type", &type, NULL);
513 if (type == FS_MEDIA_TYPE_AUDIO)
515 if (remote_candidate != NULL)
517 fs_candidate_destroy (priv->audio_remote_candidate);
518 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
519 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
522 if (local_candidate != NULL)
524 fs_candidate_destroy (priv->audio_local_candidate);
525 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
526 g_object_notify (G_OBJECT (self), "audio-local-candidate");
529 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
530 FS_MEDIA_TYPE_AUDIO);
532 else if (type == FS_MEDIA_TYPE_VIDEO)
534 if (remote_candidate != NULL)
536 fs_candidate_destroy (priv->video_remote_candidate);
537 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
538 g_object_notify (G_OBJECT (self), "video-remote-candidate");
541 if (local_candidate != NULL)
543 fs_candidate_destroy (priv->video_local_candidate);
544 priv->video_local_candidate = fs_candidate_copy (local_candidate);
545 g_object_notify (G_OBJECT (self), "video-local-candidate");
548 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
549 FS_MEDIA_TYPE_VIDEO);
552 g_object_unref (session);
556 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
557 GstBus *bus, GstMessage *message)
559 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
560 const GstStructure *s = gst_message_get_structure (message);
562 if (priv->tfchannel == NULL)
566 gst_structure_has_name (s, "farsight-send-codec-changed"))
572 DEBUG ("farsight-send-codec-changed");
574 val = gst_structure_get_value (s, "codec");
575 codec = g_value_get_boxed (val);
577 val = gst_structure_get_value (s, "session");
578 session = g_value_get_object (val);
580 update_sending_codec (handler, codec, session);
582 else if (s != NULL &&
583 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
589 DEBUG ("farsight-recv-codecs-changed");
591 val = gst_structure_get_value (s, "codecs");
592 codecs = g_value_get_boxed (val);
594 val = gst_structure_get_value (s, "stream");
595 stream = g_value_get_object (val);
597 update_receiving_codec (handler, codecs, stream);
599 else if (s != NULL &&
600 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
603 FsCandidate *remote_candidate, *local_candidate;
606 DEBUG ("farsight-new-active-candidate-pair");
608 val = gst_structure_get_value (s, "remote-candidate");
609 remote_candidate = g_value_get_boxed (val);
611 val = gst_structure_get_value (s, "local-candidate");
612 local_candidate = g_value_get_boxed (val);
614 val = gst_structure_get_value (s, "stream");
615 stream = g_value_get_object (val);
617 update_candidates (handler, remote_candidate, local_candidate, stream);
620 tf_channel_bus_message (priv->tfchannel, message);
624 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
625 GstElement *conference,
626 EmpathyCallHandler *self)
628 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
633 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
634 FsConference *conference,
635 EmpathyCallHandler *self)
637 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
638 GST_ELEMENT (conference));
642 src_pad_added_error_idle (gpointer data)
644 TfContent *content = data;
646 tf_content_error_literal (content, "Could not link sink");
647 g_object_unref (content);
653 on_tf_content_src_pad_added_cb (TfContent *content,
658 EmpathyCallHandler *handler)
662 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
663 content, pad, &retval);
666 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
670 on_tf_content_framerate_changed (TfContent *content,
672 EmpathyCallHandler *handler)
676 g_object_get (content, "framerate", &framerate, NULL);
679 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
684 on_tf_content_resolution_changed (TfContent *content,
687 EmpathyCallHandler *handler)
689 if (width > 0 && height > 0)
690 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
695 on_tf_channel_content_added_cb (TfChannel *tfchannel,
697 EmpathyCallHandler *handler)
701 // FsStream *fs_stream;
706 g_signal_connect (content, "src-pad-added",
707 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
709 g_signal_connect (content, "start-sending",
710 G_CALLBACK (on_tf_content_start_sending_cb), handler);
711 g_signal_connect (content, "stop-sending",
712 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
715 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
719 tf_content_error_literal (content, "Could not link source");
721 /* Get sending codec */
722 g_object_get (content, "fs-session", &session, NULL);
723 g_object_get (session, "current-send-codec", &codec, NULL);
725 update_sending_codec (handler, codec, session);
727 tp_clear_object (&session);
728 tp_clear_object (&codec);
730 /* Get receiving codec */
732 g_object_get (content, "fs-stream", &fs_stream, NULL);
733 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
735 update_receiving_codec (handler, codecs, fs_stream);
737 fs_codec_list_destroy (codecs);
738 tp_clear_object (&fs_stream);
741 g_object_get (content, "media-type", &mtype, NULL);
743 if (mtype == FS_MEDIA_TYPE_VIDEO)
745 guint framerate, width, height;
747 g_signal_connect (content, "notify::framerate",
748 G_CALLBACK (on_tf_content_framerate_changed),
751 g_signal_connect (content, "resolution-changed",
752 G_CALLBACK (on_tf_content_resolution_changed),
755 g_object_get (content,
756 "framerate", &framerate,
762 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
765 if (width > 0 && height > 0)
766 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
772 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
774 EmpathyCallHandler *handler)
778 DEBUG ("removing content");
780 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
785 g_warning ("Could not remove content!");
787 tf_content_error_literal (content, "Could not link source");
792 on_tf_channel_closed_cb (TfChannel *tfchannel,
793 EmpathyCallHandler *handler)
795 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
799 on_tf_channel_ready (GObject *source,
800 GAsyncResult *result,
803 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
804 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
805 GError *error = NULL;
807 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
808 G_ASYNC_INITABLE (source), result, NULL));
810 if (priv->tfchannel == NULL)
812 g_warning ("Failed to create Farstream channel: %s", error->message);
813 g_error_free (error);
817 /* Set up the telepathy farstream channel */
818 g_signal_connect (priv->tfchannel, "closed",
819 G_CALLBACK (on_tf_channel_closed_cb), self);
820 g_signal_connect (priv->tfchannel, "fs-conference-added",
821 G_CALLBACK (on_tf_channel_conference_added_cb), self);
822 g_signal_connect (priv->tfchannel, "fs-conference-removed",
823 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
824 g_signal_connect (priv->tfchannel, "content-added",
825 G_CALLBACK (on_tf_channel_content_added_cb), self);
826 g_signal_connect (priv->tfchannel, "content-removed",
827 G_CALLBACK (on_tf_channel_content_removed_cb), self);
831 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
833 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
835 tf_channel_new_async (TP_CHANNEL (priv->call),
836 on_tf_channel_ready, self);
840 on_call_accepted_cb (GObject *source_object,
844 TpCallChannel *call = TP_CALL_CHANNEL (source_object);
845 GError *error = NULL;
847 if (!tp_call_channel_accept_finish (call, res, &error))
849 g_warning ("could not accept Call: %s", error->message);
850 g_error_free (error);
855 empathy_call_handler_request_cb (GObject *source,
856 GAsyncResult *result,
859 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
860 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
862 GError *error = NULL;
863 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
865 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
866 result, NULL, &error);
869 DEBUG ("Failed to create the channel: %s", error->message);
870 g_error_free (error);
874 if (!TP_IS_CALL_CHANNEL (channel))
876 DEBUG ("The channel is not a Call channel!");
880 priv->call = TP_CALL_CHANNEL (channel);
881 tp_g_signal_connect_object (priv->call, "state-changed",
882 G_CALLBACK (on_call_state_changed_cb), self, 0);
883 tp_g_signal_connect_object (priv->call, "invalidated",
884 G_CALLBACK (on_call_invalidated_cb), self, 0);
886 g_object_notify (G_OBJECT (self), "call-channel");
888 empathy_call_handler_start_tpfs (self);
889 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
893 empathy_call_handler_start_call (EmpathyCallHandler *handler,
896 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
897 TpAccountChannelRequest *req;
901 if (priv->call != NULL)
903 empathy_call_handler_start_tpfs (handler);
904 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
908 /* No TpCallChannel (we are redialing). Request a new call channel */
909 g_assert (priv->contact != NULL);
911 account = empathy_contact_get_account (priv->contact);
912 request = empathy_call_create_call_request (
913 empathy_contact_get_id (priv->contact),
914 priv->initial_audio, priv->initial_video);
916 req = tp_account_channel_request_new (account, request, timestamp);
918 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
919 empathy_call_handler_request_cb, handler);
921 g_object_unref (req);
922 g_hash_table_unref (request);
926 * empathy_call_handler_stop_call:
927 * @handler: an #EmpathyCallHandler
929 * Closes the #EmpathyCallHandler's call and frees its resources.
932 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
934 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
936 if (priv->call != NULL)
938 tp_call_channel_hangup_async (priv->call,
939 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
941 tp_channel_close_async (TP_CHANNEL (priv->call),
943 tp_clear_object (&priv->call);
944 tp_clear_object (&priv->tfchannel);
949 * empathy_call_handler_has_initial_video:
950 * @handler: an #EmpathyCallHandler
952 * Return %TRUE if the call managed by this #EmpathyCallHandler was
953 * created with video enabled
955 * Return value: %TRUE if the call was created as a video conversation.
958 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
960 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
962 return priv->initial_video;
966 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
968 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
970 return priv->send_audio_codec;
974 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
976 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
978 return priv->send_video_codec;
982 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
984 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
986 return priv->recv_audio_codecs;
990 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
992 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
994 return priv->recv_video_codecs;
998 empathy_call_handler_get_audio_remote_candidate (
999 EmpathyCallHandler *self)
1001 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1003 return priv->audio_remote_candidate;
1007 empathy_call_handler_get_audio_local_candidate (
1008 EmpathyCallHandler *self)
1010 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1012 return priv->audio_local_candidate;
1016 empathy_call_handler_get_video_remote_candidate (
1017 EmpathyCallHandler *self)
1019 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1021 return priv->video_remote_candidate;
1025 empathy_call_handler_get_video_local_candidate (
1026 EmpathyCallHandler *self)
1028 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1030 return priv->video_local_candidate;