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"
67 #define CONTENT_HBOX_BORDER_WIDTH 6
68 #define CONTENT_HBOX_SPACING 3
69 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
71 #define SELF_VIDEO_SECTION_WIDTH 120
72 #define SELF_VIDEO_SECTION_HEIGTH 90
74 /* The avatar's default width and height are set to the same value because we
75 want a square icon. */
76 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
77 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
78 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
80 #define SMALL_TOOLBAR_SIZE 36
82 /* If an video input error occurs, the error message will start with "v4l" */
83 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
85 /* The time interval in milliseconds between 2 outgoing rings */
86 #define MS_BETWEEN_RING 500
88 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
91 PROP_CALL_HANDLER = 1,
103 CAMERA_STATE_OFF = 0,
107 struct _EmpathyCallWindowPriv
109 gboolean dispose_has_run;
110 EmpathyCallHandler *handler;
112 EmpathyContact *contact;
114 EmpathyCameraMonitor *camera_monitor;
119 GtkUIManager *ui_manager;
120 GtkWidget *errors_vbox;
121 /* widget displays the video received from the remote user. This widget is
122 * alive only during call. */
123 ClutterActor *video_output;
124 ClutterActor *video_preview;
125 ClutterActor *preview_hidden_button;
126 GtkWidget *video_container;
127 GtkWidget *remote_user_avatar_widget;
128 GtkWidget *remote_user_avatar_toolbar;
129 GtkWidget *remote_user_name_toolbar;
130 GtkWidget *status_label;
131 GtkWidget *hangup_button;
132 GtkWidget *audio_call_button;
133 GtkWidget *video_call_button;
134 GtkWidget *mic_button;
135 GtkWidget *camera_button;
136 GtkWidget *dialpad_button;
138 GtkWidget *bottom_toolbar;
140 GtkAction *menu_fullscreen;
142 /* The box that contains self and remote avatar and video
143 input/output. When we redial, we destroy and re-create the box */
144 ClutterActor *video_box;
145 ClutterLayoutManager *video_layout;
147 /* We keep a reference on the hbox which contains the main content so we can
148 easilly repack everything when toggling fullscreen */
149 GtkWidget *content_hbox;
151 gulong video_output_motion_handler_id;
152 guint bus_message_source_id;
156 GtkWidget *dtmf_panel;
159 GtkWidget *details_vbox;
160 GtkWidget *vcodec_encoding_label;
161 GtkWidget *acodec_encoding_label;
162 GtkWidget *vcodec_decoding_label;
163 GtkWidget *acodec_decoding_label;
165 GtkWidget *audio_remote_candidate_label;
166 GtkWidget *audio_local_candidate_label;
167 GtkWidget *video_remote_candidate_label;
168 GtkWidget *video_local_candidate_label;
169 GtkWidget *video_remote_candidate_info_img;
170 GtkWidget *video_local_candidate_info_img;
171 GtkWidget *audio_remote_candidate_info_img;
172 GtkWidget *audio_local_candidate_info_img;
174 GstElement *video_input;
175 GstElement *video_preview_sink;
176 GstElement *video_output_sink;
177 GstElement *audio_input;
178 GstElement *audio_output;
179 GstElement *pipeline;
180 GstElement *video_tee;
190 gboolean call_started;
191 gboolean sending_video;
192 CameraState camera_state;
194 EmpathyCallWindowFullscreen *fullscreen;
195 gboolean is_fullscreen;
200 /* Those fields represent the state of the window before it actually was in
202 gboolean dialpad_was_visible_before_fs;
203 gint original_width_before_fs;
204 gint original_height_before_fs;
206 gint x, y, w, h, dialpad_width;
209 /* TRUE if the call should be started when the pipeline is playing */
210 gboolean start_call_when_playing;
211 /* TRUE if we requested to set the pipeline in the playing state */
212 gboolean pipeline_playing;
214 EmpathySoundManager *sound_mgr;
217 EmpathyMicMenu *mic_menu;
220 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
222 static void empathy_call_window_realized_cb (GtkWidget *widget,
223 EmpathyCallWindow *window);
225 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
226 GdkEvent *event, EmpathyCallWindow *window);
228 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
229 GdkEventWindowState *event, EmpathyCallWindow *window);
231 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
234 static void empathy_call_window_mic_toggled_cb (
235 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
237 static void empathy_call_window_hangup_cb (gpointer object,
238 EmpathyCallWindow *window);
240 static void empathy_call_window_fullscreen_cb (gpointer object,
241 EmpathyCallWindow *window);
243 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
245 static gboolean empathy_call_window_video_button_press_cb (
246 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
248 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
249 GdkEventKey *event, EmpathyCallWindow *window);
251 static gboolean empathy_call_window_video_output_motion_notify (
252 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
254 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
257 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
258 EmpathyCallWindow *window);
260 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
262 static void empathy_call_window_status_message (EmpathyCallWindow *window,
265 static gboolean empathy_call_window_bus_message (GstBus *bus,
266 GstMessage *message, gpointer user_data);
269 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
270 gdouble value, EmpathyCallWindow *window);
273 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
276 gtk_widget_set_visible (self->priv->hangup_button, show);
277 gtk_widget_set_visible (self->priv->audio_call_button, !show);
278 gtk_widget_set_visible (self->priv->video_call_button, !show);
282 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
283 EmpathyCallWindow *self)
285 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
286 empathy_call_window_restart_call (self);
290 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
291 EmpathyCallWindow *self)
293 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
294 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
295 empathy_call_window_restart_call (self);
299 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
301 EmpathyCallWindowPriv *priv = GET_PRIV (window);
302 TpyCallChannel *call;
306 g_object_get (priv->handler, "call-channel", &call, NULL);
308 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
309 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
312 tpy_call_channel_dtmf_start_tone (call, event);
314 g_object_unref (call);
318 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
320 EmpathyCallWindowPriv *priv = GET_PRIV (window);
321 TpyCallChannel *call;
323 g_object_get (priv->handler, "call-channel", &call, NULL);
325 tpy_call_channel_dtmf_stop_tone (call);
327 g_object_unref (call);
331 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
333 EmpathyCallWindowPriv *priv = GET_PRIV (self);
336 volume = g_settings_get_double (priv->settings,
337 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
339 /* Don't store the volume because of muting */
340 if (volume > 0 || gtk_toggle_tool_button_get_active (
341 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
342 priv->volume = volume;
344 /* Ensure that the toggle button is active if the volume is > 0 and inactive
345 * if it's smaller than 0 */
346 if ((volume > 0) != gtk_toggle_tool_button_get_active (
347 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
348 gtk_toggle_tool_button_set_active (
349 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
351 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
356 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
358 EmpathyCallWindow *self)
360 empathy_call_window_mic_volume_changed (self);
364 empathy_call_window_show_video_output (EmpathyCallWindow *self,
367 if (self->priv->video_output != NULL)
368 g_object_set (self->priv->video_output, "visible", show, NULL);
370 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
374 create_video_output_widget (EmpathyCallWindow *self)
376 EmpathyCallWindowPriv *priv = GET_PRIV (self);
378 g_assert (priv->video_output == NULL);
379 g_assert (priv->pipeline != NULL);
381 priv->video_output = clutter_texture_new ();
383 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
386 priv->video_output_sink = clutter_gst_video_sink_new (
387 CLUTTER_TEXTURE (priv->video_output));
389 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
392 gtk_widget_add_events (priv->video_container,
393 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
394 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
395 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
399 create_video_input (EmpathyCallWindow *self)
401 EmpathyCallWindowPriv *priv = GET_PRIV (self);
403 g_assert (priv->video_input == NULL);
404 priv->video_input = empathy_video_src_new ();
405 gst_object_ref (priv->video_input);
406 gst_object_sink (priv->video_input);
410 create_audio_input (EmpathyCallWindow *self)
412 EmpathyCallWindowPriv *priv = GET_PRIV (self);
414 g_assert (priv->audio_input == NULL);
415 priv->audio_input = empathy_audio_src_new ();
416 gst_object_ref (priv->audio_input);
417 gst_object_sink (priv->audio_input);
421 add_video_preview_to_pipeline (EmpathyCallWindow *self)
423 EmpathyCallWindowPriv *priv = GET_PRIV (self);
426 g_assert (priv->video_preview != NULL);
427 g_assert (priv->pipeline != NULL);
428 g_assert (priv->video_input != NULL);
429 g_assert (priv->video_tee != NULL);
431 preview = priv->video_preview_sink;
433 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
435 g_warning ("Could not add video input to pipeline");
439 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
441 g_warning ("Could not add video preview to pipeline");
445 if (!gst_element_link (priv->video_input, priv->video_tee))
447 g_warning ("Could not link video input to video tee");
451 if (!gst_element_link (priv->video_tee, preview))
453 g_warning ("Could not link video tee to video preview");
459 empathy_call_window_disable_camera_cb (GtkAction *action,
460 EmpathyCallWindow *self)
462 clutter_actor_destroy (self->priv->preview_hidden_button);
464 gtk_toggle_tool_button_set_active (
465 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
469 empathy_call_window_minimise_camera_cb (GtkAction *action,
470 EmpathyCallWindow *self)
472 clutter_actor_hide (self->priv->video_preview);
473 clutter_actor_show (self->priv->preview_hidden_button);
477 empathy_call_window_maximise_camera_cb (GtkAction *action,
478 EmpathyCallWindow *self)
480 clutter_actor_show (self->priv->video_preview);
481 clutter_actor_hide (self->priv->preview_hidden_button);
485 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
486 EmpathyCallWindow *self)
490 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
492 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
493 0, gtk_get_current_event_time ());
494 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
498 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
499 EmpathyCallWindow *self)
503 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
504 "/preview-hidden-menu");
505 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
506 0, gtk_get_current_event_time ());
507 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
511 create_video_preview (EmpathyCallWindow *self)
513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
514 ClutterLayoutManager *layout, *layout_center;
515 ClutterActor *preview;
520 g_assert (priv->video_preview == NULL);
522 preview = clutter_texture_new ();
523 clutter_actor_set_size (preview,
524 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
525 priv->video_preview_sink = clutter_gst_video_sink_new (
526 CLUTTER_TEXTURE (preview));
528 /* Flip the video preview */
529 clutter_actor_set_rotation (preview,
532 SELF_VIDEO_SECTION_WIDTH * 0.5,
536 /* Add a little offset to the video preview */
537 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
538 CLUTTER_BIN_ALIGNMENT_START);
539 priv->video_preview = clutter_box_new (layout);
540 clutter_actor_set_size (priv->video_preview,
541 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
543 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
544 CLUTTER_BIN_ALIGNMENT_CENTER);
545 box = clutter_box_new (layout_center);
546 clutter_actor_set_size (box,
547 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
549 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
550 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
552 g_object_set (priv->video_preview_sink,
557 /* Translators: this is an "Info" label. It should be as short
559 button = gtk_button_new_with_label (_("i"));
560 b = gtk_clutter_actor_new_with_contents (button);
562 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
564 CLUTTER_BIN_ALIGNMENT_END,
565 CLUTTER_BIN_ALIGNMENT_END);
567 g_signal_connect (button, "clicked",
568 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
571 /* Translators: this is an "Info" label. It should be as short
573 button = gtk_button_new_with_label (_("i"));
574 priv->preview_hidden_button =
575 gtk_clutter_actor_new_with_contents (button);
577 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
578 priv->preview_hidden_button,
579 CLUTTER_BIN_ALIGNMENT_START,
580 CLUTTER_BIN_ALIGNMENT_END);
582 clutter_actor_hide (priv->preview_hidden_button);
584 g_signal_connect (button, "clicked",
585 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
588 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
590 CLUTTER_BIN_ALIGNMENT_START,
591 CLUTTER_BIN_ALIGNMENT_END);
595 play_camera (EmpathyCallWindow *window,
598 EmpathyCallWindowPriv *priv = GET_PRIV (window);
602 if (priv->video_preview == NULL)
604 create_video_preview (window);
605 add_video_preview_to_pipeline (window);
609 state = GST_STATE_PLAYING;
611 state = GST_STATE_NULL;
613 preview = priv->video_preview_sink;
615 gst_element_set_state (preview, state);
616 gst_element_set_state (priv->video_input, state);
617 gst_element_set_state (priv->video_tee, state);
621 display_video_preview (EmpathyCallWindow *self,
624 EmpathyCallWindowPriv *priv = GET_PRIV (self);
628 /* Display the video preview */
629 DEBUG ("Show video preview");
631 play_camera (self, TRUE);
632 clutter_actor_show (priv->video_preview);
636 /* Hide the video preview */
637 DEBUG ("Hide video preview");
639 if (priv->video_preview != NULL)
641 clutter_actor_hide (priv->video_preview);
642 play_camera (self, FALSE);
648 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
650 EmpathyCallWindowPriv *priv = GET_PRIV (window);
652 empathy_call_window_status_message (window, _("Connecting…"));
653 priv->call_state = CONNECTING;
656 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
657 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
661 disable_camera (EmpathyCallWindow *self)
663 EmpathyCallWindowPriv *priv = GET_PRIV (self);
665 if (priv->camera_state == CAMERA_STATE_OFF)
668 DEBUG ("Disable camera");
670 display_video_preview (self, FALSE);
672 if (priv->camera_state == CAMERA_STATE_ON)
673 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
675 priv->camera_state = CAMERA_STATE_OFF;
679 enable_camera (EmpathyCallWindow *self)
681 EmpathyCallWindowPriv *priv = GET_PRIV (self);
683 if (priv->camera_state == CAMERA_STATE_ON)
686 if (priv->video_input == NULL)
688 DEBUG ("Can't enable camera, no input");
692 DEBUG ("Enable camera");
694 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
696 priv->camera_state = CAMERA_STATE_ON;
700 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
701 EmpathyCallWindow *self)
703 if (gtk_toggle_tool_button_get_active (toggle))
704 enable_camera (self);
706 disable_camera (self);
710 create_pipeline (EmpathyCallWindow *self)
712 EmpathyCallWindowPriv *priv = GET_PRIV (self);
715 g_assert (priv->pipeline == NULL);
717 priv->pipeline = gst_pipeline_new (NULL);
718 priv->pipeline_playing = FALSE;
720 priv->video_tee = gst_element_factory_make ("tee", NULL);
721 gst_object_ref (priv->video_tee);
722 gst_object_sink (priv->video_tee);
724 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
726 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
727 priv->bus_message_source_id = gst_bus_add_watch (bus,
728 empathy_call_window_bus_message, self);
730 g_object_unref (bus);
734 empathy_call_window_settings_cb (GtkAction *action,
735 EmpathyCallWindow *self)
737 empathy_launch_program (BIN_DIR, "empathy", "-p");
741 empathy_call_window_contents_cb (GtkAction *action,
742 EmpathyCallWindow *self)
744 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
748 empathy_call_window_debug_cb (GtkAction *action,
749 EmpathyCallWindow *self)
751 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
755 empathy_call_window_about_cb (GtkAction *action,
756 EmpathyCallWindow *self)
758 empathy_about_dialog_new (GTK_WINDOW (self));
762 empathy_call_window_configure_event_cb (GtkWidget *widget,
764 EmpathyCallWindow *self)
766 GdkWindow *gdk_window;
767 GdkWindowState window_state;
769 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
770 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
772 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
773 &self->priv->dialpad_width, NULL);
775 gdk_window = gtk_widget_get_window (widget);
776 window_state = gdk_window_get_state (gdk_window);
777 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
783 empathy_call_window_destroyed_cb (GtkWidget *object,
784 EmpathyCallWindow *self)
786 if (gtk_widget_get_visible (self->priv->dtmf_panel))
788 /* Save the geometry as if the dialpad was hidden. */
789 empathy_geometry_save_values (GTK_WINDOW (self),
790 self->priv->x, self->priv->y,
791 self->priv->w - self->priv->dialpad_width, self->priv->h,
792 self->priv->maximized);
797 empathy_call_window_init (EmpathyCallWindow *self)
799 EmpathyCallWindowPriv *priv;
803 ClutterConstraint *size_constraint;
804 ClutterActor *remote_avatar;
805 GtkStyleContext *context;
809 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
810 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
812 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
813 gui = empathy_builder_get_file (filename,
814 "call_window_vbox", &top_vbox,
815 "errors_vbox", &priv->errors_vbox,
817 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
818 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
819 "status_label", &priv->status_label,
820 "audiocall", &priv->audio_call_button,
821 "videocall", &priv->video_call_button,
822 "microphone", &priv->mic_button,
823 "camera", &priv->camera_button,
824 "hangup", &priv->hangup_button,
825 "dialpad", &priv->dialpad_button,
826 "toolbar", &priv->toolbar,
827 "bottom_toolbar", &priv->bottom_toolbar,
828 "ui_manager", &priv->ui_manager,
829 "menufullscreen", &priv->menu_fullscreen,
830 "details_vbox", &priv->details_vbox,
831 "vcodec_encoding_label", &priv->vcodec_encoding_label,
832 "acodec_encoding_label", &priv->acodec_encoding_label,
833 "acodec_decoding_label", &priv->acodec_decoding_label,
834 "vcodec_decoding_label", &priv->vcodec_decoding_label,
835 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
836 "audio_local_candidate_label", &priv->audio_local_candidate_label,
837 "video_remote_candidate_label", &priv->video_remote_candidate_label,
838 "video_local_candidate_label", &priv->video_local_candidate_label,
839 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
840 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
841 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
842 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
846 empathy_builder_connect (gui, self,
847 "hangup", "clicked", empathy_call_window_hangup_cb,
848 "audiocall", "clicked", empathy_call_window_audio_call_cb,
849 "videocall", "clicked", empathy_call_window_video_call_cb,
850 "volume", "value-changed", empathy_call_window_volume_changed_cb,
851 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
852 "camera", "toggled", empathy_call_window_camera_toggled_cb,
853 "dialpad", "toggled", empathy_call_window_dialpad_cb,
854 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
855 "menusettings", "activate", empathy_call_window_settings_cb,
856 "menucontents", "activate", empathy_call_window_contents_cb,
857 "menudebug", "activate", empathy_call_window_debug_cb,
858 "menuabout", "activate", empathy_call_window_about_cb,
859 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
860 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
861 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
864 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
866 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
868 g_object_bind_property (priv->camera_monitor, "available",
869 priv->camera_button, "sensitive",
870 G_BINDING_SYNC_CREATE);
872 priv->lock = g_mutex_new ();
874 gtk_container_add (GTK_CONTAINER (self), top_vbox);
876 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
877 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
878 CONTENT_HBOX_BORDER_WIDTH);
879 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
882 /* avatar/video box */
883 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
884 CLUTTER_BIN_ALIGNMENT_CENTER);
886 priv->video_box = clutter_box_new (priv->video_layout);
888 priv->video_container = gtk_clutter_embed_new ();
890 /* Set the background color to that of the rest of the window */
891 context = gtk_widget_get_style_context (priv->content_hbox);
892 gtk_style_context_get_background_color (context,
893 GTK_STATE_FLAG_NORMAL, &rgba);
894 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
895 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
896 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
897 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
898 clutter_stage_set_color (
899 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
900 GTK_CLUTTER_EMBED (priv->video_container))),
903 clutter_container_add (
904 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
905 GTK_CLUTTER_EMBED (priv->video_container))),
909 size_constraint = clutter_bind_constraint_new (
910 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
911 CLUTTER_BIND_SIZE, 0);
912 clutter_actor_add_constraint (priv->video_box, size_constraint);
914 priv->remote_user_avatar_widget = gtk_image_new ();
915 remote_avatar = gtk_clutter_actor_new_with_contents (
916 priv->remote_user_avatar_widget);
918 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
921 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
922 priv->video_container, TRUE, TRUE,
923 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
925 create_pipeline (self);
926 create_video_output_widget (self);
927 create_audio_input (self);
928 create_video_input (self);
930 /* The call will be started as soon the pipeline is playing */
931 priv->start_call_when_playing = TRUE;
933 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
934 G_CALLBACK (dtmf_button_pressed_cb),
935 G_CALLBACK (dtmf_button_released_cb));
937 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
940 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
943 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
945 gtk_widget_show_all (top_vbox);
947 gtk_widget_hide (priv->dtmf_panel);
948 gtk_widget_hide (priv->details_vbox);
950 priv->fullscreen = empathy_call_window_fullscreen_new (self);
952 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
953 priv->video_container);
955 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
956 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
958 g_signal_connect (G_OBJECT (self), "realize",
959 G_CALLBACK (empathy_call_window_realized_cb), self);
961 g_signal_connect (G_OBJECT (self), "delete-event",
962 G_CALLBACK (empathy_call_window_delete_cb), self);
964 g_signal_connect (G_OBJECT (self), "window-state-event",
965 G_CALLBACK (empathy_call_window_state_event_cb), self);
967 g_signal_connect (G_OBJECT (self), "key-press-event",
968 G_CALLBACK (empathy_call_window_key_press_cb), self);
970 priv->timer = g_timer_new ();
972 g_object_ref (priv->ui_manager);
973 g_object_unref (gui);
975 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
976 priv->mic_menu = empathy_mic_menu_new (self);
978 empathy_call_window_show_hangup_button (self, TRUE);
980 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
981 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
982 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
984 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
985 /* These signals are used to track the window position and save it
986 * when the window is destroyed. We need to do this as we don't want
987 * the window geometry to be saved with the dialpad taken into account. */
988 g_signal_connect (self, "destroy",
989 G_CALLBACK (empathy_call_window_destroyed_cb), self);
990 g_signal_connect (self, "configure-event",
991 G_CALLBACK (empathy_call_window_configure_event_cb), self);
992 g_signal_connect (self, "window-state-event",
993 G_CALLBACK (empathy_call_window_configure_event_cb), self);
995 /* Don't display labels in both toolbars */
996 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
997 gtk_toolbar_set_style (GTK_TOOLBAR (priv->bottom_toolbar), GTK_TOOLBAR_ICONS);
1000 /* Instead of specifying a width and a height, we specify only one size. That's
1001 because we want a square avatar icon. */
1003 init_contact_avatar_with_size (EmpathyContact *contact,
1004 GtkWidget *image_widget,
1007 GdkPixbuf *pixbuf_avatar = NULL;
1009 if (contact != NULL)
1011 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1015 if (pixbuf_avatar == NULL)
1017 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1018 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1021 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1023 if (pixbuf_avatar != NULL)
1024 g_object_unref (pixbuf_avatar);
1028 set_window_title (EmpathyCallWindow *self)
1030 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1033 if (priv->contact != NULL)
1035 /* translators: Call is a noun and %s is the contact name. This string
1036 * is used in the window title */
1037 tmp = g_strdup_printf (_("Call with %s"),
1038 empathy_contact_get_alias (priv->contact));
1039 gtk_window_set_title (GTK_WINDOW (self), tmp);
1044 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1049 set_remote_user_name (EmpathyCallWindow *self,
1050 EmpathyContact *contact)
1052 const gchar *alias = empathy_contact_get_alias (contact);
1053 const gchar *status = empathy_contact_get_status (contact);
1056 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1057 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1063 contact_name_changed_cb (EmpathyContact *contact,
1065 EmpathyCallWindow *self)
1067 set_window_title (self);
1068 set_remote_user_name (self, contact);
1072 contact_presence_changed_cb (EmpathyContact *contact,
1074 EmpathyCallWindow *self)
1076 set_remote_user_name (self, contact);
1080 contact_avatar_changed_cb (EmpathyContact *contact,
1082 EmpathyCallWindow *self)
1085 GtkAllocation allocation;
1086 GtkWidget *avatar_widget;
1088 avatar_widget = self->priv->remote_user_avatar_widget;
1090 gtk_widget_get_allocation (avatar_widget, &allocation);
1091 size = allocation.height;
1095 /* the widget is not allocated yet, set a default size */
1096 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1097 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1100 init_contact_avatar_with_size (contact, avatar_widget, size);
1102 avatar_widget = self->priv->remote_user_avatar_toolbar;
1104 gtk_widget_get_allocation (avatar_widget, &allocation);
1105 size = allocation.height;
1109 /* the widget is not allocated yet, set a default size */
1110 size = SMALL_TOOLBAR_SIZE;
1113 init_contact_avatar_with_size (contact, avatar_widget, size);
1117 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1118 EmpathyCallHandler *handler)
1120 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1122 tp_g_signal_connect_object (priv->contact, "notify::name",
1123 G_CALLBACK (contact_name_changed_cb), self, 0);
1124 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1125 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1126 tp_g_signal_connect_object (priv->contact, "notify::presence",
1127 G_CALLBACK (contact_presence_changed_cb), self, 0);
1129 set_window_title (self);
1130 set_remote_user_name (self, priv->contact);
1132 init_contact_avatar_with_size (priv->contact,
1133 priv->remote_user_avatar_widget,
1134 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1135 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1137 init_contact_avatar_with_size (priv->contact,
1138 priv->remote_user_avatar_toolbar,
1139 SMALL_TOOLBAR_SIZE);
1141 /* The remote avatar is shown by default and will be hidden when we receive
1142 video from the remote side. */
1143 clutter_actor_hide (priv->video_output);
1144 gtk_widget_show (priv->remote_user_avatar_widget);
1148 update_send_codec (EmpathyCallWindow *self,
1151 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1158 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1159 widget = priv->acodec_encoding_label;
1163 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1164 widget = priv->vcodec_encoding_label;
1170 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1171 gtk_label_set_text (GTK_LABEL (widget), tmp);
1176 send_audio_codec_notify_cb (GObject *object,
1180 EmpathyCallWindow *self = user_data;
1182 update_send_codec (self, TRUE);
1186 send_video_codec_notify_cb (GObject *object,
1190 EmpathyCallWindow *self = user_data;
1192 update_send_codec (self, FALSE);
1196 update_recv_codec (EmpathyCallWindow *self,
1199 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1202 GString *str = NULL;
1206 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1207 widget = priv->acodec_decoding_label;
1211 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1212 widget = priv->vcodec_decoding_label;
1218 for (l = codecs; l != NULL; l = g_list_next (l))
1220 FsCodec *codec = l->data;
1223 str = g_string_new (NULL);
1225 g_string_append (str, ", ");
1227 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1231 gtk_label_set_text (GTK_LABEL (widget), str->str);
1232 g_string_free (str, TRUE);
1236 recv_audio_codecs_notify_cb (GObject *object,
1240 EmpathyCallWindow *self = user_data;
1242 update_recv_codec (self, TRUE);
1246 recv_video_codecs_notify_cb (GObject *object,
1250 EmpathyCallWindow *self = user_data;
1252 update_recv_codec (self, FALSE);
1255 static const gchar *
1256 candidate_type_to_str (FsCandidate *candidate)
1258 switch (candidate->type)
1260 case FS_CANDIDATE_TYPE_HOST:
1262 case FS_CANDIDATE_TYPE_SRFLX:
1263 return "server reflexive";
1264 case FS_CANDIDATE_TYPE_PRFLX:
1265 return "peer reflexive";
1266 case FS_CANDIDATE_TYPE_RELAY:
1268 case FS_CANDIDATE_TYPE_MULTICAST:
1275 static const gchar *
1276 candidate_type_to_desc (FsCandidate *candidate)
1278 switch (candidate->type)
1280 case FS_CANDIDATE_TYPE_HOST:
1281 return _("The IP address as seen by the machine");
1282 case FS_CANDIDATE_TYPE_SRFLX:
1283 return _("The IP address as seen by a server on the Internet");
1284 case FS_CANDIDATE_TYPE_PRFLX:
1285 return _("The IP address of the peer as seen by the other side");
1286 case FS_CANDIDATE_TYPE_RELAY:
1287 return _("The IP address of a relay server");
1288 case FS_CANDIDATE_TYPE_MULTICAST:
1289 return _("The IP address of the multicast group");
1296 update_candidat_widget (EmpathyCallWindow *self,
1299 FsCandidate *candidate)
1303 g_assert (candidate != NULL);
1304 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1305 candidate->port, candidate_type_to_str (candidate));
1307 gtk_label_set_text (GTK_LABEL (label), str);
1308 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1314 candidates_changed_cb (GObject *object,
1316 EmpathyCallWindow *self)
1318 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1319 FsCandidate *candidate = NULL;
1321 if (type == FS_MEDIA_TYPE_VIDEO)
1323 /* Update remote candidate */
1324 candidate = empathy_call_handler_get_video_remote_candidate (
1327 update_candidat_widget (self, priv->video_remote_candidate_label,
1328 priv->video_remote_candidate_info_img, candidate);
1330 /* Update local candidate */
1331 candidate = empathy_call_handler_get_video_local_candidate (
1334 update_candidat_widget (self, priv->video_local_candidate_label,
1335 priv->video_local_candidate_info_img, candidate);
1339 /* Update remote candidate */
1340 candidate = empathy_call_handler_get_audio_remote_candidate (
1343 update_candidat_widget (self, priv->audio_remote_candidate_label,
1344 priv->audio_remote_candidate_info_img, candidate);
1346 /* Update local candidate */
1347 candidate = empathy_call_handler_get_audio_local_candidate (
1350 update_candidat_widget (self, priv->audio_local_candidate_label,
1351 priv->audio_local_candidate_info_img, candidate);
1356 empathy_call_window_constructed (GObject *object)
1358 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1359 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1360 TpyCallChannel *call;
1362 g_assert (priv->handler != NULL);
1364 g_object_get (priv->handler, "call-channel", &call, NULL);
1365 priv->outgoing = (call == NULL);
1367 g_object_unref (call);
1369 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1370 g_assert (priv->contact != NULL);
1372 empathy_call_window_setup_avatars (self, priv->handler);
1373 empathy_call_window_set_state_connecting (self);
1375 if (!empathy_call_handler_has_initial_video (priv->handler))
1377 gtk_toggle_tool_button_set_active (
1378 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1380 /* If call has InitialVideo, the preview will be started once the call has
1381 * been started (start_call()). */
1383 update_send_codec (self, TRUE);
1384 update_send_codec (self, FALSE);
1385 update_recv_codec (self, TRUE);
1386 update_recv_codec (self, FALSE);
1388 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1389 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1390 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1391 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1392 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1393 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1394 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1395 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1397 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1398 G_CALLBACK (candidates_changed_cb), self, 0);
1401 static void empathy_call_window_dispose (GObject *object);
1402 static void empathy_call_window_finalize (GObject *object);
1405 empathy_call_window_set_property (GObject *object,
1406 guint property_id, const GValue *value, GParamSpec *pspec)
1408 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1410 switch (property_id)
1412 case PROP_CALL_HANDLER:
1413 priv->handler = g_value_dup_object (value);
1416 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1421 empathy_call_window_get_property (GObject *object,
1422 guint property_id, GValue *value, GParamSpec *pspec)
1424 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1426 switch (property_id)
1428 case PROP_CALL_HANDLER:
1429 g_value_set_object (value, priv->handler);
1432 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1437 empathy_call_window_class_init (
1438 EmpathyCallWindowClass *empathy_call_window_class)
1440 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1441 GParamSpec *param_spec;
1443 g_type_class_add_private (empathy_call_window_class,
1444 sizeof (EmpathyCallWindowPriv));
1446 object_class->constructed = empathy_call_window_constructed;
1447 object_class->set_property = empathy_call_window_set_property;
1448 object_class->get_property = empathy_call_window_get_property;
1450 object_class->dispose = empathy_call_window_dispose;
1451 object_class->finalize = empathy_call_window_finalize;
1453 param_spec = g_param_spec_object ("handler",
1454 "handler", "The call handler",
1455 EMPATHY_TYPE_CALL_HANDLER,
1456 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1457 g_object_class_install_property (object_class,
1458 PROP_CALL_HANDLER, param_spec);
1462 empathy_call_window_dispose (GObject *object)
1464 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1465 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1467 if (priv->dispose_has_run)
1470 priv->dispose_has_run = TRUE;
1472 if (priv->handler != NULL)
1474 empathy_call_handler_stop_call (priv->handler);
1475 tp_clear_object (&priv->handler);
1478 if (priv->bus_message_source_id != 0)
1480 g_source_remove (priv->bus_message_source_id);
1481 priv->bus_message_source_id = 0;
1484 if (priv->got_video_src > 0)
1486 g_source_remove (priv->got_video_src);
1487 priv->got_video_src = 0;
1490 tp_clear_object (&priv->pipeline);
1491 tp_clear_object (&priv->video_input);
1492 tp_clear_object (&priv->audio_input);
1493 tp_clear_object (&priv->video_tee);
1494 tp_clear_object (&priv->ui_manager);
1495 tp_clear_object (&priv->fullscreen);
1496 tp_clear_object (&priv->camera_monitor);
1497 tp_clear_object (&priv->settings);
1499 g_list_free_full (priv->notifiers, g_object_unref);
1501 if (priv->timer_id != 0)
1502 g_source_remove (priv->timer_id);
1505 if (priv->contact != NULL)
1507 g_signal_handlers_disconnect_by_func (priv->contact,
1508 contact_name_changed_cb, self);
1509 priv->contact = NULL;
1513 tp_clear_object (&priv->sound_mgr);
1515 tp_clear_object (&priv->mic_menu);
1517 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1521 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1523 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1525 if (priv->video_output_motion_handler_id != 0)
1527 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1528 priv->video_output_motion_handler_id);
1529 priv->video_output_motion_handler_id = 0;
1534 empathy_call_window_finalize (GObject *object)
1536 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1537 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1539 disconnect_video_output_motion_handler (self);
1541 /* free any data held directly by the object here */
1542 g_mutex_free (priv->lock);
1544 g_timer_destroy (priv->timer);
1546 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1551 empathy_call_window_new (EmpathyCallHandler *handler)
1553 return EMPATHY_CALL_WINDOW (
1554 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1558 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1559 GstElement *conference, gpointer user_data)
1561 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1562 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1563 FsElementAddedNotifier *notifier;
1566 DEBUG ("Conference added");
1568 /* Add notifier to set the various element properties as needed */
1569 notifier = fs_element_added_notifier_new ();
1570 keyfile = fs_utils_get_default_element_properties (conference);
1572 if (keyfile != NULL)
1573 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1575 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1577 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1579 gst_bin_add (GST_BIN (priv->pipeline), conference);
1580 gst_element_set_state (conference, GST_STATE_PLAYING);
1584 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1585 GstElement *conference, gpointer user_data)
1587 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1588 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1590 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1591 gst_element_set_state (conference, GST_STATE_NULL);
1595 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1597 GstStateChangeReturn state_change_return;
1598 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1600 if (priv->pipeline == NULL)
1603 if (priv->bus_message_source_id != 0)
1605 g_source_remove (priv->bus_message_source_id);
1606 priv->bus_message_source_id = 0;
1609 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1611 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1612 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1614 if (priv->pipeline != NULL)
1615 g_object_unref (priv->pipeline);
1616 priv->pipeline = NULL;
1618 if (priv->audio_output != NULL)
1619 g_object_unref (priv->audio_output);
1620 priv->audio_output = NULL;
1622 if (priv->video_tee != NULL)
1623 g_object_unref (priv->video_tee);
1624 priv->video_tee = NULL;
1626 if (priv->video_preview != NULL)
1627 clutter_actor_destroy (priv->video_preview);
1628 priv->video_preview = NULL;
1630 priv->funnel = NULL;
1632 create_pipeline (self);
1633 /* Call will be started when user will hit the 'redial' button */
1634 priv->start_call_when_playing = FALSE;
1635 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1641 g_message ("Error: could not destroy pipeline. Closing call window");
1642 gtk_widget_destroy (GTK_WIDGET (self));
1649 reset_details_pane (EmpathyCallWindow *self)
1651 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1653 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1654 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1655 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1656 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1660 empathy_call_window_disconnected (EmpathyCallWindow *self,
1663 gboolean could_disconnect = FALSE;
1664 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1665 gboolean could_reset_pipeline;
1667 /* Leave full screen mode if needed */
1668 gtk_window_unfullscreen (GTK_WINDOW (self));
1670 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1671 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1673 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1675 if (priv->call_state == CONNECTING)
1676 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1678 if (priv->call_state != REDIALING)
1679 priv->call_state = DISCONNECTED;
1681 if (could_reset_pipeline)
1683 g_mutex_lock (priv->lock);
1685 g_timer_stop (priv->timer);
1687 if (priv->timer_id != 0)
1688 g_source_remove (priv->timer_id);
1691 g_mutex_unlock (priv->lock);
1694 /* We are about to destroy the window, no need to update it or create
1695 * a video preview */
1698 empathy_call_window_status_message (self, _("Disconnected"));
1700 empathy_call_window_show_hangup_button (self, FALSE);
1702 /* Unsensitive the camera and mic button */
1703 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1704 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1706 /* Be sure that the mic button is enabled */
1707 gtk_toggle_tool_button_set_active (
1708 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1710 if (priv->camera_state == CAMERA_STATE_ON)
1712 /* Restart the preview with the new pipeline. */
1713 display_video_preview (self, TRUE);
1716 /* destroy the video output; it will be recreated when we'll redial */
1717 disconnect_video_output_motion_handler (self);
1718 if (priv->video_output != NULL)
1719 clutter_actor_destroy (priv->video_output);
1720 priv->video_output = NULL;
1721 if (priv->got_video_src > 0)
1723 g_source_remove (priv->got_video_src);
1724 priv->got_video_src = 0;
1727 gtk_widget_show (priv->remote_user_avatar_widget);
1729 reset_details_pane (self);
1731 priv->sending_video = FALSE;
1732 priv->call_started = FALSE;
1734 could_disconnect = TRUE;
1736 /* TODO: display the self avatar of the preview (depends if the "Always
1737 * Show Video Preview" is enabled or not) */
1740 return could_disconnect;
1745 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1748 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1749 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1751 if (empathy_call_window_disconnected (self, TRUE) &&
1752 priv->call_state == REDIALING)
1753 empathy_call_window_restart_call (self);
1757 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1759 FsMediaType media_type,
1760 EmpathyCallWindow *self)
1762 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1764 DEBUG ("removing content");
1767 * This assumes that there is only one video stream per channel...
1770 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1772 if (priv->funnel != NULL)
1776 output = priv->video_output_sink;
1778 gst_element_set_state (output, GST_STATE_NULL);
1779 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1781 gst_bin_remove (GST_BIN (priv->pipeline), output);
1782 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1783 priv->funnel = NULL;
1787 else if (media_type == FS_MEDIA_TYPE_AUDIO)
1789 if (priv->audio_output != NULL)
1791 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1793 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1794 priv->audio_output = NULL;
1802 /* Called with global lock held */
1804 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1806 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1810 if (priv->funnel == NULL)
1812 output = priv->video_output_sink;
1814 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1818 g_warning ("Could not create fsfunnel");
1822 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1824 gst_object_unref (priv->funnel);
1825 priv->funnel = NULL;
1826 g_warning ("Could not add funnel to pipeline");
1830 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
1832 g_warning ("Could not add the video output widget to the pipeline");
1836 if (!gst_element_link (priv->funnel, output))
1838 g_warning ("Could not link output sink to funnel");
1839 goto error_output_added;
1842 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1844 g_warning ("Could not start video sink");
1845 goto error_output_added;
1848 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1850 g_warning ("Could not start funnel");
1851 goto error_output_added;
1855 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
1858 g_warning ("Could not get request pad from funnel");
1865 gst_element_set_locked_state (priv->funnel, TRUE);
1866 gst_element_set_locked_state (output, TRUE);
1868 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1869 gst_element_set_state (output, GST_STATE_NULL);
1871 gst_bin_remove (GST_BIN (priv->pipeline), output);
1872 gst_element_set_locked_state (output, FALSE);
1876 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1877 priv->funnel = NULL;
1882 /* Called with global lock held */
1884 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
1886 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1888 GstPadTemplate *template;
1890 if (priv->audio_output == NULL)
1892 priv->audio_output = empathy_audio_sink_new ();
1893 g_object_ref_sink (priv->audio_output);
1895 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
1897 g_warning ("Could not add audio sink to pipeline");
1898 g_object_unref (priv->audio_output);
1899 goto error_add_output;
1902 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
1904 g_warning ("Could not start audio sink");
1909 template = gst_element_class_get_pad_template (
1910 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
1912 pad = gst_element_request_pad (priv->audio_output,
1913 template, NULL, NULL);
1917 g_warning ("Could not get sink pad from sink");
1924 gst_element_set_locked_state (priv->audio_output, TRUE);
1925 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1926 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1927 priv->audio_output = NULL;
1935 empathy_call_window_update_timer (gpointer user_data)
1937 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1938 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1939 const gchar *status;
1943 time_ = g_timer_elapsed (priv->timer, NULL);
1945 if (priv->call_state == HELD)
1946 status = _("On hold");
1947 else if (!gtk_toggle_tool_button_get_active (
1948 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
1951 status = _("Duration");
1953 /* Translators: 'status - minutes:seconds' the caller has been connected */
1954 str = g_strdup_printf (_("%s — %d:%02dm"),
1956 (int) time_ / 60, (int) time_ % 60);
1957 empathy_call_window_status_message (self, str);
1965 display_error (EmpathyCallWindow *self,
1966 TpyCallChannel *call,
1970 const gchar *details)
1972 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1973 GtkWidget *info_bar;
1974 GtkWidget *content_area;
1981 /* Create info bar */
1982 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1985 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
1987 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
1989 /* hbox containing the image and the messages vbox */
1990 hbox = gtk_hbox_new (FALSE, 3);
1991 gtk_container_add (GTK_CONTAINER (content_area), hbox);
1994 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
1995 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
1997 /* vbox containing the main message and the details expander */
1998 vbox = gtk_vbox_new (FALSE, 3);
1999 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2002 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2004 label = gtk_label_new (NULL);
2005 gtk_label_set_markup (GTK_LABEL (label), txt);
2006 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2007 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2010 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2013 if (details != NULL)
2015 GtkWidget *expander;
2017 expander = gtk_expander_new (_("Technical Details"));
2019 txt = g_strdup_printf ("<i>%s</i>", details);
2021 label = gtk_label_new (NULL);
2022 gtk_label_set_markup (GTK_LABEL (label), txt);
2023 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2024 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2027 gtk_container_add (GTK_CONTAINER (expander), label);
2028 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2031 g_signal_connect (info_bar, "response",
2032 G_CALLBACK (gtk_widget_destroy), NULL);
2034 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2035 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2036 gtk_widget_show_all (info_bar);
2040 media_stream_error_to_txt (EmpathyCallWindow *self,
2041 TpyCallChannel *call,
2043 TpMediaStreamError error)
2045 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2046 const gchar *cm = NULL;
2052 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2054 return g_strdup_printf (
2055 _("%s's software does not understand any of the audio formats "
2056 "supported by your computer"),
2057 empathy_contact_get_alias (priv->contact));
2059 return g_strdup_printf (
2060 _("%s's software does not understand any of the video formats "
2061 "supported by your computer"),
2062 empathy_contact_get_alias (priv->contact));
2064 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2065 return g_strdup_printf (
2066 _("Can't establish a connection to %s. "
2067 "One of you might be on a network that does not allow "
2068 "direct connections."),
2069 empathy_contact_get_alias (priv->contact));
2071 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2072 return g_strdup (_("There was a failure on the network"));
2074 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2076 return g_strdup (_("The audio formats necessary for this call "
2077 "are not installed on your computer"));
2079 return g_strdup (_("The video formats necessary for this call "
2080 "are not installed on your computer"));
2082 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2083 tp_connection_parse_object_path (
2084 tp_channel_borrow_connection (TP_CHANNEL (call)),
2087 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2088 "product=Telepathy&component=%s", cm);
2090 result = g_strdup_printf (
2091 _("Something unexpected happened in a Telepathy component. "
2092 "Please <a href=\"%s\">report this bug</a> and attach "
2093 "logs gathered from the 'Debug' window in the Help menu."), url);
2099 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2100 return g_strdup (_("There was a failure in the call engine"));
2102 case TP_MEDIA_STREAM_ERROR_EOS:
2103 return g_strdup (_("The end of the stream was reached"));
2105 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2112 empathy_call_window_stream_error (EmpathyCallWindow *self,
2113 TpyCallChannel *call,
2122 desc = media_stream_error_to_txt (self, call, audio, code);
2125 /* No description, use the error message. That's not great as it's not
2126 * localized but it's better than nothing. */
2127 display_error (self, call, icon, title, msg, NULL);
2131 display_error (self, call, icon, title, desc, msg);
2137 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2140 EmpathyCallWindow *self)
2142 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2143 "gnome-stock-mic", _("Can't establish audio stream"));
2147 empathy_call_window_video_stream_error (TpyCallChannel *call,
2150 EmpathyCallWindow *self)
2152 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2153 "camera-web", _("Can't establish video stream"));
2158 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2160 EmpathyCallWindow *self)
2162 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2163 TpyCallChannel *call;
2164 gboolean can_send_video;
2166 if (state != TPY_CALL_STATE_ACCEPTED)
2169 if (priv->call_state == CONNECTED)
2172 g_timer_start (priv->timer);
2173 priv->call_state = CONNECTED;
2175 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2177 can_send_video = priv->video_input != NULL &&
2178 empathy_contact_can_voip_video (priv->contact) &&
2179 empathy_camera_monitor_get_available (priv->camera_monitor);
2181 g_object_get (priv->handler, "call-channel", &call, NULL);
2183 if (tpy_call_channel_has_dtmf (call))
2184 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2186 if (priv->video_input == NULL)
2187 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2189 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2191 empathy_call_window_show_hangup_button (self, TRUE);
2193 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2195 clutter_actor_hide (priv->video_output);
2196 gtk_widget_show (priv->remote_user_avatar_widget);
2198 g_object_unref (call);
2200 g_mutex_lock (priv->lock);
2202 priv->timer_id = g_timeout_add_seconds (1,
2203 empathy_call_window_update_timer, self);
2205 g_mutex_unlock (priv->lock);
2207 empathy_call_window_update_timer (self);
2209 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2213 empathy_call_window_show_video_output_cb (gpointer user_data)
2215 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2217 if (self->priv->video_output != NULL)
2219 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2220 clutter_actor_show (self->priv->video_output);
2227 empathy_call_window_check_video_cb (gpointer data)
2229 EmpathyCallWindow *self = data;
2231 if (self->priv->got_video)
2233 self->priv->got_video = FALSE;
2237 /* No video in the last N seconds, display the remote avatar */
2238 empathy_call_window_show_video_output (self, FALSE);
2243 /* Called from the streaming thread */
2245 empathy_call_window_video_probe_cb (GstPad *pad,
2246 GstMiniObject *mini_obj,
2247 EmpathyCallWindow *self)
2250 if (GST_IS_EVENT (mini_obj))
2253 if (G_UNLIKELY (!self->priv->got_video))
2255 /* show the remote video */
2256 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2257 empathy_call_window_show_video_output_cb,
2258 g_object_ref (self), g_object_unref);
2260 self->priv->got_video = TRUE;
2266 /* Called from the streaming thread */
2268 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2269 GstPad *src, guint media_type, gpointer user_data)
2271 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2272 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2273 gboolean retval = FALSE;
2277 g_mutex_lock (priv->lock);
2281 case TP_MEDIA_STREAM_TYPE_AUDIO:
2282 pad = empathy_call_window_get_audio_sink_pad (self);
2284 case TP_MEDIA_STREAM_TYPE_VIDEO:
2285 g_idle_add (empathy_call_window_show_video_output_cb, self);
2286 pad = empathy_call_window_get_video_sink_pad (self);
2288 gst_pad_add_data_probe (src,
2289 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2290 if (priv->got_video_src > 0)
2291 g_source_remove (priv->got_video_src);
2292 priv->got_video_src = g_timeout_add_seconds (5,
2293 empathy_call_window_check_video_cb, self);
2296 g_assert_not_reached ();
2302 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2303 g_warning ("Could not link %s sink pad",
2304 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2308 gst_object_unref (pad);
2312 /* If no sink could be linked, try to add fakesink to prevent the whole call
2317 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2319 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2321 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2322 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2323 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2325 gst_element_set_locked_state (fakesink, TRUE);
2326 gst_element_set_state (fakesink, GST_STATE_NULL);
2327 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2331 DEBUG ("Could not link real sink, linked fakesink instead");
2333 gst_object_unref (sinkpad);
2337 gst_object_unref (fakesink);
2342 g_mutex_unlock (priv->lock);
2348 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2349 GstPad *sink, FsMediaType media_type, gpointer user_data)
2351 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2352 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2354 gboolean retval = FALSE;
2358 case FS_MEDIA_TYPE_AUDIO:
2359 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2361 g_warning ("Could not add audio source to pipeline");
2365 pad = gst_element_get_static_pad (priv->audio_input, "src");
2368 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2369 g_warning ("Could not get source pad from audio source");
2373 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2375 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2376 g_warning ("Could not link audio source to farsight");
2380 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2382 g_warning ("Could not start audio source");
2383 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2384 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2390 case FS_MEDIA_TYPE_VIDEO:
2391 if (priv->video_tee != NULL)
2393 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2394 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2396 g_warning ("Could not link video source input pipeline");
2399 gst_object_unref (pad);
2405 g_assert_not_reached ();
2412 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2415 GstElement *preview;
2417 disable_camera (self);
2419 DEBUG ("remove video input");
2420 preview = priv->video_preview_sink;
2422 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2423 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2424 gst_element_set_state (preview, GST_STATE_NULL);
2426 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2429 g_object_unref (priv->video_input);
2430 priv->video_input = NULL;
2431 g_object_unref (priv->video_tee);
2432 priv->video_tee = NULL;
2433 clutter_actor_destroy (priv->video_preview);
2434 priv->video_preview = NULL;
2436 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2440 start_call (EmpathyCallWindow *self)
2442 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2444 priv->call_started = TRUE;
2445 empathy_call_handler_start_call (priv->handler,
2446 gtk_get_current_event_time ());
2448 if (empathy_call_handler_has_initial_video (priv->handler))
2450 TpyCallChannel *call;
2453 g_object_get (priv->handler, "call-channel", &call, NULL);
2454 s = tpy_call_channel_get_video_state (call);
2456 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2457 s == TPY_SENDING_STATE_SENDING)
2459 /* Enable 'send video' buttons and display the preview */
2460 gtk_toggle_tool_button_set_active (
2461 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2465 gtk_toggle_tool_button_set_active (
2466 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2468 if (priv->video_preview == NULL)
2470 create_video_preview (self);
2471 add_video_preview_to_pipeline (self);
2475 g_object_unref (call);
2480 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2483 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2484 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2487 empathy_call_handler_bus_message (priv->handler, bus, message);
2489 switch (GST_MESSAGE_TYPE (message))
2491 case GST_MESSAGE_STATE_CHANGED:
2492 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2494 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2496 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2497 !priv->call_started)
2499 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2500 if (newstate == GST_STATE_PAUSED)
2502 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2503 priv->pipeline_playing = TRUE;
2505 if (priv->start_call_when_playing)
2510 case GST_MESSAGE_ERROR:
2512 GError *error = NULL;
2513 GstElement *gst_error;
2516 gst_message_parse_error (message, &error, &debug);
2517 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2519 g_message ("Element error: %s -- %s\n", error->message, debug);
2521 if (g_str_has_prefix (gst_element_get_name (gst_error),
2522 VIDEO_INPUT_ERROR_PREFIX))
2524 /* Remove the video input and continue */
2525 if (priv->video_input != NULL)
2526 empathy_call_window_remove_video_input (self);
2527 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2531 empathy_call_window_disconnected (self, TRUE);
2533 g_error_free (error);
2536 case GST_MESSAGE_UNKNOWN:
2537 case GST_MESSAGE_EOS:
2538 case GST_MESSAGE_WARNING:
2539 case GST_MESSAGE_INFO:
2540 case GST_MESSAGE_TAG:
2541 case GST_MESSAGE_BUFFERING:
2542 case GST_MESSAGE_STATE_DIRTY:
2543 case GST_MESSAGE_STEP_DONE:
2544 case GST_MESSAGE_CLOCK_PROVIDE:
2545 case GST_MESSAGE_CLOCK_LOST:
2546 case GST_MESSAGE_NEW_CLOCK:
2547 case GST_MESSAGE_STRUCTURE_CHANGE:
2548 case GST_MESSAGE_STREAM_STATUS:
2549 case GST_MESSAGE_APPLICATION:
2550 case GST_MESSAGE_ELEMENT:
2551 case GST_MESSAGE_SEGMENT_START:
2552 case GST_MESSAGE_SEGMENT_DONE:
2553 case GST_MESSAGE_DURATION:
2554 case GST_MESSAGE_ANY:
2563 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2564 GHashTable *members,
2565 EmpathyCallWindow *self)
2567 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2568 GHashTableIter iter;
2569 gpointer key, value;
2570 gboolean held = FALSE;
2572 g_hash_table_iter_init (&iter, members);
2573 while (g_hash_table_iter_next (&iter, &key, &value))
2575 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2577 /* This assumes this is a 1-1 call, otherwise one participant
2578 * putting the call on hold wouldn't mean the call is on hold
2586 priv->call_state = HELD;
2587 else if (priv->call_state == HELD)
2588 priv->call_state = CONNECTED;
2592 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2594 EmpathyCallWindow *self)
2596 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2597 TpyCallChannel *call;
2599 g_object_get (priv->handler, "call-channel", &call, NULL);
2604 tp_g_signal_connect_object (call, "audio-stream-error",
2605 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2606 tp_g_signal_connect_object (call, "video-stream-error",
2607 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2610 tp_g_signal_connect_object (call, "members-changed",
2611 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2613 g_object_unref (call);
2617 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2619 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2620 TpyCallChannel *call;
2623 /* Make the hangup button twice as wide */
2624 width = gtk_widget_get_allocated_width (priv->hangup_button);
2625 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2627 g_signal_connect (priv->handler, "state-changed",
2628 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2629 g_signal_connect (priv->handler, "conference-added",
2630 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2631 g_signal_connect (priv->handler, "conference-removed",
2632 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2633 g_signal_connect (priv->handler, "closed",
2634 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2635 g_signal_connect (priv->handler, "src-pad-added",
2636 G_CALLBACK (empathy_call_window_src_added_cb), window);
2637 g_signal_connect (priv->handler, "sink-pad-added",
2638 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2639 g_signal_connect (priv->handler, "sink-pad-removed",
2640 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2642 g_object_get (priv->handler, "call-channel", &call, NULL);
2645 call_handler_notify_call_cb (priv->handler, NULL, window);
2646 g_object_unref (call);
2650 /* call-channel doesn't exist yet, we'll connect signals once it has been
2652 g_signal_connect (priv->handler, "notify::call-channel",
2653 G_CALLBACK (call_handler_notify_call_cb), window);
2656 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2660 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2661 EmpathyCallWindow *window)
2663 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2665 if (priv->pipeline != NULL)
2667 if (priv->bus_message_source_id != 0)
2669 g_source_remove (priv->bus_message_source_id);
2670 priv->bus_message_source_id = 0;
2673 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2676 if (priv->call_state == CONNECTING)
2677 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2683 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2686 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2688 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2693 gtk_widget_hide (priv->dtmf_panel);
2694 gtk_widget_hide (menu);
2695 gtk_widget_hide (priv->toolbar);
2699 if (priv->dialpad_was_visible_before_fs)
2700 gtk_widget_show (priv->dtmf_panel);
2702 gtk_widget_show (menu);
2703 gtk_widget_show (priv->toolbar);
2705 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2706 priv->original_height_before_fs);
2711 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2713 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2715 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2716 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2717 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2718 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2720 if (priv->video_output != NULL)
2723 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2724 priv->video_output, TRUE, TRUE,
2725 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2732 empathy_call_window_state_event_cb (GtkWidget *widget,
2733 GdkEventWindowState *event, EmpathyCallWindow *window)
2735 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2737 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2738 gboolean set_fullscreen = event->new_window_state &
2739 GDK_WINDOW_STATE_FULLSCREEN;
2743 gboolean dialpad_was_visible;
2744 GtkAllocation allocation;
2745 gint original_width, original_height;
2747 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2748 original_width = allocation.width;
2749 original_height = allocation.height;
2751 g_object_get (priv->dtmf_panel,
2752 "visible", &dialpad_was_visible,
2755 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
2756 priv->original_width_before_fs = original_width;
2757 priv->original_height_before_fs = original_height;
2759 if (priv->video_output_motion_handler_id == 0 &&
2760 priv->video_output != NULL)
2762 priv->video_output_motion_handler_id = g_signal_connect (
2763 G_OBJECT (priv->video_container), "motion-notify-event",
2764 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2770 disconnect_video_output_motion_handler (window);
2773 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2775 show_controls (window, set_fullscreen);
2776 show_borders (window, set_fullscreen);
2777 gtk_action_set_stock_id (priv->menu_fullscreen,
2778 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2779 priv->is_fullscreen = set_fullscreen;
2786 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
2789 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2790 int w, h, dialpad_width;
2791 GtkAllocation allocation;
2793 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2794 w = allocation.width;
2795 h = allocation.height;
2797 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
2801 gtk_widget_show (priv->dtmf_panel);
2807 gtk_widget_hide (priv->dtmf_panel);
2811 gtk_window_resize (GTK_WINDOW (window), w, h);
2815 empathy_call_window_set_send_video (EmpathyCallWindow *window,
2818 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2819 TpyCallChannel *call;
2821 priv->sending_video = (state == CAMERA_STATE_ON);
2823 if (state == CAMERA_STATE_ON)
2825 /* When we start sending video, we want to show the video preview by
2827 display_video_preview (window, TRUE);
2831 display_video_preview (window, FALSE);
2834 if (priv->call_state != CONNECTED)
2837 g_object_get (priv->handler, "call-channel", &call, NULL);
2838 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2839 tpy_call_channel_send_video (call, priv->sending_video);
2840 g_object_unref (call);
2844 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2845 EmpathyCallWindow *window)
2847 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2850 active = (gtk_toggle_tool_button_get_active (toggle));
2854 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2855 priv->volume * 100);
2859 /* TODO, Instead of setting the input volume to 0 we should probably
2860 * stop sending but this would cause the audio call to drop if both
2861 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2862 * in the future. GNOME #574574
2864 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
2870 empathy_call_window_hangup_cb (gpointer object,
2871 EmpathyCallWindow *self)
2873 empathy_call_handler_stop_call (self->priv->handler);
2875 empathy_call_window_disconnected (self, TRUE);
2879 empathy_call_window_restart_call (EmpathyCallWindow *window)
2881 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2883 /* Remove error info bars */
2884 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
2885 (GtkCallback) gtk_widget_destroy, NULL);
2887 create_video_output_widget (window);
2889 /* While the call was disconnected, the input volume might have changed.
2890 * However, since the audio_input source was destroyed, its volume has not
2891 * been updated during that time. That's why we manually update it here */
2892 empathy_call_window_mic_volume_changed (window);
2894 priv->outgoing = TRUE;
2895 empathy_call_window_set_state_connecting (window);
2897 if (priv->pipeline_playing)
2898 start_call (window);
2900 /* call will be started when the pipeline is ready */
2901 priv->start_call_when_playing = TRUE;
2903 empathy_call_window_setup_avatars (window, priv->handler);
2905 empathy_call_window_show_hangup_button (window, TRUE);
2909 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
2910 EmpathyCallWindow *window)
2914 active = gtk_toggle_tool_button_get_active (button);
2916 empathy_call_window_show_dialpad (window, active);
2920 empathy_call_window_fullscreen_cb (gpointer object,
2921 EmpathyCallWindow *window)
2923 empathy_call_window_fullscreen_toggle (window);
2927 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
2929 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2931 if (priv->is_fullscreen)
2932 gtk_window_unfullscreen (GTK_WINDOW (window));
2934 gtk_window_fullscreen (GTK_WINDOW (window));
2938 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
2939 GdkEventButton *event, EmpathyCallWindow *window)
2941 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
2943 empathy_call_window_video_menu_popup (window, event->button);
2951 empathy_call_window_key_press_cb (GtkWidget *video_output,
2952 GdkEventKey *event, EmpathyCallWindow *window)
2954 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2956 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
2958 /* Since we are in fullscreen mode, toggling will bring us back to
2960 empathy_call_window_fullscreen_toggle (window);
2968 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
2969 GdkEventMotion *event, EmpathyCallWindow *window)
2971 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2973 if (priv->is_fullscreen)
2975 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
2982 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
2986 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2988 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2990 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
2991 button, gtk_get_current_event_time ());
2992 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
2996 empathy_call_window_status_message (EmpathyCallWindow *self,
2999 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3003 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3004 gdouble value, EmpathyCallWindow *window)
3006 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3008 if (priv->audio_output == NULL)
3011 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3016 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3018 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3020 return priv->ui_manager;
3023 EmpathyGstAudioSrc *
3024 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3026 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3028 return (EmpathyGstAudioSrc *) priv->audio_input;