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-request-util.h>
47 #include <libempathy/empathy-utils.h>
49 #include <libempathy-gtk/empathy-avatar-image.h>
50 #include <libempathy-gtk/empathy-ui-utils.h>
51 #include <libempathy-gtk/empathy-sound-manager.h>
52 #include <libempathy-gtk/empathy-geometry.h>
53 #include <libempathy-gtk/empathy-images.h>
55 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
56 #include <libempathy/empathy-debug.h>
58 #include "empathy-call-window.h"
59 #include "empathy-call-window-fullscreen.h"
60 #include "empathy-call-factory.h"
61 #include "empathy-video-widget.h"
62 #include "empathy-about-dialog.h"
63 #include "empathy-audio-src.h"
64 #include "empathy-audio-sink.h"
65 #include "empathy-video-src.h"
66 #include "empathy-mic-menu.h"
67 #include "empathy-preferences.h"
68 #include "empathy-rounded-actor.h"
69 #include "empathy-rounded-rectangle.h"
70 #include "empathy-rounded-texture.h"
71 #include "empathy-camera-menu.h"
73 #define CONTENT_HBOX_BORDER_WIDTH 6
74 #define CONTENT_HBOX_SPACING 3
75 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
77 #define SELF_VIDEO_SECTION_WIDTH 120
78 #define SELF_VIDEO_SECTION_HEIGHT 90
79 #define SELF_VIDEO_SECTION_MARGIN 10
81 #define FLOATING_TOOLBAR_OPACITY 192
82 #define FLOATING_TOOLBAR_WIDTH 280
83 #define FLOATING_TOOLBAR_HEIGHT 36
84 #define FLOATING_TOOLBAR_SPACING 20
86 /* The avatar's default width and height are set to the same value because we
87 want a square icon. */
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
89 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
90 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
92 #define SMALL_TOOLBAR_SIZE 36
94 /* If an video input error occurs, the error message will start with "v4l" */
95 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
97 /* The time interval in milliseconds between 2 outgoing rings */
98 #define MS_BETWEEN_RING 500
100 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
103 PROP_CALL_HANDLER = 1,
116 CAMERA_STATE_OFF = 0,
122 PREVIEW_POS_TOP_LEFT,
123 PREVIEW_POS_TOP_RIGHT,
124 PREVIEW_POS_BOTTOM_LEFT,
125 PREVIEW_POS_BOTTOM_RIGHT,
128 struct _EmpathyCallWindowPriv
130 gboolean dispose_has_run;
131 EmpathyCallHandler *handler;
133 EmpathyContact *contact;
135 EmpathyCameraMonitor *camera_monitor;
140 GtkUIManager *ui_manager;
141 GtkWidget *errors_vbox;
142 /* widget displays the video received from the remote user. This widget is
143 * alive only during call. */
144 ClutterActor *video_output;
145 ClutterActor *video_preview;
146 ClutterActor *drag_preview;
147 ClutterActor *preview_shown_button;
148 ClutterActor *preview_hidden_button;
149 ClutterActor *preview_rectangle1;
150 ClutterActor *preview_rectangle2;
151 ClutterActor *preview_rectangle3;
152 ClutterActor *preview_rectangle4;
153 ClutterActor *preview_rectangle_box1;
154 ClutterActor *preview_rectangle_box2;
155 ClutterActor *preview_rectangle_box3;
156 ClutterActor *preview_rectangle_box4;
157 GtkWidget *video_container;
158 GtkWidget *remote_user_avatar_widget;
159 GtkWidget *remote_user_avatar_toolbar;
160 GtkWidget *remote_user_name_toolbar;
161 GtkWidget *status_label;
162 GtkWidget *hangup_button;
163 GtkWidget *audio_call_button;
164 GtkWidget *video_call_button;
165 GtkWidget *mic_button;
166 GtkWidget *camera_button;
167 GtkWidget *dialpad_button;
169 GtkWidget *bottom_toolbar;
170 ClutterActor *floating_toolbar;
172 GtkAction *menu_fullscreen;
173 GtkAction *menu_swap_camera;
175 ClutterState *transitions;
177 /* The box that contains self and remote avatar and video
178 input/output. When we redial, we destroy and re-create the box */
179 ClutterActor *video_box;
180 ClutterLayoutManager *video_layout;
182 /* Coordinates of the preview drag event's start. */
183 PreviewPosition preview_pos;
185 /* We keep a reference on the hbox which contains the main content so we can
186 easilly repack everything when toggling fullscreen */
187 GtkWidget *content_hbox;
189 /* These are used to accept or reject an incoming call when the status
191 TpyCallChannel *pending_channel;
192 TpChannelDispatchOperation *pending_cdo;
193 TpAddDispatchOperationContext *pending_context;
195 gulong video_output_motion_handler_id;
196 guint bus_message_source_id;
200 GtkWidget *dtmf_panel;
203 GtkWidget *details_vbox;
204 GtkWidget *vcodec_encoding_label;
205 GtkWidget *acodec_encoding_label;
206 GtkWidget *vcodec_decoding_label;
207 GtkWidget *acodec_decoding_label;
209 GtkWidget *audio_remote_candidate_label;
210 GtkWidget *audio_local_candidate_label;
211 GtkWidget *video_remote_candidate_label;
212 GtkWidget *video_local_candidate_label;
213 GtkWidget *video_remote_candidate_info_img;
214 GtkWidget *video_local_candidate_info_img;
215 GtkWidget *audio_remote_candidate_info_img;
216 GtkWidget *audio_local_candidate_info_img;
218 GstElement *video_input;
219 GstElement *video_preview_sink;
220 GstElement *video_output_sink;
221 GstElement *audio_input;
222 GstElement *audio_output;
223 GstElement *pipeline;
224 GstElement *video_tee;
234 gboolean call_started;
235 gboolean sending_video;
236 CameraState camera_state;
238 EmpathyCallWindowFullscreen *fullscreen;
239 gboolean is_fullscreen;
244 guint inactivity_src;
246 /* Those fields represent the state of the window before it actually was in
248 gboolean dialpad_was_visible_before_fs;
249 gint original_width_before_fs;
250 gint original_height_before_fs;
252 gint x, y, w, h, dialpad_width;
255 /* TRUE if the call should be started when the pipeline is playing */
256 gboolean start_call_when_playing;
257 /* TRUE if we requested to set the pipeline in the playing state */
258 gboolean pipeline_playing;
260 EmpathySoundManager *sound_mgr;
263 EmpathyMicMenu *mic_menu;
264 EmpathyCameraMenu *camera_menu;
267 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
269 static void empathy_call_window_realized_cb (GtkWidget *widget,
270 EmpathyCallWindow *window);
272 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
273 GdkEvent *event, EmpathyCallWindow *window);
275 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
276 GdkEventWindowState *event, EmpathyCallWindow *window);
278 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
281 static void empathy_call_window_mic_toggled_cb (
282 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
284 static void empathy_call_window_hangup_cb (gpointer object,
285 EmpathyCallWindow *window);
287 static void empathy_call_window_fullscreen_cb (gpointer object,
288 EmpathyCallWindow *window);
290 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
292 static gboolean empathy_call_window_video_button_press_cb (
293 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
295 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
296 GdkEventKey *event, EmpathyCallWindow *window);
298 static gboolean empathy_call_window_video_output_motion_notify (
299 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
301 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
304 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
306 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
307 EmpathyCallWindow *window);
309 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
311 static void empathy_call_window_status_message (EmpathyCallWindow *window,
314 static gboolean empathy_call_window_bus_message (GstBus *bus,
315 GstMessage *message, gpointer user_data);
318 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
319 gdouble value, EmpathyCallWindow *window);
322 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
325 gtk_widget_set_visible (self->priv->hangup_button, show);
326 gtk_widget_set_visible (self->priv->audio_call_button, !show);
327 gtk_widget_set_visible (self->priv->video_call_button, !show);
331 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
332 EmpathyCallWindow *self)
334 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
335 empathy_call_window_restart_call (self);
339 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
340 EmpathyCallWindow *self)
342 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
343 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
344 empathy_call_window_restart_call (self);
348 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
350 EmpathyCallWindowPriv *priv = GET_PRIV (window);
351 TpyCallChannel *call;
355 g_object_get (priv->handler, "call-channel", &call, NULL);
357 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
358 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
361 tpy_call_channel_dtmf_start_tone (call, event);
363 g_object_unref (call);
367 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
369 EmpathyCallWindowPriv *priv = GET_PRIV (window);
370 TpyCallChannel *call;
372 g_object_get (priv->handler, "call-channel", &call, NULL);
374 tpy_call_channel_dtmf_stop_tone (call);
376 g_object_unref (call);
380 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
382 EmpathyCallWindowPriv *priv = GET_PRIV (self);
385 volume = g_settings_get_double (priv->settings,
386 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
388 /* Don't store the volume because of muting */
389 if (volume > 0 || gtk_toggle_tool_button_get_active (
390 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
391 priv->volume = volume;
393 /* Ensure that the toggle button is active if the volume is > 0 and inactive
394 * if it's smaller than 0 */
395 if ((volume > 0) != gtk_toggle_tool_button_get_active (
396 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
397 gtk_toggle_tool_button_set_active (
398 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
400 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
405 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
407 EmpathyCallWindow *self)
409 empathy_call_window_mic_volume_changed (self);
413 empathy_call_window_raise_actors (EmpathyCallWindow *self)
415 clutter_actor_raise_top (self->priv->floating_toolbar);
417 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
418 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
419 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
420 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
424 empathy_call_window_show_video_output (EmpathyCallWindow *self,
427 if (self->priv->video_output != NULL)
428 g_object_set (self->priv->video_output, "visible", show, NULL);
430 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
432 empathy_call_window_raise_actors (self);
436 create_video_output_widget (EmpathyCallWindow *self)
438 EmpathyCallWindowPriv *priv = GET_PRIV (self);
440 g_assert (priv->video_output == NULL);
441 g_assert (priv->pipeline != NULL);
443 priv->video_output = clutter_texture_new ();
445 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
448 priv->video_output_sink = clutter_gst_video_sink_new (
449 CLUTTER_TEXTURE (priv->video_output));
451 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
454 gtk_widget_add_events (priv->video_container,
455 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
456 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
457 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
461 create_video_input (EmpathyCallWindow *self)
463 EmpathyCallWindowPriv *priv = GET_PRIV (self);
465 g_assert (priv->video_input == NULL);
466 priv->video_input = empathy_video_src_new ();
467 gst_object_ref (priv->video_input);
468 gst_object_sink (priv->video_input);
472 create_audio_input (EmpathyCallWindow *self)
474 EmpathyCallWindowPriv *priv = GET_PRIV (self);
476 g_assert (priv->audio_input == NULL);
477 priv->audio_input = empathy_audio_src_new ();
478 gst_object_ref (priv->audio_input);
479 gst_object_sink (priv->audio_input);
483 add_video_preview_to_pipeline (EmpathyCallWindow *self)
485 EmpathyCallWindowPriv *priv = GET_PRIV (self);
488 g_assert (priv->video_preview != NULL);
489 g_assert (priv->pipeline != NULL);
490 g_assert (priv->video_input != NULL);
491 g_assert (priv->video_tee != NULL);
493 preview = priv->video_preview_sink;
495 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
497 g_warning ("Could not add video input to pipeline");
501 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
503 g_warning ("Could not add video preview to pipeline");
507 if (!gst_element_link (priv->video_input, priv->video_tee))
509 g_warning ("Could not link video input to video tee");
513 if (!gst_element_link (priv->video_tee, preview))
515 g_warning ("Could not link video tee to video preview");
521 empathy_call_window_disable_camera_cb (GtkAction *action,
522 EmpathyCallWindow *self)
524 clutter_actor_destroy (self->priv->preview_hidden_button);
526 gtk_toggle_tool_button_set_active (
527 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
531 empathy_call_window_minimise_camera_cb (GtkAction *action,
532 EmpathyCallWindow *self)
534 clutter_actor_hide (self->priv->video_preview);
535 clutter_actor_show (self->priv->preview_hidden_button);
539 empathy_call_window_maximise_camera_cb (GtkAction *action,
540 EmpathyCallWindow *self)
542 clutter_actor_show (self->priv->video_preview);
543 clutter_actor_hide (self->priv->preview_hidden_button);
547 empathy_call_window_swap_camera_cb (GtkAction *action,
548 EmpathyCallWindow *self)
550 const GList *cameras, *l;
553 DEBUG ("Swapping the camera");
555 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
556 current_cam = empathy_video_src_dup_device (
557 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
559 for (l = cameras; l != NULL; l = l->next)
561 EmpathyCamera *camera = l->data;
563 if (!tp_strdiff (camera->device, current_cam))
568 next = l->next->data;
570 next = cameras->data;
572 /* EmpathyCameraMenu will update itself and do the actual change
574 g_settings_set_string (self->priv->settings,
575 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
582 g_free (current_cam);
586 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
587 EmpathyCamera *camera,
588 EmpathyCallWindow *self)
590 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
592 gtk_action_set_visible (self->priv->menu_swap_camera,
593 g_list_length ((GList *) cameras) >= 2);
597 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
598 EmpathyCamera *camera,
599 EmpathyCallWindow *self)
601 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
603 gtk_action_set_visible (self->priv->menu_swap_camera,
604 g_list_length ((GList *) cameras) >= 2);
608 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
609 EmpathyCallWindow *self)
613 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
615 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
616 0, gtk_get_current_event_time ());
617 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
621 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
622 EmpathyCallWindow *self)
626 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
627 "/preview-hidden-menu");
628 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
629 0, gtk_get_current_event_time ());
630 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
633 static ClutterActor *
634 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
636 ClutterBinAlignment x,
637 ClutterBinAlignment y)
639 ClutterLayoutManager *layout1, *layout2;
640 ClutterActor *rectangle;
641 ClutterActor *box1, *box2;
643 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
644 CLUTTER_BIN_ALIGNMENT_START);
646 box1 = clutter_box_new (layout1);
650 rectangle = empathy_rounded_rectangle_new (
651 SELF_VIDEO_SECTION_WIDTH + 5,
652 SELF_VIDEO_SECTION_HEIGHT + 5);
654 clutter_actor_set_size (box1,
655 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
656 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
657 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
659 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
660 CLUTTER_BIN_ALIGNMENT_CENTER);
662 /* We have a box with the margins and the video in the middle inside
663 * a bigger box with an extra bottom margin so we're not on top of
664 * the floating toolbar. */
665 box2 = clutter_box_new (layout2);
667 clutter_actor_set_size (box2,
668 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
669 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
671 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
672 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
674 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
677 clutter_actor_hide (rectangle);
683 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
685 self->priv->preview_rectangle1 =
686 empathy_call_window_create_preview_rectangle (self,
687 &self->priv->preview_rectangle_box1,
688 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
689 self->priv->preview_rectangle2 =
690 empathy_call_window_create_preview_rectangle (self,
691 &self->priv->preview_rectangle_box2,
692 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
693 self->priv->preview_rectangle3 =
694 empathy_call_window_create_preview_rectangle (self,
695 &self->priv->preview_rectangle_box3,
696 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
697 self->priv->preview_rectangle4 =
698 empathy_call_window_create_preview_rectangle (self,
699 &self->priv->preview_rectangle_box4,
700 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
704 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
707 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
708 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
709 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
710 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
713 static PreviewPosition
714 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
719 PreviewPosition pos = PREVIEW_POS_NONE;
721 if (!clutter_actor_has_allocation (self->priv->video_box))
724 clutter_actor_get_geometry (self->priv->video_box, &box);
726 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
727 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
728 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
729 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
731 pos = PREVIEW_POS_TOP_LEFT;
733 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
734 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
735 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
736 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
738 pos = PREVIEW_POS_TOP_RIGHT;
740 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
741 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
742 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
743 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
745 pos = PREVIEW_POS_BOTTOM_LEFT;
747 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
748 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
749 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
750 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
752 pos = PREVIEW_POS_BOTTOM_RIGHT;
758 static ClutterActor *
759 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
762 ClutterActor *rectangle;
766 case PREVIEW_POS_TOP_LEFT:
767 rectangle = self->priv->preview_rectangle1;
769 case PREVIEW_POS_TOP_RIGHT:
770 rectangle = self->priv->preview_rectangle3;
772 case PREVIEW_POS_BOTTOM_LEFT:
773 rectangle = self->priv->preview_rectangle2;
775 case PREVIEW_POS_BOTTOM_RIGHT:
776 rectangle = self->priv->preview_rectangle4;
786 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
789 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
791 DEBUG ("moving the video preview to %d", pos);
793 self->priv->preview_pos = pos;
797 case PREVIEW_POS_TOP_LEFT:
798 clutter_bin_layout_set_alignment (layout,
799 self->priv->video_preview,
800 CLUTTER_BIN_ALIGNMENT_START,
801 CLUTTER_BIN_ALIGNMENT_START);
803 case PREVIEW_POS_TOP_RIGHT:
804 clutter_bin_layout_set_alignment (layout,
805 self->priv->video_preview,
806 CLUTTER_BIN_ALIGNMENT_END,
807 CLUTTER_BIN_ALIGNMENT_START);
809 case PREVIEW_POS_BOTTOM_LEFT:
810 clutter_bin_layout_set_alignment (layout,
811 self->priv->video_preview,
812 CLUTTER_BIN_ALIGNMENT_START,
813 CLUTTER_BIN_ALIGNMENT_END);
815 case PREVIEW_POS_BOTTOM_RIGHT:
816 clutter_bin_layout_set_alignment (layout,
817 self->priv->video_preview,
818 CLUTTER_BIN_ALIGNMENT_END,
819 CLUTTER_BIN_ALIGNMENT_END);
822 g_warn_if_reached ();
825 g_settings_set_enum (self->priv->settings, "camera-position", pos);
829 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
832 ClutterActor *rectangle;
834 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
836 empathy_rounded_rectangle_set_border_width (
837 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
838 empathy_rounded_rectangle_set_border_color (
839 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
843 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
844 ClutterActor *rectangle)
846 empathy_rounded_rectangle_set_border_width (
847 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
848 empathy_rounded_rectangle_set_border_color (
849 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
853 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
855 ClutterActor *rectangle;
857 rectangle = empathy_call_window_get_preview_rectangle (self,
858 self->priv->preview_pos);
860 /* We don't want to darken the rectangle where the preview
863 if (self->priv->preview_rectangle1 != rectangle)
864 empathy_call_window_darken_preview_rectangle (self,
865 self->priv->preview_rectangle1);
867 if (self->priv->preview_rectangle2 != rectangle)
868 empathy_call_window_darken_preview_rectangle (self,
869 self->priv->preview_rectangle2);
871 if (self->priv->preview_rectangle3 != rectangle)
872 empathy_call_window_darken_preview_rectangle (self,
873 self->priv->preview_rectangle3);
875 if (self->priv->preview_rectangle4 != rectangle)
876 empathy_call_window_darken_preview_rectangle (self,
877 self->priv->preview_rectangle4);
881 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
885 ClutterModifierType modifiers,
886 EmpathyCallWindow *self)
888 ClutterActor *stage = clutter_actor_get_stage (actor);
891 self->priv->drag_preview = clutter_clone_new (actor);
893 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
894 self->priv->drag_preview);
896 clutter_actor_transform_stage_point (actor, event_x, event_y,
899 clutter_actor_set_position (self->priv->drag_preview,
900 event_x - rel_x, event_y - rel_y);
902 clutter_drag_action_set_drag_handle (action,
903 self->priv->drag_preview);
905 clutter_actor_set_opacity (actor, 0);
906 clutter_actor_hide (self->priv->preview_shown_button);
908 empathy_call_window_show_preview_rectangles (self, TRUE);
909 empathy_call_window_darken_preview_rectangles (self);
913 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
917 ClutterModifierType modifiers,
918 EmpathyCallWindow *self)
922 /* Get the position before destroying the drag actor, otherwise the
923 * preview_box allocation won't be valid and we won't be able to
924 * calculate the position. */
925 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
927 /* Destroy the video preview copy that we were dragging */
928 clutter_actor_destroy (self->priv->drag_preview);
929 self->priv->drag_preview = NULL;
931 clutter_actor_set_opacity (actor, 255);
932 clutter_actor_show (self->priv->preview_shown_button);
934 if (pos != PREVIEW_POS_NONE)
935 empathy_call_window_move_video_preview (self, pos);
937 empathy_call_window_show_preview_rectangles (self, FALSE);
941 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
945 EmpathyCallWindow *self)
948 gfloat event_x, event_y;
950 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
952 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
954 if (pos != PREVIEW_POS_NONE)
955 empathy_call_window_highlight_preview_rectangle (self, pos);
957 empathy_call_window_darken_preview_rectangles (self);
961 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
962 ClutterCrossingEvent *event,
963 EmpathyCallWindow *self)
965 ClutterActor *rectangle;
967 rectangle = empathy_call_window_get_preview_rectangle (self,
968 self->priv->preview_pos);
970 empathy_call_window_highlight_preview_rectangle (self,
971 self->priv->preview_pos);
973 clutter_actor_show (rectangle);
979 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
980 ClutterCrossingEvent *event,
981 EmpathyCallWindow *self)
983 ClutterActor *rectangle;
985 rectangle = empathy_call_window_get_preview_rectangle (self,
986 self->priv->preview_pos);
988 empathy_call_window_darken_preview_rectangle (self, rectangle);
990 clutter_actor_hide (rectangle);
996 create_video_preview (EmpathyCallWindow *self)
998 EmpathyCallWindowPriv *priv = GET_PRIV (self);
999 ClutterLayoutManager *layout, *layout_center, *layout_end;
1000 ClutterActor *preview;
1003 ClutterAction *action;
1005 PreviewPosition pos;
1007 g_assert (priv->video_preview == NULL);
1009 pos = g_settings_get_enum (priv->settings, "camera-position");
1011 preview = empathy_rounded_texture_new ();
1012 clutter_actor_set_size (preview,
1013 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1014 priv->video_preview_sink = clutter_gst_video_sink_new (
1015 CLUTTER_TEXTURE (preview));
1017 /* Add a little offset to the video preview */
1018 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1019 CLUTTER_BIN_ALIGNMENT_START);
1020 priv->video_preview = clutter_box_new (layout);
1021 clutter_actor_set_size (priv->video_preview,
1022 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1023 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1024 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1026 /* We have a box with the margins and the video in the middle inside
1027 * a bigger box with an extra bottom margin so we're not on top of
1028 * the floating toolbar. */
1029 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1030 CLUTTER_BIN_ALIGNMENT_CENTER);
1031 box = clutter_box_new (layout_center);
1032 clutter_actor_set_size (box,
1033 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1034 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1036 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1037 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1039 g_object_set (priv->video_preview_sink,
1044 /* Translators: this is an "Info" label. It should be as short
1046 button = gtk_button_new_with_label (_("i"));
1047 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1049 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1051 clutter_actor_set_size (b, 24, 24);
1053 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1054 CLUTTER_BIN_ALIGNMENT_END);
1055 box = clutter_box_new (layout_end);
1056 clutter_actor_set_size (box,
1057 SELF_VIDEO_SECTION_WIDTH,
1058 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1060 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1061 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1063 g_signal_connect (button, "clicked",
1064 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1067 /* Translators: this is an "Info" label. It should be as short
1069 button = gtk_button_new_with_label (_("i"));
1070 b = empathy_rounded_actor_new ();
1072 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1074 clutter_actor_set_size (b, 24, 24);
1075 priv->preview_hidden_button = b;
1077 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1078 priv->preview_hidden_button,
1079 CLUTTER_BIN_ALIGNMENT_START,
1080 CLUTTER_BIN_ALIGNMENT_END);
1082 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1084 clutter_actor_hide (priv->preview_hidden_button);
1086 g_signal_connect (button, "clicked",
1087 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1090 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1091 priv->video_preview,
1092 CLUTTER_BIN_ALIGNMENT_START,
1093 CLUTTER_BIN_ALIGNMENT_END);
1095 empathy_call_window_move_video_preview (self, pos);
1097 action = clutter_drag_action_new ();
1098 g_signal_connect (action, "drag-begin",
1099 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1100 g_signal_connect (action, "drag-end",
1101 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1102 g_signal_connect (action, "drag-motion",
1103 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1105 g_signal_connect (preview, "enter-event",
1106 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1107 g_signal_connect (preview, "leave-event",
1108 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1110 clutter_actor_add_action (preview, action);
1111 clutter_actor_set_reactive (preview, TRUE);
1112 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1116 empathy_call_window_play_camera (EmpathyCallWindow *window,
1119 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1120 GstElement *preview;
1123 if (priv->video_preview == NULL)
1125 create_video_preview (window);
1126 add_video_preview_to_pipeline (window);
1130 state = GST_STATE_PLAYING;
1132 state = GST_STATE_NULL;
1134 preview = priv->video_preview_sink;
1136 gst_element_set_state (preview, state);
1137 gst_element_set_state (priv->video_input, state);
1138 gst_element_set_state (priv->video_tee, state);
1142 display_video_preview (EmpathyCallWindow *self,
1145 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1149 /* Display the video preview */
1150 DEBUG ("Show video preview");
1152 empathy_call_window_play_camera (self, TRUE);
1153 clutter_actor_show (priv->video_preview);
1154 clutter_actor_raise_top (priv->floating_toolbar);
1158 /* Hide the video preview */
1159 DEBUG ("Hide video preview");
1161 if (priv->video_preview != NULL)
1163 clutter_actor_hide (priv->video_preview);
1164 empathy_call_window_play_camera (self, FALSE);
1170 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1172 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1174 empathy_call_window_status_message (window, _("Connecting…"));
1175 priv->call_state = CONNECTING;
1177 /* Show the toolbar */
1178 clutter_state_set_state (priv->transitions, "fade-in");
1181 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1182 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1186 disable_camera (EmpathyCallWindow *self)
1188 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1190 if (priv->camera_state == CAMERA_STATE_OFF)
1193 DEBUG ("Disable camera");
1195 display_video_preview (self, FALSE);
1197 if (priv->camera_state == CAMERA_STATE_ON)
1198 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1200 priv->camera_state = CAMERA_STATE_OFF;
1204 enable_camera (EmpathyCallWindow *self)
1206 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1208 if (priv->camera_state == CAMERA_STATE_ON)
1211 if (priv->video_input == NULL)
1213 DEBUG ("Can't enable camera, no input");
1217 DEBUG ("Enable camera");
1219 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1221 priv->camera_state = CAMERA_STATE_ON;
1225 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1226 EmpathyCallWindow *self)
1228 if (gtk_toggle_tool_button_get_active (toggle))
1229 enable_camera (self);
1231 disable_camera (self);
1235 create_pipeline (EmpathyCallWindow *self)
1237 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1240 g_assert (priv->pipeline == NULL);
1242 priv->pipeline = gst_pipeline_new (NULL);
1243 priv->pipeline_playing = FALSE;
1245 priv->video_tee = gst_element_factory_make ("tee", NULL);
1246 gst_object_ref (priv->video_tee);
1247 gst_object_sink (priv->video_tee);
1249 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1251 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1252 priv->bus_message_source_id = gst_bus_add_watch (bus,
1253 empathy_call_window_bus_message, self);
1255 g_object_unref (bus);
1259 empathy_call_window_settings_cb (GtkAction *action,
1260 EmpathyCallWindow *self)
1262 gchar *args = g_strdup_printf ("-p %s",
1263 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1265 empathy_launch_program (BIN_DIR, "empathy", args);
1271 empathy_call_window_contents_cb (GtkAction *action,
1272 EmpathyCallWindow *self)
1274 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1278 empathy_call_window_debug_cb (GtkAction *action,
1279 EmpathyCallWindow *self)
1281 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1285 empathy_call_window_about_cb (GtkAction *action,
1286 EmpathyCallWindow *self)
1288 empathy_about_dialog_new (GTK_WINDOW (self));
1292 empathy_call_window_toolbar_timeout (gpointer data)
1294 EmpathyCallWindow *self = data;
1296 /* We don't want to hide the toolbar if we're not in a call, as
1297 * to show the call status all the time. */
1298 if (self->priv->call_state != CONNECTING &&
1299 self->priv->call_state != DISCONNECTED)
1300 clutter_state_set_state (self->priv->transitions, "fade-out");
1306 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1308 EmpathyCallWindow *self)
1310 clutter_state_set_state (self->priv->transitions, "fade-in");
1312 if (self->priv->inactivity_src > 0)
1313 g_source_remove (self->priv->inactivity_src);
1315 self->priv->inactivity_src = g_timeout_add_seconds (3,
1316 empathy_call_window_toolbar_timeout, self);
1322 empathy_call_window_configure_event_cb (GtkWidget *widget,
1324 EmpathyCallWindow *self)
1326 GdkWindow *gdk_window;
1327 GdkWindowState window_state;
1329 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1330 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1332 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1333 &self->priv->dialpad_width, NULL);
1335 gdk_window = gtk_widget_get_window (widget);
1336 window_state = gdk_window_get_state (gdk_window);
1337 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1343 empathy_call_window_destroyed_cb (GtkWidget *object,
1344 EmpathyCallWindow *self)
1346 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1348 /* Save the geometry as if the dialpad was hidden. */
1349 empathy_geometry_save_values (GTK_WINDOW (self),
1350 self->priv->x, self->priv->y,
1351 self->priv->w - self->priv->dialpad_width, self->priv->h,
1352 self->priv->maximized);
1357 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1359 ClutterBindConstraint *constraint)
1361 ClutterActorBox allocation;
1363 clutter_actor_get_allocation_box (stage, &allocation);
1365 clutter_bind_constraint_set_offset (constraint,
1366 allocation.y2 - allocation.y1 -
1367 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1371 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1373 g_assert (self->priv->call_state != CONNECTED);
1375 empathy_call_window_status_message (self, _("Incoming call"));
1376 self->priv->call_state = RINGING;
1380 empathy_call_window_stop_ringing (EmpathyCallWindow *self)
1382 empathy_call_window_status_message (self, _("Disconnected"));
1383 self->priv->call_state = DISCONNECTED;
1387 empathy_call_window_incoming_channel_invalidated_cb (TpProxy *channel,
1391 EmpathyCallWindow *self)
1393 tp_channel_dispatch_operation_destroy_channels_async (
1394 self->priv->pending_cdo, NULL, NULL);
1395 empathy_call_window_stop_ringing (self);
1397 tp_clear_object (&self->priv->pending_cdo);
1398 tp_clear_object (&self->priv->pending_channel);
1399 tp_clear_object (&self->priv->pending_context);
1403 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1404 TpyCallChannel *channel,
1405 TpChannelDispatchOperation *dispatch_operation,
1406 TpAddDispatchOperationContext *context)
1408 g_assert (self->priv->pending_channel == NULL);
1409 g_assert (self->priv->pending_context == NULL);
1410 g_assert (self->priv->pending_cdo == NULL);
1412 /* Start ringing and delay until the user answers or hangs. */
1413 self->priv->pending_channel = g_object_ref (channel);
1414 self->priv->pending_context = g_object_ref (context);
1415 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1417 g_signal_connect (self->priv->pending_channel, "invalidated",
1418 G_CALLBACK (empathy_call_window_incoming_channel_invalidated_cb), self);
1420 empathy_call_window_set_state_ringing (self);
1421 tp_add_dispatch_operation_context_accept (context);
1425 empathy_call_window_init (EmpathyCallWindow *self)
1427 EmpathyCallWindowPriv *priv;
1429 GtkWidget *top_vbox;
1431 ClutterConstraint *constraint;
1432 ClutterActor *remote_avatar;
1433 GtkStyleContext *context;
1437 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1438 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1440 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1441 gui = empathy_builder_get_file (filename,
1442 "call_window_vbox", &top_vbox,
1443 "errors_vbox", &priv->errors_vbox,
1444 "pane", &priv->pane,
1445 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1446 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1447 "status_label", &priv->status_label,
1448 "audiocall", &priv->audio_call_button,
1449 "videocall", &priv->video_call_button,
1450 "microphone", &priv->mic_button,
1451 "camera", &priv->camera_button,
1452 "hangup", &priv->hangup_button,
1453 "dialpad", &priv->dialpad_button,
1454 "toolbar", &priv->toolbar,
1455 "bottom_toolbar", &priv->bottom_toolbar,
1456 "ui_manager", &priv->ui_manager,
1457 "menufullscreen", &priv->menu_fullscreen,
1458 "menupreviewswap", &priv->menu_swap_camera,
1459 "details_vbox", &priv->details_vbox,
1460 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1461 "acodec_encoding_label", &priv->acodec_encoding_label,
1462 "acodec_decoding_label", &priv->acodec_decoding_label,
1463 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1464 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1465 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1466 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1467 "video_local_candidate_label", &priv->video_local_candidate_label,
1468 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1469 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1470 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1471 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1475 empathy_builder_connect (gui, self,
1476 "hangup", "clicked", empathy_call_window_hangup_cb,
1477 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1478 "videocall", "clicked", empathy_call_window_video_call_cb,
1479 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1480 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1481 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1482 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1483 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1484 "menusettings", "activate", empathy_call_window_settings_cb,
1485 "menucontents", "activate", empathy_call_window_contents_cb,
1486 "menudebug", "activate", empathy_call_window_debug_cb,
1487 "menuabout", "activate", empathy_call_window_about_cb,
1488 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1489 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1490 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1491 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1494 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1496 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1498 g_object_bind_property (priv->camera_monitor, "available",
1499 priv->camera_button, "sensitive",
1500 G_BINDING_SYNC_CREATE);
1502 g_signal_connect (priv->camera_monitor, "added",
1503 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1504 g_signal_connect (priv->camera_monitor, "removed",
1505 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1507 priv->lock = g_mutex_new ();
1509 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1511 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1512 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1513 CONTENT_HBOX_BORDER_WIDTH);
1514 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1517 /* avatar/video box */
1518 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1519 CLUTTER_BIN_ALIGNMENT_CENTER);
1521 priv->video_box = clutter_box_new (priv->video_layout);
1523 priv->video_container = gtk_clutter_embed_new ();
1525 /* Set the background color to that of the rest of the window */
1526 context = gtk_widget_get_style_context (priv->content_hbox);
1527 gtk_style_context_get_background_color (context,
1528 GTK_STATE_FLAG_NORMAL, &rgba);
1529 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1530 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1531 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1532 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1533 clutter_stage_set_color (
1534 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1535 GTK_CLUTTER_EMBED (priv->video_container))),
1538 clutter_container_add (
1539 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1540 GTK_CLUTTER_EMBED (priv->video_container))),
1544 constraint = clutter_bind_constraint_new (
1545 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1546 CLUTTER_BIND_SIZE, 0);
1547 clutter_actor_add_constraint (priv->video_box, constraint);
1549 priv->remote_user_avatar_widget = gtk_image_new ();
1550 remote_avatar = gtk_clutter_actor_new_with_contents (
1551 priv->remote_user_avatar_widget);
1553 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1556 empathy_call_window_create_preview_rectangles (self);
1558 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1559 priv->video_container, TRUE, TRUE,
1560 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1562 create_pipeline (self);
1563 create_video_output_widget (self);
1564 create_audio_input (self);
1565 create_video_input (self);
1567 priv->floating_toolbar = empathy_rounded_actor_new ();
1569 gtk_widget_reparent (priv->bottom_toolbar,
1570 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1572 constraint = clutter_bind_constraint_new (
1573 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1576 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1579 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1580 "notify::allocation",
1581 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1584 clutter_actor_set_size (priv->floating_toolbar,
1585 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1586 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1588 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1589 priv->floating_toolbar,
1590 CLUTTER_BIN_ALIGNMENT_CENTER,
1591 CLUTTER_BIN_ALIGNMENT_END);
1593 clutter_actor_raise_top (priv->floating_toolbar);
1595 /* Transitions for the floating toolbar */
1596 priv->transitions = clutter_state_new ();
1598 /* all transitions last for 2s */
1599 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1601 /* transition from any state to "fade-out" state */
1602 clutter_state_set (priv->transitions, NULL, "fade-out",
1603 priv->floating_toolbar,
1604 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1607 /* transition from any state to "fade-in" state */
1608 clutter_state_set (priv->transitions, NULL, "fade-in",
1609 priv->floating_toolbar,
1610 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1613 /* put the actor into the "fade-in" state with no animation */
1614 clutter_state_warp_to_state (priv->transitions, "fade-in");
1616 /* The call will be started as soon the pipeline is playing */
1617 priv->start_call_when_playing = TRUE;
1619 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1620 G_CALLBACK (dtmf_button_pressed_cb),
1621 G_CALLBACK (dtmf_button_released_cb));
1623 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1626 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1629 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1631 gtk_widget_show_all (top_vbox);
1633 gtk_widget_hide (priv->dtmf_panel);
1634 gtk_widget_hide (priv->details_vbox);
1636 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1638 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1639 priv->video_container);
1641 /* We hide the bottom toolbar after 3s of inactivity and show it
1642 * again on mouse movement */
1643 priv->inactivity_src = g_timeout_add_seconds (3,
1644 empathy_call_window_toolbar_timeout, self);
1646 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1647 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1649 g_signal_connect (G_OBJECT (self), "realize",
1650 G_CALLBACK (empathy_call_window_realized_cb), self);
1652 g_signal_connect (G_OBJECT (self), "delete-event",
1653 G_CALLBACK (empathy_call_window_delete_cb), self);
1655 g_signal_connect (G_OBJECT (self), "window-state-event",
1656 G_CALLBACK (empathy_call_window_state_event_cb), self);
1658 g_signal_connect (G_OBJECT (self), "key-press-event",
1659 G_CALLBACK (empathy_call_window_key_press_cb), self);
1661 g_signal_connect (self, "motion-notify-event",
1662 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1664 priv->timer = g_timer_new ();
1666 g_object_ref (priv->ui_manager);
1667 g_object_unref (gui);
1669 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1670 priv->mic_menu = empathy_mic_menu_new (self);
1671 priv->camera_menu = empathy_camera_menu_new (self);
1673 empathy_call_window_show_hangup_button (self, TRUE);
1675 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1677 /* Retrieve initial volume */
1678 priv->volume = g_settings_get_double (priv->settings,
1679 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1681 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1682 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1684 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1685 /* These signals are used to track the window position and save it
1686 * when the window is destroyed. We need to do this as we don't want
1687 * the window geometry to be saved with the dialpad taken into account. */
1688 g_signal_connect (self, "destroy",
1689 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1690 g_signal_connect (self, "configure-event",
1691 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1692 g_signal_connect (self, "window-state-event",
1693 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1695 /* Don't display labels in both toolbars */
1696 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1699 /* Instead of specifying a width and a height, we specify only one size. That's
1700 because we want a square avatar icon. */
1702 init_contact_avatar_with_size (EmpathyContact *contact,
1703 GtkWidget *image_widget,
1706 GdkPixbuf *pixbuf_avatar = NULL;
1708 if (contact != NULL)
1710 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1714 if (pixbuf_avatar == NULL)
1716 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1717 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1720 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1722 if (pixbuf_avatar != NULL)
1723 g_object_unref (pixbuf_avatar);
1727 set_window_title (EmpathyCallWindow *self)
1729 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1732 if (priv->contact != NULL)
1734 /* translators: Call is a noun and %s is the contact name. This string
1735 * is used in the window title */
1736 tmp = g_strdup_printf (_("Call with %s"),
1737 empathy_contact_get_alias (priv->contact));
1738 gtk_window_set_title (GTK_WINDOW (self), tmp);
1743 g_warning ("Unknown remote contact!");
1748 set_remote_user_name (EmpathyCallWindow *self,
1749 EmpathyContact *contact)
1751 const gchar *alias = empathy_contact_get_alias (contact);
1752 const gchar *status = empathy_contact_get_status (contact);
1755 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1756 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1762 contact_name_changed_cb (EmpathyContact *contact,
1764 EmpathyCallWindow *self)
1766 set_window_title (self);
1767 set_remote_user_name (self, contact);
1771 contact_presence_changed_cb (EmpathyContact *contact,
1773 EmpathyCallWindow *self)
1775 set_remote_user_name (self, contact);
1779 contact_avatar_changed_cb (EmpathyContact *contact,
1781 EmpathyCallWindow *self)
1784 GtkAllocation allocation;
1785 GtkWidget *avatar_widget;
1787 avatar_widget = self->priv->remote_user_avatar_widget;
1789 gtk_widget_get_allocation (avatar_widget, &allocation);
1790 size = allocation.height;
1794 /* the widget is not allocated yet, set a default size */
1795 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1796 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1799 init_contact_avatar_with_size (contact, avatar_widget, size);
1801 avatar_widget = self->priv->remote_user_avatar_toolbar;
1803 gtk_widget_get_allocation (avatar_widget, &allocation);
1804 size = allocation.height;
1808 /* the widget is not allocated yet, set a default size */
1809 size = SMALL_TOOLBAR_SIZE;
1812 init_contact_avatar_with_size (contact, avatar_widget, size);
1816 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1817 EmpathyCallHandler *handler)
1819 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1821 tp_g_signal_connect_object (priv->contact, "notify::name",
1822 G_CALLBACK (contact_name_changed_cb), self, 0);
1823 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1824 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1825 tp_g_signal_connect_object (priv->contact, "notify::presence",
1826 G_CALLBACK (contact_presence_changed_cb), self, 0);
1828 set_window_title (self);
1829 set_remote_user_name (self, priv->contact);
1831 init_contact_avatar_with_size (priv->contact,
1832 priv->remote_user_avatar_widget,
1833 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1834 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1836 init_contact_avatar_with_size (priv->contact,
1837 priv->remote_user_avatar_toolbar,
1838 SMALL_TOOLBAR_SIZE);
1840 /* The remote avatar is shown by default and will be hidden when we receive
1841 video from the remote side. */
1842 clutter_actor_hide (priv->video_output);
1843 gtk_widget_show (priv->remote_user_avatar_widget);
1847 update_send_codec (EmpathyCallWindow *self,
1850 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1857 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1858 widget = priv->acodec_encoding_label;
1862 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1863 widget = priv->vcodec_encoding_label;
1869 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1870 gtk_label_set_text (GTK_LABEL (widget), tmp);
1875 send_audio_codec_notify_cb (GObject *object,
1879 EmpathyCallWindow *self = user_data;
1881 update_send_codec (self, TRUE);
1885 send_video_codec_notify_cb (GObject *object,
1889 EmpathyCallWindow *self = user_data;
1891 update_send_codec (self, FALSE);
1895 update_recv_codec (EmpathyCallWindow *self,
1898 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1901 GString *str = NULL;
1905 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1906 widget = priv->acodec_decoding_label;
1910 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1911 widget = priv->vcodec_decoding_label;
1917 for (l = codecs; l != NULL; l = g_list_next (l))
1919 FsCodec *codec = l->data;
1922 str = g_string_new (NULL);
1924 g_string_append (str, ", ");
1926 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1930 gtk_label_set_text (GTK_LABEL (widget), str->str);
1931 g_string_free (str, TRUE);
1935 recv_audio_codecs_notify_cb (GObject *object,
1939 EmpathyCallWindow *self = user_data;
1941 update_recv_codec (self, TRUE);
1945 recv_video_codecs_notify_cb (GObject *object,
1949 EmpathyCallWindow *self = user_data;
1951 update_recv_codec (self, FALSE);
1954 static const gchar *
1955 candidate_type_to_str (FsCandidate *candidate)
1957 switch (candidate->type)
1959 case FS_CANDIDATE_TYPE_HOST:
1961 case FS_CANDIDATE_TYPE_SRFLX:
1962 return "server reflexive";
1963 case FS_CANDIDATE_TYPE_PRFLX:
1964 return "peer reflexive";
1965 case FS_CANDIDATE_TYPE_RELAY:
1967 case FS_CANDIDATE_TYPE_MULTICAST:
1974 static const gchar *
1975 candidate_type_to_desc (FsCandidate *candidate)
1977 switch (candidate->type)
1979 case FS_CANDIDATE_TYPE_HOST:
1980 return _("The IP address as seen by the machine");
1981 case FS_CANDIDATE_TYPE_SRFLX:
1982 return _("The IP address as seen by a server on the Internet");
1983 case FS_CANDIDATE_TYPE_PRFLX:
1984 return _("The IP address of the peer as seen by the other side");
1985 case FS_CANDIDATE_TYPE_RELAY:
1986 return _("The IP address of a relay server");
1987 case FS_CANDIDATE_TYPE_MULTICAST:
1988 return _("The IP address of the multicast group");
1995 update_candidat_widget (EmpathyCallWindow *self,
1998 FsCandidate *candidate)
2002 g_assert (candidate != NULL);
2003 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2004 candidate->port, candidate_type_to_str (candidate));
2006 gtk_label_set_text (GTK_LABEL (label), str);
2007 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2013 candidates_changed_cb (GObject *object,
2015 EmpathyCallWindow *self)
2017 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2018 FsCandidate *candidate = NULL;
2020 if (type == FS_MEDIA_TYPE_VIDEO)
2022 /* Update remote candidate */
2023 candidate = empathy_call_handler_get_video_remote_candidate (
2026 update_candidat_widget (self, priv->video_remote_candidate_label,
2027 priv->video_remote_candidate_info_img, candidate);
2029 /* Update local candidate */
2030 candidate = empathy_call_handler_get_video_local_candidate (
2033 update_candidat_widget (self, priv->video_local_candidate_label,
2034 priv->video_local_candidate_info_img, candidate);
2038 /* Update remote candidate */
2039 candidate = empathy_call_handler_get_audio_remote_candidate (
2042 update_candidat_widget (self, priv->audio_remote_candidate_label,
2043 priv->audio_remote_candidate_info_img, candidate);
2045 /* Update local candidate */
2046 candidate = empathy_call_handler_get_audio_local_candidate (
2049 update_candidat_widget (self, priv->audio_local_candidate_label,
2050 priv->audio_local_candidate_info_img, candidate);
2055 empathy_call_window_constructed (GObject *object)
2057 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2058 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2059 TpyCallChannel *call;
2061 g_assert (priv->handler != NULL);
2063 g_object_get (priv->handler, "call-channel", &call, NULL);
2064 priv->outgoing = (call == NULL);
2066 g_object_unref (call);
2068 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2069 g_assert (priv->contact != NULL);
2071 if (!empathy_contact_can_voip_video (priv->contact))
2073 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2074 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2077 empathy_call_window_setup_avatars (self, priv->handler);
2078 empathy_call_window_set_state_connecting (self);
2080 if (!empathy_call_handler_has_initial_video (priv->handler))
2082 gtk_toggle_tool_button_set_active (
2083 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2085 /* If call has InitialVideo, the preview will be started once the call has
2086 * been started (start_call()). */
2088 update_send_codec (self, TRUE);
2089 update_send_codec (self, FALSE);
2090 update_recv_codec (self, TRUE);
2091 update_recv_codec (self, FALSE);
2093 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2094 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2095 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2096 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2097 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2098 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2099 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2100 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2102 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2103 G_CALLBACK (candidates_changed_cb), self, 0);
2106 static void empathy_call_window_dispose (GObject *object);
2107 static void empathy_call_window_finalize (GObject *object);
2110 empathy_call_window_set_property (GObject *object,
2111 guint property_id, const GValue *value, GParamSpec *pspec)
2113 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2115 switch (property_id)
2117 case PROP_CALL_HANDLER:
2118 priv->handler = g_value_dup_object (value);
2121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2126 empathy_call_window_get_property (GObject *object,
2127 guint property_id, GValue *value, GParamSpec *pspec)
2129 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2131 switch (property_id)
2133 case PROP_CALL_HANDLER:
2134 g_value_set_object (value, priv->handler);
2137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2142 empathy_call_window_class_init (
2143 EmpathyCallWindowClass *empathy_call_window_class)
2145 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2146 GParamSpec *param_spec;
2148 g_type_class_add_private (empathy_call_window_class,
2149 sizeof (EmpathyCallWindowPriv));
2151 object_class->constructed = empathy_call_window_constructed;
2152 object_class->set_property = empathy_call_window_set_property;
2153 object_class->get_property = empathy_call_window_get_property;
2155 object_class->dispose = empathy_call_window_dispose;
2156 object_class->finalize = empathy_call_window_finalize;
2158 param_spec = g_param_spec_object ("handler",
2159 "handler", "The call handler",
2160 EMPATHY_TYPE_CALL_HANDLER,
2161 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2162 g_object_class_install_property (object_class,
2163 PROP_CALL_HANDLER, param_spec);
2167 empathy_call_window_dispose (GObject *object)
2169 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2170 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2172 if (priv->dispose_has_run)
2175 priv->dispose_has_run = TRUE;
2177 if (priv->handler != NULL)
2179 empathy_call_handler_stop_call (priv->handler);
2180 tp_clear_object (&priv->handler);
2183 if (priv->bus_message_source_id != 0)
2185 g_source_remove (priv->bus_message_source_id);
2186 priv->bus_message_source_id = 0;
2189 if (priv->got_video_src > 0)
2191 g_source_remove (priv->got_video_src);
2192 priv->got_video_src = 0;
2195 if (priv->inactivity_src > 0)
2197 g_source_remove (priv->inactivity_src);
2198 priv->inactivity_src = 0;
2201 tp_clear_object (&priv->pipeline);
2202 tp_clear_object (&priv->video_input);
2203 tp_clear_object (&priv->audio_input);
2204 tp_clear_object (&priv->video_tee);
2205 tp_clear_object (&priv->ui_manager);
2206 tp_clear_object (&priv->fullscreen);
2207 tp_clear_object (&priv->camera_monitor);
2208 tp_clear_object (&priv->settings);
2209 tp_clear_object (&priv->sound_mgr);
2210 tp_clear_object (&priv->mic_menu);
2211 tp_clear_object (&priv->camera_menu);
2213 g_list_free_full (priv->notifiers, g_object_unref);
2215 if (priv->timer_id != 0)
2216 g_source_remove (priv->timer_id);
2219 if (priv->contact != NULL)
2221 g_signal_handlers_disconnect_by_func (priv->contact,
2222 contact_name_changed_cb, self);
2223 priv->contact = NULL;
2226 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2230 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2232 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2234 if (priv->video_output_motion_handler_id != 0)
2236 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2237 priv->video_output_motion_handler_id);
2238 priv->video_output_motion_handler_id = 0;
2243 empathy_call_window_finalize (GObject *object)
2245 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2246 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2248 disconnect_video_output_motion_handler (self);
2250 /* free any data held directly by the object here */
2251 g_mutex_free (priv->lock);
2253 g_timer_destroy (priv->timer);
2255 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2260 empathy_call_window_new (EmpathyCallHandler *handler)
2262 return EMPATHY_CALL_WINDOW (
2263 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2267 empathy_call_window_present (EmpathyCallWindow *self,
2268 EmpathyCallHandler *handler)
2270 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2272 tp_clear_object (&self->priv->handler);
2273 self->priv->handler = g_object_ref (handler);
2274 empathy_call_window_connect_handler (self);
2276 empathy_window_present (GTK_WINDOW (self));
2277 empathy_call_window_restart_call (self);
2281 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2282 GstElement *conference, gpointer user_data)
2284 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2285 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2286 FsElementAddedNotifier *notifier;
2289 DEBUG ("Conference added");
2291 /* Add notifier to set the various element properties as needed */
2292 notifier = fs_element_added_notifier_new ();
2293 keyfile = fs_utils_get_default_element_properties (conference);
2295 if (keyfile != NULL)
2296 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2298 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2300 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2302 gst_bin_add (GST_BIN (priv->pipeline), conference);
2303 gst_element_set_state (conference, GST_STATE_PLAYING);
2307 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2308 GstElement *conference, gpointer user_data)
2310 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2311 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2313 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2314 gst_element_set_state (conference, GST_STATE_NULL);
2318 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2320 GstStateChangeReturn state_change_return;
2321 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2323 if (priv->pipeline == NULL)
2326 if (priv->bus_message_source_id != 0)
2328 g_source_remove (priv->bus_message_source_id);
2329 priv->bus_message_source_id = 0;
2332 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2334 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2335 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2337 if (priv->pipeline != NULL)
2338 g_object_unref (priv->pipeline);
2339 priv->pipeline = NULL;
2341 if (priv->audio_output != NULL)
2342 g_object_unref (priv->audio_output);
2343 priv->audio_output = NULL;
2345 if (priv->video_tee != NULL)
2346 g_object_unref (priv->video_tee);
2347 priv->video_tee = NULL;
2349 if (priv->video_preview != NULL)
2350 clutter_actor_destroy (priv->video_preview);
2351 priv->video_preview = NULL;
2353 /* If we destroy the preview while it's being dragged, we won't
2354 * get the ::drag-end signal, so manually destroy the clone */
2355 if (priv->drag_preview != NULL)
2357 clutter_actor_destroy (priv->drag_preview);
2358 empathy_call_window_show_preview_rectangles (self, FALSE);
2359 priv->drag_preview = NULL;
2362 priv->funnel = NULL;
2364 create_pipeline (self);
2365 /* Call will be started when user will hit the 'redial' button */
2366 priv->start_call_when_playing = FALSE;
2367 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2373 g_message ("Error: could not destroy pipeline. Closing call window");
2374 gtk_widget_destroy (GTK_WIDGET (self));
2381 reset_details_pane (EmpathyCallWindow *self)
2383 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2385 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2386 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2387 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2388 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2392 empathy_call_window_disconnected (EmpathyCallWindow *self,
2395 gboolean could_disconnect = FALSE;
2396 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2397 gboolean could_reset_pipeline;
2399 /* Leave full screen mode if needed */
2400 gtk_window_unfullscreen (GTK_WINDOW (self));
2402 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2403 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2405 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2407 if (priv->call_state == CONNECTING)
2408 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2410 if (priv->call_state != REDIALING)
2411 priv->call_state = DISCONNECTED;
2413 /* Show the toolbar */
2414 clutter_state_set_state (priv->transitions, "fade-in");
2416 if (could_reset_pipeline)
2418 g_mutex_lock (priv->lock);
2420 g_timer_stop (priv->timer);
2422 if (priv->timer_id != 0)
2423 g_source_remove (priv->timer_id);
2426 g_mutex_unlock (priv->lock);
2429 /* We are about to destroy the window, no need to update it or create
2430 * a video preview */
2433 empathy_call_window_status_message (self, _("Disconnected"));
2435 empathy_call_window_show_hangup_button (self, FALSE);
2437 /* Unsensitive the camera and mic button */
2438 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2439 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2441 /* Be sure that the mic button is enabled */
2442 gtk_toggle_tool_button_set_active (
2443 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2445 if (priv->camera_state == CAMERA_STATE_ON)
2447 /* Restart the preview with the new pipeline. */
2448 display_video_preview (self, TRUE);
2451 /* destroy the video output; it will be recreated when we'll redial */
2452 disconnect_video_output_motion_handler (self);
2453 if (priv->video_output != NULL)
2454 clutter_actor_destroy (priv->video_output);
2455 priv->video_output = NULL;
2456 if (priv->got_video_src > 0)
2458 g_source_remove (priv->got_video_src);
2459 priv->got_video_src = 0;
2462 gtk_widget_show (priv->remote_user_avatar_widget);
2464 reset_details_pane (self);
2466 priv->sending_video = FALSE;
2467 priv->call_started = FALSE;
2469 could_disconnect = TRUE;
2471 /* TODO: display the self avatar of the preview (depends if the "Always
2472 * Show Video Preview" is enabled or not) */
2475 return could_disconnect;
2480 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2483 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2484 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2486 if (empathy_call_window_disconnected (self, TRUE) &&
2487 priv->call_state == REDIALING)
2488 empathy_call_window_restart_call (self);
2492 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2494 FsMediaType media_type,
2495 EmpathyCallWindow *self)
2497 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2499 DEBUG ("removing content");
2502 * This assumes that there is only one video stream per channel...
2505 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2507 if (priv->funnel != NULL)
2511 output = priv->video_output_sink;
2513 gst_element_set_state (output, GST_STATE_NULL);
2514 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2516 gst_bin_remove (GST_BIN (priv->pipeline), output);
2517 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2518 priv->funnel = NULL;
2522 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2524 if (priv->audio_output != NULL)
2526 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2528 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2529 priv->audio_output = NULL;
2537 /* Called with global lock held */
2539 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2541 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2545 if (priv->funnel == NULL)
2547 output = priv->video_output_sink;
2549 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2553 g_warning ("Could not create fsfunnel");
2557 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2559 gst_object_unref (priv->funnel);
2560 priv->funnel = NULL;
2561 g_warning ("Could not add funnel to pipeline");
2565 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2567 g_warning ("Could not add the video output widget to the pipeline");
2571 if (!gst_element_link (priv->funnel, output))
2573 g_warning ("Could not link output sink to funnel");
2574 goto error_output_added;
2577 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2579 g_warning ("Could not start video sink");
2580 goto error_output_added;
2583 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2585 g_warning ("Could not start funnel");
2586 goto error_output_added;
2590 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2593 g_warning ("Could not get request pad from funnel");
2600 gst_element_set_locked_state (priv->funnel, TRUE);
2601 gst_element_set_locked_state (output, TRUE);
2603 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2604 gst_element_set_state (output, GST_STATE_NULL);
2606 gst_bin_remove (GST_BIN (priv->pipeline), output);
2607 gst_element_set_locked_state (output, FALSE);
2611 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2612 priv->funnel = NULL;
2617 /* Called with global lock held */
2619 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2621 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2623 GstPadTemplate *template;
2625 if (priv->audio_output == NULL)
2627 priv->audio_output = empathy_audio_sink_new ();
2628 g_object_ref_sink (priv->audio_output);
2630 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2632 g_warning ("Could not add audio sink to pipeline");
2633 g_object_unref (priv->audio_output);
2634 goto error_add_output;
2637 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2639 g_warning ("Could not start audio sink");
2644 template = gst_element_class_get_pad_template (
2645 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2647 pad = gst_element_request_pad (priv->audio_output,
2648 template, NULL, NULL);
2652 g_warning ("Could not get sink pad from sink");
2659 gst_element_set_locked_state (priv->audio_output, TRUE);
2660 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2661 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2662 priv->audio_output = NULL;
2670 empathy_call_window_update_timer (gpointer user_data)
2672 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2673 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2674 const gchar *status;
2678 time_ = g_timer_elapsed (priv->timer, NULL);
2680 if (priv->call_state == HELD)
2681 status = _("On hold");
2682 else if (!gtk_toggle_tool_button_get_active (
2683 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2686 status = _("Duration");
2688 /* Translators: 'status - minutes:seconds' the caller has been connected */
2689 str = g_strdup_printf (_("%s — %d:%02dm"),
2691 (int) time_ / 60, (int) time_ % 60);
2692 empathy_call_window_status_message (self, str);
2700 display_error (EmpathyCallWindow *self,
2701 TpyCallChannel *call,
2705 const gchar *details)
2707 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2708 GtkWidget *info_bar;
2709 GtkWidget *content_area;
2716 /* Create info bar */
2717 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2720 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2722 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2724 /* hbox containing the image and the messages vbox */
2725 hbox = gtk_hbox_new (FALSE, 3);
2726 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2729 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2730 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2732 /* vbox containing the main message and the details expander */
2733 vbox = gtk_vbox_new (FALSE, 3);
2734 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2737 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2739 label = gtk_label_new (NULL);
2740 gtk_label_set_markup (GTK_LABEL (label), txt);
2741 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2742 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2745 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2748 if (details != NULL)
2750 GtkWidget *expander;
2752 expander = gtk_expander_new (_("Technical Details"));
2754 txt = g_strdup_printf ("<i>%s</i>", details);
2756 label = gtk_label_new (NULL);
2757 gtk_label_set_markup (GTK_LABEL (label), txt);
2758 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2759 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2762 gtk_container_add (GTK_CONTAINER (expander), label);
2763 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2766 g_signal_connect (info_bar, "response",
2767 G_CALLBACK (gtk_widget_destroy), NULL);
2769 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2770 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2771 gtk_widget_show_all (info_bar);
2775 media_stream_error_to_txt (EmpathyCallWindow *self,
2776 TpyCallChannel *call,
2778 TpMediaStreamError error)
2780 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2781 const gchar *cm = NULL;
2787 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2789 return g_strdup_printf (
2790 _("%s's software does not understand any of the audio formats "
2791 "supported by your computer"),
2792 empathy_contact_get_alias (priv->contact));
2794 return g_strdup_printf (
2795 _("%s's software does not understand any of the video formats "
2796 "supported by your computer"),
2797 empathy_contact_get_alias (priv->contact));
2799 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2800 return g_strdup_printf (
2801 _("Can't establish a connection to %s. "
2802 "One of you might be on a network that does not allow "
2803 "direct connections."),
2804 empathy_contact_get_alias (priv->contact));
2806 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2807 return g_strdup (_("There was a failure on the network"));
2809 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2811 return g_strdup (_("The audio formats necessary for this call "
2812 "are not installed on your computer"));
2814 return g_strdup (_("The video formats necessary for this call "
2815 "are not installed on your computer"));
2817 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2818 tp_connection_parse_object_path (
2819 tp_channel_borrow_connection (TP_CHANNEL (call)),
2822 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2823 "product=Telepathy&component=%s", cm);
2825 result = g_strdup_printf (
2826 _("Something unexpected happened in a Telepathy component. "
2827 "Please <a href=\"%s\">report this bug</a> and attach "
2828 "logs gathered from the 'Debug' window in the Help menu."), url);
2834 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2835 return g_strdup (_("There was a failure in the call engine"));
2837 case TP_MEDIA_STREAM_ERROR_EOS:
2838 return g_strdup (_("The end of the stream was reached"));
2840 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2847 empathy_call_window_stream_error (EmpathyCallWindow *self,
2848 TpyCallChannel *call,
2857 desc = media_stream_error_to_txt (self, call, audio, code);
2860 /* No description, use the error message. That's not great as it's not
2861 * localized but it's better than nothing. */
2862 display_error (self, call, icon, title, msg, NULL);
2866 display_error (self, call, icon, title, desc, msg);
2872 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2875 EmpathyCallWindow *self)
2877 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2878 "gnome-stock-mic", _("Can't establish audio stream"));
2882 empathy_call_window_video_stream_error (TpyCallChannel *call,
2885 EmpathyCallWindow *self)
2887 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2888 "camera-web", _("Can't establish video stream"));
2893 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2895 EmpathyCallWindow *self)
2897 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2898 TpyCallChannel *call;
2899 gboolean can_send_video;
2901 if (state != TPY_CALL_STATE_ACCEPTED)
2904 if (priv->call_state == CONNECTED)
2907 g_timer_start (priv->timer);
2908 priv->call_state = CONNECTED;
2910 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2912 can_send_video = priv->video_input != NULL &&
2913 empathy_contact_can_voip_video (priv->contact) &&
2914 empathy_camera_monitor_get_available (priv->camera_monitor);
2916 g_object_get (priv->handler, "call-channel", &call, NULL);
2918 if (tpy_call_channel_has_dtmf (call))
2919 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2921 if (priv->video_input == NULL)
2922 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2924 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2926 empathy_call_window_show_hangup_button (self, TRUE);
2928 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2930 clutter_actor_hide (priv->video_output);
2931 gtk_widget_show (priv->remote_user_avatar_widget);
2933 g_object_unref (call);
2935 g_mutex_lock (priv->lock);
2937 priv->timer_id = g_timeout_add_seconds (1,
2938 empathy_call_window_update_timer, self);
2940 g_mutex_unlock (priv->lock);
2942 empathy_call_window_update_timer (self);
2944 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2948 empathy_call_window_show_video_output_cb (gpointer user_data)
2950 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2952 if (self->priv->video_output != NULL)
2954 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2955 clutter_actor_show (self->priv->video_output);
2956 empathy_call_window_raise_actors (self);
2963 empathy_call_window_check_video_cb (gpointer data)
2965 EmpathyCallWindow *self = data;
2967 if (self->priv->got_video)
2969 self->priv->got_video = FALSE;
2973 /* No video in the last N seconds, display the remote avatar */
2974 empathy_call_window_show_video_output (self, FALSE);
2979 /* Called from the streaming thread */
2981 empathy_call_window_video_probe_cb (GstPad *pad,
2982 GstMiniObject *mini_obj,
2983 EmpathyCallWindow *self)
2986 if (GST_IS_EVENT (mini_obj))
2989 if (G_UNLIKELY (!self->priv->got_video))
2991 /* show the remote video */
2992 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2993 empathy_call_window_show_video_output_cb,
2994 g_object_ref (self), g_object_unref);
2996 self->priv->got_video = TRUE;
3002 /* Called from the streaming thread */
3004 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3005 GstPad *src, guint media_type, gpointer user_data)
3007 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3008 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3009 gboolean retval = FALSE;
3013 g_mutex_lock (priv->lock);
3017 case TP_MEDIA_STREAM_TYPE_AUDIO:
3018 pad = empathy_call_window_get_audio_sink_pad (self);
3020 case TP_MEDIA_STREAM_TYPE_VIDEO:
3021 g_idle_add (empathy_call_window_show_video_output_cb, self);
3022 pad = empathy_call_window_get_video_sink_pad (self);
3024 gst_pad_add_data_probe (src,
3025 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3026 if (priv->got_video_src > 0)
3027 g_source_remove (priv->got_video_src);
3028 priv->got_video_src = g_timeout_add_seconds (5,
3029 empathy_call_window_check_video_cb, self);
3032 g_assert_not_reached ();
3038 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3039 g_warning ("Could not link %s sink pad",
3040 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3044 gst_object_unref (pad);
3048 /* If no sink could be linked, try to add fakesink to prevent the whole call
3053 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3055 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3057 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3058 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3059 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3061 gst_element_set_locked_state (fakesink, TRUE);
3062 gst_element_set_state (fakesink, GST_STATE_NULL);
3063 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3067 DEBUG ("Could not link real sink, linked fakesink instead");
3069 gst_object_unref (sinkpad);
3073 gst_object_unref (fakesink);
3078 g_mutex_unlock (priv->lock);
3084 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
3085 GstPad *sink, FsMediaType media_type, gpointer user_data)
3087 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3088 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3090 gboolean retval = FALSE;
3094 case FS_MEDIA_TYPE_AUDIO:
3095 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3097 g_warning ("Could not add audio source to pipeline");
3101 pad = gst_element_get_static_pad (priv->audio_input, "src");
3104 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3105 g_warning ("Could not get source pad from audio source");
3109 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3111 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3112 g_warning ("Could not link audio source to farsight");
3116 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3118 g_warning ("Could not start audio source");
3119 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3120 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3126 case FS_MEDIA_TYPE_VIDEO:
3127 if (priv->video_tee != NULL)
3129 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3130 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3132 g_warning ("Could not link video source input pipeline");
3135 gst_object_unref (pad);
3141 g_assert_not_reached ();
3148 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3150 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3151 GstElement *preview;
3153 disable_camera (self);
3155 DEBUG ("remove video input");
3156 preview = priv->video_preview_sink;
3158 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3159 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3160 gst_element_set_state (preview, GST_STATE_NULL);
3162 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3165 g_object_unref (priv->video_input);
3166 priv->video_input = NULL;
3167 g_object_unref (priv->video_tee);
3168 priv->video_tee = NULL;
3169 clutter_actor_destroy (priv->video_preview);
3170 priv->video_preview = NULL;
3172 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3176 start_call (EmpathyCallWindow *self)
3178 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3180 priv->call_started = TRUE;
3181 empathy_call_handler_start_call (priv->handler,
3182 gtk_get_current_event_time ());
3184 if (empathy_call_handler_has_initial_video (priv->handler))
3186 TpyCallChannel *call;
3189 g_object_get (priv->handler, "call-channel", &call, NULL);
3190 s = tpy_call_channel_get_video_state (call);
3192 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3193 s == TPY_SENDING_STATE_SENDING)
3195 /* Enable 'send video' buttons and display the preview */
3196 gtk_toggle_tool_button_set_active (
3197 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3201 gtk_toggle_tool_button_set_active (
3202 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3204 if (priv->video_preview == NULL)
3206 create_video_preview (self);
3207 add_video_preview_to_pipeline (self);
3211 g_object_unref (call);
3216 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3219 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3220 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3223 empathy_call_handler_bus_message (priv->handler, bus, message);
3225 switch (GST_MESSAGE_TYPE (message))
3227 case GST_MESSAGE_STATE_CHANGED:
3228 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3230 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3232 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3233 !priv->call_started)
3235 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3236 if (newstate == GST_STATE_PAUSED)
3238 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3239 priv->pipeline_playing = TRUE;
3241 if (priv->start_call_when_playing)
3246 case GST_MESSAGE_ERROR:
3248 GError *error = NULL;
3249 GstElement *gst_error;
3252 gst_message_parse_error (message, &error, &debug);
3253 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3255 g_message ("Element error: %s -- %s\n", error->message, debug);
3257 if (g_str_has_prefix (gst_element_get_name (gst_error),
3258 VIDEO_INPUT_ERROR_PREFIX))
3260 /* Remove the video input and continue */
3261 if (priv->video_input != NULL)
3262 empathy_call_window_remove_video_input (self);
3263 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3267 empathy_call_window_disconnected (self, TRUE);
3269 g_error_free (error);
3272 case GST_MESSAGE_UNKNOWN:
3273 case GST_MESSAGE_EOS:
3274 case GST_MESSAGE_WARNING:
3275 case GST_MESSAGE_INFO:
3276 case GST_MESSAGE_TAG:
3277 case GST_MESSAGE_BUFFERING:
3278 case GST_MESSAGE_STATE_DIRTY:
3279 case GST_MESSAGE_STEP_DONE:
3280 case GST_MESSAGE_CLOCK_PROVIDE:
3281 case GST_MESSAGE_CLOCK_LOST:
3282 case GST_MESSAGE_NEW_CLOCK:
3283 case GST_MESSAGE_STRUCTURE_CHANGE:
3284 case GST_MESSAGE_STREAM_STATUS:
3285 case GST_MESSAGE_APPLICATION:
3286 case GST_MESSAGE_ELEMENT:
3287 case GST_MESSAGE_SEGMENT_START:
3288 case GST_MESSAGE_SEGMENT_DONE:
3289 case GST_MESSAGE_DURATION:
3290 case GST_MESSAGE_ANY:
3299 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3300 GHashTable *members,
3301 EmpathyCallWindow *self)
3303 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3304 GHashTableIter iter;
3305 gpointer key, value;
3306 gboolean held = FALSE;
3308 g_hash_table_iter_init (&iter, members);
3309 while (g_hash_table_iter_next (&iter, &key, &value))
3311 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3313 /* This assumes this is a 1-1 call, otherwise one participant
3314 * putting the call on hold wouldn't mean the call is on hold
3322 priv->call_state = HELD;
3323 else if (priv->call_state == HELD)
3324 priv->call_state = CONNECTED;
3328 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3330 EmpathyCallWindow *self)
3332 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3333 TpyCallChannel *call;
3335 g_object_get (priv->handler, "call-channel", &call, NULL);
3340 tp_g_signal_connect_object (call, "audio-stream-error",
3341 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3342 tp_g_signal_connect_object (call, "video-stream-error",
3343 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3346 tp_g_signal_connect_object (call, "members-changed",
3347 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3349 g_object_unref (call);
3353 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3355 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3356 TpyCallChannel *call;
3359 /* Make the hangup button twice as wide */
3360 width = gtk_widget_get_allocated_width (priv->hangup_button);
3361 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3363 g_signal_connect (priv->handler, "state-changed",
3364 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3365 g_signal_connect (priv->handler, "conference-added",
3366 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3367 g_signal_connect (priv->handler, "conference-removed",
3368 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3369 g_signal_connect (priv->handler, "closed",
3370 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3371 g_signal_connect (priv->handler, "src-pad-added",
3372 G_CALLBACK (empathy_call_window_src_added_cb), self);
3373 g_signal_connect (priv->handler, "sink-pad-added",
3374 G_CALLBACK (empathy_call_window_sink_added_cb), self);
3375 g_signal_connect (priv->handler, "sink-pad-removed",
3376 G_CALLBACK (empathy_call_window_sink_removed_cb), self);
3378 g_object_get (priv->handler, "call-channel", &call, NULL);
3381 call_handler_notify_call_cb (priv->handler, NULL, self);
3382 g_object_unref (call);
3386 /* call-channel doesn't exist yet, we'll connect signals once it has been
3388 g_signal_connect (priv->handler, "notify::call-channel",
3389 G_CALLBACK (call_handler_notify_call_cb), self);
3394 empathy_call_window_realized_cb (GtkWidget *widget,
3395 EmpathyCallWindow *self)
3397 empathy_call_window_connect_handler (self);
3399 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3403 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3404 EmpathyCallWindow *window)
3406 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3408 if (priv->pipeline != NULL)
3410 if (priv->bus_message_source_id != 0)
3412 g_source_remove (priv->bus_message_source_id);
3413 priv->bus_message_source_id = 0;
3416 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3419 if (priv->call_state == CONNECTING)
3420 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3426 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3429 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3431 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3436 gtk_widget_hide (priv->dtmf_panel);
3437 gtk_widget_hide (menu);
3438 gtk_widget_hide (priv->toolbar);
3442 if (priv->dialpad_was_visible_before_fs)
3443 gtk_widget_show (priv->dtmf_panel);
3445 gtk_widget_show (menu);
3446 gtk_widget_show (priv->toolbar);
3448 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3449 priv->original_height_before_fs);
3454 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3456 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3458 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3459 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3460 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3461 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3463 if (priv->video_output != NULL)
3466 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3467 priv->video_output, TRUE, TRUE,
3468 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3475 empathy_call_window_state_event_cb (GtkWidget *widget,
3476 GdkEventWindowState *event, EmpathyCallWindow *window)
3478 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3480 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3481 gboolean set_fullscreen = event->new_window_state &
3482 GDK_WINDOW_STATE_FULLSCREEN;
3486 gboolean dialpad_was_visible;
3487 GtkAllocation allocation;
3488 gint original_width, original_height;
3490 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3491 original_width = allocation.width;
3492 original_height = allocation.height;
3494 g_object_get (priv->dtmf_panel,
3495 "visible", &dialpad_was_visible,
3498 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3499 priv->original_width_before_fs = original_width;
3500 priv->original_height_before_fs = original_height;
3502 if (priv->video_output_motion_handler_id == 0 &&
3503 priv->video_output != NULL)
3505 priv->video_output_motion_handler_id = g_signal_connect (
3506 G_OBJECT (priv->video_container), "motion-notify-event",
3507 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3513 disconnect_video_output_motion_handler (window);
3516 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3518 show_controls (window, set_fullscreen);
3519 show_borders (window, set_fullscreen);
3520 gtk_action_set_stock_id (priv->menu_fullscreen,
3521 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3522 priv->is_fullscreen = set_fullscreen;
3529 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3532 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3533 int w, h, dialpad_width;
3534 GtkAllocation allocation;
3536 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3537 w = allocation.width;
3538 h = allocation.height;
3540 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3544 gtk_widget_show (priv->dtmf_panel);
3550 gtk_widget_hide (priv->dtmf_panel);
3554 gtk_window_resize (GTK_WINDOW (window), w, h);
3558 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3561 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3562 TpyCallChannel *call;
3564 priv->sending_video = (state == CAMERA_STATE_ON);
3566 if (state == CAMERA_STATE_ON)
3568 /* When we start sending video, we want to show the video preview by
3570 display_video_preview (window, TRUE);
3574 display_video_preview (window, FALSE);
3577 if (priv->call_state != CONNECTED)
3580 g_object_get (priv->handler, "call-channel", &call, NULL);
3581 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3582 tpy_call_channel_send_video (call, priv->sending_video);
3583 g_object_unref (call);
3587 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3588 EmpathyCallWindow *self)
3590 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3593 active = (gtk_toggle_tool_button_get_active (toggle));
3595 /* We don't want the settings callback to react to this change to avoid
3597 g_signal_handlers_block_by_func (priv->settings,
3598 empathy_call_window_prefs_volume_changed_cb, self);
3602 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3603 priv->volume * 100);
3607 /* TODO, Instead of setting the input volume to 0 we should probably
3608 * stop sending but this would cause the audio call to drop if both
3609 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3610 * in the future. GNOME #574574
3612 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3616 g_signal_handlers_unblock_by_func (priv->settings,
3617 empathy_call_window_prefs_volume_changed_cb, self);
3621 empathy_call_window_hangup_cb (gpointer object,
3622 EmpathyCallWindow *self)
3624 empathy_call_handler_stop_call (self->priv->handler);
3626 empathy_call_window_disconnected (self, TRUE);
3630 empathy_call_window_restart_call (EmpathyCallWindow *window)
3632 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3634 /* Remove error info bars */
3635 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3636 (GtkCallback) gtk_widget_destroy, NULL);
3638 create_video_output_widget (window);
3640 /* While the call was disconnected, the input volume might have changed.
3641 * However, since the audio_input source was destroyed, its volume has not
3642 * been updated during that time. That's why we manually update it here */
3643 empathy_call_window_mic_volume_changed (window);
3645 priv->outgoing = TRUE;
3646 empathy_call_window_set_state_connecting (window);
3648 if (priv->pipeline_playing)
3649 start_call (window);
3651 /* call will be started when the pipeline is ready */
3652 priv->start_call_when_playing = TRUE;
3654 empathy_call_window_setup_avatars (window, priv->handler);
3656 empathy_call_window_show_hangup_button (window, TRUE);
3660 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3661 EmpathyCallWindow *window)
3665 active = gtk_toggle_tool_button_get_active (button);
3667 empathy_call_window_show_dialpad (window, active);
3671 empathy_call_window_fullscreen_cb (gpointer object,
3672 EmpathyCallWindow *window)
3674 empathy_call_window_fullscreen_toggle (window);
3678 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3680 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3682 if (priv->is_fullscreen)
3683 gtk_window_unfullscreen (GTK_WINDOW (window));
3685 gtk_window_fullscreen (GTK_WINDOW (window));
3689 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3690 GdkEventButton *event, EmpathyCallWindow *window)
3692 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3694 empathy_call_window_video_menu_popup (window, event->button);
3702 empathy_call_window_key_press_cb (GtkWidget *video_output,
3703 GdkEventKey *event, EmpathyCallWindow *window)
3705 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3707 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3709 /* Since we are in fullscreen mode, toggling will bring us back to
3711 empathy_call_window_fullscreen_toggle (window);
3719 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3720 GdkEventMotion *event, EmpathyCallWindow *window)
3722 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3724 if (priv->is_fullscreen)
3726 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3728 /* Show the bottom toolbar */
3729 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3736 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3740 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3742 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3744 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3745 button, gtk_get_current_event_time ());
3746 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3750 empathy_call_window_status_message (EmpathyCallWindow *self,
3753 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3757 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3758 gdouble value, EmpathyCallWindow *window)
3760 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3762 if (priv->audio_output == NULL)
3765 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3770 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3772 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3774 return priv->ui_manager;
3777 EmpathyGstAudioSrc *
3778 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3780 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3782 return (EmpathyGstAudioSrc *) priv->audio_input;
3785 EmpathyGstVideoSrc *
3786 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3788 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);