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);
879 /* Flip the video preview */
880 /* FIXME: disabled because it makes the drag handle to go away! */
881 clutter_actor_set_rotation (preview,
884 SELF_VIDEO_SECTION_WIDTH * 0.5,
889 clutter_container_add_actor (CLUTTER_CONTAINER (stage), preview);
890 clutter_actor_set_position (preview, event_x, event_y);
892 clutter_drag_action_set_drag_handle (action, preview);
894 empathy_call_window_show_preview_rectangles (self, TRUE);
895 empathy_call_window_darken_preview_rectangles (self);
899 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
903 ClutterModifierType modifiers,
904 EmpathyCallWindow *self)
906 ClutterActor *preview = clutter_drag_action_get_drag_handle (action);
909 /* Get the position before destroying the drag actor, otherwise the
910 * preview_box allocation won't be valid and we won't be able to
911 * calculate the position. */
912 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
914 /* Destroy the video preview copy that we were dragging */
915 clutter_actor_destroy (preview);
917 if (pos != PREVIEW_POS_NONE)
918 empathy_call_window_move_video_preview (self, pos);
920 empathy_call_window_show_preview_rectangles (self, FALSE);
924 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
928 EmpathyCallWindow *self)
931 gfloat event_x, event_y;
933 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
935 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
937 if (pos != PREVIEW_POS_NONE)
938 empathy_call_window_highlight_preview_rectangle (self, pos);
940 empathy_call_window_darken_preview_rectangles (self);
944 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
945 ClutterCrossingEvent *event,
946 EmpathyCallWindow *self)
948 ClutterActor *rectangle;
950 rectangle = empathy_call_window_get_preview_rectangle (self,
951 self->priv->preview_pos);
953 empathy_call_window_highlight_preview_rectangle (self,
954 self->priv->preview_pos);
956 clutter_actor_show (rectangle);
962 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
963 ClutterCrossingEvent *event,
964 EmpathyCallWindow *self)
966 ClutterActor *rectangle;
968 rectangle = empathy_call_window_get_preview_rectangle (self,
969 self->priv->preview_pos);
971 empathy_call_window_darken_preview_rectangle (self, rectangle);
973 clutter_actor_hide (rectangle);
979 create_video_preview (EmpathyCallWindow *self)
981 EmpathyCallWindowPriv *priv = GET_PRIV (self);
982 ClutterLayoutManager *layout, *layout_center, *layout_end;
983 ClutterActor *preview;
986 ClutterAction *action;
989 g_assert (priv->video_preview == NULL);
991 preview = clutter_texture_new ();
992 clutter_actor_set_size (preview,
993 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
994 priv->video_preview_sink = clutter_gst_video_sink_new (
995 CLUTTER_TEXTURE (preview));
997 /* Flip the video preview */
998 clutter_actor_set_rotation (preview,
1001 SELF_VIDEO_SECTION_WIDTH * 0.5,
1005 /* Add a little offset to the video preview */
1006 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1007 CLUTTER_BIN_ALIGNMENT_START);
1008 priv->video_preview = clutter_box_new (layout);
1009 clutter_actor_set_size (priv->video_preview,
1010 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1011 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1012 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1014 /* We have a box with the margins and the video in the middle inside
1015 * a bigger box with an extra bottom margin so we're not on top of
1016 * the floating toolbar. */
1017 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1018 CLUTTER_BIN_ALIGNMENT_CENTER);
1019 box = clutter_box_new (layout_center);
1020 clutter_actor_set_size (box,
1021 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1022 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1024 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1025 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1027 g_object_set (priv->video_preview_sink,
1032 /* Translators: this is an "Info" label. It should be as short
1034 button = gtk_button_new_with_label (_("i"));
1035 b = gtk_clutter_actor_new_with_contents (button);
1037 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1038 CLUTTER_BIN_ALIGNMENT_END);
1039 box = clutter_box_new (layout_end);
1040 clutter_actor_set_size (box,
1041 SELF_VIDEO_SECTION_WIDTH,
1042 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1044 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1045 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1047 g_signal_connect (button, "clicked",
1048 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1051 /* Translators: this is an "Info" label. It should be as short
1053 button = gtk_button_new_with_label (_("i"));
1054 priv->preview_hidden_button =
1055 gtk_clutter_actor_new_with_contents (button);
1057 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1058 priv->preview_hidden_button,
1059 CLUTTER_BIN_ALIGNMENT_START,
1060 CLUTTER_BIN_ALIGNMENT_END);
1062 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1064 clutter_actor_hide (priv->preview_hidden_button);
1066 g_signal_connect (button, "clicked",
1067 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1070 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1071 priv->video_preview,
1072 CLUTTER_BIN_ALIGNMENT_START,
1073 CLUTTER_BIN_ALIGNMENT_END);
1075 action = clutter_drag_action_new ();
1076 g_signal_connect (action, "drag-begin",
1077 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1078 g_signal_connect (action, "drag-end",
1079 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1080 g_signal_connect (action, "drag-motion",
1081 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1083 g_signal_connect (preview, "enter-event",
1084 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1085 g_signal_connect (preview, "leave-event",
1086 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1088 clutter_actor_add_action (preview, action);
1089 clutter_actor_set_reactive (preview, TRUE);
1093 play_camera (EmpathyCallWindow *window,
1096 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1097 GstElement *preview;
1100 if (priv->video_preview == NULL)
1102 create_video_preview (window);
1103 add_video_preview_to_pipeline (window);
1107 state = GST_STATE_PLAYING;
1109 state = GST_STATE_NULL;
1111 preview = priv->video_preview_sink;
1113 gst_element_set_state (preview, state);
1114 gst_element_set_state (priv->video_input, state);
1115 gst_element_set_state (priv->video_tee, state);
1119 display_video_preview (EmpathyCallWindow *self,
1122 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1126 /* Display the video preview */
1127 DEBUG ("Show video preview");
1129 play_camera (self, TRUE);
1130 clutter_actor_show (priv->video_preview);
1131 clutter_actor_raise_top (priv->floating_toolbar);
1135 /* Hide the video preview */
1136 DEBUG ("Hide video preview");
1138 if (priv->video_preview != NULL)
1140 clutter_actor_hide (priv->video_preview);
1141 play_camera (self, FALSE);
1147 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1149 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1151 empathy_call_window_status_message (window, _("Connecting…"));
1152 priv->call_state = CONNECTING;
1155 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1156 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1160 disable_camera (EmpathyCallWindow *self)
1162 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1164 if (priv->camera_state == CAMERA_STATE_OFF)
1167 DEBUG ("Disable camera");
1169 display_video_preview (self, FALSE);
1171 if (priv->camera_state == CAMERA_STATE_ON)
1172 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1174 priv->camera_state = CAMERA_STATE_OFF;
1178 enable_camera (EmpathyCallWindow *self)
1180 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1182 if (priv->camera_state == CAMERA_STATE_ON)
1185 if (priv->video_input == NULL)
1187 DEBUG ("Can't enable camera, no input");
1191 DEBUG ("Enable camera");
1193 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1195 priv->camera_state = CAMERA_STATE_ON;
1199 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1200 EmpathyCallWindow *self)
1202 if (gtk_toggle_tool_button_get_active (toggle))
1203 enable_camera (self);
1205 disable_camera (self);
1209 create_pipeline (EmpathyCallWindow *self)
1211 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1214 g_assert (priv->pipeline == NULL);
1216 priv->pipeline = gst_pipeline_new (NULL);
1217 priv->pipeline_playing = FALSE;
1219 priv->video_tee = gst_element_factory_make ("tee", NULL);
1220 gst_object_ref (priv->video_tee);
1221 gst_object_sink (priv->video_tee);
1223 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1225 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1226 priv->bus_message_source_id = gst_bus_add_watch (bus,
1227 empathy_call_window_bus_message, self);
1229 g_object_unref (bus);
1233 empathy_call_window_settings_cb (GtkAction *action,
1234 EmpathyCallWindow *self)
1236 gchar *args = g_strdup_printf ("-p %s",
1237 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1239 empathy_launch_program (BIN_DIR, "empathy", args);
1245 empathy_call_window_contents_cb (GtkAction *action,
1246 EmpathyCallWindow *self)
1248 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1252 empathy_call_window_debug_cb (GtkAction *action,
1253 EmpathyCallWindow *self)
1255 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1259 empathy_call_window_about_cb (GtkAction *action,
1260 EmpathyCallWindow *self)
1262 empathy_about_dialog_new (GTK_WINDOW (self));
1266 empathy_call_window_toolbar_timeout (gpointer data)
1268 EmpathyCallWindow *self = data;
1270 clutter_state_set_state (self->priv->transitions, "fade-out");
1276 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1278 EmpathyCallWindow *self)
1280 clutter_state_set_state (self->priv->transitions, "fade-in");
1282 if (self->priv->inactivity_src > 0)
1283 g_source_remove (self->priv->inactivity_src);
1285 self->priv->inactivity_src = g_timeout_add_seconds (3,
1286 empathy_call_window_toolbar_timeout, self);
1292 empathy_call_window_configure_event_cb (GtkWidget *widget,
1294 EmpathyCallWindow *self)
1296 GdkWindow *gdk_window;
1297 GdkWindowState window_state;
1299 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1300 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1302 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1303 &self->priv->dialpad_width, NULL);
1305 gdk_window = gtk_widget_get_window (widget);
1306 window_state = gdk_window_get_state (gdk_window);
1307 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1313 empathy_call_window_destroyed_cb (GtkWidget *object,
1314 EmpathyCallWindow *self)
1316 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1318 /* Save the geometry as if the dialpad was hidden. */
1319 empathy_geometry_save_values (GTK_WINDOW (self),
1320 self->priv->x, self->priv->y,
1321 self->priv->w - self->priv->dialpad_width, self->priv->h,
1322 self->priv->maximized);
1327 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1329 ClutterBindConstraint *constraint)
1331 ClutterActorBox allocation;
1333 clutter_actor_get_allocation_box (stage, &allocation);
1335 clutter_bind_constraint_set_offset (constraint,
1336 allocation.y2 - allocation.y1 -
1337 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1341 empathy_call_window_init (EmpathyCallWindow *self)
1343 EmpathyCallWindowPriv *priv;
1345 GtkWidget *top_vbox;
1347 ClutterConstraint *constraint;
1348 ClutterActor *remote_avatar;
1349 GtkStyleContext *context;
1353 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1354 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1356 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1357 gui = empathy_builder_get_file (filename,
1358 "call_window_vbox", &top_vbox,
1359 "errors_vbox", &priv->errors_vbox,
1360 "pane", &priv->pane,
1361 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1362 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1363 "status_label", &priv->status_label,
1364 "audiocall", &priv->audio_call_button,
1365 "videocall", &priv->video_call_button,
1366 "microphone", &priv->mic_button,
1367 "camera", &priv->camera_button,
1368 "hangup", &priv->hangup_button,
1369 "dialpad", &priv->dialpad_button,
1370 "toolbar", &priv->toolbar,
1371 "bottom_toolbar", &priv->bottom_toolbar,
1372 "ui_manager", &priv->ui_manager,
1373 "menufullscreen", &priv->menu_fullscreen,
1374 "menupreviewswap", &priv->menu_swap_camera,
1375 "details_vbox", &priv->details_vbox,
1376 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1377 "acodec_encoding_label", &priv->acodec_encoding_label,
1378 "acodec_decoding_label", &priv->acodec_decoding_label,
1379 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1380 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1381 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1382 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1383 "video_local_candidate_label", &priv->video_local_candidate_label,
1384 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1385 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1386 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1387 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1391 empathy_builder_connect (gui, self,
1392 "hangup", "clicked", empathy_call_window_hangup_cb,
1393 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1394 "videocall", "clicked", empathy_call_window_video_call_cb,
1395 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1396 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1397 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1398 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1399 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1400 "menusettings", "activate", empathy_call_window_settings_cb,
1401 "menucontents", "activate", empathy_call_window_contents_cb,
1402 "menudebug", "activate", empathy_call_window_debug_cb,
1403 "menuabout", "activate", empathy_call_window_about_cb,
1404 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1405 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1406 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1407 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1410 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1412 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1414 g_object_bind_property (priv->camera_monitor, "available",
1415 priv->camera_button, "sensitive",
1416 G_BINDING_SYNC_CREATE);
1418 g_signal_connect (priv->camera_monitor, "added",
1419 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1420 g_signal_connect (priv->camera_monitor, "removed",
1421 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1423 priv->lock = g_mutex_new ();
1425 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1427 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1428 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1429 CONTENT_HBOX_BORDER_WIDTH);
1430 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1433 /* avatar/video box */
1434 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1435 CLUTTER_BIN_ALIGNMENT_CENTER);
1437 priv->video_box = clutter_box_new (priv->video_layout);
1439 priv->video_container = gtk_clutter_embed_new ();
1441 /* Set the background color to that of the rest of the window */
1442 context = gtk_widget_get_style_context (priv->content_hbox);
1443 gtk_style_context_get_background_color (context,
1444 GTK_STATE_FLAG_NORMAL, &rgba);
1445 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1446 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1447 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1448 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1449 clutter_stage_set_color (
1450 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1451 GTK_CLUTTER_EMBED (priv->video_container))),
1454 clutter_container_add (
1455 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1456 GTK_CLUTTER_EMBED (priv->video_container))),
1460 constraint = clutter_bind_constraint_new (
1461 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1462 CLUTTER_BIND_SIZE, 0);
1463 clutter_actor_add_constraint (priv->video_box, constraint);
1465 priv->remote_user_avatar_widget = gtk_image_new ();
1466 remote_avatar = gtk_clutter_actor_new_with_contents (
1467 priv->remote_user_avatar_widget);
1469 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1472 empathy_call_window_create_preview_rectangles (self);
1474 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1475 priv->video_container, TRUE, TRUE,
1476 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1478 create_pipeline (self);
1479 create_video_output_widget (self);
1480 create_audio_input (self);
1481 create_video_input (self);
1483 priv->floating_toolbar = empathy_rounded_actor_new ();
1485 gtk_widget_reparent (priv->bottom_toolbar,
1486 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1488 constraint = clutter_bind_constraint_new (
1489 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1492 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1495 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1496 "notify::allocation",
1497 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1500 clutter_actor_set_size (priv->floating_toolbar,
1501 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1502 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1504 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1505 priv->floating_toolbar,
1506 CLUTTER_BIN_ALIGNMENT_CENTER,
1507 CLUTTER_BIN_ALIGNMENT_END);
1509 clutter_actor_raise_top (priv->floating_toolbar);
1511 /* Transitions for the floating toolbar */
1512 priv->transitions = clutter_state_new ();
1514 /* all transitions last for 2s */
1515 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1517 /* transition from any state to "fade-out" state */
1518 clutter_state_set (priv->transitions, NULL, "fade-out",
1519 priv->floating_toolbar,
1520 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1523 /* transition from any state to "fade-in" state */
1524 clutter_state_set (priv->transitions, NULL, "fade-in",
1525 priv->floating_toolbar,
1526 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1529 /* put the actor into the "fade-in" state with no animation */
1530 clutter_state_warp_to_state (priv->transitions, "fade-in");
1532 /* The call will be started as soon the pipeline is playing */
1533 priv->start_call_when_playing = TRUE;
1535 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1536 G_CALLBACK (dtmf_button_pressed_cb),
1537 G_CALLBACK (dtmf_button_released_cb));
1539 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1542 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1545 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1547 gtk_widget_show_all (top_vbox);
1549 gtk_widget_hide (priv->dtmf_panel);
1550 gtk_widget_hide (priv->details_vbox);
1552 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1554 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1555 priv->video_container);
1557 /* We hide the bottom toolbar after 3s of inactivity and show it
1558 * again on mouse movement */
1559 priv->inactivity_src = g_timeout_add_seconds (3,
1560 empathy_call_window_toolbar_timeout, self);
1562 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1563 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1565 g_signal_connect (G_OBJECT (self), "realize",
1566 G_CALLBACK (empathy_call_window_realized_cb), self);
1568 g_signal_connect (G_OBJECT (self), "delete-event",
1569 G_CALLBACK (empathy_call_window_delete_cb), self);
1571 g_signal_connect (G_OBJECT (self), "window-state-event",
1572 G_CALLBACK (empathy_call_window_state_event_cb), self);
1574 g_signal_connect (G_OBJECT (self), "key-press-event",
1575 G_CALLBACK (empathy_call_window_key_press_cb), self);
1577 g_signal_connect (self, "motion-notify-event",
1578 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1580 priv->timer = g_timer_new ();
1582 g_object_ref (priv->ui_manager);
1583 g_object_unref (gui);
1585 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1586 priv->mic_menu = empathy_mic_menu_new (self);
1587 priv->camera_menu = empathy_camera_menu_new (self);
1589 empathy_call_window_show_hangup_button (self, TRUE);
1591 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1593 /* Retrieve initial volume */
1594 priv->volume = g_settings_get_double (priv->settings,
1595 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1597 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1598 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1600 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1601 /* These signals are used to track the window position and save it
1602 * when the window is destroyed. We need to do this as we don't want
1603 * the window geometry to be saved with the dialpad taken into account. */
1604 g_signal_connect (self, "destroy",
1605 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1606 g_signal_connect (self, "configure-event",
1607 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1608 g_signal_connect (self, "window-state-event",
1609 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1611 /* Don't display labels in both toolbars */
1612 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1615 /* Instead of specifying a width and a height, we specify only one size. That's
1616 because we want a square avatar icon. */
1618 init_contact_avatar_with_size (EmpathyContact *contact,
1619 GtkWidget *image_widget,
1622 GdkPixbuf *pixbuf_avatar = NULL;
1624 if (contact != NULL)
1626 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1630 if (pixbuf_avatar == NULL)
1632 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1633 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1636 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1638 if (pixbuf_avatar != NULL)
1639 g_object_unref (pixbuf_avatar);
1643 set_window_title (EmpathyCallWindow *self)
1645 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1648 if (priv->contact != NULL)
1650 /* translators: Call is a noun and %s is the contact name. This string
1651 * is used in the window title */
1652 tmp = g_strdup_printf (_("Call with %s"),
1653 empathy_contact_get_alias (priv->contact));
1654 gtk_window_set_title (GTK_WINDOW (self), tmp);
1659 g_warning ("Unknown remote contact!");
1664 set_remote_user_name (EmpathyCallWindow *self,
1665 EmpathyContact *contact)
1667 const gchar *alias = empathy_contact_get_alias (contact);
1668 const gchar *status = empathy_contact_get_status (contact);
1671 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1672 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1678 contact_name_changed_cb (EmpathyContact *contact,
1680 EmpathyCallWindow *self)
1682 set_window_title (self);
1683 set_remote_user_name (self, contact);
1687 contact_presence_changed_cb (EmpathyContact *contact,
1689 EmpathyCallWindow *self)
1691 set_remote_user_name (self, contact);
1695 contact_avatar_changed_cb (EmpathyContact *contact,
1697 EmpathyCallWindow *self)
1700 GtkAllocation allocation;
1701 GtkWidget *avatar_widget;
1703 avatar_widget = self->priv->remote_user_avatar_widget;
1705 gtk_widget_get_allocation (avatar_widget, &allocation);
1706 size = allocation.height;
1710 /* the widget is not allocated yet, set a default size */
1711 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1712 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1715 init_contact_avatar_with_size (contact, avatar_widget, size);
1717 avatar_widget = self->priv->remote_user_avatar_toolbar;
1719 gtk_widget_get_allocation (avatar_widget, &allocation);
1720 size = allocation.height;
1724 /* the widget is not allocated yet, set a default size */
1725 size = SMALL_TOOLBAR_SIZE;
1728 init_contact_avatar_with_size (contact, avatar_widget, size);
1732 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1733 EmpathyCallHandler *handler)
1735 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1737 tp_g_signal_connect_object (priv->contact, "notify::name",
1738 G_CALLBACK (contact_name_changed_cb), self, 0);
1739 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1740 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1741 tp_g_signal_connect_object (priv->contact, "notify::presence",
1742 G_CALLBACK (contact_presence_changed_cb), self, 0);
1744 set_window_title (self);
1745 set_remote_user_name (self, priv->contact);
1747 init_contact_avatar_with_size (priv->contact,
1748 priv->remote_user_avatar_widget,
1749 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1750 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1752 init_contact_avatar_with_size (priv->contact,
1753 priv->remote_user_avatar_toolbar,
1754 SMALL_TOOLBAR_SIZE);
1756 /* The remote avatar is shown by default and will be hidden when we receive
1757 video from the remote side. */
1758 clutter_actor_hide (priv->video_output);
1759 gtk_widget_show (priv->remote_user_avatar_widget);
1763 update_send_codec (EmpathyCallWindow *self,
1766 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1773 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1774 widget = priv->acodec_encoding_label;
1778 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1779 widget = priv->vcodec_encoding_label;
1785 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1786 gtk_label_set_text (GTK_LABEL (widget), tmp);
1791 send_audio_codec_notify_cb (GObject *object,
1795 EmpathyCallWindow *self = user_data;
1797 update_send_codec (self, TRUE);
1801 send_video_codec_notify_cb (GObject *object,
1805 EmpathyCallWindow *self = user_data;
1807 update_send_codec (self, FALSE);
1811 update_recv_codec (EmpathyCallWindow *self,
1814 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1817 GString *str = NULL;
1821 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1822 widget = priv->acodec_decoding_label;
1826 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1827 widget = priv->vcodec_decoding_label;
1833 for (l = codecs; l != NULL; l = g_list_next (l))
1835 FsCodec *codec = l->data;
1838 str = g_string_new (NULL);
1840 g_string_append (str, ", ");
1842 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1846 gtk_label_set_text (GTK_LABEL (widget), str->str);
1847 g_string_free (str, TRUE);
1851 recv_audio_codecs_notify_cb (GObject *object,
1855 EmpathyCallWindow *self = user_data;
1857 update_recv_codec (self, TRUE);
1861 recv_video_codecs_notify_cb (GObject *object,
1865 EmpathyCallWindow *self = user_data;
1867 update_recv_codec (self, FALSE);
1870 static const gchar *
1871 candidate_type_to_str (FsCandidate *candidate)
1873 switch (candidate->type)
1875 case FS_CANDIDATE_TYPE_HOST:
1877 case FS_CANDIDATE_TYPE_SRFLX:
1878 return "server reflexive";
1879 case FS_CANDIDATE_TYPE_PRFLX:
1880 return "peer reflexive";
1881 case FS_CANDIDATE_TYPE_RELAY:
1883 case FS_CANDIDATE_TYPE_MULTICAST:
1890 static const gchar *
1891 candidate_type_to_desc (FsCandidate *candidate)
1893 switch (candidate->type)
1895 case FS_CANDIDATE_TYPE_HOST:
1896 return _("The IP address as seen by the machine");
1897 case FS_CANDIDATE_TYPE_SRFLX:
1898 return _("The IP address as seen by a server on the Internet");
1899 case FS_CANDIDATE_TYPE_PRFLX:
1900 return _("The IP address of the peer as seen by the other side");
1901 case FS_CANDIDATE_TYPE_RELAY:
1902 return _("The IP address of a relay server");
1903 case FS_CANDIDATE_TYPE_MULTICAST:
1904 return _("The IP address of the multicast group");
1911 update_candidat_widget (EmpathyCallWindow *self,
1914 FsCandidate *candidate)
1918 g_assert (candidate != NULL);
1919 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1920 candidate->port, candidate_type_to_str (candidate));
1922 gtk_label_set_text (GTK_LABEL (label), str);
1923 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1929 candidates_changed_cb (GObject *object,
1931 EmpathyCallWindow *self)
1933 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1934 FsCandidate *candidate = NULL;
1936 if (type == FS_MEDIA_TYPE_VIDEO)
1938 /* Update remote candidate */
1939 candidate = empathy_call_handler_get_video_remote_candidate (
1942 update_candidat_widget (self, priv->video_remote_candidate_label,
1943 priv->video_remote_candidate_info_img, candidate);
1945 /* Update local candidate */
1946 candidate = empathy_call_handler_get_video_local_candidate (
1949 update_candidat_widget (self, priv->video_local_candidate_label,
1950 priv->video_local_candidate_info_img, candidate);
1954 /* Update remote candidate */
1955 candidate = empathy_call_handler_get_audio_remote_candidate (
1958 update_candidat_widget (self, priv->audio_remote_candidate_label,
1959 priv->audio_remote_candidate_info_img, candidate);
1961 /* Update local candidate */
1962 candidate = empathy_call_handler_get_audio_local_candidate (
1965 update_candidat_widget (self, priv->audio_local_candidate_label,
1966 priv->audio_local_candidate_info_img, candidate);
1971 empathy_call_window_constructed (GObject *object)
1973 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1974 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1975 TpyCallChannel *call;
1977 g_assert (priv->handler != NULL);
1979 g_object_get (priv->handler, "call-channel", &call, NULL);
1980 priv->outgoing = (call == NULL);
1982 g_object_unref (call);
1984 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1985 g_assert (priv->contact != NULL);
1987 empathy_call_window_setup_avatars (self, priv->handler);
1988 empathy_call_window_set_state_connecting (self);
1990 if (!empathy_call_handler_has_initial_video (priv->handler))
1992 gtk_toggle_tool_button_set_active (
1993 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1995 /* If call has InitialVideo, the preview will be started once the call has
1996 * been started (start_call()). */
1998 update_send_codec (self, TRUE);
1999 update_send_codec (self, FALSE);
2000 update_recv_codec (self, TRUE);
2001 update_recv_codec (self, FALSE);
2003 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2004 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2005 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2006 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2007 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2008 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2009 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2010 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2012 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2013 G_CALLBACK (candidates_changed_cb), self, 0);
2016 static void empathy_call_window_dispose (GObject *object);
2017 static void empathy_call_window_finalize (GObject *object);
2020 empathy_call_window_set_property (GObject *object,
2021 guint property_id, const GValue *value, GParamSpec *pspec)
2023 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2025 switch (property_id)
2027 case PROP_CALL_HANDLER:
2028 priv->handler = g_value_dup_object (value);
2031 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2036 empathy_call_window_get_property (GObject *object,
2037 guint property_id, GValue *value, GParamSpec *pspec)
2039 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2041 switch (property_id)
2043 case PROP_CALL_HANDLER:
2044 g_value_set_object (value, priv->handler);
2047 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2052 empathy_call_window_class_init (
2053 EmpathyCallWindowClass *empathy_call_window_class)
2055 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2056 GParamSpec *param_spec;
2058 g_type_class_add_private (empathy_call_window_class,
2059 sizeof (EmpathyCallWindowPriv));
2061 object_class->constructed = empathy_call_window_constructed;
2062 object_class->set_property = empathy_call_window_set_property;
2063 object_class->get_property = empathy_call_window_get_property;
2065 object_class->dispose = empathy_call_window_dispose;
2066 object_class->finalize = empathy_call_window_finalize;
2068 param_spec = g_param_spec_object ("handler",
2069 "handler", "The call handler",
2070 EMPATHY_TYPE_CALL_HANDLER,
2071 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2072 g_object_class_install_property (object_class,
2073 PROP_CALL_HANDLER, param_spec);
2077 empathy_call_window_dispose (GObject *object)
2079 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2080 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2082 if (priv->dispose_has_run)
2085 priv->dispose_has_run = TRUE;
2087 if (priv->handler != NULL)
2089 empathy_call_handler_stop_call (priv->handler);
2090 tp_clear_object (&priv->handler);
2093 if (priv->bus_message_source_id != 0)
2095 g_source_remove (priv->bus_message_source_id);
2096 priv->bus_message_source_id = 0;
2099 if (priv->got_video_src > 0)
2101 g_source_remove (priv->got_video_src);
2102 priv->got_video_src = 0;
2105 if (priv->inactivity_src > 0)
2107 g_source_remove (priv->inactivity_src);
2108 priv->inactivity_src = 0;
2111 tp_clear_object (&priv->pipeline);
2112 tp_clear_object (&priv->video_input);
2113 tp_clear_object (&priv->audio_input);
2114 tp_clear_object (&priv->video_tee);
2115 tp_clear_object (&priv->ui_manager);
2116 tp_clear_object (&priv->fullscreen);
2117 tp_clear_object (&priv->camera_monitor);
2118 tp_clear_object (&priv->settings);
2119 tp_clear_object (&priv->sound_mgr);
2120 tp_clear_object (&priv->mic_menu);
2121 tp_clear_object (&priv->camera_menu);
2123 g_list_free_full (priv->notifiers, g_object_unref);
2125 if (priv->timer_id != 0)
2126 g_source_remove (priv->timer_id);
2129 if (priv->contact != NULL)
2131 g_signal_handlers_disconnect_by_func (priv->contact,
2132 contact_name_changed_cb, self);
2133 priv->contact = NULL;
2136 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2140 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2142 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2144 if (priv->video_output_motion_handler_id != 0)
2146 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2147 priv->video_output_motion_handler_id);
2148 priv->video_output_motion_handler_id = 0;
2153 empathy_call_window_finalize (GObject *object)
2155 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2156 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2158 disconnect_video_output_motion_handler (self);
2160 /* free any data held directly by the object here */
2161 g_mutex_free (priv->lock);
2163 g_timer_destroy (priv->timer);
2165 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2170 empathy_call_window_new (EmpathyCallHandler *handler)
2172 return EMPATHY_CALL_WINDOW (
2173 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2177 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2178 GstElement *conference, gpointer user_data)
2180 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2181 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2182 FsElementAddedNotifier *notifier;
2185 DEBUG ("Conference added");
2187 /* Add notifier to set the various element properties as needed */
2188 notifier = fs_element_added_notifier_new ();
2189 keyfile = fs_utils_get_default_element_properties (conference);
2191 if (keyfile != NULL)
2192 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2194 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2196 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2198 gst_bin_add (GST_BIN (priv->pipeline), conference);
2199 gst_element_set_state (conference, GST_STATE_PLAYING);
2203 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2204 GstElement *conference, gpointer user_data)
2206 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2207 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2209 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2210 gst_element_set_state (conference, GST_STATE_NULL);
2214 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2216 GstStateChangeReturn state_change_return;
2217 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2219 if (priv->pipeline == NULL)
2222 if (priv->bus_message_source_id != 0)
2224 g_source_remove (priv->bus_message_source_id);
2225 priv->bus_message_source_id = 0;
2228 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2230 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2231 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2233 if (priv->pipeline != NULL)
2234 g_object_unref (priv->pipeline);
2235 priv->pipeline = NULL;
2237 if (priv->audio_output != NULL)
2238 g_object_unref (priv->audio_output);
2239 priv->audio_output = NULL;
2241 if (priv->video_tee != NULL)
2242 g_object_unref (priv->video_tee);
2243 priv->video_tee = NULL;
2245 if (priv->video_preview != NULL)
2246 clutter_actor_destroy (priv->video_preview);
2247 priv->video_preview = NULL;
2249 priv->funnel = NULL;
2251 create_pipeline (self);
2252 /* Call will be started when user will hit the 'redial' button */
2253 priv->start_call_when_playing = FALSE;
2254 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2260 g_message ("Error: could not destroy pipeline. Closing call window");
2261 gtk_widget_destroy (GTK_WIDGET (self));
2268 reset_details_pane (EmpathyCallWindow *self)
2270 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2272 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2273 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2274 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2275 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2279 empathy_call_window_disconnected (EmpathyCallWindow *self,
2282 gboolean could_disconnect = FALSE;
2283 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2284 gboolean could_reset_pipeline;
2286 /* Leave full screen mode if needed */
2287 gtk_window_unfullscreen (GTK_WINDOW (self));
2289 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2290 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2292 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2294 if (priv->call_state == CONNECTING)
2295 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2297 if (priv->call_state != REDIALING)
2298 priv->call_state = DISCONNECTED;
2300 if (could_reset_pipeline)
2302 g_mutex_lock (priv->lock);
2304 g_timer_stop (priv->timer);
2306 if (priv->timer_id != 0)
2307 g_source_remove (priv->timer_id);
2310 g_mutex_unlock (priv->lock);
2313 /* We are about to destroy the window, no need to update it or create
2314 * a video preview */
2317 empathy_call_window_status_message (self, _("Disconnected"));
2319 empathy_call_window_show_hangup_button (self, FALSE);
2321 /* Unsensitive the camera and mic button */
2322 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2323 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2325 /* Be sure that the mic button is enabled */
2326 gtk_toggle_tool_button_set_active (
2327 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2329 if (priv->camera_state == CAMERA_STATE_ON)
2331 /* Restart the preview with the new pipeline. */
2332 display_video_preview (self, TRUE);
2335 /* destroy the video output; it will be recreated when we'll redial */
2336 disconnect_video_output_motion_handler (self);
2337 if (priv->video_output != NULL)
2338 clutter_actor_destroy (priv->video_output);
2339 priv->video_output = NULL;
2340 if (priv->got_video_src > 0)
2342 g_source_remove (priv->got_video_src);
2343 priv->got_video_src = 0;
2346 gtk_widget_show (priv->remote_user_avatar_widget);
2348 reset_details_pane (self);
2350 priv->sending_video = FALSE;
2351 priv->call_started = FALSE;
2353 could_disconnect = TRUE;
2355 /* TODO: display the self avatar of the preview (depends if the "Always
2356 * Show Video Preview" is enabled or not) */
2359 return could_disconnect;
2364 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2367 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2368 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2370 if (empathy_call_window_disconnected (self, TRUE) &&
2371 priv->call_state == REDIALING)
2372 empathy_call_window_restart_call (self);
2376 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2378 FsMediaType media_type,
2379 EmpathyCallWindow *self)
2381 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2383 DEBUG ("removing content");
2386 * This assumes that there is only one video stream per channel...
2389 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2391 if (priv->funnel != NULL)
2395 output = priv->video_output_sink;
2397 gst_element_set_state (output, GST_STATE_NULL);
2398 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2400 gst_bin_remove (GST_BIN (priv->pipeline), output);
2401 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2402 priv->funnel = NULL;
2406 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2408 if (priv->audio_output != NULL)
2410 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2412 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2413 priv->audio_output = NULL;
2421 /* Called with global lock held */
2423 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2425 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2429 if (priv->funnel == NULL)
2431 output = priv->video_output_sink;
2433 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2437 g_warning ("Could not create fsfunnel");
2441 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2443 gst_object_unref (priv->funnel);
2444 priv->funnel = NULL;
2445 g_warning ("Could not add funnel to pipeline");
2449 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2451 g_warning ("Could not add the video output widget to the pipeline");
2455 if (!gst_element_link (priv->funnel, output))
2457 g_warning ("Could not link output sink to funnel");
2458 goto error_output_added;
2461 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2463 g_warning ("Could not start video sink");
2464 goto error_output_added;
2467 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2469 g_warning ("Could not start funnel");
2470 goto error_output_added;
2474 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2477 g_warning ("Could not get request pad from funnel");
2484 gst_element_set_locked_state (priv->funnel, TRUE);
2485 gst_element_set_locked_state (output, TRUE);
2487 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2488 gst_element_set_state (output, GST_STATE_NULL);
2490 gst_bin_remove (GST_BIN (priv->pipeline), output);
2491 gst_element_set_locked_state (output, FALSE);
2495 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2496 priv->funnel = NULL;
2501 /* Called with global lock held */
2503 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2505 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2507 GstPadTemplate *template;
2509 if (priv->audio_output == NULL)
2511 priv->audio_output = empathy_audio_sink_new ();
2512 g_object_ref_sink (priv->audio_output);
2514 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2516 g_warning ("Could not add audio sink to pipeline");
2517 g_object_unref (priv->audio_output);
2518 goto error_add_output;
2521 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2523 g_warning ("Could not start audio sink");
2528 template = gst_element_class_get_pad_template (
2529 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2531 pad = gst_element_request_pad (priv->audio_output,
2532 template, NULL, NULL);
2536 g_warning ("Could not get sink pad from sink");
2543 gst_element_set_locked_state (priv->audio_output, TRUE);
2544 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2545 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2546 priv->audio_output = NULL;
2554 empathy_call_window_update_timer (gpointer user_data)
2556 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2557 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2558 const gchar *status;
2562 time_ = g_timer_elapsed (priv->timer, NULL);
2564 if (priv->call_state == HELD)
2565 status = _("On hold");
2566 else if (!gtk_toggle_tool_button_get_active (
2567 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2570 status = _("Duration");
2572 /* Translators: 'status - minutes:seconds' the caller has been connected */
2573 str = g_strdup_printf (_("%s — %d:%02dm"),
2575 (int) time_ / 60, (int) time_ % 60);
2576 empathy_call_window_status_message (self, str);
2584 display_error (EmpathyCallWindow *self,
2585 TpyCallChannel *call,
2589 const gchar *details)
2591 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2592 GtkWidget *info_bar;
2593 GtkWidget *content_area;
2600 /* Create info bar */
2601 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2604 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2606 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2608 /* hbox containing the image and the messages vbox */
2609 hbox = gtk_hbox_new (FALSE, 3);
2610 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2613 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2614 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2616 /* vbox containing the main message and the details expander */
2617 vbox = gtk_vbox_new (FALSE, 3);
2618 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2621 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2623 label = gtk_label_new (NULL);
2624 gtk_label_set_markup (GTK_LABEL (label), txt);
2625 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2626 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2629 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2632 if (details != NULL)
2634 GtkWidget *expander;
2636 expander = gtk_expander_new (_("Technical Details"));
2638 txt = g_strdup_printf ("<i>%s</i>", details);
2640 label = gtk_label_new (NULL);
2641 gtk_label_set_markup (GTK_LABEL (label), txt);
2642 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2643 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2646 gtk_container_add (GTK_CONTAINER (expander), label);
2647 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2650 g_signal_connect (info_bar, "response",
2651 G_CALLBACK (gtk_widget_destroy), NULL);
2653 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2654 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2655 gtk_widget_show_all (info_bar);
2659 media_stream_error_to_txt (EmpathyCallWindow *self,
2660 TpyCallChannel *call,
2662 TpMediaStreamError error)
2664 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2665 const gchar *cm = NULL;
2671 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2673 return g_strdup_printf (
2674 _("%s's software does not understand any of the audio formats "
2675 "supported by your computer"),
2676 empathy_contact_get_alias (priv->contact));
2678 return g_strdup_printf (
2679 _("%s's software does not understand any of the video formats "
2680 "supported by your computer"),
2681 empathy_contact_get_alias (priv->contact));
2683 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2684 return g_strdup_printf (
2685 _("Can't establish a connection to %s. "
2686 "One of you might be on a network that does not allow "
2687 "direct connections."),
2688 empathy_contact_get_alias (priv->contact));
2690 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2691 return g_strdup (_("There was a failure on the network"));
2693 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2695 return g_strdup (_("The audio formats necessary for this call "
2696 "are not installed on your computer"));
2698 return g_strdup (_("The video formats necessary for this call "
2699 "are not installed on your computer"));
2701 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2702 tp_connection_parse_object_path (
2703 tp_channel_borrow_connection (TP_CHANNEL (call)),
2706 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2707 "product=Telepathy&component=%s", cm);
2709 result = g_strdup_printf (
2710 _("Something unexpected happened in a Telepathy component. "
2711 "Please <a href=\"%s\">report this bug</a> and attach "
2712 "logs gathered from the 'Debug' window in the Help menu."), url);
2718 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2719 return g_strdup (_("There was a failure in the call engine"));
2721 case TP_MEDIA_STREAM_ERROR_EOS:
2722 return g_strdup (_("The end of the stream was reached"));
2724 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2731 empathy_call_window_stream_error (EmpathyCallWindow *self,
2732 TpyCallChannel *call,
2741 desc = media_stream_error_to_txt (self, call, audio, code);
2744 /* No description, use the error message. That's not great as it's not
2745 * localized but it's better than nothing. */
2746 display_error (self, call, icon, title, msg, NULL);
2750 display_error (self, call, icon, title, desc, msg);
2756 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2759 EmpathyCallWindow *self)
2761 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2762 "gnome-stock-mic", _("Can't establish audio stream"));
2766 empathy_call_window_video_stream_error (TpyCallChannel *call,
2769 EmpathyCallWindow *self)
2771 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2772 "camera-web", _("Can't establish video stream"));
2777 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2779 EmpathyCallWindow *self)
2781 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2782 TpyCallChannel *call;
2783 gboolean can_send_video;
2785 if (state != TPY_CALL_STATE_ACCEPTED)
2788 if (priv->call_state == CONNECTED)
2791 g_timer_start (priv->timer);
2792 priv->call_state = CONNECTED;
2794 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2796 can_send_video = priv->video_input != NULL &&
2797 empathy_contact_can_voip_video (priv->contact) &&
2798 empathy_camera_monitor_get_available (priv->camera_monitor);
2800 g_object_get (priv->handler, "call-channel", &call, NULL);
2802 if (tpy_call_channel_has_dtmf (call))
2803 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2805 if (priv->video_input == NULL)
2806 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2808 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2810 empathy_call_window_show_hangup_button (self, TRUE);
2812 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2814 clutter_actor_hide (priv->video_output);
2815 gtk_widget_show (priv->remote_user_avatar_widget);
2817 g_object_unref (call);
2819 g_mutex_lock (priv->lock);
2821 priv->timer_id = g_timeout_add_seconds (1,
2822 empathy_call_window_update_timer, self);
2824 g_mutex_unlock (priv->lock);
2826 empathy_call_window_update_timer (self);
2828 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2832 empathy_call_window_show_video_output_cb (gpointer user_data)
2834 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2836 if (self->priv->video_output != NULL)
2838 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2839 clutter_actor_show (self->priv->video_output);
2840 empathy_call_window_raise_actors (self);
2847 empathy_call_window_check_video_cb (gpointer data)
2849 EmpathyCallWindow *self = data;
2851 if (self->priv->got_video)
2853 self->priv->got_video = FALSE;
2857 /* No video in the last N seconds, display the remote avatar */
2858 empathy_call_window_show_video_output (self, FALSE);
2863 /* Called from the streaming thread */
2865 empathy_call_window_video_probe_cb (GstPad *pad,
2866 GstMiniObject *mini_obj,
2867 EmpathyCallWindow *self)
2870 if (GST_IS_EVENT (mini_obj))
2873 if (G_UNLIKELY (!self->priv->got_video))
2875 /* show the remote video */
2876 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2877 empathy_call_window_show_video_output_cb,
2878 g_object_ref (self), g_object_unref);
2880 self->priv->got_video = TRUE;
2886 /* Called from the streaming thread */
2888 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2889 GstPad *src, guint media_type, gpointer user_data)
2891 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2892 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2893 gboolean retval = FALSE;
2897 g_mutex_lock (priv->lock);
2901 case TP_MEDIA_STREAM_TYPE_AUDIO:
2902 pad = empathy_call_window_get_audio_sink_pad (self);
2904 case TP_MEDIA_STREAM_TYPE_VIDEO:
2905 g_idle_add (empathy_call_window_show_video_output_cb, self);
2906 pad = empathy_call_window_get_video_sink_pad (self);
2908 gst_pad_add_data_probe (src,
2909 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2910 if (priv->got_video_src > 0)
2911 g_source_remove (priv->got_video_src);
2912 priv->got_video_src = g_timeout_add_seconds (5,
2913 empathy_call_window_check_video_cb, self);
2916 g_assert_not_reached ();
2922 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2923 g_warning ("Could not link %s sink pad",
2924 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2928 gst_object_unref (pad);
2932 /* If no sink could be linked, try to add fakesink to prevent the whole call
2937 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2939 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2941 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2942 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2943 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2945 gst_element_set_locked_state (fakesink, TRUE);
2946 gst_element_set_state (fakesink, GST_STATE_NULL);
2947 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2951 DEBUG ("Could not link real sink, linked fakesink instead");
2953 gst_object_unref (sinkpad);
2957 gst_object_unref (fakesink);
2962 g_mutex_unlock (priv->lock);
2968 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2969 GstPad *sink, FsMediaType media_type, gpointer user_data)
2971 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2972 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2974 gboolean retval = FALSE;
2978 case FS_MEDIA_TYPE_AUDIO:
2979 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2981 g_warning ("Could not add audio source to pipeline");
2985 pad = gst_element_get_static_pad (priv->audio_input, "src");
2988 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2989 g_warning ("Could not get source pad from audio source");
2993 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2995 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2996 g_warning ("Could not link audio source to farsight");
3000 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3002 g_warning ("Could not start audio source");
3003 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3004 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3010 case FS_MEDIA_TYPE_VIDEO:
3011 if (priv->video_tee != NULL)
3013 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3014 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3016 g_warning ("Could not link video source input pipeline");
3019 gst_object_unref (pad);
3025 g_assert_not_reached ();
3032 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3034 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3035 GstElement *preview;
3037 disable_camera (self);
3039 DEBUG ("remove video input");
3040 preview = priv->video_preview_sink;
3042 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3043 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3044 gst_element_set_state (preview, GST_STATE_NULL);
3046 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3049 g_object_unref (priv->video_input);
3050 priv->video_input = NULL;
3051 g_object_unref (priv->video_tee);
3052 priv->video_tee = NULL;
3053 clutter_actor_destroy (priv->video_preview);
3054 priv->video_preview = NULL;
3056 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3060 start_call (EmpathyCallWindow *self)
3062 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3064 priv->call_started = TRUE;
3065 empathy_call_handler_start_call (priv->handler,
3066 gtk_get_current_event_time ());
3068 if (empathy_call_handler_has_initial_video (priv->handler))
3070 TpyCallChannel *call;
3073 g_object_get (priv->handler, "call-channel", &call, NULL);
3074 s = tpy_call_channel_get_video_state (call);
3076 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3077 s == TPY_SENDING_STATE_SENDING)
3079 /* Enable 'send video' buttons and display the preview */
3080 gtk_toggle_tool_button_set_active (
3081 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3085 gtk_toggle_tool_button_set_active (
3086 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3088 if (priv->video_preview == NULL)
3090 create_video_preview (self);
3091 add_video_preview_to_pipeline (self);
3095 g_object_unref (call);
3100 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3103 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3104 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3107 empathy_call_handler_bus_message (priv->handler, bus, message);
3109 switch (GST_MESSAGE_TYPE (message))
3111 case GST_MESSAGE_STATE_CHANGED:
3112 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3114 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3116 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3117 !priv->call_started)
3119 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3120 if (newstate == GST_STATE_PAUSED)
3122 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3123 priv->pipeline_playing = TRUE;
3125 if (priv->start_call_when_playing)
3130 case GST_MESSAGE_ERROR:
3132 GError *error = NULL;
3133 GstElement *gst_error;
3136 gst_message_parse_error (message, &error, &debug);
3137 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3139 g_message ("Element error: %s -- %s\n", error->message, debug);
3141 if (g_str_has_prefix (gst_element_get_name (gst_error),
3142 VIDEO_INPUT_ERROR_PREFIX))
3144 /* Remove the video input and continue */
3145 if (priv->video_input != NULL)
3146 empathy_call_window_remove_video_input (self);
3147 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3151 empathy_call_window_disconnected (self, TRUE);
3153 g_error_free (error);
3156 case GST_MESSAGE_UNKNOWN:
3157 case GST_MESSAGE_EOS:
3158 case GST_MESSAGE_WARNING:
3159 case GST_MESSAGE_INFO:
3160 case GST_MESSAGE_TAG:
3161 case GST_MESSAGE_BUFFERING:
3162 case GST_MESSAGE_STATE_DIRTY:
3163 case GST_MESSAGE_STEP_DONE:
3164 case GST_MESSAGE_CLOCK_PROVIDE:
3165 case GST_MESSAGE_CLOCK_LOST:
3166 case GST_MESSAGE_NEW_CLOCK:
3167 case GST_MESSAGE_STRUCTURE_CHANGE:
3168 case GST_MESSAGE_STREAM_STATUS:
3169 case GST_MESSAGE_APPLICATION:
3170 case GST_MESSAGE_ELEMENT:
3171 case GST_MESSAGE_SEGMENT_START:
3172 case GST_MESSAGE_SEGMENT_DONE:
3173 case GST_MESSAGE_DURATION:
3174 case GST_MESSAGE_ANY:
3183 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3184 GHashTable *members,
3185 EmpathyCallWindow *self)
3187 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3188 GHashTableIter iter;
3189 gpointer key, value;
3190 gboolean held = FALSE;
3192 g_hash_table_iter_init (&iter, members);
3193 while (g_hash_table_iter_next (&iter, &key, &value))
3195 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3197 /* This assumes this is a 1-1 call, otherwise one participant
3198 * putting the call on hold wouldn't mean the call is on hold
3206 priv->call_state = HELD;
3207 else if (priv->call_state == HELD)
3208 priv->call_state = CONNECTED;
3212 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3214 EmpathyCallWindow *self)
3216 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3217 TpyCallChannel *call;
3219 g_object_get (priv->handler, "call-channel", &call, NULL);
3224 tp_g_signal_connect_object (call, "audio-stream-error",
3225 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3226 tp_g_signal_connect_object (call, "video-stream-error",
3227 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3230 tp_g_signal_connect_object (call, "members-changed",
3231 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3233 g_object_unref (call);
3237 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3239 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3240 TpyCallChannel *call;
3243 /* Make the hangup button twice as wide */
3244 width = gtk_widget_get_allocated_width (priv->hangup_button);
3245 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3247 g_signal_connect (priv->handler, "state-changed",
3248 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3249 g_signal_connect (priv->handler, "conference-added",
3250 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3251 g_signal_connect (priv->handler, "conference-removed",
3252 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3253 g_signal_connect (priv->handler, "closed",
3254 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3255 g_signal_connect (priv->handler, "src-pad-added",
3256 G_CALLBACK (empathy_call_window_src_added_cb), window);
3257 g_signal_connect (priv->handler, "sink-pad-added",
3258 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3259 g_signal_connect (priv->handler, "sink-pad-removed",
3260 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3262 g_object_get (priv->handler, "call-channel", &call, NULL);
3265 call_handler_notify_call_cb (priv->handler, NULL, window);
3266 g_object_unref (call);
3270 /* call-channel doesn't exist yet, we'll connect signals once it has been
3272 g_signal_connect (priv->handler, "notify::call-channel",
3273 G_CALLBACK (call_handler_notify_call_cb), window);
3276 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3280 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3281 EmpathyCallWindow *window)
3283 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3285 if (priv->pipeline != NULL)
3287 if (priv->bus_message_source_id != 0)
3289 g_source_remove (priv->bus_message_source_id);
3290 priv->bus_message_source_id = 0;
3293 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3296 if (priv->call_state == CONNECTING)
3297 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3303 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3306 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3308 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3313 gtk_widget_hide (priv->dtmf_panel);
3314 gtk_widget_hide (menu);
3315 gtk_widget_hide (priv->toolbar);
3319 if (priv->dialpad_was_visible_before_fs)
3320 gtk_widget_show (priv->dtmf_panel);
3322 gtk_widget_show (menu);
3323 gtk_widget_show (priv->toolbar);
3325 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3326 priv->original_height_before_fs);
3331 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3333 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3335 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3336 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3337 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3338 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3340 if (priv->video_output != NULL)
3343 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3344 priv->video_output, TRUE, TRUE,
3345 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3352 empathy_call_window_state_event_cb (GtkWidget *widget,
3353 GdkEventWindowState *event, EmpathyCallWindow *window)
3355 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3357 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3358 gboolean set_fullscreen = event->new_window_state &
3359 GDK_WINDOW_STATE_FULLSCREEN;
3363 gboolean dialpad_was_visible;
3364 GtkAllocation allocation;
3365 gint original_width, original_height;
3367 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3368 original_width = allocation.width;
3369 original_height = allocation.height;
3371 g_object_get (priv->dtmf_panel,
3372 "visible", &dialpad_was_visible,
3375 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3376 priv->original_width_before_fs = original_width;
3377 priv->original_height_before_fs = original_height;
3379 if (priv->video_output_motion_handler_id == 0 &&
3380 priv->video_output != NULL)
3382 priv->video_output_motion_handler_id = g_signal_connect (
3383 G_OBJECT (priv->video_container), "motion-notify-event",
3384 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3390 disconnect_video_output_motion_handler (window);
3393 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3395 show_controls (window, set_fullscreen);
3396 show_borders (window, set_fullscreen);
3397 gtk_action_set_stock_id (priv->menu_fullscreen,
3398 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3399 priv->is_fullscreen = set_fullscreen;
3406 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3409 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3410 int w, h, dialpad_width;
3411 GtkAllocation allocation;
3413 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3414 w = allocation.width;
3415 h = allocation.height;
3417 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3421 gtk_widget_show (priv->dtmf_panel);
3427 gtk_widget_hide (priv->dtmf_panel);
3431 gtk_window_resize (GTK_WINDOW (window), w, h);
3435 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3438 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3439 TpyCallChannel *call;
3441 priv->sending_video = (state == CAMERA_STATE_ON);
3443 if (state == CAMERA_STATE_ON)
3445 /* When we start sending video, we want to show the video preview by
3447 display_video_preview (window, TRUE);
3451 display_video_preview (window, FALSE);
3454 if (priv->call_state != CONNECTED)
3457 g_object_get (priv->handler, "call-channel", &call, NULL);
3458 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3459 tpy_call_channel_send_video (call, priv->sending_video);
3460 g_object_unref (call);
3464 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3465 EmpathyCallWindow *self)
3467 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3470 active = (gtk_toggle_tool_button_get_active (toggle));
3472 /* We don't want the settings callback to react to this change to avoid
3474 g_signal_handlers_block_by_func (priv->settings,
3475 empathy_call_window_prefs_volume_changed_cb, self);
3479 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3480 priv->volume * 100);
3484 /* TODO, Instead of setting the input volume to 0 we should probably
3485 * stop sending but this would cause the audio call to drop if both
3486 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3487 * in the future. GNOME #574574
3489 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3493 g_signal_handlers_unblock_by_func (priv->settings,
3494 empathy_call_window_prefs_volume_changed_cb, self);
3498 empathy_call_window_hangup_cb (gpointer object,
3499 EmpathyCallWindow *self)
3501 empathy_call_handler_stop_call (self->priv->handler);
3503 empathy_call_window_disconnected (self, TRUE);
3507 empathy_call_window_restart_call (EmpathyCallWindow *window)
3509 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3511 /* Remove error info bars */
3512 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3513 (GtkCallback) gtk_widget_destroy, NULL);
3515 create_video_output_widget (window);
3517 /* While the call was disconnected, the input volume might have changed.
3518 * However, since the audio_input source was destroyed, its volume has not
3519 * been updated during that time. That's why we manually update it here */
3520 empathy_call_window_mic_volume_changed (window);
3522 priv->outgoing = TRUE;
3523 empathy_call_window_set_state_connecting (window);
3525 if (priv->pipeline_playing)
3526 start_call (window);
3528 /* call will be started when the pipeline is ready */
3529 priv->start_call_when_playing = TRUE;
3531 empathy_call_window_setup_avatars (window, priv->handler);
3533 empathy_call_window_show_hangup_button (window, TRUE);
3537 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3538 EmpathyCallWindow *window)
3542 active = gtk_toggle_tool_button_get_active (button);
3544 empathy_call_window_show_dialpad (window, active);
3548 empathy_call_window_fullscreen_cb (gpointer object,
3549 EmpathyCallWindow *window)
3551 empathy_call_window_fullscreen_toggle (window);
3555 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3557 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3559 if (priv->is_fullscreen)
3560 gtk_window_unfullscreen (GTK_WINDOW (window));
3562 gtk_window_fullscreen (GTK_WINDOW (window));
3566 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3567 GdkEventButton *event, EmpathyCallWindow *window)
3569 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3571 empathy_call_window_video_menu_popup (window, event->button);
3579 empathy_call_window_key_press_cb (GtkWidget *video_output,
3580 GdkEventKey *event, EmpathyCallWindow *window)
3582 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3584 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3586 /* Since we are in fullscreen mode, toggling will bring us back to
3588 empathy_call_window_fullscreen_toggle (window);
3596 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3597 GdkEventMotion *event, EmpathyCallWindow *window)
3599 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3601 if (priv->is_fullscreen)
3603 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3605 /* Show the bottom toolbar */
3606 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3613 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3617 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3619 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3621 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3622 button, gtk_get_current_event_time ());
3623 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3627 empathy_call_window_status_message (EmpathyCallWindow *self,
3630 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3634 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3635 gdouble value, EmpathyCallWindow *window)
3637 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3639 if (priv->audio_output == NULL)
3642 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3647 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3649 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3651 return priv->ui_manager;
3654 EmpathyGstAudioSrc *
3655 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3657 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3659 return (EmpathyGstAudioSrc *) priv->audio_input;
3662 EmpathyGstVideoSrc *
3663 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3665 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);