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"
68 #define CONTENT_HBOX_BORDER_WIDTH 6
69 #define CONTENT_HBOX_SPACING 3
70 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
72 #define SELF_VIDEO_SECTION_WIDTH 120
73 #define SELF_VIDEO_SECTION_HEIGTH 90
75 #define FLOATING_TOOLBAR_OPACITY 192
76 #define FLOATING_TOOLBAR_WIDTH 280
77 #define FLOATING_TOOLBAR_HEIGHT 36
78 #define FLOATING_TOOLBAR_SPACING 20
80 /* The avatar's default width and height are set to the same value because we
81 want a square icon. */
82 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
83 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
84 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
86 #define SMALL_TOOLBAR_SIZE 36
88 /* If an video input error occurs, the error message will start with "v4l" */
89 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
91 /* The time interval in milliseconds between 2 outgoing rings */
92 #define MS_BETWEEN_RING 500
94 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
97 PROP_CALL_HANDLER = 1,
109 CAMERA_STATE_OFF = 0,
113 struct _EmpathyCallWindowPriv
115 gboolean dispose_has_run;
116 EmpathyCallHandler *handler;
118 EmpathyContact *contact;
120 EmpathyCameraMonitor *camera_monitor;
125 GtkUIManager *ui_manager;
126 GtkWidget *errors_vbox;
127 /* widget displays the video received from the remote user. This widget is
128 * alive only during call. */
129 ClutterActor *video_output;
130 ClutterActor *video_preview;
131 ClutterActor *preview_hidden_button;
132 GtkWidget *video_container;
133 GtkWidget *remote_user_avatar_widget;
134 GtkWidget *remote_user_avatar_toolbar;
135 GtkWidget *remote_user_name_toolbar;
136 GtkWidget *status_label;
137 GtkWidget *hangup_button;
138 GtkWidget *audio_call_button;
139 GtkWidget *video_call_button;
140 GtkWidget *mic_button;
141 GtkWidget *camera_button;
142 GtkWidget *dialpad_button;
144 GtkWidget *bottom_toolbar;
145 ClutterActor *floating_toolbar;
147 GtkAction *menu_fullscreen;
149 ClutterState *transitions;
151 /* The box that contains self and remote avatar and video
152 input/output. When we redial, we destroy and re-create the box */
153 ClutterActor *video_box;
154 ClutterLayoutManager *video_layout;
156 /* We keep a reference on the hbox which contains the main content so we can
157 easilly repack everything when toggling fullscreen */
158 GtkWidget *content_hbox;
160 gulong video_output_motion_handler_id;
161 guint bus_message_source_id;
165 GtkWidget *dtmf_panel;
168 GtkWidget *details_vbox;
169 GtkWidget *vcodec_encoding_label;
170 GtkWidget *acodec_encoding_label;
171 GtkWidget *vcodec_decoding_label;
172 GtkWidget *acodec_decoding_label;
174 GtkWidget *audio_remote_candidate_label;
175 GtkWidget *audio_local_candidate_label;
176 GtkWidget *video_remote_candidate_label;
177 GtkWidget *video_local_candidate_label;
178 GtkWidget *video_remote_candidate_info_img;
179 GtkWidget *video_local_candidate_info_img;
180 GtkWidget *audio_remote_candidate_info_img;
181 GtkWidget *audio_local_candidate_info_img;
183 GstElement *video_input;
184 GstElement *video_preview_sink;
185 GstElement *video_output_sink;
186 GstElement *audio_input;
187 GstElement *audio_output;
188 GstElement *pipeline;
189 GstElement *video_tee;
199 gboolean call_started;
200 gboolean sending_video;
201 CameraState camera_state;
203 EmpathyCallWindowFullscreen *fullscreen;
204 gboolean is_fullscreen;
209 guint inactivity_src;
211 /* Those fields represent the state of the window before it actually was in
213 gboolean dialpad_was_visible_before_fs;
214 gint original_width_before_fs;
215 gint original_height_before_fs;
217 gint x, y, w, h, dialpad_width;
220 /* TRUE if the call should be started when the pipeline is playing */
221 gboolean start_call_when_playing;
222 /* TRUE if we requested to set the pipeline in the playing state */
223 gboolean pipeline_playing;
225 EmpathySoundManager *sound_mgr;
228 EmpathyMicMenu *mic_menu;
231 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
233 static void empathy_call_window_realized_cb (GtkWidget *widget,
234 EmpathyCallWindow *window);
236 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
237 GdkEvent *event, EmpathyCallWindow *window);
239 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
240 GdkEventWindowState *event, EmpathyCallWindow *window);
242 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
245 static void empathy_call_window_mic_toggled_cb (
246 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
248 static void empathy_call_window_hangup_cb (gpointer object,
249 EmpathyCallWindow *window);
251 static void empathy_call_window_fullscreen_cb (gpointer object,
252 EmpathyCallWindow *window);
254 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
256 static gboolean empathy_call_window_video_button_press_cb (
257 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
259 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
260 GdkEventKey *event, EmpathyCallWindow *window);
262 static gboolean empathy_call_window_video_output_motion_notify (
263 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
265 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
268 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
269 EmpathyCallWindow *window);
271 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
273 static void empathy_call_window_status_message (EmpathyCallWindow *window,
276 static gboolean empathy_call_window_bus_message (GstBus *bus,
277 GstMessage *message, gpointer user_data);
280 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
281 gdouble value, EmpathyCallWindow *window);
284 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
287 gtk_widget_set_visible (self->priv->hangup_button, show);
288 gtk_widget_set_visible (self->priv->audio_call_button, !show);
289 gtk_widget_set_visible (self->priv->video_call_button, !show);
293 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
294 EmpathyCallWindow *self)
296 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
297 empathy_call_window_restart_call (self);
301 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
302 EmpathyCallWindow *self)
304 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
305 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
306 empathy_call_window_restart_call (self);
310 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
312 EmpathyCallWindowPriv *priv = GET_PRIV (window);
313 TpyCallChannel *call;
317 g_object_get (priv->handler, "call-channel", &call, NULL);
319 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
320 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
323 tpy_call_channel_dtmf_start_tone (call, event);
325 g_object_unref (call);
329 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
331 EmpathyCallWindowPriv *priv = GET_PRIV (window);
332 TpyCallChannel *call;
334 g_object_get (priv->handler, "call-channel", &call, NULL);
336 tpy_call_channel_dtmf_stop_tone (call);
338 g_object_unref (call);
342 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
344 EmpathyCallWindowPriv *priv = GET_PRIV (self);
347 volume = g_settings_get_double (priv->settings,
348 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
350 /* Don't store the volume because of muting */
351 if (volume > 0 || gtk_toggle_tool_button_get_active (
352 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
353 priv->volume = volume;
355 /* Ensure that the toggle button is active if the volume is > 0 and inactive
356 * if it's smaller than 0 */
357 if ((volume > 0) != gtk_toggle_tool_button_get_active (
358 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
359 gtk_toggle_tool_button_set_active (
360 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
362 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
367 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
369 EmpathyCallWindow *self)
371 empathy_call_window_mic_volume_changed (self);
375 empathy_call_window_show_video_output (EmpathyCallWindow *self,
378 if (self->priv->video_output != NULL)
379 g_object_set (self->priv->video_output, "visible", show, NULL);
381 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
383 clutter_actor_raise_top (self->priv->floating_toolbar);
387 create_video_output_widget (EmpathyCallWindow *self)
389 EmpathyCallWindowPriv *priv = GET_PRIV (self);
391 g_assert (priv->video_output == NULL);
392 g_assert (priv->pipeline != NULL);
394 priv->video_output = clutter_texture_new ();
396 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
399 priv->video_output_sink = clutter_gst_video_sink_new (
400 CLUTTER_TEXTURE (priv->video_output));
402 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
405 gtk_widget_add_events (priv->video_container,
406 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
407 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
408 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
412 create_video_input (EmpathyCallWindow *self)
414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
416 g_assert (priv->video_input == NULL);
417 priv->video_input = empathy_video_src_new ();
418 gst_object_ref (priv->video_input);
419 gst_object_sink (priv->video_input);
423 create_audio_input (EmpathyCallWindow *self)
425 EmpathyCallWindowPriv *priv = GET_PRIV (self);
427 g_assert (priv->audio_input == NULL);
428 priv->audio_input = empathy_audio_src_new ();
429 gst_object_ref (priv->audio_input);
430 gst_object_sink (priv->audio_input);
434 add_video_preview_to_pipeline (EmpathyCallWindow *self)
436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
439 g_assert (priv->video_preview != NULL);
440 g_assert (priv->pipeline != NULL);
441 g_assert (priv->video_input != NULL);
442 g_assert (priv->video_tee != NULL);
444 preview = priv->video_preview_sink;
446 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
448 g_warning ("Could not add video input to pipeline");
452 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
454 g_warning ("Could not add video preview to pipeline");
458 if (!gst_element_link (priv->video_input, priv->video_tee))
460 g_warning ("Could not link video input to video tee");
464 if (!gst_element_link (priv->video_tee, preview))
466 g_warning ("Could not link video tee to video preview");
472 empathy_call_window_disable_camera_cb (GtkAction *action,
473 EmpathyCallWindow *self)
475 clutter_actor_destroy (self->priv->preview_hidden_button);
477 gtk_toggle_tool_button_set_active (
478 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
482 empathy_call_window_minimise_camera_cb (GtkAction *action,
483 EmpathyCallWindow *self)
485 clutter_actor_hide (self->priv->video_preview);
486 clutter_actor_show (self->priv->preview_hidden_button);
490 empathy_call_window_maximise_camera_cb (GtkAction *action,
491 EmpathyCallWindow *self)
493 clutter_actor_show (self->priv->video_preview);
494 clutter_actor_hide (self->priv->preview_hidden_button);
498 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
499 EmpathyCallWindow *self)
503 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
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 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
512 EmpathyCallWindow *self)
516 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
517 "/preview-hidden-menu");
518 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
519 0, gtk_get_current_event_time ());
520 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
524 create_video_preview (EmpathyCallWindow *self)
526 EmpathyCallWindowPriv *priv = GET_PRIV (self);
527 ClutterLayoutManager *layout, *layout_center;
528 ClutterActor *preview;
533 g_assert (priv->video_preview == NULL);
535 preview = clutter_texture_new ();
536 clutter_actor_set_size (preview,
537 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
538 priv->video_preview_sink = clutter_gst_video_sink_new (
539 CLUTTER_TEXTURE (preview));
541 /* Flip the video preview */
542 clutter_actor_set_rotation (preview,
545 SELF_VIDEO_SECTION_WIDTH * 0.5,
549 /* Add a little offset to the video preview */
550 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
551 CLUTTER_BIN_ALIGNMENT_START);
552 priv->video_preview = clutter_box_new (layout);
553 clutter_actor_set_size (priv->video_preview,
554 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
556 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
557 CLUTTER_BIN_ALIGNMENT_CENTER);
558 box = clutter_box_new (layout_center);
559 clutter_actor_set_size (box,
560 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
562 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
563 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
565 g_object_set (priv->video_preview_sink,
570 /* Translators: this is an "Info" label. It should be as short
572 button = gtk_button_new_with_label (_("i"));
573 b = gtk_clutter_actor_new_with_contents (button);
575 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
577 CLUTTER_BIN_ALIGNMENT_END,
578 CLUTTER_BIN_ALIGNMENT_END);
580 g_signal_connect (button, "clicked",
581 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
584 /* Translators: this is an "Info" label. It should be as short
586 button = gtk_button_new_with_label (_("i"));
587 priv->preview_hidden_button =
588 gtk_clutter_actor_new_with_contents (button);
590 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
591 priv->preview_hidden_button,
592 CLUTTER_BIN_ALIGNMENT_START,
593 CLUTTER_BIN_ALIGNMENT_END);
595 clutter_actor_hide (priv->preview_hidden_button);
597 g_signal_connect (button, "clicked",
598 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
601 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
603 CLUTTER_BIN_ALIGNMENT_START,
604 CLUTTER_BIN_ALIGNMENT_END);
608 play_camera (EmpathyCallWindow *window,
611 EmpathyCallWindowPriv *priv = GET_PRIV (window);
615 if (priv->video_preview == NULL)
617 create_video_preview (window);
618 add_video_preview_to_pipeline (window);
622 state = GST_STATE_PLAYING;
624 state = GST_STATE_NULL;
626 preview = priv->video_preview_sink;
628 gst_element_set_state (preview, state);
629 gst_element_set_state (priv->video_input, state);
630 gst_element_set_state (priv->video_tee, state);
634 display_video_preview (EmpathyCallWindow *self,
637 EmpathyCallWindowPriv *priv = GET_PRIV (self);
641 /* Display the video preview */
642 DEBUG ("Show video preview");
644 play_camera (self, TRUE);
645 clutter_actor_show (priv->video_preview);
649 /* Hide the video preview */
650 DEBUG ("Hide video preview");
652 if (priv->video_preview != NULL)
654 clutter_actor_hide (priv->video_preview);
655 play_camera (self, FALSE);
661 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
663 EmpathyCallWindowPriv *priv = GET_PRIV (window);
665 empathy_call_window_status_message (window, _("Connecting…"));
666 priv->call_state = CONNECTING;
669 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
670 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
674 disable_camera (EmpathyCallWindow *self)
676 EmpathyCallWindowPriv *priv = GET_PRIV (self);
678 if (priv->camera_state == CAMERA_STATE_OFF)
681 DEBUG ("Disable camera");
683 display_video_preview (self, FALSE);
685 if (priv->camera_state == CAMERA_STATE_ON)
686 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
688 priv->camera_state = CAMERA_STATE_OFF;
692 enable_camera (EmpathyCallWindow *self)
694 EmpathyCallWindowPriv *priv = GET_PRIV (self);
696 if (priv->camera_state == CAMERA_STATE_ON)
699 if (priv->video_input == NULL)
701 DEBUG ("Can't enable camera, no input");
705 DEBUG ("Enable camera");
707 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
709 priv->camera_state = CAMERA_STATE_ON;
713 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
714 EmpathyCallWindow *self)
716 if (gtk_toggle_tool_button_get_active (toggle))
717 enable_camera (self);
719 disable_camera (self);
723 create_pipeline (EmpathyCallWindow *self)
725 EmpathyCallWindowPriv *priv = GET_PRIV (self);
728 g_assert (priv->pipeline == NULL);
730 priv->pipeline = gst_pipeline_new (NULL);
731 priv->pipeline_playing = FALSE;
733 priv->video_tee = gst_element_factory_make ("tee", NULL);
734 gst_object_ref (priv->video_tee);
735 gst_object_sink (priv->video_tee);
737 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
739 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
740 priv->bus_message_source_id = gst_bus_add_watch (bus,
741 empathy_call_window_bus_message, self);
743 g_object_unref (bus);
747 empathy_call_window_settings_cb (GtkAction *action,
748 EmpathyCallWindow *self)
750 gchar *args = g_strdup_printf ("-p %s",
751 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
753 empathy_launch_program (BIN_DIR, "empathy", args);
759 empathy_call_window_contents_cb (GtkAction *action,
760 EmpathyCallWindow *self)
762 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
766 empathy_call_window_debug_cb (GtkAction *action,
767 EmpathyCallWindow *self)
769 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
773 empathy_call_window_about_cb (GtkAction *action,
774 EmpathyCallWindow *self)
776 empathy_about_dialog_new (GTK_WINDOW (self));
780 empathy_call_window_toolbar_timeout (gpointer data)
782 EmpathyCallWindow *self = data;
784 clutter_state_set_state (self->priv->transitions, "fade-out");
790 empathy_call_window_motion_notify_cb (GtkWidget *widget,
792 EmpathyCallWindow *self)
794 clutter_state_set_state (self->priv->transitions, "fade-in");
796 if (self->priv->inactivity_src > 0)
797 g_source_remove (self->priv->inactivity_src);
799 self->priv->inactivity_src = g_timeout_add_seconds (3,
800 empathy_call_window_toolbar_timeout, self);
806 empathy_call_window_configure_event_cb (GtkWidget *widget,
808 EmpathyCallWindow *self)
810 GdkWindow *gdk_window;
811 GdkWindowState window_state;
813 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
814 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
816 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
817 &self->priv->dialpad_width, NULL);
819 gdk_window = gtk_widget_get_window (widget);
820 window_state = gdk_window_get_state (gdk_window);
821 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
827 empathy_call_window_destroyed_cb (GtkWidget *object,
828 EmpathyCallWindow *self)
830 if (gtk_widget_get_visible (self->priv->dtmf_panel))
832 /* Save the geometry as if the dialpad was hidden. */
833 empathy_geometry_save_values (GTK_WINDOW (self),
834 self->priv->x, self->priv->y,
835 self->priv->w - self->priv->dialpad_width, self->priv->h,
836 self->priv->maximized);
841 empathy_call_window_video_box_allocation_changed_cb (ClutterActor *video_box,
843 ClutterBindConstraint *constraint)
845 ClutterActorBox allocation;
847 clutter_actor_get_allocation_box (video_box, &allocation);
849 clutter_bind_constraint_set_offset (constraint,
850 allocation.y2 - allocation.y1 -
851 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
855 empathy_call_window_init (EmpathyCallWindow *self)
857 EmpathyCallWindowPriv *priv;
861 ClutterConstraint *constraint;
862 ClutterActor *remote_avatar;
863 GtkStyleContext *context;
867 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
868 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
870 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
871 gui = empathy_builder_get_file (filename,
872 "call_window_vbox", &top_vbox,
873 "errors_vbox", &priv->errors_vbox,
875 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
876 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
877 "status_label", &priv->status_label,
878 "audiocall", &priv->audio_call_button,
879 "videocall", &priv->video_call_button,
880 "microphone", &priv->mic_button,
881 "camera", &priv->camera_button,
882 "hangup", &priv->hangup_button,
883 "dialpad", &priv->dialpad_button,
884 "toolbar", &priv->toolbar,
885 "bottom_toolbar", &priv->bottom_toolbar,
886 "ui_manager", &priv->ui_manager,
887 "menufullscreen", &priv->menu_fullscreen,
888 "details_vbox", &priv->details_vbox,
889 "vcodec_encoding_label", &priv->vcodec_encoding_label,
890 "acodec_encoding_label", &priv->acodec_encoding_label,
891 "acodec_decoding_label", &priv->acodec_decoding_label,
892 "vcodec_decoding_label", &priv->vcodec_decoding_label,
893 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
894 "audio_local_candidate_label", &priv->audio_local_candidate_label,
895 "video_remote_candidate_label", &priv->video_remote_candidate_label,
896 "video_local_candidate_label", &priv->video_local_candidate_label,
897 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
898 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
899 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
900 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
904 empathy_builder_connect (gui, self,
905 "hangup", "clicked", empathy_call_window_hangup_cb,
906 "audiocall", "clicked", empathy_call_window_audio_call_cb,
907 "videocall", "clicked", empathy_call_window_video_call_cb,
908 "volume", "value-changed", empathy_call_window_volume_changed_cb,
909 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
910 "camera", "toggled", empathy_call_window_camera_toggled_cb,
911 "dialpad", "toggled", empathy_call_window_dialpad_cb,
912 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
913 "menusettings", "activate", empathy_call_window_settings_cb,
914 "menucontents", "activate", empathy_call_window_contents_cb,
915 "menudebug", "activate", empathy_call_window_debug_cb,
916 "menuabout", "activate", empathy_call_window_about_cb,
917 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
918 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
919 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
922 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
924 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
926 g_object_bind_property (priv->camera_monitor, "available",
927 priv->camera_button, "sensitive",
928 G_BINDING_SYNC_CREATE);
930 priv->lock = g_mutex_new ();
932 gtk_container_add (GTK_CONTAINER (self), top_vbox);
934 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
935 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
936 CONTENT_HBOX_BORDER_WIDTH);
937 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
940 /* avatar/video box */
941 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
942 CLUTTER_BIN_ALIGNMENT_CENTER);
944 priv->video_box = clutter_box_new (priv->video_layout);
946 priv->video_container = gtk_clutter_embed_new ();
948 /* Set the background color to that of the rest of the window */
949 context = gtk_widget_get_style_context (priv->content_hbox);
950 gtk_style_context_get_background_color (context,
951 GTK_STATE_FLAG_NORMAL, &rgba);
952 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
953 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
954 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
955 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
956 clutter_stage_set_color (
957 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
958 GTK_CLUTTER_EMBED (priv->video_container))),
961 clutter_container_add (
962 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
963 GTK_CLUTTER_EMBED (priv->video_container))),
967 constraint = clutter_bind_constraint_new (
968 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
969 CLUTTER_BIND_SIZE, 0);
970 clutter_actor_add_constraint (priv->video_box, constraint);
972 priv->remote_user_avatar_widget = gtk_image_new ();
973 remote_avatar = gtk_clutter_actor_new_with_contents (
974 priv->remote_user_avatar_widget);
976 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
979 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
980 priv->video_container, TRUE, TRUE,
981 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
983 create_pipeline (self);
984 create_video_output_widget (self);
985 create_audio_input (self);
986 create_video_input (self);
988 priv->floating_toolbar = gtk_clutter_actor_new ();
990 gtk_widget_reparent (priv->bottom_toolbar,
991 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
993 constraint = clutter_bind_constraint_new (priv->video_box,
996 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
998 g_signal_connect (priv->video_box, "notify::allocation",
999 G_CALLBACK (empathy_call_window_video_box_allocation_changed_cb),
1002 clutter_actor_set_size (priv->floating_toolbar,
1003 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1004 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1006 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1007 priv->floating_toolbar,
1008 CLUTTER_BIN_ALIGNMENT_CENTER,
1009 CLUTTER_BIN_ALIGNMENT_END);
1011 clutter_actor_raise_top (priv->floating_toolbar);
1013 /* Transitions for the floating toolbar */
1014 priv->transitions = clutter_state_new ();
1016 /* all transitions last for 2s */
1017 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1019 /* transition from any state to "fade-out" state */
1020 clutter_state_set (priv->transitions, NULL, "fade-out",
1021 priv->floating_toolbar,
1022 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1025 /* transition from any state to "fade-in" state */
1026 clutter_state_set (priv->transitions, NULL, "fade-in",
1027 priv->floating_toolbar,
1028 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1031 /* put the actor into the "fade-in" state with no animation */
1032 clutter_state_warp_to_state (priv->transitions, "fade-in");
1034 /* The call will be started as soon the pipeline is playing */
1035 priv->start_call_when_playing = TRUE;
1037 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1038 G_CALLBACK (dtmf_button_pressed_cb),
1039 G_CALLBACK (dtmf_button_released_cb));
1041 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1044 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1047 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1049 gtk_widget_show_all (top_vbox);
1051 gtk_widget_hide (priv->dtmf_panel);
1052 gtk_widget_hide (priv->details_vbox);
1054 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1056 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1057 priv->video_container);
1059 /* We hide the bottom toolbar after 3s of inactivity and show it
1060 * again on mouse movement */
1061 priv->inactivity_src = g_timeout_add_seconds (3,
1062 empathy_call_window_toolbar_timeout, self);
1064 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1065 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1067 g_signal_connect (G_OBJECT (self), "realize",
1068 G_CALLBACK (empathy_call_window_realized_cb), self);
1070 g_signal_connect (G_OBJECT (self), "delete-event",
1071 G_CALLBACK (empathy_call_window_delete_cb), self);
1073 g_signal_connect (G_OBJECT (self), "window-state-event",
1074 G_CALLBACK (empathy_call_window_state_event_cb), self);
1076 g_signal_connect (G_OBJECT (self), "key-press-event",
1077 G_CALLBACK (empathy_call_window_key_press_cb), self);
1079 g_signal_connect (self, "motion-notify-event",
1080 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1082 priv->timer = g_timer_new ();
1084 g_object_ref (priv->ui_manager);
1085 g_object_unref (gui);
1087 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1088 priv->mic_menu = empathy_mic_menu_new (self);
1090 empathy_call_window_show_hangup_button (self, TRUE);
1092 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1093 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1094 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1096 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1097 /* These signals are used to track the window position and save it
1098 * when the window is destroyed. We need to do this as we don't want
1099 * the window geometry to be saved with the dialpad taken into account. */
1100 g_signal_connect (self, "destroy",
1101 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1102 g_signal_connect (self, "configure-event",
1103 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1104 g_signal_connect (self, "window-state-event",
1105 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1107 /* Don't display labels in both toolbars */
1108 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1111 /* Instead of specifying a width and a height, we specify only one size. That's
1112 because we want a square avatar icon. */
1114 init_contact_avatar_with_size (EmpathyContact *contact,
1115 GtkWidget *image_widget,
1118 GdkPixbuf *pixbuf_avatar = NULL;
1120 if (contact != NULL)
1122 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1126 if (pixbuf_avatar == NULL)
1128 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1129 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1132 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1134 if (pixbuf_avatar != NULL)
1135 g_object_unref (pixbuf_avatar);
1139 set_window_title (EmpathyCallWindow *self)
1141 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1144 if (priv->contact != NULL)
1146 /* translators: Call is a noun and %s is the contact name. This string
1147 * is used in the window title */
1148 tmp = g_strdup_printf (_("Call with %s"),
1149 empathy_contact_get_alias (priv->contact));
1150 gtk_window_set_title (GTK_WINDOW (self), tmp);
1155 g_warning ("Unknown remote contact!");
1160 set_remote_user_name (EmpathyCallWindow *self,
1161 EmpathyContact *contact)
1163 const gchar *alias = empathy_contact_get_alias (contact);
1164 const gchar *status = empathy_contact_get_status (contact);
1167 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1168 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1174 contact_name_changed_cb (EmpathyContact *contact,
1176 EmpathyCallWindow *self)
1178 set_window_title (self);
1179 set_remote_user_name (self, contact);
1183 contact_presence_changed_cb (EmpathyContact *contact,
1185 EmpathyCallWindow *self)
1187 set_remote_user_name (self, contact);
1191 contact_avatar_changed_cb (EmpathyContact *contact,
1193 EmpathyCallWindow *self)
1196 GtkAllocation allocation;
1197 GtkWidget *avatar_widget;
1199 avatar_widget = self->priv->remote_user_avatar_widget;
1201 gtk_widget_get_allocation (avatar_widget, &allocation);
1202 size = allocation.height;
1206 /* the widget is not allocated yet, set a default size */
1207 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1208 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1211 init_contact_avatar_with_size (contact, avatar_widget, size);
1213 avatar_widget = self->priv->remote_user_avatar_toolbar;
1215 gtk_widget_get_allocation (avatar_widget, &allocation);
1216 size = allocation.height;
1220 /* the widget is not allocated yet, set a default size */
1221 size = SMALL_TOOLBAR_SIZE;
1224 init_contact_avatar_with_size (contact, avatar_widget, size);
1228 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1229 EmpathyCallHandler *handler)
1231 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1233 tp_g_signal_connect_object (priv->contact, "notify::name",
1234 G_CALLBACK (contact_name_changed_cb), self, 0);
1235 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1236 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1237 tp_g_signal_connect_object (priv->contact, "notify::presence",
1238 G_CALLBACK (contact_presence_changed_cb), self, 0);
1240 set_window_title (self);
1241 set_remote_user_name (self, priv->contact);
1243 init_contact_avatar_with_size (priv->contact,
1244 priv->remote_user_avatar_widget,
1245 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1246 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1248 init_contact_avatar_with_size (priv->contact,
1249 priv->remote_user_avatar_toolbar,
1250 SMALL_TOOLBAR_SIZE);
1252 /* The remote avatar is shown by default and will be hidden when we receive
1253 video from the remote side. */
1254 clutter_actor_hide (priv->video_output);
1255 gtk_widget_show (priv->remote_user_avatar_widget);
1259 update_send_codec (EmpathyCallWindow *self,
1262 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1269 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1270 widget = priv->acodec_encoding_label;
1274 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1275 widget = priv->vcodec_encoding_label;
1281 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1282 gtk_label_set_text (GTK_LABEL (widget), tmp);
1287 send_audio_codec_notify_cb (GObject *object,
1291 EmpathyCallWindow *self = user_data;
1293 update_send_codec (self, TRUE);
1297 send_video_codec_notify_cb (GObject *object,
1301 EmpathyCallWindow *self = user_data;
1303 update_send_codec (self, FALSE);
1307 update_recv_codec (EmpathyCallWindow *self,
1310 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1313 GString *str = NULL;
1317 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1318 widget = priv->acodec_decoding_label;
1322 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1323 widget = priv->vcodec_decoding_label;
1329 for (l = codecs; l != NULL; l = g_list_next (l))
1331 FsCodec *codec = l->data;
1334 str = g_string_new (NULL);
1336 g_string_append (str, ", ");
1338 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1342 gtk_label_set_text (GTK_LABEL (widget), str->str);
1343 g_string_free (str, TRUE);
1347 recv_audio_codecs_notify_cb (GObject *object,
1351 EmpathyCallWindow *self = user_data;
1353 update_recv_codec (self, TRUE);
1357 recv_video_codecs_notify_cb (GObject *object,
1361 EmpathyCallWindow *self = user_data;
1363 update_recv_codec (self, FALSE);
1366 static const gchar *
1367 candidate_type_to_str (FsCandidate *candidate)
1369 switch (candidate->type)
1371 case FS_CANDIDATE_TYPE_HOST:
1373 case FS_CANDIDATE_TYPE_SRFLX:
1374 return "server reflexive";
1375 case FS_CANDIDATE_TYPE_PRFLX:
1376 return "peer reflexive";
1377 case FS_CANDIDATE_TYPE_RELAY:
1379 case FS_CANDIDATE_TYPE_MULTICAST:
1386 static const gchar *
1387 candidate_type_to_desc (FsCandidate *candidate)
1389 switch (candidate->type)
1391 case FS_CANDIDATE_TYPE_HOST:
1392 return _("The IP address as seen by the machine");
1393 case FS_CANDIDATE_TYPE_SRFLX:
1394 return _("The IP address as seen by a server on the Internet");
1395 case FS_CANDIDATE_TYPE_PRFLX:
1396 return _("The IP address of the peer as seen by the other side");
1397 case FS_CANDIDATE_TYPE_RELAY:
1398 return _("The IP address of a relay server");
1399 case FS_CANDIDATE_TYPE_MULTICAST:
1400 return _("The IP address of the multicast group");
1407 update_candidat_widget (EmpathyCallWindow *self,
1410 FsCandidate *candidate)
1414 g_assert (candidate != NULL);
1415 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1416 candidate->port, candidate_type_to_str (candidate));
1418 gtk_label_set_text (GTK_LABEL (label), str);
1419 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1425 candidates_changed_cb (GObject *object,
1427 EmpathyCallWindow *self)
1429 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1430 FsCandidate *candidate = NULL;
1432 if (type == FS_MEDIA_TYPE_VIDEO)
1434 /* Update remote candidate */
1435 candidate = empathy_call_handler_get_video_remote_candidate (
1438 update_candidat_widget (self, priv->video_remote_candidate_label,
1439 priv->video_remote_candidate_info_img, candidate);
1441 /* Update local candidate */
1442 candidate = empathy_call_handler_get_video_local_candidate (
1445 update_candidat_widget (self, priv->video_local_candidate_label,
1446 priv->video_local_candidate_info_img, candidate);
1450 /* Update remote candidate */
1451 candidate = empathy_call_handler_get_audio_remote_candidate (
1454 update_candidat_widget (self, priv->audio_remote_candidate_label,
1455 priv->audio_remote_candidate_info_img, candidate);
1457 /* Update local candidate */
1458 candidate = empathy_call_handler_get_audio_local_candidate (
1461 update_candidat_widget (self, priv->audio_local_candidate_label,
1462 priv->audio_local_candidate_info_img, candidate);
1467 empathy_call_window_constructed (GObject *object)
1469 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1470 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1471 TpyCallChannel *call;
1473 g_assert (priv->handler != NULL);
1475 g_object_get (priv->handler, "call-channel", &call, NULL);
1476 priv->outgoing = (call == NULL);
1478 g_object_unref (call);
1480 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1481 g_assert (priv->contact != NULL);
1483 empathy_call_window_setup_avatars (self, priv->handler);
1484 empathy_call_window_set_state_connecting (self);
1486 if (!empathy_call_handler_has_initial_video (priv->handler))
1488 gtk_toggle_tool_button_set_active (
1489 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1491 /* If call has InitialVideo, the preview will be started once the call has
1492 * been started (start_call()). */
1494 update_send_codec (self, TRUE);
1495 update_send_codec (self, FALSE);
1496 update_recv_codec (self, TRUE);
1497 update_recv_codec (self, FALSE);
1499 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1500 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1501 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1502 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1503 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1504 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1505 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1506 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1508 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1509 G_CALLBACK (candidates_changed_cb), self, 0);
1512 static void empathy_call_window_dispose (GObject *object);
1513 static void empathy_call_window_finalize (GObject *object);
1516 empathy_call_window_set_property (GObject *object,
1517 guint property_id, const GValue *value, GParamSpec *pspec)
1519 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1521 switch (property_id)
1523 case PROP_CALL_HANDLER:
1524 priv->handler = g_value_dup_object (value);
1527 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1532 empathy_call_window_get_property (GObject *object,
1533 guint property_id, GValue *value, GParamSpec *pspec)
1535 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1537 switch (property_id)
1539 case PROP_CALL_HANDLER:
1540 g_value_set_object (value, priv->handler);
1543 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1548 empathy_call_window_class_init (
1549 EmpathyCallWindowClass *empathy_call_window_class)
1551 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1552 GParamSpec *param_spec;
1554 g_type_class_add_private (empathy_call_window_class,
1555 sizeof (EmpathyCallWindowPriv));
1557 object_class->constructed = empathy_call_window_constructed;
1558 object_class->set_property = empathy_call_window_set_property;
1559 object_class->get_property = empathy_call_window_get_property;
1561 object_class->dispose = empathy_call_window_dispose;
1562 object_class->finalize = empathy_call_window_finalize;
1564 param_spec = g_param_spec_object ("handler",
1565 "handler", "The call handler",
1566 EMPATHY_TYPE_CALL_HANDLER,
1567 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1568 g_object_class_install_property (object_class,
1569 PROP_CALL_HANDLER, param_spec);
1573 empathy_call_window_dispose (GObject *object)
1575 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1576 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1578 if (priv->dispose_has_run)
1581 priv->dispose_has_run = TRUE;
1583 if (priv->handler != NULL)
1585 empathy_call_handler_stop_call (priv->handler);
1586 tp_clear_object (&priv->handler);
1589 if (priv->bus_message_source_id != 0)
1591 g_source_remove (priv->bus_message_source_id);
1592 priv->bus_message_source_id = 0;
1595 if (priv->got_video_src > 0)
1597 g_source_remove (priv->got_video_src);
1598 priv->got_video_src = 0;
1601 if (priv->inactivity_src > 0)
1603 g_source_remove (priv->inactivity_src);
1604 priv->inactivity_src = 0;
1607 tp_clear_object (&priv->pipeline);
1608 tp_clear_object (&priv->video_input);
1609 tp_clear_object (&priv->audio_input);
1610 tp_clear_object (&priv->video_tee);
1611 tp_clear_object (&priv->ui_manager);
1612 tp_clear_object (&priv->fullscreen);
1613 tp_clear_object (&priv->camera_monitor);
1614 tp_clear_object (&priv->settings);
1615 tp_clear_object (&priv->transitions);
1617 g_list_free_full (priv->notifiers, g_object_unref);
1619 if (priv->timer_id != 0)
1620 g_source_remove (priv->timer_id);
1623 if (priv->contact != NULL)
1625 g_signal_handlers_disconnect_by_func (priv->contact,
1626 contact_name_changed_cb, self);
1627 priv->contact = NULL;
1631 tp_clear_object (&priv->sound_mgr);
1633 tp_clear_object (&priv->mic_menu);
1635 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1639 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1641 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1643 if (priv->video_output_motion_handler_id != 0)
1645 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1646 priv->video_output_motion_handler_id);
1647 priv->video_output_motion_handler_id = 0;
1652 empathy_call_window_finalize (GObject *object)
1654 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1655 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1657 disconnect_video_output_motion_handler (self);
1659 /* free any data held directly by the object here */
1660 g_mutex_free (priv->lock);
1662 g_timer_destroy (priv->timer);
1664 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1669 empathy_call_window_new (EmpathyCallHandler *handler)
1671 return EMPATHY_CALL_WINDOW (
1672 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1676 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1677 GstElement *conference, gpointer user_data)
1679 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1680 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1681 FsElementAddedNotifier *notifier;
1684 DEBUG ("Conference added");
1686 /* Add notifier to set the various element properties as needed */
1687 notifier = fs_element_added_notifier_new ();
1688 keyfile = fs_utils_get_default_element_properties (conference);
1690 if (keyfile != NULL)
1691 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1693 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1695 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1697 gst_bin_add (GST_BIN (priv->pipeline), conference);
1698 gst_element_set_state (conference, GST_STATE_PLAYING);
1702 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1703 GstElement *conference, gpointer user_data)
1705 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1706 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1708 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1709 gst_element_set_state (conference, GST_STATE_NULL);
1713 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1715 GstStateChangeReturn state_change_return;
1716 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1718 if (priv->pipeline == NULL)
1721 if (priv->bus_message_source_id != 0)
1723 g_source_remove (priv->bus_message_source_id);
1724 priv->bus_message_source_id = 0;
1727 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1729 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1730 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1732 if (priv->pipeline != NULL)
1733 g_object_unref (priv->pipeline);
1734 priv->pipeline = NULL;
1736 if (priv->audio_output != NULL)
1737 g_object_unref (priv->audio_output);
1738 priv->audio_output = NULL;
1740 if (priv->video_tee != NULL)
1741 g_object_unref (priv->video_tee);
1742 priv->video_tee = NULL;
1744 if (priv->video_preview != NULL)
1745 clutter_actor_destroy (priv->video_preview);
1746 priv->video_preview = NULL;
1748 priv->funnel = NULL;
1750 create_pipeline (self);
1751 /* Call will be started when user will hit the 'redial' button */
1752 priv->start_call_when_playing = FALSE;
1753 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1759 g_message ("Error: could not destroy pipeline. Closing call window");
1760 gtk_widget_destroy (GTK_WIDGET (self));
1767 reset_details_pane (EmpathyCallWindow *self)
1769 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1771 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1772 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1773 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1774 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1778 empathy_call_window_disconnected (EmpathyCallWindow *self,
1781 gboolean could_disconnect = FALSE;
1782 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1783 gboolean could_reset_pipeline;
1785 /* Leave full screen mode if needed */
1786 gtk_window_unfullscreen (GTK_WINDOW (self));
1788 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1789 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1791 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1793 if (priv->call_state == CONNECTING)
1794 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1796 if (priv->call_state != REDIALING)
1797 priv->call_state = DISCONNECTED;
1799 if (could_reset_pipeline)
1801 g_mutex_lock (priv->lock);
1803 g_timer_stop (priv->timer);
1805 if (priv->timer_id != 0)
1806 g_source_remove (priv->timer_id);
1809 g_mutex_unlock (priv->lock);
1812 /* We are about to destroy the window, no need to update it or create
1813 * a video preview */
1816 empathy_call_window_status_message (self, _("Disconnected"));
1818 empathy_call_window_show_hangup_button (self, FALSE);
1820 /* Unsensitive the camera and mic button */
1821 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1822 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1824 /* Be sure that the mic button is enabled */
1825 gtk_toggle_tool_button_set_active (
1826 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1828 if (priv->camera_state == CAMERA_STATE_ON)
1830 /* Restart the preview with the new pipeline. */
1831 display_video_preview (self, TRUE);
1834 /* destroy the video output; it will be recreated when we'll redial */
1835 disconnect_video_output_motion_handler (self);
1836 if (priv->video_output != NULL)
1837 clutter_actor_destroy (priv->video_output);
1838 priv->video_output = NULL;
1839 if (priv->got_video_src > 0)
1841 g_source_remove (priv->got_video_src);
1842 priv->got_video_src = 0;
1845 gtk_widget_show (priv->remote_user_avatar_widget);
1847 reset_details_pane (self);
1849 priv->sending_video = FALSE;
1850 priv->call_started = FALSE;
1852 could_disconnect = TRUE;
1854 /* TODO: display the self avatar of the preview (depends if the "Always
1855 * Show Video Preview" is enabled or not) */
1858 return could_disconnect;
1863 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1866 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1867 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1869 if (empathy_call_window_disconnected (self, TRUE) &&
1870 priv->call_state == REDIALING)
1871 empathy_call_window_restart_call (self);
1875 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1877 FsMediaType media_type,
1878 EmpathyCallWindow *self)
1880 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1882 DEBUG ("removing content");
1885 * This assumes that there is only one video stream per channel...
1888 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1890 if (priv->funnel != NULL)
1894 output = priv->video_output_sink;
1896 gst_element_set_state (output, GST_STATE_NULL);
1897 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1899 gst_bin_remove (GST_BIN (priv->pipeline), output);
1900 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1901 priv->funnel = NULL;
1905 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1907 if (priv->audio_output != NULL)
1909 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1911 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1912 priv->audio_output = NULL;
1920 /* Called with global lock held */
1922 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1924 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1928 if (priv->funnel == NULL)
1930 output = priv->video_output_sink;
1932 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1936 g_warning ("Could not create fsfunnel");
1940 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1942 gst_object_unref (priv->funnel);
1943 priv->funnel = NULL;
1944 g_warning ("Could not add funnel to pipeline");
1948 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1950 g_warning ("Could not add the video output widget to the pipeline");
1954 if (!gst_element_link (priv->funnel, output))
1956 g_warning ("Could not link output sink to funnel");
1957 goto error_output_added;
1960 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1962 g_warning ("Could not start video sink");
1963 goto error_output_added;
1966 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1968 g_warning ("Could not start funnel");
1969 goto error_output_added;
1973 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1976 g_warning ("Could not get request pad from funnel");
1983 gst_element_set_locked_state (priv->funnel, TRUE);
1984 gst_element_set_locked_state (output, TRUE);
1986 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1987 gst_element_set_state (output, GST_STATE_NULL);
1989 gst_bin_remove (GST_BIN (priv->pipeline), output);
1990 gst_element_set_locked_state (output, FALSE);
1994 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1995 priv->funnel = NULL;
2000 /* Called with global lock held */
2002 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2004 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2006 GstPadTemplate *template;
2008 if (priv->audio_output == NULL)
2010 priv->audio_output = empathy_audio_sink_new ();
2011 g_object_ref_sink (priv->audio_output);
2013 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2015 g_warning ("Could not add audio sink to pipeline");
2016 g_object_unref (priv->audio_output);
2017 goto error_add_output;
2020 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2022 g_warning ("Could not start audio sink");
2027 template = gst_element_class_get_pad_template (
2028 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2030 pad = gst_element_request_pad (priv->audio_output,
2031 template, NULL, NULL);
2035 g_warning ("Could not get sink pad from sink");
2042 gst_element_set_locked_state (priv->audio_output, TRUE);
2043 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2044 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2045 priv->audio_output = NULL;
2053 empathy_call_window_update_timer (gpointer user_data)
2055 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2056 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2057 const gchar *status;
2061 time_ = g_timer_elapsed (priv->timer, NULL);
2063 if (priv->call_state == HELD)
2064 status = _("On hold");
2065 else if (!gtk_toggle_tool_button_get_active (
2066 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2069 status = _("Duration");
2071 /* Translators: 'status - minutes:seconds' the caller has been connected */
2072 str = g_strdup_printf (_("%s — %d:%02dm"),
2074 (int) time_ / 60, (int) time_ % 60);
2075 empathy_call_window_status_message (self, str);
2083 display_error (EmpathyCallWindow *self,
2084 TpyCallChannel *call,
2088 const gchar *details)
2090 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2091 GtkWidget *info_bar;
2092 GtkWidget *content_area;
2099 /* Create info bar */
2100 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2103 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2105 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2107 /* hbox containing the image and the messages vbox */
2108 hbox = gtk_hbox_new (FALSE, 3);
2109 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2112 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2113 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2115 /* vbox containing the main message and the details expander */
2116 vbox = gtk_vbox_new (FALSE, 3);
2117 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2120 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2122 label = gtk_label_new (NULL);
2123 gtk_label_set_markup (GTK_LABEL (label), txt);
2124 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2125 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2128 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2131 if (details != NULL)
2133 GtkWidget *expander;
2135 expander = gtk_expander_new (_("Technical Details"));
2137 txt = g_strdup_printf ("<i>%s</i>", details);
2139 label = gtk_label_new (NULL);
2140 gtk_label_set_markup (GTK_LABEL (label), txt);
2141 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2142 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2145 gtk_container_add (GTK_CONTAINER (expander), label);
2146 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2149 g_signal_connect (info_bar, "response",
2150 G_CALLBACK (gtk_widget_destroy), NULL);
2152 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2153 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2154 gtk_widget_show_all (info_bar);
2158 media_stream_error_to_txt (EmpathyCallWindow *self,
2159 TpyCallChannel *call,
2161 TpMediaStreamError error)
2163 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2164 const gchar *cm = NULL;
2170 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2172 return g_strdup_printf (
2173 _("%s's software does not understand any of the audio formats "
2174 "supported by your computer"),
2175 empathy_contact_get_alias (priv->contact));
2177 return g_strdup_printf (
2178 _("%s's software does not understand any of the video formats "
2179 "supported by your computer"),
2180 empathy_contact_get_alias (priv->contact));
2182 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2183 return g_strdup_printf (
2184 _("Can't establish a connection to %s. "
2185 "One of you might be on a network that does not allow "
2186 "direct connections."),
2187 empathy_contact_get_alias (priv->contact));
2189 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2190 return g_strdup (_("There was a failure on the network"));
2192 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2194 return g_strdup (_("The audio formats necessary for this call "
2195 "are not installed on your computer"));
2197 return g_strdup (_("The video formats necessary for this call "
2198 "are not installed on your computer"));
2200 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2201 tp_connection_parse_object_path (
2202 tp_channel_borrow_connection (TP_CHANNEL (call)),
2205 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2206 "product=Telepathy&component=%s", cm);
2208 result = g_strdup_printf (
2209 _("Something unexpected happened in a Telepathy component. "
2210 "Please <a href=\"%s\">report this bug</a> and attach "
2211 "logs gathered from the 'Debug' window in the Help menu."), url);
2217 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2218 return g_strdup (_("There was a failure in the call engine"));
2220 case TP_MEDIA_STREAM_ERROR_EOS:
2221 return g_strdup (_("The end of the stream was reached"));
2223 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2230 empathy_call_window_stream_error (EmpathyCallWindow *self,
2231 TpyCallChannel *call,
2240 desc = media_stream_error_to_txt (self, call, audio, code);
2243 /* No description, use the error message. That's not great as it's not
2244 * localized but it's better than nothing. */
2245 display_error (self, call, icon, title, msg, NULL);
2249 display_error (self, call, icon, title, desc, msg);
2255 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2258 EmpathyCallWindow *self)
2260 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2261 "gnome-stock-mic", _("Can't establish audio stream"));
2265 empathy_call_window_video_stream_error (TpyCallChannel *call,
2268 EmpathyCallWindow *self)
2270 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2271 "camera-web", _("Can't establish video stream"));
2276 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2278 EmpathyCallWindow *self)
2280 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2281 TpyCallChannel *call;
2282 gboolean can_send_video;
2284 if (state != TPY_CALL_STATE_ACCEPTED)
2287 if (priv->call_state == CONNECTED)
2290 g_timer_start (priv->timer);
2291 priv->call_state = CONNECTED;
2293 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2295 can_send_video = priv->video_input != NULL &&
2296 empathy_contact_can_voip_video (priv->contact) &&
2297 empathy_camera_monitor_get_available (priv->camera_monitor);
2299 g_object_get (priv->handler, "call-channel", &call, NULL);
2301 if (tpy_call_channel_has_dtmf (call))
2302 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2304 if (priv->video_input == NULL)
2305 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2307 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2309 empathy_call_window_show_hangup_button (self, TRUE);
2311 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2313 clutter_actor_hide (priv->video_output);
2314 gtk_widget_show (priv->remote_user_avatar_widget);
2316 g_object_unref (call);
2318 g_mutex_lock (priv->lock);
2320 priv->timer_id = g_timeout_add_seconds (1,
2321 empathy_call_window_update_timer, self);
2323 g_mutex_unlock (priv->lock);
2325 empathy_call_window_update_timer (self);
2327 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2331 empathy_call_window_show_video_output_cb (gpointer user_data)
2333 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2335 if (self->priv->video_output != NULL)
2337 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2338 clutter_actor_show (self->priv->video_output);
2339 clutter_actor_raise_top (self->priv->floating_toolbar);
2346 empathy_call_window_check_video_cb (gpointer data)
2348 EmpathyCallWindow *self = data;
2350 if (self->priv->got_video)
2352 self->priv->got_video = FALSE;
2356 /* No video in the last N seconds, display the remote avatar */
2357 empathy_call_window_show_video_output (self, FALSE);
2362 /* Called from the streaming thread */
2364 empathy_call_window_video_probe_cb (GstPad *pad,
2365 GstMiniObject *mini_obj,
2366 EmpathyCallWindow *self)
2369 if (GST_IS_EVENT (mini_obj))
2372 if (G_UNLIKELY (!self->priv->got_video))
2374 /* show the remote video */
2375 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2376 empathy_call_window_show_video_output_cb,
2377 g_object_ref (self), g_object_unref);
2379 self->priv->got_video = TRUE;
2385 /* Called from the streaming thread */
2387 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2388 GstPad *src, guint media_type, gpointer user_data)
2390 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2391 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2392 gboolean retval = FALSE;
2396 g_mutex_lock (priv->lock);
2400 case TP_MEDIA_STREAM_TYPE_AUDIO:
2401 pad = empathy_call_window_get_audio_sink_pad (self);
2403 case TP_MEDIA_STREAM_TYPE_VIDEO:
2404 g_idle_add (empathy_call_window_show_video_output_cb, self);
2405 pad = empathy_call_window_get_video_sink_pad (self);
2407 gst_pad_add_data_probe (src,
2408 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2409 if (priv->got_video_src > 0)
2410 g_source_remove (priv->got_video_src);
2411 priv->got_video_src = g_timeout_add_seconds (5,
2412 empathy_call_window_check_video_cb, self);
2415 g_assert_not_reached ();
2421 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2422 g_warning ("Could not link %s sink pad",
2423 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2427 gst_object_unref (pad);
2431 /* If no sink could be linked, try to add fakesink to prevent the whole call
2436 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2438 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2440 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2441 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2442 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2444 gst_element_set_locked_state (fakesink, TRUE);
2445 gst_element_set_state (fakesink, GST_STATE_NULL);
2446 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2450 DEBUG ("Could not link real sink, linked fakesink instead");
2452 gst_object_unref (sinkpad);
2456 gst_object_unref (fakesink);
2461 g_mutex_unlock (priv->lock);
2467 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2468 GstPad *sink, FsMediaType media_type, gpointer user_data)
2470 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2471 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2473 gboolean retval = FALSE;
2477 case FS_MEDIA_TYPE_AUDIO:
2478 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2480 g_warning ("Could not add audio source to pipeline");
2484 pad = gst_element_get_static_pad (priv->audio_input, "src");
2487 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2488 g_warning ("Could not get source pad from audio source");
2492 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2494 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2495 g_warning ("Could not link audio source to farsight");
2499 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2501 g_warning ("Could not start audio source");
2502 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2503 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2509 case FS_MEDIA_TYPE_VIDEO:
2510 if (priv->video_tee != NULL)
2512 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2513 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2515 g_warning ("Could not link video source input pipeline");
2518 gst_object_unref (pad);
2524 g_assert_not_reached ();
2531 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2533 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2534 GstElement *preview;
2536 disable_camera (self);
2538 DEBUG ("remove video input");
2539 preview = priv->video_preview_sink;
2541 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2542 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2543 gst_element_set_state (preview, GST_STATE_NULL);
2545 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2548 g_object_unref (priv->video_input);
2549 priv->video_input = NULL;
2550 g_object_unref (priv->video_tee);
2551 priv->video_tee = NULL;
2552 clutter_actor_destroy (priv->video_preview);
2553 priv->video_preview = NULL;
2555 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2559 start_call (EmpathyCallWindow *self)
2561 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2563 priv->call_started = TRUE;
2564 empathy_call_handler_start_call (priv->handler,
2565 gtk_get_current_event_time ());
2567 if (empathy_call_handler_has_initial_video (priv->handler))
2569 TpyCallChannel *call;
2572 g_object_get (priv->handler, "call-channel", &call, NULL);
2573 s = tpy_call_channel_get_video_state (call);
2575 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2576 s == TPY_SENDING_STATE_SENDING)
2578 /* Enable 'send video' buttons and display the preview */
2579 gtk_toggle_tool_button_set_active (
2580 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2584 gtk_toggle_tool_button_set_active (
2585 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2587 if (priv->video_preview == NULL)
2589 create_video_preview (self);
2590 add_video_preview_to_pipeline (self);
2594 g_object_unref (call);
2599 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2602 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2603 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2606 empathy_call_handler_bus_message (priv->handler, bus, message);
2608 switch (GST_MESSAGE_TYPE (message))
2610 case GST_MESSAGE_STATE_CHANGED:
2611 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2613 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2615 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2616 !priv->call_started)
2618 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2619 if (newstate == GST_STATE_PAUSED)
2621 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2622 priv->pipeline_playing = TRUE;
2624 if (priv->start_call_when_playing)
2629 case GST_MESSAGE_ERROR:
2631 GError *error = NULL;
2632 GstElement *gst_error;
2635 gst_message_parse_error (message, &error, &debug);
2636 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2638 g_message ("Element error: %s -- %s\n", error->message, debug);
2640 if (g_str_has_prefix (gst_element_get_name (gst_error),
2641 VIDEO_INPUT_ERROR_PREFIX))
2643 /* Remove the video input and continue */
2644 if (priv->video_input != NULL)
2645 empathy_call_window_remove_video_input (self);
2646 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2650 empathy_call_window_disconnected (self, TRUE);
2652 g_error_free (error);
2655 case GST_MESSAGE_UNKNOWN:
2656 case GST_MESSAGE_EOS:
2657 case GST_MESSAGE_WARNING:
2658 case GST_MESSAGE_INFO:
2659 case GST_MESSAGE_TAG:
2660 case GST_MESSAGE_BUFFERING:
2661 case GST_MESSAGE_STATE_DIRTY:
2662 case GST_MESSAGE_STEP_DONE:
2663 case GST_MESSAGE_CLOCK_PROVIDE:
2664 case GST_MESSAGE_CLOCK_LOST:
2665 case GST_MESSAGE_NEW_CLOCK:
2666 case GST_MESSAGE_STRUCTURE_CHANGE:
2667 case GST_MESSAGE_STREAM_STATUS:
2668 case GST_MESSAGE_APPLICATION:
2669 case GST_MESSAGE_ELEMENT:
2670 case GST_MESSAGE_SEGMENT_START:
2671 case GST_MESSAGE_SEGMENT_DONE:
2672 case GST_MESSAGE_DURATION:
2673 case GST_MESSAGE_ANY:
2682 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2683 GHashTable *members,
2684 EmpathyCallWindow *self)
2686 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2687 GHashTableIter iter;
2688 gpointer key, value;
2689 gboolean held = FALSE;
2691 g_hash_table_iter_init (&iter, members);
2692 while (g_hash_table_iter_next (&iter, &key, &value))
2694 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2696 /* This assumes this is a 1-1 call, otherwise one participant
2697 * putting the call on hold wouldn't mean the call is on hold
2705 priv->call_state = HELD;
2706 else if (priv->call_state == HELD)
2707 priv->call_state = CONNECTED;
2711 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2713 EmpathyCallWindow *self)
2715 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2716 TpyCallChannel *call;
2718 g_object_get (priv->handler, "call-channel", &call, NULL);
2723 tp_g_signal_connect_object (call, "audio-stream-error",
2724 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2725 tp_g_signal_connect_object (call, "video-stream-error",
2726 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2729 tp_g_signal_connect_object (call, "members-changed",
2730 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2732 g_object_unref (call);
2736 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2738 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2739 TpyCallChannel *call;
2742 /* Make the hangup button twice as wide */
2743 width = gtk_widget_get_allocated_width (priv->hangup_button);
2744 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2746 g_signal_connect (priv->handler, "state-changed",
2747 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2748 g_signal_connect (priv->handler, "conference-added",
2749 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2750 g_signal_connect (priv->handler, "conference-removed",
2751 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2752 g_signal_connect (priv->handler, "closed",
2753 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2754 g_signal_connect (priv->handler, "src-pad-added",
2755 G_CALLBACK (empathy_call_window_src_added_cb), window);
2756 g_signal_connect (priv->handler, "sink-pad-added",
2757 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2758 g_signal_connect (priv->handler, "sink-pad-removed",
2759 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2761 g_object_get (priv->handler, "call-channel", &call, NULL);
2764 call_handler_notify_call_cb (priv->handler, NULL, window);
2765 g_object_unref (call);
2769 /* call-channel doesn't exist yet, we'll connect signals once it has been
2771 g_signal_connect (priv->handler, "notify::call-channel",
2772 G_CALLBACK (call_handler_notify_call_cb), window);
2775 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2779 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2780 EmpathyCallWindow *window)
2782 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2784 if (priv->pipeline != NULL)
2786 if (priv->bus_message_source_id != 0)
2788 g_source_remove (priv->bus_message_source_id);
2789 priv->bus_message_source_id = 0;
2792 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2795 if (priv->call_state == CONNECTING)
2796 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2802 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2805 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2807 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2812 gtk_widget_hide (priv->dtmf_panel);
2813 gtk_widget_hide (menu);
2814 gtk_widget_hide (priv->toolbar);
2818 if (priv->dialpad_was_visible_before_fs)
2819 gtk_widget_show (priv->dtmf_panel);
2821 gtk_widget_show (menu);
2822 gtk_widget_show (priv->toolbar);
2824 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2825 priv->original_height_before_fs);
2830 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2832 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2834 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2835 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2836 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2837 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2839 if (priv->video_output != NULL)
2842 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2843 priv->video_output, TRUE, TRUE,
2844 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2851 empathy_call_window_state_event_cb (GtkWidget *widget,
2852 GdkEventWindowState *event, EmpathyCallWindow *window)
2854 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2856 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2857 gboolean set_fullscreen = event->new_window_state &
2858 GDK_WINDOW_STATE_FULLSCREEN;
2862 gboolean dialpad_was_visible;
2863 GtkAllocation allocation;
2864 gint original_width, original_height;
2866 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2867 original_width = allocation.width;
2868 original_height = allocation.height;
2870 g_object_get (priv->dtmf_panel,
2871 "visible", &dialpad_was_visible,
2874 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2875 priv->original_width_before_fs = original_width;
2876 priv->original_height_before_fs = original_height;
2878 if (priv->video_output_motion_handler_id == 0 &&
2879 priv->video_output != NULL)
2881 priv->video_output_motion_handler_id = g_signal_connect (
2882 G_OBJECT (priv->video_container), "motion-notify-event",
2883 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2889 disconnect_video_output_motion_handler (window);
2892 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2894 show_controls (window, set_fullscreen);
2895 show_borders (window, set_fullscreen);
2896 gtk_action_set_stock_id (priv->menu_fullscreen,
2897 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2898 priv->is_fullscreen = set_fullscreen;
2905 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2908 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2909 int w, h, dialpad_width;
2910 GtkAllocation allocation;
2912 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2913 w = allocation.width;
2914 h = allocation.height;
2916 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2920 gtk_widget_show (priv->dtmf_panel);
2926 gtk_widget_hide (priv->dtmf_panel);
2930 gtk_window_resize (GTK_WINDOW (window), w, h);
2934 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2937 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2938 TpyCallChannel *call;
2940 priv->sending_video = (state == CAMERA_STATE_ON);
2942 if (state == CAMERA_STATE_ON)
2944 /* When we start sending video, we want to show the video preview by
2946 display_video_preview (window, TRUE);
2950 display_video_preview (window, FALSE);
2953 if (priv->call_state != CONNECTED)
2956 g_object_get (priv->handler, "call-channel", &call, NULL);
2957 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2958 tpy_call_channel_send_video (call, priv->sending_video);
2959 g_object_unref (call);
2963 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2964 EmpathyCallWindow *window)
2966 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2969 active = (gtk_toggle_tool_button_get_active (toggle));
2973 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2974 priv->volume * 100);
2978 /* TODO, Instead of setting the input volume to 0 we should probably
2979 * stop sending but this would cause the audio call to drop if both
2980 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2981 * in the future. GNOME #574574
2983 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2989 empathy_call_window_hangup_cb (gpointer object,
2990 EmpathyCallWindow *self)
2992 empathy_call_handler_stop_call (self->priv->handler);
2994 empathy_call_window_disconnected (self, TRUE);
2998 empathy_call_window_restart_call (EmpathyCallWindow *window)
3000 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3002 /* Remove error info bars */
3003 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3004 (GtkCallback) gtk_widget_destroy, NULL);
3006 create_video_output_widget (window);
3008 /* While the call was disconnected, the input volume might have changed.
3009 * However, since the audio_input source was destroyed, its volume has not
3010 * been updated during that time. That's why we manually update it here */
3011 empathy_call_window_mic_volume_changed (window);
3013 priv->outgoing = TRUE;
3014 empathy_call_window_set_state_connecting (window);
3016 if (priv->pipeline_playing)
3017 start_call (window);
3019 /* call will be started when the pipeline is ready */
3020 priv->start_call_when_playing = TRUE;
3022 empathy_call_window_setup_avatars (window, priv->handler);
3024 empathy_call_window_show_hangup_button (window, TRUE);
3028 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3029 EmpathyCallWindow *window)
3033 active = gtk_toggle_tool_button_get_active (button);
3035 empathy_call_window_show_dialpad (window, active);
3039 empathy_call_window_fullscreen_cb (gpointer object,
3040 EmpathyCallWindow *window)
3042 empathy_call_window_fullscreen_toggle (window);
3046 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3048 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3050 if (priv->is_fullscreen)
3051 gtk_window_unfullscreen (GTK_WINDOW (window));
3053 gtk_window_fullscreen (GTK_WINDOW (window));
3057 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3058 GdkEventButton *event, EmpathyCallWindow *window)
3060 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3062 empathy_call_window_video_menu_popup (window, event->button);
3070 empathy_call_window_key_press_cb (GtkWidget *video_output,
3071 GdkEventKey *event, EmpathyCallWindow *window)
3073 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3075 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3077 /* Since we are in fullscreen mode, toggling will bring us back to
3079 empathy_call_window_fullscreen_toggle (window);
3087 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3088 GdkEventMotion *event, EmpathyCallWindow *window)
3090 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3092 if (priv->is_fullscreen)
3094 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3101 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3105 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3107 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3109 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3110 button, gtk_get_current_event_time ());
3111 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3115 empathy_call_window_status_message (EmpathyCallWindow *self,
3118 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3122 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3123 gdouble value, EmpathyCallWindow *window)
3125 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3127 if (priv->audio_output == NULL)
3130 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3135 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3137 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3139 return priv->ui_manager;
3142 EmpathyGstAudioSrc *
3143 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3145 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3147 return (EmpathyGstAudioSrc *) priv->audio_input;