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;
201 tp_value_array_unpack ((GValueArray *) call_state_reason, 3,
202 &actor, &reason, &dbus_reason);
204 g_signal_emit (handler, signals[STATE_CHANGED], 0, state, dbus_reason);
206 if (state == TPY_CALL_STATE_ENDED)
208 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
210 tp_clear_object (&priv->call);
211 tp_clear_object (&priv->tfchannel);
216 on_members_changed_cb (TpyCallChannel *call,
218 EmpathyCallHandler *self)
220 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
230 n_handles = g_hash_table_size (members);
234 handles = g_new0 (TpHandle, n_handles);
236 g_hash_table_iter_init (&iter, members);
237 while (g_hash_table_iter_next (&iter, &key, &value))
238 handles[i++] = GPOINTER_TO_UINT (key);
240 empathy_tp_contact_factory_get_from_handles (
241 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
244 NULL, NULL, G_OBJECT (self));
250 empathy_call_handler_constructed (GObject *object)
252 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
253 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
254 // GHashTable *members;
256 g_signal_connect (priv->call, "members-changed",
257 G_CALLBACK (on_members_changed_cb), object);
260 g_object_get (priv->call, "members", &members, NULL);
263 on_members_changed_cb (priv->call, members, self);
268 empathy_call_handler_set_property (GObject *object,
269 guint property_id, const GValue *value, GParamSpec *pspec)
271 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
276 priv->contact = g_value_dup_object (value);
279 priv->members = g_value_get_boxed (value);
281 case PROP_CALL_CHANNEL:
282 g_return_if_fail (priv->call == NULL);
284 priv->call = g_value_dup_object (value);
286 tp_g_signal_connect_object (priv->call, "state-changed",
287 G_CALLBACK (on_call_state_changed_cb), object, 0);
288 tp_g_signal_connect_object (priv->call, "invalidated",
289 G_CALLBACK (on_call_invalidated_cb), object, 0);
291 case PROP_INITIAL_AUDIO:
292 priv->initial_audio = g_value_get_boolean (value);
294 case PROP_INITIAL_VIDEO:
295 priv->initial_video = g_value_get_boolean (value);
298 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
303 empathy_call_handler_get_property (GObject *object,
304 guint property_id, GValue *value, GParamSpec *pspec)
306 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
311 g_value_set_object (value, priv->contact);
314 g_value_set_boxed (value, priv->members);
316 case PROP_CALL_CHANNEL:
317 g_value_set_object (value, priv->call);
319 case PROP_INITIAL_AUDIO:
320 g_value_set_boolean (value, priv->initial_audio);
322 case PROP_INITIAL_VIDEO:
323 g_value_set_boolean (value, priv->initial_video);
325 case PROP_SEND_AUDIO_CODEC:
326 g_value_set_boxed (value, priv->send_audio_codec);
328 case PROP_SEND_VIDEO_CODEC:
329 g_value_set_boxed (value, priv->send_video_codec);
331 case PROP_RECV_AUDIO_CODECS:
332 g_value_set_boxed (value, priv->recv_audio_codecs);
334 case PROP_RECV_VIDEO_CODECS:
335 g_value_set_boxed (value, priv->recv_video_codecs);
337 case PROP_AUDIO_REMOTE_CANDIDATE:
338 g_value_set_boxed (value, priv->audio_remote_candidate);
340 case PROP_VIDEO_REMOTE_CANDIDATE:
341 g_value_set_boxed (value, priv->video_remote_candidate);
343 case PROP_AUDIO_LOCAL_CANDIDATE:
344 g_value_set_boxed (value, priv->audio_local_candidate);
346 case PROP_VIDEO_LOCAL_CANDIDATE:
347 g_value_set_boxed (value, priv->video_local_candidate);
350 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
356 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
358 GObjectClass *object_class = G_OBJECT_CLASS (klass);
359 GParamSpec *param_spec;
361 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
363 object_class->constructed = empathy_call_handler_constructed;
364 object_class->set_property = empathy_call_handler_set_property;
365 object_class->get_property = empathy_call_handler_get_property;
366 object_class->dispose = empathy_call_handler_dispose;
367 object_class->finalize = empathy_call_handler_finalize;
369 param_spec = g_param_spec_object ("target-contact",
370 "TargetContact", "The contact",
371 EMPATHY_TYPE_CONTACT,
372 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
373 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
375 param_spec = g_param_spec_boxed ("members",
376 "call members", "The call participants",
378 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
379 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
381 param_spec = g_param_spec_object ("call-channel",
382 "call channel", "The call channel",
383 TPY_TYPE_CALL_CHANNEL,
384 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
385 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
387 param_spec = g_param_spec_boolean ("initial-audio",
388 "initial-audio", "Whether the call should start with audio",
390 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
391 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
394 param_spec = g_param_spec_boolean ("initial-video",
395 "initial-video", "Whether the call should start with video",
397 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
398 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
401 param_spec = g_param_spec_boxed ("send-audio-codec",
402 "send audio codec", "Codec used to encode the outgoing video stream",
404 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
405 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
408 param_spec = g_param_spec_boxed ("send-video-codec",
409 "send video codec", "Codec used to encode the outgoing video stream",
411 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
412 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
415 param_spec = g_param_spec_boxed ("recv-audio-codecs",
416 "recvs audio codec", "Codecs used to decode the incoming audio stream",
418 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
419 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
422 param_spec = g_param_spec_boxed ("recv-video-codecs",
423 "recvs video codec", "Codecs used to decode the incoming video stream",
425 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
426 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
429 param_spec = g_param_spec_boxed ("audio-remote-candidate",
430 "audio remote candidate",
431 "Remote candidate used for the audio stream",
433 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
434 g_object_class_install_property (object_class,
435 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
437 param_spec = g_param_spec_boxed ("video-remote-candidate",
438 "video remote candidate",
439 "Remote candidate used for the video stream",
441 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
442 g_object_class_install_property (object_class,
443 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
445 param_spec = g_param_spec_boxed ("audio-local-candidate",
446 "audio local candidate",
447 "Local candidate used for the audio stream",
449 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
450 g_object_class_install_property (object_class,
451 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
453 param_spec = g_param_spec_boxed ("video-local-candidate",
454 "video local candidate",
455 "Local candidate used for the video stream",
457 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
458 g_object_class_install_property (object_class,
459 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
461 signals[CONFERENCE_ADDED] =
462 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
463 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
464 g_cclosure_marshal_generic,
466 1, FS_TYPE_CONFERENCE);
468 signals[CONFERENCE_REMOVED] =
469 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
470 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
471 g_cclosure_marshal_generic,
473 1, FS_TYPE_CONFERENCE);
475 signals[SRC_PAD_ADDED] =
476 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
477 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
478 g_cclosure_marshal_generic,
480 2, GST_TYPE_PAD, G_TYPE_UINT);
482 signals[SINK_PAD_ADDED] =
483 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
484 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
485 g_cclosure_marshal_generic,
487 2, GST_TYPE_PAD, G_TYPE_UINT);
489 signals[SINK_PAD_REMOVED] =
490 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
491 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
492 g_cclosure_marshal_generic,
494 2, GST_TYPE_PAD, G_TYPE_UINT);
497 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
498 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
499 g_cclosure_marshal_generic,
503 signals[CANDIDATES_CHANGED] =
504 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
505 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
506 g_cclosure_marshal_generic,
507 G_TYPE_NONE, 1, G_TYPE_UINT);
509 signals[STATE_CHANGED] =
510 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
511 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
512 g_cclosure_marshal_generic,
513 G_TYPE_NONE, 1, G_TYPE_UINT);
517 empathy_call_handler_new_for_channel (TpyCallChannel *call,
518 EmpathyContact *contact)
520 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
521 "call-channel", call,
522 "initial-video", tpy_call_channel_has_initial_video (call),
523 "target-contact", contact,
528 update_sending_codec (EmpathyCallHandler *self,
532 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
535 if (codec == NULL || session == NULL)
538 g_object_get (session, "media-type", &type, NULL);
540 if (type == FS_MEDIA_TYPE_AUDIO)
542 priv->send_audio_codec = fs_codec_copy (codec);
543 g_object_notify (G_OBJECT (self), "send-audio-codec");
545 else if (type == FS_MEDIA_TYPE_VIDEO)
547 priv->send_video_codec = fs_codec_copy (codec);
548 g_object_notify (G_OBJECT (self), "send-video-codec");
553 update_receiving_codec (EmpathyCallHandler *self,
557 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
561 if (codecs == NULL || stream == NULL)
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 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
573 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
575 else if (type == FS_MEDIA_TYPE_VIDEO)
577 priv->recv_video_codecs = fs_codec_list_copy (codecs);
578 g_object_notify (G_OBJECT (self), "recv-video-codecs");
581 g_object_unref (session);
585 update_candidates (EmpathyCallHandler *self,
586 FsCandidate *remote_candidate,
587 FsCandidate *local_candidate,
590 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
597 g_object_get (stream, "session", &session, NULL);
601 g_object_get (session, "media-type", &type, NULL);
603 if (type == FS_MEDIA_TYPE_AUDIO)
605 if (remote_candidate != NULL)
607 fs_candidate_destroy (priv->audio_remote_candidate);
608 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
609 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
612 if (local_candidate != NULL)
614 fs_candidate_destroy (priv->audio_local_candidate);
615 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
616 g_object_notify (G_OBJECT (self), "audio-local-candidate");
619 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
620 FS_MEDIA_TYPE_AUDIO);
622 else if (type == FS_MEDIA_TYPE_VIDEO)
624 if (remote_candidate != NULL)
626 fs_candidate_destroy (priv->video_remote_candidate);
627 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
628 g_object_notify (G_OBJECT (self), "video-remote-candidate");
631 if (local_candidate != NULL)
633 fs_candidate_destroy (priv->video_local_candidate);
634 priv->video_local_candidate = fs_candidate_copy (local_candidate);
635 g_object_notify (G_OBJECT (self), "video-local-candidate");
638 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
639 FS_MEDIA_TYPE_VIDEO);
642 g_object_unref (session);
646 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
647 GstBus *bus, GstMessage *message)
649 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
650 const GstStructure *s = gst_message_get_structure (message);
652 if (priv->tfchannel == NULL)
656 gst_structure_has_name (s, "farsight-send-codec-changed"))
662 DEBUG ("farsight-send-codec-changed");
664 val = gst_structure_get_value (s, "codec");
665 codec = g_value_get_boxed (val);
667 val = gst_structure_get_value (s, "session");
668 session = g_value_get_object (val);
670 update_sending_codec (handler, codec, session);
672 else if (s != NULL &&
673 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
679 DEBUG ("farsight-recv-codecs-changed");
681 val = gst_structure_get_value (s, "codecs");
682 codecs = g_value_get_boxed (val);
684 val = gst_structure_get_value (s, "stream");
685 stream = g_value_get_object (val);
687 update_receiving_codec (handler, codecs, stream);
689 else if (s != NULL &&
690 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
693 FsCandidate *remote_candidate, *local_candidate;
696 DEBUG ("farsight-new-active-candidate-pair");
698 val = gst_structure_get_value (s, "remote-candidate");
699 remote_candidate = g_value_get_boxed (val);
701 val = gst_structure_get_value (s, "local-candidate");
702 local_candidate = g_value_get_boxed (val);
704 val = gst_structure_get_value (s, "stream");
705 stream = g_value_get_object (val);
707 update_candidates (handler, remote_candidate, local_candidate, stream);
710 tf_channel_bus_message (priv->tfchannel, message);
714 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
715 GstElement *conference,
716 EmpathyCallHandler *self)
718 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
723 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
724 FsConference *conference,
725 EmpathyCallHandler *self)
727 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
728 GST_ELEMENT (conference));
732 src_pad_added_error_idle (gpointer data)
734 TfContent *content = data;
736 tf_content_error (content, 0 /* FIXME */,
737 "Could not link sink", NULL);
738 g_object_unref (content);
744 on_tf_content_src_pad_added_cb (TfContent *content,
749 EmpathyCallHandler *handler)
754 g_object_get (content, "media-type", &media_type, NULL);
756 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
757 pad, media_type, &retval);
760 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
764 on_tf_channel_content_added_cb (TfChannel *tfchannel,
766 EmpathyCallHandler *handler)
771 // FsStream *fs_stream;
776 g_signal_connect (content, "src-pad-added",
777 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
779 g_signal_connect (content, "start-sending",
780 G_CALLBACK (on_tf_content_start_sending_cb), handler);
781 g_signal_connect (content, "stop-sending",
782 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
785 g_object_get (content, "media-type", &mtype,
786 "sink-pad", &spad, NULL);
788 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
789 spad, mtype, &retval);
792 tf_content_error (content, 0 /* FIXME */,
793 "Could not link source", NULL);
795 /* Get sending codec */
796 g_object_get (content, "fs-session", &session, NULL);
797 g_object_get (session, "current-send-codec", &codec, NULL);
799 update_sending_codec (handler, codec, session);
801 tp_clear_object (&session);
802 tp_clear_object (&codec);
804 /* Get receiving codec */
806 g_object_get (content, "fs-stream", &fs_stream, NULL);
807 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
809 update_receiving_codec (handler, codecs, fs_stream);
811 fs_codec_list_destroy (codecs);
812 tp_clear_object (&fs_stream);
815 gst_object_unref (spad);
819 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
821 EmpathyCallHandler *handler)
827 DEBUG ("removing content");
829 g_object_get (content, "media-type", &mtype,
830 "sink-pad", &spad, NULL);
832 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
833 spad, mtype, &retval);
837 g_warning ("Could not remove content!");
839 tf_content_error (content, 0 /* FIXME */,
840 "Could not link source", NULL);
845 on_tf_channel_closed_cb (TfChannel *tfchannel,
846 EmpathyCallHandler *handler)
848 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
852 on_tf_channel_ready (GObject *source,
853 GAsyncResult *result,
856 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
857 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
858 GError *error = NULL;
860 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
861 G_ASYNC_INITABLE (source), result, NULL));
863 if (priv->tfchannel == NULL)
865 g_warning ("Failed to create Farstream channel: %s", error->message);
866 g_error_free (error);
870 /* Set up the telepathy farstream channel */
871 g_signal_connect (priv->tfchannel, "closed",
872 G_CALLBACK (on_tf_channel_closed_cb), self);
873 g_signal_connect (priv->tfchannel, "fs-conference-added",
874 G_CALLBACK (on_tf_channel_conference_added_cb), self);
875 g_signal_connect (priv->tfchannel, "fs-conference-removed",
876 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
877 g_signal_connect (priv->tfchannel, "content-added",
878 G_CALLBACK (on_tf_channel_content_added_cb), self);
879 g_signal_connect (priv->tfchannel, "content-removed",
880 G_CALLBACK (on_tf_channel_content_removed_cb), self);
884 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
886 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
888 tf_channel_new_async (TP_CHANNEL (priv->call),
889 on_tf_channel_ready, self);
893 on_call_accepted_cb (GObject *source_object,
897 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
898 GError *error = NULL;
900 if (!tpy_call_channel_accept_finish (call, res, &error))
902 g_warning ("could not accept Call: %s", error->message);
903 g_error_free (error);
908 empathy_call_handler_request_cb (GObject *source,
909 GAsyncResult *result,
912 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
913 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
915 GError *error = NULL;
916 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
918 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
919 result, NULL, &error);
922 DEBUG ("Failed to create the channel: %s", error->message);
923 g_error_free (error);
927 if (!TPY_IS_CALL_CHANNEL (channel))
929 DEBUG ("The channel is not a Call channel!");
933 priv->call = TPY_CALL_CHANNEL (channel);
934 tp_g_signal_connect_object (priv->call, "state-changed",
935 G_CALLBACK (on_call_state_changed_cb), self, 0);
936 tp_g_signal_connect_object (priv->call, "invalidated",
937 G_CALLBACK (on_call_invalidated_cb), self, 0);
939 g_object_notify (G_OBJECT (self), "call-channel");
941 empathy_call_handler_start_tpfs (self);
942 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
946 empathy_call_handler_start_call (EmpathyCallHandler *handler,
949 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
950 TpAccountChannelRequest *req;
954 if (priv->call != NULL)
956 empathy_call_handler_start_tpfs (handler);
957 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
961 /* No TpyCallChannel (we are redialing). Request a new call channel */
962 g_assert (priv->contact != NULL);
964 account = empathy_contact_get_account (priv->contact);
965 request = empathy_call_create_call_request (
966 empathy_contact_get_id (priv->contact),
967 priv->initial_audio, priv->initial_video);
969 req = tp_account_channel_request_new (account, request, timestamp);
971 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
972 empathy_call_handler_request_cb, handler);
974 g_object_unref (req);
975 g_hash_table_unref (request);
979 * empathy_call_handler_stop_call:
980 * @handler: an #EmpathyCallHandler
982 * Closes the #EmpathyCallHandler's call and frees its resources.
985 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
987 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
989 if (priv->call != NULL)
991 tpy_call_channel_hangup_async (priv->call,
992 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
994 tp_channel_close_async (TP_CHANNEL (priv->call),
996 tp_clear_object (&priv->call);
997 tp_clear_object (&priv->tfchannel);
1002 * empathy_call_handler_has_initial_video:
1003 * @handler: an #EmpathyCallHandler
1005 * Return %TRUE if the call managed by this #EmpathyCallHandler was
1006 * created with video enabled
1008 * Return value: %TRUE if the call was created as a video conversation.
1011 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
1013 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1015 return priv->initial_video;
1019 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
1021 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1023 return priv->send_audio_codec;
1027 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1029 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1031 return priv->send_video_codec;
1035 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1037 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1039 return priv->recv_audio_codecs;
1043 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1045 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1047 return priv->recv_video_codecs;
1051 empathy_call_handler_get_audio_remote_candidate (
1052 EmpathyCallHandler *self)
1054 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1056 return priv->audio_remote_candidate;
1060 empathy_call_handler_get_audio_local_candidate (
1061 EmpathyCallHandler *self)
1063 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1065 return priv->audio_local_candidate;
1069 empathy_call_handler_get_video_remote_candidate (
1070 EmpathyCallHandler *self)
1072 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1074 return priv->video_remote_candidate;
1078 empathy_call_handler_get_video_local_candidate (
1079 EmpathyCallHandler *self)
1081 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1083 return priv->video_local_candidate;