2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
69 #define CONTENT_HBOX_BORDER_WIDTH 6
70 #define CONTENT_HBOX_SPACING 3
71 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
73 #define SELF_VIDEO_SECTION_WIDTH 120
74 #define SELF_VIDEO_SECTION_HEIGTH 90
75 #define SELF_VIDEO_SECTION_MARGIN 10
77 #define FLOATING_TOOLBAR_OPACITY 192
78 #define FLOATING_TOOLBAR_WIDTH 280
79 #define FLOATING_TOOLBAR_HEIGHT 36
80 #define FLOATING_TOOLBAR_SPACING 20
82 /* The avatar's default width and height are set to the same value because we
83 want a square icon. */
84 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
85 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
86 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
88 #define SMALL_TOOLBAR_SIZE 36
90 /* If an video input error occurs, the error message will start with "v4l" */
91 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
93 /* The time interval in milliseconds between 2 outgoing rings */
94 #define MS_BETWEEN_RING 500
96 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
99 PROP_CALL_HANDLER = 1,
111 CAMERA_STATE_OFF = 0,
117 PREVIEW_POS_TOP_LEFT,
118 PREVIEW_POS_TOP_RIGHT,
119 PREVIEW_POS_BOTTOM_LEFT,
120 PREVIEW_POS_BOTTOM_RIGHT,
123 struct _EmpathyCallWindowPriv
125 gboolean dispose_has_run;
126 EmpathyCallHandler *handler;
128 EmpathyContact *contact;
130 EmpathyCameraMonitor *camera_monitor;
135 GtkUIManager *ui_manager;
136 GtkWidget *errors_vbox;
137 /* widget displays the video received from the remote user. This widget is
138 * alive only during call. */
139 ClutterActor *video_output;
140 ClutterActor *video_preview;
141 ClutterActor *preview_hidden_button;
142 ClutterActor *preview_rectangle1;
143 ClutterActor *preview_rectangle2;
144 ClutterActor *preview_rectangle3;
145 ClutterActor *preview_rectangle4;
146 GtkWidget *video_container;
147 GtkWidget *remote_user_avatar_widget;
148 GtkWidget *remote_user_avatar_toolbar;
149 GtkWidget *remote_user_name_toolbar;
150 GtkWidget *status_label;
151 GtkWidget *hangup_button;
152 GtkWidget *audio_call_button;
153 GtkWidget *video_call_button;
154 GtkWidget *mic_button;
155 GtkWidget *camera_button;
156 GtkWidget *dialpad_button;
158 GtkWidget *bottom_toolbar;
159 ClutterActor *floating_toolbar;
161 GtkAction *menu_fullscreen;
163 ClutterState *transitions;
165 /* The box that contains self and remote avatar and video
166 input/output. When we redial, we destroy and re-create the box */
167 ClutterActor *video_box;
168 ClutterLayoutManager *video_layout;
170 /* Coordinates of the preview drag event's start. */
171 PreviewPosition preview_pos;
175 /* We keep a reference on the hbox which contains the main content so we can
176 easilly repack everything when toggling fullscreen */
177 GtkWidget *content_hbox;
179 gulong video_output_motion_handler_id;
180 guint bus_message_source_id;
184 GtkWidget *dtmf_panel;
187 GtkWidget *details_vbox;
188 GtkWidget *vcodec_encoding_label;
189 GtkWidget *acodec_encoding_label;
190 GtkWidget *vcodec_decoding_label;
191 GtkWidget *acodec_decoding_label;
193 GtkWidget *audio_remote_candidate_label;
194 GtkWidget *audio_local_candidate_label;
195 GtkWidget *video_remote_candidate_label;
196 GtkWidget *video_local_candidate_label;
197 GtkWidget *video_remote_candidate_info_img;
198 GtkWidget *video_local_candidate_info_img;
199 GtkWidget *audio_remote_candidate_info_img;
200 GtkWidget *audio_local_candidate_info_img;
202 GstElement *video_input;
203 GstElement *video_preview_sink;
204 GstElement *video_output_sink;
205 GstElement *audio_input;
206 GstElement *audio_output;
207 GstElement *pipeline;
208 GstElement *video_tee;
218 gboolean call_started;
219 gboolean sending_video;
220 CameraState camera_state;
222 EmpathyCallWindowFullscreen *fullscreen;
223 gboolean is_fullscreen;
228 guint inactivity_src;
230 /* Those fields represent the state of the window before it actually was in
232 gboolean dialpad_was_visible_before_fs;
233 gint original_width_before_fs;
234 gint original_height_before_fs;
236 gint x, y, w, h, dialpad_width;
239 /* TRUE if the call should be started when the pipeline is playing */
240 gboolean start_call_when_playing;
241 /* TRUE if we requested to set the pipeline in the playing state */
242 gboolean pipeline_playing;
244 EmpathySoundManager *sound_mgr;
247 EmpathyMicMenu *mic_menu;
250 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
252 static void empathy_call_window_realized_cb (GtkWidget *widget,
253 EmpathyCallWindow *window);
255 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
256 GdkEvent *event, EmpathyCallWindow *window);
258 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
259 GdkEventWindowState *event, EmpathyCallWindow *window);
261 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
264 static void empathy_call_window_mic_toggled_cb (
265 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
267 static void empathy_call_window_hangup_cb (gpointer object,
268 EmpathyCallWindow *window);
270 static void empathy_call_window_fullscreen_cb (gpointer object,
271 EmpathyCallWindow *window);
273 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
275 static gboolean empathy_call_window_video_button_press_cb (
276 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
278 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
279 GdkEventKey *event, EmpathyCallWindow *window);
281 static gboolean empathy_call_window_video_output_motion_notify (
282 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
284 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
287 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
288 EmpathyCallWindow *window);
290 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
292 static void empathy_call_window_status_message (EmpathyCallWindow *window,
295 static gboolean empathy_call_window_bus_message (GstBus *bus,
296 GstMessage *message, gpointer user_data);
299 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
300 gdouble value, EmpathyCallWindow *window);
303 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
306 gtk_widget_set_visible (self->priv->hangup_button, show);
307 gtk_widget_set_visible (self->priv->audio_call_button, !show);
308 gtk_widget_set_visible (self->priv->video_call_button, !show);
312 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
313 EmpathyCallWindow *self)
315 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
316 empathy_call_window_restart_call (self);
320 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
321 EmpathyCallWindow *self)
323 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
324 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
325 empathy_call_window_restart_call (self);
329 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
331 EmpathyCallWindowPriv *priv = GET_PRIV (window);
332 TpyCallChannel *call;
336 g_object_get (priv->handler, "call-channel", &call, NULL);
338 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
339 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
342 tpy_call_channel_dtmf_start_tone (call, event);
344 g_object_unref (call);
348 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
350 EmpathyCallWindowPriv *priv = GET_PRIV (window);
351 TpyCallChannel *call;
353 g_object_get (priv->handler, "call-channel", &call, NULL);
355 tpy_call_channel_dtmf_stop_tone (call);
357 g_object_unref (call);
361 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
363 EmpathyCallWindowPriv *priv = GET_PRIV (self);
366 volume = g_settings_get_double (priv->settings,
367 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
369 /* Don't store the volume because of muting */
370 if (volume > 0 || gtk_toggle_tool_button_get_active (
371 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
372 priv->volume = volume;
374 /* Ensure that the toggle button is active if the volume is > 0 and inactive
375 * if it's smaller than 0 */
376 if ((volume > 0) != gtk_toggle_tool_button_get_active (
377 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
378 gtk_toggle_tool_button_set_active (
379 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
381 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
386 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
388 EmpathyCallWindow *self)
390 empathy_call_window_mic_volume_changed (self);
394 empathy_call_window_show_video_output (EmpathyCallWindow *self,
397 if (self->priv->video_output != NULL)
398 g_object_set (self->priv->video_output, "visible", show, NULL);
400 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
402 clutter_actor_raise_top (self->priv->floating_toolbar);
406 create_video_output_widget (EmpathyCallWindow *self)
408 EmpathyCallWindowPriv *priv = GET_PRIV (self);
410 g_assert (priv->video_output == NULL);
411 g_assert (priv->pipeline != NULL);
413 priv->video_output = clutter_texture_new ();
415 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
418 priv->video_output_sink = clutter_gst_video_sink_new (
419 CLUTTER_TEXTURE (priv->video_output));
421 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
424 gtk_widget_add_events (priv->video_container,
425 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
426 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
427 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
431 create_video_input (EmpathyCallWindow *self)
433 EmpathyCallWindowPriv *priv = GET_PRIV (self);
435 g_assert (priv->video_input == NULL);
436 priv->video_input = empathy_video_src_new ();
437 gst_object_ref (priv->video_input);
438 gst_object_sink (priv->video_input);
442 create_audio_input (EmpathyCallWindow *self)
444 EmpathyCallWindowPriv *priv = GET_PRIV (self);
446 g_assert (priv->audio_input == NULL);
447 priv->audio_input = empathy_audio_src_new ();
448 gst_object_ref (priv->audio_input);
449 gst_object_sink (priv->audio_input);
453 add_video_preview_to_pipeline (EmpathyCallWindow *self)
455 EmpathyCallWindowPriv *priv = GET_PRIV (self);
458 g_assert (priv->video_preview != NULL);
459 g_assert (priv->pipeline != NULL);
460 g_assert (priv->video_input != NULL);
461 g_assert (priv->video_tee != NULL);
463 preview = priv->video_preview_sink;
465 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
467 g_warning ("Could not add video input to pipeline");
471 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
473 g_warning ("Could not add video preview to pipeline");
477 if (!gst_element_link (priv->video_input, priv->video_tee))
479 g_warning ("Could not link video input to video tee");
483 if (!gst_element_link (priv->video_tee, preview))
485 g_warning ("Could not link video tee to video preview");
491 empathy_call_window_disable_camera_cb (GtkAction *action,
492 EmpathyCallWindow *self)
494 clutter_actor_destroy (self->priv->preview_hidden_button);
496 gtk_toggle_tool_button_set_active (
497 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
501 empathy_call_window_minimise_camera_cb (GtkAction *action,
502 EmpathyCallWindow *self)
504 clutter_actor_hide (self->priv->video_preview);
505 clutter_actor_show (self->priv->preview_hidden_button);
509 empathy_call_window_maximise_camera_cb (GtkAction *action,
510 EmpathyCallWindow *self)
512 clutter_actor_show (self->priv->video_preview);
513 clutter_actor_hide (self->priv->preview_hidden_button);
517 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
518 EmpathyCallWindow *self)
522 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
524 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
525 0, gtk_get_current_event_time ());
526 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
530 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
531 EmpathyCallWindow *self)
535 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
536 "/preview-hidden-menu");
537 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
538 0, gtk_get_current_event_time ());
539 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
542 static ClutterActor *
543 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
544 ClutterBinAlignment x,
545 ClutterBinAlignment y)
547 ClutterLayoutManager *layout1, *layout2;
548 ClutterActor *rectangle;
549 ClutterActor *box1, *box2;
551 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
552 CLUTTER_BIN_ALIGNMENT_START);
554 box1 = clutter_box_new (layout1);
556 rectangle = clutter_rectangle_new_with_color (
557 CLUTTER_COLOR_Transparent);
559 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
562 clutter_actor_set_size (box1,
563 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
564 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
565 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
567 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
568 CLUTTER_BIN_ALIGNMENT_CENTER);
570 /* We have a box with the margins and the video in the middle inside
571 * a bigger box with an extra bottom margin so we're not on top of
572 * the floating toolbar. */
573 box2 = clutter_box_new (layout2);
575 clutter_actor_set_size (box2,
576 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
577 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN);
579 clutter_actor_set_size (rectangle,
580 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGTH + 5);
582 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
583 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
585 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
588 clutter_actor_hide (rectangle);
594 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
596 self->priv->preview_rectangle1 =
597 empathy_call_window_create_preview_rectangle (self,
598 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
599 self->priv->preview_rectangle2 =
600 empathy_call_window_create_preview_rectangle (self,
601 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
602 self->priv->preview_rectangle3 =
603 empathy_call_window_create_preview_rectangle (self,
604 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
605 self->priv->preview_rectangle4 =
606 empathy_call_window_create_preview_rectangle (self,
607 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
611 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
614 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
615 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
616 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
617 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
620 static PreviewPosition
621 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
626 PreviewPosition pos = PREVIEW_POS_NONE;
628 clutter_actor_get_geometry (self->priv->video_box, &box);
630 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
631 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
632 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
633 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
635 pos = PREVIEW_POS_TOP_LEFT;
637 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
638 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
639 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
640 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
642 pos = PREVIEW_POS_TOP_RIGHT;
644 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
645 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
646 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
647 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGTH))
649 pos = PREVIEW_POS_BOTTOM_LEFT;
651 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
652 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
653 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
654 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGTH))
656 pos = PREVIEW_POS_BOTTOM_RIGHT;
662 static ClutterActor *
663 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
666 ClutterActor *rectangle;
670 case PREVIEW_POS_TOP_LEFT:
671 rectangle = self->priv->preview_rectangle1;
673 case PREVIEW_POS_TOP_RIGHT:
674 rectangle = self->priv->preview_rectangle3;
676 case PREVIEW_POS_BOTTOM_LEFT:
677 rectangle = self->priv->preview_rectangle2;
679 case PREVIEW_POS_BOTTOM_RIGHT:
680 rectangle = self->priv->preview_rectangle4;
690 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
693 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
695 DEBUG ("moving the video preview to %d", pos);
697 self->priv->preview_pos = pos;
701 case PREVIEW_POS_TOP_LEFT:
702 clutter_bin_layout_set_alignment (layout,
703 self->priv->video_preview,
704 CLUTTER_BIN_ALIGNMENT_START,
705 CLUTTER_BIN_ALIGNMENT_START);
707 case PREVIEW_POS_TOP_RIGHT:
708 clutter_bin_layout_set_alignment (layout,
709 self->priv->video_preview,
710 CLUTTER_BIN_ALIGNMENT_END,
711 CLUTTER_BIN_ALIGNMENT_START);
713 case PREVIEW_POS_BOTTOM_LEFT:
714 clutter_bin_layout_set_alignment (layout,
715 self->priv->video_preview,
716 CLUTTER_BIN_ALIGNMENT_START,
717 CLUTTER_BIN_ALIGNMENT_END);
719 case PREVIEW_POS_BOTTOM_RIGHT:
720 clutter_bin_layout_set_alignment (layout,
721 self->priv->video_preview,
722 CLUTTER_BIN_ALIGNMENT_END,
723 CLUTTER_BIN_ALIGNMENT_END);
726 g_warn_if_reached ();
731 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
734 ClutterActor *rectangle;
736 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
738 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
739 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
744 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
745 ClutterActor *rectangle)
747 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
748 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
749 CLUTTER_COLOR_Black);
753 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
755 ClutterActor *rectangle;
757 rectangle = empathy_call_window_get_preview_rectangle (self,
758 self->priv->preview_pos);
760 /* We don't want to darken the rectangle where the preview
763 if (self->priv->preview_rectangle1 != rectangle)
764 empathy_call_window_darken_preview_rectangle (self,
765 self->priv->preview_rectangle1);
767 if (self->priv->preview_rectangle2 != rectangle)
768 empathy_call_window_darken_preview_rectangle (self,
769 self->priv->preview_rectangle2);
771 if (self->priv->preview_rectangle3 != rectangle)
772 empathy_call_window_darken_preview_rectangle (self,
773 self->priv->preview_rectangle3);
775 if (self->priv->preview_rectangle4 != rectangle)
776 empathy_call_window_darken_preview_rectangle (self,
777 self->priv->preview_rectangle4);
781 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
785 ClutterModifierType modifiers,
786 EmpathyCallWindow *self)
788 empathy_call_window_show_preview_rectangles (self, TRUE);
789 empathy_call_window_darken_preview_rectangles (self);
791 self->priv->event_x = event_x;
792 self->priv->event_y = event_y;
796 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
800 ClutterModifierType modifiers,
801 EmpathyCallWindow *self)
805 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
807 if (pos != PREVIEW_POS_NONE)
808 empathy_call_window_move_video_preview (self, pos);
810 empathy_call_window_show_preview_rectangles (self, FALSE);
814 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
818 EmpathyCallWindow *self)
822 pos = empathy_call_window_get_preview_position (self,
823 self->priv->event_x - delta_x, self->priv->event_y + delta_y);
825 if (pos != PREVIEW_POS_NONE)
826 empathy_call_window_highlight_preview_rectangle (self, pos);
828 empathy_call_window_darken_preview_rectangles (self);
832 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
833 ClutterCrossingEvent *event,
834 EmpathyCallWindow *self)
836 ClutterActor *rectangle;
839 pos = empathy_call_window_get_preview_position (self, event->x, event->y);
840 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
842 empathy_call_window_highlight_preview_rectangle (self, pos);
844 clutter_actor_show (rectangle);
850 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
851 ClutterCrossingEvent *event,
852 EmpathyCallWindow *self)
854 ClutterActor *rectangle;
856 rectangle = empathy_call_window_get_preview_rectangle (self,
857 self->priv->preview_pos);
859 empathy_call_window_darken_preview_rectangle (self, rectangle);
861 clutter_actor_hide (rectangle);
867 create_video_preview (EmpathyCallWindow *self)
869 EmpathyCallWindowPriv *priv = GET_PRIV (self);
870 ClutterLayoutManager *layout, *layout_center;
871 ClutterActor *preview;
874 ClutterAction *action;
877 g_assert (priv->video_preview == NULL);
879 preview = clutter_texture_new ();
880 clutter_actor_set_size (preview,
881 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
882 priv->video_preview_sink = clutter_gst_video_sink_new (
883 CLUTTER_TEXTURE (preview));
885 /* Flip the video preview */
886 clutter_actor_set_rotation (preview,
889 SELF_VIDEO_SECTION_WIDTH * 0.5,
893 /* Add a little offset to the video preview */
894 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
895 CLUTTER_BIN_ALIGNMENT_START);
896 priv->video_preview = clutter_box_new (layout);
897 clutter_actor_set_size (priv->video_preview,
898 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
899 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
900 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
902 /* We have a box with the margins and the video in the middle inside
903 * a bigger box with an extra bottom margin so we're not on top of
904 * the floating toolbar. */
905 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
906 CLUTTER_BIN_ALIGNMENT_CENTER);
907 box = clutter_box_new (layout_center);
908 clutter_actor_set_size (box,
909 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
910 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN);
912 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
913 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
915 g_object_set (priv->video_preview_sink,
920 /* Translators: this is an "Info" label. It should be as short
922 button = gtk_button_new_with_label (_("i"));
923 b = gtk_clutter_actor_new_with_contents (button);
925 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
927 CLUTTER_BIN_ALIGNMENT_END,
928 CLUTTER_BIN_ALIGNMENT_END);
930 g_signal_connect (button, "clicked",
931 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
934 /* Translators: this is an "Info" label. It should be as short
936 button = gtk_button_new_with_label (_("i"));
937 priv->preview_hidden_button =
938 gtk_clutter_actor_new_with_contents (button);
940 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
941 priv->preview_hidden_button,
942 CLUTTER_BIN_ALIGNMENT_START,
943 CLUTTER_BIN_ALIGNMENT_END);
945 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
947 clutter_actor_hide (priv->preview_hidden_button);
949 g_signal_connect (button, "clicked",
950 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
953 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
955 CLUTTER_BIN_ALIGNMENT_START,
956 CLUTTER_BIN_ALIGNMENT_END);
958 action = clutter_drag_action_new ();
959 g_signal_connect (action, "drag-begin",
960 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
961 g_signal_connect (action, "drag-end",
962 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
963 g_signal_connect (action, "drag-motion",
964 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
966 g_signal_connect (preview, "enter-event",
967 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
968 g_signal_connect (preview, "leave-event",
969 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
971 clutter_actor_add_action (preview, action);
972 clutter_actor_set_reactive (preview, TRUE);
976 play_camera (EmpathyCallWindow *window,
979 EmpathyCallWindowPriv *priv = GET_PRIV (window);
983 if (priv->video_preview == NULL)
985 create_video_preview (window);
986 add_video_preview_to_pipeline (window);
990 state = GST_STATE_PLAYING;
992 state = GST_STATE_NULL;
994 preview = priv->video_preview_sink;
996 gst_element_set_state (preview, state);
997 gst_element_set_state (priv->video_input, state);
998 gst_element_set_state (priv->video_tee, state);
1002 display_video_preview (EmpathyCallWindow *self,
1005 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1009 /* Display the video preview */
1010 DEBUG ("Show video preview");
1012 play_camera (self, TRUE);
1013 clutter_actor_show (priv->video_preview);
1014 clutter_actor_raise_top (priv->floating_toolbar);
1018 /* Hide the video preview */
1019 DEBUG ("Hide video preview");
1021 if (priv->video_preview != NULL)
1023 clutter_actor_hide (priv->video_preview);
1024 play_camera (self, FALSE);
1030 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1032 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1034 empathy_call_window_status_message (window, _("Connecting…"));
1035 priv->call_state = CONNECTING;
1038 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1039 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1043 disable_camera (EmpathyCallWindow *self)
1045 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1047 if (priv->camera_state == CAMERA_STATE_OFF)
1050 DEBUG ("Disable camera");
1052 display_video_preview (self, FALSE);
1054 if (priv->camera_state == CAMERA_STATE_ON)
1055 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1057 priv->camera_state = CAMERA_STATE_OFF;
1061 enable_camera (EmpathyCallWindow *self)
1063 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1065 if (priv->camera_state == CAMERA_STATE_ON)
1068 if (priv->video_input == NULL)
1070 DEBUG ("Can't enable camera, no input");
1074 DEBUG ("Enable camera");
1076 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1078 priv->camera_state = CAMERA_STATE_ON;
1082 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1083 EmpathyCallWindow *self)
1085 if (gtk_toggle_tool_button_get_active (toggle))
1086 enable_camera (self);
1088 disable_camera (self);
1092 create_pipeline (EmpathyCallWindow *self)
1094 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1097 g_assert (priv->pipeline == NULL);
1099 priv->pipeline = gst_pipeline_new (NULL);
1100 priv->pipeline_playing = FALSE;
1102 priv->video_tee = gst_element_factory_make ("tee", NULL);
1103 gst_object_ref (priv->video_tee);
1104 gst_object_sink (priv->video_tee);
1106 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1108 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1109 priv->bus_message_source_id = gst_bus_add_watch (bus,
1110 empathy_call_window_bus_message, self);
1112 g_object_unref (bus);
1116 empathy_call_window_settings_cb (GtkAction *action,
1117 EmpathyCallWindow *self)
1119 gchar *args = g_strdup_printf ("-p %s",
1120 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1122 empathy_launch_program (BIN_DIR, "empathy", args);
1128 empathy_call_window_contents_cb (GtkAction *action,
1129 EmpathyCallWindow *self)
1131 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1135 empathy_call_window_debug_cb (GtkAction *action,
1136 EmpathyCallWindow *self)
1138 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1142 empathy_call_window_about_cb (GtkAction *action,
1143 EmpathyCallWindow *self)
1145 empathy_about_dialog_new (GTK_WINDOW (self));
1149 empathy_call_window_toolbar_timeout (gpointer data)
1151 EmpathyCallWindow *self = data;
1153 clutter_state_set_state (self->priv->transitions, "fade-out");
1159 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1161 EmpathyCallWindow *self)
1163 clutter_state_set_state (self->priv->transitions, "fade-in");
1165 if (self->priv->inactivity_src > 0)
1166 g_source_remove (self->priv->inactivity_src);
1168 self->priv->inactivity_src = g_timeout_add_seconds (3,
1169 empathy_call_window_toolbar_timeout, self);
1175 empathy_call_window_configure_event_cb (GtkWidget *widget,
1177 EmpathyCallWindow *self)
1179 GdkWindow *gdk_window;
1180 GdkWindowState window_state;
1182 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1183 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1185 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1186 &self->priv->dialpad_width, NULL);
1188 gdk_window = gtk_widget_get_window (widget);
1189 window_state = gdk_window_get_state (gdk_window);
1190 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1196 empathy_call_window_destroyed_cb (GtkWidget *object,
1197 EmpathyCallWindow *self)
1199 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1201 /* Save the geometry as if the dialpad was hidden. */
1202 empathy_geometry_save_values (GTK_WINDOW (self),
1203 self->priv->x, self->priv->y,
1204 self->priv->w - self->priv->dialpad_width, self->priv->h,
1205 self->priv->maximized);
1210 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1212 ClutterBindConstraint *constraint)
1214 ClutterActorBox allocation;
1216 clutter_actor_get_allocation_box (stage, &allocation);
1218 clutter_bind_constraint_set_offset (constraint,
1219 allocation.y2 - allocation.y1 -
1220 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1224 empathy_call_window_init (EmpathyCallWindow *self)
1226 EmpathyCallWindowPriv *priv;
1228 GtkWidget *top_vbox;
1230 ClutterConstraint *constraint;
1231 ClutterActor *remote_avatar;
1232 GtkStyleContext *context;
1236 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1237 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1239 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1240 gui = empathy_builder_get_file (filename,
1241 "call_window_vbox", &top_vbox,
1242 "errors_vbox", &priv->errors_vbox,
1243 "pane", &priv->pane,
1244 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1245 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1246 "status_label", &priv->status_label,
1247 "audiocall", &priv->audio_call_button,
1248 "videocall", &priv->video_call_button,
1249 "microphone", &priv->mic_button,
1250 "camera", &priv->camera_button,
1251 "hangup", &priv->hangup_button,
1252 "dialpad", &priv->dialpad_button,
1253 "toolbar", &priv->toolbar,
1254 "bottom_toolbar", &priv->bottom_toolbar,
1255 "ui_manager", &priv->ui_manager,
1256 "menufullscreen", &priv->menu_fullscreen,
1257 "details_vbox", &priv->details_vbox,
1258 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1259 "acodec_encoding_label", &priv->acodec_encoding_label,
1260 "acodec_decoding_label", &priv->acodec_decoding_label,
1261 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1262 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1263 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1264 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1265 "video_local_candidate_label", &priv->video_local_candidate_label,
1266 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1267 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1268 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1269 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1273 empathy_builder_connect (gui, self,
1274 "hangup", "clicked", empathy_call_window_hangup_cb,
1275 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1276 "videocall", "clicked", empathy_call_window_video_call_cb,
1277 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1278 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1279 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1280 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1281 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1282 "menusettings", "activate", empathy_call_window_settings_cb,
1283 "menucontents", "activate", empathy_call_window_contents_cb,
1284 "menudebug", "activate", empathy_call_window_debug_cb,
1285 "menuabout", "activate", empathy_call_window_about_cb,
1286 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1287 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1288 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1291 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1293 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1295 g_object_bind_property (priv->camera_monitor, "available",
1296 priv->camera_button, "sensitive",
1297 G_BINDING_SYNC_CREATE);
1299 priv->lock = g_mutex_new ();
1301 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1303 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1304 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1305 CONTENT_HBOX_BORDER_WIDTH);
1306 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1309 /* avatar/video box */
1310 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1311 CLUTTER_BIN_ALIGNMENT_CENTER);
1313 priv->video_box = clutter_box_new (priv->video_layout);
1315 priv->video_container = gtk_clutter_embed_new ();
1317 /* Set the background color to that of the rest of the window */
1318 context = gtk_widget_get_style_context (priv->content_hbox);
1319 gtk_style_context_get_background_color (context,
1320 GTK_STATE_FLAG_NORMAL, &rgba);
1321 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1322 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1323 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1324 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1325 clutter_stage_set_color (
1326 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1327 GTK_CLUTTER_EMBED (priv->video_container))),
1330 clutter_container_add (
1331 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1332 GTK_CLUTTER_EMBED (priv->video_container))),
1336 constraint = clutter_bind_constraint_new (
1337 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1338 CLUTTER_BIND_SIZE, 0);
1339 clutter_actor_add_constraint (priv->video_box, constraint);
1341 priv->remote_user_avatar_widget = gtk_image_new ();
1342 remote_avatar = gtk_clutter_actor_new_with_contents (
1343 priv->remote_user_avatar_widget);
1345 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1348 empathy_call_window_create_preview_rectangles (self);
1350 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1351 priv->video_container, TRUE, TRUE,
1352 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1354 create_pipeline (self);
1355 create_video_output_widget (self);
1356 create_audio_input (self);
1357 create_video_input (self);
1359 priv->floating_toolbar = empathy_rounded_actor_new ();
1361 gtk_widget_reparent (priv->bottom_toolbar,
1362 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1364 constraint = clutter_bind_constraint_new (
1365 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1368 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1371 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1372 "notify::allocation",
1373 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1376 clutter_actor_set_size (priv->floating_toolbar,
1377 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1378 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1380 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1381 priv->floating_toolbar,
1382 CLUTTER_BIN_ALIGNMENT_CENTER,
1383 CLUTTER_BIN_ALIGNMENT_END);
1385 clutter_actor_raise_top (priv->floating_toolbar);
1387 /* Transitions for the floating toolbar */
1388 priv->transitions = clutter_state_new ();
1390 /* all transitions last for 2s */
1391 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1393 /* transition from any state to "fade-out" state */
1394 clutter_state_set (priv->transitions, NULL, "fade-out",
1395 priv->floating_toolbar,
1396 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1399 /* transition from any state to "fade-in" state */
1400 clutter_state_set (priv->transitions, NULL, "fade-in",
1401 priv->floating_toolbar,
1402 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1405 /* put the actor into the "fade-in" state with no animation */
1406 clutter_state_warp_to_state (priv->transitions, "fade-in");
1408 /* The call will be started as soon the pipeline is playing */
1409 priv->start_call_when_playing = TRUE;
1411 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1412 G_CALLBACK (dtmf_button_pressed_cb),
1413 G_CALLBACK (dtmf_button_released_cb));
1415 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1418 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1421 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1423 gtk_widget_show_all (top_vbox);
1425 gtk_widget_hide (priv->dtmf_panel);
1426 gtk_widget_hide (priv->details_vbox);
1428 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1430 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1431 priv->video_container);
1433 /* We hide the bottom toolbar after 3s of inactivity and show it
1434 * again on mouse movement */
1435 priv->inactivity_src = g_timeout_add_seconds (3,
1436 empathy_call_window_toolbar_timeout, self);
1438 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1439 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1441 g_signal_connect (G_OBJECT (self), "realize",
1442 G_CALLBACK (empathy_call_window_realized_cb), self);
1444 g_signal_connect (G_OBJECT (self), "delete-event",
1445 G_CALLBACK (empathy_call_window_delete_cb), self);
1447 g_signal_connect (G_OBJECT (self), "window-state-event",
1448 G_CALLBACK (empathy_call_window_state_event_cb), self);
1450 g_signal_connect (G_OBJECT (self), "key-press-event",
1451 G_CALLBACK (empathy_call_window_key_press_cb), self);
1453 g_signal_connect (self, "motion-notify-event",
1454 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1456 priv->timer = g_timer_new ();
1458 g_object_ref (priv->ui_manager);
1459 g_object_unref (gui);
1461 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1462 priv->mic_menu = empathy_mic_menu_new (self);
1464 empathy_call_window_show_hangup_button (self, TRUE);
1466 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1468 /* Retrieve initial volume */
1469 priv->volume = g_settings_get_double (priv->settings,
1470 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1472 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1473 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1475 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1476 /* These signals are used to track the window position and save it
1477 * when the window is destroyed. We need to do this as we don't want
1478 * the window geometry to be saved with the dialpad taken into account. */
1479 g_signal_connect (self, "destroy",
1480 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1481 g_signal_connect (self, "configure-event",
1482 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1483 g_signal_connect (self, "window-state-event",
1484 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1486 /* Don't display labels in both toolbars */
1487 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1490 /* Instead of specifying a width and a height, we specify only one size. That's
1491 because we want a square avatar icon. */
1493 init_contact_avatar_with_size (EmpathyContact *contact,
1494 GtkWidget *image_widget,
1497 GdkPixbuf *pixbuf_avatar = NULL;
1499 if (contact != NULL)
1501 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1505 if (pixbuf_avatar == NULL)
1507 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1508 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1511 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1513 if (pixbuf_avatar != NULL)
1514 g_object_unref (pixbuf_avatar);
1518 set_window_title (EmpathyCallWindow *self)
1520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1523 if (priv->contact != NULL)
1525 /* translators: Call is a noun and %s is the contact name. This string
1526 * is used in the window title */
1527 tmp = g_strdup_printf (_("Call with %s"),
1528 empathy_contact_get_alias (priv->contact));
1529 gtk_window_set_title (GTK_WINDOW (self), tmp);
1534 g_warning ("Unknown remote contact!");
1539 set_remote_user_name (EmpathyCallWindow *self,
1540 EmpathyContact *contact)
1542 const gchar *alias = empathy_contact_get_alias (contact);
1543 const gchar *status = empathy_contact_get_status (contact);
1546 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1547 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1553 contact_name_changed_cb (EmpathyContact *contact,
1555 EmpathyCallWindow *self)
1557 set_window_title (self);
1558 set_remote_user_name (self, contact);
1562 contact_presence_changed_cb (EmpathyContact *contact,
1564 EmpathyCallWindow *self)
1566 set_remote_user_name (self, contact);
1570 contact_avatar_changed_cb (EmpathyContact *contact,
1572 EmpathyCallWindow *self)
1575 GtkAllocation allocation;
1576 GtkWidget *avatar_widget;
1578 avatar_widget = self->priv->remote_user_avatar_widget;
1580 gtk_widget_get_allocation (avatar_widget, &allocation);
1581 size = allocation.height;
1585 /* the widget is not allocated yet, set a default size */
1586 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1587 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1590 init_contact_avatar_with_size (contact, avatar_widget, size);
1592 avatar_widget = self->priv->remote_user_avatar_toolbar;
1594 gtk_widget_get_allocation (avatar_widget, &allocation);
1595 size = allocation.height;
1599 /* the widget is not allocated yet, set a default size */
1600 size = SMALL_TOOLBAR_SIZE;
1603 init_contact_avatar_with_size (contact, avatar_widget, size);
1607 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1608 EmpathyCallHandler *handler)
1610 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1612 tp_g_signal_connect_object (priv->contact, "notify::name",
1613 G_CALLBACK (contact_name_changed_cb), self, 0);
1614 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1615 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1616 tp_g_signal_connect_object (priv->contact, "notify::presence",
1617 G_CALLBACK (contact_presence_changed_cb), self, 0);
1619 set_window_title (self);
1620 set_remote_user_name (self, priv->contact);
1622 init_contact_avatar_with_size (priv->contact,
1623 priv->remote_user_avatar_widget,
1624 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1625 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1627 init_contact_avatar_with_size (priv->contact,
1628 priv->remote_user_avatar_toolbar,
1629 SMALL_TOOLBAR_SIZE);
1631 /* The remote avatar is shown by default and will be hidden when we receive
1632 video from the remote side. */
1633 clutter_actor_hide (priv->video_output);
1634 gtk_widget_show (priv->remote_user_avatar_widget);
1638 update_send_codec (EmpathyCallWindow *self,
1641 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1648 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1649 widget = priv->acodec_encoding_label;
1653 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1654 widget = priv->vcodec_encoding_label;
1660 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1661 gtk_label_set_text (GTK_LABEL (widget), tmp);
1666 send_audio_codec_notify_cb (GObject *object,
1670 EmpathyCallWindow *self = user_data;
1672 update_send_codec (self, TRUE);
1676 send_video_codec_notify_cb (GObject *object,
1680 EmpathyCallWindow *self = user_data;
1682 update_send_codec (self, FALSE);
1686 update_recv_codec (EmpathyCallWindow *self,
1689 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1692 GString *str = NULL;
1696 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1697 widget = priv->acodec_decoding_label;
1701 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1702 widget = priv->vcodec_decoding_label;
1708 for (l = codecs; l != NULL; l = g_list_next (l))
1710 FsCodec *codec = l->data;
1713 str = g_string_new (NULL);
1715 g_string_append (str, ", ");
1717 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1721 gtk_label_set_text (GTK_LABEL (widget), str->str);
1722 g_string_free (str, TRUE);
1726 recv_audio_codecs_notify_cb (GObject *object,
1730 EmpathyCallWindow *self = user_data;
1732 update_recv_codec (self, TRUE);
1736 recv_video_codecs_notify_cb (GObject *object,
1740 EmpathyCallWindow *self = user_data;
1742 update_recv_codec (self, FALSE);
1745 static const gchar *
1746 candidate_type_to_str (FsCandidate *candidate)
1748 switch (candidate->type)
1750 case FS_CANDIDATE_TYPE_HOST:
1752 case FS_CANDIDATE_TYPE_SRFLX:
1753 return "server reflexive";
1754 case FS_CANDIDATE_TYPE_PRFLX:
1755 return "peer reflexive";
1756 case FS_CANDIDATE_TYPE_RELAY:
1758 case FS_CANDIDATE_TYPE_MULTICAST:
1765 static const gchar *
1766 candidate_type_to_desc (FsCandidate *candidate)
1768 switch (candidate->type)
1770 case FS_CANDIDATE_TYPE_HOST:
1771 return _("The IP address as seen by the machine");
1772 case FS_CANDIDATE_TYPE_SRFLX:
1773 return _("The IP address as seen by a server on the Internet");
1774 case FS_CANDIDATE_TYPE_PRFLX:
1775 return _("The IP address of the peer as seen by the other side");
1776 case FS_CANDIDATE_TYPE_RELAY:
1777 return _("The IP address of a relay server");
1778 case FS_CANDIDATE_TYPE_MULTICAST:
1779 return _("The IP address of the multicast group");
1786 update_candidat_widget (EmpathyCallWindow *self,
1789 FsCandidate *candidate)
1793 g_assert (candidate != NULL);
1794 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1795 candidate->port, candidate_type_to_str (candidate));
1797 gtk_label_set_text (GTK_LABEL (label), str);
1798 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1804 candidates_changed_cb (GObject *object,
1806 EmpathyCallWindow *self)
1808 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1809 FsCandidate *candidate = NULL;
1811 if (type == FS_MEDIA_TYPE_VIDEO)
1813 /* Update remote candidate */
1814 candidate = empathy_call_handler_get_video_remote_candidate (
1817 update_candidat_widget (self, priv->video_remote_candidate_label,
1818 priv->video_remote_candidate_info_img, candidate);
1820 /* Update local candidate */
1821 candidate = empathy_call_handler_get_video_local_candidate (
1824 update_candidat_widget (self, priv->video_local_candidate_label,
1825 priv->video_local_candidate_info_img, candidate);
1829 /* Update remote candidate */
1830 candidate = empathy_call_handler_get_audio_remote_candidate (
1833 update_candidat_widget (self, priv->audio_remote_candidate_label,
1834 priv->audio_remote_candidate_info_img, candidate);
1836 /* Update local candidate */
1837 candidate = empathy_call_handler_get_audio_local_candidate (
1840 update_candidat_widget (self, priv->audio_local_candidate_label,
1841 priv->audio_local_candidate_info_img, candidate);
1846 empathy_call_window_constructed (GObject *object)
1848 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1849 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1850 TpyCallChannel *call;
1852 g_assert (priv->handler != NULL);
1854 g_object_get (priv->handler, "call-channel", &call, NULL);
1855 priv->outgoing = (call == NULL);
1857 g_object_unref (call);
1859 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1860 g_assert (priv->contact != NULL);
1862 empathy_call_window_setup_avatars (self, priv->handler);
1863 empathy_call_window_set_state_connecting (self);
1865 if (!empathy_call_handler_has_initial_video (priv->handler))
1867 gtk_toggle_tool_button_set_active (
1868 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1870 /* If call has InitialVideo, the preview will be started once the call has
1871 * been started (start_call()). */
1873 update_send_codec (self, TRUE);
1874 update_send_codec (self, FALSE);
1875 update_recv_codec (self, TRUE);
1876 update_recv_codec (self, FALSE);
1878 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1879 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1880 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1881 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1882 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1883 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1884 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1885 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1887 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1888 G_CALLBACK (candidates_changed_cb), self, 0);
1891 static void empathy_call_window_dispose (GObject *object);
1892 static void empathy_call_window_finalize (GObject *object);
1895 empathy_call_window_set_property (GObject *object,
1896 guint property_id, const GValue *value, GParamSpec *pspec)
1898 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1900 switch (property_id)
1902 case PROP_CALL_HANDLER:
1903 priv->handler = g_value_dup_object (value);
1906 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1911 empathy_call_window_get_property (GObject *object,
1912 guint property_id, GValue *value, GParamSpec *pspec)
1914 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1916 switch (property_id)
1918 case PROP_CALL_HANDLER:
1919 g_value_set_object (value, priv->handler);
1922 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1927 empathy_call_window_class_init (
1928 EmpathyCallWindowClass *empathy_call_window_class)
1930 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1931 GParamSpec *param_spec;
1933 g_type_class_add_private (empathy_call_window_class,
1934 sizeof (EmpathyCallWindowPriv));
1936 object_class->constructed = empathy_call_window_constructed;
1937 object_class->set_property = empathy_call_window_set_property;
1938 object_class->get_property = empathy_call_window_get_property;
1940 object_class->dispose = empathy_call_window_dispose;
1941 object_class->finalize = empathy_call_window_finalize;
1943 param_spec = g_param_spec_object ("handler",
1944 "handler", "The call handler",
1945 EMPATHY_TYPE_CALL_HANDLER,
1946 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1947 g_object_class_install_property (object_class,
1948 PROP_CALL_HANDLER, param_spec);
1952 empathy_call_window_dispose (GObject *object)
1954 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1955 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1957 if (priv->dispose_has_run)
1960 priv->dispose_has_run = TRUE;
1962 if (priv->handler != NULL)
1964 empathy_call_handler_stop_call (priv->handler);
1965 tp_clear_object (&priv->handler);
1968 if (priv->bus_message_source_id != 0)
1970 g_source_remove (priv->bus_message_source_id);
1971 priv->bus_message_source_id = 0;
1974 if (priv->got_video_src > 0)
1976 g_source_remove (priv->got_video_src);
1977 priv->got_video_src = 0;
1980 if (priv->inactivity_src > 0)
1982 g_source_remove (priv->inactivity_src);
1983 priv->inactivity_src = 0;
1986 tp_clear_object (&priv->pipeline);
1987 tp_clear_object (&priv->video_input);
1988 tp_clear_object (&priv->audio_input);
1989 tp_clear_object (&priv->video_tee);
1990 tp_clear_object (&priv->ui_manager);
1991 tp_clear_object (&priv->fullscreen);
1992 tp_clear_object (&priv->camera_monitor);
1993 tp_clear_object (&priv->settings);
1994 tp_clear_object (&priv->transitions);
1996 g_list_free_full (priv->notifiers, g_object_unref);
1998 if (priv->timer_id != 0)
1999 g_source_remove (priv->timer_id);
2002 if (priv->contact != NULL)
2004 g_signal_handlers_disconnect_by_func (priv->contact,
2005 contact_name_changed_cb, self);
2006 priv->contact = NULL;
2010 tp_clear_object (&priv->sound_mgr);
2012 tp_clear_object (&priv->mic_menu);
2014 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2018 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2020 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2022 if (priv->video_output_motion_handler_id != 0)
2024 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2025 priv->video_output_motion_handler_id);
2026 priv->video_output_motion_handler_id = 0;
2031 empathy_call_window_finalize (GObject *object)
2033 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2034 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2036 disconnect_video_output_motion_handler (self);
2038 /* free any data held directly by the object here */
2039 g_mutex_free (priv->lock);
2041 g_timer_destroy (priv->timer);
2043 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2048 empathy_call_window_new (EmpathyCallHandler *handler)
2050 return EMPATHY_CALL_WINDOW (
2051 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2055 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2056 GstElement *conference, gpointer user_data)
2058 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2059 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2060 FsElementAddedNotifier *notifier;
2063 DEBUG ("Conference added");
2065 /* Add notifier to set the various element properties as needed */
2066 notifier = fs_element_added_notifier_new ();
2067 keyfile = fs_utils_get_default_element_properties (conference);
2069 if (keyfile != NULL)
2070 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2072 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2074 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2076 gst_bin_add (GST_BIN (priv->pipeline), conference);
2077 gst_element_set_state (conference, GST_STATE_PLAYING);
2081 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2082 GstElement *conference, gpointer user_data)
2084 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2085 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2087 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2088 gst_element_set_state (conference, GST_STATE_NULL);
2092 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2094 GstStateChangeReturn state_change_return;
2095 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2097 if (priv->pipeline == NULL)
2100 if (priv->bus_message_source_id != 0)
2102 g_source_remove (priv->bus_message_source_id);
2103 priv->bus_message_source_id = 0;
2106 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2108 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2109 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2111 if (priv->pipeline != NULL)
2112 g_object_unref (priv->pipeline);
2113 priv->pipeline = NULL;
2115 if (priv->audio_output != NULL)
2116 g_object_unref (priv->audio_output);
2117 priv->audio_output = NULL;
2119 if (priv->video_tee != NULL)
2120 g_object_unref (priv->video_tee);
2121 priv->video_tee = NULL;
2123 if (priv->video_preview != NULL)
2124 clutter_actor_destroy (priv->video_preview);
2125 priv->video_preview = NULL;
2127 priv->funnel = NULL;
2129 create_pipeline (self);
2130 /* Call will be started when user will hit the 'redial' button */
2131 priv->start_call_when_playing = FALSE;
2132 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2138 g_message ("Error: could not destroy pipeline. Closing call window");
2139 gtk_widget_destroy (GTK_WIDGET (self));
2146 reset_details_pane (EmpathyCallWindow *self)
2148 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2150 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2151 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2152 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2153 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2157 empathy_call_window_disconnected (EmpathyCallWindow *self,
2160 gboolean could_disconnect = FALSE;
2161 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2162 gboolean could_reset_pipeline;
2164 /* Leave full screen mode if needed */
2165 gtk_window_unfullscreen (GTK_WINDOW (self));
2167 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2168 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2170 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2172 if (priv->call_state == CONNECTING)
2173 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2175 if (priv->call_state != REDIALING)
2176 priv->call_state = DISCONNECTED;
2178 if (could_reset_pipeline)
2180 g_mutex_lock (priv->lock);
2182 g_timer_stop (priv->timer);
2184 if (priv->timer_id != 0)
2185 g_source_remove (priv->timer_id);
2188 g_mutex_unlock (priv->lock);
2191 /* We are about to destroy the window, no need to update it or create
2192 * a video preview */
2195 empathy_call_window_status_message (self, _("Disconnected"));
2197 empathy_call_window_show_hangup_button (self, FALSE);
2199 /* Unsensitive the camera and mic button */
2200 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2201 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2203 /* Be sure that the mic button is enabled */
2204 gtk_toggle_tool_button_set_active (
2205 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2207 if (priv->camera_state == CAMERA_STATE_ON)
2209 /* Restart the preview with the new pipeline. */
2210 display_video_preview (self, TRUE);
2213 /* destroy the video output; it will be recreated when we'll redial */
2214 disconnect_video_output_motion_handler (self);
2215 if (priv->video_output != NULL)
2216 clutter_actor_destroy (priv->video_output);
2217 priv->video_output = NULL;
2218 if (priv->got_video_src > 0)
2220 g_source_remove (priv->got_video_src);
2221 priv->got_video_src = 0;
2224 gtk_widget_show (priv->remote_user_avatar_widget);
2226 reset_details_pane (self);
2228 priv->sending_video = FALSE;
2229 priv->call_started = FALSE;
2231 could_disconnect = TRUE;
2233 /* TODO: display the self avatar of the preview (depends if the "Always
2234 * Show Video Preview" is enabled or not) */
2237 return could_disconnect;
2242 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2245 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2246 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2248 if (empathy_call_window_disconnected (self, TRUE) &&
2249 priv->call_state == REDIALING)
2250 empathy_call_window_restart_call (self);
2254 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2256 FsMediaType media_type,
2257 EmpathyCallWindow *self)
2259 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2261 DEBUG ("removing content");
2264 * This assumes that there is only one video stream per channel...
2267 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2269 if (priv->funnel != NULL)
2273 output = priv->video_output_sink;
2275 gst_element_set_state (output, GST_STATE_NULL);
2276 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2278 gst_bin_remove (GST_BIN (priv->pipeline), output);
2279 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2280 priv->funnel = NULL;
2284 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2286 if (priv->audio_output != NULL)
2288 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2290 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2291 priv->audio_output = NULL;
2299 /* Called with global lock held */
2301 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2303 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2307 if (priv->funnel == NULL)
2309 output = priv->video_output_sink;
2311 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2315 g_warning ("Could not create fsfunnel");
2319 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2321 gst_object_unref (priv->funnel);
2322 priv->funnel = NULL;
2323 g_warning ("Could not add funnel to pipeline");
2327 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2329 g_warning ("Could not add the video output widget to the pipeline");
2333 if (!gst_element_link (priv->funnel, output))
2335 g_warning ("Could not link output sink to funnel");
2336 goto error_output_added;
2339 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2341 g_warning ("Could not start video sink");
2342 goto error_output_added;
2345 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2347 g_warning ("Could not start funnel");
2348 goto error_output_added;
2352 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2355 g_warning ("Could not get request pad from funnel");
2362 gst_element_set_locked_state (priv->funnel, TRUE);
2363 gst_element_set_locked_state (output, TRUE);
2365 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2366 gst_element_set_state (output, GST_STATE_NULL);
2368 gst_bin_remove (GST_BIN (priv->pipeline), output);
2369 gst_element_set_locked_state (output, FALSE);
2373 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2374 priv->funnel = NULL;
2379 /* Called with global lock held */
2381 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2383 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2385 GstPadTemplate *template;
2387 if (priv->audio_output == NULL)
2389 priv->audio_output = empathy_audio_sink_new ();
2390 g_object_ref_sink (priv->audio_output);
2392 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2394 g_warning ("Could not add audio sink to pipeline");
2395 g_object_unref (priv->audio_output);
2396 goto error_add_output;
2399 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2401 g_warning ("Could not start audio sink");
2406 template = gst_element_class_get_pad_template (
2407 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2409 pad = gst_element_request_pad (priv->audio_output,
2410 template, NULL, NULL);
2414 g_warning ("Could not get sink pad from sink");
2421 gst_element_set_locked_state (priv->audio_output, TRUE);
2422 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2423 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2424 priv->audio_output = NULL;
2432 empathy_call_window_update_timer (gpointer user_data)
2434 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2435 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2436 const gchar *status;
2440 time_ = g_timer_elapsed (priv->timer, NULL);
2442 if (priv->call_state == HELD)
2443 status = _("On hold");
2444 else if (!gtk_toggle_tool_button_get_active (
2445 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2448 status = _("Duration");
2450 /* Translators: 'status - minutes:seconds' the caller has been connected */
2451 str = g_strdup_printf (_("%s — %d:%02dm"),
2453 (int) time_ / 60, (int) time_ % 60);
2454 empathy_call_window_status_message (self, str);
2462 display_error (EmpathyCallWindow *self,
2463 TpyCallChannel *call,
2467 const gchar *details)
2469 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2470 GtkWidget *info_bar;
2471 GtkWidget *content_area;
2478 /* Create info bar */
2479 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2482 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2484 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2486 /* hbox containing the image and the messages vbox */
2487 hbox = gtk_hbox_new (FALSE, 3);
2488 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2491 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2492 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2494 /* vbox containing the main message and the details expander */
2495 vbox = gtk_vbox_new (FALSE, 3);
2496 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2499 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2501 label = gtk_label_new (NULL);
2502 gtk_label_set_markup (GTK_LABEL (label), txt);
2503 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2504 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2507 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2510 if (details != NULL)
2512 GtkWidget *expander;
2514 expander = gtk_expander_new (_("Technical Details"));
2516 txt = g_strdup_printf ("<i>%s</i>", details);
2518 label = gtk_label_new (NULL);
2519 gtk_label_set_markup (GTK_LABEL (label), txt);
2520 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2521 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2524 gtk_container_add (GTK_CONTAINER (expander), label);
2525 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2528 g_signal_connect (info_bar, "response",
2529 G_CALLBACK (gtk_widget_destroy), NULL);
2531 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2532 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2533 gtk_widget_show_all (info_bar);
2537 media_stream_error_to_txt (EmpathyCallWindow *self,
2538 TpyCallChannel *call,
2540 TpMediaStreamError error)
2542 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2543 const gchar *cm = NULL;
2549 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2551 return g_strdup_printf (
2552 _("%s's software does not understand any of the audio formats "
2553 "supported by your computer"),
2554 empathy_contact_get_alias (priv->contact));
2556 return g_strdup_printf (
2557 _("%s's software does not understand any of the video formats "
2558 "supported by your computer"),
2559 empathy_contact_get_alias (priv->contact));
2561 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2562 return g_strdup_printf (
2563 _("Can't establish a connection to %s. "
2564 "One of you might be on a network that does not allow "
2565 "direct connections."),
2566 empathy_contact_get_alias (priv->contact));
2568 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2569 return g_strdup (_("There was a failure on the network"));
2571 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2573 return g_strdup (_("The audio formats necessary for this call "
2574 "are not installed on your computer"));
2576 return g_strdup (_("The video formats necessary for this call "
2577 "are not installed on your computer"));
2579 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2580 tp_connection_parse_object_path (
2581 tp_channel_borrow_connection (TP_CHANNEL (call)),
2584 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2585 "product=Telepathy&component=%s", cm);
2587 result = g_strdup_printf (
2588 _("Something unexpected happened in a Telepathy component. "
2589 "Please <a href=\"%s\">report this bug</a> and attach "
2590 "logs gathered from the 'Debug' window in the Help menu."), url);
2596 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2597 return g_strdup (_("There was a failure in the call engine"));
2599 case TP_MEDIA_STREAM_ERROR_EOS:
2600 return g_strdup (_("The end of the stream was reached"));
2602 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2609 empathy_call_window_stream_error (EmpathyCallWindow *self,
2610 TpyCallChannel *call,
2619 desc = media_stream_error_to_txt (self, call, audio, code);
2622 /* No description, use the error message. That's not great as it's not
2623 * localized but it's better than nothing. */
2624 display_error (self, call, icon, title, msg, NULL);
2628 display_error (self, call, icon, title, desc, msg);
2634 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2637 EmpathyCallWindow *self)
2639 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2640 "gnome-stock-mic", _("Can't establish audio stream"));
2644 empathy_call_window_video_stream_error (TpyCallChannel *call,
2647 EmpathyCallWindow *self)
2649 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2650 "camera-web", _("Can't establish video stream"));
2655 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2657 EmpathyCallWindow *self)
2659 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2660 TpyCallChannel *call;
2661 gboolean can_send_video;
2663 if (state != TPY_CALL_STATE_ACCEPTED)
2666 if (priv->call_state == CONNECTED)
2669 g_timer_start (priv->timer);
2670 priv->call_state = CONNECTED;
2672 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2674 can_send_video = priv->video_input != NULL &&
2675 empathy_contact_can_voip_video (priv->contact) &&
2676 empathy_camera_monitor_get_available (priv->camera_monitor);
2678 g_object_get (priv->handler, "call-channel", &call, NULL);
2680 if (tpy_call_channel_has_dtmf (call))
2681 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2683 if (priv->video_input == NULL)
2684 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2686 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2688 empathy_call_window_show_hangup_button (self, TRUE);
2690 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2692 clutter_actor_hide (priv->video_output);
2693 gtk_widget_show (priv->remote_user_avatar_widget);
2695 g_object_unref (call);
2697 g_mutex_lock (priv->lock);
2699 priv->timer_id = g_timeout_add_seconds (1,
2700 empathy_call_window_update_timer, self);
2702 g_mutex_unlock (priv->lock);
2704 empathy_call_window_update_timer (self);
2706 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2710 empathy_call_window_show_video_output_cb (gpointer user_data)
2712 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2714 if (self->priv->video_output != NULL)
2716 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2717 clutter_actor_show (self->priv->video_output);
2718 clutter_actor_raise_top (self->priv->floating_toolbar);
2725 empathy_call_window_check_video_cb (gpointer data)
2727 EmpathyCallWindow *self = data;
2729 if (self->priv->got_video)
2731 self->priv->got_video = FALSE;
2735 /* No video in the last N seconds, display the remote avatar */
2736 empathy_call_window_show_video_output (self, FALSE);
2741 /* Called from the streaming thread */
2743 empathy_call_window_video_probe_cb (GstPad *pad,
2744 GstMiniObject *mini_obj,
2745 EmpathyCallWindow *self)
2748 if (GST_IS_EVENT (mini_obj))
2751 if (G_UNLIKELY (!self->priv->got_video))
2753 /* show the remote video */
2754 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2755 empathy_call_window_show_video_output_cb,
2756 g_object_ref (self), g_object_unref);
2758 self->priv->got_video = TRUE;
2764 /* Called from the streaming thread */
2766 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2767 GstPad *src, guint media_type, gpointer user_data)
2769 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2770 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2771 gboolean retval = FALSE;
2775 g_mutex_lock (priv->lock);
2779 case TP_MEDIA_STREAM_TYPE_AUDIO:
2780 pad = empathy_call_window_get_audio_sink_pad (self);
2782 case TP_MEDIA_STREAM_TYPE_VIDEO:
2783 g_idle_add (empathy_call_window_show_video_output_cb, self);
2784 pad = empathy_call_window_get_video_sink_pad (self);
2786 gst_pad_add_data_probe (src,
2787 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2788 if (priv->got_video_src > 0)
2789 g_source_remove (priv->got_video_src);
2790 priv->got_video_src = g_timeout_add_seconds (5,
2791 empathy_call_window_check_video_cb, self);
2794 g_assert_not_reached ();
2800 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2801 g_warning ("Could not link %s sink pad",
2802 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2806 gst_object_unref (pad);
2810 /* If no sink could be linked, try to add fakesink to prevent the whole call
2815 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2817 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2819 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2820 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2821 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2823 gst_element_set_locked_state (fakesink, TRUE);
2824 gst_element_set_state (fakesink, GST_STATE_NULL);
2825 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2829 DEBUG ("Could not link real sink, linked fakesink instead");
2831 gst_object_unref (sinkpad);
2835 gst_object_unref (fakesink);
2840 g_mutex_unlock (priv->lock);
2846 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2847 GstPad *sink, FsMediaType media_type, gpointer user_data)
2849 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2850 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2852 gboolean retval = FALSE;
2856 case FS_MEDIA_TYPE_AUDIO:
2857 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2859 g_warning ("Could not add audio source to pipeline");
2863 pad = gst_element_get_static_pad (priv->audio_input, "src");
2866 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2867 g_warning ("Could not get source pad from audio source");
2871 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2873 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2874 g_warning ("Could not link audio source to farsight");
2878 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2880 g_warning ("Could not start audio source");
2881 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2882 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2888 case FS_MEDIA_TYPE_VIDEO:
2889 if (priv->video_tee != NULL)
2891 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2892 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2894 g_warning ("Could not link video source input pipeline");
2897 gst_object_unref (pad);
2903 g_assert_not_reached ();
2910 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2912 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2913 GstElement *preview;
2915 disable_camera (self);
2917 DEBUG ("remove video input");
2918 preview = priv->video_preview_sink;
2920 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2921 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2922 gst_element_set_state (preview, GST_STATE_NULL);
2924 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2927 g_object_unref (priv->video_input);
2928 priv->video_input = NULL;
2929 g_object_unref (priv->video_tee);
2930 priv->video_tee = NULL;
2931 clutter_actor_destroy (priv->video_preview);
2932 priv->video_preview = NULL;
2934 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2938 start_call (EmpathyCallWindow *self)
2940 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2942 priv->call_started = TRUE;
2943 empathy_call_handler_start_call (priv->handler,
2944 gtk_get_current_event_time ());
2946 if (empathy_call_handler_has_initial_video (priv->handler))
2948 TpyCallChannel *call;
2951 g_object_get (priv->handler, "call-channel", &call, NULL);
2952 s = tpy_call_channel_get_video_state (call);
2954 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2955 s == TPY_SENDING_STATE_SENDING)
2957 /* Enable 'send video' buttons and display the preview */
2958 gtk_toggle_tool_button_set_active (
2959 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2963 gtk_toggle_tool_button_set_active (
2964 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2966 if (priv->video_preview == NULL)
2968 create_video_preview (self);
2969 add_video_preview_to_pipeline (self);
2973 g_object_unref (call);
2978 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2981 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2982 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2985 empathy_call_handler_bus_message (priv->handler, bus, message);
2987 switch (GST_MESSAGE_TYPE (message))
2989 case GST_MESSAGE_STATE_CHANGED:
2990 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2992 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2994 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2995 !priv->call_started)
2997 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2998 if (newstate == GST_STATE_PAUSED)
3000 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3001 priv->pipeline_playing = TRUE;
3003 if (priv->start_call_when_playing)
3008 case GST_MESSAGE_ERROR:
3010 GError *error = NULL;
3011 GstElement *gst_error;
3014 gst_message_parse_error (message, &error, &debug);
3015 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3017 g_message ("Element error: %s -- %s\n", error->message, debug);
3019 if (g_str_has_prefix (gst_element_get_name (gst_error),
3020 VIDEO_INPUT_ERROR_PREFIX))
3022 /* Remove the video input and continue */
3023 if (priv->video_input != NULL)
3024 empathy_call_window_remove_video_input (self);
3025 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3029 empathy_call_window_disconnected (self, TRUE);
3031 g_error_free (error);
3034 case GST_MESSAGE_UNKNOWN:
3035 case GST_MESSAGE_EOS:
3036 case GST_MESSAGE_WARNING:
3037 case GST_MESSAGE_INFO:
3038 case GST_MESSAGE_TAG:
3039 case GST_MESSAGE_BUFFERING:
3040 case GST_MESSAGE_STATE_DIRTY:
3041 case GST_MESSAGE_STEP_DONE:
3042 case GST_MESSAGE_CLOCK_PROVIDE:
3043 case GST_MESSAGE_CLOCK_LOST:
3044 case GST_MESSAGE_NEW_CLOCK:
3045 case GST_MESSAGE_STRUCTURE_CHANGE:
3046 case GST_MESSAGE_STREAM_STATUS:
3047 case GST_MESSAGE_APPLICATION:
3048 case GST_MESSAGE_ELEMENT:
3049 case GST_MESSAGE_SEGMENT_START:
3050 case GST_MESSAGE_SEGMENT_DONE:
3051 case GST_MESSAGE_DURATION:
3052 case GST_MESSAGE_ANY:
3061 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3062 GHashTable *members,
3063 EmpathyCallWindow *self)
3065 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3066 GHashTableIter iter;
3067 gpointer key, value;
3068 gboolean held = FALSE;
3070 g_hash_table_iter_init (&iter, members);
3071 while (g_hash_table_iter_next (&iter, &key, &value))
3073 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3075 /* This assumes this is a 1-1 call, otherwise one participant
3076 * putting the call on hold wouldn't mean the call is on hold
3084 priv->call_state = HELD;
3085 else if (priv->call_state == HELD)
3086 priv->call_state = CONNECTED;
3090 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3092 EmpathyCallWindow *self)
3094 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3095 TpyCallChannel *call;
3097 g_object_get (priv->handler, "call-channel", &call, NULL);
3102 tp_g_signal_connect_object (call, "audio-stream-error",
3103 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3104 tp_g_signal_connect_object (call, "video-stream-error",
3105 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3108 tp_g_signal_connect_object (call, "members-changed",
3109 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3111 g_object_unref (call);
3115 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3117 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3118 TpyCallChannel *call;
3121 /* Make the hangup button twice as wide */
3122 width = gtk_widget_get_allocated_width (priv->hangup_button);
3123 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3125 g_signal_connect (priv->handler, "state-changed",
3126 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3127 g_signal_connect (priv->handler, "conference-added",
3128 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3129 g_signal_connect (priv->handler, "conference-removed",
3130 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3131 g_signal_connect (priv->handler, "closed",
3132 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3133 g_signal_connect (priv->handler, "src-pad-added",
3134 G_CALLBACK (empathy_call_window_src_added_cb), window);
3135 g_signal_connect (priv->handler, "sink-pad-added",
3136 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3137 g_signal_connect (priv->handler, "sink-pad-removed",
3138 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3140 g_object_get (priv->handler, "call-channel", &call, NULL);
3143 call_handler_notify_call_cb (priv->handler, NULL, window);
3144 g_object_unref (call);
3148 /* call-channel doesn't exist yet, we'll connect signals once it has been
3150 g_signal_connect (priv->handler, "notify::call-channel",
3151 G_CALLBACK (call_handler_notify_call_cb), window);
3154 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3158 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3159 EmpathyCallWindow *window)
3161 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3163 if (priv->pipeline != NULL)
3165 if (priv->bus_message_source_id != 0)
3167 g_source_remove (priv->bus_message_source_id);
3168 priv->bus_message_source_id = 0;
3171 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3174 if (priv->call_state == CONNECTING)
3175 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3181 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3184 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3186 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3191 gtk_widget_hide (priv->dtmf_panel);
3192 gtk_widget_hide (menu);
3193 gtk_widget_hide (priv->toolbar);
3197 if (priv->dialpad_was_visible_before_fs)
3198 gtk_widget_show (priv->dtmf_panel);
3200 gtk_widget_show (menu);
3201 gtk_widget_show (priv->toolbar);
3203 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3204 priv->original_height_before_fs);
3209 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3211 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3213 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3214 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3215 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3216 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3218 if (priv->video_output != NULL)
3221 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3222 priv->video_output, TRUE, TRUE,
3223 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3230 empathy_call_window_state_event_cb (GtkWidget *widget,
3231 GdkEventWindowState *event, EmpathyCallWindow *window)
3233 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3235 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3236 gboolean set_fullscreen = event->new_window_state &
3237 GDK_WINDOW_STATE_FULLSCREEN;
3241 gboolean dialpad_was_visible;
3242 GtkAllocation allocation;
3243 gint original_width, original_height;
3245 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3246 original_width = allocation.width;
3247 original_height = allocation.height;
3249 g_object_get (priv->dtmf_panel,
3250 "visible", &dialpad_was_visible,
3253 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3254 priv->original_width_before_fs = original_width;
3255 priv->original_height_before_fs = original_height;
3257 if (priv->video_output_motion_handler_id == 0 &&
3258 priv->video_output != NULL)
3260 priv->video_output_motion_handler_id = g_signal_connect (
3261 G_OBJECT (priv->video_container), "motion-notify-event",
3262 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3268 disconnect_video_output_motion_handler (window);
3271 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3273 show_controls (window, set_fullscreen);
3274 show_borders (window, set_fullscreen);
3275 gtk_action_set_stock_id (priv->menu_fullscreen,
3276 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3277 priv->is_fullscreen = set_fullscreen;
3284 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3287 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3288 int w, h, dialpad_width;
3289 GtkAllocation allocation;
3291 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3292 w = allocation.width;
3293 h = allocation.height;
3295 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3299 gtk_widget_show (priv->dtmf_panel);
3305 gtk_widget_hide (priv->dtmf_panel);
3309 gtk_window_resize (GTK_WINDOW (window), w, h);
3313 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3316 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3317 TpyCallChannel *call;
3319 priv->sending_video = (state == CAMERA_STATE_ON);
3321 if (state == CAMERA_STATE_ON)
3323 /* When we start sending video, we want to show the video preview by
3325 display_video_preview (window, TRUE);
3329 display_video_preview (window, FALSE);
3332 if (priv->call_state != CONNECTED)
3335 g_object_get (priv->handler, "call-channel", &call, NULL);
3336 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3337 tpy_call_channel_send_video (call, priv->sending_video);
3338 g_object_unref (call);
3342 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3343 EmpathyCallWindow *self)
3345 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3348 active = (gtk_toggle_tool_button_get_active (toggle));
3350 /* We don't want the settings callback to react to this change to avoid
3352 g_signal_handlers_block_by_func (priv->settings,
3353 empathy_call_window_prefs_volume_changed_cb, self);
3357 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3358 priv->volume * 100);
3362 /* TODO, Instead of setting the input volume to 0 we should probably
3363 * stop sending but this would cause the audio call to drop if both
3364 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3365 * in the future. GNOME #574574
3367 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3371 g_signal_handlers_unblock_by_func (priv->settings,
3372 empathy_call_window_prefs_volume_changed_cb, self);
3376 empathy_call_window_hangup_cb (gpointer object,
3377 EmpathyCallWindow *self)
3379 empathy_call_handler_stop_call (self->priv->handler);
3381 empathy_call_window_disconnected (self, TRUE);
3385 empathy_call_window_restart_call (EmpathyCallWindow *window)
3387 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3389 /* Remove error info bars */
3390 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3391 (GtkCallback) gtk_widget_destroy, NULL);
3393 create_video_output_widget (window);
3395 /* While the call was disconnected, the input volume might have changed.
3396 * However, since the audio_input source was destroyed, its volume has not
3397 * been updated during that time. That's why we manually update it here */
3398 empathy_call_window_mic_volume_changed (window);
3400 priv->outgoing = TRUE;
3401 empathy_call_window_set_state_connecting (window);
3403 if (priv->pipeline_playing)
3404 start_call (window);
3406 /* call will be started when the pipeline is ready */
3407 priv->start_call_when_playing = TRUE;
3409 empathy_call_window_setup_avatars (window, priv->handler);
3411 empathy_call_window_show_hangup_button (window, TRUE);
3415 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3416 EmpathyCallWindow *window)
3420 active = gtk_toggle_tool_button_get_active (button);
3422 empathy_call_window_show_dialpad (window, active);
3426 empathy_call_window_fullscreen_cb (gpointer object,
3427 EmpathyCallWindow *window)
3429 empathy_call_window_fullscreen_toggle (window);
3433 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3435 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3437 if (priv->is_fullscreen)
3438 gtk_window_unfullscreen (GTK_WINDOW (window));
3440 gtk_window_fullscreen (GTK_WINDOW (window));
3444 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3445 GdkEventButton *event, EmpathyCallWindow *window)
3447 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3449 empathy_call_window_video_menu_popup (window, event->button);
3457 empathy_call_window_key_press_cb (GtkWidget *video_output,
3458 GdkEventKey *event, EmpathyCallWindow *window)
3460 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3462 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3464 /* Since we are in fullscreen mode, toggling will bring us back to
3466 empathy_call_window_fullscreen_toggle (window);
3474 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3475 GdkEventMotion *event, EmpathyCallWindow *window)
3477 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3479 if (priv->is_fullscreen)
3481 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3483 /* Show the bottom toolbar */
3484 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3491 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3495 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3497 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3499 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3500 button, gtk_get_current_event_time ());
3501 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3505 empathy_call_window_status_message (EmpathyCallWindow *self,
3508 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3512 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3513 gdouble value, EmpathyCallWindow *window)
3515 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3517 if (priv->audio_output == NULL)
3520 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3525 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3527 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3529 return priv->ui_manager;
3532 EmpathyGstAudioSrc *
3533 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3535 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3537 return (EmpathyGstAudioSrc *) priv->audio_input;