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-channel-factory.h>
34 #include <libempathy/empathy-utils.h>
35 #include <libempathy/empathy-tp-contact-factory.h>
37 #include <libempathy-gtk/empathy-call-utils.h>
39 #include "empathy-call-handler.h"
40 #include "src-marshal.h"
42 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
43 #include <libempathy/empathy-debug.h>
45 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
60 static guint signals[LAST_SIGNAL] = {0};
63 PROP_CALL_CHANNEL = 1,
69 PROP_SEND_AUDIO_CODEC,
70 PROP_SEND_VIDEO_CODEC,
71 PROP_RECV_AUDIO_CODECS,
72 PROP_RECV_VIDEO_CODECS,
73 PROP_AUDIO_REMOTE_CANDIDATE,
74 PROP_VIDEO_REMOTE_CANDIDATE,
75 PROP_AUDIO_LOCAL_CANDIDATE,
76 PROP_VIDEO_LOCAL_CANDIDATE,
79 /* private structure */
81 struct _EmpathyCallHandlerPriv {
84 EmpathyContact *contact;
85 /* GArray of TpContacts */
88 gboolean initial_audio;
89 gboolean initial_video;
91 FsCodec *send_audio_codec;
92 FsCodec *send_video_codec;
93 GList *recv_audio_codecs;
94 GList *recv_video_codecs;
95 FsCandidate *audio_remote_candidate;
96 FsCandidate *video_remote_candidate;
97 FsCandidate *audio_local_candidate;
98 FsCandidate *video_local_candidate;
101 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
104 empathy_call_handler_dispose (GObject *object)
106 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
108 tp_clear_object (&priv->tfchannel);
109 tp_clear_object (&priv->call);
110 tp_clear_object (&priv->contact);
112 tp_clear_pointer (&priv->members, g_array_unref);
114 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
118 empathy_call_handler_finalize (GObject *object)
120 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
122 fs_codec_destroy (priv->send_audio_codec);
123 fs_codec_destroy (priv->send_video_codec);
124 fs_codec_list_destroy (priv->recv_audio_codecs);
125 fs_codec_list_destroy (priv->recv_video_codecs);
126 fs_candidate_destroy (priv->audio_remote_candidate);
127 fs_candidate_destroy (priv->video_remote_candidate);
128 fs_candidate_destroy (priv->audio_local_candidate);
129 fs_candidate_destroy (priv->video_local_candidate);
131 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
135 empathy_call_handler_init (EmpathyCallHandler *obj)
137 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
138 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
144 on_get_contacts_cb (TpConnection *connection,
146 EmpathyContact * const * contacts,
148 const TpHandle *failed,
151 GObject *weak_object)
153 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (weak_object);
154 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
158 g_warning ("Failed to get %d EmpathyContacts: %s",
159 n_failed, error->message);
161 priv->members = g_array_sized_new (FALSE, TRUE,
162 sizeof (EmpathyContact *), n_contacts);
164 for (i = 0; i < n_contacts; i++)
165 g_object_ref (contacts[i]);
167 g_array_append_vals (priv->members, contacts, n_contacts);
169 g_object_notify (G_OBJECT (self), "members");
173 on_call_invalidated_cb (TpyCallChannel *call,
177 EmpathyCallHandler *self)
179 EmpathyCallHandlerPriv *priv = self->priv;
181 if (priv->call == call)
183 /* Invalidated unexpectedly? Fake call ending */
184 g_signal_emit (self, signals[STATE_CHANGED], 0,
185 TPY_CALL_STATE_ENDED, NULL);
186 tp_clear_object (&priv->call);
187 tp_clear_object (&priv->tfchannel);
192 on_call_state_changed_cb (TpyCallChannel *call,
195 const GValueArray *call_state_reason,
196 GHashTable *call_state_details,
197 EmpathyCallHandler *handler)
199 EmpathyCallHandlerPriv *priv = handler->priv;
201 g_signal_emit (handler, signals[STATE_CHANGED], 0, state);
203 if (state == TPY_CALL_STATE_ENDED)
205 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
207 tp_clear_object (&priv->call);
208 tp_clear_object (&priv->tfchannel);
213 on_members_changed_cb (TpyCallChannel *call,
215 EmpathyCallHandler *self)
217 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
227 n_handles = g_hash_table_size (members);
231 handles = g_new0 (TpHandle, n_handles);
233 g_hash_table_iter_init (&iter, members);
234 while (g_hash_table_iter_next (&iter, &key, &value))
235 handles[i++] = GPOINTER_TO_UINT (key);
237 empathy_tp_contact_factory_get_from_handles (
238 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
241 NULL, NULL, G_OBJECT (self));
247 empathy_call_handler_constructed (GObject *object)
249 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
250 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
251 // GHashTable *members;
253 g_signal_connect (priv->call, "members-changed",
254 G_CALLBACK (on_members_changed_cb), object);
257 g_object_get (priv->call, "members", &members, NULL);
260 on_members_changed_cb (priv->call, members, self);
265 empathy_call_handler_set_property (GObject *object,
266 guint property_id, const GValue *value, GParamSpec *pspec)
268 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
273 priv->contact = g_value_dup_object (value);
276 priv->members = g_value_get_boxed (value);
278 case PROP_CALL_CHANNEL:
279 g_return_if_fail (priv->call == NULL);
281 priv->call = g_value_dup_object (value);
283 tp_g_signal_connect_object (priv->call, "state-changed",
284 G_CALLBACK (on_call_state_changed_cb), object, 0);
285 tp_g_signal_connect_object (priv->call, "invalidated",
286 G_CALLBACK (on_call_invalidated_cb), object, 0);
288 case PROP_INITIAL_AUDIO:
289 priv->initial_audio = g_value_get_boolean (value);
291 case PROP_INITIAL_VIDEO:
292 priv->initial_video = g_value_get_boolean (value);
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
300 empathy_call_handler_get_property (GObject *object,
301 guint property_id, GValue *value, GParamSpec *pspec)
303 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
308 g_value_set_object (value, priv->contact);
311 g_value_set_boxed (value, priv->members);
313 case PROP_CALL_CHANNEL:
314 g_value_set_object (value, priv->call);
316 case PROP_INITIAL_AUDIO:
317 g_value_set_boolean (value, priv->initial_audio);
319 case PROP_INITIAL_VIDEO:
320 g_value_set_boolean (value, priv->initial_video);
322 case PROP_SEND_AUDIO_CODEC:
323 g_value_set_boxed (value, priv->send_audio_codec);
325 case PROP_SEND_VIDEO_CODEC:
326 g_value_set_boxed (value, priv->send_video_codec);
328 case PROP_RECV_AUDIO_CODECS:
329 g_value_set_boxed (value, priv->recv_audio_codecs);
331 case PROP_RECV_VIDEO_CODECS:
332 g_value_set_boxed (value, priv->recv_video_codecs);
334 case PROP_AUDIO_REMOTE_CANDIDATE:
335 g_value_set_boxed (value, priv->audio_remote_candidate);
337 case PROP_VIDEO_REMOTE_CANDIDATE:
338 g_value_set_boxed (value, priv->video_remote_candidate);
340 case PROP_AUDIO_LOCAL_CANDIDATE:
341 g_value_set_boxed (value, priv->audio_local_candidate);
343 case PROP_VIDEO_LOCAL_CANDIDATE:
344 g_value_set_boxed (value, priv->video_local_candidate);
347 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
353 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
355 GObjectClass *object_class = G_OBJECT_CLASS (klass);
356 GParamSpec *param_spec;
358 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
360 object_class->constructed = empathy_call_handler_constructed;
361 object_class->set_property = empathy_call_handler_set_property;
362 object_class->get_property = empathy_call_handler_get_property;
363 object_class->dispose = empathy_call_handler_dispose;
364 object_class->finalize = empathy_call_handler_finalize;
366 param_spec = g_param_spec_object ("target-contact",
367 "TargetContact", "The contact",
368 EMPATHY_TYPE_CONTACT,
369 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
370 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
372 param_spec = g_param_spec_boxed ("members",
373 "call members", "The call participants",
375 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
376 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
378 param_spec = g_param_spec_object ("call-channel",
379 "call channel", "The call channel",
380 TPY_TYPE_CALL_CHANNEL,
381 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
382 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
384 param_spec = g_param_spec_boolean ("initial-audio",
385 "initial-audio", "Whether the call should start with audio",
387 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
388 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
391 param_spec = g_param_spec_boolean ("initial-video",
392 "initial-video", "Whether the call should start with video",
394 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
395 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
398 param_spec = g_param_spec_boxed ("send-audio-codec",
399 "send audio codec", "Codec used to encode the outgoing video stream",
401 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
402 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
405 param_spec = g_param_spec_boxed ("send-video-codec",
406 "send video codec", "Codec used to encode the outgoing video stream",
408 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
409 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
412 param_spec = g_param_spec_boxed ("recv-audio-codecs",
413 "recvs audio codec", "Codecs used to decode the incoming audio stream",
415 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
416 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
419 param_spec = g_param_spec_boxed ("recv-video-codecs",
420 "recvs video codec", "Codecs used to decode the incoming video stream",
422 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
423 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
426 param_spec = g_param_spec_boxed ("audio-remote-candidate",
427 "audio remote candidate",
428 "Remote candidate used for the audio stream",
430 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
431 g_object_class_install_property (object_class,
432 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
434 param_spec = g_param_spec_boxed ("video-remote-candidate",
435 "video remote candidate",
436 "Remote candidate used for the video stream",
438 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
439 g_object_class_install_property (object_class,
440 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
442 param_spec = g_param_spec_boxed ("audio-local-candidate",
443 "audio local candidate",
444 "Local candidate used for the audio stream",
446 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
447 g_object_class_install_property (object_class,
448 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
450 param_spec = g_param_spec_boxed ("video-local-candidate",
451 "video local candidate",
452 "Local candidate used for the video stream",
454 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
455 g_object_class_install_property (object_class,
456 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
458 signals[CONFERENCE_ADDED] =
459 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
460 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
461 g_cclosure_marshal_VOID__OBJECT,
463 1, FS_TYPE_CONFERENCE);
465 signals[CONFERENCE_REMOVED] =
466 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
467 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
468 g_cclosure_marshal_VOID__OBJECT,
470 1, FS_TYPE_CONFERENCE);
472 signals[SRC_PAD_ADDED] =
473 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
474 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
475 _src_marshal_BOOLEAN__OBJECT_UINT,
477 2, GST_TYPE_PAD, G_TYPE_UINT);
479 signals[SINK_PAD_ADDED] =
480 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
481 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
482 _src_marshal_BOOLEAN__OBJECT_UINT,
484 2, GST_TYPE_PAD, G_TYPE_UINT);
486 signals[SINK_PAD_REMOVED] =
487 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
488 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
489 _src_marshal_BOOLEAN__OBJECT_UINT,
491 2, GST_TYPE_PAD, G_TYPE_UINT);
494 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
495 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
496 g_cclosure_marshal_VOID__VOID,
500 signals[CANDIDATES_CHANGED] =
501 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
502 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
503 g_cclosure_marshal_VOID__UINT,
504 G_TYPE_NONE, 1, G_TYPE_UINT);
506 signals[STATE_CHANGED] =
507 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
508 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
509 g_cclosure_marshal_VOID__UINT,
510 G_TYPE_NONE, 1, G_TYPE_UINT);
514 empathy_call_handler_new_for_channel (TpyCallChannel *call,
515 EmpathyContact *contact)
517 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
518 "call-channel", call,
519 "initial-video", tpy_call_channel_has_initial_video (call),
520 "target-contact", contact,
525 update_sending_codec (EmpathyCallHandler *self,
529 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
532 if (codec == NULL || session == NULL)
535 g_object_get (session, "media-type", &type, NULL);
537 if (type == FS_MEDIA_TYPE_AUDIO)
539 priv->send_audio_codec = fs_codec_copy (codec);
540 g_object_notify (G_OBJECT (self), "send-audio-codec");
542 else if (type == FS_MEDIA_TYPE_VIDEO)
544 priv->send_video_codec = fs_codec_copy (codec);
545 g_object_notify (G_OBJECT (self), "send-video-codec");
550 update_receiving_codec (EmpathyCallHandler *self,
554 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
558 if (codecs == NULL || stream == NULL)
561 g_object_get (stream, "session", &session, NULL);
565 g_object_get (session, "media-type", &type, NULL);
567 if (type == FS_MEDIA_TYPE_AUDIO)
569 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
570 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
572 else if (type == FS_MEDIA_TYPE_VIDEO)
574 priv->recv_video_codecs = fs_codec_list_copy (codecs);
575 g_object_notify (G_OBJECT (self), "recv-video-codecs");
578 g_object_unref (session);
582 update_candidates (EmpathyCallHandler *self,
583 FsCandidate *remote_candidate,
584 FsCandidate *local_candidate,
587 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
594 g_object_get (stream, "session", &session, NULL);
598 g_object_get (session, "media-type", &type, NULL);
600 if (type == FS_MEDIA_TYPE_AUDIO)
602 if (remote_candidate != NULL)
604 fs_candidate_destroy (priv->audio_remote_candidate);
605 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
606 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
609 if (local_candidate != NULL)
611 fs_candidate_destroy (priv->audio_local_candidate);
612 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
613 g_object_notify (G_OBJECT (self), "audio-local-candidate");
616 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
617 FS_MEDIA_TYPE_AUDIO);
619 else if (type == FS_MEDIA_TYPE_VIDEO)
621 if (remote_candidate != NULL)
623 fs_candidate_destroy (priv->video_remote_candidate);
624 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
625 g_object_notify (G_OBJECT (self), "video-remote-candidate");
628 if (local_candidate != NULL)
630 fs_candidate_destroy (priv->video_local_candidate);
631 priv->video_local_candidate = fs_candidate_copy (local_candidate);
632 g_object_notify (G_OBJECT (self), "video-local-candidate");
635 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
636 FS_MEDIA_TYPE_VIDEO);
639 g_object_unref (session);
643 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
644 GstBus *bus, GstMessage *message)
646 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
647 const GstStructure *s = gst_message_get_structure (message);
649 if (priv->tfchannel == NULL)
653 gst_structure_has_name (s, "farsight-send-codec-changed"))
659 DEBUG ("farsight-send-codec-changed");
661 val = gst_structure_get_value (s, "codec");
662 codec = g_value_get_boxed (val);
664 val = gst_structure_get_value (s, "session");
665 session = g_value_get_object (val);
667 update_sending_codec (handler, codec, session);
669 else if (s != NULL &&
670 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
676 DEBUG ("farsight-recv-codecs-changed");
678 val = gst_structure_get_value (s, "codecs");
679 codecs = g_value_get_boxed (val);
681 val = gst_structure_get_value (s, "stream");
682 stream = g_value_get_object (val);
684 update_receiving_codec (handler, codecs, stream);
686 else if (s != NULL &&
687 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
690 FsCandidate *remote_candidate, *local_candidate;
693 DEBUG ("farsight-new-active-candidate-pair");
695 val = gst_structure_get_value (s, "remote-candidate");
696 remote_candidate = g_value_get_boxed (val);
698 val = gst_structure_get_value (s, "local-candidate");
699 local_candidate = g_value_get_boxed (val);
701 val = gst_structure_get_value (s, "stream");
702 stream = g_value_get_object (val);
704 update_candidates (handler, remote_candidate, local_candidate, stream);
707 tf_channel_bus_message (priv->tfchannel, message);
711 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
712 GstElement *conference,
713 EmpathyCallHandler *self)
715 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
720 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
721 FsConference *conference,
722 EmpathyCallHandler *self)
724 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
725 GST_ELEMENT (conference));
729 src_pad_added_error_idle (gpointer data)
731 TfContent *content = data;
733 tf_content_error (content, 0 /* FIXME */,
734 "Could not link sink", NULL);
735 g_object_unref (content);
741 on_tf_content_src_pad_added_cb (TfContent *content,
746 EmpathyCallHandler *handler)
751 g_object_get (content, "media-type", &media_type, NULL);
753 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
754 pad, media_type, &retval);
757 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
761 on_tf_channel_content_added_cb (TfChannel *tfchannel,
763 EmpathyCallHandler *handler)
768 // FsStream *fs_stream;
773 g_signal_connect (content, "src-pad-added",
774 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
776 g_signal_connect (content, "start-sending",
777 G_CALLBACK (on_tf_content_start_sending_cb), handler);
778 g_signal_connect (content, "stop-sending",
779 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
782 g_object_get (content, "media-type", &mtype,
783 "sink-pad", &spad, NULL);
785 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
786 spad, mtype, &retval);
789 tf_content_error (content, 0 /* FIXME */,
790 "Could not link source", NULL);
792 /* Get sending codec */
793 g_object_get (content, "fs-session", &session, NULL);
794 g_object_get (session, "current-send-codec", &codec, NULL);
796 update_sending_codec (handler, codec, session);
798 tp_clear_object (&session);
799 tp_clear_object (&codec);
801 /* Get receiving codec */
803 g_object_get (content, "fs-stream", &fs_stream, NULL);
804 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
806 update_receiving_codec (handler, codecs, fs_stream);
808 fs_codec_list_destroy (codecs);
809 tp_clear_object (&fs_stream);
812 gst_object_unref (spad);
816 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
818 EmpathyCallHandler *handler)
824 DEBUG ("removing content");
826 g_object_get (content, "media-type", &mtype,
827 "sink-pad", &spad, NULL);
829 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
830 spad, mtype, &retval);
834 g_warning ("Could not remove content!");
836 tf_content_error (content, 0 /* FIXME */,
837 "Could not link source", NULL);
842 on_tf_channel_closed_cb (TfChannel *tfchannel,
843 EmpathyCallHandler *handler)
845 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
849 on_tf_channel_ready (GObject *source,
850 GAsyncResult *result,
853 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
854 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
855 GError *error = NULL;
857 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
858 G_ASYNC_INITABLE (source), result, NULL));
860 if (priv->tfchannel == NULL)
862 g_warning ("Failed to create Farstream channel: %s", error->message);
863 g_error_free (error);
867 /* Set up the telepathy farstream channel */
868 g_signal_connect (priv->tfchannel, "closed",
869 G_CALLBACK (on_tf_channel_closed_cb), self);
870 g_signal_connect (priv->tfchannel, "fs-conference-added",
871 G_CALLBACK (on_tf_channel_conference_added_cb), self);
872 g_signal_connect (priv->tfchannel, "fs-conference-removed",
873 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
874 g_signal_connect (priv->tfchannel, "content-added",
875 G_CALLBACK (on_tf_channel_content_added_cb), self);
876 g_signal_connect (priv->tfchannel, "content-removed",
877 G_CALLBACK (on_tf_channel_content_removed_cb), self);
881 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
883 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
885 tf_channel_new_async (TP_CHANNEL (priv->call),
886 on_tf_channel_ready, self);
890 on_call_accepted_cb (GObject *source_object,
894 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
895 GError *error = NULL;
897 if (!tpy_call_channel_accept_finish (call, res, &error))
899 g_warning ("could not accept Call: %s", error->message);
900 g_error_free (error);
905 empathy_call_handler_request_cb (GObject *source,
906 GAsyncResult *result,
909 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
910 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
912 GError *error = NULL;
913 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
915 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
916 result, NULL, &error);
919 DEBUG ("Failed to create the channel: %s", error->message);
920 g_error_free (error);
924 if (!TPY_IS_CALL_CHANNEL (channel))
926 DEBUG ("The channel is not a Call channel!");
930 priv->call = TPY_CALL_CHANNEL (channel);
931 tp_g_signal_connect_object (priv->call, "state-changed",
932 G_CALLBACK (on_call_state_changed_cb), self, 0);
933 tp_g_signal_connect_object (priv->call, "invalidated",
934 G_CALLBACK (on_call_invalidated_cb), self, 0);
936 g_object_notify (G_OBJECT (self), "call-channel");
938 empathy_call_handler_start_tpfs (self);
939 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
943 empathy_call_handler_start_call (EmpathyCallHandler *handler,
946 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
947 EmpathyChannelFactory *channel_factory;
948 TpAccountChannelRequest *req;
952 if (priv->call != NULL)
954 empathy_call_handler_start_tpfs (handler);
955 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
959 /* No TpyCallChannel (we are redialing). Request a new call channel */
960 g_assert (priv->contact != NULL);
962 account = empathy_contact_get_account (priv->contact);
963 request = empathy_call_create_call_request (
964 empathy_contact_get_id (priv->contact),
965 priv->initial_audio, priv->initial_video);
967 req = tp_account_channel_request_new (account, request, timestamp);
969 channel_factory = empathy_channel_factory_dup ();
970 tp_account_channel_request_set_channel_factory (req,
971 TP_CLIENT_CHANNEL_FACTORY (channel_factory));
972 g_object_unref (channel_factory);
974 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
975 empathy_call_handler_request_cb, handler);
977 g_object_unref (req);
978 g_hash_table_unref (request);
982 * empathy_call_handler_stop_call:
983 * @handler: an #EmpathyCallHandler
985 * Closes the #EmpathyCallHandler's call and frees its resources.
988 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
990 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
992 if (priv->call != NULL)
994 tpy_call_channel_hangup_async (priv->call,
995 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
997 tp_channel_close_async (TP_CHANNEL (priv->call),
999 tp_clear_object (&priv->call);
1000 tp_clear_object (&priv->tfchannel);
1005 * empathy_call_handler_has_initial_video:
1006 * @handler: an #EmpathyCallHandler
1008 * Return %TRUE if the call managed by this #EmpathyCallHandler was
1009 * created with video enabled
1011 * Return value: %TRUE if the call was created as a video conversation.
1014 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
1016 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1018 return priv->initial_video;
1022 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
1024 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1026 return priv->send_audio_codec;
1030 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1032 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1034 return priv->send_video_codec;
1038 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1040 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1042 return priv->recv_audio_codecs;
1046 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1048 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1050 return priv->recv_video_codecs;
1054 empathy_call_handler_get_audio_remote_candidate (
1055 EmpathyCallHandler *self)
1057 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1059 return priv->audio_remote_candidate;
1063 empathy_call_handler_get_audio_local_candidate (
1064 EmpathyCallHandler *self)
1066 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1068 return priv->audio_local_candidate;
1072 empathy_call_handler_get_video_remote_candidate (
1073 EmpathyCallHandler *self)
1075 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1077 return priv->video_remote_candidate;
1081 empathy_call_handler_get_video_local_candidate (
1082 EmpathyCallHandler *self)
1084 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1086 return priv->video_local_candidate;