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_HEIGTH 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 GtkWidget *video_container;
148 GtkWidget *remote_user_avatar_widget;
149 GtkWidget *remote_user_avatar_toolbar;
150 GtkWidget *remote_user_name_toolbar;
151 GtkWidget *status_label;
152 GtkWidget *hangup_button;
153 GtkWidget *audio_call_button;
154 GtkWidget *video_call_button;
155 GtkWidget *mic_button;
156 GtkWidget *camera_button;
157 GtkWidget *dialpad_button;
159 GtkWidget *bottom_toolbar;
160 ClutterActor *floating_toolbar;
162 GtkAction *menu_fullscreen;
163 GtkAction *menu_swap_camera;
165 ClutterState *transitions;
167 /* The box that contains self and remote avatar and video
168 input/output. When we redial, we destroy and re-create the box */
169 ClutterActor *video_box;
170 ClutterLayoutManager *video_layout;
172 /* Coordinates of the preview drag event's start. */
173 PreviewPosition preview_pos;
177 /* We keep a reference on the hbox which contains the main content so we can
178 easilly repack everything when toggling fullscreen */
179 GtkWidget *content_hbox;
181 gulong video_output_motion_handler_id;
182 guint bus_message_source_id;
186 GtkWidget *dtmf_panel;
189 GtkWidget *details_vbox;
190 GtkWidget *vcodec_encoding_label;
191 GtkWidget *acodec_encoding_label;
192 GtkWidget *vcodec_decoding_label;
193 GtkWidget *acodec_decoding_label;
195 GtkWidget *audio_remote_candidate_label;
196 GtkWidget *audio_local_candidate_label;
197 GtkWidget *video_remote_candidate_label;
198 GtkWidget *video_local_candidate_label;
199 GtkWidget *video_remote_candidate_info_img;
200 GtkWidget *video_local_candidate_info_img;
201 GtkWidget *audio_remote_candidate_info_img;
202 GtkWidget *audio_local_candidate_info_img;
204 GstElement *video_input;
205 GstElement *video_preview_sink;
206 GstElement *video_output_sink;
207 GstElement *audio_input;
208 GstElement *audio_output;
209 GstElement *pipeline;
210 GstElement *video_tee;
220 gboolean call_started;
221 gboolean sending_video;
222 CameraState camera_state;
224 EmpathyCallWindowFullscreen *fullscreen;
225 gboolean is_fullscreen;
230 guint inactivity_src;
232 /* Those fields represent the state of the window before it actually was in
234 gboolean dialpad_was_visible_before_fs;
235 gint original_width_before_fs;
236 gint original_height_before_fs;
238 gint x, y, w, h, dialpad_width;
241 /* TRUE if the call should be started when the pipeline is playing */
242 gboolean start_call_when_playing;
243 /* TRUE if we requested to set the pipeline in the playing state */
244 gboolean pipeline_playing;
246 EmpathySoundManager *sound_mgr;
249 EmpathyMicMenu *mic_menu;
250 EmpathyCameraMenu *camera_menu;
253 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
255 static void empathy_call_window_realized_cb (GtkWidget *widget,
256 EmpathyCallWindow *window);
258 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
259 GdkEvent *event, EmpathyCallWindow *window);
261 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
262 GdkEventWindowState *event, EmpathyCallWindow *window);
264 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
267 static void empathy_call_window_mic_toggled_cb (
268 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
270 static void empathy_call_window_hangup_cb (gpointer object,
271 EmpathyCallWindow *window);
273 static void empathy_call_window_fullscreen_cb (gpointer object,
274 EmpathyCallWindow *window);
276 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
278 static gboolean empathy_call_window_video_button_press_cb (
279 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
281 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
282 GdkEventKey *event, EmpathyCallWindow *window);
284 static gboolean empathy_call_window_video_output_motion_notify (
285 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
287 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
290 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
291 EmpathyCallWindow *window);
293 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
295 static void empathy_call_window_status_message (EmpathyCallWindow *window,
298 static gboolean empathy_call_window_bus_message (GstBus *bus,
299 GstMessage *message, gpointer user_data);
302 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
303 gdouble value, EmpathyCallWindow *window);
306 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
309 gtk_widget_set_visible (self->priv->hangup_button, show);
310 gtk_widget_set_visible (self->priv->audio_call_button, !show);
311 gtk_widget_set_visible (self->priv->video_call_button, !show);
315 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
316 EmpathyCallWindow *self)
318 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
319 empathy_call_window_restart_call (self);
323 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
324 EmpathyCallWindow *self)
326 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
327 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
328 empathy_call_window_restart_call (self);
332 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
334 EmpathyCallWindowPriv *priv = GET_PRIV (window);
335 TpyCallChannel *call;
339 g_object_get (priv->handler, "call-channel", &call, NULL);
341 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
342 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
345 tpy_call_channel_dtmf_start_tone (call, event);
347 g_object_unref (call);
351 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
353 EmpathyCallWindowPriv *priv = GET_PRIV (window);
354 TpyCallChannel *call;
356 g_object_get (priv->handler, "call-channel", &call, NULL);
358 tpy_call_channel_dtmf_stop_tone (call);
360 g_object_unref (call);
364 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
366 EmpathyCallWindowPriv *priv = GET_PRIV (self);
369 volume = g_settings_get_double (priv->settings,
370 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
372 /* Don't store the volume because of muting */
373 if (volume > 0 || gtk_toggle_tool_button_get_active (
374 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
375 priv->volume = volume;
377 /* Ensure that the toggle button is active if the volume is > 0 and inactive
378 * if it's smaller than 0 */
379 if ((volume > 0) != gtk_toggle_tool_button_get_active (
380 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
381 gtk_toggle_tool_button_set_active (
382 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
384 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
389 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
391 EmpathyCallWindow *self)
393 empathy_call_window_mic_volume_changed (self);
397 empathy_call_window_show_video_output (EmpathyCallWindow *self,
400 if (self->priv->video_output != NULL)
401 g_object_set (self->priv->video_output, "visible", show, NULL);
403 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
405 clutter_actor_raise_top (self->priv->floating_toolbar);
409 create_video_output_widget (EmpathyCallWindow *self)
411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
413 g_assert (priv->video_output == NULL);
414 g_assert (priv->pipeline != NULL);
416 priv->video_output = clutter_texture_new ();
418 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
421 priv->video_output_sink = clutter_gst_video_sink_new (
422 CLUTTER_TEXTURE (priv->video_output));
424 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
427 gtk_widget_add_events (priv->video_container,
428 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
429 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
430 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
434 create_video_input (EmpathyCallWindow *self)
436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
438 g_assert (priv->video_input == NULL);
439 priv->video_input = empathy_video_src_new ();
440 gst_object_ref (priv->video_input);
441 gst_object_sink (priv->video_input);
445 create_audio_input (EmpathyCallWindow *self)
447 EmpathyCallWindowPriv *priv = GET_PRIV (self);
449 g_assert (priv->audio_input == NULL);
450 priv->audio_input = empathy_audio_src_new ();
451 gst_object_ref (priv->audio_input);
452 gst_object_sink (priv->audio_input);
456 add_video_preview_to_pipeline (EmpathyCallWindow *self)
458 EmpathyCallWindowPriv *priv = GET_PRIV (self);
461 g_assert (priv->video_preview != NULL);
462 g_assert (priv->pipeline != NULL);
463 g_assert (priv->video_input != NULL);
464 g_assert (priv->video_tee != NULL);
466 preview = priv->video_preview_sink;
468 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
470 g_warning ("Could not add video input to pipeline");
474 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
476 g_warning ("Could not add video preview to pipeline");
480 if (!gst_element_link (priv->video_input, priv->video_tee))
482 g_warning ("Could not link video input to video tee");
486 if (!gst_element_link (priv->video_tee, preview))
488 g_warning ("Could not link video tee to video preview");
494 empathy_call_window_disable_camera_cb (GtkAction *action,
495 EmpathyCallWindow *self)
497 clutter_actor_destroy (self->priv->preview_hidden_button);
499 gtk_toggle_tool_button_set_active (
500 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
504 empathy_call_window_minimise_camera_cb (GtkAction *action,
505 EmpathyCallWindow *self)
507 clutter_actor_hide (self->priv->video_preview);
508 clutter_actor_show (self->priv->preview_hidden_button);
512 empathy_call_window_maximise_camera_cb (GtkAction *action,
513 EmpathyCallWindow *self)
515 clutter_actor_show (self->priv->video_preview);
516 clutter_actor_hide (self->priv->preview_hidden_button);
520 empathy_call_window_swap_camera_cb (GtkAction *action,
521 EmpathyCallWindow *self)
523 const GList *cameras, *l;
526 DEBUG ("Swapping the camera");
528 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
529 current_cam = empathy_video_src_dup_device (
530 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
532 for (l = cameras; l != NULL; l = l->next)
534 EmpathyCamera *camera = l->data;
536 if (!tp_strdiff (camera->device, current_cam))
541 next = l->next->data;
543 next = cameras->data;
545 /* EmpathyCameraMenu will update itself and do the actual change
547 g_settings_set_string (self->priv->settings,
548 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
555 g_free (current_cam);
559 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
560 EmpathyCamera *camera,
561 EmpathyCallWindow *self)
563 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
565 gtk_action_set_visible (self->priv->menu_swap_camera,
566 g_list_length ((GList *) cameras) >= 2);
570 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
571 EmpathyCamera *camera,
572 EmpathyCallWindow *self)
574 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
576 gtk_action_set_visible (self->priv->menu_swap_camera,
577 g_list_length ((GList *) cameras) >= 2);
581 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
582 EmpathyCallWindow *self)
586 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
588 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
589 0, gtk_get_current_event_time ());
590 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
594 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
595 EmpathyCallWindow *self)
599 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
600 "/preview-hidden-menu");
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);
606 static ClutterActor *
607 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
608 ClutterBinAlignment x,
609 ClutterBinAlignment y)
611 ClutterLayoutManager *layout1, *layout2;
612 ClutterActor *rectangle;
613 ClutterActor *box1, *box2;
615 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
616 CLUTTER_BIN_ALIGNMENT_START);
618 box1 = clutter_box_new (layout1);
620 rectangle = clutter_rectangle_new_with_color (
621 CLUTTER_COLOR_Transparent);
623 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
626 clutter_actor_set_size (box1,
627 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
628 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
629 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
631 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
632 CLUTTER_BIN_ALIGNMENT_CENTER);
634 /* We have a box with the margins and the video in the middle inside
635 * a bigger box with an extra bottom margin so we're not on top of
636 * the floating toolbar. */
637 box2 = clutter_box_new (layout2);
639 clutter_actor_set_size (box2,
640 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
641 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN);
643 clutter_actor_set_size (rectangle,
644 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGTH + 5);
646 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
647 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
649 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
652 clutter_actor_hide (rectangle);
658 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
660 self->priv->preview_rectangle1 =
661 empathy_call_window_create_preview_rectangle (self,
662 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
663 self->priv->preview_rectangle2 =
664 empathy_call_window_create_preview_rectangle (self,
665 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
666 self->priv->preview_rectangle3 =
667 empathy_call_window_create_preview_rectangle (self,
668 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
669 self->priv->preview_rectangle4 =
670 empathy_call_window_create_preview_rectangle (self,
671 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
675 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
678 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
679 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
680 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
681 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
684 static PreviewPosition
685 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
690 PreviewPosition pos = PREVIEW_POS_NONE;
692 clutter_actor_get_geometry (self->priv->video_box, &box);
694 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
695 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
696 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
697 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
699 pos = PREVIEW_POS_TOP_LEFT;
701 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
702 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
703 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
704 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
706 pos = PREVIEW_POS_TOP_RIGHT;
708 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
709 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
710 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
711 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGTH))
713 pos = PREVIEW_POS_BOTTOM_LEFT;
715 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
716 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
717 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
718 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGTH))
720 pos = PREVIEW_POS_BOTTOM_RIGHT;
726 static ClutterActor *
727 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
730 ClutterActor *rectangle;
734 case PREVIEW_POS_TOP_LEFT:
735 rectangle = self->priv->preview_rectangle1;
737 case PREVIEW_POS_TOP_RIGHT:
738 rectangle = self->priv->preview_rectangle3;
740 case PREVIEW_POS_BOTTOM_LEFT:
741 rectangle = self->priv->preview_rectangle2;
743 case PREVIEW_POS_BOTTOM_RIGHT:
744 rectangle = self->priv->preview_rectangle4;
754 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
757 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
759 DEBUG ("moving the video preview to %d", pos);
761 self->priv->preview_pos = pos;
765 case PREVIEW_POS_TOP_LEFT:
766 clutter_bin_layout_set_alignment (layout,
767 self->priv->video_preview,
768 CLUTTER_BIN_ALIGNMENT_START,
769 CLUTTER_BIN_ALIGNMENT_START);
771 case PREVIEW_POS_TOP_RIGHT:
772 clutter_bin_layout_set_alignment (layout,
773 self->priv->video_preview,
774 CLUTTER_BIN_ALIGNMENT_END,
775 CLUTTER_BIN_ALIGNMENT_START);
777 case PREVIEW_POS_BOTTOM_LEFT:
778 clutter_bin_layout_set_alignment (layout,
779 self->priv->video_preview,
780 CLUTTER_BIN_ALIGNMENT_START,
781 CLUTTER_BIN_ALIGNMENT_END);
783 case PREVIEW_POS_BOTTOM_RIGHT:
784 clutter_bin_layout_set_alignment (layout,
785 self->priv->video_preview,
786 CLUTTER_BIN_ALIGNMENT_END,
787 CLUTTER_BIN_ALIGNMENT_END);
790 g_warn_if_reached ();
795 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
798 ClutterActor *rectangle;
800 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
802 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
803 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
808 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
809 ClutterActor *rectangle)
811 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
812 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
813 CLUTTER_COLOR_Black);
817 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
819 ClutterActor *rectangle;
821 rectangle = empathy_call_window_get_preview_rectangle (self,
822 self->priv->preview_pos);
824 /* We don't want to darken the rectangle where the preview
827 if (self->priv->preview_rectangle1 != rectangle)
828 empathy_call_window_darken_preview_rectangle (self,
829 self->priv->preview_rectangle1);
831 if (self->priv->preview_rectangle2 != rectangle)
832 empathy_call_window_darken_preview_rectangle (self,
833 self->priv->preview_rectangle2);
835 if (self->priv->preview_rectangle3 != rectangle)
836 empathy_call_window_darken_preview_rectangle (self,
837 self->priv->preview_rectangle3);
839 if (self->priv->preview_rectangle4 != rectangle)
840 empathy_call_window_darken_preview_rectangle (self,
841 self->priv->preview_rectangle4);
845 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
849 ClutterModifierType modifiers,
850 EmpathyCallWindow *self)
852 empathy_call_window_show_preview_rectangles (self, TRUE);
853 empathy_call_window_darken_preview_rectangles (self);
855 self->priv->event_x = event_x;
856 self->priv->event_y = event_y;
860 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
864 ClutterModifierType modifiers,
865 EmpathyCallWindow *self)
869 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
871 if (pos != PREVIEW_POS_NONE)
872 empathy_call_window_move_video_preview (self, pos);
874 empathy_call_window_show_preview_rectangles (self, FALSE);
878 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
882 EmpathyCallWindow *self)
886 pos = empathy_call_window_get_preview_position (self,
887 self->priv->event_x - delta_x, self->priv->event_y + delta_y);
889 if (pos != PREVIEW_POS_NONE)
890 empathy_call_window_highlight_preview_rectangle (self, pos);
892 empathy_call_window_darken_preview_rectangles (self);
896 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
897 ClutterCrossingEvent *event,
898 EmpathyCallWindow *self)
900 ClutterActor *rectangle;
903 pos = empathy_call_window_get_preview_position (self, event->x, event->y);
904 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
906 empathy_call_window_highlight_preview_rectangle (self, pos);
908 clutter_actor_show (rectangle);
914 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
915 ClutterCrossingEvent *event,
916 EmpathyCallWindow *self)
918 ClutterActor *rectangle;
920 rectangle = empathy_call_window_get_preview_rectangle (self,
921 self->priv->preview_pos);
923 empathy_call_window_darken_preview_rectangle (self, rectangle);
925 clutter_actor_hide (rectangle);
931 create_video_preview (EmpathyCallWindow *self)
933 EmpathyCallWindowPriv *priv = GET_PRIV (self);
934 ClutterLayoutManager *layout, *layout_center;
935 ClutterActor *preview;
938 ClutterAction *action;
941 g_assert (priv->video_preview == NULL);
943 preview = clutter_texture_new ();
944 clutter_actor_set_size (preview,
945 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
946 priv->video_preview_sink = clutter_gst_video_sink_new (
947 CLUTTER_TEXTURE (preview));
949 /* Flip the video preview */
950 clutter_actor_set_rotation (preview,
953 SELF_VIDEO_SECTION_WIDTH * 0.5,
957 /* Add a little offset to the video preview */
958 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
959 CLUTTER_BIN_ALIGNMENT_START);
960 priv->video_preview = clutter_box_new (layout);
961 clutter_actor_set_size (priv->video_preview,
962 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
963 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
964 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
966 /* We have a box with the margins and the video in the middle inside
967 * a bigger box with an extra bottom margin so we're not on top of
968 * the floating toolbar. */
969 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
970 CLUTTER_BIN_ALIGNMENT_CENTER);
971 box = clutter_box_new (layout_center);
972 clutter_actor_set_size (box,
973 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
974 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN);
976 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
977 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
979 g_object_set (priv->video_preview_sink,
984 /* Translators: this is an "Info" label. It should be as short
986 button = gtk_button_new_with_label (_("i"));
987 b = gtk_clutter_actor_new_with_contents (button);
989 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
991 CLUTTER_BIN_ALIGNMENT_END,
992 CLUTTER_BIN_ALIGNMENT_END);
994 g_signal_connect (button, "clicked",
995 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
998 /* Translators: this is an "Info" label. It should be as short
1000 button = gtk_button_new_with_label (_("i"));
1001 priv->preview_hidden_button =
1002 gtk_clutter_actor_new_with_contents (button);
1004 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1005 priv->preview_hidden_button,
1006 CLUTTER_BIN_ALIGNMENT_START,
1007 CLUTTER_BIN_ALIGNMENT_END);
1009 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1011 clutter_actor_hide (priv->preview_hidden_button);
1013 g_signal_connect (button, "clicked",
1014 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1017 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1018 priv->video_preview,
1019 CLUTTER_BIN_ALIGNMENT_START,
1020 CLUTTER_BIN_ALIGNMENT_END);
1022 action = clutter_drag_action_new ();
1023 g_signal_connect (action, "drag-begin",
1024 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1025 g_signal_connect (action, "drag-end",
1026 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1027 g_signal_connect (action, "drag-motion",
1028 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1030 g_signal_connect (preview, "enter-event",
1031 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1032 g_signal_connect (preview, "leave-event",
1033 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1035 clutter_actor_add_action (preview, action);
1036 clutter_actor_set_reactive (preview, TRUE);
1040 play_camera (EmpathyCallWindow *window,
1043 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1044 GstElement *preview;
1047 if (priv->video_preview == NULL)
1049 create_video_preview (window);
1050 add_video_preview_to_pipeline (window);
1054 state = GST_STATE_PLAYING;
1056 state = GST_STATE_NULL;
1058 preview = priv->video_preview_sink;
1060 gst_element_set_state (preview, state);
1061 gst_element_set_state (priv->video_input, state);
1062 gst_element_set_state (priv->video_tee, state);
1066 display_video_preview (EmpathyCallWindow *self,
1069 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1073 /* Display the video preview */
1074 DEBUG ("Show video preview");
1076 play_camera (self, TRUE);
1077 clutter_actor_show (priv->video_preview);
1078 clutter_actor_raise_top (priv->floating_toolbar);
1082 /* Hide the video preview */
1083 DEBUG ("Hide video preview");
1085 if (priv->video_preview != NULL)
1087 clutter_actor_hide (priv->video_preview);
1088 play_camera (self, FALSE);
1094 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1096 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1098 empathy_call_window_status_message (window, _("Connecting…"));
1099 priv->call_state = CONNECTING;
1102 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1103 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1107 disable_camera (EmpathyCallWindow *self)
1109 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1111 if (priv->camera_state == CAMERA_STATE_OFF)
1114 DEBUG ("Disable camera");
1116 display_video_preview (self, FALSE);
1118 if (priv->camera_state == CAMERA_STATE_ON)
1119 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1121 priv->camera_state = CAMERA_STATE_OFF;
1125 enable_camera (EmpathyCallWindow *self)
1127 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1129 if (priv->camera_state == CAMERA_STATE_ON)
1132 if (priv->video_input == NULL)
1134 DEBUG ("Can't enable camera, no input");
1138 DEBUG ("Enable camera");
1140 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1142 priv->camera_state = CAMERA_STATE_ON;
1146 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1147 EmpathyCallWindow *self)
1149 if (gtk_toggle_tool_button_get_active (toggle))
1150 enable_camera (self);
1152 disable_camera (self);
1156 create_pipeline (EmpathyCallWindow *self)
1158 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1161 g_assert (priv->pipeline == NULL);
1163 priv->pipeline = gst_pipeline_new (NULL);
1164 priv->pipeline_playing = FALSE;
1166 priv->video_tee = gst_element_factory_make ("tee", NULL);
1167 gst_object_ref (priv->video_tee);
1168 gst_object_sink (priv->video_tee);
1170 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1172 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1173 priv->bus_message_source_id = gst_bus_add_watch (bus,
1174 empathy_call_window_bus_message, self);
1176 g_object_unref (bus);
1180 empathy_call_window_settings_cb (GtkAction *action,
1181 EmpathyCallWindow *self)
1183 gchar *args = g_strdup_printf ("-p %s",
1184 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1186 empathy_launch_program (BIN_DIR, "empathy", args);
1192 empathy_call_window_contents_cb (GtkAction *action,
1193 EmpathyCallWindow *self)
1195 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1199 empathy_call_window_debug_cb (GtkAction *action,
1200 EmpathyCallWindow *self)
1202 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1206 empathy_call_window_about_cb (GtkAction *action,
1207 EmpathyCallWindow *self)
1209 empathy_about_dialog_new (GTK_WINDOW (self));
1213 empathy_call_window_toolbar_timeout (gpointer data)
1215 EmpathyCallWindow *self = data;
1217 clutter_state_set_state (self->priv->transitions, "fade-out");
1223 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1225 EmpathyCallWindow *self)
1227 clutter_state_set_state (self->priv->transitions, "fade-in");
1229 if (self->priv->inactivity_src > 0)
1230 g_source_remove (self->priv->inactivity_src);
1232 self->priv->inactivity_src = g_timeout_add_seconds (3,
1233 empathy_call_window_toolbar_timeout, self);
1239 empathy_call_window_configure_event_cb (GtkWidget *widget,
1241 EmpathyCallWindow *self)
1243 GdkWindow *gdk_window;
1244 GdkWindowState window_state;
1246 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1247 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1249 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1250 &self->priv->dialpad_width, NULL);
1252 gdk_window = gtk_widget_get_window (widget);
1253 window_state = gdk_window_get_state (gdk_window);
1254 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1260 empathy_call_window_destroyed_cb (GtkWidget *object,
1261 EmpathyCallWindow *self)
1263 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1265 /* Save the geometry as if the dialpad was hidden. */
1266 empathy_geometry_save_values (GTK_WINDOW (self),
1267 self->priv->x, self->priv->y,
1268 self->priv->w - self->priv->dialpad_width, self->priv->h,
1269 self->priv->maximized);
1274 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1276 ClutterBindConstraint *constraint)
1278 ClutterActorBox allocation;
1280 clutter_actor_get_allocation_box (stage, &allocation);
1282 clutter_bind_constraint_set_offset (constraint,
1283 allocation.y2 - allocation.y1 -
1284 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1288 empathy_call_window_init (EmpathyCallWindow *self)
1290 EmpathyCallWindowPriv *priv;
1292 GtkWidget *top_vbox;
1294 ClutterConstraint *constraint;
1295 ClutterActor *remote_avatar;
1296 GtkStyleContext *context;
1300 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1301 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1303 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1304 gui = empathy_builder_get_file (filename,
1305 "call_window_vbox", &top_vbox,
1306 "errors_vbox", &priv->errors_vbox,
1307 "pane", &priv->pane,
1308 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1309 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1310 "status_label", &priv->status_label,
1311 "audiocall", &priv->audio_call_button,
1312 "videocall", &priv->video_call_button,
1313 "microphone", &priv->mic_button,
1314 "camera", &priv->camera_button,
1315 "hangup", &priv->hangup_button,
1316 "dialpad", &priv->dialpad_button,
1317 "toolbar", &priv->toolbar,
1318 "bottom_toolbar", &priv->bottom_toolbar,
1319 "ui_manager", &priv->ui_manager,
1320 "menufullscreen", &priv->menu_fullscreen,
1321 "menupreviewswap", &priv->menu_swap_camera,
1322 "details_vbox", &priv->details_vbox,
1323 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1324 "acodec_encoding_label", &priv->acodec_encoding_label,
1325 "acodec_decoding_label", &priv->acodec_decoding_label,
1326 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1327 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1328 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1329 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1330 "video_local_candidate_label", &priv->video_local_candidate_label,
1331 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1332 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1333 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1334 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1338 empathy_builder_connect (gui, self,
1339 "hangup", "clicked", empathy_call_window_hangup_cb,
1340 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1341 "videocall", "clicked", empathy_call_window_video_call_cb,
1342 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1343 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1344 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1345 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1346 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1347 "menusettings", "activate", empathy_call_window_settings_cb,
1348 "menucontents", "activate", empathy_call_window_contents_cb,
1349 "menudebug", "activate", empathy_call_window_debug_cb,
1350 "menuabout", "activate", empathy_call_window_about_cb,
1351 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1352 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1353 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1354 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1357 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1359 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1361 g_object_bind_property (priv->camera_monitor, "available",
1362 priv->camera_button, "sensitive",
1363 G_BINDING_SYNC_CREATE);
1365 g_signal_connect (priv->camera_monitor, "added",
1366 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1367 g_signal_connect (priv->camera_monitor, "removed",
1368 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1370 priv->lock = g_mutex_new ();
1372 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1374 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1375 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1376 CONTENT_HBOX_BORDER_WIDTH);
1377 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1380 /* avatar/video box */
1381 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1382 CLUTTER_BIN_ALIGNMENT_CENTER);
1384 priv->video_box = clutter_box_new (priv->video_layout);
1386 priv->video_container = gtk_clutter_embed_new ();
1388 /* Set the background color to that of the rest of the window */
1389 context = gtk_widget_get_style_context (priv->content_hbox);
1390 gtk_style_context_get_background_color (context,
1391 GTK_STATE_FLAG_NORMAL, &rgba);
1392 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1393 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1394 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1395 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1396 clutter_stage_set_color (
1397 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1398 GTK_CLUTTER_EMBED (priv->video_container))),
1401 clutter_container_add (
1402 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1403 GTK_CLUTTER_EMBED (priv->video_container))),
1407 constraint = clutter_bind_constraint_new (
1408 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1409 CLUTTER_BIND_SIZE, 0);
1410 clutter_actor_add_constraint (priv->video_box, constraint);
1412 priv->remote_user_avatar_widget = gtk_image_new ();
1413 remote_avatar = gtk_clutter_actor_new_with_contents (
1414 priv->remote_user_avatar_widget);
1416 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1419 empathy_call_window_create_preview_rectangles (self);
1421 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1422 priv->video_container, TRUE, TRUE,
1423 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1425 create_pipeline (self);
1426 create_video_output_widget (self);
1427 create_audio_input (self);
1428 create_video_input (self);
1430 priv->floating_toolbar = empathy_rounded_actor_new ();
1432 gtk_widget_reparent (priv->bottom_toolbar,
1433 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1435 constraint = clutter_bind_constraint_new (
1436 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1439 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1442 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1443 "notify::allocation",
1444 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1447 clutter_actor_set_size (priv->floating_toolbar,
1448 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1449 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1451 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1452 priv->floating_toolbar,
1453 CLUTTER_BIN_ALIGNMENT_CENTER,
1454 CLUTTER_BIN_ALIGNMENT_END);
1456 clutter_actor_raise_top (priv->floating_toolbar);
1458 /* Transitions for the floating toolbar */
1459 priv->transitions = clutter_state_new ();
1461 /* all transitions last for 2s */
1462 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1464 /* transition from any state to "fade-out" state */
1465 clutter_state_set (priv->transitions, NULL, "fade-out",
1466 priv->floating_toolbar,
1467 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1470 /* transition from any state to "fade-in" state */
1471 clutter_state_set (priv->transitions, NULL, "fade-in",
1472 priv->floating_toolbar,
1473 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1476 /* put the actor into the "fade-in" state with no animation */
1477 clutter_state_warp_to_state (priv->transitions, "fade-in");
1479 /* The call will be started as soon the pipeline is playing */
1480 priv->start_call_when_playing = TRUE;
1482 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1483 G_CALLBACK (dtmf_button_pressed_cb),
1484 G_CALLBACK (dtmf_button_released_cb));
1486 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1489 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1492 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1494 gtk_widget_show_all (top_vbox);
1496 gtk_widget_hide (priv->dtmf_panel);
1497 gtk_widget_hide (priv->details_vbox);
1499 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1501 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1502 priv->video_container);
1504 /* We hide the bottom toolbar after 3s of inactivity and show it
1505 * again on mouse movement */
1506 priv->inactivity_src = g_timeout_add_seconds (3,
1507 empathy_call_window_toolbar_timeout, self);
1509 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1510 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1512 g_signal_connect (G_OBJECT (self), "realize",
1513 G_CALLBACK (empathy_call_window_realized_cb), self);
1515 g_signal_connect (G_OBJECT (self), "delete-event",
1516 G_CALLBACK (empathy_call_window_delete_cb), self);
1518 g_signal_connect (G_OBJECT (self), "window-state-event",
1519 G_CALLBACK (empathy_call_window_state_event_cb), self);
1521 g_signal_connect (G_OBJECT (self), "key-press-event",
1522 G_CALLBACK (empathy_call_window_key_press_cb), self);
1524 g_signal_connect (self, "motion-notify-event",
1525 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1527 priv->timer = g_timer_new ();
1529 g_object_ref (priv->ui_manager);
1530 g_object_unref (gui);
1532 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1533 priv->mic_menu = empathy_mic_menu_new (self);
1534 priv->camera_menu = empathy_camera_menu_new (self);
1536 empathy_call_window_show_hangup_button (self, TRUE);
1538 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1540 /* Retrieve initial volume */
1541 priv->volume = g_settings_get_double (priv->settings,
1542 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1544 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1545 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1547 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1548 /* These signals are used to track the window position and save it
1549 * when the window is destroyed. We need to do this as we don't want
1550 * the window geometry to be saved with the dialpad taken into account. */
1551 g_signal_connect (self, "destroy",
1552 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1553 g_signal_connect (self, "configure-event",
1554 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1555 g_signal_connect (self, "window-state-event",
1556 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1558 /* Don't display labels in both toolbars */
1559 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1562 /* Instead of specifying a width and a height, we specify only one size. That's
1563 because we want a square avatar icon. */
1565 init_contact_avatar_with_size (EmpathyContact *contact,
1566 GtkWidget *image_widget,
1569 GdkPixbuf *pixbuf_avatar = NULL;
1571 if (contact != NULL)
1573 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1577 if (pixbuf_avatar == NULL)
1579 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1580 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1583 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1585 if (pixbuf_avatar != NULL)
1586 g_object_unref (pixbuf_avatar);
1590 set_window_title (EmpathyCallWindow *self)
1592 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1595 if (priv->contact != NULL)
1597 /* translators: Call is a noun and %s is the contact name. This string
1598 * is used in the window title */
1599 tmp = g_strdup_printf (_("Call with %s"),
1600 empathy_contact_get_alias (priv->contact));
1601 gtk_window_set_title (GTK_WINDOW (self), tmp);
1606 g_warning ("Unknown remote contact!");
1611 set_remote_user_name (EmpathyCallWindow *self,
1612 EmpathyContact *contact)
1614 const gchar *alias = empathy_contact_get_alias (contact);
1615 const gchar *status = empathy_contact_get_status (contact);
1618 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1619 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1625 contact_name_changed_cb (EmpathyContact *contact,
1627 EmpathyCallWindow *self)
1629 set_window_title (self);
1630 set_remote_user_name (self, contact);
1634 contact_presence_changed_cb (EmpathyContact *contact,
1636 EmpathyCallWindow *self)
1638 set_remote_user_name (self, contact);
1642 contact_avatar_changed_cb (EmpathyContact *contact,
1644 EmpathyCallWindow *self)
1647 GtkAllocation allocation;
1648 GtkWidget *avatar_widget;
1650 avatar_widget = self->priv->remote_user_avatar_widget;
1652 gtk_widget_get_allocation (avatar_widget, &allocation);
1653 size = allocation.height;
1657 /* the widget is not allocated yet, set a default size */
1658 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1659 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1662 init_contact_avatar_with_size (contact, avatar_widget, size);
1664 avatar_widget = self->priv->remote_user_avatar_toolbar;
1666 gtk_widget_get_allocation (avatar_widget, &allocation);
1667 size = allocation.height;
1671 /* the widget is not allocated yet, set a default size */
1672 size = SMALL_TOOLBAR_SIZE;
1675 init_contact_avatar_with_size (contact, avatar_widget, size);
1679 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1680 EmpathyCallHandler *handler)
1682 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1684 tp_g_signal_connect_object (priv->contact, "notify::name",
1685 G_CALLBACK (contact_name_changed_cb), self, 0);
1686 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1687 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1688 tp_g_signal_connect_object (priv->contact, "notify::presence",
1689 G_CALLBACK (contact_presence_changed_cb), self, 0);
1691 set_window_title (self);
1692 set_remote_user_name (self, priv->contact);
1694 init_contact_avatar_with_size (priv->contact,
1695 priv->remote_user_avatar_widget,
1696 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1697 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1699 init_contact_avatar_with_size (priv->contact,
1700 priv->remote_user_avatar_toolbar,
1701 SMALL_TOOLBAR_SIZE);
1703 /* The remote avatar is shown by default and will be hidden when we receive
1704 video from the remote side. */
1705 clutter_actor_hide (priv->video_output);
1706 gtk_widget_show (priv->remote_user_avatar_widget);
1710 update_send_codec (EmpathyCallWindow *self,
1713 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1720 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1721 widget = priv->acodec_encoding_label;
1725 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1726 widget = priv->vcodec_encoding_label;
1732 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1733 gtk_label_set_text (GTK_LABEL (widget), tmp);
1738 send_audio_codec_notify_cb (GObject *object,
1742 EmpathyCallWindow *self = user_data;
1744 update_send_codec (self, TRUE);
1748 send_video_codec_notify_cb (GObject *object,
1752 EmpathyCallWindow *self = user_data;
1754 update_send_codec (self, FALSE);
1758 update_recv_codec (EmpathyCallWindow *self,
1761 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1764 GString *str = NULL;
1768 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1769 widget = priv->acodec_decoding_label;
1773 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1774 widget = priv->vcodec_decoding_label;
1780 for (l = codecs; l != NULL; l = g_list_next (l))
1782 FsCodec *codec = l->data;
1785 str = g_string_new (NULL);
1787 g_string_append (str, ", ");
1789 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1793 gtk_label_set_text (GTK_LABEL (widget), str->str);
1794 g_string_free (str, TRUE);
1798 recv_audio_codecs_notify_cb (GObject *object,
1802 EmpathyCallWindow *self = user_data;
1804 update_recv_codec (self, TRUE);
1808 recv_video_codecs_notify_cb (GObject *object,
1812 EmpathyCallWindow *self = user_data;
1814 update_recv_codec (self, FALSE);
1817 static const gchar *
1818 candidate_type_to_str (FsCandidate *candidate)
1820 switch (candidate->type)
1822 case FS_CANDIDATE_TYPE_HOST:
1824 case FS_CANDIDATE_TYPE_SRFLX:
1825 return "server reflexive";
1826 case FS_CANDIDATE_TYPE_PRFLX:
1827 return "peer reflexive";
1828 case FS_CANDIDATE_TYPE_RELAY:
1830 case FS_CANDIDATE_TYPE_MULTICAST:
1837 static const gchar *
1838 candidate_type_to_desc (FsCandidate *candidate)
1840 switch (candidate->type)
1842 case FS_CANDIDATE_TYPE_HOST:
1843 return _("The IP address as seen by the machine");
1844 case FS_CANDIDATE_TYPE_SRFLX:
1845 return _("The IP address as seen by a server on the Internet");
1846 case FS_CANDIDATE_TYPE_PRFLX:
1847 return _("The IP address of the peer as seen by the other side");
1848 case FS_CANDIDATE_TYPE_RELAY:
1849 return _("The IP address of a relay server");
1850 case FS_CANDIDATE_TYPE_MULTICAST:
1851 return _("The IP address of the multicast group");
1858 update_candidat_widget (EmpathyCallWindow *self,
1861 FsCandidate *candidate)
1865 g_assert (candidate != NULL);
1866 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1867 candidate->port, candidate_type_to_str (candidate));
1869 gtk_label_set_text (GTK_LABEL (label), str);
1870 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1876 candidates_changed_cb (GObject *object,
1878 EmpathyCallWindow *self)
1880 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1881 FsCandidate *candidate = NULL;
1883 if (type == FS_MEDIA_TYPE_VIDEO)
1885 /* Update remote candidate */
1886 candidate = empathy_call_handler_get_video_remote_candidate (
1889 update_candidat_widget (self, priv->video_remote_candidate_label,
1890 priv->video_remote_candidate_info_img, candidate);
1892 /* Update local candidate */
1893 candidate = empathy_call_handler_get_video_local_candidate (
1896 update_candidat_widget (self, priv->video_local_candidate_label,
1897 priv->video_local_candidate_info_img, candidate);
1901 /* Update remote candidate */
1902 candidate = empathy_call_handler_get_audio_remote_candidate (
1905 update_candidat_widget (self, priv->audio_remote_candidate_label,
1906 priv->audio_remote_candidate_info_img, candidate);
1908 /* Update local candidate */
1909 candidate = empathy_call_handler_get_audio_local_candidate (
1912 update_candidat_widget (self, priv->audio_local_candidate_label,
1913 priv->audio_local_candidate_info_img, candidate);
1918 empathy_call_window_constructed (GObject *object)
1920 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1921 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1922 TpyCallChannel *call;
1924 g_assert (priv->handler != NULL);
1926 g_object_get (priv->handler, "call-channel", &call, NULL);
1927 priv->outgoing = (call == NULL);
1929 g_object_unref (call);
1931 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1932 g_assert (priv->contact != NULL);
1934 empathy_call_window_setup_avatars (self, priv->handler);
1935 empathy_call_window_set_state_connecting (self);
1937 if (!empathy_call_handler_has_initial_video (priv->handler))
1939 gtk_toggle_tool_button_set_active (
1940 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1942 /* If call has InitialVideo, the preview will be started once the call has
1943 * been started (start_call()). */
1945 update_send_codec (self, TRUE);
1946 update_send_codec (self, FALSE);
1947 update_recv_codec (self, TRUE);
1948 update_recv_codec (self, FALSE);
1950 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1951 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1952 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1953 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1954 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1955 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1956 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1957 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1959 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1960 G_CALLBACK (candidates_changed_cb), self, 0);
1963 static void empathy_call_window_dispose (GObject *object);
1964 static void empathy_call_window_finalize (GObject *object);
1967 empathy_call_window_set_property (GObject *object,
1968 guint property_id, const GValue *value, GParamSpec *pspec)
1970 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1972 switch (property_id)
1974 case PROP_CALL_HANDLER:
1975 priv->handler = g_value_dup_object (value);
1978 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1983 empathy_call_window_get_property (GObject *object,
1984 guint property_id, GValue *value, GParamSpec *pspec)
1986 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1988 switch (property_id)
1990 case PROP_CALL_HANDLER:
1991 g_value_set_object (value, priv->handler);
1994 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1999 empathy_call_window_class_init (
2000 EmpathyCallWindowClass *empathy_call_window_class)
2002 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2003 GParamSpec *param_spec;
2005 g_type_class_add_private (empathy_call_window_class,
2006 sizeof (EmpathyCallWindowPriv));
2008 object_class->constructed = empathy_call_window_constructed;
2009 object_class->set_property = empathy_call_window_set_property;
2010 object_class->get_property = empathy_call_window_get_property;
2012 object_class->dispose = empathy_call_window_dispose;
2013 object_class->finalize = empathy_call_window_finalize;
2015 param_spec = g_param_spec_object ("handler",
2016 "handler", "The call handler",
2017 EMPATHY_TYPE_CALL_HANDLER,
2018 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2019 g_object_class_install_property (object_class,
2020 PROP_CALL_HANDLER, param_spec);
2024 empathy_call_window_dispose (GObject *object)
2026 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2027 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2029 if (priv->dispose_has_run)
2032 priv->dispose_has_run = TRUE;
2034 if (priv->handler != NULL)
2036 empathy_call_handler_stop_call (priv->handler);
2037 tp_clear_object (&priv->handler);
2040 if (priv->bus_message_source_id != 0)
2042 g_source_remove (priv->bus_message_source_id);
2043 priv->bus_message_source_id = 0;
2046 if (priv->got_video_src > 0)
2048 g_source_remove (priv->got_video_src);
2049 priv->got_video_src = 0;
2052 if (priv->inactivity_src > 0)
2054 g_source_remove (priv->inactivity_src);
2055 priv->inactivity_src = 0;
2058 tp_clear_object (&priv->pipeline);
2059 tp_clear_object (&priv->video_input);
2060 tp_clear_object (&priv->audio_input);
2061 tp_clear_object (&priv->video_tee);
2062 tp_clear_object (&priv->ui_manager);
2063 tp_clear_object (&priv->fullscreen);
2064 tp_clear_object (&priv->camera_monitor);
2065 tp_clear_object (&priv->settings);
2066 tp_clear_object (&priv->sound_mgr);
2067 tp_clear_object (&priv->mic_menu);
2068 tp_clear_object (&priv->camera_menu);
2070 g_list_free_full (priv->notifiers, g_object_unref);
2072 if (priv->timer_id != 0)
2073 g_source_remove (priv->timer_id);
2076 if (priv->contact != NULL)
2078 g_signal_handlers_disconnect_by_func (priv->contact,
2079 contact_name_changed_cb, self);
2080 priv->contact = NULL;
2083 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2087 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2089 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2091 if (priv->video_output_motion_handler_id != 0)
2093 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2094 priv->video_output_motion_handler_id);
2095 priv->video_output_motion_handler_id = 0;
2100 empathy_call_window_finalize (GObject *object)
2102 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2103 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2105 disconnect_video_output_motion_handler (self);
2107 /* free any data held directly by the object here */
2108 g_mutex_free (priv->lock);
2110 g_timer_destroy (priv->timer);
2112 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2117 empathy_call_window_new (EmpathyCallHandler *handler)
2119 return EMPATHY_CALL_WINDOW (
2120 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2124 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2125 GstElement *conference, gpointer user_data)
2127 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2128 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2129 FsElementAddedNotifier *notifier;
2132 DEBUG ("Conference added");
2134 /* Add notifier to set the various element properties as needed */
2135 notifier = fs_element_added_notifier_new ();
2136 keyfile = fs_utils_get_default_element_properties (conference);
2138 if (keyfile != NULL)
2139 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2141 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2143 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2145 gst_bin_add (GST_BIN (priv->pipeline), conference);
2146 gst_element_set_state (conference, GST_STATE_PLAYING);
2150 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2151 GstElement *conference, gpointer user_data)
2153 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2154 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2156 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2157 gst_element_set_state (conference, GST_STATE_NULL);
2161 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2163 GstStateChangeReturn state_change_return;
2164 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2166 if (priv->pipeline == NULL)
2169 if (priv->bus_message_source_id != 0)
2171 g_source_remove (priv->bus_message_source_id);
2172 priv->bus_message_source_id = 0;
2175 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2177 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2178 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2180 if (priv->pipeline != NULL)
2181 g_object_unref (priv->pipeline);
2182 priv->pipeline = NULL;
2184 if (priv->audio_output != NULL)
2185 g_object_unref (priv->audio_output);
2186 priv->audio_output = NULL;
2188 if (priv->video_tee != NULL)
2189 g_object_unref (priv->video_tee);
2190 priv->video_tee = NULL;
2192 if (priv->video_preview != NULL)
2193 clutter_actor_destroy (priv->video_preview);
2194 priv->video_preview = NULL;
2196 priv->funnel = NULL;
2198 create_pipeline (self);
2199 /* Call will be started when user will hit the 'redial' button */
2200 priv->start_call_when_playing = FALSE;
2201 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2207 g_message ("Error: could not destroy pipeline. Closing call window");
2208 gtk_widget_destroy (GTK_WIDGET (self));
2215 reset_details_pane (EmpathyCallWindow *self)
2217 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2219 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2220 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2221 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2222 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2226 empathy_call_window_disconnected (EmpathyCallWindow *self,
2229 gboolean could_disconnect = FALSE;
2230 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2231 gboolean could_reset_pipeline;
2233 /* Leave full screen mode if needed */
2234 gtk_window_unfullscreen (GTK_WINDOW (self));
2236 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2237 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2239 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2241 if (priv->call_state == CONNECTING)
2242 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2244 if (priv->call_state != REDIALING)
2245 priv->call_state = DISCONNECTED;
2247 if (could_reset_pipeline)
2249 g_mutex_lock (priv->lock);
2251 g_timer_stop (priv->timer);
2253 if (priv->timer_id != 0)
2254 g_source_remove (priv->timer_id);
2257 g_mutex_unlock (priv->lock);
2260 /* We are about to destroy the window, no need to update it or create
2261 * a video preview */
2264 empathy_call_window_status_message (self, _("Disconnected"));
2266 empathy_call_window_show_hangup_button (self, FALSE);
2268 /* Unsensitive the camera and mic button */
2269 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2270 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2272 /* Be sure that the mic button is enabled */
2273 gtk_toggle_tool_button_set_active (
2274 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2276 if (priv->camera_state == CAMERA_STATE_ON)
2278 /* Restart the preview with the new pipeline. */
2279 display_video_preview (self, TRUE);
2282 /* destroy the video output; it will be recreated when we'll redial */
2283 disconnect_video_output_motion_handler (self);
2284 if (priv->video_output != NULL)
2285 clutter_actor_destroy (priv->video_output);
2286 priv->video_output = NULL;
2287 if (priv->got_video_src > 0)
2289 g_source_remove (priv->got_video_src);
2290 priv->got_video_src = 0;
2293 gtk_widget_show (priv->remote_user_avatar_widget);
2295 reset_details_pane (self);
2297 priv->sending_video = FALSE;
2298 priv->call_started = FALSE;
2300 could_disconnect = TRUE;
2302 /* TODO: display the self avatar of the preview (depends if the "Always
2303 * Show Video Preview" is enabled or not) */
2306 return could_disconnect;
2311 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2314 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2315 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2317 if (empathy_call_window_disconnected (self, TRUE) &&
2318 priv->call_state == REDIALING)
2319 empathy_call_window_restart_call (self);
2323 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2325 FsMediaType media_type,
2326 EmpathyCallWindow *self)
2328 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2330 DEBUG ("removing content");
2333 * This assumes that there is only one video stream per channel...
2336 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2338 if (priv->funnel != NULL)
2342 output = priv->video_output_sink;
2344 gst_element_set_state (output, GST_STATE_NULL);
2345 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2347 gst_bin_remove (GST_BIN (priv->pipeline), output);
2348 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2349 priv->funnel = NULL;
2353 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2355 if (priv->audio_output != NULL)
2357 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2359 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2360 priv->audio_output = NULL;
2368 /* Called with global lock held */
2370 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2372 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2376 if (priv->funnel == NULL)
2378 output = priv->video_output_sink;
2380 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2384 g_warning ("Could not create fsfunnel");
2388 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2390 gst_object_unref (priv->funnel);
2391 priv->funnel = NULL;
2392 g_warning ("Could not add funnel to pipeline");
2396 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2398 g_warning ("Could not add the video output widget to the pipeline");
2402 if (!gst_element_link (priv->funnel, output))
2404 g_warning ("Could not link output sink to funnel");
2405 goto error_output_added;
2408 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2410 g_warning ("Could not start video sink");
2411 goto error_output_added;
2414 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2416 g_warning ("Could not start funnel");
2417 goto error_output_added;
2421 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2424 g_warning ("Could not get request pad from funnel");
2431 gst_element_set_locked_state (priv->funnel, TRUE);
2432 gst_element_set_locked_state (output, TRUE);
2434 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2435 gst_element_set_state (output, GST_STATE_NULL);
2437 gst_bin_remove (GST_BIN (priv->pipeline), output);
2438 gst_element_set_locked_state (output, FALSE);
2442 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2443 priv->funnel = NULL;
2448 /* Called with global lock held */
2450 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2452 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2454 GstPadTemplate *template;
2456 if (priv->audio_output == NULL)
2458 priv->audio_output = empathy_audio_sink_new ();
2459 g_object_ref_sink (priv->audio_output);
2461 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2463 g_warning ("Could not add audio sink to pipeline");
2464 g_object_unref (priv->audio_output);
2465 goto error_add_output;
2468 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2470 g_warning ("Could not start audio sink");
2475 template = gst_element_class_get_pad_template (
2476 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2478 pad = gst_element_request_pad (priv->audio_output,
2479 template, NULL, NULL);
2483 g_warning ("Could not get sink pad from sink");
2490 gst_element_set_locked_state (priv->audio_output, TRUE);
2491 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2492 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2493 priv->audio_output = NULL;
2501 empathy_call_window_update_timer (gpointer user_data)
2503 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2504 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2505 const gchar *status;
2509 time_ = g_timer_elapsed (priv->timer, NULL);
2511 if (priv->call_state == HELD)
2512 status = _("On hold");
2513 else if (!gtk_toggle_tool_button_get_active (
2514 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2517 status = _("Duration");
2519 /* Translators: 'status - minutes:seconds' the caller has been connected */
2520 str = g_strdup_printf (_("%s — %d:%02dm"),
2522 (int) time_ / 60, (int) time_ % 60);
2523 empathy_call_window_status_message (self, str);
2531 display_error (EmpathyCallWindow *self,
2532 TpyCallChannel *call,
2536 const gchar *details)
2538 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2539 GtkWidget *info_bar;
2540 GtkWidget *content_area;
2547 /* Create info bar */
2548 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2551 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2553 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2555 /* hbox containing the image and the messages vbox */
2556 hbox = gtk_hbox_new (FALSE, 3);
2557 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2560 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2561 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2563 /* vbox containing the main message and the details expander */
2564 vbox = gtk_vbox_new (FALSE, 3);
2565 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2568 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2570 label = gtk_label_new (NULL);
2571 gtk_label_set_markup (GTK_LABEL (label), txt);
2572 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2573 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2576 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2579 if (details != NULL)
2581 GtkWidget *expander;
2583 expander = gtk_expander_new (_("Technical Details"));
2585 txt = g_strdup_printf ("<i>%s</i>", details);
2587 label = gtk_label_new (NULL);
2588 gtk_label_set_markup (GTK_LABEL (label), txt);
2589 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2590 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2593 gtk_container_add (GTK_CONTAINER (expander), label);
2594 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2597 g_signal_connect (info_bar, "response",
2598 G_CALLBACK (gtk_widget_destroy), NULL);
2600 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2601 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2602 gtk_widget_show_all (info_bar);
2606 media_stream_error_to_txt (EmpathyCallWindow *self,
2607 TpyCallChannel *call,
2609 TpMediaStreamError error)
2611 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2612 const gchar *cm = NULL;
2618 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2620 return g_strdup_printf (
2621 _("%s's software does not understand any of the audio formats "
2622 "supported by your computer"),
2623 empathy_contact_get_alias (priv->contact));
2625 return g_strdup_printf (
2626 _("%s's software does not understand any of the video formats "
2627 "supported by your computer"),
2628 empathy_contact_get_alias (priv->contact));
2630 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2631 return g_strdup_printf (
2632 _("Can't establish a connection to %s. "
2633 "One of you might be on a network that does not allow "
2634 "direct connections."),
2635 empathy_contact_get_alias (priv->contact));
2637 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2638 return g_strdup (_("There was a failure on the network"));
2640 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2642 return g_strdup (_("The audio formats necessary for this call "
2643 "are not installed on your computer"));
2645 return g_strdup (_("The video formats necessary for this call "
2646 "are not installed on your computer"));
2648 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2649 tp_connection_parse_object_path (
2650 tp_channel_borrow_connection (TP_CHANNEL (call)),
2653 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2654 "product=Telepathy&component=%s", cm);
2656 result = g_strdup_printf (
2657 _("Something unexpected happened in a Telepathy component. "
2658 "Please <a href=\"%s\">report this bug</a> and attach "
2659 "logs gathered from the 'Debug' window in the Help menu."), url);
2665 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2666 return g_strdup (_("There was a failure in the call engine"));
2668 case TP_MEDIA_STREAM_ERROR_EOS:
2669 return g_strdup (_("The end of the stream was reached"));
2671 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2678 empathy_call_window_stream_error (EmpathyCallWindow *self,
2679 TpyCallChannel *call,
2688 desc = media_stream_error_to_txt (self, call, audio, code);
2691 /* No description, use the error message. That's not great as it's not
2692 * localized but it's better than nothing. */
2693 display_error (self, call, icon, title, msg, NULL);
2697 display_error (self, call, icon, title, desc, msg);
2703 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2706 EmpathyCallWindow *self)
2708 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2709 "gnome-stock-mic", _("Can't establish audio stream"));
2713 empathy_call_window_video_stream_error (TpyCallChannel *call,
2716 EmpathyCallWindow *self)
2718 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2719 "camera-web", _("Can't establish video stream"));
2724 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2726 EmpathyCallWindow *self)
2728 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2729 TpyCallChannel *call;
2730 gboolean can_send_video;
2732 if (state != TPY_CALL_STATE_ACCEPTED)
2735 if (priv->call_state == CONNECTED)
2738 g_timer_start (priv->timer);
2739 priv->call_state = CONNECTED;
2741 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2743 can_send_video = priv->video_input != NULL &&
2744 empathy_contact_can_voip_video (priv->contact) &&
2745 empathy_camera_monitor_get_available (priv->camera_monitor);
2747 g_object_get (priv->handler, "call-channel", &call, NULL);
2749 if (tpy_call_channel_has_dtmf (call))
2750 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2752 if (priv->video_input == NULL)
2753 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2755 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2757 empathy_call_window_show_hangup_button (self, TRUE);
2759 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2761 clutter_actor_hide (priv->video_output);
2762 gtk_widget_show (priv->remote_user_avatar_widget);
2764 g_object_unref (call);
2766 g_mutex_lock (priv->lock);
2768 priv->timer_id = g_timeout_add_seconds (1,
2769 empathy_call_window_update_timer, self);
2771 g_mutex_unlock (priv->lock);
2773 empathy_call_window_update_timer (self);
2775 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2779 empathy_call_window_show_video_output_cb (gpointer user_data)
2781 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2783 if (self->priv->video_output != NULL)
2785 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2786 clutter_actor_show (self->priv->video_output);
2787 clutter_actor_raise_top (self->priv->floating_toolbar);
2794 empathy_call_window_check_video_cb (gpointer data)
2796 EmpathyCallWindow *self = data;
2798 if (self->priv->got_video)
2800 self->priv->got_video = FALSE;
2804 /* No video in the last N seconds, display the remote avatar */
2805 empathy_call_window_show_video_output (self, FALSE);
2810 /* Called from the streaming thread */
2812 empathy_call_window_video_probe_cb (GstPad *pad,
2813 GstMiniObject *mini_obj,
2814 EmpathyCallWindow *self)
2817 if (GST_IS_EVENT (mini_obj))
2820 if (G_UNLIKELY (!self->priv->got_video))
2822 /* show the remote video */
2823 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2824 empathy_call_window_show_video_output_cb,
2825 g_object_ref (self), g_object_unref);
2827 self->priv->got_video = TRUE;
2833 /* Called from the streaming thread */
2835 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2836 GstPad *src, guint media_type, gpointer user_data)
2838 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2839 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2840 gboolean retval = FALSE;
2844 g_mutex_lock (priv->lock);
2848 case TP_MEDIA_STREAM_TYPE_AUDIO:
2849 pad = empathy_call_window_get_audio_sink_pad (self);
2851 case TP_MEDIA_STREAM_TYPE_VIDEO:
2852 g_idle_add (empathy_call_window_show_video_output_cb, self);
2853 pad = empathy_call_window_get_video_sink_pad (self);
2855 gst_pad_add_data_probe (src,
2856 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2857 if (priv->got_video_src > 0)
2858 g_source_remove (priv->got_video_src);
2859 priv->got_video_src = g_timeout_add_seconds (5,
2860 empathy_call_window_check_video_cb, self);
2863 g_assert_not_reached ();
2869 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2870 g_warning ("Could not link %s sink pad",
2871 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2875 gst_object_unref (pad);
2879 /* If no sink could be linked, try to add fakesink to prevent the whole call
2884 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2886 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2888 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2889 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2890 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2892 gst_element_set_locked_state (fakesink, TRUE);
2893 gst_element_set_state (fakesink, GST_STATE_NULL);
2894 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2898 DEBUG ("Could not link real sink, linked fakesink instead");
2900 gst_object_unref (sinkpad);
2904 gst_object_unref (fakesink);
2909 g_mutex_unlock (priv->lock);
2915 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2916 GstPad *sink, FsMediaType media_type, gpointer user_data)
2918 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2919 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2921 gboolean retval = FALSE;
2925 case FS_MEDIA_TYPE_AUDIO:
2926 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2928 g_warning ("Could not add audio source to pipeline");
2932 pad = gst_element_get_static_pad (priv->audio_input, "src");
2935 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2936 g_warning ("Could not get source pad from audio source");
2940 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2942 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2943 g_warning ("Could not link audio source to farsight");
2947 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2949 g_warning ("Could not start audio source");
2950 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2951 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2957 case FS_MEDIA_TYPE_VIDEO:
2958 if (priv->video_tee != NULL)
2960 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2961 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2963 g_warning ("Could not link video source input pipeline");
2966 gst_object_unref (pad);
2972 g_assert_not_reached ();
2979 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2981 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2982 GstElement *preview;
2984 disable_camera (self);
2986 DEBUG ("remove video input");
2987 preview = priv->video_preview_sink;
2989 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2990 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2991 gst_element_set_state (preview, GST_STATE_NULL);
2993 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2996 g_object_unref (priv->video_input);
2997 priv->video_input = NULL;
2998 g_object_unref (priv->video_tee);
2999 priv->video_tee = NULL;
3000 clutter_actor_destroy (priv->video_preview);
3001 priv->video_preview = NULL;
3003 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3007 start_call (EmpathyCallWindow *self)
3009 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3011 priv->call_started = TRUE;
3012 empathy_call_handler_start_call (priv->handler,
3013 gtk_get_current_event_time ());
3015 if (empathy_call_handler_has_initial_video (priv->handler))
3017 TpyCallChannel *call;
3020 g_object_get (priv->handler, "call-channel", &call, NULL);
3021 s = tpy_call_channel_get_video_state (call);
3023 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3024 s == TPY_SENDING_STATE_SENDING)
3026 /* Enable 'send video' buttons and display the preview */
3027 gtk_toggle_tool_button_set_active (
3028 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3032 gtk_toggle_tool_button_set_active (
3033 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3035 if (priv->video_preview == NULL)
3037 create_video_preview (self);
3038 add_video_preview_to_pipeline (self);
3042 g_object_unref (call);
3047 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3050 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3051 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3054 empathy_call_handler_bus_message (priv->handler, bus, message);
3056 switch (GST_MESSAGE_TYPE (message))
3058 case GST_MESSAGE_STATE_CHANGED:
3059 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3061 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3063 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3064 !priv->call_started)
3066 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3067 if (newstate == GST_STATE_PAUSED)
3069 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3070 priv->pipeline_playing = TRUE;
3072 if (priv->start_call_when_playing)
3077 case GST_MESSAGE_ERROR:
3079 GError *error = NULL;
3080 GstElement *gst_error;
3083 gst_message_parse_error (message, &error, &debug);
3084 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3086 g_message ("Element error: %s -- %s\n", error->message, debug);
3088 if (g_str_has_prefix (gst_element_get_name (gst_error),
3089 VIDEO_INPUT_ERROR_PREFIX))
3091 /* Remove the video input and continue */
3092 if (priv->video_input != NULL)
3093 empathy_call_window_remove_video_input (self);
3094 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3098 empathy_call_window_disconnected (self, TRUE);
3100 g_error_free (error);
3103 case GST_MESSAGE_UNKNOWN:
3104 case GST_MESSAGE_EOS:
3105 case GST_MESSAGE_WARNING:
3106 case GST_MESSAGE_INFO:
3107 case GST_MESSAGE_TAG:
3108 case GST_MESSAGE_BUFFERING:
3109 case GST_MESSAGE_STATE_DIRTY:
3110 case GST_MESSAGE_STEP_DONE:
3111 case GST_MESSAGE_CLOCK_PROVIDE:
3112 case GST_MESSAGE_CLOCK_LOST:
3113 case GST_MESSAGE_NEW_CLOCK:
3114 case GST_MESSAGE_STRUCTURE_CHANGE:
3115 case GST_MESSAGE_STREAM_STATUS:
3116 case GST_MESSAGE_APPLICATION:
3117 case GST_MESSAGE_ELEMENT:
3118 case GST_MESSAGE_SEGMENT_START:
3119 case GST_MESSAGE_SEGMENT_DONE:
3120 case GST_MESSAGE_DURATION:
3121 case GST_MESSAGE_ANY:
3130 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3131 GHashTable *members,
3132 EmpathyCallWindow *self)
3134 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3135 GHashTableIter iter;
3136 gpointer key, value;
3137 gboolean held = FALSE;
3139 g_hash_table_iter_init (&iter, members);
3140 while (g_hash_table_iter_next (&iter, &key, &value))
3142 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3144 /* This assumes this is a 1-1 call, otherwise one participant
3145 * putting the call on hold wouldn't mean the call is on hold
3153 priv->call_state = HELD;
3154 else if (priv->call_state == HELD)
3155 priv->call_state = CONNECTED;
3159 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3161 EmpathyCallWindow *self)
3163 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3164 TpyCallChannel *call;
3166 g_object_get (priv->handler, "call-channel", &call, NULL);
3171 tp_g_signal_connect_object (call, "audio-stream-error",
3172 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3173 tp_g_signal_connect_object (call, "video-stream-error",
3174 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3177 tp_g_signal_connect_object (call, "members-changed",
3178 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3180 g_object_unref (call);
3184 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3186 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3187 TpyCallChannel *call;
3190 /* Make the hangup button twice as wide */
3191 width = gtk_widget_get_allocated_width (priv->hangup_button);
3192 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3194 g_signal_connect (priv->handler, "state-changed",
3195 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3196 g_signal_connect (priv->handler, "conference-added",
3197 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3198 g_signal_connect (priv->handler, "conference-removed",
3199 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3200 g_signal_connect (priv->handler, "closed",
3201 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3202 g_signal_connect (priv->handler, "src-pad-added",
3203 G_CALLBACK (empathy_call_window_src_added_cb), window);
3204 g_signal_connect (priv->handler, "sink-pad-added",
3205 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3206 g_signal_connect (priv->handler, "sink-pad-removed",
3207 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3209 g_object_get (priv->handler, "call-channel", &call, NULL);
3212 call_handler_notify_call_cb (priv->handler, NULL, window);
3213 g_object_unref (call);
3217 /* call-channel doesn't exist yet, we'll connect signals once it has been
3219 g_signal_connect (priv->handler, "notify::call-channel",
3220 G_CALLBACK (call_handler_notify_call_cb), window);
3223 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3227 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3228 EmpathyCallWindow *window)
3230 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3232 if (priv->pipeline != NULL)
3234 if (priv->bus_message_source_id != 0)
3236 g_source_remove (priv->bus_message_source_id);
3237 priv->bus_message_source_id = 0;
3240 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3243 if (priv->call_state == CONNECTING)
3244 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3250 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3253 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3255 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3260 gtk_widget_hide (priv->dtmf_panel);
3261 gtk_widget_hide (menu);
3262 gtk_widget_hide (priv->toolbar);
3266 if (priv->dialpad_was_visible_before_fs)
3267 gtk_widget_show (priv->dtmf_panel);
3269 gtk_widget_show (menu);
3270 gtk_widget_show (priv->toolbar);
3272 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3273 priv->original_height_before_fs);
3278 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3280 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3282 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3283 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3284 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3285 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3287 if (priv->video_output != NULL)
3290 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3291 priv->video_output, TRUE, TRUE,
3292 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3299 empathy_call_window_state_event_cb (GtkWidget *widget,
3300 GdkEventWindowState *event, EmpathyCallWindow *window)
3302 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3304 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3305 gboolean set_fullscreen = event->new_window_state &
3306 GDK_WINDOW_STATE_FULLSCREEN;
3310 gboolean dialpad_was_visible;
3311 GtkAllocation allocation;
3312 gint original_width, original_height;
3314 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3315 original_width = allocation.width;
3316 original_height = allocation.height;
3318 g_object_get (priv->dtmf_panel,
3319 "visible", &dialpad_was_visible,
3322 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3323 priv->original_width_before_fs = original_width;
3324 priv->original_height_before_fs = original_height;
3326 if (priv->video_output_motion_handler_id == 0 &&
3327 priv->video_output != NULL)
3329 priv->video_output_motion_handler_id = g_signal_connect (
3330 G_OBJECT (priv->video_container), "motion-notify-event",
3331 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3337 disconnect_video_output_motion_handler (window);
3340 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3342 show_controls (window, set_fullscreen);
3343 show_borders (window, set_fullscreen);
3344 gtk_action_set_stock_id (priv->menu_fullscreen,
3345 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3346 priv->is_fullscreen = set_fullscreen;
3353 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3356 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3357 int w, h, dialpad_width;
3358 GtkAllocation allocation;
3360 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3361 w = allocation.width;
3362 h = allocation.height;
3364 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3368 gtk_widget_show (priv->dtmf_panel);
3374 gtk_widget_hide (priv->dtmf_panel);
3378 gtk_window_resize (GTK_WINDOW (window), w, h);
3382 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3385 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3386 TpyCallChannel *call;
3388 priv->sending_video = (state == CAMERA_STATE_ON);
3390 if (state == CAMERA_STATE_ON)
3392 /* When we start sending video, we want to show the video preview by
3394 display_video_preview (window, TRUE);
3398 display_video_preview (window, FALSE);
3401 if (priv->call_state != CONNECTED)
3404 g_object_get (priv->handler, "call-channel", &call, NULL);
3405 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3406 tpy_call_channel_send_video (call, priv->sending_video);
3407 g_object_unref (call);
3411 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3412 EmpathyCallWindow *self)
3414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3417 active = (gtk_toggle_tool_button_get_active (toggle));
3419 /* We don't want the settings callback to react to this change to avoid
3421 g_signal_handlers_block_by_func (priv->settings,
3422 empathy_call_window_prefs_volume_changed_cb, self);
3426 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3427 priv->volume * 100);
3431 /* TODO, Instead of setting the input volume to 0 we should probably
3432 * stop sending but this would cause the audio call to drop if both
3433 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3434 * in the future. GNOME #574574
3436 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3440 g_signal_handlers_unblock_by_func (priv->settings,
3441 empathy_call_window_prefs_volume_changed_cb, self);
3445 empathy_call_window_hangup_cb (gpointer object,
3446 EmpathyCallWindow *self)
3448 empathy_call_handler_stop_call (self->priv->handler);
3450 empathy_call_window_disconnected (self, TRUE);
3454 empathy_call_window_restart_call (EmpathyCallWindow *window)
3456 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3458 /* Remove error info bars */
3459 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3460 (GtkCallback) gtk_widget_destroy, NULL);
3462 create_video_output_widget (window);
3464 /* While the call was disconnected, the input volume might have changed.
3465 * However, since the audio_input source was destroyed, its volume has not
3466 * been updated during that time. That's why we manually update it here */
3467 empathy_call_window_mic_volume_changed (window);
3469 priv->outgoing = TRUE;
3470 empathy_call_window_set_state_connecting (window);
3472 if (priv->pipeline_playing)
3473 start_call (window);
3475 /* call will be started when the pipeline is ready */
3476 priv->start_call_when_playing = TRUE;
3478 empathy_call_window_setup_avatars (window, priv->handler);
3480 empathy_call_window_show_hangup_button (window, TRUE);
3484 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3485 EmpathyCallWindow *window)
3489 active = gtk_toggle_tool_button_get_active (button);
3491 empathy_call_window_show_dialpad (window, active);
3495 empathy_call_window_fullscreen_cb (gpointer object,
3496 EmpathyCallWindow *window)
3498 empathy_call_window_fullscreen_toggle (window);
3502 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3504 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3506 if (priv->is_fullscreen)
3507 gtk_window_unfullscreen (GTK_WINDOW (window));
3509 gtk_window_fullscreen (GTK_WINDOW (window));
3513 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3514 GdkEventButton *event, EmpathyCallWindow *window)
3516 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3518 empathy_call_window_video_menu_popup (window, event->button);
3526 empathy_call_window_key_press_cb (GtkWidget *video_output,
3527 GdkEventKey *event, EmpathyCallWindow *window)
3529 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3531 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3533 /* Since we are in fullscreen mode, toggling will bring us back to
3535 empathy_call_window_fullscreen_toggle (window);
3543 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3544 GdkEventMotion *event, EmpathyCallWindow *window)
3546 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3548 if (priv->is_fullscreen)
3550 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3552 /* Show the bottom toolbar */
3553 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3560 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3564 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3566 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3568 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3569 button, gtk_get_current_event_time ());
3570 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3574 empathy_call_window_status_message (EmpathyCallWindow *self,
3577 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3581 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3582 gdouble value, EmpathyCallWindow *window)
3584 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3586 if (priv->audio_output == NULL)
3589 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3594 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3596 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3598 return priv->ui_manager;
3601 EmpathyGstAudioSrc *
3602 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3604 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3606 return (EmpathyGstAudioSrc *) priv->audio_input;
3609 EmpathyGstVideoSrc *
3610 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3612 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);