2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
68 #include "empathy-rounded-rectangle.h"
69 #include "empathy-rounded-texture.h"
70 #include "empathy-camera-menu.h"
72 #define CONTENT_HBOX_BORDER_WIDTH 6
73 #define CONTENT_HBOX_SPACING 3
74 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
76 #define SELF_VIDEO_SECTION_WIDTH 120
77 #define SELF_VIDEO_SECTION_HEIGHT 90
78 #define SELF_VIDEO_SECTION_MARGIN 10
80 #define FLOATING_TOOLBAR_OPACITY 192
81 #define FLOATING_TOOLBAR_WIDTH 280
82 #define FLOATING_TOOLBAR_HEIGHT 36
83 #define FLOATING_TOOLBAR_SPACING 20
85 /* The avatar's default width and height are set to the same value because we
86 want a square icon. */
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
89 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define SMALL_TOOLBAR_SIZE 36
93 /* If an video input error occurs, the error message will start with "v4l" */
94 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
96 /* The time interval in milliseconds between 2 outgoing rings */
97 #define MS_BETWEEN_RING 500
99 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
102 PROP_CALL_HANDLER = 1,
114 CAMERA_STATE_OFF = 0,
120 PREVIEW_POS_TOP_LEFT,
121 PREVIEW_POS_TOP_RIGHT,
122 PREVIEW_POS_BOTTOM_LEFT,
123 PREVIEW_POS_BOTTOM_RIGHT,
126 struct _EmpathyCallWindowPriv
128 gboolean dispose_has_run;
129 EmpathyCallHandler *handler;
131 EmpathyContact *contact;
133 EmpathyCameraMonitor *camera_monitor;
138 GtkUIManager *ui_manager;
139 GtkWidget *errors_vbox;
140 /* widget displays the video received from the remote user. This widget is
141 * alive only during call. */
142 ClutterActor *video_output;
143 ClutterActor *video_preview;
144 ClutterActor *preview_shown_button;
145 ClutterActor *preview_hidden_button;
146 ClutterActor *preview_rectangle1;
147 ClutterActor *preview_rectangle2;
148 ClutterActor *preview_rectangle3;
149 ClutterActor *preview_rectangle4;
150 ClutterActor *preview_rectangle_box1;
151 ClutterActor *preview_rectangle_box2;
152 ClutterActor *preview_rectangle_box3;
153 ClutterActor *preview_rectangle_box4;
154 GtkWidget *video_container;
155 GtkWidget *remote_user_avatar_widget;
156 GtkWidget *remote_user_avatar_toolbar;
157 GtkWidget *remote_user_name_toolbar;
158 GtkWidget *status_label;
159 GtkWidget *hangup_button;
160 GtkWidget *audio_call_button;
161 GtkWidget *video_call_button;
162 GtkWidget *mic_button;
163 GtkWidget *camera_button;
164 GtkWidget *dialpad_button;
166 GtkWidget *bottom_toolbar;
167 ClutterActor *floating_toolbar;
169 GtkAction *menu_fullscreen;
170 GtkAction *menu_swap_camera;
172 ClutterState *transitions;
174 /* The box that contains self and remote avatar and video
175 input/output. When we redial, we destroy and re-create the box */
176 ClutterActor *video_box;
177 ClutterLayoutManager *video_layout;
179 /* Coordinates of the preview drag event's start. */
180 PreviewPosition preview_pos;
182 /* We keep a reference on the hbox which contains the main content so we can
183 easilly repack everything when toggling fullscreen */
184 GtkWidget *content_hbox;
186 gulong video_output_motion_handler_id;
187 guint bus_message_source_id;
191 GtkWidget *dtmf_panel;
194 GtkWidget *details_vbox;
195 GtkWidget *vcodec_encoding_label;
196 GtkWidget *acodec_encoding_label;
197 GtkWidget *vcodec_decoding_label;
198 GtkWidget *acodec_decoding_label;
200 GtkWidget *audio_remote_candidate_label;
201 GtkWidget *audio_local_candidate_label;
202 GtkWidget *video_remote_candidate_label;
203 GtkWidget *video_local_candidate_label;
204 GtkWidget *video_remote_candidate_info_img;
205 GtkWidget *video_local_candidate_info_img;
206 GtkWidget *audio_remote_candidate_info_img;
207 GtkWidget *audio_local_candidate_info_img;
209 GstElement *video_input;
210 GstElement *video_preview_sink;
211 GstElement *video_output_sink;
212 GstElement *audio_input;
213 GstElement *audio_output;
214 GstElement *pipeline;
215 GstElement *video_tee;
225 gboolean call_started;
226 gboolean sending_video;
227 CameraState camera_state;
229 EmpathyCallWindowFullscreen *fullscreen;
230 gboolean is_fullscreen;
235 guint inactivity_src;
237 /* Those fields represent the state of the window before it actually was in
239 gboolean dialpad_was_visible_before_fs;
240 gint original_width_before_fs;
241 gint original_height_before_fs;
243 gint x, y, w, h, dialpad_width;
246 /* TRUE if the call should be started when the pipeline is playing */
247 gboolean start_call_when_playing;
248 /* TRUE if we requested to set the pipeline in the playing state */
249 gboolean pipeline_playing;
251 EmpathySoundManager *sound_mgr;
254 EmpathyMicMenu *mic_menu;
255 EmpathyCameraMenu *camera_menu;
258 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
260 static void empathy_call_window_realized_cb (GtkWidget *widget,
261 EmpathyCallWindow *window);
263 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
264 GdkEvent *event, EmpathyCallWindow *window);
266 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
267 GdkEventWindowState *event, EmpathyCallWindow *window);
269 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
272 static void empathy_call_window_mic_toggled_cb (
273 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
275 static void empathy_call_window_hangup_cb (gpointer object,
276 EmpathyCallWindow *window);
278 static void empathy_call_window_fullscreen_cb (gpointer object,
279 EmpathyCallWindow *window);
281 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
283 static gboolean empathy_call_window_video_button_press_cb (
284 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
286 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
287 GdkEventKey *event, EmpathyCallWindow *window);
289 static gboolean empathy_call_window_video_output_motion_notify (
290 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
292 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
295 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
296 EmpathyCallWindow *window);
298 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
300 static void empathy_call_window_status_message (EmpathyCallWindow *window,
303 static gboolean empathy_call_window_bus_message (GstBus *bus,
304 GstMessage *message, gpointer user_data);
307 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
308 gdouble value, EmpathyCallWindow *window);
311 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
314 gtk_widget_set_visible (self->priv->hangup_button, show);
315 gtk_widget_set_visible (self->priv->audio_call_button, !show);
316 gtk_widget_set_visible (self->priv->video_call_button, !show);
320 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
321 EmpathyCallWindow *self)
323 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
324 empathy_call_window_restart_call (self);
328 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
329 EmpathyCallWindow *self)
331 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
332 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
333 empathy_call_window_restart_call (self);
337 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
339 EmpathyCallWindowPriv *priv = GET_PRIV (window);
340 TpyCallChannel *call;
344 g_object_get (priv->handler, "call-channel", &call, NULL);
346 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
347 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
350 tpy_call_channel_dtmf_start_tone (call, event);
352 g_object_unref (call);
356 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
358 EmpathyCallWindowPriv *priv = GET_PRIV (window);
359 TpyCallChannel *call;
361 g_object_get (priv->handler, "call-channel", &call, NULL);
363 tpy_call_channel_dtmf_stop_tone (call);
365 g_object_unref (call);
369 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
371 EmpathyCallWindowPriv *priv = GET_PRIV (self);
374 volume = g_settings_get_double (priv->settings,
375 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
377 /* Don't store the volume because of muting */
378 if (volume > 0 || gtk_toggle_tool_button_get_active (
379 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
380 priv->volume = volume;
382 /* Ensure that the toggle button is active if the volume is > 0 and inactive
383 * if it's smaller than 0 */
384 if ((volume > 0) != gtk_toggle_tool_button_get_active (
385 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
386 gtk_toggle_tool_button_set_active (
387 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
389 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
394 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
396 EmpathyCallWindow *self)
398 empathy_call_window_mic_volume_changed (self);
402 empathy_call_window_raise_actors (EmpathyCallWindow *self)
404 clutter_actor_raise_top (self->priv->floating_toolbar);
406 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
407 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
408 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
409 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
413 empathy_call_window_show_video_output (EmpathyCallWindow *self,
416 if (self->priv->video_output != NULL)
417 g_object_set (self->priv->video_output, "visible", show, NULL);
419 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
421 empathy_call_window_raise_actors (self);
425 create_video_output_widget (EmpathyCallWindow *self)
427 EmpathyCallWindowPriv *priv = GET_PRIV (self);
429 g_assert (priv->video_output == NULL);
430 g_assert (priv->pipeline != NULL);
432 priv->video_output = clutter_texture_new ();
434 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
437 priv->video_output_sink = clutter_gst_video_sink_new (
438 CLUTTER_TEXTURE (priv->video_output));
440 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
443 gtk_widget_add_events (priv->video_container,
444 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
445 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
446 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
450 create_video_input (EmpathyCallWindow *self)
452 EmpathyCallWindowPriv *priv = GET_PRIV (self);
454 g_assert (priv->video_input == NULL);
455 priv->video_input = empathy_video_src_new ();
456 gst_object_ref (priv->video_input);
457 gst_object_sink (priv->video_input);
461 create_audio_input (EmpathyCallWindow *self)
463 EmpathyCallWindowPriv *priv = GET_PRIV (self);
465 g_assert (priv->audio_input == NULL);
466 priv->audio_input = empathy_audio_src_new ();
467 gst_object_ref (priv->audio_input);
468 gst_object_sink (priv->audio_input);
472 add_video_preview_to_pipeline (EmpathyCallWindow *self)
474 EmpathyCallWindowPriv *priv = GET_PRIV (self);
477 g_assert (priv->video_preview != NULL);
478 g_assert (priv->pipeline != NULL);
479 g_assert (priv->video_input != NULL);
480 g_assert (priv->video_tee != NULL);
482 preview = priv->video_preview_sink;
484 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
486 g_warning ("Could not add video input to pipeline");
490 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
492 g_warning ("Could not add video preview to pipeline");
496 if (!gst_element_link (priv->video_input, priv->video_tee))
498 g_warning ("Could not link video input to video tee");
502 if (!gst_element_link (priv->video_tee, preview))
504 g_warning ("Could not link video tee to video preview");
510 empathy_call_window_disable_camera_cb (GtkAction *action,
511 EmpathyCallWindow *self)
513 clutter_actor_destroy (self->priv->preview_hidden_button);
515 gtk_toggle_tool_button_set_active (
516 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
520 empathy_call_window_minimise_camera_cb (GtkAction *action,
521 EmpathyCallWindow *self)
523 clutter_actor_hide (self->priv->video_preview);
524 clutter_actor_show (self->priv->preview_hidden_button);
528 empathy_call_window_maximise_camera_cb (GtkAction *action,
529 EmpathyCallWindow *self)
531 clutter_actor_show (self->priv->video_preview);
532 clutter_actor_hide (self->priv->preview_hidden_button);
536 empathy_call_window_swap_camera_cb (GtkAction *action,
537 EmpathyCallWindow *self)
539 const GList *cameras, *l;
542 DEBUG ("Swapping the camera");
544 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
545 current_cam = empathy_video_src_dup_device (
546 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
548 for (l = cameras; l != NULL; l = l->next)
550 EmpathyCamera *camera = l->data;
552 if (!tp_strdiff (camera->device, current_cam))
557 next = l->next->data;
559 next = cameras->data;
561 /* EmpathyCameraMenu will update itself and do the actual change
563 g_settings_set_string (self->priv->settings,
564 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
571 g_free (current_cam);
575 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
576 EmpathyCamera *camera,
577 EmpathyCallWindow *self)
579 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
581 gtk_action_set_visible (self->priv->menu_swap_camera,
582 g_list_length ((GList *) cameras) >= 2);
586 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
587 EmpathyCamera *camera,
588 EmpathyCallWindow *self)
590 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
592 gtk_action_set_visible (self->priv->menu_swap_camera,
593 g_list_length ((GList *) cameras) >= 2);
597 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
598 EmpathyCallWindow *self)
602 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
604 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
605 0, gtk_get_current_event_time ());
606 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
610 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
611 EmpathyCallWindow *self)
615 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
616 "/preview-hidden-menu");
617 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
618 0, gtk_get_current_event_time ());
619 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
622 static ClutterActor *
623 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
625 ClutterBinAlignment x,
626 ClutterBinAlignment y)
628 ClutterLayoutManager *layout1, *layout2;
629 ClutterActor *rectangle;
630 ClutterActor *box1, *box2;
632 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
633 CLUTTER_BIN_ALIGNMENT_START);
635 box1 = clutter_box_new (layout1);
639 rectangle = empathy_rounded_rectangle_new (
640 SELF_VIDEO_SECTION_WIDTH + 5,
641 SELF_VIDEO_SECTION_HEIGHT + 5);
643 clutter_actor_set_size (box1,
644 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
645 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
646 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
648 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
649 CLUTTER_BIN_ALIGNMENT_CENTER);
651 /* We have a box with the margins and the video in the middle inside
652 * a bigger box with an extra bottom margin so we're not on top of
653 * the floating toolbar. */
654 box2 = clutter_box_new (layout2);
656 clutter_actor_set_size (box2,
657 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
658 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
660 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
661 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
663 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
666 clutter_actor_hide (rectangle);
672 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
674 self->priv->preview_rectangle1 =
675 empathy_call_window_create_preview_rectangle (self,
676 &self->priv->preview_rectangle_box1,
677 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
678 self->priv->preview_rectangle2 =
679 empathy_call_window_create_preview_rectangle (self,
680 &self->priv->preview_rectangle_box2,
681 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
682 self->priv->preview_rectangle3 =
683 empathy_call_window_create_preview_rectangle (self,
684 &self->priv->preview_rectangle_box3,
685 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
686 self->priv->preview_rectangle4 =
687 empathy_call_window_create_preview_rectangle (self,
688 &self->priv->preview_rectangle_box4,
689 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
693 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
696 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
697 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
698 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
702 static PreviewPosition
703 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
708 PreviewPosition pos = PREVIEW_POS_NONE;
710 g_return_val_if_fail (clutter_actor_has_allocation (self->priv->video_box),
713 clutter_actor_get_geometry (self->priv->video_box, &box);
715 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
716 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
717 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
718 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
720 pos = PREVIEW_POS_TOP_LEFT;
722 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
723 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
724 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
725 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
727 pos = PREVIEW_POS_TOP_RIGHT;
729 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
730 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
731 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
732 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
734 pos = PREVIEW_POS_BOTTOM_LEFT;
736 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
737 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
738 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
739 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
741 pos = PREVIEW_POS_BOTTOM_RIGHT;
747 static ClutterActor *
748 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
751 ClutterActor *rectangle;
755 case PREVIEW_POS_TOP_LEFT:
756 rectangle = self->priv->preview_rectangle1;
758 case PREVIEW_POS_TOP_RIGHT:
759 rectangle = self->priv->preview_rectangle3;
761 case PREVIEW_POS_BOTTOM_LEFT:
762 rectangle = self->priv->preview_rectangle2;
764 case PREVIEW_POS_BOTTOM_RIGHT:
765 rectangle = self->priv->preview_rectangle4;
775 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
778 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
780 DEBUG ("moving the video preview to %d", pos);
782 self->priv->preview_pos = pos;
786 case PREVIEW_POS_TOP_LEFT:
787 clutter_bin_layout_set_alignment (layout,
788 self->priv->video_preview,
789 CLUTTER_BIN_ALIGNMENT_START,
790 CLUTTER_BIN_ALIGNMENT_START);
792 case PREVIEW_POS_TOP_RIGHT:
793 clutter_bin_layout_set_alignment (layout,
794 self->priv->video_preview,
795 CLUTTER_BIN_ALIGNMENT_END,
796 CLUTTER_BIN_ALIGNMENT_START);
798 case PREVIEW_POS_BOTTOM_LEFT:
799 clutter_bin_layout_set_alignment (layout,
800 self->priv->video_preview,
801 CLUTTER_BIN_ALIGNMENT_START,
802 CLUTTER_BIN_ALIGNMENT_END);
804 case PREVIEW_POS_BOTTOM_RIGHT:
805 clutter_bin_layout_set_alignment (layout,
806 self->priv->video_preview,
807 CLUTTER_BIN_ALIGNMENT_END,
808 CLUTTER_BIN_ALIGNMENT_END);
811 g_warn_if_reached ();
816 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
819 ClutterActor *rectangle;
821 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
823 empathy_rounded_rectangle_set_border_width (
824 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
825 empathy_rounded_rectangle_set_border_color (
826 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
830 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
831 ClutterActor *rectangle)
833 empathy_rounded_rectangle_set_border_width (
834 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
835 empathy_rounded_rectangle_set_border_color (
836 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
840 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
842 ClutterActor *rectangle;
844 rectangle = empathy_call_window_get_preview_rectangle (self,
845 self->priv->preview_pos);
847 /* We don't want to darken the rectangle where the preview
850 if (self->priv->preview_rectangle1 != rectangle)
851 empathy_call_window_darken_preview_rectangle (self,
852 self->priv->preview_rectangle1);
854 if (self->priv->preview_rectangle2 != rectangle)
855 empathy_call_window_darken_preview_rectangle (self,
856 self->priv->preview_rectangle2);
858 if (self->priv->preview_rectangle3 != rectangle)
859 empathy_call_window_darken_preview_rectangle (self,
860 self->priv->preview_rectangle3);
862 if (self->priv->preview_rectangle4 != rectangle)
863 empathy_call_window_darken_preview_rectangle (self,
864 self->priv->preview_rectangle4);
868 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
872 ClutterModifierType modifiers,
873 EmpathyCallWindow *self)
875 ClutterActor *stage = clutter_actor_get_stage (actor);
876 ClutterActor *preview = clutter_clone_new (actor);
879 /* Flip the video preview */
880 /* FIXME: disabled because it makes the drag handle to go away! */
881 clutter_actor_set_rotation (preview,
884 SELF_VIDEO_SECTION_WIDTH * 0.5,
889 clutter_container_add_actor (CLUTTER_CONTAINER (stage), preview);
890 clutter_actor_set_position (preview, event_x, event_y);
892 clutter_drag_action_set_drag_handle (action, preview);
894 clutter_actor_set_opacity (actor, 0);
895 clutter_actor_hide (self->priv->preview_shown_button);
897 empathy_call_window_show_preview_rectangles (self, TRUE);
898 empathy_call_window_darken_preview_rectangles (self);
902 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
906 ClutterModifierType modifiers,
907 EmpathyCallWindow *self)
909 ClutterActor *preview = clutter_drag_action_get_drag_handle (action);
912 /* Get the position before destroying the drag actor, otherwise the
913 * preview_box allocation won't be valid and we won't be able to
914 * calculate the position. */
915 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
917 /* Destroy the video preview copy that we were dragging */
918 clutter_actor_destroy (preview);
920 clutter_actor_set_opacity (actor, 255);
921 clutter_actor_show (self->priv->preview_shown_button);
923 if (pos != PREVIEW_POS_NONE)
924 empathy_call_window_move_video_preview (self, pos);
926 empathy_call_window_show_preview_rectangles (self, FALSE);
930 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
934 EmpathyCallWindow *self)
937 gfloat event_x, event_y;
939 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
941 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
943 if (pos != PREVIEW_POS_NONE)
944 empathy_call_window_highlight_preview_rectangle (self, pos);
946 empathy_call_window_darken_preview_rectangles (self);
950 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
951 ClutterCrossingEvent *event,
952 EmpathyCallWindow *self)
954 ClutterActor *rectangle;
956 rectangle = empathy_call_window_get_preview_rectangle (self,
957 self->priv->preview_pos);
959 empathy_call_window_highlight_preview_rectangle (self,
960 self->priv->preview_pos);
962 clutter_actor_show (rectangle);
968 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
969 ClutterCrossingEvent *event,
970 EmpathyCallWindow *self)
972 ClutterActor *rectangle;
974 rectangle = empathy_call_window_get_preview_rectangle (self,
975 self->priv->preview_pos);
977 empathy_call_window_darken_preview_rectangle (self, rectangle);
979 clutter_actor_hide (rectangle);
985 create_video_preview (EmpathyCallWindow *self)
987 EmpathyCallWindowPriv *priv = GET_PRIV (self);
988 ClutterLayoutManager *layout, *layout_center, *layout_end;
989 ClutterActor *preview;
992 ClutterAction *action;
995 g_assert (priv->video_preview == NULL);
997 preview = empathy_rounded_texture_new ();
998 clutter_actor_set_size (preview,
999 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1000 priv->video_preview_sink = clutter_gst_video_sink_new (
1001 CLUTTER_TEXTURE (preview));
1003 /* Flip the video preview */
1004 clutter_actor_set_rotation (preview,
1007 SELF_VIDEO_SECTION_WIDTH * 0.5,
1011 /* Add a little offset to the video preview */
1012 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1013 CLUTTER_BIN_ALIGNMENT_START);
1014 priv->video_preview = clutter_box_new (layout);
1015 clutter_actor_set_size (priv->video_preview,
1016 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1017 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1018 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1020 /* We have a box with the margins and the video in the middle inside
1021 * a bigger box with an extra bottom margin so we're not on top of
1022 * the floating toolbar. */
1023 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1024 CLUTTER_BIN_ALIGNMENT_CENTER);
1025 box = clutter_box_new (layout_center);
1026 clutter_actor_set_size (box,
1027 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1028 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1030 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1031 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1033 g_object_set (priv->video_preview_sink,
1038 /* Translators: this is an "Info" label. It should be as short
1040 button = gtk_button_new_with_label (_("i"));
1041 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1043 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1045 clutter_actor_set_size (b, 24, 24);
1047 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1048 CLUTTER_BIN_ALIGNMENT_END);
1049 box = clutter_box_new (layout_end);
1050 clutter_actor_set_size (box,
1051 SELF_VIDEO_SECTION_WIDTH,
1052 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1054 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1055 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1057 g_signal_connect (button, "clicked",
1058 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1061 /* Translators: this is an "Info" label. It should be as short
1063 button = gtk_button_new_with_label (_("i"));
1064 b = empathy_rounded_actor_new ();
1066 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1068 clutter_actor_set_size (b, 24, 24);
1069 priv->preview_hidden_button = b;
1071 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1072 priv->preview_hidden_button,
1073 CLUTTER_BIN_ALIGNMENT_START,
1074 CLUTTER_BIN_ALIGNMENT_END);
1076 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1078 clutter_actor_hide (priv->preview_hidden_button);
1080 g_signal_connect (button, "clicked",
1081 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1084 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1085 priv->video_preview,
1086 CLUTTER_BIN_ALIGNMENT_START,
1087 CLUTTER_BIN_ALIGNMENT_END);
1089 action = clutter_drag_action_new ();
1090 g_signal_connect (action, "drag-begin",
1091 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1092 g_signal_connect (action, "drag-end",
1093 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1094 g_signal_connect (action, "drag-motion",
1095 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1097 g_signal_connect (preview, "enter-event",
1098 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1099 g_signal_connect (preview, "leave-event",
1100 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1102 clutter_actor_add_action (preview, action);
1103 clutter_actor_set_reactive (preview, TRUE);
1104 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1108 empathy_call_window_play_camera (EmpathyCallWindow *window,
1111 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1112 GstElement *preview;
1115 if (priv->video_preview == NULL)
1117 create_video_preview (window);
1118 add_video_preview_to_pipeline (window);
1122 state = GST_STATE_PLAYING;
1124 state = GST_STATE_NULL;
1126 preview = priv->video_preview_sink;
1128 gst_element_set_state (preview, state);
1129 gst_element_set_state (priv->video_input, state);
1130 gst_element_set_state (priv->video_tee, state);
1134 display_video_preview (EmpathyCallWindow *self,
1137 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1141 /* Display the video preview */
1142 DEBUG ("Show video preview");
1144 empathy_call_window_play_camera (self, TRUE);
1145 clutter_actor_show (priv->video_preview);
1146 clutter_actor_raise_top (priv->floating_toolbar);
1150 /* Hide the video preview */
1151 DEBUG ("Hide video preview");
1153 if (priv->video_preview != NULL)
1155 clutter_actor_hide (priv->video_preview);
1156 empathy_call_window_play_camera (self, FALSE);
1162 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1164 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1166 empathy_call_window_status_message (window, _("Connecting…"));
1167 priv->call_state = CONNECTING;
1169 /* Show the toolbar */
1170 clutter_state_set_state (priv->transitions, "fade-in");
1173 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1174 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1178 disable_camera (EmpathyCallWindow *self)
1180 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1182 if (priv->camera_state == CAMERA_STATE_OFF)
1185 DEBUG ("Disable camera");
1187 display_video_preview (self, FALSE);
1189 if (priv->camera_state == CAMERA_STATE_ON)
1190 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1192 priv->camera_state = CAMERA_STATE_OFF;
1196 enable_camera (EmpathyCallWindow *self)
1198 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1200 if (priv->camera_state == CAMERA_STATE_ON)
1203 if (priv->video_input == NULL)
1205 DEBUG ("Can't enable camera, no input");
1209 DEBUG ("Enable camera");
1211 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1213 priv->camera_state = CAMERA_STATE_ON;
1217 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1218 EmpathyCallWindow *self)
1220 if (gtk_toggle_tool_button_get_active (toggle))
1221 enable_camera (self);
1223 disable_camera (self);
1227 create_pipeline (EmpathyCallWindow *self)
1229 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1232 g_assert (priv->pipeline == NULL);
1234 priv->pipeline = gst_pipeline_new (NULL);
1235 priv->pipeline_playing = FALSE;
1237 priv->video_tee = gst_element_factory_make ("tee", NULL);
1238 gst_object_ref (priv->video_tee);
1239 gst_object_sink (priv->video_tee);
1241 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1243 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1244 priv->bus_message_source_id = gst_bus_add_watch (bus,
1245 empathy_call_window_bus_message, self);
1247 g_object_unref (bus);
1251 empathy_call_window_settings_cb (GtkAction *action,
1252 EmpathyCallWindow *self)
1254 gchar *args = g_strdup_printf ("-p %s",
1255 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1257 empathy_launch_program (BIN_DIR, "empathy", args);
1263 empathy_call_window_contents_cb (GtkAction *action,
1264 EmpathyCallWindow *self)
1266 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1270 empathy_call_window_debug_cb (GtkAction *action,
1271 EmpathyCallWindow *self)
1273 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1277 empathy_call_window_about_cb (GtkAction *action,
1278 EmpathyCallWindow *self)
1280 empathy_about_dialog_new (GTK_WINDOW (self));
1284 empathy_call_window_toolbar_timeout (gpointer data)
1286 EmpathyCallWindow *self = data;
1288 /* We don't want to hide the toolbar if we're not in a call, as
1289 * to show the call status all the time. */
1290 if (self->priv->call_state != CONNECTING &&
1291 self->priv->call_state != DISCONNECTED)
1292 clutter_state_set_state (self->priv->transitions, "fade-out");
1298 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1300 EmpathyCallWindow *self)
1302 clutter_state_set_state (self->priv->transitions, "fade-in");
1304 if (self->priv->inactivity_src > 0)
1305 g_source_remove (self->priv->inactivity_src);
1307 self->priv->inactivity_src = g_timeout_add_seconds (3,
1308 empathy_call_window_toolbar_timeout, self);
1314 empathy_call_window_configure_event_cb (GtkWidget *widget,
1316 EmpathyCallWindow *self)
1318 GdkWindow *gdk_window;
1319 GdkWindowState window_state;
1321 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1322 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1324 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1325 &self->priv->dialpad_width, NULL);
1327 gdk_window = gtk_widget_get_window (widget);
1328 window_state = gdk_window_get_state (gdk_window);
1329 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1335 empathy_call_window_destroyed_cb (GtkWidget *object,
1336 EmpathyCallWindow *self)
1338 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1340 /* Save the geometry as if the dialpad was hidden. */
1341 empathy_geometry_save_values (GTK_WINDOW (self),
1342 self->priv->x, self->priv->y,
1343 self->priv->w - self->priv->dialpad_width, self->priv->h,
1344 self->priv->maximized);
1349 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1351 ClutterBindConstraint *constraint)
1353 ClutterActorBox allocation;
1355 clutter_actor_get_allocation_box (stage, &allocation);
1357 clutter_bind_constraint_set_offset (constraint,
1358 allocation.y2 - allocation.y1 -
1359 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1363 empathy_call_window_init (EmpathyCallWindow *self)
1365 EmpathyCallWindowPriv *priv;
1367 GtkWidget *top_vbox;
1369 ClutterConstraint *constraint;
1370 ClutterActor *remote_avatar;
1371 GtkStyleContext *context;
1375 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1376 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1378 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1379 gui = empathy_builder_get_file (filename,
1380 "call_window_vbox", &top_vbox,
1381 "errors_vbox", &priv->errors_vbox,
1382 "pane", &priv->pane,
1383 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1384 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1385 "status_label", &priv->status_label,
1386 "audiocall", &priv->audio_call_button,
1387 "videocall", &priv->video_call_button,
1388 "microphone", &priv->mic_button,
1389 "camera", &priv->camera_button,
1390 "hangup", &priv->hangup_button,
1391 "dialpad", &priv->dialpad_button,
1392 "toolbar", &priv->toolbar,
1393 "bottom_toolbar", &priv->bottom_toolbar,
1394 "ui_manager", &priv->ui_manager,
1395 "menufullscreen", &priv->menu_fullscreen,
1396 "menupreviewswap", &priv->menu_swap_camera,
1397 "details_vbox", &priv->details_vbox,
1398 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1399 "acodec_encoding_label", &priv->acodec_encoding_label,
1400 "acodec_decoding_label", &priv->acodec_decoding_label,
1401 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1402 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1403 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1404 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1405 "video_local_candidate_label", &priv->video_local_candidate_label,
1406 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1407 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1408 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1409 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1413 empathy_builder_connect (gui, self,
1414 "hangup", "clicked", empathy_call_window_hangup_cb,
1415 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1416 "videocall", "clicked", empathy_call_window_video_call_cb,
1417 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1418 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1419 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1420 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1421 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1422 "menusettings", "activate", empathy_call_window_settings_cb,
1423 "menucontents", "activate", empathy_call_window_contents_cb,
1424 "menudebug", "activate", empathy_call_window_debug_cb,
1425 "menuabout", "activate", empathy_call_window_about_cb,
1426 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1427 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1428 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1429 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1432 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1434 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1436 g_object_bind_property (priv->camera_monitor, "available",
1437 priv->camera_button, "sensitive",
1438 G_BINDING_SYNC_CREATE);
1440 g_signal_connect (priv->camera_monitor, "added",
1441 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1442 g_signal_connect (priv->camera_monitor, "removed",
1443 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1445 priv->lock = g_mutex_new ();
1447 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1449 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1450 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1451 CONTENT_HBOX_BORDER_WIDTH);
1452 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1455 /* avatar/video box */
1456 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1457 CLUTTER_BIN_ALIGNMENT_CENTER);
1459 priv->video_box = clutter_box_new (priv->video_layout);
1461 priv->video_container = gtk_clutter_embed_new ();
1463 /* Set the background color to that of the rest of the window */
1464 context = gtk_widget_get_style_context (priv->content_hbox);
1465 gtk_style_context_get_background_color (context,
1466 GTK_STATE_FLAG_NORMAL, &rgba);
1467 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1468 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1469 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1470 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1471 clutter_stage_set_color (
1472 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1473 GTK_CLUTTER_EMBED (priv->video_container))),
1476 clutter_container_add (
1477 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1478 GTK_CLUTTER_EMBED (priv->video_container))),
1482 constraint = clutter_bind_constraint_new (
1483 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1484 CLUTTER_BIND_SIZE, 0);
1485 clutter_actor_add_constraint (priv->video_box, constraint);
1487 priv->remote_user_avatar_widget = gtk_image_new ();
1488 remote_avatar = gtk_clutter_actor_new_with_contents (
1489 priv->remote_user_avatar_widget);
1491 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1494 empathy_call_window_create_preview_rectangles (self);
1496 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1497 priv->video_container, TRUE, TRUE,
1498 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1500 create_pipeline (self);
1501 create_video_output_widget (self);
1502 create_audio_input (self);
1503 create_video_input (self);
1505 priv->floating_toolbar = empathy_rounded_actor_new ();
1507 gtk_widget_reparent (priv->bottom_toolbar,
1508 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1510 constraint = clutter_bind_constraint_new (
1511 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1514 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1517 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1518 "notify::allocation",
1519 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1522 clutter_actor_set_size (priv->floating_toolbar,
1523 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1524 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1526 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1527 priv->floating_toolbar,
1528 CLUTTER_BIN_ALIGNMENT_CENTER,
1529 CLUTTER_BIN_ALIGNMENT_END);
1531 clutter_actor_raise_top (priv->floating_toolbar);
1533 /* Transitions for the floating toolbar */
1534 priv->transitions = clutter_state_new ();
1536 /* all transitions last for 2s */
1537 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1539 /* transition from any state to "fade-out" state */
1540 clutter_state_set (priv->transitions, NULL, "fade-out",
1541 priv->floating_toolbar,
1542 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1545 /* transition from any state to "fade-in" state */
1546 clutter_state_set (priv->transitions, NULL, "fade-in",
1547 priv->floating_toolbar,
1548 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1551 /* put the actor into the "fade-in" state with no animation */
1552 clutter_state_warp_to_state (priv->transitions, "fade-in");
1554 /* The call will be started as soon the pipeline is playing */
1555 priv->start_call_when_playing = TRUE;
1557 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1558 G_CALLBACK (dtmf_button_pressed_cb),
1559 G_CALLBACK (dtmf_button_released_cb));
1561 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1564 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1567 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1569 gtk_widget_show_all (top_vbox);
1571 gtk_widget_hide (priv->dtmf_panel);
1572 gtk_widget_hide (priv->details_vbox);
1574 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1576 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1577 priv->video_container);
1579 /* We hide the bottom toolbar after 3s of inactivity and show it
1580 * again on mouse movement */
1581 priv->inactivity_src = g_timeout_add_seconds (3,
1582 empathy_call_window_toolbar_timeout, self);
1584 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1585 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1587 g_signal_connect (G_OBJECT (self), "realize",
1588 G_CALLBACK (empathy_call_window_realized_cb), self);
1590 g_signal_connect (G_OBJECT (self), "delete-event",
1591 G_CALLBACK (empathy_call_window_delete_cb), self);
1593 g_signal_connect (G_OBJECT (self), "window-state-event",
1594 G_CALLBACK (empathy_call_window_state_event_cb), self);
1596 g_signal_connect (G_OBJECT (self), "key-press-event",
1597 G_CALLBACK (empathy_call_window_key_press_cb), self);
1599 g_signal_connect (self, "motion-notify-event",
1600 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1602 priv->timer = g_timer_new ();
1604 g_object_ref (priv->ui_manager);
1605 g_object_unref (gui);
1607 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1608 priv->mic_menu = empathy_mic_menu_new (self);
1609 priv->camera_menu = empathy_camera_menu_new (self);
1611 empathy_call_window_show_hangup_button (self, TRUE);
1613 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1615 /* Retrieve initial volume */
1616 priv->volume = g_settings_get_double (priv->settings,
1617 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1619 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1620 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1622 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1623 /* These signals are used to track the window position and save it
1624 * when the window is destroyed. We need to do this as we don't want
1625 * the window geometry to be saved with the dialpad taken into account. */
1626 g_signal_connect (self, "destroy",
1627 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1628 g_signal_connect (self, "configure-event",
1629 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1630 g_signal_connect (self, "window-state-event",
1631 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1633 /* Don't display labels in both toolbars */
1634 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1637 /* Instead of specifying a width and a height, we specify only one size. That's
1638 because we want a square avatar icon. */
1640 init_contact_avatar_with_size (EmpathyContact *contact,
1641 GtkWidget *image_widget,
1644 GdkPixbuf *pixbuf_avatar = NULL;
1646 if (contact != NULL)
1648 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1652 if (pixbuf_avatar == NULL)
1654 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1655 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1658 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1660 if (pixbuf_avatar != NULL)
1661 g_object_unref (pixbuf_avatar);
1665 set_window_title (EmpathyCallWindow *self)
1667 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1670 if (priv->contact != NULL)
1672 /* translators: Call is a noun and %s is the contact name. This string
1673 * is used in the window title */
1674 tmp = g_strdup_printf (_("Call with %s"),
1675 empathy_contact_get_alias (priv->contact));
1676 gtk_window_set_title (GTK_WINDOW (self), tmp);
1681 g_warning ("Unknown remote contact!");
1686 set_remote_user_name (EmpathyCallWindow *self,
1687 EmpathyContact *contact)
1689 const gchar *alias = empathy_contact_get_alias (contact);
1690 const gchar *status = empathy_contact_get_status (contact);
1693 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1694 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1700 contact_name_changed_cb (EmpathyContact *contact,
1702 EmpathyCallWindow *self)
1704 set_window_title (self);
1705 set_remote_user_name (self, contact);
1709 contact_presence_changed_cb (EmpathyContact *contact,
1711 EmpathyCallWindow *self)
1713 set_remote_user_name (self, contact);
1717 contact_avatar_changed_cb (EmpathyContact *contact,
1719 EmpathyCallWindow *self)
1722 GtkAllocation allocation;
1723 GtkWidget *avatar_widget;
1725 avatar_widget = self->priv->remote_user_avatar_widget;
1727 gtk_widget_get_allocation (avatar_widget, &allocation);
1728 size = allocation.height;
1732 /* the widget is not allocated yet, set a default size */
1733 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1734 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1737 init_contact_avatar_with_size (contact, avatar_widget, size);
1739 avatar_widget = self->priv->remote_user_avatar_toolbar;
1741 gtk_widget_get_allocation (avatar_widget, &allocation);
1742 size = allocation.height;
1746 /* the widget is not allocated yet, set a default size */
1747 size = SMALL_TOOLBAR_SIZE;
1750 init_contact_avatar_with_size (contact, avatar_widget, size);
1754 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1755 EmpathyCallHandler *handler)
1757 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1759 tp_g_signal_connect_object (priv->contact, "notify::name",
1760 G_CALLBACK (contact_name_changed_cb), self, 0);
1761 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1762 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1763 tp_g_signal_connect_object (priv->contact, "notify::presence",
1764 G_CALLBACK (contact_presence_changed_cb), self, 0);
1766 set_window_title (self);
1767 set_remote_user_name (self, priv->contact);
1769 init_contact_avatar_with_size (priv->contact,
1770 priv->remote_user_avatar_widget,
1771 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1772 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1774 init_contact_avatar_with_size (priv->contact,
1775 priv->remote_user_avatar_toolbar,
1776 SMALL_TOOLBAR_SIZE);
1778 /* The remote avatar is shown by default and will be hidden when we receive
1779 video from the remote side. */
1780 clutter_actor_hide (priv->video_output);
1781 gtk_widget_show (priv->remote_user_avatar_widget);
1785 update_send_codec (EmpathyCallWindow *self,
1788 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1795 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1796 widget = priv->acodec_encoding_label;
1800 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1801 widget = priv->vcodec_encoding_label;
1807 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1808 gtk_label_set_text (GTK_LABEL (widget), tmp);
1813 send_audio_codec_notify_cb (GObject *object,
1817 EmpathyCallWindow *self = user_data;
1819 update_send_codec (self, TRUE);
1823 send_video_codec_notify_cb (GObject *object,
1827 EmpathyCallWindow *self = user_data;
1829 update_send_codec (self, FALSE);
1833 update_recv_codec (EmpathyCallWindow *self,
1836 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1839 GString *str = NULL;
1843 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1844 widget = priv->acodec_decoding_label;
1848 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1849 widget = priv->vcodec_decoding_label;
1855 for (l = codecs; l != NULL; l = g_list_next (l))
1857 FsCodec *codec = l->data;
1860 str = g_string_new (NULL);
1862 g_string_append (str, ", ");
1864 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1868 gtk_label_set_text (GTK_LABEL (widget), str->str);
1869 g_string_free (str, TRUE);
1873 recv_audio_codecs_notify_cb (GObject *object,
1877 EmpathyCallWindow *self = user_data;
1879 update_recv_codec (self, TRUE);
1883 recv_video_codecs_notify_cb (GObject *object,
1887 EmpathyCallWindow *self = user_data;
1889 update_recv_codec (self, FALSE);
1892 static const gchar *
1893 candidate_type_to_str (FsCandidate *candidate)
1895 switch (candidate->type)
1897 case FS_CANDIDATE_TYPE_HOST:
1899 case FS_CANDIDATE_TYPE_SRFLX:
1900 return "server reflexive";
1901 case FS_CANDIDATE_TYPE_PRFLX:
1902 return "peer reflexive";
1903 case FS_CANDIDATE_TYPE_RELAY:
1905 case FS_CANDIDATE_TYPE_MULTICAST:
1912 static const gchar *
1913 candidate_type_to_desc (FsCandidate *candidate)
1915 switch (candidate->type)
1917 case FS_CANDIDATE_TYPE_HOST:
1918 return _("The IP address as seen by the machine");
1919 case FS_CANDIDATE_TYPE_SRFLX:
1920 return _("The IP address as seen by a server on the Internet");
1921 case FS_CANDIDATE_TYPE_PRFLX:
1922 return _("The IP address of the peer as seen by the other side");
1923 case FS_CANDIDATE_TYPE_RELAY:
1924 return _("The IP address of a relay server");
1925 case FS_CANDIDATE_TYPE_MULTICAST:
1926 return _("The IP address of the multicast group");
1933 update_candidat_widget (EmpathyCallWindow *self,
1936 FsCandidate *candidate)
1940 g_assert (candidate != NULL);
1941 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1942 candidate->port, candidate_type_to_str (candidate));
1944 gtk_label_set_text (GTK_LABEL (label), str);
1945 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1951 candidates_changed_cb (GObject *object,
1953 EmpathyCallWindow *self)
1955 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1956 FsCandidate *candidate = NULL;
1958 if (type == FS_MEDIA_TYPE_VIDEO)
1960 /* Update remote candidate */
1961 candidate = empathy_call_handler_get_video_remote_candidate (
1964 update_candidat_widget (self, priv->video_remote_candidate_label,
1965 priv->video_remote_candidate_info_img, candidate);
1967 /* Update local candidate */
1968 candidate = empathy_call_handler_get_video_local_candidate (
1971 update_candidat_widget (self, priv->video_local_candidate_label,
1972 priv->video_local_candidate_info_img, candidate);
1976 /* Update remote candidate */
1977 candidate = empathy_call_handler_get_audio_remote_candidate (
1980 update_candidat_widget (self, priv->audio_remote_candidate_label,
1981 priv->audio_remote_candidate_info_img, candidate);
1983 /* Update local candidate */
1984 candidate = empathy_call_handler_get_audio_local_candidate (
1987 update_candidat_widget (self, priv->audio_local_candidate_label,
1988 priv->audio_local_candidate_info_img, candidate);
1993 empathy_call_window_constructed (GObject *object)
1995 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1996 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1997 TpyCallChannel *call;
1999 g_assert (priv->handler != NULL);
2001 g_object_get (priv->handler, "call-channel", &call, NULL);
2002 priv->outgoing = (call == NULL);
2004 g_object_unref (call);
2006 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2007 g_assert (priv->contact != NULL);
2009 empathy_call_window_setup_avatars (self, priv->handler);
2010 empathy_call_window_set_state_connecting (self);
2012 if (!empathy_call_handler_has_initial_video (priv->handler))
2014 gtk_toggle_tool_button_set_active (
2015 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2017 /* If call has InitialVideo, the preview will be started once the call has
2018 * been started (start_call()). */
2020 update_send_codec (self, TRUE);
2021 update_send_codec (self, FALSE);
2022 update_recv_codec (self, TRUE);
2023 update_recv_codec (self, FALSE);
2025 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2026 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2027 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2028 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2029 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2030 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2031 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2032 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2034 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2035 G_CALLBACK (candidates_changed_cb), self, 0);
2038 static void empathy_call_window_dispose (GObject *object);
2039 static void empathy_call_window_finalize (GObject *object);
2042 empathy_call_window_set_property (GObject *object,
2043 guint property_id, const GValue *value, GParamSpec *pspec)
2045 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2047 switch (property_id)
2049 case PROP_CALL_HANDLER:
2050 priv->handler = g_value_dup_object (value);
2053 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2058 empathy_call_window_get_property (GObject *object,
2059 guint property_id, GValue *value, GParamSpec *pspec)
2061 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2063 switch (property_id)
2065 case PROP_CALL_HANDLER:
2066 g_value_set_object (value, priv->handler);
2069 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2074 empathy_call_window_class_init (
2075 EmpathyCallWindowClass *empathy_call_window_class)
2077 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2078 GParamSpec *param_spec;
2080 g_type_class_add_private (empathy_call_window_class,
2081 sizeof (EmpathyCallWindowPriv));
2083 object_class->constructed = empathy_call_window_constructed;
2084 object_class->set_property = empathy_call_window_set_property;
2085 object_class->get_property = empathy_call_window_get_property;
2087 object_class->dispose = empathy_call_window_dispose;
2088 object_class->finalize = empathy_call_window_finalize;
2090 param_spec = g_param_spec_object ("handler",
2091 "handler", "The call handler",
2092 EMPATHY_TYPE_CALL_HANDLER,
2093 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2094 g_object_class_install_property (object_class,
2095 PROP_CALL_HANDLER, param_spec);
2099 empathy_call_window_dispose (GObject *object)
2101 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2102 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2104 if (priv->dispose_has_run)
2107 priv->dispose_has_run = TRUE;
2109 if (priv->handler != NULL)
2111 empathy_call_handler_stop_call (priv->handler);
2112 tp_clear_object (&priv->handler);
2115 if (priv->bus_message_source_id != 0)
2117 g_source_remove (priv->bus_message_source_id);
2118 priv->bus_message_source_id = 0;
2121 if (priv->got_video_src > 0)
2123 g_source_remove (priv->got_video_src);
2124 priv->got_video_src = 0;
2127 if (priv->inactivity_src > 0)
2129 g_source_remove (priv->inactivity_src);
2130 priv->inactivity_src = 0;
2133 tp_clear_object (&priv->pipeline);
2134 tp_clear_object (&priv->video_input);
2135 tp_clear_object (&priv->audio_input);
2136 tp_clear_object (&priv->video_tee);
2137 tp_clear_object (&priv->ui_manager);
2138 tp_clear_object (&priv->fullscreen);
2139 tp_clear_object (&priv->camera_monitor);
2140 tp_clear_object (&priv->settings);
2141 tp_clear_object (&priv->sound_mgr);
2142 tp_clear_object (&priv->mic_menu);
2143 tp_clear_object (&priv->camera_menu);
2145 g_list_free_full (priv->notifiers, g_object_unref);
2147 if (priv->timer_id != 0)
2148 g_source_remove (priv->timer_id);
2151 if (priv->contact != NULL)
2153 g_signal_handlers_disconnect_by_func (priv->contact,
2154 contact_name_changed_cb, self);
2155 priv->contact = NULL;
2158 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2162 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2164 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2166 if (priv->video_output_motion_handler_id != 0)
2168 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2169 priv->video_output_motion_handler_id);
2170 priv->video_output_motion_handler_id = 0;
2175 empathy_call_window_finalize (GObject *object)
2177 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2178 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2180 disconnect_video_output_motion_handler (self);
2182 /* free any data held directly by the object here */
2183 g_mutex_free (priv->lock);
2185 g_timer_destroy (priv->timer);
2187 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2192 empathy_call_window_new (EmpathyCallHandler *handler)
2194 return EMPATHY_CALL_WINDOW (
2195 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2199 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2200 GstElement *conference, gpointer user_data)
2202 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2203 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2204 FsElementAddedNotifier *notifier;
2207 DEBUG ("Conference added");
2209 /* Add notifier to set the various element properties as needed */
2210 notifier = fs_element_added_notifier_new ();
2211 keyfile = fs_utils_get_default_element_properties (conference);
2213 if (keyfile != NULL)
2214 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2216 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2218 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2220 gst_bin_add (GST_BIN (priv->pipeline), conference);
2221 gst_element_set_state (conference, GST_STATE_PLAYING);
2225 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2226 GstElement *conference, gpointer user_data)
2228 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2229 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2231 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2232 gst_element_set_state (conference, GST_STATE_NULL);
2236 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2238 GstStateChangeReturn state_change_return;
2239 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2241 if (priv->pipeline == NULL)
2244 if (priv->bus_message_source_id != 0)
2246 g_source_remove (priv->bus_message_source_id);
2247 priv->bus_message_source_id = 0;
2250 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2252 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2253 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2255 if (priv->pipeline != NULL)
2256 g_object_unref (priv->pipeline);
2257 priv->pipeline = NULL;
2259 if (priv->audio_output != NULL)
2260 g_object_unref (priv->audio_output);
2261 priv->audio_output = NULL;
2263 if (priv->video_tee != NULL)
2264 g_object_unref (priv->video_tee);
2265 priv->video_tee = NULL;
2267 if (priv->video_preview != NULL)
2268 clutter_actor_destroy (priv->video_preview);
2269 priv->video_preview = NULL;
2271 priv->funnel = NULL;
2273 create_pipeline (self);
2274 /* Call will be started when user will hit the 'redial' button */
2275 priv->start_call_when_playing = FALSE;
2276 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2282 g_message ("Error: could not destroy pipeline. Closing call window");
2283 gtk_widget_destroy (GTK_WIDGET (self));
2290 reset_details_pane (EmpathyCallWindow *self)
2292 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2294 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2295 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2296 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2297 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2301 empathy_call_window_disconnected (EmpathyCallWindow *self,
2304 gboolean could_disconnect = FALSE;
2305 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2306 gboolean could_reset_pipeline;
2308 /* Leave full screen mode if needed */
2309 gtk_window_unfullscreen (GTK_WINDOW (self));
2311 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2312 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2314 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2316 if (priv->call_state == CONNECTING)
2317 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2319 if (priv->call_state != REDIALING)
2320 priv->call_state = DISCONNECTED;
2322 /* Show the toolbar */
2323 clutter_state_set_state (priv->transitions, "fade-in");
2325 if (could_reset_pipeline)
2327 g_mutex_lock (priv->lock);
2329 g_timer_stop (priv->timer);
2331 if (priv->timer_id != 0)
2332 g_source_remove (priv->timer_id);
2335 g_mutex_unlock (priv->lock);
2338 /* We are about to destroy the window, no need to update it or create
2339 * a video preview */
2342 empathy_call_window_status_message (self, _("Disconnected"));
2344 empathy_call_window_show_hangup_button (self, FALSE);
2346 /* Unsensitive the camera and mic button */
2347 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2348 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2350 /* Be sure that the mic button is enabled */
2351 gtk_toggle_tool_button_set_active (
2352 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2354 if (priv->camera_state == CAMERA_STATE_ON)
2356 /* Restart the preview with the new pipeline. */
2357 display_video_preview (self, TRUE);
2360 /* destroy the video output; it will be recreated when we'll redial */
2361 disconnect_video_output_motion_handler (self);
2362 if (priv->video_output != NULL)
2363 clutter_actor_destroy (priv->video_output);
2364 priv->video_output = NULL;
2365 if (priv->got_video_src > 0)
2367 g_source_remove (priv->got_video_src);
2368 priv->got_video_src = 0;
2371 gtk_widget_show (priv->remote_user_avatar_widget);
2373 reset_details_pane (self);
2375 priv->sending_video = FALSE;
2376 priv->call_started = FALSE;
2378 could_disconnect = TRUE;
2380 /* TODO: display the self avatar of the preview (depends if the "Always
2381 * Show Video Preview" is enabled or not) */
2384 return could_disconnect;
2389 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2392 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2393 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2395 if (empathy_call_window_disconnected (self, TRUE) &&
2396 priv->call_state == REDIALING)
2397 empathy_call_window_restart_call (self);
2401 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2403 FsMediaType media_type,
2404 EmpathyCallWindow *self)
2406 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2408 DEBUG ("removing content");
2411 * This assumes that there is only one video stream per channel...
2414 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2416 if (priv->funnel != NULL)
2420 output = priv->video_output_sink;
2422 gst_element_set_state (output, GST_STATE_NULL);
2423 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2425 gst_bin_remove (GST_BIN (priv->pipeline), output);
2426 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2427 priv->funnel = NULL;
2431 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2433 if (priv->audio_output != NULL)
2435 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2437 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2438 priv->audio_output = NULL;
2446 /* Called with global lock held */
2448 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2450 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2454 if (priv->funnel == NULL)
2456 output = priv->video_output_sink;
2458 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2462 g_warning ("Could not create fsfunnel");
2466 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2468 gst_object_unref (priv->funnel);
2469 priv->funnel = NULL;
2470 g_warning ("Could not add funnel to pipeline");
2474 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2476 g_warning ("Could not add the video output widget to the pipeline");
2480 if (!gst_element_link (priv->funnel, output))
2482 g_warning ("Could not link output sink to funnel");
2483 goto error_output_added;
2486 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2488 g_warning ("Could not start video sink");
2489 goto error_output_added;
2492 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2494 g_warning ("Could not start funnel");
2495 goto error_output_added;
2499 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2502 g_warning ("Could not get request pad from funnel");
2509 gst_element_set_locked_state (priv->funnel, TRUE);
2510 gst_element_set_locked_state (output, TRUE);
2512 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2513 gst_element_set_state (output, GST_STATE_NULL);
2515 gst_bin_remove (GST_BIN (priv->pipeline), output);
2516 gst_element_set_locked_state (output, FALSE);
2520 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2521 priv->funnel = NULL;
2526 /* Called with global lock held */
2528 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2530 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2532 GstPadTemplate *template;
2534 if (priv->audio_output == NULL)
2536 priv->audio_output = empathy_audio_sink_new ();
2537 g_object_ref_sink (priv->audio_output);
2539 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2541 g_warning ("Could not add audio sink to pipeline");
2542 g_object_unref (priv->audio_output);
2543 goto error_add_output;
2546 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2548 g_warning ("Could not start audio sink");
2553 template = gst_element_class_get_pad_template (
2554 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2556 pad = gst_element_request_pad (priv->audio_output,
2557 template, NULL, NULL);
2561 g_warning ("Could not get sink pad from sink");
2568 gst_element_set_locked_state (priv->audio_output, TRUE);
2569 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2570 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2571 priv->audio_output = NULL;
2579 empathy_call_window_update_timer (gpointer user_data)
2581 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2582 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2583 const gchar *status;
2587 time_ = g_timer_elapsed (priv->timer, NULL);
2589 if (priv->call_state == HELD)
2590 status = _("On hold");
2591 else if (!gtk_toggle_tool_button_get_active (
2592 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2595 status = _("Duration");
2597 /* Translators: 'status - minutes:seconds' the caller has been connected */
2598 str = g_strdup_printf (_("%s — %d:%02dm"),
2600 (int) time_ / 60, (int) time_ % 60);
2601 empathy_call_window_status_message (self, str);
2609 display_error (EmpathyCallWindow *self,
2610 TpyCallChannel *call,
2614 const gchar *details)
2616 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2617 GtkWidget *info_bar;
2618 GtkWidget *content_area;
2625 /* Create info bar */
2626 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2629 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2631 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2633 /* hbox containing the image and the messages vbox */
2634 hbox = gtk_hbox_new (FALSE, 3);
2635 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2638 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2639 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2641 /* vbox containing the main message and the details expander */
2642 vbox = gtk_vbox_new (FALSE, 3);
2643 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2646 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2648 label = gtk_label_new (NULL);
2649 gtk_label_set_markup (GTK_LABEL (label), txt);
2650 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2651 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2654 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2657 if (details != NULL)
2659 GtkWidget *expander;
2661 expander = gtk_expander_new (_("Technical Details"));
2663 txt = g_strdup_printf ("<i>%s</i>", details);
2665 label = gtk_label_new (NULL);
2666 gtk_label_set_markup (GTK_LABEL (label), txt);
2667 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2668 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2671 gtk_container_add (GTK_CONTAINER (expander), label);
2672 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2675 g_signal_connect (info_bar, "response",
2676 G_CALLBACK (gtk_widget_destroy), NULL);
2678 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2679 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2680 gtk_widget_show_all (info_bar);
2684 media_stream_error_to_txt (EmpathyCallWindow *self,
2685 TpyCallChannel *call,
2687 TpMediaStreamError error)
2689 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2690 const gchar *cm = NULL;
2696 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2698 return g_strdup_printf (
2699 _("%s's software does not understand any of the audio formats "
2700 "supported by your computer"),
2701 empathy_contact_get_alias (priv->contact));
2703 return g_strdup_printf (
2704 _("%s's software does not understand any of the video formats "
2705 "supported by your computer"),
2706 empathy_contact_get_alias (priv->contact));
2708 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2709 return g_strdup_printf (
2710 _("Can't establish a connection to %s. "
2711 "One of you might be on a network that does not allow "
2712 "direct connections."),
2713 empathy_contact_get_alias (priv->contact));
2715 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2716 return g_strdup (_("There was a failure on the network"));
2718 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2720 return g_strdup (_("The audio formats necessary for this call "
2721 "are not installed on your computer"));
2723 return g_strdup (_("The video formats necessary for this call "
2724 "are not installed on your computer"));
2726 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2727 tp_connection_parse_object_path (
2728 tp_channel_borrow_connection (TP_CHANNEL (call)),
2731 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2732 "product=Telepathy&component=%s", cm);
2734 result = g_strdup_printf (
2735 _("Something unexpected happened in a Telepathy component. "
2736 "Please <a href=\"%s\">report this bug</a> and attach "
2737 "logs gathered from the 'Debug' window in the Help menu."), url);
2743 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2744 return g_strdup (_("There was a failure in the call engine"));
2746 case TP_MEDIA_STREAM_ERROR_EOS:
2747 return g_strdup (_("The end of the stream was reached"));
2749 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2756 empathy_call_window_stream_error (EmpathyCallWindow *self,
2757 TpyCallChannel *call,
2766 desc = media_stream_error_to_txt (self, call, audio, code);
2769 /* No description, use the error message. That's not great as it's not
2770 * localized but it's better than nothing. */
2771 display_error (self, call, icon, title, msg, NULL);
2775 display_error (self, call, icon, title, desc, msg);
2781 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2784 EmpathyCallWindow *self)
2786 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2787 "gnome-stock-mic", _("Can't establish audio stream"));
2791 empathy_call_window_video_stream_error (TpyCallChannel *call,
2794 EmpathyCallWindow *self)
2796 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2797 "camera-web", _("Can't establish video stream"));
2802 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2804 EmpathyCallWindow *self)
2806 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2807 TpyCallChannel *call;
2808 gboolean can_send_video;
2810 if (state != TPY_CALL_STATE_ACCEPTED)
2813 if (priv->call_state == CONNECTED)
2816 g_timer_start (priv->timer);
2817 priv->call_state = CONNECTED;
2819 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2821 can_send_video = priv->video_input != NULL &&
2822 empathy_contact_can_voip_video (priv->contact) &&
2823 empathy_camera_monitor_get_available (priv->camera_monitor);
2825 g_object_get (priv->handler, "call-channel", &call, NULL);
2827 if (tpy_call_channel_has_dtmf (call))
2828 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2830 if (priv->video_input == NULL)
2831 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2833 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2835 empathy_call_window_show_hangup_button (self, TRUE);
2837 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2839 clutter_actor_hide (priv->video_output);
2840 gtk_widget_show (priv->remote_user_avatar_widget);
2842 g_object_unref (call);
2844 g_mutex_lock (priv->lock);
2846 priv->timer_id = g_timeout_add_seconds (1,
2847 empathy_call_window_update_timer, self);
2849 g_mutex_unlock (priv->lock);
2851 empathy_call_window_update_timer (self);
2853 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2857 empathy_call_window_show_video_output_cb (gpointer user_data)
2859 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2861 if (self->priv->video_output != NULL)
2863 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2864 clutter_actor_show (self->priv->video_output);
2865 empathy_call_window_raise_actors (self);
2872 empathy_call_window_check_video_cb (gpointer data)
2874 EmpathyCallWindow *self = data;
2876 if (self->priv->got_video)
2878 self->priv->got_video = FALSE;
2882 /* No video in the last N seconds, display the remote avatar */
2883 empathy_call_window_show_video_output (self, FALSE);
2888 /* Called from the streaming thread */
2890 empathy_call_window_video_probe_cb (GstPad *pad,
2891 GstMiniObject *mini_obj,
2892 EmpathyCallWindow *self)
2895 if (GST_IS_EVENT (mini_obj))
2898 if (G_UNLIKELY (!self->priv->got_video))
2900 /* show the remote video */
2901 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2902 empathy_call_window_show_video_output_cb,
2903 g_object_ref (self), g_object_unref);
2905 self->priv->got_video = TRUE;
2911 /* Called from the streaming thread */
2913 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2914 GstPad *src, guint media_type, gpointer user_data)
2916 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2917 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2918 gboolean retval = FALSE;
2922 g_mutex_lock (priv->lock);
2926 case TP_MEDIA_STREAM_TYPE_AUDIO:
2927 pad = empathy_call_window_get_audio_sink_pad (self);
2929 case TP_MEDIA_STREAM_TYPE_VIDEO:
2930 g_idle_add (empathy_call_window_show_video_output_cb, self);
2931 pad = empathy_call_window_get_video_sink_pad (self);
2933 gst_pad_add_data_probe (src,
2934 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2935 if (priv->got_video_src > 0)
2936 g_source_remove (priv->got_video_src);
2937 priv->got_video_src = g_timeout_add_seconds (5,
2938 empathy_call_window_check_video_cb, self);
2941 g_assert_not_reached ();
2947 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2948 g_warning ("Could not link %s sink pad",
2949 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2953 gst_object_unref (pad);
2957 /* If no sink could be linked, try to add fakesink to prevent the whole call
2962 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2964 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2966 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2967 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2968 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2970 gst_element_set_locked_state (fakesink, TRUE);
2971 gst_element_set_state (fakesink, GST_STATE_NULL);
2972 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2976 DEBUG ("Could not link real sink, linked fakesink instead");
2978 gst_object_unref (sinkpad);
2982 gst_object_unref (fakesink);
2987 g_mutex_unlock (priv->lock);
2993 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2994 GstPad *sink, FsMediaType media_type, gpointer user_data)
2996 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2997 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2999 gboolean retval = FALSE;
3003 case FS_MEDIA_TYPE_AUDIO:
3004 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3006 g_warning ("Could not add audio source to pipeline");
3010 pad = gst_element_get_static_pad (priv->audio_input, "src");
3013 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3014 g_warning ("Could not get source pad from audio source");
3018 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3020 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3021 g_warning ("Could not link audio source to farsight");
3025 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3027 g_warning ("Could not start audio source");
3028 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3029 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3035 case FS_MEDIA_TYPE_VIDEO:
3036 if (priv->video_tee != NULL)
3038 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3039 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3041 g_warning ("Could not link video source input pipeline");
3044 gst_object_unref (pad);
3050 g_assert_not_reached ();
3057 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3059 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3060 GstElement *preview;
3062 disable_camera (self);
3064 DEBUG ("remove video input");
3065 preview = priv->video_preview_sink;
3067 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3068 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3069 gst_element_set_state (preview, GST_STATE_NULL);
3071 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3074 g_object_unref (priv->video_input);
3075 priv->video_input = NULL;
3076 g_object_unref (priv->video_tee);
3077 priv->video_tee = NULL;
3078 clutter_actor_destroy (priv->video_preview);
3079 priv->video_preview = NULL;
3081 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3085 start_call (EmpathyCallWindow *self)
3087 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3089 priv->call_started = TRUE;
3090 empathy_call_handler_start_call (priv->handler,
3091 gtk_get_current_event_time ());
3093 if (empathy_call_handler_has_initial_video (priv->handler))
3095 TpyCallChannel *call;
3098 g_object_get (priv->handler, "call-channel", &call, NULL);
3099 s = tpy_call_channel_get_video_state (call);
3101 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3102 s == TPY_SENDING_STATE_SENDING)
3104 /* Enable 'send video' buttons and display the preview */
3105 gtk_toggle_tool_button_set_active (
3106 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3110 gtk_toggle_tool_button_set_active (
3111 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3113 if (priv->video_preview == NULL)
3115 create_video_preview (self);
3116 add_video_preview_to_pipeline (self);
3120 g_object_unref (call);
3125 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3128 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3129 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3132 empathy_call_handler_bus_message (priv->handler, bus, message);
3134 switch (GST_MESSAGE_TYPE (message))
3136 case GST_MESSAGE_STATE_CHANGED:
3137 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3139 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3141 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3142 !priv->call_started)
3144 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3145 if (newstate == GST_STATE_PAUSED)
3147 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3148 priv->pipeline_playing = TRUE;
3150 if (priv->start_call_when_playing)
3155 case GST_MESSAGE_ERROR:
3157 GError *error = NULL;
3158 GstElement *gst_error;
3161 gst_message_parse_error (message, &error, &debug);
3162 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3164 g_message ("Element error: %s -- %s\n", error->message, debug);
3166 if (g_str_has_prefix (gst_element_get_name (gst_error),
3167 VIDEO_INPUT_ERROR_PREFIX))
3169 /* Remove the video input and continue */
3170 if (priv->video_input != NULL)
3171 empathy_call_window_remove_video_input (self);
3172 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3176 empathy_call_window_disconnected (self, TRUE);
3178 g_error_free (error);
3181 case GST_MESSAGE_UNKNOWN:
3182 case GST_MESSAGE_EOS:
3183 case GST_MESSAGE_WARNING:
3184 case GST_MESSAGE_INFO:
3185 case GST_MESSAGE_TAG:
3186 case GST_MESSAGE_BUFFERING:
3187 case GST_MESSAGE_STATE_DIRTY:
3188 case GST_MESSAGE_STEP_DONE:
3189 case GST_MESSAGE_CLOCK_PROVIDE:
3190 case GST_MESSAGE_CLOCK_LOST:
3191 case GST_MESSAGE_NEW_CLOCK:
3192 case GST_MESSAGE_STRUCTURE_CHANGE:
3193 case GST_MESSAGE_STREAM_STATUS:
3194 case GST_MESSAGE_APPLICATION:
3195 case GST_MESSAGE_ELEMENT:
3196 case GST_MESSAGE_SEGMENT_START:
3197 case GST_MESSAGE_SEGMENT_DONE:
3198 case GST_MESSAGE_DURATION:
3199 case GST_MESSAGE_ANY:
3208 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3209 GHashTable *members,
3210 EmpathyCallWindow *self)
3212 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3213 GHashTableIter iter;
3214 gpointer key, value;
3215 gboolean held = FALSE;
3217 g_hash_table_iter_init (&iter, members);
3218 while (g_hash_table_iter_next (&iter, &key, &value))
3220 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3222 /* This assumes this is a 1-1 call, otherwise one participant
3223 * putting the call on hold wouldn't mean the call is on hold
3231 priv->call_state = HELD;
3232 else if (priv->call_state == HELD)
3233 priv->call_state = CONNECTED;
3237 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3239 EmpathyCallWindow *self)
3241 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3242 TpyCallChannel *call;
3244 g_object_get (priv->handler, "call-channel", &call, NULL);
3249 tp_g_signal_connect_object (call, "audio-stream-error",
3250 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3251 tp_g_signal_connect_object (call, "video-stream-error",
3252 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3255 tp_g_signal_connect_object (call, "members-changed",
3256 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3258 g_object_unref (call);
3262 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3264 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3265 TpyCallChannel *call;
3268 /* Make the hangup button twice as wide */
3269 width = gtk_widget_get_allocated_width (priv->hangup_button);
3270 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3272 g_signal_connect (priv->handler, "state-changed",
3273 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3274 g_signal_connect (priv->handler, "conference-added",
3275 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3276 g_signal_connect (priv->handler, "conference-removed",
3277 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3278 g_signal_connect (priv->handler, "closed",
3279 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3280 g_signal_connect (priv->handler, "src-pad-added",
3281 G_CALLBACK (empathy_call_window_src_added_cb), window);
3282 g_signal_connect (priv->handler, "sink-pad-added",
3283 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3284 g_signal_connect (priv->handler, "sink-pad-removed",
3285 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3287 g_object_get (priv->handler, "call-channel", &call, NULL);
3290 call_handler_notify_call_cb (priv->handler, NULL, window);
3291 g_object_unref (call);
3295 /* call-channel doesn't exist yet, we'll connect signals once it has been
3297 g_signal_connect (priv->handler, "notify::call-channel",
3298 G_CALLBACK (call_handler_notify_call_cb), window);
3301 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3305 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3306 EmpathyCallWindow *window)
3308 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3310 if (priv->pipeline != NULL)
3312 if (priv->bus_message_source_id != 0)
3314 g_source_remove (priv->bus_message_source_id);
3315 priv->bus_message_source_id = 0;
3318 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3321 if (priv->call_state == CONNECTING)
3322 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3328 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3331 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3333 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3338 gtk_widget_hide (priv->dtmf_panel);
3339 gtk_widget_hide (menu);
3340 gtk_widget_hide (priv->toolbar);
3344 if (priv->dialpad_was_visible_before_fs)
3345 gtk_widget_show (priv->dtmf_panel);
3347 gtk_widget_show (menu);
3348 gtk_widget_show (priv->toolbar);
3350 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3351 priv->original_height_before_fs);
3356 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3358 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3360 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3361 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3362 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3363 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3365 if (priv->video_output != NULL)
3368 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3369 priv->video_output, TRUE, TRUE,
3370 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3377 empathy_call_window_state_event_cb (GtkWidget *widget,
3378 GdkEventWindowState *event, EmpathyCallWindow *window)
3380 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3382 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3383 gboolean set_fullscreen = event->new_window_state &
3384 GDK_WINDOW_STATE_FULLSCREEN;
3388 gboolean dialpad_was_visible;
3389 GtkAllocation allocation;
3390 gint original_width, original_height;
3392 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3393 original_width = allocation.width;
3394 original_height = allocation.height;
3396 g_object_get (priv->dtmf_panel,
3397 "visible", &dialpad_was_visible,
3400 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3401 priv->original_width_before_fs = original_width;
3402 priv->original_height_before_fs = original_height;
3404 if (priv->video_output_motion_handler_id == 0 &&
3405 priv->video_output != NULL)
3407 priv->video_output_motion_handler_id = g_signal_connect (
3408 G_OBJECT (priv->video_container), "motion-notify-event",
3409 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3415 disconnect_video_output_motion_handler (window);
3418 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3420 show_controls (window, set_fullscreen);
3421 show_borders (window, set_fullscreen);
3422 gtk_action_set_stock_id (priv->menu_fullscreen,
3423 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3424 priv->is_fullscreen = set_fullscreen;
3431 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3434 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3435 int w, h, dialpad_width;
3436 GtkAllocation allocation;
3438 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3439 w = allocation.width;
3440 h = allocation.height;
3442 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3446 gtk_widget_show (priv->dtmf_panel);
3452 gtk_widget_hide (priv->dtmf_panel);
3456 gtk_window_resize (GTK_WINDOW (window), w, h);
3460 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3463 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3464 TpyCallChannel *call;
3466 priv->sending_video = (state == CAMERA_STATE_ON);
3468 if (state == CAMERA_STATE_ON)
3470 /* When we start sending video, we want to show the video preview by
3472 display_video_preview (window, TRUE);
3476 display_video_preview (window, FALSE);
3479 if (priv->call_state != CONNECTED)
3482 g_object_get (priv->handler, "call-channel", &call, NULL);
3483 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3484 tpy_call_channel_send_video (call, priv->sending_video);
3485 g_object_unref (call);
3489 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3490 EmpathyCallWindow *self)
3492 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3495 active = (gtk_toggle_tool_button_get_active (toggle));
3497 /* We don't want the settings callback to react to this change to avoid
3499 g_signal_handlers_block_by_func (priv->settings,
3500 empathy_call_window_prefs_volume_changed_cb, self);
3504 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3505 priv->volume * 100);
3509 /* TODO, Instead of setting the input volume to 0 we should probably
3510 * stop sending but this would cause the audio call to drop if both
3511 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3512 * in the future. GNOME #574574
3514 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3518 g_signal_handlers_unblock_by_func (priv->settings,
3519 empathy_call_window_prefs_volume_changed_cb, self);
3523 empathy_call_window_hangup_cb (gpointer object,
3524 EmpathyCallWindow *self)
3526 empathy_call_handler_stop_call (self->priv->handler);
3528 empathy_call_window_disconnected (self, TRUE);
3532 empathy_call_window_restart_call (EmpathyCallWindow *window)
3534 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3536 /* Remove error info bars */
3537 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3538 (GtkCallback) gtk_widget_destroy, NULL);
3540 create_video_output_widget (window);
3542 /* While the call was disconnected, the input volume might have changed.
3543 * However, since the audio_input source was destroyed, its volume has not
3544 * been updated during that time. That's why we manually update it here */
3545 empathy_call_window_mic_volume_changed (window);
3547 priv->outgoing = TRUE;
3548 empathy_call_window_set_state_connecting (window);
3550 if (priv->pipeline_playing)
3551 start_call (window);
3553 /* call will be started when the pipeline is ready */
3554 priv->start_call_when_playing = TRUE;
3556 empathy_call_window_setup_avatars (window, priv->handler);
3558 empathy_call_window_show_hangup_button (window, TRUE);
3562 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3563 EmpathyCallWindow *window)
3567 active = gtk_toggle_tool_button_get_active (button);
3569 empathy_call_window_show_dialpad (window, active);
3573 empathy_call_window_fullscreen_cb (gpointer object,
3574 EmpathyCallWindow *window)
3576 empathy_call_window_fullscreen_toggle (window);
3580 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3582 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3584 if (priv->is_fullscreen)
3585 gtk_window_unfullscreen (GTK_WINDOW (window));
3587 gtk_window_fullscreen (GTK_WINDOW (window));
3591 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3592 GdkEventButton *event, EmpathyCallWindow *window)
3594 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3596 empathy_call_window_video_menu_popup (window, event->button);
3604 empathy_call_window_key_press_cb (GtkWidget *video_output,
3605 GdkEventKey *event, EmpathyCallWindow *window)
3607 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3609 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3611 /* Since we are in fullscreen mode, toggling will bring us back to
3613 empathy_call_window_fullscreen_toggle (window);
3621 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3622 GdkEventMotion *event, EmpathyCallWindow *window)
3624 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3626 if (priv->is_fullscreen)
3628 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3630 /* Show the bottom toolbar */
3631 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3638 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3642 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3644 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3646 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3647 button, gtk_get_current_event_time ());
3648 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3652 empathy_call_window_status_message (EmpathyCallWindow *self,
3655 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3659 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3660 gdouble value, EmpathyCallWindow *window)
3662 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3664 if (priv->audio_output == NULL)
3667 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3672 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3674 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3676 return priv->ui_manager;
3679 EmpathyGstAudioSrc *
3680 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3682 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3684 return (EmpathyGstAudioSrc *) priv->audio_input;
3687 EmpathyGstVideoSrc *
3688 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3690 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);