2 * empathy-streamed-media-window.c - Source for EmpathyStreamedMediaWindow
3 * Copyright (C) 2008-2009 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
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <telepathy-glib/util.h>
34 #include <telepathy-farsight/channel.h>
35 #include <telepathy-glib/util.h>
37 #include <gst/farsight/fs-element-added-notifier.h>
39 #include <libempathy/empathy-tp-contact-factory.h>
40 #include <libempathy/empathy-utils.h>
41 #include <libempathy-gtk/empathy-avatar-image.h>
42 #include <libempathy-gtk/empathy-dialpad-widget.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
44 #include <libempathy-gtk/empathy-sound-manager.h>
45 #include <libempathy-gtk/empathy-geometry.h>
46 #include <libempathy-gtk/empathy-images.h>
48 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
49 #include <libempathy/empathy-debug.h>
51 #include "empathy-streamed-media-window.h"
52 #include "empathy-streamed-media-window-fullscreen.h"
53 #include "empathy-video-widget.h"
54 #include "empathy-audio-src.h"
55 #include "empathy-audio-sink.h"
56 #include "empathy-video-src.h"
57 #include "ev-sidebar.h"
59 #define CONTENT_HBOX_BORDER_WIDTH 6
60 #define CONTENT_HBOX_SPACING 3
61 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
63 #define SELF_VIDEO_SECTION_WIDTH 160
64 #define SELF_VIDEO_SECTION_HEIGTH 120
66 /* The avatar's default width and height are set to the same value because we
67 want a square icon. */
68 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
69 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
70 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
72 /* If an video input error occurs, the error message will start with "v4l" */
73 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
75 /* The time interval in milliseconds between 2 outgoing rings */
76 #define MS_BETWEEN_RING 500
78 G_DEFINE_TYPE(EmpathyStreamedMediaWindow, empathy_streamed_media_window, GTK_TYPE_WINDOW)
87 static guint signals[LAST_SIGNAL] = {0};
91 PROP_STREAMED_MEDIA_HANDLER = 1,
102 CAMERA_STATE_OFF = 0,
103 CAMERA_STATE_PREVIEW,
107 /* private structure */
108 typedef struct _EmpathyStreamedMediaWindowPriv EmpathyStreamedMediaWindowPriv;
110 struct _EmpathyStreamedMediaWindowPriv
112 gboolean dispose_has_run;
113 EmpathyStreamedMediaHandler *handler;
114 EmpathyContact *contact;
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 GtkWidget *video_output;
124 GtkWidget *video_preview;
125 GtkWidget *remote_user_avatar_widget;
126 GtkWidget *self_user_avatar_widget;
128 GtkWidget *sidebar_button;
129 GtkWidget *statusbar;
130 GtkWidget *volume_button;
131 GtkWidget *redial_button;
132 GtkWidget *mic_button;
136 GtkAction *menu_fullscreen;
137 GtkAction *action_camera_on;
138 GtkWidget *tool_button_camera_off;
139 GtkWidget *tool_button_camera_preview;
140 GtkWidget *tool_button_camera_on;
142 /* The frames and boxes that contain self and remote avatar and video
143 input/output. When we redial, we destroy and re-create the boxes */
144 GtkWidget *remote_user_output_frame;
145 GtkWidget *self_user_output_frame;
146 GtkWidget *remote_user_output_hbox;
147 GtkWidget *self_user_output_hbox;
149 /* We keep a reference on the hbox which contains the main content so we can
150 easilly repack everything when toggling fullscreen */
151 GtkWidget *content_hbox;
153 /* This vbox is contained in the content_hbox and it contains the
154 self_user_output_frame and the sidebar button. When toggling fullscreen,
155 it needs to be repacked. We keep a reference on it for easier access. */
158 gulong video_output_motion_handler_id;
159 guint bus_message_source_id;
162 GtkWidget *volume_scale;
163 GtkWidget *volume_progress_bar;
164 GtkAdjustment *audio_input_adj;
166 GtkWidget *dtmf_panel;
169 GtkWidget *details_vbox;
170 GtkWidget *vcodec_encoding_label;
171 GtkWidget *acodec_encoding_label;
172 GtkWidget *vcodec_decoding_label;
173 GtkWidget *acodec_decoding_label;
175 GtkWidget *audio_remote_candidate_label;
176 GtkWidget *audio_local_candidate_label;
177 GtkWidget *video_remote_candidate_label;
178 GtkWidget *video_local_candidate_label;
179 GtkWidget *video_remote_candidate_info_img;
180 GtkWidget *video_local_candidate_info_img;
181 GtkWidget *audio_remote_candidate_info_img;
182 GtkWidget *audio_local_candidate_info_img;
184 GstElement *video_input;
185 GstElement *audio_input;
186 GstElement *audio_output;
187 GstElement *pipeline;
188 GstElement *video_tee;
192 FsElementAddedNotifier *fsnotifier;
199 GtkWidget *video_contrast;
200 GtkWidget *video_brightness;
201 GtkWidget *video_gamma;
204 gboolean call_started;
205 gboolean sending_video;
206 CameraState camera_state;
208 EmpathyStreamedMediaWindowFullscreen *fullscreen;
209 gboolean is_fullscreen;
211 /* Those fields represent the state of the window before it actually was in
213 gboolean sidebar_was_visible_before_fs;
214 gint original_width_before_fs;
215 gint original_height_before_fs;
217 /* TRUE if the call should be started when the pipeline is playing */
218 gboolean start_call_when_playing;
219 /* TRUE if we requested to set the pipeline in the playing state */
220 gboolean pipeline_playing;
222 EmpathySoundManager *sound_mgr;
225 #define GET_PRIV(o) \
226 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, \
227 EmpathyStreamedMediaWindowPriv))
229 static void empathy_streamed_media_window_realized_cb (GtkWidget *widget,
230 EmpathyStreamedMediaWindow *window);
232 static gboolean empathy_streamed_media_window_delete_cb (GtkWidget *widget,
233 GdkEvent *event, EmpathyStreamedMediaWindow *window);
235 static gboolean empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
236 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window);
238 static void empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
239 EmpathyStreamedMediaWindow *window);
241 static void empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
244 static void empathy_streamed_media_window_mic_toggled_cb (
245 GtkToggleToolButton *toggle, EmpathyStreamedMediaWindow *window);
247 static void empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
248 EmpathyStreamedMediaWindow *window);
250 static void empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
251 EmpathyStreamedMediaWindow *window);
253 static void empathy_streamed_media_window_hangup_cb (gpointer object,
254 EmpathyStreamedMediaWindow *window);
256 static void empathy_streamed_media_window_fullscreen_cb (gpointer object,
257 EmpathyStreamedMediaWindow *window);
259 static void empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window);
261 static gboolean empathy_streamed_media_window_video_button_press_cb (
262 GtkWidget *video_output, GdkEventButton *event, EmpathyStreamedMediaWindow *window);
264 static gboolean empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
265 GdkEventKey *event, EmpathyStreamedMediaWindow *window);
267 static gboolean empathy_streamed_media_window_video_output_motion_notify (
268 GtkWidget *widget, GdkEventMotion *event, EmpathyStreamedMediaWindow *window);
270 static void empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
273 static void empathy_streamed_media_window_redial_cb (gpointer object,
274 EmpathyStreamedMediaWindow *window);
276 static void empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window);
278 static void empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
281 static void empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
282 EmpathyStreamedMediaWindow *window);
284 static gboolean empathy_streamed_media_window_bus_message (GstBus *bus,
285 GstMessage *message, gpointer user_data);
288 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
289 gdouble value, EmpathyStreamedMediaWindow *window);
291 static void block_camera_control_signals (EmpathyStreamedMediaWindow *self);
292 static void unblock_camera_control_signals (EmpathyStreamedMediaWindow *self);
295 empathy_streamed_media_window_setup_toolbar (EmpathyStreamedMediaWindow *self)
297 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
298 GtkToolItem *tool_item;
299 GtkWidget *camera_off_icon;
300 GdkPixbuf *pixbuf, *modded_pixbuf;
302 /* set the icon of the 'camera off' button by greying off the webcam icon */
303 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
304 GTK_ICON_SIZE_SMALL_TOOLBAR);
306 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
307 gdk_pixbuf_get_width (pixbuf),
308 gdk_pixbuf_get_height (pixbuf));
310 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
311 g_object_unref (pixbuf);
313 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
314 g_object_unref (modded_pixbuf);
315 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
316 priv->tool_button_camera_off), camera_off_icon);
318 /* Add an empty expanded GtkToolItem so the volume button is at the end of
320 tool_item = gtk_tool_item_new ();
321 gtk_tool_item_set_expand (tool_item, TRUE);
322 gtk_widget_show (GTK_WIDGET (tool_item));
323 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
325 priv->volume_button = gtk_volume_button_new ();
326 /* FIXME listen to the audiosinks signals and update the button according to
327 * that, for now starting out at 1.0 and assuming only the app changes the
329 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
330 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
331 G_CALLBACK (empathy_streamed_media_window_volume_changed_cb), self);
333 tool_item = gtk_tool_item_new ();
334 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
335 gtk_widget_show_all (GTK_WIDGET (tool_item));
336 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
340 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
342 EmpathyStreamedMediaWindow *window)
344 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
345 EmpathyTpStreamedMedia *call;
347 g_object_get (priv->handler, "tp-call", &call, NULL);
349 empathy_tp_streamed_media_start_tone (call, event);
351 g_object_unref (call);
355 dtmf_stop_tone_cb (EmpathyDialpadWidget *self,
357 EmpathyStreamedMediaWindow *window)
359 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
360 EmpathyTpStreamedMedia *call;
362 g_object_get (priv->handler, "tp-call", &call, NULL);
364 empathy_tp_streamed_media_stop_tone (call);
366 g_object_unref (call);
370 empathy_streamed_media_window_create_video_input_add_slider (EmpathyStreamedMediaWindow *self,
371 gchar *label_text, GtkWidget *bin)
373 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
374 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
375 GtkWidget *label = gtk_label_new (label_text);
377 gtk_widget_set_sensitive (scale, FALSE);
379 gtk_container_add (GTK_CONTAINER (bin), vbox);
381 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
382 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
383 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
389 empathy_streamed_media_window_video_contrast_changed_cb (GtkAdjustment *adj,
390 EmpathyStreamedMediaWindow *self)
393 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
395 empathy_video_src_set_channel (priv->video_input,
396 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
400 empathy_streamed_media_window_video_brightness_changed_cb (GtkAdjustment *adj,
401 EmpathyStreamedMediaWindow *self)
404 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
406 empathy_video_src_set_channel (priv->video_input,
407 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
411 empathy_streamed_media_window_video_gamma_changed_cb (GtkAdjustment *adj,
412 EmpathyStreamedMediaWindow *self)
415 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
417 empathy_video_src_set_channel (priv->video_input,
418 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
423 empathy_streamed_media_window_create_video_input (EmpathyStreamedMediaWindow *self)
425 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
428 hbox = gtk_hbox_new (TRUE, 3);
430 priv->video_contrast = empathy_streamed_media_window_create_video_input_add_slider (
431 self, _("Contrast"), hbox);
433 priv->video_brightness = empathy_streamed_media_window_create_video_input_add_slider (
434 self, _("Brightness"), hbox);
436 priv->video_gamma = empathy_streamed_media_window_create_video_input_add_slider (
437 self, _("Gamma"), hbox);
443 empathy_streamed_media_window_setup_video_input (EmpathyStreamedMediaWindow *self)
445 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
449 supported = empathy_video_src_get_supported_channels (priv->video_input);
451 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
453 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
455 gtk_adjustment_set_value (adj,
456 empathy_video_src_get_channel (priv->video_input,
457 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
459 g_signal_connect (G_OBJECT (adj), "value-changed",
460 G_CALLBACK (empathy_streamed_media_window_video_contrast_changed_cb), self);
462 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
465 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
467 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
469 gtk_adjustment_set_value (adj,
470 empathy_video_src_get_channel (priv->video_input,
471 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
473 g_signal_connect (G_OBJECT (adj), "value-changed",
474 G_CALLBACK (empathy_streamed_media_window_video_brightness_changed_cb), self);
475 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
478 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
480 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
482 gtk_adjustment_set_value (adj,
483 empathy_video_src_get_channel (priv->video_input,
484 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
486 g_signal_connect (G_OBJECT (adj), "value-changed",
487 G_CALLBACK (empathy_streamed_media_window_video_gamma_changed_cb), self);
488 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
493 empathy_streamed_media_window_mic_volume_changed_cb (GtkAdjustment *adj,
494 EmpathyStreamedMediaWindow *self)
496 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
499 volume = gtk_adjustment_get_value (adj)/100.0;
501 /* Don't store the volume because of muting */
502 if (volume > 0 || gtk_toggle_tool_button_get_active (
503 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
504 priv->volume = volume;
506 /* Ensure that the toggle button is active if the volume is > 0 and inactive
507 * if it's smaller than 0 */
508 if ((volume > 0) != gtk_toggle_tool_button_get_active (
509 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
510 gtk_toggle_tool_button_set_active (
511 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
513 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
518 empathy_streamed_media_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
519 gdouble level, EmpathyStreamedMediaWindow *window)
522 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
524 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
525 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
530 empathy_streamed_media_window_create_audio_input (EmpathyStreamedMediaWindow *self)
532 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
533 GtkWidget *hbox, *vbox, *label;
535 hbox = gtk_hbox_new (TRUE, 3);
537 vbox = gtk_vbox_new (FALSE, 3);
538 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
540 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
541 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
542 label = gtk_label_new (_("Volume"));
544 priv->audio_input_adj = gtk_range_get_adjustment (
545 GTK_RANGE (priv->volume_scale));
546 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
547 (priv->audio_input));
548 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
550 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
551 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), self);
553 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
554 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
556 priv->volume_progress_bar = gtk_progress_bar_new ();
558 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
559 GTK_ORIENTATION_VERTICAL);
561 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
564 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
571 create_video_output_widget (EmpathyStreamedMediaWindow *self)
573 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
576 g_assert (priv->video_output == NULL);
577 g_assert (priv->pipeline != NULL);
579 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
580 priv->video_output = empathy_video_widget_new (bus);
582 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
583 priv->video_output, TRUE, TRUE, 0);
585 gtk_widget_add_events (priv->video_output,
586 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
587 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
588 G_CALLBACK (empathy_streamed_media_window_video_button_press_cb), self);
590 g_object_unref (bus);
594 create_video_input (EmpathyStreamedMediaWindow *self)
596 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
598 g_assert (priv->video_input == NULL);
599 priv->video_input = empathy_video_src_new ();
600 gst_object_ref (priv->video_input);
601 gst_object_sink (priv->video_input);
605 create_audio_input (EmpathyStreamedMediaWindow *self)
607 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
609 g_assert (priv->audio_input == NULL);
610 priv->audio_input = empathy_audio_src_new ();
611 gst_object_ref (priv->audio_input);
612 gst_object_sink (priv->audio_input);
614 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
615 G_CALLBACK (empathy_streamed_media_window_audio_input_level_changed_cb),
620 add_video_preview_to_pipeline (EmpathyStreamedMediaWindow *self)
622 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
625 g_assert (priv->video_preview != NULL);
626 g_assert (priv->pipeline != NULL);
627 g_assert (priv->video_input != NULL);
628 g_assert (priv->video_tee != NULL);
630 preview = empathy_video_widget_get_element (
631 EMPATHY_VIDEO_WIDGET (priv->video_preview));
633 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
635 g_warning ("Could not add video input to pipeline");
639 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
641 g_warning ("Could not add video tee to pipeline");
645 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
647 g_warning ("Could not add video preview to pipeline");
651 if (!gst_element_link (priv->video_input, priv->video_tee))
653 g_warning ("Could not link video input to video tee");
657 if (!gst_element_link (priv->video_tee, preview))
659 g_warning ("Could not link video tee to video preview");
665 create_video_preview (EmpathyStreamedMediaWindow *self)
667 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
670 g_assert (priv->video_preview == NULL);
671 g_assert (priv->video_tee == NULL);
673 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
675 priv->video_preview = empathy_video_widget_new_with_size (bus,
676 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
677 g_object_set (priv->video_preview,
683 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
684 priv->video_preview, TRUE, TRUE, 0);
686 priv->video_tee = gst_element_factory_make ("tee", NULL);
687 gst_object_ref (priv->video_tee);
688 gst_object_sink (priv->video_tee);
690 g_object_unref (bus);
694 play_camera (EmpathyStreamedMediaWindow *window,
697 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
701 if (priv->video_preview == NULL)
703 create_video_preview (window);
704 add_video_preview_to_pipeline (window);
708 state = GST_STATE_PLAYING;
710 state = GST_STATE_NULL;
712 preview = empathy_video_widget_get_element (
713 EMPATHY_VIDEO_WIDGET (priv->video_preview));
715 gst_element_set_state (preview, state);
716 gst_element_set_state (priv->video_input, state);
717 gst_element_set_state (priv->video_tee, state);
721 display_video_preview (EmpathyStreamedMediaWindow *self,
724 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
728 /* Display the preview and hide the self avatar */
729 DEBUG ("Show video preview");
731 play_camera (self, TRUE);
732 gtk_widget_show (priv->video_preview);
733 gtk_widget_hide (priv->self_user_avatar_widget);
737 /* Display the self avatar and hide the preview */
738 DEBUG ("Show self avatar");
740 if (priv->video_preview != NULL)
742 gtk_widget_hide (priv->video_preview);
743 play_camera (self, FALSE);
745 gtk_widget_show (priv->self_user_avatar_widget);
750 empathy_streamed_media_window_set_state_connecting (EmpathyStreamedMediaWindow *window)
752 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
754 empathy_streamed_media_window_status_message (window, _("Connecting…"));
755 priv->call_state = CONNECTING;
758 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
759 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
763 disable_camera (EmpathyStreamedMediaWindow *self)
765 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
767 if (priv->camera_state == CAMERA_STATE_OFF)
770 DEBUG ("Disable camera");
772 display_video_preview (self, FALSE);
774 if (priv->camera_state == CAMERA_STATE_ON)
775 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
777 block_camera_control_signals (self);
778 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
779 priv->tool_button_camera_on), FALSE);
780 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
781 priv->tool_button_camera_preview), FALSE);
783 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
784 priv->tool_button_camera_off), TRUE);
785 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
787 unblock_camera_control_signals (self);
789 priv->camera_state = CAMERA_STATE_OFF;
793 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
794 EmpathyStreamedMediaWindow *self)
796 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
798 if (!gtk_toggle_tool_button_get_active (toggle))
800 if (priv->camera_state == CAMERA_STATE_OFF)
802 /* We can't change the state by disabling the button */
803 block_camera_control_signals (self);
804 gtk_toggle_tool_button_set_active (toggle, TRUE);
805 unblock_camera_control_signals (self);
811 disable_camera (self);
815 enable_preview (EmpathyStreamedMediaWindow *self)
817 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
819 if (priv->camera_state == CAMERA_STATE_PREVIEW)
822 DEBUG ("Enable preview");
824 if (priv->camera_state == CAMERA_STATE_ON)
826 /* preview is already displayed so we just have to stop sending */
827 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_PREVIEW);
831 display_video_preview (self, TRUE);
834 block_camera_control_signals (self);
835 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
836 priv->tool_button_camera_off), FALSE);
837 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
838 priv->tool_button_camera_on), FALSE);
840 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
841 priv->tool_button_camera_preview), TRUE);
842 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
843 CAMERA_STATE_PREVIEW);
844 unblock_camera_control_signals (self);
846 priv->camera_state = CAMERA_STATE_PREVIEW;
850 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
851 EmpathyStreamedMediaWindow *self)
853 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
855 if (!gtk_toggle_tool_button_get_active (toggle))
857 if (priv->camera_state == CAMERA_STATE_PREVIEW)
859 /* We can't change the state by disabling the button */
860 block_camera_control_signals (self);
861 gtk_toggle_tool_button_set_active (toggle, TRUE);
862 unblock_camera_control_signals (self);
868 enable_preview (self);
872 enable_camera (EmpathyStreamedMediaWindow *self)
874 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
876 if (priv->camera_state == CAMERA_STATE_ON)
879 if (priv->video_input == NULL)
881 DEBUG ("Can't enable camera, no input");
886 DEBUG ("Enable camera");
888 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_ON);
890 block_camera_control_signals (self);
891 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
892 priv->tool_button_camera_off), FALSE);
893 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
894 priv->tool_button_camera_preview), FALSE);
896 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
897 priv->tool_button_camera_on), TRUE);
898 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
900 unblock_camera_control_signals (self);
902 priv->camera_state = CAMERA_STATE_ON;
906 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
907 EmpathyStreamedMediaWindow *self)
909 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
911 if (!gtk_toggle_tool_button_get_active (toggle))
913 if (priv->camera_state == CAMERA_STATE_ON)
915 /* We can't change the state by disabling the button */
916 block_camera_control_signals (self);
917 gtk_toggle_tool_button_set_active (toggle, TRUE);
918 unblock_camera_control_signals (self);
924 enable_camera (self);
928 action_camera_change_cb (GtkRadioAction *action,
929 GtkRadioAction *current,
930 EmpathyStreamedMediaWindow *self)
934 state = gtk_radio_action_get_current_value (current);
938 case CAMERA_STATE_OFF:
939 disable_camera (self);
942 case CAMERA_STATE_PREVIEW:
943 enable_preview (self);
946 case CAMERA_STATE_ON:
947 enable_camera (self);
951 g_assert_not_reached ();
956 create_pipeline (EmpathyStreamedMediaWindow *self)
958 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
961 g_assert (priv->pipeline == NULL);
963 priv->pipeline = gst_pipeline_new (NULL);
964 priv->pipeline_playing = FALSE;
966 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
967 priv->bus_message_source_id = gst_bus_add_watch (bus,
968 empathy_streamed_media_window_bus_message, self);
970 g_object_unref (bus);
975 empathy_streamed_media_window_init (EmpathyStreamedMediaWindow *self)
977 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
985 GError *error = NULL;
988 filename = empathy_file_lookup ("empathy-streamed-media-window.ui", "src");
989 gui = empathy_builder_get_file (filename,
990 "call_window_vbox", &top_vbox,
991 "errors_vbox", &priv->errors_vbox,
993 "statusbar", &priv->statusbar,
994 "redial", &priv->redial_button,
995 "microphone", &priv->mic_button,
996 "toolbar", &priv->toolbar,
997 "menuredial", &priv->redial,
998 "ui_manager", &priv->ui_manager,
999 "menufullscreen", &priv->menu_fullscreen,
1000 "camera_off", &priv->tool_button_camera_off,
1001 "camera_preview", &priv->tool_button_camera_preview,
1002 "camera_on", &priv->tool_button_camera_on,
1003 "action_camera_on", &priv->action_camera_on,
1004 "details_vbox", &priv->details_vbox,
1005 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1006 "acodec_encoding_label", &priv->acodec_encoding_label,
1007 "acodec_decoding_label", &priv->acodec_decoding_label,
1008 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1009 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1010 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1011 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1012 "video_local_candidate_label", &priv->video_local_candidate_label,
1013 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1014 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1015 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1016 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1020 empathy_builder_connect (gui, self,
1021 "menuhangup", "activate", empathy_streamed_media_window_hangup_cb,
1022 "hangup", "clicked", empathy_streamed_media_window_hangup_cb,
1023 "menuredial", "activate", empathy_streamed_media_window_redial_cb,
1024 "redial", "clicked", empathy_streamed_media_window_redial_cb,
1025 "microphone", "toggled", empathy_streamed_media_window_mic_toggled_cb,
1026 "menufullscreen", "activate", empathy_streamed_media_window_fullscreen_cb,
1027 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1028 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1029 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1030 "action_camera_on", "changed", action_camera_change_cb,
1033 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1035 priv->lock = g_mutex_new ();
1037 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1039 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1040 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1041 CONTENT_HBOX_BORDER_WIDTH);
1042 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1044 /* remote user output frame */
1045 priv->remote_user_output_frame = gtk_frame_new (NULL);
1046 gtk_widget_set_size_request (priv->remote_user_output_frame,
1047 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1048 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1049 priv->remote_user_output_frame, TRUE, TRUE,
1050 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1052 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1054 priv->remote_user_avatar_widget = gtk_image_new ();
1056 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1057 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1059 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1060 priv->remote_user_output_hbox);
1062 /* self user output frame */
1063 priv->self_user_output_frame = gtk_frame_new (NULL);
1064 gtk_widget_set_size_request (priv->self_user_output_frame,
1065 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1067 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1069 priv->self_user_avatar_widget = gtk_image_new ();
1070 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1071 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1073 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1074 priv->self_user_output_hbox);
1076 create_pipeline (self);
1077 create_video_output_widget (self);
1078 create_audio_input (self);
1079 create_video_input (self);
1081 priv->fsnotifier = fs_element_added_notifier_new ();
1082 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1084 /* The call will be started as soon the pipeline is playing */
1085 priv->start_call_when_playing = TRUE;
1087 keyfile = g_key_file_new ();
1088 filename = empathy_file_lookup ("element-properties", "data");
1089 if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error))
1091 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1096 g_warning ("Could not load element-properties file: %s", error->message);
1097 g_key_file_free (keyfile);
1098 g_clear_error (&error);
1102 priv->vbox = gtk_vbox_new (FALSE, 3);
1103 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1104 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1105 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1108 empathy_streamed_media_window_setup_toolbar (self);
1110 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1111 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1112 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1113 G_CALLBACK (empathy_streamed_media_window_sidebar_toggled_cb), self);
1115 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1117 h = gtk_hbox_new (FALSE, 3);
1118 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1119 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1121 priv->sidebar = ev_sidebar_new ();
1122 g_signal_connect (G_OBJECT (priv->sidebar),
1123 "hide", G_CALLBACK (empathy_streamed_media_window_sidebar_hidden_cb), self);
1124 g_signal_connect (G_OBJECT (priv->sidebar),
1125 "show", G_CALLBACK (empathy_streamed_media_window_sidebar_shown_cb), self);
1126 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1128 page = empathy_streamed_media_window_create_audio_input (self);
1129 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1130 _("Audio input"), page);
1132 page = empathy_streamed_media_window_create_video_input (self);
1133 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1134 _("Video input"), page);
1136 priv->dtmf_panel = empathy_dialpad_widget_new ();
1137 g_signal_connect (priv->dtmf_panel, "start-tone",
1138 G_CALLBACK (dtmf_start_tone_cb), self);
1139 g_signal_connect (priv->dtmf_panel, "stop-tone",
1140 G_CALLBACK (dtmf_stop_tone_cb), self);
1141 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1142 _("Dialpad"), priv->dtmf_panel);
1144 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1146 /* Put the details vbox in a scroll window as it can require a lot of
1147 * horizontal space. */
1148 scroll = gtk_scrolled_window_new (NULL, NULL);
1149 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1150 priv->details_vbox);
1152 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details",
1153 _("Details"), scroll);
1155 gtk_widget_show_all (top_vbox);
1157 gtk_widget_hide (priv->sidebar);
1159 priv->fullscreen = empathy_streamed_media_window_fullscreen_new (self);
1160 empathy_streamed_media_window_fullscreen_set_video_widget (priv->fullscreen,
1161 priv->video_output);
1162 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1163 "clicked", G_CALLBACK (empathy_streamed_media_window_fullscreen_cb), self);
1165 g_signal_connect (G_OBJECT (self), "realize",
1166 G_CALLBACK (empathy_streamed_media_window_realized_cb), self);
1168 g_signal_connect (G_OBJECT (self), "delete-event",
1169 G_CALLBACK (empathy_streamed_media_window_delete_cb), self);
1171 g_signal_connect (G_OBJECT (self), "window-state-event",
1172 G_CALLBACK (empathy_streamed_media_window_state_event_cb), self);
1174 g_signal_connect (G_OBJECT (self), "key-press-event",
1175 G_CALLBACK (empathy_streamed_media_window_key_press_cb), self);
1177 priv->timer = g_timer_new ();
1179 g_object_ref (priv->ui_manager);
1180 g_object_unref (gui);
1182 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1184 empathy_geometry_bind (GTK_WINDOW (self), "av-window");
1187 /* Instead of specifying a width and a height, we specify only one size. That's
1188 because we want a square avatar icon. */
1190 init_contact_avatar_with_size (EmpathyContact *contact,
1191 GtkWidget *image_widget,
1194 GdkPixbuf *pixbuf_avatar = NULL;
1196 if (contact != NULL)
1198 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1202 if (pixbuf_avatar == NULL)
1204 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1205 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1208 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1210 if (pixbuf_avatar != NULL)
1211 g_object_unref (pixbuf_avatar);
1215 set_window_title (EmpathyStreamedMediaWindow *self)
1217 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1220 /* translators: Call is a noun and %s is the contact name. This string
1221 * is used in the window title */
1222 tmp = g_strdup_printf (_("Call with %s"),
1223 empathy_contact_get_alias (priv->contact));
1224 gtk_window_set_title (GTK_WINDOW (self), tmp);
1229 contact_name_changed_cb (EmpathyContact *contact,
1230 GParamSpec *pspec, EmpathyStreamedMediaWindow *self)
1232 set_window_title (self);
1236 contact_avatar_changed_cb (EmpathyContact *contact,
1237 GParamSpec *pspec, GtkWidget *avatar_widget)
1240 GtkAllocation allocation;
1242 gtk_widget_get_allocation (avatar_widget, &allocation);
1243 size = allocation.height;
1247 /* the widget is not allocated yet, set a default size */
1248 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1249 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1252 init_contact_avatar_with_size (contact, avatar_widget, size);
1256 empathy_streamed_media_window_got_self_contact_cb (TpConnection *connection,
1257 EmpathyContact *contact, const GError *error, gpointer user_data,
1258 GObject *weak_object)
1260 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1261 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1263 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1264 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1266 g_signal_connect (contact, "notify::avatar",
1267 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1271 empathy_streamed_media_window_setup_avatars (EmpathyStreamedMediaWindow *self,
1272 EmpathyStreamedMediaHandler *handler)
1274 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1276 g_object_get (handler, "contact", &(priv->contact), NULL);
1278 if (priv->contact != NULL)
1280 TpConnection *connection;
1282 set_window_title (self);
1284 g_signal_connect (priv->contact, "notify::name",
1285 G_CALLBACK (contact_name_changed_cb), self);
1286 g_signal_connect (priv->contact, "notify::avatar",
1287 G_CALLBACK (contact_avatar_changed_cb),
1288 priv->remote_user_avatar_widget);
1290 /* Retreiving the self avatar */
1291 connection = empathy_contact_get_connection (priv->contact);
1292 empathy_tp_contact_factory_get_from_handle (connection,
1293 tp_connection_get_self_handle (connection),
1294 empathy_streamed_media_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1298 g_warning ("call handler doesn't have a contact");
1299 /* translators: Call is a noun. This string is used in the window
1301 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1303 /* Since we can't access the remote contact, we can't get a connection
1304 to it and can't get the self contact (and its avatar). This means
1305 that we have to manually set the self avatar. */
1306 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1307 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1310 init_contact_avatar_with_size (priv->contact,
1311 priv->remote_user_avatar_widget,
1312 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1313 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1315 /* The remote avatar is shown by default and will be hidden when we receive
1316 video from the remote side. */
1317 gtk_widget_hide (priv->video_output);
1318 gtk_widget_show (priv->remote_user_avatar_widget);
1322 update_send_codec (EmpathyStreamedMediaWindow *self,
1325 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1332 codec = empathy_streamed_media_handler_get_send_audio_codec (priv->handler);
1333 widget = priv->acodec_encoding_label;
1337 codec = empathy_streamed_media_handler_get_send_video_codec (priv->handler);
1338 widget = priv->vcodec_encoding_label;
1344 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1345 gtk_label_set_text (GTK_LABEL (widget), tmp);
1350 send_audio_codec_notify_cb (GObject *object,
1354 EmpathyStreamedMediaWindow *self = user_data;
1356 update_send_codec (self, TRUE);
1360 send_video_codec_notify_cb (GObject *object,
1364 EmpathyStreamedMediaWindow *self = user_data;
1366 update_send_codec (self, FALSE);
1370 update_recv_codec (EmpathyStreamedMediaWindow *self,
1373 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1376 GString *str = NULL;
1380 codecs = empathy_streamed_media_handler_get_recv_audio_codecs (priv->handler);
1381 widget = priv->acodec_decoding_label;
1385 codecs = empathy_streamed_media_handler_get_recv_video_codecs (priv->handler);
1386 widget = priv->vcodec_decoding_label;
1392 for (l = codecs; l != NULL; l = g_list_next (l))
1394 FsCodec *codec = l->data;
1397 str = g_string_new (NULL);
1399 g_string_append (str, ", ");
1401 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1405 gtk_label_set_text (GTK_LABEL (widget), str->str);
1406 g_string_free (str, TRUE);
1410 recv_audio_codecs_notify_cb (GObject *object,
1414 EmpathyStreamedMediaWindow *self = user_data;
1416 update_recv_codec (self, TRUE);
1420 recv_video_codecs_notify_cb (GObject *object,
1424 EmpathyStreamedMediaWindow *self = user_data;
1426 update_recv_codec (self, FALSE);
1429 static const gchar *
1430 candidate_type_to_str (FsCandidate *candidate)
1432 switch (candidate->type)
1434 case FS_CANDIDATE_TYPE_HOST:
1436 case FS_CANDIDATE_TYPE_SRFLX:
1437 return "server reflexive";
1438 case FS_CANDIDATE_TYPE_PRFLX:
1439 return "peer reflexive";
1440 case FS_CANDIDATE_TYPE_RELAY:
1442 case FS_CANDIDATE_TYPE_MULTICAST:
1449 static const gchar *
1450 candidate_type_to_desc (FsCandidate *candidate)
1452 switch (candidate->type)
1454 case FS_CANDIDATE_TYPE_HOST:
1455 return _("The IP address as seen by the machine");
1456 case FS_CANDIDATE_TYPE_SRFLX:
1457 return _("The IP address as seen by a server on the Internet");
1458 case FS_CANDIDATE_TYPE_PRFLX:
1459 return _("The IP address of the peer as seen by the other side");
1460 case FS_CANDIDATE_TYPE_RELAY:
1461 return _("The IP address of a relay server");
1462 case FS_CANDIDATE_TYPE_MULTICAST:
1463 return _("The IP address of the multicast group");
1470 update_candidat_widget (EmpathyStreamedMediaWindow *self,
1473 FsCandidate *candidate)
1477 g_assert (candidate != NULL);
1478 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1479 candidate->port, candidate_type_to_str (candidate));
1481 gtk_label_set_text (GTK_LABEL (label), str);
1482 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1488 candidates_changed_cb (GObject *object,
1490 EmpathyStreamedMediaWindow *self)
1492 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1493 FsCandidate *candidate = NULL;
1495 if (type == FS_MEDIA_TYPE_VIDEO)
1497 /* Update remote candidate */
1498 candidate = empathy_streamed_media_handler_get_video_remote_candidate (
1501 update_candidat_widget (self, priv->video_remote_candidate_label,
1502 priv->video_remote_candidate_info_img, candidate);
1504 /* Update local candidate */
1505 candidate = empathy_streamed_media_handler_get_video_local_candidate (
1508 update_candidat_widget (self, priv->video_local_candidate_label,
1509 priv->video_local_candidate_info_img, candidate);
1513 /* Update remote candidate */
1514 candidate = empathy_streamed_media_handler_get_audio_remote_candidate (
1517 update_candidat_widget (self, priv->audio_remote_candidate_label,
1518 priv->audio_remote_candidate_info_img, candidate);
1520 /* Update local candidate */
1521 candidate = empathy_streamed_media_handler_get_audio_local_candidate (
1524 update_candidat_widget (self, priv->audio_local_candidate_label,
1525 priv->audio_local_candidate_info_img, candidate);
1530 empathy_streamed_media_window_constructed (GObject *object)
1532 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1533 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1534 EmpathyTpStreamedMedia *call;
1536 g_assert (priv->handler != NULL);
1538 g_object_get (priv->handler, "tp-call", &call, NULL);
1539 priv->outgoing = (call == NULL);
1541 g_object_unref (call);
1543 empathy_streamed_media_window_setup_avatars (self, priv->handler);
1544 empathy_streamed_media_window_set_state_connecting (self);
1546 if (!empathy_streamed_media_handler_has_initial_video (priv->handler))
1548 gtk_toggle_tool_button_set_active (
1549 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1551 /* If call has InitialVideo, the preview will be started once the call has
1552 * been started (start_call()). */
1554 update_send_codec (self, TRUE);
1555 update_send_codec (self, FALSE);
1556 update_recv_codec (self, TRUE);
1557 update_recv_codec (self, FALSE);
1559 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1560 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1561 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1562 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1563 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1564 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1565 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1566 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1568 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1569 G_CALLBACK (candidates_changed_cb), self, 0);
1572 static void empathy_streamed_media_window_dispose (GObject *object);
1573 static void empathy_streamed_media_window_finalize (GObject *object);
1576 empathy_streamed_media_window_set_property (GObject *object,
1577 guint property_id, const GValue *value, GParamSpec *pspec)
1579 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1581 switch (property_id)
1583 case PROP_STREAMED_MEDIA_HANDLER:
1584 priv->handler = g_value_dup_object (value);
1587 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1592 empathy_streamed_media_window_get_property (GObject *object,
1593 guint property_id, GValue *value, GParamSpec *pspec)
1595 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1597 switch (property_id)
1599 case PROP_STREAMED_MEDIA_HANDLER:
1600 g_value_set_object (value, priv->handler);
1603 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1608 empathy_streamed_media_window_class_init (
1609 EmpathyStreamedMediaWindowClass *empathy_streamed_media_window_class)
1611 GObjectClass *object_class = G_OBJECT_CLASS (empathy_streamed_media_window_class);
1612 GParamSpec *param_spec;
1614 g_type_class_add_private (empathy_streamed_media_window_class,
1615 sizeof (EmpathyStreamedMediaWindowPriv));
1617 object_class->constructed = empathy_streamed_media_window_constructed;
1618 object_class->set_property = empathy_streamed_media_window_set_property;
1619 object_class->get_property = empathy_streamed_media_window_get_property;
1621 object_class->dispose = empathy_streamed_media_window_dispose;
1622 object_class->finalize = empathy_streamed_media_window_finalize;
1624 param_spec = g_param_spec_object ("handler",
1625 "handler", "The call handler",
1626 EMPATHY_TYPE_STREAMED_MEDIA_HANDLER,
1627 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1628 g_object_class_install_property (object_class,
1629 PROP_STREAMED_MEDIA_HANDLER, param_spec);
1633 empathy_streamed_media_window_video_stream_changed_cb (EmpathyTpStreamedMedia *call,
1634 GParamSpec *property, EmpathyStreamedMediaWindow *self)
1636 DEBUG ("video stream changed");
1637 empathy_streamed_media_window_update_avatars_visibility (call, self);
1641 empathy_streamed_media_window_dispose (GObject *object)
1643 EmpathyTpStreamedMedia *call;
1644 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1645 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1647 if (priv->dispose_has_run)
1650 priv->dispose_has_run = TRUE;
1652 g_object_get (priv->handler, "tp-call", &call, NULL);
1656 g_object_unref (call);
1659 if (priv->handler != NULL)
1661 empathy_streamed_media_handler_stop_call (priv->handler);
1662 g_object_unref (priv->handler);
1664 priv->handler = NULL;
1666 if (priv->bus_message_source_id != 0)
1668 g_source_remove (priv->bus_message_source_id);
1669 priv->bus_message_source_id = 0;
1672 if (priv->pipeline != NULL)
1673 g_object_unref (priv->pipeline);
1674 priv->pipeline = NULL;
1676 if (priv->video_input != NULL)
1677 g_object_unref (priv->video_input);
1678 priv->video_input = NULL;
1680 if (priv->audio_input != NULL)
1681 g_object_unref (priv->audio_input);
1682 priv->audio_input = NULL;
1684 if (priv->video_tee != NULL)
1685 g_object_unref (priv->video_tee);
1686 priv->video_tee = NULL;
1688 if (priv->fsnotifier != NULL)
1689 g_object_unref (priv->fsnotifier);
1690 priv->fsnotifier = NULL;
1692 if (priv->timer_id != 0)
1693 g_source_remove (priv->timer_id);
1696 if (priv->ui_manager != NULL)
1697 g_object_unref (priv->ui_manager);
1698 priv->ui_manager = NULL;
1700 if (priv->fullscreen != NULL)
1701 g_object_unref (priv->fullscreen);
1702 priv->fullscreen = NULL;
1704 if (priv->contact != NULL)
1706 g_signal_handlers_disconnect_by_func (priv->contact,
1707 contact_name_changed_cb, self);
1708 g_object_unref (priv->contact);
1709 priv->contact = NULL;
1712 tp_clear_object (&priv->sound_mgr);
1714 /* release any references held by the object here */
1715 if (G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose)
1716 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose (object);
1720 disconnect_video_output_motion_handler (EmpathyStreamedMediaWindow *self)
1722 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1724 if (priv->video_output_motion_handler_id != 0)
1726 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1727 priv->video_output_motion_handler_id);
1728 priv->video_output_motion_handler_id = 0;
1733 empathy_streamed_media_window_finalize (GObject *object)
1735 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1736 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1738 disconnect_video_output_motion_handler (self);
1740 /* free any data held directly by the object here */
1741 g_mutex_free (priv->lock);
1743 g_timer_destroy (priv->timer);
1745 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->finalize (object);
1749 EmpathyStreamedMediaWindow *
1750 empathy_streamed_media_window_new (EmpathyStreamedMediaHandler *handler)
1752 return EMPATHY_STREAMED_MEDIA_WINDOW (
1753 g_object_new (EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, "handler", handler, NULL));
1757 empathy_streamed_media_window_conference_added_cb (EmpathyStreamedMediaHandler *handler,
1758 GstElement *conference, gpointer user_data)
1760 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1761 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1763 gst_bin_add (GST_BIN (priv->pipeline), conference);
1765 gst_element_set_state (conference, GST_STATE_PLAYING);
1769 empathy_streamed_media_window_request_resource_cb (EmpathyStreamedMediaHandler *handler,
1770 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1772 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1773 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1775 if (type != FS_MEDIA_TYPE_VIDEO)
1778 if (direction == FS_DIRECTION_RECV)
1781 /* video and direction is send */
1782 return priv->video_input != NULL;
1786 empathy_streamed_media_window_reset_pipeline (EmpathyStreamedMediaWindow *self)
1788 GstStateChangeReturn state_change_return;
1789 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1791 if (priv->pipeline == NULL)
1794 if (priv->bus_message_source_id != 0)
1796 g_source_remove (priv->bus_message_source_id);
1797 priv->bus_message_source_id = 0;
1800 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1802 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1803 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1805 if (priv->pipeline != NULL)
1806 g_object_unref (priv->pipeline);
1807 priv->pipeline = NULL;
1809 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1810 empathy_streamed_media_window_mic_volume_changed_cb, self);
1812 if (priv->video_tee != NULL)
1813 g_object_unref (priv->video_tee);
1814 priv->video_tee = NULL;
1816 if (priv->video_preview != NULL)
1817 gtk_widget_destroy (priv->video_preview);
1818 priv->video_preview = NULL;
1820 priv->funnel = NULL;
1822 create_pipeline (self);
1823 /* Call will be started when user will hit the 'redial' button */
1824 priv->start_call_when_playing = FALSE;
1825 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1831 g_message ("Error: could not destroy pipeline. Closing call window");
1832 gtk_widget_destroy (GTK_WIDGET (self));
1839 reset_details_pane (EmpathyStreamedMediaWindow *self)
1841 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1843 /* translators: encoding video codec is unknown */
1844 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label),
1845 C_("codec", "Unknown"));
1846 /* translators: encoding audio codec is unknown */
1847 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label),
1848 C_("codec", "Unknown"));
1849 /* translators: decoding video codec is unknown */
1850 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label),
1851 C_("codec", "Unknown"));
1852 /* translators: decoding audio codec is unknown */
1853 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label),
1854 C_("codec", "Unknown"));
1858 empathy_streamed_media_window_disconnected (EmpathyStreamedMediaWindow *self,
1861 gboolean could_disconnect = FALSE;
1862 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1863 gboolean could_reset_pipeline;
1865 /* Leave full screen mode if needed */
1866 gtk_window_unfullscreen (GTK_WINDOW (self));
1868 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1870 could_reset_pipeline = empathy_streamed_media_window_reset_pipeline (self);
1872 if (priv->call_state == CONNECTING)
1873 empathy_sound_manager_stop (priv->sound_mgr,
1874 EMPATHY_SOUND_PHONE_OUTGOING);
1876 if (priv->call_state != REDIALING)
1877 priv->call_state = DISCONNECTED;
1879 if (could_reset_pipeline)
1881 g_mutex_lock (priv->lock);
1883 g_timer_stop (priv->timer);
1885 if (priv->timer_id != 0)
1886 g_source_remove (priv->timer_id);
1889 g_mutex_unlock (priv->lock);
1892 /* We are about to destroy the window, no need to update it or create
1893 * a video preview */
1896 empathy_streamed_media_window_status_message (self, _("Disconnected"));
1898 gtk_action_set_sensitive (priv->redial, TRUE);
1899 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1901 /* Unsensitive the camera and mic button */
1902 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1903 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
1904 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1906 /* Be sure that the mic button is enabled */
1907 gtk_toggle_tool_button_set_active (
1908 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1910 if (priv->camera_state == CAMERA_STATE_ON)
1912 /* Enable the 'preview' button as we are not sending atm. */
1913 gtk_toggle_tool_button_set_active (
1914 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1916 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1918 /* Restart the preview with the new pipeline. */
1919 display_video_preview (self, TRUE);
1922 gtk_progress_bar_set_fraction (
1923 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1925 /* destroy the video output; it will be recreated when we'll redial */
1926 disconnect_video_output_motion_handler (self);
1927 gtk_widget_destroy (priv->video_output);
1928 priv->video_output = NULL;
1930 gtk_widget_show (priv->remote_user_avatar_widget);
1932 reset_details_pane (self);
1934 priv->sending_video = FALSE;
1935 priv->call_started = FALSE;
1937 could_disconnect = TRUE;
1939 /* TODO: display the self avatar of the preview (depends if the "Always
1940 * Show Video Preview" is enabled or not) */
1943 return could_disconnect;
1948 empathy_streamed_media_window_channel_closed_cb (EmpathyStreamedMediaHandler *handler,
1951 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1952 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1954 if (empathy_streamed_media_window_disconnected (self, TRUE) &&
1955 priv->call_state == REDIALING)
1956 empathy_streamed_media_window_restart_call (self);
1961 empathy_streamed_media_window_channel_stream_closed_cb (EmpathyStreamedMediaHandler *handler,
1962 TfStream *stream, gpointer user_data)
1964 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1965 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1968 g_object_get (stream, "media-type", &media_type, NULL);
1971 * This assumes that there is only one video stream per channel...
1974 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1976 if (priv->funnel != NULL)
1980 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1981 (priv->video_output));
1983 gst_element_set_state (output, GST_STATE_NULL);
1984 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1986 gst_bin_remove (GST_BIN (priv->pipeline), output);
1987 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1988 priv->funnel = NULL;
1991 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1993 if (priv->audio_output != NULL)
1995 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1997 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1998 priv->audio_output = NULL;
2003 /* Called with global lock held */
2005 empathy_streamed_media_window_get_video_sink_pad (EmpathyStreamedMediaWindow *self)
2007 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2011 if (priv->funnel == NULL)
2013 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
2014 (priv->video_output));
2016 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2020 g_warning ("Could not create fsfunnel");
2024 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2026 gst_object_unref (priv->funnel);
2027 priv->funnel = NULL;
2028 g_warning ("Could not add funnel to pipeline");
2032 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2034 g_warning ("Could not add the video output widget to the pipeline");
2038 if (!gst_element_link (priv->funnel, output))
2040 g_warning ("Could not link output sink to funnel");
2041 goto error_output_added;
2044 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2046 g_warning ("Could not start video sink");
2047 goto error_output_added;
2050 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2052 g_warning ("Could not start funnel");
2053 goto error_output_added;
2057 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2060 g_warning ("Could not get request pad from funnel");
2067 gst_element_set_locked_state (priv->funnel, TRUE);
2068 gst_element_set_locked_state (output, TRUE);
2070 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2071 gst_element_set_state (output, GST_STATE_NULL);
2073 gst_bin_remove (GST_BIN (priv->pipeline), output);
2074 gst_element_set_locked_state (output, FALSE);
2078 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2079 priv->funnel = NULL;
2084 /* Called with global lock held */
2086 empathy_streamed_media_window_get_audio_sink_pad (EmpathyStreamedMediaWindow *self)
2088 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2090 GstPadTemplate *template;
2092 if (priv->audio_output == NULL)
2094 priv->audio_output = empathy_audio_sink_new ();
2096 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2098 g_warning ("Could not add audio sink to pipeline");
2099 g_object_unref (priv->audio_output);
2100 goto error_add_output;
2103 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2105 g_warning ("Could not start audio sink");
2110 template = gst_element_class_get_pad_template (
2111 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2113 pad = gst_element_request_pad (priv->audio_output,
2114 template, NULL, NULL);
2118 g_warning ("Could not get sink pad from sink");
2125 gst_element_set_locked_state (priv->audio_output, TRUE);
2126 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2127 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2128 priv->audio_output = NULL;
2136 empathy_streamed_media_window_update_timer (gpointer user_data)
2138 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2139 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2143 time_ = g_timer_elapsed (priv->timer, NULL);
2145 /* Translators: number of minutes:seconds the caller has been connected */
2146 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
2148 empathy_streamed_media_window_status_message (self, str);
2155 display_error (EmpathyStreamedMediaWindow *self,
2156 EmpathyTpStreamedMedia *call,
2160 const gchar *details)
2162 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2163 GtkWidget *info_bar;
2164 GtkWidget *content_area;
2171 /* Create info bar */
2172 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2175 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2177 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2179 /* hbox containing the image and the messages vbox */
2180 hbox = gtk_hbox_new (FALSE, 3);
2181 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2184 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2185 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2187 /* vbox containing the main message and the details expander */
2188 vbox = gtk_vbox_new (FALSE, 3);
2189 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2192 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2194 label = gtk_label_new (NULL);
2195 gtk_label_set_markup (GTK_LABEL (label), txt);
2196 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2197 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2200 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2203 if (details != NULL)
2205 GtkWidget *expander;
2207 expander = gtk_expander_new (_("Technical Details"));
2209 txt = g_strdup_printf ("<i>%s</i>", details);
2211 label = gtk_label_new (NULL);
2212 gtk_label_set_markup (GTK_LABEL (label), txt);
2213 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2214 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2217 gtk_container_add (GTK_CONTAINER (expander), label);
2218 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2221 g_signal_connect (info_bar, "response",
2222 G_CALLBACK (gtk_widget_destroy), NULL);
2224 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2225 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2226 gtk_widget_show_all (info_bar);
2230 media_stream_error_to_txt (EmpathyStreamedMediaWindow *self,
2231 EmpathyTpStreamedMedia *call,
2233 TpMediaStreamError error)
2235 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2242 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2244 return g_strdup_printf (
2245 _("%s's software does not understand any of the audio formats "
2246 "supported by your computer"),
2247 empathy_contact_get_alias (priv->contact));
2249 return g_strdup_printf (
2250 _("%s's software does not understand any of the video formats "
2251 "supported by your computer"),
2252 empathy_contact_get_alias (priv->contact));
2254 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2255 return g_strdup_printf (
2256 _("Can't establish a connection to %s. "
2257 "One of you might be on a network that does not allow "
2258 "direct connections."),
2259 empathy_contact_get_alias (priv->contact));
2261 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2262 return g_strdup (_("There was a failure on the network"));
2264 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2266 return g_strdup (_("The audio formats necessary for this call "
2267 "are not installed on your computer"));
2269 return g_strdup (_("The video formats necessary for this call "
2270 "are not installed on your computer"));
2272 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2273 cm = empathy_tp_streamed_media_get_connection_manager (call);
2275 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2276 "product=Telepathy&component=%s", cm);
2278 result = g_strdup_printf (
2279 _("Something unexpected happened in a Telepathy component. "
2280 "Please <a href=\"%s\">report this bug</a> and attach "
2281 "logs gathered from the 'Debug' window in the Help menu."), url);
2286 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2287 return g_strdup (_("There was a failure in the call engine"));
2289 case TP_MEDIA_STREAM_ERROR_EOS:
2290 return g_strdup (_("The end of the stream was reached"));
2292 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2299 empathy_streamed_media_window_stream_error (EmpathyStreamedMediaWindow *self,
2300 EmpathyTpStreamedMedia *call,
2309 desc = media_stream_error_to_txt (self, call, audio, code);
2312 /* No description, use the error message. That's not great as it's not
2313 * localized but it's better than nothing. */
2314 display_error (self, call, icon, title, msg, NULL);
2318 display_error (self, call, icon, title, desc, msg);
2324 empathy_streamed_media_window_audio_stream_error (EmpathyTpStreamedMedia *call,
2327 EmpathyStreamedMediaWindow *self)
2329 empathy_streamed_media_window_stream_error (self, call, TRUE, code, msg,
2330 "gnome-stock-mic", _("Can't establish audio stream"));
2334 empathy_streamed_media_window_video_stream_error (EmpathyTpStreamedMedia *call,
2337 EmpathyStreamedMediaWindow *self)
2339 empathy_streamed_media_window_stream_error (self, call, FALSE, code, msg,
2340 "camera-web", _("Can't establish video stream"));
2344 empathy_streamed_media_window_connected (gpointer user_data)
2346 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2347 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2348 EmpathyTpStreamedMedia *call;
2349 gboolean can_send_video;
2351 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2353 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2354 empathy_contact_can_voip_video (priv->contact);
2356 g_object_get (priv->handler, "tp-call", &call, NULL);
2358 tp_g_signal_connect_object (call, "notify::video-stream",
2359 G_CALLBACK (empathy_streamed_media_window_video_stream_changed_cb),
2362 if (empathy_tp_streamed_media_has_dtmf (call))
2363 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2365 if (priv->video_input == NULL)
2366 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
2368 priv->sending_video = can_send_video ?
2369 empathy_tp_streamed_media_is_sending_video (call) : FALSE;
2371 gtk_toggle_tool_button_set_active (
2372 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2373 priv->sending_video && priv->video_input != NULL);
2374 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2375 gtk_action_set_sensitive (priv->action_camera_on, can_send_video);
2377 gtk_action_set_sensitive (priv->redial, FALSE);
2378 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2380 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2382 empathy_streamed_media_window_update_avatars_visibility (call, self);
2384 g_object_unref (call);
2386 g_mutex_lock (priv->lock);
2388 priv->timer_id = g_timeout_add_seconds (1,
2389 empathy_streamed_media_window_update_timer, self);
2391 g_mutex_unlock (priv->lock);
2393 empathy_streamed_media_window_update_timer (self);
2395 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2401 /* Called from the streaming thread */
2403 empathy_streamed_media_window_src_added_cb (EmpathyStreamedMediaHandler *handler,
2404 GstPad *src, guint media_type, gpointer user_data)
2406 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2407 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2408 gboolean retval = FALSE;
2412 g_mutex_lock (priv->lock);
2414 if (priv->call_state != CONNECTED)
2416 g_timer_start (priv->timer);
2417 priv->timer_id = g_idle_add (empathy_streamed_media_window_connected, self);
2418 priv->call_state = CONNECTED;
2423 case TP_MEDIA_STREAM_TYPE_AUDIO:
2424 pad = empathy_streamed_media_window_get_audio_sink_pad (self);
2426 case TP_MEDIA_STREAM_TYPE_VIDEO:
2427 gtk_widget_hide (priv->remote_user_avatar_widget);
2428 gtk_widget_show (priv->video_output);
2429 pad = empathy_streamed_media_window_get_video_sink_pad (self);
2432 g_assert_not_reached ();
2438 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2439 g_warning ("Could not link %s sink pad",
2440 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2444 gst_object_unref (pad);
2448 /* If no sink could be linked, try to add fakesink to prevent the whole call
2453 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2455 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2457 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2458 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2459 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2461 gst_element_set_locked_state (fakesink, TRUE);
2462 gst_element_set_state (fakesink, GST_STATE_NULL);
2463 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2467 DEBUG ("Could not link real sink, linked fakesink instead");
2469 gst_object_unref (sinkpad);
2473 gst_object_unref (fakesink);
2478 g_mutex_unlock (priv->lock);
2484 empathy_streamed_media_window_sink_added_cb (EmpathyStreamedMediaHandler *handler,
2485 GstPad *sink, guint media_type, gpointer user_data)
2487 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2488 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2490 gboolean retval = FALSE;
2494 case TP_MEDIA_STREAM_TYPE_AUDIO:
2495 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2497 g_warning ("Could not add audio source to pipeline");
2501 pad = gst_element_get_static_pad (priv->audio_input, "src");
2504 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2505 g_warning ("Could not get source pad from audio source");
2509 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2511 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2512 g_warning ("Could not link audio source to farsight");
2516 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2518 g_warning ("Could not start audio source");
2519 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2520 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2526 case TP_MEDIA_STREAM_TYPE_VIDEO:
2527 if (priv->video_input != NULL)
2529 if (priv->video_tee != NULL)
2531 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2532 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2534 g_warning ("Could not link videp soure input pipeline");
2537 gst_object_unref (pad);
2544 g_assert_not_reached ();
2551 empathy_streamed_media_window_remove_video_input (EmpathyStreamedMediaWindow *self)
2553 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2554 GstElement *preview;
2556 disable_camera (self);
2558 DEBUG ("remove video input");
2559 preview = empathy_video_widget_get_element (
2560 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2562 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2563 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2564 gst_element_set_state (preview, GST_STATE_NULL);
2566 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2567 priv->video_tee, preview, NULL);
2569 g_object_unref (priv->video_input);
2570 priv->video_input = NULL;
2571 g_object_unref (priv->video_tee);
2572 priv->video_tee = NULL;
2573 gtk_widget_destroy (priv->video_preview);
2574 priv->video_preview = NULL;
2576 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2577 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
2578 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2582 start_call (EmpathyStreamedMediaWindow *self)
2584 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2586 priv->call_started = TRUE;
2587 empathy_streamed_media_handler_start_call (priv->handler,
2588 empathy_get_current_action_time ());
2590 if (empathy_streamed_media_handler_has_initial_video (priv->handler))
2592 /* Enable 'send video' buttons and display the preview */
2593 gtk_toggle_tool_button_set_active (
2594 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2599 empathy_streamed_media_window_bus_message (GstBus *bus, GstMessage *message,
2602 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2603 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2606 empathy_streamed_media_handler_bus_message (priv->handler, bus, message);
2608 switch (GST_MESSAGE_TYPE (message))
2610 case GST_MESSAGE_STATE_CHANGED:
2611 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2613 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2614 if (newstate == GST_STATE_PAUSED)
2615 empathy_streamed_media_window_setup_video_input (self);
2617 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2618 !priv->call_started)
2620 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2621 if (newstate == GST_STATE_PAUSED)
2623 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2624 priv->pipeline_playing = TRUE;
2626 if (priv->start_call_when_playing)
2631 case GST_MESSAGE_ERROR:
2633 GError *error = NULL;
2634 GstElement *gst_error;
2637 gst_message_parse_error (message, &error, &debug);
2638 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2640 g_message ("Element error: %s -- %s\n", error->message, debug);
2642 if (g_str_has_prefix (gst_element_get_name (gst_error),
2643 VIDEO_INPUT_ERROR_PREFIX))
2645 /* Remove the video input and continue */
2646 if (priv->video_input != NULL)
2647 empathy_streamed_media_window_remove_video_input (self);
2648 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2652 empathy_streamed_media_window_disconnected (self, TRUE);
2654 g_error_free (error);
2657 case GST_MESSAGE_UNKNOWN:
2658 case GST_MESSAGE_EOS:
2659 case GST_MESSAGE_WARNING:
2660 case GST_MESSAGE_INFO:
2661 case GST_MESSAGE_TAG:
2662 case GST_MESSAGE_BUFFERING:
2663 case GST_MESSAGE_STATE_DIRTY:
2664 case GST_MESSAGE_STEP_DONE:
2665 case GST_MESSAGE_CLOCK_PROVIDE:
2666 case GST_MESSAGE_CLOCK_LOST:
2667 case GST_MESSAGE_NEW_CLOCK:
2668 case GST_MESSAGE_STRUCTURE_CHANGE:
2669 case GST_MESSAGE_STREAM_STATUS:
2670 case GST_MESSAGE_APPLICATION:
2671 case GST_MESSAGE_ELEMENT:
2672 case GST_MESSAGE_SEGMENT_START:
2673 case GST_MESSAGE_SEGMENT_DONE:
2674 case GST_MESSAGE_DURATION:
2675 case GST_MESSAGE_ANY:
2684 empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
2685 EmpathyStreamedMediaWindow *window)
2687 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2689 if (empathy_tp_streamed_media_is_receiving_video (call))
2691 gtk_widget_hide (priv->remote_user_avatar_widget);
2692 gtk_widget_show (priv->video_output);
2696 gtk_widget_hide (priv->video_output);
2697 gtk_widget_show (priv->remote_user_avatar_widget);
2702 call_handler_notify_tp_streamed_media_cb (EmpathyStreamedMediaHandler *handler,
2704 EmpathyStreamedMediaWindow *self)
2706 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2707 EmpathyTpStreamedMedia *call;
2709 g_object_get (priv->handler, "tp-call", &call, NULL);
2713 tp_g_signal_connect_object (call, "audio-stream-error",
2714 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), self, 0);
2715 tp_g_signal_connect_object (call, "video-stream-error",
2716 G_CALLBACK (empathy_streamed_media_window_video_stream_error), self, 0);
2718 g_object_unref (call);
2722 empathy_streamed_media_window_realized_cb (GtkWidget *widget, EmpathyStreamedMediaWindow *window)
2724 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2725 EmpathyTpStreamedMedia *call;
2727 g_signal_connect (priv->handler, "conference-added",
2728 G_CALLBACK (empathy_streamed_media_window_conference_added_cb), window);
2729 g_signal_connect (priv->handler, "request-resource",
2730 G_CALLBACK (empathy_streamed_media_window_request_resource_cb), window);
2731 g_signal_connect (priv->handler, "closed",
2732 G_CALLBACK (empathy_streamed_media_window_channel_closed_cb), window);
2733 g_signal_connect (priv->handler, "src-pad-added",
2734 G_CALLBACK (empathy_streamed_media_window_src_added_cb), window);
2735 g_signal_connect (priv->handler, "sink-pad-added",
2736 G_CALLBACK (empathy_streamed_media_window_sink_added_cb), window);
2737 g_signal_connect (priv->handler, "stream-closed",
2738 G_CALLBACK (empathy_streamed_media_window_channel_stream_closed_cb), window);
2740 g_object_get (priv->handler, "tp-call", &call, NULL);
2743 tp_g_signal_connect_object (call, "audio-stream-error",
2744 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), window,
2746 tp_g_signal_connect_object (call, "video-stream-error",
2747 G_CALLBACK (empathy_streamed_media_window_video_stream_error), window,
2750 g_object_unref (call);
2754 /* tp-call doesn't exist yet, we'll connect signals once it has been
2756 g_signal_connect (priv->handler, "notify::tp-call",
2757 G_CALLBACK (call_handler_notify_tp_streamed_media_cb), window);
2760 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2764 empathy_streamed_media_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2765 EmpathyStreamedMediaWindow *window)
2767 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2769 if (priv->pipeline != NULL)
2771 if (priv->bus_message_source_id != 0)
2773 g_source_remove (priv->bus_message_source_id);
2774 priv->bus_message_source_id = 0;
2777 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2780 if (priv->call_state == CONNECTING)
2781 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2787 show_controls (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2790 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2792 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2797 gtk_widget_hide (priv->sidebar);
2798 gtk_widget_hide (menu);
2799 gtk_widget_hide (priv->vbox);
2800 gtk_widget_hide (priv->statusbar);
2801 gtk_widget_hide (priv->toolbar);
2805 if (priv->sidebar_was_visible_before_fs)
2806 gtk_widget_show (priv->sidebar);
2808 gtk_widget_show (menu);
2809 gtk_widget_show (priv->vbox);
2810 gtk_widget_show (priv->statusbar);
2811 gtk_widget_show (priv->toolbar);
2813 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2814 priv->original_height_before_fs);
2819 show_borders (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2821 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2823 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2824 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2825 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2826 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2828 if (priv->video_output != NULL)
2830 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2831 priv->video_output, TRUE, TRUE,
2832 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2836 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2837 priv->vbox, TRUE, TRUE,
2838 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2843 empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
2844 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window)
2846 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2848 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2849 gboolean set_fullscreen = event->new_window_state &
2850 GDK_WINDOW_STATE_FULLSCREEN;
2854 gboolean sidebar_was_visible;
2855 GtkAllocation allocation;
2856 gint original_width, original_height;
2858 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2859 original_width = allocation.width;
2860 original_height = allocation.height;
2862 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2864 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2865 priv->original_width_before_fs = original_width;
2866 priv->original_height_before_fs = original_height;
2868 if (priv->video_output_motion_handler_id == 0 &&
2869 priv->video_output != NULL)
2871 priv->video_output_motion_handler_id = g_signal_connect (
2872 G_OBJECT (priv->video_output), "motion-notify-event",
2873 G_CALLBACK (empathy_streamed_media_window_video_output_motion_notify),
2879 disconnect_video_output_motion_handler (window);
2882 empathy_streamed_media_window_fullscreen_set_fullscreen (priv->fullscreen,
2884 show_controls (window, set_fullscreen);
2885 show_borders (window, set_fullscreen);
2886 gtk_action_set_stock_id (priv->menu_fullscreen,
2887 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2888 priv->is_fullscreen = set_fullscreen;
2895 empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2896 EmpathyStreamedMediaWindow *window)
2898 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2900 int w, h, handle_size;
2901 GtkAllocation allocation, sidebar_allocation;
2903 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2904 w = allocation.width;
2905 h = allocation.height;
2907 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2909 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2910 if (gtk_toggle_button_get_active (toggle))
2912 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2913 gtk_widget_show (priv->sidebar);
2914 w += sidebar_allocation.width + handle_size;
2918 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2919 w -= sidebar_allocation.width + handle_size;
2920 gtk_widget_hide (priv->sidebar);
2923 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2926 gtk_window_resize (GTK_WINDOW (window), w, h);
2930 empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
2933 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2934 EmpathyTpStreamedMedia *call;
2936 priv->sending_video = (state == CAMERA_STATE_ON);
2938 if (state == CAMERA_STATE_PREVIEW ||
2939 state == CAMERA_STATE_ON)
2941 /* When we start sending video, we want to show the video preview by
2943 display_video_preview (window, TRUE);
2947 display_video_preview (window, FALSE);
2950 if (priv->call_state != CONNECTED)
2953 g_object_get (priv->handler, "tp-call", &call, NULL);
2954 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2955 empathy_tp_streamed_media_request_video_stream_direction (call, priv->sending_video);
2956 g_object_unref (call);
2960 empathy_streamed_media_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2961 EmpathyStreamedMediaWindow *window)
2963 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2966 active = (gtk_toggle_tool_button_get_active (toggle));
2970 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2972 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2976 /* TODO, Instead of setting the input volume to 0 we should probably
2977 * stop sending but this would cause the audio call to drop if both
2978 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2979 * in the future. GNOME #574574
2981 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2983 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2988 empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
2989 EmpathyStreamedMediaWindow *window)
2991 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2993 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2998 empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
2999 EmpathyStreamedMediaWindow *window)
3001 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3003 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
3008 empathy_streamed_media_window_hangup_cb (gpointer object,
3009 EmpathyStreamedMediaWindow *window)
3011 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3013 empathy_streamed_media_handler_stop_call (priv->handler);
3015 if (empathy_streamed_media_window_disconnected (window, FALSE))
3016 gtk_widget_destroy (GTK_WIDGET (window));
3020 empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window)
3022 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3024 /* Remove error info bars */
3025 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3026 (GtkCallback) gtk_widget_destroy, NULL);
3028 create_video_output_widget (window);
3030 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3031 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), window);
3033 /* While the call was disconnected, the input volume might have changed.
3034 * However, since the audio_input source was destroyed, its volume has not
3035 * been updated during that time. That's why we manually update it here */
3036 empathy_streamed_media_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3038 priv->outgoing = TRUE;
3039 empathy_streamed_media_window_set_state_connecting (window);
3041 if (priv->pipeline_playing)
3042 start_call (window);
3044 /* call will be started when the pipeline is ready */
3045 priv->start_call_when_playing = TRUE;
3048 empathy_streamed_media_window_setup_avatars (window, priv->handler);
3050 gtk_action_set_sensitive (priv->redial, FALSE);
3051 gtk_widget_set_sensitive (priv->redial_button, FALSE);
3055 empathy_streamed_media_window_redial_cb (gpointer object,
3056 EmpathyStreamedMediaWindow *window)
3058 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3060 if (priv->call_state == CONNECTED)
3061 priv->call_state = REDIALING;
3063 empathy_streamed_media_handler_stop_call (priv->handler);
3065 if (priv->call_state != CONNECTED)
3066 empathy_streamed_media_window_restart_call (window);
3070 empathy_streamed_media_window_fullscreen_cb (gpointer object,
3071 EmpathyStreamedMediaWindow *window)
3073 empathy_streamed_media_window_fullscreen_toggle (window);
3077 empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window)
3079 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3081 if (priv->is_fullscreen)
3082 gtk_window_unfullscreen (GTK_WINDOW (window));
3084 gtk_window_fullscreen (GTK_WINDOW (window));
3088 empathy_streamed_media_window_video_button_press_cb (GtkWidget *video_output,
3089 GdkEventButton *event, EmpathyStreamedMediaWindow *window)
3091 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3093 empathy_streamed_media_window_video_menu_popup (window, event->button);
3101 empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
3102 GdkEventKey *event, EmpathyStreamedMediaWindow *window)
3104 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3106 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3108 /* Since we are in fullscreen mode, toggling will bring us back to
3110 empathy_streamed_media_window_fullscreen_toggle (window);
3118 empathy_streamed_media_window_video_output_motion_notify (GtkWidget *widget,
3119 GdkEventMotion *event, EmpathyStreamedMediaWindow *window)
3121 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3123 if (priv->is_fullscreen)
3125 empathy_streamed_media_window_fullscreen_show_popup (priv->fullscreen);
3132 empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
3136 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3138 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3140 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3141 button, gtk_get_current_event_time ());
3142 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3146 empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
3149 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3151 if (priv->context_id == 0)
3153 priv->context_id = gtk_statusbar_get_context_id (
3154 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
3158 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
3161 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
3166 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
3167 gdouble value, EmpathyStreamedMediaWindow *window)
3169 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3171 if (priv->audio_output == NULL)
3174 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3178 /* block all the signals related to camera control widgets. This is useful
3179 * when we are manually updating the UI and so don't want to fire the
3182 block_camera_control_signals (EmpathyStreamedMediaWindow *self)
3184 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3186 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
3187 tool_button_camera_off_toggled_cb, self);
3188 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
3189 tool_button_camera_preview_toggled_cb, self);
3190 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
3191 tool_button_camera_on_toggled_cb, self);
3192 g_signal_handlers_block_by_func (priv->action_camera_on,
3193 action_camera_change_cb, self);
3197 unblock_camera_control_signals (EmpathyStreamedMediaWindow *self)
3199 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3201 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
3202 tool_button_camera_off_toggled_cb, self);
3203 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
3204 tool_button_camera_preview_toggled_cb, self);
3205 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
3206 tool_button_camera_on_toggled_cb, self);
3207 g_signal_handlers_unblock_by_func (priv->action_camera_on,
3208 action_camera_change_cb, self);