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"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
69 #define CONTENT_HBOX_BORDER_WIDTH 6
70 #define CONTENT_HBOX_SPACING 3
71 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
73 #define SELF_VIDEO_SECTION_WIDTH 120
74 #define SELF_VIDEO_SECTION_HEIGTH 90
75 #define SELF_VIDEO_SECTION_MARGIN 10
77 #define FLOATING_TOOLBAR_OPACITY 192
78 #define FLOATING_TOOLBAR_WIDTH 280
79 #define FLOATING_TOOLBAR_HEIGHT 36
80 #define FLOATING_TOOLBAR_SPACING 20
82 /* The avatar's default width and height are set to the same value because we
83 want a square icon. */
84 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
85 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
86 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
88 #define SMALL_TOOLBAR_SIZE 36
90 /* If an video input error occurs, the error message will start with "v4l" */
91 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
93 /* The time interval in milliseconds between 2 outgoing rings */
94 #define MS_BETWEEN_RING 500
96 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
99 PROP_CALL_HANDLER = 1,
111 CAMERA_STATE_OFF = 0,
115 struct _EmpathyCallWindowPriv
117 gboolean dispose_has_run;
118 EmpathyCallHandler *handler;
120 EmpathyContact *contact;
122 EmpathyCameraMonitor *camera_monitor;
127 GtkUIManager *ui_manager;
128 GtkWidget *errors_vbox;
129 /* widget displays the video received from the remote user. This widget is
130 * alive only during call. */
131 ClutterActor *video_output;
132 ClutterActor *video_preview;
133 ClutterActor *preview_hidden_button;
134 GtkWidget *video_container;
135 GtkWidget *remote_user_avatar_widget;
136 GtkWidget *remote_user_avatar_toolbar;
137 GtkWidget *remote_user_name_toolbar;
138 GtkWidget *status_label;
139 GtkWidget *hangup_button;
140 GtkWidget *audio_call_button;
141 GtkWidget *video_call_button;
142 GtkWidget *mic_button;
143 GtkWidget *camera_button;
144 GtkWidget *dialpad_button;
146 GtkWidget *bottom_toolbar;
147 ClutterActor *floating_toolbar;
149 GtkAction *menu_fullscreen;
151 ClutterState *transitions;
153 /* The box that contains self and remote avatar and video
154 input/output. When we redial, we destroy and re-create the box */
155 ClutterActor *video_box;
156 ClutterLayoutManager *video_layout;
158 /* We keep a reference on the hbox which contains the main content so we can
159 easilly repack everything when toggling fullscreen */
160 GtkWidget *content_hbox;
162 gulong video_output_motion_handler_id;
163 guint bus_message_source_id;
167 GtkWidget *dtmf_panel;
170 GtkWidget *details_vbox;
171 GtkWidget *vcodec_encoding_label;
172 GtkWidget *acodec_encoding_label;
173 GtkWidget *vcodec_decoding_label;
174 GtkWidget *acodec_decoding_label;
176 GtkWidget *audio_remote_candidate_label;
177 GtkWidget *audio_local_candidate_label;
178 GtkWidget *video_remote_candidate_label;
179 GtkWidget *video_local_candidate_label;
180 GtkWidget *video_remote_candidate_info_img;
181 GtkWidget *video_local_candidate_info_img;
182 GtkWidget *audio_remote_candidate_info_img;
183 GtkWidget *audio_local_candidate_info_img;
185 GstElement *video_input;
186 GstElement *video_preview_sink;
187 GstElement *video_output_sink;
188 GstElement *audio_input;
189 GstElement *audio_output;
190 GstElement *pipeline;
191 GstElement *video_tee;
201 gboolean call_started;
202 gboolean sending_video;
203 CameraState camera_state;
205 EmpathyCallWindowFullscreen *fullscreen;
206 gboolean is_fullscreen;
211 guint inactivity_src;
213 /* Those fields represent the state of the window before it actually was in
215 gboolean dialpad_was_visible_before_fs;
216 gint original_width_before_fs;
217 gint original_height_before_fs;
219 gint x, y, w, h, dialpad_width;
222 /* TRUE if the call should be started when the pipeline is playing */
223 gboolean start_call_when_playing;
224 /* TRUE if we requested to set the pipeline in the playing state */
225 gboolean pipeline_playing;
227 EmpathySoundManager *sound_mgr;
230 EmpathyMicMenu *mic_menu;
233 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
235 static void empathy_call_window_realized_cb (GtkWidget *widget,
236 EmpathyCallWindow *window);
238 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
239 GdkEvent *event, EmpathyCallWindow *window);
241 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
242 GdkEventWindowState *event, EmpathyCallWindow *window);
244 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
247 static void empathy_call_window_mic_toggled_cb (
248 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
250 static void empathy_call_window_hangup_cb (gpointer object,
251 EmpathyCallWindow *window);
253 static void empathy_call_window_fullscreen_cb (gpointer object,
254 EmpathyCallWindow *window);
256 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
258 static gboolean empathy_call_window_video_button_press_cb (
259 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
261 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
262 GdkEventKey *event, EmpathyCallWindow *window);
264 static gboolean empathy_call_window_video_output_motion_notify (
265 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
267 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
270 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
271 EmpathyCallWindow *window);
273 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
275 static void empathy_call_window_status_message (EmpathyCallWindow *window,
278 static gboolean empathy_call_window_bus_message (GstBus *bus,
279 GstMessage *message, gpointer user_data);
282 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
283 gdouble value, EmpathyCallWindow *window);
286 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
289 gtk_widget_set_visible (self->priv->hangup_button, show);
290 gtk_widget_set_visible (self->priv->audio_call_button, !show);
291 gtk_widget_set_visible (self->priv->video_call_button, !show);
295 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
296 EmpathyCallWindow *self)
298 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
299 empathy_call_window_restart_call (self);
303 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
304 EmpathyCallWindow *self)
306 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
307 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
308 empathy_call_window_restart_call (self);
312 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
314 EmpathyCallWindowPriv *priv = GET_PRIV (window);
315 TpyCallChannel *call;
319 g_object_get (priv->handler, "call-channel", &call, NULL);
321 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
322 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
325 tpy_call_channel_dtmf_start_tone (call, event);
327 g_object_unref (call);
331 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
333 EmpathyCallWindowPriv *priv = GET_PRIV (window);
334 TpyCallChannel *call;
336 g_object_get (priv->handler, "call-channel", &call, NULL);
338 tpy_call_channel_dtmf_stop_tone (call);
340 g_object_unref (call);
344 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
346 EmpathyCallWindowPriv *priv = GET_PRIV (self);
349 volume = g_settings_get_double (priv->settings,
350 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
352 /* Don't store the volume because of muting */
353 if (volume > 0 || gtk_toggle_tool_button_get_active (
354 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
355 priv->volume = volume;
357 /* Ensure that the toggle button is active if the volume is > 0 and inactive
358 * if it's smaller than 0 */
359 if ((volume > 0) != gtk_toggle_tool_button_get_active (
360 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
361 gtk_toggle_tool_button_set_active (
362 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
364 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
369 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
371 EmpathyCallWindow *self)
373 empathy_call_window_mic_volume_changed (self);
377 empathy_call_window_show_video_output (EmpathyCallWindow *self,
380 if (self->priv->video_output != NULL)
381 g_object_set (self->priv->video_output, "visible", show, NULL);
383 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
385 clutter_actor_raise_top (self->priv->floating_toolbar);
389 create_video_output_widget (EmpathyCallWindow *self)
391 EmpathyCallWindowPriv *priv = GET_PRIV (self);
393 g_assert (priv->video_output == NULL);
394 g_assert (priv->pipeline != NULL);
396 priv->video_output = clutter_texture_new ();
398 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
401 priv->video_output_sink = clutter_gst_video_sink_new (
402 CLUTTER_TEXTURE (priv->video_output));
404 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
407 gtk_widget_add_events (priv->video_container,
408 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
409 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
410 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
414 create_video_input (EmpathyCallWindow *self)
416 EmpathyCallWindowPriv *priv = GET_PRIV (self);
418 g_assert (priv->video_input == NULL);
419 priv->video_input = empathy_video_src_new ();
420 gst_object_ref (priv->video_input);
421 gst_object_sink (priv->video_input);
425 create_audio_input (EmpathyCallWindow *self)
427 EmpathyCallWindowPriv *priv = GET_PRIV (self);
429 g_assert (priv->audio_input == NULL);
430 priv->audio_input = empathy_audio_src_new ();
431 gst_object_ref (priv->audio_input);
432 gst_object_sink (priv->audio_input);
436 add_video_preview_to_pipeline (EmpathyCallWindow *self)
438 EmpathyCallWindowPriv *priv = GET_PRIV (self);
441 g_assert (priv->video_preview != NULL);
442 g_assert (priv->pipeline != NULL);
443 g_assert (priv->video_input != NULL);
444 g_assert (priv->video_tee != NULL);
446 preview = priv->video_preview_sink;
448 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
450 g_warning ("Could not add video input to pipeline");
454 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
456 g_warning ("Could not add video preview to pipeline");
460 if (!gst_element_link (priv->video_input, priv->video_tee))
462 g_warning ("Could not link video input to video tee");
466 if (!gst_element_link (priv->video_tee, preview))
468 g_warning ("Could not link video tee to video preview");
474 empathy_call_window_disable_camera_cb (GtkAction *action,
475 EmpathyCallWindow *self)
477 clutter_actor_destroy (self->priv->preview_hidden_button);
479 gtk_toggle_tool_button_set_active (
480 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
484 empathy_call_window_minimise_camera_cb (GtkAction *action,
485 EmpathyCallWindow *self)
487 clutter_actor_hide (self->priv->video_preview);
488 clutter_actor_show (self->priv->preview_hidden_button);
492 empathy_call_window_maximise_camera_cb (GtkAction *action,
493 EmpathyCallWindow *self)
495 clutter_actor_show (self->priv->video_preview);
496 clutter_actor_hide (self->priv->preview_hidden_button);
500 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
501 EmpathyCallWindow *self)
505 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
507 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
508 0, gtk_get_current_event_time ());
509 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
513 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
514 EmpathyCallWindow *self)
518 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
519 "/preview-hidden-menu");
520 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
521 0, gtk_get_current_event_time ());
522 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
526 create_video_preview (EmpathyCallWindow *self)
528 EmpathyCallWindowPriv *priv = GET_PRIV (self);
529 ClutterLayoutManager *layout, *layout_center;
530 ClutterActor *preview;
535 g_assert (priv->video_preview == NULL);
537 preview = clutter_texture_new ();
538 clutter_actor_set_size (preview,
539 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
540 priv->video_preview_sink = clutter_gst_video_sink_new (
541 CLUTTER_TEXTURE (preview));
543 /* Flip the video preview */
544 clutter_actor_set_rotation (preview,
547 SELF_VIDEO_SECTION_WIDTH * 0.5,
551 /* Add a little offset to the video preview */
552 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
553 CLUTTER_BIN_ALIGNMENT_CENTER);
554 priv->video_preview = clutter_box_new (layout);
555 clutter_actor_set_size (priv->video_preview,
556 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
557 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
558 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
560 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
561 CLUTTER_BIN_ALIGNMENT_CENTER);
562 box = clutter_box_new (layout_center);
563 clutter_actor_set_size (box,
564 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
566 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
567 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
569 g_object_set (priv->video_preview_sink,
574 /* Translators: this is an "Info" label. It should be as short
576 button = gtk_button_new_with_label (_("i"));
577 b = gtk_clutter_actor_new_with_contents (button);
579 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
581 CLUTTER_BIN_ALIGNMENT_END,
582 CLUTTER_BIN_ALIGNMENT_END);
584 g_signal_connect (button, "clicked",
585 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
588 /* Translators: this is an "Info" label. It should be as short
590 button = gtk_button_new_with_label (_("i"));
591 priv->preview_hidden_button =
592 gtk_clutter_actor_new_with_contents (button);
594 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
595 priv->preview_hidden_button,
596 CLUTTER_BIN_ALIGNMENT_START,
597 CLUTTER_BIN_ALIGNMENT_END);
599 clutter_actor_hide (priv->preview_hidden_button);
601 g_signal_connect (button, "clicked",
602 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
605 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
607 CLUTTER_BIN_ALIGNMENT_START,
608 CLUTTER_BIN_ALIGNMENT_END);
612 play_camera (EmpathyCallWindow *window,
615 EmpathyCallWindowPriv *priv = GET_PRIV (window);
619 if (priv->video_preview == NULL)
621 create_video_preview (window);
622 add_video_preview_to_pipeline (window);
626 state = GST_STATE_PLAYING;
628 state = GST_STATE_NULL;
630 preview = priv->video_preview_sink;
632 gst_element_set_state (preview, state);
633 gst_element_set_state (priv->video_input, state);
634 gst_element_set_state (priv->video_tee, state);
638 display_video_preview (EmpathyCallWindow *self,
641 EmpathyCallWindowPriv *priv = GET_PRIV (self);
645 /* Display the video preview */
646 DEBUG ("Show video preview");
648 play_camera (self, TRUE);
649 clutter_actor_show (priv->video_preview);
650 clutter_actor_raise_top (priv->floating_toolbar);
654 /* Hide the video preview */
655 DEBUG ("Hide video preview");
657 if (priv->video_preview != NULL)
659 clutter_actor_hide (priv->video_preview);
660 play_camera (self, FALSE);
666 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
668 EmpathyCallWindowPriv *priv = GET_PRIV (window);
670 empathy_call_window_status_message (window, _("Connecting…"));
671 priv->call_state = CONNECTING;
674 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
675 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
679 disable_camera (EmpathyCallWindow *self)
681 EmpathyCallWindowPriv *priv = GET_PRIV (self);
683 if (priv->camera_state == CAMERA_STATE_OFF)
686 DEBUG ("Disable camera");
688 display_video_preview (self, FALSE);
690 if (priv->camera_state == CAMERA_STATE_ON)
691 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
693 priv->camera_state = CAMERA_STATE_OFF;
697 enable_camera (EmpathyCallWindow *self)
699 EmpathyCallWindowPriv *priv = GET_PRIV (self);
701 if (priv->camera_state == CAMERA_STATE_ON)
704 if (priv->video_input == NULL)
706 DEBUG ("Can't enable camera, no input");
710 DEBUG ("Enable camera");
712 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
714 priv->camera_state = CAMERA_STATE_ON;
718 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
719 EmpathyCallWindow *self)
721 if (gtk_toggle_tool_button_get_active (toggle))
722 enable_camera (self);
724 disable_camera (self);
728 create_pipeline (EmpathyCallWindow *self)
730 EmpathyCallWindowPriv *priv = GET_PRIV (self);
733 g_assert (priv->pipeline == NULL);
735 priv->pipeline = gst_pipeline_new (NULL);
736 priv->pipeline_playing = FALSE;
738 priv->video_tee = gst_element_factory_make ("tee", NULL);
739 gst_object_ref (priv->video_tee);
740 gst_object_sink (priv->video_tee);
742 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
744 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
745 priv->bus_message_source_id = gst_bus_add_watch (bus,
746 empathy_call_window_bus_message, self);
748 g_object_unref (bus);
752 empathy_call_window_settings_cb (GtkAction *action,
753 EmpathyCallWindow *self)
755 gchar *args = g_strdup_printf ("-p %s",
756 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
758 empathy_launch_program (BIN_DIR, "empathy", args);
764 empathy_call_window_contents_cb (GtkAction *action,
765 EmpathyCallWindow *self)
767 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
771 empathy_call_window_debug_cb (GtkAction *action,
772 EmpathyCallWindow *self)
774 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
778 empathy_call_window_about_cb (GtkAction *action,
779 EmpathyCallWindow *self)
781 empathy_about_dialog_new (GTK_WINDOW (self));
785 empathy_call_window_toolbar_timeout (gpointer data)
787 EmpathyCallWindow *self = data;
789 clutter_state_set_state (self->priv->transitions, "fade-out");
795 empathy_call_window_motion_notify_cb (GtkWidget *widget,
797 EmpathyCallWindow *self)
799 clutter_state_set_state (self->priv->transitions, "fade-in");
801 if (self->priv->inactivity_src > 0)
802 g_source_remove (self->priv->inactivity_src);
804 self->priv->inactivity_src = g_timeout_add_seconds (3,
805 empathy_call_window_toolbar_timeout, self);
811 empathy_call_window_configure_event_cb (GtkWidget *widget,
813 EmpathyCallWindow *self)
815 GdkWindow *gdk_window;
816 GdkWindowState window_state;
818 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
819 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
821 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
822 &self->priv->dialpad_width, NULL);
824 gdk_window = gtk_widget_get_window (widget);
825 window_state = gdk_window_get_state (gdk_window);
826 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
832 empathy_call_window_destroyed_cb (GtkWidget *object,
833 EmpathyCallWindow *self)
835 if (gtk_widget_get_visible (self->priv->dtmf_panel))
837 /* Save the geometry as if the dialpad was hidden. */
838 empathy_geometry_save_values (GTK_WINDOW (self),
839 self->priv->x, self->priv->y,
840 self->priv->w - self->priv->dialpad_width, self->priv->h,
841 self->priv->maximized);
846 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
848 ClutterBindConstraint *constraint)
850 ClutterActorBox allocation;
852 clutter_actor_get_allocation_box (stage, &allocation);
854 clutter_bind_constraint_set_offset (constraint,
855 allocation.y2 - allocation.y1 -
856 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
860 empathy_call_window_init (EmpathyCallWindow *self)
862 EmpathyCallWindowPriv *priv;
866 ClutterConstraint *constraint;
867 ClutterActor *remote_avatar;
868 GtkStyleContext *context;
872 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
873 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
875 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
876 gui = empathy_builder_get_file (filename,
877 "call_window_vbox", &top_vbox,
878 "errors_vbox", &priv->errors_vbox,
880 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
881 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
882 "status_label", &priv->status_label,
883 "audiocall", &priv->audio_call_button,
884 "videocall", &priv->video_call_button,
885 "microphone", &priv->mic_button,
886 "camera", &priv->camera_button,
887 "hangup", &priv->hangup_button,
888 "dialpad", &priv->dialpad_button,
889 "toolbar", &priv->toolbar,
890 "bottom_toolbar", &priv->bottom_toolbar,
891 "ui_manager", &priv->ui_manager,
892 "menufullscreen", &priv->menu_fullscreen,
893 "details_vbox", &priv->details_vbox,
894 "vcodec_encoding_label", &priv->vcodec_encoding_label,
895 "acodec_encoding_label", &priv->acodec_encoding_label,
896 "acodec_decoding_label", &priv->acodec_decoding_label,
897 "vcodec_decoding_label", &priv->vcodec_decoding_label,
898 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
899 "audio_local_candidate_label", &priv->audio_local_candidate_label,
900 "video_remote_candidate_label", &priv->video_remote_candidate_label,
901 "video_local_candidate_label", &priv->video_local_candidate_label,
902 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
903 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
904 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
905 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
909 empathy_builder_connect (gui, self,
910 "hangup", "clicked", empathy_call_window_hangup_cb,
911 "audiocall", "clicked", empathy_call_window_audio_call_cb,
912 "videocall", "clicked", empathy_call_window_video_call_cb,
913 "volume", "value-changed", empathy_call_window_volume_changed_cb,
914 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
915 "camera", "toggled", empathy_call_window_camera_toggled_cb,
916 "dialpad", "toggled", empathy_call_window_dialpad_cb,
917 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
918 "menusettings", "activate", empathy_call_window_settings_cb,
919 "menucontents", "activate", empathy_call_window_contents_cb,
920 "menudebug", "activate", empathy_call_window_debug_cb,
921 "menuabout", "activate", empathy_call_window_about_cb,
922 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
923 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
924 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
927 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
929 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
931 g_object_bind_property (priv->camera_monitor, "available",
932 priv->camera_button, "sensitive",
933 G_BINDING_SYNC_CREATE);
935 priv->lock = g_mutex_new ();
937 gtk_container_add (GTK_CONTAINER (self), top_vbox);
939 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
940 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
941 CONTENT_HBOX_BORDER_WIDTH);
942 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
945 /* avatar/video box */
946 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
947 CLUTTER_BIN_ALIGNMENT_CENTER);
949 priv->video_box = clutter_box_new (priv->video_layout);
951 priv->video_container = gtk_clutter_embed_new ();
953 /* Set the background color to that of the rest of the window */
954 context = gtk_widget_get_style_context (priv->content_hbox);
955 gtk_style_context_get_background_color (context,
956 GTK_STATE_FLAG_NORMAL, &rgba);
957 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
958 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
959 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
960 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
961 clutter_stage_set_color (
962 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
963 GTK_CLUTTER_EMBED (priv->video_container))),
966 clutter_container_add (
967 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
968 GTK_CLUTTER_EMBED (priv->video_container))),
972 constraint = clutter_bind_constraint_new (
973 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
974 CLUTTER_BIND_SIZE, 0);
975 clutter_actor_add_constraint (priv->video_box, constraint);
977 priv->remote_user_avatar_widget = gtk_image_new ();
978 remote_avatar = gtk_clutter_actor_new_with_contents (
979 priv->remote_user_avatar_widget);
981 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
984 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
985 priv->video_container, TRUE, TRUE,
986 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
988 create_pipeline (self);
989 create_video_output_widget (self);
990 create_audio_input (self);
991 create_video_input (self);
993 priv->floating_toolbar = empathy_rounded_actor_new ();
995 gtk_widget_reparent (priv->bottom_toolbar,
996 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
998 constraint = clutter_bind_constraint_new (
999 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1002 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1005 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1006 "notify::allocation",
1007 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1010 clutter_actor_set_size (priv->floating_toolbar,
1011 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1012 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1014 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1015 priv->floating_toolbar,
1016 CLUTTER_BIN_ALIGNMENT_CENTER,
1017 CLUTTER_BIN_ALIGNMENT_END);
1019 clutter_actor_raise_top (priv->floating_toolbar);
1021 /* Transitions for the floating toolbar */
1022 priv->transitions = clutter_state_new ();
1024 /* all transitions last for 2s */
1025 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1027 /* transition from any state to "fade-out" state */
1028 clutter_state_set (priv->transitions, NULL, "fade-out",
1029 priv->floating_toolbar,
1030 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1033 /* transition from any state to "fade-in" state */
1034 clutter_state_set (priv->transitions, NULL, "fade-in",
1035 priv->floating_toolbar,
1036 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1039 /* put the actor into the "fade-in" state with no animation */
1040 clutter_state_warp_to_state (priv->transitions, "fade-in");
1042 /* The call will be started as soon the pipeline is playing */
1043 priv->start_call_when_playing = TRUE;
1045 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1046 G_CALLBACK (dtmf_button_pressed_cb),
1047 G_CALLBACK (dtmf_button_released_cb));
1049 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1052 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1055 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1057 gtk_widget_show_all (top_vbox);
1059 gtk_widget_hide (priv->dtmf_panel);
1060 gtk_widget_hide (priv->details_vbox);
1062 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1064 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1065 priv->video_container);
1067 /* We hide the bottom toolbar after 3s of inactivity and show it
1068 * again on mouse movement */
1069 priv->inactivity_src = g_timeout_add_seconds (3,
1070 empathy_call_window_toolbar_timeout, self);
1072 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1073 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1075 g_signal_connect (G_OBJECT (self), "realize",
1076 G_CALLBACK (empathy_call_window_realized_cb), self);
1078 g_signal_connect (G_OBJECT (self), "delete-event",
1079 G_CALLBACK (empathy_call_window_delete_cb), self);
1081 g_signal_connect (G_OBJECT (self), "window-state-event",
1082 G_CALLBACK (empathy_call_window_state_event_cb), self);
1084 g_signal_connect (G_OBJECT (self), "key-press-event",
1085 G_CALLBACK (empathy_call_window_key_press_cb), self);
1087 g_signal_connect (self, "motion-notify-event",
1088 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1090 priv->timer = g_timer_new ();
1092 g_object_ref (priv->ui_manager);
1093 g_object_unref (gui);
1095 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1096 priv->mic_menu = empathy_mic_menu_new (self);
1098 empathy_call_window_show_hangup_button (self, TRUE);
1100 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1102 /* Retrieve initial volume */
1103 priv->volume = g_settings_get_double (priv->settings,
1104 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1106 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1107 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1109 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1110 /* These signals are used to track the window position and save it
1111 * when the window is destroyed. We need to do this as we don't want
1112 * the window geometry to be saved with the dialpad taken into account. */
1113 g_signal_connect (self, "destroy",
1114 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1115 g_signal_connect (self, "configure-event",
1116 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1117 g_signal_connect (self, "window-state-event",
1118 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1120 /* Don't display labels in both toolbars */
1121 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1124 /* Instead of specifying a width and a height, we specify only one size. That's
1125 because we want a square avatar icon. */
1127 init_contact_avatar_with_size (EmpathyContact *contact,
1128 GtkWidget *image_widget,
1131 GdkPixbuf *pixbuf_avatar = NULL;
1133 if (contact != NULL)
1135 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1139 if (pixbuf_avatar == NULL)
1141 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1142 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1145 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1147 if (pixbuf_avatar != NULL)
1148 g_object_unref (pixbuf_avatar);
1152 set_window_title (EmpathyCallWindow *self)
1154 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1157 if (priv->contact != NULL)
1159 /* translators: Call is a noun and %s is the contact name. This string
1160 * is used in the window title */
1161 tmp = g_strdup_printf (_("Call with %s"),
1162 empathy_contact_get_alias (priv->contact));
1163 gtk_window_set_title (GTK_WINDOW (self), tmp);
1168 g_warning ("Unknown remote contact!");
1173 set_remote_user_name (EmpathyCallWindow *self,
1174 EmpathyContact *contact)
1176 const gchar *alias = empathy_contact_get_alias (contact);
1177 const gchar *status = empathy_contact_get_status (contact);
1180 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1181 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1187 contact_name_changed_cb (EmpathyContact *contact,
1189 EmpathyCallWindow *self)
1191 set_window_title (self);
1192 set_remote_user_name (self, contact);
1196 contact_presence_changed_cb (EmpathyContact *contact,
1198 EmpathyCallWindow *self)
1200 set_remote_user_name (self, contact);
1204 contact_avatar_changed_cb (EmpathyContact *contact,
1206 EmpathyCallWindow *self)
1209 GtkAllocation allocation;
1210 GtkWidget *avatar_widget;
1212 avatar_widget = self->priv->remote_user_avatar_widget;
1214 gtk_widget_get_allocation (avatar_widget, &allocation);
1215 size = allocation.height;
1219 /* the widget is not allocated yet, set a default size */
1220 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1221 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1224 init_contact_avatar_with_size (contact, avatar_widget, size);
1226 avatar_widget = self->priv->remote_user_avatar_toolbar;
1228 gtk_widget_get_allocation (avatar_widget, &allocation);
1229 size = allocation.height;
1233 /* the widget is not allocated yet, set a default size */
1234 size = SMALL_TOOLBAR_SIZE;
1237 init_contact_avatar_with_size (contact, avatar_widget, size);
1241 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1242 EmpathyCallHandler *handler)
1244 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1246 tp_g_signal_connect_object (priv->contact, "notify::name",
1247 G_CALLBACK (contact_name_changed_cb), self, 0);
1248 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1249 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1250 tp_g_signal_connect_object (priv->contact, "notify::presence",
1251 G_CALLBACK (contact_presence_changed_cb), self, 0);
1253 set_window_title (self);
1254 set_remote_user_name (self, priv->contact);
1256 init_contact_avatar_with_size (priv->contact,
1257 priv->remote_user_avatar_widget,
1258 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1259 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1261 init_contact_avatar_with_size (priv->contact,
1262 priv->remote_user_avatar_toolbar,
1263 SMALL_TOOLBAR_SIZE);
1265 /* The remote avatar is shown by default and will be hidden when we receive
1266 video from the remote side. */
1267 clutter_actor_hide (priv->video_output);
1268 gtk_widget_show (priv->remote_user_avatar_widget);
1272 update_send_codec (EmpathyCallWindow *self,
1275 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1282 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1283 widget = priv->acodec_encoding_label;
1287 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1288 widget = priv->vcodec_encoding_label;
1294 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1295 gtk_label_set_text (GTK_LABEL (widget), tmp);
1300 send_audio_codec_notify_cb (GObject *object,
1304 EmpathyCallWindow *self = user_data;
1306 update_send_codec (self, TRUE);
1310 send_video_codec_notify_cb (GObject *object,
1314 EmpathyCallWindow *self = user_data;
1316 update_send_codec (self, FALSE);
1320 update_recv_codec (EmpathyCallWindow *self,
1323 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1326 GString *str = NULL;
1330 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1331 widget = priv->acodec_decoding_label;
1335 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1336 widget = priv->vcodec_decoding_label;
1342 for (l = codecs; l != NULL; l = g_list_next (l))
1344 FsCodec *codec = l->data;
1347 str = g_string_new (NULL);
1349 g_string_append (str, ", ");
1351 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1355 gtk_label_set_text (GTK_LABEL (widget), str->str);
1356 g_string_free (str, TRUE);
1360 recv_audio_codecs_notify_cb (GObject *object,
1364 EmpathyCallWindow *self = user_data;
1366 update_recv_codec (self, TRUE);
1370 recv_video_codecs_notify_cb (GObject *object,
1374 EmpathyCallWindow *self = user_data;
1376 update_recv_codec (self, FALSE);
1379 static const gchar *
1380 candidate_type_to_str (FsCandidate *candidate)
1382 switch (candidate->type)
1384 case FS_CANDIDATE_TYPE_HOST:
1386 case FS_CANDIDATE_TYPE_SRFLX:
1387 return "server reflexive";
1388 case FS_CANDIDATE_TYPE_PRFLX:
1389 return "peer reflexive";
1390 case FS_CANDIDATE_TYPE_RELAY:
1392 case FS_CANDIDATE_TYPE_MULTICAST:
1399 static const gchar *
1400 candidate_type_to_desc (FsCandidate *candidate)
1402 switch (candidate->type)
1404 case FS_CANDIDATE_TYPE_HOST:
1405 return _("The IP address as seen by the machine");
1406 case FS_CANDIDATE_TYPE_SRFLX:
1407 return _("The IP address as seen by a server on the Internet");
1408 case FS_CANDIDATE_TYPE_PRFLX:
1409 return _("The IP address of the peer as seen by the other side");
1410 case FS_CANDIDATE_TYPE_RELAY:
1411 return _("The IP address of a relay server");
1412 case FS_CANDIDATE_TYPE_MULTICAST:
1413 return _("The IP address of the multicast group");
1420 update_candidat_widget (EmpathyCallWindow *self,
1423 FsCandidate *candidate)
1427 g_assert (candidate != NULL);
1428 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1429 candidate->port, candidate_type_to_str (candidate));
1431 gtk_label_set_text (GTK_LABEL (label), str);
1432 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1438 candidates_changed_cb (GObject *object,
1440 EmpathyCallWindow *self)
1442 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1443 FsCandidate *candidate = NULL;
1445 if (type == FS_MEDIA_TYPE_VIDEO)
1447 /* Update remote candidate */
1448 candidate = empathy_call_handler_get_video_remote_candidate (
1451 update_candidat_widget (self, priv->video_remote_candidate_label,
1452 priv->video_remote_candidate_info_img, candidate);
1454 /* Update local candidate */
1455 candidate = empathy_call_handler_get_video_local_candidate (
1458 update_candidat_widget (self, priv->video_local_candidate_label,
1459 priv->video_local_candidate_info_img, candidate);
1463 /* Update remote candidate */
1464 candidate = empathy_call_handler_get_audio_remote_candidate (
1467 update_candidat_widget (self, priv->audio_remote_candidate_label,
1468 priv->audio_remote_candidate_info_img, candidate);
1470 /* Update local candidate */
1471 candidate = empathy_call_handler_get_audio_local_candidate (
1474 update_candidat_widget (self, priv->audio_local_candidate_label,
1475 priv->audio_local_candidate_info_img, candidate);
1480 empathy_call_window_constructed (GObject *object)
1482 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1483 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1484 TpyCallChannel *call;
1486 g_assert (priv->handler != NULL);
1488 g_object_get (priv->handler, "call-channel", &call, NULL);
1489 priv->outgoing = (call == NULL);
1491 g_object_unref (call);
1493 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1494 g_assert (priv->contact != NULL);
1496 empathy_call_window_setup_avatars (self, priv->handler);
1497 empathy_call_window_set_state_connecting (self);
1499 if (!empathy_call_handler_has_initial_video (priv->handler))
1501 gtk_toggle_tool_button_set_active (
1502 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1504 /* If call has InitialVideo, the preview will be started once the call has
1505 * been started (start_call()). */
1507 update_send_codec (self, TRUE);
1508 update_send_codec (self, FALSE);
1509 update_recv_codec (self, TRUE);
1510 update_recv_codec (self, FALSE);
1512 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1513 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1514 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1515 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1516 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1517 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1518 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1519 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1521 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1522 G_CALLBACK (candidates_changed_cb), self, 0);
1525 static void empathy_call_window_dispose (GObject *object);
1526 static void empathy_call_window_finalize (GObject *object);
1529 empathy_call_window_set_property (GObject *object,
1530 guint property_id, const GValue *value, GParamSpec *pspec)
1532 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1534 switch (property_id)
1536 case PROP_CALL_HANDLER:
1537 priv->handler = g_value_dup_object (value);
1540 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1545 empathy_call_window_get_property (GObject *object,
1546 guint property_id, GValue *value, GParamSpec *pspec)
1548 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1550 switch (property_id)
1552 case PROP_CALL_HANDLER:
1553 g_value_set_object (value, priv->handler);
1556 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1561 empathy_call_window_class_init (
1562 EmpathyCallWindowClass *empathy_call_window_class)
1564 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1565 GParamSpec *param_spec;
1567 g_type_class_add_private (empathy_call_window_class,
1568 sizeof (EmpathyCallWindowPriv));
1570 object_class->constructed = empathy_call_window_constructed;
1571 object_class->set_property = empathy_call_window_set_property;
1572 object_class->get_property = empathy_call_window_get_property;
1574 object_class->dispose = empathy_call_window_dispose;
1575 object_class->finalize = empathy_call_window_finalize;
1577 param_spec = g_param_spec_object ("handler",
1578 "handler", "The call handler",
1579 EMPATHY_TYPE_CALL_HANDLER,
1580 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1581 g_object_class_install_property (object_class,
1582 PROP_CALL_HANDLER, param_spec);
1586 empathy_call_window_dispose (GObject *object)
1588 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1589 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1591 if (priv->dispose_has_run)
1594 priv->dispose_has_run = TRUE;
1596 if (priv->handler != NULL)
1598 empathy_call_handler_stop_call (priv->handler);
1599 tp_clear_object (&priv->handler);
1602 if (priv->bus_message_source_id != 0)
1604 g_source_remove (priv->bus_message_source_id);
1605 priv->bus_message_source_id = 0;
1608 if (priv->got_video_src > 0)
1610 g_source_remove (priv->got_video_src);
1611 priv->got_video_src = 0;
1614 if (priv->inactivity_src > 0)
1616 g_source_remove (priv->inactivity_src);
1617 priv->inactivity_src = 0;
1620 tp_clear_object (&priv->pipeline);
1621 tp_clear_object (&priv->video_input);
1622 tp_clear_object (&priv->audio_input);
1623 tp_clear_object (&priv->video_tee);
1624 tp_clear_object (&priv->ui_manager);
1625 tp_clear_object (&priv->fullscreen);
1626 tp_clear_object (&priv->camera_monitor);
1627 tp_clear_object (&priv->settings);
1628 tp_clear_object (&priv->transitions);
1630 g_list_free_full (priv->notifiers, g_object_unref);
1632 if (priv->timer_id != 0)
1633 g_source_remove (priv->timer_id);
1636 if (priv->contact != NULL)
1638 g_signal_handlers_disconnect_by_func (priv->contact,
1639 contact_name_changed_cb, self);
1640 priv->contact = NULL;
1644 tp_clear_object (&priv->sound_mgr);
1646 tp_clear_object (&priv->mic_menu);
1648 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1652 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1654 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1656 if (priv->video_output_motion_handler_id != 0)
1658 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1659 priv->video_output_motion_handler_id);
1660 priv->video_output_motion_handler_id = 0;
1665 empathy_call_window_finalize (GObject *object)
1667 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1668 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1670 disconnect_video_output_motion_handler (self);
1672 /* free any data held directly by the object here */
1673 g_mutex_free (priv->lock);
1675 g_timer_destroy (priv->timer);
1677 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1682 empathy_call_window_new (EmpathyCallHandler *handler)
1684 return EMPATHY_CALL_WINDOW (
1685 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1689 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1690 GstElement *conference, gpointer user_data)
1692 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1693 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1694 FsElementAddedNotifier *notifier;
1697 DEBUG ("Conference added");
1699 /* Add notifier to set the various element properties as needed */
1700 notifier = fs_element_added_notifier_new ();
1701 keyfile = fs_utils_get_default_element_properties (conference);
1703 if (keyfile != NULL)
1704 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1706 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1708 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1710 gst_bin_add (GST_BIN (priv->pipeline), conference);
1711 gst_element_set_state (conference, GST_STATE_PLAYING);
1715 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1716 GstElement *conference, gpointer user_data)
1718 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1719 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1721 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1722 gst_element_set_state (conference, GST_STATE_NULL);
1726 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1728 GstStateChangeReturn state_change_return;
1729 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1731 if (priv->pipeline == NULL)
1734 if (priv->bus_message_source_id != 0)
1736 g_source_remove (priv->bus_message_source_id);
1737 priv->bus_message_source_id = 0;
1740 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1742 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1743 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1745 if (priv->pipeline != NULL)
1746 g_object_unref (priv->pipeline);
1747 priv->pipeline = NULL;
1749 if (priv->audio_output != NULL)
1750 g_object_unref (priv->audio_output);
1751 priv->audio_output = NULL;
1753 if (priv->video_tee != NULL)
1754 g_object_unref (priv->video_tee);
1755 priv->video_tee = NULL;
1757 if (priv->video_preview != NULL)
1758 clutter_actor_destroy (priv->video_preview);
1759 priv->video_preview = NULL;
1761 priv->funnel = NULL;
1763 create_pipeline (self);
1764 /* Call will be started when user will hit the 'redial' button */
1765 priv->start_call_when_playing = FALSE;
1766 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1772 g_message ("Error: could not destroy pipeline. Closing call window");
1773 gtk_widget_destroy (GTK_WIDGET (self));
1780 reset_details_pane (EmpathyCallWindow *self)
1782 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1784 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1785 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1786 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1787 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1791 empathy_call_window_disconnected (EmpathyCallWindow *self,
1794 gboolean could_disconnect = FALSE;
1795 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1796 gboolean could_reset_pipeline;
1798 /* Leave full screen mode if needed */
1799 gtk_window_unfullscreen (GTK_WINDOW (self));
1801 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1802 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1804 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1806 if (priv->call_state == CONNECTING)
1807 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1809 if (priv->call_state != REDIALING)
1810 priv->call_state = DISCONNECTED;
1812 if (could_reset_pipeline)
1814 g_mutex_lock (priv->lock);
1816 g_timer_stop (priv->timer);
1818 if (priv->timer_id != 0)
1819 g_source_remove (priv->timer_id);
1822 g_mutex_unlock (priv->lock);
1825 /* We are about to destroy the window, no need to update it or create
1826 * a video preview */
1829 empathy_call_window_status_message (self, _("Disconnected"));
1831 empathy_call_window_show_hangup_button (self, FALSE);
1833 /* Unsensitive the camera and mic button */
1834 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1835 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1837 /* Be sure that the mic button is enabled */
1838 gtk_toggle_tool_button_set_active (
1839 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1841 if (priv->camera_state == CAMERA_STATE_ON)
1843 /* Restart the preview with the new pipeline. */
1844 display_video_preview (self, TRUE);
1847 /* destroy the video output; it will be recreated when we'll redial */
1848 disconnect_video_output_motion_handler (self);
1849 if (priv->video_output != NULL)
1850 clutter_actor_destroy (priv->video_output);
1851 priv->video_output = NULL;
1852 if (priv->got_video_src > 0)
1854 g_source_remove (priv->got_video_src);
1855 priv->got_video_src = 0;
1858 gtk_widget_show (priv->remote_user_avatar_widget);
1860 reset_details_pane (self);
1862 priv->sending_video = FALSE;
1863 priv->call_started = FALSE;
1865 could_disconnect = TRUE;
1867 /* TODO: display the self avatar of the preview (depends if the "Always
1868 * Show Video Preview" is enabled or not) */
1871 return could_disconnect;
1876 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1879 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1880 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1882 if (empathy_call_window_disconnected (self, TRUE) &&
1883 priv->call_state == REDIALING)
1884 empathy_call_window_restart_call (self);
1888 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1890 FsMediaType media_type,
1891 EmpathyCallWindow *self)
1893 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1895 DEBUG ("removing content");
1898 * This assumes that there is only one video stream per channel...
1901 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1903 if (priv->funnel != NULL)
1907 output = priv->video_output_sink;
1909 gst_element_set_state (output, GST_STATE_NULL);
1910 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1912 gst_bin_remove (GST_BIN (priv->pipeline), output);
1913 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1914 priv->funnel = NULL;
1918 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1920 if (priv->audio_output != NULL)
1922 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1924 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1925 priv->audio_output = NULL;
1933 /* Called with global lock held */
1935 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1937 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1941 if (priv->funnel == NULL)
1943 output = priv->video_output_sink;
1945 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1949 g_warning ("Could not create fsfunnel");
1953 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1955 gst_object_unref (priv->funnel);
1956 priv->funnel = NULL;
1957 g_warning ("Could not add funnel to pipeline");
1961 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1963 g_warning ("Could not add the video output widget to the pipeline");
1967 if (!gst_element_link (priv->funnel, output))
1969 g_warning ("Could not link output sink to funnel");
1970 goto error_output_added;
1973 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1975 g_warning ("Could not start video sink");
1976 goto error_output_added;
1979 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1981 g_warning ("Could not start funnel");
1982 goto error_output_added;
1986 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1989 g_warning ("Could not get request pad from funnel");
1996 gst_element_set_locked_state (priv->funnel, TRUE);
1997 gst_element_set_locked_state (output, TRUE);
1999 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2000 gst_element_set_state (output, GST_STATE_NULL);
2002 gst_bin_remove (GST_BIN (priv->pipeline), output);
2003 gst_element_set_locked_state (output, FALSE);
2007 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2008 priv->funnel = NULL;
2013 /* Called with global lock held */
2015 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2017 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2019 GstPadTemplate *template;
2021 if (priv->audio_output == NULL)
2023 priv->audio_output = empathy_audio_sink_new ();
2024 g_object_ref_sink (priv->audio_output);
2026 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2028 g_warning ("Could not add audio sink to pipeline");
2029 g_object_unref (priv->audio_output);
2030 goto error_add_output;
2033 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2035 g_warning ("Could not start audio sink");
2040 template = gst_element_class_get_pad_template (
2041 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2043 pad = gst_element_request_pad (priv->audio_output,
2044 template, NULL, NULL);
2048 g_warning ("Could not get sink pad from sink");
2055 gst_element_set_locked_state (priv->audio_output, TRUE);
2056 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2057 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2058 priv->audio_output = NULL;
2066 empathy_call_window_update_timer (gpointer user_data)
2068 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2069 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2070 const gchar *status;
2074 time_ = g_timer_elapsed (priv->timer, NULL);
2076 if (priv->call_state == HELD)
2077 status = _("On hold");
2078 else if (!gtk_toggle_tool_button_get_active (
2079 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2082 status = _("Duration");
2084 /* Translators: 'status - minutes:seconds' the caller has been connected */
2085 str = g_strdup_printf (_("%s — %d:%02dm"),
2087 (int) time_ / 60, (int) time_ % 60);
2088 empathy_call_window_status_message (self, str);
2096 display_error (EmpathyCallWindow *self,
2097 TpyCallChannel *call,
2101 const gchar *details)
2103 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2104 GtkWidget *info_bar;
2105 GtkWidget *content_area;
2112 /* Create info bar */
2113 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2116 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2118 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2120 /* hbox containing the image and the messages vbox */
2121 hbox = gtk_hbox_new (FALSE, 3);
2122 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2125 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2126 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2128 /* vbox containing the main message and the details expander */
2129 vbox = gtk_vbox_new (FALSE, 3);
2130 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2133 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2135 label = gtk_label_new (NULL);
2136 gtk_label_set_markup (GTK_LABEL (label), txt);
2137 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2138 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2141 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2144 if (details != NULL)
2146 GtkWidget *expander;
2148 expander = gtk_expander_new (_("Technical Details"));
2150 txt = g_strdup_printf ("<i>%s</i>", details);
2152 label = gtk_label_new (NULL);
2153 gtk_label_set_markup (GTK_LABEL (label), txt);
2154 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2155 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2158 gtk_container_add (GTK_CONTAINER (expander), label);
2159 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2162 g_signal_connect (info_bar, "response",
2163 G_CALLBACK (gtk_widget_destroy), NULL);
2165 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2166 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2167 gtk_widget_show_all (info_bar);
2171 media_stream_error_to_txt (EmpathyCallWindow *self,
2172 TpyCallChannel *call,
2174 TpMediaStreamError error)
2176 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2177 const gchar *cm = NULL;
2183 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2185 return g_strdup_printf (
2186 _("%s's software does not understand any of the audio formats "
2187 "supported by your computer"),
2188 empathy_contact_get_alias (priv->contact));
2190 return g_strdup_printf (
2191 _("%s's software does not understand any of the video formats "
2192 "supported by your computer"),
2193 empathy_contact_get_alias (priv->contact));
2195 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2196 return g_strdup_printf (
2197 _("Can't establish a connection to %s. "
2198 "One of you might be on a network that does not allow "
2199 "direct connections."),
2200 empathy_contact_get_alias (priv->contact));
2202 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2203 return g_strdup (_("There was a failure on the network"));
2205 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2207 return g_strdup (_("The audio formats necessary for this call "
2208 "are not installed on your computer"));
2210 return g_strdup (_("The video formats necessary for this call "
2211 "are not installed on your computer"));
2213 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2214 tp_connection_parse_object_path (
2215 tp_channel_borrow_connection (TP_CHANNEL (call)),
2218 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2219 "product=Telepathy&component=%s", cm);
2221 result = g_strdup_printf (
2222 _("Something unexpected happened in a Telepathy component. "
2223 "Please <a href=\"%s\">report this bug</a> and attach "
2224 "logs gathered from the 'Debug' window in the Help menu."), url);
2230 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2231 return g_strdup (_("There was a failure in the call engine"));
2233 case TP_MEDIA_STREAM_ERROR_EOS:
2234 return g_strdup (_("The end of the stream was reached"));
2236 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2243 empathy_call_window_stream_error (EmpathyCallWindow *self,
2244 TpyCallChannel *call,
2253 desc = media_stream_error_to_txt (self, call, audio, code);
2256 /* No description, use the error message. That's not great as it's not
2257 * localized but it's better than nothing. */
2258 display_error (self, call, icon, title, msg, NULL);
2262 display_error (self, call, icon, title, desc, msg);
2268 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2271 EmpathyCallWindow *self)
2273 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2274 "gnome-stock-mic", _("Can't establish audio stream"));
2278 empathy_call_window_video_stream_error (TpyCallChannel *call,
2281 EmpathyCallWindow *self)
2283 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2284 "camera-web", _("Can't establish video stream"));
2289 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2291 EmpathyCallWindow *self)
2293 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2294 TpyCallChannel *call;
2295 gboolean can_send_video;
2297 if (state != TPY_CALL_STATE_ACCEPTED)
2300 if (priv->call_state == CONNECTED)
2303 g_timer_start (priv->timer);
2304 priv->call_state = CONNECTED;
2306 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2308 can_send_video = priv->video_input != NULL &&
2309 empathy_contact_can_voip_video (priv->contact) &&
2310 empathy_camera_monitor_get_available (priv->camera_monitor);
2312 g_object_get (priv->handler, "call-channel", &call, NULL);
2314 if (tpy_call_channel_has_dtmf (call))
2315 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2317 if (priv->video_input == NULL)
2318 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2320 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2322 empathy_call_window_show_hangup_button (self, TRUE);
2324 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2326 clutter_actor_hide (priv->video_output);
2327 gtk_widget_show (priv->remote_user_avatar_widget);
2329 g_object_unref (call);
2331 g_mutex_lock (priv->lock);
2333 priv->timer_id = g_timeout_add_seconds (1,
2334 empathy_call_window_update_timer, self);
2336 g_mutex_unlock (priv->lock);
2338 empathy_call_window_update_timer (self);
2340 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2344 empathy_call_window_show_video_output_cb (gpointer user_data)
2346 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2348 if (self->priv->video_output != NULL)
2350 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2351 clutter_actor_show (self->priv->video_output);
2352 clutter_actor_raise_top (self->priv->floating_toolbar);
2359 empathy_call_window_check_video_cb (gpointer data)
2361 EmpathyCallWindow *self = data;
2363 if (self->priv->got_video)
2365 self->priv->got_video = FALSE;
2369 /* No video in the last N seconds, display the remote avatar */
2370 empathy_call_window_show_video_output (self, FALSE);
2375 /* Called from the streaming thread */
2377 empathy_call_window_video_probe_cb (GstPad *pad,
2378 GstMiniObject *mini_obj,
2379 EmpathyCallWindow *self)
2382 if (GST_IS_EVENT (mini_obj))
2385 if (G_UNLIKELY (!self->priv->got_video))
2387 /* show the remote video */
2388 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2389 empathy_call_window_show_video_output_cb,
2390 g_object_ref (self), g_object_unref);
2392 self->priv->got_video = TRUE;
2398 /* Called from the streaming thread */
2400 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2401 GstPad *src, guint media_type, gpointer user_data)
2403 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2404 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2405 gboolean retval = FALSE;
2409 g_mutex_lock (priv->lock);
2413 case TP_MEDIA_STREAM_TYPE_AUDIO:
2414 pad = empathy_call_window_get_audio_sink_pad (self);
2416 case TP_MEDIA_STREAM_TYPE_VIDEO:
2417 g_idle_add (empathy_call_window_show_video_output_cb, self);
2418 pad = empathy_call_window_get_video_sink_pad (self);
2420 gst_pad_add_data_probe (src,
2421 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2422 if (priv->got_video_src > 0)
2423 g_source_remove (priv->got_video_src);
2424 priv->got_video_src = g_timeout_add_seconds (5,
2425 empathy_call_window_check_video_cb, self);
2428 g_assert_not_reached ();
2434 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2435 g_warning ("Could not link %s sink pad",
2436 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2440 gst_object_unref (pad);
2444 /* If no sink could be linked, try to add fakesink to prevent the whole call
2449 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2451 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2453 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2454 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2455 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2457 gst_element_set_locked_state (fakesink, TRUE);
2458 gst_element_set_state (fakesink, GST_STATE_NULL);
2459 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2463 DEBUG ("Could not link real sink, linked fakesink instead");
2465 gst_object_unref (sinkpad);
2469 gst_object_unref (fakesink);
2474 g_mutex_unlock (priv->lock);
2480 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2481 GstPad *sink, FsMediaType media_type, gpointer user_data)
2483 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2484 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2486 gboolean retval = FALSE;
2490 case FS_MEDIA_TYPE_AUDIO:
2491 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2493 g_warning ("Could not add audio source to pipeline");
2497 pad = gst_element_get_static_pad (priv->audio_input, "src");
2500 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2501 g_warning ("Could not get source pad from audio source");
2505 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2507 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2508 g_warning ("Could not link audio source to farsight");
2512 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2514 g_warning ("Could not start audio source");
2515 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2516 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2522 case FS_MEDIA_TYPE_VIDEO:
2523 if (priv->video_tee != NULL)
2525 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2526 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2528 g_warning ("Could not link video source input pipeline");
2531 gst_object_unref (pad);
2537 g_assert_not_reached ();
2544 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2546 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2547 GstElement *preview;
2549 disable_camera (self);
2551 DEBUG ("remove video input");
2552 preview = priv->video_preview_sink;
2554 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2555 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2556 gst_element_set_state (preview, GST_STATE_NULL);
2558 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2561 g_object_unref (priv->video_input);
2562 priv->video_input = NULL;
2563 g_object_unref (priv->video_tee);
2564 priv->video_tee = NULL;
2565 clutter_actor_destroy (priv->video_preview);
2566 priv->video_preview = NULL;
2568 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2572 start_call (EmpathyCallWindow *self)
2574 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2576 priv->call_started = TRUE;
2577 empathy_call_handler_start_call (priv->handler,
2578 gtk_get_current_event_time ());
2580 if (empathy_call_handler_has_initial_video (priv->handler))
2582 TpyCallChannel *call;
2585 g_object_get (priv->handler, "call-channel", &call, NULL);
2586 s = tpy_call_channel_get_video_state (call);
2588 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2589 s == TPY_SENDING_STATE_SENDING)
2591 /* Enable 'send video' buttons and display the preview */
2592 gtk_toggle_tool_button_set_active (
2593 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2597 gtk_toggle_tool_button_set_active (
2598 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2600 if (priv->video_preview == NULL)
2602 create_video_preview (self);
2603 add_video_preview_to_pipeline (self);
2607 g_object_unref (call);
2612 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2615 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2616 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2619 empathy_call_handler_bus_message (priv->handler, bus, message);
2621 switch (GST_MESSAGE_TYPE (message))
2623 case GST_MESSAGE_STATE_CHANGED:
2624 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2626 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2628 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2629 !priv->call_started)
2631 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2632 if (newstate == GST_STATE_PAUSED)
2634 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2635 priv->pipeline_playing = TRUE;
2637 if (priv->start_call_when_playing)
2642 case GST_MESSAGE_ERROR:
2644 GError *error = NULL;
2645 GstElement *gst_error;
2648 gst_message_parse_error (message, &error, &debug);
2649 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2651 g_message ("Element error: %s -- %s\n", error->message, debug);
2653 if (g_str_has_prefix (gst_element_get_name (gst_error),
2654 VIDEO_INPUT_ERROR_PREFIX))
2656 /* Remove the video input and continue */
2657 if (priv->video_input != NULL)
2658 empathy_call_window_remove_video_input (self);
2659 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2663 empathy_call_window_disconnected (self, TRUE);
2665 g_error_free (error);
2668 case GST_MESSAGE_UNKNOWN:
2669 case GST_MESSAGE_EOS:
2670 case GST_MESSAGE_WARNING:
2671 case GST_MESSAGE_INFO:
2672 case GST_MESSAGE_TAG:
2673 case GST_MESSAGE_BUFFERING:
2674 case GST_MESSAGE_STATE_DIRTY:
2675 case GST_MESSAGE_STEP_DONE:
2676 case GST_MESSAGE_CLOCK_PROVIDE:
2677 case GST_MESSAGE_CLOCK_LOST:
2678 case GST_MESSAGE_NEW_CLOCK:
2679 case GST_MESSAGE_STRUCTURE_CHANGE:
2680 case GST_MESSAGE_STREAM_STATUS:
2681 case GST_MESSAGE_APPLICATION:
2682 case GST_MESSAGE_ELEMENT:
2683 case GST_MESSAGE_SEGMENT_START:
2684 case GST_MESSAGE_SEGMENT_DONE:
2685 case GST_MESSAGE_DURATION:
2686 case GST_MESSAGE_ANY:
2695 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2696 GHashTable *members,
2697 EmpathyCallWindow *self)
2699 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2700 GHashTableIter iter;
2701 gpointer key, value;
2702 gboolean held = FALSE;
2704 g_hash_table_iter_init (&iter, members);
2705 while (g_hash_table_iter_next (&iter, &key, &value))
2707 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2709 /* This assumes this is a 1-1 call, otherwise one participant
2710 * putting the call on hold wouldn't mean the call is on hold
2718 priv->call_state = HELD;
2719 else if (priv->call_state == HELD)
2720 priv->call_state = CONNECTED;
2724 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2726 EmpathyCallWindow *self)
2728 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2729 TpyCallChannel *call;
2731 g_object_get (priv->handler, "call-channel", &call, NULL);
2736 tp_g_signal_connect_object (call, "audio-stream-error",
2737 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2738 tp_g_signal_connect_object (call, "video-stream-error",
2739 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2742 tp_g_signal_connect_object (call, "members-changed",
2743 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2745 g_object_unref (call);
2749 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2751 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2752 TpyCallChannel *call;
2755 /* Make the hangup button twice as wide */
2756 width = gtk_widget_get_allocated_width (priv->hangup_button);
2757 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2759 g_signal_connect (priv->handler, "state-changed",
2760 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2761 g_signal_connect (priv->handler, "conference-added",
2762 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2763 g_signal_connect (priv->handler, "conference-removed",
2764 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2765 g_signal_connect (priv->handler, "closed",
2766 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2767 g_signal_connect (priv->handler, "src-pad-added",
2768 G_CALLBACK (empathy_call_window_src_added_cb), window);
2769 g_signal_connect (priv->handler, "sink-pad-added",
2770 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2771 g_signal_connect (priv->handler, "sink-pad-removed",
2772 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2774 g_object_get (priv->handler, "call-channel", &call, NULL);
2777 call_handler_notify_call_cb (priv->handler, NULL, window);
2778 g_object_unref (call);
2782 /* call-channel doesn't exist yet, we'll connect signals once it has been
2784 g_signal_connect (priv->handler, "notify::call-channel",
2785 G_CALLBACK (call_handler_notify_call_cb), window);
2788 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2792 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2793 EmpathyCallWindow *window)
2795 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2797 if (priv->pipeline != NULL)
2799 if (priv->bus_message_source_id != 0)
2801 g_source_remove (priv->bus_message_source_id);
2802 priv->bus_message_source_id = 0;
2805 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2808 if (priv->call_state == CONNECTING)
2809 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2815 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2818 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2820 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2825 gtk_widget_hide (priv->dtmf_panel);
2826 gtk_widget_hide (menu);
2827 gtk_widget_hide (priv->toolbar);
2831 if (priv->dialpad_was_visible_before_fs)
2832 gtk_widget_show (priv->dtmf_panel);
2834 gtk_widget_show (menu);
2835 gtk_widget_show (priv->toolbar);
2837 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2838 priv->original_height_before_fs);
2843 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2845 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2847 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2848 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2849 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2850 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2852 if (priv->video_output != NULL)
2855 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2856 priv->video_output, TRUE, TRUE,
2857 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2864 empathy_call_window_state_event_cb (GtkWidget *widget,
2865 GdkEventWindowState *event, EmpathyCallWindow *window)
2867 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2869 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2870 gboolean set_fullscreen = event->new_window_state &
2871 GDK_WINDOW_STATE_FULLSCREEN;
2875 gboolean dialpad_was_visible;
2876 GtkAllocation allocation;
2877 gint original_width, original_height;
2879 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2880 original_width = allocation.width;
2881 original_height = allocation.height;
2883 g_object_get (priv->dtmf_panel,
2884 "visible", &dialpad_was_visible,
2887 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2888 priv->original_width_before_fs = original_width;
2889 priv->original_height_before_fs = original_height;
2891 if (priv->video_output_motion_handler_id == 0 &&
2892 priv->video_output != NULL)
2894 priv->video_output_motion_handler_id = g_signal_connect (
2895 G_OBJECT (priv->video_container), "motion-notify-event",
2896 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2902 disconnect_video_output_motion_handler (window);
2905 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2907 show_controls (window, set_fullscreen);
2908 show_borders (window, set_fullscreen);
2909 gtk_action_set_stock_id (priv->menu_fullscreen,
2910 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2911 priv->is_fullscreen = set_fullscreen;
2918 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2921 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2922 int w, h, dialpad_width;
2923 GtkAllocation allocation;
2925 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2926 w = allocation.width;
2927 h = allocation.height;
2929 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2933 gtk_widget_show (priv->dtmf_panel);
2939 gtk_widget_hide (priv->dtmf_panel);
2943 gtk_window_resize (GTK_WINDOW (window), w, h);
2947 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2950 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2951 TpyCallChannel *call;
2953 priv->sending_video = (state == CAMERA_STATE_ON);
2955 if (state == CAMERA_STATE_ON)
2957 /* When we start sending video, we want to show the video preview by
2959 display_video_preview (window, TRUE);
2963 display_video_preview (window, FALSE);
2966 if (priv->call_state != CONNECTED)
2969 g_object_get (priv->handler, "call-channel", &call, NULL);
2970 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2971 tpy_call_channel_send_video (call, priv->sending_video);
2972 g_object_unref (call);
2976 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2977 EmpathyCallWindow *self)
2979 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2982 active = (gtk_toggle_tool_button_get_active (toggle));
2984 /* We don't want the settings callback to react to this change to avoid
2986 g_signal_handlers_block_by_func (priv->settings,
2987 empathy_call_window_prefs_volume_changed_cb, self);
2991 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2992 priv->volume * 100);
2996 /* TODO, Instead of setting the input volume to 0 we should probably
2997 * stop sending but this would cause the audio call to drop if both
2998 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2999 * in the future. GNOME #574574
3001 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3005 g_signal_handlers_unblock_by_func (priv->settings,
3006 empathy_call_window_prefs_volume_changed_cb, self);
3010 empathy_call_window_hangup_cb (gpointer object,
3011 EmpathyCallWindow *self)
3013 empathy_call_handler_stop_call (self->priv->handler);
3015 empathy_call_window_disconnected (self, TRUE);
3019 empathy_call_window_restart_call (EmpathyCallWindow *window)
3021 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3023 /* Remove error info bars */
3024 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3025 (GtkCallback) gtk_widget_destroy, NULL);
3027 create_video_output_widget (window);
3029 /* While the call was disconnected, the input volume might have changed.
3030 * However, since the audio_input source was destroyed, its volume has not
3031 * been updated during that time. That's why we manually update it here */
3032 empathy_call_window_mic_volume_changed (window);
3034 priv->outgoing = TRUE;
3035 empathy_call_window_set_state_connecting (window);
3037 if (priv->pipeline_playing)
3038 start_call (window);
3040 /* call will be started when the pipeline is ready */
3041 priv->start_call_when_playing = TRUE;
3043 empathy_call_window_setup_avatars (window, priv->handler);
3045 empathy_call_window_show_hangup_button (window, TRUE);
3049 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3050 EmpathyCallWindow *window)
3054 active = gtk_toggle_tool_button_get_active (button);
3056 empathy_call_window_show_dialpad (window, active);
3060 empathy_call_window_fullscreen_cb (gpointer object,
3061 EmpathyCallWindow *window)
3063 empathy_call_window_fullscreen_toggle (window);
3067 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3069 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3071 if (priv->is_fullscreen)
3072 gtk_window_unfullscreen (GTK_WINDOW (window));
3074 gtk_window_fullscreen (GTK_WINDOW (window));
3078 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3079 GdkEventButton *event, EmpathyCallWindow *window)
3081 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3083 empathy_call_window_video_menu_popup (window, event->button);
3091 empathy_call_window_key_press_cb (GtkWidget *video_output,
3092 GdkEventKey *event, EmpathyCallWindow *window)
3094 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3096 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3098 /* Since we are in fullscreen mode, toggling will bring us back to
3100 empathy_call_window_fullscreen_toggle (window);
3108 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3109 GdkEventMotion *event, EmpathyCallWindow *window)
3111 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3113 if (priv->is_fullscreen)
3115 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3117 /* Show the bottom toolbar */
3118 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3125 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3129 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3131 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3133 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3134 button, gtk_get_current_event_time ());
3135 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3139 empathy_call_window_status_message (EmpathyCallWindow *self,
3142 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3146 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3147 gdouble value, EmpathyCallWindow *window)
3149 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3151 if (priv->audio_output == NULL)
3154 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3159 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3161 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3163 return priv->ui_manager;
3166 EmpathyGstAudioSrc *
3167 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3169 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3171 return (EmpathyGstAudioSrc *) priv->audio_input;