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"
39 #include "src-marshal.h"
41 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
42 #include <libempathy/empathy-debug.h>
44 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
59 static guint signals[LAST_SIGNAL] = {0};
62 PROP_CALL_CHANNEL = 1,
68 PROP_SEND_AUDIO_CODEC,
69 PROP_SEND_VIDEO_CODEC,
70 PROP_RECV_AUDIO_CODECS,
71 PROP_RECV_VIDEO_CODECS,
72 PROP_AUDIO_REMOTE_CANDIDATE,
73 PROP_VIDEO_REMOTE_CANDIDATE,
74 PROP_AUDIO_LOCAL_CANDIDATE,
75 PROP_VIDEO_LOCAL_CANDIDATE,
78 /* private structure */
80 struct _EmpathyCallHandlerPriv {
83 EmpathyContact *contact;
84 /* GArray of TpContacts */
87 gboolean initial_audio;
88 gboolean initial_video;
90 FsCodec *send_audio_codec;
91 FsCodec *send_video_codec;
92 GList *recv_audio_codecs;
93 GList *recv_video_codecs;
94 FsCandidate *audio_remote_candidate;
95 FsCandidate *video_remote_candidate;
96 FsCandidate *audio_local_candidate;
97 FsCandidate *video_local_candidate;
100 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
103 empathy_call_handler_dispose (GObject *object)
105 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
107 tp_clear_object (&priv->tfchannel);
108 tp_clear_object (&priv->call);
109 tp_clear_object (&priv->contact);
111 tp_clear_pointer (&priv->members, g_array_unref);
113 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
117 empathy_call_handler_finalize (GObject *object)
119 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
121 fs_codec_destroy (priv->send_audio_codec);
122 fs_codec_destroy (priv->send_video_codec);
123 fs_codec_list_destroy (priv->recv_audio_codecs);
124 fs_codec_list_destroy (priv->recv_video_codecs);
125 fs_candidate_destroy (priv->audio_remote_candidate);
126 fs_candidate_destroy (priv->video_remote_candidate);
127 fs_candidate_destroy (priv->audio_local_candidate);
128 fs_candidate_destroy (priv->video_local_candidate);
130 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
134 empathy_call_handler_init (EmpathyCallHandler *obj)
136 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
137 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
143 on_get_contacts_cb (TpConnection *connection,
145 EmpathyContact * const * contacts,
147 const TpHandle *failed,
150 GObject *weak_object)
152 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (weak_object);
153 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
157 g_warning ("Failed to get %d EmpathyContacts: %s",
158 n_failed, error->message);
160 priv->members = g_array_sized_new (FALSE, TRUE,
161 sizeof (EmpathyContact *), n_contacts);
163 for (i = 0; i < n_contacts; i++)
164 g_object_ref (contacts[i]);
166 g_array_append_vals (priv->members, contacts, n_contacts);
168 g_object_notify (G_OBJECT (self), "members");
172 on_call_invalidated_cb (TpyCallChannel *call,
176 EmpathyCallHandler *self)
178 EmpathyCallHandlerPriv *priv = self->priv;
180 if (priv->call == call)
182 /* Invalidated unexpectedly? Fake call ending */
183 g_signal_emit (self, signals[STATE_CHANGED], 0,
184 TPY_CALL_STATE_ENDED, NULL);
185 tp_clear_object (&priv->call);
186 tp_clear_object (&priv->tfchannel);
191 on_call_state_changed_cb (TpyCallChannel *call,
194 const GValueArray *call_state_reason,
195 GHashTable *call_state_details,
196 EmpathyCallHandler *handler)
198 EmpathyCallHandlerPriv *priv = handler->priv;
200 g_signal_emit (handler, signals[STATE_CHANGED], 0, state);
202 if (state == TPY_CALL_STATE_ENDED)
204 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
206 tp_clear_object (&priv->call);
207 tp_clear_object (&priv->tfchannel);
212 on_members_changed_cb (TpyCallChannel *call,
214 EmpathyCallHandler *self)
216 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
226 n_handles = g_hash_table_size (members);
230 handles = g_new0 (TpHandle, n_handles);
232 g_hash_table_iter_init (&iter, members);
233 while (g_hash_table_iter_next (&iter, &key, &value))
234 handles[i++] = GPOINTER_TO_UINT (key);
236 empathy_tp_contact_factory_get_from_handles (
237 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
240 NULL, NULL, G_OBJECT (self));
246 empathy_call_handler_constructed (GObject *object)
248 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
249 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
250 // GHashTable *members;
252 g_signal_connect (priv->call, "members-changed",
253 G_CALLBACK (on_members_changed_cb), object);
256 g_object_get (priv->call, "members", &members, NULL);
259 on_members_changed_cb (priv->call, members, self);
264 empathy_call_handler_set_property (GObject *object,
265 guint property_id, const GValue *value, GParamSpec *pspec)
267 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
272 priv->contact = g_value_dup_object (value);
275 priv->members = g_value_get_boxed (value);
277 case PROP_CALL_CHANNEL:
278 g_return_if_fail (priv->call == NULL);
280 priv->call = g_value_dup_object (value);
282 tp_g_signal_connect_object (priv->call, "state-changed",
283 G_CALLBACK (on_call_state_changed_cb), object, 0);
284 tp_g_signal_connect_object (priv->call, "invalidated",
285 G_CALLBACK (on_call_invalidated_cb), object, 0);
287 case PROP_INITIAL_AUDIO:
288 priv->initial_audio = g_value_get_boolean (value);
290 case PROP_INITIAL_VIDEO:
291 priv->initial_video = g_value_get_boolean (value);
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
299 empathy_call_handler_get_property (GObject *object,
300 guint property_id, GValue *value, GParamSpec *pspec)
302 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
307 g_value_set_object (value, priv->contact);
310 g_value_set_boxed (value, priv->members);
312 case PROP_CALL_CHANNEL:
313 g_value_set_object (value, priv->call);
315 case PROP_INITIAL_AUDIO:
316 g_value_set_boolean (value, priv->initial_audio);
318 case PROP_INITIAL_VIDEO:
319 g_value_set_boolean (value, priv->initial_video);
321 case PROP_SEND_AUDIO_CODEC:
322 g_value_set_boxed (value, priv->send_audio_codec);
324 case PROP_SEND_VIDEO_CODEC:
325 g_value_set_boxed (value, priv->send_video_codec);
327 case PROP_RECV_AUDIO_CODECS:
328 g_value_set_boxed (value, priv->recv_audio_codecs);
330 case PROP_RECV_VIDEO_CODECS:
331 g_value_set_boxed (value, priv->recv_video_codecs);
333 case PROP_AUDIO_REMOTE_CANDIDATE:
334 g_value_set_boxed (value, priv->audio_remote_candidate);
336 case PROP_VIDEO_REMOTE_CANDIDATE:
337 g_value_set_boxed (value, priv->video_remote_candidate);
339 case PROP_AUDIO_LOCAL_CANDIDATE:
340 g_value_set_boxed (value, priv->audio_local_candidate);
342 case PROP_VIDEO_LOCAL_CANDIDATE:
343 g_value_set_boxed (value, priv->video_local_candidate);
346 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
352 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
354 GObjectClass *object_class = G_OBJECT_CLASS (klass);
355 GParamSpec *param_spec;
357 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
359 object_class->constructed = empathy_call_handler_constructed;
360 object_class->set_property = empathy_call_handler_set_property;
361 object_class->get_property = empathy_call_handler_get_property;
362 object_class->dispose = empathy_call_handler_dispose;
363 object_class->finalize = empathy_call_handler_finalize;
365 param_spec = g_param_spec_object ("target-contact",
366 "TargetContact", "The contact",
367 EMPATHY_TYPE_CONTACT,
368 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
369 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
371 param_spec = g_param_spec_boxed ("members",
372 "call members", "The call participants",
374 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
375 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
377 param_spec = g_param_spec_object ("call-channel",
378 "call channel", "The call channel",
379 TPY_TYPE_CALL_CHANNEL,
380 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
381 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
383 param_spec = g_param_spec_boolean ("initial-audio",
384 "initial-audio", "Whether the call should start with audio",
386 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
387 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
390 param_spec = g_param_spec_boolean ("initial-video",
391 "initial-video", "Whether the call should start with video",
393 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
394 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
397 param_spec = g_param_spec_boxed ("send-audio-codec",
398 "send audio codec", "Codec used to encode the outgoing video stream",
400 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
401 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
404 param_spec = g_param_spec_boxed ("send-video-codec",
405 "send video codec", "Codec used to encode the outgoing video stream",
407 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
408 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
411 param_spec = g_param_spec_boxed ("recv-audio-codecs",
412 "recvs audio codec", "Codecs used to decode the incoming audio stream",
414 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
415 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
418 param_spec = g_param_spec_boxed ("recv-video-codecs",
419 "recvs video codec", "Codecs used to decode the incoming video stream",
421 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
422 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
425 param_spec = g_param_spec_boxed ("audio-remote-candidate",
426 "audio remote candidate",
427 "Remote candidate used for the audio stream",
429 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
430 g_object_class_install_property (object_class,
431 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
433 param_spec = g_param_spec_boxed ("video-remote-candidate",
434 "video remote candidate",
435 "Remote candidate used for the video stream",
437 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
438 g_object_class_install_property (object_class,
439 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
441 param_spec = g_param_spec_boxed ("audio-local-candidate",
442 "audio local candidate",
443 "Local candidate used for the audio stream",
445 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
446 g_object_class_install_property (object_class,
447 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
449 param_spec = g_param_spec_boxed ("video-local-candidate",
450 "video local candidate",
451 "Local candidate used for the video stream",
453 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
454 g_object_class_install_property (object_class,
455 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
457 signals[CONFERENCE_ADDED] =
458 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
459 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
460 g_cclosure_marshal_VOID__OBJECT,
462 1, FS_TYPE_CONFERENCE);
464 signals[CONFERENCE_REMOVED] =
465 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
466 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
467 g_cclosure_marshal_VOID__OBJECT,
469 1, FS_TYPE_CONFERENCE);
471 signals[SRC_PAD_ADDED] =
472 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
473 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
474 _src_marshal_BOOLEAN__OBJECT_UINT,
476 2, GST_TYPE_PAD, G_TYPE_UINT);
478 signals[SINK_PAD_ADDED] =
479 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
480 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
481 _src_marshal_BOOLEAN__OBJECT_UINT,
483 2, GST_TYPE_PAD, G_TYPE_UINT);
485 signals[SINK_PAD_REMOVED] =
486 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
487 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
488 _src_marshal_BOOLEAN__OBJECT_UINT,
490 2, GST_TYPE_PAD, G_TYPE_UINT);
493 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
494 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
495 g_cclosure_marshal_VOID__VOID,
499 signals[CANDIDATES_CHANGED] =
500 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
501 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
502 g_cclosure_marshal_VOID__UINT,
503 G_TYPE_NONE, 1, G_TYPE_UINT);
505 signals[STATE_CHANGED] =
506 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
507 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
508 g_cclosure_marshal_VOID__UINT,
509 G_TYPE_NONE, 1, G_TYPE_UINT);
513 empathy_call_handler_new_for_channel (TpyCallChannel *call,
514 EmpathyContact *contact)
516 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
517 "call-channel", call,
518 "initial-video", tpy_call_channel_has_initial_video (call),
519 "target-contact", contact,
524 update_sending_codec (EmpathyCallHandler *self,
528 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
531 if (codec == NULL || session == NULL)
534 g_object_get (session, "media-type", &type, NULL);
536 if (type == FS_MEDIA_TYPE_AUDIO)
538 priv->send_audio_codec = fs_codec_copy (codec);
539 g_object_notify (G_OBJECT (self), "send-audio-codec");
541 else if (type == FS_MEDIA_TYPE_VIDEO)
543 priv->send_video_codec = fs_codec_copy (codec);
544 g_object_notify (G_OBJECT (self), "send-video-codec");
549 update_receiving_codec (EmpathyCallHandler *self,
553 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
557 if (codecs == NULL || stream == NULL)
560 g_object_get (stream, "session", &session, NULL);
564 g_object_get (session, "media-type", &type, NULL);
566 if (type == FS_MEDIA_TYPE_AUDIO)
568 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
569 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
571 else if (type == FS_MEDIA_TYPE_VIDEO)
573 priv->recv_video_codecs = fs_codec_list_copy (codecs);
574 g_object_notify (G_OBJECT (self), "recv-video-codecs");
577 g_object_unref (session);
581 update_candidates (EmpathyCallHandler *self,
582 FsCandidate *remote_candidate,
583 FsCandidate *local_candidate,
586 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
593 g_object_get (stream, "session", &session, NULL);
597 g_object_get (session, "media-type", &type, NULL);
599 if (type == FS_MEDIA_TYPE_AUDIO)
601 if (remote_candidate != NULL)
603 fs_candidate_destroy (priv->audio_remote_candidate);
604 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
605 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
608 if (local_candidate != NULL)
610 fs_candidate_destroy (priv->audio_local_candidate);
611 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
612 g_object_notify (G_OBJECT (self), "audio-local-candidate");
615 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
616 FS_MEDIA_TYPE_AUDIO);
618 else if (type == FS_MEDIA_TYPE_VIDEO)
620 if (remote_candidate != NULL)
622 fs_candidate_destroy (priv->video_remote_candidate);
623 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
624 g_object_notify (G_OBJECT (self), "video-remote-candidate");
627 if (local_candidate != NULL)
629 fs_candidate_destroy (priv->video_local_candidate);
630 priv->video_local_candidate = fs_candidate_copy (local_candidate);
631 g_object_notify (G_OBJECT (self), "video-local-candidate");
634 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
635 FS_MEDIA_TYPE_VIDEO);
638 g_object_unref (session);
642 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
643 GstBus *bus, GstMessage *message)
645 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
646 const GstStructure *s = gst_message_get_structure (message);
648 if (priv->tfchannel == NULL)
652 gst_structure_has_name (s, "farsight-send-codec-changed"))
658 DEBUG ("farsight-send-codec-changed");
660 val = gst_structure_get_value (s, "codec");
661 codec = g_value_get_boxed (val);
663 val = gst_structure_get_value (s, "session");
664 session = g_value_get_object (val);
666 update_sending_codec (handler, codec, session);
668 else if (s != NULL &&
669 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
675 DEBUG ("farsight-recv-codecs-changed");
677 val = gst_structure_get_value (s, "codecs");
678 codecs = g_value_get_boxed (val);
680 val = gst_structure_get_value (s, "stream");
681 stream = g_value_get_object (val);
683 update_receiving_codec (handler, codecs, stream);
685 else if (s != NULL &&
686 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
689 FsCandidate *remote_candidate, *local_candidate;
692 DEBUG ("farsight-new-active-candidate-pair");
694 val = gst_structure_get_value (s, "remote-candidate");
695 remote_candidate = g_value_get_boxed (val);
697 val = gst_structure_get_value (s, "local-candidate");
698 local_candidate = g_value_get_boxed (val);
700 val = gst_structure_get_value (s, "stream");
701 stream = g_value_get_object (val);
703 update_candidates (handler, remote_candidate, local_candidate, stream);
706 tf_channel_bus_message (priv->tfchannel, message);
710 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
711 GstElement *conference,
712 EmpathyCallHandler *self)
714 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
719 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
720 FsConference *conference,
721 EmpathyCallHandler *self)
723 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
724 GST_ELEMENT (conference));
728 src_pad_added_error_idle (gpointer data)
730 TfContent *content = data;
732 tf_content_error (content, 0 /* FIXME */,
733 "Could not link sink", NULL);
734 g_object_unref (content);
740 on_tf_content_src_pad_added_cb (TfContent *content,
745 EmpathyCallHandler *handler)
750 g_object_get (content, "media-type", &media_type, NULL);
752 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
753 pad, media_type, &retval);
756 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
760 on_tf_channel_content_added_cb (TfChannel *tfchannel,
762 EmpathyCallHandler *handler)
767 // FsStream *fs_stream;
772 g_signal_connect (content, "src-pad-added",
773 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
775 g_signal_connect (content, "start-sending",
776 G_CALLBACK (on_tf_content_start_sending_cb), handler);
777 g_signal_connect (content, "stop-sending",
778 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
781 g_object_get (content, "media-type", &mtype,
782 "sink-pad", &spad, NULL);
784 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
785 spad, mtype, &retval);
788 tf_content_error (content, 0 /* FIXME */,
789 "Could not link source", NULL);
791 /* Get sending codec */
792 g_object_get (content, "fs-session", &session, NULL);
793 g_object_get (session, "current-send-codec", &codec, NULL);
795 update_sending_codec (handler, codec, session);
797 tp_clear_object (&session);
798 tp_clear_object (&codec);
800 /* Get receiving codec */
802 g_object_get (content, "fs-stream", &fs_stream, NULL);
803 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
805 update_receiving_codec (handler, codecs, fs_stream);
807 fs_codec_list_destroy (codecs);
808 tp_clear_object (&fs_stream);
811 gst_object_unref (spad);
815 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
817 EmpathyCallHandler *handler)
823 DEBUG ("removing content");
825 g_object_get (content, "media-type", &mtype,
826 "sink-pad", &spad, NULL);
828 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
829 spad, mtype, &retval);
833 g_warning ("Could not remove content!");
835 tf_content_error (content, 0 /* FIXME */,
836 "Could not link source", NULL);
841 on_tf_channel_closed_cb (TfChannel *tfchannel,
842 EmpathyCallHandler *handler)
844 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
848 on_tf_channel_ready (GObject *source,
849 GAsyncResult *result,
852 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
853 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
854 GError *error = NULL;
856 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
857 G_ASYNC_INITABLE (source), result, NULL));
859 if (priv->tfchannel == NULL)
861 g_warning ("Failed to create Farstream channel: %s", error->message);
862 g_error_free (error);
866 /* Set up the telepathy farstream channel */
867 g_signal_connect (priv->tfchannel, "closed",
868 G_CALLBACK (on_tf_channel_closed_cb), self);
869 g_signal_connect (priv->tfchannel, "fs-conference-added",
870 G_CALLBACK (on_tf_channel_conference_added_cb), self);
871 g_signal_connect (priv->tfchannel, "fs-conference-removed",
872 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
873 g_signal_connect (priv->tfchannel, "content-added",
874 G_CALLBACK (on_tf_channel_content_added_cb), self);
875 g_signal_connect (priv->tfchannel, "content-removed",
876 G_CALLBACK (on_tf_channel_content_removed_cb), self);
880 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
882 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
884 tf_channel_new_async (TP_CHANNEL (priv->call),
885 on_tf_channel_ready, self);
889 on_call_accepted_cb (GObject *source_object,
893 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
894 GError *error = NULL;
896 if (!tpy_call_channel_accept_finish (call, res, &error))
898 g_warning ("could not accept Call: %s", error->message);
899 g_error_free (error);
904 empathy_call_handler_request_cb (GObject *source,
905 GAsyncResult *result,
908 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
909 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
911 GError *error = NULL;
912 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
914 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
915 result, NULL, &error);
918 DEBUG ("Failed to create the channel: %s", error->message);
919 g_error_free (error);
923 if (!TPY_IS_CALL_CHANNEL (channel))
925 DEBUG ("The channel is not a Call channel!");
929 priv->call = TPY_CALL_CHANNEL (channel);
930 tp_g_signal_connect_object (priv->call, "state-changed",
931 G_CALLBACK (on_call_state_changed_cb), self, 0);
932 tp_g_signal_connect_object (priv->call, "invalidated",
933 G_CALLBACK (on_call_invalidated_cb), self, 0);
935 g_object_notify (G_OBJECT (self), "call-channel");
937 empathy_call_handler_start_tpfs (self);
938 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
942 empathy_call_handler_start_call (EmpathyCallHandler *handler,
945 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
946 TpAccountChannelRequest *req;
950 if (priv->call != NULL)
952 empathy_call_handler_start_tpfs (handler);
953 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
957 /* No TpyCallChannel (we are redialing). Request a new call channel */
958 g_assert (priv->contact != NULL);
960 account = empathy_contact_get_account (priv->contact);
961 request = empathy_call_create_call_request (
962 empathy_contact_get_id (priv->contact),
963 priv->initial_audio, priv->initial_video);
965 req = tp_account_channel_request_new (account, request, timestamp);
967 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
968 empathy_call_handler_request_cb, handler);
970 g_object_unref (req);
971 g_hash_table_unref (request);
975 * empathy_call_handler_stop_call:
976 * @handler: an #EmpathyCallHandler
978 * Closes the #EmpathyCallHandler's call and frees its resources.
981 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
983 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
985 if (priv->call != NULL)
987 tpy_call_channel_hangup_async (priv->call,
988 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
990 tp_channel_close_async (TP_CHANNEL (priv->call),
992 tp_clear_object (&priv->call);
993 tp_clear_object (&priv->tfchannel);
998 * empathy_call_handler_has_initial_video:
999 * @handler: an #EmpathyCallHandler
1001 * Return %TRUE if the call managed by this #EmpathyCallHandler was
1002 * created with video enabled
1004 * Return value: %TRUE if the call was created as a video conversation.
1007 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
1009 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1011 return priv->initial_video;
1015 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
1017 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1019 return priv->send_audio_codec;
1023 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1025 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1027 return priv->send_video_codec;
1031 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1033 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1035 return priv->recv_audio_codecs;
1039 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1041 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1043 return priv->recv_video_codecs;
1047 empathy_call_handler_get_audio_remote_candidate (
1048 EmpathyCallHandler *self)
1050 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1052 return priv->audio_remote_candidate;
1056 empathy_call_handler_get_audio_local_candidate (
1057 EmpathyCallHandler *self)
1059 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1061 return priv->audio_local_candidate;
1065 empathy_call_handler_get_video_remote_candidate (
1066 EmpathyCallHandler *self)
1068 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1070 return priv->video_remote_candidate;
1074 empathy_call_handler_get_video_local_candidate (
1075 EmpathyCallHandler *self)
1077 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1079 return priv->video_local_candidate;