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-tp-contact-factory.h>
45 #include <libempathy/empathy-utils.h>
46 #include <libempathy-gtk/empathy-avatar-image.h>
47 #include <libempathy-gtk/empathy-ui-utils.h>
48 #include <libempathy-gtk/empathy-sound-manager.h>
49 #include <libempathy-gtk/empathy-geometry.h>
50 #include <libempathy-gtk/empathy-images.h>
52 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
53 #include <libempathy/empathy-debug.h>
55 #include "empathy-call-window.h"
56 #include "empathy-call-window-fullscreen.h"
57 #include "empathy-call-factory.h"
58 #include "empathy-video-widget.h"
59 #include "empathy-audio-src.h"
60 #include "empathy-audio-sink.h"
61 #include "empathy-video-src.h"
62 #include "ev-sidebar.h"
64 #define CONTENT_HBOX_BORDER_WIDTH 6
65 #define CONTENT_HBOX_SPACING 3
66 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
68 #define SELF_VIDEO_SECTION_WIDTH 120
69 #define SELF_VIDEO_SECTION_HEIGTH 90
71 /* The avatar's default width and height are set to the same value because we
72 want a square icon. */
73 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
74 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
75 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
77 #define SMALL_TOOLBAR_SIZE 36
79 /* If an video input error occurs, the error message will start with "v4l" */
80 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
82 /* The time interval in milliseconds between 2 outgoing rings */
83 #define MS_BETWEEN_RING 500
85 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
88 PROP_CALL_HANDLER = 1,
100 CAMERA_STATE_OFF = 0,
104 struct _EmpathyCallWindowPriv
106 gboolean dispose_has_run;
107 EmpathyCallHandler *handler;
109 EmpathyContact *contact;
111 EmpathyCameraMonitor *camera_monitor;
116 GtkUIManager *ui_manager;
117 GtkWidget *errors_vbox;
118 /* widget displays the video received from the remote user. This widget is
119 * alive only during call. */
120 ClutterActor *video_output;
121 ClutterActor *video_preview;
122 ClutterActor *preview_hidden_button;
123 GtkWidget *video_container;
124 GtkWidget *remote_user_avatar_widget;
125 GtkWidget *remote_user_avatar_toolbar;
126 GtkWidget *remote_user_name_toolbar;
128 GtkWidget *volume_item;
129 GtkWidget *status_label;
130 GtkWidget *redial_button;
131 GtkWidget *mic_button;
132 GtkWidget *camera_button;
133 GtkWidget *dialpad_button;
135 GtkWidget *bottom_toolbar;
138 GtkAction *menu_sidebar;
139 GtkAction *menu_fullscreen;
141 /* The box that contains self and remote avatar and video
142 input/output. When we redial, we destroy and re-create the box */
143 ClutterActor *video_box;
144 ClutterLayoutManager *video_layout;
146 /* We keep a reference on the hbox which contains the main content so we can
147 easilly repack everything when toggling fullscreen */
148 GtkWidget *content_hbox;
150 gulong video_output_motion_handler_id;
151 guint bus_message_source_id;
154 GtkWidget *volume_scale;
155 GtkWidget *volume_progress_bar;
156 GtkAdjustment *audio_input_adj;
158 GtkWidget *dtmf_panel;
161 GtkWidget *details_vbox;
162 GtkWidget *vcodec_encoding_label;
163 GtkWidget *acodec_encoding_label;
164 GtkWidget *vcodec_decoding_label;
165 GtkWidget *acodec_decoding_label;
167 GtkWidget *audio_remote_candidate_label;
168 GtkWidget *audio_local_candidate_label;
169 GtkWidget *video_remote_candidate_label;
170 GtkWidget *video_local_candidate_label;
171 GtkWidget *video_remote_candidate_info_img;
172 GtkWidget *video_local_candidate_info_img;
173 GtkWidget *audio_remote_candidate_info_img;
174 GtkWidget *audio_local_candidate_info_img;
176 GstElement *video_input;
177 GstElement *video_preview_sink;
178 GstElement *video_output_sink;
179 GstElement *audio_input;
180 GstElement *audio_output;
181 GstElement *pipeline;
182 GstElement *video_tee;
191 GtkWidget *video_contrast;
192 GtkWidget *video_brightness;
193 GtkWidget *video_gamma;
196 gboolean call_started;
197 gboolean sending_video;
198 CameraState camera_state;
200 EmpathyCallWindowFullscreen *fullscreen;
201 gboolean is_fullscreen;
206 /* Those fields represent the state of the window before it actually was in
208 gboolean sidebar_was_visible_before_fs;
209 gint original_width_before_fs;
210 gint original_height_before_fs;
212 gint x, y, w, h, sidebar_width;
215 /* TRUE if the call should be started when the pipeline is playing */
216 gboolean start_call_when_playing;
217 /* TRUE if we requested to set the pipeline in the playing state */
218 gboolean pipeline_playing;
220 EmpathySoundManager *sound_mgr;
223 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
225 static void empathy_call_window_realized_cb (GtkWidget *widget,
226 EmpathyCallWindow *window);
228 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
229 GdkEvent *event, EmpathyCallWindow *window);
231 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
232 GdkEventWindowState *event, EmpathyCallWindow *window);
234 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
237 static void empathy_call_window_mic_toggled_cb (
238 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
240 static void empathy_call_window_sidebar_cb (GtkToggleAction *menu,
241 EmpathyCallWindow *self);
243 static void empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
244 EmpathyCallWindow *window);
246 static void empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
247 EmpathyCallWindow *window);
249 static void empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
251 EmpathyCallWindow *window);
253 static void empathy_call_window_hangup_cb (gpointer object,
254 EmpathyCallWindow *window);
256 static void empathy_call_window_fullscreen_cb (gpointer object,
257 EmpathyCallWindow *window);
259 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
261 static gboolean empathy_call_window_video_button_press_cb (
262 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
264 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
265 GdkEventKey *event, EmpathyCallWindow *window);
267 static gboolean empathy_call_window_video_output_motion_notify (
268 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
270 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
273 static void empathy_call_window_redial_cb (gpointer object,
274 EmpathyCallWindow *window);
276 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
277 EmpathyCallWindow *window);
279 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
281 static void empathy_call_window_status_message (EmpathyCallWindow *window,
284 static gboolean empathy_call_window_bus_message (GstBus *bus,
285 GstMessage *message, gpointer user_data);
288 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
289 gdouble value, EmpathyCallWindow *window);
292 empathy_call_window_setup_toolbars (EmpathyCallWindow *self)
294 EmpathyCallWindowPriv *priv = GET_PRIV (self);
295 GtkWidget *volume_button;
296 GtkToolItem *tool_item;
298 /* Add an empty expanded GtkToolItem to the top toolbar */
299 tool_item = gtk_tool_item_new ();
300 gtk_tool_item_set_expand (tool_item, TRUE);
301 gtk_widget_show (GTK_WIDGET (tool_item));
302 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
304 /* Set the remote name */
305 tool_item = gtk_tool_item_new ();
306 priv->remote_user_name_toolbar = gtk_label_new (NULL);
307 gtk_container_add (GTK_CONTAINER (tool_item),
308 priv->remote_user_name_toolbar);
309 gtk_widget_show_all (GTK_WIDGET (tool_item));
310 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
312 /* Add some space between the image and the name */
313 tool_item = gtk_separator_tool_item_new ();
314 gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item),
316 gtk_widget_show (GTK_WIDGET (tool_item));
317 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
319 /* Set the remote avatar */
320 tool_item = gtk_tool_item_new ();
321 priv->remote_user_avatar_toolbar = gtk_image_new ();
322 gtk_container_add (GTK_CONTAINER (tool_item),
323 priv->remote_user_avatar_toolbar);
324 gtk_widget_show_all (GTK_WIDGET (tool_item));
325 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
327 /* Set the volume button */
328 volume_button = gtk_volume_button_new ();
329 /* FIXME listen to the audiosinks signals and update the button according to
330 * that, for now starting out at 1.0 and assuming only the app changes the
332 gtk_scale_button_set_value (GTK_SCALE_BUTTON (volume_button), 1.0);
333 g_signal_connect (G_OBJECT (volume_button), "value-changed",
334 G_CALLBACK (empathy_call_window_volume_changed_cb), self);
336 gtk_container_add (GTK_CONTAINER (priv->volume_item),
338 gtk_widget_show (GTK_WIDGET (volume_button));
340 /* Add an empty expanded GtkToolItem so the label is at the end */
341 tool_item = gtk_tool_item_new ();
342 gtk_tool_item_set_expand (tool_item, TRUE);
343 gtk_widget_show (GTK_WIDGET (tool_item));
344 gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
346 /* Set the status label */
347 tool_item = gtk_tool_item_new ();
348 priv->status_label = gtk_label_new (NULL);
349 gtk_container_add (GTK_CONTAINER (tool_item),
351 gtk_widget_show_all (GTK_WIDGET (tool_item));
352 gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
356 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
358 EmpathyCallWindowPriv *priv = GET_PRIV (window);
359 TpyCallChannel *call;
363 g_object_get (priv->handler, "call-channel", &call, NULL);
365 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
366 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
369 tpy_call_channel_dtmf_start_tone (call, event);
371 g_object_unref (call);
375 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
377 EmpathyCallWindowPriv *priv = GET_PRIV (window);
378 TpyCallChannel *call;
380 g_object_get (priv->handler, "call-channel", &call, NULL);
382 tpy_call_channel_dtmf_stop_tone (call);
384 g_object_unref (call);
388 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
389 gchar *label_text, GtkWidget *bin)
391 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
392 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
393 GtkWidget *label = gtk_label_new (label_text);
395 gtk_widget_set_sensitive (scale, FALSE);
397 gtk_container_add (GTK_CONTAINER (bin), vbox);
399 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
400 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
401 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
407 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
408 EmpathyCallWindow *self)
411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
413 empathy_video_src_set_channel (priv->video_input,
414 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
418 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
419 EmpathyCallWindow *self)
422 EmpathyCallWindowPriv *priv = GET_PRIV (self);
424 empathy_video_src_set_channel (priv->video_input,
425 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
429 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
430 EmpathyCallWindow *self)
433 EmpathyCallWindowPriv *priv = GET_PRIV (self);
435 empathy_video_src_set_channel (priv->video_input,
436 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
441 empathy_call_window_create_video_input (EmpathyCallWindow *self)
443 EmpathyCallWindowPriv *priv = GET_PRIV (self);
446 hbox = gtk_hbox_new (TRUE, 3);
448 priv->video_contrast = empathy_call_window_create_video_input_add_slider (
449 self, _("Contrast"), hbox);
451 priv->video_brightness = empathy_call_window_create_video_input_add_slider (
452 self, _("Brightness"), hbox);
454 priv->video_gamma = empathy_call_window_create_video_input_add_slider (
455 self, _("Gamma"), hbox);
461 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
463 EmpathyCallWindowPriv *priv = GET_PRIV (self);
467 supported = empathy_video_src_get_supported_channels (priv->video_input);
469 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
471 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
473 gtk_adjustment_set_value (adj,
474 empathy_video_src_get_channel (priv->video_input,
475 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
477 g_signal_connect (G_OBJECT (adj), "value-changed",
478 G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
480 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
483 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
485 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
487 gtk_adjustment_set_value (adj,
488 empathy_video_src_get_channel (priv->video_input,
489 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
491 g_signal_connect (G_OBJECT (adj), "value-changed",
492 G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
493 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
496 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
498 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
500 gtk_adjustment_set_value (adj,
501 empathy_video_src_get_channel (priv->video_input,
502 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
504 g_signal_connect (G_OBJECT (adj), "value-changed",
505 G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
506 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
511 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
512 EmpathyCallWindow *self)
514 EmpathyCallWindowPriv *priv = GET_PRIV (self);
517 volume = gtk_adjustment_get_value (adj)/100.0;
519 /* Don't store the volume because of muting */
520 if (volume > 0 || gtk_toggle_tool_button_get_active (
521 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
522 priv->volume = volume;
524 /* Ensure that the toggle button is active if the volume is > 0 and inactive
525 * if it's smaller than 0 */
526 if ((volume > 0) != gtk_toggle_tool_button_get_active (
527 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
528 gtk_toggle_tool_button_set_active (
529 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
531 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
536 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
537 gdouble level, EmpathyCallWindow *window)
540 EmpathyCallWindowPriv *priv = GET_PRIV (window);
542 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
543 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
548 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
550 EmpathyCallWindowPriv *priv = GET_PRIV (self);
551 GtkWidget *hbox, *vbox, *label;
553 hbox = gtk_hbox_new (TRUE, 3);
555 vbox = gtk_vbox_new (FALSE, 3);
556 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
558 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
559 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
560 label = gtk_label_new (_("Volume"));
562 priv->audio_input_adj = gtk_range_get_adjustment (
563 GTK_RANGE (priv->volume_scale));
564 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
565 (priv->audio_input));
566 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
568 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
569 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
571 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
572 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
574 priv->volume_progress_bar = gtk_progress_bar_new ();
576 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
577 GTK_ORIENTATION_VERTICAL);
579 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
582 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
589 empathy_call_window_show_video_output (EmpathyCallWindow *self,
592 if (self->priv->video_output != NULL)
593 g_object_set (self->priv->video_output, "visible", show, NULL);
595 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
599 create_video_output_widget (EmpathyCallWindow *self)
601 EmpathyCallWindowPriv *priv = GET_PRIV (self);
603 g_assert (priv->video_output == NULL);
604 g_assert (priv->pipeline != NULL);
606 priv->video_output = clutter_texture_new ();
608 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
611 priv->video_output_sink = clutter_gst_video_sink_new (
612 CLUTTER_TEXTURE (priv->video_output));
614 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
617 gtk_widget_add_events (priv->video_container,
618 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
619 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
620 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
624 create_video_input (EmpathyCallWindow *self)
626 EmpathyCallWindowPriv *priv = GET_PRIV (self);
628 g_assert (priv->video_input == NULL);
629 priv->video_input = empathy_video_src_new ();
630 gst_object_ref (priv->video_input);
631 gst_object_sink (priv->video_input);
635 create_audio_input (EmpathyCallWindow *self)
637 EmpathyCallWindowPriv *priv = GET_PRIV (self);
639 g_assert (priv->audio_input == NULL);
640 priv->audio_input = empathy_audio_src_new ();
641 gst_object_ref (priv->audio_input);
642 gst_object_sink (priv->audio_input);
644 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
645 G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
650 add_video_preview_to_pipeline (EmpathyCallWindow *self)
652 EmpathyCallWindowPriv *priv = GET_PRIV (self);
655 g_assert (priv->video_preview != NULL);
656 g_assert (priv->pipeline != NULL);
657 g_assert (priv->video_input != NULL);
658 g_assert (priv->video_tee != NULL);
660 preview = priv->video_preview_sink;
662 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
664 g_warning ("Could not add video input to pipeline");
668 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
670 g_warning ("Could not add video preview to pipeline");
674 if (!gst_element_link (priv->video_input, priv->video_tee))
676 g_warning ("Could not link video input to video tee");
680 if (!gst_element_link (priv->video_tee, preview))
682 g_warning ("Could not link video tee to video preview");
688 empathy_call_window_disable_camera_cb (GtkAction *action,
689 EmpathyCallWindow *self)
691 clutter_actor_destroy (self->priv->preview_hidden_button);
693 gtk_toggle_tool_button_set_active (
694 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
698 empathy_call_window_minimise_camera_cb (GtkAction *action,
699 EmpathyCallWindow *self)
701 clutter_actor_hide (self->priv->video_preview);
702 clutter_actor_show (self->priv->preview_hidden_button);
706 empathy_call_window_maximise_camera_cb (GtkAction *action,
707 EmpathyCallWindow *self)
709 clutter_actor_show (self->priv->video_preview);
710 clutter_actor_hide (self->priv->preview_hidden_button);
714 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
715 EmpathyCallWindow *self)
719 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
721 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
722 0, gtk_get_current_event_time ());
723 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
727 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
728 EmpathyCallWindow *self)
732 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
733 "/preview-hidden-menu");
734 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
735 0, gtk_get_current_event_time ());
736 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
740 create_video_preview (EmpathyCallWindow *self)
742 EmpathyCallWindowPriv *priv = GET_PRIV (self);
743 ClutterLayoutManager *layout, *layout_center;
744 ClutterActor *preview;
749 g_assert (priv->video_preview == NULL);
751 preview = clutter_texture_new ();
752 clutter_actor_set_size (preview,
753 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
754 priv->video_preview_sink = clutter_gst_video_sink_new (
755 CLUTTER_TEXTURE (preview));
757 /* Flip the video preview */
758 clutter_actor_set_rotation (preview,
761 SELF_VIDEO_SECTION_WIDTH * 0.5,
765 /* Add a little offset to the video preview */
766 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
767 CLUTTER_BIN_ALIGNMENT_START);
768 priv->video_preview = clutter_box_new (layout);
769 clutter_actor_set_size (priv->video_preview,
770 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
772 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
773 CLUTTER_BIN_ALIGNMENT_CENTER);
774 box = clutter_box_new (layout_center);
775 clutter_actor_set_size (box,
776 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
778 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
779 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
781 g_object_set (priv->video_preview_sink,
786 /* Translators: this is an "Info" label. It should be as short
788 button = gtk_button_new_with_label (_("i"));
789 b = gtk_clutter_actor_new_with_contents (button);
791 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
793 CLUTTER_BIN_ALIGNMENT_END,
794 CLUTTER_BIN_ALIGNMENT_END);
796 g_signal_connect (button, "clicked",
797 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
800 /* Translators: this is an "Info" label. It should be as short
802 button = gtk_button_new_with_label (_("i"));
803 priv->preview_hidden_button =
804 gtk_clutter_actor_new_with_contents (button);
806 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
807 priv->preview_hidden_button,
808 CLUTTER_BIN_ALIGNMENT_START,
809 CLUTTER_BIN_ALIGNMENT_END);
811 clutter_actor_hide (priv->preview_hidden_button);
813 g_signal_connect (button, "clicked",
814 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
817 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
819 CLUTTER_BIN_ALIGNMENT_START,
820 CLUTTER_BIN_ALIGNMENT_END);
824 play_camera (EmpathyCallWindow *window,
827 EmpathyCallWindowPriv *priv = GET_PRIV (window);
831 if (priv->video_preview == NULL)
833 create_video_preview (window);
834 add_video_preview_to_pipeline (window);
838 state = GST_STATE_PLAYING;
840 state = GST_STATE_NULL;
842 preview = priv->video_preview_sink;
844 gst_element_set_state (preview, state);
845 gst_element_set_state (priv->video_input, state);
846 gst_element_set_state (priv->video_tee, state);
850 display_video_preview (EmpathyCallWindow *self,
853 EmpathyCallWindowPriv *priv = GET_PRIV (self);
857 /* Display the video preview */
858 DEBUG ("Show video preview");
860 play_camera (self, TRUE);
861 clutter_actor_show (priv->video_preview);
865 /* Hide the video preview */
866 DEBUG ("Hide video preview");
868 if (priv->video_preview != NULL)
870 clutter_actor_hide (priv->video_preview);
871 play_camera (self, FALSE);
877 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
879 EmpathyCallWindowPriv *priv = GET_PRIV (window);
881 empathy_call_window_status_message (window, _("Connecting…"));
882 priv->call_state = CONNECTING;
885 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
886 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
890 disable_camera (EmpathyCallWindow *self)
892 EmpathyCallWindowPriv *priv = GET_PRIV (self);
894 if (priv->camera_state == CAMERA_STATE_OFF)
897 DEBUG ("Disable camera");
899 display_video_preview (self, FALSE);
901 if (priv->camera_state == CAMERA_STATE_ON)
902 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
904 priv->camera_state = CAMERA_STATE_OFF;
908 enable_camera (EmpathyCallWindow *self)
910 EmpathyCallWindowPriv *priv = GET_PRIV (self);
912 if (priv->camera_state == CAMERA_STATE_ON)
915 if (priv->video_input == NULL)
917 DEBUG ("Can't enable camera, no input");
921 DEBUG ("Enable camera");
923 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
925 priv->camera_state = CAMERA_STATE_ON;
929 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
930 EmpathyCallWindow *self)
932 if (gtk_toggle_tool_button_get_active (toggle))
933 enable_camera (self);
935 disable_camera (self);
939 create_pipeline (EmpathyCallWindow *self)
941 EmpathyCallWindowPriv *priv = GET_PRIV (self);
944 g_assert (priv->pipeline == NULL);
946 priv->pipeline = gst_pipeline_new (NULL);
947 priv->pipeline_playing = FALSE;
949 priv->video_tee = gst_element_factory_make ("tee", NULL);
950 gst_object_ref (priv->video_tee);
951 gst_object_sink (priv->video_tee);
953 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
955 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
956 priv->bus_message_source_id = gst_bus_add_watch (bus,
957 empathy_call_window_bus_message, self);
959 g_object_unref (bus);
963 empathy_call_window_configure_event_cb (GtkWidget *widget,
965 EmpathyCallWindow *self)
967 GdkWindow *gdk_window;
968 GdkWindowState window_state;
970 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
971 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
973 gtk_widget_get_preferred_width (self->priv->sidebar,
974 &self->priv->sidebar_width, NULL);
976 gdk_window = gtk_widget_get_window (widget);
977 window_state = gdk_window_get_state (gdk_window);
978 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
984 empathy_call_window_destroyed_cb (GtkWidget *object,
985 EmpathyCallWindow *self)
987 if (gtk_widget_get_visible (self->priv->sidebar))
989 /* Save the geometry as if the sidebar was hidden. */
990 empathy_geometry_save_values (GTK_WINDOW (self),
991 self->priv->x, self->priv->y,
992 self->priv->w - self->priv->sidebar_width, self->priv->h,
993 self->priv->maximized);
998 empathy_call_window_init (EmpathyCallWindow *self)
1000 EmpathyCallWindowPriv *priv;
1002 GtkWidget *top_vbox;
1006 ClutterConstraint *size_constraint;
1007 ClutterActor *remote_avatar;
1008 GtkStyleContext *context;
1012 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1013 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1015 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1016 gui = empathy_builder_get_file (filename,
1017 "call_window_vbox", &top_vbox,
1018 "errors_vbox", &priv->errors_vbox,
1019 "pane", &priv->pane,
1020 "redial", &priv->redial_button,
1021 "volume", &priv->volume_item,
1022 "microphone", &priv->mic_button,
1023 "camera", &priv->camera_button,
1024 "dialpad", &priv->dialpad_button,
1025 "toolbar", &priv->toolbar,
1026 "bottom_toolbar", &priv->bottom_toolbar,
1027 "menuredial", &priv->redial,
1028 "menusidebar", &priv->menu_sidebar,
1029 "ui_manager", &priv->ui_manager,
1030 "menufullscreen", &priv->menu_fullscreen,
1031 "details_vbox", &priv->details_vbox,
1032 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1033 "acodec_encoding_label", &priv->acodec_encoding_label,
1034 "acodec_decoding_label", &priv->acodec_decoding_label,
1035 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1036 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1037 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1038 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1039 "video_local_candidate_label", &priv->video_local_candidate_label,
1040 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1041 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1042 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1043 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1047 empathy_builder_connect (gui, self,
1048 "menuhangup", "activate", empathy_call_window_hangup_cb,
1049 "hangup", "clicked", empathy_call_window_hangup_cb,
1050 "menuredial", "activate", empathy_call_window_redial_cb,
1051 "redial", "clicked", empathy_call_window_redial_cb,
1052 "menusidebar", "toggled", empathy_call_window_sidebar_cb,
1053 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1054 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1055 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1056 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1057 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1058 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1059 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1062 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1064 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1066 g_object_bind_property (priv->camera_monitor, "available",
1067 priv->camera_button, "sensitive",
1068 G_BINDING_SYNC_CREATE);
1070 priv->lock = g_mutex_new ();
1072 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1074 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1075 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1076 CONTENT_HBOX_BORDER_WIDTH);
1077 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1079 /* avatar/video box */
1080 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1081 CLUTTER_BIN_ALIGNMENT_CENTER);
1083 priv->video_box = clutter_box_new (priv->video_layout);
1085 priv->video_container = gtk_clutter_embed_new ();
1087 /* Set the background color to that of the rest of the window */
1088 context = gtk_widget_get_style_context (priv->content_hbox);
1089 gtk_style_context_get_background_color (context,
1090 GTK_STATE_FLAG_NORMAL, &rgba);
1091 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1092 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1093 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1094 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1095 clutter_stage_set_color (
1096 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1097 GTK_CLUTTER_EMBED (priv->video_container))),
1100 clutter_container_add (
1101 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1102 GTK_CLUTTER_EMBED (priv->video_container))),
1106 size_constraint = clutter_bind_constraint_new (
1107 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1108 CLUTTER_BIND_SIZE, 0);
1109 clutter_actor_add_constraint (priv->video_box, size_constraint);
1111 priv->remote_user_avatar_widget = gtk_image_new ();
1112 remote_avatar = gtk_clutter_actor_new_with_contents (
1113 priv->remote_user_avatar_widget);
1115 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1118 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1119 priv->video_container, TRUE, TRUE,
1120 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1122 create_pipeline (self);
1123 create_video_output_widget (self);
1124 create_audio_input (self);
1125 create_video_input (self);
1127 /* The call will be started as soon the pipeline is playing */
1128 priv->start_call_when_playing = TRUE;
1130 empathy_call_window_setup_toolbars (self);
1132 priv->sidebar = ev_sidebar_new ();
1133 g_signal_connect (G_OBJECT (priv->sidebar),
1134 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1135 g_signal_connect (G_OBJECT (priv->sidebar),
1136 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1137 g_signal_connect (G_OBJECT (priv->sidebar), "changed",
1138 G_CALLBACK (empathy_call_window_sidebar_changed_cb), self);
1139 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1141 page = empathy_call_window_create_audio_input (self);
1142 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1143 _("Audio input"), page);
1145 page = empathy_call_window_create_video_input (self);
1146 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1147 _("Video input"), page);
1149 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1150 G_CALLBACK (dtmf_button_pressed_cb),
1151 G_CALLBACK (dtmf_button_released_cb));
1152 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1153 _("Dialpad"), priv->dtmf_panel);
1155 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1157 /* Put the details vbox in a scroll window as it can require a lot of
1158 * horizontal space. */
1159 scroll = gtk_scrolled_window_new (NULL, NULL);
1160 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1161 priv->details_vbox);
1163 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details", _("Details"),
1166 gtk_widget_show_all (top_vbox);
1168 gtk_widget_hide (priv->sidebar);
1170 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1172 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1173 priv->video_container);
1175 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1176 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1178 g_signal_connect (G_OBJECT (self), "realize",
1179 G_CALLBACK (empathy_call_window_realized_cb), self);
1181 g_signal_connect (G_OBJECT (self), "delete-event",
1182 G_CALLBACK (empathy_call_window_delete_cb), self);
1184 g_signal_connect (G_OBJECT (self), "window-state-event",
1185 G_CALLBACK (empathy_call_window_state_event_cb), self);
1187 g_signal_connect (G_OBJECT (self), "key-press-event",
1188 G_CALLBACK (empathy_call_window_key_press_cb), self);
1190 priv->timer = g_timer_new ();
1192 g_object_ref (priv->ui_manager);
1193 g_object_unref (gui);
1195 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1197 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1198 /* These signals are used to track the window position and save it
1199 * when the window is destroyed. We need to do this as we don't want
1200 * the window geometry to be saved with the sidebar taken into account. */
1201 g_signal_connect (self, "destroy",
1202 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1203 g_signal_connect (self, "configure-event",
1204 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1205 g_signal_connect (self, "window-state-event",
1206 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1209 /* Instead of specifying a width and a height, we specify only one size. That's
1210 because we want a square avatar icon. */
1212 init_contact_avatar_with_size (EmpathyContact *contact,
1213 GtkWidget *image_widget,
1216 GdkPixbuf *pixbuf_avatar = NULL;
1218 if (contact != NULL)
1220 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1224 if (pixbuf_avatar == NULL)
1226 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1227 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1230 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1232 if (pixbuf_avatar != NULL)
1233 g_object_unref (pixbuf_avatar);
1237 set_window_title (EmpathyCallWindow *self)
1239 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1242 if (priv->contact != NULL)
1244 /* translators: Call is a noun and %s is the contact name. This string
1245 * is used in the window title */
1246 tmp = g_strdup_printf (_("Call with %s"),
1247 empathy_contact_get_alias (priv->contact));
1248 gtk_window_set_title (GTK_WINDOW (self), tmp);
1253 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1258 set_remote_user_name (EmpathyCallWindow *self,
1259 EmpathyContact *contact)
1261 const gchar *alias = empathy_contact_get_alias (contact);
1262 const gchar *status = empathy_contact_get_status (contact);
1265 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1266 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1272 contact_name_changed_cb (EmpathyContact *contact,
1274 EmpathyCallWindow *self)
1276 set_window_title (self);
1277 set_remote_user_name (self, contact);
1281 contact_presence_changed_cb (EmpathyContact *contact,
1283 EmpathyCallWindow *self)
1285 set_remote_user_name (self, contact);
1289 contact_avatar_changed_cb (EmpathyContact *contact,
1291 EmpathyCallWindow *self)
1294 GtkAllocation allocation;
1295 GtkWidget *avatar_widget;
1297 avatar_widget = self->priv->remote_user_avatar_widget;
1299 gtk_widget_get_allocation (avatar_widget, &allocation);
1300 size = allocation.height;
1304 /* the widget is not allocated yet, set a default size */
1305 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1306 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1309 init_contact_avatar_with_size (contact, avatar_widget, size);
1311 avatar_widget = self->priv->remote_user_avatar_toolbar;
1313 gtk_widget_get_allocation (avatar_widget, &allocation);
1314 size = allocation.height;
1318 /* the widget is not allocated yet, set a default size */
1319 size = SMALL_TOOLBAR_SIZE;
1322 init_contact_avatar_with_size (contact, avatar_widget, size);
1326 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1327 EmpathyCallHandler *handler)
1329 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1331 g_signal_connect (priv->contact, "notify::name",
1332 G_CALLBACK (contact_name_changed_cb), self);
1333 g_signal_connect (priv->contact, "notify::avatar",
1334 G_CALLBACK (contact_avatar_changed_cb), self);
1335 /* FIXME: There's no EmpathyContact::presence yet */
1336 g_signal_connect (priv->contact, "notify::presence",
1337 G_CALLBACK (contact_presence_changed_cb), self);
1339 set_window_title (self);
1340 set_remote_user_name (self, priv->contact);
1342 init_contact_avatar_with_size (priv->contact,
1343 priv->remote_user_avatar_widget,
1344 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1345 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1347 init_contact_avatar_with_size (priv->contact,
1348 priv->remote_user_avatar_toolbar,
1349 SMALL_TOOLBAR_SIZE);
1351 /* The remote avatar is shown by default and will be hidden when we receive
1352 video from the remote side. */
1353 clutter_actor_hide (priv->video_output);
1354 gtk_widget_show (priv->remote_user_avatar_widget);
1358 update_send_codec (EmpathyCallWindow *self,
1361 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1368 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1369 widget = priv->acodec_encoding_label;
1373 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1374 widget = priv->vcodec_encoding_label;
1380 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1381 gtk_label_set_text (GTK_LABEL (widget), tmp);
1386 send_audio_codec_notify_cb (GObject *object,
1390 EmpathyCallWindow *self = user_data;
1392 update_send_codec (self, TRUE);
1396 send_video_codec_notify_cb (GObject *object,
1400 EmpathyCallWindow *self = user_data;
1402 update_send_codec (self, FALSE);
1406 update_recv_codec (EmpathyCallWindow *self,
1409 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1412 GString *str = NULL;
1416 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1417 widget = priv->acodec_decoding_label;
1421 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1422 widget = priv->vcodec_decoding_label;
1428 for (l = codecs; l != NULL; l = g_list_next (l))
1430 FsCodec *codec = l->data;
1433 str = g_string_new (NULL);
1435 g_string_append (str, ", ");
1437 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1441 gtk_label_set_text (GTK_LABEL (widget), str->str);
1442 g_string_free (str, TRUE);
1446 recv_audio_codecs_notify_cb (GObject *object,
1450 EmpathyCallWindow *self = user_data;
1452 update_recv_codec (self, TRUE);
1456 recv_video_codecs_notify_cb (GObject *object,
1460 EmpathyCallWindow *self = user_data;
1462 update_recv_codec (self, FALSE);
1465 static const gchar *
1466 candidate_type_to_str (FsCandidate *candidate)
1468 switch (candidate->type)
1470 case FS_CANDIDATE_TYPE_HOST:
1472 case FS_CANDIDATE_TYPE_SRFLX:
1473 return "server reflexive";
1474 case FS_CANDIDATE_TYPE_PRFLX:
1475 return "peer reflexive";
1476 case FS_CANDIDATE_TYPE_RELAY:
1478 case FS_CANDIDATE_TYPE_MULTICAST:
1485 static const gchar *
1486 candidate_type_to_desc (FsCandidate *candidate)
1488 switch (candidate->type)
1490 case FS_CANDIDATE_TYPE_HOST:
1491 return _("The IP address as seen by the machine");
1492 case FS_CANDIDATE_TYPE_SRFLX:
1493 return _("The IP address as seen by a server on the Internet");
1494 case FS_CANDIDATE_TYPE_PRFLX:
1495 return _("The IP address of the peer as seen by the other side");
1496 case FS_CANDIDATE_TYPE_RELAY:
1497 return _("The IP address of a relay server");
1498 case FS_CANDIDATE_TYPE_MULTICAST:
1499 return _("The IP address of the multicast group");
1506 update_candidat_widget (EmpathyCallWindow *self,
1509 FsCandidate *candidate)
1513 g_assert (candidate != NULL);
1514 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1515 candidate->port, candidate_type_to_str (candidate));
1517 gtk_label_set_text (GTK_LABEL (label), str);
1518 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1524 candidates_changed_cb (GObject *object,
1526 EmpathyCallWindow *self)
1528 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1529 FsCandidate *candidate = NULL;
1531 if (type == FS_MEDIA_TYPE_VIDEO)
1533 /* Update remote candidate */
1534 candidate = empathy_call_handler_get_video_remote_candidate (
1537 update_candidat_widget (self, priv->video_remote_candidate_label,
1538 priv->video_remote_candidate_info_img, candidate);
1540 /* Update local candidate */
1541 candidate = empathy_call_handler_get_video_local_candidate (
1544 update_candidat_widget (self, priv->video_local_candidate_label,
1545 priv->video_local_candidate_info_img, candidate);
1549 /* Update remote candidate */
1550 candidate = empathy_call_handler_get_audio_remote_candidate (
1553 update_candidat_widget (self, priv->audio_remote_candidate_label,
1554 priv->audio_remote_candidate_info_img, candidate);
1556 /* Update local candidate */
1557 candidate = empathy_call_handler_get_audio_local_candidate (
1560 update_candidat_widget (self, priv->audio_local_candidate_label,
1561 priv->audio_local_candidate_info_img, candidate);
1566 empathy_call_window_constructed (GObject *object)
1568 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1569 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1570 TpyCallChannel *call;
1572 g_assert (priv->handler != NULL);
1574 g_object_get (priv->handler, "call-channel", &call, NULL);
1575 priv->outgoing = (call == NULL);
1577 g_object_unref (call);
1579 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1580 g_assert (priv->contact != NULL);
1582 empathy_call_window_setup_avatars (self, priv->handler);
1583 empathy_call_window_set_state_connecting (self);
1585 if (!empathy_call_handler_has_initial_video (priv->handler))
1587 gtk_toggle_tool_button_set_active (
1588 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1590 /* If call has InitialVideo, the preview will be started once the call has
1591 * been started (start_call()). */
1593 update_send_codec (self, TRUE);
1594 update_send_codec (self, FALSE);
1595 update_recv_codec (self, TRUE);
1596 update_recv_codec (self, FALSE);
1598 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1599 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1600 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1601 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1602 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1603 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1604 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1605 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1607 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1608 G_CALLBACK (candidates_changed_cb), self, 0);
1611 static void empathy_call_window_dispose (GObject *object);
1612 static void empathy_call_window_finalize (GObject *object);
1615 empathy_call_window_set_property (GObject *object,
1616 guint property_id, const GValue *value, GParamSpec *pspec)
1618 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1620 switch (property_id)
1622 case PROP_CALL_HANDLER:
1623 priv->handler = g_value_dup_object (value);
1626 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1631 empathy_call_window_get_property (GObject *object,
1632 guint property_id, GValue *value, GParamSpec *pspec)
1634 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1636 switch (property_id)
1638 case PROP_CALL_HANDLER:
1639 g_value_set_object (value, priv->handler);
1642 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1647 empathy_call_window_class_init (
1648 EmpathyCallWindowClass *empathy_call_window_class)
1650 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1651 GParamSpec *param_spec;
1653 g_type_class_add_private (empathy_call_window_class,
1654 sizeof (EmpathyCallWindowPriv));
1656 object_class->constructed = empathy_call_window_constructed;
1657 object_class->set_property = empathy_call_window_set_property;
1658 object_class->get_property = empathy_call_window_get_property;
1660 object_class->dispose = empathy_call_window_dispose;
1661 object_class->finalize = empathy_call_window_finalize;
1663 param_spec = g_param_spec_object ("handler",
1664 "handler", "The call handler",
1665 EMPATHY_TYPE_CALL_HANDLER,
1666 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1667 g_object_class_install_property (object_class,
1668 PROP_CALL_HANDLER, param_spec);
1672 empathy_call_window_dispose (GObject *object)
1674 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1675 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1677 if (priv->dispose_has_run)
1680 priv->dispose_has_run = TRUE;
1682 if (priv->handler != NULL)
1684 empathy_call_handler_stop_call (priv->handler);
1685 tp_clear_object (&priv->handler);
1688 if (priv->bus_message_source_id != 0)
1690 g_source_remove (priv->bus_message_source_id);
1691 priv->bus_message_source_id = 0;
1694 if (priv->got_video_src > 0)
1696 g_source_remove (priv->got_video_src);
1697 priv->got_video_src = 0;
1700 tp_clear_object (&priv->pipeline);
1701 tp_clear_object (&priv->video_input);
1702 tp_clear_object (&priv->audio_input);
1703 tp_clear_object (&priv->video_tee);
1704 tp_clear_object (&priv->ui_manager);
1705 tp_clear_object (&priv->fullscreen);
1706 tp_clear_object (&priv->camera_monitor);
1708 g_list_free_full (priv->notifiers, g_object_unref);
1710 if (priv->timer_id != 0)
1711 g_source_remove (priv->timer_id);
1714 if (priv->contact != NULL)
1716 g_signal_handlers_disconnect_by_func (priv->contact,
1717 contact_name_changed_cb, self);
1718 priv->contact = NULL;
1722 tp_clear_object (&priv->sound_mgr);
1724 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1728 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1730 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1732 if (priv->video_output_motion_handler_id != 0)
1734 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1735 priv->video_output_motion_handler_id);
1736 priv->video_output_motion_handler_id = 0;
1741 empathy_call_window_finalize (GObject *object)
1743 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1744 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1746 disconnect_video_output_motion_handler (self);
1748 /* free any data held directly by the object here */
1749 g_mutex_free (priv->lock);
1751 g_timer_destroy (priv->timer);
1753 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1758 empathy_call_window_new (EmpathyCallHandler *handler)
1760 return EMPATHY_CALL_WINDOW (
1761 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1765 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1766 GstElement *conference, gpointer user_data)
1768 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1769 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1770 FsElementAddedNotifier *notifier;
1773 DEBUG ("Conference added");
1775 /* Add notifier to set the various element properties as needed */
1776 notifier = fs_element_added_notifier_new ();
1777 keyfile = fs_utils_get_default_element_properties (conference);
1779 if (keyfile != NULL)
1780 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1782 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1784 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1786 gst_bin_add (GST_BIN (priv->pipeline), conference);
1787 gst_element_set_state (conference, GST_STATE_PLAYING);
1791 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1792 GstElement *conference, gpointer user_data)
1794 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1795 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1797 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1798 gst_element_set_state (conference, GST_STATE_NULL);
1802 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1804 GstStateChangeReturn state_change_return;
1805 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1807 if (priv->pipeline == NULL)
1810 if (priv->bus_message_source_id != 0)
1812 g_source_remove (priv->bus_message_source_id);
1813 priv->bus_message_source_id = 0;
1816 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1818 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1819 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1821 if (priv->pipeline != NULL)
1822 g_object_unref (priv->pipeline);
1823 priv->pipeline = NULL;
1825 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1826 empathy_call_window_mic_volume_changed_cb, self);
1828 if (priv->audio_output != NULL)
1829 g_object_unref (priv->audio_output);
1830 priv->audio_output = NULL;
1832 if (priv->video_tee != NULL)
1833 g_object_unref (priv->video_tee);
1834 priv->video_tee = NULL;
1836 if (priv->video_preview != NULL)
1837 clutter_actor_destroy (priv->video_preview);
1838 priv->video_preview = NULL;
1840 priv->funnel = NULL;
1842 create_pipeline (self);
1843 /* Call will be started when user will hit the 'redial' button */
1844 priv->start_call_when_playing = FALSE;
1845 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1851 g_message ("Error: could not destroy pipeline. Closing call window");
1852 gtk_widget_destroy (GTK_WIDGET (self));
1859 reset_details_pane (EmpathyCallWindow *self)
1861 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1863 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1864 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1865 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1866 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1870 empathy_call_window_disconnected (EmpathyCallWindow *self,
1873 gboolean could_disconnect = FALSE;
1874 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1875 gboolean could_reset_pipeline;
1877 /* Leave full screen mode if needed */
1878 gtk_window_unfullscreen (GTK_WINDOW (self));
1880 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1881 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1883 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1885 if (priv->call_state == CONNECTING)
1886 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1888 if (priv->call_state != REDIALING)
1889 priv->call_state = DISCONNECTED;
1891 if (could_reset_pipeline)
1893 g_mutex_lock (priv->lock);
1895 g_timer_stop (priv->timer);
1897 if (priv->timer_id != 0)
1898 g_source_remove (priv->timer_id);
1901 g_mutex_unlock (priv->lock);
1904 /* We are about to destroy the window, no need to update it or create
1905 * a video preview */
1908 empathy_call_window_status_message (self, _("Disconnected"));
1910 gtk_action_set_sensitive (priv->redial, TRUE);
1911 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1913 /* Unsensitive the camera and mic button */
1914 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1915 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1917 /* Be sure that the mic button is enabled */
1918 gtk_toggle_tool_button_set_active (
1919 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1921 if (priv->camera_state == CAMERA_STATE_ON)
1923 /* Restart the preview with the new pipeline. */
1924 display_video_preview (self, TRUE);
1927 gtk_progress_bar_set_fraction (
1928 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1930 /* destroy the video output; it will be recreated when we'll redial */
1931 disconnect_video_output_motion_handler (self);
1932 if (priv->video_output != NULL)
1933 clutter_actor_destroy (priv->video_output);
1934 priv->video_output = NULL;
1935 if (priv->got_video_src > 0)
1937 g_source_remove (priv->got_video_src);
1938 priv->got_video_src = 0;
1941 gtk_widget_show (priv->remote_user_avatar_widget);
1943 reset_details_pane (self);
1945 priv->sending_video = FALSE;
1946 priv->call_started = FALSE;
1948 could_disconnect = TRUE;
1950 /* TODO: display the self avatar of the preview (depends if the "Always
1951 * Show Video Preview" is enabled or not) */
1954 return could_disconnect;
1959 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1962 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1963 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1965 if (empathy_call_window_disconnected (self, TRUE) &&
1966 priv->call_state == REDIALING)
1967 empathy_call_window_restart_call (self);
1971 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1973 FsMediaType media_type,
1974 EmpathyCallWindow *self)
1976 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1978 DEBUG ("removing content");
1981 * This assumes that there is only one video stream per channel...
1984 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1986 if (priv->funnel != NULL)
1990 output = priv->video_output_sink;
1992 gst_element_set_state (output, GST_STATE_NULL);
1993 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1995 gst_bin_remove (GST_BIN (priv->pipeline), output);
1996 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1997 priv->funnel = NULL;
2001 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2003 if (priv->audio_output != NULL)
2005 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2007 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2008 priv->audio_output = NULL;
2016 /* Called with global lock held */
2018 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2020 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2024 if (priv->funnel == NULL)
2026 output = priv->video_output_sink;
2028 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2032 g_warning ("Could not create fsfunnel");
2036 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2038 gst_object_unref (priv->funnel);
2039 priv->funnel = NULL;
2040 g_warning ("Could not add funnel to pipeline");
2044 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2046 g_warning ("Could not add the video output widget to the pipeline");
2050 if (!gst_element_link (priv->funnel, output))
2052 g_warning ("Could not link output sink to funnel");
2053 goto error_output_added;
2056 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2058 g_warning ("Could not start video sink");
2059 goto error_output_added;
2062 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2064 g_warning ("Could not start funnel");
2065 goto error_output_added;
2069 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2072 g_warning ("Could not get request pad from funnel");
2079 gst_element_set_locked_state (priv->funnel, TRUE);
2080 gst_element_set_locked_state (output, TRUE);
2082 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2083 gst_element_set_state (output, GST_STATE_NULL);
2085 gst_bin_remove (GST_BIN (priv->pipeline), output);
2086 gst_element_set_locked_state (output, FALSE);
2090 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2091 priv->funnel = NULL;
2096 /* Called with global lock held */
2098 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2100 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2102 GstPadTemplate *template;
2104 if (priv->audio_output == NULL)
2106 priv->audio_output = empathy_audio_sink_new ();
2107 g_object_ref_sink (priv->audio_output);
2109 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2111 g_warning ("Could not add audio sink to pipeline");
2112 g_object_unref (priv->audio_output);
2113 goto error_add_output;
2116 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2118 g_warning ("Could not start audio sink");
2123 template = gst_element_class_get_pad_template (
2124 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2126 pad = gst_element_request_pad (priv->audio_output,
2127 template, NULL, NULL);
2131 g_warning ("Could not get sink pad from sink");
2138 gst_element_set_locked_state (priv->audio_output, TRUE);
2139 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2140 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2141 priv->audio_output = NULL;
2149 empathy_call_window_update_timer (gpointer user_data)
2151 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2152 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2156 time_ = g_timer_elapsed (priv->timer, NULL);
2158 /* Translators: 'status - minutes:seconds' the caller has been connected */
2159 str = g_strdup_printf (_("%s — %d:%02dm"),
2160 priv->call_state == HELD ? _("On hold") : _("Connected"),
2161 (int) time_ / 60, (int) time_ % 60);
2162 empathy_call_window_status_message (self, str);
2170 display_error (EmpathyCallWindow *self,
2171 TpyCallChannel *call,
2175 const gchar *details)
2177 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2178 GtkWidget *info_bar;
2179 GtkWidget *content_area;
2186 /* Create info bar */
2187 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2190 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2192 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2194 /* hbox containing the image and the messages vbox */
2195 hbox = gtk_hbox_new (FALSE, 3);
2196 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2199 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2200 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2202 /* vbox containing the main message and the details expander */
2203 vbox = gtk_vbox_new (FALSE, 3);
2204 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2207 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2209 label = gtk_label_new (NULL);
2210 gtk_label_set_markup (GTK_LABEL (label), txt);
2211 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2212 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2215 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2218 if (details != NULL)
2220 GtkWidget *expander;
2222 expander = gtk_expander_new (_("Technical Details"));
2224 txt = g_strdup_printf ("<i>%s</i>", details);
2226 label = gtk_label_new (NULL);
2227 gtk_label_set_markup (GTK_LABEL (label), txt);
2228 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2229 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2232 gtk_container_add (GTK_CONTAINER (expander), label);
2233 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2236 g_signal_connect (info_bar, "response",
2237 G_CALLBACK (gtk_widget_destroy), NULL);
2239 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2240 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2241 gtk_widget_show_all (info_bar);
2245 media_stream_error_to_txt (EmpathyCallWindow *self,
2246 TpyCallChannel *call,
2248 TpMediaStreamError error)
2250 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2251 const gchar *cm = NULL;
2257 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2259 return g_strdup_printf (
2260 _("%s's software does not understand any of the audio formats "
2261 "supported by your computer"),
2262 empathy_contact_get_alias (priv->contact));
2264 return g_strdup_printf (
2265 _("%s's software does not understand any of the video formats "
2266 "supported by your computer"),
2267 empathy_contact_get_alias (priv->contact));
2269 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2270 return g_strdup_printf (
2271 _("Can't establish a connection to %s. "
2272 "One of you might be on a network that does not allow "
2273 "direct connections."),
2274 empathy_contact_get_alias (priv->contact));
2276 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2277 return g_strdup (_("There was a failure on the network"));
2279 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2281 return g_strdup (_("The audio formats necessary for this call "
2282 "are not installed on your computer"));
2284 return g_strdup (_("The video formats necessary for this call "
2285 "are not installed on your computer"));
2287 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2288 tp_connection_parse_object_path (
2289 tp_channel_borrow_connection (TP_CHANNEL (call)),
2292 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2293 "product=Telepathy&component=%s", cm);
2295 result = g_strdup_printf (
2296 _("Something unexpected happened in a Telepathy component. "
2297 "Please <a href=\"%s\">report this bug</a> and attach "
2298 "logs gathered from the 'Debug' window in the Help menu."), url);
2304 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2305 return g_strdup (_("There was a failure in the call engine"));
2307 case TP_MEDIA_STREAM_ERROR_EOS:
2308 return g_strdup (_("The end of the stream was reached"));
2310 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2317 empathy_call_window_stream_error (EmpathyCallWindow *self,
2318 TpyCallChannel *call,
2327 desc = media_stream_error_to_txt (self, call, audio, code);
2330 /* No description, use the error message. That's not great as it's not
2331 * localized but it's better than nothing. */
2332 display_error (self, call, icon, title, msg, NULL);
2336 display_error (self, call, icon, title, desc, msg);
2342 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2345 EmpathyCallWindow *self)
2347 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2348 "gnome-stock-mic", _("Can't establish audio stream"));
2352 empathy_call_window_video_stream_error (TpyCallChannel *call,
2355 EmpathyCallWindow *self)
2357 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2358 "camera-web", _("Can't establish video stream"));
2363 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2365 EmpathyCallWindow *self)
2367 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2368 TpyCallChannel *call;
2369 gboolean can_send_video;
2371 if (state != TPY_CALL_STATE_ACCEPTED)
2374 if (priv->call_state == CONNECTED)
2377 g_timer_start (priv->timer);
2378 priv->call_state = CONNECTED;
2380 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2382 can_send_video = priv->video_input != NULL &&
2383 empathy_contact_can_voip_video (priv->contact) &&
2384 empathy_camera_monitor_get_available (priv->camera_monitor);
2386 g_object_get (priv->handler, "call-channel", &call, NULL);
2388 if (tpy_call_channel_has_dtmf (call))
2389 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2391 if (priv->video_input == NULL)
2392 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2394 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2396 gtk_action_set_sensitive (priv->redial, FALSE);
2397 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2399 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2401 clutter_actor_hide (priv->video_output);
2402 gtk_widget_show (priv->remote_user_avatar_widget);
2404 g_object_unref (call);
2406 g_mutex_lock (priv->lock);
2408 priv->timer_id = g_timeout_add_seconds (1,
2409 empathy_call_window_update_timer, self);
2411 g_mutex_unlock (priv->lock);
2413 empathy_call_window_update_timer (self);
2415 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2419 empathy_call_window_show_video_output_cb (gpointer user_data)
2421 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2423 if (self->priv->video_output != NULL)
2425 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2426 clutter_actor_show (self->priv->video_output);
2433 empathy_call_window_check_video_cb (gpointer data)
2435 EmpathyCallWindow *self = data;
2437 if (self->priv->got_video)
2439 self->priv->got_video = FALSE;
2443 /* No video in the last N seconds, display the remote avatar */
2444 empathy_call_window_show_video_output (self, FALSE);
2449 /* Called from the streaming thread */
2451 empathy_call_window_video_probe_cb (GstPad *pad,
2452 GstMiniObject *mini_obj,
2453 EmpathyCallWindow *self)
2456 if (GST_IS_EVENT (mini_obj))
2459 if (G_UNLIKELY (!self->priv->got_video))
2461 /* show the remote video */
2462 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2463 empathy_call_window_show_video_output_cb,
2464 g_object_ref (self), g_object_unref);
2466 self->priv->got_video = TRUE;
2472 /* Called from the streaming thread */
2474 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2475 GstPad *src, guint media_type, gpointer user_data)
2477 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2478 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2479 gboolean retval = FALSE;
2483 g_mutex_lock (priv->lock);
2487 case TP_MEDIA_STREAM_TYPE_AUDIO:
2488 pad = empathy_call_window_get_audio_sink_pad (self);
2490 case TP_MEDIA_STREAM_TYPE_VIDEO:
2491 g_idle_add (empathy_call_window_show_video_output_cb, self);
2492 pad = empathy_call_window_get_video_sink_pad (self);
2494 gst_pad_add_data_probe (src,
2495 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2496 if (priv->got_video_src > 0)
2497 g_source_remove (priv->got_video_src);
2498 priv->got_video_src = g_timeout_add_seconds (5,
2499 empathy_call_window_check_video_cb, self);
2502 g_assert_not_reached ();
2508 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2509 g_warning ("Could not link %s sink pad",
2510 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2514 gst_object_unref (pad);
2518 /* If no sink could be linked, try to add fakesink to prevent the whole call
2523 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2525 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2527 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2528 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2529 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2531 gst_element_set_locked_state (fakesink, TRUE);
2532 gst_element_set_state (fakesink, GST_STATE_NULL);
2533 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2537 DEBUG ("Could not link real sink, linked fakesink instead");
2539 gst_object_unref (sinkpad);
2543 gst_object_unref (fakesink);
2548 g_mutex_unlock (priv->lock);
2554 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2555 GstPad *sink, FsMediaType media_type, gpointer user_data)
2557 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2558 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2560 gboolean retval = FALSE;
2564 case FS_MEDIA_TYPE_AUDIO:
2565 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2567 g_warning ("Could not add audio source to pipeline");
2571 pad = gst_element_get_static_pad (priv->audio_input, "src");
2574 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2575 g_warning ("Could not get source pad from audio source");
2579 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2581 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2582 g_warning ("Could not link audio source to farsight");
2586 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2588 g_warning ("Could not start audio source");
2589 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2590 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2596 case FS_MEDIA_TYPE_VIDEO:
2597 if (priv->video_tee != NULL)
2599 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2600 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2602 g_warning ("Could not link video source input pipeline");
2605 gst_object_unref (pad);
2611 g_assert_not_reached ();
2618 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2620 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2621 GstElement *preview;
2623 disable_camera (self);
2625 DEBUG ("remove video input");
2626 preview = priv->video_preview_sink;
2628 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2629 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2630 gst_element_set_state (preview, GST_STATE_NULL);
2632 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2635 g_object_unref (priv->video_input);
2636 priv->video_input = NULL;
2637 g_object_unref (priv->video_tee);
2638 priv->video_tee = NULL;
2639 clutter_actor_destroy (priv->video_preview);
2640 priv->video_preview = NULL;
2642 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2646 start_call (EmpathyCallWindow *self)
2648 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2650 priv->call_started = TRUE;
2651 empathy_call_handler_start_call (priv->handler,
2652 gtk_get_current_event_time ());
2654 if (empathy_call_handler_has_initial_video (priv->handler))
2656 TpyCallChannel *call;
2659 g_object_get (priv->handler, "call-channel", &call, NULL);
2660 s = tpy_call_channel_get_video_state (call);
2662 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2663 s == TPY_SENDING_STATE_SENDING)
2665 /* Enable 'send video' buttons and display the preview */
2666 gtk_toggle_tool_button_set_active (
2667 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2671 gtk_toggle_tool_button_set_active (
2672 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2674 if (priv->video_preview == NULL)
2676 create_video_preview (self);
2677 add_video_preview_to_pipeline (self);
2681 g_object_unref (call);
2686 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2689 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2690 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2693 empathy_call_handler_bus_message (priv->handler, bus, message);
2695 switch (GST_MESSAGE_TYPE (message))
2697 case GST_MESSAGE_STATE_CHANGED:
2698 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2700 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2701 if (newstate == GST_STATE_PAUSED)
2702 empathy_call_window_setup_video_input (self);
2704 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2705 !priv->call_started)
2707 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2708 if (newstate == GST_STATE_PAUSED)
2710 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2711 priv->pipeline_playing = TRUE;
2713 if (priv->start_call_when_playing)
2718 case GST_MESSAGE_ERROR:
2720 GError *error = NULL;
2721 GstElement *gst_error;
2724 gst_message_parse_error (message, &error, &debug);
2725 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2727 g_message ("Element error: %s -- %s\n", error->message, debug);
2729 if (g_str_has_prefix (gst_element_get_name (gst_error),
2730 VIDEO_INPUT_ERROR_PREFIX))
2732 /* Remove the video input and continue */
2733 if (priv->video_input != NULL)
2734 empathy_call_window_remove_video_input (self);
2735 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2739 empathy_call_window_disconnected (self, TRUE);
2741 g_error_free (error);
2744 case GST_MESSAGE_UNKNOWN:
2745 case GST_MESSAGE_EOS:
2746 case GST_MESSAGE_WARNING:
2747 case GST_MESSAGE_INFO:
2748 case GST_MESSAGE_TAG:
2749 case GST_MESSAGE_BUFFERING:
2750 case GST_MESSAGE_STATE_DIRTY:
2751 case GST_MESSAGE_STEP_DONE:
2752 case GST_MESSAGE_CLOCK_PROVIDE:
2753 case GST_MESSAGE_CLOCK_LOST:
2754 case GST_MESSAGE_NEW_CLOCK:
2755 case GST_MESSAGE_STRUCTURE_CHANGE:
2756 case GST_MESSAGE_STREAM_STATUS:
2757 case GST_MESSAGE_APPLICATION:
2758 case GST_MESSAGE_ELEMENT:
2759 case GST_MESSAGE_SEGMENT_START:
2760 case GST_MESSAGE_SEGMENT_DONE:
2761 case GST_MESSAGE_DURATION:
2762 case GST_MESSAGE_ANY:
2771 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2772 GHashTable *members,
2773 EmpathyCallWindow *self)
2775 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2776 GHashTableIter iter;
2777 gpointer key, value;
2778 gboolean held = FALSE;
2780 g_hash_table_iter_init (&iter, members);
2781 while (g_hash_table_iter_next (&iter, &key, &value))
2783 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2785 /* This assumes this is a 1-1 call, otherwise one participant
2786 * putting the call on hold wouldn't mean the call is on hold
2794 priv->call_state = HELD;
2795 else if (priv->call_state == HELD)
2796 priv->call_state = CONNECTED;
2800 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2802 EmpathyCallWindow *self)
2804 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2805 TpyCallChannel *call;
2807 g_object_get (priv->handler, "call-channel", &call, NULL);
2812 tp_g_signal_connect_object (call, "audio-stream-error",
2813 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2814 tp_g_signal_connect_object (call, "video-stream-error",
2815 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2818 tp_g_signal_connect_object (call, "members-changed",
2819 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2821 g_object_unref (call);
2825 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2827 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2828 TpyCallChannel *call;
2830 g_signal_connect (priv->handler, "state-changed",
2831 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2832 g_signal_connect (priv->handler, "conference-added",
2833 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2834 g_signal_connect (priv->handler, "conference-removed",
2835 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2836 g_signal_connect (priv->handler, "closed",
2837 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2838 g_signal_connect (priv->handler, "src-pad-added",
2839 G_CALLBACK (empathy_call_window_src_added_cb), window);
2840 g_signal_connect (priv->handler, "sink-pad-added",
2841 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2842 g_signal_connect (priv->handler, "sink-pad-removed",
2843 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2845 g_object_get (priv->handler, "call-channel", &call, NULL);
2848 call_handler_notify_call_cb (priv->handler, NULL, window);
2849 g_object_unref (call);
2853 /* call-channel doesn't exist yet, we'll connect signals once it has been
2855 g_signal_connect (priv->handler, "notify::call-channel",
2856 G_CALLBACK (call_handler_notify_call_cb), window);
2859 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2863 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2864 EmpathyCallWindow *window)
2866 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2868 if (priv->pipeline != NULL)
2870 if (priv->bus_message_source_id != 0)
2872 g_source_remove (priv->bus_message_source_id);
2873 priv->bus_message_source_id = 0;
2876 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2879 if (priv->call_state == CONNECTING)
2880 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2886 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2889 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2891 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2896 gtk_widget_hide (priv->sidebar);
2897 gtk_widget_hide (menu);
2898 gtk_widget_hide (priv->toolbar);
2902 if (priv->sidebar_was_visible_before_fs)
2903 gtk_widget_show (priv->sidebar);
2905 gtk_widget_show (menu);
2906 gtk_widget_show (priv->toolbar);
2908 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2909 priv->original_height_before_fs);
2914 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2916 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2918 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2919 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2920 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2921 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2923 if (priv->video_output != NULL)
2926 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2927 priv->video_output, TRUE, TRUE,
2928 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2935 empathy_call_window_state_event_cb (GtkWidget *widget,
2936 GdkEventWindowState *event, EmpathyCallWindow *window)
2938 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2940 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2941 gboolean set_fullscreen = event->new_window_state &
2942 GDK_WINDOW_STATE_FULLSCREEN;
2946 gboolean sidebar_was_visible;
2947 GtkAllocation allocation;
2948 gint original_width, original_height;
2950 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2951 original_width = allocation.width;
2952 original_height = allocation.height;
2954 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2956 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2957 priv->original_width_before_fs = original_width;
2958 priv->original_height_before_fs = original_height;
2960 if (priv->video_output_motion_handler_id == 0 &&
2961 priv->video_output != NULL)
2963 priv->video_output_motion_handler_id = g_signal_connect (
2964 G_OBJECT (priv->video_container), "motion-notify-event",
2965 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2971 disconnect_video_output_motion_handler (window);
2974 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2976 show_controls (window, set_fullscreen);
2977 show_borders (window, set_fullscreen);
2978 gtk_action_set_stock_id (priv->menu_fullscreen,
2979 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2980 priv->is_fullscreen = set_fullscreen;
2987 empathy_call_window_update_sidebar_buttons (EmpathyCallWindow *window,
2990 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2992 /* Update dialpad button */
2993 g_signal_handlers_block_by_func (priv->dialpad_button,
2994 empathy_call_window_dialpad_cb, window);
2995 gtk_toggle_tool_button_set_active (
2996 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button),
2998 g_signal_handlers_unblock_by_func (priv->dialpad_button,
2999 empathy_call_window_dialpad_cb, window);
3001 /* Update sidebar menu */
3002 g_signal_handlers_block_by_func (priv->menu_sidebar,
3003 empathy_call_window_sidebar_cb, window);
3004 gtk_toggle_action_set_active (
3005 GTK_TOGGLE_ACTION (priv->menu_sidebar),
3006 gtk_widget_get_visible (priv->sidebar));
3007 g_signal_handlers_unblock_by_func (priv->menu_sidebar,
3008 empathy_call_window_sidebar_cb, window);
3012 empathy_call_window_show_sidebar (EmpathyCallWindow *window,
3015 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3016 int w, h, sidebar_width, handle_size;
3017 GtkAllocation allocation;
3019 gboolean dialpad_shown;
3021 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3022 w = allocation.width;
3023 h = allocation.height;
3025 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
3027 gtk_widget_get_preferred_width (priv->sidebar, &sidebar_width, NULL);
3031 gtk_widget_show (priv->sidebar);
3032 w += sidebar_width + handle_size;
3036 w -= sidebar_width + handle_size;
3037 gtk_widget_hide (priv->sidebar);
3041 gtk_window_resize (GTK_WINDOW (window), w, h);
3043 /* Update the 'Dialpad' menu */
3044 page = ev_sidebar_get_current_page (EV_SIDEBAR (priv->sidebar));
3045 dialpad_shown = active && !tp_strdiff (page, "dialpad");
3048 empathy_call_window_update_sidebar_buttons (window, dialpad_shown);
3052 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3055 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3056 TpyCallChannel *call;
3058 priv->sending_video = (state == CAMERA_STATE_ON);
3060 if (state == CAMERA_STATE_ON)
3062 /* When we start sending video, we want to show the video preview by
3064 display_video_preview (window, TRUE);
3068 display_video_preview (window, FALSE);
3071 if (priv->call_state != CONNECTED)
3074 g_object_get (priv->handler, "call-channel", &call, NULL);
3075 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3076 tpy_call_channel_send_video (call, priv->sending_video);
3077 g_object_unref (call);
3081 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3082 EmpathyCallWindow *window)
3084 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3087 active = (gtk_toggle_tool_button_get_active (toggle));
3091 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3093 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
3097 /* TODO, Instead of setting the input volume to 0 we should probably
3098 * stop sending but this would cause the audio call to drop if both
3099 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3100 * in the future. GNOME #574574
3102 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3104 gtk_adjustment_set_value (priv->audio_input_adj, 0);
3109 empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
3110 EmpathyCallWindow *window)
3112 empathy_call_window_show_sidebar (window, FALSE);
3116 empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
3117 EmpathyCallWindow *window)
3119 empathy_call_window_show_sidebar (window, TRUE);
3123 empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
3125 EmpathyCallWindow *window)
3127 empathy_call_window_update_sidebar_buttons (window,
3128 !tp_strdiff (page, "dialpad"));
3132 empathy_call_window_hangup_cb (gpointer object,
3133 EmpathyCallWindow *window)
3135 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3137 empathy_call_handler_stop_call (priv->handler);
3139 if (empathy_call_window_disconnected (window, FALSE))
3140 gtk_widget_destroy (GTK_WIDGET (window));
3144 empathy_call_window_restart_call (EmpathyCallWindow *window)
3146 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3148 /* Remove error info bars */
3149 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3150 (GtkCallback) gtk_widget_destroy, NULL);
3152 create_video_output_widget (window);
3154 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3155 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
3157 /* While the call was disconnected, the input volume might have changed.
3158 * However, since the audio_input source was destroyed, its volume has not
3159 * been updated during that time. That's why we manually update it here */
3160 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3162 priv->outgoing = TRUE;
3163 empathy_call_window_set_state_connecting (window);
3165 if (priv->pipeline_playing)
3166 start_call (window);
3168 /* call will be started when the pipeline is ready */
3169 priv->start_call_when_playing = TRUE;
3172 empathy_call_window_setup_avatars (window, priv->handler);
3174 gtk_action_set_sensitive (priv->redial, FALSE);
3175 gtk_widget_set_sensitive (priv->redial_button, FALSE);
3179 empathy_call_window_redial_cb (gpointer object,
3180 EmpathyCallWindow *window)
3182 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3184 if (priv->call_state == CONNECTED)
3185 priv->call_state = REDIALING;
3187 empathy_call_handler_stop_call (priv->handler);
3189 if (priv->call_state != CONNECTED)
3190 empathy_call_window_restart_call (window);
3194 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3195 EmpathyCallWindow *window)
3197 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3200 active = gtk_toggle_tool_button_get_active (button);
3203 ev_sidebar_set_current_page (EV_SIDEBAR (priv->sidebar), "dialpad");
3205 empathy_call_window_show_sidebar (window, active);
3209 empathy_call_window_sidebar_cb (GtkToggleAction *menu,
3210 EmpathyCallWindow *self)
3212 empathy_call_window_show_sidebar (self,
3213 gtk_toggle_action_get_active (menu));
3217 empathy_call_window_fullscreen_cb (gpointer object,
3218 EmpathyCallWindow *window)
3220 empathy_call_window_fullscreen_toggle (window);
3224 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3226 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3228 if (priv->is_fullscreen)
3229 gtk_window_unfullscreen (GTK_WINDOW (window));
3231 gtk_window_fullscreen (GTK_WINDOW (window));
3235 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3236 GdkEventButton *event, EmpathyCallWindow *window)
3238 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3240 empathy_call_window_video_menu_popup (window, event->button);
3248 empathy_call_window_key_press_cb (GtkWidget *video_output,
3249 GdkEventKey *event, EmpathyCallWindow *window)
3251 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3253 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3255 /* Since we are in fullscreen mode, toggling will bring us back to
3257 empathy_call_window_fullscreen_toggle (window);
3265 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3266 GdkEventMotion *event, EmpathyCallWindow *window)
3268 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3270 if (priv->is_fullscreen)
3272 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3279 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3283 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3285 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3287 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3288 button, gtk_get_current_event_time ());
3289 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3293 empathy_call_window_status_message (EmpathyCallWindow *self,
3296 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3300 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3301 gdouble value, EmpathyCallWindow *window)
3303 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3305 if (priv->audio_output == NULL)
3308 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),