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 #define SELF_VIDEO_MARGIN 10
84 /* The avatar's default width and height are set to the same value because we
85 want a square icon. */
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
88 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
101 PROP_CALL_HANDLER = 1,
113 CAMERA_STATE_OFF = 0,
119 PREVIEW_POS_TOP_LEFT,
120 PREVIEW_POS_TOP_RIGHT,
121 PREVIEW_POS_BOTTOM_LEFT,
122 PREVIEW_POS_BOTTOM_RIGHT,
125 struct _EmpathyCallWindowPriv
127 gboolean dispose_has_run;
128 EmpathyCallHandler *handler;
130 EmpathyContact *contact;
132 EmpathyCameraMonitor *camera_monitor;
137 GtkUIManager *ui_manager;
138 GtkWidget *errors_vbox;
139 /* widget displays the video received from the remote user. This widget is
140 * alive only during call. */
141 ClutterActor *video_output;
142 ClutterActor *video_preview;
143 ClutterActor *preview_hidden_button;
144 ClutterActor *preview_rectangle1;
145 ClutterActor *preview_rectangle2;
146 ClutterActor *preview_rectangle3;
147 ClutterActor *preview_rectangle4;
148 GtkWidget *video_container;
149 GtkWidget *remote_user_avatar_widget;
150 GtkWidget *remote_user_avatar_toolbar;
151 GtkWidget *remote_user_name_toolbar;
152 GtkWidget *status_label;
153 GtkWidget *hangup_button;
154 GtkWidget *audio_call_button;
155 GtkWidget *video_call_button;
156 GtkWidget *mic_button;
157 GtkWidget *camera_button;
158 GtkWidget *dialpad_button;
160 GtkWidget *bottom_toolbar;
161 ClutterActor *floating_toolbar;
163 GtkAction *menu_fullscreen;
165 ClutterState *transitions;
167 /* The box that contains self and remote avatar and video
168 input/output. When we redial, we destroy and re-create the box */
169 ClutterActor *video_box;
170 ClutterLayoutManager *video_layout;
172 /* Coordinates of the preview drag event's start. */
173 PreviewPosition preview_pos;
177 /* We keep a reference on the hbox which contains the main content so we can
178 easilly repack everything when toggling fullscreen */
179 GtkWidget *content_hbox;
181 gulong video_output_motion_handler_id;
182 guint bus_message_source_id;
186 GtkWidget *dtmf_panel;
189 GtkWidget *details_vbox;
190 GtkWidget *vcodec_encoding_label;
191 GtkWidget *acodec_encoding_label;
192 GtkWidget *vcodec_decoding_label;
193 GtkWidget *acodec_decoding_label;
195 GtkWidget *audio_remote_candidate_label;
196 GtkWidget *audio_local_candidate_label;
197 GtkWidget *video_remote_candidate_label;
198 GtkWidget *video_local_candidate_label;
199 GtkWidget *video_remote_candidate_info_img;
200 GtkWidget *video_local_candidate_info_img;
201 GtkWidget *audio_remote_candidate_info_img;
202 GtkWidget *audio_local_candidate_info_img;
204 GstElement *video_input;
205 GstElement *video_preview_sink;
206 GstElement *video_output_sink;
207 GstElement *audio_input;
208 GstElement *audio_output;
209 GstElement *pipeline;
210 GstElement *video_tee;
220 gboolean call_started;
221 gboolean sending_video;
222 CameraState camera_state;
224 EmpathyCallWindowFullscreen *fullscreen;
225 gboolean is_fullscreen;
230 guint inactivity_src;
232 /* Those fields represent the state of the window before it actually was in
234 gboolean dialpad_was_visible_before_fs;
235 gint original_width_before_fs;
236 gint original_height_before_fs;
238 gint x, y, w, h, dialpad_width;
241 /* TRUE if the call should be started when the pipeline is playing */
242 gboolean start_call_when_playing;
243 /* TRUE if we requested to set the pipeline in the playing state */
244 gboolean pipeline_playing;
246 EmpathySoundManager *sound_mgr;
249 EmpathyMicMenu *mic_menu;
252 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
254 static void empathy_call_window_realized_cb (GtkWidget *widget,
255 EmpathyCallWindow *window);
257 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
258 GdkEvent *event, EmpathyCallWindow *window);
260 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
261 GdkEventWindowState *event, EmpathyCallWindow *window);
263 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
266 static void empathy_call_window_mic_toggled_cb (
267 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
269 static void empathy_call_window_hangup_cb (gpointer object,
270 EmpathyCallWindow *window);
272 static void empathy_call_window_fullscreen_cb (gpointer object,
273 EmpathyCallWindow *window);
275 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
277 static gboolean empathy_call_window_video_button_press_cb (
278 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
280 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
281 GdkEventKey *event, EmpathyCallWindow *window);
283 static gboolean empathy_call_window_video_output_motion_notify (
284 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
286 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
289 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
290 EmpathyCallWindow *window);
292 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
294 static void empathy_call_window_status_message (EmpathyCallWindow *window,
297 static gboolean empathy_call_window_bus_message (GstBus *bus,
298 GstMessage *message, gpointer user_data);
301 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
302 gdouble value, EmpathyCallWindow *window);
305 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
308 gtk_widget_set_visible (self->priv->hangup_button, show);
309 gtk_widget_set_visible (self->priv->audio_call_button, !show);
310 gtk_widget_set_visible (self->priv->video_call_button, !show);
314 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
315 EmpathyCallWindow *self)
317 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
318 empathy_call_window_restart_call (self);
322 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
323 EmpathyCallWindow *self)
325 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
326 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
327 empathy_call_window_restart_call (self);
331 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
333 EmpathyCallWindowPriv *priv = GET_PRIV (window);
334 TpyCallChannel *call;
338 g_object_get (priv->handler, "call-channel", &call, NULL);
340 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
341 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
344 tpy_call_channel_dtmf_start_tone (call, event);
346 g_object_unref (call);
350 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
352 EmpathyCallWindowPriv *priv = GET_PRIV (window);
353 TpyCallChannel *call;
355 g_object_get (priv->handler, "call-channel", &call, NULL);
357 tpy_call_channel_dtmf_stop_tone (call);
359 g_object_unref (call);
363 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
365 EmpathyCallWindowPriv *priv = GET_PRIV (self);
368 volume = g_settings_get_double (priv->settings,
369 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
371 /* Don't store the volume because of muting */
372 if (volume > 0 || gtk_toggle_tool_button_get_active (
373 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
374 priv->volume = volume;
376 /* Ensure that the toggle button is active if the volume is > 0 and inactive
377 * if it's smaller than 0 */
378 if ((volume > 0) != gtk_toggle_tool_button_get_active (
379 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
380 gtk_toggle_tool_button_set_active (
381 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
383 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
388 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
390 EmpathyCallWindow *self)
392 empathy_call_window_mic_volume_changed (self);
396 empathy_call_window_show_video_output (EmpathyCallWindow *self,
399 if (self->priv->video_output != NULL)
400 g_object_set (self->priv->video_output, "visible", show, NULL);
402 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
404 clutter_actor_raise_top (self->priv->floating_toolbar);
408 create_video_output_widget (EmpathyCallWindow *self)
410 EmpathyCallWindowPriv *priv = GET_PRIV (self);
412 g_assert (priv->video_output == NULL);
413 g_assert (priv->pipeline != NULL);
415 priv->video_output = clutter_texture_new ();
417 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
420 priv->video_output_sink = clutter_gst_video_sink_new (
421 CLUTTER_TEXTURE (priv->video_output));
423 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
426 gtk_widget_add_events (priv->video_container,
427 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
428 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
429 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
433 create_video_input (EmpathyCallWindow *self)
435 EmpathyCallWindowPriv *priv = GET_PRIV (self);
437 g_assert (priv->video_input == NULL);
438 priv->video_input = empathy_video_src_new ();
439 gst_object_ref (priv->video_input);
440 gst_object_sink (priv->video_input);
444 create_audio_input (EmpathyCallWindow *self)
446 EmpathyCallWindowPriv *priv = GET_PRIV (self);
448 g_assert (priv->audio_input == NULL);
449 priv->audio_input = empathy_audio_src_new ();
450 gst_object_ref (priv->audio_input);
451 gst_object_sink (priv->audio_input);
455 add_video_preview_to_pipeline (EmpathyCallWindow *self)
457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
460 g_assert (priv->video_preview != NULL);
461 g_assert (priv->pipeline != NULL);
462 g_assert (priv->video_input != NULL);
463 g_assert (priv->video_tee != NULL);
465 preview = priv->video_preview_sink;
467 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
469 g_warning ("Could not add video input to pipeline");
473 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
475 g_warning ("Could not add video preview to pipeline");
479 if (!gst_element_link (priv->video_input, priv->video_tee))
481 g_warning ("Could not link video input to video tee");
485 if (!gst_element_link (priv->video_tee, preview))
487 g_warning ("Could not link video tee to video preview");
493 empathy_call_window_disable_camera_cb (GtkAction *action,
494 EmpathyCallWindow *self)
496 clutter_actor_destroy (self->priv->preview_hidden_button);
498 gtk_toggle_tool_button_set_active (
499 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
503 empathy_call_window_minimise_camera_cb (GtkAction *action,
504 EmpathyCallWindow *self)
506 clutter_actor_hide (self->priv->video_preview);
507 clutter_actor_show (self->priv->preview_hidden_button);
511 empathy_call_window_maximise_camera_cb (GtkAction *action,
512 EmpathyCallWindow *self)
514 clutter_actor_show (self->priv->video_preview);
515 clutter_actor_hide (self->priv->preview_hidden_button);
519 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
520 EmpathyCallWindow *self)
524 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
526 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
527 0, gtk_get_current_event_time ());
528 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
532 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
533 EmpathyCallWindow *self)
537 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
538 "/preview-hidden-menu");
539 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
540 0, gtk_get_current_event_time ());
541 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
544 static ClutterActor *
545 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
546 ClutterBinAlignment x,
547 ClutterBinAlignment y)
549 ClutterLayoutManager *layout;
550 ClutterActor *rectangle;
553 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
554 CLUTTER_BIN_ALIGNMENT_CENTER);
556 box = clutter_box_new (layout);
558 rectangle = clutter_rectangle_new_with_color (
559 CLUTTER_COLOR_Transparent);
561 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
564 clutter_actor_set_size (box,
565 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_MARGIN,
566 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_MARGIN);
568 clutter_actor_set_size (rectangle,
569 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGTH + 5);
571 clutter_container_add_actor (CLUTTER_CONTAINER (box), rectangle);
573 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
576 clutter_actor_hide (rectangle);
582 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
584 self->priv->preview_rectangle1 =
585 empathy_call_window_create_preview_rectangle (self,
586 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
587 self->priv->preview_rectangle2 =
588 empathy_call_window_create_preview_rectangle (self,
589 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
590 self->priv->preview_rectangle3 =
591 empathy_call_window_create_preview_rectangle (self,
592 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
593 self->priv->preview_rectangle4 =
594 empathy_call_window_create_preview_rectangle (self,
595 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
599 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
602 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
603 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
604 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
605 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
608 static PreviewPosition
609 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
614 PreviewPosition pos = PREVIEW_POS_NONE;
616 clutter_actor_get_geometry (self->priv->video_box, &box);
618 if (0 + SELF_VIDEO_MARGIN <= event_x &&
619 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
620 0 + SELF_VIDEO_MARGIN <= event_y &&
621 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
623 pos = PREVIEW_POS_TOP_LEFT;
625 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
626 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
627 0 + SELF_VIDEO_MARGIN <= event_y &&
628 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
630 pos = PREVIEW_POS_TOP_RIGHT;
632 else if (0 + SELF_VIDEO_MARGIN <= event_x &&
633 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
634 box.height - SELF_VIDEO_MARGIN >= event_y &&
635 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
637 pos = PREVIEW_POS_BOTTOM_LEFT;
639 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
640 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
641 box.height - SELF_VIDEO_MARGIN >= event_y &&
642 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
644 pos = PREVIEW_POS_BOTTOM_RIGHT;
650 static ClutterActor *
651 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
654 ClutterActor *rectangle;
658 case PREVIEW_POS_TOP_LEFT:
659 rectangle = self->priv->preview_rectangle1;
661 case PREVIEW_POS_TOP_RIGHT:
662 rectangle = self->priv->preview_rectangle3;
664 case PREVIEW_POS_BOTTOM_LEFT:
665 rectangle = self->priv->preview_rectangle2;
667 case PREVIEW_POS_BOTTOM_RIGHT:
668 rectangle = self->priv->preview_rectangle4;
678 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
681 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
683 DEBUG ("moving the video preview to %d", pos);
685 self->priv->preview_pos = pos;
689 case PREVIEW_POS_TOP_LEFT:
690 clutter_bin_layout_set_alignment (layout,
691 self->priv->video_preview,
692 CLUTTER_BIN_ALIGNMENT_START,
693 CLUTTER_BIN_ALIGNMENT_START);
695 case PREVIEW_POS_TOP_RIGHT:
696 clutter_bin_layout_set_alignment (layout,
697 self->priv->video_preview,
698 CLUTTER_BIN_ALIGNMENT_END,
699 CLUTTER_BIN_ALIGNMENT_START);
701 case PREVIEW_POS_BOTTOM_LEFT:
702 clutter_bin_layout_set_alignment (layout,
703 self->priv->video_preview,
704 CLUTTER_BIN_ALIGNMENT_START,
705 CLUTTER_BIN_ALIGNMENT_END);
707 case PREVIEW_POS_BOTTOM_RIGHT:
708 clutter_bin_layout_set_alignment (layout,
709 self->priv->video_preview,
710 CLUTTER_BIN_ALIGNMENT_END,
711 CLUTTER_BIN_ALIGNMENT_END);
714 g_warn_if_reached ();
719 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
722 ClutterActor *rectangle;
724 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
726 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
727 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
732 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
733 ClutterActor *rectangle)
735 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
736 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
737 CLUTTER_COLOR_Black);
741 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
743 ClutterActor *rectangle;
745 rectangle = empathy_call_window_get_preview_rectangle (self,
746 self->priv->preview_pos);
748 /* We don't want to darken the rectangle where the preview
751 if (self->priv->preview_rectangle1 != rectangle)
752 empathy_call_window_darken_preview_rectangle (self,
753 self->priv->preview_rectangle1);
755 if (self->priv->preview_rectangle2 != rectangle)
756 empathy_call_window_darken_preview_rectangle (self,
757 self->priv->preview_rectangle2);
759 if (self->priv->preview_rectangle3 != rectangle)
760 empathy_call_window_darken_preview_rectangle (self,
761 self->priv->preview_rectangle3);
763 if (self->priv->preview_rectangle4 != rectangle)
764 empathy_call_window_darken_preview_rectangle (self,
765 self->priv->preview_rectangle4);
769 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
773 ClutterModifierType modifiers,
774 EmpathyCallWindow *self)
776 empathy_call_window_show_preview_rectangles (self, TRUE);
777 empathy_call_window_darken_preview_rectangles (self);
779 self->priv->event_x = event_x;
780 self->priv->event_y = event_y;
784 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
788 ClutterModifierType modifiers,
789 EmpathyCallWindow *self)
793 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
795 if (pos != PREVIEW_POS_NONE)
796 empathy_call_window_move_video_preview (self, pos);
798 empathy_call_window_show_preview_rectangles (self, FALSE);
802 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
806 EmpathyCallWindow *self)
810 pos = empathy_call_window_get_preview_position (self,
811 self->priv->event_x - delta_x, self->priv->event_y + delta_y);
813 if (pos != PREVIEW_POS_NONE)
814 empathy_call_window_highlight_preview_rectangle (self, pos);
816 empathy_call_window_darken_preview_rectangles (self);
820 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
821 ClutterCrossingEvent *event,
822 EmpathyCallWindow *self)
824 ClutterActor *rectangle;
827 pos = empathy_call_window_get_preview_position (self, event->x, event->y);
828 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
830 empathy_call_window_highlight_preview_rectangle (self, pos);
832 clutter_actor_show (rectangle);
838 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
839 ClutterCrossingEvent *event,
840 EmpathyCallWindow *self)
842 ClutterActor *rectangle;
845 pos = empathy_call_window_get_preview_position (self, event->x, event->y);
846 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
848 empathy_call_window_darken_preview_rectangle (self, rectangle);
850 clutter_actor_hide (rectangle);
856 create_video_preview (EmpathyCallWindow *self)
858 EmpathyCallWindowPriv *priv = GET_PRIV (self);
859 ClutterLayoutManager *layout, *layout_center;
860 ClutterActor *preview;
863 ClutterAction *action;
866 g_assert (priv->video_preview == NULL);
868 preview = clutter_texture_new ();
869 clutter_actor_set_size (preview,
870 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
871 priv->video_preview_sink = clutter_gst_video_sink_new (
872 CLUTTER_TEXTURE (preview));
874 /* Flip the video preview */
875 clutter_actor_set_rotation (preview,
878 SELF_VIDEO_SECTION_WIDTH * 0.5,
882 /* Add a little offset to the video preview */
883 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
884 CLUTTER_BIN_ALIGNMENT_CENTER);
885 priv->video_preview = clutter_box_new (layout);
886 clutter_actor_set_size (priv->video_preview,
887 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
888 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
889 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
891 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
892 CLUTTER_BIN_ALIGNMENT_CENTER);
893 box = clutter_box_new (layout_center);
894 clutter_actor_set_size (box,
895 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
897 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
898 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
900 g_object_set (priv->video_preview_sink,
905 /* Translators: this is an "Info" label. It should be as short
907 button = gtk_button_new_with_label (_("i"));
908 b = gtk_clutter_actor_new_with_contents (button);
910 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
912 CLUTTER_BIN_ALIGNMENT_END,
913 CLUTTER_BIN_ALIGNMENT_END);
915 g_signal_connect (button, "clicked",
916 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
919 /* Translators: this is an "Info" label. It should be as short
921 button = gtk_button_new_with_label (_("i"));
922 priv->preview_hidden_button =
923 gtk_clutter_actor_new_with_contents (button);
925 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
926 priv->preview_hidden_button,
927 CLUTTER_BIN_ALIGNMENT_START,
928 CLUTTER_BIN_ALIGNMENT_END);
930 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
932 clutter_actor_hide (priv->preview_hidden_button);
934 g_signal_connect (button, "clicked",
935 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
938 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
940 CLUTTER_BIN_ALIGNMENT_START,
941 CLUTTER_BIN_ALIGNMENT_END);
943 action = clutter_drag_action_new ();
944 g_signal_connect (action, "drag-begin",
945 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
946 g_signal_connect (action, "drag-end",
947 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
948 g_signal_connect (action, "drag-motion",
949 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
951 g_signal_connect (preview, "enter-event",
952 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
953 g_signal_connect (preview, "leave-event",
954 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
956 clutter_actor_add_action (preview, action);
957 clutter_actor_set_reactive (preview, TRUE);
961 play_camera (EmpathyCallWindow *window,
964 EmpathyCallWindowPriv *priv = GET_PRIV (window);
968 if (priv->video_preview == NULL)
970 create_video_preview (window);
971 add_video_preview_to_pipeline (window);
975 state = GST_STATE_PLAYING;
977 state = GST_STATE_NULL;
979 preview = priv->video_preview_sink;
981 gst_element_set_state (preview, state);
982 gst_element_set_state (priv->video_input, state);
983 gst_element_set_state (priv->video_tee, state);
987 display_video_preview (EmpathyCallWindow *self,
990 EmpathyCallWindowPriv *priv = GET_PRIV (self);
994 /* Display the video preview */
995 DEBUG ("Show video preview");
997 play_camera (self, TRUE);
998 clutter_actor_show (priv->video_preview);
999 clutter_actor_raise_top (priv->floating_toolbar);
1003 /* Hide the video preview */
1004 DEBUG ("Hide video preview");
1006 if (priv->video_preview != NULL)
1008 clutter_actor_hide (priv->video_preview);
1009 play_camera (self, FALSE);
1015 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1017 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1019 empathy_call_window_status_message (window, _("Connecting…"));
1020 priv->call_state = CONNECTING;
1023 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1024 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1028 disable_camera (EmpathyCallWindow *self)
1030 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1032 if (priv->camera_state == CAMERA_STATE_OFF)
1035 DEBUG ("Disable camera");
1037 display_video_preview (self, FALSE);
1039 if (priv->camera_state == CAMERA_STATE_ON)
1040 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1042 priv->camera_state = CAMERA_STATE_OFF;
1046 enable_camera (EmpathyCallWindow *self)
1048 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1050 if (priv->camera_state == CAMERA_STATE_ON)
1053 if (priv->video_input == NULL)
1055 DEBUG ("Can't enable camera, no input");
1059 DEBUG ("Enable camera");
1061 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1063 priv->camera_state = CAMERA_STATE_ON;
1067 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1068 EmpathyCallWindow *self)
1070 if (gtk_toggle_tool_button_get_active (toggle))
1071 enable_camera (self);
1073 disable_camera (self);
1077 create_pipeline (EmpathyCallWindow *self)
1079 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1082 g_assert (priv->pipeline == NULL);
1084 priv->pipeline = gst_pipeline_new (NULL);
1085 priv->pipeline_playing = FALSE;
1087 priv->video_tee = gst_element_factory_make ("tee", NULL);
1088 gst_object_ref (priv->video_tee);
1089 gst_object_sink (priv->video_tee);
1091 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1093 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1094 priv->bus_message_source_id = gst_bus_add_watch (bus,
1095 empathy_call_window_bus_message, self);
1097 g_object_unref (bus);
1101 empathy_call_window_settings_cb (GtkAction *action,
1102 EmpathyCallWindow *self)
1104 gchar *args = g_strdup_printf ("-p %s",
1105 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1107 empathy_launch_program (BIN_DIR, "empathy", args);
1113 empathy_call_window_contents_cb (GtkAction *action,
1114 EmpathyCallWindow *self)
1116 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1120 empathy_call_window_debug_cb (GtkAction *action,
1121 EmpathyCallWindow *self)
1123 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1127 empathy_call_window_about_cb (GtkAction *action,
1128 EmpathyCallWindow *self)
1130 empathy_about_dialog_new (GTK_WINDOW (self));
1134 empathy_call_window_toolbar_timeout (gpointer data)
1136 EmpathyCallWindow *self = data;
1138 clutter_state_set_state (self->priv->transitions, "fade-out");
1144 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1146 EmpathyCallWindow *self)
1148 clutter_state_set_state (self->priv->transitions, "fade-in");
1150 if (self->priv->inactivity_src > 0)
1151 g_source_remove (self->priv->inactivity_src);
1153 self->priv->inactivity_src = g_timeout_add_seconds (3,
1154 empathy_call_window_toolbar_timeout, self);
1160 empathy_call_window_configure_event_cb (GtkWidget *widget,
1162 EmpathyCallWindow *self)
1164 GdkWindow *gdk_window;
1165 GdkWindowState window_state;
1167 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1168 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1170 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1171 &self->priv->dialpad_width, NULL);
1173 gdk_window = gtk_widget_get_window (widget);
1174 window_state = gdk_window_get_state (gdk_window);
1175 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1181 empathy_call_window_destroyed_cb (GtkWidget *object,
1182 EmpathyCallWindow *self)
1184 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1186 /* Save the geometry as if the dialpad was hidden. */
1187 empathy_geometry_save_values (GTK_WINDOW (self),
1188 self->priv->x, self->priv->y,
1189 self->priv->w - self->priv->dialpad_width, self->priv->h,
1190 self->priv->maximized);
1195 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1197 ClutterBindConstraint *constraint)
1199 ClutterActorBox allocation;
1201 clutter_actor_get_allocation_box (stage, &allocation);
1203 clutter_bind_constraint_set_offset (constraint,
1204 allocation.y2 - allocation.y1 -
1205 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1209 empathy_call_window_init (EmpathyCallWindow *self)
1211 EmpathyCallWindowPriv *priv;
1213 GtkWidget *top_vbox;
1215 ClutterConstraint *constraint;
1216 ClutterActor *remote_avatar;
1217 GtkStyleContext *context;
1221 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1222 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1224 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1225 gui = empathy_builder_get_file (filename,
1226 "call_window_vbox", &top_vbox,
1227 "errors_vbox", &priv->errors_vbox,
1228 "pane", &priv->pane,
1229 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1230 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1231 "status_label", &priv->status_label,
1232 "audiocall", &priv->audio_call_button,
1233 "videocall", &priv->video_call_button,
1234 "microphone", &priv->mic_button,
1235 "camera", &priv->camera_button,
1236 "hangup", &priv->hangup_button,
1237 "dialpad", &priv->dialpad_button,
1238 "toolbar", &priv->toolbar,
1239 "bottom_toolbar", &priv->bottom_toolbar,
1240 "ui_manager", &priv->ui_manager,
1241 "menufullscreen", &priv->menu_fullscreen,
1242 "details_vbox", &priv->details_vbox,
1243 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1244 "acodec_encoding_label", &priv->acodec_encoding_label,
1245 "acodec_decoding_label", &priv->acodec_decoding_label,
1246 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1247 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1248 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1249 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1250 "video_local_candidate_label", &priv->video_local_candidate_label,
1251 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1252 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1253 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1254 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1258 empathy_builder_connect (gui, self,
1259 "hangup", "clicked", empathy_call_window_hangup_cb,
1260 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1261 "videocall", "clicked", empathy_call_window_video_call_cb,
1262 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1263 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1264 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1265 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1266 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1267 "menusettings", "activate", empathy_call_window_settings_cb,
1268 "menucontents", "activate", empathy_call_window_contents_cb,
1269 "menudebug", "activate", empathy_call_window_debug_cb,
1270 "menuabout", "activate", empathy_call_window_about_cb,
1271 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1272 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1273 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1276 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1278 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1280 g_object_bind_property (priv->camera_monitor, "available",
1281 priv->camera_button, "sensitive",
1282 G_BINDING_SYNC_CREATE);
1284 priv->lock = g_mutex_new ();
1286 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1288 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1289 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1290 CONTENT_HBOX_BORDER_WIDTH);
1291 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1294 /* avatar/video box */
1295 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1296 CLUTTER_BIN_ALIGNMENT_CENTER);
1298 priv->video_box = clutter_box_new (priv->video_layout);
1300 empathy_call_window_create_preview_rectangles (self);
1302 priv->video_container = gtk_clutter_embed_new ();
1304 /* Set the background color to that of the rest of the window */
1305 context = gtk_widget_get_style_context (priv->content_hbox);
1306 gtk_style_context_get_background_color (context,
1307 GTK_STATE_FLAG_NORMAL, &rgba);
1308 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1309 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1310 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1311 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1312 clutter_stage_set_color (
1313 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1314 GTK_CLUTTER_EMBED (priv->video_container))),
1317 clutter_container_add (
1318 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1319 GTK_CLUTTER_EMBED (priv->video_container))),
1323 constraint = clutter_bind_constraint_new (
1324 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1325 CLUTTER_BIND_SIZE, 0);
1326 clutter_actor_add_constraint (priv->video_box, constraint);
1328 priv->remote_user_avatar_widget = gtk_image_new ();
1329 remote_avatar = gtk_clutter_actor_new_with_contents (
1330 priv->remote_user_avatar_widget);
1332 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1335 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1336 priv->video_container, TRUE, TRUE,
1337 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1339 create_pipeline (self);
1340 create_video_output_widget (self);
1341 create_audio_input (self);
1342 create_video_input (self);
1344 priv->floating_toolbar = empathy_rounded_actor_new ();
1346 gtk_widget_reparent (priv->bottom_toolbar,
1347 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1349 constraint = clutter_bind_constraint_new (
1350 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1353 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1356 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1357 "notify::allocation",
1358 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1361 clutter_actor_set_size (priv->floating_toolbar,
1362 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1363 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1365 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1366 priv->floating_toolbar,
1367 CLUTTER_BIN_ALIGNMENT_CENTER,
1368 CLUTTER_BIN_ALIGNMENT_END);
1370 clutter_actor_raise_top (priv->floating_toolbar);
1372 /* Transitions for the floating toolbar */
1373 priv->transitions = clutter_state_new ();
1375 /* all transitions last for 2s */
1376 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1378 /* transition from any state to "fade-out" state */
1379 clutter_state_set (priv->transitions, NULL, "fade-out",
1380 priv->floating_toolbar,
1381 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1384 /* transition from any state to "fade-in" state */
1385 clutter_state_set (priv->transitions, NULL, "fade-in",
1386 priv->floating_toolbar,
1387 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1390 /* put the actor into the "fade-in" state with no animation */
1391 clutter_state_warp_to_state (priv->transitions, "fade-in");
1393 /* The call will be started as soon the pipeline is playing */
1394 priv->start_call_when_playing = TRUE;
1396 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1397 G_CALLBACK (dtmf_button_pressed_cb),
1398 G_CALLBACK (dtmf_button_released_cb));
1400 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1403 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1406 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1408 gtk_widget_show_all (top_vbox);
1410 gtk_widget_hide (priv->dtmf_panel);
1411 gtk_widget_hide (priv->details_vbox);
1413 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1415 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1416 priv->video_container);
1418 /* We hide the bottom toolbar after 3s of inactivity and show it
1419 * again on mouse movement */
1420 priv->inactivity_src = g_timeout_add_seconds (3,
1421 empathy_call_window_toolbar_timeout, self);
1423 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1424 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1426 g_signal_connect (G_OBJECT (self), "realize",
1427 G_CALLBACK (empathy_call_window_realized_cb), self);
1429 g_signal_connect (G_OBJECT (self), "delete-event",
1430 G_CALLBACK (empathy_call_window_delete_cb), self);
1432 g_signal_connect (G_OBJECT (self), "window-state-event",
1433 G_CALLBACK (empathy_call_window_state_event_cb), self);
1435 g_signal_connect (G_OBJECT (self), "key-press-event",
1436 G_CALLBACK (empathy_call_window_key_press_cb), self);
1438 g_signal_connect (self, "motion-notify-event",
1439 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1441 priv->timer = g_timer_new ();
1443 g_object_ref (priv->ui_manager);
1444 g_object_unref (gui);
1446 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1447 priv->mic_menu = empathy_mic_menu_new (self);
1449 empathy_call_window_show_hangup_button (self, TRUE);
1451 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1453 /* Retrieve initial volume */
1454 priv->volume = g_settings_get_double (priv->settings,
1455 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1457 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1458 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1460 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1461 /* These signals are used to track the window position and save it
1462 * when the window is destroyed. We need to do this as we don't want
1463 * the window geometry to be saved with the dialpad taken into account. */
1464 g_signal_connect (self, "destroy",
1465 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1466 g_signal_connect (self, "configure-event",
1467 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1468 g_signal_connect (self, "window-state-event",
1469 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1471 /* Don't display labels in both toolbars */
1472 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1475 /* Instead of specifying a width and a height, we specify only one size. That's
1476 because we want a square avatar icon. */
1478 init_contact_avatar_with_size (EmpathyContact *contact,
1479 GtkWidget *image_widget,
1482 GdkPixbuf *pixbuf_avatar = NULL;
1484 if (contact != NULL)
1486 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1490 if (pixbuf_avatar == NULL)
1492 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1493 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1496 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1498 if (pixbuf_avatar != NULL)
1499 g_object_unref (pixbuf_avatar);
1503 set_window_title (EmpathyCallWindow *self)
1505 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1508 if (priv->contact != NULL)
1510 /* translators: Call is a noun and %s is the contact name. This string
1511 * is used in the window title */
1512 tmp = g_strdup_printf (_("Call with %s"),
1513 empathy_contact_get_alias (priv->contact));
1514 gtk_window_set_title (GTK_WINDOW (self), tmp);
1519 g_warning ("Unknown remote contact!");
1524 set_remote_user_name (EmpathyCallWindow *self,
1525 EmpathyContact *contact)
1527 const gchar *alias = empathy_contact_get_alias (contact);
1528 const gchar *status = empathy_contact_get_status (contact);
1531 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1532 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1538 contact_name_changed_cb (EmpathyContact *contact,
1540 EmpathyCallWindow *self)
1542 set_window_title (self);
1543 set_remote_user_name (self, contact);
1547 contact_presence_changed_cb (EmpathyContact *contact,
1549 EmpathyCallWindow *self)
1551 set_remote_user_name (self, contact);
1555 contact_avatar_changed_cb (EmpathyContact *contact,
1557 EmpathyCallWindow *self)
1560 GtkAllocation allocation;
1561 GtkWidget *avatar_widget;
1563 avatar_widget = self->priv->remote_user_avatar_widget;
1565 gtk_widget_get_allocation (avatar_widget, &allocation);
1566 size = allocation.height;
1570 /* the widget is not allocated yet, set a default size */
1571 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1572 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1575 init_contact_avatar_with_size (contact, avatar_widget, size);
1577 avatar_widget = self->priv->remote_user_avatar_toolbar;
1579 gtk_widget_get_allocation (avatar_widget, &allocation);
1580 size = allocation.height;
1584 /* the widget is not allocated yet, set a default size */
1585 size = SMALL_TOOLBAR_SIZE;
1588 init_contact_avatar_with_size (contact, avatar_widget, size);
1592 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1593 EmpathyCallHandler *handler)
1595 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1597 tp_g_signal_connect_object (priv->contact, "notify::name",
1598 G_CALLBACK (contact_name_changed_cb), self, 0);
1599 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1600 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1601 tp_g_signal_connect_object (priv->contact, "notify::presence",
1602 G_CALLBACK (contact_presence_changed_cb), self, 0);
1604 set_window_title (self);
1605 set_remote_user_name (self, priv->contact);
1607 init_contact_avatar_with_size (priv->contact,
1608 priv->remote_user_avatar_widget,
1609 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1610 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1612 init_contact_avatar_with_size (priv->contact,
1613 priv->remote_user_avatar_toolbar,
1614 SMALL_TOOLBAR_SIZE);
1616 /* The remote avatar is shown by default and will be hidden when we receive
1617 video from the remote side. */
1618 clutter_actor_hide (priv->video_output);
1619 gtk_widget_show (priv->remote_user_avatar_widget);
1623 update_send_codec (EmpathyCallWindow *self,
1626 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1633 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1634 widget = priv->acodec_encoding_label;
1638 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1639 widget = priv->vcodec_encoding_label;
1645 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1646 gtk_label_set_text (GTK_LABEL (widget), tmp);
1651 send_audio_codec_notify_cb (GObject *object,
1655 EmpathyCallWindow *self = user_data;
1657 update_send_codec (self, TRUE);
1661 send_video_codec_notify_cb (GObject *object,
1665 EmpathyCallWindow *self = user_data;
1667 update_send_codec (self, FALSE);
1671 update_recv_codec (EmpathyCallWindow *self,
1674 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1677 GString *str = NULL;
1681 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1682 widget = priv->acodec_decoding_label;
1686 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1687 widget = priv->vcodec_decoding_label;
1693 for (l = codecs; l != NULL; l = g_list_next (l))
1695 FsCodec *codec = l->data;
1698 str = g_string_new (NULL);
1700 g_string_append (str, ", ");
1702 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1706 gtk_label_set_text (GTK_LABEL (widget), str->str);
1707 g_string_free (str, TRUE);
1711 recv_audio_codecs_notify_cb (GObject *object,
1715 EmpathyCallWindow *self = user_data;
1717 update_recv_codec (self, TRUE);
1721 recv_video_codecs_notify_cb (GObject *object,
1725 EmpathyCallWindow *self = user_data;
1727 update_recv_codec (self, FALSE);
1730 static const gchar *
1731 candidate_type_to_str (FsCandidate *candidate)
1733 switch (candidate->type)
1735 case FS_CANDIDATE_TYPE_HOST:
1737 case FS_CANDIDATE_TYPE_SRFLX:
1738 return "server reflexive";
1739 case FS_CANDIDATE_TYPE_PRFLX:
1740 return "peer reflexive";
1741 case FS_CANDIDATE_TYPE_RELAY:
1743 case FS_CANDIDATE_TYPE_MULTICAST:
1750 static const gchar *
1751 candidate_type_to_desc (FsCandidate *candidate)
1753 switch (candidate->type)
1755 case FS_CANDIDATE_TYPE_HOST:
1756 return _("The IP address as seen by the machine");
1757 case FS_CANDIDATE_TYPE_SRFLX:
1758 return _("The IP address as seen by a server on the Internet");
1759 case FS_CANDIDATE_TYPE_PRFLX:
1760 return _("The IP address of the peer as seen by the other side");
1761 case FS_CANDIDATE_TYPE_RELAY:
1762 return _("The IP address of a relay server");
1763 case FS_CANDIDATE_TYPE_MULTICAST:
1764 return _("The IP address of the multicast group");
1771 update_candidat_widget (EmpathyCallWindow *self,
1774 FsCandidate *candidate)
1778 g_assert (candidate != NULL);
1779 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1780 candidate->port, candidate_type_to_str (candidate));
1782 gtk_label_set_text (GTK_LABEL (label), str);
1783 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1789 candidates_changed_cb (GObject *object,
1791 EmpathyCallWindow *self)
1793 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1794 FsCandidate *candidate = NULL;
1796 if (type == FS_MEDIA_TYPE_VIDEO)
1798 /* Update remote candidate */
1799 candidate = empathy_call_handler_get_video_remote_candidate (
1802 update_candidat_widget (self, priv->video_remote_candidate_label,
1803 priv->video_remote_candidate_info_img, candidate);
1805 /* Update local candidate */
1806 candidate = empathy_call_handler_get_video_local_candidate (
1809 update_candidat_widget (self, priv->video_local_candidate_label,
1810 priv->video_local_candidate_info_img, candidate);
1814 /* Update remote candidate */
1815 candidate = empathy_call_handler_get_audio_remote_candidate (
1818 update_candidat_widget (self, priv->audio_remote_candidate_label,
1819 priv->audio_remote_candidate_info_img, candidate);
1821 /* Update local candidate */
1822 candidate = empathy_call_handler_get_audio_local_candidate (
1825 update_candidat_widget (self, priv->audio_local_candidate_label,
1826 priv->audio_local_candidate_info_img, candidate);
1831 empathy_call_window_constructed (GObject *object)
1833 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1834 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1835 TpyCallChannel *call;
1837 g_assert (priv->handler != NULL);
1839 g_object_get (priv->handler, "call-channel", &call, NULL);
1840 priv->outgoing = (call == NULL);
1842 g_object_unref (call);
1844 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1845 g_assert (priv->contact != NULL);
1847 empathy_call_window_setup_avatars (self, priv->handler);
1848 empathy_call_window_set_state_connecting (self);
1850 if (!empathy_call_handler_has_initial_video (priv->handler))
1852 gtk_toggle_tool_button_set_active (
1853 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1855 /* If call has InitialVideo, the preview will be started once the call has
1856 * been started (start_call()). */
1858 update_send_codec (self, TRUE);
1859 update_send_codec (self, FALSE);
1860 update_recv_codec (self, TRUE);
1861 update_recv_codec (self, FALSE);
1863 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1864 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1865 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1866 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1867 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1868 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1869 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1870 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1872 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1873 G_CALLBACK (candidates_changed_cb), self, 0);
1876 static void empathy_call_window_dispose (GObject *object);
1877 static void empathy_call_window_finalize (GObject *object);
1880 empathy_call_window_set_property (GObject *object,
1881 guint property_id, const GValue *value, GParamSpec *pspec)
1883 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1885 switch (property_id)
1887 case PROP_CALL_HANDLER:
1888 priv->handler = g_value_dup_object (value);
1891 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1896 empathy_call_window_get_property (GObject *object,
1897 guint property_id, GValue *value, GParamSpec *pspec)
1899 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1901 switch (property_id)
1903 case PROP_CALL_HANDLER:
1904 g_value_set_object (value, priv->handler);
1907 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1912 empathy_call_window_class_init (
1913 EmpathyCallWindowClass *empathy_call_window_class)
1915 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1916 GParamSpec *param_spec;
1918 g_type_class_add_private (empathy_call_window_class,
1919 sizeof (EmpathyCallWindowPriv));
1921 object_class->constructed = empathy_call_window_constructed;
1922 object_class->set_property = empathy_call_window_set_property;
1923 object_class->get_property = empathy_call_window_get_property;
1925 object_class->dispose = empathy_call_window_dispose;
1926 object_class->finalize = empathy_call_window_finalize;
1928 param_spec = g_param_spec_object ("handler",
1929 "handler", "The call handler",
1930 EMPATHY_TYPE_CALL_HANDLER,
1931 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1932 g_object_class_install_property (object_class,
1933 PROP_CALL_HANDLER, param_spec);
1937 empathy_call_window_dispose (GObject *object)
1939 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1940 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1942 if (priv->dispose_has_run)
1945 priv->dispose_has_run = TRUE;
1947 if (priv->handler != NULL)
1949 empathy_call_handler_stop_call (priv->handler);
1950 tp_clear_object (&priv->handler);
1953 if (priv->bus_message_source_id != 0)
1955 g_source_remove (priv->bus_message_source_id);
1956 priv->bus_message_source_id = 0;
1959 if (priv->got_video_src > 0)
1961 g_source_remove (priv->got_video_src);
1962 priv->got_video_src = 0;
1965 if (priv->inactivity_src > 0)
1967 g_source_remove (priv->inactivity_src);
1968 priv->inactivity_src = 0;
1971 tp_clear_object (&priv->pipeline);
1972 tp_clear_object (&priv->video_input);
1973 tp_clear_object (&priv->audio_input);
1974 tp_clear_object (&priv->video_tee);
1975 tp_clear_object (&priv->ui_manager);
1976 tp_clear_object (&priv->fullscreen);
1977 tp_clear_object (&priv->camera_monitor);
1978 tp_clear_object (&priv->settings);
1979 tp_clear_object (&priv->transitions);
1981 g_list_free_full (priv->notifiers, g_object_unref);
1983 if (priv->timer_id != 0)
1984 g_source_remove (priv->timer_id);
1987 if (priv->contact != NULL)
1989 g_signal_handlers_disconnect_by_func (priv->contact,
1990 contact_name_changed_cb, self);
1991 priv->contact = NULL;
1995 tp_clear_object (&priv->sound_mgr);
1997 tp_clear_object (&priv->mic_menu);
1999 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2003 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2005 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2007 if (priv->video_output_motion_handler_id != 0)
2009 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2010 priv->video_output_motion_handler_id);
2011 priv->video_output_motion_handler_id = 0;
2016 empathy_call_window_finalize (GObject *object)
2018 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2019 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2021 disconnect_video_output_motion_handler (self);
2023 /* free any data held directly by the object here */
2024 g_mutex_free (priv->lock);
2026 g_timer_destroy (priv->timer);
2028 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2033 empathy_call_window_new (EmpathyCallHandler *handler)
2035 return EMPATHY_CALL_WINDOW (
2036 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2040 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2041 GstElement *conference, gpointer user_data)
2043 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2044 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2045 FsElementAddedNotifier *notifier;
2048 DEBUG ("Conference added");
2050 /* Add notifier to set the various element properties as needed */
2051 notifier = fs_element_added_notifier_new ();
2052 keyfile = fs_utils_get_default_element_properties (conference);
2054 if (keyfile != NULL)
2055 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2057 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2059 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2061 gst_bin_add (GST_BIN (priv->pipeline), conference);
2062 gst_element_set_state (conference, GST_STATE_PLAYING);
2066 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2067 GstElement *conference, gpointer user_data)
2069 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2070 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2072 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2073 gst_element_set_state (conference, GST_STATE_NULL);
2077 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2079 GstStateChangeReturn state_change_return;
2080 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2082 if (priv->pipeline == NULL)
2085 if (priv->bus_message_source_id != 0)
2087 g_source_remove (priv->bus_message_source_id);
2088 priv->bus_message_source_id = 0;
2091 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2093 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2094 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2096 if (priv->pipeline != NULL)
2097 g_object_unref (priv->pipeline);
2098 priv->pipeline = NULL;
2100 if (priv->audio_output != NULL)
2101 g_object_unref (priv->audio_output);
2102 priv->audio_output = NULL;
2104 if (priv->video_tee != NULL)
2105 g_object_unref (priv->video_tee);
2106 priv->video_tee = NULL;
2108 if (priv->video_preview != NULL)
2109 clutter_actor_destroy (priv->video_preview);
2110 priv->video_preview = NULL;
2112 priv->funnel = NULL;
2114 create_pipeline (self);
2115 /* Call will be started when user will hit the 'redial' button */
2116 priv->start_call_when_playing = FALSE;
2117 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2123 g_message ("Error: could not destroy pipeline. Closing call window");
2124 gtk_widget_destroy (GTK_WIDGET (self));
2131 reset_details_pane (EmpathyCallWindow *self)
2133 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2135 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2136 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2137 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2138 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2142 empathy_call_window_disconnected (EmpathyCallWindow *self,
2145 gboolean could_disconnect = FALSE;
2146 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2147 gboolean could_reset_pipeline;
2149 /* Leave full screen mode if needed */
2150 gtk_window_unfullscreen (GTK_WINDOW (self));
2152 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2153 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2155 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2157 if (priv->call_state == CONNECTING)
2158 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2160 if (priv->call_state != REDIALING)
2161 priv->call_state = DISCONNECTED;
2163 if (could_reset_pipeline)
2165 g_mutex_lock (priv->lock);
2167 g_timer_stop (priv->timer);
2169 if (priv->timer_id != 0)
2170 g_source_remove (priv->timer_id);
2173 g_mutex_unlock (priv->lock);
2176 /* We are about to destroy the window, no need to update it or create
2177 * a video preview */
2180 empathy_call_window_status_message (self, _("Disconnected"));
2182 empathy_call_window_show_hangup_button (self, FALSE);
2184 /* Unsensitive the camera and mic button */
2185 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2186 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2188 /* Be sure that the mic button is enabled */
2189 gtk_toggle_tool_button_set_active (
2190 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2192 if (priv->camera_state == CAMERA_STATE_ON)
2194 /* Restart the preview with the new pipeline. */
2195 display_video_preview (self, TRUE);
2198 /* destroy the video output; it will be recreated when we'll redial */
2199 disconnect_video_output_motion_handler (self);
2200 if (priv->video_output != NULL)
2201 clutter_actor_destroy (priv->video_output);
2202 priv->video_output = NULL;
2203 if (priv->got_video_src > 0)
2205 g_source_remove (priv->got_video_src);
2206 priv->got_video_src = 0;
2209 gtk_widget_show (priv->remote_user_avatar_widget);
2211 reset_details_pane (self);
2213 priv->sending_video = FALSE;
2214 priv->call_started = FALSE;
2216 could_disconnect = TRUE;
2218 /* TODO: display the self avatar of the preview (depends if the "Always
2219 * Show Video Preview" is enabled or not) */
2222 return could_disconnect;
2227 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2230 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2231 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2233 if (empathy_call_window_disconnected (self, TRUE) &&
2234 priv->call_state == REDIALING)
2235 empathy_call_window_restart_call (self);
2239 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2241 FsMediaType media_type,
2242 EmpathyCallWindow *self)
2244 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2246 DEBUG ("removing content");
2249 * This assumes that there is only one video stream per channel...
2252 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2254 if (priv->funnel != NULL)
2258 output = priv->video_output_sink;
2260 gst_element_set_state (output, GST_STATE_NULL);
2261 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2263 gst_bin_remove (GST_BIN (priv->pipeline), output);
2264 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2265 priv->funnel = NULL;
2269 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2271 if (priv->audio_output != NULL)
2273 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2275 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2276 priv->audio_output = NULL;
2284 /* Called with global lock held */
2286 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2288 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2292 if (priv->funnel == NULL)
2294 output = priv->video_output_sink;
2296 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2300 g_warning ("Could not create fsfunnel");
2304 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2306 gst_object_unref (priv->funnel);
2307 priv->funnel = NULL;
2308 g_warning ("Could not add funnel to pipeline");
2312 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2314 g_warning ("Could not add the video output widget to the pipeline");
2318 if (!gst_element_link (priv->funnel, output))
2320 g_warning ("Could not link output sink to funnel");
2321 goto error_output_added;
2324 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2326 g_warning ("Could not start video sink");
2327 goto error_output_added;
2330 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2332 g_warning ("Could not start funnel");
2333 goto error_output_added;
2337 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2340 g_warning ("Could not get request pad from funnel");
2347 gst_element_set_locked_state (priv->funnel, TRUE);
2348 gst_element_set_locked_state (output, TRUE);
2350 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2351 gst_element_set_state (output, GST_STATE_NULL);
2353 gst_bin_remove (GST_BIN (priv->pipeline), output);
2354 gst_element_set_locked_state (output, FALSE);
2358 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2359 priv->funnel = NULL;
2364 /* Called with global lock held */
2366 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2368 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2370 GstPadTemplate *template;
2372 if (priv->audio_output == NULL)
2374 priv->audio_output = empathy_audio_sink_new ();
2375 g_object_ref_sink (priv->audio_output);
2377 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2379 g_warning ("Could not add audio sink to pipeline");
2380 g_object_unref (priv->audio_output);
2381 goto error_add_output;
2384 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2386 g_warning ("Could not start audio sink");
2391 template = gst_element_class_get_pad_template (
2392 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2394 pad = gst_element_request_pad (priv->audio_output,
2395 template, NULL, NULL);
2399 g_warning ("Could not get sink pad from sink");
2406 gst_element_set_locked_state (priv->audio_output, TRUE);
2407 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2408 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2409 priv->audio_output = NULL;
2417 empathy_call_window_update_timer (gpointer user_data)
2419 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2420 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2421 const gchar *status;
2425 time_ = g_timer_elapsed (priv->timer, NULL);
2427 if (priv->call_state == HELD)
2428 status = _("On hold");
2429 else if (!gtk_toggle_tool_button_get_active (
2430 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2433 status = _("Duration");
2435 /* Translators: 'status - minutes:seconds' the caller has been connected */
2436 str = g_strdup_printf (_("%s — %d:%02dm"),
2438 (int) time_ / 60, (int) time_ % 60);
2439 empathy_call_window_status_message (self, str);
2447 display_error (EmpathyCallWindow *self,
2448 TpyCallChannel *call,
2452 const gchar *details)
2454 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2455 GtkWidget *info_bar;
2456 GtkWidget *content_area;
2463 /* Create info bar */
2464 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2467 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2469 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2471 /* hbox containing the image and the messages vbox */
2472 hbox = gtk_hbox_new (FALSE, 3);
2473 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2476 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2477 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2479 /* vbox containing the main message and the details expander */
2480 vbox = gtk_vbox_new (FALSE, 3);
2481 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2484 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2486 label = gtk_label_new (NULL);
2487 gtk_label_set_markup (GTK_LABEL (label), txt);
2488 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2489 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2492 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2495 if (details != NULL)
2497 GtkWidget *expander;
2499 expander = gtk_expander_new (_("Technical Details"));
2501 txt = g_strdup_printf ("<i>%s</i>", details);
2503 label = gtk_label_new (NULL);
2504 gtk_label_set_markup (GTK_LABEL (label), txt);
2505 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2506 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2509 gtk_container_add (GTK_CONTAINER (expander), label);
2510 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2513 g_signal_connect (info_bar, "response",
2514 G_CALLBACK (gtk_widget_destroy), NULL);
2516 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2517 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2518 gtk_widget_show_all (info_bar);
2522 media_stream_error_to_txt (EmpathyCallWindow *self,
2523 TpyCallChannel *call,
2525 TpMediaStreamError error)
2527 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2528 const gchar *cm = NULL;
2534 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2536 return g_strdup_printf (
2537 _("%s's software does not understand any of the audio formats "
2538 "supported by your computer"),
2539 empathy_contact_get_alias (priv->contact));
2541 return g_strdup_printf (
2542 _("%s's software does not understand any of the video formats "
2543 "supported by your computer"),
2544 empathy_contact_get_alias (priv->contact));
2546 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2547 return g_strdup_printf (
2548 _("Can't establish a connection to %s. "
2549 "One of you might be on a network that does not allow "
2550 "direct connections."),
2551 empathy_contact_get_alias (priv->contact));
2553 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2554 return g_strdup (_("There was a failure on the network"));
2556 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2558 return g_strdup (_("The audio formats necessary for this call "
2559 "are not installed on your computer"));
2561 return g_strdup (_("The video formats necessary for this call "
2562 "are not installed on your computer"));
2564 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2565 tp_connection_parse_object_path (
2566 tp_channel_borrow_connection (TP_CHANNEL (call)),
2569 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2570 "product=Telepathy&component=%s", cm);
2572 result = g_strdup_printf (
2573 _("Something unexpected happened in a Telepathy component. "
2574 "Please <a href=\"%s\">report this bug</a> and attach "
2575 "logs gathered from the 'Debug' window in the Help menu."), url);
2581 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2582 return g_strdup (_("There was a failure in the call engine"));
2584 case TP_MEDIA_STREAM_ERROR_EOS:
2585 return g_strdup (_("The end of the stream was reached"));
2587 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2594 empathy_call_window_stream_error (EmpathyCallWindow *self,
2595 TpyCallChannel *call,
2604 desc = media_stream_error_to_txt (self, call, audio, code);
2607 /* No description, use the error message. That's not great as it's not
2608 * localized but it's better than nothing. */
2609 display_error (self, call, icon, title, msg, NULL);
2613 display_error (self, call, icon, title, desc, msg);
2619 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2622 EmpathyCallWindow *self)
2624 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2625 "gnome-stock-mic", _("Can't establish audio stream"));
2629 empathy_call_window_video_stream_error (TpyCallChannel *call,
2632 EmpathyCallWindow *self)
2634 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2635 "camera-web", _("Can't establish video stream"));
2640 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2642 EmpathyCallWindow *self)
2644 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2645 TpyCallChannel *call;
2646 gboolean can_send_video;
2648 if (state != TPY_CALL_STATE_ACCEPTED)
2651 if (priv->call_state == CONNECTED)
2654 g_timer_start (priv->timer);
2655 priv->call_state = CONNECTED;
2657 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2659 can_send_video = priv->video_input != NULL &&
2660 empathy_contact_can_voip_video (priv->contact) &&
2661 empathy_camera_monitor_get_available (priv->camera_monitor);
2663 g_object_get (priv->handler, "call-channel", &call, NULL);
2665 if (tpy_call_channel_has_dtmf (call))
2666 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2668 if (priv->video_input == NULL)
2669 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2671 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2673 empathy_call_window_show_hangup_button (self, TRUE);
2675 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2677 clutter_actor_hide (priv->video_output);
2678 gtk_widget_show (priv->remote_user_avatar_widget);
2680 g_object_unref (call);
2682 g_mutex_lock (priv->lock);
2684 priv->timer_id = g_timeout_add_seconds (1,
2685 empathy_call_window_update_timer, self);
2687 g_mutex_unlock (priv->lock);
2689 empathy_call_window_update_timer (self);
2691 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2695 empathy_call_window_show_video_output_cb (gpointer user_data)
2697 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2699 if (self->priv->video_output != NULL)
2701 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2702 clutter_actor_show (self->priv->video_output);
2703 clutter_actor_raise_top (self->priv->floating_toolbar);
2710 empathy_call_window_check_video_cb (gpointer data)
2712 EmpathyCallWindow *self = data;
2714 if (self->priv->got_video)
2716 self->priv->got_video = FALSE;
2720 /* No video in the last N seconds, display the remote avatar */
2721 empathy_call_window_show_video_output (self, FALSE);
2726 /* Called from the streaming thread */
2728 empathy_call_window_video_probe_cb (GstPad *pad,
2729 GstMiniObject *mini_obj,
2730 EmpathyCallWindow *self)
2733 if (GST_IS_EVENT (mini_obj))
2736 if (G_UNLIKELY (!self->priv->got_video))
2738 /* show the remote video */
2739 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2740 empathy_call_window_show_video_output_cb,
2741 g_object_ref (self), g_object_unref);
2743 self->priv->got_video = TRUE;
2749 /* Called from the streaming thread */
2751 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2752 GstPad *src, guint media_type, gpointer user_data)
2754 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2755 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2756 gboolean retval = FALSE;
2760 g_mutex_lock (priv->lock);
2764 case TP_MEDIA_STREAM_TYPE_AUDIO:
2765 pad = empathy_call_window_get_audio_sink_pad (self);
2767 case TP_MEDIA_STREAM_TYPE_VIDEO:
2768 g_idle_add (empathy_call_window_show_video_output_cb, self);
2769 pad = empathy_call_window_get_video_sink_pad (self);
2771 gst_pad_add_data_probe (src,
2772 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2773 if (priv->got_video_src > 0)
2774 g_source_remove (priv->got_video_src);
2775 priv->got_video_src = g_timeout_add_seconds (5,
2776 empathy_call_window_check_video_cb, self);
2779 g_assert_not_reached ();
2785 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2786 g_warning ("Could not link %s sink pad",
2787 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2791 gst_object_unref (pad);
2795 /* If no sink could be linked, try to add fakesink to prevent the whole call
2800 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2802 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2804 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2805 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2806 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2808 gst_element_set_locked_state (fakesink, TRUE);
2809 gst_element_set_state (fakesink, GST_STATE_NULL);
2810 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2814 DEBUG ("Could not link real sink, linked fakesink instead");
2816 gst_object_unref (sinkpad);
2820 gst_object_unref (fakesink);
2825 g_mutex_unlock (priv->lock);
2831 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2832 GstPad *sink, FsMediaType media_type, gpointer user_data)
2834 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2835 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2837 gboolean retval = FALSE;
2841 case FS_MEDIA_TYPE_AUDIO:
2842 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2844 g_warning ("Could not add audio source to pipeline");
2848 pad = gst_element_get_static_pad (priv->audio_input, "src");
2851 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2852 g_warning ("Could not get source pad from audio source");
2856 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2858 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2859 g_warning ("Could not link audio source to farsight");
2863 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2865 g_warning ("Could not start audio source");
2866 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2867 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2873 case FS_MEDIA_TYPE_VIDEO:
2874 if (priv->video_tee != NULL)
2876 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2877 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2879 g_warning ("Could not link video source input pipeline");
2882 gst_object_unref (pad);
2888 g_assert_not_reached ();
2895 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2897 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2898 GstElement *preview;
2900 disable_camera (self);
2902 DEBUG ("remove video input");
2903 preview = priv->video_preview_sink;
2905 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2906 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2907 gst_element_set_state (preview, GST_STATE_NULL);
2909 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2912 g_object_unref (priv->video_input);
2913 priv->video_input = NULL;
2914 g_object_unref (priv->video_tee);
2915 priv->video_tee = NULL;
2916 clutter_actor_destroy (priv->video_preview);
2917 priv->video_preview = NULL;
2919 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2923 start_call (EmpathyCallWindow *self)
2925 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2927 priv->call_started = TRUE;
2928 empathy_call_handler_start_call (priv->handler,
2929 gtk_get_current_event_time ());
2931 if (empathy_call_handler_has_initial_video (priv->handler))
2933 TpyCallChannel *call;
2936 g_object_get (priv->handler, "call-channel", &call, NULL);
2937 s = tpy_call_channel_get_video_state (call);
2939 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2940 s == TPY_SENDING_STATE_SENDING)
2942 /* Enable 'send video' buttons and display the preview */
2943 gtk_toggle_tool_button_set_active (
2944 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2948 gtk_toggle_tool_button_set_active (
2949 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2951 if (priv->video_preview == NULL)
2953 create_video_preview (self);
2954 add_video_preview_to_pipeline (self);
2958 g_object_unref (call);
2963 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2966 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2967 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2970 empathy_call_handler_bus_message (priv->handler, bus, message);
2972 switch (GST_MESSAGE_TYPE (message))
2974 case GST_MESSAGE_STATE_CHANGED:
2975 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2977 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2979 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2980 !priv->call_started)
2982 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2983 if (newstate == GST_STATE_PAUSED)
2985 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2986 priv->pipeline_playing = TRUE;
2988 if (priv->start_call_when_playing)
2993 case GST_MESSAGE_ERROR:
2995 GError *error = NULL;
2996 GstElement *gst_error;
2999 gst_message_parse_error (message, &error, &debug);
3000 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3002 g_message ("Element error: %s -- %s\n", error->message, debug);
3004 if (g_str_has_prefix (gst_element_get_name (gst_error),
3005 VIDEO_INPUT_ERROR_PREFIX))
3007 /* Remove the video input and continue */
3008 if (priv->video_input != NULL)
3009 empathy_call_window_remove_video_input (self);
3010 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3014 empathy_call_window_disconnected (self, TRUE);
3016 g_error_free (error);
3019 case GST_MESSAGE_UNKNOWN:
3020 case GST_MESSAGE_EOS:
3021 case GST_MESSAGE_WARNING:
3022 case GST_MESSAGE_INFO:
3023 case GST_MESSAGE_TAG:
3024 case GST_MESSAGE_BUFFERING:
3025 case GST_MESSAGE_STATE_DIRTY:
3026 case GST_MESSAGE_STEP_DONE:
3027 case GST_MESSAGE_CLOCK_PROVIDE:
3028 case GST_MESSAGE_CLOCK_LOST:
3029 case GST_MESSAGE_NEW_CLOCK:
3030 case GST_MESSAGE_STRUCTURE_CHANGE:
3031 case GST_MESSAGE_STREAM_STATUS:
3032 case GST_MESSAGE_APPLICATION:
3033 case GST_MESSAGE_ELEMENT:
3034 case GST_MESSAGE_SEGMENT_START:
3035 case GST_MESSAGE_SEGMENT_DONE:
3036 case GST_MESSAGE_DURATION:
3037 case GST_MESSAGE_ANY:
3046 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3047 GHashTable *members,
3048 EmpathyCallWindow *self)
3050 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3051 GHashTableIter iter;
3052 gpointer key, value;
3053 gboolean held = FALSE;
3055 g_hash_table_iter_init (&iter, members);
3056 while (g_hash_table_iter_next (&iter, &key, &value))
3058 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3060 /* This assumes this is a 1-1 call, otherwise one participant
3061 * putting the call on hold wouldn't mean the call is on hold
3069 priv->call_state = HELD;
3070 else if (priv->call_state == HELD)
3071 priv->call_state = CONNECTED;
3075 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3077 EmpathyCallWindow *self)
3079 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3080 TpyCallChannel *call;
3082 g_object_get (priv->handler, "call-channel", &call, NULL);
3087 tp_g_signal_connect_object (call, "audio-stream-error",
3088 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3089 tp_g_signal_connect_object (call, "video-stream-error",
3090 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3093 tp_g_signal_connect_object (call, "members-changed",
3094 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3096 g_object_unref (call);
3100 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3102 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3103 TpyCallChannel *call;
3106 /* Make the hangup button twice as wide */
3107 width = gtk_widget_get_allocated_width (priv->hangup_button);
3108 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3110 g_signal_connect (priv->handler, "state-changed",
3111 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3112 g_signal_connect (priv->handler, "conference-added",
3113 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3114 g_signal_connect (priv->handler, "conference-removed",
3115 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3116 g_signal_connect (priv->handler, "closed",
3117 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3118 g_signal_connect (priv->handler, "src-pad-added",
3119 G_CALLBACK (empathy_call_window_src_added_cb), window);
3120 g_signal_connect (priv->handler, "sink-pad-added",
3121 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3122 g_signal_connect (priv->handler, "sink-pad-removed",
3123 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3125 g_object_get (priv->handler, "call-channel", &call, NULL);
3128 call_handler_notify_call_cb (priv->handler, NULL, window);
3129 g_object_unref (call);
3133 /* call-channel doesn't exist yet, we'll connect signals once it has been
3135 g_signal_connect (priv->handler, "notify::call-channel",
3136 G_CALLBACK (call_handler_notify_call_cb), window);
3139 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3143 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3144 EmpathyCallWindow *window)
3146 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3148 if (priv->pipeline != NULL)
3150 if (priv->bus_message_source_id != 0)
3152 g_source_remove (priv->bus_message_source_id);
3153 priv->bus_message_source_id = 0;
3156 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3159 if (priv->call_state == CONNECTING)
3160 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3166 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3169 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3171 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3176 gtk_widget_hide (priv->dtmf_panel);
3177 gtk_widget_hide (menu);
3178 gtk_widget_hide (priv->toolbar);
3182 if (priv->dialpad_was_visible_before_fs)
3183 gtk_widget_show (priv->dtmf_panel);
3185 gtk_widget_show (menu);
3186 gtk_widget_show (priv->toolbar);
3188 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3189 priv->original_height_before_fs);
3194 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3196 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3198 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3199 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3200 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3201 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3203 if (priv->video_output != NULL)
3206 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3207 priv->video_output, TRUE, TRUE,
3208 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3215 empathy_call_window_state_event_cb (GtkWidget *widget,
3216 GdkEventWindowState *event, EmpathyCallWindow *window)
3218 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3220 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3221 gboolean set_fullscreen = event->new_window_state &
3222 GDK_WINDOW_STATE_FULLSCREEN;
3226 gboolean dialpad_was_visible;
3227 GtkAllocation allocation;
3228 gint original_width, original_height;
3230 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3231 original_width = allocation.width;
3232 original_height = allocation.height;
3234 g_object_get (priv->dtmf_panel,
3235 "visible", &dialpad_was_visible,
3238 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3239 priv->original_width_before_fs = original_width;
3240 priv->original_height_before_fs = original_height;
3242 if (priv->video_output_motion_handler_id == 0 &&
3243 priv->video_output != NULL)
3245 priv->video_output_motion_handler_id = g_signal_connect (
3246 G_OBJECT (priv->video_container), "motion-notify-event",
3247 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3253 disconnect_video_output_motion_handler (window);
3256 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3258 show_controls (window, set_fullscreen);
3259 show_borders (window, set_fullscreen);
3260 gtk_action_set_stock_id (priv->menu_fullscreen,
3261 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3262 priv->is_fullscreen = set_fullscreen;
3269 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3272 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3273 int w, h, dialpad_width;
3274 GtkAllocation allocation;
3276 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3277 w = allocation.width;
3278 h = allocation.height;
3280 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3284 gtk_widget_show (priv->dtmf_panel);
3290 gtk_widget_hide (priv->dtmf_panel);
3294 gtk_window_resize (GTK_WINDOW (window), w, h);
3298 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3301 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3302 TpyCallChannel *call;
3304 priv->sending_video = (state == CAMERA_STATE_ON);
3306 if (state == CAMERA_STATE_ON)
3308 /* When we start sending video, we want to show the video preview by
3310 display_video_preview (window, TRUE);
3314 display_video_preview (window, FALSE);
3317 if (priv->call_state != CONNECTED)
3320 g_object_get (priv->handler, "call-channel", &call, NULL);
3321 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3322 tpy_call_channel_send_video (call, priv->sending_video);
3323 g_object_unref (call);
3327 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3328 EmpathyCallWindow *self)
3330 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3333 active = (gtk_toggle_tool_button_get_active (toggle));
3335 /* We don't want the settings callback to react to this change to avoid
3337 g_signal_handlers_block_by_func (priv->settings,
3338 empathy_call_window_prefs_volume_changed_cb, self);
3342 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3343 priv->volume * 100);
3347 /* TODO, Instead of setting the input volume to 0 we should probably
3348 * stop sending but this would cause the audio call to drop if both
3349 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3350 * in the future. GNOME #574574
3352 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3356 g_signal_handlers_unblock_by_func (priv->settings,
3357 empathy_call_window_prefs_volume_changed_cb, self);
3361 empathy_call_window_hangup_cb (gpointer object,
3362 EmpathyCallWindow *self)
3364 empathy_call_handler_stop_call (self->priv->handler);
3366 empathy_call_window_disconnected (self, TRUE);
3370 empathy_call_window_restart_call (EmpathyCallWindow *window)
3372 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3374 /* Remove error info bars */
3375 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3376 (GtkCallback) gtk_widget_destroy, NULL);
3378 create_video_output_widget (window);
3380 /* While the call was disconnected, the input volume might have changed.
3381 * However, since the audio_input source was destroyed, its volume has not
3382 * been updated during that time. That's why we manually update it here */
3383 empathy_call_window_mic_volume_changed (window);
3385 priv->outgoing = TRUE;
3386 empathy_call_window_set_state_connecting (window);
3388 if (priv->pipeline_playing)
3389 start_call (window);
3391 /* call will be started when the pipeline is ready */
3392 priv->start_call_when_playing = TRUE;
3394 empathy_call_window_setup_avatars (window, priv->handler);
3396 empathy_call_window_show_hangup_button (window, TRUE);
3400 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3401 EmpathyCallWindow *window)
3405 active = gtk_toggle_tool_button_get_active (button);
3407 empathy_call_window_show_dialpad (window, active);
3411 empathy_call_window_fullscreen_cb (gpointer object,
3412 EmpathyCallWindow *window)
3414 empathy_call_window_fullscreen_toggle (window);
3418 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3420 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3422 if (priv->is_fullscreen)
3423 gtk_window_unfullscreen (GTK_WINDOW (window));
3425 gtk_window_fullscreen (GTK_WINDOW (window));
3429 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3430 GdkEventButton *event, EmpathyCallWindow *window)
3432 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3434 empathy_call_window_video_menu_popup (window, event->button);
3442 empathy_call_window_key_press_cb (GtkWidget *video_output,
3443 GdkEventKey *event, EmpathyCallWindow *window)
3445 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3447 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3449 /* Since we are in fullscreen mode, toggling will bring us back to
3451 empathy_call_window_fullscreen_toggle (window);
3459 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3460 GdkEventMotion *event, EmpathyCallWindow *window)
3462 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3464 if (priv->is_fullscreen)
3466 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3468 /* Show the bottom toolbar */
3469 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3476 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3480 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3482 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3484 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3485 button, gtk_get_current_event_time ());
3486 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3490 empathy_call_window_status_message (EmpathyCallWindow *self,
3493 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3497 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3498 gdouble value, EmpathyCallWindow *window)
3500 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3502 if (priv->audio_output == NULL)
3505 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3510 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3512 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3514 return priv->ui_manager;
3517 EmpathyGstAudioSrc *
3518 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3520 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3522 return (EmpathyGstAudioSrc *) priv->audio_input;