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
25 #include <telepathy-glib/account-channel-request.h>
26 #include <telepathy-glib/util.h>
27 #include <telepathy-glib/interfaces.h>
29 #include <telepathy-yell/telepathy-yell.h>
31 #include <telepathy-farstream/telepathy-farstream.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy/empathy-tp-contact-factory.h>
36 #include "empathy-call-handler.h"
37 #include "empathy-call-factory.h"
38 #include "src-marshal.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
41 #include <libempathy/empathy-debug.h>
43 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
58 static guint signals[LAST_SIGNAL] = {0};
61 PROP_CALL_CHANNEL = 1,
67 PROP_SEND_AUDIO_CODEC,
68 PROP_SEND_VIDEO_CODEC,
69 PROP_RECV_AUDIO_CODECS,
70 PROP_RECV_VIDEO_CODECS,
71 PROP_AUDIO_REMOTE_CANDIDATE,
72 PROP_VIDEO_REMOTE_CANDIDATE,
73 PROP_AUDIO_LOCAL_CANDIDATE,
74 PROP_VIDEO_LOCAL_CANDIDATE,
77 /* private structure */
82 EmpathyContact *contact;
83 /* GArray of TpContacts */
86 gboolean initial_audio;
87 gboolean initial_video;
89 FsCodec *send_audio_codec;
90 FsCodec *send_video_codec;
91 GList *recv_audio_codecs;
92 GList *recv_video_codecs;
93 FsCandidate *audio_remote_candidate;
94 FsCandidate *video_remote_candidate;
95 FsCandidate *audio_local_candidate;
96 FsCandidate *video_local_candidate;
97 } EmpathyCallHandlerPriv;
99 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
102 empathy_call_handler_dispose (GObject *object)
104 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
106 tp_clear_object (&priv->tfchannel);
107 tp_clear_object (&priv->call);
108 tp_clear_object (&priv->contact);
110 tp_clear_pointer (&priv->members, g_array_unref);
112 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
116 empathy_call_handler_finalize (GObject *object)
118 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
120 fs_codec_destroy (priv->send_audio_codec);
121 fs_codec_destroy (priv->send_video_codec);
122 fs_codec_list_destroy (priv->recv_audio_codecs);
123 fs_codec_list_destroy (priv->recv_video_codecs);
124 fs_candidate_destroy (priv->audio_remote_candidate);
125 fs_candidate_destroy (priv->video_remote_candidate);
126 fs_candidate_destroy (priv->audio_local_candidate);
127 fs_candidate_destroy (priv->video_local_candidate);
129 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
133 empathy_call_handler_init (EmpathyCallHandler *obj)
135 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
136 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
142 on_get_contacts_cb (TpConnection *connection,
144 EmpathyContact * const * contacts,
146 const TpHandle *failed,
149 GObject *weak_object)
151 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (weak_object);
152 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
156 g_warning ("Failed to get %d EmpathyContacts: %s",
157 n_failed, error->message);
159 priv->members = g_array_sized_new (FALSE, TRUE,
160 sizeof (EmpathyContact *), n_contacts);
162 for (i = 0; i < n_contacts; i++)
163 g_object_ref (contacts[i]);
165 g_array_append_vals (priv->members, contacts, n_contacts);
167 g_object_notify (G_OBJECT (self), "members");
171 on_call_state_changed_cb (TpyCallChannel *call,
174 const GValueArray *call_state_reason,
175 GHashTable *call_state_details,
176 EmpathyCallHandler *handler)
178 if (state == TPY_CALL_STATE_ENDED)
179 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
181 g_signal_emit (handler, signals[STATE_CHANGED], 0, state);
185 on_members_changed_cb (TpyCallChannel *call,
187 EmpathyCallHandler *self)
189 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
199 n_handles = g_hash_table_size (members);
203 handles = g_new0 (TpHandle, n_handles);
205 g_hash_table_iter_init (&iter, members);
206 while (g_hash_table_iter_next (&iter, &key, &value))
207 handles[i++] = GPOINTER_TO_UINT (key);
209 empathy_tp_contact_factory_get_from_handles (
210 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
213 NULL, NULL, G_OBJECT (self));
219 empathy_call_handler_constructed (GObject *object)
221 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
222 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
223 // GHashTable *members;
225 g_signal_connect (priv->call, "members-changed",
226 G_CALLBACK (on_members_changed_cb), object);
229 g_object_get (priv->call, "members", &members, NULL);
232 on_members_changed_cb (priv->call, members, self);
237 empathy_call_handler_set_property (GObject *object,
238 guint property_id, const GValue *value, GParamSpec *pspec)
240 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
245 priv->contact = g_value_dup_object (value);
248 priv->members = g_value_get_boxed (value);
250 case PROP_CALL_CHANNEL:
251 g_return_if_fail (priv->call == NULL);
253 priv->call = g_value_dup_object (value);
255 tp_g_signal_connect_object (priv->call, "state-changed",
256 G_CALLBACK (on_call_state_changed_cb), object, 0);
258 case PROP_INITIAL_AUDIO:
259 priv->initial_audio = g_value_get_boolean (value);
261 case PROP_INITIAL_VIDEO:
262 priv->initial_video = g_value_get_boolean (value);
265 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
270 empathy_call_handler_get_property (GObject *object,
271 guint property_id, GValue *value, GParamSpec *pspec)
273 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
278 g_value_set_object (value, priv->contact);
281 g_value_set_boxed (value, priv->members);
283 case PROP_CALL_CHANNEL:
284 g_value_set_object (value, priv->call);
286 case PROP_INITIAL_AUDIO:
287 g_value_set_boolean (value, priv->initial_audio);
289 case PROP_INITIAL_VIDEO:
290 g_value_set_boolean (value, priv->initial_video);
292 case PROP_SEND_AUDIO_CODEC:
293 g_value_set_boxed (value, priv->send_audio_codec);
295 case PROP_SEND_VIDEO_CODEC:
296 g_value_set_boxed (value, priv->send_video_codec);
298 case PROP_RECV_AUDIO_CODECS:
299 g_value_set_boxed (value, priv->recv_audio_codecs);
301 case PROP_RECV_VIDEO_CODECS:
302 g_value_set_boxed (value, priv->recv_video_codecs);
304 case PROP_AUDIO_REMOTE_CANDIDATE:
305 g_value_set_boxed (value, priv->audio_remote_candidate);
307 case PROP_VIDEO_REMOTE_CANDIDATE:
308 g_value_set_boxed (value, priv->video_remote_candidate);
310 case PROP_AUDIO_LOCAL_CANDIDATE:
311 g_value_set_boxed (value, priv->audio_local_candidate);
313 case PROP_VIDEO_LOCAL_CANDIDATE:
314 g_value_set_boxed (value, priv->video_local_candidate);
317 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
323 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
325 GObjectClass *object_class = G_OBJECT_CLASS (klass);
326 GParamSpec *param_spec;
328 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
330 object_class->constructed = empathy_call_handler_constructed;
331 object_class->set_property = empathy_call_handler_set_property;
332 object_class->get_property = empathy_call_handler_get_property;
333 object_class->dispose = empathy_call_handler_dispose;
334 object_class->finalize = empathy_call_handler_finalize;
336 param_spec = g_param_spec_object ("target-contact",
337 "TargetContact", "The contact",
338 EMPATHY_TYPE_CONTACT,
339 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
340 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
342 param_spec = g_param_spec_boxed ("members",
343 "call members", "The call participants",
345 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
346 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
348 param_spec = g_param_spec_object ("call-channel",
349 "call channel", "The call channel",
350 TPY_TYPE_CALL_CHANNEL,
351 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
352 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
354 param_spec = g_param_spec_boolean ("initial-audio",
355 "initial-audio", "Whether the call should start with audio",
357 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
358 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
361 param_spec = g_param_spec_boolean ("initial-video",
362 "initial-video", "Whether the call should start with video",
364 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
365 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
368 param_spec = g_param_spec_boxed ("send-audio-codec",
369 "send audio codec", "Codec used to encode the outgoing video stream",
371 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
372 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
375 param_spec = g_param_spec_boxed ("send-video-codec",
376 "send video codec", "Codec used to encode the outgoing video stream",
378 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
379 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
382 param_spec = g_param_spec_boxed ("recv-audio-codecs",
383 "recvs audio codec", "Codecs used to decode the incoming audio stream",
385 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
386 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
389 param_spec = g_param_spec_boxed ("recv-video-codecs",
390 "recvs video codec", "Codecs used to decode the incoming video stream",
392 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
393 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
396 param_spec = g_param_spec_boxed ("audio-remote-candidate",
397 "audio remote candidate",
398 "Remote candidate used for the audio stream",
400 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
401 g_object_class_install_property (object_class,
402 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
404 param_spec = g_param_spec_boxed ("video-remote-candidate",
405 "video remote candidate",
406 "Remote candidate used for the video stream",
408 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
409 g_object_class_install_property (object_class,
410 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
412 param_spec = g_param_spec_boxed ("audio-local-candidate",
413 "audio local candidate",
414 "Local candidate used for the audio stream",
416 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
417 g_object_class_install_property (object_class,
418 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
420 param_spec = g_param_spec_boxed ("video-local-candidate",
421 "video local candidate",
422 "Local candidate used for the video stream",
424 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
425 g_object_class_install_property (object_class,
426 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
428 signals[CONFERENCE_ADDED] =
429 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
430 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
431 g_cclosure_marshal_VOID__OBJECT,
433 1, FS_TYPE_CONFERENCE);
435 signals[CONFERENCE_REMOVED] =
436 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
437 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
438 g_cclosure_marshal_VOID__OBJECT,
440 1, FS_TYPE_CONFERENCE);
442 signals[SRC_PAD_ADDED] =
443 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
444 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
445 _src_marshal_BOOLEAN__OBJECT_UINT,
447 2, GST_TYPE_PAD, G_TYPE_UINT);
449 signals[SINK_PAD_ADDED] =
450 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
451 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
452 _src_marshal_BOOLEAN__OBJECT_UINT,
454 2, GST_TYPE_PAD, G_TYPE_UINT);
456 signals[SINK_PAD_REMOVED] =
457 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
458 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
459 _src_marshal_BOOLEAN__OBJECT_UINT,
461 2, GST_TYPE_PAD, G_TYPE_UINT);
464 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
465 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
466 g_cclosure_marshal_VOID__VOID,
470 signals[CANDIDATES_CHANGED] =
471 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
472 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
473 g_cclosure_marshal_VOID__UINT,
474 G_TYPE_NONE, 1, G_TYPE_UINT);
476 signals[STATE_CHANGED] =
477 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
478 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
479 g_cclosure_marshal_VOID__UINT,
480 G_TYPE_NONE, 1, G_TYPE_UINT);
484 empathy_call_handler_new_for_channel (TpyCallChannel *call,
485 EmpathyContact *contact)
487 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
488 "call-channel", call,
489 "initial-video", tpy_call_channel_has_initial_video (call),
490 "target-contact", contact,
495 update_sending_codec (EmpathyCallHandler *self,
499 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
502 if (codec == NULL || session == NULL)
505 g_object_get (session, "media-type", &type, NULL);
507 if (type == FS_MEDIA_TYPE_AUDIO)
509 priv->send_audio_codec = fs_codec_copy (codec);
510 g_object_notify (G_OBJECT (self), "send-audio-codec");
512 else if (type == FS_MEDIA_TYPE_VIDEO)
514 priv->send_video_codec = fs_codec_copy (codec);
515 g_object_notify (G_OBJECT (self), "send-video-codec");
520 update_receiving_codec (EmpathyCallHandler *self,
524 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
528 if (codecs == NULL || stream == NULL)
531 g_object_get (stream, "session", &session, NULL);
535 g_object_get (session, "media-type", &type, NULL);
537 if (type == FS_MEDIA_TYPE_AUDIO)
539 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
540 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
542 else if (type == FS_MEDIA_TYPE_VIDEO)
544 priv->recv_video_codecs = fs_codec_list_copy (codecs);
545 g_object_notify (G_OBJECT (self), "recv-video-codecs");
548 g_object_unref (session);
552 update_candidates (EmpathyCallHandler *self,
553 FsCandidate *remote_candidate,
554 FsCandidate *local_candidate,
557 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
564 g_object_get (stream, "session", &session, NULL);
568 g_object_get (session, "media-type", &type, NULL);
570 if (type == FS_MEDIA_TYPE_AUDIO)
572 if (remote_candidate != NULL)
574 fs_candidate_destroy (priv->audio_remote_candidate);
575 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
576 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
579 if (local_candidate != NULL)
581 fs_candidate_destroy (priv->audio_local_candidate);
582 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
583 g_object_notify (G_OBJECT (self), "audio-local-candidate");
586 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
587 FS_MEDIA_TYPE_AUDIO);
589 else if (type == FS_MEDIA_TYPE_VIDEO)
591 if (remote_candidate != NULL)
593 fs_candidate_destroy (priv->video_remote_candidate);
594 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
595 g_object_notify (G_OBJECT (self), "video-remote-candidate");
598 if (local_candidate != NULL)
600 fs_candidate_destroy (priv->video_local_candidate);
601 priv->video_local_candidate = fs_candidate_copy (local_candidate);
602 g_object_notify (G_OBJECT (self), "video-local-candidate");
605 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
606 FS_MEDIA_TYPE_VIDEO);
609 g_object_unref (session);
613 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
614 GstBus *bus, GstMessage *message)
616 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
617 const GstStructure *s = gst_message_get_structure (message);
619 if (priv->tfchannel == NULL)
623 gst_structure_has_name (s, "farsight-send-codec-changed"))
629 g_print ("empathy_call_handler_bus_message: farsight-send-codec-changed\n");
631 val = gst_structure_get_value (s, "codec");
632 codec = g_value_get_boxed (val);
634 val = gst_structure_get_value (s, "session");
635 session = g_value_get_object (val);
637 update_sending_codec (handler, codec, session);
639 else if (s != NULL &&
640 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
646 g_print ("empathy_call_handler_bus_message: farsight-recv-codecs-changed\n");
648 val = gst_structure_get_value (s, "codecs");
649 codecs = g_value_get_boxed (val);
651 val = gst_structure_get_value (s, "stream");
652 stream = g_value_get_object (val);
654 update_receiving_codec (handler, codecs, stream);
656 else if (s != NULL &&
657 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
660 FsCandidate *remote_candidate, *local_candidate;
663 g_print ("empathy_call_handler_bus_message: farsight-new-active-candidate-pair\n");
665 val = gst_structure_get_value (s, "remote-candidate");
666 remote_candidate = g_value_get_boxed (val);
668 val = gst_structure_get_value (s, "local-candidate");
669 local_candidate = g_value_get_boxed (val);
671 val = gst_structure_get_value (s, "stream");
672 stream = g_value_get_object (val);
674 update_candidates (handler, remote_candidate, local_candidate, stream);
677 tf_channel_bus_message (priv->tfchannel, message);
681 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
682 GstElement *conference,
683 EmpathyCallHandler *self)
685 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
690 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
691 FsConference *conference,
692 EmpathyCallHandler *self)
694 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
695 GST_ELEMENT (conference));
699 src_pad_added_error_idle (gpointer data)
701 TfContent *content = data;
703 tf_content_error (content, 0 /* FIXME */,
704 "Could not link sink", NULL);
705 g_object_unref (content);
711 on_tf_content_src_pad_added_cb (TfContent *content,
716 EmpathyCallHandler *handler)
721 g_object_get (content, "media-type", &media_type, NULL);
723 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
724 pad, media_type, &retval);
727 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
731 on_tf_channel_content_added_cb (TfChannel *tfchannel,
733 EmpathyCallHandler *handler)
738 // FsStream *fs_stream;
743 g_signal_connect (content, "src-pad-added",
744 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
746 g_signal_connect (content, "start-sending",
747 G_CALLBACK (on_tf_content_start_sending_cb), handler);
748 g_signal_connect (content, "stop-sending",
749 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
752 g_object_get (content, "media-type", &mtype,
753 "sink-pad", &spad, NULL);
755 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
756 spad, mtype, &retval);
759 tf_content_error (content, 0 /* FIXME */,
760 "Could not link source", NULL);
762 /* Get sending codec */
763 g_object_get (content, "fs-session", &session, NULL);
764 g_object_get (session, "current-send-codec", &codec, NULL);
766 update_sending_codec (handler, codec, session);
768 tp_clear_object (&session);
769 tp_clear_object (&codec);
771 /* Get receiving codec */
773 g_object_get (content, "fs-stream", &fs_stream, NULL);
774 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
776 update_receiving_codec (handler, codecs, fs_stream);
778 fs_codec_list_destroy (codecs);
779 tp_clear_object (&fs_stream);
782 gst_object_unref (spad);
786 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
788 EmpathyCallHandler *handler)
794 g_print ("removing content\n");
796 g_object_get (content, "media-type", &mtype,
797 "sink-pad", &spad, NULL);
799 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
800 spad, mtype, &retval);
804 g_warning ("Could not remove content!");
806 tf_content_error (content, 0 /* FIXME */,
807 "Could not link source", NULL);
812 on_tf_channel_closed_cb (TfChannel *tfchannel,
813 EmpathyCallHandler *handler)
815 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
819 on_tf_channel_ready (GObject *source,
820 GAsyncResult *result,
823 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
824 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
825 GError *error = NULL;
827 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
828 G_ASYNC_INITABLE (source), result, NULL));
830 if (priv->tfchannel == NULL)
832 g_warning ("Failed to create Farstream channel: %s", error->message);
833 g_error_free (error);
837 /* Set up the telepathy farstream channel */
838 g_signal_connect (priv->tfchannel, "closed",
839 G_CALLBACK (on_tf_channel_closed_cb), self);
840 g_signal_connect (priv->tfchannel, "fs-conference-added",
841 G_CALLBACK (on_tf_channel_conference_added_cb), self);
842 g_signal_connect (priv->tfchannel, "fs-conference-removed",
843 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
844 g_signal_connect (priv->tfchannel, "content-added",
845 G_CALLBACK (on_tf_channel_content_added_cb), self);
846 g_signal_connect (priv->tfchannel, "content-removed",
847 G_CALLBACK (on_tf_channel_content_removed_cb), self);
851 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
853 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
855 tf_channel_new_async (TP_CHANNEL (priv->call),
856 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 (!TPY_IS_CALL_CHANNEL (channel))
882 DEBUG ("The channel is not a Call channel!");
886 priv->call = TPY_CALL_CHANNEL (channel);
888 g_object_notify (G_OBJECT (self), "call-channel");
890 empathy_call_handler_start_tpfs (self);
895 on_call_accepted_cb (GObject *source_object,
899 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
900 GError *error = NULL;
902 if (!tpy_call_channel_accept_finish (call, res, &error))
904 g_warning ("could not accept Call: %s", error->message);
905 g_error_free (error);
910 empathy_call_handler_start_call (EmpathyCallHandler *handler,
913 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
914 /*TpAccountChannelRequest *req;
916 GHashTable *request;*/
918 if (priv->call != NULL)
920 empathy_call_handler_start_tpfs (handler);
921 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
926 g_warning ("No Call channel!");
930 /* No TpyCallChannel (we are redialing). Request a new call channel */
931 g_assert (priv->contact != NULL);
933 account = empathy_contact_get_account (priv->contact);
934 request = empathy_call_create_call_request (priv->contact,
935 priv->initial_audio, priv->initial_video);
937 req = tp_account_channel_request_new (account, request, timestamp);
939 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
940 empathy_call_handler_request_cb, handler);
942 g_object_unref (req);
943 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 tpy_call_channel_hangup_async (priv->call,
961 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
963 tp_channel_close_async (TP_CHANNEL (priv->call),
965 tp_clear_object (&priv->call);
966 tp_clear_object (&priv->tfchannel);
971 * empathy_call_handler_has_initial_video:
972 * @handler: an #EmpathyCallHandler
974 * Return %TRUE if the call managed by this #EmpathyCallHandler was
975 * created with video enabled
977 * Return value: %TRUE if the call was created as a video conversation.
980 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
982 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
984 return priv->initial_video;
988 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
990 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
992 return priv->send_audio_codec;
996 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
998 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1000 return priv->send_video_codec;
1004 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1006 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1008 return priv->recv_audio_codecs;
1012 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1014 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1016 return priv->recv_video_codecs;
1020 empathy_call_handler_get_audio_remote_candidate (
1021 EmpathyCallHandler *self)
1023 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1025 return priv->audio_remote_candidate;
1029 empathy_call_handler_get_audio_local_candidate (
1030 EmpathyCallHandler *self)
1032 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1034 return priv->audio_local_candidate;
1038 empathy_call_handler_get_video_remote_candidate (
1039 EmpathyCallHandler *self)
1041 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1043 return priv->video_remote_candidate;
1047 empathy_call_handler_get_video_local_candidate (
1048 EmpathyCallHandler *self)
1050 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1052 return priv->video_local_candidate;