2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 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
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
67 #define CONTENT_HBOX_BORDER_WIDTH 6
68 #define CONTENT_HBOX_SPACING 3
69 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
71 #define SELF_VIDEO_SECTION_WIDTH 120
72 #define SELF_VIDEO_SECTION_HEIGTH 90
74 /* The avatar's default width and height are set to the same value because we
75 want a square icon. */
76 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
77 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
78 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
80 #define SMALL_TOOLBAR_SIZE 36
82 /* If an video input error occurs, the error message will start with "v4l" */
83 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
85 /* The time interval in milliseconds between 2 outgoing rings */
86 #define MS_BETWEEN_RING 500
88 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
91 PROP_CALL_HANDLER = 1,
103 CAMERA_STATE_OFF = 0,
107 struct _EmpathyCallWindowPriv
109 gboolean dispose_has_run;
110 EmpathyCallHandler *handler;
112 EmpathyContact *contact;
114 EmpathyCameraMonitor *camera_monitor;
119 GtkUIManager *ui_manager;
120 GtkWidget *errors_vbox;
121 /* widget displays the video received from the remote user. This widget is
122 * alive only during call. */
123 ClutterActor *video_output;
124 ClutterActor *video_preview;
125 ClutterActor *preview_hidden_button;
126 GtkWidget *video_container;
127 GtkWidget *remote_user_avatar_widget;
128 GtkWidget *remote_user_avatar_toolbar;
129 GtkWidget *remote_user_name_toolbar;
130 GtkWidget *status_label;
131 GtkWidget *hangup_button;
132 GtkWidget *audio_call_button;
133 GtkWidget *video_call_button;
134 GtkWidget *mic_button;
135 GtkWidget *camera_button;
136 GtkWidget *dialpad_button;
138 GtkWidget *bottom_toolbar;
140 GtkAction *menu_fullscreen;
142 /* The box that contains self and remote avatar and video
143 input/output. When we redial, we destroy and re-create the box */
144 ClutterActor *video_box;
145 ClutterLayoutManager *video_layout;
147 /* We keep a reference on the hbox which contains the main content so we can
148 easilly repack everything when toggling fullscreen */
149 GtkWidget *content_hbox;
151 gulong video_output_motion_handler_id;
152 guint bus_message_source_id;
156 GtkWidget *dtmf_panel;
159 GtkWidget *details_vbox;
160 GtkWidget *vcodec_encoding_label;
161 GtkWidget *acodec_encoding_label;
162 GtkWidget *vcodec_decoding_label;
163 GtkWidget *acodec_decoding_label;
165 GtkWidget *audio_remote_candidate_label;
166 GtkWidget *audio_local_candidate_label;
167 GtkWidget *video_remote_candidate_label;
168 GtkWidget *video_local_candidate_label;
169 GtkWidget *video_remote_candidate_info_img;
170 GtkWidget *video_local_candidate_info_img;
171 GtkWidget *audio_remote_candidate_info_img;
172 GtkWidget *audio_local_candidate_info_img;
174 GstElement *video_input;
175 GstElement *video_preview_sink;
176 GstElement *video_output_sink;
177 GstElement *audio_input;
178 GstElement *audio_output;
179 GstElement *pipeline;
180 GstElement *video_tee;
190 gboolean call_started;
191 gboolean sending_video;
192 CameraState camera_state;
194 EmpathyCallWindowFullscreen *fullscreen;
195 gboolean is_fullscreen;
200 /* Those fields represent the state of the window before it actually was in
202 gboolean dialpad_was_visible_before_fs;
203 gint original_width_before_fs;
204 gint original_height_before_fs;
206 gint x, y, w, h, dialpad_width;
209 /* TRUE if the call should be started when the pipeline is playing */
210 gboolean start_call_when_playing;
211 /* TRUE if we requested to set the pipeline in the playing state */
212 gboolean pipeline_playing;
214 EmpathySoundManager *sound_mgr;
217 EmpathyMicMenu *mic_menu;
220 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
222 static void empathy_call_window_realized_cb (GtkWidget *widget,
223 EmpathyCallWindow *window);
225 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
226 GdkEvent *event, EmpathyCallWindow *window);
228 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
229 GdkEventWindowState *event, EmpathyCallWindow *window);
231 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
234 static void empathy_call_window_mic_toggled_cb (
235 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
237 static void empathy_call_window_hangup_cb (gpointer object,
238 EmpathyCallWindow *window);
240 static void empathy_call_window_fullscreen_cb (gpointer object,
241 EmpathyCallWindow *window);
243 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
245 static gboolean empathy_call_window_video_button_press_cb (
246 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
248 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
249 GdkEventKey *event, EmpathyCallWindow *window);
251 static gboolean empathy_call_window_video_output_motion_notify (
252 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
254 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
257 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
258 EmpathyCallWindow *window);
260 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
262 static void empathy_call_window_status_message (EmpathyCallWindow *window,
265 static gboolean empathy_call_window_bus_message (GstBus *bus,
266 GstMessage *message, gpointer user_data);
269 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
270 gdouble value, EmpathyCallWindow *window);
273 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
276 gtk_widget_set_visible (self->priv->hangup_button, show);
277 gtk_widget_set_visible (self->priv->audio_call_button, !show);
278 gtk_widget_set_visible (self->priv->video_call_button, !show);
282 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
283 EmpathyCallWindow *self)
285 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
286 empathy_call_window_restart_call (self);
290 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
291 EmpathyCallWindow *self)
293 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
294 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
295 empathy_call_window_restart_call (self);
299 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
301 EmpathyCallWindowPriv *priv = GET_PRIV (window);
302 TpyCallChannel *call;
306 g_object_get (priv->handler, "call-channel", &call, NULL);
308 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
309 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
312 tpy_call_channel_dtmf_start_tone (call, event);
314 g_object_unref (call);
318 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
320 EmpathyCallWindowPriv *priv = GET_PRIV (window);
321 TpyCallChannel *call;
323 g_object_get (priv->handler, "call-channel", &call, NULL);
325 tpy_call_channel_dtmf_stop_tone (call);
327 g_object_unref (call);
331 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
333 EmpathyCallWindowPriv *priv = GET_PRIV (self);
336 volume = g_settings_get_double (priv->settings,
337 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
339 /* Don't store the volume because of muting */
340 if (volume > 0 || gtk_toggle_tool_button_get_active (
341 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
342 priv->volume = volume;
344 /* Ensure that the toggle button is active if the volume is > 0 and inactive
345 * if it's smaller than 0 */
346 if ((volume > 0) != gtk_toggle_tool_button_get_active (
347 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
348 gtk_toggle_tool_button_set_active (
349 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
351 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
356 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
358 EmpathyCallWindow *self)
360 empathy_call_window_mic_volume_changed (self);
364 empathy_call_window_show_video_output (EmpathyCallWindow *self,
367 if (self->priv->video_output != NULL)
368 g_object_set (self->priv->video_output, "visible", show, NULL);
370 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
374 create_video_output_widget (EmpathyCallWindow *self)
376 EmpathyCallWindowPriv *priv = GET_PRIV (self);
378 g_assert (priv->video_output == NULL);
379 g_assert (priv->pipeline != NULL);
381 priv->video_output = clutter_texture_new ();
383 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
386 priv->video_output_sink = clutter_gst_video_sink_new (
387 CLUTTER_TEXTURE (priv->video_output));
389 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
392 gtk_widget_add_events (priv->video_container,
393 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
394 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
395 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
399 create_video_input (EmpathyCallWindow *self)
401 EmpathyCallWindowPriv *priv = GET_PRIV (self);
403 g_assert (priv->video_input == NULL);
404 priv->video_input = empathy_video_src_new ();
405 gst_object_ref (priv->video_input);
406 gst_object_sink (priv->video_input);
410 create_audio_input (EmpathyCallWindow *self)
412 EmpathyCallWindowPriv *priv = GET_PRIV (self);
414 g_assert (priv->audio_input == NULL);
415 priv->audio_input = empathy_audio_src_new ();
416 gst_object_ref (priv->audio_input);
417 gst_object_sink (priv->audio_input);
421 add_video_preview_to_pipeline (EmpathyCallWindow *self)
423 EmpathyCallWindowPriv *priv = GET_PRIV (self);
426 g_assert (priv->video_preview != NULL);
427 g_assert (priv->pipeline != NULL);
428 g_assert (priv->video_input != NULL);
429 g_assert (priv->video_tee != NULL);
431 preview = priv->video_preview_sink;
433 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
435 g_warning ("Could not add video input to pipeline");
439 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
441 g_warning ("Could not add video preview to pipeline");
445 if (!gst_element_link (priv->video_input, priv->video_tee))
447 g_warning ("Could not link video input to video tee");
451 if (!gst_element_link (priv->video_tee, preview))
453 g_warning ("Could not link video tee to video preview");
459 empathy_call_window_disable_camera_cb (GtkAction *action,
460 EmpathyCallWindow *self)
462 clutter_actor_destroy (self->priv->preview_hidden_button);
464 gtk_toggle_tool_button_set_active (
465 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
469 empathy_call_window_minimise_camera_cb (GtkAction *action,
470 EmpathyCallWindow *self)
472 clutter_actor_hide (self->priv->video_preview);
473 clutter_actor_show (self->priv->preview_hidden_button);
477 empathy_call_window_maximise_camera_cb (GtkAction *action,
478 EmpathyCallWindow *self)
480 clutter_actor_show (self->priv->video_preview);
481 clutter_actor_hide (self->priv->preview_hidden_button);
485 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
486 EmpathyCallWindow *self)
490 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
492 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
493 0, gtk_get_current_event_time ());
494 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
498 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
499 EmpathyCallWindow *self)
503 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
504 "/preview-hidden-menu");
505 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
506 0, gtk_get_current_event_time ());
507 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
511 create_video_preview (EmpathyCallWindow *self)
513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
514 ClutterLayoutManager *layout, *layout_center;
515 ClutterActor *preview;
520 g_assert (priv->video_preview == NULL);
522 preview = clutter_texture_new ();
523 clutter_actor_set_size (preview,
524 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
525 priv->video_preview_sink = clutter_gst_video_sink_new (
526 CLUTTER_TEXTURE (preview));
528 /* Flip the video preview */
529 clutter_actor_set_rotation (preview,
532 SELF_VIDEO_SECTION_WIDTH * 0.5,
536 /* Add a little offset to the video preview */
537 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
538 CLUTTER_BIN_ALIGNMENT_START);
539 priv->video_preview = clutter_box_new (layout);
540 clutter_actor_set_size (priv->video_preview,
541 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
543 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
544 CLUTTER_BIN_ALIGNMENT_CENTER);
545 box = clutter_box_new (layout_center);
546 clutter_actor_set_size (box,
547 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
549 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
550 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
552 g_object_set (priv->video_preview_sink,
557 /* Translators: this is an "Info" label. It should be as short
559 button = gtk_button_new_with_label (_("i"));
560 b = gtk_clutter_actor_new_with_contents (button);
562 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
564 CLUTTER_BIN_ALIGNMENT_END,
565 CLUTTER_BIN_ALIGNMENT_END);
567 g_signal_connect (button, "clicked",
568 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
571 /* Translators: this is an "Info" label. It should be as short
573 button = gtk_button_new_with_label (_("i"));
574 priv->preview_hidden_button =
575 gtk_clutter_actor_new_with_contents (button);
577 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
578 priv->preview_hidden_button,
579 CLUTTER_BIN_ALIGNMENT_START,
580 CLUTTER_BIN_ALIGNMENT_END);
582 clutter_actor_hide (priv->preview_hidden_button);
584 g_signal_connect (button, "clicked",
585 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
588 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
590 CLUTTER_BIN_ALIGNMENT_START,
591 CLUTTER_BIN_ALIGNMENT_END);
595 play_camera (EmpathyCallWindow *window,
598 EmpathyCallWindowPriv *priv = GET_PRIV (window);
602 if (priv->video_preview == NULL)
604 create_video_preview (window);
605 add_video_preview_to_pipeline (window);
609 state = GST_STATE_PLAYING;
611 state = GST_STATE_NULL;
613 preview = priv->video_preview_sink;
615 gst_element_set_state (preview, state);
616 gst_element_set_state (priv->video_input, state);
617 gst_element_set_state (priv->video_tee, state);
621 display_video_preview (EmpathyCallWindow *self,
624 EmpathyCallWindowPriv *priv = GET_PRIV (self);
628 /* Display the video preview */
629 DEBUG ("Show video preview");
631 play_camera (self, TRUE);
632 clutter_actor_show (priv->video_preview);
636 /* Hide the video preview */
637 DEBUG ("Hide video preview");
639 if (priv->video_preview != NULL)
641 clutter_actor_hide (priv->video_preview);
642 play_camera (self, FALSE);
648 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
650 EmpathyCallWindowPriv *priv = GET_PRIV (window);
652 empathy_call_window_status_message (window, _("Connecting…"));
653 priv->call_state = CONNECTING;
656 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
657 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
661 disable_camera (EmpathyCallWindow *self)
663 EmpathyCallWindowPriv *priv = GET_PRIV (self);
665 if (priv->camera_state == CAMERA_STATE_OFF)
668 DEBUG ("Disable camera");
670 display_video_preview (self, FALSE);
672 if (priv->camera_state == CAMERA_STATE_ON)
673 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
675 priv->camera_state = CAMERA_STATE_OFF;
679 enable_camera (EmpathyCallWindow *self)
681 EmpathyCallWindowPriv *priv = GET_PRIV (self);
683 if (priv->camera_state == CAMERA_STATE_ON)
686 if (priv->video_input == NULL)
688 DEBUG ("Can't enable camera, no input");
692 DEBUG ("Enable camera");
694 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
696 priv->camera_state = CAMERA_STATE_ON;
700 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
701 EmpathyCallWindow *self)
703 if (gtk_toggle_tool_button_get_active (toggle))
704 enable_camera (self);
706 disable_camera (self);
710 create_pipeline (EmpathyCallWindow *self)
712 EmpathyCallWindowPriv *priv = GET_PRIV (self);
715 g_assert (priv->pipeline == NULL);
717 priv->pipeline = gst_pipeline_new (NULL);
718 priv->pipeline_playing = FALSE;
720 priv->video_tee = gst_element_factory_make ("tee", NULL);
721 gst_object_ref (priv->video_tee);
722 gst_object_sink (priv->video_tee);
724 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
726 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
727 priv->bus_message_source_id = gst_bus_add_watch (bus,
728 empathy_call_window_bus_message, self);
730 g_object_unref (bus);
734 empathy_call_window_settings_cb (GtkAction *action,
735 EmpathyCallWindow *self)
738 GError *error = NULL;
741 GdkAppLaunchContext *context = NULL;
743 /* Try to run from source directory if possible */
744 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
747 if (!g_file_test (path, G_FILE_TEST_EXISTS))
750 path = g_build_filename (BIN_DIR, "empathy", NULL);
753 cmd = g_strconcat (path, " -p", NULL);
755 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
756 if (app_info == NULL)
758 DEBUG ("Failed to create app info: %s", error->message);
759 g_error_free (error);
763 display = gdk_display_get_default ();
764 context = gdk_display_get_app_launch_context (display);
766 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
769 g_warning ("Failed to open debug window: %s", error->message);
770 g_error_free (error);
775 tp_clear_object (&app_info);
776 tp_clear_object (&context);
782 empathy_call_window_contents_cb (GtkAction *action,
783 EmpathyCallWindow *self)
785 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
789 empathy_call_window_debug_cb (GtkAction *action,
790 EmpathyCallWindow *self)
793 GError *error = NULL;
796 GdkAppLaunchContext *context = NULL;
798 /* Try to run from source directory if possible */
799 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
800 "empathy-debugger", NULL);
802 if (!g_file_test (path, G_FILE_TEST_EXISTS))
805 path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
808 app_info = g_app_info_create_from_commandline (path, NULL, 0, &error);
809 if (app_info == NULL)
811 DEBUG ("Failed to create app info: %s", error->message);
812 g_error_free (error);
816 display = gdk_display_get_default ();
817 context = gdk_display_get_app_launch_context (display);
819 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
822 g_warning ("Failed to open debug window: %s", error->message);
823 g_error_free (error);
828 tp_clear_object (&app_info);
829 tp_clear_object (&context);
834 empathy_call_window_about_cb (GtkAction *action,
835 EmpathyCallWindow *self)
837 empathy_about_dialog_new (GTK_WINDOW (self));
841 empathy_call_window_configure_event_cb (GtkWidget *widget,
843 EmpathyCallWindow *self)
845 GdkWindow *gdk_window;
846 GdkWindowState window_state;
848 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
849 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
851 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
852 &self->priv->dialpad_width, NULL);
854 gdk_window = gtk_widget_get_window (widget);
855 window_state = gdk_window_get_state (gdk_window);
856 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
862 empathy_call_window_destroyed_cb (GtkWidget *object,
863 EmpathyCallWindow *self)
865 if (gtk_widget_get_visible (self->priv->dtmf_panel))
867 /* Save the geometry as if the dialpad was hidden. */
868 empathy_geometry_save_values (GTK_WINDOW (self),
869 self->priv->x, self->priv->y,
870 self->priv->w - self->priv->dialpad_width, self->priv->h,
871 self->priv->maximized);
876 empathy_call_window_init (EmpathyCallWindow *self)
878 EmpathyCallWindowPriv *priv;
882 ClutterConstraint *size_constraint;
883 ClutterActor *remote_avatar;
884 GtkStyleContext *context;
888 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
889 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
891 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
892 gui = empathy_builder_get_file (filename,
893 "call_window_vbox", &top_vbox,
894 "errors_vbox", &priv->errors_vbox,
896 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
897 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
898 "status_label", &priv->status_label,
899 "audiocall", &priv->audio_call_button,
900 "videocall", &priv->video_call_button,
901 "microphone", &priv->mic_button,
902 "camera", &priv->camera_button,
903 "hangup", &priv->hangup_button,
904 "dialpad", &priv->dialpad_button,
905 "toolbar", &priv->toolbar,
906 "bottom_toolbar", &priv->bottom_toolbar,
907 "ui_manager", &priv->ui_manager,
908 "menufullscreen", &priv->menu_fullscreen,
909 "details_vbox", &priv->details_vbox,
910 "vcodec_encoding_label", &priv->vcodec_encoding_label,
911 "acodec_encoding_label", &priv->acodec_encoding_label,
912 "acodec_decoding_label", &priv->acodec_decoding_label,
913 "vcodec_decoding_label", &priv->vcodec_decoding_label,
914 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
915 "audio_local_candidate_label", &priv->audio_local_candidate_label,
916 "video_remote_candidate_label", &priv->video_remote_candidate_label,
917 "video_local_candidate_label", &priv->video_local_candidate_label,
918 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
919 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
920 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
921 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
925 empathy_builder_connect (gui, self,
926 "hangup", "clicked", empathy_call_window_hangup_cb,
927 "audiocall", "clicked", empathy_call_window_audio_call_cb,
928 "videocall", "clicked", empathy_call_window_video_call_cb,
929 "volume", "value-changed", empathy_call_window_volume_changed_cb,
930 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
931 "camera", "toggled", empathy_call_window_camera_toggled_cb,
932 "dialpad", "toggled", empathy_call_window_dialpad_cb,
933 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
934 "menusettings", "activate", empathy_call_window_settings_cb,
935 "menucontents", "activate", empathy_call_window_contents_cb,
936 "menudebug", "activate", empathy_call_window_debug_cb,
937 "menuabout", "activate", empathy_call_window_about_cb,
938 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
939 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
940 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
943 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
945 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
947 g_object_bind_property (priv->camera_monitor, "available",
948 priv->camera_button, "sensitive",
949 G_BINDING_SYNC_CREATE);
951 priv->lock = g_mutex_new ();
953 gtk_container_add (GTK_CONTAINER (self), top_vbox);
955 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
956 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
957 CONTENT_HBOX_BORDER_WIDTH);
958 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
961 /* avatar/video box */
962 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
963 CLUTTER_BIN_ALIGNMENT_CENTER);
965 priv->video_box = clutter_box_new (priv->video_layout);
967 priv->video_container = gtk_clutter_embed_new ();
969 /* Set the background color to that of the rest of the window */
970 context = gtk_widget_get_style_context (priv->content_hbox);
971 gtk_style_context_get_background_color (context,
972 GTK_STATE_FLAG_NORMAL, &rgba);
973 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
974 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
975 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
976 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
977 clutter_stage_set_color (
978 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
979 GTK_CLUTTER_EMBED (priv->video_container))),
982 clutter_container_add (
983 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
984 GTK_CLUTTER_EMBED (priv->video_container))),
988 size_constraint = clutter_bind_constraint_new (
989 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
990 CLUTTER_BIND_SIZE, 0);
991 clutter_actor_add_constraint (priv->video_box, size_constraint);
993 priv->remote_user_avatar_widget = gtk_image_new ();
994 remote_avatar = gtk_clutter_actor_new_with_contents (
995 priv->remote_user_avatar_widget);
997 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1000 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1001 priv->video_container, TRUE, TRUE,
1002 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1004 create_pipeline (self);
1005 create_video_output_widget (self);
1006 create_audio_input (self);
1007 create_video_input (self);
1009 /* The call will be started as soon the pipeline is playing */
1010 priv->start_call_when_playing = TRUE;
1012 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1013 G_CALLBACK (dtmf_button_pressed_cb),
1014 G_CALLBACK (dtmf_button_released_cb));
1016 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1019 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1022 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1024 gtk_widget_show_all (top_vbox);
1026 gtk_widget_hide (priv->dtmf_panel);
1027 gtk_widget_hide (priv->details_vbox);
1029 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1031 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1032 priv->video_container);
1034 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1035 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1037 g_signal_connect (G_OBJECT (self), "realize",
1038 G_CALLBACK (empathy_call_window_realized_cb), self);
1040 g_signal_connect (G_OBJECT (self), "delete-event",
1041 G_CALLBACK (empathy_call_window_delete_cb), self);
1043 g_signal_connect (G_OBJECT (self), "window-state-event",
1044 G_CALLBACK (empathy_call_window_state_event_cb), self);
1046 g_signal_connect (G_OBJECT (self), "key-press-event",
1047 G_CALLBACK (empathy_call_window_key_press_cb), self);
1049 priv->timer = g_timer_new ();
1051 g_object_ref (priv->ui_manager);
1052 g_object_unref (gui);
1054 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1055 priv->mic_menu = empathy_mic_menu_new (self);
1057 empathy_call_window_show_hangup_button (self, TRUE);
1059 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1060 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1061 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1063 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1064 /* These signals are used to track the window position and save it
1065 * when the window is destroyed. We need to do this as we don't want
1066 * the window geometry to be saved with the dialpad taken into account. */
1067 g_signal_connect (self, "destroy",
1068 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1069 g_signal_connect (self, "configure-event",
1070 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1071 g_signal_connect (self, "window-state-event",
1072 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1074 /* Don't display labels in both toolbars */
1075 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1076 gtk_toolbar_set_style (GTK_TOOLBAR (priv->bottom_toolbar), GTK_TOOLBAR_ICONS);
1079 /* Instead of specifying a width and a height, we specify only one size. That's
1080 because we want a square avatar icon. */
1082 init_contact_avatar_with_size (EmpathyContact *contact,
1083 GtkWidget *image_widget,
1086 GdkPixbuf *pixbuf_avatar = NULL;
1088 if (contact != NULL)
1090 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1094 if (pixbuf_avatar == NULL)
1096 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1097 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1100 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1102 if (pixbuf_avatar != NULL)
1103 g_object_unref (pixbuf_avatar);
1107 set_window_title (EmpathyCallWindow *self)
1109 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1112 if (priv->contact != NULL)
1114 /* translators: Call is a noun and %s is the contact name. This string
1115 * is used in the window title */
1116 tmp = g_strdup_printf (_("Call with %s"),
1117 empathy_contact_get_alias (priv->contact));
1118 gtk_window_set_title (GTK_WINDOW (self), tmp);
1123 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1128 set_remote_user_name (EmpathyCallWindow *self,
1129 EmpathyContact *contact)
1131 const gchar *alias = empathy_contact_get_alias (contact);
1132 const gchar *status = empathy_contact_get_status (contact);
1135 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1136 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1142 contact_name_changed_cb (EmpathyContact *contact,
1144 EmpathyCallWindow *self)
1146 set_window_title (self);
1147 set_remote_user_name (self, contact);
1151 contact_presence_changed_cb (EmpathyContact *contact,
1153 EmpathyCallWindow *self)
1155 set_remote_user_name (self, contact);
1159 contact_avatar_changed_cb (EmpathyContact *contact,
1161 EmpathyCallWindow *self)
1164 GtkAllocation allocation;
1165 GtkWidget *avatar_widget;
1167 avatar_widget = self->priv->remote_user_avatar_widget;
1169 gtk_widget_get_allocation (avatar_widget, &allocation);
1170 size = allocation.height;
1174 /* the widget is not allocated yet, set a default size */
1175 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1176 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1179 init_contact_avatar_with_size (contact, avatar_widget, size);
1181 avatar_widget = self->priv->remote_user_avatar_toolbar;
1183 gtk_widget_get_allocation (avatar_widget, &allocation);
1184 size = allocation.height;
1188 /* the widget is not allocated yet, set a default size */
1189 size = SMALL_TOOLBAR_SIZE;
1192 init_contact_avatar_with_size (contact, avatar_widget, size);
1196 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1197 EmpathyCallHandler *handler)
1199 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1201 tp_g_signal_connect_object (priv->contact, "notify::name",
1202 G_CALLBACK (contact_name_changed_cb), self, 0);
1203 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1204 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1205 tp_g_signal_connect_object (priv->contact, "notify::presence",
1206 G_CALLBACK (contact_presence_changed_cb), self, 0);
1208 set_window_title (self);
1209 set_remote_user_name (self, priv->contact);
1211 init_contact_avatar_with_size (priv->contact,
1212 priv->remote_user_avatar_widget,
1213 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1214 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1216 init_contact_avatar_with_size (priv->contact,
1217 priv->remote_user_avatar_toolbar,
1218 SMALL_TOOLBAR_SIZE);
1220 /* The remote avatar is shown by default and will be hidden when we receive
1221 video from the remote side. */
1222 clutter_actor_hide (priv->video_output);
1223 gtk_widget_show (priv->remote_user_avatar_widget);
1227 update_send_codec (EmpathyCallWindow *self,
1230 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1237 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1238 widget = priv->acodec_encoding_label;
1242 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1243 widget = priv->vcodec_encoding_label;
1249 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1250 gtk_label_set_text (GTK_LABEL (widget), tmp);
1255 send_audio_codec_notify_cb (GObject *object,
1259 EmpathyCallWindow *self = user_data;
1261 update_send_codec (self, TRUE);
1265 send_video_codec_notify_cb (GObject *object,
1269 EmpathyCallWindow *self = user_data;
1271 update_send_codec (self, FALSE);
1275 update_recv_codec (EmpathyCallWindow *self,
1278 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1281 GString *str = NULL;
1285 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1286 widget = priv->acodec_decoding_label;
1290 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1291 widget = priv->vcodec_decoding_label;
1297 for (l = codecs; l != NULL; l = g_list_next (l))
1299 FsCodec *codec = l->data;
1302 str = g_string_new (NULL);
1304 g_string_append (str, ", ");
1306 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1310 gtk_label_set_text (GTK_LABEL (widget), str->str);
1311 g_string_free (str, TRUE);
1315 recv_audio_codecs_notify_cb (GObject *object,
1319 EmpathyCallWindow *self = user_data;
1321 update_recv_codec (self, TRUE);
1325 recv_video_codecs_notify_cb (GObject *object,
1329 EmpathyCallWindow *self = user_data;
1331 update_recv_codec (self, FALSE);
1334 static const gchar *
1335 candidate_type_to_str (FsCandidate *candidate)
1337 switch (candidate->type)
1339 case FS_CANDIDATE_TYPE_HOST:
1341 case FS_CANDIDATE_TYPE_SRFLX:
1342 return "server reflexive";
1343 case FS_CANDIDATE_TYPE_PRFLX:
1344 return "peer reflexive";
1345 case FS_CANDIDATE_TYPE_RELAY:
1347 case FS_CANDIDATE_TYPE_MULTICAST:
1354 static const gchar *
1355 candidate_type_to_desc (FsCandidate *candidate)
1357 switch (candidate->type)
1359 case FS_CANDIDATE_TYPE_HOST:
1360 return _("The IP address as seen by the machine");
1361 case FS_CANDIDATE_TYPE_SRFLX:
1362 return _("The IP address as seen by a server on the Internet");
1363 case FS_CANDIDATE_TYPE_PRFLX:
1364 return _("The IP address of the peer as seen by the other side");
1365 case FS_CANDIDATE_TYPE_RELAY:
1366 return _("The IP address of a relay server");
1367 case FS_CANDIDATE_TYPE_MULTICAST:
1368 return _("The IP address of the multicast group");
1375 update_candidat_widget (EmpathyCallWindow *self,
1378 FsCandidate *candidate)
1382 g_assert (candidate != NULL);
1383 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1384 candidate->port, candidate_type_to_str (candidate));
1386 gtk_label_set_text (GTK_LABEL (label), str);
1387 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1393 candidates_changed_cb (GObject *object,
1395 EmpathyCallWindow *self)
1397 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1398 FsCandidate *candidate = NULL;
1400 if (type == FS_MEDIA_TYPE_VIDEO)
1402 /* Update remote candidate */
1403 candidate = empathy_call_handler_get_video_remote_candidate (
1406 update_candidat_widget (self, priv->video_remote_candidate_label,
1407 priv->video_remote_candidate_info_img, candidate);
1409 /* Update local candidate */
1410 candidate = empathy_call_handler_get_video_local_candidate (
1413 update_candidat_widget (self, priv->video_local_candidate_label,
1414 priv->video_local_candidate_info_img, candidate);
1418 /* Update remote candidate */
1419 candidate = empathy_call_handler_get_audio_remote_candidate (
1422 update_candidat_widget (self, priv->audio_remote_candidate_label,
1423 priv->audio_remote_candidate_info_img, candidate);
1425 /* Update local candidate */
1426 candidate = empathy_call_handler_get_audio_local_candidate (
1429 update_candidat_widget (self, priv->audio_local_candidate_label,
1430 priv->audio_local_candidate_info_img, candidate);
1435 empathy_call_window_constructed (GObject *object)
1437 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1438 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1439 TpyCallChannel *call;
1441 g_assert (priv->handler != NULL);
1443 g_object_get (priv->handler, "call-channel", &call, NULL);
1444 priv->outgoing = (call == NULL);
1446 g_object_unref (call);
1448 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1449 g_assert (priv->contact != NULL);
1451 empathy_call_window_setup_avatars (self, priv->handler);
1452 empathy_call_window_set_state_connecting (self);
1454 if (!empathy_call_handler_has_initial_video (priv->handler))
1456 gtk_toggle_tool_button_set_active (
1457 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1459 /* If call has InitialVideo, the preview will be started once the call has
1460 * been started (start_call()). */
1462 update_send_codec (self, TRUE);
1463 update_send_codec (self, FALSE);
1464 update_recv_codec (self, TRUE);
1465 update_recv_codec (self, FALSE);
1467 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1468 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1469 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1470 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1471 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1472 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1473 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1474 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1476 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1477 G_CALLBACK (candidates_changed_cb), self, 0);
1480 static void empathy_call_window_dispose (GObject *object);
1481 static void empathy_call_window_finalize (GObject *object);
1484 empathy_call_window_set_property (GObject *object,
1485 guint property_id, const GValue *value, GParamSpec *pspec)
1487 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1489 switch (property_id)
1491 case PROP_CALL_HANDLER:
1492 priv->handler = g_value_dup_object (value);
1495 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1500 empathy_call_window_get_property (GObject *object,
1501 guint property_id, GValue *value, GParamSpec *pspec)
1503 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1505 switch (property_id)
1507 case PROP_CALL_HANDLER:
1508 g_value_set_object (value, priv->handler);
1511 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1516 empathy_call_window_class_init (
1517 EmpathyCallWindowClass *empathy_call_window_class)
1519 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1520 GParamSpec *param_spec;
1522 g_type_class_add_private (empathy_call_window_class,
1523 sizeof (EmpathyCallWindowPriv));
1525 object_class->constructed = empathy_call_window_constructed;
1526 object_class->set_property = empathy_call_window_set_property;
1527 object_class->get_property = empathy_call_window_get_property;
1529 object_class->dispose = empathy_call_window_dispose;
1530 object_class->finalize = empathy_call_window_finalize;
1532 param_spec = g_param_spec_object ("handler",
1533 "handler", "The call handler",
1534 EMPATHY_TYPE_CALL_HANDLER,
1535 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1536 g_object_class_install_property (object_class,
1537 PROP_CALL_HANDLER, param_spec);
1541 empathy_call_window_dispose (GObject *object)
1543 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1544 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1546 if (priv->dispose_has_run)
1549 priv->dispose_has_run = TRUE;
1551 if (priv->handler != NULL)
1553 empathy_call_handler_stop_call (priv->handler);
1554 tp_clear_object (&priv->handler);
1557 if (priv->bus_message_source_id != 0)
1559 g_source_remove (priv->bus_message_source_id);
1560 priv->bus_message_source_id = 0;
1563 if (priv->got_video_src > 0)
1565 g_source_remove (priv->got_video_src);
1566 priv->got_video_src = 0;
1569 tp_clear_object (&priv->pipeline);
1570 tp_clear_object (&priv->video_input);
1571 tp_clear_object (&priv->audio_input);
1572 tp_clear_object (&priv->video_tee);
1573 tp_clear_object (&priv->ui_manager);
1574 tp_clear_object (&priv->fullscreen);
1575 tp_clear_object (&priv->camera_monitor);
1576 tp_clear_object (&priv->settings);
1578 g_list_free_full (priv->notifiers, g_object_unref);
1580 if (priv->timer_id != 0)
1581 g_source_remove (priv->timer_id);
1584 if (priv->contact != NULL)
1586 g_signal_handlers_disconnect_by_func (priv->contact,
1587 contact_name_changed_cb, self);
1588 priv->contact = NULL;
1592 tp_clear_object (&priv->sound_mgr);
1594 tp_clear_object (&priv->mic_menu);
1596 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1600 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1602 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1604 if (priv->video_output_motion_handler_id != 0)
1606 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1607 priv->video_output_motion_handler_id);
1608 priv->video_output_motion_handler_id = 0;
1613 empathy_call_window_finalize (GObject *object)
1615 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1616 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1618 disconnect_video_output_motion_handler (self);
1620 /* free any data held directly by the object here */
1621 g_mutex_free (priv->lock);
1623 g_timer_destroy (priv->timer);
1625 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1630 empathy_call_window_new (EmpathyCallHandler *handler)
1632 return EMPATHY_CALL_WINDOW (
1633 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1637 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1638 GstElement *conference, gpointer user_data)
1640 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1641 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1642 FsElementAddedNotifier *notifier;
1645 DEBUG ("Conference added");
1647 /* Add notifier to set the various element properties as needed */
1648 notifier = fs_element_added_notifier_new ();
1649 keyfile = fs_utils_get_default_element_properties (conference);
1651 if (keyfile != NULL)
1652 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1654 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1656 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1658 gst_bin_add (GST_BIN (priv->pipeline), conference);
1659 gst_element_set_state (conference, GST_STATE_PLAYING);
1663 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1664 GstElement *conference, gpointer user_data)
1666 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1667 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1669 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1670 gst_element_set_state (conference, GST_STATE_NULL);
1674 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1676 GstStateChangeReturn state_change_return;
1677 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1679 if (priv->pipeline == NULL)
1682 if (priv->bus_message_source_id != 0)
1684 g_source_remove (priv->bus_message_source_id);
1685 priv->bus_message_source_id = 0;
1688 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1690 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1691 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1693 if (priv->pipeline != NULL)
1694 g_object_unref (priv->pipeline);
1695 priv->pipeline = NULL;
1697 if (priv->audio_output != NULL)
1698 g_object_unref (priv->audio_output);
1699 priv->audio_output = NULL;
1701 if (priv->video_tee != NULL)
1702 g_object_unref (priv->video_tee);
1703 priv->video_tee = NULL;
1705 if (priv->video_preview != NULL)
1706 clutter_actor_destroy (priv->video_preview);
1707 priv->video_preview = NULL;
1709 priv->funnel = NULL;
1711 create_pipeline (self);
1712 /* Call will be started when user will hit the 'redial' button */
1713 priv->start_call_when_playing = FALSE;
1714 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1720 g_message ("Error: could not destroy pipeline. Closing call window");
1721 gtk_widget_destroy (GTK_WIDGET (self));
1728 reset_details_pane (EmpathyCallWindow *self)
1730 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1732 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1733 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1734 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1735 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1739 empathy_call_window_disconnected (EmpathyCallWindow *self,
1742 gboolean could_disconnect = FALSE;
1743 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1744 gboolean could_reset_pipeline;
1746 /* Leave full screen mode if needed */
1747 gtk_window_unfullscreen (GTK_WINDOW (self));
1749 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1750 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1752 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1754 if (priv->call_state == CONNECTING)
1755 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1757 if (priv->call_state != REDIALING)
1758 priv->call_state = DISCONNECTED;
1760 if (could_reset_pipeline)
1762 g_mutex_lock (priv->lock);
1764 g_timer_stop (priv->timer);
1766 if (priv->timer_id != 0)
1767 g_source_remove (priv->timer_id);
1770 g_mutex_unlock (priv->lock);
1773 /* We are about to destroy the window, no need to update it or create
1774 * a video preview */
1777 empathy_call_window_status_message (self, _("Disconnected"));
1779 empathy_call_window_show_hangup_button (self, FALSE);
1781 /* Unsensitive the camera and mic button */
1782 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1783 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1785 /* Be sure that the mic button is enabled */
1786 gtk_toggle_tool_button_set_active (
1787 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1789 if (priv->camera_state == CAMERA_STATE_ON)
1791 /* Restart the preview with the new pipeline. */
1792 display_video_preview (self, TRUE);
1795 /* destroy the video output; it will be recreated when we'll redial */
1796 disconnect_video_output_motion_handler (self);
1797 if (priv->video_output != NULL)
1798 clutter_actor_destroy (priv->video_output);
1799 priv->video_output = NULL;
1800 if (priv->got_video_src > 0)
1802 g_source_remove (priv->got_video_src);
1803 priv->got_video_src = 0;
1806 gtk_widget_show (priv->remote_user_avatar_widget);
1808 reset_details_pane (self);
1810 priv->sending_video = FALSE;
1811 priv->call_started = FALSE;
1813 could_disconnect = TRUE;
1815 /* TODO: display the self avatar of the preview (depends if the "Always
1816 * Show Video Preview" is enabled or not) */
1819 return could_disconnect;
1824 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1827 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1828 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1830 if (empathy_call_window_disconnected (self, TRUE) &&
1831 priv->call_state == REDIALING)
1832 empathy_call_window_restart_call (self);
1836 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1838 FsMediaType media_type,
1839 EmpathyCallWindow *self)
1841 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1843 DEBUG ("removing content");
1846 * This assumes that there is only one video stream per channel...
1849 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1851 if (priv->funnel != NULL)
1855 output = priv->video_output_sink;
1857 gst_element_set_state (output, GST_STATE_NULL);
1858 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1860 gst_bin_remove (GST_BIN (priv->pipeline), output);
1861 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1862 priv->funnel = NULL;
1866 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1868 if (priv->audio_output != NULL)
1870 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1872 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1873 priv->audio_output = NULL;
1881 /* Called with global lock held */
1883 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1885 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1889 if (priv->funnel == NULL)
1891 output = priv->video_output_sink;
1893 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1897 g_warning ("Could not create fsfunnel");
1901 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1903 gst_object_unref (priv->funnel);
1904 priv->funnel = NULL;
1905 g_warning ("Could not add funnel to pipeline");
1909 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1911 g_warning ("Could not add the video output widget to the pipeline");
1915 if (!gst_element_link (priv->funnel, output))
1917 g_warning ("Could not link output sink to funnel");
1918 goto error_output_added;
1921 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1923 g_warning ("Could not start video sink");
1924 goto error_output_added;
1927 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1929 g_warning ("Could not start funnel");
1930 goto error_output_added;
1934 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1937 g_warning ("Could not get request pad from funnel");
1944 gst_element_set_locked_state (priv->funnel, TRUE);
1945 gst_element_set_locked_state (output, TRUE);
1947 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1948 gst_element_set_state (output, GST_STATE_NULL);
1950 gst_bin_remove (GST_BIN (priv->pipeline), output);
1951 gst_element_set_locked_state (output, FALSE);
1955 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1956 priv->funnel = NULL;
1961 /* Called with global lock held */
1963 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1965 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1967 GstPadTemplate *template;
1969 if (priv->audio_output == NULL)
1971 priv->audio_output = empathy_audio_sink_new ();
1972 g_object_ref_sink (priv->audio_output);
1974 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1976 g_warning ("Could not add audio sink to pipeline");
1977 g_object_unref (priv->audio_output);
1978 goto error_add_output;
1981 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1983 g_warning ("Could not start audio sink");
1988 template = gst_element_class_get_pad_template (
1989 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
1991 pad = gst_element_request_pad (priv->audio_output,
1992 template, NULL, NULL);
1996 g_warning ("Could not get sink pad from sink");
2003 gst_element_set_locked_state (priv->audio_output, TRUE);
2004 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2005 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2006 priv->audio_output = NULL;
2014 empathy_call_window_update_timer (gpointer user_data)
2016 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2017 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2018 const gchar *status;
2022 time_ = g_timer_elapsed (priv->timer, NULL);
2024 if (priv->call_state == HELD)
2025 status = _("On hold");
2026 else if (!gtk_toggle_tool_button_get_active (
2027 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2030 status = _("Duration");
2032 /* Translators: 'status - minutes:seconds' the caller has been connected */
2033 str = g_strdup_printf (_("%s — %d:%02dm"),
2035 (int) time_ / 60, (int) time_ % 60);
2036 empathy_call_window_status_message (self, str);
2044 display_error (EmpathyCallWindow *self,
2045 TpyCallChannel *call,
2049 const gchar *details)
2051 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2052 GtkWidget *info_bar;
2053 GtkWidget *content_area;
2060 /* Create info bar */
2061 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2064 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2066 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2068 /* hbox containing the image and the messages vbox */
2069 hbox = gtk_hbox_new (FALSE, 3);
2070 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2073 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2074 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2076 /* vbox containing the main message and the details expander */
2077 vbox = gtk_vbox_new (FALSE, 3);
2078 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2081 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2083 label = gtk_label_new (NULL);
2084 gtk_label_set_markup (GTK_LABEL (label), txt);
2085 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2086 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2089 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2092 if (details != NULL)
2094 GtkWidget *expander;
2096 expander = gtk_expander_new (_("Technical Details"));
2098 txt = g_strdup_printf ("<i>%s</i>", details);
2100 label = gtk_label_new (NULL);
2101 gtk_label_set_markup (GTK_LABEL (label), txt);
2102 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2103 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2106 gtk_container_add (GTK_CONTAINER (expander), label);
2107 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2110 g_signal_connect (info_bar, "response",
2111 G_CALLBACK (gtk_widget_destroy), NULL);
2113 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2114 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2115 gtk_widget_show_all (info_bar);
2119 media_stream_error_to_txt (EmpathyCallWindow *self,
2120 TpyCallChannel *call,
2122 TpMediaStreamError error)
2124 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2125 const gchar *cm = NULL;
2131 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2133 return g_strdup_printf (
2134 _("%s's software does not understand any of the audio formats "
2135 "supported by your computer"),
2136 empathy_contact_get_alias (priv->contact));
2138 return g_strdup_printf (
2139 _("%s's software does not understand any of the video formats "
2140 "supported by your computer"),
2141 empathy_contact_get_alias (priv->contact));
2143 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2144 return g_strdup_printf (
2145 _("Can't establish a connection to %s. "
2146 "One of you might be on a network that does not allow "
2147 "direct connections."),
2148 empathy_contact_get_alias (priv->contact));
2150 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2151 return g_strdup (_("There was a failure on the network"));
2153 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2155 return g_strdup (_("The audio formats necessary for this call "
2156 "are not installed on your computer"));
2158 return g_strdup (_("The video formats necessary for this call "
2159 "are not installed on your computer"));
2161 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2162 tp_connection_parse_object_path (
2163 tp_channel_borrow_connection (TP_CHANNEL (call)),
2166 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2167 "product=Telepathy&component=%s", cm);
2169 result = g_strdup_printf (
2170 _("Something unexpected happened in a Telepathy component. "
2171 "Please <a href=\"%s\">report this bug</a> and attach "
2172 "logs gathered from the 'Debug' window in the Help menu."), url);
2178 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2179 return g_strdup (_("There was a failure in the call engine"));
2181 case TP_MEDIA_STREAM_ERROR_EOS:
2182 return g_strdup (_("The end of the stream was reached"));
2184 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2191 empathy_call_window_stream_error (EmpathyCallWindow *self,
2192 TpyCallChannel *call,
2201 desc = media_stream_error_to_txt (self, call, audio, code);
2204 /* No description, use the error message. That's not great as it's not
2205 * localized but it's better than nothing. */
2206 display_error (self, call, icon, title, msg, NULL);
2210 display_error (self, call, icon, title, desc, msg);
2216 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2219 EmpathyCallWindow *self)
2221 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2222 "gnome-stock-mic", _("Can't establish audio stream"));
2226 empathy_call_window_video_stream_error (TpyCallChannel *call,
2229 EmpathyCallWindow *self)
2231 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2232 "camera-web", _("Can't establish video stream"));
2237 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2239 EmpathyCallWindow *self)
2241 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2242 TpyCallChannel *call;
2243 gboolean can_send_video;
2245 if (state != TPY_CALL_STATE_ACCEPTED)
2248 if (priv->call_state == CONNECTED)
2251 g_timer_start (priv->timer);
2252 priv->call_state = CONNECTED;
2254 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2256 can_send_video = priv->video_input != NULL &&
2257 empathy_contact_can_voip_video (priv->contact) &&
2258 empathy_camera_monitor_get_available (priv->camera_monitor);
2260 g_object_get (priv->handler, "call-channel", &call, NULL);
2262 if (tpy_call_channel_has_dtmf (call))
2263 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2265 if (priv->video_input == NULL)
2266 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2268 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2270 empathy_call_window_show_hangup_button (self, TRUE);
2272 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2274 clutter_actor_hide (priv->video_output);
2275 gtk_widget_show (priv->remote_user_avatar_widget);
2277 g_object_unref (call);
2279 g_mutex_lock (priv->lock);
2281 priv->timer_id = g_timeout_add_seconds (1,
2282 empathy_call_window_update_timer, self);
2284 g_mutex_unlock (priv->lock);
2286 empathy_call_window_update_timer (self);
2288 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2292 empathy_call_window_show_video_output_cb (gpointer user_data)
2294 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2296 if (self->priv->video_output != NULL)
2298 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2299 clutter_actor_show (self->priv->video_output);
2306 empathy_call_window_check_video_cb (gpointer data)
2308 EmpathyCallWindow *self = data;
2310 if (self->priv->got_video)
2312 self->priv->got_video = FALSE;
2316 /* No video in the last N seconds, display the remote avatar */
2317 empathy_call_window_show_video_output (self, FALSE);
2322 /* Called from the streaming thread */
2324 empathy_call_window_video_probe_cb (GstPad *pad,
2325 GstMiniObject *mini_obj,
2326 EmpathyCallWindow *self)
2329 if (GST_IS_EVENT (mini_obj))
2332 if (G_UNLIKELY (!self->priv->got_video))
2334 /* show the remote video */
2335 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2336 empathy_call_window_show_video_output_cb,
2337 g_object_ref (self), g_object_unref);
2339 self->priv->got_video = TRUE;
2345 /* Called from the streaming thread */
2347 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2348 GstPad *src, guint media_type, gpointer user_data)
2350 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2351 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2352 gboolean retval = FALSE;
2356 g_mutex_lock (priv->lock);
2360 case TP_MEDIA_STREAM_TYPE_AUDIO:
2361 pad = empathy_call_window_get_audio_sink_pad (self);
2363 case TP_MEDIA_STREAM_TYPE_VIDEO:
2364 g_idle_add (empathy_call_window_show_video_output_cb, self);
2365 pad = empathy_call_window_get_video_sink_pad (self);
2367 gst_pad_add_data_probe (src,
2368 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2369 if (priv->got_video_src > 0)
2370 g_source_remove (priv->got_video_src);
2371 priv->got_video_src = g_timeout_add_seconds (5,
2372 empathy_call_window_check_video_cb, self);
2375 g_assert_not_reached ();
2381 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2382 g_warning ("Could not link %s sink pad",
2383 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2387 gst_object_unref (pad);
2391 /* If no sink could be linked, try to add fakesink to prevent the whole call
2396 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2398 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2400 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2401 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2402 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2404 gst_element_set_locked_state (fakesink, TRUE);
2405 gst_element_set_state (fakesink, GST_STATE_NULL);
2406 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2410 DEBUG ("Could not link real sink, linked fakesink instead");
2412 gst_object_unref (sinkpad);
2416 gst_object_unref (fakesink);
2421 g_mutex_unlock (priv->lock);
2427 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2428 GstPad *sink, FsMediaType media_type, gpointer user_data)
2430 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2431 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2433 gboolean retval = FALSE;
2437 case FS_MEDIA_TYPE_AUDIO:
2438 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2440 g_warning ("Could not add audio source to pipeline");
2444 pad = gst_element_get_static_pad (priv->audio_input, "src");
2447 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2448 g_warning ("Could not get source pad from audio source");
2452 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2454 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2455 g_warning ("Could not link audio source to farsight");
2459 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2461 g_warning ("Could not start audio source");
2462 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2463 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2469 case FS_MEDIA_TYPE_VIDEO:
2470 if (priv->video_tee != NULL)
2472 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2473 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2475 g_warning ("Could not link video source input pipeline");
2478 gst_object_unref (pad);
2484 g_assert_not_reached ();
2491 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2493 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2494 GstElement *preview;
2496 disable_camera (self);
2498 DEBUG ("remove video input");
2499 preview = priv->video_preview_sink;
2501 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2502 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2503 gst_element_set_state (preview, GST_STATE_NULL);
2505 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2508 g_object_unref (priv->video_input);
2509 priv->video_input = NULL;
2510 g_object_unref (priv->video_tee);
2511 priv->video_tee = NULL;
2512 clutter_actor_destroy (priv->video_preview);
2513 priv->video_preview = NULL;
2515 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2519 start_call (EmpathyCallWindow *self)
2521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2523 priv->call_started = TRUE;
2524 empathy_call_handler_start_call (priv->handler,
2525 gtk_get_current_event_time ());
2527 if (empathy_call_handler_has_initial_video (priv->handler))
2529 TpyCallChannel *call;
2532 g_object_get (priv->handler, "call-channel", &call, NULL);
2533 s = tpy_call_channel_get_video_state (call);
2535 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2536 s == TPY_SENDING_STATE_SENDING)
2538 /* Enable 'send video' buttons and display the preview */
2539 gtk_toggle_tool_button_set_active (
2540 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2544 gtk_toggle_tool_button_set_active (
2545 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2547 if (priv->video_preview == NULL)
2549 create_video_preview (self);
2550 add_video_preview_to_pipeline (self);
2554 g_object_unref (call);
2559 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2562 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2563 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2566 empathy_call_handler_bus_message (priv->handler, bus, message);
2568 switch (GST_MESSAGE_TYPE (message))
2570 case GST_MESSAGE_STATE_CHANGED:
2571 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2573 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2575 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2576 !priv->call_started)
2578 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2579 if (newstate == GST_STATE_PAUSED)
2581 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2582 priv->pipeline_playing = TRUE;
2584 if (priv->start_call_when_playing)
2589 case GST_MESSAGE_ERROR:
2591 GError *error = NULL;
2592 GstElement *gst_error;
2595 gst_message_parse_error (message, &error, &debug);
2596 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2598 g_message ("Element error: %s -- %s\n", error->message, debug);
2600 if (g_str_has_prefix (gst_element_get_name (gst_error),
2601 VIDEO_INPUT_ERROR_PREFIX))
2603 /* Remove the video input and continue */
2604 if (priv->video_input != NULL)
2605 empathy_call_window_remove_video_input (self);
2606 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2610 empathy_call_window_disconnected (self, TRUE);
2612 g_error_free (error);
2615 case GST_MESSAGE_UNKNOWN:
2616 case GST_MESSAGE_EOS:
2617 case GST_MESSAGE_WARNING:
2618 case GST_MESSAGE_INFO:
2619 case GST_MESSAGE_TAG:
2620 case GST_MESSAGE_BUFFERING:
2621 case GST_MESSAGE_STATE_DIRTY:
2622 case GST_MESSAGE_STEP_DONE:
2623 case GST_MESSAGE_CLOCK_PROVIDE:
2624 case GST_MESSAGE_CLOCK_LOST:
2625 case GST_MESSAGE_NEW_CLOCK:
2626 case GST_MESSAGE_STRUCTURE_CHANGE:
2627 case GST_MESSAGE_STREAM_STATUS:
2628 case GST_MESSAGE_APPLICATION:
2629 case GST_MESSAGE_ELEMENT:
2630 case GST_MESSAGE_SEGMENT_START:
2631 case GST_MESSAGE_SEGMENT_DONE:
2632 case GST_MESSAGE_DURATION:
2633 case GST_MESSAGE_ANY:
2642 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2643 GHashTable *members,
2644 EmpathyCallWindow *self)
2646 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2647 GHashTableIter iter;
2648 gpointer key, value;
2649 gboolean held = FALSE;
2651 g_hash_table_iter_init (&iter, members);
2652 while (g_hash_table_iter_next (&iter, &key, &value))
2654 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2656 /* This assumes this is a 1-1 call, otherwise one participant
2657 * putting the call on hold wouldn't mean the call is on hold
2665 priv->call_state = HELD;
2666 else if (priv->call_state == HELD)
2667 priv->call_state = CONNECTED;
2671 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2673 EmpathyCallWindow *self)
2675 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2676 TpyCallChannel *call;
2678 g_object_get (priv->handler, "call-channel", &call, NULL);
2683 tp_g_signal_connect_object (call, "audio-stream-error",
2684 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2685 tp_g_signal_connect_object (call, "video-stream-error",
2686 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2689 tp_g_signal_connect_object (call, "members-changed",
2690 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2692 g_object_unref (call);
2696 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2698 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2699 TpyCallChannel *call;
2702 /* Make the hangup button twice as wide */
2703 width = gtk_widget_get_allocated_width (priv->hangup_button);
2704 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2706 g_signal_connect (priv->handler, "state-changed",
2707 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2708 g_signal_connect (priv->handler, "conference-added",
2709 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2710 g_signal_connect (priv->handler, "conference-removed",
2711 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2712 g_signal_connect (priv->handler, "closed",
2713 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2714 g_signal_connect (priv->handler, "src-pad-added",
2715 G_CALLBACK (empathy_call_window_src_added_cb), window);
2716 g_signal_connect (priv->handler, "sink-pad-added",
2717 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2718 g_signal_connect (priv->handler, "sink-pad-removed",
2719 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2721 g_object_get (priv->handler, "call-channel", &call, NULL);
2724 call_handler_notify_call_cb (priv->handler, NULL, window);
2725 g_object_unref (call);
2729 /* call-channel doesn't exist yet, we'll connect signals once it has been
2731 g_signal_connect (priv->handler, "notify::call-channel",
2732 G_CALLBACK (call_handler_notify_call_cb), window);
2735 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2739 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2740 EmpathyCallWindow *window)
2742 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2744 if (priv->pipeline != NULL)
2746 if (priv->bus_message_source_id != 0)
2748 g_source_remove (priv->bus_message_source_id);
2749 priv->bus_message_source_id = 0;
2752 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2755 if (priv->call_state == CONNECTING)
2756 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2762 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2765 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2767 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2772 gtk_widget_hide (priv->dtmf_panel);
2773 gtk_widget_hide (menu);
2774 gtk_widget_hide (priv->toolbar);
2778 if (priv->dialpad_was_visible_before_fs)
2779 gtk_widget_show (priv->dtmf_panel);
2781 gtk_widget_show (menu);
2782 gtk_widget_show (priv->toolbar);
2784 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2785 priv->original_height_before_fs);
2790 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2792 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2794 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2795 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2796 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2797 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2799 if (priv->video_output != NULL)
2802 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2803 priv->video_output, TRUE, TRUE,
2804 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2811 empathy_call_window_state_event_cb (GtkWidget *widget,
2812 GdkEventWindowState *event, EmpathyCallWindow *window)
2814 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2816 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2817 gboolean set_fullscreen = event->new_window_state &
2818 GDK_WINDOW_STATE_FULLSCREEN;
2822 gboolean dialpad_was_visible;
2823 GtkAllocation allocation;
2824 gint original_width, original_height;
2826 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2827 original_width = allocation.width;
2828 original_height = allocation.height;
2830 g_object_get (priv->dtmf_panel,
2831 "visible", &dialpad_was_visible,
2834 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2835 priv->original_width_before_fs = original_width;
2836 priv->original_height_before_fs = original_height;
2838 if (priv->video_output_motion_handler_id == 0 &&
2839 priv->video_output != NULL)
2841 priv->video_output_motion_handler_id = g_signal_connect (
2842 G_OBJECT (priv->video_container), "motion-notify-event",
2843 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2849 disconnect_video_output_motion_handler (window);
2852 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2854 show_controls (window, set_fullscreen);
2855 show_borders (window, set_fullscreen);
2856 gtk_action_set_stock_id (priv->menu_fullscreen,
2857 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2858 priv->is_fullscreen = set_fullscreen;
2865 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2868 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2869 int w, h, dialpad_width;
2870 GtkAllocation allocation;
2872 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2873 w = allocation.width;
2874 h = allocation.height;
2876 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2880 gtk_widget_show (priv->dtmf_panel);
2886 gtk_widget_hide (priv->dtmf_panel);
2890 gtk_window_resize (GTK_WINDOW (window), w, h);
2894 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2897 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2898 TpyCallChannel *call;
2900 priv->sending_video = (state == CAMERA_STATE_ON);
2902 if (state == CAMERA_STATE_ON)
2904 /* When we start sending video, we want to show the video preview by
2906 display_video_preview (window, TRUE);
2910 display_video_preview (window, FALSE);
2913 if (priv->call_state != CONNECTED)
2916 g_object_get (priv->handler, "call-channel", &call, NULL);
2917 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2918 tpy_call_channel_send_video (call, priv->sending_video);
2919 g_object_unref (call);
2923 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2924 EmpathyCallWindow *window)
2926 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2929 active = (gtk_toggle_tool_button_get_active (toggle));
2933 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2934 priv->volume * 100);
2938 /* TODO, Instead of setting the input volume to 0 we should probably
2939 * stop sending but this would cause the audio call to drop if both
2940 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2941 * in the future. GNOME #574574
2943 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2949 empathy_call_window_hangup_cb (gpointer object,
2950 EmpathyCallWindow *self)
2952 empathy_call_handler_stop_call (self->priv->handler);
2954 empathy_call_window_disconnected (self, TRUE);
2958 empathy_call_window_restart_call (EmpathyCallWindow *window)
2960 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2962 /* Remove error info bars */
2963 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
2964 (GtkCallback) gtk_widget_destroy, NULL);
2966 create_video_output_widget (window);
2968 /* While the call was disconnected, the input volume might have changed.
2969 * However, since the audio_input source was destroyed, its volume has not
2970 * been updated during that time. That's why we manually update it here */
2971 empathy_call_window_mic_volume_changed (window);
2973 priv->outgoing = TRUE;
2974 empathy_call_window_set_state_connecting (window);
2976 if (priv->pipeline_playing)
2977 start_call (window);
2979 /* call will be started when the pipeline is ready */
2980 priv->start_call_when_playing = TRUE;
2982 empathy_call_window_setup_avatars (window, priv->handler);
2984 empathy_call_window_show_hangup_button (window, TRUE);
2988 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
2989 EmpathyCallWindow *window)
2993 active = gtk_toggle_tool_button_get_active (button);
2995 empathy_call_window_show_dialpad (window, active);
2999 empathy_call_window_fullscreen_cb (gpointer object,
3000 EmpathyCallWindow *window)
3002 empathy_call_window_fullscreen_toggle (window);
3006 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3008 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3010 if (priv->is_fullscreen)
3011 gtk_window_unfullscreen (GTK_WINDOW (window));
3013 gtk_window_fullscreen (GTK_WINDOW (window));
3017 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3018 GdkEventButton *event, EmpathyCallWindow *window)
3020 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3022 empathy_call_window_video_menu_popup (window, event->button);
3030 empathy_call_window_key_press_cb (GtkWidget *video_output,
3031 GdkEventKey *event, EmpathyCallWindow *window)
3033 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3035 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3037 /* Since we are in fullscreen mode, toggling will bring us back to
3039 empathy_call_window_fullscreen_toggle (window);
3047 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3048 GdkEventMotion *event, EmpathyCallWindow *window)
3050 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3052 if (priv->is_fullscreen)
3054 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3061 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3065 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3067 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3069 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3070 button, gtk_get_current_event_time ());
3071 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3075 empathy_call_window_status_message (EmpathyCallWindow *self,
3078 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3082 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3083 gdouble value, EmpathyCallWindow *window)
3085 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3087 if (priv->audio_output == NULL)
3090 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3095 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3097 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3099 return priv->ui_manager;
3102 EmpathyGstAudioSrc *
3103 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3105 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3107 return (EmpathyGstAudioSrc *) priv->audio_input;