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-audio-src.h"
62 #include "empathy-audio-sink.h"
63 #include "empathy-video-src.h"
65 #define CONTENT_HBOX_BORDER_WIDTH 6
66 #define CONTENT_HBOX_SPACING 3
67 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
69 #define SELF_VIDEO_SECTION_WIDTH 120
70 #define SELF_VIDEO_SECTION_HEIGTH 90
72 /* The avatar's default width and height are set to the same value because we
73 want a square icon. */
74 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
75 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
76 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
78 #define SMALL_TOOLBAR_SIZE 36
80 /* If an video input error occurs, the error message will start with "v4l" */
81 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
83 /* The time interval in milliseconds between 2 outgoing rings */
84 #define MS_BETWEEN_RING 500
86 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
89 PROP_CALL_HANDLER = 1,
101 CAMERA_STATE_OFF = 0,
105 struct _EmpathyCallWindowPriv
107 gboolean dispose_has_run;
108 EmpathyCallHandler *handler;
110 EmpathyContact *contact;
112 EmpathyCameraMonitor *camera_monitor;
117 GtkUIManager *ui_manager;
118 GtkWidget *errors_vbox;
119 /* widget displays the video received from the remote user. This widget is
120 * alive only during call. */
121 ClutterActor *video_output;
122 ClutterActor *video_preview;
123 ClutterActor *preview_hidden_button;
124 GtkWidget *video_container;
125 GtkWidget *remote_user_avatar_widget;
126 GtkWidget *remote_user_avatar_toolbar;
127 GtkWidget *remote_user_name_toolbar;
128 GtkWidget *status_label;
129 GtkWidget *hangup_button;
130 GtkWidget *audio_call_button;
131 GtkWidget *video_call_button;
132 GtkWidget *mic_button;
133 GtkWidget *camera_button;
134 GtkWidget *dialpad_button;
136 GtkWidget *bottom_toolbar;
138 GtkAction *menu_fullscreen;
140 /* The box that contains self and remote avatar and video
141 input/output. When we redial, we destroy and re-create the box */
142 ClutterActor *video_box;
143 ClutterLayoutManager *video_layout;
145 /* We keep a reference on the hbox which contains the main content so we can
146 easilly repack everything when toggling fullscreen */
147 GtkWidget *content_hbox;
149 gulong video_output_motion_handler_id;
150 guint bus_message_source_id;
154 GtkWidget *dtmf_panel;
157 GtkWidget *details_vbox;
158 GtkWidget *vcodec_encoding_label;
159 GtkWidget *acodec_encoding_label;
160 GtkWidget *vcodec_decoding_label;
161 GtkWidget *acodec_decoding_label;
163 GtkWidget *audio_remote_candidate_label;
164 GtkWidget *audio_local_candidate_label;
165 GtkWidget *video_remote_candidate_label;
166 GtkWidget *video_local_candidate_label;
167 GtkWidget *video_remote_candidate_info_img;
168 GtkWidget *video_local_candidate_info_img;
169 GtkWidget *audio_remote_candidate_info_img;
170 GtkWidget *audio_local_candidate_info_img;
172 GstElement *video_input;
173 GstElement *video_preview_sink;
174 GstElement *video_output_sink;
175 GstElement *audio_input;
176 GstElement *audio_output;
177 GstElement *pipeline;
178 GstElement *video_tee;
188 gboolean call_started;
189 gboolean sending_video;
190 CameraState camera_state;
192 EmpathyCallWindowFullscreen *fullscreen;
193 gboolean is_fullscreen;
198 /* Those fields represent the state of the window before it actually was in
200 gboolean dialpad_was_visible_before_fs;
201 gint original_width_before_fs;
202 gint original_height_before_fs;
204 gint x, y, w, h, dialpad_width;
207 /* TRUE if the call should be started when the pipeline is playing */
208 gboolean start_call_when_playing;
209 /* TRUE if we requested to set the pipeline in the playing state */
210 gboolean pipeline_playing;
212 EmpathySoundManager *sound_mgr;
217 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
219 static void empathy_call_window_realized_cb (GtkWidget *widget,
220 EmpathyCallWindow *window);
222 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
223 GdkEvent *event, EmpathyCallWindow *window);
225 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
226 GdkEventWindowState *event, EmpathyCallWindow *window);
228 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
231 static void empathy_call_window_mic_toggled_cb (
232 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
234 static void empathy_call_window_hangup_cb (gpointer object,
235 EmpathyCallWindow *window);
237 static void empathy_call_window_fullscreen_cb (gpointer object,
238 EmpathyCallWindow *window);
240 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
242 static gboolean empathy_call_window_video_button_press_cb (
243 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
245 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
246 GdkEventKey *event, EmpathyCallWindow *window);
248 static gboolean empathy_call_window_video_output_motion_notify (
249 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
251 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
254 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
255 EmpathyCallWindow *window);
257 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
259 static void empathy_call_window_status_message (EmpathyCallWindow *window,
262 static gboolean empathy_call_window_bus_message (GstBus *bus,
263 GstMessage *message, gpointer user_data);
266 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
267 gdouble value, EmpathyCallWindow *window);
270 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
273 gtk_widget_set_visible (self->priv->hangup_button, show);
274 gtk_widget_set_visible (self->priv->audio_call_button, !show);
275 gtk_widget_set_visible (self->priv->video_call_button, !show);
279 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
280 EmpathyCallWindow *self)
282 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
283 empathy_call_window_restart_call (self);
287 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
288 EmpathyCallWindow *self)
290 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
291 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
292 empathy_call_window_restart_call (self);
296 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
298 EmpathyCallWindowPriv *priv = GET_PRIV (window);
299 TpyCallChannel *call;
303 g_object_get (priv->handler, "call-channel", &call, NULL);
305 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
306 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
309 tpy_call_channel_dtmf_start_tone (call, event);
311 g_object_unref (call);
315 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
317 EmpathyCallWindowPriv *priv = GET_PRIV (window);
318 TpyCallChannel *call;
320 g_object_get (priv->handler, "call-channel", &call, NULL);
322 tpy_call_channel_dtmf_stop_tone (call);
324 g_object_unref (call);
328 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
330 EmpathyCallWindowPriv *priv = GET_PRIV (self);
333 volume = g_settings_get_double (priv->settings,
334 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
336 /* Don't store the volume because of muting */
337 if (volume > 0 || gtk_toggle_tool_button_get_active (
338 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
339 priv->volume = volume;
341 /* Ensure that the toggle button is active if the volume is > 0 and inactive
342 * if it's smaller than 0 */
343 if ((volume > 0) != gtk_toggle_tool_button_get_active (
344 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
345 gtk_toggle_tool_button_set_active (
346 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
348 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
353 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
355 EmpathyCallWindow *self)
357 empathy_call_window_mic_volume_changed (self);
361 empathy_call_window_show_video_output (EmpathyCallWindow *self,
364 if (self->priv->video_output != NULL)
365 g_object_set (self->priv->video_output, "visible", show, NULL);
367 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
371 create_video_output_widget (EmpathyCallWindow *self)
373 EmpathyCallWindowPriv *priv = GET_PRIV (self);
375 g_assert (priv->video_output == NULL);
376 g_assert (priv->pipeline != NULL);
378 priv->video_output = clutter_texture_new ();
380 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
383 priv->video_output_sink = clutter_gst_video_sink_new (
384 CLUTTER_TEXTURE (priv->video_output));
386 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
389 gtk_widget_add_events (priv->video_container,
390 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
391 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
392 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
396 create_video_input (EmpathyCallWindow *self)
398 EmpathyCallWindowPriv *priv = GET_PRIV (self);
400 g_assert (priv->video_input == NULL);
401 priv->video_input = empathy_video_src_new ();
402 gst_object_ref (priv->video_input);
403 gst_object_sink (priv->video_input);
407 create_audio_input (EmpathyCallWindow *self)
409 EmpathyCallWindowPriv *priv = GET_PRIV (self);
411 g_assert (priv->audio_input == NULL);
412 priv->audio_input = empathy_audio_src_new ();
413 gst_object_ref (priv->audio_input);
414 gst_object_sink (priv->audio_input);
418 add_video_preview_to_pipeline (EmpathyCallWindow *self)
420 EmpathyCallWindowPriv *priv = GET_PRIV (self);
423 g_assert (priv->video_preview != NULL);
424 g_assert (priv->pipeline != NULL);
425 g_assert (priv->video_input != NULL);
426 g_assert (priv->video_tee != NULL);
428 preview = priv->video_preview_sink;
430 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
432 g_warning ("Could not add video input to pipeline");
436 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
438 g_warning ("Could not add video preview to pipeline");
442 if (!gst_element_link (priv->video_input, priv->video_tee))
444 g_warning ("Could not link video input to video tee");
448 if (!gst_element_link (priv->video_tee, preview))
450 g_warning ("Could not link video tee to video preview");
456 empathy_call_window_disable_camera_cb (GtkAction *action,
457 EmpathyCallWindow *self)
459 clutter_actor_destroy (self->priv->preview_hidden_button);
461 gtk_toggle_tool_button_set_active (
462 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
466 empathy_call_window_minimise_camera_cb (GtkAction *action,
467 EmpathyCallWindow *self)
469 clutter_actor_hide (self->priv->video_preview);
470 clutter_actor_show (self->priv->preview_hidden_button);
474 empathy_call_window_maximise_camera_cb (GtkAction *action,
475 EmpathyCallWindow *self)
477 clutter_actor_show (self->priv->video_preview);
478 clutter_actor_hide (self->priv->preview_hidden_button);
482 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
483 EmpathyCallWindow *self)
487 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
489 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
490 0, gtk_get_current_event_time ());
491 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
495 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
496 EmpathyCallWindow *self)
500 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
501 "/preview-hidden-menu");
502 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
503 0, gtk_get_current_event_time ());
504 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
508 create_video_preview (EmpathyCallWindow *self)
510 EmpathyCallWindowPriv *priv = GET_PRIV (self);
511 ClutterLayoutManager *layout, *layout_center;
512 ClutterActor *preview;
517 g_assert (priv->video_preview == NULL);
519 preview = clutter_texture_new ();
520 clutter_actor_set_size (preview,
521 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
522 priv->video_preview_sink = clutter_gst_video_sink_new (
523 CLUTTER_TEXTURE (preview));
525 /* Flip the video preview */
526 clutter_actor_set_rotation (preview,
529 SELF_VIDEO_SECTION_WIDTH * 0.5,
533 /* Add a little offset to the video preview */
534 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
535 CLUTTER_BIN_ALIGNMENT_START);
536 priv->video_preview = clutter_box_new (layout);
537 clutter_actor_set_size (priv->video_preview,
538 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
540 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
541 CLUTTER_BIN_ALIGNMENT_CENTER);
542 box = clutter_box_new (layout_center);
543 clutter_actor_set_size (box,
544 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
546 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
547 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
549 g_object_set (priv->video_preview_sink,
554 /* Translators: this is an "Info" label. It should be as short
556 button = gtk_button_new_with_label (_("i"));
557 b = gtk_clutter_actor_new_with_contents (button);
559 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
561 CLUTTER_BIN_ALIGNMENT_END,
562 CLUTTER_BIN_ALIGNMENT_END);
564 g_signal_connect (button, "clicked",
565 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
568 /* Translators: this is an "Info" label. It should be as short
570 button = gtk_button_new_with_label (_("i"));
571 priv->preview_hidden_button =
572 gtk_clutter_actor_new_with_contents (button);
574 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
575 priv->preview_hidden_button,
576 CLUTTER_BIN_ALIGNMENT_START,
577 CLUTTER_BIN_ALIGNMENT_END);
579 clutter_actor_hide (priv->preview_hidden_button);
581 g_signal_connect (button, "clicked",
582 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
585 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
587 CLUTTER_BIN_ALIGNMENT_START,
588 CLUTTER_BIN_ALIGNMENT_END);
592 play_camera (EmpathyCallWindow *window,
595 EmpathyCallWindowPriv *priv = GET_PRIV (window);
599 if (priv->video_preview == NULL)
601 create_video_preview (window);
602 add_video_preview_to_pipeline (window);
606 state = GST_STATE_PLAYING;
608 state = GST_STATE_NULL;
610 preview = priv->video_preview_sink;
612 gst_element_set_state (preview, state);
613 gst_element_set_state (priv->video_input, state);
614 gst_element_set_state (priv->video_tee, state);
618 display_video_preview (EmpathyCallWindow *self,
621 EmpathyCallWindowPriv *priv = GET_PRIV (self);
625 /* Display the video preview */
626 DEBUG ("Show video preview");
628 play_camera (self, TRUE);
629 clutter_actor_show (priv->video_preview);
633 /* Hide the video preview */
634 DEBUG ("Hide video preview");
636 if (priv->video_preview != NULL)
638 clutter_actor_hide (priv->video_preview);
639 play_camera (self, FALSE);
645 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
647 EmpathyCallWindowPriv *priv = GET_PRIV (window);
649 empathy_call_window_status_message (window, _("Connecting…"));
650 priv->call_state = CONNECTING;
653 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
654 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
658 disable_camera (EmpathyCallWindow *self)
660 EmpathyCallWindowPriv *priv = GET_PRIV (self);
662 if (priv->camera_state == CAMERA_STATE_OFF)
665 DEBUG ("Disable camera");
667 display_video_preview (self, FALSE);
669 if (priv->camera_state == CAMERA_STATE_ON)
670 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
672 priv->camera_state = CAMERA_STATE_OFF;
676 enable_camera (EmpathyCallWindow *self)
678 EmpathyCallWindowPriv *priv = GET_PRIV (self);
680 if (priv->camera_state == CAMERA_STATE_ON)
683 if (priv->video_input == NULL)
685 DEBUG ("Can't enable camera, no input");
689 DEBUG ("Enable camera");
691 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
693 priv->camera_state = CAMERA_STATE_ON;
697 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
698 EmpathyCallWindow *self)
700 if (gtk_toggle_tool_button_get_active (toggle))
701 enable_camera (self);
703 disable_camera (self);
707 create_pipeline (EmpathyCallWindow *self)
709 EmpathyCallWindowPriv *priv = GET_PRIV (self);
712 g_assert (priv->pipeline == NULL);
714 priv->pipeline = gst_pipeline_new (NULL);
715 priv->pipeline_playing = FALSE;
717 priv->video_tee = gst_element_factory_make ("tee", NULL);
718 gst_object_ref (priv->video_tee);
719 gst_object_sink (priv->video_tee);
721 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
723 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
724 priv->bus_message_source_id = gst_bus_add_watch (bus,
725 empathy_call_window_bus_message, self);
727 g_object_unref (bus);
731 empathy_call_window_configure_event_cb (GtkWidget *widget,
733 EmpathyCallWindow *self)
735 GdkWindow *gdk_window;
736 GdkWindowState window_state;
738 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
739 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
741 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
742 &self->priv->dialpad_width, NULL);
744 gdk_window = gtk_widget_get_window (widget);
745 window_state = gdk_window_get_state (gdk_window);
746 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
752 empathy_call_window_destroyed_cb (GtkWidget *object,
753 EmpathyCallWindow *self)
755 if (gtk_widget_get_visible (self->priv->dtmf_panel))
757 /* Save the geometry as if the dialpad was hidden. */
758 empathy_geometry_save_values (GTK_WINDOW (self),
759 self->priv->x, self->priv->y,
760 self->priv->w - self->priv->dialpad_width, self->priv->h,
761 self->priv->maximized);
766 empathy_call_window_init (EmpathyCallWindow *self)
768 EmpathyCallWindowPriv *priv;
772 ClutterConstraint *size_constraint;
773 ClutterActor *remote_avatar;
774 GtkStyleContext *context;
778 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
779 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
781 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
782 gui = empathy_builder_get_file (filename,
783 "call_window_vbox", &top_vbox,
784 "errors_vbox", &priv->errors_vbox,
786 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
787 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
788 "status_label", &priv->status_label,
789 "audiocall", &priv->audio_call_button,
790 "videocall", &priv->video_call_button,
791 "microphone", &priv->mic_button,
792 "camera", &priv->camera_button,
793 "hangup", &priv->hangup_button,
794 "dialpad", &priv->dialpad_button,
795 "toolbar", &priv->toolbar,
796 "bottom_toolbar", &priv->bottom_toolbar,
797 "ui_manager", &priv->ui_manager,
798 "menufullscreen", &priv->menu_fullscreen,
799 "details_vbox", &priv->details_vbox,
800 "vcodec_encoding_label", &priv->vcodec_encoding_label,
801 "acodec_encoding_label", &priv->acodec_encoding_label,
802 "acodec_decoding_label", &priv->acodec_decoding_label,
803 "vcodec_decoding_label", &priv->vcodec_decoding_label,
804 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
805 "audio_local_candidate_label", &priv->audio_local_candidate_label,
806 "video_remote_candidate_label", &priv->video_remote_candidate_label,
807 "video_local_candidate_label", &priv->video_local_candidate_label,
808 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
809 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
810 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
811 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
815 empathy_builder_connect (gui, self,
816 "menuhangup", "activate", empathy_call_window_hangup_cb,
817 "hangup", "clicked", empathy_call_window_hangup_cb,
818 "audiocall", "clicked", empathy_call_window_audio_call_cb,
819 "videocall", "clicked", empathy_call_window_video_call_cb,
820 "volume", "value-changed", empathy_call_window_volume_changed_cb,
821 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
822 "camera", "toggled", empathy_call_window_camera_toggled_cb,
823 "dialpad", "toggled", empathy_call_window_dialpad_cb,
824 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
825 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
826 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
827 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
830 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
832 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
834 g_object_bind_property (priv->camera_monitor, "available",
835 priv->camera_button, "sensitive",
836 G_BINDING_SYNC_CREATE);
838 priv->lock = g_mutex_new ();
840 gtk_container_add (GTK_CONTAINER (self), top_vbox);
842 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
843 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
844 CONTENT_HBOX_BORDER_WIDTH);
845 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
848 /* avatar/video box */
849 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
850 CLUTTER_BIN_ALIGNMENT_CENTER);
852 priv->video_box = clutter_box_new (priv->video_layout);
854 priv->video_container = gtk_clutter_embed_new ();
856 /* Set the background color to that of the rest of the window */
857 context = gtk_widget_get_style_context (priv->content_hbox);
858 gtk_style_context_get_background_color (context,
859 GTK_STATE_FLAG_NORMAL, &rgba);
860 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
861 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
862 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
863 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
864 clutter_stage_set_color (
865 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
866 GTK_CLUTTER_EMBED (priv->video_container))),
869 clutter_container_add (
870 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
871 GTK_CLUTTER_EMBED (priv->video_container))),
875 size_constraint = clutter_bind_constraint_new (
876 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
877 CLUTTER_BIND_SIZE, 0);
878 clutter_actor_add_constraint (priv->video_box, size_constraint);
880 priv->remote_user_avatar_widget = gtk_image_new ();
881 remote_avatar = gtk_clutter_actor_new_with_contents (
882 priv->remote_user_avatar_widget);
884 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
887 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
888 priv->video_container, TRUE, TRUE,
889 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
891 create_pipeline (self);
892 create_video_output_widget (self);
893 create_audio_input (self);
894 create_video_input (self);
896 /* The call will be started as soon the pipeline is playing */
897 priv->start_call_when_playing = TRUE;
899 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
900 G_CALLBACK (dtmf_button_pressed_cb),
901 G_CALLBACK (dtmf_button_released_cb));
903 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
906 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
909 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
911 gtk_widget_show_all (top_vbox);
913 gtk_widget_hide (priv->dtmf_panel);
914 gtk_widget_hide (priv->details_vbox);
916 priv->fullscreen = empathy_call_window_fullscreen_new (self);
918 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
919 priv->video_container);
921 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
922 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
924 g_signal_connect (G_OBJECT (self), "realize",
925 G_CALLBACK (empathy_call_window_realized_cb), self);
927 g_signal_connect (G_OBJECT (self), "delete-event",
928 G_CALLBACK (empathy_call_window_delete_cb), self);
930 g_signal_connect (G_OBJECT (self), "window-state-event",
931 G_CALLBACK (empathy_call_window_state_event_cb), self);
933 g_signal_connect (G_OBJECT (self), "key-press-event",
934 G_CALLBACK (empathy_call_window_key_press_cb), self);
936 priv->timer = g_timer_new ();
938 g_object_ref (priv->ui_manager);
939 g_object_unref (gui);
941 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
943 empathy_call_window_show_hangup_button (self, TRUE);
945 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
946 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
947 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
949 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
950 /* These signals are used to track the window position and save it
951 * when the window is destroyed. We need to do this as we don't want
952 * the window geometry to be saved with the dialpad taken into account. */
953 g_signal_connect (self, "destroy",
954 G_CALLBACK (empathy_call_window_destroyed_cb), self);
955 g_signal_connect (self, "configure-event",
956 G_CALLBACK (empathy_call_window_configure_event_cb), self);
957 g_signal_connect (self, "window-state-event",
958 G_CALLBACK (empathy_call_window_configure_event_cb), self);
961 /* Instead of specifying a width and a height, we specify only one size. That's
962 because we want a square avatar icon. */
964 init_contact_avatar_with_size (EmpathyContact *contact,
965 GtkWidget *image_widget,
968 GdkPixbuf *pixbuf_avatar = NULL;
972 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
976 if (pixbuf_avatar == NULL)
978 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
979 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
982 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
984 if (pixbuf_avatar != NULL)
985 g_object_unref (pixbuf_avatar);
989 set_window_title (EmpathyCallWindow *self)
991 EmpathyCallWindowPriv *priv = GET_PRIV (self);
994 if (priv->contact != NULL)
996 /* translators: Call is a noun and %s is the contact name. This string
997 * is used in the window title */
998 tmp = g_strdup_printf (_("Call with %s"),
999 empathy_contact_get_alias (priv->contact));
1000 gtk_window_set_title (GTK_WINDOW (self), tmp);
1005 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1010 set_remote_user_name (EmpathyCallWindow *self,
1011 EmpathyContact *contact)
1013 const gchar *alias = empathy_contact_get_alias (contact);
1014 const gchar *status = empathy_contact_get_status (contact);
1017 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1018 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1024 contact_name_changed_cb (EmpathyContact *contact,
1026 EmpathyCallWindow *self)
1028 set_window_title (self);
1029 set_remote_user_name (self, contact);
1033 contact_presence_changed_cb (EmpathyContact *contact,
1035 EmpathyCallWindow *self)
1037 set_remote_user_name (self, contact);
1041 contact_avatar_changed_cb (EmpathyContact *contact,
1043 EmpathyCallWindow *self)
1046 GtkAllocation allocation;
1047 GtkWidget *avatar_widget;
1049 avatar_widget = self->priv->remote_user_avatar_widget;
1051 gtk_widget_get_allocation (avatar_widget, &allocation);
1052 size = allocation.height;
1056 /* the widget is not allocated yet, set a default size */
1057 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1058 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1061 init_contact_avatar_with_size (contact, avatar_widget, size);
1063 avatar_widget = self->priv->remote_user_avatar_toolbar;
1065 gtk_widget_get_allocation (avatar_widget, &allocation);
1066 size = allocation.height;
1070 /* the widget is not allocated yet, set a default size */
1071 size = SMALL_TOOLBAR_SIZE;
1074 init_contact_avatar_with_size (contact, avatar_widget, size);
1078 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1079 EmpathyCallHandler *handler)
1081 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1083 tp_g_signal_connect_object (priv->contact, "notify::name",
1084 G_CALLBACK (contact_name_changed_cb), self, 0);
1085 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1086 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1087 tp_g_signal_connect_object (priv->contact, "notify::presence",
1088 G_CALLBACK (contact_presence_changed_cb), self, 0);
1090 set_window_title (self);
1091 set_remote_user_name (self, priv->contact);
1093 init_contact_avatar_with_size (priv->contact,
1094 priv->remote_user_avatar_widget,
1095 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1096 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1098 init_contact_avatar_with_size (priv->contact,
1099 priv->remote_user_avatar_toolbar,
1100 SMALL_TOOLBAR_SIZE);
1102 /* The remote avatar is shown by default and will be hidden when we receive
1103 video from the remote side. */
1104 clutter_actor_hide (priv->video_output);
1105 gtk_widget_show (priv->remote_user_avatar_widget);
1109 update_send_codec (EmpathyCallWindow *self,
1112 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1119 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1120 widget = priv->acodec_encoding_label;
1124 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1125 widget = priv->vcodec_encoding_label;
1131 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1132 gtk_label_set_text (GTK_LABEL (widget), tmp);
1137 send_audio_codec_notify_cb (GObject *object,
1141 EmpathyCallWindow *self = user_data;
1143 update_send_codec (self, TRUE);
1147 send_video_codec_notify_cb (GObject *object,
1151 EmpathyCallWindow *self = user_data;
1153 update_send_codec (self, FALSE);
1157 update_recv_codec (EmpathyCallWindow *self,
1160 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1163 GString *str = NULL;
1167 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1168 widget = priv->acodec_decoding_label;
1172 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1173 widget = priv->vcodec_decoding_label;
1179 for (l = codecs; l != NULL; l = g_list_next (l))
1181 FsCodec *codec = l->data;
1184 str = g_string_new (NULL);
1186 g_string_append (str, ", ");
1188 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1192 gtk_label_set_text (GTK_LABEL (widget), str->str);
1193 g_string_free (str, TRUE);
1197 recv_audio_codecs_notify_cb (GObject *object,
1201 EmpathyCallWindow *self = user_data;
1203 update_recv_codec (self, TRUE);
1207 recv_video_codecs_notify_cb (GObject *object,
1211 EmpathyCallWindow *self = user_data;
1213 update_recv_codec (self, FALSE);
1216 static const gchar *
1217 candidate_type_to_str (FsCandidate *candidate)
1219 switch (candidate->type)
1221 case FS_CANDIDATE_TYPE_HOST:
1223 case FS_CANDIDATE_TYPE_SRFLX:
1224 return "server reflexive";
1225 case FS_CANDIDATE_TYPE_PRFLX:
1226 return "peer reflexive";
1227 case FS_CANDIDATE_TYPE_RELAY:
1229 case FS_CANDIDATE_TYPE_MULTICAST:
1236 static const gchar *
1237 candidate_type_to_desc (FsCandidate *candidate)
1239 switch (candidate->type)
1241 case FS_CANDIDATE_TYPE_HOST:
1242 return _("The IP address as seen by the machine");
1243 case FS_CANDIDATE_TYPE_SRFLX:
1244 return _("The IP address as seen by a server on the Internet");
1245 case FS_CANDIDATE_TYPE_PRFLX:
1246 return _("The IP address of the peer as seen by the other side");
1247 case FS_CANDIDATE_TYPE_RELAY:
1248 return _("The IP address of a relay server");
1249 case FS_CANDIDATE_TYPE_MULTICAST:
1250 return _("The IP address of the multicast group");
1257 update_candidat_widget (EmpathyCallWindow *self,
1260 FsCandidate *candidate)
1264 g_assert (candidate != NULL);
1265 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1266 candidate->port, candidate_type_to_str (candidate));
1268 gtk_label_set_text (GTK_LABEL (label), str);
1269 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1275 candidates_changed_cb (GObject *object,
1277 EmpathyCallWindow *self)
1279 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1280 FsCandidate *candidate = NULL;
1282 if (type == FS_MEDIA_TYPE_VIDEO)
1284 /* Update remote candidate */
1285 candidate = empathy_call_handler_get_video_remote_candidate (
1288 update_candidat_widget (self, priv->video_remote_candidate_label,
1289 priv->video_remote_candidate_info_img, candidate);
1291 /* Update local candidate */
1292 candidate = empathy_call_handler_get_video_local_candidate (
1295 update_candidat_widget (self, priv->video_local_candidate_label,
1296 priv->video_local_candidate_info_img, candidate);
1300 /* Update remote candidate */
1301 candidate = empathy_call_handler_get_audio_remote_candidate (
1304 update_candidat_widget (self, priv->audio_remote_candidate_label,
1305 priv->audio_remote_candidate_info_img, candidate);
1307 /* Update local candidate */
1308 candidate = empathy_call_handler_get_audio_local_candidate (
1311 update_candidat_widget (self, priv->audio_local_candidate_label,
1312 priv->audio_local_candidate_info_img, candidate);
1317 empathy_call_window_constructed (GObject *object)
1319 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1320 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1321 TpyCallChannel *call;
1323 g_assert (priv->handler != NULL);
1325 g_object_get (priv->handler, "call-channel", &call, NULL);
1326 priv->outgoing = (call == NULL);
1328 g_object_unref (call);
1330 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1331 g_assert (priv->contact != NULL);
1333 empathy_call_window_setup_avatars (self, priv->handler);
1334 empathy_call_window_set_state_connecting (self);
1336 if (!empathy_call_handler_has_initial_video (priv->handler))
1338 gtk_toggle_tool_button_set_active (
1339 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1341 /* If call has InitialVideo, the preview will be started once the call has
1342 * been started (start_call()). */
1344 update_send_codec (self, TRUE);
1345 update_send_codec (self, FALSE);
1346 update_recv_codec (self, TRUE);
1347 update_recv_codec (self, FALSE);
1349 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1350 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1351 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1352 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1353 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1354 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1355 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1356 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1358 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1359 G_CALLBACK (candidates_changed_cb), self, 0);
1362 static void empathy_call_window_dispose (GObject *object);
1363 static void empathy_call_window_finalize (GObject *object);
1366 empathy_call_window_set_property (GObject *object,
1367 guint property_id, const GValue *value, GParamSpec *pspec)
1369 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1371 switch (property_id)
1373 case PROP_CALL_HANDLER:
1374 priv->handler = g_value_dup_object (value);
1377 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1382 empathy_call_window_get_property (GObject *object,
1383 guint property_id, GValue *value, GParamSpec *pspec)
1385 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1387 switch (property_id)
1389 case PROP_CALL_HANDLER:
1390 g_value_set_object (value, priv->handler);
1393 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1398 empathy_call_window_class_init (
1399 EmpathyCallWindowClass *empathy_call_window_class)
1401 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1402 GParamSpec *param_spec;
1404 g_type_class_add_private (empathy_call_window_class,
1405 sizeof (EmpathyCallWindowPriv));
1407 object_class->constructed = empathy_call_window_constructed;
1408 object_class->set_property = empathy_call_window_set_property;
1409 object_class->get_property = empathy_call_window_get_property;
1411 object_class->dispose = empathy_call_window_dispose;
1412 object_class->finalize = empathy_call_window_finalize;
1414 param_spec = g_param_spec_object ("handler",
1415 "handler", "The call handler",
1416 EMPATHY_TYPE_CALL_HANDLER,
1417 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1418 g_object_class_install_property (object_class,
1419 PROP_CALL_HANDLER, param_spec);
1423 empathy_call_window_dispose (GObject *object)
1425 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1428 if (priv->dispose_has_run)
1431 priv->dispose_has_run = TRUE;
1433 if (priv->handler != NULL)
1435 empathy_call_handler_stop_call (priv->handler);
1436 tp_clear_object (&priv->handler);
1439 if (priv->bus_message_source_id != 0)
1441 g_source_remove (priv->bus_message_source_id);
1442 priv->bus_message_source_id = 0;
1445 if (priv->got_video_src > 0)
1447 g_source_remove (priv->got_video_src);
1448 priv->got_video_src = 0;
1451 tp_clear_object (&priv->pipeline);
1452 tp_clear_object (&priv->video_input);
1453 tp_clear_object (&priv->audio_input);
1454 tp_clear_object (&priv->video_tee);
1455 tp_clear_object (&priv->ui_manager);
1456 tp_clear_object (&priv->fullscreen);
1457 tp_clear_object (&priv->camera_monitor);
1458 tp_clear_object (&priv->settings);
1460 g_list_free_full (priv->notifiers, g_object_unref);
1462 if (priv->timer_id != 0)
1463 g_source_remove (priv->timer_id);
1466 if (priv->contact != NULL)
1468 g_signal_handlers_disconnect_by_func (priv->contact,
1469 contact_name_changed_cb, self);
1470 priv->contact = NULL;
1474 tp_clear_object (&priv->sound_mgr);
1476 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1480 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1482 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1484 if (priv->video_output_motion_handler_id != 0)
1486 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1487 priv->video_output_motion_handler_id);
1488 priv->video_output_motion_handler_id = 0;
1493 empathy_call_window_finalize (GObject *object)
1495 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1496 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1498 disconnect_video_output_motion_handler (self);
1500 /* free any data held directly by the object here */
1501 g_mutex_free (priv->lock);
1503 g_timer_destroy (priv->timer);
1505 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1510 empathy_call_window_new (EmpathyCallHandler *handler)
1512 return EMPATHY_CALL_WINDOW (
1513 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1517 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1518 GstElement *conference, gpointer user_data)
1520 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1522 FsElementAddedNotifier *notifier;
1525 DEBUG ("Conference added");
1527 /* Add notifier to set the various element properties as needed */
1528 notifier = fs_element_added_notifier_new ();
1529 keyfile = fs_utils_get_default_element_properties (conference);
1531 if (keyfile != NULL)
1532 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1534 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1536 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1538 gst_bin_add (GST_BIN (priv->pipeline), conference);
1539 gst_element_set_state (conference, GST_STATE_PLAYING);
1543 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1544 GstElement *conference, gpointer user_data)
1546 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1547 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1549 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1550 gst_element_set_state (conference, GST_STATE_NULL);
1554 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1556 GstStateChangeReturn state_change_return;
1557 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1559 if (priv->pipeline == NULL)
1562 if (priv->bus_message_source_id != 0)
1564 g_source_remove (priv->bus_message_source_id);
1565 priv->bus_message_source_id = 0;
1568 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1570 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1571 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1573 if (priv->pipeline != NULL)
1574 g_object_unref (priv->pipeline);
1575 priv->pipeline = NULL;
1577 if (priv->audio_output != NULL)
1578 g_object_unref (priv->audio_output);
1579 priv->audio_output = NULL;
1581 if (priv->video_tee != NULL)
1582 g_object_unref (priv->video_tee);
1583 priv->video_tee = NULL;
1585 if (priv->video_preview != NULL)
1586 clutter_actor_destroy (priv->video_preview);
1587 priv->video_preview = NULL;
1589 priv->funnel = NULL;
1591 create_pipeline (self);
1592 /* Call will be started when user will hit the 'redial' button */
1593 priv->start_call_when_playing = FALSE;
1594 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1600 g_message ("Error: could not destroy pipeline. Closing call window");
1601 gtk_widget_destroy (GTK_WIDGET (self));
1608 reset_details_pane (EmpathyCallWindow *self)
1610 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1612 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1613 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1614 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1615 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1619 empathy_call_window_disconnected (EmpathyCallWindow *self,
1622 gboolean could_disconnect = FALSE;
1623 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1624 gboolean could_reset_pipeline;
1626 /* Leave full screen mode if needed */
1627 gtk_window_unfullscreen (GTK_WINDOW (self));
1629 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1630 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1632 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1634 if (priv->call_state == CONNECTING)
1635 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1637 if (priv->call_state != REDIALING)
1638 priv->call_state = DISCONNECTED;
1640 if (could_reset_pipeline)
1642 g_mutex_lock (priv->lock);
1644 g_timer_stop (priv->timer);
1646 if (priv->timer_id != 0)
1647 g_source_remove (priv->timer_id);
1650 g_mutex_unlock (priv->lock);
1653 /* We are about to destroy the window, no need to update it or create
1654 * a video preview */
1657 empathy_call_window_status_message (self, _("Disconnected"));
1659 empathy_call_window_show_hangup_button (self, FALSE);
1661 /* Unsensitive the camera and mic button */
1662 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1663 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1665 /* Be sure that the mic button is enabled */
1666 gtk_toggle_tool_button_set_active (
1667 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1669 if (priv->camera_state == CAMERA_STATE_ON)
1671 /* Restart the preview with the new pipeline. */
1672 display_video_preview (self, TRUE);
1675 /* destroy the video output; it will be recreated when we'll redial */
1676 disconnect_video_output_motion_handler (self);
1677 if (priv->video_output != NULL)
1678 clutter_actor_destroy (priv->video_output);
1679 priv->video_output = NULL;
1680 if (priv->got_video_src > 0)
1682 g_source_remove (priv->got_video_src);
1683 priv->got_video_src = 0;
1686 gtk_widget_show (priv->remote_user_avatar_widget);
1688 reset_details_pane (self);
1690 priv->sending_video = FALSE;
1691 priv->call_started = FALSE;
1693 could_disconnect = TRUE;
1695 /* TODO: display the self avatar of the preview (depends if the "Always
1696 * Show Video Preview" is enabled or not) */
1699 return could_disconnect;
1704 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1707 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1708 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1710 if (empathy_call_window_disconnected (self, TRUE) &&
1711 priv->call_state == REDIALING)
1712 empathy_call_window_restart_call (self);
1716 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1718 FsMediaType media_type,
1719 EmpathyCallWindow *self)
1721 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1723 DEBUG ("removing content");
1726 * This assumes that there is only one video stream per channel...
1729 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1731 if (priv->funnel != NULL)
1735 output = priv->video_output_sink;
1737 gst_element_set_state (output, GST_STATE_NULL);
1738 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1740 gst_bin_remove (GST_BIN (priv->pipeline), output);
1741 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1742 priv->funnel = NULL;
1746 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1748 if (priv->audio_output != NULL)
1750 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1752 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1753 priv->audio_output = NULL;
1761 /* Called with global lock held */
1763 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1765 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1769 if (priv->funnel == NULL)
1771 output = priv->video_output_sink;
1773 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1777 g_warning ("Could not create fsfunnel");
1781 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1783 gst_object_unref (priv->funnel);
1784 priv->funnel = NULL;
1785 g_warning ("Could not add funnel to pipeline");
1789 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1791 g_warning ("Could not add the video output widget to the pipeline");
1795 if (!gst_element_link (priv->funnel, output))
1797 g_warning ("Could not link output sink to funnel");
1798 goto error_output_added;
1801 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1803 g_warning ("Could not start video sink");
1804 goto error_output_added;
1807 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1809 g_warning ("Could not start funnel");
1810 goto error_output_added;
1814 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1817 g_warning ("Could not get request pad from funnel");
1824 gst_element_set_locked_state (priv->funnel, TRUE);
1825 gst_element_set_locked_state (output, TRUE);
1827 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1828 gst_element_set_state (output, GST_STATE_NULL);
1830 gst_bin_remove (GST_BIN (priv->pipeline), output);
1831 gst_element_set_locked_state (output, FALSE);
1835 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1836 priv->funnel = NULL;
1841 /* Called with global lock held */
1843 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1845 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1847 GstPadTemplate *template;
1849 if (priv->audio_output == NULL)
1851 priv->audio_output = empathy_audio_sink_new ();
1852 g_object_ref_sink (priv->audio_output);
1854 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1856 g_warning ("Could not add audio sink to pipeline");
1857 g_object_unref (priv->audio_output);
1858 goto error_add_output;
1861 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1863 g_warning ("Could not start audio sink");
1868 template = gst_element_class_get_pad_template (
1869 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
1871 pad = gst_element_request_pad (priv->audio_output,
1872 template, NULL, NULL);
1876 g_warning ("Could not get sink pad from sink");
1883 gst_element_set_locked_state (priv->audio_output, TRUE);
1884 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1885 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1886 priv->audio_output = NULL;
1894 empathy_call_window_update_timer (gpointer user_data)
1896 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1897 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1901 time_ = g_timer_elapsed (priv->timer, NULL);
1903 /* Translators: 'status - minutes:seconds' the caller has been connected */
1904 str = g_strdup_printf (_("%s — %d:%02dm"),
1905 priv->call_state == HELD ? _("On hold") : _("Connected"),
1906 (int) time_ / 60, (int) time_ % 60);
1907 empathy_call_window_status_message (self, str);
1915 display_error (EmpathyCallWindow *self,
1916 TpyCallChannel *call,
1920 const gchar *details)
1922 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1923 GtkWidget *info_bar;
1924 GtkWidget *content_area;
1931 /* Create info bar */
1932 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1935 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1937 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1939 /* hbox containing the image and the messages vbox */
1940 hbox = gtk_hbox_new (FALSE, 3);
1941 gtk_container_add (GTK_CONTAINER (content_area), hbox);
1944 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
1945 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1947 /* vbox containing the main message and the details expander */
1948 vbox = gtk_vbox_new (FALSE, 3);
1949 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
1952 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
1954 label = gtk_label_new (NULL);
1955 gtk_label_set_markup (GTK_LABEL (label), txt);
1956 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1957 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1960 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
1963 if (details != NULL)
1965 GtkWidget *expander;
1967 expander = gtk_expander_new (_("Technical Details"));
1969 txt = g_strdup_printf ("<i>%s</i>", details);
1971 label = gtk_label_new (NULL);
1972 gtk_label_set_markup (GTK_LABEL (label), txt);
1973 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1974 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
1977 gtk_container_add (GTK_CONTAINER (expander), label);
1978 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
1981 g_signal_connect (info_bar, "response",
1982 G_CALLBACK (gtk_widget_destroy), NULL);
1984 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
1985 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1986 gtk_widget_show_all (info_bar);
1990 media_stream_error_to_txt (EmpathyCallWindow *self,
1991 TpyCallChannel *call,
1993 TpMediaStreamError error)
1995 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1996 const gchar *cm = NULL;
2002 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2004 return g_strdup_printf (
2005 _("%s's software does not understand any of the audio formats "
2006 "supported by your computer"),
2007 empathy_contact_get_alias (priv->contact));
2009 return g_strdup_printf (
2010 _("%s's software does not understand any of the video formats "
2011 "supported by your computer"),
2012 empathy_contact_get_alias (priv->contact));
2014 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2015 return g_strdup_printf (
2016 _("Can't establish a connection to %s. "
2017 "One of you might be on a network that does not allow "
2018 "direct connections."),
2019 empathy_contact_get_alias (priv->contact));
2021 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2022 return g_strdup (_("There was a failure on the network"));
2024 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2026 return g_strdup (_("The audio formats necessary for this call "
2027 "are not installed on your computer"));
2029 return g_strdup (_("The video formats necessary for this call "
2030 "are not installed on your computer"));
2032 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2033 tp_connection_parse_object_path (
2034 tp_channel_borrow_connection (TP_CHANNEL (call)),
2037 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2038 "product=Telepathy&component=%s", cm);
2040 result = g_strdup_printf (
2041 _("Something unexpected happened in a Telepathy component. "
2042 "Please <a href=\"%s\">report this bug</a> and attach "
2043 "logs gathered from the 'Debug' window in the Help menu."), url);
2049 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2050 return g_strdup (_("There was a failure in the call engine"));
2052 case TP_MEDIA_STREAM_ERROR_EOS:
2053 return g_strdup (_("The end of the stream was reached"));
2055 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2062 empathy_call_window_stream_error (EmpathyCallWindow *self,
2063 TpyCallChannel *call,
2072 desc = media_stream_error_to_txt (self, call, audio, code);
2075 /* No description, use the error message. That's not great as it's not
2076 * localized but it's better than nothing. */
2077 display_error (self, call, icon, title, msg, NULL);
2081 display_error (self, call, icon, title, desc, msg);
2087 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2090 EmpathyCallWindow *self)
2092 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2093 "gnome-stock-mic", _("Can't establish audio stream"));
2097 empathy_call_window_video_stream_error (TpyCallChannel *call,
2100 EmpathyCallWindow *self)
2102 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2103 "camera-web", _("Can't establish video stream"));
2108 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2110 EmpathyCallWindow *self)
2112 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2113 TpyCallChannel *call;
2114 gboolean can_send_video;
2116 if (state != TPY_CALL_STATE_ACCEPTED)
2119 if (priv->call_state == CONNECTED)
2122 g_timer_start (priv->timer);
2123 priv->call_state = CONNECTED;
2125 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2127 can_send_video = priv->video_input != NULL &&
2128 empathy_contact_can_voip_video (priv->contact) &&
2129 empathy_camera_monitor_get_available (priv->camera_monitor);
2131 g_object_get (priv->handler, "call-channel", &call, NULL);
2133 if (tpy_call_channel_has_dtmf (call))
2134 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2136 if (priv->video_input == NULL)
2137 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2139 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2141 empathy_call_window_show_hangup_button (self, TRUE);
2143 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2145 clutter_actor_hide (priv->video_output);
2146 gtk_widget_show (priv->remote_user_avatar_widget);
2148 g_object_unref (call);
2150 g_mutex_lock (priv->lock);
2152 priv->timer_id = g_timeout_add_seconds (1,
2153 empathy_call_window_update_timer, self);
2155 g_mutex_unlock (priv->lock);
2157 empathy_call_window_update_timer (self);
2159 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2163 empathy_call_window_show_video_output_cb (gpointer user_data)
2165 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2167 if (self->priv->video_output != NULL)
2169 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2170 clutter_actor_show (self->priv->video_output);
2177 empathy_call_window_check_video_cb (gpointer data)
2179 EmpathyCallWindow *self = data;
2181 if (self->priv->got_video)
2183 self->priv->got_video = FALSE;
2187 /* No video in the last N seconds, display the remote avatar */
2188 empathy_call_window_show_video_output (self, FALSE);
2193 /* Called from the streaming thread */
2195 empathy_call_window_video_probe_cb (GstPad *pad,
2196 GstMiniObject *mini_obj,
2197 EmpathyCallWindow *self)
2200 if (GST_IS_EVENT (mini_obj))
2203 if (G_UNLIKELY (!self->priv->got_video))
2205 /* show the remote video */
2206 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2207 empathy_call_window_show_video_output_cb,
2208 g_object_ref (self), g_object_unref);
2210 self->priv->got_video = TRUE;
2216 /* Called from the streaming thread */
2218 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2219 GstPad *src, guint media_type, gpointer user_data)
2221 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2222 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2223 gboolean retval = FALSE;
2227 g_mutex_lock (priv->lock);
2231 case TP_MEDIA_STREAM_TYPE_AUDIO:
2232 pad = empathy_call_window_get_audio_sink_pad (self);
2234 case TP_MEDIA_STREAM_TYPE_VIDEO:
2235 g_idle_add (empathy_call_window_show_video_output_cb, self);
2236 pad = empathy_call_window_get_video_sink_pad (self);
2238 gst_pad_add_data_probe (src,
2239 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2240 if (priv->got_video_src > 0)
2241 g_source_remove (priv->got_video_src);
2242 priv->got_video_src = g_timeout_add_seconds (5,
2243 empathy_call_window_check_video_cb, self);
2246 g_assert_not_reached ();
2252 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2253 g_warning ("Could not link %s sink pad",
2254 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2258 gst_object_unref (pad);
2262 /* If no sink could be linked, try to add fakesink to prevent the whole call
2267 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2269 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2271 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2272 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2273 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2275 gst_element_set_locked_state (fakesink, TRUE);
2276 gst_element_set_state (fakesink, GST_STATE_NULL);
2277 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2281 DEBUG ("Could not link real sink, linked fakesink instead");
2283 gst_object_unref (sinkpad);
2287 gst_object_unref (fakesink);
2292 g_mutex_unlock (priv->lock);
2298 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2299 GstPad *sink, FsMediaType media_type, gpointer user_data)
2301 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2302 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2304 gboolean retval = FALSE;
2308 case FS_MEDIA_TYPE_AUDIO:
2309 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2311 g_warning ("Could not add audio source to pipeline");
2315 pad = gst_element_get_static_pad (priv->audio_input, "src");
2318 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2319 g_warning ("Could not get source pad from audio source");
2323 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2325 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2326 g_warning ("Could not link audio source to farsight");
2330 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2332 g_warning ("Could not start audio source");
2333 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2334 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2340 case FS_MEDIA_TYPE_VIDEO:
2341 if (priv->video_tee != NULL)
2343 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2344 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2346 g_warning ("Could not link video source input pipeline");
2349 gst_object_unref (pad);
2355 g_assert_not_reached ();
2362 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2364 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2365 GstElement *preview;
2367 disable_camera (self);
2369 DEBUG ("remove video input");
2370 preview = priv->video_preview_sink;
2372 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2373 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2374 gst_element_set_state (preview, GST_STATE_NULL);
2376 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2379 g_object_unref (priv->video_input);
2380 priv->video_input = NULL;
2381 g_object_unref (priv->video_tee);
2382 priv->video_tee = NULL;
2383 clutter_actor_destroy (priv->video_preview);
2384 priv->video_preview = NULL;
2386 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2390 start_call (EmpathyCallWindow *self)
2392 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2394 priv->call_started = TRUE;
2395 empathy_call_handler_start_call (priv->handler,
2396 gtk_get_current_event_time ());
2398 if (empathy_call_handler_has_initial_video (priv->handler))
2400 TpyCallChannel *call;
2403 g_object_get (priv->handler, "call-channel", &call, NULL);
2404 s = tpy_call_channel_get_video_state (call);
2406 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2407 s == TPY_SENDING_STATE_SENDING)
2409 /* Enable 'send video' buttons and display the preview */
2410 gtk_toggle_tool_button_set_active (
2411 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2415 gtk_toggle_tool_button_set_active (
2416 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2418 if (priv->video_preview == NULL)
2420 create_video_preview (self);
2421 add_video_preview_to_pipeline (self);
2425 g_object_unref (call);
2430 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2433 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2434 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2437 empathy_call_handler_bus_message (priv->handler, bus, message);
2439 switch (GST_MESSAGE_TYPE (message))
2441 case GST_MESSAGE_STATE_CHANGED:
2442 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2444 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2446 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2447 !priv->call_started)
2449 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2450 if (newstate == GST_STATE_PAUSED)
2452 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2453 priv->pipeline_playing = TRUE;
2455 if (priv->start_call_when_playing)
2460 case GST_MESSAGE_ERROR:
2462 GError *error = NULL;
2463 GstElement *gst_error;
2466 gst_message_parse_error (message, &error, &debug);
2467 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2469 g_message ("Element error: %s -- %s\n", error->message, debug);
2471 if (g_str_has_prefix (gst_element_get_name (gst_error),
2472 VIDEO_INPUT_ERROR_PREFIX))
2474 /* Remove the video input and continue */
2475 if (priv->video_input != NULL)
2476 empathy_call_window_remove_video_input (self);
2477 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2481 empathy_call_window_disconnected (self, TRUE);
2483 g_error_free (error);
2486 case GST_MESSAGE_UNKNOWN:
2487 case GST_MESSAGE_EOS:
2488 case GST_MESSAGE_WARNING:
2489 case GST_MESSAGE_INFO:
2490 case GST_MESSAGE_TAG:
2491 case GST_MESSAGE_BUFFERING:
2492 case GST_MESSAGE_STATE_DIRTY:
2493 case GST_MESSAGE_STEP_DONE:
2494 case GST_MESSAGE_CLOCK_PROVIDE:
2495 case GST_MESSAGE_CLOCK_LOST:
2496 case GST_MESSAGE_NEW_CLOCK:
2497 case GST_MESSAGE_STRUCTURE_CHANGE:
2498 case GST_MESSAGE_STREAM_STATUS:
2499 case GST_MESSAGE_APPLICATION:
2500 case GST_MESSAGE_ELEMENT:
2501 case GST_MESSAGE_SEGMENT_START:
2502 case GST_MESSAGE_SEGMENT_DONE:
2503 case GST_MESSAGE_DURATION:
2504 case GST_MESSAGE_ANY:
2513 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2514 GHashTable *members,
2515 EmpathyCallWindow *self)
2517 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2518 GHashTableIter iter;
2519 gpointer key, value;
2520 gboolean held = FALSE;
2522 g_hash_table_iter_init (&iter, members);
2523 while (g_hash_table_iter_next (&iter, &key, &value))
2525 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2527 /* This assumes this is a 1-1 call, otherwise one participant
2528 * putting the call on hold wouldn't mean the call is on hold
2536 priv->call_state = HELD;
2537 else if (priv->call_state == HELD)
2538 priv->call_state = CONNECTED;
2542 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2544 EmpathyCallWindow *self)
2546 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2547 TpyCallChannel *call;
2549 g_object_get (priv->handler, "call-channel", &call, NULL);
2554 tp_g_signal_connect_object (call, "audio-stream-error",
2555 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2556 tp_g_signal_connect_object (call, "video-stream-error",
2557 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2560 tp_g_signal_connect_object (call, "members-changed",
2561 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2563 g_object_unref (call);
2567 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2569 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2570 TpyCallChannel *call;
2573 /* Make the hangup button twice as wide */
2574 width = gtk_widget_get_allocated_width (priv->hangup_button);
2575 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2577 g_signal_connect (priv->handler, "state-changed",
2578 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2579 g_signal_connect (priv->handler, "conference-added",
2580 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2581 g_signal_connect (priv->handler, "conference-removed",
2582 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2583 g_signal_connect (priv->handler, "closed",
2584 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2585 g_signal_connect (priv->handler, "src-pad-added",
2586 G_CALLBACK (empathy_call_window_src_added_cb), window);
2587 g_signal_connect (priv->handler, "sink-pad-added",
2588 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2589 g_signal_connect (priv->handler, "sink-pad-removed",
2590 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2592 g_object_get (priv->handler, "call-channel", &call, NULL);
2595 call_handler_notify_call_cb (priv->handler, NULL, window);
2596 g_object_unref (call);
2600 /* call-channel doesn't exist yet, we'll connect signals once it has been
2602 g_signal_connect (priv->handler, "notify::call-channel",
2603 G_CALLBACK (call_handler_notify_call_cb), window);
2606 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2610 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2611 EmpathyCallWindow *window)
2613 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2615 if (priv->pipeline != NULL)
2617 if (priv->bus_message_source_id != 0)
2619 g_source_remove (priv->bus_message_source_id);
2620 priv->bus_message_source_id = 0;
2623 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2626 if (priv->call_state == CONNECTING)
2627 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2633 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2636 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2638 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2643 gtk_widget_hide (priv->dtmf_panel);
2644 gtk_widget_hide (menu);
2645 gtk_widget_hide (priv->toolbar);
2649 if (priv->dialpad_was_visible_before_fs)
2650 gtk_widget_show (priv->dtmf_panel);
2652 gtk_widget_show (menu);
2653 gtk_widget_show (priv->toolbar);
2655 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2656 priv->original_height_before_fs);
2661 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2663 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2665 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2666 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2667 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2668 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2670 if (priv->video_output != NULL)
2673 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2674 priv->video_output, TRUE, TRUE,
2675 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2682 empathy_call_window_state_event_cb (GtkWidget *widget,
2683 GdkEventWindowState *event, EmpathyCallWindow *window)
2685 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2687 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2688 gboolean set_fullscreen = event->new_window_state &
2689 GDK_WINDOW_STATE_FULLSCREEN;
2693 gboolean dialpad_was_visible;
2694 GtkAllocation allocation;
2695 gint original_width, original_height;
2697 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2698 original_width = allocation.width;
2699 original_height = allocation.height;
2701 g_object_get (priv->dtmf_panel,
2702 "visible", &dialpad_was_visible,
2705 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2706 priv->original_width_before_fs = original_width;
2707 priv->original_height_before_fs = original_height;
2709 if (priv->video_output_motion_handler_id == 0 &&
2710 priv->video_output != NULL)
2712 priv->video_output_motion_handler_id = g_signal_connect (
2713 G_OBJECT (priv->video_container), "motion-notify-event",
2714 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2720 disconnect_video_output_motion_handler (window);
2723 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2725 show_controls (window, set_fullscreen);
2726 show_borders (window, set_fullscreen);
2727 gtk_action_set_stock_id (priv->menu_fullscreen,
2728 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2729 priv->is_fullscreen = set_fullscreen;
2736 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2739 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2740 int w, h, dialpad_width;
2741 GtkAllocation allocation;
2743 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2744 w = allocation.width;
2745 h = allocation.height;
2747 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2751 gtk_widget_show (priv->dtmf_panel);
2757 gtk_widget_hide (priv->dtmf_panel);
2761 gtk_window_resize (GTK_WINDOW (window), w, h);
2765 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2768 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2769 TpyCallChannel *call;
2771 priv->sending_video = (state == CAMERA_STATE_ON);
2773 if (state == CAMERA_STATE_ON)
2775 /* When we start sending video, we want to show the video preview by
2777 display_video_preview (window, TRUE);
2781 display_video_preview (window, FALSE);
2784 if (priv->call_state != CONNECTED)
2787 g_object_get (priv->handler, "call-channel", &call, NULL);
2788 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2789 tpy_call_channel_send_video (call, priv->sending_video);
2790 g_object_unref (call);
2794 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2795 EmpathyCallWindow *window)
2797 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2800 active = (gtk_toggle_tool_button_get_active (toggle));
2804 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2805 priv->volume * 100);
2809 /* TODO, Instead of setting the input volume to 0 we should probably
2810 * stop sending but this would cause the audio call to drop if both
2811 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2812 * in the future. GNOME #574574
2814 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2820 empathy_call_window_hangup_cb (gpointer object,
2821 EmpathyCallWindow *window)
2823 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2825 empathy_call_handler_stop_call (priv->handler);
2827 if (empathy_call_window_disconnected (window, FALSE))
2828 gtk_widget_destroy (GTK_WIDGET (window));
2832 empathy_call_window_restart_call (EmpathyCallWindow *window)
2834 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2836 /* Remove error info bars */
2837 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
2838 (GtkCallback) gtk_widget_destroy, NULL);
2840 create_video_output_widget (window);
2842 /* While the call was disconnected, the input volume might have changed.
2843 * However, since the audio_input source was destroyed, its volume has not
2844 * been updated during that time. That's why we manually update it here */
2845 empathy_call_window_mic_volume_changed (window);
2847 priv->outgoing = TRUE;
2848 empathy_call_window_set_state_connecting (window);
2850 if (priv->pipeline_playing)
2851 start_call (window);
2853 /* call will be started when the pipeline is ready */
2854 priv->start_call_when_playing = TRUE;
2856 empathy_call_window_setup_avatars (window, priv->handler);
2858 empathy_call_window_show_hangup_button (window, TRUE);
2862 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
2863 EmpathyCallWindow *window)
2867 active = gtk_toggle_tool_button_get_active (button);
2869 empathy_call_window_show_dialpad (window, active);
2873 empathy_call_window_fullscreen_cb (gpointer object,
2874 EmpathyCallWindow *window)
2876 empathy_call_window_fullscreen_toggle (window);
2880 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2882 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2884 if (priv->is_fullscreen)
2885 gtk_window_unfullscreen (GTK_WINDOW (window));
2887 gtk_window_fullscreen (GTK_WINDOW (window));
2891 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
2892 GdkEventButton *event, EmpathyCallWindow *window)
2894 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2896 empathy_call_window_video_menu_popup (window, event->button);
2904 empathy_call_window_key_press_cb (GtkWidget *video_output,
2905 GdkEventKey *event, EmpathyCallWindow *window)
2907 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2909 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
2911 /* Since we are in fullscreen mode, toggling will bring us back to
2913 empathy_call_window_fullscreen_toggle (window);
2921 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2922 GdkEventMotion *event, EmpathyCallWindow *window)
2924 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2926 if (priv->is_fullscreen)
2928 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2935 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2939 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2941 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2943 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2944 button, gtk_get_current_event_time ());
2945 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2949 empathy_call_window_status_message (EmpathyCallWindow *self,
2952 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
2956 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
2957 gdouble value, EmpathyCallWindow *window)
2959 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2961 if (priv->audio_output == NULL)
2964 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),