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/telepathy-glib.h>
28 #include <telepathy-farstream/telepathy-farstream.h>
30 #include <libempathy/empathy-utils.h>
32 #include <libempathy-gtk/empathy-call-utils.h>
34 #include "empathy-call-handler.h"
36 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
37 #include <libempathy/empathy-debug.h>
39 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
56 static guint signals[LAST_SIGNAL] = {0};
59 PROP_CALL_CHANNEL = 1,
64 PROP_SEND_AUDIO_CODEC,
65 PROP_SEND_VIDEO_CODEC,
66 PROP_RECV_AUDIO_CODECS,
67 PROP_RECV_VIDEO_CODECS,
68 PROP_AUDIO_REMOTE_CANDIDATE,
69 PROP_VIDEO_REMOTE_CANDIDATE,
70 PROP_AUDIO_LOCAL_CANDIDATE,
71 PROP_VIDEO_LOCAL_CANDIDATE,
74 /* private structure */
76 struct _EmpathyCallHandlerPriv {
79 EmpathyContact *contact;
81 gboolean initial_audio;
82 gboolean initial_video;
84 FsCodec *send_audio_codec;
85 FsCodec *send_video_codec;
86 GList *recv_audio_codecs;
87 GList *recv_video_codecs;
88 FsCandidate *audio_remote_candidate;
89 FsCandidate *video_remote_candidate;
90 FsCandidate *audio_local_candidate;
91 FsCandidate *video_local_candidate;
92 gboolean accept_when_initialised;
95 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
98 empathy_call_handler_dispose (GObject *object)
100 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
102 tp_clear_object (&priv->tfchannel);
103 tp_clear_object (&priv->call);
104 tp_clear_object (&priv->contact);
106 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
110 empathy_call_handler_finalize (GObject *object)
112 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
114 fs_codec_destroy (priv->send_audio_codec);
115 fs_codec_destroy (priv->send_video_codec);
116 fs_codec_list_destroy (priv->recv_audio_codecs);
117 fs_codec_list_destroy (priv->recv_video_codecs);
118 fs_candidate_destroy (priv->audio_remote_candidate);
119 fs_candidate_destroy (priv->video_remote_candidate);
120 fs_candidate_destroy (priv->audio_local_candidate);
121 fs_candidate_destroy (priv->video_local_candidate);
123 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
127 empathy_call_handler_init (EmpathyCallHandler *obj)
129 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
130 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
136 on_call_accepted_cb (GObject *source_object,
140 TpCallChannel *call = TP_CALL_CHANNEL (source_object);
141 GError *error = NULL;
143 if (!tp_call_channel_accept_finish (call, res, &error))
145 g_warning ("could not accept Call: %s", error->message);
146 g_error_free (error);
151 on_call_invalidated_cb (TpCallChannel *call,
155 EmpathyCallHandler *self)
157 EmpathyCallHandlerPriv *priv = self->priv;
159 if (priv->call == call)
161 /* Invalidated unexpectedly? Fake call ending */
162 g_signal_emit (self, signals[STATE_CHANGED], 0,
163 TP_CALL_STATE_ENDED, NULL);
164 priv->accept_when_initialised = FALSE;
165 tp_clear_object (&priv->call);
166 tp_clear_object (&priv->tfchannel);
171 on_call_state_changed_cb (TpCallChannel *call,
174 TpCallStateReason *reason,
176 EmpathyCallHandler *handler)
178 EmpathyCallHandlerPriv *priv = handler->priv;
180 g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
181 reason->dbus_reason);
183 if (state == TP_CALL_STATE_INITIALISED &&
184 priv->accept_when_initialised)
186 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
187 priv->accept_when_initialised = FALSE;
190 if (state == TP_CALL_STATE_ENDED)
192 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
193 priv->accept_when_initialised = FALSE;
194 tp_clear_object (&priv->call);
195 tp_clear_object (&priv->tfchannel);
200 empathy_call_handler_set_property (GObject *object,
201 guint property_id, const GValue *value, GParamSpec *pspec)
203 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
208 priv->contact = g_value_dup_object (value);
210 case PROP_CALL_CHANNEL:
211 g_return_if_fail (priv->call == NULL);
213 priv->call = g_value_dup_object (value);
215 tp_g_signal_connect_object (priv->call, "state-changed",
216 G_CALLBACK (on_call_state_changed_cb), object, 0);
217 tp_g_signal_connect_object (priv->call, "invalidated",
218 G_CALLBACK (on_call_invalidated_cb), object, 0);
220 case PROP_INITIAL_AUDIO:
221 priv->initial_audio = g_value_get_boolean (value);
223 case PROP_INITIAL_VIDEO:
224 priv->initial_video = g_value_get_boolean (value);
227 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
232 empathy_call_handler_get_property (GObject *object,
233 guint property_id, GValue *value, GParamSpec *pspec)
235 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
240 g_value_set_object (value, priv->contact);
242 case PROP_CALL_CHANNEL:
243 g_value_set_object (value, priv->call);
245 case PROP_INITIAL_AUDIO:
246 g_value_set_boolean (value, priv->initial_audio);
248 case PROP_INITIAL_VIDEO:
249 g_value_set_boolean (value, priv->initial_video);
251 case PROP_SEND_AUDIO_CODEC:
252 g_value_set_boxed (value, priv->send_audio_codec);
254 case PROP_SEND_VIDEO_CODEC:
255 g_value_set_boxed (value, priv->send_video_codec);
257 case PROP_RECV_AUDIO_CODECS:
258 g_value_set_boxed (value, priv->recv_audio_codecs);
260 case PROP_RECV_VIDEO_CODECS:
261 g_value_set_boxed (value, priv->recv_video_codecs);
263 case PROP_AUDIO_REMOTE_CANDIDATE:
264 g_value_set_boxed (value, priv->audio_remote_candidate);
266 case PROP_VIDEO_REMOTE_CANDIDATE:
267 g_value_set_boxed (value, priv->video_remote_candidate);
269 case PROP_AUDIO_LOCAL_CANDIDATE:
270 g_value_set_boxed (value, priv->audio_local_candidate);
272 case PROP_VIDEO_LOCAL_CANDIDATE:
273 g_value_set_boxed (value, priv->video_local_candidate);
276 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
282 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
284 GObjectClass *object_class = G_OBJECT_CLASS (klass);
285 GParamSpec *param_spec;
287 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
289 object_class->set_property = empathy_call_handler_set_property;
290 object_class->get_property = empathy_call_handler_get_property;
291 object_class->dispose = empathy_call_handler_dispose;
292 object_class->finalize = empathy_call_handler_finalize;
294 param_spec = g_param_spec_object ("target-contact",
295 "TargetContact", "The contact",
296 EMPATHY_TYPE_CONTACT,
297 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
298 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
300 param_spec = g_param_spec_object ("call-channel",
301 "call channel", "The call channel",
302 TP_TYPE_CALL_CHANNEL,
303 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
304 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
306 param_spec = g_param_spec_boolean ("initial-audio",
307 "initial-audio", "Whether the call should start with audio",
309 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
310 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
313 param_spec = g_param_spec_boolean ("initial-video",
314 "initial-video", "Whether the call should start with video",
316 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
317 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
320 param_spec = g_param_spec_boxed ("send-audio-codec",
321 "send audio codec", "Codec used to encode the outgoing video stream",
323 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
324 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
327 param_spec = g_param_spec_boxed ("send-video-codec",
328 "send video codec", "Codec used to encode the outgoing video stream",
330 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
331 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
334 param_spec = g_param_spec_boxed ("recv-audio-codecs",
335 "recvs audio codec", "Codecs used to decode the incoming audio stream",
337 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
338 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
341 param_spec = g_param_spec_boxed ("recv-video-codecs",
342 "recvs video codec", "Codecs used to decode the incoming video stream",
344 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
345 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
348 param_spec = g_param_spec_boxed ("audio-remote-candidate",
349 "audio remote candidate",
350 "Remote candidate used for the audio stream",
352 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
353 g_object_class_install_property (object_class,
354 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
356 param_spec = g_param_spec_boxed ("video-remote-candidate",
357 "video remote candidate",
358 "Remote candidate used for the video stream",
360 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
361 g_object_class_install_property (object_class,
362 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
364 param_spec = g_param_spec_boxed ("audio-local-candidate",
365 "audio local candidate",
366 "Local candidate used for the audio stream",
368 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
369 g_object_class_install_property (object_class,
370 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
372 param_spec = g_param_spec_boxed ("video-local-candidate",
373 "video local candidate",
374 "Local candidate used for the video stream",
376 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
377 g_object_class_install_property (object_class,
378 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
380 signals[CONFERENCE_ADDED] =
381 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
382 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
383 g_cclosure_marshal_generic,
385 1, FS_TYPE_CONFERENCE);
387 signals[CONFERENCE_REMOVED] =
388 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
389 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
390 g_cclosure_marshal_generic,
392 1, FS_TYPE_CONFERENCE);
394 signals[SRC_PAD_ADDED] =
395 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
396 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
397 g_cclosure_marshal_generic,
399 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
401 signals[CONTENT_ADDED] =
402 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
403 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
404 g_cclosure_marshal_generic,
408 signals[CONTENT_REMOVED] =
409 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
410 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
411 g_cclosure_marshal_generic,
416 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
417 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
418 g_cclosure_marshal_generic,
422 signals[CANDIDATES_CHANGED] =
423 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
424 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
425 g_cclosure_marshal_generic,
426 G_TYPE_NONE, 1, G_TYPE_UINT);
428 signals[STATE_CHANGED] =
429 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
430 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
431 g_cclosure_marshal_generic,
432 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
434 signals[FRAMERATE_CHANGED] =
435 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
436 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
437 g_cclosure_marshal_generic,
438 G_TYPE_NONE, 1, G_TYPE_UINT);
440 signals[RESOLUTION_CHANGED] =
441 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
442 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
443 g_cclosure_marshal_generic,
445 2, G_TYPE_UINT, G_TYPE_UINT);
449 empathy_call_handler_new_for_channel (TpCallChannel *call,
450 EmpathyContact *contact)
452 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
453 "call-channel", call,
454 "initial-video", tp_call_channel_has_initial_video (call, NULL),
455 "target-contact", contact,
460 update_sending_codec (EmpathyCallHandler *self,
464 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
467 if (codec == NULL || session == NULL)
470 g_object_get (session, "media-type", &type, NULL);
472 if (type == FS_MEDIA_TYPE_AUDIO)
474 priv->send_audio_codec = fs_codec_copy (codec);
475 g_object_notify (G_OBJECT (self), "send-audio-codec");
477 else if (type == FS_MEDIA_TYPE_VIDEO)
479 priv->send_video_codec = fs_codec_copy (codec);
480 g_object_notify (G_OBJECT (self), "send-video-codec");
485 update_receiving_codec (EmpathyCallHandler *self,
489 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
493 if (codecs == NULL || stream == NULL)
496 g_object_get (stream, "session", &session, NULL);
500 g_object_get (session, "media-type", &type, NULL);
502 if (type == FS_MEDIA_TYPE_AUDIO)
504 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
505 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
507 else if (type == FS_MEDIA_TYPE_VIDEO)
509 priv->recv_video_codecs = fs_codec_list_copy (codecs);
510 g_object_notify (G_OBJECT (self), "recv-video-codecs");
513 g_object_unref (session);
517 update_candidates (EmpathyCallHandler *self,
518 FsCandidate *remote_candidate,
519 FsCandidate *local_candidate,
522 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
529 g_object_get (stream, "session", &session, NULL);
533 g_object_get (session, "media-type", &type, NULL);
535 if (type == FS_MEDIA_TYPE_AUDIO)
537 if (remote_candidate != NULL)
539 fs_candidate_destroy (priv->audio_remote_candidate);
540 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
541 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
544 if (local_candidate != NULL)
546 fs_candidate_destroy (priv->audio_local_candidate);
547 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
548 g_object_notify (G_OBJECT (self), "audio-local-candidate");
551 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
552 FS_MEDIA_TYPE_AUDIO);
554 else if (type == FS_MEDIA_TYPE_VIDEO)
556 if (remote_candidate != NULL)
558 fs_candidate_destroy (priv->video_remote_candidate);
559 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
560 g_object_notify (G_OBJECT (self), "video-remote-candidate");
563 if (local_candidate != NULL)
565 fs_candidate_destroy (priv->video_local_candidate);
566 priv->video_local_candidate = fs_candidate_copy (local_candidate);
567 g_object_notify (G_OBJECT (self), "video-local-candidate");
570 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
571 FS_MEDIA_TYPE_VIDEO);
574 g_object_unref (session);
578 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
579 GstBus *bus, GstMessage *message)
581 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
582 const GstStructure *s = gst_message_get_structure (message);
584 if (priv->tfchannel == NULL)
588 gst_structure_has_name (s, "farsight-send-codec-changed"))
594 DEBUG ("farsight-send-codec-changed");
596 val = gst_structure_get_value (s, "codec");
597 codec = g_value_get_boxed (val);
599 val = gst_structure_get_value (s, "session");
600 session = g_value_get_object (val);
602 update_sending_codec (handler, codec, session);
604 else if (s != NULL &&
605 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
611 DEBUG ("farsight-recv-codecs-changed");
613 val = gst_structure_get_value (s, "codecs");
614 codecs = g_value_get_boxed (val);
616 val = gst_structure_get_value (s, "stream");
617 stream = g_value_get_object (val);
619 update_receiving_codec (handler, codecs, stream);
621 else if (s != NULL &&
622 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
625 FsCandidate *remote_candidate, *local_candidate;
628 DEBUG ("farsight-new-active-candidate-pair");
630 val = gst_structure_get_value (s, "remote-candidate");
631 remote_candidate = g_value_get_boxed (val);
633 val = gst_structure_get_value (s, "local-candidate");
634 local_candidate = g_value_get_boxed (val);
636 val = gst_structure_get_value (s, "stream");
637 stream = g_value_get_object (val);
639 update_candidates (handler, remote_candidate, local_candidate, stream);
642 tf_channel_bus_message (priv->tfchannel, message);
646 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
647 GstElement *conference,
648 EmpathyCallHandler *self)
650 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
655 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
656 FsConference *conference,
657 EmpathyCallHandler *self)
659 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
660 GST_ELEMENT (conference));
664 src_pad_added_error_idle (gpointer data)
666 TfContent *content = data;
668 tf_content_error_literal (content, "Could not link sink");
669 g_object_unref (content);
675 on_tf_content_src_pad_added_cb (TfContent *content,
680 EmpathyCallHandler *handler)
684 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
685 content, pad, &retval);
688 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
692 on_tf_content_framerate_changed (TfContent *content,
694 EmpathyCallHandler *handler)
698 g_object_get (content, "framerate", &framerate, NULL);
701 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
706 on_tf_content_resolution_changed (TfContent *content,
709 EmpathyCallHandler *handler)
711 if (width > 0 && height > 0)
712 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
717 on_tf_channel_content_added_cb (TfChannel *tfchannel,
719 EmpathyCallHandler *handler)
723 // FsStream *fs_stream;
728 g_signal_connect (content, "src-pad-added",
729 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
731 g_signal_connect (content, "start-sending",
732 G_CALLBACK (on_tf_content_start_sending_cb), handler);
733 g_signal_connect (content, "stop-sending",
734 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
737 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
741 tf_content_error_literal (content, "Could not link source");
743 /* Get sending codec */
744 g_object_get (content, "fs-session", &session, NULL);
745 g_object_get (session, "current-send-codec", &codec, NULL);
747 update_sending_codec (handler, codec, session);
749 tp_clear_object (&session);
750 tp_clear_object (&codec);
752 /* Get receiving codec */
754 g_object_get (content, "fs-stream", &fs_stream, NULL);
755 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
757 update_receiving_codec (handler, codecs, fs_stream);
759 fs_codec_list_destroy (codecs);
760 tp_clear_object (&fs_stream);
763 g_object_get (content, "media-type", &mtype, NULL);
765 if (mtype == FS_MEDIA_TYPE_VIDEO)
767 guint framerate, width, height;
769 g_signal_connect (content, "notify::framerate",
770 G_CALLBACK (on_tf_content_framerate_changed),
773 g_signal_connect (content, "resolution-changed",
774 G_CALLBACK (on_tf_content_resolution_changed),
777 g_object_get (content,
778 "framerate", &framerate,
784 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
787 if (width > 0 && height > 0)
788 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
794 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
796 EmpathyCallHandler *handler)
800 DEBUG ("removing content");
802 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
807 g_warning ("Could not remove content!");
809 tf_content_error_literal (content, "Could not link source");
814 on_tf_channel_closed_cb (TfChannel *tfchannel,
815 EmpathyCallHandler *handler)
817 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
821 on_tf_channel_ready (GObject *source,
822 GAsyncResult *result,
825 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
826 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
827 GError *error = NULL;
829 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
830 G_ASYNC_INITABLE (source), result, NULL));
832 if (priv->tfchannel == NULL)
834 g_warning ("Failed to create Farstream channel: %s", error->message);
835 g_error_free (error);
839 /* Set up the telepathy farstream channel */
840 g_signal_connect (priv->tfchannel, "closed",
841 G_CALLBACK (on_tf_channel_closed_cb), self);
842 g_signal_connect (priv->tfchannel, "fs-conference-added",
843 G_CALLBACK (on_tf_channel_conference_added_cb), self);
844 g_signal_connect (priv->tfchannel, "fs-conference-removed",
845 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
846 g_signal_connect (priv->tfchannel, "content-added",
847 G_CALLBACK (on_tf_channel_content_added_cb), self);
848 g_signal_connect (priv->tfchannel, "content-removed",
849 G_CALLBACK (on_tf_channel_content_removed_cb), self);
853 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
855 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
857 tf_channel_new_async (TP_CHANNEL (priv->call),
858 on_tf_channel_ready, self);
862 empathy_call_handler_request_cb (GObject *source,
863 GAsyncResult *result,
866 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
867 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
869 GError *error = NULL;
870 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
872 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
873 result, NULL, &error);
876 DEBUG ("Failed to create the channel: %s", error->message);
877 g_error_free (error);
881 if (!TP_IS_CALL_CHANNEL (channel))
883 DEBUG ("The channel is not a Call channel!");
887 priv->call = TP_CALL_CHANNEL (channel);
888 tp_g_signal_connect_object (priv->call, "state-changed",
889 G_CALLBACK (on_call_state_changed_cb), self, 0);
890 tp_g_signal_connect_object (priv->call, "invalidated",
891 G_CALLBACK (on_call_invalidated_cb), self, 0);
893 g_object_notify (G_OBJECT (self), "call-channel");
895 empathy_call_handler_start_tpfs (self);
896 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
900 empathy_call_handler_start_call (EmpathyCallHandler *handler,
903 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
904 TpAccountChannelRequest *req;
908 if (priv->call != NULL)
910 empathy_call_handler_start_tpfs (handler);
912 if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
914 /* accept outgoing channels immediately */
915 tp_call_channel_accept_async (priv->call,
916 on_call_accepted_cb, NULL);
920 /* accepting incoming channels when they are INITIALISED */
921 if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
922 TP_CALL_STATE_INITIALISED)
923 tp_call_channel_accept_async (priv->call,
924 on_call_accepted_cb, NULL);
926 priv->accept_when_initialised = TRUE;
932 /* No TpCallChannel (we are redialing). Request a new call channel */
933 g_assert (priv->contact != NULL);
935 account = empathy_contact_get_account (priv->contact);
936 request = empathy_call_create_call_request (
937 empathy_contact_get_id (priv->contact),
938 priv->initial_audio, priv->initial_video);
940 req = tp_account_channel_request_new (account, request, timestamp);
942 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
943 empathy_call_handler_request_cb, handler);
945 g_object_unref (req);
946 g_hash_table_unref (request);
950 * empathy_call_handler_stop_call:
951 * @handler: an #EmpathyCallHandler
953 * Closes the #EmpathyCallHandler's call and frees its resources.
956 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
958 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
960 if (priv->call != NULL)
962 tp_call_channel_hangup_async (priv->call,
963 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
969 * empathy_call_handler_has_initial_video:
970 * @handler: an #EmpathyCallHandler
972 * Return %TRUE if the call managed by this #EmpathyCallHandler was
973 * created with video enabled
975 * Return value: %TRUE if the call was created as a video conversation.
978 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
980 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
982 return priv->initial_video;
986 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
988 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
990 return priv->send_audio_codec;
994 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
996 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
998 return priv->send_video_codec;
1002 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1004 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1006 return priv->recv_audio_codecs;
1010 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1012 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1014 return priv->recv_video_codecs;
1018 empathy_call_handler_get_audio_remote_candidate (
1019 EmpathyCallHandler *self)
1021 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1023 return priv->audio_remote_candidate;
1027 empathy_call_handler_get_audio_local_candidate (
1028 EmpathyCallHandler *self)
1030 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1032 return priv->audio_local_candidate;
1036 empathy_call_handler_get_video_remote_candidate (
1037 EmpathyCallHandler *self)
1039 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1041 return priv->video_remote_candidate;
1045 empathy_call_handler_get_video_local_candidate (
1046 EmpathyCallHandler *self)
1048 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1050 return priv->video_local_candidate;
1054 empathy_call_handler_get_contact (EmpathyCallHandler *self)
1056 return self->priv->contact;