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 */
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, TPY_CALL_STATE_ENDED);
183 tp_clear_object (&priv->call);
184 tp_clear_object (&priv->tfchannel);
189 on_call_state_changed_cb (TpyCallChannel *call,
192 const GValueArray *call_state_reason,
193 GHashTable *call_state_details,
194 EmpathyCallHandler *handler)
196 if (state == TPY_CALL_STATE_ENDED)
197 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
199 g_signal_emit (handler, signals[STATE_CHANGED], 0, state);
203 on_members_changed_cb (TpyCallChannel *call,
205 EmpathyCallHandler *self)
207 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
217 n_handles = g_hash_table_size (members);
221 handles = g_new0 (TpHandle, n_handles);
223 g_hash_table_iter_init (&iter, members);
224 while (g_hash_table_iter_next (&iter, &key, &value))
225 handles[i++] = GPOINTER_TO_UINT (key);
227 empathy_tp_contact_factory_get_from_handles (
228 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
231 NULL, NULL, G_OBJECT (self));
237 empathy_call_handler_constructed (GObject *object)
239 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
240 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
241 // GHashTable *members;
243 g_signal_connect (priv->call, "members-changed",
244 G_CALLBACK (on_members_changed_cb), object);
247 g_object_get (priv->call, "members", &members, NULL);
250 on_members_changed_cb (priv->call, members, self);
255 empathy_call_handler_set_property (GObject *object,
256 guint property_id, const GValue *value, GParamSpec *pspec)
258 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
263 priv->contact = g_value_dup_object (value);
266 priv->members = g_value_get_boxed (value);
268 case PROP_CALL_CHANNEL:
269 g_return_if_fail (priv->call == NULL);
271 priv->call = g_value_dup_object (value);
273 tp_g_signal_connect_object (priv->call, "state-changed",
274 G_CALLBACK (on_call_state_changed_cb), object, 0);
275 tp_g_signal_connect_object (priv->call, "invalidated",
276 G_CALLBACK (on_call_invalidated_cb), object, 0);
278 case PROP_INITIAL_AUDIO:
279 priv->initial_audio = g_value_get_boolean (value);
281 case PROP_INITIAL_VIDEO:
282 priv->initial_video = g_value_get_boolean (value);
285 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
290 empathy_call_handler_get_property (GObject *object,
291 guint property_id, GValue *value, GParamSpec *pspec)
293 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
298 g_value_set_object (value, priv->contact);
301 g_value_set_boxed (value, priv->members);
303 case PROP_CALL_CHANNEL:
304 g_value_set_object (value, priv->call);
306 case PROP_INITIAL_AUDIO:
307 g_value_set_boolean (value, priv->initial_audio);
309 case PROP_INITIAL_VIDEO:
310 g_value_set_boolean (value, priv->initial_video);
312 case PROP_SEND_AUDIO_CODEC:
313 g_value_set_boxed (value, priv->send_audio_codec);
315 case PROP_SEND_VIDEO_CODEC:
316 g_value_set_boxed (value, priv->send_video_codec);
318 case PROP_RECV_AUDIO_CODECS:
319 g_value_set_boxed (value, priv->recv_audio_codecs);
321 case PROP_RECV_VIDEO_CODECS:
322 g_value_set_boxed (value, priv->recv_video_codecs);
324 case PROP_AUDIO_REMOTE_CANDIDATE:
325 g_value_set_boxed (value, priv->audio_remote_candidate);
327 case PROP_VIDEO_REMOTE_CANDIDATE:
328 g_value_set_boxed (value, priv->video_remote_candidate);
330 case PROP_AUDIO_LOCAL_CANDIDATE:
331 g_value_set_boxed (value, priv->audio_local_candidate);
333 case PROP_VIDEO_LOCAL_CANDIDATE:
334 g_value_set_boxed (value, priv->video_local_candidate);
337 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
343 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
345 GObjectClass *object_class = G_OBJECT_CLASS (klass);
346 GParamSpec *param_spec;
348 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
350 object_class->constructed = empathy_call_handler_constructed;
351 object_class->set_property = empathy_call_handler_set_property;
352 object_class->get_property = empathy_call_handler_get_property;
353 object_class->dispose = empathy_call_handler_dispose;
354 object_class->finalize = empathy_call_handler_finalize;
356 param_spec = g_param_spec_object ("target-contact",
357 "TargetContact", "The contact",
358 EMPATHY_TYPE_CONTACT,
359 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
360 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
362 param_spec = g_param_spec_boxed ("members",
363 "call members", "The call participants",
365 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
366 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
368 param_spec = g_param_spec_object ("call-channel",
369 "call channel", "The call channel",
370 TPY_TYPE_CALL_CHANNEL,
371 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
372 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
374 param_spec = g_param_spec_boolean ("initial-audio",
375 "initial-audio", "Whether the call should start with audio",
377 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
378 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
381 param_spec = g_param_spec_boolean ("initial-video",
382 "initial-video", "Whether the call should start with video",
384 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
385 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
388 param_spec = g_param_spec_boxed ("send-audio-codec",
389 "send audio codec", "Codec used to encode the outgoing video stream",
391 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
392 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
395 param_spec = g_param_spec_boxed ("send-video-codec",
396 "send video codec", "Codec used to encode the outgoing video stream",
398 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
399 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
402 param_spec = g_param_spec_boxed ("recv-audio-codecs",
403 "recvs audio codec", "Codecs used to decode the incoming audio stream",
405 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
406 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
409 param_spec = g_param_spec_boxed ("recv-video-codecs",
410 "recvs video codec", "Codecs used to decode the incoming video stream",
412 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
413 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
416 param_spec = g_param_spec_boxed ("audio-remote-candidate",
417 "audio remote candidate",
418 "Remote candidate used for the audio stream",
420 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
421 g_object_class_install_property (object_class,
422 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
424 param_spec = g_param_spec_boxed ("video-remote-candidate",
425 "video remote candidate",
426 "Remote candidate used for the video stream",
428 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
429 g_object_class_install_property (object_class,
430 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
432 param_spec = g_param_spec_boxed ("audio-local-candidate",
433 "audio local candidate",
434 "Local candidate used for the audio stream",
436 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
437 g_object_class_install_property (object_class,
438 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
440 param_spec = g_param_spec_boxed ("video-local-candidate",
441 "video local candidate",
442 "Local candidate used for the video stream",
444 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
445 g_object_class_install_property (object_class,
446 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
448 signals[CONFERENCE_ADDED] =
449 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
450 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
451 g_cclosure_marshal_VOID__OBJECT,
453 1, FS_TYPE_CONFERENCE);
455 signals[CONFERENCE_REMOVED] =
456 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
457 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
458 g_cclosure_marshal_VOID__OBJECT,
460 1, FS_TYPE_CONFERENCE);
462 signals[SRC_PAD_ADDED] =
463 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
464 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
465 _src_marshal_BOOLEAN__OBJECT_UINT,
467 2, GST_TYPE_PAD, G_TYPE_UINT);
469 signals[SINK_PAD_ADDED] =
470 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
471 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
472 _src_marshal_BOOLEAN__OBJECT_UINT,
474 2, GST_TYPE_PAD, G_TYPE_UINT);
476 signals[SINK_PAD_REMOVED] =
477 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
478 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
479 _src_marshal_BOOLEAN__OBJECT_UINT,
481 2, GST_TYPE_PAD, G_TYPE_UINT);
484 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
485 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
486 g_cclosure_marshal_VOID__VOID,
490 signals[CANDIDATES_CHANGED] =
491 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
492 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
493 g_cclosure_marshal_VOID__UINT,
494 G_TYPE_NONE, 1, G_TYPE_UINT);
496 signals[STATE_CHANGED] =
497 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
498 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
499 g_cclosure_marshal_VOID__UINT,
500 G_TYPE_NONE, 1, G_TYPE_UINT);
504 empathy_call_handler_new_for_channel (TpyCallChannel *call,
505 EmpathyContact *contact)
507 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
508 "call-channel", call,
509 "initial-video", tpy_call_channel_has_initial_video (call),
510 "target-contact", contact,
515 update_sending_codec (EmpathyCallHandler *self,
519 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
522 if (codec == NULL || session == NULL)
525 g_object_get (session, "media-type", &type, NULL);
527 if (type == FS_MEDIA_TYPE_AUDIO)
529 priv->send_audio_codec = fs_codec_copy (codec);
530 g_object_notify (G_OBJECT (self), "send-audio-codec");
532 else if (type == FS_MEDIA_TYPE_VIDEO)
534 priv->send_video_codec = fs_codec_copy (codec);
535 g_object_notify (G_OBJECT (self), "send-video-codec");
540 update_receiving_codec (EmpathyCallHandler *self,
544 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
548 if (codecs == NULL || stream == NULL)
551 g_object_get (stream, "session", &session, NULL);
555 g_object_get (session, "media-type", &type, NULL);
557 if (type == FS_MEDIA_TYPE_AUDIO)
559 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
560 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
562 else if (type == FS_MEDIA_TYPE_VIDEO)
564 priv->recv_video_codecs = fs_codec_list_copy (codecs);
565 g_object_notify (G_OBJECT (self), "recv-video-codecs");
568 g_object_unref (session);
572 update_candidates (EmpathyCallHandler *self,
573 FsCandidate *remote_candidate,
574 FsCandidate *local_candidate,
577 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
584 g_object_get (stream, "session", &session, NULL);
588 g_object_get (session, "media-type", &type, NULL);
590 if (type == FS_MEDIA_TYPE_AUDIO)
592 if (remote_candidate != NULL)
594 fs_candidate_destroy (priv->audio_remote_candidate);
595 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
596 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
599 if (local_candidate != NULL)
601 fs_candidate_destroy (priv->audio_local_candidate);
602 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
603 g_object_notify (G_OBJECT (self), "audio-local-candidate");
606 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
607 FS_MEDIA_TYPE_AUDIO);
609 else if (type == FS_MEDIA_TYPE_VIDEO)
611 if (remote_candidate != NULL)
613 fs_candidate_destroy (priv->video_remote_candidate);
614 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
615 g_object_notify (G_OBJECT (self), "video-remote-candidate");
618 if (local_candidate != NULL)
620 fs_candidate_destroy (priv->video_local_candidate);
621 priv->video_local_candidate = fs_candidate_copy (local_candidate);
622 g_object_notify (G_OBJECT (self), "video-local-candidate");
625 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
626 FS_MEDIA_TYPE_VIDEO);
629 g_object_unref (session);
633 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
634 GstBus *bus, GstMessage *message)
636 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
637 const GstStructure *s = gst_message_get_structure (message);
639 if (priv->tfchannel == NULL)
643 gst_structure_has_name (s, "farsight-send-codec-changed"))
649 g_print ("empathy_call_handler_bus_message: farsight-send-codec-changed\n");
651 val = gst_structure_get_value (s, "codec");
652 codec = g_value_get_boxed (val);
654 val = gst_structure_get_value (s, "session");
655 session = g_value_get_object (val);
657 update_sending_codec (handler, codec, session);
659 else if (s != NULL &&
660 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
666 g_print ("empathy_call_handler_bus_message: farsight-recv-codecs-changed\n");
668 val = gst_structure_get_value (s, "codecs");
669 codecs = g_value_get_boxed (val);
671 val = gst_structure_get_value (s, "stream");
672 stream = g_value_get_object (val);
674 update_receiving_codec (handler, codecs, stream);
676 else if (s != NULL &&
677 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
680 FsCandidate *remote_candidate, *local_candidate;
683 g_print ("empathy_call_handler_bus_message: farsight-new-active-candidate-pair\n");
685 val = gst_structure_get_value (s, "remote-candidate");
686 remote_candidate = g_value_get_boxed (val);
688 val = gst_structure_get_value (s, "local-candidate");
689 local_candidate = g_value_get_boxed (val);
691 val = gst_structure_get_value (s, "stream");
692 stream = g_value_get_object (val);
694 update_candidates (handler, remote_candidate, local_candidate, stream);
697 tf_channel_bus_message (priv->tfchannel, message);
701 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
702 GstElement *conference,
703 EmpathyCallHandler *self)
705 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
710 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
711 FsConference *conference,
712 EmpathyCallHandler *self)
714 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
715 GST_ELEMENT (conference));
719 src_pad_added_error_idle (gpointer data)
721 TfContent *content = data;
723 tf_content_error (content, 0 /* FIXME */,
724 "Could not link sink", NULL);
725 g_object_unref (content);
731 on_tf_content_src_pad_added_cb (TfContent *content,
736 EmpathyCallHandler *handler)
741 g_object_get (content, "media-type", &media_type, NULL);
743 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
744 pad, media_type, &retval);
747 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
751 on_tf_channel_content_added_cb (TfChannel *tfchannel,
753 EmpathyCallHandler *handler)
758 // FsStream *fs_stream;
763 g_signal_connect (content, "src-pad-added",
764 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
766 g_signal_connect (content, "start-sending",
767 G_CALLBACK (on_tf_content_start_sending_cb), handler);
768 g_signal_connect (content, "stop-sending",
769 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
772 g_object_get (content, "media-type", &mtype,
773 "sink-pad", &spad, NULL);
775 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
776 spad, mtype, &retval);
779 tf_content_error (content, 0 /* FIXME */,
780 "Could not link source", NULL);
782 /* Get sending codec */
783 g_object_get (content, "fs-session", &session, NULL);
784 g_object_get (session, "current-send-codec", &codec, NULL);
786 update_sending_codec (handler, codec, session);
788 tp_clear_object (&session);
789 tp_clear_object (&codec);
791 /* Get receiving codec */
793 g_object_get (content, "fs-stream", &fs_stream, NULL);
794 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
796 update_receiving_codec (handler, codecs, fs_stream);
798 fs_codec_list_destroy (codecs);
799 tp_clear_object (&fs_stream);
802 gst_object_unref (spad);
806 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
808 EmpathyCallHandler *handler)
814 g_print ("removing content\n");
816 g_object_get (content, "media-type", &mtype,
817 "sink-pad", &spad, NULL);
819 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
820 spad, mtype, &retval);
824 g_warning ("Could not remove content!");
826 tf_content_error (content, 0 /* FIXME */,
827 "Could not link source", NULL);
832 on_tf_channel_closed_cb (TfChannel *tfchannel,
833 EmpathyCallHandler *handler)
835 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
839 on_tf_channel_ready (GObject *source,
840 GAsyncResult *result,
843 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
844 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
845 GError *error = NULL;
847 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
848 G_ASYNC_INITABLE (source), result, NULL));
850 if (priv->tfchannel == NULL)
852 g_warning ("Failed to create Farstream channel: %s", error->message);
853 g_error_free (error);
857 /* Set up the telepathy farstream channel */
858 g_signal_connect (priv->tfchannel, "closed",
859 G_CALLBACK (on_tf_channel_closed_cb), self);
860 g_signal_connect (priv->tfchannel, "fs-conference-added",
861 G_CALLBACK (on_tf_channel_conference_added_cb), self);
862 g_signal_connect (priv->tfchannel, "fs-conference-removed",
863 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
864 g_signal_connect (priv->tfchannel, "content-added",
865 G_CALLBACK (on_tf_channel_content_added_cb), self);
866 g_signal_connect (priv->tfchannel, "content-removed",
867 G_CALLBACK (on_tf_channel_content_removed_cb), self);
871 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
873 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
875 tf_channel_new_async (TP_CHANNEL (priv->call),
876 on_tf_channel_ready, self);
881 empathy_call_handler_request_cb (GObject *source,
882 GAsyncResult *result,
885 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
886 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
888 GError *error = NULL;
889 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
891 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
892 result, NULL, &error);
895 DEBUG ("Failed to create the channel: %s", error->message);
896 g_error_free (error);
900 if (!TPY_IS_CALL_CHANNEL (channel))
902 DEBUG ("The channel is not a Call channel!");
906 priv->call = TPY_CALL_CHANNEL (channel);
908 g_object_notify (G_OBJECT (self), "call-channel");
910 empathy_call_handler_start_tpfs (self);
915 on_call_accepted_cb (GObject *source_object,
919 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
920 GError *error = NULL;
922 if (!tpy_call_channel_accept_finish (call, res, &error))
924 g_warning ("could not accept Call: %s", error->message);
925 g_error_free (error);
930 empathy_call_handler_start_call (EmpathyCallHandler *handler,
933 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
934 /*TpAccountChannelRequest *req;
936 GHashTable *request;*/
938 if (priv->call != NULL)
940 empathy_call_handler_start_tpfs (handler);
941 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
946 g_warning ("No Call channel!");
950 /* No TpyCallChannel (we are redialing). Request a new call channel */
951 g_assert (priv->contact != NULL);
953 account = empathy_contact_get_account (priv->contact);
954 request = empathy_call_create_call_request (priv->contact,
955 priv->initial_audio, priv->initial_video);
957 req = tp_account_channel_request_new (account, request, timestamp);
959 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
960 empathy_call_handler_request_cb, handler);
962 g_object_unref (req);
963 g_hash_table_unref (request);
968 * empathy_call_handler_stop_call:
969 * @handler: an #EmpathyCallHandler
971 * Closes the #EmpathyCallHandler's call and frees its resources.
974 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
976 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
978 if (priv->call != NULL)
980 tpy_call_channel_hangup_async (priv->call,
981 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
983 tp_channel_close_async (TP_CHANNEL (priv->call),
985 tp_clear_object (&priv->call);
986 tp_clear_object (&priv->tfchannel);
991 * empathy_call_handler_has_initial_video:
992 * @handler: an #EmpathyCallHandler
994 * Return %TRUE if the call managed by this #EmpathyCallHandler was
995 * created with video enabled
997 * Return value: %TRUE if the call was created as a video conversation.
1000 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
1002 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1004 return priv->initial_video;
1008 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
1010 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1012 return priv->send_audio_codec;
1016 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1018 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1020 return priv->send_video_codec;
1024 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1026 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1028 return priv->recv_audio_codecs;
1032 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1034 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1036 return priv->recv_video_codecs;
1040 empathy_call_handler_get_audio_remote_candidate (
1041 EmpathyCallHandler *self)
1043 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1045 return priv->audio_remote_candidate;
1049 empathy_call_handler_get_audio_local_candidate (
1050 EmpathyCallHandler *self)
1052 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1054 return priv->audio_local_candidate;
1058 empathy_call_handler_get_video_remote_candidate (
1059 EmpathyCallHandler *self)
1061 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1063 return priv->video_remote_candidate;
1067 empathy_call_handler_get_video_local_candidate (
1068 EmpathyCallHandler *self)
1070 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1072 return priv->video_local_candidate;