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 empathy_call_window_setup_avatars (self, priv->handler);
2008 empathy_call_window_set_state_connecting (self);
2010 if (!empathy_call_handler_has_initial_video (priv->handler))
2012 gtk_toggle_tool_button_set_active (
2013 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2015 /* If call has InitialVideo, the preview will be started once the call has
2016 * been started (start_call()). */
2018 update_send_codec (self, TRUE);
2019 update_send_codec (self, FALSE);
2020 update_recv_codec (self, TRUE);
2021 update_recv_codec (self, FALSE);
2023 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2024 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2025 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2026 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2027 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2028 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2029 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2030 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2032 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2033 G_CALLBACK (candidates_changed_cb), self, 0);
2036 static void empathy_call_window_dispose (GObject *object);
2037 static void empathy_call_window_finalize (GObject *object);
2040 empathy_call_window_set_property (GObject *object,
2041 guint property_id, const GValue *value, GParamSpec *pspec)
2043 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2045 switch (property_id)
2047 case PROP_CALL_HANDLER:
2048 priv->handler = g_value_dup_object (value);
2051 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2056 empathy_call_window_get_property (GObject *object,
2057 guint property_id, GValue *value, GParamSpec *pspec)
2059 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2061 switch (property_id)
2063 case PROP_CALL_HANDLER:
2064 g_value_set_object (value, priv->handler);
2067 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2072 empathy_call_window_class_init (
2073 EmpathyCallWindowClass *empathy_call_window_class)
2075 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2076 GParamSpec *param_spec;
2078 g_type_class_add_private (empathy_call_window_class,
2079 sizeof (EmpathyCallWindowPriv));
2081 object_class->constructed = empathy_call_window_constructed;
2082 object_class->set_property = empathy_call_window_set_property;
2083 object_class->get_property = empathy_call_window_get_property;
2085 object_class->dispose = empathy_call_window_dispose;
2086 object_class->finalize = empathy_call_window_finalize;
2088 param_spec = g_param_spec_object ("handler",
2089 "handler", "The call handler",
2090 EMPATHY_TYPE_CALL_HANDLER,
2091 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2092 g_object_class_install_property (object_class,
2093 PROP_CALL_HANDLER, param_spec);
2097 empathy_call_window_dispose (GObject *object)
2099 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2100 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2102 if (priv->dispose_has_run)
2105 priv->dispose_has_run = TRUE;
2107 if (priv->handler != NULL)
2109 empathy_call_handler_stop_call (priv->handler);
2110 tp_clear_object (&priv->handler);
2113 if (priv->bus_message_source_id != 0)
2115 g_source_remove (priv->bus_message_source_id);
2116 priv->bus_message_source_id = 0;
2119 if (priv->got_video_src > 0)
2121 g_source_remove (priv->got_video_src);
2122 priv->got_video_src = 0;
2125 if (priv->inactivity_src > 0)
2127 g_source_remove (priv->inactivity_src);
2128 priv->inactivity_src = 0;
2131 tp_clear_object (&priv->pipeline);
2132 tp_clear_object (&priv->video_input);
2133 tp_clear_object (&priv->audio_input);
2134 tp_clear_object (&priv->video_tee);
2135 tp_clear_object (&priv->ui_manager);
2136 tp_clear_object (&priv->fullscreen);
2137 tp_clear_object (&priv->camera_monitor);
2138 tp_clear_object (&priv->settings);
2139 tp_clear_object (&priv->sound_mgr);
2140 tp_clear_object (&priv->mic_menu);
2141 tp_clear_object (&priv->camera_menu);
2143 g_list_free_full (priv->notifiers, g_object_unref);
2145 if (priv->timer_id != 0)
2146 g_source_remove (priv->timer_id);
2149 if (priv->contact != NULL)
2151 g_signal_handlers_disconnect_by_func (priv->contact,
2152 contact_name_changed_cb, self);
2153 priv->contact = NULL;
2156 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2160 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2162 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2164 if (priv->video_output_motion_handler_id != 0)
2166 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2167 priv->video_output_motion_handler_id);
2168 priv->video_output_motion_handler_id = 0;
2173 empathy_call_window_finalize (GObject *object)
2175 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2176 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2178 disconnect_video_output_motion_handler (self);
2180 /* free any data held directly by the object here */
2181 g_mutex_free (priv->lock);
2183 g_timer_destroy (priv->timer);
2185 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2190 empathy_call_window_new (EmpathyCallHandler *handler)
2192 return EMPATHY_CALL_WINDOW (
2193 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2197 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2198 GstElement *conference, gpointer user_data)
2200 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2201 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2202 FsElementAddedNotifier *notifier;
2205 DEBUG ("Conference added");
2207 /* Add notifier to set the various element properties as needed */
2208 notifier = fs_element_added_notifier_new ();
2209 keyfile = fs_utils_get_default_element_properties (conference);
2211 if (keyfile != NULL)
2212 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2214 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2216 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2218 gst_bin_add (GST_BIN (priv->pipeline), conference);
2219 gst_element_set_state (conference, GST_STATE_PLAYING);
2223 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2224 GstElement *conference, gpointer user_data)
2226 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2227 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2229 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2230 gst_element_set_state (conference, GST_STATE_NULL);
2234 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2236 GstStateChangeReturn state_change_return;
2237 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2239 if (priv->pipeline == NULL)
2242 if (priv->bus_message_source_id != 0)
2244 g_source_remove (priv->bus_message_source_id);
2245 priv->bus_message_source_id = 0;
2248 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2250 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2251 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2253 if (priv->pipeline != NULL)
2254 g_object_unref (priv->pipeline);
2255 priv->pipeline = NULL;
2257 if (priv->audio_output != NULL)
2258 g_object_unref (priv->audio_output);
2259 priv->audio_output = NULL;
2261 if (priv->video_tee != NULL)
2262 g_object_unref (priv->video_tee);
2263 priv->video_tee = NULL;
2265 if (priv->video_preview != NULL)
2266 clutter_actor_destroy (priv->video_preview);
2267 priv->video_preview = NULL;
2269 /* If we destroy the preview while it's being dragged, we won't
2270 * get the ::drag-end signal, so manually destroy the clone */
2271 if (priv->drag_preview != NULL)
2273 clutter_actor_destroy (priv->drag_preview);
2274 empathy_call_window_show_preview_rectangles (self, FALSE);
2275 priv->drag_preview = NULL;
2278 priv->funnel = NULL;
2280 create_pipeline (self);
2281 /* Call will be started when user will hit the 'redial' button */
2282 priv->start_call_when_playing = FALSE;
2283 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2289 g_message ("Error: could not destroy pipeline. Closing call window");
2290 gtk_widget_destroy (GTK_WIDGET (self));
2297 reset_details_pane (EmpathyCallWindow *self)
2299 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2301 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2302 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2303 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2304 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2308 empathy_call_window_disconnected (EmpathyCallWindow *self,
2311 gboolean could_disconnect = FALSE;
2312 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2313 gboolean could_reset_pipeline;
2315 /* Leave full screen mode if needed */
2316 gtk_window_unfullscreen (GTK_WINDOW (self));
2318 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2319 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2321 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2323 if (priv->call_state == CONNECTING)
2324 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2326 if (priv->call_state != REDIALING)
2327 priv->call_state = DISCONNECTED;
2329 /* Show the toolbar */
2330 clutter_state_set_state (priv->transitions, "fade-in");
2332 if (could_reset_pipeline)
2334 g_mutex_lock (priv->lock);
2336 g_timer_stop (priv->timer);
2338 if (priv->timer_id != 0)
2339 g_source_remove (priv->timer_id);
2342 g_mutex_unlock (priv->lock);
2345 /* We are about to destroy the window, no need to update it or create
2346 * a video preview */
2349 empathy_call_window_status_message (self, _("Disconnected"));
2351 empathy_call_window_show_hangup_button (self, FALSE);
2353 /* Unsensitive the camera and mic button */
2354 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2355 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2357 /* Be sure that the mic button is enabled */
2358 gtk_toggle_tool_button_set_active (
2359 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2361 if (priv->camera_state == CAMERA_STATE_ON)
2363 /* Restart the preview with the new pipeline. */
2364 display_video_preview (self, TRUE);
2367 /* destroy the video output; it will be recreated when we'll redial */
2368 disconnect_video_output_motion_handler (self);
2369 if (priv->video_output != NULL)
2370 clutter_actor_destroy (priv->video_output);
2371 priv->video_output = NULL;
2372 if (priv->got_video_src > 0)
2374 g_source_remove (priv->got_video_src);
2375 priv->got_video_src = 0;
2378 gtk_widget_show (priv->remote_user_avatar_widget);
2380 reset_details_pane (self);
2382 priv->sending_video = FALSE;
2383 priv->call_started = FALSE;
2385 could_disconnect = TRUE;
2387 /* TODO: display the self avatar of the preview (depends if the "Always
2388 * Show Video Preview" is enabled or not) */
2391 return could_disconnect;
2396 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2399 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2400 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2402 if (empathy_call_window_disconnected (self, TRUE) &&
2403 priv->call_state == REDIALING)
2404 empathy_call_window_restart_call (self);
2408 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2410 FsMediaType media_type,
2411 EmpathyCallWindow *self)
2413 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2415 DEBUG ("removing content");
2418 * This assumes that there is only one video stream per channel...
2421 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2423 if (priv->funnel != NULL)
2427 output = priv->video_output_sink;
2429 gst_element_set_state (output, GST_STATE_NULL);
2430 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2432 gst_bin_remove (GST_BIN (priv->pipeline), output);
2433 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2434 priv->funnel = NULL;
2438 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2440 if (priv->audio_output != NULL)
2442 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2444 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2445 priv->audio_output = NULL;
2453 /* Called with global lock held */
2455 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2461 if (priv->funnel == NULL)
2463 output = priv->video_output_sink;
2465 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2469 g_warning ("Could not create fsfunnel");
2473 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2475 gst_object_unref (priv->funnel);
2476 priv->funnel = NULL;
2477 g_warning ("Could not add funnel to pipeline");
2481 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2483 g_warning ("Could not add the video output widget to the pipeline");
2487 if (!gst_element_link (priv->funnel, output))
2489 g_warning ("Could not link output sink to funnel");
2490 goto error_output_added;
2493 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2495 g_warning ("Could not start video sink");
2496 goto error_output_added;
2499 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2501 g_warning ("Could not start funnel");
2502 goto error_output_added;
2506 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2509 g_warning ("Could not get request pad from funnel");
2516 gst_element_set_locked_state (priv->funnel, TRUE);
2517 gst_element_set_locked_state (output, TRUE);
2519 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2520 gst_element_set_state (output, GST_STATE_NULL);
2522 gst_bin_remove (GST_BIN (priv->pipeline), output);
2523 gst_element_set_locked_state (output, FALSE);
2527 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2528 priv->funnel = NULL;
2533 /* Called with global lock held */
2535 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2537 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2539 GstPadTemplate *template;
2541 if (priv->audio_output == NULL)
2543 priv->audio_output = empathy_audio_sink_new ();
2544 g_object_ref_sink (priv->audio_output);
2546 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2548 g_warning ("Could not add audio sink to pipeline");
2549 g_object_unref (priv->audio_output);
2550 goto error_add_output;
2553 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2555 g_warning ("Could not start audio sink");
2560 template = gst_element_class_get_pad_template (
2561 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2563 pad = gst_element_request_pad (priv->audio_output,
2564 template, NULL, NULL);
2568 g_warning ("Could not get sink pad from sink");
2575 gst_element_set_locked_state (priv->audio_output, TRUE);
2576 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2577 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2578 priv->audio_output = NULL;
2586 empathy_call_window_update_timer (gpointer user_data)
2588 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2589 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2590 const gchar *status;
2594 time_ = g_timer_elapsed (priv->timer, NULL);
2596 if (priv->call_state == HELD)
2597 status = _("On hold");
2598 else if (!gtk_toggle_tool_button_get_active (
2599 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2602 status = _("Duration");
2604 /* Translators: 'status - minutes:seconds' the caller has been connected */
2605 str = g_strdup_printf (_("%s — %d:%02dm"),
2607 (int) time_ / 60, (int) time_ % 60);
2608 empathy_call_window_status_message (self, str);
2616 display_error (EmpathyCallWindow *self,
2617 TpyCallChannel *call,
2621 const gchar *details)
2623 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2624 GtkWidget *info_bar;
2625 GtkWidget *content_area;
2632 /* Create info bar */
2633 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2636 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2638 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2640 /* hbox containing the image and the messages vbox */
2641 hbox = gtk_hbox_new (FALSE, 3);
2642 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2645 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2646 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2648 /* vbox containing the main message and the details expander */
2649 vbox = gtk_vbox_new (FALSE, 3);
2650 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2653 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2655 label = gtk_label_new (NULL);
2656 gtk_label_set_markup (GTK_LABEL (label), txt);
2657 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2658 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2661 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2664 if (details != NULL)
2666 GtkWidget *expander;
2668 expander = gtk_expander_new (_("Technical Details"));
2670 txt = g_strdup_printf ("<i>%s</i>", details);
2672 label = gtk_label_new (NULL);
2673 gtk_label_set_markup (GTK_LABEL (label), txt);
2674 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2675 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2678 gtk_container_add (GTK_CONTAINER (expander), label);
2679 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2682 g_signal_connect (info_bar, "response",
2683 G_CALLBACK (gtk_widget_destroy), NULL);
2685 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2686 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2687 gtk_widget_show_all (info_bar);
2691 media_stream_error_to_txt (EmpathyCallWindow *self,
2692 TpyCallChannel *call,
2694 TpMediaStreamError error)
2696 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2697 const gchar *cm = NULL;
2703 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2705 return g_strdup_printf (
2706 _("%s's software does not understand any of the audio formats "
2707 "supported by your computer"),
2708 empathy_contact_get_alias (priv->contact));
2710 return g_strdup_printf (
2711 _("%s's software does not understand any of the video formats "
2712 "supported by your computer"),
2713 empathy_contact_get_alias (priv->contact));
2715 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2716 return g_strdup_printf (
2717 _("Can't establish a connection to %s. "
2718 "One of you might be on a network that does not allow "
2719 "direct connections."),
2720 empathy_contact_get_alias (priv->contact));
2722 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2723 return g_strdup (_("There was a failure on the network"));
2725 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2727 return g_strdup (_("The audio formats necessary for this call "
2728 "are not installed on your computer"));
2730 return g_strdup (_("The video formats necessary for this call "
2731 "are not installed on your computer"));
2733 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2734 tp_connection_parse_object_path (
2735 tp_channel_borrow_connection (TP_CHANNEL (call)),
2738 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2739 "product=Telepathy&component=%s", cm);
2741 result = g_strdup_printf (
2742 _("Something unexpected happened in a Telepathy component. "
2743 "Please <a href=\"%s\">report this bug</a> and attach "
2744 "logs gathered from the 'Debug' window in the Help menu."), url);
2750 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2751 return g_strdup (_("There was a failure in the call engine"));
2753 case TP_MEDIA_STREAM_ERROR_EOS:
2754 return g_strdup (_("The end of the stream was reached"));
2756 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2763 empathy_call_window_stream_error (EmpathyCallWindow *self,
2764 TpyCallChannel *call,
2773 desc = media_stream_error_to_txt (self, call, audio, code);
2776 /* No description, use the error message. That's not great as it's not
2777 * localized but it's better than nothing. */
2778 display_error (self, call, icon, title, msg, NULL);
2782 display_error (self, call, icon, title, desc, msg);
2788 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2791 EmpathyCallWindow *self)
2793 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2794 "gnome-stock-mic", _("Can't establish audio stream"));
2798 empathy_call_window_video_stream_error (TpyCallChannel *call,
2801 EmpathyCallWindow *self)
2803 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2804 "camera-web", _("Can't establish video stream"));
2809 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2811 EmpathyCallWindow *self)
2813 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2814 TpyCallChannel *call;
2815 gboolean can_send_video;
2817 if (state != TPY_CALL_STATE_ACCEPTED)
2820 if (priv->call_state == CONNECTED)
2823 g_timer_start (priv->timer);
2824 priv->call_state = CONNECTED;
2826 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2828 can_send_video = priv->video_input != NULL &&
2829 empathy_contact_can_voip_video (priv->contact) &&
2830 empathy_camera_monitor_get_available (priv->camera_monitor);
2832 g_object_get (priv->handler, "call-channel", &call, NULL);
2834 if (tpy_call_channel_has_dtmf (call))
2835 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2837 if (priv->video_input == NULL)
2838 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2840 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2842 empathy_call_window_show_hangup_button (self, TRUE);
2844 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2846 clutter_actor_hide (priv->video_output);
2847 gtk_widget_show (priv->remote_user_avatar_widget);
2849 g_object_unref (call);
2851 g_mutex_lock (priv->lock);
2853 priv->timer_id = g_timeout_add_seconds (1,
2854 empathy_call_window_update_timer, self);
2856 g_mutex_unlock (priv->lock);
2858 empathy_call_window_update_timer (self);
2860 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2864 empathy_call_window_show_video_output_cb (gpointer user_data)
2866 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2868 if (self->priv->video_output != NULL)
2870 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2871 clutter_actor_show (self->priv->video_output);
2872 empathy_call_window_raise_actors (self);
2879 empathy_call_window_check_video_cb (gpointer data)
2881 EmpathyCallWindow *self = data;
2883 if (self->priv->got_video)
2885 self->priv->got_video = FALSE;
2889 /* No video in the last N seconds, display the remote avatar */
2890 empathy_call_window_show_video_output (self, FALSE);
2895 /* Called from the streaming thread */
2897 empathy_call_window_video_probe_cb (GstPad *pad,
2898 GstMiniObject *mini_obj,
2899 EmpathyCallWindow *self)
2902 if (GST_IS_EVENT (mini_obj))
2905 if (G_UNLIKELY (!self->priv->got_video))
2907 /* show the remote video */
2908 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2909 empathy_call_window_show_video_output_cb,
2910 g_object_ref (self), g_object_unref);
2912 self->priv->got_video = TRUE;
2918 /* Called from the streaming thread */
2920 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2921 GstPad *src, guint media_type, gpointer user_data)
2923 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2924 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2925 gboolean retval = FALSE;
2929 g_mutex_lock (priv->lock);
2933 case TP_MEDIA_STREAM_TYPE_AUDIO:
2934 pad = empathy_call_window_get_audio_sink_pad (self);
2936 case TP_MEDIA_STREAM_TYPE_VIDEO:
2937 g_idle_add (empathy_call_window_show_video_output_cb, self);
2938 pad = empathy_call_window_get_video_sink_pad (self);
2940 gst_pad_add_data_probe (src,
2941 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2942 if (priv->got_video_src > 0)
2943 g_source_remove (priv->got_video_src);
2944 priv->got_video_src = g_timeout_add_seconds (5,
2945 empathy_call_window_check_video_cb, self);
2948 g_assert_not_reached ();
2954 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2955 g_warning ("Could not link %s sink pad",
2956 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2960 gst_object_unref (pad);
2964 /* If no sink could be linked, try to add fakesink to prevent the whole call
2969 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2971 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2973 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2974 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2975 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2977 gst_element_set_locked_state (fakesink, TRUE);
2978 gst_element_set_state (fakesink, GST_STATE_NULL);
2979 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2983 DEBUG ("Could not link real sink, linked fakesink instead");
2985 gst_object_unref (sinkpad);
2989 gst_object_unref (fakesink);
2994 g_mutex_unlock (priv->lock);
3000 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
3001 GstPad *sink, FsMediaType media_type, gpointer user_data)
3003 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3004 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3006 gboolean retval = FALSE;
3010 case FS_MEDIA_TYPE_AUDIO:
3011 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3013 g_warning ("Could not add audio source to pipeline");
3017 pad = gst_element_get_static_pad (priv->audio_input, "src");
3020 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3021 g_warning ("Could not get source pad from audio source");
3025 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3027 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3028 g_warning ("Could not link audio source to farsight");
3032 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3034 g_warning ("Could not start audio source");
3035 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3036 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3042 case FS_MEDIA_TYPE_VIDEO:
3043 if (priv->video_tee != NULL)
3045 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3046 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3048 g_warning ("Could not link video source input pipeline");
3051 gst_object_unref (pad);
3057 g_assert_not_reached ();
3064 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3066 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3067 GstElement *preview;
3069 disable_camera (self);
3071 DEBUG ("remove video input");
3072 preview = priv->video_preview_sink;
3074 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3075 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3076 gst_element_set_state (preview, GST_STATE_NULL);
3078 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3081 g_object_unref (priv->video_input);
3082 priv->video_input = NULL;
3083 g_object_unref (priv->video_tee);
3084 priv->video_tee = NULL;
3085 clutter_actor_destroy (priv->video_preview);
3086 priv->video_preview = NULL;
3088 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3092 start_call (EmpathyCallWindow *self)
3094 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3096 priv->call_started = TRUE;
3097 empathy_call_handler_start_call (priv->handler,
3098 gtk_get_current_event_time ());
3100 if (empathy_call_handler_has_initial_video (priv->handler))
3102 TpyCallChannel *call;
3105 g_object_get (priv->handler, "call-channel", &call, NULL);
3106 s = tpy_call_channel_get_video_state (call);
3108 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3109 s == TPY_SENDING_STATE_SENDING)
3111 /* Enable 'send video' buttons and display the preview */
3112 gtk_toggle_tool_button_set_active (
3113 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3117 gtk_toggle_tool_button_set_active (
3118 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3120 if (priv->video_preview == NULL)
3122 create_video_preview (self);
3123 add_video_preview_to_pipeline (self);
3127 g_object_unref (call);
3132 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3135 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3136 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3139 empathy_call_handler_bus_message (priv->handler, bus, message);
3141 switch (GST_MESSAGE_TYPE (message))
3143 case GST_MESSAGE_STATE_CHANGED:
3144 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3146 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3148 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3149 !priv->call_started)
3151 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3152 if (newstate == GST_STATE_PAUSED)
3154 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3155 priv->pipeline_playing = TRUE;
3157 if (priv->start_call_when_playing)
3162 case GST_MESSAGE_ERROR:
3164 GError *error = NULL;
3165 GstElement *gst_error;
3168 gst_message_parse_error (message, &error, &debug);
3169 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3171 g_message ("Element error: %s -- %s\n", error->message, debug);
3173 if (g_str_has_prefix (gst_element_get_name (gst_error),
3174 VIDEO_INPUT_ERROR_PREFIX))
3176 /* Remove the video input and continue */
3177 if (priv->video_input != NULL)
3178 empathy_call_window_remove_video_input (self);
3179 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3183 empathy_call_window_disconnected (self, TRUE);
3185 g_error_free (error);
3188 case GST_MESSAGE_UNKNOWN:
3189 case GST_MESSAGE_EOS:
3190 case GST_MESSAGE_WARNING:
3191 case GST_MESSAGE_INFO:
3192 case GST_MESSAGE_TAG:
3193 case GST_MESSAGE_BUFFERING:
3194 case GST_MESSAGE_STATE_DIRTY:
3195 case GST_MESSAGE_STEP_DONE:
3196 case GST_MESSAGE_CLOCK_PROVIDE:
3197 case GST_MESSAGE_CLOCK_LOST:
3198 case GST_MESSAGE_NEW_CLOCK:
3199 case GST_MESSAGE_STRUCTURE_CHANGE:
3200 case GST_MESSAGE_STREAM_STATUS:
3201 case GST_MESSAGE_APPLICATION:
3202 case GST_MESSAGE_ELEMENT:
3203 case GST_MESSAGE_SEGMENT_START:
3204 case GST_MESSAGE_SEGMENT_DONE:
3205 case GST_MESSAGE_DURATION:
3206 case GST_MESSAGE_ANY:
3215 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3216 GHashTable *members,
3217 EmpathyCallWindow *self)
3219 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3220 GHashTableIter iter;
3221 gpointer key, value;
3222 gboolean held = FALSE;
3224 g_hash_table_iter_init (&iter, members);
3225 while (g_hash_table_iter_next (&iter, &key, &value))
3227 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3229 /* This assumes this is a 1-1 call, otherwise one participant
3230 * putting the call on hold wouldn't mean the call is on hold
3238 priv->call_state = HELD;
3239 else if (priv->call_state == HELD)
3240 priv->call_state = CONNECTED;
3244 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3246 EmpathyCallWindow *self)
3248 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3249 TpyCallChannel *call;
3251 g_object_get (priv->handler, "call-channel", &call, NULL);
3256 tp_g_signal_connect_object (call, "audio-stream-error",
3257 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3258 tp_g_signal_connect_object (call, "video-stream-error",
3259 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3262 tp_g_signal_connect_object (call, "members-changed",
3263 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3265 g_object_unref (call);
3269 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3271 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3272 TpyCallChannel *call;
3275 /* Make the hangup button twice as wide */
3276 width = gtk_widget_get_allocated_width (priv->hangup_button);
3277 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3279 g_signal_connect (priv->handler, "state-changed",
3280 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3281 g_signal_connect (priv->handler, "conference-added",
3282 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3283 g_signal_connect (priv->handler, "conference-removed",
3284 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3285 g_signal_connect (priv->handler, "closed",
3286 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3287 g_signal_connect (priv->handler, "src-pad-added",
3288 G_CALLBACK (empathy_call_window_src_added_cb), window);
3289 g_signal_connect (priv->handler, "sink-pad-added",
3290 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3291 g_signal_connect (priv->handler, "sink-pad-removed",
3292 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3294 g_object_get (priv->handler, "call-channel", &call, NULL);
3297 call_handler_notify_call_cb (priv->handler, NULL, window);
3298 g_object_unref (call);
3302 /* call-channel doesn't exist yet, we'll connect signals once it has been
3304 g_signal_connect (priv->handler, "notify::call-channel",
3305 G_CALLBACK (call_handler_notify_call_cb), window);
3308 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3312 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3313 EmpathyCallWindow *window)
3315 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3317 if (priv->pipeline != NULL)
3319 if (priv->bus_message_source_id != 0)
3321 g_source_remove (priv->bus_message_source_id);
3322 priv->bus_message_source_id = 0;
3325 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3328 if (priv->call_state == CONNECTING)
3329 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3335 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3338 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3340 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3345 gtk_widget_hide (priv->dtmf_panel);
3346 gtk_widget_hide (menu);
3347 gtk_widget_hide (priv->toolbar);
3351 if (priv->dialpad_was_visible_before_fs)
3352 gtk_widget_show (priv->dtmf_panel);
3354 gtk_widget_show (menu);
3355 gtk_widget_show (priv->toolbar);
3357 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3358 priv->original_height_before_fs);
3363 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3365 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3367 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3368 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3369 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3370 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3372 if (priv->video_output != NULL)
3375 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3376 priv->video_output, TRUE, TRUE,
3377 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3384 empathy_call_window_state_event_cb (GtkWidget *widget,
3385 GdkEventWindowState *event, EmpathyCallWindow *window)
3387 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3389 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3390 gboolean set_fullscreen = event->new_window_state &
3391 GDK_WINDOW_STATE_FULLSCREEN;
3395 gboolean dialpad_was_visible;
3396 GtkAllocation allocation;
3397 gint original_width, original_height;
3399 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3400 original_width = allocation.width;
3401 original_height = allocation.height;
3403 g_object_get (priv->dtmf_panel,
3404 "visible", &dialpad_was_visible,
3407 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3408 priv->original_width_before_fs = original_width;
3409 priv->original_height_before_fs = original_height;
3411 if (priv->video_output_motion_handler_id == 0 &&
3412 priv->video_output != NULL)
3414 priv->video_output_motion_handler_id = g_signal_connect (
3415 G_OBJECT (priv->video_container), "motion-notify-event",
3416 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3422 disconnect_video_output_motion_handler (window);
3425 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3427 show_controls (window, set_fullscreen);
3428 show_borders (window, set_fullscreen);
3429 gtk_action_set_stock_id (priv->menu_fullscreen,
3430 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3431 priv->is_fullscreen = set_fullscreen;
3438 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3441 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3442 int w, h, dialpad_width;
3443 GtkAllocation allocation;
3445 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3446 w = allocation.width;
3447 h = allocation.height;
3449 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3453 gtk_widget_show (priv->dtmf_panel);
3459 gtk_widget_hide (priv->dtmf_panel);
3463 gtk_window_resize (GTK_WINDOW (window), w, h);
3467 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3470 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3471 TpyCallChannel *call;
3473 priv->sending_video = (state == CAMERA_STATE_ON);
3475 if (state == CAMERA_STATE_ON)
3477 /* When we start sending video, we want to show the video preview by
3479 display_video_preview (window, TRUE);
3483 display_video_preview (window, FALSE);
3486 if (priv->call_state != CONNECTED)
3489 g_object_get (priv->handler, "call-channel", &call, NULL);
3490 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3491 tpy_call_channel_send_video (call, priv->sending_video);
3492 g_object_unref (call);
3496 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3497 EmpathyCallWindow *self)
3499 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3502 active = (gtk_toggle_tool_button_get_active (toggle));
3504 /* We don't want the settings callback to react to this change to avoid
3506 g_signal_handlers_block_by_func (priv->settings,
3507 empathy_call_window_prefs_volume_changed_cb, self);
3511 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3512 priv->volume * 100);
3516 /* TODO, Instead of setting the input volume to 0 we should probably
3517 * stop sending but this would cause the audio call to drop if both
3518 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3519 * in the future. GNOME #574574
3521 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3525 g_signal_handlers_unblock_by_func (priv->settings,
3526 empathy_call_window_prefs_volume_changed_cb, self);
3530 empathy_call_window_hangup_cb (gpointer object,
3531 EmpathyCallWindow *self)
3533 empathy_call_handler_stop_call (self->priv->handler);
3535 empathy_call_window_disconnected (self, TRUE);
3539 empathy_call_window_restart_call (EmpathyCallWindow *window)
3541 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3543 /* Remove error info bars */
3544 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3545 (GtkCallback) gtk_widget_destroy, NULL);
3547 create_video_output_widget (window);
3549 /* While the call was disconnected, the input volume might have changed.
3550 * However, since the audio_input source was destroyed, its volume has not
3551 * been updated during that time. That's why we manually update it here */
3552 empathy_call_window_mic_volume_changed (window);
3554 priv->outgoing = TRUE;
3555 empathy_call_window_set_state_connecting (window);
3557 if (priv->pipeline_playing)
3558 start_call (window);
3560 /* call will be started when the pipeline is ready */
3561 priv->start_call_when_playing = TRUE;
3563 empathy_call_window_setup_avatars (window, priv->handler);
3565 empathy_call_window_show_hangup_button (window, TRUE);
3569 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3570 EmpathyCallWindow *window)
3574 active = gtk_toggle_tool_button_get_active (button);
3576 empathy_call_window_show_dialpad (window, active);
3580 empathy_call_window_fullscreen_cb (gpointer object,
3581 EmpathyCallWindow *window)
3583 empathy_call_window_fullscreen_toggle (window);
3587 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3589 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3591 if (priv->is_fullscreen)
3592 gtk_window_unfullscreen (GTK_WINDOW (window));
3594 gtk_window_fullscreen (GTK_WINDOW (window));
3598 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3599 GdkEventButton *event, EmpathyCallWindow *window)
3601 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3603 empathy_call_window_video_menu_popup (window, event->button);
3611 empathy_call_window_key_press_cb (GtkWidget *video_output,
3612 GdkEventKey *event, EmpathyCallWindow *window)
3614 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3616 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3618 /* Since we are in fullscreen mode, toggling will bring us back to
3620 empathy_call_window_fullscreen_toggle (window);
3628 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3629 GdkEventMotion *event, EmpathyCallWindow *window)
3631 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3633 if (priv->is_fullscreen)
3635 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3637 /* Show the bottom toolbar */
3638 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3645 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3649 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3651 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3653 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3654 button, gtk_get_current_event_time ());
3655 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3659 empathy_call_window_status_message (EmpathyCallWindow *self,
3662 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3666 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3667 gdouble value, EmpathyCallWindow *window)
3669 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3671 if (priv->audio_output == NULL)
3674 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3679 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3681 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3683 return priv->ui_manager;
3686 EmpathyGstAudioSrc *
3687 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3689 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3691 return (EmpathyGstAudioSrc *) priv->audio_input;
3694 EmpathyGstVideoSrc *
3695 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3697 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);