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>
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;
94 gboolean accept_when_initialised;
97 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
100 empathy_call_handler_dispose (GObject *object)
102 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
104 tp_clear_object (&priv->tfchannel);
105 tp_clear_object (&priv->call);
106 tp_clear_object (&priv->contact);
108 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
112 empathy_call_handler_finalize (GObject *object)
114 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
116 fs_codec_destroy (priv->send_audio_codec);
117 fs_codec_destroy (priv->send_video_codec);
118 fs_codec_list_destroy (priv->recv_audio_codecs);
119 fs_codec_list_destroy (priv->recv_video_codecs);
120 fs_candidate_destroy (priv->audio_remote_candidate);
121 fs_candidate_destroy (priv->video_remote_candidate);
122 fs_candidate_destroy (priv->audio_local_candidate);
123 fs_candidate_destroy (priv->video_local_candidate);
125 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
129 empathy_call_handler_init (EmpathyCallHandler *obj)
131 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
132 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
138 on_call_accepted_cb (GObject *source_object,
142 TpCallChannel *call = TP_CALL_CHANNEL (source_object);
143 GError *error = NULL;
145 if (!tp_call_channel_accept_finish (call, res, &error))
147 g_warning ("could not accept Call: %s", error->message);
148 g_error_free (error);
153 on_call_invalidated_cb (TpCallChannel *call,
157 EmpathyCallHandler *self)
159 EmpathyCallHandlerPriv *priv = self->priv;
161 if (priv->call == call)
163 /* Invalidated unexpectedly? Fake call ending */
164 g_signal_emit (self, signals[STATE_CHANGED], 0,
165 TP_CALL_STATE_ENDED, NULL);
166 priv->accept_when_initialised = FALSE;
167 tp_clear_object (&priv->call);
168 tp_clear_object (&priv->tfchannel);
173 on_call_state_changed_cb (TpCallChannel *call,
176 TpCallStateReason *reason,
178 EmpathyCallHandler *handler)
180 EmpathyCallHandlerPriv *priv = handler->priv;
182 g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
183 reason->dbus_reason);
185 if (state == TP_CALL_STATE_INITIALISED &&
186 priv->accept_when_initialised)
188 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
189 priv->accept_when_initialised = FALSE;
192 if (state == TP_CALL_STATE_ENDED)
194 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
195 priv->accept_when_initialised = FALSE;
196 tp_clear_object (&priv->call);
197 tp_clear_object (&priv->tfchannel);
202 empathy_call_handler_set_property (GObject *object,
203 guint property_id, const GValue *value, GParamSpec *pspec)
205 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
210 priv->contact = g_value_dup_object (value);
212 case PROP_CALL_CHANNEL:
213 g_return_if_fail (priv->call == NULL);
215 priv->call = g_value_dup_object (value);
217 tp_g_signal_connect_object (priv->call, "state-changed",
218 G_CALLBACK (on_call_state_changed_cb), object, 0);
219 tp_g_signal_connect_object (priv->call, "invalidated",
220 G_CALLBACK (on_call_invalidated_cb), object, 0);
222 case PROP_INITIAL_AUDIO:
223 priv->initial_audio = g_value_get_boolean (value);
225 case PROP_INITIAL_VIDEO:
226 priv->initial_video = g_value_get_boolean (value);
229 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
234 empathy_call_handler_get_property (GObject *object,
235 guint property_id, GValue *value, GParamSpec *pspec)
237 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
242 g_value_set_object (value, priv->contact);
244 case PROP_CALL_CHANNEL:
245 g_value_set_object (value, priv->call);
247 case PROP_INITIAL_AUDIO:
248 g_value_set_boolean (value, priv->initial_audio);
250 case PROP_INITIAL_VIDEO:
251 g_value_set_boolean (value, priv->initial_video);
253 case PROP_SEND_AUDIO_CODEC:
254 g_value_set_boxed (value, priv->send_audio_codec);
256 case PROP_SEND_VIDEO_CODEC:
257 g_value_set_boxed (value, priv->send_video_codec);
259 case PROP_RECV_AUDIO_CODECS:
260 g_value_set_boxed (value, priv->recv_audio_codecs);
262 case PROP_RECV_VIDEO_CODECS:
263 g_value_set_boxed (value, priv->recv_video_codecs);
265 case PROP_AUDIO_REMOTE_CANDIDATE:
266 g_value_set_boxed (value, priv->audio_remote_candidate);
268 case PROP_VIDEO_REMOTE_CANDIDATE:
269 g_value_set_boxed (value, priv->video_remote_candidate);
271 case PROP_AUDIO_LOCAL_CANDIDATE:
272 g_value_set_boxed (value, priv->audio_local_candidate);
274 case PROP_VIDEO_LOCAL_CANDIDATE:
275 g_value_set_boxed (value, priv->video_local_candidate);
278 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
284 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
286 GObjectClass *object_class = G_OBJECT_CLASS (klass);
287 GParamSpec *param_spec;
289 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
291 object_class->set_property = empathy_call_handler_set_property;
292 object_class->get_property = empathy_call_handler_get_property;
293 object_class->dispose = empathy_call_handler_dispose;
294 object_class->finalize = empathy_call_handler_finalize;
296 param_spec = g_param_spec_object ("target-contact",
297 "TargetContact", "The contact",
298 EMPATHY_TYPE_CONTACT,
299 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
300 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
302 param_spec = g_param_spec_object ("call-channel",
303 "call channel", "The call channel",
304 TP_TYPE_CALL_CHANNEL,
305 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
306 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
308 param_spec = g_param_spec_boolean ("initial-audio",
309 "initial-audio", "Whether the call should start with audio",
311 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
312 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
315 param_spec = g_param_spec_boolean ("initial-video",
316 "initial-video", "Whether the call should start with video",
318 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
319 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
322 param_spec = g_param_spec_boxed ("send-audio-codec",
323 "send audio codec", "Codec used to encode the outgoing video stream",
325 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
326 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
329 param_spec = g_param_spec_boxed ("send-video-codec",
330 "send video codec", "Codec used to encode the outgoing video stream",
332 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
333 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
336 param_spec = g_param_spec_boxed ("recv-audio-codecs",
337 "recvs audio codec", "Codecs used to decode the incoming audio stream",
339 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
340 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
343 param_spec = g_param_spec_boxed ("recv-video-codecs",
344 "recvs video codec", "Codecs used to decode the incoming video stream",
346 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
347 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
350 param_spec = g_param_spec_boxed ("audio-remote-candidate",
351 "audio remote candidate",
352 "Remote candidate used for the audio stream",
354 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
355 g_object_class_install_property (object_class,
356 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
358 param_spec = g_param_spec_boxed ("video-remote-candidate",
359 "video remote candidate",
360 "Remote candidate used for the video stream",
362 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
363 g_object_class_install_property (object_class,
364 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
366 param_spec = g_param_spec_boxed ("audio-local-candidate",
367 "audio local candidate",
368 "Local candidate used for the audio stream",
370 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
371 g_object_class_install_property (object_class,
372 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
374 param_spec = g_param_spec_boxed ("video-local-candidate",
375 "video local candidate",
376 "Local candidate used for the video stream",
378 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
379 g_object_class_install_property (object_class,
380 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
382 signals[CONFERENCE_ADDED] =
383 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
384 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
385 g_cclosure_marshal_generic,
387 1, FS_TYPE_CONFERENCE);
389 signals[CONFERENCE_REMOVED] =
390 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
391 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
392 g_cclosure_marshal_generic,
394 1, FS_TYPE_CONFERENCE);
396 signals[SRC_PAD_ADDED] =
397 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
398 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
399 g_cclosure_marshal_generic,
401 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
403 signals[CONTENT_ADDED] =
404 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
405 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
406 g_cclosure_marshal_generic,
410 signals[CONTENT_REMOVED] =
411 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
412 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
413 g_cclosure_marshal_generic,
418 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
419 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
420 g_cclosure_marshal_generic,
424 signals[CANDIDATES_CHANGED] =
425 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
426 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
427 g_cclosure_marshal_generic,
428 G_TYPE_NONE, 1, G_TYPE_UINT);
430 signals[STATE_CHANGED] =
431 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
432 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
433 g_cclosure_marshal_generic,
434 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
436 signals[FRAMERATE_CHANGED] =
437 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
438 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
439 g_cclosure_marshal_generic,
440 G_TYPE_NONE, 1, G_TYPE_UINT);
442 signals[RESOLUTION_CHANGED] =
443 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
444 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
445 g_cclosure_marshal_generic,
447 2, G_TYPE_UINT, G_TYPE_UINT);
451 empathy_call_handler_new_for_channel (TpCallChannel *call,
452 EmpathyContact *contact)
454 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
455 "call-channel", call,
456 "initial-video", tp_call_channel_has_initial_video (call, NULL),
457 "target-contact", contact,
462 update_sending_codec (EmpathyCallHandler *self,
466 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
469 if (codec == NULL || session == NULL)
472 g_object_get (session, "media-type", &type, NULL);
474 if (type == FS_MEDIA_TYPE_AUDIO)
476 priv->send_audio_codec = fs_codec_copy (codec);
477 g_object_notify (G_OBJECT (self), "send-audio-codec");
479 else if (type == FS_MEDIA_TYPE_VIDEO)
481 priv->send_video_codec = fs_codec_copy (codec);
482 g_object_notify (G_OBJECT (self), "send-video-codec");
487 update_receiving_codec (EmpathyCallHandler *self,
491 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
495 if (codecs == NULL || stream == NULL)
498 g_object_get (stream, "session", &session, NULL);
502 g_object_get (session, "media-type", &type, NULL);
504 if (type == FS_MEDIA_TYPE_AUDIO)
506 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
507 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
509 else if (type == FS_MEDIA_TYPE_VIDEO)
511 priv->recv_video_codecs = fs_codec_list_copy (codecs);
512 g_object_notify (G_OBJECT (self), "recv-video-codecs");
515 g_object_unref (session);
519 update_candidates (EmpathyCallHandler *self,
520 FsCandidate *remote_candidate,
521 FsCandidate *local_candidate,
524 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
531 g_object_get (stream, "session", &session, NULL);
535 g_object_get (session, "media-type", &type, NULL);
537 if (type == FS_MEDIA_TYPE_AUDIO)
539 if (remote_candidate != NULL)
541 fs_candidate_destroy (priv->audio_remote_candidate);
542 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
543 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
546 if (local_candidate != NULL)
548 fs_candidate_destroy (priv->audio_local_candidate);
549 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
550 g_object_notify (G_OBJECT (self), "audio-local-candidate");
553 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
554 FS_MEDIA_TYPE_AUDIO);
556 else if (type == FS_MEDIA_TYPE_VIDEO)
558 if (remote_candidate != NULL)
560 fs_candidate_destroy (priv->video_remote_candidate);
561 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
562 g_object_notify (G_OBJECT (self), "video-remote-candidate");
565 if (local_candidate != NULL)
567 fs_candidate_destroy (priv->video_local_candidate);
568 priv->video_local_candidate = fs_candidate_copy (local_candidate);
569 g_object_notify (G_OBJECT (self), "video-local-candidate");
572 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
573 FS_MEDIA_TYPE_VIDEO);
576 g_object_unref (session);
580 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
581 GstBus *bus, GstMessage *message)
583 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
584 const GstStructure *s = gst_message_get_structure (message);
586 if (priv->tfchannel == NULL)
590 gst_structure_has_name (s, "farsight-send-codec-changed"))
596 DEBUG ("farsight-send-codec-changed");
598 val = gst_structure_get_value (s, "codec");
599 codec = g_value_get_boxed (val);
601 val = gst_structure_get_value (s, "session");
602 session = g_value_get_object (val);
604 update_sending_codec (handler, codec, session);
606 else if (s != NULL &&
607 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
613 DEBUG ("farsight-recv-codecs-changed");
615 val = gst_structure_get_value (s, "codecs");
616 codecs = g_value_get_boxed (val);
618 val = gst_structure_get_value (s, "stream");
619 stream = g_value_get_object (val);
621 update_receiving_codec (handler, codecs, stream);
623 else if (s != NULL &&
624 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
627 FsCandidate *remote_candidate, *local_candidate;
630 DEBUG ("farsight-new-active-candidate-pair");
632 val = gst_structure_get_value (s, "remote-candidate");
633 remote_candidate = g_value_get_boxed (val);
635 val = gst_structure_get_value (s, "local-candidate");
636 local_candidate = g_value_get_boxed (val);
638 val = gst_structure_get_value (s, "stream");
639 stream = g_value_get_object (val);
641 update_candidates (handler, remote_candidate, local_candidate, stream);
644 tf_channel_bus_message (priv->tfchannel, message);
648 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
649 GstElement *conference,
650 EmpathyCallHandler *self)
652 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
657 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
658 FsConference *conference,
659 EmpathyCallHandler *self)
661 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
662 GST_ELEMENT (conference));
666 src_pad_added_error_idle (gpointer data)
668 TfContent *content = data;
670 tf_content_error_literal (content, "Could not link sink");
671 g_object_unref (content);
677 on_tf_content_src_pad_added_cb (TfContent *content,
682 EmpathyCallHandler *handler)
686 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
687 content, pad, &retval);
690 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
694 on_tf_content_framerate_changed (TfContent *content,
696 EmpathyCallHandler *handler)
700 g_object_get (content, "framerate", &framerate, NULL);
703 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
708 on_tf_content_resolution_changed (TfContent *content,
711 EmpathyCallHandler *handler)
713 if (width > 0 && height > 0)
714 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
719 on_tf_channel_content_added_cb (TfChannel *tfchannel,
721 EmpathyCallHandler *handler)
725 // FsStream *fs_stream;
730 g_signal_connect (content, "src-pad-added",
731 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
733 g_signal_connect (content, "start-sending",
734 G_CALLBACK (on_tf_content_start_sending_cb), handler);
735 g_signal_connect (content, "stop-sending",
736 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
739 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
743 tf_content_error_literal (content, "Could not link source");
745 /* Get sending codec */
746 g_object_get (content, "fs-session", &session, NULL);
747 g_object_get (session, "current-send-codec", &codec, NULL);
749 update_sending_codec (handler, codec, session);
751 tp_clear_object (&session);
752 tp_clear_object (&codec);
754 /* Get receiving codec */
756 g_object_get (content, "fs-stream", &fs_stream, NULL);
757 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
759 update_receiving_codec (handler, codecs, fs_stream);
761 fs_codec_list_destroy (codecs);
762 tp_clear_object (&fs_stream);
765 g_object_get (content, "media-type", &mtype, NULL);
767 if (mtype == FS_MEDIA_TYPE_VIDEO)
769 guint framerate, width, height;
771 g_signal_connect (content, "notify::framerate",
772 G_CALLBACK (on_tf_content_framerate_changed),
775 g_signal_connect (content, "resolution-changed",
776 G_CALLBACK (on_tf_content_resolution_changed),
779 g_object_get (content,
780 "framerate", &framerate,
786 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
789 if (width > 0 && height > 0)
790 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
796 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
798 EmpathyCallHandler *handler)
802 DEBUG ("removing content");
804 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
809 g_warning ("Could not remove content!");
811 tf_content_error_literal (content, "Could not link source");
816 on_tf_channel_closed_cb (TfChannel *tfchannel,
817 EmpathyCallHandler *handler)
819 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
823 on_tf_channel_ready (GObject *source,
824 GAsyncResult *result,
827 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
828 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
829 GError *error = NULL;
831 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
832 G_ASYNC_INITABLE (source), result, NULL));
834 if (priv->tfchannel == NULL)
836 g_warning ("Failed to create Farstream channel: %s", error->message);
837 g_error_free (error);
841 /* Set up the telepathy farstream channel */
842 g_signal_connect (priv->tfchannel, "closed",
843 G_CALLBACK (on_tf_channel_closed_cb), self);
844 g_signal_connect (priv->tfchannel, "fs-conference-added",
845 G_CALLBACK (on_tf_channel_conference_added_cb), self);
846 g_signal_connect (priv->tfchannel, "fs-conference-removed",
847 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
848 g_signal_connect (priv->tfchannel, "content-added",
849 G_CALLBACK (on_tf_channel_content_added_cb), self);
850 g_signal_connect (priv->tfchannel, "content-removed",
851 G_CALLBACK (on_tf_channel_content_removed_cb), self);
855 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
857 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
859 tf_channel_new_async (TP_CHANNEL (priv->call),
860 on_tf_channel_ready, self);
864 empathy_call_handler_request_cb (GObject *source,
865 GAsyncResult *result,
868 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
869 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
871 GError *error = NULL;
872 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
874 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
875 result, NULL, &error);
878 DEBUG ("Failed to create the channel: %s", error->message);
879 g_error_free (error);
883 if (!TP_IS_CALL_CHANNEL (channel))
885 DEBUG ("The channel is not a Call channel!");
889 priv->call = TP_CALL_CHANNEL (channel);
890 tp_g_signal_connect_object (priv->call, "state-changed",
891 G_CALLBACK (on_call_state_changed_cb), self, 0);
892 tp_g_signal_connect_object (priv->call, "invalidated",
893 G_CALLBACK (on_call_invalidated_cb), self, 0);
895 g_object_notify (G_OBJECT (self), "call-channel");
897 empathy_call_handler_start_tpfs (self);
898 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
902 empathy_call_handler_start_call (EmpathyCallHandler *handler,
905 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
906 TpAccountChannelRequest *req;
910 if (priv->call != NULL)
912 empathy_call_handler_start_tpfs (handler);
914 if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
916 /* accept outgoing channels immediately */
917 tp_call_channel_accept_async (priv->call,
918 on_call_accepted_cb, NULL);
922 /* accepting incoming channels when they are INITIALISED */
923 if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
924 TP_CALL_STATE_INITIALISED)
925 tp_call_channel_accept_async (priv->call,
926 on_call_accepted_cb, NULL);
928 priv->accept_when_initialised = TRUE;
934 /* No TpCallChannel (we are redialing). Request a new call channel */
935 g_assert (priv->contact != NULL);
937 account = empathy_contact_get_account (priv->contact);
938 request = empathy_call_create_call_request (
939 empathy_contact_get_id (priv->contact),
940 priv->initial_audio, priv->initial_video);
942 req = tp_account_channel_request_new (account, request, timestamp);
944 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
945 empathy_call_handler_request_cb, handler);
947 g_object_unref (req);
948 g_hash_table_unref (request);
952 * empathy_call_handler_stop_call:
953 * @handler: an #EmpathyCallHandler
955 * Closes the #EmpathyCallHandler's call and frees its resources.
958 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
960 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
962 if (priv->call != NULL)
964 tp_call_channel_hangup_async (priv->call,
965 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
971 * empathy_call_handler_has_initial_video:
972 * @handler: an #EmpathyCallHandler
974 * Return %TRUE if the call managed by this #EmpathyCallHandler was
975 * created with video enabled
977 * Return value: %TRUE if the call was created as a video conversation.
980 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
982 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
984 return priv->initial_video;
988 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
990 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
992 return priv->send_audio_codec;
996 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
998 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1000 return priv->send_video_codec;
1004 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1006 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1008 return priv->recv_audio_codecs;
1012 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1014 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1016 return priv->recv_video_codecs;
1020 empathy_call_handler_get_audio_remote_candidate (
1021 EmpathyCallHandler *self)
1023 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1025 return priv->audio_remote_candidate;
1029 empathy_call_handler_get_audio_local_candidate (
1030 EmpathyCallHandler *self)
1032 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1034 return priv->audio_local_candidate;
1038 empathy_call_handler_get_video_remote_candidate (
1039 EmpathyCallHandler *self)
1041 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1043 return priv->video_remote_candidate;
1047 empathy_call_handler_get_video_local_candidate (
1048 EmpathyCallHandler *self)
1050 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1052 return priv->video_local_candidate;
1056 empathy_call_handler_get_contact (EmpathyCallHandler *self)
1058 return self->priv->contact;