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
22 #include "empathy-call-handler.h"
24 #include <telepathy-farstream/telepathy-farstream.h>
26 #include "empathy-call-utils.h"
27 #include "empathy-utils.h"
29 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
30 #include "empathy-debug.h"
32 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
49 static guint signals[LAST_SIGNAL] = {0};
52 PROP_CALL_CHANNEL = 1,
57 PROP_SEND_AUDIO_CODEC,
58 PROP_SEND_VIDEO_CODEC,
59 PROP_RECV_AUDIO_CODECS,
60 PROP_RECV_VIDEO_CODECS,
61 PROP_AUDIO_REMOTE_CANDIDATE,
62 PROP_VIDEO_REMOTE_CANDIDATE,
63 PROP_AUDIO_LOCAL_CANDIDATE,
64 PROP_VIDEO_LOCAL_CANDIDATE,
67 /* private structure */
69 struct _EmpathyCallHandlerPriv {
72 EmpathyContact *contact;
74 gboolean initial_audio;
75 gboolean initial_video;
77 FsCodec *send_audio_codec;
78 FsCodec *send_video_codec;
79 GList *recv_audio_codecs;
80 GList *recv_video_codecs;
81 FsCandidate *audio_remote_candidate;
82 FsCandidate *video_remote_candidate;
83 FsCandidate *audio_local_candidate;
84 FsCandidate *video_local_candidate;
85 gboolean accept_when_initialised;
88 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
91 empathy_call_handler_dispose (GObject *object)
93 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
95 tp_clear_object (&priv->tfchannel);
96 tp_clear_object (&priv->call);
97 tp_clear_object (&priv->contact);
99 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
103 empathy_call_handler_finalize (GObject *object)
105 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
107 fs_codec_destroy (priv->send_audio_codec);
108 fs_codec_destroy (priv->send_video_codec);
109 fs_codec_list_destroy (priv->recv_audio_codecs);
110 fs_codec_list_destroy (priv->recv_video_codecs);
111 fs_candidate_destroy (priv->audio_remote_candidate);
112 fs_candidate_destroy (priv->video_remote_candidate);
113 fs_candidate_destroy (priv->audio_local_candidate);
114 fs_candidate_destroy (priv->video_local_candidate);
116 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
120 empathy_call_handler_init (EmpathyCallHandler *obj)
122 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
123 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
129 on_call_accepted_cb (GObject *source_object,
133 TpCallChannel *call = TP_CALL_CHANNEL (source_object);
134 GError *error = NULL;
136 if (!tp_call_channel_accept_finish (call, res, &error))
138 g_warning ("could not accept Call: %s", error->message);
139 g_error_free (error);
144 on_call_invalidated_cb (TpCallChannel *call,
148 EmpathyCallHandler *self)
150 EmpathyCallHandlerPriv *priv = self->priv;
152 if (priv->call == call)
154 /* Invalidated unexpectedly? Fake call ending */
155 g_signal_emit (self, signals[STATE_CHANGED], 0,
156 TP_CALL_STATE_ENDED, NULL);
157 priv->accept_when_initialised = FALSE;
158 tp_clear_object (&priv->call);
159 tp_clear_object (&priv->tfchannel);
164 on_call_state_changed_cb (TpCallChannel *call,
167 TpCallStateReason *reason,
169 EmpathyCallHandler *handler)
171 EmpathyCallHandlerPriv *priv = handler->priv;
173 /* Clean up the TfChannel before bubbling the state-change signal
174 * further up. This ensures that the conference-removed signal is
175 * emitted before state-changed so that the client gets a chance
176 * to remove the conference from the pipeline before resetting the
179 if (state == TP_CALL_STATE_ENDED)
181 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
182 priv->accept_when_initialised = FALSE;
183 tp_clear_object (&priv->call);
184 tp_clear_object (&priv->tfchannel);
187 g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
188 reason->dbus_reason);
190 if (state == TP_CALL_STATE_INITIALISED &&
191 priv->accept_when_initialised)
193 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
194 priv->accept_when_initialised = FALSE;
199 empathy_call_handler_set_property (GObject *object,
200 guint property_id, const GValue *value, GParamSpec *pspec)
202 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
207 priv->contact = g_value_dup_object (value);
209 case PROP_CALL_CHANNEL:
210 g_return_if_fail (priv->call == NULL);
212 priv->call = g_value_dup_object (value);
214 tp_g_signal_connect_object (priv->call, "state-changed",
215 G_CALLBACK (on_call_state_changed_cb), object, 0);
216 tp_g_signal_connect_object (priv->call, "invalidated",
217 G_CALLBACK (on_call_invalidated_cb), object, 0);
219 case PROP_INITIAL_AUDIO:
220 priv->initial_audio = g_value_get_boolean (value);
222 case PROP_INITIAL_VIDEO:
223 priv->initial_video = g_value_get_boolean (value);
226 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
231 empathy_call_handler_get_property (GObject *object,
232 guint property_id, GValue *value, GParamSpec *pspec)
234 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
239 g_value_set_object (value, priv->contact);
241 case PROP_CALL_CHANNEL:
242 g_value_set_object (value, priv->call);
244 case PROP_INITIAL_AUDIO:
245 g_value_set_boolean (value, priv->initial_audio);
247 case PROP_INITIAL_VIDEO:
248 g_value_set_boolean (value, priv->initial_video);
250 case PROP_SEND_AUDIO_CODEC:
251 g_value_set_boxed (value, priv->send_audio_codec);
253 case PROP_SEND_VIDEO_CODEC:
254 g_value_set_boxed (value, priv->send_video_codec);
256 case PROP_RECV_AUDIO_CODECS:
257 g_value_set_boxed (value, priv->recv_audio_codecs);
259 case PROP_RECV_VIDEO_CODECS:
260 g_value_set_boxed (value, priv->recv_video_codecs);
262 case PROP_AUDIO_REMOTE_CANDIDATE:
263 g_value_set_boxed (value, priv->audio_remote_candidate);
265 case PROP_VIDEO_REMOTE_CANDIDATE:
266 g_value_set_boxed (value, priv->video_remote_candidate);
268 case PROP_AUDIO_LOCAL_CANDIDATE:
269 g_value_set_boxed (value, priv->audio_local_candidate);
271 case PROP_VIDEO_LOCAL_CANDIDATE:
272 g_value_set_boxed (value, priv->video_local_candidate);
275 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
281 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
283 GObjectClass *object_class = G_OBJECT_CLASS (klass);
284 GParamSpec *param_spec;
286 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
288 object_class->set_property = empathy_call_handler_set_property;
289 object_class->get_property = empathy_call_handler_get_property;
290 object_class->dispose = empathy_call_handler_dispose;
291 object_class->finalize = empathy_call_handler_finalize;
293 param_spec = g_param_spec_object ("target-contact",
294 "TargetContact", "The contact",
295 EMPATHY_TYPE_CONTACT,
296 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
297 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
299 param_spec = g_param_spec_object ("call-channel",
300 "call channel", "The call channel",
301 TP_TYPE_CALL_CHANNEL,
302 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
303 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
305 param_spec = g_param_spec_boolean ("initial-audio",
306 "initial-audio", "Whether the call should start with audio",
308 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
309 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
312 param_spec = g_param_spec_boolean ("initial-video",
313 "initial-video", "Whether the call should start with video",
315 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
316 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
319 param_spec = g_param_spec_boxed ("send-audio-codec",
320 "send audio codec", "Codec used to encode the outgoing video stream",
322 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
323 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
326 param_spec = g_param_spec_boxed ("send-video-codec",
327 "send video codec", "Codec used to encode the outgoing video stream",
329 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
330 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
333 param_spec = g_param_spec_boxed ("recv-audio-codecs",
334 "recvs audio codec", "Codecs used to decode the incoming audio stream",
336 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
337 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
340 param_spec = g_param_spec_boxed ("recv-video-codecs",
341 "recvs video codec", "Codecs used to decode the incoming video stream",
343 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
344 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
347 param_spec = g_param_spec_boxed ("audio-remote-candidate",
348 "audio remote candidate",
349 "Remote candidate used for the audio stream",
351 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
352 g_object_class_install_property (object_class,
353 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
355 param_spec = g_param_spec_boxed ("video-remote-candidate",
356 "video remote candidate",
357 "Remote candidate used for the video stream",
359 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
360 g_object_class_install_property (object_class,
361 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
363 param_spec = g_param_spec_boxed ("audio-local-candidate",
364 "audio local candidate",
365 "Local candidate used for the audio stream",
367 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
368 g_object_class_install_property (object_class,
369 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
371 param_spec = g_param_spec_boxed ("video-local-candidate",
372 "video local candidate",
373 "Local candidate used for the video stream",
375 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
376 g_object_class_install_property (object_class,
377 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
379 signals[CONFERENCE_ADDED] =
380 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
381 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
382 g_cclosure_marshal_generic,
384 1, FS_TYPE_CONFERENCE);
386 signals[CONFERENCE_REMOVED] =
387 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
388 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
389 g_cclosure_marshal_generic,
391 1, FS_TYPE_CONFERENCE);
393 signals[SRC_PAD_ADDED] =
394 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
395 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
396 g_cclosure_marshal_generic,
398 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
400 signals[CONTENT_ADDED] =
401 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
402 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
403 g_cclosure_marshal_generic,
407 signals[CONTENT_REMOVED] =
408 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
409 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
410 g_cclosure_marshal_generic,
415 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
416 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
417 g_cclosure_marshal_generic,
421 signals[CANDIDATES_CHANGED] =
422 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
423 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
424 g_cclosure_marshal_generic,
425 G_TYPE_NONE, 1, G_TYPE_UINT);
427 signals[STATE_CHANGED] =
428 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
429 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
430 g_cclosure_marshal_generic,
431 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
433 signals[FRAMERATE_CHANGED] =
434 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
435 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
436 g_cclosure_marshal_generic,
437 G_TYPE_NONE, 1, G_TYPE_UINT);
439 signals[RESOLUTION_CHANGED] =
440 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
441 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
442 g_cclosure_marshal_generic,
444 2, G_TYPE_UINT, G_TYPE_UINT);
448 empathy_call_handler_new_for_channel (TpCallChannel *call,
449 EmpathyContact *contact)
451 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
452 "call-channel", call,
453 "initial-video", tp_call_channel_has_initial_video (call, NULL),
454 "target-contact", contact,
459 update_sending_codec (EmpathyCallHandler *self,
463 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
466 if (codec == NULL || session == NULL)
469 g_object_get (session, "media-type", &type, NULL);
471 if (type == FS_MEDIA_TYPE_AUDIO)
473 priv->send_audio_codec = fs_codec_copy (codec);
474 g_object_notify (G_OBJECT (self), "send-audio-codec");
476 else if (type == FS_MEDIA_TYPE_VIDEO)
478 priv->send_video_codec = fs_codec_copy (codec);
479 g_object_notify (G_OBJECT (self), "send-video-codec");
484 update_receiving_codec (EmpathyCallHandler *self,
488 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
492 if (codecs == NULL || stream == NULL)
495 g_object_get (stream, "session", &session, NULL);
499 g_object_get (session, "media-type", &type, NULL);
501 if (type == FS_MEDIA_TYPE_AUDIO)
503 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
504 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
506 else if (type == FS_MEDIA_TYPE_VIDEO)
508 priv->recv_video_codecs = fs_codec_list_copy (codecs);
509 g_object_notify (G_OBJECT (self), "recv-video-codecs");
512 g_object_unref (session);
516 update_candidates (EmpathyCallHandler *self,
517 FsCandidate *remote_candidate,
518 FsCandidate *local_candidate,
521 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
528 g_object_get (stream, "session", &session, NULL);
532 g_object_get (session, "media-type", &type, NULL);
534 if (type == FS_MEDIA_TYPE_AUDIO)
536 if (remote_candidate != NULL)
538 fs_candidate_destroy (priv->audio_remote_candidate);
539 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
540 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
543 if (local_candidate != NULL)
545 fs_candidate_destroy (priv->audio_local_candidate);
546 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
547 g_object_notify (G_OBJECT (self), "audio-local-candidate");
550 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
551 FS_MEDIA_TYPE_AUDIO);
553 else if (type == FS_MEDIA_TYPE_VIDEO)
555 if (remote_candidate != NULL)
557 fs_candidate_destroy (priv->video_remote_candidate);
558 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
559 g_object_notify (G_OBJECT (self), "video-remote-candidate");
562 if (local_candidate != NULL)
564 fs_candidate_destroy (priv->video_local_candidate);
565 priv->video_local_candidate = fs_candidate_copy (local_candidate);
566 g_object_notify (G_OBJECT (self), "video-local-candidate");
569 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
570 FS_MEDIA_TYPE_VIDEO);
573 g_object_unref (session);
577 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
578 GstBus *bus, GstMessage *message)
580 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
581 const GstStructure *s = gst_message_get_structure (message);
583 if (priv->tfchannel == NULL)
587 gst_structure_has_name (s, "farsight-send-codec-changed"))
593 DEBUG ("farsight-send-codec-changed");
595 val = gst_structure_get_value (s, "codec");
596 codec = g_value_get_boxed (val);
598 val = gst_structure_get_value (s, "session");
599 session = g_value_get_object (val);
601 update_sending_codec (handler, codec, session);
603 else if (s != NULL &&
604 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
610 DEBUG ("farsight-recv-codecs-changed");
612 val = gst_structure_get_value (s, "codecs");
613 codecs = g_value_get_boxed (val);
615 val = gst_structure_get_value (s, "stream");
616 stream = g_value_get_object (val);
618 update_receiving_codec (handler, codecs, stream);
620 else if (s != NULL &&
621 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
624 FsCandidate *remote_candidate, *local_candidate;
627 DEBUG ("farsight-new-active-candidate-pair");
629 val = gst_structure_get_value (s, "remote-candidate");
630 remote_candidate = g_value_get_boxed (val);
632 val = gst_structure_get_value (s, "local-candidate");
633 local_candidate = g_value_get_boxed (val);
635 val = gst_structure_get_value (s, "stream");
636 stream = g_value_get_object (val);
638 update_candidates (handler, remote_candidate, local_candidate, stream);
641 tf_channel_bus_message (priv->tfchannel, message);
645 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
646 GstElement *conference,
647 EmpathyCallHandler *self)
649 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
654 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
655 FsConference *conference,
656 EmpathyCallHandler *self)
658 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
659 GST_ELEMENT (conference));
663 src_pad_added_error_idle (gpointer data)
665 TfContent *content = data;
667 tf_content_error_literal (content, "Could not link sink");
668 g_object_unref (content);
674 on_tf_content_src_pad_added_cb (TfContent *content,
679 EmpathyCallHandler *handler)
683 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
684 content, pad, &retval);
687 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
691 on_tf_content_framerate_changed (TfContent *content,
693 EmpathyCallHandler *handler)
697 g_object_get (content, "framerate", &framerate, NULL);
700 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
705 on_tf_content_resolution_changed (TfContent *content,
708 EmpathyCallHandler *handler)
710 if (width > 0 && height > 0)
711 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
716 on_tf_channel_content_added_cb (TfChannel *tfchannel,
718 EmpathyCallHandler *handler)
722 // FsStream *fs_stream;
727 g_signal_connect (content, "src-pad-added",
728 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
730 g_signal_connect (content, "start-sending",
731 G_CALLBACK (on_tf_content_start_sending_cb), handler);
732 g_signal_connect (content, "stop-sending",
733 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
736 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
740 tf_content_error_literal (content, "Could not link source");
742 /* Get sending codec */
743 g_object_get (content, "fs-session", &session, NULL);
744 g_object_get (session, "current-send-codec", &codec, NULL);
746 update_sending_codec (handler, codec, session);
748 tp_clear_object (&session);
749 tp_clear_object (&codec);
751 /* Get receiving codec */
753 g_object_get (content, "fs-stream", &fs_stream, NULL);
754 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
756 update_receiving_codec (handler, codecs, fs_stream);
758 fs_codec_list_destroy (codecs);
759 tp_clear_object (&fs_stream);
762 g_object_get (content, "media-type", &mtype, NULL);
764 if (mtype == FS_MEDIA_TYPE_VIDEO)
766 guint framerate, width, height;
768 g_signal_connect (content, "notify::framerate",
769 G_CALLBACK (on_tf_content_framerate_changed),
772 g_signal_connect (content, "resolution-changed",
773 G_CALLBACK (on_tf_content_resolution_changed),
776 g_object_get (content,
777 "framerate", &framerate,
783 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
786 if (width > 0 && height > 0)
787 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
793 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
795 EmpathyCallHandler *handler)
799 DEBUG ("removing content");
801 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
806 g_warning ("Could not remove content!");
808 tf_content_error_literal (content, "Could not link source");
813 on_tf_channel_closed_cb (TfChannel *tfchannel,
814 EmpathyCallHandler *handler)
816 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
820 on_tf_channel_ready (GObject *source,
821 GAsyncResult *result,
824 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
825 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
826 GError *error = NULL;
828 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
829 G_ASYNC_INITABLE (source), result, NULL));
831 if (priv->tfchannel == NULL)
833 g_warning ("Failed to create Farstream channel: %s", error->message);
834 g_error_free (error);
838 /* Set up the telepathy farstream channel */
839 g_signal_connect (priv->tfchannel, "closed",
840 G_CALLBACK (on_tf_channel_closed_cb), self);
841 g_signal_connect (priv->tfchannel, "fs-conference-added",
842 G_CALLBACK (on_tf_channel_conference_added_cb), self);
843 g_signal_connect (priv->tfchannel, "fs-conference-removed",
844 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
845 g_signal_connect (priv->tfchannel, "content-added",
846 G_CALLBACK (on_tf_channel_content_added_cb), self);
847 g_signal_connect (priv->tfchannel, "content-removed",
848 G_CALLBACK (on_tf_channel_content_removed_cb), self);
852 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
854 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
856 tf_channel_new_async (TP_CHANNEL (priv->call),
857 on_tf_channel_ready, self);
861 empathy_call_handler_request_cb (GObject *source,
862 GAsyncResult *result,
865 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
866 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
868 GError *error = NULL;
869 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
871 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
872 result, NULL, &error);
875 DEBUG ("Failed to create the channel: %s", error->message);
876 g_error_free (error);
880 if (!TP_IS_CALL_CHANNEL (channel))
882 DEBUG ("The channel is not a Call channel!");
886 priv->call = TP_CALL_CHANNEL (channel);
887 tp_g_signal_connect_object (priv->call, "state-changed",
888 G_CALLBACK (on_call_state_changed_cb), self, 0);
889 tp_g_signal_connect_object (priv->call, "invalidated",
890 G_CALLBACK (on_call_invalidated_cb), self, 0);
892 g_object_notify (G_OBJECT (self), "call-channel");
894 empathy_call_handler_start_tpfs (self);
895 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
899 empathy_call_handler_start_call (EmpathyCallHandler *handler,
902 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
903 TpAccountChannelRequest *req;
907 if (priv->call != NULL)
909 empathy_call_handler_start_tpfs (handler);
911 if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
913 /* accept outgoing channels immediately */
914 tp_call_channel_accept_async (priv->call,
915 on_call_accepted_cb, NULL);
919 /* accepting incoming channels when they are INITIALISED */
920 if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
921 TP_CALL_STATE_INITIALISED)
922 tp_call_channel_accept_async (priv->call,
923 on_call_accepted_cb, NULL);
925 priv->accept_when_initialised = TRUE;
931 /* No TpCallChannel (we are redialing). Request a new call channel */
932 g_assert (priv->contact != NULL);
934 account = empathy_contact_get_account (priv->contact);
935 request = empathy_call_create_call_request (
936 empathy_contact_get_id (priv->contact), priv->initial_video);
938 req = tp_account_channel_request_new (account, request, timestamp);
940 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
941 empathy_call_handler_request_cb, handler);
943 g_object_unref (req);
944 g_hash_table_unref (request);
948 * empathy_call_handler_stop_call:
949 * @handler: an #EmpathyCallHandler
951 * Closes the #EmpathyCallHandler's call and frees its resources.
954 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
956 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
958 if (priv->call != NULL)
960 tp_call_channel_hangup_async (priv->call,
961 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
967 * empathy_call_handler_has_initial_video:
968 * @handler: an #EmpathyCallHandler
970 * Return %TRUE if the call managed by this #EmpathyCallHandler was
971 * created with video enabled
973 * Return value: %TRUE if the call was created as a video conversation.
976 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
978 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
980 return priv->initial_video;
984 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
986 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
988 return priv->send_audio_codec;
992 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
994 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
996 return priv->send_video_codec;
1000 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1002 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1004 return priv->recv_audio_codecs;
1008 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1010 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1012 return priv->recv_video_codecs;
1016 empathy_call_handler_get_audio_remote_candidate (
1017 EmpathyCallHandler *self)
1019 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1021 return priv->audio_remote_candidate;
1025 empathy_call_handler_get_audio_local_candidate (
1026 EmpathyCallHandler *self)
1028 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1030 return priv->audio_local_candidate;
1034 empathy_call_handler_get_video_remote_candidate (
1035 EmpathyCallHandler *self)
1037 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1039 return priv->video_remote_candidate;
1043 empathy_call_handler_get_video_local_candidate (
1044 EmpathyCallHandler *self)
1046 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1048 return priv->video_local_candidate;
1052 empathy_call_handler_get_contact (EmpathyCallHandler *self)
1054 return self->priv->contact;