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)
57 static guint signals[LAST_SIGNAL] = {0};
60 PROP_CALL_CHANNEL = 1,
65 PROP_SEND_AUDIO_CODEC,
66 PROP_SEND_VIDEO_CODEC,
67 PROP_RECV_AUDIO_CODECS,
68 PROP_RECV_VIDEO_CODECS,
69 PROP_AUDIO_REMOTE_CANDIDATE,
70 PROP_VIDEO_REMOTE_CANDIDATE,
71 PROP_AUDIO_LOCAL_CANDIDATE,
72 PROP_VIDEO_LOCAL_CANDIDATE,
75 /* private structure */
80 /* GArray of TpContacts */
83 gboolean initial_audio;
84 gboolean initial_video;
86 FsCodec *send_audio_codec;
87 FsCodec *send_video_codec;
88 GList *recv_audio_codecs;
89 GList *recv_video_codecs;
90 FsCandidate *audio_remote_candidate;
91 FsCandidate *video_remote_candidate;
92 FsCandidate *audio_local_candidate;
93 FsCandidate *video_local_candidate;
94 } EmpathyCallHandlerPriv;
96 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
99 empathy_call_handler_dispose (GObject *object)
101 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
103 tp_clear_object (&priv->tfchannel);
104 tp_clear_object (&priv->call);
106 tp_clear_pointer (&priv->members, g_array_unref);
108 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
112 empathy_call_handler_finalize (GObject *object)
114 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
116 fs_codec_destroy (priv->send_audio_codec);
117 fs_codec_destroy (priv->send_video_codec);
118 fs_codec_list_destroy (priv->recv_audio_codecs);
119 fs_codec_list_destroy (priv->recv_video_codecs);
120 fs_candidate_destroy (priv->audio_remote_candidate);
121 fs_candidate_destroy (priv->video_remote_candidate);
122 fs_candidate_destroy (priv->audio_local_candidate);
123 fs_candidate_destroy (priv->video_local_candidate);
125 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
129 empathy_call_handler_init (EmpathyCallHandler *obj)
131 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
132 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
138 on_get_contacts_cb (TpConnection *connection,
140 EmpathyContact * const * contacts,
142 const TpHandle *failed,
145 GObject *weak_object)
147 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (weak_object);
148 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
151 g_print ("\nGot %d EmpathyContacts\n\n", n_contacts);
154 g_warning ("Failed to get %d EmpathyContacts: %s",
155 n_failed, error->message);
157 priv->members = g_array_sized_new (FALSE, TRUE,
158 sizeof (EmpathyContact *), n_contacts);
160 for (i = 0; i < n_contacts; i++)
161 g_object_ref (contacts[i]);
163 g_array_append_vals (priv->members, contacts, n_contacts);
165 g_object_notify (G_OBJECT (self), "members");
169 on_members_changed_cb (TpyCallChannel *call,
171 EmpathyCallHandler *self)
173 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
180 g_print ("\non_members_changed!\n\n");
184 g_print ("\nmembers is null!\n\n");
188 n_handles = g_hash_table_size (members);
189 g_print ("\nn_handles: %d\n\n", n_handles);
193 handles = g_new0 (TpHandle, n_handles);
195 g_hash_table_iter_init (&iter, members);
196 while (g_hash_table_iter_next (&iter, &key, &value))
197 handles[i++] = GPOINTER_TO_UINT (key);
199 empathy_tp_contact_factory_get_from_handles (
200 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
203 NULL, NULL, G_OBJECT (self));
209 empathy_call_handler_constructed (GObject *object)
211 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
212 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
215 g_signal_connect (priv->call, "members-changed",
216 G_CALLBACK (on_members_changed_cb), object);
218 g_object_get (priv->call, "members", &members, NULL);
220 on_members_changed_cb (priv->call, members, self);
224 empathy_call_handler_set_property (GObject *object,
225 guint property_id, const GValue *value, GParamSpec *pspec)
227 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
232 priv->members = g_value_get_boxed (value);
234 case PROP_CALL_CHANNEL:
235 priv->call = g_value_dup_object (value);
237 case PROP_INITIAL_AUDIO:
238 priv->initial_audio = g_value_get_boolean (value);
240 case PROP_INITIAL_VIDEO:
241 priv->initial_video = g_value_get_boolean (value);
244 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
249 empathy_call_handler_get_property (GObject *object,
250 guint property_id, GValue *value, GParamSpec *pspec)
252 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
257 g_value_set_boxed (value, priv->members);
259 case PROP_CALL_CHANNEL:
260 g_value_set_object (value, priv->call);
262 case PROP_INITIAL_AUDIO:
263 g_value_set_boolean (value, priv->initial_audio);
265 case PROP_INITIAL_VIDEO:
266 g_value_set_boolean (value, priv->initial_video);
268 case PROP_SEND_AUDIO_CODEC:
269 g_value_set_boxed (value, priv->send_audio_codec);
271 case PROP_SEND_VIDEO_CODEC:
272 g_value_set_boxed (value, priv->send_video_codec);
274 case PROP_RECV_AUDIO_CODECS:
275 g_value_set_boxed (value, priv->recv_audio_codecs);
277 case PROP_RECV_VIDEO_CODECS:
278 g_value_set_boxed (value, priv->recv_video_codecs);
280 case PROP_AUDIO_REMOTE_CANDIDATE:
281 g_value_set_boxed (value, priv->audio_remote_candidate);
283 case PROP_VIDEO_REMOTE_CANDIDATE:
284 g_value_set_boxed (value, priv->video_remote_candidate);
286 case PROP_AUDIO_LOCAL_CANDIDATE:
287 g_value_set_boxed (value, priv->audio_local_candidate);
289 case PROP_VIDEO_LOCAL_CANDIDATE:
290 g_value_set_boxed (value, priv->video_local_candidate);
293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
299 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
301 GObjectClass *object_class = G_OBJECT_CLASS (klass);
302 GParamSpec *param_spec;
304 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
306 object_class->constructed = empathy_call_handler_constructed;
307 object_class->set_property = empathy_call_handler_set_property;
308 object_class->get_property = empathy_call_handler_get_property;
309 object_class->dispose = empathy_call_handler_dispose;
310 object_class->finalize = empathy_call_handler_finalize;
312 param_spec = g_param_spec_boxed ("members",
313 "call members", "The call participants",
315 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
316 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
318 param_spec = g_param_spec_object ("call-channel",
319 "call channel", "The call channel",
320 TPY_TYPE_CALL_CHANNEL,
321 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
322 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
324 param_spec = g_param_spec_boolean ("initial-audio",
325 "initial-audio", "Whether the call should start with audio",
327 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
328 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
331 param_spec = g_param_spec_boolean ("initial-video",
332 "initial-video", "Whether the call should start with video",
334 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
335 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
338 param_spec = g_param_spec_boxed ("send-audio-codec",
339 "send audio codec", "Codec used to encode the outgoing video stream",
341 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
342 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
345 param_spec = g_param_spec_boxed ("send-video-codec",
346 "send video codec", "Codec used to encode the outgoing video stream",
348 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
349 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
352 param_spec = g_param_spec_boxed ("recv-audio-codecs",
353 "recvs audio codec", "Codecs used to decode the incoming audio stream",
355 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
356 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
359 param_spec = g_param_spec_boxed ("recv-video-codecs",
360 "recvs video codec", "Codecs used to decode the incoming video stream",
362 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
363 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
366 param_spec = g_param_spec_boxed ("audio-remote-candidate",
367 "audio remote candidate",
368 "Remote candidate used for the audio stream",
370 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
371 g_object_class_install_property (object_class,
372 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
374 param_spec = g_param_spec_boxed ("video-remote-candidate",
375 "video remote candidate",
376 "Remote candidate used for the video stream",
378 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
379 g_object_class_install_property (object_class,
380 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
382 param_spec = g_param_spec_boxed ("audio-local-candidate",
383 "audio local candidate",
384 "Local candidate used for the audio stream",
386 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
387 g_object_class_install_property (object_class,
388 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
390 param_spec = g_param_spec_boxed ("video-local-candidate",
391 "video local candidate",
392 "Local candidate used for the video stream",
394 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
395 g_object_class_install_property (object_class,
396 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
398 signals[CONFERENCE_ADDED] =
399 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
400 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
401 g_cclosure_marshal_VOID__OBJECT,
403 1, FS_TYPE_CONFERENCE);
405 signals[CONFERENCE_REMOVED] =
406 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
407 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
408 g_cclosure_marshal_VOID__OBJECT,
410 1, FS_TYPE_CONFERENCE);
412 signals[SRC_PAD_ADDED] =
413 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
414 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
415 _src_marshal_BOOLEAN__OBJECT_UINT,
417 2, GST_TYPE_PAD, G_TYPE_UINT);
419 signals[SINK_PAD_ADDED] =
420 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
421 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
422 _src_marshal_BOOLEAN__OBJECT_UINT,
424 2, GST_TYPE_PAD, G_TYPE_UINT);
426 signals[SINK_PAD_REMOVED] =
427 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
428 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
429 _src_marshal_BOOLEAN__OBJECT_UINT,
431 2, GST_TYPE_PAD, G_TYPE_UINT);
434 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
435 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
436 g_cclosure_marshal_VOID__VOID,
440 signals[CANDIDATES_CHANGED] =
441 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
442 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
443 g_cclosure_marshal_VOID__UINT,
444 G_TYPE_NONE, 1, G_TYPE_UINT);
448 empathy_call_handler_new_for_channel (TpyCallChannel *call)
450 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
451 "call-channel", call,
452 "initial-video", tpy_call_channel_has_initial_video (call),
457 update_sending_codec (EmpathyCallHandler *self,
461 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
464 if (codec == NULL || session == NULL)
467 g_object_get (session, "media-type", &type, NULL);
469 if (type == FS_MEDIA_TYPE_AUDIO)
471 priv->send_audio_codec = fs_codec_copy (codec);
472 g_object_notify (G_OBJECT (self), "send-audio-codec");
474 else if (type == FS_MEDIA_TYPE_VIDEO)
476 priv->send_video_codec = fs_codec_copy (codec);
477 g_object_notify (G_OBJECT (self), "send-video-codec");
482 update_receiving_codec (EmpathyCallHandler *self,
486 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
490 if (codecs == NULL || stream == NULL)
493 g_object_get (stream, "session", &session, NULL);
497 g_object_get (session, "media-type", &type, NULL);
499 if (type == FS_MEDIA_TYPE_AUDIO)
501 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
502 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
504 else if (type == FS_MEDIA_TYPE_VIDEO)
506 priv->recv_video_codecs = fs_codec_list_copy (codecs);
507 g_object_notify (G_OBJECT (self), "recv-video-codecs");
510 g_object_unref (session);
514 update_candidates (EmpathyCallHandler *self,
515 FsCandidate *remote_candidate,
516 FsCandidate *local_candidate,
519 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
526 g_object_get (stream, "session", &session, NULL);
530 g_object_get (session, "media-type", &type, NULL);
532 if (type == FS_MEDIA_TYPE_AUDIO)
534 if (remote_candidate != NULL)
536 fs_candidate_destroy (priv->audio_remote_candidate);
537 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
538 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
541 if (local_candidate != NULL)
543 fs_candidate_destroy (priv->audio_local_candidate);
544 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
545 g_object_notify (G_OBJECT (self), "audio-local-candidate");
548 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
549 FS_MEDIA_TYPE_AUDIO);
551 else if (type == FS_MEDIA_TYPE_VIDEO)
553 if (remote_candidate != NULL)
555 fs_candidate_destroy (priv->video_remote_candidate);
556 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
557 g_object_notify (G_OBJECT (self), "video-remote-candidate");
560 if (local_candidate != NULL)
562 fs_candidate_destroy (priv->video_local_candidate);
563 priv->video_local_candidate = fs_candidate_copy (local_candidate);
564 g_object_notify (G_OBJECT (self), "video-local-candidate");
567 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
568 FS_MEDIA_TYPE_VIDEO);
571 g_object_unref (session);
575 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
576 GstBus *bus, GstMessage *message)
578 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
579 const GstStructure *s = gst_message_get_structure (message);
581 if (priv->tfchannel == NULL)
585 gst_structure_has_name (s, "farsight-send-codec-changed"))
591 g_print ("empathy_call_handler_bus_message: farsight-send-codec-changed\n");
593 val = gst_structure_get_value (s, "codec");
594 codec = g_value_get_boxed (val);
596 val = gst_structure_get_value (s, "session");
597 session = g_value_get_object (val);
599 update_sending_codec (handler, codec, session);
601 else if (s != NULL &&
602 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
608 g_print ("empathy_call_handler_bus_message: farsight-recv-codecs-changed\n");
610 val = gst_structure_get_value (s, "codecs");
611 codecs = g_value_get_boxed (val);
613 val = gst_structure_get_value (s, "stream");
614 stream = g_value_get_object (val);
616 update_receiving_codec (handler, codecs, stream);
618 else if (s != NULL &&
619 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
622 FsCandidate *remote_candidate, *local_candidate;
625 g_print ("empathy_call_handler_bus_message: farsight-new-active-candidate-pair\n");
627 val = gst_structure_get_value (s, "remote-candidate");
628 remote_candidate = g_value_get_boxed (val);
630 val = gst_structure_get_value (s, "local-candidate");
631 local_candidate = g_value_get_boxed (val);
633 val = gst_structure_get_value (s, "stream");
634 stream = g_value_get_object (val);
636 update_candidates (handler, remote_candidate, local_candidate, stream);
639 tf_channel_bus_message (priv->tfchannel, message);
643 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
644 GstElement *conference,
645 EmpathyCallHandler *self)
647 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
652 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
653 FsConference *conference,
654 EmpathyCallHandler *self)
656 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
657 GST_ELEMENT (conference));
661 src_pad_added_error_idle (gpointer data)
663 TfContent *content = data;
665 tf_content_error (content, 0 /* FIXME */,
666 "Could not link sink", NULL);
667 g_object_unref (content);
673 on_tf_content_src_pad_added_cb (TfContent *content,
678 EmpathyCallHandler *handler)
683 g_object_get (content, "media-type", &media_type, NULL);
685 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
686 pad, media_type, &retval);
689 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
693 on_tf_channel_content_added_cb (TfChannel *tfchannel,
695 EmpathyCallHandler *handler)
700 // FsStream *fs_stream;
705 g_signal_connect (content, "src-pad-added",
706 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
708 g_signal_connect (content, "start-sending",
709 G_CALLBACK (on_tf_content_start_sending_cb), handler);
710 g_signal_connect (content, "stop-sending",
711 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
714 g_object_get (content, "media-type", &mtype,
715 "sink-pad", &spad, NULL);
717 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
718 spad, mtype, &retval);
721 tf_content_error (content, 0 /* FIXME */,
722 "Could not link source", NULL);
724 /* Get sending codec */
725 g_object_get (content, "fs-session", &session, NULL);
726 g_object_get (session, "current-send-codec", &codec, NULL);
728 update_sending_codec (handler, codec, session);
730 tp_clear_object (&session);
731 tp_clear_object (&codec);
733 /* Get receiving codec */
735 g_object_get (content, "fs-stream", &fs_stream, NULL);
736 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
738 update_receiving_codec (handler, codecs, fs_stream);
740 fs_codec_list_destroy (codecs);
741 tp_clear_object (&fs_stream);
744 gst_object_unref (spad);
748 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
750 EmpathyCallHandler *handler)
756 g_print ("removing content\n");
758 g_object_get (content, "media-type", &mtype,
759 "sink-pad", &spad, NULL);
761 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
762 spad, mtype, &retval);
766 g_warning ("Could not remove content!");
768 tf_content_error (content, 0 /* FIXME */,
769 "Could not link source", NULL);
774 on_tf_channel_closed_cb (TfChannel *tfchannel,
775 EmpathyCallHandler *handler)
777 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
781 on_tf_channel_ready (GObject *source,
782 GAsyncResult *result,
785 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
786 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
787 GError *error = NULL;
789 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
790 G_ASYNC_INITABLE (source), result, NULL));
792 if (priv->tfchannel == NULL)
794 g_warning ("Failed to create Farstream channel: %s", error->message);
795 g_error_free (error);
799 /* Set up the telepathy farstream channel */
800 g_signal_connect (priv->tfchannel, "closed",
801 G_CALLBACK (on_tf_channel_closed_cb), self);
802 g_signal_connect (priv->tfchannel, "fs-conference-added",
803 G_CALLBACK (on_tf_channel_conference_added_cb), self);
804 g_signal_connect (priv->tfchannel, "fs-conference-removed",
805 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
806 g_signal_connect (priv->tfchannel, "content-added",
807 G_CALLBACK (on_tf_channel_content_added_cb), self);
808 g_signal_connect (priv->tfchannel, "content-removed",
809 G_CALLBACK (on_tf_channel_content_removed_cb), self);
813 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
815 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
817 tf_channel_new_async (TP_CHANNEL (priv->call),
818 on_tf_channel_ready, self);
823 empathy_call_handler_request_cb (GObject *source,
824 GAsyncResult *result,
827 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
828 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
830 GError *error = NULL;
831 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
833 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
834 result, NULL, &error);
837 DEBUG ("Failed to create the channel: %s", error->message);
838 g_error_free (error);
842 if (!TPY_IS_CALL_CHANNEL (channel))
844 DEBUG ("The channel is not a Call channel!");
848 priv->call = TPY_CALL_CHANNEL (channel);
850 g_object_notify (G_OBJECT (self), "call-channel");
852 empathy_call_handler_start_tpfs (self);
857 on_call_accepted_cb (GObject *source_object,
861 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
862 GError *error = NULL;
864 if (!tpy_call_channel_accept_finish (call, res, &error))
866 g_warning ("could not accept Call: %s", error->message);
867 g_error_free (error);
872 empathy_call_handler_start_call (EmpathyCallHandler *handler,
875 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
876 /*TpAccountChannelRequest *req;
878 GHashTable *request;*/
880 if (priv->call != NULL)
882 empathy_call_handler_start_tpfs (handler);
883 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
888 g_warning ("No Call channel!");
892 /* No TpyCallChannel (we are redialing). Request a new call channel */
893 g_assert (priv->contact != NULL);
895 account = empathy_contact_get_account (priv->contact);
896 request = empathy_call_create_call_request (priv->contact,
897 priv->initial_audio, priv->initial_video);
899 req = tp_account_channel_request_new (account, request, timestamp);
901 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
902 empathy_call_handler_request_cb, handler);
904 g_object_unref (req);
905 g_hash_table_unref (request);
910 * empathy_call_handler_stop_call:
911 * @handler: an #EmpathyCallHandler
913 * Closes the #EmpathyCallHandler's call and frees its resources.
916 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
918 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
920 if (priv->call != NULL)
922 tpy_call_channel_hangup_async (priv->call,
923 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
925 tp_clear_object (&priv->call);
930 * empathy_call_handler_has_initial_video:
931 * @handler: an #EmpathyCallHandler
933 * Return %TRUE if the call managed by this #EmpathyCallHandler was
934 * created with video enabled
936 * Return value: %TRUE if the call was created as a video conversation.
939 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
941 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
943 return priv->initial_video;
947 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
949 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
951 return priv->send_audio_codec;
955 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
957 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
959 return priv->send_video_codec;
963 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
965 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
967 return priv->recv_audio_codecs;
971 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
973 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
975 return priv->recv_video_codecs;
979 empathy_call_handler_get_audio_remote_candidate (
980 EmpathyCallHandler *self)
982 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
984 return priv->audio_remote_candidate;
988 empathy_call_handler_get_audio_local_candidate (
989 EmpathyCallHandler *self)
991 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
993 return priv->audio_local_candidate;
997 empathy_call_handler_get_video_remote_candidate (
998 EmpathyCallHandler *self)
1000 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1002 return priv->video_remote_candidate;
1006 empathy_call_handler_get_video_local_candidate (
1007 EmpathyCallHandler *self)
1009 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1011 return priv->video_local_candidate;