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"
68 #define CONTENT_HBOX_BORDER_WIDTH 6
69 #define CONTENT_HBOX_SPACING 3
70 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
72 #define SELF_VIDEO_SECTION_WIDTH 120
73 #define SELF_VIDEO_SECTION_HEIGTH 90
75 #define FLOATING_TOOLBAR_OPACITY 192
76 #define FLOATING_TOOLBAR_WIDTH 280
77 #define FLOATING_TOOLBAR_HEIGHT 36
78 #define FLOATING_TOOLBAR_SPACING 20
80 /* The avatar's default width and height are set to the same value because we
81 want a square icon. */
82 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
83 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
84 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
86 #define SMALL_TOOLBAR_SIZE 36
88 /* If an video input error occurs, the error message will start with "v4l" */
89 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
91 /* The time interval in milliseconds between 2 outgoing rings */
92 #define MS_BETWEEN_RING 500
94 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
97 PROP_CALL_HANDLER = 1,
109 CAMERA_STATE_OFF = 0,
113 struct _EmpathyCallWindowPriv
115 gboolean dispose_has_run;
116 EmpathyCallHandler *handler;
118 EmpathyContact *contact;
120 EmpathyCameraMonitor *camera_monitor;
125 GtkUIManager *ui_manager;
126 GtkWidget *errors_vbox;
127 /* widget displays the video received from the remote user. This widget is
128 * alive only during call. */
129 ClutterActor *video_output;
130 ClutterActor *video_preview;
131 ClutterActor *preview_hidden_button;
132 GtkWidget *video_container;
133 GtkWidget *remote_user_avatar_widget;
134 GtkWidget *remote_user_avatar_toolbar;
135 GtkWidget *remote_user_name_toolbar;
136 GtkWidget *status_label;
137 GtkWidget *hangup_button;
138 GtkWidget *audio_call_button;
139 GtkWidget *video_call_button;
140 GtkWidget *mic_button;
141 GtkWidget *camera_button;
142 GtkWidget *dialpad_button;
144 GtkWidget *bottom_toolbar;
145 ClutterActor *floating_toolbar;
147 GtkAction *menu_fullscreen;
149 /* The box that contains self and remote avatar and video
150 input/output. When we redial, we destroy and re-create the box */
151 ClutterActor *video_box;
152 ClutterLayoutManager *video_layout;
154 /* We keep a reference on the hbox which contains the main content so we can
155 easilly repack everything when toggling fullscreen */
156 GtkWidget *content_hbox;
158 gulong video_output_motion_handler_id;
159 guint bus_message_source_id;
163 GtkWidget *dtmf_panel;
166 GtkWidget *details_vbox;
167 GtkWidget *vcodec_encoding_label;
168 GtkWidget *acodec_encoding_label;
169 GtkWidget *vcodec_decoding_label;
170 GtkWidget *acodec_decoding_label;
172 GtkWidget *audio_remote_candidate_label;
173 GtkWidget *audio_local_candidate_label;
174 GtkWidget *video_remote_candidate_label;
175 GtkWidget *video_local_candidate_label;
176 GtkWidget *video_remote_candidate_info_img;
177 GtkWidget *video_local_candidate_info_img;
178 GtkWidget *audio_remote_candidate_info_img;
179 GtkWidget *audio_local_candidate_info_img;
181 GstElement *video_input;
182 GstElement *video_preview_sink;
183 GstElement *video_output_sink;
184 GstElement *audio_input;
185 GstElement *audio_output;
186 GstElement *pipeline;
187 GstElement *video_tee;
197 gboolean call_started;
198 gboolean sending_video;
199 CameraState camera_state;
201 EmpathyCallWindowFullscreen *fullscreen;
202 gboolean is_fullscreen;
207 /* Those fields represent the state of the window before it actually was in
209 gboolean dialpad_was_visible_before_fs;
210 gint original_width_before_fs;
211 gint original_height_before_fs;
213 gint x, y, w, h, dialpad_width;
216 /* TRUE if the call should be started when the pipeline is playing */
217 gboolean start_call_when_playing;
218 /* TRUE if we requested to set the pipeline in the playing state */
219 gboolean pipeline_playing;
221 EmpathySoundManager *sound_mgr;
224 EmpathyMicMenu *mic_menu;
227 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
229 static void empathy_call_window_realized_cb (GtkWidget *widget,
230 EmpathyCallWindow *window);
232 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
233 GdkEvent *event, EmpathyCallWindow *window);
235 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
236 GdkEventWindowState *event, EmpathyCallWindow *window);
238 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
241 static void empathy_call_window_mic_toggled_cb (
242 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
244 static void empathy_call_window_hangup_cb (gpointer object,
245 EmpathyCallWindow *window);
247 static void empathy_call_window_fullscreen_cb (gpointer object,
248 EmpathyCallWindow *window);
250 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
252 static gboolean empathy_call_window_video_button_press_cb (
253 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
255 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
256 GdkEventKey *event, EmpathyCallWindow *window);
258 static gboolean empathy_call_window_video_output_motion_notify (
259 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
261 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
264 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
265 EmpathyCallWindow *window);
267 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
269 static void empathy_call_window_status_message (EmpathyCallWindow *window,
272 static gboolean empathy_call_window_bus_message (GstBus *bus,
273 GstMessage *message, gpointer user_data);
276 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
277 gdouble value, EmpathyCallWindow *window);
280 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
283 gtk_widget_set_visible (self->priv->hangup_button, show);
284 gtk_widget_set_visible (self->priv->audio_call_button, !show);
285 gtk_widget_set_visible (self->priv->video_call_button, !show);
289 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
290 EmpathyCallWindow *self)
292 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
293 empathy_call_window_restart_call (self);
297 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
298 EmpathyCallWindow *self)
300 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
301 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
302 empathy_call_window_restart_call (self);
306 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
308 EmpathyCallWindowPriv *priv = GET_PRIV (window);
309 TpyCallChannel *call;
313 g_object_get (priv->handler, "call-channel", &call, NULL);
315 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
316 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
319 tpy_call_channel_dtmf_start_tone (call, event);
321 g_object_unref (call);
325 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
327 EmpathyCallWindowPriv *priv = GET_PRIV (window);
328 TpyCallChannel *call;
330 g_object_get (priv->handler, "call-channel", &call, NULL);
332 tpy_call_channel_dtmf_stop_tone (call);
334 g_object_unref (call);
338 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
340 EmpathyCallWindowPriv *priv = GET_PRIV (self);
343 volume = g_settings_get_double (priv->settings,
344 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
346 /* Don't store the volume because of muting */
347 if (volume > 0 || gtk_toggle_tool_button_get_active (
348 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
349 priv->volume = volume;
351 /* Ensure that the toggle button is active if the volume is > 0 and inactive
352 * if it's smaller than 0 */
353 if ((volume > 0) != gtk_toggle_tool_button_get_active (
354 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
355 gtk_toggle_tool_button_set_active (
356 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
358 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
363 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
365 EmpathyCallWindow *self)
367 empathy_call_window_mic_volume_changed (self);
371 empathy_call_window_show_video_output (EmpathyCallWindow *self,
374 if (self->priv->video_output != NULL)
375 g_object_set (self->priv->video_output, "visible", show, NULL);
377 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
379 clutter_actor_raise_top (self->priv->floating_toolbar);
383 create_video_output_widget (EmpathyCallWindow *self)
385 EmpathyCallWindowPriv *priv = GET_PRIV (self);
387 g_assert (priv->video_output == NULL);
388 g_assert (priv->pipeline != NULL);
390 priv->video_output = clutter_texture_new ();
392 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
395 priv->video_output_sink = clutter_gst_video_sink_new (
396 CLUTTER_TEXTURE (priv->video_output));
398 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
401 gtk_widget_add_events (priv->video_container,
402 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
403 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
404 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
408 create_video_input (EmpathyCallWindow *self)
410 EmpathyCallWindowPriv *priv = GET_PRIV (self);
412 g_assert (priv->video_input == NULL);
413 priv->video_input = empathy_video_src_new ();
414 gst_object_ref (priv->video_input);
415 gst_object_sink (priv->video_input);
419 create_audio_input (EmpathyCallWindow *self)
421 EmpathyCallWindowPriv *priv = GET_PRIV (self);
423 g_assert (priv->audio_input == NULL);
424 priv->audio_input = empathy_audio_src_new ();
425 gst_object_ref (priv->audio_input);
426 gst_object_sink (priv->audio_input);
430 add_video_preview_to_pipeline (EmpathyCallWindow *self)
432 EmpathyCallWindowPriv *priv = GET_PRIV (self);
435 g_assert (priv->video_preview != NULL);
436 g_assert (priv->pipeline != NULL);
437 g_assert (priv->video_input != NULL);
438 g_assert (priv->video_tee != NULL);
440 preview = priv->video_preview_sink;
442 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
444 g_warning ("Could not add video input to pipeline");
448 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
450 g_warning ("Could not add video preview to pipeline");
454 if (!gst_element_link (priv->video_input, priv->video_tee))
456 g_warning ("Could not link video input to video tee");
460 if (!gst_element_link (priv->video_tee, preview))
462 g_warning ("Could not link video tee to video preview");
468 empathy_call_window_disable_camera_cb (GtkAction *action,
469 EmpathyCallWindow *self)
471 clutter_actor_destroy (self->priv->preview_hidden_button);
473 gtk_toggle_tool_button_set_active (
474 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
478 empathy_call_window_minimise_camera_cb (GtkAction *action,
479 EmpathyCallWindow *self)
481 clutter_actor_hide (self->priv->video_preview);
482 clutter_actor_show (self->priv->preview_hidden_button);
486 empathy_call_window_maximise_camera_cb (GtkAction *action,
487 EmpathyCallWindow *self)
489 clutter_actor_show (self->priv->video_preview);
490 clutter_actor_hide (self->priv->preview_hidden_button);
494 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
495 EmpathyCallWindow *self)
499 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
501 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
502 0, gtk_get_current_event_time ());
503 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
507 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
508 EmpathyCallWindow *self)
512 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
513 "/preview-hidden-menu");
514 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
515 0, gtk_get_current_event_time ());
516 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
520 create_video_preview (EmpathyCallWindow *self)
522 EmpathyCallWindowPriv *priv = GET_PRIV (self);
523 ClutterLayoutManager *layout, *layout_center;
524 ClutterActor *preview;
529 g_assert (priv->video_preview == NULL);
531 preview = clutter_texture_new ();
532 clutter_actor_set_size (preview,
533 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
534 priv->video_preview_sink = clutter_gst_video_sink_new (
535 CLUTTER_TEXTURE (preview));
537 /* Flip the video preview */
538 clutter_actor_set_rotation (preview,
541 SELF_VIDEO_SECTION_WIDTH * 0.5,
545 /* Add a little offset to the video preview */
546 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
547 CLUTTER_BIN_ALIGNMENT_START);
548 priv->video_preview = clutter_box_new (layout);
549 clutter_actor_set_size (priv->video_preview,
550 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
552 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
553 CLUTTER_BIN_ALIGNMENT_CENTER);
554 box = clutter_box_new (layout_center);
555 clutter_actor_set_size (box,
556 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
558 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
559 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
561 g_object_set (priv->video_preview_sink,
566 /* Translators: this is an "Info" label. It should be as short
568 button = gtk_button_new_with_label (_("i"));
569 b = gtk_clutter_actor_new_with_contents (button);
571 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
573 CLUTTER_BIN_ALIGNMENT_END,
574 CLUTTER_BIN_ALIGNMENT_END);
576 g_signal_connect (button, "clicked",
577 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
580 /* Translators: this is an "Info" label. It should be as short
582 button = gtk_button_new_with_label (_("i"));
583 priv->preview_hidden_button =
584 gtk_clutter_actor_new_with_contents (button);
586 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
587 priv->preview_hidden_button,
588 CLUTTER_BIN_ALIGNMENT_START,
589 CLUTTER_BIN_ALIGNMENT_END);
591 clutter_actor_hide (priv->preview_hidden_button);
593 g_signal_connect (button, "clicked",
594 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
597 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
599 CLUTTER_BIN_ALIGNMENT_START,
600 CLUTTER_BIN_ALIGNMENT_END);
604 play_camera (EmpathyCallWindow *window,
607 EmpathyCallWindowPriv *priv = GET_PRIV (window);
611 if (priv->video_preview == NULL)
613 create_video_preview (window);
614 add_video_preview_to_pipeline (window);
618 state = GST_STATE_PLAYING;
620 state = GST_STATE_NULL;
622 preview = priv->video_preview_sink;
624 gst_element_set_state (preview, state);
625 gst_element_set_state (priv->video_input, state);
626 gst_element_set_state (priv->video_tee, state);
630 display_video_preview (EmpathyCallWindow *self,
633 EmpathyCallWindowPriv *priv = GET_PRIV (self);
637 /* Display the video preview */
638 DEBUG ("Show video preview");
640 play_camera (self, TRUE);
641 clutter_actor_show (priv->video_preview);
645 /* Hide the video preview */
646 DEBUG ("Hide video preview");
648 if (priv->video_preview != NULL)
650 clutter_actor_hide (priv->video_preview);
651 play_camera (self, FALSE);
657 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
659 EmpathyCallWindowPriv *priv = GET_PRIV (window);
661 empathy_call_window_status_message (window, _("Connecting…"));
662 priv->call_state = CONNECTING;
665 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
666 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
670 disable_camera (EmpathyCallWindow *self)
672 EmpathyCallWindowPriv *priv = GET_PRIV (self);
674 if (priv->camera_state == CAMERA_STATE_OFF)
677 DEBUG ("Disable camera");
679 display_video_preview (self, FALSE);
681 if (priv->camera_state == CAMERA_STATE_ON)
682 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
684 priv->camera_state = CAMERA_STATE_OFF;
688 enable_camera (EmpathyCallWindow *self)
690 EmpathyCallWindowPriv *priv = GET_PRIV (self);
692 if (priv->camera_state == CAMERA_STATE_ON)
695 if (priv->video_input == NULL)
697 DEBUG ("Can't enable camera, no input");
701 DEBUG ("Enable camera");
703 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
705 priv->camera_state = CAMERA_STATE_ON;
709 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
710 EmpathyCallWindow *self)
712 if (gtk_toggle_tool_button_get_active (toggle))
713 enable_camera (self);
715 disable_camera (self);
719 create_pipeline (EmpathyCallWindow *self)
721 EmpathyCallWindowPriv *priv = GET_PRIV (self);
724 g_assert (priv->pipeline == NULL);
726 priv->pipeline = gst_pipeline_new (NULL);
727 priv->pipeline_playing = FALSE;
729 priv->video_tee = gst_element_factory_make ("tee", NULL);
730 gst_object_ref (priv->video_tee);
731 gst_object_sink (priv->video_tee);
733 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
735 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
736 priv->bus_message_source_id = gst_bus_add_watch (bus,
737 empathy_call_window_bus_message, self);
739 g_object_unref (bus);
743 empathy_call_window_settings_cb (GtkAction *action,
744 EmpathyCallWindow *self)
746 gchar *args = g_strdup_printf ("-p %s",
747 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
749 empathy_launch_program (BIN_DIR, "empathy", args);
755 empathy_call_window_contents_cb (GtkAction *action,
756 EmpathyCallWindow *self)
758 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
762 empathy_call_window_debug_cb (GtkAction *action,
763 EmpathyCallWindow *self)
765 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
769 empathy_call_window_about_cb (GtkAction *action,
770 EmpathyCallWindow *self)
772 empathy_about_dialog_new (GTK_WINDOW (self));
776 empathy_call_window_configure_event_cb (GtkWidget *widget,
778 EmpathyCallWindow *self)
780 GdkWindow *gdk_window;
781 GdkWindowState window_state;
783 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
784 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
786 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
787 &self->priv->dialpad_width, NULL);
789 gdk_window = gtk_widget_get_window (widget);
790 window_state = gdk_window_get_state (gdk_window);
791 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
797 empathy_call_window_destroyed_cb (GtkWidget *object,
798 EmpathyCallWindow *self)
800 if (gtk_widget_get_visible (self->priv->dtmf_panel))
802 /* Save the geometry as if the dialpad was hidden. */
803 empathy_geometry_save_values (GTK_WINDOW (self),
804 self->priv->x, self->priv->y,
805 self->priv->w - self->priv->dialpad_width, self->priv->h,
806 self->priv->maximized);
811 empathy_call_window_video_box_allocation_changed_cb (ClutterActor *video_box,
813 ClutterBindConstraint *constraint)
815 ClutterActorBox allocation;
817 clutter_actor_get_allocation_box (video_box, &allocation);
819 clutter_bind_constraint_set_offset (constraint,
820 allocation.y2 - allocation.y1 -
821 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
825 empathy_call_window_init (EmpathyCallWindow *self)
827 EmpathyCallWindowPriv *priv;
831 ClutterConstraint *constraint;
832 ClutterActor *remote_avatar;
833 GtkStyleContext *context;
837 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
838 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
840 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
841 gui = empathy_builder_get_file (filename,
842 "call_window_vbox", &top_vbox,
843 "errors_vbox", &priv->errors_vbox,
845 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
846 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
847 "status_label", &priv->status_label,
848 "audiocall", &priv->audio_call_button,
849 "videocall", &priv->video_call_button,
850 "microphone", &priv->mic_button,
851 "camera", &priv->camera_button,
852 "hangup", &priv->hangup_button,
853 "dialpad", &priv->dialpad_button,
854 "toolbar", &priv->toolbar,
855 "bottom_toolbar", &priv->bottom_toolbar,
856 "ui_manager", &priv->ui_manager,
857 "menufullscreen", &priv->menu_fullscreen,
858 "details_vbox", &priv->details_vbox,
859 "vcodec_encoding_label", &priv->vcodec_encoding_label,
860 "acodec_encoding_label", &priv->acodec_encoding_label,
861 "acodec_decoding_label", &priv->acodec_decoding_label,
862 "vcodec_decoding_label", &priv->vcodec_decoding_label,
863 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
864 "audio_local_candidate_label", &priv->audio_local_candidate_label,
865 "video_remote_candidate_label", &priv->video_remote_candidate_label,
866 "video_local_candidate_label", &priv->video_local_candidate_label,
867 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
868 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
869 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
870 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
874 empathy_builder_connect (gui, self,
875 "hangup", "clicked", empathy_call_window_hangup_cb,
876 "audiocall", "clicked", empathy_call_window_audio_call_cb,
877 "videocall", "clicked", empathy_call_window_video_call_cb,
878 "volume", "value-changed", empathy_call_window_volume_changed_cb,
879 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
880 "camera", "toggled", empathy_call_window_camera_toggled_cb,
881 "dialpad", "toggled", empathy_call_window_dialpad_cb,
882 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
883 "menusettings", "activate", empathy_call_window_settings_cb,
884 "menucontents", "activate", empathy_call_window_contents_cb,
885 "menudebug", "activate", empathy_call_window_debug_cb,
886 "menuabout", "activate", empathy_call_window_about_cb,
887 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
888 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
889 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
892 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
894 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
896 g_object_bind_property (priv->camera_monitor, "available",
897 priv->camera_button, "sensitive",
898 G_BINDING_SYNC_CREATE);
900 priv->lock = g_mutex_new ();
902 gtk_container_add (GTK_CONTAINER (self), top_vbox);
904 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
905 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
906 CONTENT_HBOX_BORDER_WIDTH);
907 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
910 /* avatar/video box */
911 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
912 CLUTTER_BIN_ALIGNMENT_CENTER);
914 priv->video_box = clutter_box_new (priv->video_layout);
916 priv->video_container = gtk_clutter_embed_new ();
918 /* Set the background color to that of the rest of the window */
919 context = gtk_widget_get_style_context (priv->content_hbox);
920 gtk_style_context_get_background_color (context,
921 GTK_STATE_FLAG_NORMAL, &rgba);
922 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
923 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
924 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
925 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
926 clutter_stage_set_color (
927 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
928 GTK_CLUTTER_EMBED (priv->video_container))),
931 clutter_container_add (
932 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
933 GTK_CLUTTER_EMBED (priv->video_container))),
937 constraint = clutter_bind_constraint_new (
938 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
939 CLUTTER_BIND_SIZE, 0);
940 clutter_actor_add_constraint (priv->video_box, constraint);
942 priv->remote_user_avatar_widget = gtk_image_new ();
943 remote_avatar = gtk_clutter_actor_new_with_contents (
944 priv->remote_user_avatar_widget);
946 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
949 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
950 priv->video_container, TRUE, TRUE,
951 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
953 create_pipeline (self);
954 create_video_output_widget (self);
955 create_audio_input (self);
956 create_video_input (self);
958 priv->floating_toolbar = gtk_clutter_actor_new ();
960 gtk_widget_reparent (priv->bottom_toolbar,
961 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
963 constraint = clutter_bind_constraint_new (priv->video_box,
966 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
968 g_signal_connect (priv->video_box, "notify::allocation",
969 G_CALLBACK (empathy_call_window_video_box_allocation_changed_cb),
972 clutter_actor_set_size (priv->floating_toolbar,
973 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
974 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
976 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
977 priv->floating_toolbar,
978 CLUTTER_BIN_ALIGNMENT_CENTER,
979 CLUTTER_BIN_ALIGNMENT_END);
981 clutter_actor_raise_top (priv->floating_toolbar);
983 /* The call will be started as soon the pipeline is playing */
984 priv->start_call_when_playing = TRUE;
986 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
987 G_CALLBACK (dtmf_button_pressed_cb),
988 G_CALLBACK (dtmf_button_released_cb));
990 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
993 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
996 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
998 gtk_widget_show_all (top_vbox);
1000 gtk_widget_hide (priv->dtmf_panel);
1001 gtk_widget_hide (priv->details_vbox);
1003 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1005 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1006 priv->video_container);
1008 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1009 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1011 g_signal_connect (G_OBJECT (self), "realize",
1012 G_CALLBACK (empathy_call_window_realized_cb), self);
1014 g_signal_connect (G_OBJECT (self), "delete-event",
1015 G_CALLBACK (empathy_call_window_delete_cb), self);
1017 g_signal_connect (G_OBJECT (self), "window-state-event",
1018 G_CALLBACK (empathy_call_window_state_event_cb), self);
1020 g_signal_connect (G_OBJECT (self), "key-press-event",
1021 G_CALLBACK (empathy_call_window_key_press_cb), self);
1023 priv->timer = g_timer_new ();
1025 g_object_ref (priv->ui_manager);
1026 g_object_unref (gui);
1028 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1029 priv->mic_menu = empathy_mic_menu_new (self);
1031 empathy_call_window_show_hangup_button (self, TRUE);
1033 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1034 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1035 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1037 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1038 /* These signals are used to track the window position and save it
1039 * when the window is destroyed. We need to do this as we don't want
1040 * the window geometry to be saved with the dialpad taken into account. */
1041 g_signal_connect (self, "destroy",
1042 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1043 g_signal_connect (self, "configure-event",
1044 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1045 g_signal_connect (self, "window-state-event",
1046 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1048 /* Don't display labels in both toolbars */
1049 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1052 /* Instead of specifying a width and a height, we specify only one size. That's
1053 because we want a square avatar icon. */
1055 init_contact_avatar_with_size (EmpathyContact *contact,
1056 GtkWidget *image_widget,
1059 GdkPixbuf *pixbuf_avatar = NULL;
1061 if (contact != NULL)
1063 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1067 if (pixbuf_avatar == NULL)
1069 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1070 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1073 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1075 if (pixbuf_avatar != NULL)
1076 g_object_unref (pixbuf_avatar);
1080 set_window_title (EmpathyCallWindow *self)
1082 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1085 if (priv->contact != NULL)
1087 /* translators: Call is a noun and %s is the contact name. This string
1088 * is used in the window title */
1089 tmp = g_strdup_printf (_("Call with %s"),
1090 empathy_contact_get_alias (priv->contact));
1091 gtk_window_set_title (GTK_WINDOW (self), tmp);
1096 g_warning ("Unknown remote contact!");
1101 set_remote_user_name (EmpathyCallWindow *self,
1102 EmpathyContact *contact)
1104 const gchar *alias = empathy_contact_get_alias (contact);
1105 const gchar *status = empathy_contact_get_status (contact);
1108 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1109 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1115 contact_name_changed_cb (EmpathyContact *contact,
1117 EmpathyCallWindow *self)
1119 set_window_title (self);
1120 set_remote_user_name (self, contact);
1124 contact_presence_changed_cb (EmpathyContact *contact,
1126 EmpathyCallWindow *self)
1128 set_remote_user_name (self, contact);
1132 contact_avatar_changed_cb (EmpathyContact *contact,
1134 EmpathyCallWindow *self)
1137 GtkAllocation allocation;
1138 GtkWidget *avatar_widget;
1140 avatar_widget = self->priv->remote_user_avatar_widget;
1142 gtk_widget_get_allocation (avatar_widget, &allocation);
1143 size = allocation.height;
1147 /* the widget is not allocated yet, set a default size */
1148 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1149 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1152 init_contact_avatar_with_size (contact, avatar_widget, size);
1154 avatar_widget = self->priv->remote_user_avatar_toolbar;
1156 gtk_widget_get_allocation (avatar_widget, &allocation);
1157 size = allocation.height;
1161 /* the widget is not allocated yet, set a default size */
1162 size = SMALL_TOOLBAR_SIZE;
1165 init_contact_avatar_with_size (contact, avatar_widget, size);
1169 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1170 EmpathyCallHandler *handler)
1172 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1174 tp_g_signal_connect_object (priv->contact, "notify::name",
1175 G_CALLBACK (contact_name_changed_cb), self, 0);
1176 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1177 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1178 tp_g_signal_connect_object (priv->contact, "notify::presence",
1179 G_CALLBACK (contact_presence_changed_cb), self, 0);
1181 set_window_title (self);
1182 set_remote_user_name (self, priv->contact);
1184 init_contact_avatar_with_size (priv->contact,
1185 priv->remote_user_avatar_widget,
1186 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1187 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1189 init_contact_avatar_with_size (priv->contact,
1190 priv->remote_user_avatar_toolbar,
1191 SMALL_TOOLBAR_SIZE);
1193 /* The remote avatar is shown by default and will be hidden when we receive
1194 video from the remote side. */
1195 clutter_actor_hide (priv->video_output);
1196 gtk_widget_show (priv->remote_user_avatar_widget);
1200 update_send_codec (EmpathyCallWindow *self,
1203 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1210 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1211 widget = priv->acodec_encoding_label;
1215 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1216 widget = priv->vcodec_encoding_label;
1222 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1223 gtk_label_set_text (GTK_LABEL (widget), tmp);
1228 send_audio_codec_notify_cb (GObject *object,
1232 EmpathyCallWindow *self = user_data;
1234 update_send_codec (self, TRUE);
1238 send_video_codec_notify_cb (GObject *object,
1242 EmpathyCallWindow *self = user_data;
1244 update_send_codec (self, FALSE);
1248 update_recv_codec (EmpathyCallWindow *self,
1251 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1254 GString *str = NULL;
1258 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1259 widget = priv->acodec_decoding_label;
1263 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1264 widget = priv->vcodec_decoding_label;
1270 for (l = codecs; l != NULL; l = g_list_next (l))
1272 FsCodec *codec = l->data;
1275 str = g_string_new (NULL);
1277 g_string_append (str, ", ");
1279 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1283 gtk_label_set_text (GTK_LABEL (widget), str->str);
1284 g_string_free (str, TRUE);
1288 recv_audio_codecs_notify_cb (GObject *object,
1292 EmpathyCallWindow *self = user_data;
1294 update_recv_codec (self, TRUE);
1298 recv_video_codecs_notify_cb (GObject *object,
1302 EmpathyCallWindow *self = user_data;
1304 update_recv_codec (self, FALSE);
1307 static const gchar *
1308 candidate_type_to_str (FsCandidate *candidate)
1310 switch (candidate->type)
1312 case FS_CANDIDATE_TYPE_HOST:
1314 case FS_CANDIDATE_TYPE_SRFLX:
1315 return "server reflexive";
1316 case FS_CANDIDATE_TYPE_PRFLX:
1317 return "peer reflexive";
1318 case FS_CANDIDATE_TYPE_RELAY:
1320 case FS_CANDIDATE_TYPE_MULTICAST:
1327 static const gchar *
1328 candidate_type_to_desc (FsCandidate *candidate)
1330 switch (candidate->type)
1332 case FS_CANDIDATE_TYPE_HOST:
1333 return _("The IP address as seen by the machine");
1334 case FS_CANDIDATE_TYPE_SRFLX:
1335 return _("The IP address as seen by a server on the Internet");
1336 case FS_CANDIDATE_TYPE_PRFLX:
1337 return _("The IP address of the peer as seen by the other side");
1338 case FS_CANDIDATE_TYPE_RELAY:
1339 return _("The IP address of a relay server");
1340 case FS_CANDIDATE_TYPE_MULTICAST:
1341 return _("The IP address of the multicast group");
1348 update_candidat_widget (EmpathyCallWindow *self,
1351 FsCandidate *candidate)
1355 g_assert (candidate != NULL);
1356 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1357 candidate->port, candidate_type_to_str (candidate));
1359 gtk_label_set_text (GTK_LABEL (label), str);
1360 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1366 candidates_changed_cb (GObject *object,
1368 EmpathyCallWindow *self)
1370 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1371 FsCandidate *candidate = NULL;
1373 if (type == FS_MEDIA_TYPE_VIDEO)
1375 /* Update remote candidate */
1376 candidate = empathy_call_handler_get_video_remote_candidate (
1379 update_candidat_widget (self, priv->video_remote_candidate_label,
1380 priv->video_remote_candidate_info_img, candidate);
1382 /* Update local candidate */
1383 candidate = empathy_call_handler_get_video_local_candidate (
1386 update_candidat_widget (self, priv->video_local_candidate_label,
1387 priv->video_local_candidate_info_img, candidate);
1391 /* Update remote candidate */
1392 candidate = empathy_call_handler_get_audio_remote_candidate (
1395 update_candidat_widget (self, priv->audio_remote_candidate_label,
1396 priv->audio_remote_candidate_info_img, candidate);
1398 /* Update local candidate */
1399 candidate = empathy_call_handler_get_audio_local_candidate (
1402 update_candidat_widget (self, priv->audio_local_candidate_label,
1403 priv->audio_local_candidate_info_img, candidate);
1408 empathy_call_window_constructed (GObject *object)
1410 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1412 TpyCallChannel *call;
1414 g_assert (priv->handler != NULL);
1416 g_object_get (priv->handler, "call-channel", &call, NULL);
1417 priv->outgoing = (call == NULL);
1419 g_object_unref (call);
1421 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1422 g_assert (priv->contact != NULL);
1424 empathy_call_window_setup_avatars (self, priv->handler);
1425 empathy_call_window_set_state_connecting (self);
1427 if (!empathy_call_handler_has_initial_video (priv->handler))
1429 gtk_toggle_tool_button_set_active (
1430 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1432 /* If call has InitialVideo, the preview will be started once the call has
1433 * been started (start_call()). */
1435 update_send_codec (self, TRUE);
1436 update_send_codec (self, FALSE);
1437 update_recv_codec (self, TRUE);
1438 update_recv_codec (self, FALSE);
1440 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1441 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1442 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1443 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1444 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1445 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1446 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1447 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1449 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1450 G_CALLBACK (candidates_changed_cb), self, 0);
1453 static void empathy_call_window_dispose (GObject *object);
1454 static void empathy_call_window_finalize (GObject *object);
1457 empathy_call_window_set_property (GObject *object,
1458 guint property_id, const GValue *value, GParamSpec *pspec)
1460 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1462 switch (property_id)
1464 case PROP_CALL_HANDLER:
1465 priv->handler = g_value_dup_object (value);
1468 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1473 empathy_call_window_get_property (GObject *object,
1474 guint property_id, GValue *value, GParamSpec *pspec)
1476 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1478 switch (property_id)
1480 case PROP_CALL_HANDLER:
1481 g_value_set_object (value, priv->handler);
1484 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1489 empathy_call_window_class_init (
1490 EmpathyCallWindowClass *empathy_call_window_class)
1492 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1493 GParamSpec *param_spec;
1495 g_type_class_add_private (empathy_call_window_class,
1496 sizeof (EmpathyCallWindowPriv));
1498 object_class->constructed = empathy_call_window_constructed;
1499 object_class->set_property = empathy_call_window_set_property;
1500 object_class->get_property = empathy_call_window_get_property;
1502 object_class->dispose = empathy_call_window_dispose;
1503 object_class->finalize = empathy_call_window_finalize;
1505 param_spec = g_param_spec_object ("handler",
1506 "handler", "The call handler",
1507 EMPATHY_TYPE_CALL_HANDLER,
1508 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1509 g_object_class_install_property (object_class,
1510 PROP_CALL_HANDLER, param_spec);
1514 empathy_call_window_dispose (GObject *object)
1516 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1517 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1519 if (priv->dispose_has_run)
1522 priv->dispose_has_run = TRUE;
1524 if (priv->handler != NULL)
1526 empathy_call_handler_stop_call (priv->handler);
1527 tp_clear_object (&priv->handler);
1530 if (priv->bus_message_source_id != 0)
1532 g_source_remove (priv->bus_message_source_id);
1533 priv->bus_message_source_id = 0;
1536 if (priv->got_video_src > 0)
1538 g_source_remove (priv->got_video_src);
1539 priv->got_video_src = 0;
1542 tp_clear_object (&priv->pipeline);
1543 tp_clear_object (&priv->video_input);
1544 tp_clear_object (&priv->audio_input);
1545 tp_clear_object (&priv->video_tee);
1546 tp_clear_object (&priv->ui_manager);
1547 tp_clear_object (&priv->fullscreen);
1548 tp_clear_object (&priv->camera_monitor);
1549 tp_clear_object (&priv->settings);
1551 g_list_free_full (priv->notifiers, g_object_unref);
1553 if (priv->timer_id != 0)
1554 g_source_remove (priv->timer_id);
1557 if (priv->contact != NULL)
1559 g_signal_handlers_disconnect_by_func (priv->contact,
1560 contact_name_changed_cb, self);
1561 priv->contact = NULL;
1565 tp_clear_object (&priv->sound_mgr);
1567 tp_clear_object (&priv->mic_menu);
1569 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1573 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1575 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1577 if (priv->video_output_motion_handler_id != 0)
1579 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1580 priv->video_output_motion_handler_id);
1581 priv->video_output_motion_handler_id = 0;
1586 empathy_call_window_finalize (GObject *object)
1588 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1589 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1591 disconnect_video_output_motion_handler (self);
1593 /* free any data held directly by the object here */
1594 g_mutex_free (priv->lock);
1596 g_timer_destroy (priv->timer);
1598 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1603 empathy_call_window_new (EmpathyCallHandler *handler)
1605 return EMPATHY_CALL_WINDOW (
1606 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1610 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1611 GstElement *conference, gpointer user_data)
1613 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1614 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1615 FsElementAddedNotifier *notifier;
1618 DEBUG ("Conference added");
1620 /* Add notifier to set the various element properties as needed */
1621 notifier = fs_element_added_notifier_new ();
1622 keyfile = fs_utils_get_default_element_properties (conference);
1624 if (keyfile != NULL)
1625 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1627 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1629 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1631 gst_bin_add (GST_BIN (priv->pipeline), conference);
1632 gst_element_set_state (conference, GST_STATE_PLAYING);
1636 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1637 GstElement *conference, gpointer user_data)
1639 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1640 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1642 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1643 gst_element_set_state (conference, GST_STATE_NULL);
1647 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1649 GstStateChangeReturn state_change_return;
1650 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1652 if (priv->pipeline == NULL)
1655 if (priv->bus_message_source_id != 0)
1657 g_source_remove (priv->bus_message_source_id);
1658 priv->bus_message_source_id = 0;
1661 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1663 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1664 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1666 if (priv->pipeline != NULL)
1667 g_object_unref (priv->pipeline);
1668 priv->pipeline = NULL;
1670 if (priv->audio_output != NULL)
1671 g_object_unref (priv->audio_output);
1672 priv->audio_output = NULL;
1674 if (priv->video_tee != NULL)
1675 g_object_unref (priv->video_tee);
1676 priv->video_tee = NULL;
1678 if (priv->video_preview != NULL)
1679 clutter_actor_destroy (priv->video_preview);
1680 priv->video_preview = NULL;
1682 priv->funnel = NULL;
1684 create_pipeline (self);
1685 /* Call will be started when user will hit the 'redial' button */
1686 priv->start_call_when_playing = FALSE;
1687 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1693 g_message ("Error: could not destroy pipeline. Closing call window");
1694 gtk_widget_destroy (GTK_WIDGET (self));
1701 reset_details_pane (EmpathyCallWindow *self)
1703 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1705 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1706 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1707 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1708 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1712 empathy_call_window_disconnected (EmpathyCallWindow *self,
1715 gboolean could_disconnect = FALSE;
1716 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1717 gboolean could_reset_pipeline;
1719 /* Leave full screen mode if needed */
1720 gtk_window_unfullscreen (GTK_WINDOW (self));
1722 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1723 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1725 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1727 if (priv->call_state == CONNECTING)
1728 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1730 if (priv->call_state != REDIALING)
1731 priv->call_state = DISCONNECTED;
1733 if (could_reset_pipeline)
1735 g_mutex_lock (priv->lock);
1737 g_timer_stop (priv->timer);
1739 if (priv->timer_id != 0)
1740 g_source_remove (priv->timer_id);
1743 g_mutex_unlock (priv->lock);
1746 /* We are about to destroy the window, no need to update it or create
1747 * a video preview */
1750 empathy_call_window_status_message (self, _("Disconnected"));
1752 empathy_call_window_show_hangup_button (self, FALSE);
1754 /* Unsensitive the camera and mic button */
1755 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1756 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1758 /* Be sure that the mic button is enabled */
1759 gtk_toggle_tool_button_set_active (
1760 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1762 if (priv->camera_state == CAMERA_STATE_ON)
1764 /* Restart the preview with the new pipeline. */
1765 display_video_preview (self, TRUE);
1768 /* destroy the video output; it will be recreated when we'll redial */
1769 disconnect_video_output_motion_handler (self);
1770 if (priv->video_output != NULL)
1771 clutter_actor_destroy (priv->video_output);
1772 priv->video_output = NULL;
1773 if (priv->got_video_src > 0)
1775 g_source_remove (priv->got_video_src);
1776 priv->got_video_src = 0;
1779 gtk_widget_show (priv->remote_user_avatar_widget);
1781 reset_details_pane (self);
1783 priv->sending_video = FALSE;
1784 priv->call_started = FALSE;
1786 could_disconnect = TRUE;
1788 /* TODO: display the self avatar of the preview (depends if the "Always
1789 * Show Video Preview" is enabled or not) */
1792 return could_disconnect;
1797 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1800 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1801 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1803 if (empathy_call_window_disconnected (self, TRUE) &&
1804 priv->call_state == REDIALING)
1805 empathy_call_window_restart_call (self);
1809 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1811 FsMediaType media_type,
1812 EmpathyCallWindow *self)
1814 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1816 DEBUG ("removing content");
1819 * This assumes that there is only one video stream per channel...
1822 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1824 if (priv->funnel != NULL)
1828 output = priv->video_output_sink;
1830 gst_element_set_state (output, GST_STATE_NULL);
1831 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1833 gst_bin_remove (GST_BIN (priv->pipeline), output);
1834 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1835 priv->funnel = NULL;
1839 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1841 if (priv->audio_output != NULL)
1843 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1845 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1846 priv->audio_output = NULL;
1854 /* Called with global lock held */
1856 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1858 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1862 if (priv->funnel == NULL)
1864 output = priv->video_output_sink;
1866 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1870 g_warning ("Could not create fsfunnel");
1874 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1876 gst_object_unref (priv->funnel);
1877 priv->funnel = NULL;
1878 g_warning ("Could not add funnel to pipeline");
1882 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1884 g_warning ("Could not add the video output widget to the pipeline");
1888 if (!gst_element_link (priv->funnel, output))
1890 g_warning ("Could not link output sink to funnel");
1891 goto error_output_added;
1894 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1896 g_warning ("Could not start video sink");
1897 goto error_output_added;
1900 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1902 g_warning ("Could not start funnel");
1903 goto error_output_added;
1907 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1910 g_warning ("Could not get request pad from funnel");
1917 gst_element_set_locked_state (priv->funnel, TRUE);
1918 gst_element_set_locked_state (output, TRUE);
1920 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1921 gst_element_set_state (output, GST_STATE_NULL);
1923 gst_bin_remove (GST_BIN (priv->pipeline), output);
1924 gst_element_set_locked_state (output, FALSE);
1928 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1929 priv->funnel = NULL;
1934 /* Called with global lock held */
1936 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1938 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1940 GstPadTemplate *template;
1942 if (priv->audio_output == NULL)
1944 priv->audio_output = empathy_audio_sink_new ();
1945 g_object_ref_sink (priv->audio_output);
1947 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1949 g_warning ("Could not add audio sink to pipeline");
1950 g_object_unref (priv->audio_output);
1951 goto error_add_output;
1954 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1956 g_warning ("Could not start audio sink");
1961 template = gst_element_class_get_pad_template (
1962 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
1964 pad = gst_element_request_pad (priv->audio_output,
1965 template, NULL, NULL);
1969 g_warning ("Could not get sink pad from sink");
1976 gst_element_set_locked_state (priv->audio_output, TRUE);
1977 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1978 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1979 priv->audio_output = NULL;
1987 empathy_call_window_update_timer (gpointer user_data)
1989 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1990 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1991 const gchar *status;
1995 time_ = g_timer_elapsed (priv->timer, NULL);
1997 if (priv->call_state == HELD)
1998 status = _("On hold");
1999 else if (!gtk_toggle_tool_button_get_active (
2000 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2003 status = _("Duration");
2005 /* Translators: 'status - minutes:seconds' the caller has been connected */
2006 str = g_strdup_printf (_("%s — %d:%02dm"),
2008 (int) time_ / 60, (int) time_ % 60);
2009 empathy_call_window_status_message (self, str);
2017 display_error (EmpathyCallWindow *self,
2018 TpyCallChannel *call,
2022 const gchar *details)
2024 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2025 GtkWidget *info_bar;
2026 GtkWidget *content_area;
2033 /* Create info bar */
2034 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2037 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2039 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2041 /* hbox containing the image and the messages vbox */
2042 hbox = gtk_hbox_new (FALSE, 3);
2043 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2046 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2047 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2049 /* vbox containing the main message and the details expander */
2050 vbox = gtk_vbox_new (FALSE, 3);
2051 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2054 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2056 label = gtk_label_new (NULL);
2057 gtk_label_set_markup (GTK_LABEL (label), txt);
2058 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2059 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2062 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2065 if (details != NULL)
2067 GtkWidget *expander;
2069 expander = gtk_expander_new (_("Technical Details"));
2071 txt = g_strdup_printf ("<i>%s</i>", details);
2073 label = gtk_label_new (NULL);
2074 gtk_label_set_markup (GTK_LABEL (label), txt);
2075 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2076 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2079 gtk_container_add (GTK_CONTAINER (expander), label);
2080 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2083 g_signal_connect (info_bar, "response",
2084 G_CALLBACK (gtk_widget_destroy), NULL);
2086 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2087 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2088 gtk_widget_show_all (info_bar);
2092 media_stream_error_to_txt (EmpathyCallWindow *self,
2093 TpyCallChannel *call,
2095 TpMediaStreamError error)
2097 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2098 const gchar *cm = NULL;
2104 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2106 return g_strdup_printf (
2107 _("%s's software does not understand any of the audio formats "
2108 "supported by your computer"),
2109 empathy_contact_get_alias (priv->contact));
2111 return g_strdup_printf (
2112 _("%s's software does not understand any of the video formats "
2113 "supported by your computer"),
2114 empathy_contact_get_alias (priv->contact));
2116 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2117 return g_strdup_printf (
2118 _("Can't establish a connection to %s. "
2119 "One of you might be on a network that does not allow "
2120 "direct connections."),
2121 empathy_contact_get_alias (priv->contact));
2123 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2124 return g_strdup (_("There was a failure on the network"));
2126 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2128 return g_strdup (_("The audio formats necessary for this call "
2129 "are not installed on your computer"));
2131 return g_strdup (_("The video formats necessary for this call "
2132 "are not installed on your computer"));
2134 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2135 tp_connection_parse_object_path (
2136 tp_channel_borrow_connection (TP_CHANNEL (call)),
2139 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2140 "product=Telepathy&component=%s", cm);
2142 result = g_strdup_printf (
2143 _("Something unexpected happened in a Telepathy component. "
2144 "Please <a href=\"%s\">report this bug</a> and attach "
2145 "logs gathered from the 'Debug' window in the Help menu."), url);
2151 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2152 return g_strdup (_("There was a failure in the call engine"));
2154 case TP_MEDIA_STREAM_ERROR_EOS:
2155 return g_strdup (_("The end of the stream was reached"));
2157 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2164 empathy_call_window_stream_error (EmpathyCallWindow *self,
2165 TpyCallChannel *call,
2174 desc = media_stream_error_to_txt (self, call, audio, code);
2177 /* No description, use the error message. That's not great as it's not
2178 * localized but it's better than nothing. */
2179 display_error (self, call, icon, title, msg, NULL);
2183 display_error (self, call, icon, title, desc, msg);
2189 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2192 EmpathyCallWindow *self)
2194 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2195 "gnome-stock-mic", _("Can't establish audio stream"));
2199 empathy_call_window_video_stream_error (TpyCallChannel *call,
2202 EmpathyCallWindow *self)
2204 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2205 "camera-web", _("Can't establish video stream"));
2210 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2212 EmpathyCallWindow *self)
2214 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2215 TpyCallChannel *call;
2216 gboolean can_send_video;
2218 if (state != TPY_CALL_STATE_ACCEPTED)
2221 if (priv->call_state == CONNECTED)
2224 g_timer_start (priv->timer);
2225 priv->call_state = CONNECTED;
2227 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2229 can_send_video = priv->video_input != NULL &&
2230 empathy_contact_can_voip_video (priv->contact) &&
2231 empathy_camera_monitor_get_available (priv->camera_monitor);
2233 g_object_get (priv->handler, "call-channel", &call, NULL);
2235 if (tpy_call_channel_has_dtmf (call))
2236 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2238 if (priv->video_input == NULL)
2239 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2241 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2243 empathy_call_window_show_hangup_button (self, TRUE);
2245 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2247 clutter_actor_hide (priv->video_output);
2248 gtk_widget_show (priv->remote_user_avatar_widget);
2250 g_object_unref (call);
2252 g_mutex_lock (priv->lock);
2254 priv->timer_id = g_timeout_add_seconds (1,
2255 empathy_call_window_update_timer, self);
2257 g_mutex_unlock (priv->lock);
2259 empathy_call_window_update_timer (self);
2261 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2265 empathy_call_window_show_video_output_cb (gpointer user_data)
2267 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2269 if (self->priv->video_output != NULL)
2271 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2272 clutter_actor_show (self->priv->video_output);
2273 clutter_actor_raise_top (self->priv->floating_toolbar);
2280 empathy_call_window_check_video_cb (gpointer data)
2282 EmpathyCallWindow *self = data;
2284 if (self->priv->got_video)
2286 self->priv->got_video = FALSE;
2290 /* No video in the last N seconds, display the remote avatar */
2291 empathy_call_window_show_video_output (self, FALSE);
2296 /* Called from the streaming thread */
2298 empathy_call_window_video_probe_cb (GstPad *pad,
2299 GstMiniObject *mini_obj,
2300 EmpathyCallWindow *self)
2303 if (GST_IS_EVENT (mini_obj))
2306 if (G_UNLIKELY (!self->priv->got_video))
2308 /* show the remote video */
2309 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2310 empathy_call_window_show_video_output_cb,
2311 g_object_ref (self), g_object_unref);
2313 self->priv->got_video = TRUE;
2319 /* Called from the streaming thread */
2321 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2322 GstPad *src, guint media_type, gpointer user_data)
2324 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2325 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2326 gboolean retval = FALSE;
2330 g_mutex_lock (priv->lock);
2334 case TP_MEDIA_STREAM_TYPE_AUDIO:
2335 pad = empathy_call_window_get_audio_sink_pad (self);
2337 case TP_MEDIA_STREAM_TYPE_VIDEO:
2338 g_idle_add (empathy_call_window_show_video_output_cb, self);
2339 pad = empathy_call_window_get_video_sink_pad (self);
2341 gst_pad_add_data_probe (src,
2342 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2343 if (priv->got_video_src > 0)
2344 g_source_remove (priv->got_video_src);
2345 priv->got_video_src = g_timeout_add_seconds (5,
2346 empathy_call_window_check_video_cb, self);
2349 g_assert_not_reached ();
2355 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2356 g_warning ("Could not link %s sink pad",
2357 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2361 gst_object_unref (pad);
2365 /* If no sink could be linked, try to add fakesink to prevent the whole call
2370 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2372 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2374 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2375 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2376 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2378 gst_element_set_locked_state (fakesink, TRUE);
2379 gst_element_set_state (fakesink, GST_STATE_NULL);
2380 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2384 DEBUG ("Could not link real sink, linked fakesink instead");
2386 gst_object_unref (sinkpad);
2390 gst_object_unref (fakesink);
2395 g_mutex_unlock (priv->lock);
2401 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2402 GstPad *sink, FsMediaType media_type, gpointer user_data)
2404 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2405 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2407 gboolean retval = FALSE;
2411 case FS_MEDIA_TYPE_AUDIO:
2412 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2414 g_warning ("Could not add audio source to pipeline");
2418 pad = gst_element_get_static_pad (priv->audio_input, "src");
2421 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2422 g_warning ("Could not get source pad from audio source");
2426 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2428 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2429 g_warning ("Could not link audio source to farsight");
2433 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2435 g_warning ("Could not start audio source");
2436 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2437 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2443 case FS_MEDIA_TYPE_VIDEO:
2444 if (priv->video_tee != NULL)
2446 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2447 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2449 g_warning ("Could not link video source input pipeline");
2452 gst_object_unref (pad);
2458 g_assert_not_reached ();
2465 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2467 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2468 GstElement *preview;
2470 disable_camera (self);
2472 DEBUG ("remove video input");
2473 preview = priv->video_preview_sink;
2475 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2476 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2477 gst_element_set_state (preview, GST_STATE_NULL);
2479 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2482 g_object_unref (priv->video_input);
2483 priv->video_input = NULL;
2484 g_object_unref (priv->video_tee);
2485 priv->video_tee = NULL;
2486 clutter_actor_destroy (priv->video_preview);
2487 priv->video_preview = NULL;
2489 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2493 start_call (EmpathyCallWindow *self)
2495 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2497 priv->call_started = TRUE;
2498 empathy_call_handler_start_call (priv->handler,
2499 gtk_get_current_event_time ());
2501 if (empathy_call_handler_has_initial_video (priv->handler))
2503 TpyCallChannel *call;
2506 g_object_get (priv->handler, "call-channel", &call, NULL);
2507 s = tpy_call_channel_get_video_state (call);
2509 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2510 s == TPY_SENDING_STATE_SENDING)
2512 /* Enable 'send video' buttons and display the preview */
2513 gtk_toggle_tool_button_set_active (
2514 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2518 gtk_toggle_tool_button_set_active (
2519 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2521 if (priv->video_preview == NULL)
2523 create_video_preview (self);
2524 add_video_preview_to_pipeline (self);
2528 g_object_unref (call);
2533 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2536 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2537 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2540 empathy_call_handler_bus_message (priv->handler, bus, message);
2542 switch (GST_MESSAGE_TYPE (message))
2544 case GST_MESSAGE_STATE_CHANGED:
2545 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2547 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2549 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2550 !priv->call_started)
2552 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2553 if (newstate == GST_STATE_PAUSED)
2555 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2556 priv->pipeline_playing = TRUE;
2558 if (priv->start_call_when_playing)
2563 case GST_MESSAGE_ERROR:
2565 GError *error = NULL;
2566 GstElement *gst_error;
2569 gst_message_parse_error (message, &error, &debug);
2570 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2572 g_message ("Element error: %s -- %s\n", error->message, debug);
2574 if (g_str_has_prefix (gst_element_get_name (gst_error),
2575 VIDEO_INPUT_ERROR_PREFIX))
2577 /* Remove the video input and continue */
2578 if (priv->video_input != NULL)
2579 empathy_call_window_remove_video_input (self);
2580 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2584 empathy_call_window_disconnected (self, TRUE);
2586 g_error_free (error);
2589 case GST_MESSAGE_UNKNOWN:
2590 case GST_MESSAGE_EOS:
2591 case GST_MESSAGE_WARNING:
2592 case GST_MESSAGE_INFO:
2593 case GST_MESSAGE_TAG:
2594 case GST_MESSAGE_BUFFERING:
2595 case GST_MESSAGE_STATE_DIRTY:
2596 case GST_MESSAGE_STEP_DONE:
2597 case GST_MESSAGE_CLOCK_PROVIDE:
2598 case GST_MESSAGE_CLOCK_LOST:
2599 case GST_MESSAGE_NEW_CLOCK:
2600 case GST_MESSAGE_STRUCTURE_CHANGE:
2601 case GST_MESSAGE_STREAM_STATUS:
2602 case GST_MESSAGE_APPLICATION:
2603 case GST_MESSAGE_ELEMENT:
2604 case GST_MESSAGE_SEGMENT_START:
2605 case GST_MESSAGE_SEGMENT_DONE:
2606 case GST_MESSAGE_DURATION:
2607 case GST_MESSAGE_ANY:
2616 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2617 GHashTable *members,
2618 EmpathyCallWindow *self)
2620 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2621 GHashTableIter iter;
2622 gpointer key, value;
2623 gboolean held = FALSE;
2625 g_hash_table_iter_init (&iter, members);
2626 while (g_hash_table_iter_next (&iter, &key, &value))
2628 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2630 /* This assumes this is a 1-1 call, otherwise one participant
2631 * putting the call on hold wouldn't mean the call is on hold
2639 priv->call_state = HELD;
2640 else if (priv->call_state == HELD)
2641 priv->call_state = CONNECTED;
2645 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2647 EmpathyCallWindow *self)
2649 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2650 TpyCallChannel *call;
2652 g_object_get (priv->handler, "call-channel", &call, NULL);
2657 tp_g_signal_connect_object (call, "audio-stream-error",
2658 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2659 tp_g_signal_connect_object (call, "video-stream-error",
2660 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2663 tp_g_signal_connect_object (call, "members-changed",
2664 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2666 g_object_unref (call);
2670 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2672 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2673 TpyCallChannel *call;
2676 /* Make the hangup button twice as wide */
2677 width = gtk_widget_get_allocated_width (priv->hangup_button);
2678 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2680 g_signal_connect (priv->handler, "state-changed",
2681 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2682 g_signal_connect (priv->handler, "conference-added",
2683 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2684 g_signal_connect (priv->handler, "conference-removed",
2685 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2686 g_signal_connect (priv->handler, "closed",
2687 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2688 g_signal_connect (priv->handler, "src-pad-added",
2689 G_CALLBACK (empathy_call_window_src_added_cb), window);
2690 g_signal_connect (priv->handler, "sink-pad-added",
2691 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2692 g_signal_connect (priv->handler, "sink-pad-removed",
2693 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2695 g_object_get (priv->handler, "call-channel", &call, NULL);
2698 call_handler_notify_call_cb (priv->handler, NULL, window);
2699 g_object_unref (call);
2703 /* call-channel doesn't exist yet, we'll connect signals once it has been
2705 g_signal_connect (priv->handler, "notify::call-channel",
2706 G_CALLBACK (call_handler_notify_call_cb), window);
2709 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2713 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2714 EmpathyCallWindow *window)
2716 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2718 if (priv->pipeline != NULL)
2720 if (priv->bus_message_source_id != 0)
2722 g_source_remove (priv->bus_message_source_id);
2723 priv->bus_message_source_id = 0;
2726 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2729 if (priv->call_state == CONNECTING)
2730 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2736 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2739 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2741 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2746 gtk_widget_hide (priv->dtmf_panel);
2747 gtk_widget_hide (menu);
2748 gtk_widget_hide (priv->toolbar);
2752 if (priv->dialpad_was_visible_before_fs)
2753 gtk_widget_show (priv->dtmf_panel);
2755 gtk_widget_show (menu);
2756 gtk_widget_show (priv->toolbar);
2758 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2759 priv->original_height_before_fs);
2764 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2766 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2768 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2769 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2770 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2771 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2773 if (priv->video_output != NULL)
2776 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2777 priv->video_output, TRUE, TRUE,
2778 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2785 empathy_call_window_state_event_cb (GtkWidget *widget,
2786 GdkEventWindowState *event, EmpathyCallWindow *window)
2788 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2790 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2791 gboolean set_fullscreen = event->new_window_state &
2792 GDK_WINDOW_STATE_FULLSCREEN;
2796 gboolean dialpad_was_visible;
2797 GtkAllocation allocation;
2798 gint original_width, original_height;
2800 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2801 original_width = allocation.width;
2802 original_height = allocation.height;
2804 g_object_get (priv->dtmf_panel,
2805 "visible", &dialpad_was_visible,
2808 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2809 priv->original_width_before_fs = original_width;
2810 priv->original_height_before_fs = original_height;
2812 if (priv->video_output_motion_handler_id == 0 &&
2813 priv->video_output != NULL)
2815 priv->video_output_motion_handler_id = g_signal_connect (
2816 G_OBJECT (priv->video_container), "motion-notify-event",
2817 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2823 disconnect_video_output_motion_handler (window);
2826 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2828 show_controls (window, set_fullscreen);
2829 show_borders (window, set_fullscreen);
2830 gtk_action_set_stock_id (priv->menu_fullscreen,
2831 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2832 priv->is_fullscreen = set_fullscreen;
2839 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2842 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2843 int w, h, dialpad_width;
2844 GtkAllocation allocation;
2846 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2847 w = allocation.width;
2848 h = allocation.height;
2850 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2854 gtk_widget_show (priv->dtmf_panel);
2860 gtk_widget_hide (priv->dtmf_panel);
2864 gtk_window_resize (GTK_WINDOW (window), w, h);
2868 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2871 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2872 TpyCallChannel *call;
2874 priv->sending_video = (state == CAMERA_STATE_ON);
2876 if (state == CAMERA_STATE_ON)
2878 /* When we start sending video, we want to show the video preview by
2880 display_video_preview (window, TRUE);
2884 display_video_preview (window, FALSE);
2887 if (priv->call_state != CONNECTED)
2890 g_object_get (priv->handler, "call-channel", &call, NULL);
2891 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2892 tpy_call_channel_send_video (call, priv->sending_video);
2893 g_object_unref (call);
2897 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2898 EmpathyCallWindow *window)
2900 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2903 active = (gtk_toggle_tool_button_get_active (toggle));
2907 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2908 priv->volume * 100);
2912 /* TODO, Instead of setting the input volume to 0 we should probably
2913 * stop sending but this would cause the audio call to drop if both
2914 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2915 * in the future. GNOME #574574
2917 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2923 empathy_call_window_hangup_cb (gpointer object,
2924 EmpathyCallWindow *self)
2926 empathy_call_handler_stop_call (self->priv->handler);
2928 empathy_call_window_disconnected (self, TRUE);
2932 empathy_call_window_restart_call (EmpathyCallWindow *window)
2934 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2936 /* Remove error info bars */
2937 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
2938 (GtkCallback) gtk_widget_destroy, NULL);
2940 create_video_output_widget (window);
2942 /* While the call was disconnected, the input volume might have changed.
2943 * However, since the audio_input source was destroyed, its volume has not
2944 * been updated during that time. That's why we manually update it here */
2945 empathy_call_window_mic_volume_changed (window);
2947 priv->outgoing = TRUE;
2948 empathy_call_window_set_state_connecting (window);
2950 if (priv->pipeline_playing)
2951 start_call (window);
2953 /* call will be started when the pipeline is ready */
2954 priv->start_call_when_playing = TRUE;
2956 empathy_call_window_setup_avatars (window, priv->handler);
2958 empathy_call_window_show_hangup_button (window, TRUE);
2962 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
2963 EmpathyCallWindow *window)
2967 active = gtk_toggle_tool_button_get_active (button);
2969 empathy_call_window_show_dialpad (window, active);
2973 empathy_call_window_fullscreen_cb (gpointer object,
2974 EmpathyCallWindow *window)
2976 empathy_call_window_fullscreen_toggle (window);
2980 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2982 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2984 if (priv->is_fullscreen)
2985 gtk_window_unfullscreen (GTK_WINDOW (window));
2987 gtk_window_fullscreen (GTK_WINDOW (window));
2991 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
2992 GdkEventButton *event, EmpathyCallWindow *window)
2994 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2996 empathy_call_window_video_menu_popup (window, event->button);
3004 empathy_call_window_key_press_cb (GtkWidget *video_output,
3005 GdkEventKey *event, EmpathyCallWindow *window)
3007 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3009 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3011 /* Since we are in fullscreen mode, toggling will bring us back to
3013 empathy_call_window_fullscreen_toggle (window);
3021 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3022 GdkEventMotion *event, EmpathyCallWindow *window)
3024 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3026 if (priv->is_fullscreen)
3028 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3035 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3039 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3041 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3043 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3044 button, gtk_get_current_event_time ());
3045 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3049 empathy_call_window_status_message (EmpathyCallWindow *self,
3052 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3056 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3057 gdouble value, EmpathyCallWindow *window)
3059 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3061 if (priv->audio_output == NULL)
3064 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3069 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3071 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3073 return priv->ui_manager;
3076 EmpathyGstAudioSrc *
3077 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3079 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3081 return (EmpathyGstAudioSrc *) priv->audio_input;