2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
68 #include "empathy-rounded-texture.h"
69 #include "empathy-camera-menu.h"
71 #define CONTENT_HBOX_BORDER_WIDTH 6
72 #define CONTENT_HBOX_SPACING 3
73 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
75 #define SELF_VIDEO_SECTION_WIDTH 120
76 #define SELF_VIDEO_SECTION_HEIGHT 90
77 #define SELF_VIDEO_SECTION_MARGIN 10
79 #define FLOATING_TOOLBAR_OPACITY 192
80 #define FLOATING_TOOLBAR_WIDTH 280
81 #define FLOATING_TOOLBAR_HEIGHT 36
82 #define FLOATING_TOOLBAR_SPACING 20
84 /* The avatar's default width and height are set to the same value because we
85 want a square icon. */
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
88 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
101 PROP_CALL_HANDLER = 1,
113 CAMERA_STATE_OFF = 0,
119 PREVIEW_POS_TOP_LEFT,
120 PREVIEW_POS_TOP_RIGHT,
121 PREVIEW_POS_BOTTOM_LEFT,
122 PREVIEW_POS_BOTTOM_RIGHT,
125 struct _EmpathyCallWindowPriv
127 gboolean dispose_has_run;
128 EmpathyCallHandler *handler;
130 EmpathyContact *contact;
132 EmpathyCameraMonitor *camera_monitor;
137 GtkUIManager *ui_manager;
138 GtkWidget *errors_vbox;
139 /* widget displays the video received from the remote user. This widget is
140 * alive only during call. */
141 ClutterActor *video_output;
142 ClutterActor *video_preview;
143 ClutterActor *preview_shown_button;
144 ClutterActor *preview_hidden_button;
145 ClutterActor *preview_rectangle1;
146 ClutterActor *preview_rectangle2;
147 ClutterActor *preview_rectangle3;
148 ClutterActor *preview_rectangle4;
149 ClutterActor *preview_rectangle_box1;
150 ClutterActor *preview_rectangle_box2;
151 ClutterActor *preview_rectangle_box3;
152 ClutterActor *preview_rectangle_box4;
153 GtkWidget *video_container;
154 GtkWidget *remote_user_avatar_widget;
155 GtkWidget *remote_user_avatar_toolbar;
156 GtkWidget *remote_user_name_toolbar;
157 GtkWidget *status_label;
158 GtkWidget *hangup_button;
159 GtkWidget *audio_call_button;
160 GtkWidget *video_call_button;
161 GtkWidget *mic_button;
162 GtkWidget *camera_button;
163 GtkWidget *dialpad_button;
165 GtkWidget *bottom_toolbar;
166 ClutterActor *floating_toolbar;
168 GtkAction *menu_fullscreen;
169 GtkAction *menu_swap_camera;
171 ClutterState *transitions;
173 /* The box that contains self and remote avatar and video
174 input/output. When we redial, we destroy and re-create the box */
175 ClutterActor *video_box;
176 ClutterLayoutManager *video_layout;
178 /* Coordinates of the preview drag event's start. */
179 PreviewPosition preview_pos;
181 /* We keep a reference on the hbox which contains the main content so we can
182 easilly repack everything when toggling fullscreen */
183 GtkWidget *content_hbox;
185 gulong video_output_motion_handler_id;
186 guint bus_message_source_id;
190 GtkWidget *dtmf_panel;
193 GtkWidget *details_vbox;
194 GtkWidget *vcodec_encoding_label;
195 GtkWidget *acodec_encoding_label;
196 GtkWidget *vcodec_decoding_label;
197 GtkWidget *acodec_decoding_label;
199 GtkWidget *audio_remote_candidate_label;
200 GtkWidget *audio_local_candidate_label;
201 GtkWidget *video_remote_candidate_label;
202 GtkWidget *video_local_candidate_label;
203 GtkWidget *video_remote_candidate_info_img;
204 GtkWidget *video_local_candidate_info_img;
205 GtkWidget *audio_remote_candidate_info_img;
206 GtkWidget *audio_local_candidate_info_img;
208 GstElement *video_input;
209 GstElement *video_preview_sink;
210 GstElement *video_output_sink;
211 GstElement *audio_input;
212 GstElement *audio_output;
213 GstElement *pipeline;
214 GstElement *video_tee;
224 gboolean call_started;
225 gboolean sending_video;
226 CameraState camera_state;
228 EmpathyCallWindowFullscreen *fullscreen;
229 gboolean is_fullscreen;
234 guint inactivity_src;
236 /* Those fields represent the state of the window before it actually was in
238 gboolean dialpad_was_visible_before_fs;
239 gint original_width_before_fs;
240 gint original_height_before_fs;
242 gint x, y, w, h, dialpad_width;
245 /* TRUE if the call should be started when the pipeline is playing */
246 gboolean start_call_when_playing;
247 /* TRUE if we requested to set the pipeline in the playing state */
248 gboolean pipeline_playing;
250 EmpathySoundManager *sound_mgr;
253 EmpathyMicMenu *mic_menu;
254 EmpathyCameraMenu *camera_menu;
257 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
259 static void empathy_call_window_realized_cb (GtkWidget *widget,
260 EmpathyCallWindow *window);
262 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
263 GdkEvent *event, EmpathyCallWindow *window);
265 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
266 GdkEventWindowState *event, EmpathyCallWindow *window);
268 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
271 static void empathy_call_window_mic_toggled_cb (
272 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
274 static void empathy_call_window_hangup_cb (gpointer object,
275 EmpathyCallWindow *window);
277 static void empathy_call_window_fullscreen_cb (gpointer object,
278 EmpathyCallWindow *window);
280 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
282 static gboolean empathy_call_window_video_button_press_cb (
283 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
285 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
286 GdkEventKey *event, EmpathyCallWindow *window);
288 static gboolean empathy_call_window_video_output_motion_notify (
289 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
291 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
294 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
295 EmpathyCallWindow *window);
297 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
299 static void empathy_call_window_status_message (EmpathyCallWindow *window,
302 static gboolean empathy_call_window_bus_message (GstBus *bus,
303 GstMessage *message, gpointer user_data);
306 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
307 gdouble value, EmpathyCallWindow *window);
310 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
313 gtk_widget_set_visible (self->priv->hangup_button, show);
314 gtk_widget_set_visible (self->priv->audio_call_button, !show);
315 gtk_widget_set_visible (self->priv->video_call_button, !show);
319 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
320 EmpathyCallWindow *self)
322 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
323 empathy_call_window_restart_call (self);
327 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
328 EmpathyCallWindow *self)
330 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
331 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
332 empathy_call_window_restart_call (self);
336 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
338 EmpathyCallWindowPriv *priv = GET_PRIV (window);
339 TpyCallChannel *call;
343 g_object_get (priv->handler, "call-channel", &call, NULL);
345 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
346 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
349 tpy_call_channel_dtmf_start_tone (call, event);
351 g_object_unref (call);
355 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
357 EmpathyCallWindowPriv *priv = GET_PRIV (window);
358 TpyCallChannel *call;
360 g_object_get (priv->handler, "call-channel", &call, NULL);
362 tpy_call_channel_dtmf_stop_tone (call);
364 g_object_unref (call);
368 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
370 EmpathyCallWindowPriv *priv = GET_PRIV (self);
373 volume = g_settings_get_double (priv->settings,
374 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
376 /* Don't store the volume because of muting */
377 if (volume > 0 || gtk_toggle_tool_button_get_active (
378 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
379 priv->volume = volume;
381 /* Ensure that the toggle button is active if the volume is > 0 and inactive
382 * if it's smaller than 0 */
383 if ((volume > 0) != gtk_toggle_tool_button_get_active (
384 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
385 gtk_toggle_tool_button_set_active (
386 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
388 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
393 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
395 EmpathyCallWindow *self)
397 empathy_call_window_mic_volume_changed (self);
401 empathy_call_window_raise_actors (EmpathyCallWindow *self)
403 clutter_actor_raise_top (self->priv->floating_toolbar);
405 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
406 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
407 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
408 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
412 empathy_call_window_show_video_output (EmpathyCallWindow *self,
415 if (self->priv->video_output != NULL)
416 g_object_set (self->priv->video_output, "visible", show, NULL);
418 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
420 empathy_call_window_raise_actors (self);
424 create_video_output_widget (EmpathyCallWindow *self)
426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
428 g_assert (priv->video_output == NULL);
429 g_assert (priv->pipeline != NULL);
431 priv->video_output = clutter_texture_new ();
433 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
436 priv->video_output_sink = clutter_gst_video_sink_new (
437 CLUTTER_TEXTURE (priv->video_output));
439 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
442 gtk_widget_add_events (priv->video_container,
443 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
444 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
445 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
449 create_video_input (EmpathyCallWindow *self)
451 EmpathyCallWindowPriv *priv = GET_PRIV (self);
453 g_assert (priv->video_input == NULL);
454 priv->video_input = empathy_video_src_new ();
455 gst_object_ref (priv->video_input);
456 gst_object_sink (priv->video_input);
460 create_audio_input (EmpathyCallWindow *self)
462 EmpathyCallWindowPriv *priv = GET_PRIV (self);
464 g_assert (priv->audio_input == NULL);
465 priv->audio_input = empathy_audio_src_new ();
466 gst_object_ref (priv->audio_input);
467 gst_object_sink (priv->audio_input);
471 add_video_preview_to_pipeline (EmpathyCallWindow *self)
473 EmpathyCallWindowPriv *priv = GET_PRIV (self);
476 g_assert (priv->video_preview != NULL);
477 g_assert (priv->pipeline != NULL);
478 g_assert (priv->video_input != NULL);
479 g_assert (priv->video_tee != NULL);
481 preview = priv->video_preview_sink;
483 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
485 g_warning ("Could not add video input to pipeline");
489 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
491 g_warning ("Could not add video preview to pipeline");
495 if (!gst_element_link (priv->video_input, priv->video_tee))
497 g_warning ("Could not link video input to video tee");
501 if (!gst_element_link (priv->video_tee, preview))
503 g_warning ("Could not link video tee to video preview");
509 empathy_call_window_disable_camera_cb (GtkAction *action,
510 EmpathyCallWindow *self)
512 clutter_actor_destroy (self->priv->preview_hidden_button);
514 gtk_toggle_tool_button_set_active (
515 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
519 empathy_call_window_minimise_camera_cb (GtkAction *action,
520 EmpathyCallWindow *self)
522 clutter_actor_hide (self->priv->video_preview);
523 clutter_actor_show (self->priv->preview_hidden_button);
527 empathy_call_window_maximise_camera_cb (GtkAction *action,
528 EmpathyCallWindow *self)
530 clutter_actor_show (self->priv->video_preview);
531 clutter_actor_hide (self->priv->preview_hidden_button);
535 empathy_call_window_swap_camera_cb (GtkAction *action,
536 EmpathyCallWindow *self)
538 const GList *cameras, *l;
541 DEBUG ("Swapping the camera");
543 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
544 current_cam = empathy_video_src_dup_device (
545 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
547 for (l = cameras; l != NULL; l = l->next)
549 EmpathyCamera *camera = l->data;
551 if (!tp_strdiff (camera->device, current_cam))
556 next = l->next->data;
558 next = cameras->data;
560 /* EmpathyCameraMenu will update itself and do the actual change
562 g_settings_set_string (self->priv->settings,
563 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
570 g_free (current_cam);
574 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
575 EmpathyCamera *camera,
576 EmpathyCallWindow *self)
578 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
580 gtk_action_set_visible (self->priv->menu_swap_camera,
581 g_list_length ((GList *) cameras) >= 2);
585 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
586 EmpathyCamera *camera,
587 EmpathyCallWindow *self)
589 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
591 gtk_action_set_visible (self->priv->menu_swap_camera,
592 g_list_length ((GList *) cameras) >= 2);
596 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
597 EmpathyCallWindow *self)
601 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
603 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
604 0, gtk_get_current_event_time ());
605 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
609 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
610 EmpathyCallWindow *self)
614 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
615 "/preview-hidden-menu");
616 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
617 0, gtk_get_current_event_time ());
618 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
621 static ClutterActor *
622 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
624 ClutterBinAlignment x,
625 ClutterBinAlignment y)
627 ClutterLayoutManager *layout1, *layout2;
628 ClutterActor *rectangle;
629 ClutterActor *box1, *box2;
631 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
632 CLUTTER_BIN_ALIGNMENT_START);
634 box1 = clutter_box_new (layout1);
638 rectangle = clutter_rectangle_new_with_color (
639 CLUTTER_COLOR_Transparent);
641 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
644 clutter_actor_set_size (box1,
645 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
646 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
647 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
649 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
650 CLUTTER_BIN_ALIGNMENT_CENTER);
652 /* We have a box with the margins and the video in the middle inside
653 * a bigger box with an extra bottom margin so we're not on top of
654 * the floating toolbar. */
655 box2 = clutter_box_new (layout2);
657 clutter_actor_set_size (box2,
658 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
659 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
661 clutter_actor_set_size (rectangle,
662 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGHT + 5);
664 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
665 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
667 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
670 clutter_actor_hide (rectangle);
676 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
678 self->priv->preview_rectangle1 =
679 empathy_call_window_create_preview_rectangle (self,
680 &self->priv->preview_rectangle_box1,
681 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
682 self->priv->preview_rectangle2 =
683 empathy_call_window_create_preview_rectangle (self,
684 &self->priv->preview_rectangle_box2,
685 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
686 self->priv->preview_rectangle3 =
687 empathy_call_window_create_preview_rectangle (self,
688 &self->priv->preview_rectangle_box3,
689 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
690 self->priv->preview_rectangle4 =
691 empathy_call_window_create_preview_rectangle (self,
692 &self->priv->preview_rectangle_box4,
693 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
697 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
700 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
701 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
702 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
703 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
706 static PreviewPosition
707 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
712 PreviewPosition pos = PREVIEW_POS_NONE;
714 g_return_val_if_fail (clutter_actor_has_allocation (self->priv->video_box),
717 clutter_actor_get_geometry (self->priv->video_box, &box);
719 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
720 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
721 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
722 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
724 pos = PREVIEW_POS_TOP_LEFT;
726 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
727 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
728 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
729 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
731 pos = PREVIEW_POS_TOP_RIGHT;
733 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
734 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
735 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
736 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
738 pos = PREVIEW_POS_BOTTOM_LEFT;
740 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
741 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
742 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
743 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
745 pos = PREVIEW_POS_BOTTOM_RIGHT;
751 static ClutterActor *
752 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
755 ClutterActor *rectangle;
759 case PREVIEW_POS_TOP_LEFT:
760 rectangle = self->priv->preview_rectangle1;
762 case PREVIEW_POS_TOP_RIGHT:
763 rectangle = self->priv->preview_rectangle3;
765 case PREVIEW_POS_BOTTOM_LEFT:
766 rectangle = self->priv->preview_rectangle2;
768 case PREVIEW_POS_BOTTOM_RIGHT:
769 rectangle = self->priv->preview_rectangle4;
779 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
782 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
784 DEBUG ("moving the video preview to %d", pos);
786 self->priv->preview_pos = pos;
790 case PREVIEW_POS_TOP_LEFT:
791 clutter_bin_layout_set_alignment (layout,
792 self->priv->video_preview,
793 CLUTTER_BIN_ALIGNMENT_START,
794 CLUTTER_BIN_ALIGNMENT_START);
796 case PREVIEW_POS_TOP_RIGHT:
797 clutter_bin_layout_set_alignment (layout,
798 self->priv->video_preview,
799 CLUTTER_BIN_ALIGNMENT_END,
800 CLUTTER_BIN_ALIGNMENT_START);
802 case PREVIEW_POS_BOTTOM_LEFT:
803 clutter_bin_layout_set_alignment (layout,
804 self->priv->video_preview,
805 CLUTTER_BIN_ALIGNMENT_START,
806 CLUTTER_BIN_ALIGNMENT_END);
808 case PREVIEW_POS_BOTTOM_RIGHT:
809 clutter_bin_layout_set_alignment (layout,
810 self->priv->video_preview,
811 CLUTTER_BIN_ALIGNMENT_END,
812 CLUTTER_BIN_ALIGNMENT_END);
815 g_warn_if_reached ();
820 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
823 ClutterActor *rectangle;
825 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
827 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
828 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
833 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
834 ClutterActor *rectangle)
836 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
837 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
838 CLUTTER_COLOR_Black);
842 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
844 ClutterActor *rectangle;
846 rectangle = empathy_call_window_get_preview_rectangle (self,
847 self->priv->preview_pos);
849 /* We don't want to darken the rectangle where the preview
852 if (self->priv->preview_rectangle1 != rectangle)
853 empathy_call_window_darken_preview_rectangle (self,
854 self->priv->preview_rectangle1);
856 if (self->priv->preview_rectangle2 != rectangle)
857 empathy_call_window_darken_preview_rectangle (self,
858 self->priv->preview_rectangle2);
860 if (self->priv->preview_rectangle3 != rectangle)
861 empathy_call_window_darken_preview_rectangle (self,
862 self->priv->preview_rectangle3);
864 if (self->priv->preview_rectangle4 != rectangle)
865 empathy_call_window_darken_preview_rectangle (self,
866 self->priv->preview_rectangle4);
870 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
874 ClutterModifierType modifiers,
875 EmpathyCallWindow *self)
877 ClutterActor *stage = clutter_actor_get_stage (actor);
878 ClutterActor *preview = clutter_clone_new (actor);
881 /* Flip the video preview */
882 /* FIXME: disabled because it makes the drag handle to go away! */
883 clutter_actor_set_rotation (preview,
886 SELF_VIDEO_SECTION_WIDTH * 0.5,
891 clutter_container_add_actor (CLUTTER_CONTAINER (stage), preview);
892 clutter_actor_set_position (preview, event_x, event_y);
894 clutter_drag_action_set_drag_handle (action, preview);
896 clutter_actor_set_opacity (actor, 0);
897 clutter_actor_hide (self->priv->preview_shown_button);
899 empathy_call_window_show_preview_rectangles (self, TRUE);
900 empathy_call_window_darken_preview_rectangles (self);
904 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
908 ClutterModifierType modifiers,
909 EmpathyCallWindow *self)
911 ClutterActor *preview = clutter_drag_action_get_drag_handle (action);
914 /* Get the position before destroying the drag actor, otherwise the
915 * preview_box allocation won't be valid and we won't be able to
916 * calculate the position. */
917 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
919 /* Destroy the video preview copy that we were dragging */
920 clutter_actor_destroy (preview);
922 clutter_actor_set_opacity (actor, 255);
923 clutter_actor_show (self->priv->preview_shown_button);
925 if (pos != PREVIEW_POS_NONE)
926 empathy_call_window_move_video_preview (self, pos);
928 empathy_call_window_show_preview_rectangles (self, FALSE);
932 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
936 EmpathyCallWindow *self)
939 gfloat event_x, event_y;
941 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
943 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
945 if (pos != PREVIEW_POS_NONE)
946 empathy_call_window_highlight_preview_rectangle (self, pos);
948 empathy_call_window_darken_preview_rectangles (self);
952 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
953 ClutterCrossingEvent *event,
954 EmpathyCallWindow *self)
956 ClutterActor *rectangle;
958 rectangle = empathy_call_window_get_preview_rectangle (self,
959 self->priv->preview_pos);
961 empathy_call_window_highlight_preview_rectangle (self,
962 self->priv->preview_pos);
964 clutter_actor_show (rectangle);
970 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
971 ClutterCrossingEvent *event,
972 EmpathyCallWindow *self)
974 ClutterActor *rectangle;
976 rectangle = empathy_call_window_get_preview_rectangle (self,
977 self->priv->preview_pos);
979 empathy_call_window_darken_preview_rectangle (self, rectangle);
981 clutter_actor_hide (rectangle);
987 create_video_preview (EmpathyCallWindow *self)
989 EmpathyCallWindowPriv *priv = GET_PRIV (self);
990 ClutterLayoutManager *layout, *layout_center, *layout_end;
991 ClutterActor *preview;
994 ClutterAction *action;
997 g_assert (priv->video_preview == NULL);
999 preview = empathy_rounded_texture_new ();
1000 clutter_actor_set_size (preview,
1001 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1002 priv->video_preview_sink = clutter_gst_video_sink_new (
1003 CLUTTER_TEXTURE (preview));
1005 /* Flip the video preview */
1006 clutter_actor_set_rotation (preview,
1009 SELF_VIDEO_SECTION_WIDTH * 0.5,
1013 /* Add a little offset to the video preview */
1014 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1015 CLUTTER_BIN_ALIGNMENT_START);
1016 priv->video_preview = clutter_box_new (layout);
1017 clutter_actor_set_size (priv->video_preview,
1018 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1019 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1020 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1022 /* We have a box with the margins and the video in the middle inside
1023 * a bigger box with an extra bottom margin so we're not on top of
1024 * the floating toolbar. */
1025 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1026 CLUTTER_BIN_ALIGNMENT_CENTER);
1027 box = clutter_box_new (layout_center);
1028 clutter_actor_set_size (box,
1029 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1030 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1032 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1033 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1035 g_object_set (priv->video_preview_sink,
1040 /* Translators: this is an "Info" label. It should be as short
1042 button = gtk_button_new_with_label (_("i"));
1043 priv->preview_shown_button = b =
1044 gtk_clutter_actor_new_with_contents (button);
1046 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1047 CLUTTER_BIN_ALIGNMENT_END);
1048 box = clutter_box_new (layout_end);
1049 clutter_actor_set_size (box,
1050 SELF_VIDEO_SECTION_WIDTH,
1051 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1053 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1054 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1056 g_signal_connect (button, "clicked",
1057 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1060 /* Translators: this is an "Info" label. It should be as short
1062 button = gtk_button_new_with_label (_("i"));
1063 priv->preview_hidden_button =
1064 gtk_clutter_actor_new_with_contents (button);
1066 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1067 priv->preview_hidden_button,
1068 CLUTTER_BIN_ALIGNMENT_START,
1069 CLUTTER_BIN_ALIGNMENT_END);
1071 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1073 clutter_actor_hide (priv->preview_hidden_button);
1075 g_signal_connect (button, "clicked",
1076 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1079 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1080 priv->video_preview,
1081 CLUTTER_BIN_ALIGNMENT_START,
1082 CLUTTER_BIN_ALIGNMENT_END);
1084 action = clutter_drag_action_new ();
1085 g_signal_connect (action, "drag-begin",
1086 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1087 g_signal_connect (action, "drag-end",
1088 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1089 g_signal_connect (action, "drag-motion",
1090 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1092 g_signal_connect (preview, "enter-event",
1093 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1094 g_signal_connect (preview, "leave-event",
1095 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1097 clutter_actor_add_action (preview, action);
1098 clutter_actor_set_reactive (preview, TRUE);
1102 play_camera (EmpathyCallWindow *window,
1105 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1106 GstElement *preview;
1109 if (priv->video_preview == NULL)
1111 create_video_preview (window);
1112 add_video_preview_to_pipeline (window);
1116 state = GST_STATE_PLAYING;
1118 state = GST_STATE_NULL;
1120 preview = priv->video_preview_sink;
1122 gst_element_set_state (preview, state);
1123 gst_element_set_state (priv->video_input, state);
1124 gst_element_set_state (priv->video_tee, state);
1128 display_video_preview (EmpathyCallWindow *self,
1131 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1135 /* Display the video preview */
1136 DEBUG ("Show video preview");
1138 play_camera (self, TRUE);
1139 clutter_actor_show (priv->video_preview);
1140 clutter_actor_raise_top (priv->floating_toolbar);
1144 /* Hide the video preview */
1145 DEBUG ("Hide video preview");
1147 if (priv->video_preview != NULL)
1149 clutter_actor_hide (priv->video_preview);
1150 play_camera (self, FALSE);
1156 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1158 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1160 empathy_call_window_status_message (window, _("Connecting…"));
1161 priv->call_state = CONNECTING;
1163 /* Show the toolbar */
1164 clutter_state_set_state (priv->transitions, "fade-in");
1167 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1168 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1172 disable_camera (EmpathyCallWindow *self)
1174 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1176 if (priv->camera_state == CAMERA_STATE_OFF)
1179 DEBUG ("Disable camera");
1181 display_video_preview (self, FALSE);
1183 if (priv->camera_state == CAMERA_STATE_ON)
1184 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1186 priv->camera_state = CAMERA_STATE_OFF;
1190 enable_camera (EmpathyCallWindow *self)
1192 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1194 if (priv->camera_state == CAMERA_STATE_ON)
1197 if (priv->video_input == NULL)
1199 DEBUG ("Can't enable camera, no input");
1203 DEBUG ("Enable camera");
1205 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1207 priv->camera_state = CAMERA_STATE_ON;
1211 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1212 EmpathyCallWindow *self)
1214 if (gtk_toggle_tool_button_get_active (toggle))
1215 enable_camera (self);
1217 disable_camera (self);
1221 create_pipeline (EmpathyCallWindow *self)
1223 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1226 g_assert (priv->pipeline == NULL);
1228 priv->pipeline = gst_pipeline_new (NULL);
1229 priv->pipeline_playing = FALSE;
1231 priv->video_tee = gst_element_factory_make ("tee", NULL);
1232 gst_object_ref (priv->video_tee);
1233 gst_object_sink (priv->video_tee);
1235 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1237 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1238 priv->bus_message_source_id = gst_bus_add_watch (bus,
1239 empathy_call_window_bus_message, self);
1241 g_object_unref (bus);
1245 empathy_call_window_settings_cb (GtkAction *action,
1246 EmpathyCallWindow *self)
1248 gchar *args = g_strdup_printf ("-p %s",
1249 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1251 empathy_launch_program (BIN_DIR, "empathy", args);
1257 empathy_call_window_contents_cb (GtkAction *action,
1258 EmpathyCallWindow *self)
1260 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1264 empathy_call_window_debug_cb (GtkAction *action,
1265 EmpathyCallWindow *self)
1267 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1271 empathy_call_window_about_cb (GtkAction *action,
1272 EmpathyCallWindow *self)
1274 empathy_about_dialog_new (GTK_WINDOW (self));
1278 empathy_call_window_toolbar_timeout (gpointer data)
1280 EmpathyCallWindow *self = data;
1282 /* We don't want to hide the toolbar if we're not in a call, as
1283 * to show the call status all the time. */
1284 if (self->priv->call_state != CONNECTING &&
1285 self->priv->call_state != DISCONNECTED)
1286 clutter_state_set_state (self->priv->transitions, "fade-out");
1292 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1294 EmpathyCallWindow *self)
1296 clutter_state_set_state (self->priv->transitions, "fade-in");
1298 if (self->priv->inactivity_src > 0)
1299 g_source_remove (self->priv->inactivity_src);
1301 self->priv->inactivity_src = g_timeout_add_seconds (3,
1302 empathy_call_window_toolbar_timeout, self);
1308 empathy_call_window_configure_event_cb (GtkWidget *widget,
1310 EmpathyCallWindow *self)
1312 GdkWindow *gdk_window;
1313 GdkWindowState window_state;
1315 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1316 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1318 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1319 &self->priv->dialpad_width, NULL);
1321 gdk_window = gtk_widget_get_window (widget);
1322 window_state = gdk_window_get_state (gdk_window);
1323 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1329 empathy_call_window_destroyed_cb (GtkWidget *object,
1330 EmpathyCallWindow *self)
1332 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1334 /* Save the geometry as if the dialpad was hidden. */
1335 empathy_geometry_save_values (GTK_WINDOW (self),
1336 self->priv->x, self->priv->y,
1337 self->priv->w - self->priv->dialpad_width, self->priv->h,
1338 self->priv->maximized);
1343 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1345 ClutterBindConstraint *constraint)
1347 ClutterActorBox allocation;
1349 clutter_actor_get_allocation_box (stage, &allocation);
1351 clutter_bind_constraint_set_offset (constraint,
1352 allocation.y2 - allocation.y1 -
1353 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1357 empathy_call_window_init (EmpathyCallWindow *self)
1359 EmpathyCallWindowPriv *priv;
1361 GtkWidget *top_vbox;
1363 ClutterConstraint *constraint;
1364 ClutterActor *remote_avatar;
1365 GtkStyleContext *context;
1369 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1370 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1372 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1373 gui = empathy_builder_get_file (filename,
1374 "call_window_vbox", &top_vbox,
1375 "errors_vbox", &priv->errors_vbox,
1376 "pane", &priv->pane,
1377 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1378 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1379 "status_label", &priv->status_label,
1380 "audiocall", &priv->audio_call_button,
1381 "videocall", &priv->video_call_button,
1382 "microphone", &priv->mic_button,
1383 "camera", &priv->camera_button,
1384 "hangup", &priv->hangup_button,
1385 "dialpad", &priv->dialpad_button,
1386 "toolbar", &priv->toolbar,
1387 "bottom_toolbar", &priv->bottom_toolbar,
1388 "ui_manager", &priv->ui_manager,
1389 "menufullscreen", &priv->menu_fullscreen,
1390 "menupreviewswap", &priv->menu_swap_camera,
1391 "details_vbox", &priv->details_vbox,
1392 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1393 "acodec_encoding_label", &priv->acodec_encoding_label,
1394 "acodec_decoding_label", &priv->acodec_decoding_label,
1395 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1396 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1397 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1398 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1399 "video_local_candidate_label", &priv->video_local_candidate_label,
1400 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1401 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1402 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1403 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1407 empathy_builder_connect (gui, self,
1408 "hangup", "clicked", empathy_call_window_hangup_cb,
1409 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1410 "videocall", "clicked", empathy_call_window_video_call_cb,
1411 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1412 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1413 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1414 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1415 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1416 "menusettings", "activate", empathy_call_window_settings_cb,
1417 "menucontents", "activate", empathy_call_window_contents_cb,
1418 "menudebug", "activate", empathy_call_window_debug_cb,
1419 "menuabout", "activate", empathy_call_window_about_cb,
1420 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1421 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1422 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1423 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1426 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1428 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1430 g_object_bind_property (priv->camera_monitor, "available",
1431 priv->camera_button, "sensitive",
1432 G_BINDING_SYNC_CREATE);
1434 g_signal_connect (priv->camera_monitor, "added",
1435 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1436 g_signal_connect (priv->camera_monitor, "removed",
1437 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1439 priv->lock = g_mutex_new ();
1441 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1443 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1444 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1445 CONTENT_HBOX_BORDER_WIDTH);
1446 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1449 /* avatar/video box */
1450 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1451 CLUTTER_BIN_ALIGNMENT_CENTER);
1453 priv->video_box = clutter_box_new (priv->video_layout);
1455 priv->video_container = gtk_clutter_embed_new ();
1457 /* Set the background color to that of the rest of the window */
1458 context = gtk_widget_get_style_context (priv->content_hbox);
1459 gtk_style_context_get_background_color (context,
1460 GTK_STATE_FLAG_NORMAL, &rgba);
1461 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1462 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1463 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1464 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1465 clutter_stage_set_color (
1466 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1467 GTK_CLUTTER_EMBED (priv->video_container))),
1470 clutter_container_add (
1471 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1472 GTK_CLUTTER_EMBED (priv->video_container))),
1476 constraint = clutter_bind_constraint_new (
1477 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1478 CLUTTER_BIND_SIZE, 0);
1479 clutter_actor_add_constraint (priv->video_box, constraint);
1481 priv->remote_user_avatar_widget = gtk_image_new ();
1482 remote_avatar = gtk_clutter_actor_new_with_contents (
1483 priv->remote_user_avatar_widget);
1485 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1488 empathy_call_window_create_preview_rectangles (self);
1490 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1491 priv->video_container, TRUE, TRUE,
1492 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1494 create_pipeline (self);
1495 create_video_output_widget (self);
1496 create_audio_input (self);
1497 create_video_input (self);
1499 priv->floating_toolbar = empathy_rounded_actor_new ();
1501 gtk_widget_reparent (priv->bottom_toolbar,
1502 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1504 constraint = clutter_bind_constraint_new (
1505 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1508 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1511 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1512 "notify::allocation",
1513 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1516 clutter_actor_set_size (priv->floating_toolbar,
1517 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1518 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1520 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1521 priv->floating_toolbar,
1522 CLUTTER_BIN_ALIGNMENT_CENTER,
1523 CLUTTER_BIN_ALIGNMENT_END);
1525 clutter_actor_raise_top (priv->floating_toolbar);
1527 /* Transitions for the floating toolbar */
1528 priv->transitions = clutter_state_new ();
1530 /* all transitions last for 2s */
1531 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1533 /* transition from any state to "fade-out" state */
1534 clutter_state_set (priv->transitions, NULL, "fade-out",
1535 priv->floating_toolbar,
1536 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1539 /* transition from any state to "fade-in" state */
1540 clutter_state_set (priv->transitions, NULL, "fade-in",
1541 priv->floating_toolbar,
1542 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1545 /* put the actor into the "fade-in" state with no animation */
1546 clutter_state_warp_to_state (priv->transitions, "fade-in");
1548 /* The call will be started as soon the pipeline is playing */
1549 priv->start_call_when_playing = TRUE;
1551 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1552 G_CALLBACK (dtmf_button_pressed_cb),
1553 G_CALLBACK (dtmf_button_released_cb));
1555 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1558 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1561 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1563 gtk_widget_show_all (top_vbox);
1565 gtk_widget_hide (priv->dtmf_panel);
1566 gtk_widget_hide (priv->details_vbox);
1568 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1570 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1571 priv->video_container);
1573 /* We hide the bottom toolbar after 3s of inactivity and show it
1574 * again on mouse movement */
1575 priv->inactivity_src = g_timeout_add_seconds (3,
1576 empathy_call_window_toolbar_timeout, self);
1578 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1579 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1581 g_signal_connect (G_OBJECT (self), "realize",
1582 G_CALLBACK (empathy_call_window_realized_cb), self);
1584 g_signal_connect (G_OBJECT (self), "delete-event",
1585 G_CALLBACK (empathy_call_window_delete_cb), self);
1587 g_signal_connect (G_OBJECT (self), "window-state-event",
1588 G_CALLBACK (empathy_call_window_state_event_cb), self);
1590 g_signal_connect (G_OBJECT (self), "key-press-event",
1591 G_CALLBACK (empathy_call_window_key_press_cb), self);
1593 g_signal_connect (self, "motion-notify-event",
1594 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1596 priv->timer = g_timer_new ();
1598 g_object_ref (priv->ui_manager);
1599 g_object_unref (gui);
1601 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1602 priv->mic_menu = empathy_mic_menu_new (self);
1603 priv->camera_menu = empathy_camera_menu_new (self);
1605 empathy_call_window_show_hangup_button (self, TRUE);
1607 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1609 /* Retrieve initial volume */
1610 priv->volume = g_settings_get_double (priv->settings,
1611 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1613 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1614 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1616 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1617 /* These signals are used to track the window position and save it
1618 * when the window is destroyed. We need to do this as we don't want
1619 * the window geometry to be saved with the dialpad taken into account. */
1620 g_signal_connect (self, "destroy",
1621 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1622 g_signal_connect (self, "configure-event",
1623 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1624 g_signal_connect (self, "window-state-event",
1625 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1627 /* Don't display labels in both toolbars */
1628 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1631 /* Instead of specifying a width and a height, we specify only one size. That's
1632 because we want a square avatar icon. */
1634 init_contact_avatar_with_size (EmpathyContact *contact,
1635 GtkWidget *image_widget,
1638 GdkPixbuf *pixbuf_avatar = NULL;
1640 if (contact != NULL)
1642 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1646 if (pixbuf_avatar == NULL)
1648 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1649 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1652 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1654 if (pixbuf_avatar != NULL)
1655 g_object_unref (pixbuf_avatar);
1659 set_window_title (EmpathyCallWindow *self)
1661 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1664 if (priv->contact != NULL)
1666 /* translators: Call is a noun and %s is the contact name. This string
1667 * is used in the window title */
1668 tmp = g_strdup_printf (_("Call with %s"),
1669 empathy_contact_get_alias (priv->contact));
1670 gtk_window_set_title (GTK_WINDOW (self), tmp);
1675 g_warning ("Unknown remote contact!");
1680 set_remote_user_name (EmpathyCallWindow *self,
1681 EmpathyContact *contact)
1683 const gchar *alias = empathy_contact_get_alias (contact);
1684 const gchar *status = empathy_contact_get_status (contact);
1687 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1688 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1694 contact_name_changed_cb (EmpathyContact *contact,
1696 EmpathyCallWindow *self)
1698 set_window_title (self);
1699 set_remote_user_name (self, contact);
1703 contact_presence_changed_cb (EmpathyContact *contact,
1705 EmpathyCallWindow *self)
1707 set_remote_user_name (self, contact);
1711 contact_avatar_changed_cb (EmpathyContact *contact,
1713 EmpathyCallWindow *self)
1716 GtkAllocation allocation;
1717 GtkWidget *avatar_widget;
1719 avatar_widget = self->priv->remote_user_avatar_widget;
1721 gtk_widget_get_allocation (avatar_widget, &allocation);
1722 size = allocation.height;
1726 /* the widget is not allocated yet, set a default size */
1727 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1728 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1731 init_contact_avatar_with_size (contact, avatar_widget, size);
1733 avatar_widget = self->priv->remote_user_avatar_toolbar;
1735 gtk_widget_get_allocation (avatar_widget, &allocation);
1736 size = allocation.height;
1740 /* the widget is not allocated yet, set a default size */
1741 size = SMALL_TOOLBAR_SIZE;
1744 init_contact_avatar_with_size (contact, avatar_widget, size);
1748 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1749 EmpathyCallHandler *handler)
1751 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1753 tp_g_signal_connect_object (priv->contact, "notify::name",
1754 G_CALLBACK (contact_name_changed_cb), self, 0);
1755 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1756 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1757 tp_g_signal_connect_object (priv->contact, "notify::presence",
1758 G_CALLBACK (contact_presence_changed_cb), self, 0);
1760 set_window_title (self);
1761 set_remote_user_name (self, priv->contact);
1763 init_contact_avatar_with_size (priv->contact,
1764 priv->remote_user_avatar_widget,
1765 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1766 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1768 init_contact_avatar_with_size (priv->contact,
1769 priv->remote_user_avatar_toolbar,
1770 SMALL_TOOLBAR_SIZE);
1772 /* The remote avatar is shown by default and will be hidden when we receive
1773 video from the remote side. */
1774 clutter_actor_hide (priv->video_output);
1775 gtk_widget_show (priv->remote_user_avatar_widget);
1779 update_send_codec (EmpathyCallWindow *self,
1782 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1789 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1790 widget = priv->acodec_encoding_label;
1794 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1795 widget = priv->vcodec_encoding_label;
1801 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1802 gtk_label_set_text (GTK_LABEL (widget), tmp);
1807 send_audio_codec_notify_cb (GObject *object,
1811 EmpathyCallWindow *self = user_data;
1813 update_send_codec (self, TRUE);
1817 send_video_codec_notify_cb (GObject *object,
1821 EmpathyCallWindow *self = user_data;
1823 update_send_codec (self, FALSE);
1827 update_recv_codec (EmpathyCallWindow *self,
1830 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1833 GString *str = NULL;
1837 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1838 widget = priv->acodec_decoding_label;
1842 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1843 widget = priv->vcodec_decoding_label;
1849 for (l = codecs; l != NULL; l = g_list_next (l))
1851 FsCodec *codec = l->data;
1854 str = g_string_new (NULL);
1856 g_string_append (str, ", ");
1858 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1862 gtk_label_set_text (GTK_LABEL (widget), str->str);
1863 g_string_free (str, TRUE);
1867 recv_audio_codecs_notify_cb (GObject *object,
1871 EmpathyCallWindow *self = user_data;
1873 update_recv_codec (self, TRUE);
1877 recv_video_codecs_notify_cb (GObject *object,
1881 EmpathyCallWindow *self = user_data;
1883 update_recv_codec (self, FALSE);
1886 static const gchar *
1887 candidate_type_to_str (FsCandidate *candidate)
1889 switch (candidate->type)
1891 case FS_CANDIDATE_TYPE_HOST:
1893 case FS_CANDIDATE_TYPE_SRFLX:
1894 return "server reflexive";
1895 case FS_CANDIDATE_TYPE_PRFLX:
1896 return "peer reflexive";
1897 case FS_CANDIDATE_TYPE_RELAY:
1899 case FS_CANDIDATE_TYPE_MULTICAST:
1906 static const gchar *
1907 candidate_type_to_desc (FsCandidate *candidate)
1909 switch (candidate->type)
1911 case FS_CANDIDATE_TYPE_HOST:
1912 return _("The IP address as seen by the machine");
1913 case FS_CANDIDATE_TYPE_SRFLX:
1914 return _("The IP address as seen by a server on the Internet");
1915 case FS_CANDIDATE_TYPE_PRFLX:
1916 return _("The IP address of the peer as seen by the other side");
1917 case FS_CANDIDATE_TYPE_RELAY:
1918 return _("The IP address of a relay server");
1919 case FS_CANDIDATE_TYPE_MULTICAST:
1920 return _("The IP address of the multicast group");
1927 update_candidat_widget (EmpathyCallWindow *self,
1930 FsCandidate *candidate)
1934 g_assert (candidate != NULL);
1935 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1936 candidate->port, candidate_type_to_str (candidate));
1938 gtk_label_set_text (GTK_LABEL (label), str);
1939 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1945 candidates_changed_cb (GObject *object,
1947 EmpathyCallWindow *self)
1949 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1950 FsCandidate *candidate = NULL;
1952 if (type == FS_MEDIA_TYPE_VIDEO)
1954 /* Update remote candidate */
1955 candidate = empathy_call_handler_get_video_remote_candidate (
1958 update_candidat_widget (self, priv->video_remote_candidate_label,
1959 priv->video_remote_candidate_info_img, candidate);
1961 /* Update local candidate */
1962 candidate = empathy_call_handler_get_video_local_candidate (
1965 update_candidat_widget (self, priv->video_local_candidate_label,
1966 priv->video_local_candidate_info_img, candidate);
1970 /* Update remote candidate */
1971 candidate = empathy_call_handler_get_audio_remote_candidate (
1974 update_candidat_widget (self, priv->audio_remote_candidate_label,
1975 priv->audio_remote_candidate_info_img, candidate);
1977 /* Update local candidate */
1978 candidate = empathy_call_handler_get_audio_local_candidate (
1981 update_candidat_widget (self, priv->audio_local_candidate_label,
1982 priv->audio_local_candidate_info_img, candidate);
1987 empathy_call_window_constructed (GObject *object)
1989 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1990 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1991 TpyCallChannel *call;
1993 g_assert (priv->handler != NULL);
1995 g_object_get (priv->handler, "call-channel", &call, NULL);
1996 priv->outgoing = (call == NULL);
1998 g_object_unref (call);
2000 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2001 g_assert (priv->contact != NULL);
2003 empathy_call_window_setup_avatars (self, priv->handler);
2004 empathy_call_window_set_state_connecting (self);
2006 if (!empathy_call_handler_has_initial_video (priv->handler))
2008 gtk_toggle_tool_button_set_active (
2009 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2011 /* If call has InitialVideo, the preview will be started once the call has
2012 * been started (start_call()). */
2014 update_send_codec (self, TRUE);
2015 update_send_codec (self, FALSE);
2016 update_recv_codec (self, TRUE);
2017 update_recv_codec (self, FALSE);
2019 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2020 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2021 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2022 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2023 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2024 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2025 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2026 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2028 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2029 G_CALLBACK (candidates_changed_cb), self, 0);
2032 static void empathy_call_window_dispose (GObject *object);
2033 static void empathy_call_window_finalize (GObject *object);
2036 empathy_call_window_set_property (GObject *object,
2037 guint property_id, const GValue *value, GParamSpec *pspec)
2039 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2041 switch (property_id)
2043 case PROP_CALL_HANDLER:
2044 priv->handler = g_value_dup_object (value);
2047 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2052 empathy_call_window_get_property (GObject *object,
2053 guint property_id, GValue *value, GParamSpec *pspec)
2055 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2057 switch (property_id)
2059 case PROP_CALL_HANDLER:
2060 g_value_set_object (value, priv->handler);
2063 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2068 empathy_call_window_class_init (
2069 EmpathyCallWindowClass *empathy_call_window_class)
2071 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2072 GParamSpec *param_spec;
2074 g_type_class_add_private (empathy_call_window_class,
2075 sizeof (EmpathyCallWindowPriv));
2077 object_class->constructed = empathy_call_window_constructed;
2078 object_class->set_property = empathy_call_window_set_property;
2079 object_class->get_property = empathy_call_window_get_property;
2081 object_class->dispose = empathy_call_window_dispose;
2082 object_class->finalize = empathy_call_window_finalize;
2084 param_spec = g_param_spec_object ("handler",
2085 "handler", "The call handler",
2086 EMPATHY_TYPE_CALL_HANDLER,
2087 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2088 g_object_class_install_property (object_class,
2089 PROP_CALL_HANDLER, param_spec);
2093 empathy_call_window_dispose (GObject *object)
2095 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2096 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2098 if (priv->dispose_has_run)
2101 priv->dispose_has_run = TRUE;
2103 if (priv->handler != NULL)
2105 empathy_call_handler_stop_call (priv->handler);
2106 tp_clear_object (&priv->handler);
2109 if (priv->bus_message_source_id != 0)
2111 g_source_remove (priv->bus_message_source_id);
2112 priv->bus_message_source_id = 0;
2115 if (priv->got_video_src > 0)
2117 g_source_remove (priv->got_video_src);
2118 priv->got_video_src = 0;
2121 if (priv->inactivity_src > 0)
2123 g_source_remove (priv->inactivity_src);
2124 priv->inactivity_src = 0;
2127 tp_clear_object (&priv->pipeline);
2128 tp_clear_object (&priv->video_input);
2129 tp_clear_object (&priv->audio_input);
2130 tp_clear_object (&priv->video_tee);
2131 tp_clear_object (&priv->ui_manager);
2132 tp_clear_object (&priv->fullscreen);
2133 tp_clear_object (&priv->camera_monitor);
2134 tp_clear_object (&priv->settings);
2135 tp_clear_object (&priv->sound_mgr);
2136 tp_clear_object (&priv->mic_menu);
2137 tp_clear_object (&priv->camera_menu);
2139 g_list_free_full (priv->notifiers, g_object_unref);
2141 if (priv->timer_id != 0)
2142 g_source_remove (priv->timer_id);
2145 if (priv->contact != NULL)
2147 g_signal_handlers_disconnect_by_func (priv->contact,
2148 contact_name_changed_cb, self);
2149 priv->contact = NULL;
2152 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2156 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2158 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2160 if (priv->video_output_motion_handler_id != 0)
2162 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2163 priv->video_output_motion_handler_id);
2164 priv->video_output_motion_handler_id = 0;
2169 empathy_call_window_finalize (GObject *object)
2171 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2172 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2174 disconnect_video_output_motion_handler (self);
2176 /* free any data held directly by the object here */
2177 g_mutex_free (priv->lock);
2179 g_timer_destroy (priv->timer);
2181 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2186 empathy_call_window_new (EmpathyCallHandler *handler)
2188 return EMPATHY_CALL_WINDOW (
2189 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2193 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2194 GstElement *conference, gpointer user_data)
2196 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2197 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2198 FsElementAddedNotifier *notifier;
2201 DEBUG ("Conference added");
2203 /* Add notifier to set the various element properties as needed */
2204 notifier = fs_element_added_notifier_new ();
2205 keyfile = fs_utils_get_default_element_properties (conference);
2207 if (keyfile != NULL)
2208 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2210 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2212 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2214 gst_bin_add (GST_BIN (priv->pipeline), conference);
2215 gst_element_set_state (conference, GST_STATE_PLAYING);
2219 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2220 GstElement *conference, gpointer user_data)
2222 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2223 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2225 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2226 gst_element_set_state (conference, GST_STATE_NULL);
2230 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2232 GstStateChangeReturn state_change_return;
2233 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2235 if (priv->pipeline == NULL)
2238 if (priv->bus_message_source_id != 0)
2240 g_source_remove (priv->bus_message_source_id);
2241 priv->bus_message_source_id = 0;
2244 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2246 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2247 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2249 if (priv->pipeline != NULL)
2250 g_object_unref (priv->pipeline);
2251 priv->pipeline = NULL;
2253 if (priv->audio_output != NULL)
2254 g_object_unref (priv->audio_output);
2255 priv->audio_output = NULL;
2257 if (priv->video_tee != NULL)
2258 g_object_unref (priv->video_tee);
2259 priv->video_tee = NULL;
2261 if (priv->video_preview != NULL)
2262 clutter_actor_destroy (priv->video_preview);
2263 priv->video_preview = NULL;
2265 priv->funnel = NULL;
2267 create_pipeline (self);
2268 /* Call will be started when user will hit the 'redial' button */
2269 priv->start_call_when_playing = FALSE;
2270 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2276 g_message ("Error: could not destroy pipeline. Closing call window");
2277 gtk_widget_destroy (GTK_WIDGET (self));
2284 reset_details_pane (EmpathyCallWindow *self)
2286 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2288 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2289 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2290 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2291 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2295 empathy_call_window_disconnected (EmpathyCallWindow *self,
2298 gboolean could_disconnect = FALSE;
2299 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2300 gboolean could_reset_pipeline;
2302 /* Leave full screen mode if needed */
2303 gtk_window_unfullscreen (GTK_WINDOW (self));
2305 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2306 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2308 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2310 if (priv->call_state == CONNECTING)
2311 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2313 if (priv->call_state != REDIALING)
2314 priv->call_state = DISCONNECTED;
2316 /* Show the toolbar */
2317 clutter_state_set_state (priv->transitions, "fade-in");
2319 if (could_reset_pipeline)
2321 g_mutex_lock (priv->lock);
2323 g_timer_stop (priv->timer);
2325 if (priv->timer_id != 0)
2326 g_source_remove (priv->timer_id);
2329 g_mutex_unlock (priv->lock);
2332 /* We are about to destroy the window, no need to update it or create
2333 * a video preview */
2336 empathy_call_window_status_message (self, _("Disconnected"));
2338 empathy_call_window_show_hangup_button (self, FALSE);
2340 /* Unsensitive the camera and mic button */
2341 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2342 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2344 /* Be sure that the mic button is enabled */
2345 gtk_toggle_tool_button_set_active (
2346 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2348 if (priv->camera_state == CAMERA_STATE_ON)
2350 /* Restart the preview with the new pipeline. */
2351 display_video_preview (self, TRUE);
2354 /* destroy the video output; it will be recreated when we'll redial */
2355 disconnect_video_output_motion_handler (self);
2356 if (priv->video_output != NULL)
2357 clutter_actor_destroy (priv->video_output);
2358 priv->video_output = NULL;
2359 if (priv->got_video_src > 0)
2361 g_source_remove (priv->got_video_src);
2362 priv->got_video_src = 0;
2365 gtk_widget_show (priv->remote_user_avatar_widget);
2367 reset_details_pane (self);
2369 priv->sending_video = FALSE;
2370 priv->call_started = FALSE;
2372 could_disconnect = TRUE;
2374 /* TODO: display the self avatar of the preview (depends if the "Always
2375 * Show Video Preview" is enabled or not) */
2378 return could_disconnect;
2383 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2386 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2387 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2389 if (empathy_call_window_disconnected (self, TRUE) &&
2390 priv->call_state == REDIALING)
2391 empathy_call_window_restart_call (self);
2395 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2397 FsMediaType media_type,
2398 EmpathyCallWindow *self)
2400 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2402 DEBUG ("removing content");
2405 * This assumes that there is only one video stream per channel...
2408 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2410 if (priv->funnel != NULL)
2414 output = priv->video_output_sink;
2416 gst_element_set_state (output, GST_STATE_NULL);
2417 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2419 gst_bin_remove (GST_BIN (priv->pipeline), output);
2420 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2421 priv->funnel = NULL;
2425 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2427 if (priv->audio_output != NULL)
2429 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2431 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2432 priv->audio_output = NULL;
2440 /* Called with global lock held */
2442 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2444 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2448 if (priv->funnel == NULL)
2450 output = priv->video_output_sink;
2452 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2456 g_warning ("Could not create fsfunnel");
2460 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2462 gst_object_unref (priv->funnel);
2463 priv->funnel = NULL;
2464 g_warning ("Could not add funnel to pipeline");
2468 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2470 g_warning ("Could not add the video output widget to the pipeline");
2474 if (!gst_element_link (priv->funnel, output))
2476 g_warning ("Could not link output sink to funnel");
2477 goto error_output_added;
2480 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2482 g_warning ("Could not start video sink");
2483 goto error_output_added;
2486 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2488 g_warning ("Could not start funnel");
2489 goto error_output_added;
2493 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2496 g_warning ("Could not get request pad from funnel");
2503 gst_element_set_locked_state (priv->funnel, TRUE);
2504 gst_element_set_locked_state (output, TRUE);
2506 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2507 gst_element_set_state (output, GST_STATE_NULL);
2509 gst_bin_remove (GST_BIN (priv->pipeline), output);
2510 gst_element_set_locked_state (output, FALSE);
2514 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2515 priv->funnel = NULL;
2520 /* Called with global lock held */
2522 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2524 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2526 GstPadTemplate *template;
2528 if (priv->audio_output == NULL)
2530 priv->audio_output = empathy_audio_sink_new ();
2531 g_object_ref_sink (priv->audio_output);
2533 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2535 g_warning ("Could not add audio sink to pipeline");
2536 g_object_unref (priv->audio_output);
2537 goto error_add_output;
2540 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2542 g_warning ("Could not start audio sink");
2547 template = gst_element_class_get_pad_template (
2548 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2550 pad = gst_element_request_pad (priv->audio_output,
2551 template, NULL, NULL);
2555 g_warning ("Could not get sink pad from sink");
2562 gst_element_set_locked_state (priv->audio_output, TRUE);
2563 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2564 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2565 priv->audio_output = NULL;
2573 empathy_call_window_update_timer (gpointer user_data)
2575 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2576 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2577 const gchar *status;
2581 time_ = g_timer_elapsed (priv->timer, NULL);
2583 if (priv->call_state == HELD)
2584 status = _("On hold");
2585 else if (!gtk_toggle_tool_button_get_active (
2586 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2589 status = _("Duration");
2591 /* Translators: 'status - minutes:seconds' the caller has been connected */
2592 str = g_strdup_printf (_("%s — %d:%02dm"),
2594 (int) time_ / 60, (int) time_ % 60);
2595 empathy_call_window_status_message (self, str);
2603 display_error (EmpathyCallWindow *self,
2604 TpyCallChannel *call,
2608 const gchar *details)
2610 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2611 GtkWidget *info_bar;
2612 GtkWidget *content_area;
2619 /* Create info bar */
2620 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2623 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2625 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2627 /* hbox containing the image and the messages vbox */
2628 hbox = gtk_hbox_new (FALSE, 3);
2629 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2632 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2633 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2635 /* vbox containing the main message and the details expander */
2636 vbox = gtk_vbox_new (FALSE, 3);
2637 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2640 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2642 label = gtk_label_new (NULL);
2643 gtk_label_set_markup (GTK_LABEL (label), txt);
2644 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2645 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2648 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2651 if (details != NULL)
2653 GtkWidget *expander;
2655 expander = gtk_expander_new (_("Technical Details"));
2657 txt = g_strdup_printf ("<i>%s</i>", details);
2659 label = gtk_label_new (NULL);
2660 gtk_label_set_markup (GTK_LABEL (label), txt);
2661 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2662 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2665 gtk_container_add (GTK_CONTAINER (expander), label);
2666 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2669 g_signal_connect (info_bar, "response",
2670 G_CALLBACK (gtk_widget_destroy), NULL);
2672 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2673 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2674 gtk_widget_show_all (info_bar);
2678 media_stream_error_to_txt (EmpathyCallWindow *self,
2679 TpyCallChannel *call,
2681 TpMediaStreamError error)
2683 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2684 const gchar *cm = NULL;
2690 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2692 return g_strdup_printf (
2693 _("%s's software does not understand any of the audio formats "
2694 "supported by your computer"),
2695 empathy_contact_get_alias (priv->contact));
2697 return g_strdup_printf (
2698 _("%s's software does not understand any of the video formats "
2699 "supported by your computer"),
2700 empathy_contact_get_alias (priv->contact));
2702 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2703 return g_strdup_printf (
2704 _("Can't establish a connection to %s. "
2705 "One of you might be on a network that does not allow "
2706 "direct connections."),
2707 empathy_contact_get_alias (priv->contact));
2709 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2710 return g_strdup (_("There was a failure on the network"));
2712 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2714 return g_strdup (_("The audio formats necessary for this call "
2715 "are not installed on your computer"));
2717 return g_strdup (_("The video formats necessary for this call "
2718 "are not installed on your computer"));
2720 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2721 tp_connection_parse_object_path (
2722 tp_channel_borrow_connection (TP_CHANNEL (call)),
2725 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2726 "product=Telepathy&component=%s", cm);
2728 result = g_strdup_printf (
2729 _("Something unexpected happened in a Telepathy component. "
2730 "Please <a href=\"%s\">report this bug</a> and attach "
2731 "logs gathered from the 'Debug' window in the Help menu."), url);
2737 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2738 return g_strdup (_("There was a failure in the call engine"));
2740 case TP_MEDIA_STREAM_ERROR_EOS:
2741 return g_strdup (_("The end of the stream was reached"));
2743 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2750 empathy_call_window_stream_error (EmpathyCallWindow *self,
2751 TpyCallChannel *call,
2760 desc = media_stream_error_to_txt (self, call, audio, code);
2763 /* No description, use the error message. That's not great as it's not
2764 * localized but it's better than nothing. */
2765 display_error (self, call, icon, title, msg, NULL);
2769 display_error (self, call, icon, title, desc, msg);
2775 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2778 EmpathyCallWindow *self)
2780 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2781 "gnome-stock-mic", _("Can't establish audio stream"));
2785 empathy_call_window_video_stream_error (TpyCallChannel *call,
2788 EmpathyCallWindow *self)
2790 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2791 "camera-web", _("Can't establish video stream"));
2796 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2798 EmpathyCallWindow *self)
2800 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2801 TpyCallChannel *call;
2802 gboolean can_send_video;
2804 if (state != TPY_CALL_STATE_ACCEPTED)
2807 if (priv->call_state == CONNECTED)
2810 g_timer_start (priv->timer);
2811 priv->call_state = CONNECTED;
2813 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2815 can_send_video = priv->video_input != NULL &&
2816 empathy_contact_can_voip_video (priv->contact) &&
2817 empathy_camera_monitor_get_available (priv->camera_monitor);
2819 g_object_get (priv->handler, "call-channel", &call, NULL);
2821 if (tpy_call_channel_has_dtmf (call))
2822 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2824 if (priv->video_input == NULL)
2825 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2827 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2829 empathy_call_window_show_hangup_button (self, TRUE);
2831 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2833 clutter_actor_hide (priv->video_output);
2834 gtk_widget_show (priv->remote_user_avatar_widget);
2836 g_object_unref (call);
2838 g_mutex_lock (priv->lock);
2840 priv->timer_id = g_timeout_add_seconds (1,
2841 empathy_call_window_update_timer, self);
2843 g_mutex_unlock (priv->lock);
2845 empathy_call_window_update_timer (self);
2847 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2851 empathy_call_window_show_video_output_cb (gpointer user_data)
2853 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2855 if (self->priv->video_output != NULL)
2857 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2858 clutter_actor_show (self->priv->video_output);
2859 empathy_call_window_raise_actors (self);
2866 empathy_call_window_check_video_cb (gpointer data)
2868 EmpathyCallWindow *self = data;
2870 if (self->priv->got_video)
2872 self->priv->got_video = FALSE;
2876 /* No video in the last N seconds, display the remote avatar */
2877 empathy_call_window_show_video_output (self, FALSE);
2882 /* Called from the streaming thread */
2884 empathy_call_window_video_probe_cb (GstPad *pad,
2885 GstMiniObject *mini_obj,
2886 EmpathyCallWindow *self)
2889 if (GST_IS_EVENT (mini_obj))
2892 if (G_UNLIKELY (!self->priv->got_video))
2894 /* show the remote video */
2895 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2896 empathy_call_window_show_video_output_cb,
2897 g_object_ref (self), g_object_unref);
2899 self->priv->got_video = TRUE;
2905 /* Called from the streaming thread */
2907 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2908 GstPad *src, guint media_type, gpointer user_data)
2910 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2911 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2912 gboolean retval = FALSE;
2916 g_mutex_lock (priv->lock);
2920 case TP_MEDIA_STREAM_TYPE_AUDIO:
2921 pad = empathy_call_window_get_audio_sink_pad (self);
2923 case TP_MEDIA_STREAM_TYPE_VIDEO:
2924 g_idle_add (empathy_call_window_show_video_output_cb, self);
2925 pad = empathy_call_window_get_video_sink_pad (self);
2927 gst_pad_add_data_probe (src,
2928 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2929 if (priv->got_video_src > 0)
2930 g_source_remove (priv->got_video_src);
2931 priv->got_video_src = g_timeout_add_seconds (5,
2932 empathy_call_window_check_video_cb, self);
2935 g_assert_not_reached ();
2941 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2942 g_warning ("Could not link %s sink pad",
2943 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2947 gst_object_unref (pad);
2951 /* If no sink could be linked, try to add fakesink to prevent the whole call
2956 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2958 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2960 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2961 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2962 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2964 gst_element_set_locked_state (fakesink, TRUE);
2965 gst_element_set_state (fakesink, GST_STATE_NULL);
2966 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2970 DEBUG ("Could not link real sink, linked fakesink instead");
2972 gst_object_unref (sinkpad);
2976 gst_object_unref (fakesink);
2981 g_mutex_unlock (priv->lock);
2987 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2988 GstPad *sink, FsMediaType media_type, gpointer user_data)
2990 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2991 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2993 gboolean retval = FALSE;
2997 case FS_MEDIA_TYPE_AUDIO:
2998 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3000 g_warning ("Could not add audio source to pipeline");
3004 pad = gst_element_get_static_pad (priv->audio_input, "src");
3007 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3008 g_warning ("Could not get source pad from audio source");
3012 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3014 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3015 g_warning ("Could not link audio source to farsight");
3019 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3021 g_warning ("Could not start audio source");
3022 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3023 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3029 case FS_MEDIA_TYPE_VIDEO:
3030 if (priv->video_tee != NULL)
3032 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3033 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3035 g_warning ("Could not link video source input pipeline");
3038 gst_object_unref (pad);
3044 g_assert_not_reached ();
3051 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3053 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3054 GstElement *preview;
3056 disable_camera (self);
3058 DEBUG ("remove video input");
3059 preview = priv->video_preview_sink;
3061 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3062 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3063 gst_element_set_state (preview, GST_STATE_NULL);
3065 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3068 g_object_unref (priv->video_input);
3069 priv->video_input = NULL;
3070 g_object_unref (priv->video_tee);
3071 priv->video_tee = NULL;
3072 clutter_actor_destroy (priv->video_preview);
3073 priv->video_preview = NULL;
3075 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3079 start_call (EmpathyCallWindow *self)
3081 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3083 priv->call_started = TRUE;
3084 empathy_call_handler_start_call (priv->handler,
3085 gtk_get_current_event_time ());
3087 if (empathy_call_handler_has_initial_video (priv->handler))
3089 TpyCallChannel *call;
3092 g_object_get (priv->handler, "call-channel", &call, NULL);
3093 s = tpy_call_channel_get_video_state (call);
3095 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3096 s == TPY_SENDING_STATE_SENDING)
3098 /* Enable 'send video' buttons and display the preview */
3099 gtk_toggle_tool_button_set_active (
3100 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3104 gtk_toggle_tool_button_set_active (
3105 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3107 if (priv->video_preview == NULL)
3109 create_video_preview (self);
3110 add_video_preview_to_pipeline (self);
3114 g_object_unref (call);
3119 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3122 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3123 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3126 empathy_call_handler_bus_message (priv->handler, bus, message);
3128 switch (GST_MESSAGE_TYPE (message))
3130 case GST_MESSAGE_STATE_CHANGED:
3131 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3133 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3135 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3136 !priv->call_started)
3138 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3139 if (newstate == GST_STATE_PAUSED)
3141 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3142 priv->pipeline_playing = TRUE;
3144 if (priv->start_call_when_playing)
3149 case GST_MESSAGE_ERROR:
3151 GError *error = NULL;
3152 GstElement *gst_error;
3155 gst_message_parse_error (message, &error, &debug);
3156 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3158 g_message ("Element error: %s -- %s\n", error->message, debug);
3160 if (g_str_has_prefix (gst_element_get_name (gst_error),
3161 VIDEO_INPUT_ERROR_PREFIX))
3163 /* Remove the video input and continue */
3164 if (priv->video_input != NULL)
3165 empathy_call_window_remove_video_input (self);
3166 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3170 empathy_call_window_disconnected (self, TRUE);
3172 g_error_free (error);
3175 case GST_MESSAGE_UNKNOWN:
3176 case GST_MESSAGE_EOS:
3177 case GST_MESSAGE_WARNING:
3178 case GST_MESSAGE_INFO:
3179 case GST_MESSAGE_TAG:
3180 case GST_MESSAGE_BUFFERING:
3181 case GST_MESSAGE_STATE_DIRTY:
3182 case GST_MESSAGE_STEP_DONE:
3183 case GST_MESSAGE_CLOCK_PROVIDE:
3184 case GST_MESSAGE_CLOCK_LOST:
3185 case GST_MESSAGE_NEW_CLOCK:
3186 case GST_MESSAGE_STRUCTURE_CHANGE:
3187 case GST_MESSAGE_STREAM_STATUS:
3188 case GST_MESSAGE_APPLICATION:
3189 case GST_MESSAGE_ELEMENT:
3190 case GST_MESSAGE_SEGMENT_START:
3191 case GST_MESSAGE_SEGMENT_DONE:
3192 case GST_MESSAGE_DURATION:
3193 case GST_MESSAGE_ANY:
3202 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3203 GHashTable *members,
3204 EmpathyCallWindow *self)
3206 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3207 GHashTableIter iter;
3208 gpointer key, value;
3209 gboolean held = FALSE;
3211 g_hash_table_iter_init (&iter, members);
3212 while (g_hash_table_iter_next (&iter, &key, &value))
3214 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3216 /* This assumes this is a 1-1 call, otherwise one participant
3217 * putting the call on hold wouldn't mean the call is on hold
3225 priv->call_state = HELD;
3226 else if (priv->call_state == HELD)
3227 priv->call_state = CONNECTED;
3231 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3233 EmpathyCallWindow *self)
3235 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3236 TpyCallChannel *call;
3238 g_object_get (priv->handler, "call-channel", &call, NULL);
3243 tp_g_signal_connect_object (call, "audio-stream-error",
3244 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3245 tp_g_signal_connect_object (call, "video-stream-error",
3246 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3249 tp_g_signal_connect_object (call, "members-changed",
3250 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3252 g_object_unref (call);
3256 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3258 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3259 TpyCallChannel *call;
3262 /* Make the hangup button twice as wide */
3263 width = gtk_widget_get_allocated_width (priv->hangup_button);
3264 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3266 g_signal_connect (priv->handler, "state-changed",
3267 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3268 g_signal_connect (priv->handler, "conference-added",
3269 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3270 g_signal_connect (priv->handler, "conference-removed",
3271 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3272 g_signal_connect (priv->handler, "closed",
3273 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3274 g_signal_connect (priv->handler, "src-pad-added",
3275 G_CALLBACK (empathy_call_window_src_added_cb), window);
3276 g_signal_connect (priv->handler, "sink-pad-added",
3277 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3278 g_signal_connect (priv->handler, "sink-pad-removed",
3279 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3281 g_object_get (priv->handler, "call-channel", &call, NULL);
3284 call_handler_notify_call_cb (priv->handler, NULL, window);
3285 g_object_unref (call);
3289 /* call-channel doesn't exist yet, we'll connect signals once it has been
3291 g_signal_connect (priv->handler, "notify::call-channel",
3292 G_CALLBACK (call_handler_notify_call_cb), window);
3295 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3299 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3300 EmpathyCallWindow *window)
3302 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3304 if (priv->pipeline != NULL)
3306 if (priv->bus_message_source_id != 0)
3308 g_source_remove (priv->bus_message_source_id);
3309 priv->bus_message_source_id = 0;
3312 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3315 if (priv->call_state == CONNECTING)
3316 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3322 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3325 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3327 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3332 gtk_widget_hide (priv->dtmf_panel);
3333 gtk_widget_hide (menu);
3334 gtk_widget_hide (priv->toolbar);
3338 if (priv->dialpad_was_visible_before_fs)
3339 gtk_widget_show (priv->dtmf_panel);
3341 gtk_widget_show (menu);
3342 gtk_widget_show (priv->toolbar);
3344 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3345 priv->original_height_before_fs);
3350 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3352 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3354 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3355 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3356 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3357 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3359 if (priv->video_output != NULL)
3362 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3363 priv->video_output, TRUE, TRUE,
3364 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3371 empathy_call_window_state_event_cb (GtkWidget *widget,
3372 GdkEventWindowState *event, EmpathyCallWindow *window)
3374 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3376 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3377 gboolean set_fullscreen = event->new_window_state &
3378 GDK_WINDOW_STATE_FULLSCREEN;
3382 gboolean dialpad_was_visible;
3383 GtkAllocation allocation;
3384 gint original_width, original_height;
3386 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3387 original_width = allocation.width;
3388 original_height = allocation.height;
3390 g_object_get (priv->dtmf_panel,
3391 "visible", &dialpad_was_visible,
3394 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3395 priv->original_width_before_fs = original_width;
3396 priv->original_height_before_fs = original_height;
3398 if (priv->video_output_motion_handler_id == 0 &&
3399 priv->video_output != NULL)
3401 priv->video_output_motion_handler_id = g_signal_connect (
3402 G_OBJECT (priv->video_container), "motion-notify-event",
3403 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3409 disconnect_video_output_motion_handler (window);
3412 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3414 show_controls (window, set_fullscreen);
3415 show_borders (window, set_fullscreen);
3416 gtk_action_set_stock_id (priv->menu_fullscreen,
3417 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3418 priv->is_fullscreen = set_fullscreen;
3425 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3428 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3429 int w, h, dialpad_width;
3430 GtkAllocation allocation;
3432 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3433 w = allocation.width;
3434 h = allocation.height;
3436 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3440 gtk_widget_show (priv->dtmf_panel);
3446 gtk_widget_hide (priv->dtmf_panel);
3450 gtk_window_resize (GTK_WINDOW (window), w, h);
3454 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3457 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3458 TpyCallChannel *call;
3460 priv->sending_video = (state == CAMERA_STATE_ON);
3462 if (state == CAMERA_STATE_ON)
3464 /* When we start sending video, we want to show the video preview by
3466 display_video_preview (window, TRUE);
3470 display_video_preview (window, FALSE);
3473 if (priv->call_state != CONNECTED)
3476 g_object_get (priv->handler, "call-channel", &call, NULL);
3477 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3478 tpy_call_channel_send_video (call, priv->sending_video);
3479 g_object_unref (call);
3483 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3484 EmpathyCallWindow *self)
3486 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3489 active = (gtk_toggle_tool_button_get_active (toggle));
3491 /* We don't want the settings callback to react to this change to avoid
3493 g_signal_handlers_block_by_func (priv->settings,
3494 empathy_call_window_prefs_volume_changed_cb, self);
3498 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3499 priv->volume * 100);
3503 /* TODO, Instead of setting the input volume to 0 we should probably
3504 * stop sending but this would cause the audio call to drop if both
3505 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3506 * in the future. GNOME #574574
3508 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3512 g_signal_handlers_unblock_by_func (priv->settings,
3513 empathy_call_window_prefs_volume_changed_cb, self);
3517 empathy_call_window_hangup_cb (gpointer object,
3518 EmpathyCallWindow *self)
3520 empathy_call_handler_stop_call (self->priv->handler);
3522 empathy_call_window_disconnected (self, TRUE);
3526 empathy_call_window_restart_call (EmpathyCallWindow *window)
3528 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3530 /* Remove error info bars */
3531 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3532 (GtkCallback) gtk_widget_destroy, NULL);
3534 create_video_output_widget (window);
3536 /* While the call was disconnected, the input volume might have changed.
3537 * However, since the audio_input source was destroyed, its volume has not
3538 * been updated during that time. That's why we manually update it here */
3539 empathy_call_window_mic_volume_changed (window);
3541 priv->outgoing = TRUE;
3542 empathy_call_window_set_state_connecting (window);
3544 if (priv->pipeline_playing)
3545 start_call (window);
3547 /* call will be started when the pipeline is ready */
3548 priv->start_call_when_playing = TRUE;
3550 empathy_call_window_setup_avatars (window, priv->handler);
3552 empathy_call_window_show_hangup_button (window, TRUE);
3556 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3557 EmpathyCallWindow *window)
3561 active = gtk_toggle_tool_button_get_active (button);
3563 empathy_call_window_show_dialpad (window, active);
3567 empathy_call_window_fullscreen_cb (gpointer object,
3568 EmpathyCallWindow *window)
3570 empathy_call_window_fullscreen_toggle (window);
3574 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3576 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3578 if (priv->is_fullscreen)
3579 gtk_window_unfullscreen (GTK_WINDOW (window));
3581 gtk_window_fullscreen (GTK_WINDOW (window));
3585 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3586 GdkEventButton *event, EmpathyCallWindow *window)
3588 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3590 empathy_call_window_video_menu_popup (window, event->button);
3598 empathy_call_window_key_press_cb (GtkWidget *video_output,
3599 GdkEventKey *event, EmpathyCallWindow *window)
3601 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3603 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3605 /* Since we are in fullscreen mode, toggling will bring us back to
3607 empathy_call_window_fullscreen_toggle (window);
3615 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3616 GdkEventMotion *event, EmpathyCallWindow *window)
3618 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3620 if (priv->is_fullscreen)
3622 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3624 /* Show the bottom toolbar */
3625 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3632 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3636 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3638 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3640 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3641 button, gtk_get_current_event_time ());
3642 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3646 empathy_call_window_status_message (EmpathyCallWindow *self,
3649 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3653 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3654 gdouble value, EmpathyCallWindow *window)
3656 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3658 if (priv->audio_output == NULL)
3661 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3666 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3668 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3670 return priv->ui_manager;
3673 EmpathyGstAudioSrc *
3674 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3676 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3678 return (EmpathyGstAudioSrc *) priv->audio_input;
3681 EmpathyGstVideoSrc *
3682 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3684 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);