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
23 #include <telepathy-farstream/telepathy-farstream.h>
25 #include <libempathy/empathy-utils.h>
27 #include <libempathy-gtk/empathy-call-utils.h>
29 #include "empathy-call-handler.h"
31 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
32 #include <libempathy/empathy-debug.h>
34 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
51 static guint signals[LAST_SIGNAL] = {0};
54 PROP_CALL_CHANNEL = 1,
59 PROP_SEND_AUDIO_CODEC,
60 PROP_SEND_VIDEO_CODEC,
61 PROP_RECV_AUDIO_CODECS,
62 PROP_RECV_VIDEO_CODECS,
63 PROP_AUDIO_REMOTE_CANDIDATE,
64 PROP_VIDEO_REMOTE_CANDIDATE,
65 PROP_AUDIO_LOCAL_CANDIDATE,
66 PROP_VIDEO_LOCAL_CANDIDATE,
69 /* private structure */
71 struct _EmpathyCallHandlerPriv {
74 EmpathyContact *contact;
76 gboolean initial_audio;
77 gboolean initial_video;
79 FsCodec *send_audio_codec;
80 FsCodec *send_video_codec;
81 GList *recv_audio_codecs;
82 GList *recv_video_codecs;
83 FsCandidate *audio_remote_candidate;
84 FsCandidate *video_remote_candidate;
85 FsCandidate *audio_local_candidate;
86 FsCandidate *video_local_candidate;
87 gboolean accept_when_initialised;
90 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
93 empathy_call_handler_dispose (GObject *object)
95 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
97 tp_clear_object (&priv->tfchannel);
98 tp_clear_object (&priv->call);
99 tp_clear_object (&priv->contact);
101 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
105 empathy_call_handler_finalize (GObject *object)
107 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
109 fs_codec_destroy (priv->send_audio_codec);
110 fs_codec_destroy (priv->send_video_codec);
111 fs_codec_list_destroy (priv->recv_audio_codecs);
112 fs_codec_list_destroy (priv->recv_video_codecs);
113 fs_candidate_destroy (priv->audio_remote_candidate);
114 fs_candidate_destroy (priv->video_remote_candidate);
115 fs_candidate_destroy (priv->audio_local_candidate);
116 fs_candidate_destroy (priv->video_local_candidate);
118 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
122 empathy_call_handler_init (EmpathyCallHandler *obj)
124 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
125 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
131 on_call_accepted_cb (GObject *source_object,
135 TpCallChannel *call = TP_CALL_CHANNEL (source_object);
136 GError *error = NULL;
138 if (!tp_call_channel_accept_finish (call, res, &error))
140 g_warning ("could not accept Call: %s", error->message);
141 g_error_free (error);
146 on_call_invalidated_cb (TpCallChannel *call,
150 EmpathyCallHandler *self)
152 EmpathyCallHandlerPriv *priv = self->priv;
154 if (priv->call == call)
156 /* Invalidated unexpectedly? Fake call ending */
157 g_signal_emit (self, signals[STATE_CHANGED], 0,
158 TP_CALL_STATE_ENDED, NULL);
159 priv->accept_when_initialised = FALSE;
160 tp_clear_object (&priv->call);
161 tp_clear_object (&priv->tfchannel);
166 on_call_state_changed_cb (TpCallChannel *call,
169 TpCallStateReason *reason,
171 EmpathyCallHandler *handler)
173 EmpathyCallHandlerPriv *priv = handler->priv;
175 /* Clean up the TfChannel before bubbling the state-change signal
176 * further up. This ensures that the conference-removed signal is
177 * emitted before state-changed so that the client gets a chance
178 * to remove the conference from the pipeline before resetting the
181 if (state == TP_CALL_STATE_ENDED)
183 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
184 priv->accept_when_initialised = FALSE;
185 tp_clear_object (&priv->call);
186 tp_clear_object (&priv->tfchannel);
189 g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
190 reason->dbus_reason);
192 if (state == TP_CALL_STATE_INITIALISED &&
193 priv->accept_when_initialised)
195 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
196 priv->accept_when_initialised = FALSE;
201 empathy_call_handler_set_property (GObject *object,
202 guint property_id, const GValue *value, GParamSpec *pspec)
204 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
209 priv->contact = g_value_dup_object (value);
211 case PROP_CALL_CHANNEL:
212 g_return_if_fail (priv->call == NULL);
214 priv->call = g_value_dup_object (value);
216 tp_g_signal_connect_object (priv->call, "state-changed",
217 G_CALLBACK (on_call_state_changed_cb), object, 0);
218 tp_g_signal_connect_object (priv->call, "invalidated",
219 G_CALLBACK (on_call_invalidated_cb), object, 0);
221 case PROP_INITIAL_AUDIO:
222 priv->initial_audio = g_value_get_boolean (value);
224 case PROP_INITIAL_VIDEO:
225 priv->initial_video = g_value_get_boolean (value);
228 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
233 empathy_call_handler_get_property (GObject *object,
234 guint property_id, GValue *value, GParamSpec *pspec)
236 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
241 g_value_set_object (value, priv->contact);
243 case PROP_CALL_CHANNEL:
244 g_value_set_object (value, priv->call);
246 case PROP_INITIAL_AUDIO:
247 g_value_set_boolean (value, priv->initial_audio);
249 case PROP_INITIAL_VIDEO:
250 g_value_set_boolean (value, priv->initial_video);
252 case PROP_SEND_AUDIO_CODEC:
253 g_value_set_boxed (value, priv->send_audio_codec);
255 case PROP_SEND_VIDEO_CODEC:
256 g_value_set_boxed (value, priv->send_video_codec);
258 case PROP_RECV_AUDIO_CODECS:
259 g_value_set_boxed (value, priv->recv_audio_codecs);
261 case PROP_RECV_VIDEO_CODECS:
262 g_value_set_boxed (value, priv->recv_video_codecs);
264 case PROP_AUDIO_REMOTE_CANDIDATE:
265 g_value_set_boxed (value, priv->audio_remote_candidate);
267 case PROP_VIDEO_REMOTE_CANDIDATE:
268 g_value_set_boxed (value, priv->video_remote_candidate);
270 case PROP_AUDIO_LOCAL_CANDIDATE:
271 g_value_set_boxed (value, priv->audio_local_candidate);
273 case PROP_VIDEO_LOCAL_CANDIDATE:
274 g_value_set_boxed (value, priv->video_local_candidate);
277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
283 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
285 GObjectClass *object_class = G_OBJECT_CLASS (klass);
286 GParamSpec *param_spec;
288 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
290 object_class->set_property = empathy_call_handler_set_property;
291 object_class->get_property = empathy_call_handler_get_property;
292 object_class->dispose = empathy_call_handler_dispose;
293 object_class->finalize = empathy_call_handler_finalize;
295 param_spec = g_param_spec_object ("target-contact",
296 "TargetContact", "The contact",
297 EMPATHY_TYPE_CONTACT,
298 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
299 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
301 param_spec = g_param_spec_object ("call-channel",
302 "call channel", "The call channel",
303 TP_TYPE_CALL_CHANNEL,
304 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
305 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
307 param_spec = g_param_spec_boolean ("initial-audio",
308 "initial-audio", "Whether the call should start with audio",
310 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
311 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
314 param_spec = g_param_spec_boolean ("initial-video",
315 "initial-video", "Whether the call should start with video",
317 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
318 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
321 param_spec = g_param_spec_boxed ("send-audio-codec",
322 "send audio codec", "Codec used to encode the outgoing video stream",
324 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
325 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
328 param_spec = g_param_spec_boxed ("send-video-codec",
329 "send video codec", "Codec used to encode the outgoing video stream",
331 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
332 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
335 param_spec = g_param_spec_boxed ("recv-audio-codecs",
336 "recvs audio codec", "Codecs used to decode the incoming audio stream",
338 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
339 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
342 param_spec = g_param_spec_boxed ("recv-video-codecs",
343 "recvs video codec", "Codecs used to decode the incoming video stream",
345 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
346 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
349 param_spec = g_param_spec_boxed ("audio-remote-candidate",
350 "audio remote candidate",
351 "Remote candidate used for the audio stream",
353 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
354 g_object_class_install_property (object_class,
355 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
357 param_spec = g_param_spec_boxed ("video-remote-candidate",
358 "video remote candidate",
359 "Remote candidate used for the video stream",
361 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
362 g_object_class_install_property (object_class,
363 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
365 param_spec = g_param_spec_boxed ("audio-local-candidate",
366 "audio local candidate",
367 "Local candidate used for the audio stream",
369 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
370 g_object_class_install_property (object_class,
371 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
373 param_spec = g_param_spec_boxed ("video-local-candidate",
374 "video local candidate",
375 "Local candidate used for the video stream",
377 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
378 g_object_class_install_property (object_class,
379 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
381 signals[CONFERENCE_ADDED] =
382 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
383 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
384 g_cclosure_marshal_generic,
386 1, FS_TYPE_CONFERENCE);
388 signals[CONFERENCE_REMOVED] =
389 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
390 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
391 g_cclosure_marshal_generic,
393 1, FS_TYPE_CONFERENCE);
395 signals[SRC_PAD_ADDED] =
396 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
397 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
398 g_cclosure_marshal_generic,
400 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
402 signals[CONTENT_ADDED] =
403 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
404 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
405 g_cclosure_marshal_generic,
409 signals[CONTENT_REMOVED] =
410 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
411 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
412 g_cclosure_marshal_generic,
417 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
418 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
419 g_cclosure_marshal_generic,
423 signals[CANDIDATES_CHANGED] =
424 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
425 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
426 g_cclosure_marshal_generic,
427 G_TYPE_NONE, 1, G_TYPE_UINT);
429 signals[STATE_CHANGED] =
430 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
431 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
432 g_cclosure_marshal_generic,
433 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
435 signals[FRAMERATE_CHANGED] =
436 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
437 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
438 g_cclosure_marshal_generic,
439 G_TYPE_NONE, 1, G_TYPE_UINT);
441 signals[RESOLUTION_CHANGED] =
442 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
443 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
444 g_cclosure_marshal_generic,
446 2, G_TYPE_UINT, G_TYPE_UINT);
450 empathy_call_handler_new_for_channel (TpCallChannel *call,
451 EmpathyContact *contact)
453 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
454 "call-channel", call,
455 "initial-video", tp_call_channel_has_initial_video (call, NULL),
456 "target-contact", contact,
461 update_sending_codec (EmpathyCallHandler *self,
465 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
468 if (codec == NULL || session == NULL)
471 g_object_get (session, "media-type", &type, NULL);
473 if (type == FS_MEDIA_TYPE_AUDIO)
475 priv->send_audio_codec = fs_codec_copy (codec);
476 g_object_notify (G_OBJECT (self), "send-audio-codec");
478 else if (type == FS_MEDIA_TYPE_VIDEO)
480 priv->send_video_codec = fs_codec_copy (codec);
481 g_object_notify (G_OBJECT (self), "send-video-codec");
486 update_receiving_codec (EmpathyCallHandler *self,
490 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
494 if (codecs == NULL || stream == NULL)
497 g_object_get (stream, "session", &session, NULL);
501 g_object_get (session, "media-type", &type, NULL);
503 if (type == FS_MEDIA_TYPE_AUDIO)
505 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
506 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
508 else if (type == FS_MEDIA_TYPE_VIDEO)
510 priv->recv_video_codecs = fs_codec_list_copy (codecs);
511 g_object_notify (G_OBJECT (self), "recv-video-codecs");
514 g_object_unref (session);
518 update_candidates (EmpathyCallHandler *self,
519 FsCandidate *remote_candidate,
520 FsCandidate *local_candidate,
523 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
530 g_object_get (stream, "session", &session, NULL);
534 g_object_get (session, "media-type", &type, NULL);
536 if (type == FS_MEDIA_TYPE_AUDIO)
538 if (remote_candidate != NULL)
540 fs_candidate_destroy (priv->audio_remote_candidate);
541 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
542 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
545 if (local_candidate != NULL)
547 fs_candidate_destroy (priv->audio_local_candidate);
548 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
549 g_object_notify (G_OBJECT (self), "audio-local-candidate");
552 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
553 FS_MEDIA_TYPE_AUDIO);
555 else if (type == FS_MEDIA_TYPE_VIDEO)
557 if (remote_candidate != NULL)
559 fs_candidate_destroy (priv->video_remote_candidate);
560 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
561 g_object_notify (G_OBJECT (self), "video-remote-candidate");
564 if (local_candidate != NULL)
566 fs_candidate_destroy (priv->video_local_candidate);
567 priv->video_local_candidate = fs_candidate_copy (local_candidate);
568 g_object_notify (G_OBJECT (self), "video-local-candidate");
571 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
572 FS_MEDIA_TYPE_VIDEO);
575 g_object_unref (session);
579 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
580 GstBus *bus, GstMessage *message)
582 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
583 const GstStructure *s = gst_message_get_structure (message);
585 if (priv->tfchannel == NULL)
589 gst_structure_has_name (s, "farsight-send-codec-changed"))
595 DEBUG ("farsight-send-codec-changed");
597 val = gst_structure_get_value (s, "codec");
598 codec = g_value_get_boxed (val);
600 val = gst_structure_get_value (s, "session");
601 session = g_value_get_object (val);
603 update_sending_codec (handler, codec, session);
605 else if (s != NULL &&
606 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
612 DEBUG ("farsight-recv-codecs-changed");
614 val = gst_structure_get_value (s, "codecs");
615 codecs = g_value_get_boxed (val);
617 val = gst_structure_get_value (s, "stream");
618 stream = g_value_get_object (val);
620 update_receiving_codec (handler, codecs, stream);
622 else if (s != NULL &&
623 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
626 FsCandidate *remote_candidate, *local_candidate;
629 DEBUG ("farsight-new-active-candidate-pair");
631 val = gst_structure_get_value (s, "remote-candidate");
632 remote_candidate = g_value_get_boxed (val);
634 val = gst_structure_get_value (s, "local-candidate");
635 local_candidate = g_value_get_boxed (val);
637 val = gst_structure_get_value (s, "stream");
638 stream = g_value_get_object (val);
640 update_candidates (handler, remote_candidate, local_candidate, stream);
643 tf_channel_bus_message (priv->tfchannel, message);
647 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
648 GstElement *conference,
649 EmpathyCallHandler *self)
651 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
656 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
657 FsConference *conference,
658 EmpathyCallHandler *self)
660 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
661 GST_ELEMENT (conference));
665 src_pad_added_error_idle (gpointer data)
667 TfContent *content = data;
669 tf_content_error_literal (content, "Could not link sink");
670 g_object_unref (content);
676 on_tf_content_src_pad_added_cb (TfContent *content,
681 EmpathyCallHandler *handler)
685 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
686 content, pad, &retval);
689 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
693 on_tf_content_framerate_changed (TfContent *content,
695 EmpathyCallHandler *handler)
699 g_object_get (content, "framerate", &framerate, NULL);
702 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
707 on_tf_content_resolution_changed (TfContent *content,
710 EmpathyCallHandler *handler)
712 if (width > 0 && height > 0)
713 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
718 on_tf_channel_content_added_cb (TfChannel *tfchannel,
720 EmpathyCallHandler *handler)
724 // FsStream *fs_stream;
729 g_signal_connect (content, "src-pad-added",
730 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
732 g_signal_connect (content, "start-sending",
733 G_CALLBACK (on_tf_content_start_sending_cb), handler);
734 g_signal_connect (content, "stop-sending",
735 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
738 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
742 tf_content_error_literal (content, "Could not link source");
744 /* Get sending codec */
745 g_object_get (content, "fs-session", &session, NULL);
746 g_object_get (session, "current-send-codec", &codec, NULL);
748 update_sending_codec (handler, codec, session);
750 tp_clear_object (&session);
751 tp_clear_object (&codec);
753 /* Get receiving codec */
755 g_object_get (content, "fs-stream", &fs_stream, NULL);
756 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
758 update_receiving_codec (handler, codecs, fs_stream);
760 fs_codec_list_destroy (codecs);
761 tp_clear_object (&fs_stream);
764 g_object_get (content, "media-type", &mtype, NULL);
766 if (mtype == FS_MEDIA_TYPE_VIDEO)
768 guint framerate, width, height;
770 g_signal_connect (content, "notify::framerate",
771 G_CALLBACK (on_tf_content_framerate_changed),
774 g_signal_connect (content, "resolution-changed",
775 G_CALLBACK (on_tf_content_resolution_changed),
778 g_object_get (content,
779 "framerate", &framerate,
785 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
788 if (width > 0 && height > 0)
789 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
795 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
797 EmpathyCallHandler *handler)
801 DEBUG ("removing content");
803 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
808 g_warning ("Could not remove content!");
810 tf_content_error_literal (content, "Could not link source");
815 on_tf_channel_closed_cb (TfChannel *tfchannel,
816 EmpathyCallHandler *handler)
818 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
822 on_tf_channel_ready (GObject *source,
823 GAsyncResult *result,
826 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
827 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
828 GError *error = NULL;
830 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
831 G_ASYNC_INITABLE (source), result, NULL));
833 if (priv->tfchannel == NULL)
835 g_warning ("Failed to create Farstream channel: %s", error->message);
836 g_error_free (error);
840 /* Set up the telepathy farstream channel */
841 g_signal_connect (priv->tfchannel, "closed",
842 G_CALLBACK (on_tf_channel_closed_cb), self);
843 g_signal_connect (priv->tfchannel, "fs-conference-added",
844 G_CALLBACK (on_tf_channel_conference_added_cb), self);
845 g_signal_connect (priv->tfchannel, "fs-conference-removed",
846 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
847 g_signal_connect (priv->tfchannel, "content-added",
848 G_CALLBACK (on_tf_channel_content_added_cb), self);
849 g_signal_connect (priv->tfchannel, "content-removed",
850 G_CALLBACK (on_tf_channel_content_removed_cb), self);
854 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
856 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
858 tf_channel_new_async (TP_CHANNEL (priv->call),
859 on_tf_channel_ready, self);
863 empathy_call_handler_request_cb (GObject *source,
864 GAsyncResult *result,
867 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
868 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
870 GError *error = NULL;
871 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
873 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
874 result, NULL, &error);
877 DEBUG ("Failed to create the channel: %s", error->message);
878 g_error_free (error);
882 if (!TP_IS_CALL_CHANNEL (channel))
884 DEBUG ("The channel is not a Call channel!");
888 priv->call = TP_CALL_CHANNEL (channel);
889 tp_g_signal_connect_object (priv->call, "state-changed",
890 G_CALLBACK (on_call_state_changed_cb), self, 0);
891 tp_g_signal_connect_object (priv->call, "invalidated",
892 G_CALLBACK (on_call_invalidated_cb), self, 0);
894 g_object_notify (G_OBJECT (self), "call-channel");
896 empathy_call_handler_start_tpfs (self);
897 tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
901 empathy_call_handler_start_call (EmpathyCallHandler *handler,
904 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
905 TpAccountChannelRequest *req;
909 if (priv->call != NULL)
911 empathy_call_handler_start_tpfs (handler);
913 if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
915 /* accept outgoing channels immediately */
916 tp_call_channel_accept_async (priv->call,
917 on_call_accepted_cb, NULL);
921 /* accepting incoming channels when they are INITIALISED */
922 if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
923 TP_CALL_STATE_INITIALISED)
924 tp_call_channel_accept_async (priv->call,
925 on_call_accepted_cb, NULL);
927 priv->accept_when_initialised = TRUE;
933 /* No TpCallChannel (we are redialing). Request a new call channel */
934 g_assert (priv->contact != NULL);
936 account = empathy_contact_get_account (priv->contact);
937 request = empathy_call_create_call_request (
938 empathy_contact_get_id (priv->contact),
939 priv->initial_audio, priv->initial_video);
941 req = tp_account_channel_request_new (account, request, timestamp);
943 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
944 empathy_call_handler_request_cb, handler);
946 g_object_unref (req);
947 g_hash_table_unref (request);
951 * empathy_call_handler_stop_call:
952 * @handler: an #EmpathyCallHandler
954 * Closes the #EmpathyCallHandler's call and frees its resources.
957 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
959 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
961 if (priv->call != NULL)
963 tp_call_channel_hangup_async (priv->call,
964 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
970 * empathy_call_handler_has_initial_video:
971 * @handler: an #EmpathyCallHandler
973 * Return %TRUE if the call managed by this #EmpathyCallHandler was
974 * created with video enabled
976 * Return value: %TRUE if the call was created as a video conversation.
979 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
981 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
983 return priv->initial_video;
987 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
989 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
991 return priv->send_audio_codec;
995 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
997 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
999 return priv->send_video_codec;
1003 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1005 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1007 return priv->recv_audio_codecs;
1011 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1013 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1015 return priv->recv_video_codecs;
1019 empathy_call_handler_get_audio_remote_candidate (
1020 EmpathyCallHandler *self)
1022 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1024 return priv->audio_remote_candidate;
1028 empathy_call_handler_get_audio_local_candidate (
1029 EmpathyCallHandler *self)
1031 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1033 return priv->audio_local_candidate;
1037 empathy_call_handler_get_video_remote_candidate (
1038 EmpathyCallHandler *self)
1040 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1042 return priv->video_remote_candidate;
1046 empathy_call_handler_get_video_local_candidate (
1047 EmpathyCallHandler *self)
1049 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1051 return priv->video_local_candidate;
1055 empathy_call_handler_get_contact (EmpathyCallHandler *self)
1057 return self->priv->contact;