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, GST_TYPE_PAD, G_TYPE_UINT);
484 signals[SINK_PAD_ADDED] =
485 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
486 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
487 g_cclosure_marshal_generic,
489 2, GST_TYPE_PAD, G_TYPE_UINT);
491 signals[SINK_PAD_REMOVED] =
492 g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
493 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
494 g_cclosure_marshal_generic,
496 2, GST_TYPE_PAD, G_TYPE_UINT);
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)
769 g_object_get (content, "media-type", &media_type, NULL);
771 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
772 pad, media_type, &retval);
775 g_idle_add (src_pad_added_error_idle, g_object_ref (content));
779 on_tf_content_framerate_changed (TfContent *content,
781 EmpathyCallHandler *handler)
785 g_object_get (content, "framerate", &framerate, NULL);
788 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
793 on_tf_content_resolution_changed (TfContent *content,
796 EmpathyCallHandler *handler)
798 if (width > 0 && height > 0)
799 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
804 on_tf_channel_content_added_cb (TfChannel *tfchannel,
806 EmpathyCallHandler *handler)
811 // FsStream *fs_stream;
816 g_signal_connect (content, "src-pad-added",
817 G_CALLBACK (on_tf_content_src_pad_added_cb), handler);
819 g_signal_connect (content, "start-sending",
820 G_CALLBACK (on_tf_content_start_sending_cb), handler);
821 g_signal_connect (content, "stop-sending",
822 G_CALLBACK (on_tf_content_stop_sending_cb), handler);
825 g_object_get (content, "media-type", &mtype,
826 "sink-pad", &spad, NULL);
828 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
829 spad, mtype, &retval);
832 tf_content_error (content, 0 /* FIXME */,
833 "Could not link source", NULL);
835 /* Get sending codec */
836 g_object_get (content, "fs-session", &session, NULL);
837 g_object_get (session, "current-send-codec", &codec, NULL);
839 update_sending_codec (handler, codec, session);
841 tp_clear_object (&session);
842 tp_clear_object (&codec);
844 /* Get receiving codec */
846 g_object_get (content, "fs-stream", &fs_stream, NULL);
847 g_object_get (fs_stream, "current-recv-codecs", &codecs, NULL);
849 update_receiving_codec (handler, codecs, fs_stream);
851 fs_codec_list_destroy (codecs);
852 tp_clear_object (&fs_stream);
855 if (mtype == FS_MEDIA_TYPE_VIDEO)
857 guint framerate, width, height;
859 g_signal_connect (content, "notify::framerate",
860 G_CALLBACK (on_tf_content_framerate_changed),
863 g_signal_connect (content, "resolution-changed",
864 G_CALLBACK (on_tf_content_resolution_changed),
867 g_object_get (content,
868 "framerate", &framerate,
874 g_signal_emit (G_OBJECT (handler), signals[FRAMERATE_CHANGED], 0,
877 if (width > 0 && height > 0)
878 g_signal_emit (G_OBJECT (handler), signals[RESOLUTION_CHANGED], 0,
882 gst_object_unref (spad);
886 on_tf_channel_content_removed_cb (TfChannel *tfchannel,
888 EmpathyCallHandler *handler)
894 DEBUG ("removing content");
896 g_object_get (content, "media-type", &mtype,
897 "sink-pad", &spad, NULL);
899 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_REMOVED], 0,
900 spad, mtype, &retval);
904 g_warning ("Could not remove content!");
906 tf_content_error (content, 0 /* FIXME */,
907 "Could not link source", NULL);
912 on_tf_channel_closed_cb (TfChannel *tfchannel,
913 EmpathyCallHandler *handler)
915 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
919 on_tf_channel_ready (GObject *source,
920 GAsyncResult *result,
923 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
924 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
925 GError *error = NULL;
927 priv->tfchannel = TF_CHANNEL (g_async_initable_new_finish (
928 G_ASYNC_INITABLE (source), result, NULL));
930 if (priv->tfchannel == NULL)
932 g_warning ("Failed to create Farstream channel: %s", error->message);
933 g_error_free (error);
937 /* Set up the telepathy farstream channel */
938 g_signal_connect (priv->tfchannel, "closed",
939 G_CALLBACK (on_tf_channel_closed_cb), self);
940 g_signal_connect (priv->tfchannel, "fs-conference-added",
941 G_CALLBACK (on_tf_channel_conference_added_cb), self);
942 g_signal_connect (priv->tfchannel, "fs-conference-removed",
943 G_CALLBACK (on_tf_channel_conference_removed_cb), self);
944 g_signal_connect (priv->tfchannel, "content-added",
945 G_CALLBACK (on_tf_channel_content_added_cb), self);
946 g_signal_connect (priv->tfchannel, "content-removed",
947 G_CALLBACK (on_tf_channel_content_removed_cb), self);
951 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
953 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
955 tf_channel_new_async (TP_CHANNEL (priv->call),
956 on_tf_channel_ready, self);
960 on_call_accepted_cb (GObject *source_object,
964 TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
965 GError *error = NULL;
967 if (!tpy_call_channel_accept_finish (call, res, &error))
969 g_warning ("could not accept Call: %s", error->message);
970 g_error_free (error);
975 empathy_call_handler_request_cb (GObject *source,
976 GAsyncResult *result,
979 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
980 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
982 GError *error = NULL;
983 TpAccountChannelRequest *req = TP_ACCOUNT_CHANNEL_REQUEST (source);
985 channel = tp_account_channel_request_create_and_handle_channel_finish (req,
986 result, NULL, &error);
989 DEBUG ("Failed to create the channel: %s", error->message);
990 g_error_free (error);
994 if (!TPY_IS_CALL_CHANNEL (channel))
996 DEBUG ("The channel is not a Call channel!");
1000 priv->call = TPY_CALL_CHANNEL (channel);
1001 tp_g_signal_connect_object (priv->call, "state-changed",
1002 G_CALLBACK (on_call_state_changed_cb), self, 0);
1003 tp_g_signal_connect_object (priv->call, "invalidated",
1004 G_CALLBACK (on_call_invalidated_cb), self, 0);
1006 g_object_notify (G_OBJECT (self), "call-channel");
1008 empathy_call_handler_start_tpfs (self);
1009 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
1013 empathy_call_handler_start_call (EmpathyCallHandler *handler,
1016 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1017 TpAccountChannelRequest *req;
1019 GHashTable *request;
1021 if (priv->call != NULL)
1023 empathy_call_handler_start_tpfs (handler);
1024 tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
1028 /* No TpyCallChannel (we are redialing). Request a new call channel */
1029 g_assert (priv->contact != NULL);
1031 account = empathy_contact_get_account (priv->contact);
1032 request = empathy_call_create_call_request (
1033 empathy_contact_get_id (priv->contact),
1034 priv->initial_audio, priv->initial_video);
1036 req = tp_account_channel_request_new (account, request, timestamp);
1038 tp_account_channel_request_create_and_handle_channel_async (req, NULL,
1039 empathy_call_handler_request_cb, handler);
1041 g_object_unref (req);
1042 g_hash_table_unref (request);
1046 * empathy_call_handler_stop_call:
1047 * @handler: an #EmpathyCallHandler
1049 * Closes the #EmpathyCallHandler's call and frees its resources.
1052 empathy_call_handler_stop_call (EmpathyCallHandler *handler)
1054 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1056 if (priv->call != NULL)
1058 tpy_call_channel_hangup_async (priv->call,
1059 TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
1060 "", "", NULL, NULL);
1061 tp_channel_close_async (TP_CHANNEL (priv->call),
1063 tp_clear_object (&priv->call);
1064 tp_clear_object (&priv->tfchannel);
1069 * empathy_call_handler_has_initial_video:
1070 * @handler: an #EmpathyCallHandler
1072 * Return %TRUE if the call managed by this #EmpathyCallHandler was
1073 * created with video enabled
1075 * Return value: %TRUE if the call was created as a video conversation.
1078 empathy_call_handler_has_initial_video (EmpathyCallHandler *handler)
1080 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
1082 return priv->initial_video;
1086 empathy_call_handler_get_send_audio_codec (EmpathyCallHandler *self)
1088 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1090 return priv->send_audio_codec;
1094 empathy_call_handler_get_send_video_codec (EmpathyCallHandler *self)
1096 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1098 return priv->send_video_codec;
1102 empathy_call_handler_get_recv_audio_codecs (EmpathyCallHandler *self)
1104 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1106 return priv->recv_audio_codecs;
1110 empathy_call_handler_get_recv_video_codecs (EmpathyCallHandler *self)
1112 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1114 return priv->recv_video_codecs;
1118 empathy_call_handler_get_audio_remote_candidate (
1119 EmpathyCallHandler *self)
1121 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1123 return priv->audio_remote_candidate;
1127 empathy_call_handler_get_audio_local_candidate (
1128 EmpathyCallHandler *self)
1130 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1132 return priv->audio_local_candidate;
1136 empathy_call_handler_get_video_remote_candidate (
1137 EmpathyCallHandler *self)
1139 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1141 return priv->video_remote_candidate;
1145 empathy_call_handler_get_video_local_candidate (
1146 EmpathyCallHandler *self)
1148 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
1150 return priv->video_local_candidate;