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)
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;
203 tp_value_array_unpack ((GValueArray *) call_state_reason, 3,
204 &actor, &reason, &dbus_reason);
206 g_signal_emit (handler, signals[STATE_CHANGED], 0, state, dbus_reason);
208 if (state == TPY_CALL_STATE_ENDED)
210 tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
212 tp_clear_object (&priv->call);
213 tp_clear_object (&priv->tfchannel);
218 on_members_changed_cb (TpyCallChannel *call,
220 EmpathyCallHandler *self)
222 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
232 n_handles = g_hash_table_size (members);
236 handles = g_new0 (TpHandle, n_handles);
238 g_hash_table_iter_init (&iter, members);
239 while (g_hash_table_iter_next (&iter, &key, &value))
240 handles[i++] = GPOINTER_TO_UINT (key);
242 empathy_tp_contact_factory_get_from_handles (
243 tp_channel_borrow_connection (TP_CHANNEL (priv->call)),
246 NULL, NULL, G_OBJECT (self));
252 empathy_call_handler_constructed (GObject *object)
254 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
255 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
256 // GHashTable *members;
258 g_signal_connect (priv->call, "members-changed",
259 G_CALLBACK (on_members_changed_cb), object);
262 g_object_get (priv->call, "members", &members, NULL);
265 on_members_changed_cb (priv->call, members, self);
270 empathy_call_handler_set_property (GObject *object,
271 guint property_id, const GValue *value, GParamSpec *pspec)
273 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
278 priv->contact = g_value_dup_object (value);
281 priv->members = g_value_get_boxed (value);
283 case PROP_CALL_CHANNEL:
284 g_return_if_fail (priv->call == NULL);
286 priv->call = g_value_dup_object (value);
288 tp_g_signal_connect_object (priv->call, "state-changed",
289 G_CALLBACK (on_call_state_changed_cb), object, 0);
290 tp_g_signal_connect_object (priv->call, "invalidated",
291 G_CALLBACK (on_call_invalidated_cb), object, 0);
293 case PROP_INITIAL_AUDIO:
294 priv->initial_audio = g_value_get_boolean (value);
296 case PROP_INITIAL_VIDEO:
297 priv->initial_video = g_value_get_boolean (value);
300 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
305 empathy_call_handler_get_property (GObject *object,
306 guint property_id, GValue *value, GParamSpec *pspec)
308 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
313 g_value_set_object (value, priv->contact);
316 g_value_set_boxed (value, priv->members);
318 case PROP_CALL_CHANNEL:
319 g_value_set_object (value, priv->call);
321 case PROP_INITIAL_AUDIO:
322 g_value_set_boolean (value, priv->initial_audio);
324 case PROP_INITIAL_VIDEO:
325 g_value_set_boolean (value, priv->initial_video);
327 case PROP_SEND_AUDIO_CODEC:
328 g_value_set_boxed (value, priv->send_audio_codec);
330 case PROP_SEND_VIDEO_CODEC:
331 g_value_set_boxed (value, priv->send_video_codec);
333 case PROP_RECV_AUDIO_CODECS:
334 g_value_set_boxed (value, priv->recv_audio_codecs);
336 case PROP_RECV_VIDEO_CODECS:
337 g_value_set_boxed (value, priv->recv_video_codecs);
339 case PROP_AUDIO_REMOTE_CANDIDATE:
340 g_value_set_boxed (value, priv->audio_remote_candidate);
342 case PROP_VIDEO_REMOTE_CANDIDATE:
343 g_value_set_boxed (value, priv->video_remote_candidate);
345 case PROP_AUDIO_LOCAL_CANDIDATE:
346 g_value_set_boxed (value, priv->audio_local_candidate);
348 case PROP_VIDEO_LOCAL_CANDIDATE:
349 g_value_set_boxed (value, priv->video_local_candidate);
352 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
358 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
360 GObjectClass *object_class = G_OBJECT_CLASS (klass);
361 GParamSpec *param_spec;
363 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
365 object_class->constructed = empathy_call_handler_constructed;
366 object_class->set_property = empathy_call_handler_set_property;
367 object_class->get_property = empathy_call_handler_get_property;
368 object_class->dispose = empathy_call_handler_dispose;
369 object_class->finalize = empathy_call_handler_finalize;
371 param_spec = g_param_spec_object ("target-contact",
372 "TargetContact", "The contact",
373 EMPATHY_TYPE_CONTACT,
374 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
375 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
377 param_spec = g_param_spec_boxed ("members",
378 "call members", "The call participants",
380 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
381 g_object_class_install_property (object_class, PROP_MEMBERS, param_spec);
383 param_spec = g_param_spec_object ("call-channel",
384 "call channel", "The call channel",
385 TPY_TYPE_CALL_CHANNEL,
386 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
387 g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
389 param_spec = g_param_spec_boolean ("initial-audio",
390 "initial-audio", "Whether the call should start with audio",
392 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
393 g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
396 param_spec = g_param_spec_boolean ("initial-video",
397 "initial-video", "Whether the call should start with video",
399 G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
400 g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
403 param_spec = g_param_spec_boxed ("send-audio-codec",
404 "send audio codec", "Codec used to encode the outgoing video stream",
406 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
407 g_object_class_install_property (object_class, PROP_SEND_AUDIO_CODEC,
410 param_spec = g_param_spec_boxed ("send-video-codec",
411 "send video codec", "Codec used to encode the outgoing video stream",
413 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
414 g_object_class_install_property (object_class, PROP_SEND_VIDEO_CODEC,
417 param_spec = g_param_spec_boxed ("recv-audio-codecs",
418 "recvs audio codec", "Codecs used to decode the incoming audio stream",
420 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
421 g_object_class_install_property (object_class, PROP_RECV_AUDIO_CODECS,
424 param_spec = g_param_spec_boxed ("recv-video-codecs",
425 "recvs video codec", "Codecs used to decode the incoming video stream",
427 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
428 g_object_class_install_property (object_class, PROP_RECV_VIDEO_CODECS,
431 param_spec = g_param_spec_boxed ("audio-remote-candidate",
432 "audio remote candidate",
433 "Remote candidate used for the audio stream",
435 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
436 g_object_class_install_property (object_class,
437 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
439 param_spec = g_param_spec_boxed ("video-remote-candidate",
440 "video remote candidate",
441 "Remote candidate used for the video stream",
443 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
444 g_object_class_install_property (object_class,
445 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
447 param_spec = g_param_spec_boxed ("audio-local-candidate",
448 "audio local candidate",
449 "Local candidate used for the audio stream",
451 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
452 g_object_class_install_property (object_class,
453 PROP_AUDIO_REMOTE_CANDIDATE, param_spec);
455 param_spec = g_param_spec_boxed ("video-local-candidate",
456 "video local candidate",
457 "Local candidate used for the video stream",
459 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
460 g_object_class_install_property (object_class,
461 PROP_VIDEO_REMOTE_CANDIDATE, param_spec);
463 signals[CONFERENCE_ADDED] =
464 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
465 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
466 g_cclosure_marshal_generic,
468 1, FS_TYPE_CONFERENCE);
470 signals[CONFERENCE_REMOVED] =
471 g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
472 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
473 g_cclosure_marshal_generic,
475 1, FS_TYPE_CONFERENCE);
477 signals[SRC_PAD_ADDED] =
478 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
479 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
480 g_cclosure_marshal_generic,
482 2, TF_TYPE_CONTENT, GST_TYPE_PAD);
484 signals[CONTENT_ADDED] =
485 g_signal_new ("content-added", G_TYPE_FROM_CLASS (klass),
486 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
487 g_cclosure_marshal_generic,
491 signals[CONTENT_REMOVED] =
492 g_signal_new ("content-removed", G_TYPE_FROM_CLASS (klass),
493 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
494 g_cclosure_marshal_generic,
499 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
500 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
501 g_cclosure_marshal_generic,
505 signals[CANDIDATES_CHANGED] =
506 g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
507 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
508 g_cclosure_marshal_generic,
509 G_TYPE_NONE, 1, G_TYPE_UINT);
511 signals[STATE_CHANGED] =
512 g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
513 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
514 g_cclosure_marshal_generic,
515 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
517 signals[FRAMERATE_CHANGED] =
518 g_signal_new ("framerate-changed", G_TYPE_FROM_CLASS (klass),
519 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
520 g_cclosure_marshal_generic,
521 G_TYPE_NONE, 1, G_TYPE_UINT);
523 signals[RESOLUTION_CHANGED] =
524 g_signal_new ("resolution-changed", G_TYPE_FROM_CLASS (klass),
525 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
526 g_cclosure_marshal_generic,
528 2, G_TYPE_UINT, G_TYPE_UINT);
532 empathy_call_handler_new_for_channel (TpyCallChannel *call,
533 EmpathyContact *contact)
535 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
536 "call-channel", call,
537 "initial-video", tpy_call_channel_has_initial_video (call),
538 "target-contact", contact,
543 update_sending_codec (EmpathyCallHandler *self,
547 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
550 if (codec == NULL || session == NULL)
553 g_object_get (session, "media-type", &type, NULL);
555 if (type == FS_MEDIA_TYPE_AUDIO)
557 priv->send_audio_codec = fs_codec_copy (codec);
558 g_object_notify (G_OBJECT (self), "send-audio-codec");
560 else if (type == FS_MEDIA_TYPE_VIDEO)
562 priv->send_video_codec = fs_codec_copy (codec);
563 g_object_notify (G_OBJECT (self), "send-video-codec");
568 update_receiving_codec (EmpathyCallHandler *self,
572 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
576 if (codecs == NULL || stream == NULL)
579 g_object_get (stream, "session", &session, NULL);
583 g_object_get (session, "media-type", &type, NULL);
585 if (type == FS_MEDIA_TYPE_AUDIO)
587 priv->recv_audio_codecs = fs_codec_list_copy (codecs);
588 g_object_notify (G_OBJECT (self), "recv-audio-codecs");
590 else if (type == FS_MEDIA_TYPE_VIDEO)
592 priv->recv_video_codecs = fs_codec_list_copy (codecs);
593 g_object_notify (G_OBJECT (self), "recv-video-codecs");
596 g_object_unref (session);
600 update_candidates (EmpathyCallHandler *self,
601 FsCandidate *remote_candidate,
602 FsCandidate *local_candidate,
605 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
612 g_object_get (stream, "session", &session, NULL);
616 g_object_get (session, "media-type", &type, NULL);
618 if (type == FS_MEDIA_TYPE_AUDIO)
620 if (remote_candidate != NULL)
622 fs_candidate_destroy (priv->audio_remote_candidate);
623 priv->audio_remote_candidate = fs_candidate_copy (remote_candidate);
624 g_object_notify (G_OBJECT (self), "audio-remote-candidate");
627 if (local_candidate != NULL)
629 fs_candidate_destroy (priv->audio_local_candidate);
630 priv->audio_local_candidate = fs_candidate_copy (local_candidate);
631 g_object_notify (G_OBJECT (self), "audio-local-candidate");
634 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
635 FS_MEDIA_TYPE_AUDIO);
637 else if (type == FS_MEDIA_TYPE_VIDEO)
639 if (remote_candidate != NULL)
641 fs_candidate_destroy (priv->video_remote_candidate);
642 priv->video_remote_candidate = fs_candidate_copy (remote_candidate);
643 g_object_notify (G_OBJECT (self), "video-remote-candidate");
646 if (local_candidate != NULL)
648 fs_candidate_destroy (priv->video_local_candidate);
649 priv->video_local_candidate = fs_candidate_copy (local_candidate);
650 g_object_notify (G_OBJECT (self), "video-local-candidate");
653 g_signal_emit (G_OBJECT (self), signals[CANDIDATES_CHANGED], 0,
654 FS_MEDIA_TYPE_VIDEO);
657 g_object_unref (session);
661 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
662 GstBus *bus, GstMessage *message)
664 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
665 const GstStructure *s = gst_message_get_structure (message);
667 if (priv->tfchannel == NULL)
671 gst_structure_has_name (s, "farsight-send-codec-changed"))
677 DEBUG ("farsight-send-codec-changed");
679 val = gst_structure_get_value (s, "codec");
680 codec = g_value_get_boxed (val);
682 val = gst_structure_get_value (s, "session");
683 session = g_value_get_object (val);
685 update_sending_codec (handler, codec, session);
687 else if (s != NULL &&
688 gst_structure_has_name (s, "farsight-recv-codecs-changed"))
694 DEBUG ("farsight-recv-codecs-changed");
696 val = gst_structure_get_value (s, "codecs");
697 codecs = g_value_get_boxed (val);
699 val = gst_structure_get_value (s, "stream");
700 stream = g_value_get_object (val);
702 update_receiving_codec (handler, codecs, stream);
704 else if (s != NULL &&
705 gst_structure_has_name (s, "farsight-new-active-candidate-pair"))
708 FsCandidate *remote_candidate, *local_candidate;
711 DEBUG ("farsight-new-active-candidate-pair");
713 val = gst_structure_get_value (s, "remote-candidate");
714 remote_candidate = g_value_get_boxed (val);
716 val = gst_structure_get_value (s, "local-candidate");
717 local_candidate = g_value_get_boxed (val);
719 val = gst_structure_get_value (s, "stream");
720 stream = g_value_get_object (val);
722 update_candidates (handler, remote_candidate, local_candidate, stream);
725 tf_channel_bus_message (priv->tfchannel, message);
729 on_tf_channel_conference_added_cb (TfChannel *tfchannel,
730 GstElement *conference,
731 EmpathyCallHandler *self)
733 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
738 on_tf_channel_conference_removed_cb (TfChannel *tfchannel,
739 FsConference *conference,
740 EmpathyCallHandler *self)
742 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_REMOVED], 0,
743 GST_ELEMENT (conference));
747 src_pad_added_error_idle (gpointer data)
749 TfContent *content = data;
751 tf_content_error (content, 0 /* FIXME */,
752 "Could not link sink", NULL);
753 g_object_unref (content);
759 on_tf_content_src_pad_added_cb (TfContent *content,
764 EmpathyCallHandler *handler)
768 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
769 content, pad, &retval);
772 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
776 on_tf_content_framerate_changed (TfContent *content,
778 EmpathyCallHandler *handler)
782 g_object_get (content, "framerate", &framerate, NULL);
785 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
790 on_tf_content_resolution_changed (TfContent *content,
793 EmpathyCallHandler *handler)
795 if (width > 0 && height > 0)
796 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
801 on_tf_channel_content_added_cb (TfChannel *tfchannel,
803 EmpathyCallHandler *handler)
807 // FsStream *fs_stream;
812 g_signal_connect (content, "src-pad-added",
813 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
815 g_signal_connect (content, "start-sending",
816 G_CALLBACK (on_tf_content_start_sending_cb), handler);
817 g_signal_connect (content, "stop-sending",
818 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
821 g_signal_emit (G_OBJECT (handler), signals[CONTENT_ADDED], 0,
825 tf_content_error (content, 0 /* FIXME */,
826 "Could not link source", NULL);
828 /* Get sending codec */
829 g_object_get (content, "fs-session", &session, NULL);
830 g_object_get (session, "current-send-codec", &codec, NULL);
832 update_sending_codec (handler, codec, session);
834 tp_clear_object (&session);
835 tp_clear_object (&codec);
837 /* Get receiving codec */
839 g_object_get (content, "fs-stream", &fs_stream, NULL);
840 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
842 update_receiving_codec (handler, codecs, fs_stream);
844 fs_codec_list_destroy (codecs);
845 tp_clear_object (&fs_stream);
848 g_object_get (content, "media-type", &mtype, NULL);
850 if (mtype == FS_MEDIA_TYPE_VIDEO)
852 guint framerate, width, height;
854 g_signal_connect (content, "notify::framerate",
855 G_CALLBACK (on_tf_content_framerate_changed),
858 g_signal_connect (content, "resolution-changed",
859 G_CALLBACK (on_tf_content_resolution_changed),
862 g_object_get (content,
863 "framerate", &framerate,
869 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
872 if (width > 0 && height > 0)
873 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
879 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
881 EmpathyCallHandler *handler)
885 DEBUG ("removing content");
887 g_signal_emit (G_OBJECT (handler), signals[CONTENT_REMOVED], 0,
892 g_warning ("Could not remove content!");
894 tf_content_error (content, 0 /* FIXME */,
895 "Could not link source", NULL);
900 on_tf_channel_closed_cb (TfChannel *tfchannel,
901 EmpathyCallHandler *handler)
903 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
907 on_tf_channel_ready (GObject *source,
908 GAsyncResult *result,
911 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
912 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
913 GError *error = NULL;
915 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
916 G_ASYNC_INITABLE (source), result, NULL));
918 if (priv->tfchannel == NULL)
920 g_warning ("Failed to create Farstream channel: %s", error->message);
921 g_error_free (error);
925 /* Set up the telepathy farstream channel */
926 g_signal_connect (priv->tfchannel, "closed",
927 G_CALLBACK (on_tf_channel_closed_cb), self);
928 g_signal_connect (priv->tfchannel, "fs-conference-added",
929 G_CALLBACK (on_tf_channel_conference_added_cb), self);
930 g_signal_connect (priv->tfchannel, "fs-conference-removed",
931 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
932 g_signal_connect (priv->tfchannel, "content-added",
933 G_CALLBACK (on_tf_channel_content_added_cb), self);
934 g_signal_connect (priv->tfchannel, "content-removed",
935 G_CALLBACK (on_tf_channel_content_removed_cb), self);
939 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
941 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
943 tf_channel_new_async (TP_CHANNEL (priv->call),
944 on_tf_channel_ready, self);
948 on_call_accepted_cb (GObject *source_object,
952 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
953 GError *error = NULL;
955 if (!tpy_call_channel_accept_finish (call, res, &error))
957 g_warning ("could not accept Call: %s", error->message);
958 g_error_free (error);
963 empathy_call_handler_request_cb (GObject *source,
964 GAsyncResult *result,
967 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
968 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
970 GError *error = NULL;
971 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
973 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
974 result, NULL, &error);
977 DEBUG ("Failed to create the channel: %s", error->message);
978 g_error_free (error);
982 if (!TPY_IS_CALL_CHANNEL (channel))
984 DEBUG ("The channel is not a Call channel!");
988 priv->call = TPY_CALL_CHANNEL (channel);
989 tp_g_signal_connect_object (priv->call, "state-changed",
990 G_CALLBACK (on_call_state_changed_cb), self, 0);
991 tp_g_signal_connect_object (priv->call, "invalidated",
992 G_CALLBACK (on_call_invalidated_cb), self, 0);
994 g_object_notify (G_OBJECT (self), "call-channel");
996 empathy_call_handler_start_tpfs (self);
997 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
1001 empathy_call_handler_start_call (EmpathyCallHandler *handler,
1004 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1005 TpAccountChannelRequest *req;
1007 GHashTable *request;
1009 if (priv->call != NULL)
1011 empathy_call_handler_start_tpfs (handler);
1012 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
1016 /* No TpyCallChannel (we are redialing). Request a new call channel */
1017 g_assert (priv->contact != NULL);
1019 account = empathy_contact_get_account (priv->contact);
1020 request = empathy_call_create_call_request (
1021 empathy_contact_get_id (priv->contact),
1022 priv->initial_audio, priv->initial_video);
1024 req = tp_account_channel_request_new (account, request, timestamp);
1026 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
1027 empathy_call_handler_request_cb, handler);
1029 g_object_unref (req);
1030 g_hash_table_unref (request);
1034 * empathy_call_handler_stop_call:
1035 * @handler: an #EmpathyCallHandler
1037 * Closes the #EmpathyCallHandler's call and frees its resources.
1040 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
1042 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1044 if (priv->call != NULL)
1046 tpy_call_channel_hangup_async (priv->call,
1047 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
1048 "", "", NULL, NULL);
1049 tp_channel_close_async (TP_CHANNEL (priv->call),
1051 tp_clear_object (&priv->call);
1052 tp_clear_object (&priv->tfchannel);
1057 * empathy_call_handler_has_initial_video:
1058 * @handler: an #EmpathyCallHandler
1060 * Return %TRUE if the call managed by this #EmpathyCallHandler was
1061 * created with video enabled
1063 * Return value: %TRUE if the call was created as a video conversation.
1066 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
1068 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1070 return priv->initial_video;
1074 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
1076 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1078 return priv->send_audio_codec;
1082 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1084 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1086 return priv->send_video_codec;
1090 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1092 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1094 return priv->recv_audio_codecs;
1098 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1100 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1102 return priv->recv_video_codecs;
1106 empathy_call_handler_get_audio_remote_candidate (
1107 EmpathyCallHandler *self)
1109 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1111 return priv->audio_remote_candidate;
1115 empathy_call_handler_get_audio_local_candidate (
1116 EmpathyCallHandler *self)
1118 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1120 return priv->audio_local_candidate;
1124 empathy_call_handler_get_video_remote_candidate (
1125 EmpathyCallHandler *self)
1127 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1129 return priv->video_remote_candidate;
1133 empathy_call_handler_get_video_local_candidate (
1134 EmpathyCallHandler *self)
1136 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1138 return priv->video_local_candidate;