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-camera-menu.h"
70 #define CONTENT_HBOX_BORDER_WIDTH 6
71 #define CONTENT_HBOX_SPACING 3
72 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
74 #define SELF_VIDEO_SECTION_WIDTH 120
75 #define SELF_VIDEO_SECTION_HEIGHT 90
76 #define SELF_VIDEO_SECTION_MARGIN 10
78 #define FLOATING_TOOLBAR_OPACITY 192
79 #define FLOATING_TOOLBAR_WIDTH 280
80 #define FLOATING_TOOLBAR_HEIGHT 36
81 #define FLOATING_TOOLBAR_SPACING 20
83 /* The avatar's default width and height are set to the same value because we
84 want a square icon. */
85 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
87 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
89 #define SMALL_TOOLBAR_SIZE 36
91 /* If an video input error occurs, the error message will start with "v4l" */
92 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
94 /* The time interval in milliseconds between 2 outgoing rings */
95 #define MS_BETWEEN_RING 500
97 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
100 PROP_CALL_HANDLER = 1,
112 CAMERA_STATE_OFF = 0,
118 PREVIEW_POS_TOP_LEFT,
119 PREVIEW_POS_TOP_RIGHT,
120 PREVIEW_POS_BOTTOM_LEFT,
121 PREVIEW_POS_BOTTOM_RIGHT,
124 struct _EmpathyCallWindowPriv
126 gboolean dispose_has_run;
127 EmpathyCallHandler *handler;
129 EmpathyContact *contact;
131 EmpathyCameraMonitor *camera_monitor;
136 GtkUIManager *ui_manager;
137 GtkWidget *errors_vbox;
138 /* widget displays the video received from the remote user. This widget is
139 * alive only during call. */
140 ClutterActor *video_output;
141 ClutterActor *video_preview;
142 ClutterActor *preview_hidden_button;
143 ClutterActor *preview_rectangle1;
144 ClutterActor *preview_rectangle2;
145 ClutterActor *preview_rectangle3;
146 ClutterActor *preview_rectangle4;
147 ClutterActor *preview_rectangle_box1;
148 ClutterActor *preview_rectangle_box2;
149 ClutterActor *preview_rectangle_box3;
150 ClutterActor *preview_rectangle_box4;
151 GtkWidget *video_container;
152 GtkWidget *remote_user_avatar_widget;
153 GtkWidget *remote_user_avatar_toolbar;
154 GtkWidget *remote_user_name_toolbar;
155 GtkWidget *status_label;
156 GtkWidget *hangup_button;
157 GtkWidget *audio_call_button;
158 GtkWidget *video_call_button;
159 GtkWidget *mic_button;
160 GtkWidget *camera_button;
161 GtkWidget *dialpad_button;
163 GtkWidget *bottom_toolbar;
164 ClutterActor *floating_toolbar;
166 GtkAction *menu_fullscreen;
167 GtkAction *menu_swap_camera;
169 ClutterState *transitions;
171 /* The box that contains self and remote avatar and video
172 input/output. When we redial, we destroy and re-create the box */
173 ClutterActor *video_box;
174 ClutterLayoutManager *video_layout;
176 /* Coordinates of the preview drag event's start. */
177 PreviewPosition preview_pos;
179 /* We keep a reference on the hbox which contains the main content so we can
180 easilly repack everything when toggling fullscreen */
181 GtkWidget *content_hbox;
183 gulong video_output_motion_handler_id;
184 guint bus_message_source_id;
188 GtkWidget *dtmf_panel;
191 GtkWidget *details_vbox;
192 GtkWidget *vcodec_encoding_label;
193 GtkWidget *acodec_encoding_label;
194 GtkWidget *vcodec_decoding_label;
195 GtkWidget *acodec_decoding_label;
197 GtkWidget *audio_remote_candidate_label;
198 GtkWidget *audio_local_candidate_label;
199 GtkWidget *video_remote_candidate_label;
200 GtkWidget *video_local_candidate_label;
201 GtkWidget *video_remote_candidate_info_img;
202 GtkWidget *video_local_candidate_info_img;
203 GtkWidget *audio_remote_candidate_info_img;
204 GtkWidget *audio_local_candidate_info_img;
206 GstElement *video_input;
207 GstElement *video_preview_sink;
208 GstElement *video_output_sink;
209 GstElement *audio_input;
210 GstElement *audio_output;
211 GstElement *pipeline;
212 GstElement *video_tee;
222 gboolean call_started;
223 gboolean sending_video;
224 CameraState camera_state;
226 EmpathyCallWindowFullscreen *fullscreen;
227 gboolean is_fullscreen;
232 guint inactivity_src;
234 /* Those fields represent the state of the window before it actually was in
236 gboolean dialpad_was_visible_before_fs;
237 gint original_width_before_fs;
238 gint original_height_before_fs;
240 gint x, y, w, h, dialpad_width;
243 /* TRUE if the call should be started when the pipeline is playing */
244 gboolean start_call_when_playing;
245 /* TRUE if we requested to set the pipeline in the playing state */
246 gboolean pipeline_playing;
248 EmpathySoundManager *sound_mgr;
251 EmpathyMicMenu *mic_menu;
252 EmpathyCameraMenu *camera_menu;
255 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
257 static void empathy_call_window_realized_cb (GtkWidget *widget,
258 EmpathyCallWindow *window);
260 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
261 GdkEvent *event, EmpathyCallWindow *window);
263 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
264 GdkEventWindowState *event, EmpathyCallWindow *window);
266 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
269 static void empathy_call_window_mic_toggled_cb (
270 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
272 static void empathy_call_window_hangup_cb (gpointer object,
273 EmpathyCallWindow *window);
275 static void empathy_call_window_fullscreen_cb (gpointer object,
276 EmpathyCallWindow *window);
278 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
280 static gboolean empathy_call_window_video_button_press_cb (
281 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
283 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
284 GdkEventKey *event, EmpathyCallWindow *window);
286 static gboolean empathy_call_window_video_output_motion_notify (
287 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
289 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
292 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
293 EmpathyCallWindow *window);
295 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
297 static void empathy_call_window_status_message (EmpathyCallWindow *window,
300 static gboolean empathy_call_window_bus_message (GstBus *bus,
301 GstMessage *message, gpointer user_data);
304 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
305 gdouble value, EmpathyCallWindow *window);
308 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
311 gtk_widget_set_visible (self->priv->hangup_button, show);
312 gtk_widget_set_visible (self->priv->audio_call_button, !show);
313 gtk_widget_set_visible (self->priv->video_call_button, !show);
317 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
318 EmpathyCallWindow *self)
320 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
321 empathy_call_window_restart_call (self);
325 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
326 EmpathyCallWindow *self)
328 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
329 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
330 empathy_call_window_restart_call (self);
334 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
336 EmpathyCallWindowPriv *priv = GET_PRIV (window);
337 TpyCallChannel *call;
341 g_object_get (priv->handler, "call-channel", &call, NULL);
343 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
344 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
347 tpy_call_channel_dtmf_start_tone (call, event);
349 g_object_unref (call);
353 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
355 EmpathyCallWindowPriv *priv = GET_PRIV (window);
356 TpyCallChannel *call;
358 g_object_get (priv->handler, "call-channel", &call, NULL);
360 tpy_call_channel_dtmf_stop_tone (call);
362 g_object_unref (call);
366 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
368 EmpathyCallWindowPriv *priv = GET_PRIV (self);
371 volume = g_settings_get_double (priv->settings,
372 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
374 /* Don't store the volume because of muting */
375 if (volume > 0 || gtk_toggle_tool_button_get_active (
376 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
377 priv->volume = volume;
379 /* Ensure that the toggle button is active if the volume is > 0 and inactive
380 * if it's smaller than 0 */
381 if ((volume > 0) != gtk_toggle_tool_button_get_active (
382 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
383 gtk_toggle_tool_button_set_active (
384 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
386 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
391 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
393 EmpathyCallWindow *self)
395 empathy_call_window_mic_volume_changed (self);
399 empathy_call_window_raise_actors (EmpathyCallWindow *self)
401 clutter_actor_raise_top (self->priv->floating_toolbar);
403 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
404 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
405 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
406 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
410 empathy_call_window_show_video_output (EmpathyCallWindow *self,
413 if (self->priv->video_output != NULL)
414 g_object_set (self->priv->video_output, "visible", show, NULL);
416 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
418 empathy_call_window_raise_actors (self);
422 create_video_output_widget (EmpathyCallWindow *self)
424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
426 g_assert (priv->video_output == NULL);
427 g_assert (priv->pipeline != NULL);
429 priv->video_output = clutter_texture_new ();
431 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
434 priv->video_output_sink = clutter_gst_video_sink_new (
435 CLUTTER_TEXTURE (priv->video_output));
437 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
440 gtk_widget_add_events (priv->video_container,
441 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
442 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
443 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
447 create_video_input (EmpathyCallWindow *self)
449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
451 g_assert (priv->video_input == NULL);
452 priv->video_input = empathy_video_src_new ();
453 gst_object_ref (priv->video_input);
454 gst_object_sink (priv->video_input);
458 create_audio_input (EmpathyCallWindow *self)
460 EmpathyCallWindowPriv *priv = GET_PRIV (self);
462 g_assert (priv->audio_input == NULL);
463 priv->audio_input = empathy_audio_src_new ();
464 gst_object_ref (priv->audio_input);
465 gst_object_sink (priv->audio_input);
469 add_video_preview_to_pipeline (EmpathyCallWindow *self)
471 EmpathyCallWindowPriv *priv = GET_PRIV (self);
474 g_assert (priv->video_preview != NULL);
475 g_assert (priv->pipeline != NULL);
476 g_assert (priv->video_input != NULL);
477 g_assert (priv->video_tee != NULL);
479 preview = priv->video_preview_sink;
481 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
483 g_warning ("Could not add video input to pipeline");
487 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
489 g_warning ("Could not add video preview to pipeline");
493 if (!gst_element_link (priv->video_input, priv->video_tee))
495 g_warning ("Could not link video input to video tee");
499 if (!gst_element_link (priv->video_tee, preview))
501 g_warning ("Could not link video tee to video preview");
507 empathy_call_window_disable_camera_cb (GtkAction *action,
508 EmpathyCallWindow *self)
510 clutter_actor_destroy (self->priv->preview_hidden_button);
512 gtk_toggle_tool_button_set_active (
513 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
517 empathy_call_window_minimise_camera_cb (GtkAction *action,
518 EmpathyCallWindow *self)
520 clutter_actor_hide (self->priv->video_preview);
521 clutter_actor_show (self->priv->preview_hidden_button);
525 empathy_call_window_maximise_camera_cb (GtkAction *action,
526 EmpathyCallWindow *self)
528 clutter_actor_show (self->priv->video_preview);
529 clutter_actor_hide (self->priv->preview_hidden_button);
533 empathy_call_window_swap_camera_cb (GtkAction *action,
534 EmpathyCallWindow *self)
536 const GList *cameras, *l;
539 DEBUG ("Swapping the camera");
541 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
542 current_cam = empathy_video_src_dup_device (
543 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
545 for (l = cameras; l != NULL; l = l->next)
547 EmpathyCamera *camera = l->data;
549 if (!tp_strdiff (camera->device, current_cam))
554 next = l->next->data;
556 next = cameras->data;
558 /* EmpathyCameraMenu will update itself and do the actual change
560 g_settings_set_string (self->priv->settings,
561 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
568 g_free (current_cam);
572 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
573 EmpathyCamera *camera,
574 EmpathyCallWindow *self)
576 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
578 gtk_action_set_visible (self->priv->menu_swap_camera,
579 g_list_length ((GList *) cameras) >= 2);
583 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
584 EmpathyCamera *camera,
585 EmpathyCallWindow *self)
587 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
589 gtk_action_set_visible (self->priv->menu_swap_camera,
590 g_list_length ((GList *) cameras) >= 2);
594 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
595 EmpathyCallWindow *self)
599 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
601 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
602 0, gtk_get_current_event_time ());
603 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
607 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
608 EmpathyCallWindow *self)
612 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
613 "/preview-hidden-menu");
614 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
615 0, gtk_get_current_event_time ());
616 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
619 static ClutterActor *
620 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
622 ClutterBinAlignment x,
623 ClutterBinAlignment y)
625 ClutterLayoutManager *layout1, *layout2;
626 ClutterActor *rectangle;
627 ClutterActor *box1, *box2;
629 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
630 CLUTTER_BIN_ALIGNMENT_START);
632 box1 = clutter_box_new (layout1);
636 rectangle = clutter_rectangle_new_with_color (
637 CLUTTER_COLOR_Transparent);
639 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
642 clutter_actor_set_size (box1,
643 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
644 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
645 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
647 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
648 CLUTTER_BIN_ALIGNMENT_CENTER);
650 /* We have a box with the margins and the video in the middle inside
651 * a bigger box with an extra bottom margin so we're not on top of
652 * the floating toolbar. */
653 box2 = clutter_box_new (layout2);
655 clutter_actor_set_size (box2,
656 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
657 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
659 clutter_actor_set_size (rectangle,
660 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGHT + 5);
662 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
663 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
665 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
668 clutter_actor_hide (rectangle);
674 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
676 self->priv->preview_rectangle1 =
677 empathy_call_window_create_preview_rectangle (self,
678 &self->priv->preview_rectangle_box1,
679 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
680 self->priv->preview_rectangle2 =
681 empathy_call_window_create_preview_rectangle (self,
682 &self->priv->preview_rectangle_box2,
683 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
684 self->priv->preview_rectangle3 =
685 empathy_call_window_create_preview_rectangle (self,
686 &self->priv->preview_rectangle_box3,
687 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
688 self->priv->preview_rectangle4 =
689 empathy_call_window_create_preview_rectangle (self,
690 &self->priv->preview_rectangle_box4,
691 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
695 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
698 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
700 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
701 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
704 static PreviewPosition
705 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
710 PreviewPosition pos = PREVIEW_POS_NONE;
712 g_return_val_if_fail (clutter_actor_has_allocation (self->priv->video_box),
715 clutter_actor_get_geometry (self->priv->video_box, &box);
717 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
718 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
719 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
720 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
722 pos = PREVIEW_POS_TOP_LEFT;
724 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
725 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
726 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
727 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
729 pos = PREVIEW_POS_TOP_RIGHT;
731 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
732 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
733 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
734 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
736 pos = PREVIEW_POS_BOTTOM_LEFT;
738 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
739 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
740 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
741 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
743 pos = PREVIEW_POS_BOTTOM_RIGHT;
749 static ClutterActor *
750 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
753 ClutterActor *rectangle;
757 case PREVIEW_POS_TOP_LEFT:
758 rectangle = self->priv->preview_rectangle1;
760 case PREVIEW_POS_TOP_RIGHT:
761 rectangle = self->priv->preview_rectangle3;
763 case PREVIEW_POS_BOTTOM_LEFT:
764 rectangle = self->priv->preview_rectangle2;
766 case PREVIEW_POS_BOTTOM_RIGHT:
767 rectangle = self->priv->preview_rectangle4;
777 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
780 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
782 DEBUG ("moving the video preview to %d", pos);
784 self->priv->preview_pos = pos;
788 case PREVIEW_POS_TOP_LEFT:
789 clutter_bin_layout_set_alignment (layout,
790 self->priv->video_preview,
791 CLUTTER_BIN_ALIGNMENT_START,
792 CLUTTER_BIN_ALIGNMENT_START);
794 case PREVIEW_POS_TOP_RIGHT:
795 clutter_bin_layout_set_alignment (layout,
796 self->priv->video_preview,
797 CLUTTER_BIN_ALIGNMENT_END,
798 CLUTTER_BIN_ALIGNMENT_START);
800 case PREVIEW_POS_BOTTOM_LEFT:
801 clutter_bin_layout_set_alignment (layout,
802 self->priv->video_preview,
803 CLUTTER_BIN_ALIGNMENT_START,
804 CLUTTER_BIN_ALIGNMENT_END);
806 case PREVIEW_POS_BOTTOM_RIGHT:
807 clutter_bin_layout_set_alignment (layout,
808 self->priv->video_preview,
809 CLUTTER_BIN_ALIGNMENT_END,
810 CLUTTER_BIN_ALIGNMENT_END);
813 g_warn_if_reached ();
818 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
821 ClutterActor *rectangle;
823 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
825 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
826 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
831 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
832 ClutterActor *rectangle)
834 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
835 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
836 CLUTTER_COLOR_Black);
840 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
842 ClutterActor *rectangle;
844 rectangle = empathy_call_window_get_preview_rectangle (self,
845 self->priv->preview_pos);
847 /* We don't want to darken the rectangle where the preview
850 if (self->priv->preview_rectangle1 != rectangle)
851 empathy_call_window_darken_preview_rectangle (self,
852 self->priv->preview_rectangle1);
854 if (self->priv->preview_rectangle2 != rectangle)
855 empathy_call_window_darken_preview_rectangle (self,
856 self->priv->preview_rectangle2);
858 if (self->priv->preview_rectangle3 != rectangle)
859 empathy_call_window_darken_preview_rectangle (self,
860 self->priv->preview_rectangle3);
862 if (self->priv->preview_rectangle4 != rectangle)
863 empathy_call_window_darken_preview_rectangle (self,
864 self->priv->preview_rectangle4);
868 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
872 ClutterModifierType modifiers,
873 EmpathyCallWindow *self)
875 ClutterActor *stage = clutter_actor_get_stage (actor);
876 ClutterActor *preview = clutter_clone_new (actor);
878 clutter_container_add_actor (CLUTTER_CONTAINER (stage), preview);
879 clutter_actor_set_position (preview, event_x, event_y);
881 clutter_drag_action_set_drag_handle (action, preview);
883 empathy_call_window_show_preview_rectangles (self, TRUE);
884 empathy_call_window_darken_preview_rectangles (self);
888 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
892 ClutterModifierType modifiers,
893 EmpathyCallWindow *self)
895 ClutterActor *preview = clutter_drag_action_get_drag_handle (action);
898 /* Get the position before destroying the drag actor, otherwise the
899 * preview_box allocation won't be valid and we won't be able to
900 * calculate the position. */
901 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
903 /* Destroy the video preview copy that we were dragging */
904 clutter_actor_destroy (preview);
906 if (pos != PREVIEW_POS_NONE)
907 empathy_call_window_move_video_preview (self, pos);
909 empathy_call_window_show_preview_rectangles (self, FALSE);
913 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
917 EmpathyCallWindow *self)
920 gfloat event_x, event_y;
922 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
924 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
926 if (pos != PREVIEW_POS_NONE)
927 empathy_call_window_highlight_preview_rectangle (self, pos);
929 empathy_call_window_darken_preview_rectangles (self);
933 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
934 ClutterCrossingEvent *event,
935 EmpathyCallWindow *self)
937 ClutterActor *rectangle;
939 rectangle = empathy_call_window_get_preview_rectangle (self,
940 self->priv->preview_pos);
942 empathy_call_window_highlight_preview_rectangle (self,
943 self->priv->preview_pos);
945 clutter_actor_show (rectangle);
951 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
952 ClutterCrossingEvent *event,
953 EmpathyCallWindow *self)
955 ClutterActor *rectangle;
957 rectangle = empathy_call_window_get_preview_rectangle (self,
958 self->priv->preview_pos);
960 empathy_call_window_darken_preview_rectangle (self, rectangle);
962 clutter_actor_hide (rectangle);
968 create_video_preview (EmpathyCallWindow *self)
970 EmpathyCallWindowPriv *priv = GET_PRIV (self);
971 ClutterLayoutManager *layout, *layout_center, *layout_end;
972 ClutterActor *preview;
975 ClutterAction *action;
978 g_assert (priv->video_preview == NULL);
980 preview = clutter_texture_new ();
981 clutter_actor_set_size (preview,
982 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
983 priv->video_preview_sink = clutter_gst_video_sink_new (
984 CLUTTER_TEXTURE (preview));
986 /* Flip the video preview */
987 clutter_actor_set_rotation (preview,
990 SELF_VIDEO_SECTION_WIDTH * 0.5,
994 /* Add a little offset to the video preview */
995 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
996 CLUTTER_BIN_ALIGNMENT_START);
997 priv->video_preview = clutter_box_new (layout);
998 clutter_actor_set_size (priv->video_preview,
999 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1000 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1001 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1003 /* We have a box with the margins and the video in the middle inside
1004 * a bigger box with an extra bottom margin so we're not on top of
1005 * the floating toolbar. */
1006 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1007 CLUTTER_BIN_ALIGNMENT_CENTER);
1008 box = clutter_box_new (layout_center);
1009 clutter_actor_set_size (box,
1010 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1011 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1013 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1014 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1016 g_object_set (priv->video_preview_sink,
1021 /* Translators: this is an "Info" label. It should be as short
1023 button = gtk_button_new_with_label (_("i"));
1024 b = gtk_clutter_actor_new_with_contents (button);
1026 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1027 CLUTTER_BIN_ALIGNMENT_END);
1028 box = clutter_box_new (layout_end);
1029 clutter_actor_set_size (box,
1030 SELF_VIDEO_SECTION_WIDTH,
1031 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1033 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1034 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1036 g_signal_connect (button, "clicked",
1037 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1040 /* Translators: this is an "Info" label. It should be as short
1042 button = gtk_button_new_with_label (_("i"));
1043 priv->preview_hidden_button =
1044 gtk_clutter_actor_new_with_contents (button);
1046 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1047 priv->preview_hidden_button,
1048 CLUTTER_BIN_ALIGNMENT_START,
1049 CLUTTER_BIN_ALIGNMENT_END);
1051 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1053 clutter_actor_hide (priv->preview_hidden_button);
1055 g_signal_connect (button, "clicked",
1056 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1059 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1060 priv->video_preview,
1061 CLUTTER_BIN_ALIGNMENT_START,
1062 CLUTTER_BIN_ALIGNMENT_END);
1064 action = clutter_drag_action_new ();
1065 g_signal_connect (action, "drag-begin",
1066 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1067 g_signal_connect (action, "drag-end",
1068 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1069 g_signal_connect (action, "drag-motion",
1070 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1072 g_signal_connect (preview, "enter-event",
1073 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1074 g_signal_connect (preview, "leave-event",
1075 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1077 clutter_actor_add_action (preview, action);
1078 clutter_actor_set_reactive (preview, TRUE);
1082 play_camera (EmpathyCallWindow *window,
1085 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1086 GstElement *preview;
1089 if (priv->video_preview == NULL)
1091 create_video_preview (window);
1092 add_video_preview_to_pipeline (window);
1096 state = GST_STATE_PLAYING;
1098 state = GST_STATE_NULL;
1100 preview = priv->video_preview_sink;
1102 gst_element_set_state (preview, state);
1103 gst_element_set_state (priv->video_input, state);
1104 gst_element_set_state (priv->video_tee, state);
1108 display_video_preview (EmpathyCallWindow *self,
1111 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1115 /* Display the video preview */
1116 DEBUG ("Show video preview");
1118 play_camera (self, TRUE);
1119 clutter_actor_show (priv->video_preview);
1120 clutter_actor_raise_top (priv->floating_toolbar);
1124 /* Hide the video preview */
1125 DEBUG ("Hide video preview");
1127 if (priv->video_preview != NULL)
1129 clutter_actor_hide (priv->video_preview);
1130 play_camera (self, FALSE);
1136 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1138 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1140 empathy_call_window_status_message (window, _("Connecting…"));
1141 priv->call_state = CONNECTING;
1144 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1145 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1149 disable_camera (EmpathyCallWindow *self)
1151 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1153 if (priv->camera_state == CAMERA_STATE_OFF)
1156 DEBUG ("Disable camera");
1158 display_video_preview (self, FALSE);
1160 if (priv->camera_state == CAMERA_STATE_ON)
1161 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1163 priv->camera_state = CAMERA_STATE_OFF;
1167 enable_camera (EmpathyCallWindow *self)
1169 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1171 if (priv->camera_state == CAMERA_STATE_ON)
1174 if (priv->video_input == NULL)
1176 DEBUG ("Can't enable camera, no input");
1180 DEBUG ("Enable camera");
1182 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1184 priv->camera_state = CAMERA_STATE_ON;
1188 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1189 EmpathyCallWindow *self)
1191 if (gtk_toggle_tool_button_get_active (toggle))
1192 enable_camera (self);
1194 disable_camera (self);
1198 create_pipeline (EmpathyCallWindow *self)
1200 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1203 g_assert (priv->pipeline == NULL);
1205 priv->pipeline = gst_pipeline_new (NULL);
1206 priv->pipeline_playing = FALSE;
1208 priv->video_tee = gst_element_factory_make ("tee", NULL);
1209 gst_object_ref (priv->video_tee);
1210 gst_object_sink (priv->video_tee);
1212 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1214 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1215 priv->bus_message_source_id = gst_bus_add_watch (bus,
1216 empathy_call_window_bus_message, self);
1218 g_object_unref (bus);
1222 empathy_call_window_settings_cb (GtkAction *action,
1223 EmpathyCallWindow *self)
1225 gchar *args = g_strdup_printf ("-p %s",
1226 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1228 empathy_launch_program (BIN_DIR, "empathy", args);
1234 empathy_call_window_contents_cb (GtkAction *action,
1235 EmpathyCallWindow *self)
1237 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1241 empathy_call_window_debug_cb (GtkAction *action,
1242 EmpathyCallWindow *self)
1244 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1248 empathy_call_window_about_cb (GtkAction *action,
1249 EmpathyCallWindow *self)
1251 empathy_about_dialog_new (GTK_WINDOW (self));
1255 empathy_call_window_toolbar_timeout (gpointer data)
1257 EmpathyCallWindow *self = data;
1259 clutter_state_set_state (self->priv->transitions, "fade-out");
1265 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1267 EmpathyCallWindow *self)
1269 clutter_state_set_state (self->priv->transitions, "fade-in");
1271 if (self->priv->inactivity_src > 0)
1272 g_source_remove (self->priv->inactivity_src);
1274 self->priv->inactivity_src = g_timeout_add_seconds (3,
1275 empathy_call_window_toolbar_timeout, self);
1281 empathy_call_window_configure_event_cb (GtkWidget *widget,
1283 EmpathyCallWindow *self)
1285 GdkWindow *gdk_window;
1286 GdkWindowState window_state;
1288 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1289 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1291 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1292 &self->priv->dialpad_width, NULL);
1294 gdk_window = gtk_widget_get_window (widget);
1295 window_state = gdk_window_get_state (gdk_window);
1296 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1302 empathy_call_window_destroyed_cb (GtkWidget *object,
1303 EmpathyCallWindow *self)
1305 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1307 /* Save the geometry as if the dialpad was hidden. */
1308 empathy_geometry_save_values (GTK_WINDOW (self),
1309 self->priv->x, self->priv->y,
1310 self->priv->w - self->priv->dialpad_width, self->priv->h,
1311 self->priv->maximized);
1316 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1318 ClutterBindConstraint *constraint)
1320 ClutterActorBox allocation;
1322 clutter_actor_get_allocation_box (stage, &allocation);
1324 clutter_bind_constraint_set_offset (constraint,
1325 allocation.y2 - allocation.y1 -
1326 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1330 empathy_call_window_init (EmpathyCallWindow *self)
1332 EmpathyCallWindowPriv *priv;
1334 GtkWidget *top_vbox;
1336 ClutterConstraint *constraint;
1337 ClutterActor *remote_avatar;
1338 GtkStyleContext *context;
1342 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1343 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1345 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1346 gui = empathy_builder_get_file (filename,
1347 "call_window_vbox", &top_vbox,
1348 "errors_vbox", &priv->errors_vbox,
1349 "pane", &priv->pane,
1350 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1351 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1352 "status_label", &priv->status_label,
1353 "audiocall", &priv->audio_call_button,
1354 "videocall", &priv->video_call_button,
1355 "microphone", &priv->mic_button,
1356 "camera", &priv->camera_button,
1357 "hangup", &priv->hangup_button,
1358 "dialpad", &priv->dialpad_button,
1359 "toolbar", &priv->toolbar,
1360 "bottom_toolbar", &priv->bottom_toolbar,
1361 "ui_manager", &priv->ui_manager,
1362 "menufullscreen", &priv->menu_fullscreen,
1363 "menupreviewswap", &priv->menu_swap_camera,
1364 "details_vbox", &priv->details_vbox,
1365 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1366 "acodec_encoding_label", &priv->acodec_encoding_label,
1367 "acodec_decoding_label", &priv->acodec_decoding_label,
1368 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1369 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1370 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1371 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1372 "video_local_candidate_label", &priv->video_local_candidate_label,
1373 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1374 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1375 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1376 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1380 empathy_builder_connect (gui, self,
1381 "hangup", "clicked", empathy_call_window_hangup_cb,
1382 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1383 "videocall", "clicked", empathy_call_window_video_call_cb,
1384 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1385 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1386 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1387 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1388 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1389 "menusettings", "activate", empathy_call_window_settings_cb,
1390 "menucontents", "activate", empathy_call_window_contents_cb,
1391 "menudebug", "activate", empathy_call_window_debug_cb,
1392 "menuabout", "activate", empathy_call_window_about_cb,
1393 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1394 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1395 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1396 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1399 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1401 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1403 g_object_bind_property (priv->camera_monitor, "available",
1404 priv->camera_button, "sensitive",
1405 G_BINDING_SYNC_CREATE);
1407 g_signal_connect (priv->camera_monitor, "added",
1408 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1409 g_signal_connect (priv->camera_monitor, "removed",
1410 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1412 priv->lock = g_mutex_new ();
1414 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1416 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1417 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1418 CONTENT_HBOX_BORDER_WIDTH);
1419 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1422 /* avatar/video box */
1423 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1424 CLUTTER_BIN_ALIGNMENT_CENTER);
1426 priv->video_box = clutter_box_new (priv->video_layout);
1428 priv->video_container = gtk_clutter_embed_new ();
1430 /* Set the background color to that of the rest of the window */
1431 context = gtk_widget_get_style_context (priv->content_hbox);
1432 gtk_style_context_get_background_color (context,
1433 GTK_STATE_FLAG_NORMAL, &rgba);
1434 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1435 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1436 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1437 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1438 clutter_stage_set_color (
1439 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1440 GTK_CLUTTER_EMBED (priv->video_container))),
1443 clutter_container_add (
1444 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1445 GTK_CLUTTER_EMBED (priv->video_container))),
1449 constraint = clutter_bind_constraint_new (
1450 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1451 CLUTTER_BIND_SIZE, 0);
1452 clutter_actor_add_constraint (priv->video_box, constraint);
1454 priv->remote_user_avatar_widget = gtk_image_new ();
1455 remote_avatar = gtk_clutter_actor_new_with_contents (
1456 priv->remote_user_avatar_widget);
1458 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1461 empathy_call_window_create_preview_rectangles (self);
1463 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1464 priv->video_container, TRUE, TRUE,
1465 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1467 create_pipeline (self);
1468 create_video_output_widget (self);
1469 create_audio_input (self);
1470 create_video_input (self);
1472 priv->floating_toolbar = empathy_rounded_actor_new ();
1474 gtk_widget_reparent (priv->bottom_toolbar,
1475 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1477 constraint = clutter_bind_constraint_new (
1478 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1481 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1484 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1485 "notify::allocation",
1486 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1489 clutter_actor_set_size (priv->floating_toolbar,
1490 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1491 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1493 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1494 priv->floating_toolbar,
1495 CLUTTER_BIN_ALIGNMENT_CENTER,
1496 CLUTTER_BIN_ALIGNMENT_END);
1498 clutter_actor_raise_top (priv->floating_toolbar);
1500 /* Transitions for the floating toolbar */
1501 priv->transitions = clutter_state_new ();
1503 /* all transitions last for 2s */
1504 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1506 /* transition from any state to "fade-out" state */
1507 clutter_state_set (priv->transitions, NULL, "fade-out",
1508 priv->floating_toolbar,
1509 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1512 /* transition from any state to "fade-in" state */
1513 clutter_state_set (priv->transitions, NULL, "fade-in",
1514 priv->floating_toolbar,
1515 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1518 /* put the actor into the "fade-in" state with no animation */
1519 clutter_state_warp_to_state (priv->transitions, "fade-in");
1521 /* The call will be started as soon the pipeline is playing */
1522 priv->start_call_when_playing = TRUE;
1524 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1525 G_CALLBACK (dtmf_button_pressed_cb),
1526 G_CALLBACK (dtmf_button_released_cb));
1528 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1531 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1534 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1536 gtk_widget_show_all (top_vbox);
1538 gtk_widget_hide (priv->dtmf_panel);
1539 gtk_widget_hide (priv->details_vbox);
1541 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1543 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1544 priv->video_container);
1546 /* We hide the bottom toolbar after 3s of inactivity and show it
1547 * again on mouse movement */
1548 priv->inactivity_src = g_timeout_add_seconds (3,
1549 empathy_call_window_toolbar_timeout, self);
1551 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1552 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1554 g_signal_connect (G_OBJECT (self), "realize",
1555 G_CALLBACK (empathy_call_window_realized_cb), self);
1557 g_signal_connect (G_OBJECT (self), "delete-event",
1558 G_CALLBACK (empathy_call_window_delete_cb), self);
1560 g_signal_connect (G_OBJECT (self), "window-state-event",
1561 G_CALLBACK (empathy_call_window_state_event_cb), self);
1563 g_signal_connect (G_OBJECT (self), "key-press-event",
1564 G_CALLBACK (empathy_call_window_key_press_cb), self);
1566 g_signal_connect (self, "motion-notify-event",
1567 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1569 priv->timer = g_timer_new ();
1571 g_object_ref (priv->ui_manager);
1572 g_object_unref (gui);
1574 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1575 priv->mic_menu = empathy_mic_menu_new (self);
1576 priv->camera_menu = empathy_camera_menu_new (self);
1578 empathy_call_window_show_hangup_button (self, TRUE);
1580 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1582 /* Retrieve initial volume */
1583 priv->volume = g_settings_get_double (priv->settings,
1584 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1586 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1587 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1589 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1590 /* These signals are used to track the window position and save it
1591 * when the window is destroyed. We need to do this as we don't want
1592 * the window geometry to be saved with the dialpad taken into account. */
1593 g_signal_connect (self, "destroy",
1594 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1595 g_signal_connect (self, "configure-event",
1596 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1597 g_signal_connect (self, "window-state-event",
1598 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1600 /* Don't display labels in both toolbars */
1601 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1604 /* Instead of specifying a width and a height, we specify only one size. That's
1605 because we want a square avatar icon. */
1607 init_contact_avatar_with_size (EmpathyContact *contact,
1608 GtkWidget *image_widget,
1611 GdkPixbuf *pixbuf_avatar = NULL;
1613 if (contact != NULL)
1615 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1619 if (pixbuf_avatar == NULL)
1621 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1622 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1625 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1627 if (pixbuf_avatar != NULL)
1628 g_object_unref (pixbuf_avatar);
1632 set_window_title (EmpathyCallWindow *self)
1634 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1637 if (priv->contact != NULL)
1639 /* translators: Call is a noun and %s is the contact name. This string
1640 * is used in the window title */
1641 tmp = g_strdup_printf (_("Call with %s"),
1642 empathy_contact_get_alias (priv->contact));
1643 gtk_window_set_title (GTK_WINDOW (self), tmp);
1648 g_warning ("Unknown remote contact!");
1653 set_remote_user_name (EmpathyCallWindow *self,
1654 EmpathyContact *contact)
1656 const gchar *alias = empathy_contact_get_alias (contact);
1657 const gchar *status = empathy_contact_get_status (contact);
1660 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1661 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1667 contact_name_changed_cb (EmpathyContact *contact,
1669 EmpathyCallWindow *self)
1671 set_window_title (self);
1672 set_remote_user_name (self, contact);
1676 contact_presence_changed_cb (EmpathyContact *contact,
1678 EmpathyCallWindow *self)
1680 set_remote_user_name (self, contact);
1684 contact_avatar_changed_cb (EmpathyContact *contact,
1686 EmpathyCallWindow *self)
1689 GtkAllocation allocation;
1690 GtkWidget *avatar_widget;
1692 avatar_widget = self->priv->remote_user_avatar_widget;
1694 gtk_widget_get_allocation (avatar_widget, &allocation);
1695 size = allocation.height;
1699 /* the widget is not allocated yet, set a default size */
1700 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1701 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1704 init_contact_avatar_with_size (contact, avatar_widget, size);
1706 avatar_widget = self->priv->remote_user_avatar_toolbar;
1708 gtk_widget_get_allocation (avatar_widget, &allocation);
1709 size = allocation.height;
1713 /* the widget is not allocated yet, set a default size */
1714 size = SMALL_TOOLBAR_SIZE;
1717 init_contact_avatar_with_size (contact, avatar_widget, size);
1721 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1722 EmpathyCallHandler *handler)
1724 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1726 tp_g_signal_connect_object (priv->contact, "notify::name",
1727 G_CALLBACK (contact_name_changed_cb), self, 0);
1728 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1729 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1730 tp_g_signal_connect_object (priv->contact, "notify::presence",
1731 G_CALLBACK (contact_presence_changed_cb), self, 0);
1733 set_window_title (self);
1734 set_remote_user_name (self, priv->contact);
1736 init_contact_avatar_with_size (priv->contact,
1737 priv->remote_user_avatar_widget,
1738 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1739 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1741 init_contact_avatar_with_size (priv->contact,
1742 priv->remote_user_avatar_toolbar,
1743 SMALL_TOOLBAR_SIZE);
1745 /* The remote avatar is shown by default and will be hidden when we receive
1746 video from the remote side. */
1747 clutter_actor_hide (priv->video_output);
1748 gtk_widget_show (priv->remote_user_avatar_widget);
1752 update_send_codec (EmpathyCallWindow *self,
1755 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1762 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1763 widget = priv->acodec_encoding_label;
1767 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1768 widget = priv->vcodec_encoding_label;
1774 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1775 gtk_label_set_text (GTK_LABEL (widget), tmp);
1780 send_audio_codec_notify_cb (GObject *object,
1784 EmpathyCallWindow *self = user_data;
1786 update_send_codec (self, TRUE);
1790 send_video_codec_notify_cb (GObject *object,
1794 EmpathyCallWindow *self = user_data;
1796 update_send_codec (self, FALSE);
1800 update_recv_codec (EmpathyCallWindow *self,
1803 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1806 GString *str = NULL;
1810 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1811 widget = priv->acodec_decoding_label;
1815 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1816 widget = priv->vcodec_decoding_label;
1822 for (l = codecs; l != NULL; l = g_list_next (l))
1824 FsCodec *codec = l->data;
1827 str = g_string_new (NULL);
1829 g_string_append (str, ", ");
1831 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1835 gtk_label_set_text (GTK_LABEL (widget), str->str);
1836 g_string_free (str, TRUE);
1840 recv_audio_codecs_notify_cb (GObject *object,
1844 EmpathyCallWindow *self = user_data;
1846 update_recv_codec (self, TRUE);
1850 recv_video_codecs_notify_cb (GObject *object,
1854 EmpathyCallWindow *self = user_data;
1856 update_recv_codec (self, FALSE);
1859 static const gchar *
1860 candidate_type_to_str (FsCandidate *candidate)
1862 switch (candidate->type)
1864 case FS_CANDIDATE_TYPE_HOST:
1866 case FS_CANDIDATE_TYPE_SRFLX:
1867 return "server reflexive";
1868 case FS_CANDIDATE_TYPE_PRFLX:
1869 return "peer reflexive";
1870 case FS_CANDIDATE_TYPE_RELAY:
1872 case FS_CANDIDATE_TYPE_MULTICAST:
1879 static const gchar *
1880 candidate_type_to_desc (FsCandidate *candidate)
1882 switch (candidate->type)
1884 case FS_CANDIDATE_TYPE_HOST:
1885 return _("The IP address as seen by the machine");
1886 case FS_CANDIDATE_TYPE_SRFLX:
1887 return _("The IP address as seen by a server on the Internet");
1888 case FS_CANDIDATE_TYPE_PRFLX:
1889 return _("The IP address of the peer as seen by the other side");
1890 case FS_CANDIDATE_TYPE_RELAY:
1891 return _("The IP address of a relay server");
1892 case FS_CANDIDATE_TYPE_MULTICAST:
1893 return _("The IP address of the multicast group");
1900 update_candidat_widget (EmpathyCallWindow *self,
1903 FsCandidate *candidate)
1907 g_assert (candidate != NULL);
1908 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1909 candidate->port, candidate_type_to_str (candidate));
1911 gtk_label_set_text (GTK_LABEL (label), str);
1912 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1918 candidates_changed_cb (GObject *object,
1920 EmpathyCallWindow *self)
1922 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1923 FsCandidate *candidate = NULL;
1925 if (type == FS_MEDIA_TYPE_VIDEO)
1927 /* Update remote candidate */
1928 candidate = empathy_call_handler_get_video_remote_candidate (
1931 update_candidat_widget (self, priv->video_remote_candidate_label,
1932 priv->video_remote_candidate_info_img, candidate);
1934 /* Update local candidate */
1935 candidate = empathy_call_handler_get_video_local_candidate (
1938 update_candidat_widget (self, priv->video_local_candidate_label,
1939 priv->video_local_candidate_info_img, candidate);
1943 /* Update remote candidate */
1944 candidate = empathy_call_handler_get_audio_remote_candidate (
1947 update_candidat_widget (self, priv->audio_remote_candidate_label,
1948 priv->audio_remote_candidate_info_img, candidate);
1950 /* Update local candidate */
1951 candidate = empathy_call_handler_get_audio_local_candidate (
1954 update_candidat_widget (self, priv->audio_local_candidate_label,
1955 priv->audio_local_candidate_info_img, candidate);
1960 empathy_call_window_constructed (GObject *object)
1962 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1963 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1964 TpyCallChannel *call;
1966 g_assert (priv->handler != NULL);
1968 g_object_get (priv->handler, "call-channel", &call, NULL);
1969 priv->outgoing = (call == NULL);
1971 g_object_unref (call);
1973 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1974 g_assert (priv->contact != NULL);
1976 empathy_call_window_setup_avatars (self, priv->handler);
1977 empathy_call_window_set_state_connecting (self);
1979 if (!empathy_call_handler_has_initial_video (priv->handler))
1981 gtk_toggle_tool_button_set_active (
1982 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1984 /* If call has InitialVideo, the preview will be started once the call has
1985 * been started (start_call()). */
1987 update_send_codec (self, TRUE);
1988 update_send_codec (self, FALSE);
1989 update_recv_codec (self, TRUE);
1990 update_recv_codec (self, FALSE);
1992 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1993 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1994 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1995 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1996 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1997 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1998 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1999 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2001 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2002 G_CALLBACK (candidates_changed_cb), self, 0);
2005 static void empathy_call_window_dispose (GObject *object);
2006 static void empathy_call_window_finalize (GObject *object);
2009 empathy_call_window_set_property (GObject *object,
2010 guint property_id, const GValue *value, GParamSpec *pspec)
2012 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2014 switch (property_id)
2016 case PROP_CALL_HANDLER:
2017 priv->handler = g_value_dup_object (value);
2020 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2025 empathy_call_window_get_property (GObject *object,
2026 guint property_id, GValue *value, GParamSpec *pspec)
2028 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2030 switch (property_id)
2032 case PROP_CALL_HANDLER:
2033 g_value_set_object (value, priv->handler);
2036 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2041 empathy_call_window_class_init (
2042 EmpathyCallWindowClass *empathy_call_window_class)
2044 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2045 GParamSpec *param_spec;
2047 g_type_class_add_private (empathy_call_window_class,
2048 sizeof (EmpathyCallWindowPriv));
2050 object_class->constructed = empathy_call_window_constructed;
2051 object_class->set_property = empathy_call_window_set_property;
2052 object_class->get_property = empathy_call_window_get_property;
2054 object_class->dispose = empathy_call_window_dispose;
2055 object_class->finalize = empathy_call_window_finalize;
2057 param_spec = g_param_spec_object ("handler",
2058 "handler", "The call handler",
2059 EMPATHY_TYPE_CALL_HANDLER,
2060 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2061 g_object_class_install_property (object_class,
2062 PROP_CALL_HANDLER, param_spec);
2066 empathy_call_window_dispose (GObject *object)
2068 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2069 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2071 if (priv->dispose_has_run)
2074 priv->dispose_has_run = TRUE;
2076 if (priv->handler != NULL)
2078 empathy_call_handler_stop_call (priv->handler);
2079 tp_clear_object (&priv->handler);
2082 if (priv->bus_message_source_id != 0)
2084 g_source_remove (priv->bus_message_source_id);
2085 priv->bus_message_source_id = 0;
2088 if (priv->got_video_src > 0)
2090 g_source_remove (priv->got_video_src);
2091 priv->got_video_src = 0;
2094 if (priv->inactivity_src > 0)
2096 g_source_remove (priv->inactivity_src);
2097 priv->inactivity_src = 0;
2100 tp_clear_object (&priv->pipeline);
2101 tp_clear_object (&priv->video_input);
2102 tp_clear_object (&priv->audio_input);
2103 tp_clear_object (&priv->video_tee);
2104 tp_clear_object (&priv->ui_manager);
2105 tp_clear_object (&priv->fullscreen);
2106 tp_clear_object (&priv->camera_monitor);
2107 tp_clear_object (&priv->settings);
2108 tp_clear_object (&priv->sound_mgr);
2109 tp_clear_object (&priv->mic_menu);
2110 tp_clear_object (&priv->camera_menu);
2112 g_list_free_full (priv->notifiers, g_object_unref);
2114 if (priv->timer_id != 0)
2115 g_source_remove (priv->timer_id);
2118 if (priv->contact != NULL)
2120 g_signal_handlers_disconnect_by_func (priv->contact,
2121 contact_name_changed_cb, self);
2122 priv->contact = NULL;
2125 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2129 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2131 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2133 if (priv->video_output_motion_handler_id != 0)
2135 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2136 priv->video_output_motion_handler_id);
2137 priv->video_output_motion_handler_id = 0;
2142 empathy_call_window_finalize (GObject *object)
2144 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2145 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2147 disconnect_video_output_motion_handler (self);
2149 /* free any data held directly by the object here */
2150 g_mutex_free (priv->lock);
2152 g_timer_destroy (priv->timer);
2154 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2159 empathy_call_window_new (EmpathyCallHandler *handler)
2161 return EMPATHY_CALL_WINDOW (
2162 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2166 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2167 GstElement *conference, gpointer user_data)
2169 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2170 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2171 FsElementAddedNotifier *notifier;
2174 DEBUG ("Conference added");
2176 /* Add notifier to set the various element properties as needed */
2177 notifier = fs_element_added_notifier_new ();
2178 keyfile = fs_utils_get_default_element_properties (conference);
2180 if (keyfile != NULL)
2181 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2183 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2185 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2187 gst_bin_add (GST_BIN (priv->pipeline), conference);
2188 gst_element_set_state (conference, GST_STATE_PLAYING);
2192 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2193 GstElement *conference, gpointer user_data)
2195 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2196 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2198 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2199 gst_element_set_state (conference, GST_STATE_NULL);
2203 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2205 GstStateChangeReturn state_change_return;
2206 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2208 if (priv->pipeline == NULL)
2211 if (priv->bus_message_source_id != 0)
2213 g_source_remove (priv->bus_message_source_id);
2214 priv->bus_message_source_id = 0;
2217 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2219 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2220 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2222 if (priv->pipeline != NULL)
2223 g_object_unref (priv->pipeline);
2224 priv->pipeline = NULL;
2226 if (priv->audio_output != NULL)
2227 g_object_unref (priv->audio_output);
2228 priv->audio_output = NULL;
2230 if (priv->video_tee != NULL)
2231 g_object_unref (priv->video_tee);
2232 priv->video_tee = NULL;
2234 if (priv->video_preview != NULL)
2235 clutter_actor_destroy (priv->video_preview);
2236 priv->video_preview = NULL;
2238 priv->funnel = NULL;
2240 create_pipeline (self);
2241 /* Call will be started when user will hit the 'redial' button */
2242 priv->start_call_when_playing = FALSE;
2243 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2249 g_message ("Error: could not destroy pipeline. Closing call window");
2250 gtk_widget_destroy (GTK_WIDGET (self));
2257 reset_details_pane (EmpathyCallWindow *self)
2259 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2261 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2262 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2263 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2264 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2268 empathy_call_window_disconnected (EmpathyCallWindow *self,
2271 gboolean could_disconnect = FALSE;
2272 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2273 gboolean could_reset_pipeline;
2275 /* Leave full screen mode if needed */
2276 gtk_window_unfullscreen (GTK_WINDOW (self));
2278 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2279 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2281 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2283 if (priv->call_state == CONNECTING)
2284 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2286 if (priv->call_state != REDIALING)
2287 priv->call_state = DISCONNECTED;
2289 if (could_reset_pipeline)
2291 g_mutex_lock (priv->lock);
2293 g_timer_stop (priv->timer);
2295 if (priv->timer_id != 0)
2296 g_source_remove (priv->timer_id);
2299 g_mutex_unlock (priv->lock);
2302 /* We are about to destroy the window, no need to update it or create
2303 * a video preview */
2306 empathy_call_window_status_message (self, _("Disconnected"));
2308 empathy_call_window_show_hangup_button (self, FALSE);
2310 /* Unsensitive the camera and mic button */
2311 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2312 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2314 /* Be sure that the mic button is enabled */
2315 gtk_toggle_tool_button_set_active (
2316 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2318 if (priv->camera_state == CAMERA_STATE_ON)
2320 /* Restart the preview with the new pipeline. */
2321 display_video_preview (self, TRUE);
2324 /* destroy the video output; it will be recreated when we'll redial */
2325 disconnect_video_output_motion_handler (self);
2326 if (priv->video_output != NULL)
2327 clutter_actor_destroy (priv->video_output);
2328 priv->video_output = NULL;
2329 if (priv->got_video_src > 0)
2331 g_source_remove (priv->got_video_src);
2332 priv->got_video_src = 0;
2335 gtk_widget_show (priv->remote_user_avatar_widget);
2337 reset_details_pane (self);
2339 priv->sending_video = FALSE;
2340 priv->call_started = FALSE;
2342 could_disconnect = TRUE;
2344 /* TODO: display the self avatar of the preview (depends if the "Always
2345 * Show Video Preview" is enabled or not) */
2348 return could_disconnect;
2353 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2356 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2357 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2359 if (empathy_call_window_disconnected (self, TRUE) &&
2360 priv->call_state == REDIALING)
2361 empathy_call_window_restart_call (self);
2365 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2367 FsMediaType media_type,
2368 EmpathyCallWindow *self)
2370 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2372 DEBUG ("removing content");
2375 * This assumes that there is only one video stream per channel...
2378 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2380 if (priv->funnel != NULL)
2384 output = priv->video_output_sink;
2386 gst_element_set_state (output, GST_STATE_NULL);
2387 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2389 gst_bin_remove (GST_BIN (priv->pipeline), output);
2390 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2391 priv->funnel = NULL;
2395 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2397 if (priv->audio_output != NULL)
2399 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2401 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2402 priv->audio_output = NULL;
2410 /* Called with global lock held */
2412 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2418 if (priv->funnel == NULL)
2420 output = priv->video_output_sink;
2422 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2426 g_warning ("Could not create fsfunnel");
2430 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2432 gst_object_unref (priv->funnel);
2433 priv->funnel = NULL;
2434 g_warning ("Could not add funnel to pipeline");
2438 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2440 g_warning ("Could not add the video output widget to the pipeline");
2444 if (!gst_element_link (priv->funnel, output))
2446 g_warning ("Could not link output sink to funnel");
2447 goto error_output_added;
2450 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2452 g_warning ("Could not start video sink");
2453 goto error_output_added;
2456 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2458 g_warning ("Could not start funnel");
2459 goto error_output_added;
2463 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2466 g_warning ("Could not get request pad from funnel");
2473 gst_element_set_locked_state (priv->funnel, TRUE);
2474 gst_element_set_locked_state (output, TRUE);
2476 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2477 gst_element_set_state (output, GST_STATE_NULL);
2479 gst_bin_remove (GST_BIN (priv->pipeline), output);
2480 gst_element_set_locked_state (output, FALSE);
2484 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2485 priv->funnel = NULL;
2490 /* Called with global lock held */
2492 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2496 GstPadTemplate *template;
2498 if (priv->audio_output == NULL)
2500 priv->audio_output = empathy_audio_sink_new ();
2501 g_object_ref_sink (priv->audio_output);
2503 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2505 g_warning ("Could not add audio sink to pipeline");
2506 g_object_unref (priv->audio_output);
2507 goto error_add_output;
2510 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2512 g_warning ("Could not start audio sink");
2517 template = gst_element_class_get_pad_template (
2518 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2520 pad = gst_element_request_pad (priv->audio_output,
2521 template, NULL, NULL);
2525 g_warning ("Could not get sink pad from sink");
2532 gst_element_set_locked_state (priv->audio_output, TRUE);
2533 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2534 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2535 priv->audio_output = NULL;
2543 empathy_call_window_update_timer (gpointer user_data)
2545 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2546 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2547 const gchar *status;
2551 time_ = g_timer_elapsed (priv->timer, NULL);
2553 if (priv->call_state == HELD)
2554 status = _("On hold");
2555 else if (!gtk_toggle_tool_button_get_active (
2556 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2559 status = _("Duration");
2561 /* Translators: 'status - minutes:seconds' the caller has been connected */
2562 str = g_strdup_printf (_("%s — %d:%02dm"),
2564 (int) time_ / 60, (int) time_ % 60);
2565 empathy_call_window_status_message (self, str);
2573 display_error (EmpathyCallWindow *self,
2574 TpyCallChannel *call,
2578 const gchar *details)
2580 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2581 GtkWidget *info_bar;
2582 GtkWidget *content_area;
2589 /* Create info bar */
2590 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2593 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2595 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2597 /* hbox containing the image and the messages vbox */
2598 hbox = gtk_hbox_new (FALSE, 3);
2599 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2602 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2603 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2605 /* vbox containing the main message and the details expander */
2606 vbox = gtk_vbox_new (FALSE, 3);
2607 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2610 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2612 label = gtk_label_new (NULL);
2613 gtk_label_set_markup (GTK_LABEL (label), txt);
2614 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2615 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2618 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2621 if (details != NULL)
2623 GtkWidget *expander;
2625 expander = gtk_expander_new (_("Technical Details"));
2627 txt = g_strdup_printf ("<i>%s</i>", details);
2629 label = gtk_label_new (NULL);
2630 gtk_label_set_markup (GTK_LABEL (label), txt);
2631 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2632 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2635 gtk_container_add (GTK_CONTAINER (expander), label);
2636 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2639 g_signal_connect (info_bar, "response",
2640 G_CALLBACK (gtk_widget_destroy), NULL);
2642 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2643 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2644 gtk_widget_show_all (info_bar);
2648 media_stream_error_to_txt (EmpathyCallWindow *self,
2649 TpyCallChannel *call,
2651 TpMediaStreamError error)
2653 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2654 const gchar *cm = NULL;
2660 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2662 return g_strdup_printf (
2663 _("%s's software does not understand any of the audio formats "
2664 "supported by your computer"),
2665 empathy_contact_get_alias (priv->contact));
2667 return g_strdup_printf (
2668 _("%s's software does not understand any of the video formats "
2669 "supported by your computer"),
2670 empathy_contact_get_alias (priv->contact));
2672 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2673 return g_strdup_printf (
2674 _("Can't establish a connection to %s. "
2675 "One of you might be on a network that does not allow "
2676 "direct connections."),
2677 empathy_contact_get_alias (priv->contact));
2679 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2680 return g_strdup (_("There was a failure on the network"));
2682 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2684 return g_strdup (_("The audio formats necessary for this call "
2685 "are not installed on your computer"));
2687 return g_strdup (_("The video formats necessary for this call "
2688 "are not installed on your computer"));
2690 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2691 tp_connection_parse_object_path (
2692 tp_channel_borrow_connection (TP_CHANNEL (call)),
2695 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2696 "product=Telepathy&component=%s", cm);
2698 result = g_strdup_printf (
2699 _("Something unexpected happened in a Telepathy component. "
2700 "Please <a href=\"%s\">report this bug</a> and attach "
2701 "logs gathered from the 'Debug' window in the Help menu."), url);
2707 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2708 return g_strdup (_("There was a failure in the call engine"));
2710 case TP_MEDIA_STREAM_ERROR_EOS:
2711 return g_strdup (_("The end of the stream was reached"));
2713 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2720 empathy_call_window_stream_error (EmpathyCallWindow *self,
2721 TpyCallChannel *call,
2730 desc = media_stream_error_to_txt (self, call, audio, code);
2733 /* No description, use the error message. That's not great as it's not
2734 * localized but it's better than nothing. */
2735 display_error (self, call, icon, title, msg, NULL);
2739 display_error (self, call, icon, title, desc, msg);
2745 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2748 EmpathyCallWindow *self)
2750 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2751 "gnome-stock-mic", _("Can't establish audio stream"));
2755 empathy_call_window_video_stream_error (TpyCallChannel *call,
2758 EmpathyCallWindow *self)
2760 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2761 "camera-web", _("Can't establish video stream"));
2766 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2768 EmpathyCallWindow *self)
2770 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2771 TpyCallChannel *call;
2772 gboolean can_send_video;
2774 if (state != TPY_CALL_STATE_ACCEPTED)
2777 if (priv->call_state == CONNECTED)
2780 g_timer_start (priv->timer);
2781 priv->call_state = CONNECTED;
2783 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2785 can_send_video = priv->video_input != NULL &&
2786 empathy_contact_can_voip_video (priv->contact) &&
2787 empathy_camera_monitor_get_available (priv->camera_monitor);
2789 g_object_get (priv->handler, "call-channel", &call, NULL);
2791 if (tpy_call_channel_has_dtmf (call))
2792 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2794 if (priv->video_input == NULL)
2795 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2797 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2799 empathy_call_window_show_hangup_button (self, TRUE);
2801 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2803 clutter_actor_hide (priv->video_output);
2804 gtk_widget_show (priv->remote_user_avatar_widget);
2806 g_object_unref (call);
2808 g_mutex_lock (priv->lock);
2810 priv->timer_id = g_timeout_add_seconds (1,
2811 empathy_call_window_update_timer, self);
2813 g_mutex_unlock (priv->lock);
2815 empathy_call_window_update_timer (self);
2817 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2821 empathy_call_window_show_video_output_cb (gpointer user_data)
2823 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2825 if (self->priv->video_output != NULL)
2827 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2828 clutter_actor_show (self->priv->video_output);
2829 empathy_call_window_raise_actors (self);
2836 empathy_call_window_check_video_cb (gpointer data)
2838 EmpathyCallWindow *self = data;
2840 if (self->priv->got_video)
2842 self->priv->got_video = FALSE;
2846 /* No video in the last N seconds, display the remote avatar */
2847 empathy_call_window_show_video_output (self, FALSE);
2852 /* Called from the streaming thread */
2854 empathy_call_window_video_probe_cb (GstPad *pad,
2855 GstMiniObject *mini_obj,
2856 EmpathyCallWindow *self)
2859 if (GST_IS_EVENT (mini_obj))
2862 if (G_UNLIKELY (!self->priv->got_video))
2864 /* show the remote video */
2865 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2866 empathy_call_window_show_video_output_cb,
2867 g_object_ref (self), g_object_unref);
2869 self->priv->got_video = TRUE;
2875 /* Called from the streaming thread */
2877 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2878 GstPad *src, guint media_type, gpointer user_data)
2880 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2881 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2882 gboolean retval = FALSE;
2886 g_mutex_lock (priv->lock);
2890 case TP_MEDIA_STREAM_TYPE_AUDIO:
2891 pad = empathy_call_window_get_audio_sink_pad (self);
2893 case TP_MEDIA_STREAM_TYPE_VIDEO:
2894 g_idle_add (empathy_call_window_show_video_output_cb, self);
2895 pad = empathy_call_window_get_video_sink_pad (self);
2897 gst_pad_add_data_probe (src,
2898 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2899 if (priv->got_video_src > 0)
2900 g_source_remove (priv->got_video_src);
2901 priv->got_video_src = g_timeout_add_seconds (5,
2902 empathy_call_window_check_video_cb, self);
2905 g_assert_not_reached ();
2911 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2912 g_warning ("Could not link %s sink pad",
2913 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2917 gst_object_unref (pad);
2921 /* If no sink could be linked, try to add fakesink to prevent the whole call
2926 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2928 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2930 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2931 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2932 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2934 gst_element_set_locked_state (fakesink, TRUE);
2935 gst_element_set_state (fakesink, GST_STATE_NULL);
2936 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2940 DEBUG ("Could not link real sink, linked fakesink instead");
2942 gst_object_unref (sinkpad);
2946 gst_object_unref (fakesink);
2951 g_mutex_unlock (priv->lock);
2957 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2958 GstPad *sink, FsMediaType media_type, gpointer user_data)
2960 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2961 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2963 gboolean retval = FALSE;
2967 case FS_MEDIA_TYPE_AUDIO:
2968 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2970 g_warning ("Could not add audio source to pipeline");
2974 pad = gst_element_get_static_pad (priv->audio_input, "src");
2977 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2978 g_warning ("Could not get source pad from audio source");
2982 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2984 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2985 g_warning ("Could not link audio source to farsight");
2989 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2991 g_warning ("Could not start audio source");
2992 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2993 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2999 case FS_MEDIA_TYPE_VIDEO:
3000 if (priv->video_tee != NULL)
3002 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3003 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3005 g_warning ("Could not link video source input pipeline");
3008 gst_object_unref (pad);
3014 g_assert_not_reached ();
3021 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3023 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3024 GstElement *preview;
3026 disable_camera (self);
3028 DEBUG ("remove video input");
3029 preview = priv->video_preview_sink;
3031 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3032 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3033 gst_element_set_state (preview, GST_STATE_NULL);
3035 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3038 g_object_unref (priv->video_input);
3039 priv->video_input = NULL;
3040 g_object_unref (priv->video_tee);
3041 priv->video_tee = NULL;
3042 clutter_actor_destroy (priv->video_preview);
3043 priv->video_preview = NULL;
3045 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3049 start_call (EmpathyCallWindow *self)
3051 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3053 priv->call_started = TRUE;
3054 empathy_call_handler_start_call (priv->handler,
3055 gtk_get_current_event_time ());
3057 if (empathy_call_handler_has_initial_video (priv->handler))
3059 TpyCallChannel *call;
3062 g_object_get (priv->handler, "call-channel", &call, NULL);
3063 s = tpy_call_channel_get_video_state (call);
3065 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3066 s == TPY_SENDING_STATE_SENDING)
3068 /* Enable 'send video' buttons and display the preview */
3069 gtk_toggle_tool_button_set_active (
3070 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3074 gtk_toggle_tool_button_set_active (
3075 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3077 if (priv->video_preview == NULL)
3079 create_video_preview (self);
3080 add_video_preview_to_pipeline (self);
3084 g_object_unref (call);
3089 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3092 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3093 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3096 empathy_call_handler_bus_message (priv->handler, bus, message);
3098 switch (GST_MESSAGE_TYPE (message))
3100 case GST_MESSAGE_STATE_CHANGED:
3101 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3103 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3105 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3106 !priv->call_started)
3108 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3109 if (newstate == GST_STATE_PAUSED)
3111 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3112 priv->pipeline_playing = TRUE;
3114 if (priv->start_call_when_playing)
3119 case GST_MESSAGE_ERROR:
3121 GError *error = NULL;
3122 GstElement *gst_error;
3125 gst_message_parse_error (message, &error, &debug);
3126 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3128 g_message ("Element error: %s -- %s\n", error->message, debug);
3130 if (g_str_has_prefix (gst_element_get_name (gst_error),
3131 VIDEO_INPUT_ERROR_PREFIX))
3133 /* Remove the video input and continue */
3134 if (priv->video_input != NULL)
3135 empathy_call_window_remove_video_input (self);
3136 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3140 empathy_call_window_disconnected (self, TRUE);
3142 g_error_free (error);
3145 case GST_MESSAGE_UNKNOWN:
3146 case GST_MESSAGE_EOS:
3147 case GST_MESSAGE_WARNING:
3148 case GST_MESSAGE_INFO:
3149 case GST_MESSAGE_TAG:
3150 case GST_MESSAGE_BUFFERING:
3151 case GST_MESSAGE_STATE_DIRTY:
3152 case GST_MESSAGE_STEP_DONE:
3153 case GST_MESSAGE_CLOCK_PROVIDE:
3154 case GST_MESSAGE_CLOCK_LOST:
3155 case GST_MESSAGE_NEW_CLOCK:
3156 case GST_MESSAGE_STRUCTURE_CHANGE:
3157 case GST_MESSAGE_STREAM_STATUS:
3158 case GST_MESSAGE_APPLICATION:
3159 case GST_MESSAGE_ELEMENT:
3160 case GST_MESSAGE_SEGMENT_START:
3161 case GST_MESSAGE_SEGMENT_DONE:
3162 case GST_MESSAGE_DURATION:
3163 case GST_MESSAGE_ANY:
3172 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3173 GHashTable *members,
3174 EmpathyCallWindow *self)
3176 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3177 GHashTableIter iter;
3178 gpointer key, value;
3179 gboolean held = FALSE;
3181 g_hash_table_iter_init (&iter, members);
3182 while (g_hash_table_iter_next (&iter, &key, &value))
3184 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3186 /* This assumes this is a 1-1 call, otherwise one participant
3187 * putting the call on hold wouldn't mean the call is on hold
3195 priv->call_state = HELD;
3196 else if (priv->call_state == HELD)
3197 priv->call_state = CONNECTED;
3201 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3203 EmpathyCallWindow *self)
3205 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3206 TpyCallChannel *call;
3208 g_object_get (priv->handler, "call-channel", &call, NULL);
3213 tp_g_signal_connect_object (call, "audio-stream-error",
3214 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3215 tp_g_signal_connect_object (call, "video-stream-error",
3216 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3219 tp_g_signal_connect_object (call, "members-changed",
3220 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3222 g_object_unref (call);
3226 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3228 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3229 TpyCallChannel *call;
3232 /* Make the hangup button twice as wide */
3233 width = gtk_widget_get_allocated_width (priv->hangup_button);
3234 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3236 g_signal_connect (priv->handler, "state-changed",
3237 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3238 g_signal_connect (priv->handler, "conference-added",
3239 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3240 g_signal_connect (priv->handler, "conference-removed",
3241 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3242 g_signal_connect (priv->handler, "closed",
3243 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3244 g_signal_connect (priv->handler, "src-pad-added",
3245 G_CALLBACK (empathy_call_window_src_added_cb), window);
3246 g_signal_connect (priv->handler, "sink-pad-added",
3247 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3248 g_signal_connect (priv->handler, "sink-pad-removed",
3249 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3251 g_object_get (priv->handler, "call-channel", &call, NULL);
3254 call_handler_notify_call_cb (priv->handler, NULL, window);
3255 g_object_unref (call);
3259 /* call-channel doesn't exist yet, we'll connect signals once it has been
3261 g_signal_connect (priv->handler, "notify::call-channel",
3262 G_CALLBACK (call_handler_notify_call_cb), window);
3265 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3269 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3270 EmpathyCallWindow *window)
3272 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3274 if (priv->pipeline != NULL)
3276 if (priv->bus_message_source_id != 0)
3278 g_source_remove (priv->bus_message_source_id);
3279 priv->bus_message_source_id = 0;
3282 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3285 if (priv->call_state == CONNECTING)
3286 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3292 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3295 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3297 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3302 gtk_widget_hide (priv->dtmf_panel);
3303 gtk_widget_hide (menu);
3304 gtk_widget_hide (priv->toolbar);
3308 if (priv->dialpad_was_visible_before_fs)
3309 gtk_widget_show (priv->dtmf_panel);
3311 gtk_widget_show (menu);
3312 gtk_widget_show (priv->toolbar);
3314 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3315 priv->original_height_before_fs);
3320 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3322 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3324 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3325 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3326 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3327 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3329 if (priv->video_output != NULL)
3332 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3333 priv->video_output, TRUE, TRUE,
3334 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3341 empathy_call_window_state_event_cb (GtkWidget *widget,
3342 GdkEventWindowState *event, EmpathyCallWindow *window)
3344 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3346 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3347 gboolean set_fullscreen = event->new_window_state &
3348 GDK_WINDOW_STATE_FULLSCREEN;
3352 gboolean dialpad_was_visible;
3353 GtkAllocation allocation;
3354 gint original_width, original_height;
3356 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3357 original_width = allocation.width;
3358 original_height = allocation.height;
3360 g_object_get (priv->dtmf_panel,
3361 "visible", &dialpad_was_visible,
3364 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3365 priv->original_width_before_fs = original_width;
3366 priv->original_height_before_fs = original_height;
3368 if (priv->video_output_motion_handler_id == 0 &&
3369 priv->video_output != NULL)
3371 priv->video_output_motion_handler_id = g_signal_connect (
3372 G_OBJECT (priv->video_container), "motion-notify-event",
3373 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3379 disconnect_video_output_motion_handler (window);
3382 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3384 show_controls (window, set_fullscreen);
3385 show_borders (window, set_fullscreen);
3386 gtk_action_set_stock_id (priv->menu_fullscreen,
3387 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3388 priv->is_fullscreen = set_fullscreen;
3395 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3398 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3399 int w, h, dialpad_width;
3400 GtkAllocation allocation;
3402 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3403 w = allocation.width;
3404 h = allocation.height;
3406 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3410 gtk_widget_show (priv->dtmf_panel);
3416 gtk_widget_hide (priv->dtmf_panel);
3420 gtk_window_resize (GTK_WINDOW (window), w, h);
3424 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3427 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3428 TpyCallChannel *call;
3430 priv->sending_video = (state == CAMERA_STATE_ON);
3432 if (state == CAMERA_STATE_ON)
3434 /* When we start sending video, we want to show the video preview by
3436 display_video_preview (window, TRUE);
3440 display_video_preview (window, FALSE);
3443 if (priv->call_state != CONNECTED)
3446 g_object_get (priv->handler, "call-channel", &call, NULL);
3447 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3448 tpy_call_channel_send_video (call, priv->sending_video);
3449 g_object_unref (call);
3453 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3454 EmpathyCallWindow *self)
3456 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3459 active = (gtk_toggle_tool_button_get_active (toggle));
3461 /* We don't want the settings callback to react to this change to avoid
3463 g_signal_handlers_block_by_func (priv->settings,
3464 empathy_call_window_prefs_volume_changed_cb, self);
3468 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3469 priv->volume * 100);
3473 /* TODO, Instead of setting the input volume to 0 we should probably
3474 * stop sending but this would cause the audio call to drop if both
3475 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3476 * in the future. GNOME #574574
3478 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3482 g_signal_handlers_unblock_by_func (priv->settings,
3483 empathy_call_window_prefs_volume_changed_cb, self);
3487 empathy_call_window_hangup_cb (gpointer object,
3488 EmpathyCallWindow *self)
3490 empathy_call_handler_stop_call (self->priv->handler);
3492 empathy_call_window_disconnected (self, TRUE);
3496 empathy_call_window_restart_call (EmpathyCallWindow *window)
3498 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3500 /* Remove error info bars */
3501 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3502 (GtkCallback) gtk_widget_destroy, NULL);
3504 create_video_output_widget (window);
3506 /* While the call was disconnected, the input volume might have changed.
3507 * However, since the audio_input source was destroyed, its volume has not
3508 * been updated during that time. That's why we manually update it here */
3509 empathy_call_window_mic_volume_changed (window);
3511 priv->outgoing = TRUE;
3512 empathy_call_window_set_state_connecting (window);
3514 if (priv->pipeline_playing)
3515 start_call (window);
3517 /* call will be started when the pipeline is ready */
3518 priv->start_call_when_playing = TRUE;
3520 empathy_call_window_setup_avatars (window, priv->handler);
3522 empathy_call_window_show_hangup_button (window, TRUE);
3526 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3527 EmpathyCallWindow *window)
3531 active = gtk_toggle_tool_button_get_active (button);
3533 empathy_call_window_show_dialpad (window, active);
3537 empathy_call_window_fullscreen_cb (gpointer object,
3538 EmpathyCallWindow *window)
3540 empathy_call_window_fullscreen_toggle (window);
3544 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3546 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3548 if (priv->is_fullscreen)
3549 gtk_window_unfullscreen (GTK_WINDOW (window));
3551 gtk_window_fullscreen (GTK_WINDOW (window));
3555 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3556 GdkEventButton *event, EmpathyCallWindow *window)
3558 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3560 empathy_call_window_video_menu_popup (window, event->button);
3568 empathy_call_window_key_press_cb (GtkWidget *video_output,
3569 GdkEventKey *event, EmpathyCallWindow *window)
3571 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3573 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3575 /* Since we are in fullscreen mode, toggling will bring us back to
3577 empathy_call_window_fullscreen_toggle (window);
3585 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3586 GdkEventMotion *event, EmpathyCallWindow *window)
3588 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3590 if (priv->is_fullscreen)
3592 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3594 /* Show the bottom toolbar */
3595 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3602 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3606 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3608 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3610 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3611 button, gtk_get_current_event_time ());
3612 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3616 empathy_call_window_status_message (EmpathyCallWindow *self,
3619 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3623 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3624 gdouble value, EmpathyCallWindow *window)
3626 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3628 if (priv->audio_output == NULL)
3631 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3636 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3638 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3640 return priv->ui_manager;
3643 EmpathyGstAudioSrc *
3644 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3646 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3648 return (EmpathyGstAudioSrc *) priv->audio_input;
3651 EmpathyGstVideoSrc *
3652 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3654 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);