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 <libempathy-gtk/empathy-call-utils.h>
38 #include "empathy-call-handler.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 */
79 struct _EmpathyCallHandlerPriv {
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;
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_invalidated_cb (TpyCallChannel *call,
175 EmpathyCallHandler *self)
177 EmpathyCallHandlerPriv *priv = self->priv;
179 if (priv->call == call)
181 /* Invalidated unexpectedly? Fake call ending */
182 g_signal_emit (self, signals[STATE_CHANGED], 0,
183 TPY_CALL_STATE_ENDED, NULL);
184 tp_clear_object (&priv->call);
185 tp_clear_object (&priv->tfchannel);
190 on_call_state_changed_cb (TpyCallChannel *call,
193 const GValueArray *call_state_reason,
194 GHashTable *call_state_details,
195 EmpathyCallHandler *handler)
197 EmpathyCallHandlerPriv *priv = handler->priv;
199 g_signal_emit (handler, signals[STATE_CHANGED], 0, state);
201 if (state == TPY_CALL_STATE_ENDED)
203 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
205 tp_clear_object (&priv->call);
206 tp_clear_object (&priv->tfchannel);
211 on_members_changed_cb (TpyCallChannel *call,
213 EmpathyCallHandler *self)
215 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
225 n_handles = g_hash_table_size (members);
229 handles = g_new0 (TpHandle, n_handles);
231 g_hash_table_iter_init (&iter, members);
232 while (g_hash_table_iter_next (&iter, &key, &value))
233 handles[i++] = GPOINTER_TO_UINT (key);
235 empathy_tp_contact_factory_get_from_handles (
236 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
239 NULL, NULL, G_OBJECT (self));
245 empathy_call_handler_constructed (GObject *object)
247 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
248 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
249 // GHashTable *members;
251 g_signal_connect (priv->call, "members-changed",
252 G_CALLBACK (on_members_changed_cb), object);
255 g_object_get (priv->call, "members", &members, NULL);
258 on_members_changed_cb (priv->call, members, self);
263 empathy_call_handler_set_property (GObject *object,
264 guint property_id, const GValue *value, GParamSpec *pspec)
266 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
271 priv->contact = g_value_dup_object (value);
274 priv->members = g_value_get_boxed (value);
276 case PROP_CALL_CHANNEL:
277 g_return_if_fail (priv->call == NULL);
279 priv->call = g_value_dup_object (value);
281 tp_g_signal_connect_object (priv->call, "state-changed",
282 G_CALLBACK (on_call_state_changed_cb), object, 0);
283 tp_g_signal_connect_object (priv->call, "invalidated",
284 G_CALLBACK (on_call_invalidated_cb), object, 0);
286 case PROP_INITIAL_AUDIO:
287 priv->initial_audio = g_value_get_boolean (value);
289 case PROP_INITIAL_VIDEO:
290 priv->initial_video = g_value_get_boolean (value);
293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
298 empathy_call_handler_get_property (GObject *object,
299 guint property_id, GValue *value, GParamSpec *pspec)
301 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
306 g_value_set_object (value, priv->contact);
309 g_value_set_boxed (value, priv->members);
311 case PROP_CALL_CHANNEL:
312 g_value_set_object (value, priv->call);
314 case PROP_INITIAL_AUDIO:
315 g_value_set_boolean (value, priv->initial_audio);
317 case PROP_INITIAL_VIDEO:
318 g_value_set_boolean (value, priv->initial_video);
320 case PROP_SEND_AUDIO_CODEC:
321 g_value_set_boxed (value, priv->send_audio_codec);
323 case PROP_SEND_VIDEO_CODEC:
324 g_value_set_boxed (value, priv->send_video_codec);
326 case PROP_RECV_AUDIO_CODECS:
327 g_value_set_boxed (value, priv->recv_audio_codecs);
329 case PROP_RECV_VIDEO_CODECS:
330 g_value_set_boxed (value, priv->recv_video_codecs);
332 case PROP_AUDIO_REMOTE_CANDIDATE:
333 g_value_set_boxed (value, priv->audio_remote_candidate);
335 case PROP_VIDEO_REMOTE_CANDIDATE:
336 g_value_set_boxed (value, priv->video_remote_candidate);
338 case PROP_AUDIO_LOCAL_CANDIDATE:
339 g_value_set_boxed (value, priv->audio_local_candidate);
341 case PROP_VIDEO_LOCAL_CANDIDATE:
342 g_value_set_boxed (value, priv->video_local_candidate);
345 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
351 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
353 GObjectClass *object_class = G_OBJECT_CLASS (klass);
354 GParamSpec *param_spec;
356 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
358 object_class->constructed = empathy_call_handler_constructed;
359 object_class->set_property = empathy_call_handler_set_property;
360 object_class->get_property = empathy_call_handler_get_property;
361 object_class->dispose = empathy_call_handler_dispose;
362 object_class->finalize = empathy_call_handler_finalize;
364 param_spec = g_param_spec_object ("target-contact",
365 "TargetContact", "The contact",
366 EMPATHY_TYPE_CONTACT,
367 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
368 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
370 param_spec = g_param_spec_boxed ("members",
371 "call members", "The call participants",
373 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
374 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
376 param_spec = g_param_spec_object ("call-channel",
377 "call channel", "The call channel",
378 TPY_TYPE_CALL_CHANNEL,
379 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
380 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
382 param_spec = g_param_spec_boolean ("initial-audio",
383 "initial-audio", "Whether the call should start with audio",
385 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
386 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
389 param_spec = g_param_spec_boolean ("initial-video",
390 "initial-video", "Whether the call should start with video",
392 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
393 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
396 param_spec = g_param_spec_boxed ("send-audio-codec",
397 "send audio codec", "Codec used to encode the outgoing video stream",
399 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
400 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
403 param_spec = g_param_spec_boxed ("send-video-codec",
404 "send video codec", "Codec used to encode the outgoing video stream",
406 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
407 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
410 param_spec = g_param_spec_boxed ("recv-audio-codecs",
411 "recvs audio codec", "Codecs used to decode the incoming audio stream",
413 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
414 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
417 param_spec = g_param_spec_boxed ("recv-video-codecs",
418 "recvs video codec", "Codecs used to decode the incoming video stream",
420 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
421 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
424 param_spec = g_param_spec_boxed ("audio-remote-candidate",
425 "audio remote candidate",
426 "Remote candidate used for the audio stream",
428 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
429 g_object_class_install_property (object_class,
430 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
432 param_spec = g_param_spec_boxed ("video-remote-candidate",
433 "video remote candidate",
434 "Remote candidate used for the video stream",
436 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
437 g_object_class_install_property (object_class,
438 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
440 param_spec = g_param_spec_boxed ("audio-local-candidate",
441 "audio local candidate",
442 "Local candidate used for the audio stream",
444 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
445 g_object_class_install_property (object_class,
446 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
448 param_spec = g_param_spec_boxed ("video-local-candidate",
449 "video local candidate",
450 "Local candidate used for the video stream",
452 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
453 g_object_class_install_property (object_class,
454 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
456 signals[CONFERENCE_ADDED] =
457 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
458 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
459 g_cclosure_marshal_generic,
461 1, FS_TYPE_CONFERENCE);
463 signals[CONFERENCE_REMOVED] =
464 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
465 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
466 g_cclosure_marshal_generic,
468 1, FS_TYPE_CONFERENCE);
470 signals[SRC_PAD_ADDED] =
471 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
472 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
473 g_cclosure_marshal_generic,
475 2, GST_TYPE_PAD, G_TYPE_UINT);
477 signals[SINK_PAD_ADDED] =
478 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
479 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
480 g_cclosure_marshal_generic,
482 2, GST_TYPE_PAD, G_TYPE_UINT);
484 signals[SINK_PAD_REMOVED] =
485 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
486 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
487 g_cclosure_marshal_generic,
489 2, GST_TYPE_PAD, G_TYPE_UINT);
492 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
493 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
494 g_cclosure_marshal_generic,
498 signals[CANDIDATES_CHANGED] =
499 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
500 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
501 g_cclosure_marshal_generic,
502 G_TYPE_NONE, 1, G_TYPE_UINT);
504 signals[STATE_CHANGED] =
505 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
506 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
507 g_cclosure_marshal_generic,
508 G_TYPE_NONE, 1, G_TYPE_UINT);
512 empathy_call_handler_new_for_channel (TpyCallChannel *call,
513 EmpathyContact *contact)
515 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
516 "call-channel", call,
517 "initial-video", tpy_call_channel_has_initial_video (call),
518 "target-contact", contact,
523 update_sending_codec (EmpathyCallHandler *self,
527 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
530 if (codec == NULL || session == NULL)
533 g_object_get (session, "media-type", &type, NULL);
535 if (type == FS_MEDIA_TYPE_AUDIO)
537 priv->send_audio_codec = fs_codec_copy (codec);
538 g_object_notify (G_OBJECT (self), "send-audio-codec");
540 else if (type == FS_MEDIA_TYPE_VIDEO)
542 priv->send_video_codec = fs_codec_copy (codec);
543 g_object_notify (G_OBJECT (self), "send-video-codec");
548 update_receiving_codec (EmpathyCallHandler *self,
552 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
556 if (codecs == NULL || stream == NULL)
559 g_object_get (stream, "session", &session, NULL);
563 g_object_get (session, "media-type", &type, NULL);
565 if (type == FS_MEDIA_TYPE_AUDIO)
567 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
568 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
570 else if (type == FS_MEDIA_TYPE_VIDEO)
572 priv->recv_video_codecs = fs_codec_list_copy (codecs);
573 g_object_notify (G_OBJECT (self), "recv-video-codecs");
576 g_object_unref (session);
580 update_candidates (EmpathyCallHandler *self,
581 FsCandidate *remote_candidate,
582 FsCandidate *local_candidate,
585 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
592 g_object_get (stream, "session", &session, NULL);
596 g_object_get (session, "media-type", &type, NULL);
598 if (type == FS_MEDIA_TYPE_AUDIO)
600 if (remote_candidate != NULL)
602 fs_candidate_destroy (priv->audio_remote_candidate);
603 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
604 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
607 if (local_candidate != NULL)
609 fs_candidate_destroy (priv->audio_local_candidate);
610 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
611 g_object_notify (G_OBJECT (self), "audio-local-candidate");
614 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
615 FS_MEDIA_TYPE_AUDIO);
617 else if (type == FS_MEDIA_TYPE_VIDEO)
619 if (remote_candidate != NULL)
621 fs_candidate_destroy (priv->video_remote_candidate);
622 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
623 g_object_notify (G_OBJECT (self), "video-remote-candidate");
626 if (local_candidate != NULL)
628 fs_candidate_destroy (priv->video_local_candidate);
629 priv->video_local_candidate = fs_candidate_copy (local_candidate);
630 g_object_notify (G_OBJECT (self), "video-local-candidate");
633 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
634 FS_MEDIA_TYPE_VIDEO);
637 g_object_unref (session);
641 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
642 GstBus *bus, GstMessage *message)
644 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
645 const GstStructure *s = gst_message_get_structure (message);
647 if (priv->tfchannel == NULL)
651 gst_structure_has_name (s, "farsight-send-codec-changed"))
657 DEBUG ("farsight-send-codec-changed");
659 val = gst_structure_get_value (s, "codec");
660 codec = g_value_get_boxed (val);
662 val = gst_structure_get_value (s, "session");
663 session = g_value_get_object (val);
665 update_sending_codec (handler, codec, session);
667 else if (s != NULL &&
668 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
674 DEBUG ("farsight-recv-codecs-changed");
676 val = gst_structure_get_value (s, "codecs");
677 codecs = g_value_get_boxed (val);
679 val = gst_structure_get_value (s, "stream");
680 stream = g_value_get_object (val);
682 update_receiving_codec (handler, codecs, stream);
684 else if (s != NULL &&
685 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
688 FsCandidate *remote_candidate, *local_candidate;
691 DEBUG ("farsight-new-active-candidate-pair");
693 val = gst_structure_get_value (s, "remote-candidate");
694 remote_candidate = g_value_get_boxed (val);
696 val = gst_structure_get_value (s, "local-candidate");
697 local_candidate = g_value_get_boxed (val);
699 val = gst_structure_get_value (s, "stream");
700 stream = g_value_get_object (val);
702 update_candidates (handler, remote_candidate, local_candidate, stream);
705 tf_channel_bus_message (priv->tfchannel, message);
709 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
710 GstElement *conference,
711 EmpathyCallHandler *self)
713 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
718 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
719 FsConference *conference,
720 EmpathyCallHandler *self)
722 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
723 GST_ELEMENT (conference));
727 src_pad_added_error_idle (gpointer data)
729 TfContent *content = data;
731 tf_content_error (content, 0 /* FIXME */,
732 "Could not link sink", NULL);
733 g_object_unref (content);
739 on_tf_content_src_pad_added_cb (TfContent *content,
744 EmpathyCallHandler *handler)
749 g_object_get (content, "media-type", &media_type, NULL);
751 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
752 pad, media_type, &retval);
755 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
759 on_tf_channel_content_added_cb (TfChannel *tfchannel,
761 EmpathyCallHandler *handler)
766 // FsStream *fs_stream;
771 g_signal_connect (content, "src-pad-added",
772 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
774 g_signal_connect (content, "start-sending",
775 G_CALLBACK (on_tf_content_start_sending_cb), handler);
776 g_signal_connect (content, "stop-sending",
777 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
780 g_object_get (content, "media-type", &mtype,
781 "sink-pad", &spad, NULL);
783 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
784 spad, mtype, &retval);
787 tf_content_error (content, 0 /* FIXME */,
788 "Could not link source", NULL);
790 /* Get sending codec */
791 g_object_get (content, "fs-session", &session, NULL);
792 g_object_get (session, "current-send-codec", &codec, NULL);
794 update_sending_codec (handler, codec, session);
796 tp_clear_object (&session);
797 tp_clear_object (&codec);
799 /* Get receiving codec */
801 g_object_get (content, "fs-stream", &fs_stream, NULL);
802 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
804 update_receiving_codec (handler, codecs, fs_stream);
806 fs_codec_list_destroy (codecs);
807 tp_clear_object (&fs_stream);
810 gst_object_unref (spad);
814 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
816 EmpathyCallHandler *handler)
822 DEBUG ("removing content");
824 g_object_get (content, "media-type", &mtype,
825 "sink-pad", &spad, NULL);
827 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
828 spad, mtype, &retval);
832 g_warning ("Could not remove content!");
834 tf_content_error (content, 0 /* FIXME */,
835 "Could not link source", NULL);
840 on_tf_channel_closed_cb (TfChannel *tfchannel,
841 EmpathyCallHandler *handler)
843 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
847 on_tf_channel_ready (GObject *source,
848 GAsyncResult *result,
851 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
852 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
853 GError *error = NULL;
855 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
856 G_ASYNC_INITABLE (source), result, NULL));
858 if (priv->tfchannel == NULL)
860 g_warning ("Failed to create Farstream channel: %s", error->message);
861 g_error_free (error);
865 /* Set up the telepathy farstream channel */
866 g_signal_connect (priv->tfchannel, "closed",
867 G_CALLBACK (on_tf_channel_closed_cb), self);
868 g_signal_connect (priv->tfchannel, "fs-conference-added",
869 G_CALLBACK (on_tf_channel_conference_added_cb), self);
870 g_signal_connect (priv->tfchannel, "fs-conference-removed",
871 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
872 g_signal_connect (priv->tfchannel, "content-added",
873 G_CALLBACK (on_tf_channel_content_added_cb), self);
874 g_signal_connect (priv->tfchannel, "content-removed",
875 G_CALLBACK (on_tf_channel_content_removed_cb), self);
879 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
881 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
883 tf_channel_new_async (TP_CHANNEL (priv->call),
884 on_tf_channel_ready, self);
888 on_call_accepted_cb (GObject *source_object,
892 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
893 GError *error = NULL;
895 if (!tpy_call_channel_accept_finish (call, res, &error))
897 g_warning ("could not accept Call: %s", error->message);
898 g_error_free (error);
903 empathy_call_handler_request_cb (GObject *source,
904 GAsyncResult *result,
907 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
908 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
910 GError *error = NULL;
911 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
913 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
914 result, NULL, &error);
917 DEBUG ("Failed to create the channel: %s", error->message);
918 g_error_free (error);
922 if (!TPY_IS_CALL_CHANNEL (channel))
924 DEBUG ("The channel is not a Call channel!");
928 priv->call = TPY_CALL_CHANNEL (channel);
929 tp_g_signal_connect_object (priv->call, "state-changed",
930 G_CALLBACK (on_call_state_changed_cb), self, 0);
931 tp_g_signal_connect_object (priv->call, "invalidated",
932 G_CALLBACK (on_call_invalidated_cb), self, 0);
934 g_object_notify (G_OBJECT (self), "call-channel");
936 empathy_call_handler_start_tpfs (self);
937 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
941 empathy_call_handler_start_call (EmpathyCallHandler *handler,
944 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
945 TpAccountChannelRequest *req;
949 if (priv->call != NULL)
951 empathy_call_handler_start_tpfs (handler);
952 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
956 /* No TpyCallChannel (we are redialing). Request a new call channel */
957 g_assert (priv->contact != NULL);
959 account = empathy_contact_get_account (priv->contact);
960 request = empathy_call_create_call_request (
961 empathy_contact_get_id (priv->contact),
962 priv->initial_audio, priv->initial_video);
964 req = tp_account_channel_request_new (account, request, timestamp);
966 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
967 empathy_call_handler_request_cb, handler);
969 g_object_unref (req);
970 g_hash_table_unref (request);
974 * empathy_call_handler_stop_call:
975 * @handler: an #EmpathyCallHandler
977 * Closes the #EmpathyCallHandler's call and frees its resources.
980 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
982 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
984 if (priv->call != NULL)
986 tpy_call_channel_hangup_async (priv->call,
987 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
989 tp_channel_close_async (TP_CHANNEL (priv->call),
991 tp_clear_object (&priv->call);
992 tp_clear_object (&priv->tfchannel);
997 * empathy_call_handler_has_initial_video:
998 * @handler: an #EmpathyCallHandler
1000 * Return %TRUE if the call managed by this #EmpathyCallHandler was
1001 * created with video enabled
1003 * Return value: %TRUE if the call was created as a video conversation.
1006 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
1008 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1010 return priv->initial_video;
1014 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
1016 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1018 return priv->send_audio_codec;
1022 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1024 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1026 return priv->send_video_codec;
1030 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1032 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1034 return priv->recv_audio_codecs;
1038 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1040 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1042 return priv->recv_video_codecs;
1046 empathy_call_handler_get_audio_remote_candidate (
1047 EmpathyCallHandler *self)
1049 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1051 return priv->audio_remote_candidate;
1055 empathy_call_handler_get_audio_local_candidate (
1056 EmpathyCallHandler *self)
1058 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1060 return priv->audio_local_candidate;
1064 empathy_call_handler_get_video_remote_candidate (
1065 EmpathyCallHandler *self)
1067 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1069 return priv->video_remote_candidate;
1073 empathy_call_handler_get_video_local_candidate (
1074 EmpathyCallHandler *self)
1076 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1078 return priv->video_local_candidate;