2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
68 #include "empathy-camera-menu.h"
70 #define CONTENT_HBOX_BORDER_WIDTH 6
71 #define CONTENT_HBOX_SPACING 3
72 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
74 #define SELF_VIDEO_SECTION_WIDTH 120
75 #define SELF_VIDEO_SECTION_HEIGHT 90
76 #define SELF_VIDEO_SECTION_MARGIN 10
78 #define FLOATING_TOOLBAR_OPACITY 192
79 #define FLOATING_TOOLBAR_WIDTH 280
80 #define FLOATING_TOOLBAR_HEIGHT 36
81 #define FLOATING_TOOLBAR_SPACING 20
83 /* The avatar's default width and height are set to the same value because we
84 want a square icon. */
85 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
87 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
89 #define SMALL_TOOLBAR_SIZE 36
91 /* If an video input error occurs, the error message will start with "v4l" */
92 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
94 /* The time interval in milliseconds between 2 outgoing rings */
95 #define MS_BETWEEN_RING 500
97 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
100 PROP_CALL_HANDLER = 1,
112 CAMERA_STATE_OFF = 0,
118 PREVIEW_POS_TOP_LEFT,
119 PREVIEW_POS_TOP_RIGHT,
120 PREVIEW_POS_BOTTOM_LEFT,
121 PREVIEW_POS_BOTTOM_RIGHT,
124 struct _EmpathyCallWindowPriv
126 gboolean dispose_has_run;
127 EmpathyCallHandler *handler;
129 EmpathyContact *contact;
131 EmpathyCameraMonitor *camera_monitor;
136 GtkUIManager *ui_manager;
137 GtkWidget *errors_vbox;
138 /* widget displays the video received from the remote user. This widget is
139 * alive only during call. */
140 ClutterActor *video_output;
141 ClutterActor *video_preview;
142 ClutterActor *preview_hidden_button;
143 ClutterActor *preview_rectangle1;
144 ClutterActor *preview_rectangle2;
145 ClutterActor *preview_rectangle3;
146 ClutterActor *preview_rectangle4;
147 ClutterActor *preview_rectangle_box1;
148 ClutterActor *preview_rectangle_box2;
149 ClutterActor *preview_rectangle_box3;
150 ClutterActor *preview_rectangle_box4;
151 GtkWidget *video_container;
152 GtkWidget *remote_user_avatar_widget;
153 GtkWidget *remote_user_avatar_toolbar;
154 GtkWidget *remote_user_name_toolbar;
155 GtkWidget *status_label;
156 GtkWidget *hangup_button;
157 GtkWidget *audio_call_button;
158 GtkWidget *video_call_button;
159 GtkWidget *mic_button;
160 GtkWidget *camera_button;
161 GtkWidget *dialpad_button;
163 GtkWidget *bottom_toolbar;
164 ClutterActor *floating_toolbar;
166 GtkAction *menu_fullscreen;
167 GtkAction *menu_swap_camera;
169 ClutterState *transitions;
171 /* The box that contains self and remote avatar and video
172 input/output. When we redial, we destroy and re-create the box */
173 ClutterActor *video_box;
174 ClutterLayoutManager *video_layout;
176 /* Coordinates of the preview drag event's start. */
177 PreviewPosition preview_pos;
181 /* We keep a reference on the hbox which contains the main content so we can
182 easilly repack everything when toggling fullscreen */
183 GtkWidget *content_hbox;
185 gulong video_output_motion_handler_id;
186 guint bus_message_source_id;
190 GtkWidget *dtmf_panel;
193 GtkWidget *details_vbox;
194 GtkWidget *vcodec_encoding_label;
195 GtkWidget *acodec_encoding_label;
196 GtkWidget *vcodec_decoding_label;
197 GtkWidget *acodec_decoding_label;
199 GtkWidget *audio_remote_candidate_label;
200 GtkWidget *audio_local_candidate_label;
201 GtkWidget *video_remote_candidate_label;
202 GtkWidget *video_local_candidate_label;
203 GtkWidget *video_remote_candidate_info_img;
204 GtkWidget *video_local_candidate_info_img;
205 GtkWidget *audio_remote_candidate_info_img;
206 GtkWidget *audio_local_candidate_info_img;
208 GstElement *video_input;
209 GstElement *video_preview_sink;
210 GstElement *video_output_sink;
211 GstElement *audio_input;
212 GstElement *audio_output;
213 GstElement *pipeline;
214 GstElement *video_tee;
224 gboolean call_started;
225 gboolean sending_video;
226 CameraState camera_state;
228 EmpathyCallWindowFullscreen *fullscreen;
229 gboolean is_fullscreen;
234 guint inactivity_src;
236 /* Those fields represent the state of the window before it actually was in
238 gboolean dialpad_was_visible_before_fs;
239 gint original_width_before_fs;
240 gint original_height_before_fs;
242 gint x, y, w, h, dialpad_width;
245 /* TRUE if the call should be started when the pipeline is playing */
246 gboolean start_call_when_playing;
247 /* TRUE if we requested to set the pipeline in the playing state */
248 gboolean pipeline_playing;
250 EmpathySoundManager *sound_mgr;
253 EmpathyMicMenu *mic_menu;
254 EmpathyCameraMenu *camera_menu;
257 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
259 static void empathy_call_window_realized_cb (GtkWidget *widget,
260 EmpathyCallWindow *window);
262 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
263 GdkEvent *event, EmpathyCallWindow *window);
265 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
266 GdkEventWindowState *event, EmpathyCallWindow *window);
268 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
271 static void empathy_call_window_mic_toggled_cb (
272 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
274 static void empathy_call_window_hangup_cb (gpointer object,
275 EmpathyCallWindow *window);
277 static void empathy_call_window_fullscreen_cb (gpointer object,
278 EmpathyCallWindow *window);
280 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
282 static gboolean empathy_call_window_video_button_press_cb (
283 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
285 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
286 GdkEventKey *event, EmpathyCallWindow *window);
288 static gboolean empathy_call_window_video_output_motion_notify (
289 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
291 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
294 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
295 EmpathyCallWindow *window);
297 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
299 static void empathy_call_window_status_message (EmpathyCallWindow *window,
302 static gboolean empathy_call_window_bus_message (GstBus *bus,
303 GstMessage *message, gpointer user_data);
306 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
307 gdouble value, EmpathyCallWindow *window);
310 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
313 gtk_widget_set_visible (self->priv->hangup_button, show);
314 gtk_widget_set_visible (self->priv->audio_call_button, !show);
315 gtk_widget_set_visible (self->priv->video_call_button, !show);
319 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
320 EmpathyCallWindow *self)
322 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
323 empathy_call_window_restart_call (self);
327 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
328 EmpathyCallWindow *self)
330 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
331 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
332 empathy_call_window_restart_call (self);
336 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
338 EmpathyCallWindowPriv *priv = GET_PRIV (window);
339 TpyCallChannel *call;
343 g_object_get (priv->handler, "call-channel", &call, NULL);
345 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
346 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
349 tpy_call_channel_dtmf_start_tone (call, event);
351 g_object_unref (call);
355 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
357 EmpathyCallWindowPriv *priv = GET_PRIV (window);
358 TpyCallChannel *call;
360 g_object_get (priv->handler, "call-channel", &call, NULL);
362 tpy_call_channel_dtmf_stop_tone (call);
364 g_object_unref (call);
368 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
370 EmpathyCallWindowPriv *priv = GET_PRIV (self);
373 volume = g_settings_get_double (priv->settings,
374 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
376 /* Don't store the volume because of muting */
377 if (volume > 0 || gtk_toggle_tool_button_get_active (
378 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
379 priv->volume = volume;
381 /* Ensure that the toggle button is active if the volume is > 0 and inactive
382 * if it's smaller than 0 */
383 if ((volume > 0) != gtk_toggle_tool_button_get_active (
384 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
385 gtk_toggle_tool_button_set_active (
386 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
388 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
393 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
395 EmpathyCallWindow *self)
397 empathy_call_window_mic_volume_changed (self);
401 empathy_call_window_raise_actors (EmpathyCallWindow *self)
403 clutter_actor_raise_top (self->priv->floating_toolbar);
405 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
406 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
407 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
408 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
412 empathy_call_window_show_video_output (EmpathyCallWindow *self,
415 if (self->priv->video_output != NULL)
416 g_object_set (self->priv->video_output, "visible", show, NULL);
418 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
420 empathy_call_window_raise_actors (self);
424 create_video_output_widget (EmpathyCallWindow *self)
426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
428 g_assert (priv->video_output == NULL);
429 g_assert (priv->pipeline != NULL);
431 priv->video_output = clutter_texture_new ();
433 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
436 priv->video_output_sink = clutter_gst_video_sink_new (
437 CLUTTER_TEXTURE (priv->video_output));
439 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
442 gtk_widget_add_events (priv->video_container,
443 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
444 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
445 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
449 create_video_input (EmpathyCallWindow *self)
451 EmpathyCallWindowPriv *priv = GET_PRIV (self);
453 g_assert (priv->video_input == NULL);
454 priv->video_input = empathy_video_src_new ();
455 gst_object_ref (priv->video_input);
456 gst_object_sink (priv->video_input);
460 create_audio_input (EmpathyCallWindow *self)
462 EmpathyCallWindowPriv *priv = GET_PRIV (self);
464 g_assert (priv->audio_input == NULL);
465 priv->audio_input = empathy_audio_src_new ();
466 gst_object_ref (priv->audio_input);
467 gst_object_sink (priv->audio_input);
471 add_video_preview_to_pipeline (EmpathyCallWindow *self)
473 EmpathyCallWindowPriv *priv = GET_PRIV (self);
476 g_assert (priv->video_preview != NULL);
477 g_assert (priv->pipeline != NULL);
478 g_assert (priv->video_input != NULL);
479 g_assert (priv->video_tee != NULL);
481 preview = priv->video_preview_sink;
483 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
485 g_warning ("Could not add video input to pipeline");
489 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
491 g_warning ("Could not add video preview to pipeline");
495 if (!gst_element_link (priv->video_input, priv->video_tee))
497 g_warning ("Could not link video input to video tee");
501 if (!gst_element_link (priv->video_tee, preview))
503 g_warning ("Could not link video tee to video preview");
509 empathy_call_window_disable_camera_cb (GtkAction *action,
510 EmpathyCallWindow *self)
512 clutter_actor_destroy (self->priv->preview_hidden_button);
514 gtk_toggle_tool_button_set_active (
515 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
519 empathy_call_window_minimise_camera_cb (GtkAction *action,
520 EmpathyCallWindow *self)
522 clutter_actor_hide (self->priv->video_preview);
523 clutter_actor_show (self->priv->preview_hidden_button);
527 empathy_call_window_maximise_camera_cb (GtkAction *action,
528 EmpathyCallWindow *self)
530 clutter_actor_show (self->priv->video_preview);
531 clutter_actor_hide (self->priv->preview_hidden_button);
535 empathy_call_window_swap_camera_cb (GtkAction *action,
536 EmpathyCallWindow *self)
538 const GList *cameras, *l;
541 DEBUG ("Swapping the camera");
543 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
544 current_cam = empathy_video_src_dup_device (
545 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
547 for (l = cameras; l != NULL; l = l->next)
549 EmpathyCamera *camera = l->data;
551 if (!tp_strdiff (camera->device, current_cam))
556 next = l->next->data;
558 next = cameras->data;
560 /* EmpathyCameraMenu will update itself and do the actual change
562 g_settings_set_string (self->priv->settings,
563 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
570 g_free (current_cam);
574 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
575 EmpathyCamera *camera,
576 EmpathyCallWindow *self)
578 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
580 gtk_action_set_visible (self->priv->menu_swap_camera,
581 g_list_length ((GList *) cameras) >= 2);
585 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
586 EmpathyCamera *camera,
587 EmpathyCallWindow *self)
589 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
591 gtk_action_set_visible (self->priv->menu_swap_camera,
592 g_list_length ((GList *) cameras) >= 2);
596 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
597 EmpathyCallWindow *self)
601 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
603 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
604 0, gtk_get_current_event_time ());
605 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
609 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
610 EmpathyCallWindow *self)
614 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
615 "/preview-hidden-menu");
616 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
617 0, gtk_get_current_event_time ());
618 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
621 static ClutterActor *
622 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
624 ClutterBinAlignment x,
625 ClutterBinAlignment y)
627 ClutterLayoutManager *layout1, *layout2;
628 ClutterActor *rectangle;
629 ClutterActor *box1, *box2;
631 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
632 CLUTTER_BIN_ALIGNMENT_START);
634 box1 = clutter_box_new (layout1);
638 rectangle = clutter_rectangle_new_with_color (
639 CLUTTER_COLOR_Transparent);
641 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
644 clutter_actor_set_size (box1,
645 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
646 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
647 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
649 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
650 CLUTTER_BIN_ALIGNMENT_CENTER);
652 /* We have a box with the margins and the video in the middle inside
653 * a bigger box with an extra bottom margin so we're not on top of
654 * the floating toolbar. */
655 box2 = clutter_box_new (layout2);
657 clutter_actor_set_size (box2,
658 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
659 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
661 clutter_actor_set_size (rectangle,
662 SELF_VIDEO_SECTION_WIDTH + 5, SELF_VIDEO_SECTION_HEIGHT + 5);
664 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
665 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
667 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
670 clutter_actor_hide (rectangle);
676 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
678 self->priv->preview_rectangle1 =
679 empathy_call_window_create_preview_rectangle (self,
680 &self->priv->preview_rectangle_box1,
681 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
682 self->priv->preview_rectangle2 =
683 empathy_call_window_create_preview_rectangle (self,
684 &self->priv->preview_rectangle_box2,
685 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
686 self->priv->preview_rectangle3 =
687 empathy_call_window_create_preview_rectangle (self,
688 &self->priv->preview_rectangle_box3,
689 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
690 self->priv->preview_rectangle4 =
691 empathy_call_window_create_preview_rectangle (self,
692 &self->priv->preview_rectangle_box4,
693 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
697 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
700 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
701 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
702 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
703 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
706 static PreviewPosition
707 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
712 PreviewPosition pos = PREVIEW_POS_NONE;
714 clutter_actor_get_geometry (self->priv->video_box, &box);
716 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
717 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
718 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
719 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
721 pos = PREVIEW_POS_TOP_LEFT;
723 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
724 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
725 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
726 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
728 pos = PREVIEW_POS_TOP_RIGHT;
730 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
731 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
732 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
733 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
735 pos = PREVIEW_POS_BOTTOM_LEFT;
737 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
738 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
739 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
740 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
742 pos = PREVIEW_POS_BOTTOM_RIGHT;
748 static ClutterActor *
749 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
752 ClutterActor *rectangle;
756 case PREVIEW_POS_TOP_LEFT:
757 rectangle = self->priv->preview_rectangle1;
759 case PREVIEW_POS_TOP_RIGHT:
760 rectangle = self->priv->preview_rectangle3;
762 case PREVIEW_POS_BOTTOM_LEFT:
763 rectangle = self->priv->preview_rectangle2;
765 case PREVIEW_POS_BOTTOM_RIGHT:
766 rectangle = self->priv->preview_rectangle4;
776 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
779 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
781 DEBUG ("moving the video preview to %d", pos);
783 self->priv->preview_pos = pos;
787 case PREVIEW_POS_TOP_LEFT:
788 clutter_bin_layout_set_alignment (layout,
789 self->priv->video_preview,
790 CLUTTER_BIN_ALIGNMENT_START,
791 CLUTTER_BIN_ALIGNMENT_START);
793 case PREVIEW_POS_TOP_RIGHT:
794 clutter_bin_layout_set_alignment (layout,
795 self->priv->video_preview,
796 CLUTTER_BIN_ALIGNMENT_END,
797 CLUTTER_BIN_ALIGNMENT_START);
799 case PREVIEW_POS_BOTTOM_LEFT:
800 clutter_bin_layout_set_alignment (layout,
801 self->priv->video_preview,
802 CLUTTER_BIN_ALIGNMENT_START,
803 CLUTTER_BIN_ALIGNMENT_END);
805 case PREVIEW_POS_BOTTOM_RIGHT:
806 clutter_bin_layout_set_alignment (layout,
807 self->priv->video_preview,
808 CLUTTER_BIN_ALIGNMENT_END,
809 CLUTTER_BIN_ALIGNMENT_END);
812 g_warn_if_reached ();
817 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
820 ClutterActor *rectangle;
822 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
824 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 3);
825 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
830 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
831 ClutterActor *rectangle)
833 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle), 1);
834 clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rectangle),
835 CLUTTER_COLOR_Black);
839 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
841 ClutterActor *rectangle;
843 rectangle = empathy_call_window_get_preview_rectangle (self,
844 self->priv->preview_pos);
846 /* We don't want to darken the rectangle where the preview
849 if (self->priv->preview_rectangle1 != rectangle)
850 empathy_call_window_darken_preview_rectangle (self,
851 self->priv->preview_rectangle1);
853 if (self->priv->preview_rectangle2 != rectangle)
854 empathy_call_window_darken_preview_rectangle (self,
855 self->priv->preview_rectangle2);
857 if (self->priv->preview_rectangle3 != rectangle)
858 empathy_call_window_darken_preview_rectangle (self,
859 self->priv->preview_rectangle3);
861 if (self->priv->preview_rectangle4 != rectangle)
862 empathy_call_window_darken_preview_rectangle (self,
863 self->priv->preview_rectangle4);
867 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
871 ClutterModifierType modifiers,
872 EmpathyCallWindow *self)
874 empathy_call_window_show_preview_rectangles (self, TRUE);
875 empathy_call_window_darken_preview_rectangles (self);
877 self->priv->event_x = event_x;
878 self->priv->event_y = event_y;
882 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
886 ClutterModifierType modifiers,
887 EmpathyCallWindow *self)
891 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
893 if (pos != PREVIEW_POS_NONE)
894 empathy_call_window_move_video_preview (self, pos);
896 empathy_call_window_show_preview_rectangles (self, FALSE);
900 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
904 EmpathyCallWindow *self)
908 pos = empathy_call_window_get_preview_position (self,
909 self->priv->event_x - delta_x, self->priv->event_y + delta_y);
911 if (pos != PREVIEW_POS_NONE)
912 empathy_call_window_highlight_preview_rectangle (self, pos);
914 empathy_call_window_darken_preview_rectangles (self);
918 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
919 ClutterCrossingEvent *event,
920 EmpathyCallWindow *self)
922 ClutterActor *rectangle;
924 rectangle = empathy_call_window_get_preview_rectangle (self,
925 self->priv->preview_pos);
927 empathy_call_window_highlight_preview_rectangle (self,
928 self->priv->preview_pos);
930 clutter_actor_show (rectangle);
936 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
937 ClutterCrossingEvent *event,
938 EmpathyCallWindow *self)
940 ClutterActor *rectangle;
942 rectangle = empathy_call_window_get_preview_rectangle (self,
943 self->priv->preview_pos);
945 empathy_call_window_darken_preview_rectangle (self, rectangle);
947 clutter_actor_hide (rectangle);
953 create_video_preview (EmpathyCallWindow *self)
955 EmpathyCallWindowPriv *priv = GET_PRIV (self);
956 ClutterLayoutManager *layout, *layout_center, *layout_end;
957 ClutterActor *preview;
960 ClutterAction *action;
963 g_assert (priv->video_preview == NULL);
965 preview = clutter_texture_new ();
966 clutter_actor_set_size (preview,
967 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
968 priv->video_preview_sink = clutter_gst_video_sink_new (
969 CLUTTER_TEXTURE (preview));
971 /* Flip the video preview */
972 clutter_actor_set_rotation (preview,
975 SELF_VIDEO_SECTION_WIDTH * 0.5,
979 /* Add a little offset to the video preview */
980 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
981 CLUTTER_BIN_ALIGNMENT_START);
982 priv->video_preview = clutter_box_new (layout);
983 clutter_actor_set_size (priv->video_preview,
984 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
985 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
986 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
988 /* We have a box with the margins and the video in the middle inside
989 * a bigger box with an extra bottom margin so we're not on top of
990 * the floating toolbar. */
991 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
992 CLUTTER_BIN_ALIGNMENT_CENTER);
993 box = clutter_box_new (layout_center);
994 clutter_actor_set_size (box,
995 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
996 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
998 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
999 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1001 g_object_set (priv->video_preview_sink,
1006 /* Translators: this is an "Info" label. It should be as short
1008 button = gtk_button_new_with_label (_("i"));
1009 b = gtk_clutter_actor_new_with_contents (button);
1011 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1012 CLUTTER_BIN_ALIGNMENT_END);
1013 box = clutter_box_new (layout_end);
1014 clutter_actor_set_size (box,
1015 SELF_VIDEO_SECTION_WIDTH,
1016 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1018 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1019 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1021 g_signal_connect (button, "clicked",
1022 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1025 /* Translators: this is an "Info" label. It should be as short
1027 button = gtk_button_new_with_label (_("i"));
1028 priv->preview_hidden_button =
1029 gtk_clutter_actor_new_with_contents (button);
1031 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1032 priv->preview_hidden_button,
1033 CLUTTER_BIN_ALIGNMENT_START,
1034 CLUTTER_BIN_ALIGNMENT_END);
1036 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1038 clutter_actor_hide (priv->preview_hidden_button);
1040 g_signal_connect (button, "clicked",
1041 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1044 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1045 priv->video_preview,
1046 CLUTTER_BIN_ALIGNMENT_START,
1047 CLUTTER_BIN_ALIGNMENT_END);
1049 action = clutter_drag_action_new ();
1050 g_signal_connect (action, "drag-begin",
1051 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1052 g_signal_connect (action, "drag-end",
1053 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1054 g_signal_connect (action, "drag-motion",
1055 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1057 g_signal_connect (preview, "enter-event",
1058 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1059 g_signal_connect (preview, "leave-event",
1060 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1062 clutter_actor_add_action (preview, action);
1063 clutter_actor_set_reactive (preview, TRUE);
1067 play_camera (EmpathyCallWindow *window,
1070 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1071 GstElement *preview;
1074 if (priv->video_preview == NULL)
1076 create_video_preview (window);
1077 add_video_preview_to_pipeline (window);
1081 state = GST_STATE_PLAYING;
1083 state = GST_STATE_NULL;
1085 preview = priv->video_preview_sink;
1087 gst_element_set_state (preview, state);
1088 gst_element_set_state (priv->video_input, state);
1089 gst_element_set_state (priv->video_tee, state);
1093 display_video_preview (EmpathyCallWindow *self,
1096 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1100 /* Display the video preview */
1101 DEBUG ("Show video preview");
1103 play_camera (self, TRUE);
1104 clutter_actor_show (priv->video_preview);
1105 clutter_actor_raise_top (priv->floating_toolbar);
1109 /* Hide the video preview */
1110 DEBUG ("Hide video preview");
1112 if (priv->video_preview != NULL)
1114 clutter_actor_hide (priv->video_preview);
1115 play_camera (self, FALSE);
1121 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1123 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1125 empathy_call_window_status_message (window, _("Connecting…"));
1126 priv->call_state = CONNECTING;
1129 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1130 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1134 disable_camera (EmpathyCallWindow *self)
1136 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1138 if (priv->camera_state == CAMERA_STATE_OFF)
1141 DEBUG ("Disable camera");
1143 display_video_preview (self, FALSE);
1145 if (priv->camera_state == CAMERA_STATE_ON)
1146 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1148 priv->camera_state = CAMERA_STATE_OFF;
1152 enable_camera (EmpathyCallWindow *self)
1154 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1156 if (priv->camera_state == CAMERA_STATE_ON)
1159 if (priv->video_input == NULL)
1161 DEBUG ("Can't enable camera, no input");
1165 DEBUG ("Enable camera");
1167 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1169 priv->camera_state = CAMERA_STATE_ON;
1173 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1174 EmpathyCallWindow *self)
1176 if (gtk_toggle_tool_button_get_active (toggle))
1177 enable_camera (self);
1179 disable_camera (self);
1183 create_pipeline (EmpathyCallWindow *self)
1185 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1188 g_assert (priv->pipeline == NULL);
1190 priv->pipeline = gst_pipeline_new (NULL);
1191 priv->pipeline_playing = FALSE;
1193 priv->video_tee = gst_element_factory_make ("tee", NULL);
1194 gst_object_ref (priv->video_tee);
1195 gst_object_sink (priv->video_tee);
1197 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1199 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1200 priv->bus_message_source_id = gst_bus_add_watch (bus,
1201 empathy_call_window_bus_message, self);
1203 g_object_unref (bus);
1207 empathy_call_window_settings_cb (GtkAction *action,
1208 EmpathyCallWindow *self)
1210 gchar *args = g_strdup_printf ("-p %s",
1211 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1213 empathy_launch_program (BIN_DIR, "empathy", args);
1219 empathy_call_window_contents_cb (GtkAction *action,
1220 EmpathyCallWindow *self)
1222 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1226 empathy_call_window_debug_cb (GtkAction *action,
1227 EmpathyCallWindow *self)
1229 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1233 empathy_call_window_about_cb (GtkAction *action,
1234 EmpathyCallWindow *self)
1236 empathy_about_dialog_new (GTK_WINDOW (self));
1240 empathy_call_window_toolbar_timeout (gpointer data)
1242 EmpathyCallWindow *self = data;
1244 clutter_state_set_state (self->priv->transitions, "fade-out");
1250 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1252 EmpathyCallWindow *self)
1254 clutter_state_set_state (self->priv->transitions, "fade-in");
1256 if (self->priv->inactivity_src > 0)
1257 g_source_remove (self->priv->inactivity_src);
1259 self->priv->inactivity_src = g_timeout_add_seconds (3,
1260 empathy_call_window_toolbar_timeout, self);
1266 empathy_call_window_configure_event_cb (GtkWidget *widget,
1268 EmpathyCallWindow *self)
1270 GdkWindow *gdk_window;
1271 GdkWindowState window_state;
1273 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1274 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1276 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1277 &self->priv->dialpad_width, NULL);
1279 gdk_window = gtk_widget_get_window (widget);
1280 window_state = gdk_window_get_state (gdk_window);
1281 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1287 empathy_call_window_destroyed_cb (GtkWidget *object,
1288 EmpathyCallWindow *self)
1290 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1292 /* Save the geometry as if the dialpad was hidden. */
1293 empathy_geometry_save_values (GTK_WINDOW (self),
1294 self->priv->x, self->priv->y,
1295 self->priv->w - self->priv->dialpad_width, self->priv->h,
1296 self->priv->maximized);
1301 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1303 ClutterBindConstraint *constraint)
1305 ClutterActorBox allocation;
1307 clutter_actor_get_allocation_box (stage, &allocation);
1309 clutter_bind_constraint_set_offset (constraint,
1310 allocation.y2 - allocation.y1 -
1311 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1315 empathy_call_window_init (EmpathyCallWindow *self)
1317 EmpathyCallWindowPriv *priv;
1319 GtkWidget *top_vbox;
1321 ClutterConstraint *constraint;
1322 ClutterActor *remote_avatar;
1323 GtkStyleContext *context;
1327 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1328 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1330 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1331 gui = empathy_builder_get_file (filename,
1332 "call_window_vbox", &top_vbox,
1333 "errors_vbox", &priv->errors_vbox,
1334 "pane", &priv->pane,
1335 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1336 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1337 "status_label", &priv->status_label,
1338 "audiocall", &priv->audio_call_button,
1339 "videocall", &priv->video_call_button,
1340 "microphone", &priv->mic_button,
1341 "camera", &priv->camera_button,
1342 "hangup", &priv->hangup_button,
1343 "dialpad", &priv->dialpad_button,
1344 "toolbar", &priv->toolbar,
1345 "bottom_toolbar", &priv->bottom_toolbar,
1346 "ui_manager", &priv->ui_manager,
1347 "menufullscreen", &priv->menu_fullscreen,
1348 "menupreviewswap", &priv->menu_swap_camera,
1349 "details_vbox", &priv->details_vbox,
1350 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1351 "acodec_encoding_label", &priv->acodec_encoding_label,
1352 "acodec_decoding_label", &priv->acodec_decoding_label,
1353 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1354 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1355 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1356 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1357 "video_local_candidate_label", &priv->video_local_candidate_label,
1358 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1359 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1360 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1361 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1365 empathy_builder_connect (gui, self,
1366 "hangup", "clicked", empathy_call_window_hangup_cb,
1367 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1368 "videocall", "clicked", empathy_call_window_video_call_cb,
1369 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1370 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1371 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1372 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1373 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1374 "menusettings", "activate", empathy_call_window_settings_cb,
1375 "menucontents", "activate", empathy_call_window_contents_cb,
1376 "menudebug", "activate", empathy_call_window_debug_cb,
1377 "menuabout", "activate", empathy_call_window_about_cb,
1378 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1379 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1380 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1381 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1384 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1386 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1388 g_object_bind_property (priv->camera_monitor, "available",
1389 priv->camera_button, "sensitive",
1390 G_BINDING_SYNC_CREATE);
1392 g_signal_connect (priv->camera_monitor, "added",
1393 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1394 g_signal_connect (priv->camera_monitor, "removed",
1395 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1397 priv->lock = g_mutex_new ();
1399 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1401 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1402 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1403 CONTENT_HBOX_BORDER_WIDTH);
1404 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1407 /* avatar/video box */
1408 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1409 CLUTTER_BIN_ALIGNMENT_CENTER);
1411 priv->video_box = clutter_box_new (priv->video_layout);
1413 priv->video_container = gtk_clutter_embed_new ();
1415 /* Set the background color to that of the rest of the window */
1416 context = gtk_widget_get_style_context (priv->content_hbox);
1417 gtk_style_context_get_background_color (context,
1418 GTK_STATE_FLAG_NORMAL, &rgba);
1419 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1420 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1421 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1422 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1423 clutter_stage_set_color (
1424 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1425 GTK_CLUTTER_EMBED (priv->video_container))),
1428 clutter_container_add (
1429 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1430 GTK_CLUTTER_EMBED (priv->video_container))),
1434 constraint = clutter_bind_constraint_new (
1435 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1436 CLUTTER_BIND_SIZE, 0);
1437 clutter_actor_add_constraint (priv->video_box, constraint);
1439 priv->remote_user_avatar_widget = gtk_image_new ();
1440 remote_avatar = gtk_clutter_actor_new_with_contents (
1441 priv->remote_user_avatar_widget);
1443 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1446 empathy_call_window_create_preview_rectangles (self);
1448 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1449 priv->video_container, TRUE, TRUE,
1450 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1452 create_pipeline (self);
1453 create_video_output_widget (self);
1454 create_audio_input (self);
1455 create_video_input (self);
1457 priv->floating_toolbar = empathy_rounded_actor_new ();
1459 gtk_widget_reparent (priv->bottom_toolbar,
1460 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1462 constraint = clutter_bind_constraint_new (
1463 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1466 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1469 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1470 "notify::allocation",
1471 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1474 clutter_actor_set_size (priv->floating_toolbar,
1475 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1476 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1478 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1479 priv->floating_toolbar,
1480 CLUTTER_BIN_ALIGNMENT_CENTER,
1481 CLUTTER_BIN_ALIGNMENT_END);
1483 clutter_actor_raise_top (priv->floating_toolbar);
1485 /* Transitions for the floating toolbar */
1486 priv->transitions = clutter_state_new ();
1488 /* all transitions last for 2s */
1489 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1491 /* transition from any state to "fade-out" state */
1492 clutter_state_set (priv->transitions, NULL, "fade-out",
1493 priv->floating_toolbar,
1494 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1497 /* transition from any state to "fade-in" state */
1498 clutter_state_set (priv->transitions, NULL, "fade-in",
1499 priv->floating_toolbar,
1500 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1503 /* put the actor into the "fade-in" state with no animation */
1504 clutter_state_warp_to_state (priv->transitions, "fade-in");
1506 /* The call will be started as soon the pipeline is playing */
1507 priv->start_call_when_playing = TRUE;
1509 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1510 G_CALLBACK (dtmf_button_pressed_cb),
1511 G_CALLBACK (dtmf_button_released_cb));
1513 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1516 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1519 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1521 gtk_widget_show_all (top_vbox);
1523 gtk_widget_hide (priv->dtmf_panel);
1524 gtk_widget_hide (priv->details_vbox);
1526 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1528 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1529 priv->video_container);
1531 /* We hide the bottom toolbar after 3s of inactivity and show it
1532 * again on mouse movement */
1533 priv->inactivity_src = g_timeout_add_seconds (3,
1534 empathy_call_window_toolbar_timeout, self);
1536 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1537 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1539 g_signal_connect (G_OBJECT (self), "realize",
1540 G_CALLBACK (empathy_call_window_realized_cb), self);
1542 g_signal_connect (G_OBJECT (self), "delete-event",
1543 G_CALLBACK (empathy_call_window_delete_cb), self);
1545 g_signal_connect (G_OBJECT (self), "window-state-event",
1546 G_CALLBACK (empathy_call_window_state_event_cb), self);
1548 g_signal_connect (G_OBJECT (self), "key-press-event",
1549 G_CALLBACK (empathy_call_window_key_press_cb), self);
1551 g_signal_connect (self, "motion-notify-event",
1552 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1554 priv->timer = g_timer_new ();
1556 g_object_ref (priv->ui_manager);
1557 g_object_unref (gui);
1559 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1560 priv->mic_menu = empathy_mic_menu_new (self);
1561 priv->camera_menu = empathy_camera_menu_new (self);
1563 empathy_call_window_show_hangup_button (self, TRUE);
1565 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1567 /* Retrieve initial volume */
1568 priv->volume = g_settings_get_double (priv->settings,
1569 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1571 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1572 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1574 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1575 /* These signals are used to track the window position and save it
1576 * when the window is destroyed. We need to do this as we don't want
1577 * the window geometry to be saved with the dialpad taken into account. */
1578 g_signal_connect (self, "destroy",
1579 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1580 g_signal_connect (self, "configure-event",
1581 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1582 g_signal_connect (self, "window-state-event",
1583 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1585 /* Don't display labels in both toolbars */
1586 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1589 /* Instead of specifying a width and a height, we specify only one size. That's
1590 because we want a square avatar icon. */
1592 init_contact_avatar_with_size (EmpathyContact *contact,
1593 GtkWidget *image_widget,
1596 GdkPixbuf *pixbuf_avatar = NULL;
1598 if (contact != NULL)
1600 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1604 if (pixbuf_avatar == NULL)
1606 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1607 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1610 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1612 if (pixbuf_avatar != NULL)
1613 g_object_unref (pixbuf_avatar);
1617 set_window_title (EmpathyCallWindow *self)
1619 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1622 if (priv->contact != NULL)
1624 /* translators: Call is a noun and %s is the contact name. This string
1625 * is used in the window title */
1626 tmp = g_strdup_printf (_("Call with %s"),
1627 empathy_contact_get_alias (priv->contact));
1628 gtk_window_set_title (GTK_WINDOW (self), tmp);
1633 g_warning ("Unknown remote contact!");
1638 set_remote_user_name (EmpathyCallWindow *self,
1639 EmpathyContact *contact)
1641 const gchar *alias = empathy_contact_get_alias (contact);
1642 const gchar *status = empathy_contact_get_status (contact);
1645 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1646 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1652 contact_name_changed_cb (EmpathyContact *contact,
1654 EmpathyCallWindow *self)
1656 set_window_title (self);
1657 set_remote_user_name (self, contact);
1661 contact_presence_changed_cb (EmpathyContact *contact,
1663 EmpathyCallWindow *self)
1665 set_remote_user_name (self, contact);
1669 contact_avatar_changed_cb (EmpathyContact *contact,
1671 EmpathyCallWindow *self)
1674 GtkAllocation allocation;
1675 GtkWidget *avatar_widget;
1677 avatar_widget = self->priv->remote_user_avatar_widget;
1679 gtk_widget_get_allocation (avatar_widget, &allocation);
1680 size = allocation.height;
1684 /* the widget is not allocated yet, set a default size */
1685 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1686 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1689 init_contact_avatar_with_size (contact, avatar_widget, size);
1691 avatar_widget = self->priv->remote_user_avatar_toolbar;
1693 gtk_widget_get_allocation (avatar_widget, &allocation);
1694 size = allocation.height;
1698 /* the widget is not allocated yet, set a default size */
1699 size = SMALL_TOOLBAR_SIZE;
1702 init_contact_avatar_with_size (contact, avatar_widget, size);
1706 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1707 EmpathyCallHandler *handler)
1709 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1711 tp_g_signal_connect_object (priv->contact, "notify::name",
1712 G_CALLBACK (contact_name_changed_cb), self, 0);
1713 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1714 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1715 tp_g_signal_connect_object (priv->contact, "notify::presence",
1716 G_CALLBACK (contact_presence_changed_cb), self, 0);
1718 set_window_title (self);
1719 set_remote_user_name (self, priv->contact);
1721 init_contact_avatar_with_size (priv->contact,
1722 priv->remote_user_avatar_widget,
1723 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1724 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1726 init_contact_avatar_with_size (priv->contact,
1727 priv->remote_user_avatar_toolbar,
1728 SMALL_TOOLBAR_SIZE);
1730 /* The remote avatar is shown by default and will be hidden when we receive
1731 video from the remote side. */
1732 clutter_actor_hide (priv->video_output);
1733 gtk_widget_show (priv->remote_user_avatar_widget);
1737 update_send_codec (EmpathyCallWindow *self,
1740 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1747 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1748 widget = priv->acodec_encoding_label;
1752 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1753 widget = priv->vcodec_encoding_label;
1759 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1760 gtk_label_set_text (GTK_LABEL (widget), tmp);
1765 send_audio_codec_notify_cb (GObject *object,
1769 EmpathyCallWindow *self = user_data;
1771 update_send_codec (self, TRUE);
1775 send_video_codec_notify_cb (GObject *object,
1779 EmpathyCallWindow *self = user_data;
1781 update_send_codec (self, FALSE);
1785 update_recv_codec (EmpathyCallWindow *self,
1788 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1791 GString *str = NULL;
1795 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1796 widget = priv->acodec_decoding_label;
1800 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1801 widget = priv->vcodec_decoding_label;
1807 for (l = codecs; l != NULL; l = g_list_next (l))
1809 FsCodec *codec = l->data;
1812 str = g_string_new (NULL);
1814 g_string_append (str, ", ");
1816 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1820 gtk_label_set_text (GTK_LABEL (widget), str->str);
1821 g_string_free (str, TRUE);
1825 recv_audio_codecs_notify_cb (GObject *object,
1829 EmpathyCallWindow *self = user_data;
1831 update_recv_codec (self, TRUE);
1835 recv_video_codecs_notify_cb (GObject *object,
1839 EmpathyCallWindow *self = user_data;
1841 update_recv_codec (self, FALSE);
1844 static const gchar *
1845 candidate_type_to_str (FsCandidate *candidate)
1847 switch (candidate->type)
1849 case FS_CANDIDATE_TYPE_HOST:
1851 case FS_CANDIDATE_TYPE_SRFLX:
1852 return "server reflexive";
1853 case FS_CANDIDATE_TYPE_PRFLX:
1854 return "peer reflexive";
1855 case FS_CANDIDATE_TYPE_RELAY:
1857 case FS_CANDIDATE_TYPE_MULTICAST:
1864 static const gchar *
1865 candidate_type_to_desc (FsCandidate *candidate)
1867 switch (candidate->type)
1869 case FS_CANDIDATE_TYPE_HOST:
1870 return _("The IP address as seen by the machine");
1871 case FS_CANDIDATE_TYPE_SRFLX:
1872 return _("The IP address as seen by a server on the Internet");
1873 case FS_CANDIDATE_TYPE_PRFLX:
1874 return _("The IP address of the peer as seen by the other side");
1875 case FS_CANDIDATE_TYPE_RELAY:
1876 return _("The IP address of a relay server");
1877 case FS_CANDIDATE_TYPE_MULTICAST:
1878 return _("The IP address of the multicast group");
1885 update_candidat_widget (EmpathyCallWindow *self,
1888 FsCandidate *candidate)
1892 g_assert (candidate != NULL);
1893 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1894 candidate->port, candidate_type_to_str (candidate));
1896 gtk_label_set_text (GTK_LABEL (label), str);
1897 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1903 candidates_changed_cb (GObject *object,
1905 EmpathyCallWindow *self)
1907 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1908 FsCandidate *candidate = NULL;
1910 if (type == FS_MEDIA_TYPE_VIDEO)
1912 /* Update remote candidate */
1913 candidate = empathy_call_handler_get_video_remote_candidate (
1916 update_candidat_widget (self, priv->video_remote_candidate_label,
1917 priv->video_remote_candidate_info_img, candidate);
1919 /* Update local candidate */
1920 candidate = empathy_call_handler_get_video_local_candidate (
1923 update_candidat_widget (self, priv->video_local_candidate_label,
1924 priv->video_local_candidate_info_img, candidate);
1928 /* Update remote candidate */
1929 candidate = empathy_call_handler_get_audio_remote_candidate (
1932 update_candidat_widget (self, priv->audio_remote_candidate_label,
1933 priv->audio_remote_candidate_info_img, candidate);
1935 /* Update local candidate */
1936 candidate = empathy_call_handler_get_audio_local_candidate (
1939 update_candidat_widget (self, priv->audio_local_candidate_label,
1940 priv->audio_local_candidate_info_img, candidate);
1945 empathy_call_window_constructed (GObject *object)
1947 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1948 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1949 TpyCallChannel *call;
1951 g_assert (priv->handler != NULL);
1953 g_object_get (priv->handler, "call-channel", &call, NULL);
1954 priv->outgoing = (call == NULL);
1956 g_object_unref (call);
1958 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1959 g_assert (priv->contact != NULL);
1961 empathy_call_window_setup_avatars (self, priv->handler);
1962 empathy_call_window_set_state_connecting (self);
1964 if (!empathy_call_handler_has_initial_video (priv->handler))
1966 gtk_toggle_tool_button_set_active (
1967 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1969 /* If call has InitialVideo, the preview will be started once the call has
1970 * been started (start_call()). */
1972 update_send_codec (self, TRUE);
1973 update_send_codec (self, FALSE);
1974 update_recv_codec (self, TRUE);
1975 update_recv_codec (self, FALSE);
1977 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1978 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1979 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1980 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1981 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1982 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1983 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1984 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1986 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1987 G_CALLBACK (candidates_changed_cb), self, 0);
1990 static void empathy_call_window_dispose (GObject *object);
1991 static void empathy_call_window_finalize (GObject *object);
1994 empathy_call_window_set_property (GObject *object,
1995 guint property_id, const GValue *value, GParamSpec *pspec)
1997 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1999 switch (property_id)
2001 case PROP_CALL_HANDLER:
2002 priv->handler = g_value_dup_object (value);
2005 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2010 empathy_call_window_get_property (GObject *object,
2011 guint property_id, GValue *value, GParamSpec *pspec)
2013 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2015 switch (property_id)
2017 case PROP_CALL_HANDLER:
2018 g_value_set_object (value, priv->handler);
2021 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2026 empathy_call_window_class_init (
2027 EmpathyCallWindowClass *empathy_call_window_class)
2029 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2030 GParamSpec *param_spec;
2032 g_type_class_add_private (empathy_call_window_class,
2033 sizeof (EmpathyCallWindowPriv));
2035 object_class->constructed = empathy_call_window_constructed;
2036 object_class->set_property = empathy_call_window_set_property;
2037 object_class->get_property = empathy_call_window_get_property;
2039 object_class->dispose = empathy_call_window_dispose;
2040 object_class->finalize = empathy_call_window_finalize;
2042 param_spec = g_param_spec_object ("handler",
2043 "handler", "The call handler",
2044 EMPATHY_TYPE_CALL_HANDLER,
2045 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2046 g_object_class_install_property (object_class,
2047 PROP_CALL_HANDLER, param_spec);
2051 empathy_call_window_dispose (GObject *object)
2053 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2054 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2056 if (priv->dispose_has_run)
2059 priv->dispose_has_run = TRUE;
2061 if (priv->handler != NULL)
2063 empathy_call_handler_stop_call (priv->handler);
2064 tp_clear_object (&priv->handler);
2067 if (priv->bus_message_source_id != 0)
2069 g_source_remove (priv->bus_message_source_id);
2070 priv->bus_message_source_id = 0;
2073 if (priv->got_video_src > 0)
2075 g_source_remove (priv->got_video_src);
2076 priv->got_video_src = 0;
2079 if (priv->inactivity_src > 0)
2081 g_source_remove (priv->inactivity_src);
2082 priv->inactivity_src = 0;
2085 tp_clear_object (&priv->pipeline);
2086 tp_clear_object (&priv->video_input);
2087 tp_clear_object (&priv->audio_input);
2088 tp_clear_object (&priv->video_tee);
2089 tp_clear_object (&priv->ui_manager);
2090 tp_clear_object (&priv->fullscreen);
2091 tp_clear_object (&priv->camera_monitor);
2092 tp_clear_object (&priv->settings);
2093 tp_clear_object (&priv->sound_mgr);
2094 tp_clear_object (&priv->mic_menu);
2095 tp_clear_object (&priv->camera_menu);
2097 g_list_free_full (priv->notifiers, g_object_unref);
2099 if (priv->timer_id != 0)
2100 g_source_remove (priv->timer_id);
2103 if (priv->contact != NULL)
2105 g_signal_handlers_disconnect_by_func (priv->contact,
2106 contact_name_changed_cb, self);
2107 priv->contact = NULL;
2110 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2114 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2116 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2118 if (priv->video_output_motion_handler_id != 0)
2120 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2121 priv->video_output_motion_handler_id);
2122 priv->video_output_motion_handler_id = 0;
2127 empathy_call_window_finalize (GObject *object)
2129 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2130 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2132 disconnect_video_output_motion_handler (self);
2134 /* free any data held directly by the object here */
2135 g_mutex_free (priv->lock);
2137 g_timer_destroy (priv->timer);
2139 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2144 empathy_call_window_new (EmpathyCallHandler *handler)
2146 return EMPATHY_CALL_WINDOW (
2147 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2151 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2152 GstElement *conference, gpointer user_data)
2154 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2155 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2156 FsElementAddedNotifier *notifier;
2159 DEBUG ("Conference added");
2161 /* Add notifier to set the various element properties as needed */
2162 notifier = fs_element_added_notifier_new ();
2163 keyfile = fs_utils_get_default_element_properties (conference);
2165 if (keyfile != NULL)
2166 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2168 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2170 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2172 gst_bin_add (GST_BIN (priv->pipeline), conference);
2173 gst_element_set_state (conference, GST_STATE_PLAYING);
2177 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2178 GstElement *conference, gpointer user_data)
2180 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2181 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2183 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2184 gst_element_set_state (conference, GST_STATE_NULL);
2188 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2190 GstStateChangeReturn state_change_return;
2191 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2193 if (priv->pipeline == NULL)
2196 if (priv->bus_message_source_id != 0)
2198 g_source_remove (priv->bus_message_source_id);
2199 priv->bus_message_source_id = 0;
2202 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2204 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2205 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2207 if (priv->pipeline != NULL)
2208 g_object_unref (priv->pipeline);
2209 priv->pipeline = NULL;
2211 if (priv->audio_output != NULL)
2212 g_object_unref (priv->audio_output);
2213 priv->audio_output = NULL;
2215 if (priv->video_tee != NULL)
2216 g_object_unref (priv->video_tee);
2217 priv->video_tee = NULL;
2219 if (priv->video_preview != NULL)
2220 clutter_actor_destroy (priv->video_preview);
2221 priv->video_preview = NULL;
2223 priv->funnel = NULL;
2225 create_pipeline (self);
2226 /* Call will be started when user will hit the 'redial' button */
2227 priv->start_call_when_playing = FALSE;
2228 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2234 g_message ("Error: could not destroy pipeline. Closing call window");
2235 gtk_widget_destroy (GTK_WIDGET (self));
2242 reset_details_pane (EmpathyCallWindow *self)
2244 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2246 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2247 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2248 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2249 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2253 empathy_call_window_disconnected (EmpathyCallWindow *self,
2256 gboolean could_disconnect = FALSE;
2257 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2258 gboolean could_reset_pipeline;
2260 /* Leave full screen mode if needed */
2261 gtk_window_unfullscreen (GTK_WINDOW (self));
2263 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2264 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2266 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2268 if (priv->call_state == CONNECTING)
2269 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2271 if (priv->call_state != REDIALING)
2272 priv->call_state = DISCONNECTED;
2274 if (could_reset_pipeline)
2276 g_mutex_lock (priv->lock);
2278 g_timer_stop (priv->timer);
2280 if (priv->timer_id != 0)
2281 g_source_remove (priv->timer_id);
2284 g_mutex_unlock (priv->lock);
2287 /* We are about to destroy the window, no need to update it or create
2288 * a video preview */
2291 empathy_call_window_status_message (self, _("Disconnected"));
2293 empathy_call_window_show_hangup_button (self, FALSE);
2295 /* Unsensitive the camera and mic button */
2296 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2297 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2299 /* Be sure that the mic button is enabled */
2300 gtk_toggle_tool_button_set_active (
2301 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2303 if (priv->camera_state == CAMERA_STATE_ON)
2305 /* Restart the preview with the new pipeline. */
2306 display_video_preview (self, TRUE);
2309 /* destroy the video output; it will be recreated when we'll redial */
2310 disconnect_video_output_motion_handler (self);
2311 if (priv->video_output != NULL)
2312 clutter_actor_destroy (priv->video_output);
2313 priv->video_output = NULL;
2314 if (priv->got_video_src > 0)
2316 g_source_remove (priv->got_video_src);
2317 priv->got_video_src = 0;
2320 gtk_widget_show (priv->remote_user_avatar_widget);
2322 reset_details_pane (self);
2324 priv->sending_video = FALSE;
2325 priv->call_started = FALSE;
2327 could_disconnect = TRUE;
2329 /* TODO: display the self avatar of the preview (depends if the "Always
2330 * Show Video Preview" is enabled or not) */
2333 return could_disconnect;
2338 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2341 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2342 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2344 if (empathy_call_window_disconnected (self, TRUE) &&
2345 priv->call_state == REDIALING)
2346 empathy_call_window_restart_call (self);
2350 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2352 FsMediaType media_type,
2353 EmpathyCallWindow *self)
2355 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2357 DEBUG ("removing content");
2360 * This assumes that there is only one video stream per channel...
2363 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2365 if (priv->funnel != NULL)
2369 output = priv->video_output_sink;
2371 gst_element_set_state (output, GST_STATE_NULL);
2372 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2374 gst_bin_remove (GST_BIN (priv->pipeline), output);
2375 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2376 priv->funnel = NULL;
2380 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2382 if (priv->audio_output != NULL)
2384 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2386 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2387 priv->audio_output = NULL;
2395 /* Called with global lock held */
2397 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2399 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2403 if (priv->funnel == NULL)
2405 output = priv->video_output_sink;
2407 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2411 g_warning ("Could not create fsfunnel");
2415 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2417 gst_object_unref (priv->funnel);
2418 priv->funnel = NULL;
2419 g_warning ("Could not add funnel to pipeline");
2423 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2425 g_warning ("Could not add the video output widget to the pipeline");
2429 if (!gst_element_link (priv->funnel, output))
2431 g_warning ("Could not link output sink to funnel");
2432 goto error_output_added;
2435 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2437 g_warning ("Could not start video sink");
2438 goto error_output_added;
2441 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2443 g_warning ("Could not start funnel");
2444 goto error_output_added;
2448 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2451 g_warning ("Could not get request pad from funnel");
2458 gst_element_set_locked_state (priv->funnel, TRUE);
2459 gst_element_set_locked_state (output, TRUE);
2461 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2462 gst_element_set_state (output, GST_STATE_NULL);
2464 gst_bin_remove (GST_BIN (priv->pipeline), output);
2465 gst_element_set_locked_state (output, FALSE);
2469 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2470 priv->funnel = NULL;
2475 /* Called with global lock held */
2477 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2479 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2481 GstPadTemplate *template;
2483 if (priv->audio_output == NULL)
2485 priv->audio_output = empathy_audio_sink_new ();
2486 g_object_ref_sink (priv->audio_output);
2488 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2490 g_warning ("Could not add audio sink to pipeline");
2491 g_object_unref (priv->audio_output);
2492 goto error_add_output;
2495 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2497 g_warning ("Could not start audio sink");
2502 template = gst_element_class_get_pad_template (
2503 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2505 pad = gst_element_request_pad (priv->audio_output,
2506 template, NULL, NULL);
2510 g_warning ("Could not get sink pad from sink");
2517 gst_element_set_locked_state (priv->audio_output, TRUE);
2518 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2519 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2520 priv->audio_output = NULL;
2528 empathy_call_window_update_timer (gpointer user_data)
2530 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2531 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2532 const gchar *status;
2536 time_ = g_timer_elapsed (priv->timer, NULL);
2538 if (priv->call_state == HELD)
2539 status = _("On hold");
2540 else if (!gtk_toggle_tool_button_get_active (
2541 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2544 status = _("Duration");
2546 /* Translators: 'status - minutes:seconds' the caller has been connected */
2547 str = g_strdup_printf (_("%s — %d:%02dm"),
2549 (int) time_ / 60, (int) time_ % 60);
2550 empathy_call_window_status_message (self, str);
2558 display_error (EmpathyCallWindow *self,
2559 TpyCallChannel *call,
2563 const gchar *details)
2565 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2566 GtkWidget *info_bar;
2567 GtkWidget *content_area;
2574 /* Create info bar */
2575 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2578 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2580 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2582 /* hbox containing the image and the messages vbox */
2583 hbox = gtk_hbox_new (FALSE, 3);
2584 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2587 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2588 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2590 /* vbox containing the main message and the details expander */
2591 vbox = gtk_vbox_new (FALSE, 3);
2592 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2595 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2597 label = gtk_label_new (NULL);
2598 gtk_label_set_markup (GTK_LABEL (label), txt);
2599 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2600 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2603 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2606 if (details != NULL)
2608 GtkWidget *expander;
2610 expander = gtk_expander_new (_("Technical Details"));
2612 txt = g_strdup_printf ("<i>%s</i>", details);
2614 label = gtk_label_new (NULL);
2615 gtk_label_set_markup (GTK_LABEL (label), txt);
2616 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2617 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2620 gtk_container_add (GTK_CONTAINER (expander), label);
2621 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2624 g_signal_connect (info_bar, "response",
2625 G_CALLBACK (gtk_widget_destroy), NULL);
2627 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2628 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2629 gtk_widget_show_all (info_bar);
2633 media_stream_error_to_txt (EmpathyCallWindow *self,
2634 TpyCallChannel *call,
2636 TpMediaStreamError error)
2638 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2639 const gchar *cm = NULL;
2645 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2647 return g_strdup_printf (
2648 _("%s's software does not understand any of the audio formats "
2649 "supported by your computer"),
2650 empathy_contact_get_alias (priv->contact));
2652 return g_strdup_printf (
2653 _("%s's software does not understand any of the video formats "
2654 "supported by your computer"),
2655 empathy_contact_get_alias (priv->contact));
2657 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2658 return g_strdup_printf (
2659 _("Can't establish a connection to %s. "
2660 "One of you might be on a network that does not allow "
2661 "direct connections."),
2662 empathy_contact_get_alias (priv->contact));
2664 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2665 return g_strdup (_("There was a failure on the network"));
2667 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2669 return g_strdup (_("The audio formats necessary for this call "
2670 "are not installed on your computer"));
2672 return g_strdup (_("The video formats necessary for this call "
2673 "are not installed on your computer"));
2675 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2676 tp_connection_parse_object_path (
2677 tp_channel_borrow_connection (TP_CHANNEL (call)),
2680 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2681 "product=Telepathy&component=%s", cm);
2683 result = g_strdup_printf (
2684 _("Something unexpected happened in a Telepathy component. "
2685 "Please <a href=\"%s\">report this bug</a> and attach "
2686 "logs gathered from the 'Debug' window in the Help menu."), url);
2692 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2693 return g_strdup (_("There was a failure in the call engine"));
2695 case TP_MEDIA_STREAM_ERROR_EOS:
2696 return g_strdup (_("The end of the stream was reached"));
2698 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2705 empathy_call_window_stream_error (EmpathyCallWindow *self,
2706 TpyCallChannel *call,
2715 desc = media_stream_error_to_txt (self, call, audio, code);
2718 /* No description, use the error message. That's not great as it's not
2719 * localized but it's better than nothing. */
2720 display_error (self, call, icon, title, msg, NULL);
2724 display_error (self, call, icon, title, desc, msg);
2730 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2733 EmpathyCallWindow *self)
2735 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2736 "gnome-stock-mic", _("Can't establish audio stream"));
2740 empathy_call_window_video_stream_error (TpyCallChannel *call,
2743 EmpathyCallWindow *self)
2745 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2746 "camera-web", _("Can't establish video stream"));
2751 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2753 EmpathyCallWindow *self)
2755 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2756 TpyCallChannel *call;
2757 gboolean can_send_video;
2759 if (state != TPY_CALL_STATE_ACCEPTED)
2762 if (priv->call_state == CONNECTED)
2765 g_timer_start (priv->timer);
2766 priv->call_state = CONNECTED;
2768 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2770 can_send_video = priv->video_input != NULL &&
2771 empathy_contact_can_voip_video (priv->contact) &&
2772 empathy_camera_monitor_get_available (priv->camera_monitor);
2774 g_object_get (priv->handler, "call-channel", &call, NULL);
2776 if (tpy_call_channel_has_dtmf (call))
2777 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2779 if (priv->video_input == NULL)
2780 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2782 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2784 empathy_call_window_show_hangup_button (self, TRUE);
2786 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2788 clutter_actor_hide (priv->video_output);
2789 gtk_widget_show (priv->remote_user_avatar_widget);
2791 g_object_unref (call);
2793 g_mutex_lock (priv->lock);
2795 priv->timer_id = g_timeout_add_seconds (1,
2796 empathy_call_window_update_timer, self);
2798 g_mutex_unlock (priv->lock);
2800 empathy_call_window_update_timer (self);
2802 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2806 empathy_call_window_show_video_output_cb (gpointer user_data)
2808 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2810 if (self->priv->video_output != NULL)
2812 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2813 clutter_actor_show (self->priv->video_output);
2814 empathy_call_window_raise_actors (self);
2821 empathy_call_window_check_video_cb (gpointer data)
2823 EmpathyCallWindow *self = data;
2825 if (self->priv->got_video)
2827 self->priv->got_video = FALSE;
2831 /* No video in the last N seconds, display the remote avatar */
2832 empathy_call_window_show_video_output (self, FALSE);
2837 /* Called from the streaming thread */
2839 empathy_call_window_video_probe_cb (GstPad *pad,
2840 GstMiniObject *mini_obj,
2841 EmpathyCallWindow *self)
2844 if (GST_IS_EVENT (mini_obj))
2847 if (G_UNLIKELY (!self->priv->got_video))
2849 /* show the remote video */
2850 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2851 empathy_call_window_show_video_output_cb,
2852 g_object_ref (self), g_object_unref);
2854 self->priv->got_video = TRUE;
2860 /* Called from the streaming thread */
2862 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2863 GstPad *src, guint media_type, gpointer user_data)
2865 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2866 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2867 gboolean retval = FALSE;
2871 g_mutex_lock (priv->lock);
2875 case TP_MEDIA_STREAM_TYPE_AUDIO:
2876 pad = empathy_call_window_get_audio_sink_pad (self);
2878 case TP_MEDIA_STREAM_TYPE_VIDEO:
2879 g_idle_add (empathy_call_window_show_video_output_cb, self);
2880 pad = empathy_call_window_get_video_sink_pad (self);
2882 gst_pad_add_data_probe (src,
2883 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2884 if (priv->got_video_src > 0)
2885 g_source_remove (priv->got_video_src);
2886 priv->got_video_src = g_timeout_add_seconds (5,
2887 empathy_call_window_check_video_cb, self);
2890 g_assert_not_reached ();
2896 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2897 g_warning ("Could not link %s sink pad",
2898 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2902 gst_object_unref (pad);
2906 /* If no sink could be linked, try to add fakesink to prevent the whole call
2911 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2913 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2915 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2916 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2917 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2919 gst_element_set_locked_state (fakesink, TRUE);
2920 gst_element_set_state (fakesink, GST_STATE_NULL);
2921 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2925 DEBUG ("Could not link real sink, linked fakesink instead");
2927 gst_object_unref (sinkpad);
2931 gst_object_unref (fakesink);
2936 g_mutex_unlock (priv->lock);
2942 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2943 GstPad *sink, FsMediaType media_type, gpointer user_data)
2945 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2946 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2948 gboolean retval = FALSE;
2952 case FS_MEDIA_TYPE_AUDIO:
2953 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2955 g_warning ("Could not add audio source to pipeline");
2959 pad = gst_element_get_static_pad (priv->audio_input, "src");
2962 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2963 g_warning ("Could not get source pad from audio source");
2967 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2969 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2970 g_warning ("Could not link audio source to farsight");
2974 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2976 g_warning ("Could not start audio source");
2977 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2978 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2984 case FS_MEDIA_TYPE_VIDEO:
2985 if (priv->video_tee != NULL)
2987 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2988 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2990 g_warning ("Could not link video source input pipeline");
2993 gst_object_unref (pad);
2999 g_assert_not_reached ();
3006 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3008 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3009 GstElement *preview;
3011 disable_camera (self);
3013 DEBUG ("remove video input");
3014 preview = priv->video_preview_sink;
3016 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3017 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3018 gst_element_set_state (preview, GST_STATE_NULL);
3020 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3023 g_object_unref (priv->video_input);
3024 priv->video_input = NULL;
3025 g_object_unref (priv->video_tee);
3026 priv->video_tee = NULL;
3027 clutter_actor_destroy (priv->video_preview);
3028 priv->video_preview = NULL;
3030 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3034 start_call (EmpathyCallWindow *self)
3036 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3038 priv->call_started = TRUE;
3039 empathy_call_handler_start_call (priv->handler,
3040 gtk_get_current_event_time ());
3042 if (empathy_call_handler_has_initial_video (priv->handler))
3044 TpyCallChannel *call;
3047 g_object_get (priv->handler, "call-channel", &call, NULL);
3048 s = tpy_call_channel_get_video_state (call);
3050 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3051 s == TPY_SENDING_STATE_SENDING)
3053 /* Enable 'send video' buttons and display the preview */
3054 gtk_toggle_tool_button_set_active (
3055 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3059 gtk_toggle_tool_button_set_active (
3060 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3062 if (priv->video_preview == NULL)
3064 create_video_preview (self);
3065 add_video_preview_to_pipeline (self);
3069 g_object_unref (call);
3074 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3077 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3078 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3081 empathy_call_handler_bus_message (priv->handler, bus, message);
3083 switch (GST_MESSAGE_TYPE (message))
3085 case GST_MESSAGE_STATE_CHANGED:
3086 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3088 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3090 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3091 !priv->call_started)
3093 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3094 if (newstate == GST_STATE_PAUSED)
3096 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3097 priv->pipeline_playing = TRUE;
3099 if (priv->start_call_when_playing)
3104 case GST_MESSAGE_ERROR:
3106 GError *error = NULL;
3107 GstElement *gst_error;
3110 gst_message_parse_error (message, &error, &debug);
3111 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3113 g_message ("Element error: %s -- %s\n", error->message, debug);
3115 if (g_str_has_prefix (gst_element_get_name (gst_error),
3116 VIDEO_INPUT_ERROR_PREFIX))
3118 /* Remove the video input and continue */
3119 if (priv->video_input != NULL)
3120 empathy_call_window_remove_video_input (self);
3121 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3125 empathy_call_window_disconnected (self, TRUE);
3127 g_error_free (error);
3130 case GST_MESSAGE_UNKNOWN:
3131 case GST_MESSAGE_EOS:
3132 case GST_MESSAGE_WARNING:
3133 case GST_MESSAGE_INFO:
3134 case GST_MESSAGE_TAG:
3135 case GST_MESSAGE_BUFFERING:
3136 case GST_MESSAGE_STATE_DIRTY:
3137 case GST_MESSAGE_STEP_DONE:
3138 case GST_MESSAGE_CLOCK_PROVIDE:
3139 case GST_MESSAGE_CLOCK_LOST:
3140 case GST_MESSAGE_NEW_CLOCK:
3141 case GST_MESSAGE_STRUCTURE_CHANGE:
3142 case GST_MESSAGE_STREAM_STATUS:
3143 case GST_MESSAGE_APPLICATION:
3144 case GST_MESSAGE_ELEMENT:
3145 case GST_MESSAGE_SEGMENT_START:
3146 case GST_MESSAGE_SEGMENT_DONE:
3147 case GST_MESSAGE_DURATION:
3148 case GST_MESSAGE_ANY:
3157 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3158 GHashTable *members,
3159 EmpathyCallWindow *self)
3161 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3162 GHashTableIter iter;
3163 gpointer key, value;
3164 gboolean held = FALSE;
3166 g_hash_table_iter_init (&iter, members);
3167 while (g_hash_table_iter_next (&iter, &key, &value))
3169 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3171 /* This assumes this is a 1-1 call, otherwise one participant
3172 * putting the call on hold wouldn't mean the call is on hold
3180 priv->call_state = HELD;
3181 else if (priv->call_state == HELD)
3182 priv->call_state = CONNECTED;
3186 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3188 EmpathyCallWindow *self)
3190 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3191 TpyCallChannel *call;
3193 g_object_get (priv->handler, "call-channel", &call, NULL);
3198 tp_g_signal_connect_object (call, "audio-stream-error",
3199 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3200 tp_g_signal_connect_object (call, "video-stream-error",
3201 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3204 tp_g_signal_connect_object (call, "members-changed",
3205 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3207 g_object_unref (call);
3211 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3213 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3214 TpyCallChannel *call;
3217 /* Make the hangup button twice as wide */
3218 width = gtk_widget_get_allocated_width (priv->hangup_button);
3219 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3221 g_signal_connect (priv->handler, "state-changed",
3222 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3223 g_signal_connect (priv->handler, "conference-added",
3224 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3225 g_signal_connect (priv->handler, "conference-removed",
3226 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3227 g_signal_connect (priv->handler, "closed",
3228 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3229 g_signal_connect (priv->handler, "src-pad-added",
3230 G_CALLBACK (empathy_call_window_src_added_cb), window);
3231 g_signal_connect (priv->handler, "sink-pad-added",
3232 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3233 g_signal_connect (priv->handler, "sink-pad-removed",
3234 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3236 g_object_get (priv->handler, "call-channel", &call, NULL);
3239 call_handler_notify_call_cb (priv->handler, NULL, window);
3240 g_object_unref (call);
3244 /* call-channel doesn't exist yet, we'll connect signals once it has been
3246 g_signal_connect (priv->handler, "notify::call-channel",
3247 G_CALLBACK (call_handler_notify_call_cb), window);
3250 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3254 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3255 EmpathyCallWindow *window)
3257 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3259 if (priv->pipeline != NULL)
3261 if (priv->bus_message_source_id != 0)
3263 g_source_remove (priv->bus_message_source_id);
3264 priv->bus_message_source_id = 0;
3267 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3270 if (priv->call_state == CONNECTING)
3271 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3277 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3280 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3282 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3287 gtk_widget_hide (priv->dtmf_panel);
3288 gtk_widget_hide (menu);
3289 gtk_widget_hide (priv->toolbar);
3293 if (priv->dialpad_was_visible_before_fs)
3294 gtk_widget_show (priv->dtmf_panel);
3296 gtk_widget_show (menu);
3297 gtk_widget_show (priv->toolbar);
3299 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3300 priv->original_height_before_fs);
3305 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3307 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3309 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3310 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3311 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3312 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3314 if (priv->video_output != NULL)
3317 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3318 priv->video_output, TRUE, TRUE,
3319 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3326 empathy_call_window_state_event_cb (GtkWidget *widget,
3327 GdkEventWindowState *event, EmpathyCallWindow *window)
3329 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3331 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3332 gboolean set_fullscreen = event->new_window_state &
3333 GDK_WINDOW_STATE_FULLSCREEN;
3337 gboolean dialpad_was_visible;
3338 GtkAllocation allocation;
3339 gint original_width, original_height;
3341 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3342 original_width = allocation.width;
3343 original_height = allocation.height;
3345 g_object_get (priv->dtmf_panel,
3346 "visible", &dialpad_was_visible,
3349 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3350 priv->original_width_before_fs = original_width;
3351 priv->original_height_before_fs = original_height;
3353 if (priv->video_output_motion_handler_id == 0 &&
3354 priv->video_output != NULL)
3356 priv->video_output_motion_handler_id = g_signal_connect (
3357 G_OBJECT (priv->video_container), "motion-notify-event",
3358 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3364 disconnect_video_output_motion_handler (window);
3367 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3369 show_controls (window, set_fullscreen);
3370 show_borders (window, set_fullscreen);
3371 gtk_action_set_stock_id (priv->menu_fullscreen,
3372 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3373 priv->is_fullscreen = set_fullscreen;
3380 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3383 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3384 int w, h, dialpad_width;
3385 GtkAllocation allocation;
3387 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3388 w = allocation.width;
3389 h = allocation.height;
3391 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3395 gtk_widget_show (priv->dtmf_panel);
3401 gtk_widget_hide (priv->dtmf_panel);
3405 gtk_window_resize (GTK_WINDOW (window), w, h);
3409 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3412 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3413 TpyCallChannel *call;
3415 priv->sending_video = (state == CAMERA_STATE_ON);
3417 if (state == CAMERA_STATE_ON)
3419 /* When we start sending video, we want to show the video preview by
3421 display_video_preview (window, TRUE);
3425 display_video_preview (window, FALSE);
3428 if (priv->call_state != CONNECTED)
3431 g_object_get (priv->handler, "call-channel", &call, NULL);
3432 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3433 tpy_call_channel_send_video (call, priv->sending_video);
3434 g_object_unref (call);
3438 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3439 EmpathyCallWindow *self)
3441 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3444 active = (gtk_toggle_tool_button_get_active (toggle));
3446 /* We don't want the settings callback to react to this change to avoid
3448 g_signal_handlers_block_by_func (priv->settings,
3449 empathy_call_window_prefs_volume_changed_cb, self);
3453 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3454 priv->volume * 100);
3458 /* TODO, Instead of setting the input volume to 0 we should probably
3459 * stop sending but this would cause the audio call to drop if both
3460 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3461 * in the future. GNOME #574574
3463 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3467 g_signal_handlers_unblock_by_func (priv->settings,
3468 empathy_call_window_prefs_volume_changed_cb, self);
3472 empathy_call_window_hangup_cb (gpointer object,
3473 EmpathyCallWindow *self)
3475 empathy_call_handler_stop_call (self->priv->handler);
3477 empathy_call_window_disconnected (self, TRUE);
3481 empathy_call_window_restart_call (EmpathyCallWindow *window)
3483 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3485 /* Remove error info bars */
3486 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3487 (GtkCallback) gtk_widget_destroy, NULL);
3489 create_video_output_widget (window);
3491 /* While the call was disconnected, the input volume might have changed.
3492 * However, since the audio_input source was destroyed, its volume has not
3493 * been updated during that time. That's why we manually update it here */
3494 empathy_call_window_mic_volume_changed (window);
3496 priv->outgoing = TRUE;
3497 empathy_call_window_set_state_connecting (window);
3499 if (priv->pipeline_playing)
3500 start_call (window);
3502 /* call will be started when the pipeline is ready */
3503 priv->start_call_when_playing = TRUE;
3505 empathy_call_window_setup_avatars (window, priv->handler);
3507 empathy_call_window_show_hangup_button (window, TRUE);
3511 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3512 EmpathyCallWindow *window)
3516 active = gtk_toggle_tool_button_get_active (button);
3518 empathy_call_window_show_dialpad (window, active);
3522 empathy_call_window_fullscreen_cb (gpointer object,
3523 EmpathyCallWindow *window)
3525 empathy_call_window_fullscreen_toggle (window);
3529 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3531 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3533 if (priv->is_fullscreen)
3534 gtk_window_unfullscreen (GTK_WINDOW (window));
3536 gtk_window_fullscreen (GTK_WINDOW (window));
3540 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3541 GdkEventButton *event, EmpathyCallWindow *window)
3543 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3545 empathy_call_window_video_menu_popup (window, event->button);
3553 empathy_call_window_key_press_cb (GtkWidget *video_output,
3554 GdkEventKey *event, EmpathyCallWindow *window)
3556 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3558 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3560 /* Since we are in fullscreen mode, toggling will bring us back to
3562 empathy_call_window_fullscreen_toggle (window);
3570 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3571 GdkEventMotion *event, EmpathyCallWindow *window)
3573 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3575 if (priv->is_fullscreen)
3577 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3579 /* Show the bottom toolbar */
3580 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3587 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3591 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3593 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3595 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3596 button, gtk_get_current_event_time ());
3597 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3601 empathy_call_window_status_message (EmpathyCallWindow *self,
3604 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3608 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3609 gdouble value, EmpathyCallWindow *window)
3611 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3613 if (priv->audio_output == NULL)
3616 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3621 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3623 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3625 return priv->ui_manager;
3628 EmpathyGstAudioSrc *
3629 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3631 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3633 return (EmpathyGstAudioSrc *) priv->audio_input;
3636 EmpathyGstVideoSrc *
3637 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3639 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);