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 /* Clean up the TfChannel before bubbling the state-change signal
181 * further up. This ensures that the conference-removed signal is
182 * emitted before state-changed so that the client gets a chance
183 * to remove the conference from the pipeline before resetting the
186 if (state == TP_CALL_STATE_ENDED)
188 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
189 priv->accept_when_initialised = FALSE;
190 tp_clear_object (&priv->call);
191 tp_clear_object (&priv->tfchannel);
194 g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
195 reason->dbus_reason);
197 if (state == TP_CALL_STATE_INITIALISED &&
198 priv->accept_when_initialised)
200 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
201 priv->accept_when_initialised = FALSE;
206 empathy_call_handler_set_property (GObject *object,
207 guint property_id, const GValue *value, GParamSpec *pspec)
209 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
214 priv->contact = g_value_dup_object (value);
216 case PROP_CALL_CHANNEL:
217 g_return_if_fail (priv->call == NULL);
219 priv->call = g_value_dup_object (value);
221 tp_g_signal_connect_object (priv->call, "state-changed",
222 G_CALLBACK (on_call_state_changed_cb), object, 0);
223 tp_g_signal_connect_object (priv->call, "invalidated",
224 G_CALLBACK (on_call_invalidated_cb), object, 0);
226 case PROP_INITIAL_AUDIO:
227 priv->initial_audio = g_value_get_boolean (value);
229 case PROP_INITIAL_VIDEO:
230 priv->initial_video = g_value_get_boolean (value);
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
238 empathy_call_handler_get_property (GObject *object,
239 guint property_id, GValue *value, GParamSpec *pspec)
241 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
246 g_value_set_object (value, priv->contact);
248 case PROP_CALL_CHANNEL:
249 g_value_set_object (value, priv->call);
251 case PROP_INITIAL_AUDIO:
252 g_value_set_boolean (value, priv->initial_audio);
254 case PROP_INITIAL_VIDEO:
255 g_value_set_boolean (value, priv->initial_video);
257 case PROP_SEND_AUDIO_CODEC:
258 g_value_set_boxed (value, priv->send_audio_codec);
260 case PROP_SEND_VIDEO_CODEC:
261 g_value_set_boxed (value, priv->send_video_codec);
263 case PROP_RECV_AUDIO_CODECS:
264 g_value_set_boxed (value, priv->recv_audio_codecs);
266 case PROP_RECV_VIDEO_CODECS:
267 g_value_set_boxed (value, priv->recv_video_codecs);
269 case PROP_AUDIO_REMOTE_CANDIDATE:
270 g_value_set_boxed (value, priv->audio_remote_candidate);
272 case PROP_VIDEO_REMOTE_CANDIDATE:
273 g_value_set_boxed (value, priv->video_remote_candidate);
275 case PROP_AUDIO_LOCAL_CANDIDATE:
276 g_value_set_boxed (value, priv->audio_local_candidate);
278 case PROP_VIDEO_LOCAL_CANDIDATE:
279 g_value_set_boxed (value, priv->video_local_candidate);
282 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
288 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
290 GObjectClass *object_class = G_OBJECT_CLASS (klass);
291 GParamSpec *param_spec;
293 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
295 object_class->set_property = empathy_call_handler_set_property;
296 object_class->get_property = empathy_call_handler_get_property;
297 object_class->dispose = empathy_call_handler_dispose;
298 object_class->finalize = empathy_call_handler_finalize;
300 param_spec = g_param_spec_object ("target-contact",
301 "TargetContact", "The contact",
302 EMPATHY_TYPE_CONTACT,
303 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
304 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
306 param_spec = g_param_spec_object ("call-channel",
307 "call channel", "The call channel",
308 TP_TYPE_CALL_CHANNEL,
309 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
310 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
312 param_spec = g_param_spec_boolean ("initial-audio",
313 "initial-audio", "Whether the call should start with audio",
315 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
316 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
319 param_spec = g_param_spec_boolean ("initial-video",
320 "initial-video", "Whether the call should start with video",
322 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
323 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
326 param_spec = g_param_spec_boxed ("send-audio-codec",
327 "send audio 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_AUDIO_CODEC,
333 param_spec = g_param_spec_boxed ("send-video-codec",
334 "send video codec", "Codec used to encode the outgoing video stream",
336 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
337 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
340 param_spec = g_param_spec_boxed ("recv-audio-codecs",
341 "recvs audio codec", "Codecs used to decode the incoming audio stream",
343 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
344 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
347 param_spec = g_param_spec_boxed ("recv-video-codecs",
348 "recvs video codec", "Codecs used to decode the incoming video stream",
350 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
351 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
354 param_spec = g_param_spec_boxed ("audio-remote-candidate",
355 "audio remote candidate",
356 "Remote candidate used for the audio stream",
358 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
359 g_object_class_install_property (object_class,
360 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
362 param_spec = g_param_spec_boxed ("video-remote-candidate",
363 "video remote candidate",
364 "Remote candidate used for the video stream",
366 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
367 g_object_class_install_property (object_class,
368 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
370 param_spec = g_param_spec_boxed ("audio-local-candidate",
371 "audio local candidate",
372 "Local candidate used for the audio stream",
374 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
375 g_object_class_install_property (object_class,
376 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
378 param_spec = g_param_spec_boxed ("video-local-candidate",
379 "video local candidate",
380 "Local candidate used for the video stream",
382 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
383 g_object_class_install_property (object_class,
384 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
386 signals[CONFERENCE_ADDED] =
387 g_signal_new ("conference-added", 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[CONFERENCE_REMOVED] =
394 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
395 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
396 g_cclosure_marshal_generic,
398 1, FS_TYPE_CONFERENCE);
400 signals[SRC_PAD_ADDED] =
401 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
402 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
403 g_cclosure_marshal_generic,
405 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
407 signals[CONTENT_ADDED] =
408 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
409 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
410 g_cclosure_marshal_generic,
414 signals[CONTENT_REMOVED] =
415 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
416 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
417 g_cclosure_marshal_generic,
422 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
423 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
424 g_cclosure_marshal_generic,
428 signals[CANDIDATES_CHANGED] =
429 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
430 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
431 g_cclosure_marshal_generic,
432 G_TYPE_NONE, 1, G_TYPE_UINT);
434 signals[STATE_CHANGED] =
435 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
436 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
437 g_cclosure_marshal_generic,
438 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
440 signals[FRAMERATE_CHANGED] =
441 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
442 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
443 g_cclosure_marshal_generic,
444 G_TYPE_NONE, 1, G_TYPE_UINT);
446 signals[RESOLUTION_CHANGED] =
447 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
448 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
449 g_cclosure_marshal_generic,
451 2, G_TYPE_UINT, G_TYPE_UINT);
455 empathy_call_handler_new_for_channel (TpCallChannel *call,
456 EmpathyContact *contact)
458 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
459 "call-channel", call,
460 "initial-video", tp_call_channel_has_initial_video (call, NULL),
461 "target-contact", contact,
466 update_sending_codec (EmpathyCallHandler *self,
470 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
473 if (codec == NULL || session == NULL)
476 g_object_get (session, "media-type", &type, NULL);
478 if (type == FS_MEDIA_TYPE_AUDIO)
480 priv->send_audio_codec = fs_codec_copy (codec);
481 g_object_notify (G_OBJECT (self), "send-audio-codec");
483 else if (type == FS_MEDIA_TYPE_VIDEO)
485 priv->send_video_codec = fs_codec_copy (codec);
486 g_object_notify (G_OBJECT (self), "send-video-codec");
491 update_receiving_codec (EmpathyCallHandler *self,
495 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
499 if (codecs == NULL || stream == NULL)
502 g_object_get (stream, "session", &session, NULL);
506 g_object_get (session, "media-type", &type, NULL);
508 if (type == FS_MEDIA_TYPE_AUDIO)
510 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
511 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
513 else if (type == FS_MEDIA_TYPE_VIDEO)
515 priv->recv_video_codecs = fs_codec_list_copy (codecs);
516 g_object_notify (G_OBJECT (self), "recv-video-codecs");
519 g_object_unref (session);
523 update_candidates (EmpathyCallHandler *self,
524 FsCandidate *remote_candidate,
525 FsCandidate *local_candidate,
528 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
535 g_object_get (stream, "session", &session, NULL);
539 g_object_get (session, "media-type", &type, NULL);
541 if (type == FS_MEDIA_TYPE_AUDIO)
543 if (remote_candidate != NULL)
545 fs_candidate_destroy (priv->audio_remote_candidate);
546 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
547 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
550 if (local_candidate != NULL)
552 fs_candidate_destroy (priv->audio_local_candidate);
553 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
554 g_object_notify (G_OBJECT (self), "audio-local-candidate");
557 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
558 FS_MEDIA_TYPE_AUDIO);
560 else if (type == FS_MEDIA_TYPE_VIDEO)
562 if (remote_candidate != NULL)
564 fs_candidate_destroy (priv->video_remote_candidate);
565 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
566 g_object_notify (G_OBJECT (self), "video-remote-candidate");
569 if (local_candidate != NULL)
571 fs_candidate_destroy (priv->video_local_candidate);
572 priv->video_local_candidate = fs_candidate_copy (local_candidate);
573 g_object_notify (G_OBJECT (self), "video-local-candidate");
576 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
577 FS_MEDIA_TYPE_VIDEO);
580 g_object_unref (session);
584 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
585 GstBus *bus, GstMessage *message)
587 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
588 const GstStructure *s = gst_message_get_structure (message);
590 if (priv->tfchannel == NULL)
594 gst_structure_has_name (s, "farsight-send-codec-changed"))
600 DEBUG ("farsight-send-codec-changed");
602 val = gst_structure_get_value (s, "codec");
603 codec = g_value_get_boxed (val);
605 val = gst_structure_get_value (s, "session");
606 session = g_value_get_object (val);
608 update_sending_codec (handler, codec, session);
610 else if (s != NULL &&
611 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
617 DEBUG ("farsight-recv-codecs-changed");
619 val = gst_structure_get_value (s, "codecs");
620 codecs = g_value_get_boxed (val);
622 val = gst_structure_get_value (s, "stream");
623 stream = g_value_get_object (val);
625 update_receiving_codec (handler, codecs, stream);
627 else if (s != NULL &&
628 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
631 FsCandidate *remote_candidate, *local_candidate;
634 DEBUG ("farsight-new-active-candidate-pair");
636 val = gst_structure_get_value (s, "remote-candidate");
637 remote_candidate = g_value_get_boxed (val);
639 val = gst_structure_get_value (s, "local-candidate");
640 local_candidate = g_value_get_boxed (val);
642 val = gst_structure_get_value (s, "stream");
643 stream = g_value_get_object (val);
645 update_candidates (handler, remote_candidate, local_candidate, stream);
648 tf_channel_bus_message (priv->tfchannel, message);
652 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
653 GstElement *conference,
654 EmpathyCallHandler *self)
656 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
661 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
662 FsConference *conference,
663 EmpathyCallHandler *self)
665 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
666 GST_ELEMENT (conference));
670 src_pad_added_error_idle (gpointer data)
672 TfContent *content = data;
674 tf_content_error_literal (content, "Could not link sink");
675 g_object_unref (content);
681 on_tf_content_src_pad_added_cb (TfContent *content,
686 EmpathyCallHandler *handler)
690 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
691 content, pad, &retval);
694 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
698 on_tf_content_framerate_changed (TfContent *content,
700 EmpathyCallHandler *handler)
704 g_object_get (content, "framerate", &framerate, NULL);
707 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
712 on_tf_content_resolution_changed (TfContent *content,
715 EmpathyCallHandler *handler)
717 if (width > 0 && height > 0)
718 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
723 on_tf_channel_content_added_cb (TfChannel *tfchannel,
725 EmpathyCallHandler *handler)
729 // FsStream *fs_stream;
734 g_signal_connect (content, "src-pad-added",
735 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
737 g_signal_connect (content, "start-sending",
738 G_CALLBACK (on_tf_content_start_sending_cb), handler);
739 g_signal_connect (content, "stop-sending",
740 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
743 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
747 tf_content_error_literal (content, "Could not link source");
749 /* Get sending codec */
750 g_object_get (content, "fs-session", &session, NULL);
751 g_object_get (session, "current-send-codec", &codec, NULL);
753 update_sending_codec (handler, codec, session);
755 tp_clear_object (&session);
756 tp_clear_object (&codec);
758 /* Get receiving codec */
760 g_object_get (content, "fs-stream", &fs_stream, NULL);
761 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
763 update_receiving_codec (handler, codecs, fs_stream);
765 fs_codec_list_destroy (codecs);
766 tp_clear_object (&fs_stream);
769 g_object_get (content, "media-type", &mtype, NULL);
771 if (mtype == FS_MEDIA_TYPE_VIDEO)
773 guint framerate, width, height;
775 g_signal_connect (content, "notify::framerate",
776 G_CALLBACK (on_tf_content_framerate_changed),
779 g_signal_connect (content, "resolution-changed",
780 G_CALLBACK (on_tf_content_resolution_changed),
783 g_object_get (content,
784 "framerate", &framerate,
790 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
793 if (width > 0 && height > 0)
794 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
800 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
802 EmpathyCallHandler *handler)
806 DEBUG ("removing content");
808 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
813 g_warning ("Could not remove content!");
815 tf_content_error_literal (content, "Could not link source");
820 on_tf_channel_closed_cb (TfChannel *tfchannel,
821 EmpathyCallHandler *handler)
823 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
827 on_tf_channel_ready (GObject *source,
828 GAsyncResult *result,
831 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
832 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
833 GError *error = NULL;
835 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
836 G_ASYNC_INITABLE (source), result, NULL));
838 if (priv->tfchannel == NULL)
840 g_warning ("Failed to create Farstream channel: %s", error->message);
841 g_error_free (error);
845 /* Set up the telepathy farstream channel */
846 g_signal_connect (priv->tfchannel, "closed",
847 G_CALLBACK (on_tf_channel_closed_cb), self);
848 g_signal_connect (priv->tfchannel, "fs-conference-added",
849 G_CALLBACK (on_tf_channel_conference_added_cb), self);
850 g_signal_connect (priv->tfchannel, "fs-conference-removed",
851 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
852 g_signal_connect (priv->tfchannel, "content-added",
853 G_CALLBACK (on_tf_channel_content_added_cb), self);
854 g_signal_connect (priv->tfchannel, "content-removed",
855 G_CALLBACK (on_tf_channel_content_removed_cb), self);
859 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
861 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
863 tf_channel_new_async (TP_CHANNEL (priv->call),
864 on_tf_channel_ready, self);
868 empathy_call_handler_request_cb (GObject *source,
869 GAsyncResult *result,
872 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
873 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
875 GError *error = NULL;
876 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
878 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
879 result, NULL, &error);
882 DEBUG ("Failed to create the channel: %s", error->message);
883 g_error_free (error);
887 if (!TP_IS_CALL_CHANNEL (channel))
889 DEBUG ("The channel is not a Call channel!");
893 priv->call = TP_CALL_CHANNEL (channel);
894 tp_g_signal_connect_object (priv->call, "state-changed",
895 G_CALLBACK (on_call_state_changed_cb), self, 0);
896 tp_g_signal_connect_object (priv->call, "invalidated",
897 G_CALLBACK (on_call_invalidated_cb), self, 0);
899 g_object_notify (G_OBJECT (self), "call-channel");
901 empathy_call_handler_start_tpfs (self);
902 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
906 empathy_call_handler_start_call (EmpathyCallHandler *handler,
909 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
910 TpAccountChannelRequest *req;
914 if (priv->call != NULL)
916 empathy_call_handler_start_tpfs (handler);
918 if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
920 /* accept outgoing channels immediately */
921 tp_call_channel_accept_async (priv->call,
922 on_call_accepted_cb, NULL);
926 /* accepting incoming channels when they are INITIALISED */
927 if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
928 TP_CALL_STATE_INITIALISED)
929 tp_call_channel_accept_async (priv->call,
930 on_call_accepted_cb, NULL);
932 priv->accept_when_initialised = TRUE;
938 /* No TpCallChannel (we are redialing). Request a new call channel */
939 g_assert (priv->contact != NULL);
941 account = empathy_contact_get_account (priv->contact);
942 request = empathy_call_create_call_request (
943 empathy_contact_get_id (priv->contact),
944 priv->initial_audio, priv->initial_video);
946 req = tp_account_channel_request_new (account, request, timestamp);
948 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
949 empathy_call_handler_request_cb, handler);
951 g_object_unref (req);
952 g_hash_table_unref (request);
956 * empathy_call_handler_stop_call:
957 * @handler: an #EmpathyCallHandler
959 * Closes the #EmpathyCallHandler's call and frees its resources.
962 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
964 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
966 if (priv->call != NULL)
968 tp_call_channel_hangup_async (priv->call,
969 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
975 * empathy_call_handler_has_initial_video:
976 * @handler: an #EmpathyCallHandler
978 * Return %TRUE if the call managed by this #EmpathyCallHandler was
979 * created with video enabled
981 * Return value: %TRUE if the call was created as a video conversation.
984 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
986 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
988 return priv->initial_video;
992 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
994 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
996 return priv->send_audio_codec;
1000 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1002 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1004 return priv->send_video_codec;
1008 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1010 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1012 return priv->recv_audio_codecs;
1016 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1018 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1020 return priv->recv_video_codecs;
1024 empathy_call_handler_get_audio_remote_candidate (
1025 EmpathyCallHandler *self)
1027 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1029 return priv->audio_remote_candidate;
1033 empathy_call_handler_get_audio_local_candidate (
1034 EmpathyCallHandler *self)
1036 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1038 return priv->audio_local_candidate;
1042 empathy_call_handler_get_video_remote_candidate (
1043 EmpathyCallHandler *self)
1045 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1047 return priv->video_remote_candidate;
1051 empathy_call_handler_get_video_local_candidate (
1052 EmpathyCallHandler *self)
1054 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1056 return priv->video_local_candidate;
1060 empathy_call_handler_get_contact (EmpathyCallHandler *self)
1062 return self->priv->contact;