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"
68 #include "empathy-rounded-texture.h"
69 #include "empathy-camera-menu.h"
71 #define CONTENT_HBOX_BORDER_WIDTH 6
72 #define CONTENT_HBOX_SPACING 3
73 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
75 #define SELF_VIDEO_SECTION_WIDTH 120
76 #define SELF_VIDEO_SECTION_HEIGHT 90
77 #define SELF_VIDEO_SECTION_MARGIN 10
79 #define FLOATING_TOOLBAR_OPACITY 192
80 #define FLOATING_TOOLBAR_WIDTH 280
81 #define FLOATING_TOOLBAR_HEIGHT 36
82 #define FLOATING_TOOLBAR_SPACING 20
84 /* The avatar's default width and height are set to the same value because we
85 want a square icon. */
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
88 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
101 PROP_CALL_HANDLER = 1,
113 CAMERA_STATE_OFF = 0,
119 PREVIEW_POS_TOP_LEFT,
120 PREVIEW_POS_TOP_RIGHT,
121 PREVIEW_POS_BOTTOM_LEFT,
122 PREVIEW_POS_BOTTOM_RIGHT,
125 struct _EmpathyCallWindowPriv
127 gboolean dispose_has_run;
128 EmpathyCallHandler *handler;
130 EmpathyContact *contact;
132 EmpathyCameraMonitor *camera_monitor;
137 GtkUIManager *ui_manager;
138 GtkWidget *errors_vbox;
139 /* widget displays the video received from the remote user. This widget is
140 * alive only during call. */
141 ClutterActor *video_output;
142 ClutterActor *video_preview;
143 ClutterActor *preview_shown_button;
144 ClutterActor *preview_hidden_button;
145 ClutterActor *preview_rectangle1;
146 ClutterActor *preview_rectangle2;
147 ClutterActor *preview_rectangle3;
148 ClutterActor *preview_rectangle4;
149 ClutterActor *preview_rectangle_box1;
150 ClutterActor *preview_rectangle_box2;
151 ClutterActor *preview_rectangle_box3;
152 ClutterActor *preview_rectangle_box4;
153 GtkWidget *video_container;
154 GtkWidget *remote_user_avatar_widget;
155 GtkWidget *remote_user_avatar_toolbar;
156 GtkWidget *remote_user_name_toolbar;
157 GtkWidget *status_label;
158 GtkWidget *hangup_button;
159 GtkWidget *audio_call_button;
160 GtkWidget *video_call_button;
161 GtkWidget *mic_button;
162 GtkWidget *camera_button;
163 GtkWidget *dialpad_button;
165 GtkWidget *bottom_toolbar;
166 ClutterActor *floating_toolbar;
168 GtkAction *menu_fullscreen;
169 GtkAction *menu_swap_camera;
171 ClutterState *transitions;
173 /* The box that contains self and remote avatar and video
174 input/output. When we redial, we destroy and re-create the box */
175 ClutterActor *video_box;
176 ClutterLayoutManager *video_layout;
178 /* Coordinates of the preview drag event's start. */
179 PreviewPosition preview_pos;
181 /* We keep a reference on the hbox which contains the main content so we can
182 easilly repack everything when toggling fullscreen */
183 GtkWidget *content_hbox;
185 gulong video_output_motion_handler_id;
186 guint bus_message_source_id;
190 GtkWidget *dtmf_panel;
193 GtkWidget *details_vbox;
194 GtkWidget *vcodec_encoding_label;
195 GtkWidget *acodec_encoding_label;
196 GtkWidget *vcodec_decoding_label;
197 GtkWidget *acodec_decoding_label;
199 GtkWidget *audio_remote_candidate_label;
200 GtkWidget *audio_local_candidate_label;
201 GtkWidget *video_remote_candidate_label;
202 GtkWidget *video_local_candidate_label;
203 GtkWidget *video_remote_candidate_info_img;
204 GtkWidget *video_local_candidate_info_img;
205 GtkWidget *audio_remote_candidate_info_img;
206 GtkWidget *audio_local_candidate_info_img;
208 GstElement *video_input;
209 GstElement *video_preview_sink;
210 GstElement *video_output_sink;
211 GstElement *audio_input;
212 GstElement *audio_output;
213 GstElement *pipeline;
214 GstElement *video_tee;
224 gboolean call_started;
225 gboolean sending_video;
226 CameraState camera_state;
228 EmpathyCallWindowFullscreen *fullscreen;
229 gboolean is_fullscreen;
234 guint inactivity_src;
236 /* Those fields represent the state of the window before it actually was in
238 gboolean dialpad_was_visible_before_fs;
239 gint original_width_before_fs;
240 gint original_height_before_fs;
242 gint x, y, w, h, dialpad_width;
245 /* TRUE if the call should be started when the pipeline is playing */
246 gboolean start_call_when_playing;
247 /* TRUE if we requested to set the pipeline in the playing state */
248 gboolean pipeline_playing;
250 EmpathySoundManager *sound_mgr;
253 EmpathyMicMenu *mic_menu;
254 EmpathyCameraMenu *camera_menu;
257 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
259 static void empathy_call_window_realized_cb (GtkWidget *widget,
260 EmpathyCallWindow *window);
262 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
263 GdkEvent *event, EmpathyCallWindow *window);
265 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
266 GdkEventWindowState *event, EmpathyCallWindow *window);
268 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
271 static void empathy_call_window_mic_toggled_cb (
272 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
274 static void empathy_call_window_hangup_cb (gpointer object,
275 EmpathyCallWindow *window);
277 static void empathy_call_window_fullscreen_cb (gpointer object,
278 EmpathyCallWindow *window);
280 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
282 static gboolean empathy_call_window_video_button_press_cb (
283 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
285 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
286 GdkEventKey *event, EmpathyCallWindow *window);
288 static gboolean empathy_call_window_video_output_motion_notify (
289 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
291 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
294 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
295 EmpathyCallWindow *window);
297 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
299 static void empathy_call_window_status_message (EmpathyCallWindow *window,
302 static gboolean empathy_call_window_bus_message (GstBus *bus,
303 GstMessage *message, gpointer user_data);
306 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
307 gdouble value, EmpathyCallWindow *window);
310 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
313 gtk_widget_set_visible (self->priv->hangup_button, show);
314 gtk_widget_set_visible (self->priv->audio_call_button, !show);
315 gtk_widget_set_visible (self->priv->video_call_button, !show);
319 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
320 EmpathyCallWindow *self)
322 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
323 empathy_call_window_restart_call (self);
327 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
328 EmpathyCallWindow *self)
330 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
331 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
332 empathy_call_window_restart_call (self);
336 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
338 EmpathyCallWindowPriv *priv = GET_PRIV (window);
339 TpyCallChannel *call;
343 g_object_get (priv->handler, "call-channel", &call, NULL);
345 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
346 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
349 tpy_call_channel_dtmf_start_tone (call, event);
351 g_object_unref (call);
355 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
357 EmpathyCallWindowPriv *priv = GET_PRIV (window);
358 TpyCallChannel *call;
360 g_object_get (priv->handler, "call-channel", &call, NULL);
362 tpy_call_channel_dtmf_stop_tone (call);
364 g_object_unref (call);
368 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
370 EmpathyCallWindowPriv *priv = GET_PRIV (self);
373 volume = g_settings_get_double (priv->settings,
374 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
376 /* Don't store the volume because of muting */
377 if (volume > 0 || gtk_toggle_tool_button_get_active (
378 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
379 priv->volume = volume;
381 /* Ensure that the toggle button is active if the volume is > 0 and inactive
382 * if it's smaller than 0 */
383 if ((volume > 0) != gtk_toggle_tool_button_get_active (
384 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
385 gtk_toggle_tool_button_set_active (
386 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
388 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
393 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
395 EmpathyCallWindow *self)
397 empathy_call_window_mic_volume_changed (self);
401 empathy_call_window_raise_actors (EmpathyCallWindow *self)
403 clutter_actor_raise_top (self->priv->floating_toolbar);
405 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
406 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
407 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
408 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
412 empathy_call_window_show_video_output (EmpathyCallWindow *self,
415 if (self->priv->video_output != NULL)
416 g_object_set (self->priv->video_output, "visible", show, NULL);
418 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
420 empathy_call_window_raise_actors (self);
424 create_video_output_widget (EmpathyCallWindow *self)
426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
428 g_assert (priv->video_output == NULL);
429 g_assert (priv->pipeline != NULL);
431 priv->video_output = clutter_texture_new ();
433 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
436 priv->video_output_sink = clutter_gst_video_sink_new (
437 CLUTTER_TEXTURE (priv->video_output));
439 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
442 gtk_widget_add_events (priv->video_container,
443 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
444 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
445 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
449 create_video_input (EmpathyCallWindow *self)
451 EmpathyCallWindowPriv *priv = GET_PRIV (self);
453 g_assert (priv->video_input == NULL);
454 priv->video_input = empathy_video_src_new ();
455 gst_object_ref (priv->video_input);
456 gst_object_sink (priv->video_input);
460 create_audio_input (EmpathyCallWindow *self)
462 EmpathyCallWindowPriv *priv = GET_PRIV (self);
464 g_assert (priv->audio_input == NULL);
465 priv->audio_input = empathy_audio_src_new ();
466 gst_object_ref (priv->audio_input);
467 gst_object_sink (priv->audio_input);
471 add_video_preview_to_pipeline (EmpathyCallWindow *self)
473 EmpathyCallWindowPriv *priv = GET_PRIV (self);
476 g_assert (priv->video_preview != NULL);
477 g_assert (priv->pipeline != NULL);
478 g_assert (priv->video_input != NULL);
479 g_assert (priv->video_tee != NULL);
481 preview = priv->video_preview_sink;
483 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
485 g_warning ("Could not add video input to pipeline");
489 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
491 g_warning ("Could not add video preview to pipeline");
495 if (!gst_element_link (priv->video_input, priv->video_tee))
497 g_warning ("Could not link video input to video tee");
501 if (!gst_element_link (priv->video_tee, preview))
503 g_warning ("Could not link video tee to video preview");
509 empathy_call_window_disable_camera_cb (GtkAction *action,
510 EmpathyCallWindow *self)
512 clutter_actor_destroy (self->priv->preview_hidden_button);
514 gtk_toggle_tool_button_set_active (
515 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
519 empathy_call_window_minimise_camera_cb (GtkAction *action,
520 EmpathyCallWindow *self)
522 clutter_actor_hide (self->priv->video_preview);
523 clutter_actor_show (self->priv->preview_hidden_button);
527 empathy_call_window_maximise_camera_cb (GtkAction *action,
528 EmpathyCallWindow *self)
530 clutter_actor_show (self->priv->video_preview);
531 clutter_actor_hide (self->priv->preview_hidden_button);
535 empathy_call_window_swap_camera_cb (GtkAction *action,
536 EmpathyCallWindow *self)
538 const GList *cameras, *l;
541 DEBUG ("Swapping the camera");
543 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
544 current_cam = empathy_video_src_dup_device (
545 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
547 for (l = cameras; l != NULL; l = l->next)
549 EmpathyCamera *camera = l->data;
551 if (!tp_strdiff (camera->device, current_cam))
556 next = l->next->data;
558 next = cameras->data;
560 /* EmpathyCameraMenu will update itself and do the actual change
562 g_settings_set_string (self->priv->settings,
563 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
570 g_free (current_cam);
574 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
575 EmpathyCamera *camera,
576 EmpathyCallWindow *self)
578 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
580 gtk_action_set_visible (self->priv->menu_swap_camera,
581 g_list_length ((GList *) cameras) >= 2);
585 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
586 EmpathyCamera *camera,
587 EmpathyCallWindow *self)
589 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
591 gtk_action_set_visible (self->priv->menu_swap_camera,
592 g_list_length ((GList *) cameras) >= 2);
596 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
597 EmpathyCallWindow *self)
601 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
603 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
604 0, gtk_get_current_event_time ());
605 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
609 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
610 EmpathyCallWindow *self)
614 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
615 "/preview-hidden-menu");
616 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
617 0, gtk_get_current_event_time ());
618 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
621 static ClutterActor *
622 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
624 ClutterBinAlignment x,
625 ClutterBinAlignment y)
627 ClutterLayoutManager *layout1, *layout2;
628 ClutterActor *rectangle;
629 ClutterActor *box1, *box2;
631 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
632 CLUTTER_BIN_ALIGNMENT_START);
634 box1 = clutter_box_new (layout1);
638 rectangle = clutter_rectangle_new_with_color (
639 CLUTTER_COLOR_Transparent);
641 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
644 clutter_actor_set_size (box1,
645 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
646 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
647 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
649 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
650 CLUTTER_BIN_ALIGNMENT_CENTER);
652 /* We have a box with the margins and the video in the middle inside
653 * a bigger box with an extra bottom margin so we're not on top of
654 * the floating toolbar. */
655 box2 = clutter_box_new (layout2);
657 clutter_actor_set_size (box2,
658 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
659 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
661 clutter_actor_set_size (rectangle,
662 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGHT + 5);
664 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
665 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
667 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
670 clutter_actor_hide (rectangle);
676 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
678 self->priv->preview_rectangle1 =
679 empathy_call_window_create_preview_rectangle (self,
680 &self->priv->preview_rectangle_box1,
681 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
682 self->priv->preview_rectangle2 =
683 empathy_call_window_create_preview_rectangle (self,
684 &self->priv->preview_rectangle_box2,
685 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
686 self->priv->preview_rectangle3 =
687 empathy_call_window_create_preview_rectangle (self,
688 &self->priv->preview_rectangle_box3,
689 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
690 self->priv->preview_rectangle4 =
691 empathy_call_window_create_preview_rectangle (self,
692 &self->priv->preview_rectangle_box4,
693 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
697 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
700 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
701 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
702 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
703 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
706 static PreviewPosition
707 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
712 PreviewPosition pos = PREVIEW_POS_NONE;
714 g_return_val_if_fail (clutter_actor_has_allocation (self->priv->video_box),
717 clutter_actor_get_geometry (self->priv->video_box, &box);
719 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
720 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
721 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
722 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
724 pos = PREVIEW_POS_TOP_LEFT;
726 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
727 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
728 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
729 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
731 pos = PREVIEW_POS_TOP_RIGHT;
733 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
734 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
735 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
736 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
738 pos = PREVIEW_POS_BOTTOM_LEFT;
740 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
741 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
742 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
743 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
745 pos = PREVIEW_POS_BOTTOM_RIGHT;
751 static ClutterActor *
752 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
755 ClutterActor *rectangle;
759 case PREVIEW_POS_TOP_LEFT:
760 rectangle = self->priv->preview_rectangle1;
762 case PREVIEW_POS_TOP_RIGHT:
763 rectangle = self->priv->preview_rectangle3;
765 case PREVIEW_POS_BOTTOM_LEFT:
766 rectangle = self->priv->preview_rectangle2;
768 case PREVIEW_POS_BOTTOM_RIGHT:
769 rectangle = self->priv->preview_rectangle4;
779 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
782 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
784 DEBUG ("moving the video preview to %d", pos);
786 self->priv->preview_pos = pos;
790 case PREVIEW_POS_TOP_LEFT:
791 clutter_bin_layout_set_alignment (layout,
792 self->priv->video_preview,
793 CLUTTER_BIN_ALIGNMENT_START,
794 CLUTTER_BIN_ALIGNMENT_START);
796 case PREVIEW_POS_TOP_RIGHT:
797 clutter_bin_layout_set_alignment (layout,
798 self->priv->video_preview,
799 CLUTTER_BIN_ALIGNMENT_END,
800 CLUTTER_BIN_ALIGNMENT_START);
802 case PREVIEW_POS_BOTTOM_LEFT:
803 clutter_bin_layout_set_alignment (layout,
804 self->priv->video_preview,
805 CLUTTER_BIN_ALIGNMENT_START,
806 CLUTTER_BIN_ALIGNMENT_END);
808 case PREVIEW_POS_BOTTOM_RIGHT:
809 clutter_bin_layout_set_alignment (layout,
810 self->priv->video_preview,
811 CLUTTER_BIN_ALIGNMENT_END,
812 CLUTTER_BIN_ALIGNMENT_END);
815 g_warn_if_reached ();
820 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
823 ClutterActor *rectangle;
825 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
827 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
828 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
833 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
834 ClutterActor *rectangle)
836 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
837 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
838 CLUTTER_COLOR_Black);
842 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
844 ClutterActor *rectangle;
846 rectangle = empathy_call_window_get_preview_rectangle (self,
847 self->priv->preview_pos);
849 /* We don't want to darken the rectangle where the preview
852 if (self->priv->preview_rectangle1 != rectangle)
853 empathy_call_window_darken_preview_rectangle (self,
854 self->priv->preview_rectangle1);
856 if (self->priv->preview_rectangle2 != rectangle)
857 empathy_call_window_darken_preview_rectangle (self,
858 self->priv->preview_rectangle2);
860 if (self->priv->preview_rectangle3 != rectangle)
861 empathy_call_window_darken_preview_rectangle (self,
862 self->priv->preview_rectangle3);
864 if (self->priv->preview_rectangle4 != rectangle)
865 empathy_call_window_darken_preview_rectangle (self,
866 self->priv->preview_rectangle4);
870 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
874 ClutterModifierType modifiers,
875 EmpathyCallWindow *self)
877 ClutterActor *stage = clutter_actor_get_stage (actor);
878 ClutterActor *preview = clutter_clone_new (actor);
881 /* Flip the video preview */
882 /* FIXME: disabled because it makes the drag handle to go away! */
883 clutter_actor_set_rotation (preview,
886 SELF_VIDEO_SECTION_WIDTH * 0.5,
891 clutter_container_add_actor (CLUTTER_CONTAINER (stage), preview);
892 clutter_actor_set_position (preview, event_x, event_y);
894 clutter_drag_action_set_drag_handle (action, preview);
896 clutter_actor_set_opacity (actor, 0);
897 clutter_actor_hide (self->priv->preview_shown_button);
899 empathy_call_window_show_preview_rectangles (self, TRUE);
900 empathy_call_window_darken_preview_rectangles (self);
904 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
908 ClutterModifierType modifiers,
909 EmpathyCallWindow *self)
911 ClutterActor *preview = clutter_drag_action_get_drag_handle (action);
914 /* Get the position before destroying the drag actor, otherwise the
915 * preview_box allocation won't be valid and we won't be able to
916 * calculate the position. */
917 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
919 /* Destroy the video preview copy that we were dragging */
920 clutter_actor_destroy (preview);
922 clutter_actor_set_opacity (actor, 255);
923 clutter_actor_show (self->priv->preview_shown_button);
925 if (pos != PREVIEW_POS_NONE)
926 empathy_call_window_move_video_preview (self, pos);
928 empathy_call_window_show_preview_rectangles (self, FALSE);
932 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
936 EmpathyCallWindow *self)
939 gfloat event_x, event_y;
941 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
943 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
945 if (pos != PREVIEW_POS_NONE)
946 empathy_call_window_highlight_preview_rectangle (self, pos);
948 empathy_call_window_darken_preview_rectangles (self);
952 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
953 ClutterCrossingEvent *event,
954 EmpathyCallWindow *self)
956 ClutterActor *rectangle;
958 rectangle = empathy_call_window_get_preview_rectangle (self,
959 self->priv->preview_pos);
961 empathy_call_window_highlight_preview_rectangle (self,
962 self->priv->preview_pos);
964 clutter_actor_show (rectangle);
970 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
971 ClutterCrossingEvent *event,
972 EmpathyCallWindow *self)
974 ClutterActor *rectangle;
976 rectangle = empathy_call_window_get_preview_rectangle (self,
977 self->priv->preview_pos);
979 empathy_call_window_darken_preview_rectangle (self, rectangle);
981 clutter_actor_hide (rectangle);
987 create_video_preview (EmpathyCallWindow *self)
989 EmpathyCallWindowPriv *priv = GET_PRIV (self);
990 ClutterLayoutManager *layout, *layout_center, *layout_end;
991 ClutterActor *preview;
994 ClutterAction *action;
997 g_assert (priv->video_preview == NULL);
999 preview = empathy_rounded_texture_new ();
1000 clutter_actor_set_size (preview,
1001 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1002 priv->video_preview_sink = clutter_gst_video_sink_new (
1003 CLUTTER_TEXTURE (preview));
1005 /* Flip the video preview */
1006 clutter_actor_set_rotation (preview,
1009 SELF_VIDEO_SECTION_WIDTH * 0.5,
1013 /* Add a little offset to the video preview */
1014 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1015 CLUTTER_BIN_ALIGNMENT_START);
1016 priv->video_preview = clutter_box_new (layout);
1017 clutter_actor_set_size (priv->video_preview,
1018 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1019 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1020 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1022 /* We have a box with the margins and the video in the middle inside
1023 * a bigger box with an extra bottom margin so we're not on top of
1024 * the floating toolbar. */
1025 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1026 CLUTTER_BIN_ALIGNMENT_CENTER);
1027 box = clutter_box_new (layout_center);
1028 clutter_actor_set_size (box,
1029 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1030 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1032 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1033 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1035 g_object_set (priv->video_preview_sink,
1040 /* Translators: this is an "Info" label. It should be as short
1042 button = gtk_button_new_with_label (_("i"));
1043 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1045 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1047 clutter_actor_set_size (b, 24, 24);
1049 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1050 CLUTTER_BIN_ALIGNMENT_END);
1051 box = clutter_box_new (layout_end);
1052 clutter_actor_set_size (box,
1053 SELF_VIDEO_SECTION_WIDTH,
1054 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1056 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1057 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1059 g_signal_connect (button, "clicked",
1060 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1063 /* Translators: this is an "Info" label. It should be as short
1065 button = gtk_button_new_with_label (_("i"));
1066 b = empathy_rounded_actor_new ();
1068 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1070 clutter_actor_set_size (b, 24, 24);
1071 priv->preview_hidden_button = b;
1073 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1074 priv->preview_hidden_button,
1075 CLUTTER_BIN_ALIGNMENT_START,
1076 CLUTTER_BIN_ALIGNMENT_END);
1078 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1080 clutter_actor_hide (priv->preview_hidden_button);
1082 g_signal_connect (button, "clicked",
1083 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1086 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1087 priv->video_preview,
1088 CLUTTER_BIN_ALIGNMENT_START,
1089 CLUTTER_BIN_ALIGNMENT_END);
1091 action = clutter_drag_action_new ();
1092 g_signal_connect (action, "drag-begin",
1093 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1094 g_signal_connect (action, "drag-end",
1095 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1096 g_signal_connect (action, "drag-motion",
1097 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1099 g_signal_connect (preview, "enter-event",
1100 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1101 g_signal_connect (preview, "leave-event",
1102 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1104 clutter_actor_add_action (preview, action);
1105 clutter_actor_set_reactive (preview, TRUE);
1109 play_camera (EmpathyCallWindow *window,
1112 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1113 GstElement *preview;
1116 if (priv->video_preview == NULL)
1118 create_video_preview (window);
1119 add_video_preview_to_pipeline (window);
1123 state = GST_STATE_PLAYING;
1125 state = GST_STATE_NULL;
1127 preview = priv->video_preview_sink;
1129 gst_element_set_state (preview, state);
1130 gst_element_set_state (priv->video_input, state);
1131 gst_element_set_state (priv->video_tee, state);
1135 display_video_preview (EmpathyCallWindow *self,
1138 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1142 /* Display the video preview */
1143 DEBUG ("Show video preview");
1145 play_camera (self, TRUE);
1146 clutter_actor_show (priv->video_preview);
1147 clutter_actor_raise_top (priv->floating_toolbar);
1151 /* Hide the video preview */
1152 DEBUG ("Hide video preview");
1154 if (priv->video_preview != NULL)
1156 clutter_actor_hide (priv->video_preview);
1157 play_camera (self, FALSE);
1163 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1165 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1167 empathy_call_window_status_message (window, _("Connecting…"));
1168 priv->call_state = CONNECTING;
1170 /* Show the toolbar */
1171 clutter_state_set_state (priv->transitions, "fade-in");
1174 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1175 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1179 disable_camera (EmpathyCallWindow *self)
1181 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1183 if (priv->camera_state == CAMERA_STATE_OFF)
1186 DEBUG ("Disable camera");
1188 display_video_preview (self, FALSE);
1190 if (priv->camera_state == CAMERA_STATE_ON)
1191 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1193 priv->camera_state = CAMERA_STATE_OFF;
1197 enable_camera (EmpathyCallWindow *self)
1199 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1201 if (priv->camera_state == CAMERA_STATE_ON)
1204 if (priv->video_input == NULL)
1206 DEBUG ("Can't enable camera, no input");
1210 DEBUG ("Enable camera");
1212 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1214 priv->camera_state = CAMERA_STATE_ON;
1218 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1219 EmpathyCallWindow *self)
1221 if (gtk_toggle_tool_button_get_active (toggle))
1222 enable_camera (self);
1224 disable_camera (self);
1228 create_pipeline (EmpathyCallWindow *self)
1230 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1233 g_assert (priv->pipeline == NULL);
1235 priv->pipeline = gst_pipeline_new (NULL);
1236 priv->pipeline_playing = FALSE;
1238 priv->video_tee = gst_element_factory_make ("tee", NULL);
1239 gst_object_ref (priv->video_tee);
1240 gst_object_sink (priv->video_tee);
1242 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1244 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1245 priv->bus_message_source_id = gst_bus_add_watch (bus,
1246 empathy_call_window_bus_message, self);
1248 g_object_unref (bus);
1252 empathy_call_window_settings_cb (GtkAction *action,
1253 EmpathyCallWindow *self)
1255 gchar *args = g_strdup_printf ("-p %s",
1256 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1258 empathy_launch_program (BIN_DIR, "empathy", args);
1264 empathy_call_window_contents_cb (GtkAction *action,
1265 EmpathyCallWindow *self)
1267 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1271 empathy_call_window_debug_cb (GtkAction *action,
1272 EmpathyCallWindow *self)
1274 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1278 empathy_call_window_about_cb (GtkAction *action,
1279 EmpathyCallWindow *self)
1281 empathy_about_dialog_new (GTK_WINDOW (self));
1285 empathy_call_window_toolbar_timeout (gpointer data)
1287 EmpathyCallWindow *self = data;
1289 /* We don't want to hide the toolbar if we're not in a call, as
1290 * to show the call status all the time. */
1291 if (self->priv->call_state != CONNECTING &&
1292 self->priv->call_state != DISCONNECTED)
1293 clutter_state_set_state (self->priv->transitions, "fade-out");
1299 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1301 EmpathyCallWindow *self)
1303 clutter_state_set_state (self->priv->transitions, "fade-in");
1305 if (self->priv->inactivity_src > 0)
1306 g_source_remove (self->priv->inactivity_src);
1308 self->priv->inactivity_src = g_timeout_add_seconds (3,
1309 empathy_call_window_toolbar_timeout, self);
1315 empathy_call_window_configure_event_cb (GtkWidget *widget,
1317 EmpathyCallWindow *self)
1319 GdkWindow *gdk_window;
1320 GdkWindowState window_state;
1322 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1323 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1325 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1326 &self->priv->dialpad_width, NULL);
1328 gdk_window = gtk_widget_get_window (widget);
1329 window_state = gdk_window_get_state (gdk_window);
1330 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1336 empathy_call_window_destroyed_cb (GtkWidget *object,
1337 EmpathyCallWindow *self)
1339 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1341 /* Save the geometry as if the dialpad was hidden. */
1342 empathy_geometry_save_values (GTK_WINDOW (self),
1343 self->priv->x, self->priv->y,
1344 self->priv->w - self->priv->dialpad_width, self->priv->h,
1345 self->priv->maximized);
1350 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1352 ClutterBindConstraint *constraint)
1354 ClutterActorBox allocation;
1356 clutter_actor_get_allocation_box (stage, &allocation);
1358 clutter_bind_constraint_set_offset (constraint,
1359 allocation.y2 - allocation.y1 -
1360 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1364 empathy_call_window_init (EmpathyCallWindow *self)
1366 EmpathyCallWindowPriv *priv;
1368 GtkWidget *top_vbox;
1370 ClutterConstraint *constraint;
1371 ClutterActor *remote_avatar;
1372 GtkStyleContext *context;
1376 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1377 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1379 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1380 gui = empathy_builder_get_file (filename,
1381 "call_window_vbox", &top_vbox,
1382 "errors_vbox", &priv->errors_vbox,
1383 "pane", &priv->pane,
1384 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1385 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1386 "status_label", &priv->status_label,
1387 "audiocall", &priv->audio_call_button,
1388 "videocall", &priv->video_call_button,
1389 "microphone", &priv->mic_button,
1390 "camera", &priv->camera_button,
1391 "hangup", &priv->hangup_button,
1392 "dialpad", &priv->dialpad_button,
1393 "toolbar", &priv->toolbar,
1394 "bottom_toolbar", &priv->bottom_toolbar,
1395 "ui_manager", &priv->ui_manager,
1396 "menufullscreen", &priv->menu_fullscreen,
1397 "menupreviewswap", &priv->menu_swap_camera,
1398 "details_vbox", &priv->details_vbox,
1399 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1400 "acodec_encoding_label", &priv->acodec_encoding_label,
1401 "acodec_decoding_label", &priv->acodec_decoding_label,
1402 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1403 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1404 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1405 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1406 "video_local_candidate_label", &priv->video_local_candidate_label,
1407 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1408 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1409 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1410 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1414 empathy_builder_connect (gui, self,
1415 "hangup", "clicked", empathy_call_window_hangup_cb,
1416 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1417 "videocall", "clicked", empathy_call_window_video_call_cb,
1418 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1419 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1420 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1421 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1422 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1423 "menusettings", "activate", empathy_call_window_settings_cb,
1424 "menucontents", "activate", empathy_call_window_contents_cb,
1425 "menudebug", "activate", empathy_call_window_debug_cb,
1426 "menuabout", "activate", empathy_call_window_about_cb,
1427 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1428 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1429 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1430 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1433 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1435 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1437 g_object_bind_property (priv->camera_monitor, "available",
1438 priv->camera_button, "sensitive",
1439 G_BINDING_SYNC_CREATE);
1441 g_signal_connect (priv->camera_monitor, "added",
1442 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1443 g_signal_connect (priv->camera_monitor, "removed",
1444 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1446 priv->lock = g_mutex_new ();
1448 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1450 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1451 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1452 CONTENT_HBOX_BORDER_WIDTH);
1453 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1456 /* avatar/video box */
1457 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1458 CLUTTER_BIN_ALIGNMENT_CENTER);
1460 priv->video_box = clutter_box_new (priv->video_layout);
1462 priv->video_container = gtk_clutter_embed_new ();
1464 /* Set the background color to that of the rest of the window */
1465 context = gtk_widget_get_style_context (priv->content_hbox);
1466 gtk_style_context_get_background_color (context,
1467 GTK_STATE_FLAG_NORMAL, &rgba);
1468 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1469 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1470 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1471 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1472 clutter_stage_set_color (
1473 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1474 GTK_CLUTTER_EMBED (priv->video_container))),
1477 clutter_container_add (
1478 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1479 GTK_CLUTTER_EMBED (priv->video_container))),
1483 constraint = clutter_bind_constraint_new (
1484 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1485 CLUTTER_BIND_SIZE, 0);
1486 clutter_actor_add_constraint (priv->video_box, constraint);
1488 priv->remote_user_avatar_widget = gtk_image_new ();
1489 remote_avatar = gtk_clutter_actor_new_with_contents (
1490 priv->remote_user_avatar_widget);
1492 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1495 empathy_call_window_create_preview_rectangles (self);
1497 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1498 priv->video_container, TRUE, TRUE,
1499 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1501 create_pipeline (self);
1502 create_video_output_widget (self);
1503 create_audio_input (self);
1504 create_video_input (self);
1506 priv->floating_toolbar = empathy_rounded_actor_new ();
1508 gtk_widget_reparent (priv->bottom_toolbar,
1509 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1511 constraint = clutter_bind_constraint_new (
1512 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1515 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1518 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1519 "notify::allocation",
1520 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1523 clutter_actor_set_size (priv->floating_toolbar,
1524 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1525 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1527 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1528 priv->floating_toolbar,
1529 CLUTTER_BIN_ALIGNMENT_CENTER,
1530 CLUTTER_BIN_ALIGNMENT_END);
1532 clutter_actor_raise_top (priv->floating_toolbar);
1534 /* Transitions for the floating toolbar */
1535 priv->transitions = clutter_state_new ();
1537 /* all transitions last for 2s */
1538 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1540 /* transition from any state to "fade-out" state */
1541 clutter_state_set (priv->transitions, NULL, "fade-out",
1542 priv->floating_toolbar,
1543 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1546 /* transition from any state to "fade-in" state */
1547 clutter_state_set (priv->transitions, NULL, "fade-in",
1548 priv->floating_toolbar,
1549 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1552 /* put the actor into the "fade-in" state with no animation */
1553 clutter_state_warp_to_state (priv->transitions, "fade-in");
1555 /* The call will be started as soon the pipeline is playing */
1556 priv->start_call_when_playing = TRUE;
1558 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1559 G_CALLBACK (dtmf_button_pressed_cb),
1560 G_CALLBACK (dtmf_button_released_cb));
1562 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1565 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1568 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1570 gtk_widget_show_all (top_vbox);
1572 gtk_widget_hide (priv->dtmf_panel);
1573 gtk_widget_hide (priv->details_vbox);
1575 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1577 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1578 priv->video_container);
1580 /* We hide the bottom toolbar after 3s of inactivity and show it
1581 * again on mouse movement */
1582 priv->inactivity_src = g_timeout_add_seconds (3,
1583 empathy_call_window_toolbar_timeout, self);
1585 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1586 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1588 g_signal_connect (G_OBJECT (self), "realize",
1589 G_CALLBACK (empathy_call_window_realized_cb), self);
1591 g_signal_connect (G_OBJECT (self), "delete-event",
1592 G_CALLBACK (empathy_call_window_delete_cb), self);
1594 g_signal_connect (G_OBJECT (self), "window-state-event",
1595 G_CALLBACK (empathy_call_window_state_event_cb), self);
1597 g_signal_connect (G_OBJECT (self), "key-press-event",
1598 G_CALLBACK (empathy_call_window_key_press_cb), self);
1600 g_signal_connect (self, "motion-notify-event",
1601 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1603 priv->timer = g_timer_new ();
1605 g_object_ref (priv->ui_manager);
1606 g_object_unref (gui);
1608 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1609 priv->mic_menu = empathy_mic_menu_new (self);
1610 priv->camera_menu = empathy_camera_menu_new (self);
1612 empathy_call_window_show_hangup_button (self, TRUE);
1614 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1616 /* Retrieve initial volume */
1617 priv->volume = g_settings_get_double (priv->settings,
1618 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1620 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1621 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1623 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1624 /* These signals are used to track the window position and save it
1625 * when the window is destroyed. We need to do this as we don't want
1626 * the window geometry to be saved with the dialpad taken into account. */
1627 g_signal_connect (self, "destroy",
1628 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1629 g_signal_connect (self, "configure-event",
1630 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1631 g_signal_connect (self, "window-state-event",
1632 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1634 /* Don't display labels in both toolbars */
1635 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1638 /* Instead of specifying a width and a height, we specify only one size. That's
1639 because we want a square avatar icon. */
1641 init_contact_avatar_with_size (EmpathyContact *contact,
1642 GtkWidget *image_widget,
1645 GdkPixbuf *pixbuf_avatar = NULL;
1647 if (contact != NULL)
1649 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1653 if (pixbuf_avatar == NULL)
1655 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1656 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1659 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1661 if (pixbuf_avatar != NULL)
1662 g_object_unref (pixbuf_avatar);
1666 set_window_title (EmpathyCallWindow *self)
1668 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1671 if (priv->contact != NULL)
1673 /* translators: Call is a noun and %s is the contact name. This string
1674 * is used in the window title */
1675 tmp = g_strdup_printf (_("Call with %s"),
1676 empathy_contact_get_alias (priv->contact));
1677 gtk_window_set_title (GTK_WINDOW (self), tmp);
1682 g_warning ("Unknown remote contact!");
1687 set_remote_user_name (EmpathyCallWindow *self,
1688 EmpathyContact *contact)
1690 const gchar *alias = empathy_contact_get_alias (contact);
1691 const gchar *status = empathy_contact_get_status (contact);
1694 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1695 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1701 contact_name_changed_cb (EmpathyContact *contact,
1703 EmpathyCallWindow *self)
1705 set_window_title (self);
1706 set_remote_user_name (self, contact);
1710 contact_presence_changed_cb (EmpathyContact *contact,
1712 EmpathyCallWindow *self)
1714 set_remote_user_name (self, contact);
1718 contact_avatar_changed_cb (EmpathyContact *contact,
1720 EmpathyCallWindow *self)
1723 GtkAllocation allocation;
1724 GtkWidget *avatar_widget;
1726 avatar_widget = self->priv->remote_user_avatar_widget;
1728 gtk_widget_get_allocation (avatar_widget, &allocation);
1729 size = allocation.height;
1733 /* the widget is not allocated yet, set a default size */
1734 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1735 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1738 init_contact_avatar_with_size (contact, avatar_widget, size);
1740 avatar_widget = self->priv->remote_user_avatar_toolbar;
1742 gtk_widget_get_allocation (avatar_widget, &allocation);
1743 size = allocation.height;
1747 /* the widget is not allocated yet, set a default size */
1748 size = SMALL_TOOLBAR_SIZE;
1751 init_contact_avatar_with_size (contact, avatar_widget, size);
1755 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1756 EmpathyCallHandler *handler)
1758 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1760 tp_g_signal_connect_object (priv->contact, "notify::name",
1761 G_CALLBACK (contact_name_changed_cb), self, 0);
1762 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1763 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1764 tp_g_signal_connect_object (priv->contact, "notify::presence",
1765 G_CALLBACK (contact_presence_changed_cb), self, 0);
1767 set_window_title (self);
1768 set_remote_user_name (self, priv->contact);
1770 init_contact_avatar_with_size (priv->contact,
1771 priv->remote_user_avatar_widget,
1772 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1773 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1775 init_contact_avatar_with_size (priv->contact,
1776 priv->remote_user_avatar_toolbar,
1777 SMALL_TOOLBAR_SIZE);
1779 /* The remote avatar is shown by default and will be hidden when we receive
1780 video from the remote side. */
1781 clutter_actor_hide (priv->video_output);
1782 gtk_widget_show (priv->remote_user_avatar_widget);
1786 update_send_codec (EmpathyCallWindow *self,
1789 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1796 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1797 widget = priv->acodec_encoding_label;
1801 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1802 widget = priv->vcodec_encoding_label;
1808 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1809 gtk_label_set_text (GTK_LABEL (widget), tmp);
1814 send_audio_codec_notify_cb (GObject *object,
1818 EmpathyCallWindow *self = user_data;
1820 update_send_codec (self, TRUE);
1824 send_video_codec_notify_cb (GObject *object,
1828 EmpathyCallWindow *self = user_data;
1830 update_send_codec (self, FALSE);
1834 update_recv_codec (EmpathyCallWindow *self,
1837 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1840 GString *str = NULL;
1844 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1845 widget = priv->acodec_decoding_label;
1849 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1850 widget = priv->vcodec_decoding_label;
1856 for (l = codecs; l != NULL; l = g_list_next (l))
1858 FsCodec *codec = l->data;
1861 str = g_string_new (NULL);
1863 g_string_append (str, ", ");
1865 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1869 gtk_label_set_text (GTK_LABEL (widget), str->str);
1870 g_string_free (str, TRUE);
1874 recv_audio_codecs_notify_cb (GObject *object,
1878 EmpathyCallWindow *self = user_data;
1880 update_recv_codec (self, TRUE);
1884 recv_video_codecs_notify_cb (GObject *object,
1888 EmpathyCallWindow *self = user_data;
1890 update_recv_codec (self, FALSE);
1893 static const gchar *
1894 candidate_type_to_str (FsCandidate *candidate)
1896 switch (candidate->type)
1898 case FS_CANDIDATE_TYPE_HOST:
1900 case FS_CANDIDATE_TYPE_SRFLX:
1901 return "server reflexive";
1902 case FS_CANDIDATE_TYPE_PRFLX:
1903 return "peer reflexive";
1904 case FS_CANDIDATE_TYPE_RELAY:
1906 case FS_CANDIDATE_TYPE_MULTICAST:
1913 static const gchar *
1914 candidate_type_to_desc (FsCandidate *candidate)
1916 switch (candidate->type)
1918 case FS_CANDIDATE_TYPE_HOST:
1919 return _("The IP address as seen by the machine");
1920 case FS_CANDIDATE_TYPE_SRFLX:
1921 return _("The IP address as seen by a server on the Internet");
1922 case FS_CANDIDATE_TYPE_PRFLX:
1923 return _("The IP address of the peer as seen by the other side");
1924 case FS_CANDIDATE_TYPE_RELAY:
1925 return _("The IP address of a relay server");
1926 case FS_CANDIDATE_TYPE_MULTICAST:
1927 return _("The IP address of the multicast group");
1934 update_candidat_widget (EmpathyCallWindow *self,
1937 FsCandidate *candidate)
1941 g_assert (candidate != NULL);
1942 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1943 candidate->port, candidate_type_to_str (candidate));
1945 gtk_label_set_text (GTK_LABEL (label), str);
1946 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1952 candidates_changed_cb (GObject *object,
1954 EmpathyCallWindow *self)
1956 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1957 FsCandidate *candidate = NULL;
1959 if (type == FS_MEDIA_TYPE_VIDEO)
1961 /* Update remote candidate */
1962 candidate = empathy_call_handler_get_video_remote_candidate (
1965 update_candidat_widget (self, priv->video_remote_candidate_label,
1966 priv->video_remote_candidate_info_img, candidate);
1968 /* Update local candidate */
1969 candidate = empathy_call_handler_get_video_local_candidate (
1972 update_candidat_widget (self, priv->video_local_candidate_label,
1973 priv->video_local_candidate_info_img, candidate);
1977 /* Update remote candidate */
1978 candidate = empathy_call_handler_get_audio_remote_candidate (
1981 update_candidat_widget (self, priv->audio_remote_candidate_label,
1982 priv->audio_remote_candidate_info_img, candidate);
1984 /* Update local candidate */
1985 candidate = empathy_call_handler_get_audio_local_candidate (
1988 update_candidat_widget (self, priv->audio_local_candidate_label,
1989 priv->audio_local_candidate_info_img, candidate);
1994 empathy_call_window_constructed (GObject *object)
1996 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1997 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1998 TpyCallChannel *call;
2000 g_assert (priv->handler != NULL);
2002 g_object_get (priv->handler, "call-channel", &call, NULL);
2003 priv->outgoing = (call == NULL);
2005 g_object_unref (call);
2007 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2008 g_assert (priv->contact != NULL);
2010 empathy_call_window_setup_avatars (self, priv->handler);
2011 empathy_call_window_set_state_connecting (self);
2013 if (!empathy_call_handler_has_initial_video (priv->handler))
2015 gtk_toggle_tool_button_set_active (
2016 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2018 /* If call has InitialVideo, the preview will be started once the call has
2019 * been started (start_call()). */
2021 update_send_codec (self, TRUE);
2022 update_send_codec (self, FALSE);
2023 update_recv_codec (self, TRUE);
2024 update_recv_codec (self, FALSE);
2026 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2027 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2028 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2029 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2030 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2031 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2032 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2033 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2035 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2036 G_CALLBACK (candidates_changed_cb), self, 0);
2039 static void empathy_call_window_dispose (GObject *object);
2040 static void empathy_call_window_finalize (GObject *object);
2043 empathy_call_window_set_property (GObject *object,
2044 guint property_id, const GValue *value, GParamSpec *pspec)
2046 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2048 switch (property_id)
2050 case PROP_CALL_HANDLER:
2051 priv->handler = g_value_dup_object (value);
2054 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2059 empathy_call_window_get_property (GObject *object,
2060 guint property_id, GValue *value, GParamSpec *pspec)
2062 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2064 switch (property_id)
2066 case PROP_CALL_HANDLER:
2067 g_value_set_object (value, priv->handler);
2070 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2075 empathy_call_window_class_init (
2076 EmpathyCallWindowClass *empathy_call_window_class)
2078 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2079 GParamSpec *param_spec;
2081 g_type_class_add_private (empathy_call_window_class,
2082 sizeof (EmpathyCallWindowPriv));
2084 object_class->constructed = empathy_call_window_constructed;
2085 object_class->set_property = empathy_call_window_set_property;
2086 object_class->get_property = empathy_call_window_get_property;
2088 object_class->dispose = empathy_call_window_dispose;
2089 object_class->finalize = empathy_call_window_finalize;
2091 param_spec = g_param_spec_object ("handler",
2092 "handler", "The call handler",
2093 EMPATHY_TYPE_CALL_HANDLER,
2094 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2095 g_object_class_install_property (object_class,
2096 PROP_CALL_HANDLER, param_spec);
2100 empathy_call_window_dispose (GObject *object)
2102 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2103 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2105 if (priv->dispose_has_run)
2108 priv->dispose_has_run = TRUE;
2110 if (priv->handler != NULL)
2112 empathy_call_handler_stop_call (priv->handler);
2113 tp_clear_object (&priv->handler);
2116 if (priv->bus_message_source_id != 0)
2118 g_source_remove (priv->bus_message_source_id);
2119 priv->bus_message_source_id = 0;
2122 if (priv->got_video_src > 0)
2124 g_source_remove (priv->got_video_src);
2125 priv->got_video_src = 0;
2128 if (priv->inactivity_src > 0)
2130 g_source_remove (priv->inactivity_src);
2131 priv->inactivity_src = 0;
2134 tp_clear_object (&priv->pipeline);
2135 tp_clear_object (&priv->video_input);
2136 tp_clear_object (&priv->audio_input);
2137 tp_clear_object (&priv->video_tee);
2138 tp_clear_object (&priv->ui_manager);
2139 tp_clear_object (&priv->fullscreen);
2140 tp_clear_object (&priv->camera_monitor);
2141 tp_clear_object (&priv->settings);
2142 tp_clear_object (&priv->sound_mgr);
2143 tp_clear_object (&priv->mic_menu);
2144 tp_clear_object (&priv->camera_menu);
2146 g_list_free_full (priv->notifiers, g_object_unref);
2148 if (priv->timer_id != 0)
2149 g_source_remove (priv->timer_id);
2152 if (priv->contact != NULL)
2154 g_signal_handlers_disconnect_by_func (priv->contact,
2155 contact_name_changed_cb, self);
2156 priv->contact = NULL;
2159 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2163 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2165 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2167 if (priv->video_output_motion_handler_id != 0)
2169 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2170 priv->video_output_motion_handler_id);
2171 priv->video_output_motion_handler_id = 0;
2176 empathy_call_window_finalize (GObject *object)
2178 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2179 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2181 disconnect_video_output_motion_handler (self);
2183 /* free any data held directly by the object here */
2184 g_mutex_free (priv->lock);
2186 g_timer_destroy (priv->timer);
2188 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2193 empathy_call_window_new (EmpathyCallHandler *handler)
2195 return EMPATHY_CALL_WINDOW (
2196 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2200 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2201 GstElement *conference, gpointer user_data)
2203 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2204 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2205 FsElementAddedNotifier *notifier;
2208 DEBUG ("Conference added");
2210 /* Add notifier to set the various element properties as needed */
2211 notifier = fs_element_added_notifier_new ();
2212 keyfile = fs_utils_get_default_element_properties (conference);
2214 if (keyfile != NULL)
2215 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2217 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2219 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2221 gst_bin_add (GST_BIN (priv->pipeline), conference);
2222 gst_element_set_state (conference, GST_STATE_PLAYING);
2226 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2227 GstElement *conference, gpointer user_data)
2229 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2230 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2232 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2233 gst_element_set_state (conference, GST_STATE_NULL);
2237 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2239 GstStateChangeReturn state_change_return;
2240 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2242 if (priv->pipeline == NULL)
2245 if (priv->bus_message_source_id != 0)
2247 g_source_remove (priv->bus_message_source_id);
2248 priv->bus_message_source_id = 0;
2251 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2253 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2254 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2256 if (priv->pipeline != NULL)
2257 g_object_unref (priv->pipeline);
2258 priv->pipeline = NULL;
2260 if (priv->audio_output != NULL)
2261 g_object_unref (priv->audio_output);
2262 priv->audio_output = NULL;
2264 if (priv->video_tee != NULL)
2265 g_object_unref (priv->video_tee);
2266 priv->video_tee = NULL;
2268 if (priv->video_preview != NULL)
2269 clutter_actor_destroy (priv->video_preview);
2270 priv->video_preview = NULL;
2272 priv->funnel = NULL;
2274 create_pipeline (self);
2275 /* Call will be started when user will hit the 'redial' button */
2276 priv->start_call_when_playing = FALSE;
2277 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2283 g_message ("Error: could not destroy pipeline. Closing call window");
2284 gtk_widget_destroy (GTK_WIDGET (self));
2291 reset_details_pane (EmpathyCallWindow *self)
2293 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2295 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2296 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2297 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2298 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2302 empathy_call_window_disconnected (EmpathyCallWindow *self,
2305 gboolean could_disconnect = FALSE;
2306 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2307 gboolean could_reset_pipeline;
2309 /* Leave full screen mode if needed */
2310 gtk_window_unfullscreen (GTK_WINDOW (self));
2312 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2313 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2315 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2317 if (priv->call_state == CONNECTING)
2318 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2320 if (priv->call_state != REDIALING)
2321 priv->call_state = DISCONNECTED;
2323 /* Show the toolbar */
2324 clutter_state_set_state (priv->transitions, "fade-in");
2326 if (could_reset_pipeline)
2328 g_mutex_lock (priv->lock);
2330 g_timer_stop (priv->timer);
2332 if (priv->timer_id != 0)
2333 g_source_remove (priv->timer_id);
2336 g_mutex_unlock (priv->lock);
2339 /* We are about to destroy the window, no need to update it or create
2340 * a video preview */
2343 empathy_call_window_status_message (self, _("Disconnected"));
2345 empathy_call_window_show_hangup_button (self, FALSE);
2347 /* Unsensitive the camera and mic button */
2348 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2349 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2351 /* Be sure that the mic button is enabled */
2352 gtk_toggle_tool_button_set_active (
2353 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2355 if (priv->camera_state == CAMERA_STATE_ON)
2357 /* Restart the preview with the new pipeline. */
2358 display_video_preview (self, TRUE);
2361 /* destroy the video output; it will be recreated when we'll redial */
2362 disconnect_video_output_motion_handler (self);
2363 if (priv->video_output != NULL)
2364 clutter_actor_destroy (priv->video_output);
2365 priv->video_output = NULL;
2366 if (priv->got_video_src > 0)
2368 g_source_remove (priv->got_video_src);
2369 priv->got_video_src = 0;
2372 gtk_widget_show (priv->remote_user_avatar_widget);
2374 reset_details_pane (self);
2376 priv->sending_video = FALSE;
2377 priv->call_started = FALSE;
2379 could_disconnect = TRUE;
2381 /* TODO: display the self avatar of the preview (depends if the "Always
2382 * Show Video Preview" is enabled or not) */
2385 return could_disconnect;
2390 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2393 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2394 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2396 if (empathy_call_window_disconnected (self, TRUE) &&
2397 priv->call_state == REDIALING)
2398 empathy_call_window_restart_call (self);
2402 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2404 FsMediaType media_type,
2405 EmpathyCallWindow *self)
2407 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2409 DEBUG ("removing content");
2412 * This assumes that there is only one video stream per channel...
2415 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2417 if (priv->funnel != NULL)
2421 output = priv->video_output_sink;
2423 gst_element_set_state (output, GST_STATE_NULL);
2424 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2426 gst_bin_remove (GST_BIN (priv->pipeline), output);
2427 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2428 priv->funnel = NULL;
2432 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2434 if (priv->audio_output != NULL)
2436 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2438 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2439 priv->audio_output = NULL;
2447 /* Called with global lock held */
2449 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2451 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2455 if (priv->funnel == NULL)
2457 output = priv->video_output_sink;
2459 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2463 g_warning ("Could not create fsfunnel");
2467 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2469 gst_object_unref (priv->funnel);
2470 priv->funnel = NULL;
2471 g_warning ("Could not add funnel to pipeline");
2475 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2477 g_warning ("Could not add the video output widget to the pipeline");
2481 if (!gst_element_link (priv->funnel, output))
2483 g_warning ("Could not link output sink to funnel");
2484 goto error_output_added;
2487 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2489 g_warning ("Could not start video sink");
2490 goto error_output_added;
2493 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2495 g_warning ("Could not start funnel");
2496 goto error_output_added;
2500 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2503 g_warning ("Could not get request pad from funnel");
2510 gst_element_set_locked_state (priv->funnel, TRUE);
2511 gst_element_set_locked_state (output, TRUE);
2513 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2514 gst_element_set_state (output, GST_STATE_NULL);
2516 gst_bin_remove (GST_BIN (priv->pipeline), output);
2517 gst_element_set_locked_state (output, FALSE);
2521 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2522 priv->funnel = NULL;
2527 /* Called with global lock held */
2529 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2531 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2533 GstPadTemplate *template;
2535 if (priv->audio_output == NULL)
2537 priv->audio_output = empathy_audio_sink_new ();
2538 g_object_ref_sink (priv->audio_output);
2540 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2542 g_warning ("Could not add audio sink to pipeline");
2543 g_object_unref (priv->audio_output);
2544 goto error_add_output;
2547 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2549 g_warning ("Could not start audio sink");
2554 template = gst_element_class_get_pad_template (
2555 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2557 pad = gst_element_request_pad (priv->audio_output,
2558 template, NULL, NULL);
2562 g_warning ("Could not get sink pad from sink");
2569 gst_element_set_locked_state (priv->audio_output, TRUE);
2570 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2571 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2572 priv->audio_output = NULL;
2580 empathy_call_window_update_timer (gpointer user_data)
2582 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2583 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2584 const gchar *status;
2588 time_ = g_timer_elapsed (priv->timer, NULL);
2590 if (priv->call_state == HELD)
2591 status = _("On hold");
2592 else if (!gtk_toggle_tool_button_get_active (
2593 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2596 status = _("Duration");
2598 /* Translators: 'status - minutes:seconds' the caller has been connected */
2599 str = g_strdup_printf (_("%s — %d:%02dm"),
2601 (int) time_ / 60, (int) time_ % 60);
2602 empathy_call_window_status_message (self, str);
2610 display_error (EmpathyCallWindow *self,
2611 TpyCallChannel *call,
2615 const gchar *details)
2617 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2618 GtkWidget *info_bar;
2619 GtkWidget *content_area;
2626 /* Create info bar */
2627 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2630 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2632 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2634 /* hbox containing the image and the messages vbox */
2635 hbox = gtk_hbox_new (FALSE, 3);
2636 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2639 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2640 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2642 /* vbox containing the main message and the details expander */
2643 vbox = gtk_vbox_new (FALSE, 3);
2644 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2647 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2649 label = gtk_label_new (NULL);
2650 gtk_label_set_markup (GTK_LABEL (label), txt);
2651 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2652 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2655 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2658 if (details != NULL)
2660 GtkWidget *expander;
2662 expander = gtk_expander_new (_("Technical Details"));
2664 txt = g_strdup_printf ("<i>%s</i>", details);
2666 label = gtk_label_new (NULL);
2667 gtk_label_set_markup (GTK_LABEL (label), txt);
2668 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2669 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2672 gtk_container_add (GTK_CONTAINER (expander), label);
2673 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2676 g_signal_connect (info_bar, "response",
2677 G_CALLBACK (gtk_widget_destroy), NULL);
2679 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2680 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2681 gtk_widget_show_all (info_bar);
2685 media_stream_error_to_txt (EmpathyCallWindow *self,
2686 TpyCallChannel *call,
2688 TpMediaStreamError error)
2690 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2691 const gchar *cm = NULL;
2697 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2699 return g_strdup_printf (
2700 _("%s's software does not understand any of the audio formats "
2701 "supported by your computer"),
2702 empathy_contact_get_alias (priv->contact));
2704 return g_strdup_printf (
2705 _("%s's software does not understand any of the video formats "
2706 "supported by your computer"),
2707 empathy_contact_get_alias (priv->contact));
2709 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2710 return g_strdup_printf (
2711 _("Can't establish a connection to %s. "
2712 "One of you might be on a network that does not allow "
2713 "direct connections."),
2714 empathy_contact_get_alias (priv->contact));
2716 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2717 return g_strdup (_("There was a failure on the network"));
2719 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2721 return g_strdup (_("The audio formats necessary for this call "
2722 "are not installed on your computer"));
2724 return g_strdup (_("The video formats necessary for this call "
2725 "are not installed on your computer"));
2727 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2728 tp_connection_parse_object_path (
2729 tp_channel_borrow_connection (TP_CHANNEL (call)),
2732 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2733 "product=Telepathy&component=%s", cm);
2735 result = g_strdup_printf (
2736 _("Something unexpected happened in a Telepathy component. "
2737 "Please <a href=\"%s\">report this bug</a> and attach "
2738 "logs gathered from the 'Debug' window in the Help menu."), url);
2744 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2745 return g_strdup (_("There was a failure in the call engine"));
2747 case TP_MEDIA_STREAM_ERROR_EOS:
2748 return g_strdup (_("The end of the stream was reached"));
2750 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2757 empathy_call_window_stream_error (EmpathyCallWindow *self,
2758 TpyCallChannel *call,
2767 desc = media_stream_error_to_txt (self, call, audio, code);
2770 /* No description, use the error message. That's not great as it's not
2771 * localized but it's better than nothing. */
2772 display_error (self, call, icon, title, msg, NULL);
2776 display_error (self, call, icon, title, desc, msg);
2782 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2785 EmpathyCallWindow *self)
2787 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2788 "gnome-stock-mic", _("Can't establish audio stream"));
2792 empathy_call_window_video_stream_error (TpyCallChannel *call,
2795 EmpathyCallWindow *self)
2797 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2798 "camera-web", _("Can't establish video stream"));
2803 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2805 EmpathyCallWindow *self)
2807 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2808 TpyCallChannel *call;
2809 gboolean can_send_video;
2811 if (state != TPY_CALL_STATE_ACCEPTED)
2814 if (priv->call_state == CONNECTED)
2817 g_timer_start (priv->timer);
2818 priv->call_state = CONNECTED;
2820 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2822 can_send_video = priv->video_input != NULL &&
2823 empathy_contact_can_voip_video (priv->contact) &&
2824 empathy_camera_monitor_get_available (priv->camera_monitor);
2826 g_object_get (priv->handler, "call-channel", &call, NULL);
2828 if (tpy_call_channel_has_dtmf (call))
2829 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2831 if (priv->video_input == NULL)
2832 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2834 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2836 empathy_call_window_show_hangup_button (self, TRUE);
2838 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2840 clutter_actor_hide (priv->video_output);
2841 gtk_widget_show (priv->remote_user_avatar_widget);
2843 g_object_unref (call);
2845 g_mutex_lock (priv->lock);
2847 priv->timer_id = g_timeout_add_seconds (1,
2848 empathy_call_window_update_timer, self);
2850 g_mutex_unlock (priv->lock);
2852 empathy_call_window_update_timer (self);
2854 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2858 empathy_call_window_show_video_output_cb (gpointer user_data)
2860 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2862 if (self->priv->video_output != NULL)
2864 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2865 clutter_actor_show (self->priv->video_output);
2866 empathy_call_window_raise_actors (self);
2873 empathy_call_window_check_video_cb (gpointer data)
2875 EmpathyCallWindow *self = data;
2877 if (self->priv->got_video)
2879 self->priv->got_video = FALSE;
2883 /* No video in the last N seconds, display the remote avatar */
2884 empathy_call_window_show_video_output (self, FALSE);
2889 /* Called from the streaming thread */
2891 empathy_call_window_video_probe_cb (GstPad *pad,
2892 GstMiniObject *mini_obj,
2893 EmpathyCallWindow *self)
2896 if (GST_IS_EVENT (mini_obj))
2899 if (G_UNLIKELY (!self->priv->got_video))
2901 /* show the remote video */
2902 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2903 empathy_call_window_show_video_output_cb,
2904 g_object_ref (self), g_object_unref);
2906 self->priv->got_video = TRUE;
2912 /* Called from the streaming thread */
2914 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2915 GstPad *src, guint media_type, gpointer user_data)
2917 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2918 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2919 gboolean retval = FALSE;
2923 g_mutex_lock (priv->lock);
2927 case TP_MEDIA_STREAM_TYPE_AUDIO:
2928 pad = empathy_call_window_get_audio_sink_pad (self);
2930 case TP_MEDIA_STREAM_TYPE_VIDEO:
2931 g_idle_add (empathy_call_window_show_video_output_cb, self);
2932 pad = empathy_call_window_get_video_sink_pad (self);
2934 gst_pad_add_data_probe (src,
2935 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2936 if (priv->got_video_src > 0)
2937 g_source_remove (priv->got_video_src);
2938 priv->got_video_src = g_timeout_add_seconds (5,
2939 empathy_call_window_check_video_cb, self);
2942 g_assert_not_reached ();
2948 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2949 g_warning ("Could not link %s sink pad",
2950 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2954 gst_object_unref (pad);
2958 /* If no sink could be linked, try to add fakesink to prevent the whole call
2963 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2965 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2967 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2968 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2969 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2971 gst_element_set_locked_state (fakesink, TRUE);
2972 gst_element_set_state (fakesink, GST_STATE_NULL);
2973 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2977 DEBUG ("Could not link real sink, linked fakesink instead");
2979 gst_object_unref (sinkpad);
2983 gst_object_unref (fakesink);
2988 g_mutex_unlock (priv->lock);
2994 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2995 GstPad *sink, FsMediaType media_type, gpointer user_data)
2997 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2998 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3000 gboolean retval = FALSE;
3004 case FS_MEDIA_TYPE_AUDIO:
3005 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3007 g_warning ("Could not add audio source to pipeline");
3011 pad = gst_element_get_static_pad (priv->audio_input, "src");
3014 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3015 g_warning ("Could not get source pad from audio source");
3019 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3021 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3022 g_warning ("Could not link audio source to farsight");
3026 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3028 g_warning ("Could not start audio source");
3029 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3030 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3036 case FS_MEDIA_TYPE_VIDEO:
3037 if (priv->video_tee != NULL)
3039 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3040 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3042 g_warning ("Could not link video source input pipeline");
3045 gst_object_unref (pad);
3051 g_assert_not_reached ();
3058 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3060 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3061 GstElement *preview;
3063 disable_camera (self);
3065 DEBUG ("remove video input");
3066 preview = priv->video_preview_sink;
3068 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3069 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3070 gst_element_set_state (preview, GST_STATE_NULL);
3072 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3075 g_object_unref (priv->video_input);
3076 priv->video_input = NULL;
3077 g_object_unref (priv->video_tee);
3078 priv->video_tee = NULL;
3079 clutter_actor_destroy (priv->video_preview);
3080 priv->video_preview = NULL;
3082 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3086 start_call (EmpathyCallWindow *self)
3088 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3090 priv->call_started = TRUE;
3091 empathy_call_handler_start_call (priv->handler,
3092 gtk_get_current_event_time ());
3094 if (empathy_call_handler_has_initial_video (priv->handler))
3096 TpyCallChannel *call;
3099 g_object_get (priv->handler, "call-channel", &call, NULL);
3100 s = tpy_call_channel_get_video_state (call);
3102 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3103 s == TPY_SENDING_STATE_SENDING)
3105 /* Enable 'send video' buttons and display the preview */
3106 gtk_toggle_tool_button_set_active (
3107 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3111 gtk_toggle_tool_button_set_active (
3112 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3114 if (priv->video_preview == NULL)
3116 create_video_preview (self);
3117 add_video_preview_to_pipeline (self);
3121 g_object_unref (call);
3126 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3129 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3130 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3133 empathy_call_handler_bus_message (priv->handler, bus, message);
3135 switch (GST_MESSAGE_TYPE (message))
3137 case GST_MESSAGE_STATE_CHANGED:
3138 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3140 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3142 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3143 !priv->call_started)
3145 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3146 if (newstate == GST_STATE_PAUSED)
3148 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3149 priv->pipeline_playing = TRUE;
3151 if (priv->start_call_when_playing)
3156 case GST_MESSAGE_ERROR:
3158 GError *error = NULL;
3159 GstElement *gst_error;
3162 gst_message_parse_error (message, &error, &debug);
3163 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3165 g_message ("Element error: %s -- %s\n", error->message, debug);
3167 if (g_str_has_prefix (gst_element_get_name (gst_error),
3168 VIDEO_INPUT_ERROR_PREFIX))
3170 /* Remove the video input and continue */
3171 if (priv->video_input != NULL)
3172 empathy_call_window_remove_video_input (self);
3173 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3177 empathy_call_window_disconnected (self, TRUE);
3179 g_error_free (error);
3182 case GST_MESSAGE_UNKNOWN:
3183 case GST_MESSAGE_EOS:
3184 case GST_MESSAGE_WARNING:
3185 case GST_MESSAGE_INFO:
3186 case GST_MESSAGE_TAG:
3187 case GST_MESSAGE_BUFFERING:
3188 case GST_MESSAGE_STATE_DIRTY:
3189 case GST_MESSAGE_STEP_DONE:
3190 case GST_MESSAGE_CLOCK_PROVIDE:
3191 case GST_MESSAGE_CLOCK_LOST:
3192 case GST_MESSAGE_NEW_CLOCK:
3193 case GST_MESSAGE_STRUCTURE_CHANGE:
3194 case GST_MESSAGE_STREAM_STATUS:
3195 case GST_MESSAGE_APPLICATION:
3196 case GST_MESSAGE_ELEMENT:
3197 case GST_MESSAGE_SEGMENT_START:
3198 case GST_MESSAGE_SEGMENT_DONE:
3199 case GST_MESSAGE_DURATION:
3200 case GST_MESSAGE_ANY:
3209 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3210 GHashTable *members,
3211 EmpathyCallWindow *self)
3213 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3214 GHashTableIter iter;
3215 gpointer key, value;
3216 gboolean held = FALSE;
3218 g_hash_table_iter_init (&iter, members);
3219 while (g_hash_table_iter_next (&iter, &key, &value))
3221 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3223 /* This assumes this is a 1-1 call, otherwise one participant
3224 * putting the call on hold wouldn't mean the call is on hold
3232 priv->call_state = HELD;
3233 else if (priv->call_state == HELD)
3234 priv->call_state = CONNECTED;
3238 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3240 EmpathyCallWindow *self)
3242 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3243 TpyCallChannel *call;
3245 g_object_get (priv->handler, "call-channel", &call, NULL);
3250 tp_g_signal_connect_object (call, "audio-stream-error",
3251 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3252 tp_g_signal_connect_object (call, "video-stream-error",
3253 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3256 tp_g_signal_connect_object (call, "members-changed",
3257 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3259 g_object_unref (call);
3263 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3265 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3266 TpyCallChannel *call;
3269 /* Make the hangup button twice as wide */
3270 width = gtk_widget_get_allocated_width (priv->hangup_button);
3271 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3273 g_signal_connect (priv->handler, "state-changed",
3274 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3275 g_signal_connect (priv->handler, "conference-added",
3276 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3277 g_signal_connect (priv->handler, "conference-removed",
3278 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3279 g_signal_connect (priv->handler, "closed",
3280 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3281 g_signal_connect (priv->handler, "src-pad-added",
3282 G_CALLBACK (empathy_call_window_src_added_cb), window);
3283 g_signal_connect (priv->handler, "sink-pad-added",
3284 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3285 g_signal_connect (priv->handler, "sink-pad-removed",
3286 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3288 g_object_get (priv->handler, "call-channel", &call, NULL);
3291 call_handler_notify_call_cb (priv->handler, NULL, window);
3292 g_object_unref (call);
3296 /* call-channel doesn't exist yet, we'll connect signals once it has been
3298 g_signal_connect (priv->handler, "notify::call-channel",
3299 G_CALLBACK (call_handler_notify_call_cb), window);
3302 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3306 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3307 EmpathyCallWindow *window)
3309 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3311 if (priv->pipeline != NULL)
3313 if (priv->bus_message_source_id != 0)
3315 g_source_remove (priv->bus_message_source_id);
3316 priv->bus_message_source_id = 0;
3319 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3322 if (priv->call_state == CONNECTING)
3323 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3329 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3332 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3334 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3339 gtk_widget_hide (priv->dtmf_panel);
3340 gtk_widget_hide (menu);
3341 gtk_widget_hide (priv->toolbar);
3345 if (priv->dialpad_was_visible_before_fs)
3346 gtk_widget_show (priv->dtmf_panel);
3348 gtk_widget_show (menu);
3349 gtk_widget_show (priv->toolbar);
3351 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3352 priv->original_height_before_fs);
3357 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3359 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3361 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3362 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3363 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3364 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3366 if (priv->video_output != NULL)
3369 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3370 priv->video_output, TRUE, TRUE,
3371 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3378 empathy_call_window_state_event_cb (GtkWidget *widget,
3379 GdkEventWindowState *event, EmpathyCallWindow *window)
3381 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3383 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3384 gboolean set_fullscreen = event->new_window_state &
3385 GDK_WINDOW_STATE_FULLSCREEN;
3389 gboolean dialpad_was_visible;
3390 GtkAllocation allocation;
3391 gint original_width, original_height;
3393 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3394 original_width = allocation.width;
3395 original_height = allocation.height;
3397 g_object_get (priv->dtmf_panel,
3398 "visible", &dialpad_was_visible,
3401 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3402 priv->original_width_before_fs = original_width;
3403 priv->original_height_before_fs = original_height;
3405 if (priv->video_output_motion_handler_id == 0 &&
3406 priv->video_output != NULL)
3408 priv->video_output_motion_handler_id = g_signal_connect (
3409 G_OBJECT (priv->video_container), "motion-notify-event",
3410 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3416 disconnect_video_output_motion_handler (window);
3419 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3421 show_controls (window, set_fullscreen);
3422 show_borders (window, set_fullscreen);
3423 gtk_action_set_stock_id (priv->menu_fullscreen,
3424 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3425 priv->is_fullscreen = set_fullscreen;
3432 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3435 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3436 int w, h, dialpad_width;
3437 GtkAllocation allocation;
3439 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3440 w = allocation.width;
3441 h = allocation.height;
3443 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3447 gtk_widget_show (priv->dtmf_panel);
3453 gtk_widget_hide (priv->dtmf_panel);
3457 gtk_window_resize (GTK_WINDOW (window), w, h);
3461 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3464 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3465 TpyCallChannel *call;
3467 priv->sending_video = (state == CAMERA_STATE_ON);
3469 if (state == CAMERA_STATE_ON)
3471 /* When we start sending video, we want to show the video preview by
3473 display_video_preview (window, TRUE);
3477 display_video_preview (window, FALSE);
3480 if (priv->call_state != CONNECTED)
3483 g_object_get (priv->handler, "call-channel", &call, NULL);
3484 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3485 tpy_call_channel_send_video (call, priv->sending_video);
3486 g_object_unref (call);
3490 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3491 EmpathyCallWindow *self)
3493 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3496 active = (gtk_toggle_tool_button_get_active (toggle));
3498 /* We don't want the settings callback to react to this change to avoid
3500 g_signal_handlers_block_by_func (priv->settings,
3501 empathy_call_window_prefs_volume_changed_cb, self);
3505 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3506 priv->volume * 100);
3510 /* TODO, Instead of setting the input volume to 0 we should probably
3511 * stop sending but this would cause the audio call to drop if both
3512 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3513 * in the future. GNOME #574574
3515 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3519 g_signal_handlers_unblock_by_func (priv->settings,
3520 empathy_call_window_prefs_volume_changed_cb, self);
3524 empathy_call_window_hangup_cb (gpointer object,
3525 EmpathyCallWindow *self)
3527 empathy_call_handler_stop_call (self->priv->handler);
3529 empathy_call_window_disconnected (self, TRUE);
3533 empathy_call_window_restart_call (EmpathyCallWindow *window)
3535 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3537 /* Remove error info bars */
3538 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3539 (GtkCallback) gtk_widget_destroy, NULL);
3541 create_video_output_widget (window);
3543 /* While the call was disconnected, the input volume might have changed.
3544 * However, since the audio_input source was destroyed, its volume has not
3545 * been updated during that time. That's why we manually update it here */
3546 empathy_call_window_mic_volume_changed (window);
3548 priv->outgoing = TRUE;
3549 empathy_call_window_set_state_connecting (window);
3551 if (priv->pipeline_playing)
3552 start_call (window);
3554 /* call will be started when the pipeline is ready */
3555 priv->start_call_when_playing = TRUE;
3557 empathy_call_window_setup_avatars (window, priv->handler);
3559 empathy_call_window_show_hangup_button (window, TRUE);
3563 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3564 EmpathyCallWindow *window)
3568 active = gtk_toggle_tool_button_get_active (button);
3570 empathy_call_window_show_dialpad (window, active);
3574 empathy_call_window_fullscreen_cb (gpointer object,
3575 EmpathyCallWindow *window)
3577 empathy_call_window_fullscreen_toggle (window);
3581 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3583 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3585 if (priv->is_fullscreen)
3586 gtk_window_unfullscreen (GTK_WINDOW (window));
3588 gtk_window_fullscreen (GTK_WINDOW (window));
3592 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3593 GdkEventButton *event, EmpathyCallWindow *window)
3595 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3597 empathy_call_window_video_menu_popup (window, event->button);
3605 empathy_call_window_key_press_cb (GtkWidget *video_output,
3606 GdkEventKey *event, EmpathyCallWindow *window)
3608 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3610 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3612 /* Since we are in fullscreen mode, toggling will bring us back to
3614 empathy_call_window_fullscreen_toggle (window);
3622 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3623 GdkEventMotion *event, EmpathyCallWindow *window)
3625 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3627 if (priv->is_fullscreen)
3629 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3631 /* Show the bottom toolbar */
3632 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3639 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3643 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3645 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3647 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3648 button, gtk_get_current_event_time ());
3649 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3653 empathy_call_window_status_message (EmpathyCallWindow *self,
3656 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3660 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3661 gdouble value, EmpathyCallWindow *window)
3663 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3665 if (priv->audio_output == NULL)
3668 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3673 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3675 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3677 return priv->ui_manager;
3680 EmpathyGstAudioSrc *
3681 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3683 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3685 return (EmpathyGstAudioSrc *) priv->audio_input;
3688 EmpathyGstVideoSrc *
3689 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3691 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);