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-rectangle.h"
69 #include "empathy-rounded-texture.h"
70 #include "empathy-camera-menu.h"
72 #define CONTENT_HBOX_BORDER_WIDTH 6
73 #define CONTENT_HBOX_SPACING 3
74 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
76 #define SELF_VIDEO_SECTION_WIDTH 120
77 #define SELF_VIDEO_SECTION_HEIGHT 90
78 #define SELF_VIDEO_SECTION_MARGIN 10
80 #define FLOATING_TOOLBAR_OPACITY 192
81 #define FLOATING_TOOLBAR_WIDTH 280
82 #define FLOATING_TOOLBAR_HEIGHT 36
83 #define FLOATING_TOOLBAR_SPACING 20
85 /* The avatar's default width and height are set to the same value because we
86 want a square icon. */
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
89 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define SMALL_TOOLBAR_SIZE 36
93 /* If an video input error occurs, the error message will start with "v4l" */
94 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
96 /* The time interval in milliseconds between 2 outgoing rings */
97 #define MS_BETWEEN_RING 500
99 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
102 PROP_CALL_HANDLER = 1,
114 CAMERA_STATE_OFF = 0,
120 PREVIEW_POS_TOP_LEFT,
121 PREVIEW_POS_TOP_RIGHT,
122 PREVIEW_POS_BOTTOM_LEFT,
123 PREVIEW_POS_BOTTOM_RIGHT,
126 struct _EmpathyCallWindowPriv
128 gboolean dispose_has_run;
129 EmpathyCallHandler *handler;
131 EmpathyContact *contact;
133 EmpathyCameraMonitor *camera_monitor;
138 GtkUIManager *ui_manager;
139 GtkWidget *errors_vbox;
140 /* widget displays the video received from the remote user. This widget is
141 * alive only during call. */
142 ClutterActor *video_output;
143 ClutterActor *video_preview;
144 ClutterActor *drag_preview;
145 ClutterActor *preview_shown_button;
146 ClutterActor *preview_hidden_button;
147 ClutterActor *preview_rectangle1;
148 ClutterActor *preview_rectangle2;
149 ClutterActor *preview_rectangle3;
150 ClutterActor *preview_rectangle4;
151 ClutterActor *preview_rectangle_box1;
152 ClutterActor *preview_rectangle_box2;
153 ClutterActor *preview_rectangle_box3;
154 ClutterActor *preview_rectangle_box4;
155 GtkWidget *video_container;
156 GtkWidget *remote_user_avatar_widget;
157 GtkWidget *remote_user_avatar_toolbar;
158 GtkWidget *remote_user_name_toolbar;
159 GtkWidget *status_label;
160 GtkWidget *hangup_button;
161 GtkWidget *audio_call_button;
162 GtkWidget *video_call_button;
163 GtkWidget *mic_button;
164 GtkWidget *camera_button;
165 GtkWidget *dialpad_button;
167 GtkWidget *bottom_toolbar;
168 ClutterActor *floating_toolbar;
170 GtkAction *menu_fullscreen;
171 GtkAction *menu_swap_camera;
173 ClutterState *transitions;
175 /* The box that contains self and remote avatar and video
176 input/output. When we redial, we destroy and re-create the box */
177 ClutterActor *video_box;
178 ClutterLayoutManager *video_layout;
180 /* Coordinates of the preview drag event's start. */
181 PreviewPosition preview_pos;
183 /* We keep a reference on the hbox which contains the main content so we can
184 easilly repack everything when toggling fullscreen */
185 GtkWidget *content_hbox;
187 gulong video_output_motion_handler_id;
188 guint bus_message_source_id;
192 GtkWidget *dtmf_panel;
195 GtkWidget *details_vbox;
196 GtkWidget *vcodec_encoding_label;
197 GtkWidget *acodec_encoding_label;
198 GtkWidget *vcodec_decoding_label;
199 GtkWidget *acodec_decoding_label;
201 GtkWidget *audio_remote_candidate_label;
202 GtkWidget *audio_local_candidate_label;
203 GtkWidget *video_remote_candidate_label;
204 GtkWidget *video_local_candidate_label;
205 GtkWidget *video_remote_candidate_info_img;
206 GtkWidget *video_local_candidate_info_img;
207 GtkWidget *audio_remote_candidate_info_img;
208 GtkWidget *audio_local_candidate_info_img;
210 GstElement *video_input;
211 GstElement *video_preview_sink;
212 GstElement *video_output_sink;
213 GstElement *audio_input;
214 GstElement *audio_output;
215 GstElement *pipeline;
216 GstElement *video_tee;
226 gboolean call_started;
227 gboolean sending_video;
228 CameraState camera_state;
230 EmpathyCallWindowFullscreen *fullscreen;
231 gboolean is_fullscreen;
236 guint inactivity_src;
238 /* Those fields represent the state of the window before it actually was in
240 gboolean dialpad_was_visible_before_fs;
241 gint original_width_before_fs;
242 gint original_height_before_fs;
244 gint x, y, w, h, dialpad_width;
247 /* TRUE if the call should be started when the pipeline is playing */
248 gboolean start_call_when_playing;
249 /* TRUE if we requested to set the pipeline in the playing state */
250 gboolean pipeline_playing;
252 EmpathySoundManager *sound_mgr;
255 EmpathyMicMenu *mic_menu;
256 EmpathyCameraMenu *camera_menu;
259 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
261 static void empathy_call_window_realized_cb (GtkWidget *widget,
262 EmpathyCallWindow *window);
264 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
265 GdkEvent *event, EmpathyCallWindow *window);
267 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
268 GdkEventWindowState *event, EmpathyCallWindow *window);
270 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
273 static void empathy_call_window_mic_toggled_cb (
274 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
276 static void empathy_call_window_hangup_cb (gpointer object,
277 EmpathyCallWindow *window);
279 static void empathy_call_window_fullscreen_cb (gpointer object,
280 EmpathyCallWindow *window);
282 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
284 static gboolean empathy_call_window_video_button_press_cb (
285 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
287 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
288 GdkEventKey *event, EmpathyCallWindow *window);
290 static gboolean empathy_call_window_video_output_motion_notify (
291 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
293 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
296 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
297 EmpathyCallWindow *window);
299 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
301 static void empathy_call_window_status_message (EmpathyCallWindow *window,
304 static gboolean empathy_call_window_bus_message (GstBus *bus,
305 GstMessage *message, gpointer user_data);
308 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
309 gdouble value, EmpathyCallWindow *window);
312 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
315 gtk_widget_set_visible (self->priv->hangup_button, show);
316 gtk_widget_set_visible (self->priv->audio_call_button, !show);
317 gtk_widget_set_visible (self->priv->video_call_button, !show);
321 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
322 EmpathyCallWindow *self)
324 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
325 empathy_call_window_restart_call (self);
329 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
330 EmpathyCallWindow *self)
332 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
333 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
334 empathy_call_window_restart_call (self);
338 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
340 EmpathyCallWindowPriv *priv = GET_PRIV (window);
341 TpyCallChannel *call;
345 g_object_get (priv->handler, "call-channel", &call, NULL);
347 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
348 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
351 tpy_call_channel_dtmf_start_tone (call, event);
353 g_object_unref (call);
357 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
359 EmpathyCallWindowPriv *priv = GET_PRIV (window);
360 TpyCallChannel *call;
362 g_object_get (priv->handler, "call-channel", &call, NULL);
364 tpy_call_channel_dtmf_stop_tone (call);
366 g_object_unref (call);
370 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
372 EmpathyCallWindowPriv *priv = GET_PRIV (self);
375 volume = g_settings_get_double (priv->settings,
376 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
378 /* Don't store the volume because of muting */
379 if (volume > 0 || gtk_toggle_tool_button_get_active (
380 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
381 priv->volume = volume;
383 /* Ensure that the toggle button is active if the volume is > 0 and inactive
384 * if it's smaller than 0 */
385 if ((volume > 0) != gtk_toggle_tool_button_get_active (
386 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
387 gtk_toggle_tool_button_set_active (
388 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
390 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
395 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
397 EmpathyCallWindow *self)
399 empathy_call_window_mic_volume_changed (self);
403 empathy_call_window_raise_actors (EmpathyCallWindow *self)
405 clutter_actor_raise_top (self->priv->floating_toolbar);
407 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
408 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
409 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
410 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
414 empathy_call_window_show_video_output (EmpathyCallWindow *self,
417 if (self->priv->video_output != NULL)
418 g_object_set (self->priv->video_output, "visible", show, NULL);
420 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
422 empathy_call_window_raise_actors (self);
426 create_video_output_widget (EmpathyCallWindow *self)
428 EmpathyCallWindowPriv *priv = GET_PRIV (self);
430 g_assert (priv->video_output == NULL);
431 g_assert (priv->pipeline != NULL);
433 priv->video_output = clutter_texture_new ();
435 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
438 priv->video_output_sink = clutter_gst_video_sink_new (
439 CLUTTER_TEXTURE (priv->video_output));
441 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
444 gtk_widget_add_events (priv->video_container,
445 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
446 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
447 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
451 create_video_input (EmpathyCallWindow *self)
453 EmpathyCallWindowPriv *priv = GET_PRIV (self);
455 g_assert (priv->video_input == NULL);
456 priv->video_input = empathy_video_src_new ();
457 gst_object_ref (priv->video_input);
458 gst_object_sink (priv->video_input);
462 create_audio_input (EmpathyCallWindow *self)
464 EmpathyCallWindowPriv *priv = GET_PRIV (self);
466 g_assert (priv->audio_input == NULL);
467 priv->audio_input = empathy_audio_src_new ();
468 gst_object_ref (priv->audio_input);
469 gst_object_sink (priv->audio_input);
473 add_video_preview_to_pipeline (EmpathyCallWindow *self)
475 EmpathyCallWindowPriv *priv = GET_PRIV (self);
478 g_assert (priv->video_preview != NULL);
479 g_assert (priv->pipeline != NULL);
480 g_assert (priv->video_input != NULL);
481 g_assert (priv->video_tee != NULL);
483 preview = priv->video_preview_sink;
485 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
487 g_warning ("Could not add video input to pipeline");
491 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
493 g_warning ("Could not add video preview to pipeline");
497 if (!gst_element_link (priv->video_input, priv->video_tee))
499 g_warning ("Could not link video input to video tee");
503 if (!gst_element_link (priv->video_tee, preview))
505 g_warning ("Could not link video tee to video preview");
511 empathy_call_window_disable_camera_cb (GtkAction *action,
512 EmpathyCallWindow *self)
514 clutter_actor_destroy (self->priv->preview_hidden_button);
516 gtk_toggle_tool_button_set_active (
517 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
521 empathy_call_window_minimise_camera_cb (GtkAction *action,
522 EmpathyCallWindow *self)
524 clutter_actor_hide (self->priv->video_preview);
525 clutter_actor_show (self->priv->preview_hidden_button);
529 empathy_call_window_maximise_camera_cb (GtkAction *action,
530 EmpathyCallWindow *self)
532 clutter_actor_show (self->priv->video_preview);
533 clutter_actor_hide (self->priv->preview_hidden_button);
537 empathy_call_window_swap_camera_cb (GtkAction *action,
538 EmpathyCallWindow *self)
540 const GList *cameras, *l;
543 DEBUG ("Swapping the camera");
545 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
546 current_cam = empathy_video_src_dup_device (
547 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
549 for (l = cameras; l != NULL; l = l->next)
551 EmpathyCamera *camera = l->data;
553 if (!tp_strdiff (camera->device, current_cam))
558 next = l->next->data;
560 next = cameras->data;
562 /* EmpathyCameraMenu will update itself and do the actual change
564 g_settings_set_string (self->priv->settings,
565 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
572 g_free (current_cam);
576 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
577 EmpathyCamera *camera,
578 EmpathyCallWindow *self)
580 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
582 gtk_action_set_visible (self->priv->menu_swap_camera,
583 g_list_length ((GList *) cameras) >= 2);
587 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
588 EmpathyCamera *camera,
589 EmpathyCallWindow *self)
591 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
593 gtk_action_set_visible (self->priv->menu_swap_camera,
594 g_list_length ((GList *) cameras) >= 2);
598 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
599 EmpathyCallWindow *self)
603 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
605 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
606 0, gtk_get_current_event_time ());
607 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
611 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
612 EmpathyCallWindow *self)
616 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
617 "/preview-hidden-menu");
618 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
619 0, gtk_get_current_event_time ());
620 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
623 static ClutterActor *
624 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
626 ClutterBinAlignment x,
627 ClutterBinAlignment y)
629 ClutterLayoutManager *layout1, *layout2;
630 ClutterActor *rectangle;
631 ClutterActor *box1, *box2;
633 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
634 CLUTTER_BIN_ALIGNMENT_START);
636 box1 = clutter_box_new (layout1);
640 rectangle = empathy_rounded_rectangle_new (
641 SELF_VIDEO_SECTION_WIDTH + 5,
642 SELF_VIDEO_SECTION_HEIGHT + 5);
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_container_add_actor (CLUTTER_CONTAINER (box1), box2);
662 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
664 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
667 clutter_actor_hide (rectangle);
673 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
675 self->priv->preview_rectangle1 =
676 empathy_call_window_create_preview_rectangle (self,
677 &self->priv->preview_rectangle_box1,
678 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
679 self->priv->preview_rectangle2 =
680 empathy_call_window_create_preview_rectangle (self,
681 &self->priv->preview_rectangle_box2,
682 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
683 self->priv->preview_rectangle3 =
684 empathy_call_window_create_preview_rectangle (self,
685 &self->priv->preview_rectangle_box3,
686 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
687 self->priv->preview_rectangle4 =
688 empathy_call_window_create_preview_rectangle (self,
689 &self->priv->preview_rectangle_box4,
690 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
694 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
697 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
698 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
700 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
703 static PreviewPosition
704 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
709 PreviewPosition pos = PREVIEW_POS_NONE;
711 if (!clutter_actor_has_allocation (self->priv->video_box))
714 clutter_actor_get_geometry (self->priv->video_box, &box);
716 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
717 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
718 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
719 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
721 pos = PREVIEW_POS_TOP_LEFT;
723 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
724 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
725 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
726 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
728 pos = PREVIEW_POS_TOP_RIGHT;
730 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
731 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
732 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
733 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
735 pos = PREVIEW_POS_BOTTOM_LEFT;
737 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
738 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
739 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
740 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
742 pos = PREVIEW_POS_BOTTOM_RIGHT;
748 static ClutterActor *
749 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
752 ClutterActor *rectangle;
756 case PREVIEW_POS_TOP_LEFT:
757 rectangle = self->priv->preview_rectangle1;
759 case PREVIEW_POS_TOP_RIGHT:
760 rectangle = self->priv->preview_rectangle3;
762 case PREVIEW_POS_BOTTOM_LEFT:
763 rectangle = self->priv->preview_rectangle2;
765 case PREVIEW_POS_BOTTOM_RIGHT:
766 rectangle = self->priv->preview_rectangle4;
776 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
779 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
781 DEBUG ("moving the video preview to %d", pos);
783 self->priv->preview_pos = pos;
787 case PREVIEW_POS_TOP_LEFT:
788 clutter_bin_layout_set_alignment (layout,
789 self->priv->video_preview,
790 CLUTTER_BIN_ALIGNMENT_START,
791 CLUTTER_BIN_ALIGNMENT_START);
793 case PREVIEW_POS_TOP_RIGHT:
794 clutter_bin_layout_set_alignment (layout,
795 self->priv->video_preview,
796 CLUTTER_BIN_ALIGNMENT_END,
797 CLUTTER_BIN_ALIGNMENT_START);
799 case PREVIEW_POS_BOTTOM_LEFT:
800 clutter_bin_layout_set_alignment (layout,
801 self->priv->video_preview,
802 CLUTTER_BIN_ALIGNMENT_START,
803 CLUTTER_BIN_ALIGNMENT_END);
805 case PREVIEW_POS_BOTTOM_RIGHT:
806 clutter_bin_layout_set_alignment (layout,
807 self->priv->video_preview,
808 CLUTTER_BIN_ALIGNMENT_END,
809 CLUTTER_BIN_ALIGNMENT_END);
812 g_warn_if_reached ();
815 g_settings_set_enum (self->priv->settings, "camera-position", pos);
819 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
822 ClutterActor *rectangle;
824 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
826 empathy_rounded_rectangle_set_border_width (
827 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
828 empathy_rounded_rectangle_set_border_color (
829 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
833 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
834 ClutterActor *rectangle)
836 empathy_rounded_rectangle_set_border_width (
837 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
838 empathy_rounded_rectangle_set_border_color (
839 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
843 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
845 ClutterActor *rectangle;
847 rectangle = empathy_call_window_get_preview_rectangle (self,
848 self->priv->preview_pos);
850 /* We don't want to darken the rectangle where the preview
853 if (self->priv->preview_rectangle1 != rectangle)
854 empathy_call_window_darken_preview_rectangle (self,
855 self->priv->preview_rectangle1);
857 if (self->priv->preview_rectangle2 != rectangle)
858 empathy_call_window_darken_preview_rectangle (self,
859 self->priv->preview_rectangle2);
861 if (self->priv->preview_rectangle3 != rectangle)
862 empathy_call_window_darken_preview_rectangle (self,
863 self->priv->preview_rectangle3);
865 if (self->priv->preview_rectangle4 != rectangle)
866 empathy_call_window_darken_preview_rectangle (self,
867 self->priv->preview_rectangle4);
871 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
875 ClutterModifierType modifiers,
876 EmpathyCallWindow *self)
878 ClutterActor *stage = clutter_actor_get_stage (actor);
881 self->priv->drag_preview = clutter_clone_new (actor);
883 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
884 self->priv->drag_preview);
886 clutter_actor_transform_stage_point (actor, event_x, event_y,
889 clutter_actor_set_position (self->priv->drag_preview,
890 event_x - rel_x, event_y - rel_y);
892 clutter_drag_action_set_drag_handle (action,
893 self->priv->drag_preview);
895 clutter_actor_set_opacity (actor, 0);
896 clutter_actor_hide (self->priv->preview_shown_button);
898 empathy_call_window_show_preview_rectangles (self, TRUE);
899 empathy_call_window_darken_preview_rectangles (self);
903 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
907 ClutterModifierType modifiers,
908 EmpathyCallWindow *self)
912 /* Get the position before destroying the drag actor, otherwise the
913 * preview_box allocation won't be valid and we won't be able to
914 * calculate the position. */
915 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
917 /* Destroy the video preview copy that we were dragging */
918 clutter_actor_destroy (self->priv->drag_preview);
919 self->priv->drag_preview = NULL;
921 clutter_actor_set_opacity (actor, 255);
922 clutter_actor_show (self->priv->preview_shown_button);
924 if (pos != PREVIEW_POS_NONE)
925 empathy_call_window_move_video_preview (self, pos);
927 empathy_call_window_show_preview_rectangles (self, FALSE);
931 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
935 EmpathyCallWindow *self)
938 gfloat event_x, event_y;
940 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
942 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
944 if (pos != PREVIEW_POS_NONE)
945 empathy_call_window_highlight_preview_rectangle (self, pos);
947 empathy_call_window_darken_preview_rectangles (self);
951 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
952 ClutterCrossingEvent *event,
953 EmpathyCallWindow *self)
955 ClutterActor *rectangle;
957 rectangle = empathy_call_window_get_preview_rectangle (self,
958 self->priv->preview_pos);
960 empathy_call_window_highlight_preview_rectangle (self,
961 self->priv->preview_pos);
963 clutter_actor_show (rectangle);
969 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
970 ClutterCrossingEvent *event,
971 EmpathyCallWindow *self)
973 ClutterActor *rectangle;
975 rectangle = empathy_call_window_get_preview_rectangle (self,
976 self->priv->preview_pos);
978 empathy_call_window_darken_preview_rectangle (self, rectangle);
980 clutter_actor_hide (rectangle);
986 create_video_preview (EmpathyCallWindow *self)
988 EmpathyCallWindowPriv *priv = GET_PRIV (self);
989 ClutterLayoutManager *layout, *layout_center, *layout_end;
990 ClutterActor *preview;
993 ClutterAction *action;
997 g_assert (priv->video_preview == NULL);
999 pos = g_settings_get_enum (priv->settings, "camera-position");
1001 preview = empathy_rounded_texture_new ();
1002 clutter_actor_set_size (preview,
1003 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1004 priv->video_preview_sink = clutter_gst_video_sink_new (
1005 CLUTTER_TEXTURE (preview));
1007 /* Add a little offset to the video preview */
1008 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1009 CLUTTER_BIN_ALIGNMENT_START);
1010 priv->video_preview = clutter_box_new (layout);
1011 clutter_actor_set_size (priv->video_preview,
1012 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1013 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1014 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1016 /* We have a box with the margins and the video in the middle inside
1017 * a bigger box with an extra bottom margin so we're not on top of
1018 * the floating toolbar. */
1019 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1020 CLUTTER_BIN_ALIGNMENT_CENTER);
1021 box = clutter_box_new (layout_center);
1022 clutter_actor_set_size (box,
1023 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1024 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1026 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1027 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1029 g_object_set (priv->video_preview_sink,
1034 /* Translators: this is an "Info" label. It should be as short
1036 button = gtk_button_new_with_label (_("i"));
1037 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1039 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1041 clutter_actor_set_size (b, 24, 24);
1043 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1044 CLUTTER_BIN_ALIGNMENT_END);
1045 box = clutter_box_new (layout_end);
1046 clutter_actor_set_size (box,
1047 SELF_VIDEO_SECTION_WIDTH,
1048 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1050 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1051 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1053 g_signal_connect (button, "clicked",
1054 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1057 /* Translators: this is an "Info" label. It should be as short
1059 button = gtk_button_new_with_label (_("i"));
1060 b = empathy_rounded_actor_new ();
1062 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1064 clutter_actor_set_size (b, 24, 24);
1065 priv->preview_hidden_button = b;
1067 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1068 priv->preview_hidden_button,
1069 CLUTTER_BIN_ALIGNMENT_START,
1070 CLUTTER_BIN_ALIGNMENT_END);
1072 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1074 clutter_actor_hide (priv->preview_hidden_button);
1076 g_signal_connect (button, "clicked",
1077 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1080 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1081 priv->video_preview,
1082 CLUTTER_BIN_ALIGNMENT_START,
1083 CLUTTER_BIN_ALIGNMENT_END);
1085 empathy_call_window_move_video_preview (self, pos);
1087 action = clutter_drag_action_new ();
1088 g_signal_connect (action, "drag-begin",
1089 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1090 g_signal_connect (action, "drag-end",
1091 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1092 g_signal_connect (action, "drag-motion",
1093 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1095 g_signal_connect (preview, "enter-event",
1096 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1097 g_signal_connect (preview, "leave-event",
1098 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1100 clutter_actor_add_action (preview, action);
1101 clutter_actor_set_reactive (preview, TRUE);
1102 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1106 empathy_call_window_play_camera (EmpathyCallWindow *window,
1109 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1110 GstElement *preview;
1113 if (priv->video_preview == NULL)
1115 create_video_preview (window);
1116 add_video_preview_to_pipeline (window);
1120 state = GST_STATE_PLAYING;
1122 state = GST_STATE_NULL;
1124 preview = priv->video_preview_sink;
1126 gst_element_set_state (preview, state);
1127 gst_element_set_state (priv->video_input, state);
1128 gst_element_set_state (priv->video_tee, state);
1132 display_video_preview (EmpathyCallWindow *self,
1135 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1139 /* Display the video preview */
1140 DEBUG ("Show video preview");
1142 empathy_call_window_play_camera (self, TRUE);
1143 clutter_actor_show (priv->video_preview);
1144 clutter_actor_raise_top (priv->floating_toolbar);
1148 /* Hide the video preview */
1149 DEBUG ("Hide video preview");
1151 if (priv->video_preview != NULL)
1153 clutter_actor_hide (priv->video_preview);
1154 empathy_call_window_play_camera (self, FALSE);
1160 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1162 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1164 empathy_call_window_status_message (window, _("Connecting…"));
1165 priv->call_state = CONNECTING;
1167 /* Show the toolbar */
1168 clutter_state_set_state (priv->transitions, "fade-in");
1171 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1172 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1176 disable_camera (EmpathyCallWindow *self)
1178 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1180 if (priv->camera_state == CAMERA_STATE_OFF)
1183 DEBUG ("Disable camera");
1185 display_video_preview (self, FALSE);
1187 if (priv->camera_state == CAMERA_STATE_ON)
1188 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1190 priv->camera_state = CAMERA_STATE_OFF;
1194 enable_camera (EmpathyCallWindow *self)
1196 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1198 if (priv->camera_state == CAMERA_STATE_ON)
1201 if (priv->video_input == NULL)
1203 DEBUG ("Can't enable camera, no input");
1207 DEBUG ("Enable camera");
1209 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1211 priv->camera_state = CAMERA_STATE_ON;
1215 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1216 EmpathyCallWindow *self)
1218 if (gtk_toggle_tool_button_get_active (toggle))
1219 enable_camera (self);
1221 disable_camera (self);
1225 create_pipeline (EmpathyCallWindow *self)
1227 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1230 g_assert (priv->pipeline == NULL);
1232 priv->pipeline = gst_pipeline_new (NULL);
1233 priv->pipeline_playing = FALSE;
1235 priv->video_tee = gst_element_factory_make ("tee", NULL);
1236 gst_object_ref (priv->video_tee);
1237 gst_object_sink (priv->video_tee);
1239 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1241 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1242 priv->bus_message_source_id = gst_bus_add_watch (bus,
1243 empathy_call_window_bus_message, self);
1245 g_object_unref (bus);
1249 empathy_call_window_settings_cb (GtkAction *action,
1250 EmpathyCallWindow *self)
1252 gchar *args = g_strdup_printf ("-p %s",
1253 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1255 empathy_launch_program (BIN_DIR, "empathy", args);
1261 empathy_call_window_contents_cb (GtkAction *action,
1262 EmpathyCallWindow *self)
1264 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1268 empathy_call_window_debug_cb (GtkAction *action,
1269 EmpathyCallWindow *self)
1271 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1275 empathy_call_window_about_cb (GtkAction *action,
1276 EmpathyCallWindow *self)
1278 empathy_about_dialog_new (GTK_WINDOW (self));
1282 empathy_call_window_toolbar_timeout (gpointer data)
1284 EmpathyCallWindow *self = data;
1286 /* We don't want to hide the toolbar if we're not in a call, as
1287 * to show the call status all the time. */
1288 if (self->priv->call_state != CONNECTING &&
1289 self->priv->call_state != DISCONNECTED)
1290 clutter_state_set_state (self->priv->transitions, "fade-out");
1296 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1298 EmpathyCallWindow *self)
1300 clutter_state_set_state (self->priv->transitions, "fade-in");
1302 if (self->priv->inactivity_src > 0)
1303 g_source_remove (self->priv->inactivity_src);
1305 self->priv->inactivity_src = g_timeout_add_seconds (3,
1306 empathy_call_window_toolbar_timeout, self);
1312 empathy_call_window_configure_event_cb (GtkWidget *widget,
1314 EmpathyCallWindow *self)
1316 GdkWindow *gdk_window;
1317 GdkWindowState window_state;
1319 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1320 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1322 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1323 &self->priv->dialpad_width, NULL);
1325 gdk_window = gtk_widget_get_window (widget);
1326 window_state = gdk_window_get_state (gdk_window);
1327 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1333 empathy_call_window_destroyed_cb (GtkWidget *object,
1334 EmpathyCallWindow *self)
1336 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1338 /* Save the geometry as if the dialpad was hidden. */
1339 empathy_geometry_save_values (GTK_WINDOW (self),
1340 self->priv->x, self->priv->y,
1341 self->priv->w - self->priv->dialpad_width, self->priv->h,
1342 self->priv->maximized);
1347 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1349 ClutterBindConstraint *constraint)
1351 ClutterActorBox allocation;
1353 clutter_actor_get_allocation_box (stage, &allocation);
1355 clutter_bind_constraint_set_offset (constraint,
1356 allocation.y2 - allocation.y1 -
1357 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1361 empathy_call_window_init (EmpathyCallWindow *self)
1363 EmpathyCallWindowPriv *priv;
1365 GtkWidget *top_vbox;
1367 ClutterConstraint *constraint;
1368 ClutterActor *remote_avatar;
1369 GtkStyleContext *context;
1373 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1374 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1376 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1377 gui = empathy_builder_get_file (filename,
1378 "call_window_vbox", &top_vbox,
1379 "errors_vbox", &priv->errors_vbox,
1380 "pane", &priv->pane,
1381 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1382 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1383 "status_label", &priv->status_label,
1384 "audiocall", &priv->audio_call_button,
1385 "videocall", &priv->video_call_button,
1386 "microphone", &priv->mic_button,
1387 "camera", &priv->camera_button,
1388 "hangup", &priv->hangup_button,
1389 "dialpad", &priv->dialpad_button,
1390 "toolbar", &priv->toolbar,
1391 "bottom_toolbar", &priv->bottom_toolbar,
1392 "ui_manager", &priv->ui_manager,
1393 "menufullscreen", &priv->menu_fullscreen,
1394 "menupreviewswap", &priv->menu_swap_camera,
1395 "details_vbox", &priv->details_vbox,
1396 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1397 "acodec_encoding_label", &priv->acodec_encoding_label,
1398 "acodec_decoding_label", &priv->acodec_decoding_label,
1399 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1400 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1401 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1402 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1403 "video_local_candidate_label", &priv->video_local_candidate_label,
1404 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1405 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1406 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1407 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1411 empathy_builder_connect (gui, self,
1412 "hangup", "clicked", empathy_call_window_hangup_cb,
1413 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1414 "videocall", "clicked", empathy_call_window_video_call_cb,
1415 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1416 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1417 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1418 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1419 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1420 "menusettings", "activate", empathy_call_window_settings_cb,
1421 "menucontents", "activate", empathy_call_window_contents_cb,
1422 "menudebug", "activate", empathy_call_window_debug_cb,
1423 "menuabout", "activate", empathy_call_window_about_cb,
1424 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1425 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1426 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1427 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1430 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1432 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1434 g_object_bind_property (priv->camera_monitor, "available",
1435 priv->camera_button, "sensitive",
1436 G_BINDING_SYNC_CREATE);
1438 g_signal_connect (priv->camera_monitor, "added",
1439 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1440 g_signal_connect (priv->camera_monitor, "removed",
1441 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1443 priv->lock = g_mutex_new ();
1445 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1447 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1448 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1449 CONTENT_HBOX_BORDER_WIDTH);
1450 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1453 /* avatar/video box */
1454 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1455 CLUTTER_BIN_ALIGNMENT_CENTER);
1457 priv->video_box = clutter_box_new (priv->video_layout);
1459 priv->video_container = gtk_clutter_embed_new ();
1461 /* Set the background color to that of the rest of the window */
1462 context = gtk_widget_get_style_context (priv->content_hbox);
1463 gtk_style_context_get_background_color (context,
1464 GTK_STATE_FLAG_NORMAL, &rgba);
1465 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1466 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1467 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1468 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1469 clutter_stage_set_color (
1470 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1471 GTK_CLUTTER_EMBED (priv->video_container))),
1474 clutter_container_add (
1475 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1476 GTK_CLUTTER_EMBED (priv->video_container))),
1480 constraint = clutter_bind_constraint_new (
1481 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1482 CLUTTER_BIND_SIZE, 0);
1483 clutter_actor_add_constraint (priv->video_box, constraint);
1485 priv->remote_user_avatar_widget = gtk_image_new ();
1486 remote_avatar = gtk_clutter_actor_new_with_contents (
1487 priv->remote_user_avatar_widget);
1489 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1492 empathy_call_window_create_preview_rectangles (self);
1494 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1495 priv->video_container, TRUE, TRUE,
1496 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1498 create_pipeline (self);
1499 create_video_output_widget (self);
1500 create_audio_input (self);
1501 create_video_input (self);
1503 priv->floating_toolbar = empathy_rounded_actor_new ();
1505 gtk_widget_reparent (priv->bottom_toolbar,
1506 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1508 constraint = clutter_bind_constraint_new (
1509 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1512 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1515 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1516 "notify::allocation",
1517 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1520 clutter_actor_set_size (priv->floating_toolbar,
1521 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1522 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1524 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1525 priv->floating_toolbar,
1526 CLUTTER_BIN_ALIGNMENT_CENTER,
1527 CLUTTER_BIN_ALIGNMENT_END);
1529 clutter_actor_raise_top (priv->floating_toolbar);
1531 /* Transitions for the floating toolbar */
1532 priv->transitions = clutter_state_new ();
1534 /* all transitions last for 2s */
1535 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1537 /* transition from any state to "fade-out" state */
1538 clutter_state_set (priv->transitions, NULL, "fade-out",
1539 priv->floating_toolbar,
1540 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1543 /* transition from any state to "fade-in" state */
1544 clutter_state_set (priv->transitions, NULL, "fade-in",
1545 priv->floating_toolbar,
1546 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1549 /* put the actor into the "fade-in" state with no animation */
1550 clutter_state_warp_to_state (priv->transitions, "fade-in");
1552 /* The call will be started as soon the pipeline is playing */
1553 priv->start_call_when_playing = TRUE;
1555 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1556 G_CALLBACK (dtmf_button_pressed_cb),
1557 G_CALLBACK (dtmf_button_released_cb));
1559 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1562 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1565 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1567 gtk_widget_show_all (top_vbox);
1569 gtk_widget_hide (priv->dtmf_panel);
1570 gtk_widget_hide (priv->details_vbox);
1572 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1574 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1575 priv->video_container);
1577 /* We hide the bottom toolbar after 3s of inactivity and show it
1578 * again on mouse movement */
1579 priv->inactivity_src = g_timeout_add_seconds (3,
1580 empathy_call_window_toolbar_timeout, self);
1582 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1583 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1585 g_signal_connect (G_OBJECT (self), "realize",
1586 G_CALLBACK (empathy_call_window_realized_cb), self);
1588 g_signal_connect (G_OBJECT (self), "delete-event",
1589 G_CALLBACK (empathy_call_window_delete_cb), self);
1591 g_signal_connect (G_OBJECT (self), "window-state-event",
1592 G_CALLBACK (empathy_call_window_state_event_cb), self);
1594 g_signal_connect (G_OBJECT (self), "key-press-event",
1595 G_CALLBACK (empathy_call_window_key_press_cb), self);
1597 g_signal_connect (self, "motion-notify-event",
1598 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1600 priv->timer = g_timer_new ();
1602 g_object_ref (priv->ui_manager);
1603 g_object_unref (gui);
1605 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1606 priv->mic_menu = empathy_mic_menu_new (self);
1607 priv->camera_menu = empathy_camera_menu_new (self);
1609 empathy_call_window_show_hangup_button (self, TRUE);
1611 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1613 /* Retrieve initial volume */
1614 priv->volume = g_settings_get_double (priv->settings,
1615 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1617 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1618 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1620 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1621 /* These signals are used to track the window position and save it
1622 * when the window is destroyed. We need to do this as we don't want
1623 * the window geometry to be saved with the dialpad taken into account. */
1624 g_signal_connect (self, "destroy",
1625 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1626 g_signal_connect (self, "configure-event",
1627 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1628 g_signal_connect (self, "window-state-event",
1629 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1631 /* Don't display labels in both toolbars */
1632 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1635 /* Instead of specifying a width and a height, we specify only one size. That's
1636 because we want a square avatar icon. */
1638 init_contact_avatar_with_size (EmpathyContact *contact,
1639 GtkWidget *image_widget,
1642 GdkPixbuf *pixbuf_avatar = NULL;
1644 if (contact != NULL)
1646 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1650 if (pixbuf_avatar == NULL)
1652 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1653 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1656 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1658 if (pixbuf_avatar != NULL)
1659 g_object_unref (pixbuf_avatar);
1663 set_window_title (EmpathyCallWindow *self)
1665 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1668 if (priv->contact != NULL)
1670 /* translators: Call is a noun and %s is the contact name. This string
1671 * is used in the window title */
1672 tmp = g_strdup_printf (_("Call with %s"),
1673 empathy_contact_get_alias (priv->contact));
1674 gtk_window_set_title (GTK_WINDOW (self), tmp);
1679 g_warning ("Unknown remote contact!");
1684 set_remote_user_name (EmpathyCallWindow *self,
1685 EmpathyContact *contact)
1687 const gchar *alias = empathy_contact_get_alias (contact);
1688 const gchar *status = empathy_contact_get_status (contact);
1691 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1692 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1698 contact_name_changed_cb (EmpathyContact *contact,
1700 EmpathyCallWindow *self)
1702 set_window_title (self);
1703 set_remote_user_name (self, contact);
1707 contact_presence_changed_cb (EmpathyContact *contact,
1709 EmpathyCallWindow *self)
1711 set_remote_user_name (self, contact);
1715 contact_avatar_changed_cb (EmpathyContact *contact,
1717 EmpathyCallWindow *self)
1720 GtkAllocation allocation;
1721 GtkWidget *avatar_widget;
1723 avatar_widget = self->priv->remote_user_avatar_widget;
1725 gtk_widget_get_allocation (avatar_widget, &allocation);
1726 size = allocation.height;
1730 /* the widget is not allocated yet, set a default size */
1731 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1732 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1735 init_contact_avatar_with_size (contact, avatar_widget, size);
1737 avatar_widget = self->priv->remote_user_avatar_toolbar;
1739 gtk_widget_get_allocation (avatar_widget, &allocation);
1740 size = allocation.height;
1744 /* the widget is not allocated yet, set a default size */
1745 size = SMALL_TOOLBAR_SIZE;
1748 init_contact_avatar_with_size (contact, avatar_widget, size);
1752 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1753 EmpathyCallHandler *handler)
1755 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1757 tp_g_signal_connect_object (priv->contact, "notify::name",
1758 G_CALLBACK (contact_name_changed_cb), self, 0);
1759 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1760 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1761 tp_g_signal_connect_object (priv->contact, "notify::presence",
1762 G_CALLBACK (contact_presence_changed_cb), self, 0);
1764 set_window_title (self);
1765 set_remote_user_name (self, priv->contact);
1767 init_contact_avatar_with_size (priv->contact,
1768 priv->remote_user_avatar_widget,
1769 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1770 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1772 init_contact_avatar_with_size (priv->contact,
1773 priv->remote_user_avatar_toolbar,
1774 SMALL_TOOLBAR_SIZE);
1776 /* The remote avatar is shown by default and will be hidden when we receive
1777 video from the remote side. */
1778 clutter_actor_hide (priv->video_output);
1779 gtk_widget_show (priv->remote_user_avatar_widget);
1783 update_send_codec (EmpathyCallWindow *self,
1786 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1793 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1794 widget = priv->acodec_encoding_label;
1798 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1799 widget = priv->vcodec_encoding_label;
1805 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1806 gtk_label_set_text (GTK_LABEL (widget), tmp);
1811 send_audio_codec_notify_cb (GObject *object,
1815 EmpathyCallWindow *self = user_data;
1817 update_send_codec (self, TRUE);
1821 send_video_codec_notify_cb (GObject *object,
1825 EmpathyCallWindow *self = user_data;
1827 update_send_codec (self, FALSE);
1831 update_recv_codec (EmpathyCallWindow *self,
1834 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1837 GString *str = NULL;
1841 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1842 widget = priv->acodec_decoding_label;
1846 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1847 widget = priv->vcodec_decoding_label;
1853 for (l = codecs; l != NULL; l = g_list_next (l))
1855 FsCodec *codec = l->data;
1858 str = g_string_new (NULL);
1860 g_string_append (str, ", ");
1862 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1866 gtk_label_set_text (GTK_LABEL (widget), str->str);
1867 g_string_free (str, TRUE);
1871 recv_audio_codecs_notify_cb (GObject *object,
1875 EmpathyCallWindow *self = user_data;
1877 update_recv_codec (self, TRUE);
1881 recv_video_codecs_notify_cb (GObject *object,
1885 EmpathyCallWindow *self = user_data;
1887 update_recv_codec (self, FALSE);
1890 static const gchar *
1891 candidate_type_to_str (FsCandidate *candidate)
1893 switch (candidate->type)
1895 case FS_CANDIDATE_TYPE_HOST:
1897 case FS_CANDIDATE_TYPE_SRFLX:
1898 return "server reflexive";
1899 case FS_CANDIDATE_TYPE_PRFLX:
1900 return "peer reflexive";
1901 case FS_CANDIDATE_TYPE_RELAY:
1903 case FS_CANDIDATE_TYPE_MULTICAST:
1910 static const gchar *
1911 candidate_type_to_desc (FsCandidate *candidate)
1913 switch (candidate->type)
1915 case FS_CANDIDATE_TYPE_HOST:
1916 return _("The IP address as seen by the machine");
1917 case FS_CANDIDATE_TYPE_SRFLX:
1918 return _("The IP address as seen by a server on the Internet");
1919 case FS_CANDIDATE_TYPE_PRFLX:
1920 return _("The IP address of the peer as seen by the other side");
1921 case FS_CANDIDATE_TYPE_RELAY:
1922 return _("The IP address of a relay server");
1923 case FS_CANDIDATE_TYPE_MULTICAST:
1924 return _("The IP address of the multicast group");
1931 update_candidat_widget (EmpathyCallWindow *self,
1934 FsCandidate *candidate)
1938 g_assert (candidate != NULL);
1939 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1940 candidate->port, candidate_type_to_str (candidate));
1942 gtk_label_set_text (GTK_LABEL (label), str);
1943 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1949 candidates_changed_cb (GObject *object,
1951 EmpathyCallWindow *self)
1953 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1954 FsCandidate *candidate = NULL;
1956 if (type == FS_MEDIA_TYPE_VIDEO)
1958 /* Update remote candidate */
1959 candidate = empathy_call_handler_get_video_remote_candidate (
1962 update_candidat_widget (self, priv->video_remote_candidate_label,
1963 priv->video_remote_candidate_info_img, candidate);
1965 /* Update local candidate */
1966 candidate = empathy_call_handler_get_video_local_candidate (
1969 update_candidat_widget (self, priv->video_local_candidate_label,
1970 priv->video_local_candidate_info_img, candidate);
1974 /* Update remote candidate */
1975 candidate = empathy_call_handler_get_audio_remote_candidate (
1978 update_candidat_widget (self, priv->audio_remote_candidate_label,
1979 priv->audio_remote_candidate_info_img, candidate);
1981 /* Update local candidate */
1982 candidate = empathy_call_handler_get_audio_local_candidate (
1985 update_candidat_widget (self, priv->audio_local_candidate_label,
1986 priv->audio_local_candidate_info_img, candidate);
1991 empathy_call_window_constructed (GObject *object)
1993 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1994 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1995 TpyCallChannel *call;
1997 g_assert (priv->handler != NULL);
1999 g_object_get (priv->handler, "call-channel", &call, NULL);
2000 priv->outgoing = (call == NULL);
2002 g_object_unref (call);
2004 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2005 g_assert (priv->contact != NULL);
2007 if (!empathy_contact_can_voip_video (priv->contact))
2009 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2010 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2013 empathy_call_window_setup_avatars (self, priv->handler);
2014 empathy_call_window_set_state_connecting (self);
2016 if (!empathy_call_handler_has_initial_video (priv->handler))
2018 gtk_toggle_tool_button_set_active (
2019 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2021 /* If call has InitialVideo, the preview will be started once the call has
2022 * been started (start_call()). */
2024 update_send_codec (self, TRUE);
2025 update_send_codec (self, FALSE);
2026 update_recv_codec (self, TRUE);
2027 update_recv_codec (self, FALSE);
2029 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2030 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2031 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2032 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2033 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2034 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2035 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2036 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2038 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2039 G_CALLBACK (candidates_changed_cb), self, 0);
2042 static void empathy_call_window_dispose (GObject *object);
2043 static void empathy_call_window_finalize (GObject *object);
2046 empathy_call_window_set_property (GObject *object,
2047 guint property_id, const GValue *value, GParamSpec *pspec)
2049 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2051 switch (property_id)
2053 case PROP_CALL_HANDLER:
2054 priv->handler = g_value_dup_object (value);
2057 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2062 empathy_call_window_get_property (GObject *object,
2063 guint property_id, GValue *value, GParamSpec *pspec)
2065 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2067 switch (property_id)
2069 case PROP_CALL_HANDLER:
2070 g_value_set_object (value, priv->handler);
2073 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2078 empathy_call_window_class_init (
2079 EmpathyCallWindowClass *empathy_call_window_class)
2081 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2082 GParamSpec *param_spec;
2084 g_type_class_add_private (empathy_call_window_class,
2085 sizeof (EmpathyCallWindowPriv));
2087 object_class->constructed = empathy_call_window_constructed;
2088 object_class->set_property = empathy_call_window_set_property;
2089 object_class->get_property = empathy_call_window_get_property;
2091 object_class->dispose = empathy_call_window_dispose;
2092 object_class->finalize = empathy_call_window_finalize;
2094 param_spec = g_param_spec_object ("handler",
2095 "handler", "The call handler",
2096 EMPATHY_TYPE_CALL_HANDLER,
2097 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2098 g_object_class_install_property (object_class,
2099 PROP_CALL_HANDLER, param_spec);
2103 empathy_call_window_dispose (GObject *object)
2105 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2106 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2108 if (priv->dispose_has_run)
2111 priv->dispose_has_run = TRUE;
2113 if (priv->handler != NULL)
2115 empathy_call_handler_stop_call (priv->handler);
2116 tp_clear_object (&priv->handler);
2119 if (priv->bus_message_source_id != 0)
2121 g_source_remove (priv->bus_message_source_id);
2122 priv->bus_message_source_id = 0;
2125 if (priv->got_video_src > 0)
2127 g_source_remove (priv->got_video_src);
2128 priv->got_video_src = 0;
2131 if (priv->inactivity_src > 0)
2133 g_source_remove (priv->inactivity_src);
2134 priv->inactivity_src = 0;
2137 tp_clear_object (&priv->pipeline);
2138 tp_clear_object (&priv->video_input);
2139 tp_clear_object (&priv->audio_input);
2140 tp_clear_object (&priv->video_tee);
2141 tp_clear_object (&priv->ui_manager);
2142 tp_clear_object (&priv->fullscreen);
2143 tp_clear_object (&priv->camera_monitor);
2144 tp_clear_object (&priv->settings);
2145 tp_clear_object (&priv->sound_mgr);
2146 tp_clear_object (&priv->mic_menu);
2147 tp_clear_object (&priv->camera_menu);
2149 g_list_free_full (priv->notifiers, g_object_unref);
2151 if (priv->timer_id != 0)
2152 g_source_remove (priv->timer_id);
2155 if (priv->contact != NULL)
2157 g_signal_handlers_disconnect_by_func (priv->contact,
2158 contact_name_changed_cb, self);
2159 priv->contact = NULL;
2162 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2166 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2168 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2170 if (priv->video_output_motion_handler_id != 0)
2172 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2173 priv->video_output_motion_handler_id);
2174 priv->video_output_motion_handler_id = 0;
2179 empathy_call_window_finalize (GObject *object)
2181 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2182 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2184 disconnect_video_output_motion_handler (self);
2186 /* free any data held directly by the object here */
2187 g_mutex_free (priv->lock);
2189 g_timer_destroy (priv->timer);
2191 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2196 empathy_call_window_new (EmpathyCallHandler *handler)
2198 return EMPATHY_CALL_WINDOW (
2199 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2203 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2204 GstElement *conference, gpointer user_data)
2206 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2207 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2208 FsElementAddedNotifier *notifier;
2211 DEBUG ("Conference added");
2213 /* Add notifier to set the various element properties as needed */
2214 notifier = fs_element_added_notifier_new ();
2215 keyfile = fs_utils_get_default_element_properties (conference);
2217 if (keyfile != NULL)
2218 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2220 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2222 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2224 gst_bin_add (GST_BIN (priv->pipeline), conference);
2225 gst_element_set_state (conference, GST_STATE_PLAYING);
2229 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2230 GstElement *conference, gpointer user_data)
2232 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2233 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2235 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2236 gst_element_set_state (conference, GST_STATE_NULL);
2240 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2242 GstStateChangeReturn state_change_return;
2243 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2245 if (priv->pipeline == NULL)
2248 if (priv->bus_message_source_id != 0)
2250 g_source_remove (priv->bus_message_source_id);
2251 priv->bus_message_source_id = 0;
2254 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2256 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2257 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2259 if (priv->pipeline != NULL)
2260 g_object_unref (priv->pipeline);
2261 priv->pipeline = NULL;
2263 if (priv->audio_output != NULL)
2264 g_object_unref (priv->audio_output);
2265 priv->audio_output = NULL;
2267 if (priv->video_tee != NULL)
2268 g_object_unref (priv->video_tee);
2269 priv->video_tee = NULL;
2271 if (priv->video_preview != NULL)
2272 clutter_actor_destroy (priv->video_preview);
2273 priv->video_preview = NULL;
2275 /* If we destroy the preview while it's being dragged, we won't
2276 * get the ::drag-end signal, so manually destroy the clone */
2277 if (priv->drag_preview != NULL)
2279 clutter_actor_destroy (priv->drag_preview);
2280 empathy_call_window_show_preview_rectangles (self, FALSE);
2281 priv->drag_preview = NULL;
2284 priv->funnel = NULL;
2286 create_pipeline (self);
2287 /* Call will be started when user will hit the 'redial' button */
2288 priv->start_call_when_playing = FALSE;
2289 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2295 g_message ("Error: could not destroy pipeline. Closing call window");
2296 gtk_widget_destroy (GTK_WIDGET (self));
2303 reset_details_pane (EmpathyCallWindow *self)
2305 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2307 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2308 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2309 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2310 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2314 empathy_call_window_disconnected (EmpathyCallWindow *self,
2317 gboolean could_disconnect = FALSE;
2318 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2319 gboolean could_reset_pipeline;
2321 /* Leave full screen mode if needed */
2322 gtk_window_unfullscreen (GTK_WINDOW (self));
2324 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2325 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2327 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2329 if (priv->call_state == CONNECTING)
2330 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2332 if (priv->call_state != REDIALING)
2333 priv->call_state = DISCONNECTED;
2335 /* Show the toolbar */
2336 clutter_state_set_state (priv->transitions, "fade-in");
2338 if (could_reset_pipeline)
2340 g_mutex_lock (priv->lock);
2342 g_timer_stop (priv->timer);
2344 if (priv->timer_id != 0)
2345 g_source_remove (priv->timer_id);
2348 g_mutex_unlock (priv->lock);
2351 /* We are about to destroy the window, no need to update it or create
2352 * a video preview */
2355 empathy_call_window_status_message (self, _("Disconnected"));
2357 empathy_call_window_show_hangup_button (self, FALSE);
2359 /* Unsensitive the camera and mic button */
2360 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2361 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2363 /* Be sure that the mic button is enabled */
2364 gtk_toggle_tool_button_set_active (
2365 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2367 if (priv->camera_state == CAMERA_STATE_ON)
2369 /* Restart the preview with the new pipeline. */
2370 display_video_preview (self, TRUE);
2373 /* destroy the video output; it will be recreated when we'll redial */
2374 disconnect_video_output_motion_handler (self);
2375 if (priv->video_output != NULL)
2376 clutter_actor_destroy (priv->video_output);
2377 priv->video_output = NULL;
2378 if (priv->got_video_src > 0)
2380 g_source_remove (priv->got_video_src);
2381 priv->got_video_src = 0;
2384 gtk_widget_show (priv->remote_user_avatar_widget);
2386 reset_details_pane (self);
2388 priv->sending_video = FALSE;
2389 priv->call_started = FALSE;
2391 could_disconnect = TRUE;
2393 /* TODO: display the self avatar of the preview (depends if the "Always
2394 * Show Video Preview" is enabled or not) */
2397 return could_disconnect;
2402 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2405 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2406 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2408 if (empathy_call_window_disconnected (self, TRUE) &&
2409 priv->call_state == REDIALING)
2410 empathy_call_window_restart_call (self);
2414 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2416 FsMediaType media_type,
2417 EmpathyCallWindow *self)
2419 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2421 DEBUG ("removing content");
2424 * This assumes that there is only one video stream per channel...
2427 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2429 if (priv->funnel != NULL)
2433 output = priv->video_output_sink;
2435 gst_element_set_state (output, GST_STATE_NULL);
2436 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2438 gst_bin_remove (GST_BIN (priv->pipeline), output);
2439 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2440 priv->funnel = NULL;
2444 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2446 if (priv->audio_output != NULL)
2448 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2450 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2451 priv->audio_output = NULL;
2459 /* Called with global lock held */
2461 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2463 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2467 if (priv->funnel == NULL)
2469 output = priv->video_output_sink;
2471 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2475 g_warning ("Could not create fsfunnel");
2479 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2481 gst_object_unref (priv->funnel);
2482 priv->funnel = NULL;
2483 g_warning ("Could not add funnel to pipeline");
2487 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2489 g_warning ("Could not add the video output widget to the pipeline");
2493 if (!gst_element_link (priv->funnel, output))
2495 g_warning ("Could not link output sink to funnel");
2496 goto error_output_added;
2499 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2501 g_warning ("Could not start video sink");
2502 goto error_output_added;
2505 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2507 g_warning ("Could not start funnel");
2508 goto error_output_added;
2512 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2515 g_warning ("Could not get request pad from funnel");
2522 gst_element_set_locked_state (priv->funnel, TRUE);
2523 gst_element_set_locked_state (output, TRUE);
2525 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2526 gst_element_set_state (output, GST_STATE_NULL);
2528 gst_bin_remove (GST_BIN (priv->pipeline), output);
2529 gst_element_set_locked_state (output, FALSE);
2533 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2534 priv->funnel = NULL;
2539 /* Called with global lock held */
2541 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2543 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2545 GstPadTemplate *template;
2547 if (priv->audio_output == NULL)
2549 priv->audio_output = empathy_audio_sink_new ();
2550 g_object_ref_sink (priv->audio_output);
2552 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2554 g_warning ("Could not add audio sink to pipeline");
2555 g_object_unref (priv->audio_output);
2556 goto error_add_output;
2559 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2561 g_warning ("Could not start audio sink");
2566 template = gst_element_class_get_pad_template (
2567 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2569 pad = gst_element_request_pad (priv->audio_output,
2570 template, NULL, NULL);
2574 g_warning ("Could not get sink pad from sink");
2581 gst_element_set_locked_state (priv->audio_output, TRUE);
2582 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2583 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2584 priv->audio_output = NULL;
2592 empathy_call_window_update_timer (gpointer user_data)
2594 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2595 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2596 const gchar *status;
2600 time_ = g_timer_elapsed (priv->timer, NULL);
2602 if (priv->call_state == HELD)
2603 status = _("On hold");
2604 else if (!gtk_toggle_tool_button_get_active (
2605 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2608 status = _("Duration");
2610 /* Translators: 'status - minutes:seconds' the caller has been connected */
2611 str = g_strdup_printf (_("%s — %d:%02dm"),
2613 (int) time_ / 60, (int) time_ % 60);
2614 empathy_call_window_status_message (self, str);
2622 display_error (EmpathyCallWindow *self,
2623 TpyCallChannel *call,
2627 const gchar *details)
2629 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2630 GtkWidget *info_bar;
2631 GtkWidget *content_area;
2638 /* Create info bar */
2639 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2642 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2644 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2646 /* hbox containing the image and the messages vbox */
2647 hbox = gtk_hbox_new (FALSE, 3);
2648 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2651 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2652 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2654 /* vbox containing the main message and the details expander */
2655 vbox = gtk_vbox_new (FALSE, 3);
2656 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2659 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2661 label = gtk_label_new (NULL);
2662 gtk_label_set_markup (GTK_LABEL (label), txt);
2663 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2664 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2667 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2670 if (details != NULL)
2672 GtkWidget *expander;
2674 expander = gtk_expander_new (_("Technical Details"));
2676 txt = g_strdup_printf ("<i>%s</i>", details);
2678 label = gtk_label_new (NULL);
2679 gtk_label_set_markup (GTK_LABEL (label), txt);
2680 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2681 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2684 gtk_container_add (GTK_CONTAINER (expander), label);
2685 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2688 g_signal_connect (info_bar, "response",
2689 G_CALLBACK (gtk_widget_destroy), NULL);
2691 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2692 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2693 gtk_widget_show_all (info_bar);
2697 media_stream_error_to_txt (EmpathyCallWindow *self,
2698 TpyCallChannel *call,
2700 TpMediaStreamError error)
2702 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2703 const gchar *cm = NULL;
2709 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2711 return g_strdup_printf (
2712 _("%s's software does not understand any of the audio formats "
2713 "supported by your computer"),
2714 empathy_contact_get_alias (priv->contact));
2716 return g_strdup_printf (
2717 _("%s's software does not understand any of the video formats "
2718 "supported by your computer"),
2719 empathy_contact_get_alias (priv->contact));
2721 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2722 return g_strdup_printf (
2723 _("Can't establish a connection to %s. "
2724 "One of you might be on a network that does not allow "
2725 "direct connections."),
2726 empathy_contact_get_alias (priv->contact));
2728 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2729 return g_strdup (_("There was a failure on the network"));
2731 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2733 return g_strdup (_("The audio formats necessary for this call "
2734 "are not installed on your computer"));
2736 return g_strdup (_("The video formats necessary for this call "
2737 "are not installed on your computer"));
2739 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2740 tp_connection_parse_object_path (
2741 tp_channel_borrow_connection (TP_CHANNEL (call)),
2744 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2745 "product=Telepathy&component=%s", cm);
2747 result = g_strdup_printf (
2748 _("Something unexpected happened in a Telepathy component. "
2749 "Please <a href=\"%s\">report this bug</a> and attach "
2750 "logs gathered from the 'Debug' window in the Help menu."), url);
2756 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2757 return g_strdup (_("There was a failure in the call engine"));
2759 case TP_MEDIA_STREAM_ERROR_EOS:
2760 return g_strdup (_("The end of the stream was reached"));
2762 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2769 empathy_call_window_stream_error (EmpathyCallWindow *self,
2770 TpyCallChannel *call,
2779 desc = media_stream_error_to_txt (self, call, audio, code);
2782 /* No description, use the error message. That's not great as it's not
2783 * localized but it's better than nothing. */
2784 display_error (self, call, icon, title, msg, NULL);
2788 display_error (self, call, icon, title, desc, msg);
2794 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2797 EmpathyCallWindow *self)
2799 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2800 "gnome-stock-mic", _("Can't establish audio stream"));
2804 empathy_call_window_video_stream_error (TpyCallChannel *call,
2807 EmpathyCallWindow *self)
2809 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2810 "camera-web", _("Can't establish video stream"));
2815 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2817 EmpathyCallWindow *self)
2819 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2820 TpyCallChannel *call;
2821 gboolean can_send_video;
2823 if (state != TPY_CALL_STATE_ACCEPTED)
2826 if (priv->call_state == CONNECTED)
2829 g_timer_start (priv->timer);
2830 priv->call_state = CONNECTED;
2832 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2834 can_send_video = priv->video_input != NULL &&
2835 empathy_contact_can_voip_video (priv->contact) &&
2836 empathy_camera_monitor_get_available (priv->camera_monitor);
2838 g_object_get (priv->handler, "call-channel", &call, NULL);
2840 if (tpy_call_channel_has_dtmf (call))
2841 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2843 if (priv->video_input == NULL)
2844 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2846 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2848 empathy_call_window_show_hangup_button (self, TRUE);
2850 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2852 clutter_actor_hide (priv->video_output);
2853 gtk_widget_show (priv->remote_user_avatar_widget);
2855 g_object_unref (call);
2857 g_mutex_lock (priv->lock);
2859 priv->timer_id = g_timeout_add_seconds (1,
2860 empathy_call_window_update_timer, self);
2862 g_mutex_unlock (priv->lock);
2864 empathy_call_window_update_timer (self);
2866 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2870 empathy_call_window_show_video_output_cb (gpointer user_data)
2872 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2874 if (self->priv->video_output != NULL)
2876 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2877 clutter_actor_show (self->priv->video_output);
2878 empathy_call_window_raise_actors (self);
2885 empathy_call_window_check_video_cb (gpointer data)
2887 EmpathyCallWindow *self = data;
2889 if (self->priv->got_video)
2891 self->priv->got_video = FALSE;
2895 /* No video in the last N seconds, display the remote avatar */
2896 empathy_call_window_show_video_output (self, FALSE);
2901 /* Called from the streaming thread */
2903 empathy_call_window_video_probe_cb (GstPad *pad,
2904 GstMiniObject *mini_obj,
2905 EmpathyCallWindow *self)
2908 if (GST_IS_EVENT (mini_obj))
2911 if (G_UNLIKELY (!self->priv->got_video))
2913 /* show the remote video */
2914 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2915 empathy_call_window_show_video_output_cb,
2916 g_object_ref (self), g_object_unref);
2918 self->priv->got_video = TRUE;
2924 /* Called from the streaming thread */
2926 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2927 GstPad *src, guint media_type, gpointer user_data)
2929 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2930 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2931 gboolean retval = FALSE;
2935 g_mutex_lock (priv->lock);
2939 case TP_MEDIA_STREAM_TYPE_AUDIO:
2940 pad = empathy_call_window_get_audio_sink_pad (self);
2942 case TP_MEDIA_STREAM_TYPE_VIDEO:
2943 g_idle_add (empathy_call_window_show_video_output_cb, self);
2944 pad = empathy_call_window_get_video_sink_pad (self);
2946 gst_pad_add_data_probe (src,
2947 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2948 if (priv->got_video_src > 0)
2949 g_source_remove (priv->got_video_src);
2950 priv->got_video_src = g_timeout_add_seconds (5,
2951 empathy_call_window_check_video_cb, self);
2954 g_assert_not_reached ();
2960 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2961 g_warning ("Could not link %s sink pad",
2962 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2966 gst_object_unref (pad);
2970 /* If no sink could be linked, try to add fakesink to prevent the whole call
2975 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2977 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2979 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2980 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2981 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2983 gst_element_set_locked_state (fakesink, TRUE);
2984 gst_element_set_state (fakesink, GST_STATE_NULL);
2985 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2989 DEBUG ("Could not link real sink, linked fakesink instead");
2991 gst_object_unref (sinkpad);
2995 gst_object_unref (fakesink);
3000 g_mutex_unlock (priv->lock);
3006 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
3007 GstPad *sink, FsMediaType media_type, gpointer user_data)
3009 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3010 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3012 gboolean retval = FALSE;
3016 case FS_MEDIA_TYPE_AUDIO:
3017 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3019 g_warning ("Could not add audio source to pipeline");
3023 pad = gst_element_get_static_pad (priv->audio_input, "src");
3026 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3027 g_warning ("Could not get source pad from audio source");
3031 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3033 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3034 g_warning ("Could not link audio source to farsight");
3038 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3040 g_warning ("Could not start audio source");
3041 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3042 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3048 case FS_MEDIA_TYPE_VIDEO:
3049 if (priv->video_tee != NULL)
3051 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3052 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3054 g_warning ("Could not link video source input pipeline");
3057 gst_object_unref (pad);
3063 g_assert_not_reached ();
3070 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3072 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3073 GstElement *preview;
3075 disable_camera (self);
3077 DEBUG ("remove video input");
3078 preview = priv->video_preview_sink;
3080 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3081 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3082 gst_element_set_state (preview, GST_STATE_NULL);
3084 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3087 g_object_unref (priv->video_input);
3088 priv->video_input = NULL;
3089 g_object_unref (priv->video_tee);
3090 priv->video_tee = NULL;
3091 clutter_actor_destroy (priv->video_preview);
3092 priv->video_preview = NULL;
3094 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3098 start_call (EmpathyCallWindow *self)
3100 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3102 priv->call_started = TRUE;
3103 empathy_call_handler_start_call (priv->handler,
3104 gtk_get_current_event_time ());
3106 if (empathy_call_handler_has_initial_video (priv->handler))
3108 TpyCallChannel *call;
3111 g_object_get (priv->handler, "call-channel", &call, NULL);
3112 s = tpy_call_channel_get_video_state (call);
3114 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3115 s == TPY_SENDING_STATE_SENDING)
3117 /* Enable 'send video' buttons and display the preview */
3118 gtk_toggle_tool_button_set_active (
3119 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3123 gtk_toggle_tool_button_set_active (
3124 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3126 if (priv->video_preview == NULL)
3128 create_video_preview (self);
3129 add_video_preview_to_pipeline (self);
3133 g_object_unref (call);
3138 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3141 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3142 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3145 empathy_call_handler_bus_message (priv->handler, bus, message);
3147 switch (GST_MESSAGE_TYPE (message))
3149 case GST_MESSAGE_STATE_CHANGED:
3150 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3152 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3154 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3155 !priv->call_started)
3157 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3158 if (newstate == GST_STATE_PAUSED)
3160 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3161 priv->pipeline_playing = TRUE;
3163 if (priv->start_call_when_playing)
3168 case GST_MESSAGE_ERROR:
3170 GError *error = NULL;
3171 GstElement *gst_error;
3174 gst_message_parse_error (message, &error, &debug);
3175 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3177 g_message ("Element error: %s -- %s\n", error->message, debug);
3179 if (g_str_has_prefix (gst_element_get_name (gst_error),
3180 VIDEO_INPUT_ERROR_PREFIX))
3182 /* Remove the video input and continue */
3183 if (priv->video_input != NULL)
3184 empathy_call_window_remove_video_input (self);
3185 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3189 empathy_call_window_disconnected (self, TRUE);
3191 g_error_free (error);
3194 case GST_MESSAGE_UNKNOWN:
3195 case GST_MESSAGE_EOS:
3196 case GST_MESSAGE_WARNING:
3197 case GST_MESSAGE_INFO:
3198 case GST_MESSAGE_TAG:
3199 case GST_MESSAGE_BUFFERING:
3200 case GST_MESSAGE_STATE_DIRTY:
3201 case GST_MESSAGE_STEP_DONE:
3202 case GST_MESSAGE_CLOCK_PROVIDE:
3203 case GST_MESSAGE_CLOCK_LOST:
3204 case GST_MESSAGE_NEW_CLOCK:
3205 case GST_MESSAGE_STRUCTURE_CHANGE:
3206 case GST_MESSAGE_STREAM_STATUS:
3207 case GST_MESSAGE_APPLICATION:
3208 case GST_MESSAGE_ELEMENT:
3209 case GST_MESSAGE_SEGMENT_START:
3210 case GST_MESSAGE_SEGMENT_DONE:
3211 case GST_MESSAGE_DURATION:
3212 case GST_MESSAGE_ANY:
3221 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3222 GHashTable *members,
3223 EmpathyCallWindow *self)
3225 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3226 GHashTableIter iter;
3227 gpointer key, value;
3228 gboolean held = FALSE;
3230 g_hash_table_iter_init (&iter, members);
3231 while (g_hash_table_iter_next (&iter, &key, &value))
3233 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3235 /* This assumes this is a 1-1 call, otherwise one participant
3236 * putting the call on hold wouldn't mean the call is on hold
3244 priv->call_state = HELD;
3245 else if (priv->call_state == HELD)
3246 priv->call_state = CONNECTED;
3250 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3252 EmpathyCallWindow *self)
3254 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3255 TpyCallChannel *call;
3257 g_object_get (priv->handler, "call-channel", &call, NULL);
3262 tp_g_signal_connect_object (call, "audio-stream-error",
3263 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3264 tp_g_signal_connect_object (call, "video-stream-error",
3265 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3268 tp_g_signal_connect_object (call, "members-changed",
3269 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3271 g_object_unref (call);
3275 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3277 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3278 TpyCallChannel *call;
3281 /* Make the hangup button twice as wide */
3282 width = gtk_widget_get_allocated_width (priv->hangup_button);
3283 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3285 g_signal_connect (priv->handler, "state-changed",
3286 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3287 g_signal_connect (priv->handler, "conference-added",
3288 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3289 g_signal_connect (priv->handler, "conference-removed",
3290 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3291 g_signal_connect (priv->handler, "closed",
3292 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3293 g_signal_connect (priv->handler, "src-pad-added",
3294 G_CALLBACK (empathy_call_window_src_added_cb), window);
3295 g_signal_connect (priv->handler, "sink-pad-added",
3296 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3297 g_signal_connect (priv->handler, "sink-pad-removed",
3298 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3300 g_object_get (priv->handler, "call-channel", &call, NULL);
3303 call_handler_notify_call_cb (priv->handler, NULL, window);
3304 g_object_unref (call);
3308 /* call-channel doesn't exist yet, we'll connect signals once it has been
3310 g_signal_connect (priv->handler, "notify::call-channel",
3311 G_CALLBACK (call_handler_notify_call_cb), window);
3314 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3318 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3319 EmpathyCallWindow *window)
3321 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3323 if (priv->pipeline != NULL)
3325 if (priv->bus_message_source_id != 0)
3327 g_source_remove (priv->bus_message_source_id);
3328 priv->bus_message_source_id = 0;
3331 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3334 if (priv->call_state == CONNECTING)
3335 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3341 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3344 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3346 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3351 gtk_widget_hide (priv->dtmf_panel);
3352 gtk_widget_hide (menu);
3353 gtk_widget_hide (priv->toolbar);
3357 if (priv->dialpad_was_visible_before_fs)
3358 gtk_widget_show (priv->dtmf_panel);
3360 gtk_widget_show (menu);
3361 gtk_widget_show (priv->toolbar);
3363 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3364 priv->original_height_before_fs);
3369 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3371 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3373 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3374 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3375 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3376 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3378 if (priv->video_output != NULL)
3381 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3382 priv->video_output, TRUE, TRUE,
3383 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3390 empathy_call_window_state_event_cb (GtkWidget *widget,
3391 GdkEventWindowState *event, EmpathyCallWindow *window)
3393 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3395 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3396 gboolean set_fullscreen = event->new_window_state &
3397 GDK_WINDOW_STATE_FULLSCREEN;
3401 gboolean dialpad_was_visible;
3402 GtkAllocation allocation;
3403 gint original_width, original_height;
3405 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3406 original_width = allocation.width;
3407 original_height = allocation.height;
3409 g_object_get (priv->dtmf_panel,
3410 "visible", &dialpad_was_visible,
3413 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3414 priv->original_width_before_fs = original_width;
3415 priv->original_height_before_fs = original_height;
3417 if (priv->video_output_motion_handler_id == 0 &&
3418 priv->video_output != NULL)
3420 priv->video_output_motion_handler_id = g_signal_connect (
3421 G_OBJECT (priv->video_container), "motion-notify-event",
3422 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3428 disconnect_video_output_motion_handler (window);
3431 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3433 show_controls (window, set_fullscreen);
3434 show_borders (window, set_fullscreen);
3435 gtk_action_set_stock_id (priv->menu_fullscreen,
3436 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3437 priv->is_fullscreen = set_fullscreen;
3444 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3447 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3448 int w, h, dialpad_width;
3449 GtkAllocation allocation;
3451 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3452 w = allocation.width;
3453 h = allocation.height;
3455 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3459 gtk_widget_show (priv->dtmf_panel);
3465 gtk_widget_hide (priv->dtmf_panel);
3469 gtk_window_resize (GTK_WINDOW (window), w, h);
3473 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3476 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3477 TpyCallChannel *call;
3479 priv->sending_video = (state == CAMERA_STATE_ON);
3481 if (state == CAMERA_STATE_ON)
3483 /* When we start sending video, we want to show the video preview by
3485 display_video_preview (window, TRUE);
3489 display_video_preview (window, FALSE);
3492 if (priv->call_state != CONNECTED)
3495 g_object_get (priv->handler, "call-channel", &call, NULL);
3496 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3497 tpy_call_channel_send_video (call, priv->sending_video);
3498 g_object_unref (call);
3502 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3503 EmpathyCallWindow *self)
3505 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3508 active = (gtk_toggle_tool_button_get_active (toggle));
3510 /* We don't want the settings callback to react to this change to avoid
3512 g_signal_handlers_block_by_func (priv->settings,
3513 empathy_call_window_prefs_volume_changed_cb, self);
3517 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3518 priv->volume * 100);
3522 /* TODO, Instead of setting the input volume to 0 we should probably
3523 * stop sending but this would cause the audio call to drop if both
3524 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3525 * in the future. GNOME #574574
3527 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3531 g_signal_handlers_unblock_by_func (priv->settings,
3532 empathy_call_window_prefs_volume_changed_cb, self);
3536 empathy_call_window_hangup_cb (gpointer object,
3537 EmpathyCallWindow *self)
3539 empathy_call_handler_stop_call (self->priv->handler);
3541 empathy_call_window_disconnected (self, TRUE);
3545 empathy_call_window_restart_call (EmpathyCallWindow *window)
3547 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3549 /* Remove error info bars */
3550 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3551 (GtkCallback) gtk_widget_destroy, NULL);
3553 create_video_output_widget (window);
3555 /* While the call was disconnected, the input volume might have changed.
3556 * However, since the audio_input source was destroyed, its volume has not
3557 * been updated during that time. That's why we manually update it here */
3558 empathy_call_window_mic_volume_changed (window);
3560 priv->outgoing = TRUE;
3561 empathy_call_window_set_state_connecting (window);
3563 if (priv->pipeline_playing)
3564 start_call (window);
3566 /* call will be started when the pipeline is ready */
3567 priv->start_call_when_playing = TRUE;
3569 empathy_call_window_setup_avatars (window, priv->handler);
3571 empathy_call_window_show_hangup_button (window, TRUE);
3575 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3576 EmpathyCallWindow *window)
3580 active = gtk_toggle_tool_button_get_active (button);
3582 empathy_call_window_show_dialpad (window, active);
3586 empathy_call_window_fullscreen_cb (gpointer object,
3587 EmpathyCallWindow *window)
3589 empathy_call_window_fullscreen_toggle (window);
3593 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3595 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3597 if (priv->is_fullscreen)
3598 gtk_window_unfullscreen (GTK_WINDOW (window));
3600 gtk_window_fullscreen (GTK_WINDOW (window));
3604 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3605 GdkEventButton *event, EmpathyCallWindow *window)
3607 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3609 empathy_call_window_video_menu_popup (window, event->button);
3617 empathy_call_window_key_press_cb (GtkWidget *video_output,
3618 GdkEventKey *event, EmpathyCallWindow *window)
3620 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3622 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3624 /* Since we are in fullscreen mode, toggling will bring us back to
3626 empathy_call_window_fullscreen_toggle (window);
3634 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3635 GdkEventMotion *event, EmpathyCallWindow *window)
3637 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3639 if (priv->is_fullscreen)
3641 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3643 /* Show the bottom toolbar */
3644 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3651 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3655 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3657 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3659 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3660 button, gtk_get_current_event_time ());
3661 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3665 empathy_call_window_status_message (EmpathyCallWindow *self,
3668 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3672 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3673 gdouble value, EmpathyCallWindow *window)
3675 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3677 if (priv->audio_output == NULL)
3680 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3685 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3687 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3689 return priv->ui_manager;
3692 EmpathyGstAudioSrc *
3693 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3695 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3697 return (EmpathyGstAudioSrc *) priv->audio_input;
3700 EmpathyGstVideoSrc *
3701 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3703 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);