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 ();
814 g_settings_set_enum (self->priv->settings, "camera-position", pos);
818 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
821 ClutterActor *rectangle;
823 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
825 empathy_rounded_rectangle_set_border_width (
826 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
827 empathy_rounded_rectangle_set_border_color (
828 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
832 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
833 ClutterActor *rectangle)
835 empathy_rounded_rectangle_set_border_width (
836 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
837 empathy_rounded_rectangle_set_border_color (
838 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
842 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
844 ClutterActor *rectangle;
846 rectangle = empathy_call_window_get_preview_rectangle (self,
847 self->priv->preview_pos);
849 /* We don't want to darken the rectangle where the preview
852 if (self->priv->preview_rectangle1 != rectangle)
853 empathy_call_window_darken_preview_rectangle (self,
854 self->priv->preview_rectangle1);
856 if (self->priv->preview_rectangle2 != rectangle)
857 empathy_call_window_darken_preview_rectangle (self,
858 self->priv->preview_rectangle2);
860 if (self->priv->preview_rectangle3 != rectangle)
861 empathy_call_window_darken_preview_rectangle (self,
862 self->priv->preview_rectangle3);
864 if (self->priv->preview_rectangle4 != rectangle)
865 empathy_call_window_darken_preview_rectangle (self,
866 self->priv->preview_rectangle4);
870 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
874 ClutterModifierType modifiers,
875 EmpathyCallWindow *self)
877 ClutterActor *stage = clutter_actor_get_stage (actor);
878 ClutterActor *preview = clutter_clone_new (actor);
881 clutter_container_add_actor (CLUTTER_CONTAINER (stage), preview);
883 clutter_actor_transform_stage_point (actor, event_x, event_y,
886 clutter_actor_set_position (preview, event_x - rel_x, event_y - rel_y);
888 clutter_drag_action_set_drag_handle (action, preview);
890 clutter_actor_set_opacity (actor, 0);
891 clutter_actor_hide (self->priv->preview_shown_button);
893 empathy_call_window_show_preview_rectangles (self, TRUE);
894 empathy_call_window_darken_preview_rectangles (self);
898 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
902 ClutterModifierType modifiers,
903 EmpathyCallWindow *self)
905 ClutterActor *preview = clutter_drag_action_get_drag_handle (action);
908 /* Get the position before destroying the drag actor, otherwise the
909 * preview_box allocation won't be valid and we won't be able to
910 * calculate the position. */
911 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
913 /* Destroy the video preview copy that we were dragging */
914 clutter_actor_destroy (preview);
916 clutter_actor_set_opacity (actor, 255);
917 clutter_actor_show (self->priv->preview_shown_button);
919 if (pos != PREVIEW_POS_NONE)
920 empathy_call_window_move_video_preview (self, pos);
922 empathy_call_window_show_preview_rectangles (self, FALSE);
926 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
930 EmpathyCallWindow *self)
933 gfloat event_x, event_y;
935 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
937 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
939 if (pos != PREVIEW_POS_NONE)
940 empathy_call_window_highlight_preview_rectangle (self, pos);
942 empathy_call_window_darken_preview_rectangles (self);
946 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
947 ClutterCrossingEvent *event,
948 EmpathyCallWindow *self)
950 ClutterActor *rectangle;
952 rectangle = empathy_call_window_get_preview_rectangle (self,
953 self->priv->preview_pos);
955 empathy_call_window_highlight_preview_rectangle (self,
956 self->priv->preview_pos);
958 clutter_actor_show (rectangle);
964 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
965 ClutterCrossingEvent *event,
966 EmpathyCallWindow *self)
968 ClutterActor *rectangle;
970 rectangle = empathy_call_window_get_preview_rectangle (self,
971 self->priv->preview_pos);
973 empathy_call_window_darken_preview_rectangle (self, rectangle);
975 clutter_actor_hide (rectangle);
981 create_video_preview (EmpathyCallWindow *self)
983 EmpathyCallWindowPriv *priv = GET_PRIV (self);
984 ClutterLayoutManager *layout, *layout_center, *layout_end;
985 ClutterActor *preview;
988 ClutterAction *action;
992 g_assert (priv->video_preview == NULL);
994 pos = g_settings_get_enum (priv->settings, "camera-position");
996 preview = empathy_rounded_texture_new ();
997 clutter_actor_set_size (preview,
998 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
999 priv->video_preview_sink = clutter_gst_video_sink_new (
1000 CLUTTER_TEXTURE (preview));
1002 /* Add a little offset to the video preview */
1003 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1004 CLUTTER_BIN_ALIGNMENT_START);
1005 priv->video_preview = clutter_box_new (layout);
1006 clutter_actor_set_size (priv->video_preview,
1007 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1008 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1009 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1011 /* We have a box with the margins and the video in the middle inside
1012 * a bigger box with an extra bottom margin so we're not on top of
1013 * the floating toolbar. */
1014 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1015 CLUTTER_BIN_ALIGNMENT_CENTER);
1016 box = clutter_box_new (layout_center);
1017 clutter_actor_set_size (box,
1018 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1019 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1021 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1022 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1024 g_object_set (priv->video_preview_sink,
1029 /* Translators: this is an "Info" label. It should be as short
1031 button = gtk_button_new_with_label (_("i"));
1032 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1034 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1036 clutter_actor_set_size (b, 24, 24);
1038 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1039 CLUTTER_BIN_ALIGNMENT_END);
1040 box = clutter_box_new (layout_end);
1041 clutter_actor_set_size (box,
1042 SELF_VIDEO_SECTION_WIDTH,
1043 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1045 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1046 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1048 g_signal_connect (button, "clicked",
1049 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1052 /* Translators: this is an "Info" label. It should be as short
1054 button = gtk_button_new_with_label (_("i"));
1055 b = empathy_rounded_actor_new ();
1057 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1059 clutter_actor_set_size (b, 24, 24);
1060 priv->preview_hidden_button = b;
1062 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1063 priv->preview_hidden_button,
1064 CLUTTER_BIN_ALIGNMENT_START,
1065 CLUTTER_BIN_ALIGNMENT_END);
1067 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1069 clutter_actor_hide (priv->preview_hidden_button);
1071 g_signal_connect (button, "clicked",
1072 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1075 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1076 priv->video_preview,
1077 CLUTTER_BIN_ALIGNMENT_START,
1078 CLUTTER_BIN_ALIGNMENT_END);
1080 empathy_call_window_move_video_preview (self, pos);
1082 action = clutter_drag_action_new ();
1083 g_signal_connect (action, "drag-begin",
1084 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1085 g_signal_connect (action, "drag-end",
1086 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1087 g_signal_connect (action, "drag-motion",
1088 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1090 g_signal_connect (preview, "enter-event",
1091 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1092 g_signal_connect (preview, "leave-event",
1093 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1095 clutter_actor_add_action (preview, action);
1096 clutter_actor_set_reactive (preview, TRUE);
1097 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1101 empathy_call_window_play_camera (EmpathyCallWindow *window,
1104 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1105 GstElement *preview;
1108 if (priv->video_preview == NULL)
1110 create_video_preview (window);
1111 add_video_preview_to_pipeline (window);
1115 state = GST_STATE_PLAYING;
1117 state = GST_STATE_NULL;
1119 preview = priv->video_preview_sink;
1121 gst_element_set_state (preview, state);
1122 gst_element_set_state (priv->video_input, state);
1123 gst_element_set_state (priv->video_tee, state);
1127 display_video_preview (EmpathyCallWindow *self,
1130 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1134 /* Display the video preview */
1135 DEBUG ("Show video preview");
1137 empathy_call_window_play_camera (self, TRUE);
1138 clutter_actor_show (priv->video_preview);
1139 clutter_actor_raise_top (priv->floating_toolbar);
1143 /* Hide the video preview */
1144 DEBUG ("Hide video preview");
1146 if (priv->video_preview != NULL)
1148 clutter_actor_hide (priv->video_preview);
1149 empathy_call_window_play_camera (self, FALSE);
1155 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1157 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1159 empathy_call_window_status_message (window, _("Connecting…"));
1160 priv->call_state = CONNECTING;
1162 /* Show the toolbar */
1163 clutter_state_set_state (priv->transitions, "fade-in");
1166 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1167 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1171 disable_camera (EmpathyCallWindow *self)
1173 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1175 if (priv->camera_state == CAMERA_STATE_OFF)
1178 DEBUG ("Disable camera");
1180 display_video_preview (self, FALSE);
1182 if (priv->camera_state == CAMERA_STATE_ON)
1183 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1185 priv->camera_state = CAMERA_STATE_OFF;
1189 enable_camera (EmpathyCallWindow *self)
1191 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1193 if (priv->camera_state == CAMERA_STATE_ON)
1196 if (priv->video_input == NULL)
1198 DEBUG ("Can't enable camera, no input");
1202 DEBUG ("Enable camera");
1204 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1206 priv->camera_state = CAMERA_STATE_ON;
1210 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1211 EmpathyCallWindow *self)
1213 if (gtk_toggle_tool_button_get_active (toggle))
1214 enable_camera (self);
1216 disable_camera (self);
1220 create_pipeline (EmpathyCallWindow *self)
1222 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1225 g_assert (priv->pipeline == NULL);
1227 priv->pipeline = gst_pipeline_new (NULL);
1228 priv->pipeline_playing = FALSE;
1230 priv->video_tee = gst_element_factory_make ("tee", NULL);
1231 gst_object_ref (priv->video_tee);
1232 gst_object_sink (priv->video_tee);
1234 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1236 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1237 priv->bus_message_source_id = gst_bus_add_watch (bus,
1238 empathy_call_window_bus_message, self);
1240 g_object_unref (bus);
1244 empathy_call_window_settings_cb (GtkAction *action,
1245 EmpathyCallWindow *self)
1247 gchar *args = g_strdup_printf ("-p %s",
1248 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1250 empathy_launch_program (BIN_DIR, "empathy", args);
1256 empathy_call_window_contents_cb (GtkAction *action,
1257 EmpathyCallWindow *self)
1259 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1263 empathy_call_window_debug_cb (GtkAction *action,
1264 EmpathyCallWindow *self)
1266 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1270 empathy_call_window_about_cb (GtkAction *action,
1271 EmpathyCallWindow *self)
1273 empathy_about_dialog_new (GTK_WINDOW (self));
1277 empathy_call_window_toolbar_timeout (gpointer data)
1279 EmpathyCallWindow *self = data;
1281 /* We don't want to hide the toolbar if we're not in a call, as
1282 * to show the call status all the time. */
1283 if (self->priv->call_state != CONNECTING &&
1284 self->priv->call_state != DISCONNECTED)
1285 clutter_state_set_state (self->priv->transitions, "fade-out");
1291 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1293 EmpathyCallWindow *self)
1295 clutter_state_set_state (self->priv->transitions, "fade-in");
1297 if (self->priv->inactivity_src > 0)
1298 g_source_remove (self->priv->inactivity_src);
1300 self->priv->inactivity_src = g_timeout_add_seconds (3,
1301 empathy_call_window_toolbar_timeout, self);
1307 empathy_call_window_configure_event_cb (GtkWidget *widget,
1309 EmpathyCallWindow *self)
1311 GdkWindow *gdk_window;
1312 GdkWindowState window_state;
1314 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1315 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1317 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1318 &self->priv->dialpad_width, NULL);
1320 gdk_window = gtk_widget_get_window (widget);
1321 window_state = gdk_window_get_state (gdk_window);
1322 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1328 empathy_call_window_destroyed_cb (GtkWidget *object,
1329 EmpathyCallWindow *self)
1331 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1333 /* Save the geometry as if the dialpad was hidden. */
1334 empathy_geometry_save_values (GTK_WINDOW (self),
1335 self->priv->x, self->priv->y,
1336 self->priv->w - self->priv->dialpad_width, self->priv->h,
1337 self->priv->maximized);
1342 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1344 ClutterBindConstraint *constraint)
1346 ClutterActorBox allocation;
1348 clutter_actor_get_allocation_box (stage, &allocation);
1350 clutter_bind_constraint_set_offset (constraint,
1351 allocation.y2 - allocation.y1 -
1352 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1356 empathy_call_window_init (EmpathyCallWindow *self)
1358 EmpathyCallWindowPriv *priv;
1360 GtkWidget *top_vbox;
1362 ClutterConstraint *constraint;
1363 ClutterActor *remote_avatar;
1364 GtkStyleContext *context;
1368 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1369 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1371 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1372 gui = empathy_builder_get_file (filename,
1373 "call_window_vbox", &top_vbox,
1374 "errors_vbox", &priv->errors_vbox,
1375 "pane", &priv->pane,
1376 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1377 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1378 "status_label", &priv->status_label,
1379 "audiocall", &priv->audio_call_button,
1380 "videocall", &priv->video_call_button,
1381 "microphone", &priv->mic_button,
1382 "camera", &priv->camera_button,
1383 "hangup", &priv->hangup_button,
1384 "dialpad", &priv->dialpad_button,
1385 "toolbar", &priv->toolbar,
1386 "bottom_toolbar", &priv->bottom_toolbar,
1387 "ui_manager", &priv->ui_manager,
1388 "menufullscreen", &priv->menu_fullscreen,
1389 "menupreviewswap", &priv->menu_swap_camera,
1390 "details_vbox", &priv->details_vbox,
1391 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1392 "acodec_encoding_label", &priv->acodec_encoding_label,
1393 "acodec_decoding_label", &priv->acodec_decoding_label,
1394 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1395 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1396 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1397 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1398 "video_local_candidate_label", &priv->video_local_candidate_label,
1399 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1400 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1401 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1402 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1406 empathy_builder_connect (gui, self,
1407 "hangup", "clicked", empathy_call_window_hangup_cb,
1408 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1409 "videocall", "clicked", empathy_call_window_video_call_cb,
1410 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1411 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1412 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1413 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1414 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1415 "menusettings", "activate", empathy_call_window_settings_cb,
1416 "menucontents", "activate", empathy_call_window_contents_cb,
1417 "menudebug", "activate", empathy_call_window_debug_cb,
1418 "menuabout", "activate", empathy_call_window_about_cb,
1419 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1420 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1421 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1422 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1425 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1427 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1429 g_object_bind_property (priv->camera_monitor, "available",
1430 priv->camera_button, "sensitive",
1431 G_BINDING_SYNC_CREATE);
1433 g_signal_connect (priv->camera_monitor, "added",
1434 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1435 g_signal_connect (priv->camera_monitor, "removed",
1436 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1438 priv->lock = g_mutex_new ();
1440 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1442 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1443 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1444 CONTENT_HBOX_BORDER_WIDTH);
1445 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1448 /* avatar/video box */
1449 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1450 CLUTTER_BIN_ALIGNMENT_CENTER);
1452 priv->video_box = clutter_box_new (priv->video_layout);
1454 priv->video_container = gtk_clutter_embed_new ();
1456 /* Set the background color to that of the rest of the window */
1457 context = gtk_widget_get_style_context (priv->content_hbox);
1458 gtk_style_context_get_background_color (context,
1459 GTK_STATE_FLAG_NORMAL, &rgba);
1460 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1461 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1462 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1463 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1464 clutter_stage_set_color (
1465 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1466 GTK_CLUTTER_EMBED (priv->video_container))),
1469 clutter_container_add (
1470 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1471 GTK_CLUTTER_EMBED (priv->video_container))),
1475 constraint = clutter_bind_constraint_new (
1476 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1477 CLUTTER_BIND_SIZE, 0);
1478 clutter_actor_add_constraint (priv->video_box, constraint);
1480 priv->remote_user_avatar_widget = gtk_image_new ();
1481 remote_avatar = gtk_clutter_actor_new_with_contents (
1482 priv->remote_user_avatar_widget);
1484 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1487 empathy_call_window_create_preview_rectangles (self);
1489 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1490 priv->video_container, TRUE, TRUE,
1491 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1493 create_pipeline (self);
1494 create_video_output_widget (self);
1495 create_audio_input (self);
1496 create_video_input (self);
1498 priv->floating_toolbar = empathy_rounded_actor_new ();
1500 gtk_widget_reparent (priv->bottom_toolbar,
1501 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1503 constraint = clutter_bind_constraint_new (
1504 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1507 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1510 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1511 "notify::allocation",
1512 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1515 clutter_actor_set_size (priv->floating_toolbar,
1516 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1517 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1519 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1520 priv->floating_toolbar,
1521 CLUTTER_BIN_ALIGNMENT_CENTER,
1522 CLUTTER_BIN_ALIGNMENT_END);
1524 clutter_actor_raise_top (priv->floating_toolbar);
1526 /* Transitions for the floating toolbar */
1527 priv->transitions = clutter_state_new ();
1529 /* all transitions last for 2s */
1530 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1532 /* transition from any state to "fade-out" state */
1533 clutter_state_set (priv->transitions, NULL, "fade-out",
1534 priv->floating_toolbar,
1535 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1538 /* transition from any state to "fade-in" state */
1539 clutter_state_set (priv->transitions, NULL, "fade-in",
1540 priv->floating_toolbar,
1541 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1544 /* put the actor into the "fade-in" state with no animation */
1545 clutter_state_warp_to_state (priv->transitions, "fade-in");
1547 /* The call will be started as soon the pipeline is playing */
1548 priv->start_call_when_playing = TRUE;
1550 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1551 G_CALLBACK (dtmf_button_pressed_cb),
1552 G_CALLBACK (dtmf_button_released_cb));
1554 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1557 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1560 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1562 gtk_widget_show_all (top_vbox);
1564 gtk_widget_hide (priv->dtmf_panel);
1565 gtk_widget_hide (priv->details_vbox);
1567 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1569 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1570 priv->video_container);
1572 /* We hide the bottom toolbar after 3s of inactivity and show it
1573 * again on mouse movement */
1574 priv->inactivity_src = g_timeout_add_seconds (3,
1575 empathy_call_window_toolbar_timeout, self);
1577 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1578 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1580 g_signal_connect (G_OBJECT (self), "realize",
1581 G_CALLBACK (empathy_call_window_realized_cb), self);
1583 g_signal_connect (G_OBJECT (self), "delete-event",
1584 G_CALLBACK (empathy_call_window_delete_cb), self);
1586 g_signal_connect (G_OBJECT (self), "window-state-event",
1587 G_CALLBACK (empathy_call_window_state_event_cb), self);
1589 g_signal_connect (G_OBJECT (self), "key-press-event",
1590 G_CALLBACK (empathy_call_window_key_press_cb), self);
1592 g_signal_connect (self, "motion-notify-event",
1593 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1595 priv->timer = g_timer_new ();
1597 g_object_ref (priv->ui_manager);
1598 g_object_unref (gui);
1600 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1601 priv->mic_menu = empathy_mic_menu_new (self);
1602 priv->camera_menu = empathy_camera_menu_new (self);
1604 empathy_call_window_show_hangup_button (self, TRUE);
1606 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1608 /* Retrieve initial volume */
1609 priv->volume = g_settings_get_double (priv->settings,
1610 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1612 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1613 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1615 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1616 /* These signals are used to track the window position and save it
1617 * when the window is destroyed. We need to do this as we don't want
1618 * the window geometry to be saved with the dialpad taken into account. */
1619 g_signal_connect (self, "destroy",
1620 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1621 g_signal_connect (self, "configure-event",
1622 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1623 g_signal_connect (self, "window-state-event",
1624 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1626 /* Don't display labels in both toolbars */
1627 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1630 /* Instead of specifying a width and a height, we specify only one size. That's
1631 because we want a square avatar icon. */
1633 init_contact_avatar_with_size (EmpathyContact *contact,
1634 GtkWidget *image_widget,
1637 GdkPixbuf *pixbuf_avatar = NULL;
1639 if (contact != NULL)
1641 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1645 if (pixbuf_avatar == NULL)
1647 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1648 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1651 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1653 if (pixbuf_avatar != NULL)
1654 g_object_unref (pixbuf_avatar);
1658 set_window_title (EmpathyCallWindow *self)
1660 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1663 if (priv->contact != NULL)
1665 /* translators: Call is a noun and %s is the contact name. This string
1666 * is used in the window title */
1667 tmp = g_strdup_printf (_("Call with %s"),
1668 empathy_contact_get_alias (priv->contact));
1669 gtk_window_set_title (GTK_WINDOW (self), tmp);
1674 g_warning ("Unknown remote contact!");
1679 set_remote_user_name (EmpathyCallWindow *self,
1680 EmpathyContact *contact)
1682 const gchar *alias = empathy_contact_get_alias (contact);
1683 const gchar *status = empathy_contact_get_status (contact);
1686 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1687 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1693 contact_name_changed_cb (EmpathyContact *contact,
1695 EmpathyCallWindow *self)
1697 set_window_title (self);
1698 set_remote_user_name (self, contact);
1702 contact_presence_changed_cb (EmpathyContact *contact,
1704 EmpathyCallWindow *self)
1706 set_remote_user_name (self, contact);
1710 contact_avatar_changed_cb (EmpathyContact *contact,
1712 EmpathyCallWindow *self)
1715 GtkAllocation allocation;
1716 GtkWidget *avatar_widget;
1718 avatar_widget = self->priv->remote_user_avatar_widget;
1720 gtk_widget_get_allocation (avatar_widget, &allocation);
1721 size = allocation.height;
1725 /* the widget is not allocated yet, set a default size */
1726 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1727 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1730 init_contact_avatar_with_size (contact, avatar_widget, size);
1732 avatar_widget = self->priv->remote_user_avatar_toolbar;
1734 gtk_widget_get_allocation (avatar_widget, &allocation);
1735 size = allocation.height;
1739 /* the widget is not allocated yet, set a default size */
1740 size = SMALL_TOOLBAR_SIZE;
1743 init_contact_avatar_with_size (contact, avatar_widget, size);
1747 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1748 EmpathyCallHandler *handler)
1750 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1752 tp_g_signal_connect_object (priv->contact, "notify::name",
1753 G_CALLBACK (contact_name_changed_cb), self, 0);
1754 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1755 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1756 tp_g_signal_connect_object (priv->contact, "notify::presence",
1757 G_CALLBACK (contact_presence_changed_cb), self, 0);
1759 set_window_title (self);
1760 set_remote_user_name (self, priv->contact);
1762 init_contact_avatar_with_size (priv->contact,
1763 priv->remote_user_avatar_widget,
1764 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1765 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1767 init_contact_avatar_with_size (priv->contact,
1768 priv->remote_user_avatar_toolbar,
1769 SMALL_TOOLBAR_SIZE);
1771 /* The remote avatar is shown by default and will be hidden when we receive
1772 video from the remote side. */
1773 clutter_actor_hide (priv->video_output);
1774 gtk_widget_show (priv->remote_user_avatar_widget);
1778 update_send_codec (EmpathyCallWindow *self,
1781 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1788 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1789 widget = priv->acodec_encoding_label;
1793 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1794 widget = priv->vcodec_encoding_label;
1800 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1801 gtk_label_set_text (GTK_LABEL (widget), tmp);
1806 send_audio_codec_notify_cb (GObject *object,
1810 EmpathyCallWindow *self = user_data;
1812 update_send_codec (self, TRUE);
1816 send_video_codec_notify_cb (GObject *object,
1820 EmpathyCallWindow *self = user_data;
1822 update_send_codec (self, FALSE);
1826 update_recv_codec (EmpathyCallWindow *self,
1829 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1832 GString *str = NULL;
1836 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1837 widget = priv->acodec_decoding_label;
1841 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1842 widget = priv->vcodec_decoding_label;
1848 for (l = codecs; l != NULL; l = g_list_next (l))
1850 FsCodec *codec = l->data;
1853 str = g_string_new (NULL);
1855 g_string_append (str, ", ");
1857 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1861 gtk_label_set_text (GTK_LABEL (widget), str->str);
1862 g_string_free (str, TRUE);
1866 recv_audio_codecs_notify_cb (GObject *object,
1870 EmpathyCallWindow *self = user_data;
1872 update_recv_codec (self, TRUE);
1876 recv_video_codecs_notify_cb (GObject *object,
1880 EmpathyCallWindow *self = user_data;
1882 update_recv_codec (self, FALSE);
1885 static const gchar *
1886 candidate_type_to_str (FsCandidate *candidate)
1888 switch (candidate->type)
1890 case FS_CANDIDATE_TYPE_HOST:
1892 case FS_CANDIDATE_TYPE_SRFLX:
1893 return "server reflexive";
1894 case FS_CANDIDATE_TYPE_PRFLX:
1895 return "peer reflexive";
1896 case FS_CANDIDATE_TYPE_RELAY:
1898 case FS_CANDIDATE_TYPE_MULTICAST:
1905 static const gchar *
1906 candidate_type_to_desc (FsCandidate *candidate)
1908 switch (candidate->type)
1910 case FS_CANDIDATE_TYPE_HOST:
1911 return _("The IP address as seen by the machine");
1912 case FS_CANDIDATE_TYPE_SRFLX:
1913 return _("The IP address as seen by a server on the Internet");
1914 case FS_CANDIDATE_TYPE_PRFLX:
1915 return _("The IP address of the peer as seen by the other side");
1916 case FS_CANDIDATE_TYPE_RELAY:
1917 return _("The IP address of a relay server");
1918 case FS_CANDIDATE_TYPE_MULTICAST:
1919 return _("The IP address of the multicast group");
1926 update_candidat_widget (EmpathyCallWindow *self,
1929 FsCandidate *candidate)
1933 g_assert (candidate != NULL);
1934 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1935 candidate->port, candidate_type_to_str (candidate));
1937 gtk_label_set_text (GTK_LABEL (label), str);
1938 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1944 candidates_changed_cb (GObject *object,
1946 EmpathyCallWindow *self)
1948 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1949 FsCandidate *candidate = NULL;
1951 if (type == FS_MEDIA_TYPE_VIDEO)
1953 /* Update remote candidate */
1954 candidate = empathy_call_handler_get_video_remote_candidate (
1957 update_candidat_widget (self, priv->video_remote_candidate_label,
1958 priv->video_remote_candidate_info_img, candidate);
1960 /* Update local candidate */
1961 candidate = empathy_call_handler_get_video_local_candidate (
1964 update_candidat_widget (self, priv->video_local_candidate_label,
1965 priv->video_local_candidate_info_img, candidate);
1969 /* Update remote candidate */
1970 candidate = empathy_call_handler_get_audio_remote_candidate (
1973 update_candidat_widget (self, priv->audio_remote_candidate_label,
1974 priv->audio_remote_candidate_info_img, candidate);
1976 /* Update local candidate */
1977 candidate = empathy_call_handler_get_audio_local_candidate (
1980 update_candidat_widget (self, priv->audio_local_candidate_label,
1981 priv->audio_local_candidate_info_img, candidate);
1986 empathy_call_window_constructed (GObject *object)
1988 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1989 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1990 TpyCallChannel *call;
1992 g_assert (priv->handler != NULL);
1994 g_object_get (priv->handler, "call-channel", &call, NULL);
1995 priv->outgoing = (call == NULL);
1997 g_object_unref (call);
1999 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2000 g_assert (priv->contact != NULL);
2002 empathy_call_window_setup_avatars (self, priv->handler);
2003 empathy_call_window_set_state_connecting (self);
2005 if (!empathy_call_handler_has_initial_video (priv->handler))
2007 gtk_toggle_tool_button_set_active (
2008 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2010 /* If call has InitialVideo, the preview will be started once the call has
2011 * been started (start_call()). */
2013 update_send_codec (self, TRUE);
2014 update_send_codec (self, FALSE);
2015 update_recv_codec (self, TRUE);
2016 update_recv_codec (self, FALSE);
2018 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2019 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2020 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2021 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2022 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2023 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2024 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2025 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2027 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2028 G_CALLBACK (candidates_changed_cb), self, 0);
2031 static void empathy_call_window_dispose (GObject *object);
2032 static void empathy_call_window_finalize (GObject *object);
2035 empathy_call_window_set_property (GObject *object,
2036 guint property_id, const GValue *value, GParamSpec *pspec)
2038 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2040 switch (property_id)
2042 case PROP_CALL_HANDLER:
2043 priv->handler = g_value_dup_object (value);
2046 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2051 empathy_call_window_get_property (GObject *object,
2052 guint property_id, GValue *value, GParamSpec *pspec)
2054 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2056 switch (property_id)
2058 case PROP_CALL_HANDLER:
2059 g_value_set_object (value, priv->handler);
2062 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2067 empathy_call_window_class_init (
2068 EmpathyCallWindowClass *empathy_call_window_class)
2070 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2071 GParamSpec *param_spec;
2073 g_type_class_add_private (empathy_call_window_class,
2074 sizeof (EmpathyCallWindowPriv));
2076 object_class->constructed = empathy_call_window_constructed;
2077 object_class->set_property = empathy_call_window_set_property;
2078 object_class->get_property = empathy_call_window_get_property;
2080 object_class->dispose = empathy_call_window_dispose;
2081 object_class->finalize = empathy_call_window_finalize;
2083 param_spec = g_param_spec_object ("handler",
2084 "handler", "The call handler",
2085 EMPATHY_TYPE_CALL_HANDLER,
2086 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2087 g_object_class_install_property (object_class,
2088 PROP_CALL_HANDLER, param_spec);
2092 empathy_call_window_dispose (GObject *object)
2094 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2095 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2097 if (priv->dispose_has_run)
2100 priv->dispose_has_run = TRUE;
2102 if (priv->handler != NULL)
2104 empathy_call_handler_stop_call (priv->handler);
2105 tp_clear_object (&priv->handler);
2108 if (priv->bus_message_source_id != 0)
2110 g_source_remove (priv->bus_message_source_id);
2111 priv->bus_message_source_id = 0;
2114 if (priv->got_video_src > 0)
2116 g_source_remove (priv->got_video_src);
2117 priv->got_video_src = 0;
2120 if (priv->inactivity_src > 0)
2122 g_source_remove (priv->inactivity_src);
2123 priv->inactivity_src = 0;
2126 tp_clear_object (&priv->pipeline);
2127 tp_clear_object (&priv->video_input);
2128 tp_clear_object (&priv->audio_input);
2129 tp_clear_object (&priv->video_tee);
2130 tp_clear_object (&priv->ui_manager);
2131 tp_clear_object (&priv->fullscreen);
2132 tp_clear_object (&priv->camera_monitor);
2133 tp_clear_object (&priv->settings);
2134 tp_clear_object (&priv->sound_mgr);
2135 tp_clear_object (&priv->mic_menu);
2136 tp_clear_object (&priv->camera_menu);
2138 g_list_free_full (priv->notifiers, g_object_unref);
2140 if (priv->timer_id != 0)
2141 g_source_remove (priv->timer_id);
2144 if (priv->contact != NULL)
2146 g_signal_handlers_disconnect_by_func (priv->contact,
2147 contact_name_changed_cb, self);
2148 priv->contact = NULL;
2151 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2155 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2157 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2159 if (priv->video_output_motion_handler_id != 0)
2161 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2162 priv->video_output_motion_handler_id);
2163 priv->video_output_motion_handler_id = 0;
2168 empathy_call_window_finalize (GObject *object)
2170 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2171 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2173 disconnect_video_output_motion_handler (self);
2175 /* free any data held directly by the object here */
2176 g_mutex_free (priv->lock);
2178 g_timer_destroy (priv->timer);
2180 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2185 empathy_call_window_new (EmpathyCallHandler *handler)
2187 return EMPATHY_CALL_WINDOW (
2188 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2192 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2193 GstElement *conference, gpointer user_data)
2195 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2196 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2197 FsElementAddedNotifier *notifier;
2200 DEBUG ("Conference added");
2202 /* Add notifier to set the various element properties as needed */
2203 notifier = fs_element_added_notifier_new ();
2204 keyfile = fs_utils_get_default_element_properties (conference);
2206 if (keyfile != NULL)
2207 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2209 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2211 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2213 gst_bin_add (GST_BIN (priv->pipeline), conference);
2214 gst_element_set_state (conference, GST_STATE_PLAYING);
2218 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2219 GstElement *conference, gpointer user_data)
2221 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2222 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2224 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2225 gst_element_set_state (conference, GST_STATE_NULL);
2229 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2231 GstStateChangeReturn state_change_return;
2232 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2234 if (priv->pipeline == NULL)
2237 if (priv->bus_message_source_id != 0)
2239 g_source_remove (priv->bus_message_source_id);
2240 priv->bus_message_source_id = 0;
2243 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2245 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2246 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2248 if (priv->pipeline != NULL)
2249 g_object_unref (priv->pipeline);
2250 priv->pipeline = NULL;
2252 if (priv->audio_output != NULL)
2253 g_object_unref (priv->audio_output);
2254 priv->audio_output = NULL;
2256 if (priv->video_tee != NULL)
2257 g_object_unref (priv->video_tee);
2258 priv->video_tee = NULL;
2260 if (priv->video_preview != NULL)
2261 clutter_actor_destroy (priv->video_preview);
2262 priv->video_preview = NULL;
2264 priv->funnel = NULL;
2266 create_pipeline (self);
2267 /* Call will be started when user will hit the 'redial' button */
2268 priv->start_call_when_playing = FALSE;
2269 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2275 g_message ("Error: could not destroy pipeline. Closing call window");
2276 gtk_widget_destroy (GTK_WIDGET (self));
2283 reset_details_pane (EmpathyCallWindow *self)
2285 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2287 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2288 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2289 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2290 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2294 empathy_call_window_disconnected (EmpathyCallWindow *self,
2297 gboolean could_disconnect = FALSE;
2298 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2299 gboolean could_reset_pipeline;
2301 /* Leave full screen mode if needed */
2302 gtk_window_unfullscreen (GTK_WINDOW (self));
2304 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2305 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2307 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2309 if (priv->call_state == CONNECTING)
2310 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2312 if (priv->call_state != REDIALING)
2313 priv->call_state = DISCONNECTED;
2315 /* Show the toolbar */
2316 clutter_state_set_state (priv->transitions, "fade-in");
2318 if (could_reset_pipeline)
2320 g_mutex_lock (priv->lock);
2322 g_timer_stop (priv->timer);
2324 if (priv->timer_id != 0)
2325 g_source_remove (priv->timer_id);
2328 g_mutex_unlock (priv->lock);
2331 /* We are about to destroy the window, no need to update it or create
2332 * a video preview */
2335 empathy_call_window_status_message (self, _("Disconnected"));
2337 empathy_call_window_show_hangup_button (self, FALSE);
2339 /* Unsensitive the camera and mic button */
2340 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2341 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2343 /* Be sure that the mic button is enabled */
2344 gtk_toggle_tool_button_set_active (
2345 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2347 if (priv->camera_state == CAMERA_STATE_ON)
2349 /* Restart the preview with the new pipeline. */
2350 display_video_preview (self, TRUE);
2353 /* destroy the video output; it will be recreated when we'll redial */
2354 disconnect_video_output_motion_handler (self);
2355 if (priv->video_output != NULL)
2356 clutter_actor_destroy (priv->video_output);
2357 priv->video_output = NULL;
2358 if (priv->got_video_src > 0)
2360 g_source_remove (priv->got_video_src);
2361 priv->got_video_src = 0;
2364 gtk_widget_show (priv->remote_user_avatar_widget);
2366 reset_details_pane (self);
2368 priv->sending_video = FALSE;
2369 priv->call_started = FALSE;
2371 could_disconnect = TRUE;
2373 /* TODO: display the self avatar of the preview (depends if the "Always
2374 * Show Video Preview" is enabled or not) */
2377 return could_disconnect;
2382 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2385 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2386 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2388 if (empathy_call_window_disconnected (self, TRUE) &&
2389 priv->call_state == REDIALING)
2390 empathy_call_window_restart_call (self);
2394 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2396 FsMediaType media_type,
2397 EmpathyCallWindow *self)
2399 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2401 DEBUG ("removing content");
2404 * This assumes that there is only one video stream per channel...
2407 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2409 if (priv->funnel != NULL)
2413 output = priv->video_output_sink;
2415 gst_element_set_state (output, GST_STATE_NULL);
2416 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2418 gst_bin_remove (GST_BIN (priv->pipeline), output);
2419 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2420 priv->funnel = NULL;
2424 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2426 if (priv->audio_output != NULL)
2428 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2430 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2431 priv->audio_output = NULL;
2439 /* Called with global lock held */
2441 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2443 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2447 if (priv->funnel == NULL)
2449 output = priv->video_output_sink;
2451 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2455 g_warning ("Could not create fsfunnel");
2459 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2461 gst_object_unref (priv->funnel);
2462 priv->funnel = NULL;
2463 g_warning ("Could not add funnel to pipeline");
2467 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2469 g_warning ("Could not add the video output widget to the pipeline");
2473 if (!gst_element_link (priv->funnel, output))
2475 g_warning ("Could not link output sink to funnel");
2476 goto error_output_added;
2479 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2481 g_warning ("Could not start video sink");
2482 goto error_output_added;
2485 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2487 g_warning ("Could not start funnel");
2488 goto error_output_added;
2492 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2495 g_warning ("Could not get request pad from funnel");
2502 gst_element_set_locked_state (priv->funnel, TRUE);
2503 gst_element_set_locked_state (output, TRUE);
2505 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2506 gst_element_set_state (output, GST_STATE_NULL);
2508 gst_bin_remove (GST_BIN (priv->pipeline), output);
2509 gst_element_set_locked_state (output, FALSE);
2513 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2514 priv->funnel = NULL;
2519 /* Called with global lock held */
2521 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2523 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2525 GstPadTemplate *template;
2527 if (priv->audio_output == NULL)
2529 priv->audio_output = empathy_audio_sink_new ();
2530 g_object_ref_sink (priv->audio_output);
2532 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2534 g_warning ("Could not add audio sink to pipeline");
2535 g_object_unref (priv->audio_output);
2536 goto error_add_output;
2539 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2541 g_warning ("Could not start audio sink");
2546 template = gst_element_class_get_pad_template (
2547 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2549 pad = gst_element_request_pad (priv->audio_output,
2550 template, NULL, NULL);
2554 g_warning ("Could not get sink pad from sink");
2561 gst_element_set_locked_state (priv->audio_output, TRUE);
2562 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2563 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2564 priv->audio_output = NULL;
2572 empathy_call_window_update_timer (gpointer user_data)
2574 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2575 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2576 const gchar *status;
2580 time_ = g_timer_elapsed (priv->timer, NULL);
2582 if (priv->call_state == HELD)
2583 status = _("On hold");
2584 else if (!gtk_toggle_tool_button_get_active (
2585 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2588 status = _("Duration");
2590 /* Translators: 'status - minutes:seconds' the caller has been connected */
2591 str = g_strdup_printf (_("%s — %d:%02dm"),
2593 (int) time_ / 60, (int) time_ % 60);
2594 empathy_call_window_status_message (self, str);
2602 display_error (EmpathyCallWindow *self,
2603 TpyCallChannel *call,
2607 const gchar *details)
2609 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2610 GtkWidget *info_bar;
2611 GtkWidget *content_area;
2618 /* Create info bar */
2619 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2622 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2624 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2626 /* hbox containing the image and the messages vbox */
2627 hbox = gtk_hbox_new (FALSE, 3);
2628 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2631 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2632 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2634 /* vbox containing the main message and the details expander */
2635 vbox = gtk_vbox_new (FALSE, 3);
2636 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2639 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2641 label = gtk_label_new (NULL);
2642 gtk_label_set_markup (GTK_LABEL (label), txt);
2643 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2644 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2647 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2650 if (details != NULL)
2652 GtkWidget *expander;
2654 expander = gtk_expander_new (_("Technical Details"));
2656 txt = g_strdup_printf ("<i>%s</i>", details);
2658 label = gtk_label_new (NULL);
2659 gtk_label_set_markup (GTK_LABEL (label), txt);
2660 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2661 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2664 gtk_container_add (GTK_CONTAINER (expander), label);
2665 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2668 g_signal_connect (info_bar, "response",
2669 G_CALLBACK (gtk_widget_destroy), NULL);
2671 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2672 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2673 gtk_widget_show_all (info_bar);
2677 media_stream_error_to_txt (EmpathyCallWindow *self,
2678 TpyCallChannel *call,
2680 TpMediaStreamError error)
2682 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2683 const gchar *cm = NULL;
2689 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2691 return g_strdup_printf (
2692 _("%s's software does not understand any of the audio formats "
2693 "supported by your computer"),
2694 empathy_contact_get_alias (priv->contact));
2696 return g_strdup_printf (
2697 _("%s's software does not understand any of the video formats "
2698 "supported by your computer"),
2699 empathy_contact_get_alias (priv->contact));
2701 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2702 return g_strdup_printf (
2703 _("Can't establish a connection to %s. "
2704 "One of you might be on a network that does not allow "
2705 "direct connections."),
2706 empathy_contact_get_alias (priv->contact));
2708 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2709 return g_strdup (_("There was a failure on the network"));
2711 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2713 return g_strdup (_("The audio formats necessary for this call "
2714 "are not installed on your computer"));
2716 return g_strdup (_("The video formats necessary for this call "
2717 "are not installed on your computer"));
2719 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2720 tp_connection_parse_object_path (
2721 tp_channel_borrow_connection (TP_CHANNEL (call)),
2724 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2725 "product=Telepathy&component=%s", cm);
2727 result = g_strdup_printf (
2728 _("Something unexpected happened in a Telepathy component. "
2729 "Please <a href=\"%s\">report this bug</a> and attach "
2730 "logs gathered from the 'Debug' window in the Help menu."), url);
2736 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2737 return g_strdup (_("There was a failure in the call engine"));
2739 case TP_MEDIA_STREAM_ERROR_EOS:
2740 return g_strdup (_("The end of the stream was reached"));
2742 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2749 empathy_call_window_stream_error (EmpathyCallWindow *self,
2750 TpyCallChannel *call,
2759 desc = media_stream_error_to_txt (self, call, audio, code);
2762 /* No description, use the error message. That's not great as it's not
2763 * localized but it's better than nothing. */
2764 display_error (self, call, icon, title, msg, NULL);
2768 display_error (self, call, icon, title, desc, msg);
2774 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2777 EmpathyCallWindow *self)
2779 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2780 "gnome-stock-mic", _("Can't establish audio stream"));
2784 empathy_call_window_video_stream_error (TpyCallChannel *call,
2787 EmpathyCallWindow *self)
2789 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2790 "camera-web", _("Can't establish video stream"));
2795 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2797 EmpathyCallWindow *self)
2799 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2800 TpyCallChannel *call;
2801 gboolean can_send_video;
2803 if (state != TPY_CALL_STATE_ACCEPTED)
2806 if (priv->call_state == CONNECTED)
2809 g_timer_start (priv->timer);
2810 priv->call_state = CONNECTED;
2812 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2814 can_send_video = priv->video_input != NULL &&
2815 empathy_contact_can_voip_video (priv->contact) &&
2816 empathy_camera_monitor_get_available (priv->camera_monitor);
2818 g_object_get (priv->handler, "call-channel", &call, NULL);
2820 if (tpy_call_channel_has_dtmf (call))
2821 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2823 if (priv->video_input == NULL)
2824 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2826 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2828 empathy_call_window_show_hangup_button (self, TRUE);
2830 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2832 clutter_actor_hide (priv->video_output);
2833 gtk_widget_show (priv->remote_user_avatar_widget);
2835 g_object_unref (call);
2837 g_mutex_lock (priv->lock);
2839 priv->timer_id = g_timeout_add_seconds (1,
2840 empathy_call_window_update_timer, self);
2842 g_mutex_unlock (priv->lock);
2844 empathy_call_window_update_timer (self);
2846 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2850 empathy_call_window_show_video_output_cb (gpointer user_data)
2852 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2854 if (self->priv->video_output != NULL)
2856 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2857 clutter_actor_show (self->priv->video_output);
2858 empathy_call_window_raise_actors (self);
2865 empathy_call_window_check_video_cb (gpointer data)
2867 EmpathyCallWindow *self = data;
2869 if (self->priv->got_video)
2871 self->priv->got_video = FALSE;
2875 /* No video in the last N seconds, display the remote avatar */
2876 empathy_call_window_show_video_output (self, FALSE);
2881 /* Called from the streaming thread */
2883 empathy_call_window_video_probe_cb (GstPad *pad,
2884 GstMiniObject *mini_obj,
2885 EmpathyCallWindow *self)
2888 if (GST_IS_EVENT (mini_obj))
2891 if (G_UNLIKELY (!self->priv->got_video))
2893 /* show the remote video */
2894 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2895 empathy_call_window_show_video_output_cb,
2896 g_object_ref (self), g_object_unref);
2898 self->priv->got_video = TRUE;
2904 /* Called from the streaming thread */
2906 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2907 GstPad *src, guint media_type, gpointer user_data)
2909 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2910 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2911 gboolean retval = FALSE;
2915 g_mutex_lock (priv->lock);
2919 case TP_MEDIA_STREAM_TYPE_AUDIO:
2920 pad = empathy_call_window_get_audio_sink_pad (self);
2922 case TP_MEDIA_STREAM_TYPE_VIDEO:
2923 g_idle_add (empathy_call_window_show_video_output_cb, self);
2924 pad = empathy_call_window_get_video_sink_pad (self);
2926 gst_pad_add_data_probe (src,
2927 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2928 if (priv->got_video_src > 0)
2929 g_source_remove (priv->got_video_src);
2930 priv->got_video_src = g_timeout_add_seconds (5,
2931 empathy_call_window_check_video_cb, self);
2934 g_assert_not_reached ();
2940 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2941 g_warning ("Could not link %s sink pad",
2942 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2946 gst_object_unref (pad);
2950 /* If no sink could be linked, try to add fakesink to prevent the whole call
2955 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2957 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2959 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2960 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2961 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2963 gst_element_set_locked_state (fakesink, TRUE);
2964 gst_element_set_state (fakesink, GST_STATE_NULL);
2965 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2969 DEBUG ("Could not link real sink, linked fakesink instead");
2971 gst_object_unref (sinkpad);
2975 gst_object_unref (fakesink);
2980 g_mutex_unlock (priv->lock);
2986 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2987 GstPad *sink, FsMediaType media_type, gpointer user_data)
2989 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2990 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2992 gboolean retval = FALSE;
2996 case FS_MEDIA_TYPE_AUDIO:
2997 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2999 g_warning ("Could not add audio source to pipeline");
3003 pad = gst_element_get_static_pad (priv->audio_input, "src");
3006 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3007 g_warning ("Could not get source pad from audio source");
3011 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3013 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3014 g_warning ("Could not link audio source to farsight");
3018 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3020 g_warning ("Could not start audio source");
3021 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3022 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3028 case FS_MEDIA_TYPE_VIDEO:
3029 if (priv->video_tee != NULL)
3031 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3032 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3034 g_warning ("Could not link video source input pipeline");
3037 gst_object_unref (pad);
3043 g_assert_not_reached ();
3050 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3052 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3053 GstElement *preview;
3055 disable_camera (self);
3057 DEBUG ("remove video input");
3058 preview = priv->video_preview_sink;
3060 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3061 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3062 gst_element_set_state (preview, GST_STATE_NULL);
3064 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3067 g_object_unref (priv->video_input);
3068 priv->video_input = NULL;
3069 g_object_unref (priv->video_tee);
3070 priv->video_tee = NULL;
3071 clutter_actor_destroy (priv->video_preview);
3072 priv->video_preview = NULL;
3074 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3078 start_call (EmpathyCallWindow *self)
3080 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3082 priv->call_started = TRUE;
3083 empathy_call_handler_start_call (priv->handler,
3084 gtk_get_current_event_time ());
3086 if (empathy_call_handler_has_initial_video (priv->handler))
3088 TpyCallChannel *call;
3091 g_object_get (priv->handler, "call-channel", &call, NULL);
3092 s = tpy_call_channel_get_video_state (call);
3094 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3095 s == TPY_SENDING_STATE_SENDING)
3097 /* Enable 'send video' buttons and display the preview */
3098 gtk_toggle_tool_button_set_active (
3099 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3103 gtk_toggle_tool_button_set_active (
3104 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3106 if (priv->video_preview == NULL)
3108 create_video_preview (self);
3109 add_video_preview_to_pipeline (self);
3113 g_object_unref (call);
3118 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3121 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3122 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3125 empathy_call_handler_bus_message (priv->handler, bus, message);
3127 switch (GST_MESSAGE_TYPE (message))
3129 case GST_MESSAGE_STATE_CHANGED:
3130 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3132 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3134 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3135 !priv->call_started)
3137 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3138 if (newstate == GST_STATE_PAUSED)
3140 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3141 priv->pipeline_playing = TRUE;
3143 if (priv->start_call_when_playing)
3148 case GST_MESSAGE_ERROR:
3150 GError *error = NULL;
3151 GstElement *gst_error;
3154 gst_message_parse_error (message, &error, &debug);
3155 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3157 g_message ("Element error: %s -- %s\n", error->message, debug);
3159 if (g_str_has_prefix (gst_element_get_name (gst_error),
3160 VIDEO_INPUT_ERROR_PREFIX))
3162 /* Remove the video input and continue */
3163 if (priv->video_input != NULL)
3164 empathy_call_window_remove_video_input (self);
3165 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3169 empathy_call_window_disconnected (self, TRUE);
3171 g_error_free (error);
3174 case GST_MESSAGE_UNKNOWN:
3175 case GST_MESSAGE_EOS:
3176 case GST_MESSAGE_WARNING:
3177 case GST_MESSAGE_INFO:
3178 case GST_MESSAGE_TAG:
3179 case GST_MESSAGE_BUFFERING:
3180 case GST_MESSAGE_STATE_DIRTY:
3181 case GST_MESSAGE_STEP_DONE:
3182 case GST_MESSAGE_CLOCK_PROVIDE:
3183 case GST_MESSAGE_CLOCK_LOST:
3184 case GST_MESSAGE_NEW_CLOCK:
3185 case GST_MESSAGE_STRUCTURE_CHANGE:
3186 case GST_MESSAGE_STREAM_STATUS:
3187 case GST_MESSAGE_APPLICATION:
3188 case GST_MESSAGE_ELEMENT:
3189 case GST_MESSAGE_SEGMENT_START:
3190 case GST_MESSAGE_SEGMENT_DONE:
3191 case GST_MESSAGE_DURATION:
3192 case GST_MESSAGE_ANY:
3201 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3202 GHashTable *members,
3203 EmpathyCallWindow *self)
3205 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3206 GHashTableIter iter;
3207 gpointer key, value;
3208 gboolean held = FALSE;
3210 g_hash_table_iter_init (&iter, members);
3211 while (g_hash_table_iter_next (&iter, &key, &value))
3213 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3215 /* This assumes this is a 1-1 call, otherwise one participant
3216 * putting the call on hold wouldn't mean the call is on hold
3224 priv->call_state = HELD;
3225 else if (priv->call_state == HELD)
3226 priv->call_state = CONNECTED;
3230 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3232 EmpathyCallWindow *self)
3234 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3235 TpyCallChannel *call;
3237 g_object_get (priv->handler, "call-channel", &call, NULL);
3242 tp_g_signal_connect_object (call, "audio-stream-error",
3243 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3244 tp_g_signal_connect_object (call, "video-stream-error",
3245 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3248 tp_g_signal_connect_object (call, "members-changed",
3249 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3251 g_object_unref (call);
3255 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
3257 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3258 TpyCallChannel *call;
3261 /* Make the hangup button twice as wide */
3262 width = gtk_widget_get_allocated_width (priv->hangup_button);
3263 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
3265 g_signal_connect (priv->handler, "state-changed",
3266 G_CALLBACK (empathy_call_window_state_changed_cb), window);
3267 g_signal_connect (priv->handler, "conference-added",
3268 G_CALLBACK (empathy_call_window_conference_added_cb), window);
3269 g_signal_connect (priv->handler, "conference-removed",
3270 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
3271 g_signal_connect (priv->handler, "closed",
3272 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
3273 g_signal_connect (priv->handler, "src-pad-added",
3274 G_CALLBACK (empathy_call_window_src_added_cb), window);
3275 g_signal_connect (priv->handler, "sink-pad-added",
3276 G_CALLBACK (empathy_call_window_sink_added_cb), window);
3277 g_signal_connect (priv->handler, "sink-pad-removed",
3278 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
3280 g_object_get (priv->handler, "call-channel", &call, NULL);
3283 call_handler_notify_call_cb (priv->handler, NULL, window);
3284 g_object_unref (call);
3288 /* call-channel doesn't exist yet, we'll connect signals once it has been
3290 g_signal_connect (priv->handler, "notify::call-channel",
3291 G_CALLBACK (call_handler_notify_call_cb), window);
3294 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
3298 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3299 EmpathyCallWindow *window)
3301 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3303 if (priv->pipeline != NULL)
3305 if (priv->bus_message_source_id != 0)
3307 g_source_remove (priv->bus_message_source_id);
3308 priv->bus_message_source_id = 0;
3311 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3314 if (priv->call_state == CONNECTING)
3315 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3321 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3324 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3326 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3331 gtk_widget_hide (priv->dtmf_panel);
3332 gtk_widget_hide (menu);
3333 gtk_widget_hide (priv->toolbar);
3337 if (priv->dialpad_was_visible_before_fs)
3338 gtk_widget_show (priv->dtmf_panel);
3340 gtk_widget_show (menu);
3341 gtk_widget_show (priv->toolbar);
3343 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3344 priv->original_height_before_fs);
3349 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3351 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3353 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3354 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3355 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3356 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3358 if (priv->video_output != NULL)
3361 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3362 priv->video_output, TRUE, TRUE,
3363 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3370 empathy_call_window_state_event_cb (GtkWidget *widget,
3371 GdkEventWindowState *event, EmpathyCallWindow *window)
3373 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3375 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3376 gboolean set_fullscreen = event->new_window_state &
3377 GDK_WINDOW_STATE_FULLSCREEN;
3381 gboolean dialpad_was_visible;
3382 GtkAllocation allocation;
3383 gint original_width, original_height;
3385 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3386 original_width = allocation.width;
3387 original_height = allocation.height;
3389 g_object_get (priv->dtmf_panel,
3390 "visible", &dialpad_was_visible,
3393 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3394 priv->original_width_before_fs = original_width;
3395 priv->original_height_before_fs = original_height;
3397 if (priv->video_output_motion_handler_id == 0 &&
3398 priv->video_output != NULL)
3400 priv->video_output_motion_handler_id = g_signal_connect (
3401 G_OBJECT (priv->video_container), "motion-notify-event",
3402 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3408 disconnect_video_output_motion_handler (window);
3411 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3413 show_controls (window, set_fullscreen);
3414 show_borders (window, set_fullscreen);
3415 gtk_action_set_stock_id (priv->menu_fullscreen,
3416 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3417 priv->is_fullscreen = set_fullscreen;
3424 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3427 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3428 int w, h, dialpad_width;
3429 GtkAllocation allocation;
3431 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3432 w = allocation.width;
3433 h = allocation.height;
3435 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3439 gtk_widget_show (priv->dtmf_panel);
3445 gtk_widget_hide (priv->dtmf_panel);
3449 gtk_window_resize (GTK_WINDOW (window), w, h);
3453 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3456 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3457 TpyCallChannel *call;
3459 priv->sending_video = (state == CAMERA_STATE_ON);
3461 if (state == CAMERA_STATE_ON)
3463 /* When we start sending video, we want to show the video preview by
3465 display_video_preview (window, TRUE);
3469 display_video_preview (window, FALSE);
3472 if (priv->call_state != CONNECTED)
3475 g_object_get (priv->handler, "call-channel", &call, NULL);
3476 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3477 tpy_call_channel_send_video (call, priv->sending_video);
3478 g_object_unref (call);
3482 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3483 EmpathyCallWindow *self)
3485 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3488 active = (gtk_toggle_tool_button_get_active (toggle));
3490 /* We don't want the settings callback to react to this change to avoid
3492 g_signal_handlers_block_by_func (priv->settings,
3493 empathy_call_window_prefs_volume_changed_cb, self);
3497 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3498 priv->volume * 100);
3502 /* TODO, Instead of setting the input volume to 0 we should probably
3503 * stop sending but this would cause the audio call to drop if both
3504 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3505 * in the future. GNOME #574574
3507 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3511 g_signal_handlers_unblock_by_func (priv->settings,
3512 empathy_call_window_prefs_volume_changed_cb, self);
3516 empathy_call_window_hangup_cb (gpointer object,
3517 EmpathyCallWindow *self)
3519 empathy_call_handler_stop_call (self->priv->handler);
3521 empathy_call_window_disconnected (self, TRUE);
3525 empathy_call_window_restart_call (EmpathyCallWindow *window)
3527 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3529 /* Remove error info bars */
3530 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3531 (GtkCallback) gtk_widget_destroy, NULL);
3533 create_video_output_widget (window);
3535 /* While the call was disconnected, the input volume might have changed.
3536 * However, since the audio_input source was destroyed, its volume has not
3537 * been updated during that time. That's why we manually update it here */
3538 empathy_call_window_mic_volume_changed (window);
3540 priv->outgoing = TRUE;
3541 empathy_call_window_set_state_connecting (window);
3543 if (priv->pipeline_playing)
3544 start_call (window);
3546 /* call will be started when the pipeline is ready */
3547 priv->start_call_when_playing = TRUE;
3549 empathy_call_window_setup_avatars (window, priv->handler);
3551 empathy_call_window_show_hangup_button (window, TRUE);
3555 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3556 EmpathyCallWindow *window)
3560 active = gtk_toggle_tool_button_get_active (button);
3562 empathy_call_window_show_dialpad (window, active);
3566 empathy_call_window_fullscreen_cb (gpointer object,
3567 EmpathyCallWindow *window)
3569 empathy_call_window_fullscreen_toggle (window);
3573 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3575 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3577 if (priv->is_fullscreen)
3578 gtk_window_unfullscreen (GTK_WINDOW (window));
3580 gtk_window_fullscreen (GTK_WINDOW (window));
3584 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3585 GdkEventButton *event, EmpathyCallWindow *window)
3587 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3589 empathy_call_window_video_menu_popup (window, event->button);
3597 empathy_call_window_key_press_cb (GtkWidget *video_output,
3598 GdkEventKey *event, EmpathyCallWindow *window)
3600 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3602 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3604 /* Since we are in fullscreen mode, toggling will bring us back to
3606 empathy_call_window_fullscreen_toggle (window);
3614 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3615 GdkEventMotion *event, EmpathyCallWindow *window)
3617 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3619 if (priv->is_fullscreen)
3621 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3623 /* Show the bottom toolbar */
3624 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3631 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3635 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3637 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3639 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3640 button, gtk_get_current_event_time ());
3641 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3645 empathy_call_window_status_message (EmpathyCallWindow *self,
3648 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3652 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3653 gdouble value, EmpathyCallWindow *window)
3655 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3657 if (priv->audio_output == NULL)
3660 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3665 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3667 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3669 return priv->ui_manager;
3672 EmpathyGstAudioSrc *
3673 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3675 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3677 return (EmpathyGstAudioSrc *) priv->audio_input;
3680 EmpathyGstVideoSrc *
3681 empathy_call_window_get_video_src (EmpathyCallWindow *self)
3683 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);