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>
38 #include <gst/farsight/fs-utils.h>
40 #include <libempathy/empathy-tp-contact-factory.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy-gtk/empathy-avatar-image.h>
43 #include <libempathy-gtk/empathy-dialpad-widget.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include <libempathy-gtk/empathy-sound-manager.h>
46 #include <libempathy-gtk/empathy-geometry.h>
47 #include <libempathy-gtk/empathy-images.h>
49 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
50 #include <libempathy/empathy-debug.h>
52 #include "empathy-streamed-media-window.h"
53 #include "empathy-streamed-media-window-fullscreen.h"
54 #include "empathy-video-widget.h"
55 #include "empathy-audio-src.h"
56 #include "empathy-audio-sink.h"
57 #include "empathy-video-src.h"
58 #include "ev-sidebar.h"
60 #define CONTENT_HBOX_BORDER_WIDTH 6
61 #define CONTENT_HBOX_SPACING 3
62 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
64 #define SELF_VIDEO_SECTION_WIDTH 160
65 #define SELF_VIDEO_SECTION_HEIGTH 120
67 /* The avatar's default width and height are set to the same value because we
68 want a square icon. */
69 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
70 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
71 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
73 /* If an video input error occurs, the error message will start with "v4l" */
74 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
76 /* The time interval in milliseconds between 2 outgoing rings */
77 #define MS_BETWEEN_RING 500
79 G_DEFINE_TYPE(EmpathyStreamedMediaWindow, empathy_streamed_media_window, GTK_TYPE_WINDOW)
88 static guint signals[LAST_SIGNAL] = {0};
92 PROP_STREAMED_MEDIA_HANDLER = 1,
103 CAMERA_STATE_OFF = 0,
104 CAMERA_STATE_PREVIEW,
108 /* private structure */
109 typedef struct _EmpathyStreamedMediaWindowPriv EmpathyStreamedMediaWindowPriv;
111 struct _EmpathyStreamedMediaWindowPriv
113 gboolean dispose_has_run;
114 EmpathyStreamedMediaHandler *handler;
115 EmpathyContact *contact;
120 GtkUIManager *ui_manager;
121 GtkWidget *errors_vbox;
122 /* widget displays the video received from the remote user. This widget is
123 * alive only during call. */
124 GtkWidget *video_output;
125 GtkWidget *video_preview;
126 GtkWidget *remote_user_avatar_widget;
127 GtkWidget *self_user_avatar_widget;
129 GtkWidget *sidebar_button;
130 GtkWidget *statusbar;
131 GtkWidget *volume_button;
132 GtkWidget *redial_button;
133 GtkWidget *mic_button;
137 GtkAction *menu_fullscreen;
138 GtkAction *action_camera_on;
139 GtkWidget *tool_button_camera_off;
140 GtkWidget *tool_button_camera_preview;
141 GtkWidget *tool_button_camera_on;
143 /* The frames and boxes that contain self and remote avatar and video
144 input/output. When we redial, we destroy and re-create the boxes */
145 GtkWidget *remote_user_output_frame;
146 GtkWidget *self_user_output_frame;
147 GtkWidget *remote_user_output_hbox;
148 GtkWidget *self_user_output_hbox;
150 /* We keep a reference on the hbox which contains the main content so we can
151 easilly repack everything when toggling fullscreen */
152 GtkWidget *content_hbox;
154 /* This vbox is contained in the content_hbox and it contains the
155 self_user_output_frame and the sidebar button. When toggling fullscreen,
156 it needs to be repacked. We keep a reference on it for easier access. */
159 gulong video_output_motion_handler_id;
160 guint bus_message_source_id;
163 GtkWidget *volume_scale;
164 GtkWidget *volume_progress_bar;
165 GtkAdjustment *audio_input_adj;
167 GtkWidget *dtmf_panel;
170 GtkWidget *details_vbox;
171 GtkWidget *vcodec_encoding_label;
172 GtkWidget *acodec_encoding_label;
173 GtkWidget *vcodec_decoding_label;
174 GtkWidget *acodec_decoding_label;
176 GtkWidget *audio_remote_candidate_label;
177 GtkWidget *audio_local_candidate_label;
178 GtkWidget *video_remote_candidate_label;
179 GtkWidget *video_local_candidate_label;
180 GtkWidget *video_remote_candidate_info_img;
181 GtkWidget *video_local_candidate_info_img;
182 GtkWidget *audio_remote_candidate_info_img;
183 GtkWidget *audio_local_candidate_info_img;
185 GstElement *video_input;
186 GstElement *audio_input;
187 GstElement *audio_output;
188 GstElement *pipeline;
189 GstElement *video_tee;
193 FsElementAddedNotifier *fsnotifier;
200 GtkWidget *video_contrast;
201 GtkWidget *video_brightness;
202 GtkWidget *video_gamma;
205 gboolean call_started;
206 gboolean sending_video;
207 CameraState camera_state;
209 EmpathyStreamedMediaWindowFullscreen *fullscreen;
210 gboolean is_fullscreen;
212 /* Those fields represent the state of the window before it actually was in
214 gboolean sidebar_was_visible_before_fs;
215 gint original_width_before_fs;
216 gint original_height_before_fs;
218 /* TRUE if the call should be started when the pipeline is playing */
219 gboolean start_call_when_playing;
220 /* TRUE if we requested to set the pipeline in the playing state */
221 gboolean pipeline_playing;
223 EmpathySoundManager *sound_mgr;
226 #define GET_PRIV(o) \
227 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, \
228 EmpathyStreamedMediaWindowPriv))
230 static void empathy_streamed_media_window_realized_cb (GtkWidget *widget,
231 EmpathyStreamedMediaWindow *window);
233 static gboolean empathy_streamed_media_window_delete_cb (GtkWidget *widget,
234 GdkEvent *event, EmpathyStreamedMediaWindow *window);
236 static gboolean empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
237 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window);
239 static void empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
240 EmpathyStreamedMediaWindow *window);
242 static void empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
245 static void empathy_streamed_media_window_mic_toggled_cb (
246 GtkToggleToolButton *toggle, EmpathyStreamedMediaWindow *window);
248 static void empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
249 EmpathyStreamedMediaWindow *window);
251 static void empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
252 EmpathyStreamedMediaWindow *window);
254 static void empathy_streamed_media_window_hangup_cb (gpointer object,
255 EmpathyStreamedMediaWindow *window);
257 static void empathy_streamed_media_window_fullscreen_cb (gpointer object,
258 EmpathyStreamedMediaWindow *window);
260 static void empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window);
262 static gboolean empathy_streamed_media_window_video_button_press_cb (
263 GtkWidget *video_output, GdkEventButton *event, EmpathyStreamedMediaWindow *window);
265 static gboolean empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
266 GdkEventKey *event, EmpathyStreamedMediaWindow *window);
268 static gboolean empathy_streamed_media_window_video_output_motion_notify (
269 GtkWidget *widget, GdkEventMotion *event, EmpathyStreamedMediaWindow *window);
271 static void empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
274 static void empathy_streamed_media_window_redial_cb (gpointer object,
275 EmpathyStreamedMediaWindow *window);
277 static void empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window);
279 static void empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
282 static void empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
283 EmpathyStreamedMediaWindow *window);
285 static gboolean empathy_streamed_media_window_bus_message (GstBus *bus,
286 GstMessage *message, gpointer user_data);
289 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
290 gdouble value, EmpathyStreamedMediaWindow *window);
292 static void block_camera_control_signals (EmpathyStreamedMediaWindow *self);
293 static void unblock_camera_control_signals (EmpathyStreamedMediaWindow *self);
296 empathy_streamed_media_window_setup_toolbar (EmpathyStreamedMediaWindow *self)
298 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
299 GtkToolItem *tool_item;
300 GtkWidget *camera_off_icon;
301 GdkPixbuf *pixbuf, *modded_pixbuf;
303 /* set the icon of the 'camera off' button by greying off the webcam icon */
304 pixbuf = empathy_pixbuf_from_icon_name ("camera-web",
305 GTK_ICON_SIZE_SMALL_TOOLBAR);
307 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
308 gdk_pixbuf_get_width (pixbuf),
309 gdk_pixbuf_get_height (pixbuf));
311 gdk_pixbuf_saturate_and_pixelate (pixbuf, modded_pixbuf, 1.0, TRUE);
312 g_object_unref (pixbuf);
314 camera_off_icon = gtk_image_new_from_pixbuf (modded_pixbuf);
315 g_object_unref (modded_pixbuf);
316 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (
317 priv->tool_button_camera_off), camera_off_icon);
319 /* Add an empty expanded GtkToolItem so the volume button is at the end of
321 tool_item = gtk_tool_item_new ();
322 gtk_tool_item_set_expand (tool_item, TRUE);
323 gtk_widget_show (GTK_WIDGET (tool_item));
324 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
326 priv->volume_button = gtk_volume_button_new ();
327 /* FIXME listen to the audiosinks signals and update the button according to
328 * that, for now starting out at 1.0 and assuming only the app changes the
330 gtk_scale_button_set_value (GTK_SCALE_BUTTON (priv->volume_button), 1.0);
331 g_signal_connect (G_OBJECT (priv->volume_button), "value-changed",
332 G_CALLBACK (empathy_streamed_media_window_volume_changed_cb), self);
334 tool_item = gtk_tool_item_new ();
335 gtk_container_add (GTK_CONTAINER (tool_item), priv->volume_button);
336 gtk_widget_show_all (GTK_WIDGET (tool_item));
337 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, -1);
341 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
343 EmpathyStreamedMediaWindow *window)
345 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
346 EmpathyTpStreamedMedia *call;
348 g_object_get (priv->handler, "tp-call", &call, NULL);
350 empathy_tp_streamed_media_start_tone (call, event);
352 g_object_unref (call);
356 dtmf_stop_tone_cb (EmpathyDialpadWidget *self,
358 EmpathyStreamedMediaWindow *window)
360 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
361 EmpathyTpStreamedMedia *call;
363 g_object_get (priv->handler, "tp-call", &call, NULL);
365 empathy_tp_streamed_media_stop_tone (call);
367 g_object_unref (call);
371 empathy_streamed_media_window_create_video_input_add_slider (EmpathyStreamedMediaWindow *self,
372 gchar *label_text, GtkWidget *bin)
374 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
375 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
376 GtkWidget *label = gtk_label_new (label_text);
378 gtk_widget_set_sensitive (scale, FALSE);
380 gtk_container_add (GTK_CONTAINER (bin), vbox);
382 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
383 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
384 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
390 empathy_streamed_media_window_video_contrast_changed_cb (GtkAdjustment *adj,
391 EmpathyStreamedMediaWindow *self)
394 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
396 empathy_video_src_set_channel (priv->video_input,
397 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
401 empathy_streamed_media_window_video_brightness_changed_cb (GtkAdjustment *adj,
402 EmpathyStreamedMediaWindow *self)
405 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
407 empathy_video_src_set_channel (priv->video_input,
408 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
412 empathy_streamed_media_window_video_gamma_changed_cb (GtkAdjustment *adj,
413 EmpathyStreamedMediaWindow *self)
416 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
418 empathy_video_src_set_channel (priv->video_input,
419 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
424 empathy_streamed_media_window_create_video_input (EmpathyStreamedMediaWindow *self)
426 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
429 hbox = gtk_hbox_new (TRUE, 3);
431 priv->video_contrast = empathy_streamed_media_window_create_video_input_add_slider (
432 self, _("Contrast"), hbox);
434 priv->video_brightness = empathy_streamed_media_window_create_video_input_add_slider (
435 self, _("Brightness"), hbox);
437 priv->video_gamma = empathy_streamed_media_window_create_video_input_add_slider (
438 self, _("Gamma"), hbox);
444 empathy_streamed_media_window_setup_video_input (EmpathyStreamedMediaWindow *self)
446 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
450 supported = empathy_video_src_get_supported_channels (priv->video_input);
452 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
454 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
456 gtk_adjustment_set_value (adj,
457 empathy_video_src_get_channel (priv->video_input,
458 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
460 g_signal_connect (G_OBJECT (adj), "value-changed",
461 G_CALLBACK (empathy_streamed_media_window_video_contrast_changed_cb), self);
463 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
466 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
468 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
470 gtk_adjustment_set_value (adj,
471 empathy_video_src_get_channel (priv->video_input,
472 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
474 g_signal_connect (G_OBJECT (adj), "value-changed",
475 G_CALLBACK (empathy_streamed_media_window_video_brightness_changed_cb), self);
476 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
479 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
481 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
483 gtk_adjustment_set_value (adj,
484 empathy_video_src_get_channel (priv->video_input,
485 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
487 g_signal_connect (G_OBJECT (adj), "value-changed",
488 G_CALLBACK (empathy_streamed_media_window_video_gamma_changed_cb), self);
489 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
494 empathy_streamed_media_window_mic_volume_changed_cb (GtkAdjustment *adj,
495 EmpathyStreamedMediaWindow *self)
497 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
500 volume = gtk_adjustment_get_value (adj)/100.0;
502 /* Don't store the volume because of muting */
503 if (volume > 0 || gtk_toggle_tool_button_get_active (
504 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
505 priv->volume = volume;
507 /* Ensure that the toggle button is active if the volume is > 0 and inactive
508 * if it's smaller than 0 */
509 if ((volume > 0) != gtk_toggle_tool_button_get_active (
510 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
511 gtk_toggle_tool_button_set_active (
512 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
514 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
519 empathy_streamed_media_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
520 gdouble level, EmpathyStreamedMediaWindow *window)
523 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
525 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
526 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
531 empathy_streamed_media_window_create_audio_input (EmpathyStreamedMediaWindow *self)
533 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
534 GtkWidget *hbox, *vbox, *label;
536 hbox = gtk_hbox_new (TRUE, 3);
538 vbox = gtk_vbox_new (FALSE, 3);
539 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
541 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
542 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
543 label = gtk_label_new (_("Volume"));
545 priv->audio_input_adj = gtk_range_get_adjustment (
546 GTK_RANGE (priv->volume_scale));
547 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
548 (priv->audio_input));
549 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
551 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
552 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), self);
554 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
555 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
557 priv->volume_progress_bar = gtk_progress_bar_new ();
559 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
560 GTK_ORIENTATION_VERTICAL);
562 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
565 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
572 create_video_output_widget (EmpathyStreamedMediaWindow *self)
574 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
577 g_assert (priv->video_output == NULL);
578 g_assert (priv->pipeline != NULL);
580 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
581 priv->video_output = empathy_video_widget_new (bus);
583 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
584 priv->video_output, TRUE, TRUE, 0);
586 gtk_widget_add_events (priv->video_output,
587 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
588 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
589 G_CALLBACK (empathy_streamed_media_window_video_button_press_cb), self);
591 g_object_unref (bus);
595 create_video_input (EmpathyStreamedMediaWindow *self)
597 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
599 g_assert (priv->video_input == NULL);
600 priv->video_input = empathy_video_src_new ();
601 gst_object_ref (priv->video_input);
602 gst_object_sink (priv->video_input);
606 create_audio_input (EmpathyStreamedMediaWindow *self)
608 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
610 g_assert (priv->audio_input == NULL);
611 priv->audio_input = empathy_audio_src_new ();
612 gst_object_ref (priv->audio_input);
613 gst_object_sink (priv->audio_input);
615 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
616 G_CALLBACK (empathy_streamed_media_window_audio_input_level_changed_cb),
621 add_video_preview_to_pipeline (EmpathyStreamedMediaWindow *self)
623 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
626 g_assert (priv->video_preview != NULL);
627 g_assert (priv->pipeline != NULL);
628 g_assert (priv->video_input != NULL);
629 g_assert (priv->video_tee != NULL);
631 preview = empathy_video_widget_get_element (
632 EMPATHY_VIDEO_WIDGET (priv->video_preview));
634 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
636 g_warning ("Could not add video input to pipeline");
640 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
642 g_warning ("Could not add video tee to pipeline");
646 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
648 g_warning ("Could not add video preview to pipeline");
652 if (!gst_element_link (priv->video_input, priv->video_tee))
654 g_warning ("Could not link video input to video tee");
658 if (!gst_element_link (priv->video_tee, preview))
660 g_warning ("Could not link video tee to video preview");
666 create_video_preview (EmpathyStreamedMediaWindow *self)
668 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
671 g_assert (priv->video_preview == NULL);
672 g_assert (priv->video_tee == NULL);
674 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
676 priv->video_preview = empathy_video_widget_new_with_size (bus,
677 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
678 g_object_set (priv->video_preview,
684 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
685 priv->video_preview, TRUE, TRUE, 0);
687 priv->video_tee = gst_element_factory_make ("tee", NULL);
688 gst_object_ref (priv->video_tee);
689 gst_object_sink (priv->video_tee);
691 g_object_unref (bus);
695 play_camera (EmpathyStreamedMediaWindow *window,
698 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
702 if (priv->video_preview == NULL)
704 create_video_preview (window);
705 add_video_preview_to_pipeline (window);
709 state = GST_STATE_PLAYING;
711 state = GST_STATE_NULL;
713 preview = empathy_video_widget_get_element (
714 EMPATHY_VIDEO_WIDGET (priv->video_preview));
716 gst_element_set_state (preview, state);
717 gst_element_set_state (priv->video_input, state);
718 gst_element_set_state (priv->video_tee, state);
722 display_video_preview (EmpathyStreamedMediaWindow *self,
725 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
729 /* Display the preview and hide the self avatar */
730 DEBUG ("Show video preview");
732 play_camera (self, TRUE);
733 gtk_widget_show (priv->video_preview);
734 gtk_widget_hide (priv->self_user_avatar_widget);
738 /* Display the self avatar and hide the preview */
739 DEBUG ("Show self avatar");
741 if (priv->video_preview != NULL)
743 gtk_widget_hide (priv->video_preview);
744 play_camera (self, FALSE);
746 gtk_widget_show (priv->self_user_avatar_widget);
751 empathy_streamed_media_window_set_state_connecting (EmpathyStreamedMediaWindow *window)
753 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
755 empathy_streamed_media_window_status_message (window, _("Connecting…"));
756 priv->call_state = CONNECTING;
759 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
760 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
764 disable_camera (EmpathyStreamedMediaWindow *self)
766 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
768 if (priv->camera_state == CAMERA_STATE_OFF)
771 DEBUG ("Disable camera");
773 display_video_preview (self, FALSE);
775 if (priv->camera_state == CAMERA_STATE_ON)
776 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
778 block_camera_control_signals (self);
779 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
780 priv->tool_button_camera_on), FALSE);
781 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
782 priv->tool_button_camera_preview), FALSE);
784 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
785 priv->tool_button_camera_off), TRUE);
786 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
788 unblock_camera_control_signals (self);
790 priv->camera_state = CAMERA_STATE_OFF;
794 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
795 EmpathyStreamedMediaWindow *self)
797 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
799 if (!gtk_toggle_tool_button_get_active (toggle))
801 if (priv->camera_state == CAMERA_STATE_OFF)
803 /* We can't change the state by disabling the button */
804 block_camera_control_signals (self);
805 gtk_toggle_tool_button_set_active (toggle, TRUE);
806 unblock_camera_control_signals (self);
812 disable_camera (self);
816 enable_preview (EmpathyStreamedMediaWindow *self)
818 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
820 if (priv->camera_state == CAMERA_STATE_PREVIEW)
823 DEBUG ("Enable preview");
825 if (priv->camera_state == CAMERA_STATE_ON)
827 /* preview is already displayed so we just have to stop sending */
828 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_PREVIEW);
832 display_video_preview (self, TRUE);
835 block_camera_control_signals (self);
836 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
837 priv->tool_button_camera_off), FALSE);
838 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
839 priv->tool_button_camera_on), FALSE);
841 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
842 priv->tool_button_camera_preview), TRUE);
843 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
844 CAMERA_STATE_PREVIEW);
845 unblock_camera_control_signals (self);
847 priv->camera_state = CAMERA_STATE_PREVIEW;
851 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
852 EmpathyStreamedMediaWindow *self)
854 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
856 if (!gtk_toggle_tool_button_get_active (toggle))
858 if (priv->camera_state == CAMERA_STATE_PREVIEW)
860 /* We can't change the state by disabling the button */
861 block_camera_control_signals (self);
862 gtk_toggle_tool_button_set_active (toggle, TRUE);
863 unblock_camera_control_signals (self);
869 enable_preview (self);
873 enable_camera (EmpathyStreamedMediaWindow *self)
875 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
877 if (priv->camera_state == CAMERA_STATE_ON)
880 if (priv->video_input == NULL)
882 DEBUG ("Can't enable camera, no input");
887 DEBUG ("Enable camera");
889 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_ON);
891 block_camera_control_signals (self);
892 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
893 priv->tool_button_camera_off), FALSE);
894 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
895 priv->tool_button_camera_preview), FALSE);
897 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
898 priv->tool_button_camera_on), TRUE);
899 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
901 unblock_camera_control_signals (self);
903 priv->camera_state = CAMERA_STATE_ON;
907 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
908 EmpathyStreamedMediaWindow *self)
910 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
912 if (!gtk_toggle_tool_button_get_active (toggle))
914 if (priv->camera_state == CAMERA_STATE_ON)
916 /* We can't change the state by disabling the button */
917 block_camera_control_signals (self);
918 gtk_toggle_tool_button_set_active (toggle, TRUE);
919 unblock_camera_control_signals (self);
925 enable_camera (self);
929 action_camera_change_cb (GtkRadioAction *action,
930 GtkRadioAction *current,
931 EmpathyStreamedMediaWindow *self)
935 state = gtk_radio_action_get_current_value (current);
939 case CAMERA_STATE_OFF:
940 disable_camera (self);
943 case CAMERA_STATE_PREVIEW:
944 enable_preview (self);
947 case CAMERA_STATE_ON:
948 enable_camera (self);
952 g_assert_not_reached ();
957 create_pipeline (EmpathyStreamedMediaWindow *self)
959 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
962 g_assert (priv->pipeline == NULL);
964 priv->pipeline = gst_pipeline_new (NULL);
965 priv->pipeline_playing = FALSE;
967 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
968 priv->bus_message_source_id = gst_bus_add_watch (bus,
969 empathy_streamed_media_window_bus_message, self);
971 g_object_unref (bus);
976 empathy_streamed_media_window_init (EmpathyStreamedMediaWindow *self)
978 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
987 filename = empathy_file_lookup ("empathy-streamed-media-window.ui", "src");
988 gui = empathy_builder_get_file (filename,
989 "call_window_vbox", &top_vbox,
990 "errors_vbox", &priv->errors_vbox,
992 "statusbar", &priv->statusbar,
993 "redial", &priv->redial_button,
994 "microphone", &priv->mic_button,
995 "toolbar", &priv->toolbar,
996 "menuredial", &priv->redial,
997 "ui_manager", &priv->ui_manager,
998 "menufullscreen", &priv->menu_fullscreen,
999 "camera_off", &priv->tool_button_camera_off,
1000 "camera_preview", &priv->tool_button_camera_preview,
1001 "camera_on", &priv->tool_button_camera_on,
1002 "action_camera_on", &priv->action_camera_on,
1003 "details_vbox", &priv->details_vbox,
1004 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1005 "acodec_encoding_label", &priv->acodec_encoding_label,
1006 "acodec_decoding_label", &priv->acodec_decoding_label,
1007 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1008 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1009 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1010 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1011 "video_local_candidate_label", &priv->video_local_candidate_label,
1012 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1013 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1014 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1015 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1019 empathy_builder_connect (gui, self,
1020 "menuhangup", "activate", empathy_streamed_media_window_hangup_cb,
1021 "hangup", "clicked", empathy_streamed_media_window_hangup_cb,
1022 "menuredial", "activate", empathy_streamed_media_window_redial_cb,
1023 "redial", "clicked", empathy_streamed_media_window_redial_cb,
1024 "microphone", "toggled", empathy_streamed_media_window_mic_toggled_cb,
1025 "menufullscreen", "activate", empathy_streamed_media_window_fullscreen_cb,
1026 "camera_off", "toggled", tool_button_camera_off_toggled_cb,
1027 "camera_preview", "toggled", tool_button_camera_preview_toggled_cb,
1028 "camera_on", "toggled", tool_button_camera_on_toggled_cb,
1029 "action_camera_on", "changed", action_camera_change_cb,
1032 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1034 priv->lock = g_mutex_new ();
1036 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1038 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1039 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1040 CONTENT_HBOX_BORDER_WIDTH);
1041 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1043 /* remote user output frame */
1044 priv->remote_user_output_frame = gtk_frame_new (NULL);
1045 gtk_widget_set_size_request (priv->remote_user_output_frame,
1046 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1047 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1048 priv->remote_user_output_frame, TRUE, TRUE,
1049 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1051 priv->remote_user_output_hbox = gtk_hbox_new (FALSE, 0);
1053 priv->remote_user_avatar_widget = gtk_image_new ();
1055 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1056 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1058 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1059 priv->remote_user_output_hbox);
1061 /* self user output frame */
1062 priv->self_user_output_frame = gtk_frame_new (NULL);
1063 gtk_widget_set_size_request (priv->self_user_output_frame,
1064 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1066 priv->self_user_output_hbox = gtk_hbox_new (FALSE, 0);
1068 priv->self_user_avatar_widget = gtk_image_new ();
1069 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1070 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1072 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1073 priv->self_user_output_hbox);
1075 create_pipeline (self);
1076 create_video_output_widget (self);
1077 create_audio_input (self);
1078 create_video_input (self);
1080 priv->fsnotifier = fs_element_added_notifier_new ();
1081 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1083 /* The call will be started as soon the pipeline is playing */
1084 priv->start_call_when_playing = TRUE;
1086 priv->vbox = gtk_vbox_new (FALSE, 3);
1087 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1088 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1089 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1092 empathy_streamed_media_window_setup_toolbar (self);
1094 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1095 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1096 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1097 G_CALLBACK (empathy_streamed_media_window_sidebar_toggled_cb), self);
1099 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1101 h = gtk_hbox_new (FALSE, 3);
1102 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1103 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1105 priv->sidebar = ev_sidebar_new ();
1106 g_signal_connect (G_OBJECT (priv->sidebar),
1107 "hide", G_CALLBACK (empathy_streamed_media_window_sidebar_hidden_cb), self);
1108 g_signal_connect (G_OBJECT (priv->sidebar),
1109 "show", G_CALLBACK (empathy_streamed_media_window_sidebar_shown_cb), self);
1110 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1112 page = empathy_streamed_media_window_create_audio_input (self);
1113 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1114 _("Audio input"), page);
1116 page = empathy_streamed_media_window_create_video_input (self);
1117 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1118 _("Video input"), page);
1120 priv->dtmf_panel = empathy_dialpad_widget_new ();
1121 g_signal_connect (priv->dtmf_panel, "start-tone",
1122 G_CALLBACK (dtmf_start_tone_cb), self);
1123 g_signal_connect (priv->dtmf_panel, "stop-tone",
1124 G_CALLBACK (dtmf_stop_tone_cb), self);
1125 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1126 _("Dialpad"), priv->dtmf_panel);
1128 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1130 /* Put the details vbox in a scroll window as it can require a lot of
1131 * horizontal space. */
1132 scroll = gtk_scrolled_window_new (NULL, NULL);
1133 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1134 priv->details_vbox);
1136 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details",
1137 _("Details"), scroll);
1139 gtk_widget_show_all (top_vbox);
1141 gtk_widget_hide (priv->sidebar);
1143 priv->fullscreen = empathy_streamed_media_window_fullscreen_new (self);
1144 empathy_streamed_media_window_fullscreen_set_video_widget (priv->fullscreen,
1145 priv->video_output);
1146 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1147 "clicked", G_CALLBACK (empathy_streamed_media_window_fullscreen_cb), self);
1149 g_signal_connect (G_OBJECT (self), "realize",
1150 G_CALLBACK (empathy_streamed_media_window_realized_cb), self);
1152 g_signal_connect (G_OBJECT (self), "delete-event",
1153 G_CALLBACK (empathy_streamed_media_window_delete_cb), self);
1155 g_signal_connect (G_OBJECT (self), "window-state-event",
1156 G_CALLBACK (empathy_streamed_media_window_state_event_cb), self);
1158 g_signal_connect (G_OBJECT (self), "key-press-event",
1159 G_CALLBACK (empathy_streamed_media_window_key_press_cb), self);
1161 priv->timer = g_timer_new ();
1163 g_object_ref (priv->ui_manager);
1164 g_object_unref (gui);
1166 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1168 empathy_geometry_bind (GTK_WINDOW (self), "av-window");
1171 /* Instead of specifying a width and a height, we specify only one size. That's
1172 because we want a square avatar icon. */
1174 init_contact_avatar_with_size (EmpathyContact *contact,
1175 GtkWidget *image_widget,
1178 GdkPixbuf *pixbuf_avatar = NULL;
1180 if (contact != NULL)
1182 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1186 if (pixbuf_avatar == NULL)
1188 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1189 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1192 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1194 if (pixbuf_avatar != NULL)
1195 g_object_unref (pixbuf_avatar);
1199 set_window_title (EmpathyStreamedMediaWindow *self)
1201 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1204 /* translators: Call is a noun and %s is the contact name. This string
1205 * is used in the window title */
1206 tmp = g_strdup_printf (_("Call with %s"),
1207 empathy_contact_get_alias (priv->contact));
1208 gtk_window_set_title (GTK_WINDOW (self), tmp);
1213 contact_name_changed_cb (EmpathyContact *contact,
1214 GParamSpec *pspec, EmpathyStreamedMediaWindow *self)
1216 set_window_title (self);
1220 contact_avatar_changed_cb (EmpathyContact *contact,
1221 GParamSpec *pspec, GtkWidget *avatar_widget)
1224 GtkAllocation allocation;
1226 gtk_widget_get_allocation (avatar_widget, &allocation);
1227 size = allocation.height;
1231 /* the widget is not allocated yet, set a default size */
1232 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1233 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1236 init_contact_avatar_with_size (contact, avatar_widget, size);
1240 empathy_streamed_media_window_got_self_contact_cb (TpConnection *connection,
1241 EmpathyContact *contact, const GError *error, gpointer user_data,
1242 GObject *weak_object)
1244 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1245 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1247 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1248 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1250 g_signal_connect (contact, "notify::avatar",
1251 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1255 empathy_streamed_media_window_setup_avatars (EmpathyStreamedMediaWindow *self,
1256 EmpathyStreamedMediaHandler *handler)
1258 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1260 g_object_get (handler, "contact", &(priv->contact), NULL);
1262 if (priv->contact != NULL)
1264 TpConnection *connection;
1266 set_window_title (self);
1268 g_signal_connect (priv->contact, "notify::name",
1269 G_CALLBACK (contact_name_changed_cb), self);
1270 g_signal_connect (priv->contact, "notify::avatar",
1271 G_CALLBACK (contact_avatar_changed_cb),
1272 priv->remote_user_avatar_widget);
1274 /* Retreiving the self avatar */
1275 connection = empathy_contact_get_connection (priv->contact);
1276 empathy_tp_contact_factory_get_from_handle (connection,
1277 tp_connection_get_self_handle (connection),
1278 empathy_streamed_media_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1282 g_warning ("call handler doesn't have a contact");
1283 /* translators: Call is a noun. This string is used in the window
1285 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1287 /* Since we can't access the remote contact, we can't get a connection
1288 to it and can't get the self contact (and its avatar). This means
1289 that we have to manually set the self avatar. */
1290 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1291 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1294 init_contact_avatar_with_size (priv->contact,
1295 priv->remote_user_avatar_widget,
1296 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1297 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1299 /* The remote avatar is shown by default and will be hidden when we receive
1300 video from the remote side. */
1301 gtk_widget_hide (priv->video_output);
1302 gtk_widget_show (priv->remote_user_avatar_widget);
1306 update_send_codec (EmpathyStreamedMediaWindow *self,
1309 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1316 codec = empathy_streamed_media_handler_get_send_audio_codec (priv->handler);
1317 widget = priv->acodec_encoding_label;
1321 codec = empathy_streamed_media_handler_get_send_video_codec (priv->handler);
1322 widget = priv->vcodec_encoding_label;
1328 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1329 gtk_label_set_text (GTK_LABEL (widget), tmp);
1334 send_audio_codec_notify_cb (GObject *object,
1338 EmpathyStreamedMediaWindow *self = user_data;
1340 update_send_codec (self, TRUE);
1344 send_video_codec_notify_cb (GObject *object,
1348 EmpathyStreamedMediaWindow *self = user_data;
1350 update_send_codec (self, FALSE);
1354 update_recv_codec (EmpathyStreamedMediaWindow *self,
1357 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1360 GString *str = NULL;
1364 codecs = empathy_streamed_media_handler_get_recv_audio_codecs (priv->handler);
1365 widget = priv->acodec_decoding_label;
1369 codecs = empathy_streamed_media_handler_get_recv_video_codecs (priv->handler);
1370 widget = priv->vcodec_decoding_label;
1376 for (l = codecs; l != NULL; l = g_list_next (l))
1378 FsCodec *codec = l->data;
1381 str = g_string_new (NULL);
1383 g_string_append (str, ", ");
1385 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1389 gtk_label_set_text (GTK_LABEL (widget), str->str);
1390 g_string_free (str, TRUE);
1394 recv_audio_codecs_notify_cb (GObject *object,
1398 EmpathyStreamedMediaWindow *self = user_data;
1400 update_recv_codec (self, TRUE);
1404 recv_video_codecs_notify_cb (GObject *object,
1408 EmpathyStreamedMediaWindow *self = user_data;
1410 update_recv_codec (self, FALSE);
1413 static const gchar *
1414 candidate_type_to_str (FsCandidate *candidate)
1416 switch (candidate->type)
1418 case FS_CANDIDATE_TYPE_HOST:
1420 case FS_CANDIDATE_TYPE_SRFLX:
1421 return "server reflexive";
1422 case FS_CANDIDATE_TYPE_PRFLX:
1423 return "peer reflexive";
1424 case FS_CANDIDATE_TYPE_RELAY:
1426 case FS_CANDIDATE_TYPE_MULTICAST:
1433 static const gchar *
1434 candidate_type_to_desc (FsCandidate *candidate)
1436 switch (candidate->type)
1438 case FS_CANDIDATE_TYPE_HOST:
1439 return _("The IP address as seen by the machine");
1440 case FS_CANDIDATE_TYPE_SRFLX:
1441 return _("The IP address as seen by a server on the Internet");
1442 case FS_CANDIDATE_TYPE_PRFLX:
1443 return _("The IP address of the peer as seen by the other side");
1444 case FS_CANDIDATE_TYPE_RELAY:
1445 return _("The IP address of a relay server");
1446 case FS_CANDIDATE_TYPE_MULTICAST:
1447 return _("The IP address of the multicast group");
1454 update_candidat_widget (EmpathyStreamedMediaWindow *self,
1457 FsCandidate *candidate)
1461 g_assert (candidate != NULL);
1462 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1463 candidate->port, candidate_type_to_str (candidate));
1465 gtk_label_set_text (GTK_LABEL (label), str);
1466 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1472 candidates_changed_cb (GObject *object,
1474 EmpathyStreamedMediaWindow *self)
1476 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1477 FsCandidate *candidate = NULL;
1479 if (type == FS_MEDIA_TYPE_VIDEO)
1481 /* Update remote candidate */
1482 candidate = empathy_streamed_media_handler_get_video_remote_candidate (
1485 update_candidat_widget (self, priv->video_remote_candidate_label,
1486 priv->video_remote_candidate_info_img, candidate);
1488 /* Update local candidate */
1489 candidate = empathy_streamed_media_handler_get_video_local_candidate (
1492 update_candidat_widget (self, priv->video_local_candidate_label,
1493 priv->video_local_candidate_info_img, candidate);
1497 /* Update remote candidate */
1498 candidate = empathy_streamed_media_handler_get_audio_remote_candidate (
1501 update_candidat_widget (self, priv->audio_remote_candidate_label,
1502 priv->audio_remote_candidate_info_img, candidate);
1504 /* Update local candidate */
1505 candidate = empathy_streamed_media_handler_get_audio_local_candidate (
1508 update_candidat_widget (self, priv->audio_local_candidate_label,
1509 priv->audio_local_candidate_info_img, candidate);
1514 empathy_streamed_media_window_constructed (GObject *object)
1516 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1517 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1518 EmpathyTpStreamedMedia *call;
1520 g_assert (priv->handler != NULL);
1522 g_object_get (priv->handler, "tp-call", &call, NULL);
1523 priv->outgoing = (call == NULL);
1525 g_object_unref (call);
1527 empathy_streamed_media_window_setup_avatars (self, priv->handler);
1528 empathy_streamed_media_window_set_state_connecting (self);
1530 if (!empathy_streamed_media_handler_has_initial_video (priv->handler))
1532 gtk_toggle_tool_button_set_active (
1533 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1535 /* If call has InitialVideo, the preview will be started once the call has
1536 * been started (start_call()). */
1538 update_send_codec (self, TRUE);
1539 update_send_codec (self, FALSE);
1540 update_recv_codec (self, TRUE);
1541 update_recv_codec (self, FALSE);
1543 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1544 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1545 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1546 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1547 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1548 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1549 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1550 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1552 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1553 G_CALLBACK (candidates_changed_cb), self, 0);
1556 static void empathy_streamed_media_window_dispose (GObject *object);
1557 static void empathy_streamed_media_window_finalize (GObject *object);
1560 empathy_streamed_media_window_set_property (GObject *object,
1561 guint property_id, const GValue *value, GParamSpec *pspec)
1563 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1565 switch (property_id)
1567 case PROP_STREAMED_MEDIA_HANDLER:
1568 priv->handler = g_value_dup_object (value);
1571 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1576 empathy_streamed_media_window_get_property (GObject *object,
1577 guint property_id, GValue *value, GParamSpec *pspec)
1579 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1581 switch (property_id)
1583 case PROP_STREAMED_MEDIA_HANDLER:
1584 g_value_set_object (value, priv->handler);
1587 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1592 empathy_streamed_media_window_class_init (
1593 EmpathyStreamedMediaWindowClass *empathy_streamed_media_window_class)
1595 GObjectClass *object_class = G_OBJECT_CLASS (empathy_streamed_media_window_class);
1596 GParamSpec *param_spec;
1598 g_type_class_add_private (empathy_streamed_media_window_class,
1599 sizeof (EmpathyStreamedMediaWindowPriv));
1601 object_class->constructed = empathy_streamed_media_window_constructed;
1602 object_class->set_property = empathy_streamed_media_window_set_property;
1603 object_class->get_property = empathy_streamed_media_window_get_property;
1605 object_class->dispose = empathy_streamed_media_window_dispose;
1606 object_class->finalize = empathy_streamed_media_window_finalize;
1608 param_spec = g_param_spec_object ("handler",
1609 "handler", "The call handler",
1610 EMPATHY_TYPE_STREAMED_MEDIA_HANDLER,
1611 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1612 g_object_class_install_property (object_class,
1613 PROP_STREAMED_MEDIA_HANDLER, param_spec);
1617 empathy_streamed_media_window_video_stream_changed_cb (EmpathyTpStreamedMedia *call,
1618 GParamSpec *property, EmpathyStreamedMediaWindow *self)
1620 DEBUG ("video stream changed");
1621 empathy_streamed_media_window_update_avatars_visibility (call, self);
1625 empathy_streamed_media_window_dispose (GObject *object)
1627 EmpathyTpStreamedMedia *call;
1628 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1629 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1631 if (priv->dispose_has_run)
1634 priv->dispose_has_run = TRUE;
1636 g_object_get (priv->handler, "tp-call", &call, NULL);
1640 g_object_unref (call);
1643 if (priv->handler != NULL)
1645 empathy_streamed_media_handler_stop_call (priv->handler);
1646 g_object_unref (priv->handler);
1648 priv->handler = NULL;
1650 if (priv->bus_message_source_id != 0)
1652 g_source_remove (priv->bus_message_source_id);
1653 priv->bus_message_source_id = 0;
1656 if (priv->pipeline != NULL)
1657 g_object_unref (priv->pipeline);
1658 priv->pipeline = NULL;
1660 if (priv->video_input != NULL)
1661 g_object_unref (priv->video_input);
1662 priv->video_input = NULL;
1664 if (priv->audio_input != NULL)
1665 g_object_unref (priv->audio_input);
1666 priv->audio_input = NULL;
1668 if (priv->video_tee != NULL)
1669 g_object_unref (priv->video_tee);
1670 priv->video_tee = NULL;
1672 if (priv->fsnotifier != NULL)
1673 g_object_unref (priv->fsnotifier);
1674 priv->fsnotifier = NULL;
1676 if (priv->timer_id != 0)
1677 g_source_remove (priv->timer_id);
1680 if (priv->ui_manager != NULL)
1681 g_object_unref (priv->ui_manager);
1682 priv->ui_manager = NULL;
1684 if (priv->fullscreen != NULL)
1685 g_object_unref (priv->fullscreen);
1686 priv->fullscreen = NULL;
1688 if (priv->contact != NULL)
1690 g_signal_handlers_disconnect_by_func (priv->contact,
1691 contact_name_changed_cb, self);
1692 g_object_unref (priv->contact);
1693 priv->contact = NULL;
1696 tp_clear_object (&priv->sound_mgr);
1698 /* release any references held by the object here */
1699 if (G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose)
1700 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose (object);
1704 disconnect_video_output_motion_handler (EmpathyStreamedMediaWindow *self)
1706 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1708 if (priv->video_output_motion_handler_id != 0)
1710 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1711 priv->video_output_motion_handler_id);
1712 priv->video_output_motion_handler_id = 0;
1717 empathy_streamed_media_window_finalize (GObject *object)
1719 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1720 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1722 disconnect_video_output_motion_handler (self);
1724 /* free any data held directly by the object here */
1725 g_mutex_free (priv->lock);
1727 g_timer_destroy (priv->timer);
1729 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->finalize (object);
1733 EmpathyStreamedMediaWindow *
1734 empathy_streamed_media_window_new (EmpathyStreamedMediaHandler *handler)
1736 return EMPATHY_STREAMED_MEDIA_WINDOW (
1737 g_object_new (EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, "handler", handler, NULL));
1741 empathy_streamed_media_window_conference_added_cb (EmpathyStreamedMediaHandler *handler,
1742 GstElement *conference, gpointer user_data)
1744 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1745 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1748 keyfile = fs_utils_get_default_element_properties (conference);
1749 if (keyfile != NULL)
1750 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1753 gst_bin_add (GST_BIN (priv->pipeline), conference);
1755 gst_element_set_state (conference, GST_STATE_PLAYING);
1759 empathy_streamed_media_window_request_resource_cb (EmpathyStreamedMediaHandler *handler,
1760 FsMediaType type, FsStreamDirection direction, gpointer user_data)
1762 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1763 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1765 if (type != FS_MEDIA_TYPE_VIDEO)
1768 if (direction == FS_DIRECTION_RECV)
1771 /* video and direction is send */
1772 return priv->video_input != NULL;
1776 empathy_streamed_media_window_reset_pipeline (EmpathyStreamedMediaWindow *self)
1778 GstStateChangeReturn state_change_return;
1779 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1781 if (priv->pipeline == NULL)
1784 if (priv->bus_message_source_id != 0)
1786 g_source_remove (priv->bus_message_source_id);
1787 priv->bus_message_source_id = 0;
1790 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1792 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1793 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1795 if (priv->pipeline != NULL)
1796 g_object_unref (priv->pipeline);
1797 priv->pipeline = NULL;
1799 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1800 empathy_streamed_media_window_mic_volume_changed_cb, self);
1802 if (priv->video_tee != NULL)
1803 g_object_unref (priv->video_tee);
1804 priv->video_tee = NULL;
1806 if (priv->video_preview != NULL)
1807 gtk_widget_destroy (priv->video_preview);
1808 priv->video_preview = NULL;
1810 priv->funnel = NULL;
1812 create_pipeline (self);
1813 /* Call will be started when user will hit the 'redial' button */
1814 priv->start_call_when_playing = FALSE;
1815 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1821 g_message ("Error: could not destroy pipeline. Closing call window");
1822 gtk_widget_destroy (GTK_WIDGET (self));
1829 reset_details_pane (EmpathyStreamedMediaWindow *self)
1831 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1833 /* translators: encoding video codec is unknown */
1834 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label),
1835 C_("codec", "Unknown"));
1836 /* translators: encoding audio codec is unknown */
1837 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label),
1838 C_("codec", "Unknown"));
1839 /* translators: decoding video codec is unknown */
1840 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label),
1841 C_("codec", "Unknown"));
1842 /* translators: decoding audio codec is unknown */
1843 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label),
1844 C_("codec", "Unknown"));
1848 empathy_streamed_media_window_disconnected (EmpathyStreamedMediaWindow *self,
1851 gboolean could_disconnect = FALSE;
1852 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1853 gboolean could_reset_pipeline;
1855 /* Leave full screen mode if needed */
1856 gtk_window_unfullscreen (GTK_WINDOW (self));
1858 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1860 could_reset_pipeline = empathy_streamed_media_window_reset_pipeline (self);
1862 if (priv->call_state == CONNECTING)
1863 empathy_sound_manager_stop (priv->sound_mgr,
1864 EMPATHY_SOUND_PHONE_OUTGOING);
1866 if (priv->call_state != REDIALING)
1867 priv->call_state = DISCONNECTED;
1869 if (could_reset_pipeline)
1871 g_mutex_lock (priv->lock);
1873 g_timer_stop (priv->timer);
1875 if (priv->timer_id != 0)
1876 g_source_remove (priv->timer_id);
1879 g_mutex_unlock (priv->lock);
1882 /* We are about to destroy the window, no need to update it or create
1883 * a video preview */
1886 empathy_streamed_media_window_status_message (self, _("Disconnected"));
1888 gtk_action_set_sensitive (priv->redial, TRUE);
1889 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1891 /* Unsensitive the camera and mic button */
1892 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1893 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
1894 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1896 /* Be sure that the mic button is enabled */
1897 gtk_toggle_tool_button_set_active (
1898 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1900 if (priv->camera_state == CAMERA_STATE_ON)
1902 /* Enable the 'preview' button as we are not sending atm. */
1903 gtk_toggle_tool_button_set_active (
1904 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1906 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1908 /* Restart the preview with the new pipeline. */
1909 display_video_preview (self, TRUE);
1912 gtk_progress_bar_set_fraction (
1913 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1915 /* destroy the video output; it will be recreated when we'll redial */
1916 disconnect_video_output_motion_handler (self);
1917 gtk_widget_destroy (priv->video_output);
1918 priv->video_output = NULL;
1920 gtk_widget_show (priv->remote_user_avatar_widget);
1922 reset_details_pane (self);
1924 priv->sending_video = FALSE;
1925 priv->call_started = FALSE;
1927 could_disconnect = TRUE;
1929 /* TODO: display the self avatar of the preview (depends if the "Always
1930 * Show Video Preview" is enabled or not) */
1933 return could_disconnect;
1938 empathy_streamed_media_window_channel_closed_cb (EmpathyStreamedMediaHandler *handler,
1941 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1942 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1944 if (empathy_streamed_media_window_disconnected (self, TRUE) &&
1945 priv->call_state == REDIALING)
1946 empathy_streamed_media_window_restart_call (self);
1951 empathy_streamed_media_window_channel_stream_closed_cb (EmpathyStreamedMediaHandler *handler,
1952 TfStream *stream, gpointer user_data)
1954 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1955 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1958 g_object_get (stream, "media-type", &media_type, NULL);
1961 * This assumes that there is only one video stream per channel...
1964 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1966 if (priv->funnel != NULL)
1970 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1971 (priv->video_output));
1973 gst_element_set_state (output, GST_STATE_NULL);
1974 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1976 gst_bin_remove (GST_BIN (priv->pipeline), output);
1977 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1978 priv->funnel = NULL;
1981 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1983 if (priv->audio_output != NULL)
1985 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1987 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1988 priv->audio_output = NULL;
1993 /* Called with global lock held */
1995 empathy_streamed_media_window_get_video_sink_pad (EmpathyStreamedMediaWindow *self)
1997 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2001 if (priv->funnel == NULL)
2003 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
2004 (priv->video_output));
2006 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2010 g_warning ("Could not create fsfunnel");
2014 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2016 gst_object_unref (priv->funnel);
2017 priv->funnel = NULL;
2018 g_warning ("Could not add funnel to pipeline");
2022 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2024 g_warning ("Could not add the video output widget to the pipeline");
2028 if (!gst_element_link (priv->funnel, output))
2030 g_warning ("Could not link output sink to funnel");
2031 goto error_output_added;
2034 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2036 g_warning ("Could not start video sink");
2037 goto error_output_added;
2040 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2042 g_warning ("Could not start funnel");
2043 goto error_output_added;
2047 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2050 g_warning ("Could not get request pad from funnel");
2057 gst_element_set_locked_state (priv->funnel, TRUE);
2058 gst_element_set_locked_state (output, TRUE);
2060 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2061 gst_element_set_state (output, GST_STATE_NULL);
2063 gst_bin_remove (GST_BIN (priv->pipeline), output);
2064 gst_element_set_locked_state (output, FALSE);
2068 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2069 priv->funnel = NULL;
2074 /* Called with global lock held */
2076 empathy_streamed_media_window_get_audio_sink_pad (EmpathyStreamedMediaWindow *self)
2078 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2080 GstPadTemplate *template;
2082 if (priv->audio_output == NULL)
2084 priv->audio_output = empathy_audio_sink_new ();
2086 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2088 g_warning ("Could not add audio sink to pipeline");
2089 g_object_unref (priv->audio_output);
2090 goto error_add_output;
2093 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2095 g_warning ("Could not start audio sink");
2100 template = gst_element_class_get_pad_template (
2101 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2103 pad = gst_element_request_pad (priv->audio_output,
2104 template, NULL, NULL);
2108 g_warning ("Could not get sink pad from sink");
2115 gst_element_set_locked_state (priv->audio_output, TRUE);
2116 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2117 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2118 priv->audio_output = NULL;
2126 empathy_streamed_media_window_update_timer (gpointer user_data)
2128 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2129 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2133 time_ = g_timer_elapsed (priv->timer, NULL);
2135 /* Translators: number of minutes:seconds the caller has been connected */
2136 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
2138 empathy_streamed_media_window_status_message (self, str);
2145 display_error (EmpathyStreamedMediaWindow *self,
2146 EmpathyTpStreamedMedia *call,
2150 const gchar *details)
2152 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2153 GtkWidget *info_bar;
2154 GtkWidget *content_area;
2161 /* Create info bar */
2162 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2165 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2167 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2169 /* hbox containing the image and the messages vbox */
2170 hbox = gtk_hbox_new (FALSE, 3);
2171 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2174 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2175 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2177 /* vbox containing the main message and the details expander */
2178 vbox = gtk_vbox_new (FALSE, 3);
2179 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2182 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2184 label = gtk_label_new (NULL);
2185 gtk_label_set_markup (GTK_LABEL (label), txt);
2186 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2187 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2190 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2193 if (details != NULL)
2195 GtkWidget *expander;
2197 expander = gtk_expander_new (_("Technical Details"));
2199 txt = g_strdup_printf ("<i>%s</i>", details);
2201 label = gtk_label_new (NULL);
2202 gtk_label_set_markup (GTK_LABEL (label), txt);
2203 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2204 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2207 gtk_container_add (GTK_CONTAINER (expander), label);
2208 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2211 g_signal_connect (info_bar, "response",
2212 G_CALLBACK (gtk_widget_destroy), NULL);
2214 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2215 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2216 gtk_widget_show_all (info_bar);
2220 media_stream_error_to_txt (EmpathyStreamedMediaWindow *self,
2221 EmpathyTpStreamedMedia *call,
2223 TpMediaStreamError error)
2225 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2232 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2234 return g_strdup_printf (
2235 _("%s's software does not understand any of the audio formats "
2236 "supported by your computer"),
2237 empathy_contact_get_alias (priv->contact));
2239 return g_strdup_printf (
2240 _("%s's software does not understand any of the video formats "
2241 "supported by your computer"),
2242 empathy_contact_get_alias (priv->contact));
2244 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2245 return g_strdup_printf (
2246 _("Can't establish a connection to %s. "
2247 "One of you might be on a network that does not allow "
2248 "direct connections."),
2249 empathy_contact_get_alias (priv->contact));
2251 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2252 return g_strdup (_("There was a failure on the network"));
2254 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2256 return g_strdup (_("The audio formats necessary for this call "
2257 "are not installed on your computer"));
2259 return g_strdup (_("The video formats necessary for this call "
2260 "are not installed on your computer"));
2262 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2263 cm = empathy_tp_streamed_media_get_connection_manager (call);
2265 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2266 "product=Telepathy&component=%s", cm);
2268 result = g_strdup_printf (
2269 _("Something unexpected happened in a Telepathy component. "
2270 "Please <a href=\"%s\">report this bug</a> and attach "
2271 "logs gathered from the 'Debug' window in the Help menu."), url);
2276 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2277 return g_strdup (_("There was a failure in the call engine"));
2279 case TP_MEDIA_STREAM_ERROR_EOS:
2280 return g_strdup (_("The end of the stream was reached"));
2282 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2289 empathy_streamed_media_window_stream_error (EmpathyStreamedMediaWindow *self,
2290 EmpathyTpStreamedMedia *call,
2299 desc = media_stream_error_to_txt (self, call, audio, code);
2302 /* No description, use the error message. That's not great as it's not
2303 * localized but it's better than nothing. */
2304 display_error (self, call, icon, title, msg, NULL);
2308 display_error (self, call, icon, title, desc, msg);
2314 empathy_streamed_media_window_audio_stream_error (EmpathyTpStreamedMedia *call,
2317 EmpathyStreamedMediaWindow *self)
2319 empathy_streamed_media_window_stream_error (self, call, TRUE, code, msg,
2320 "gnome-stock-mic", _("Can't establish audio stream"));
2324 empathy_streamed_media_window_video_stream_error (EmpathyTpStreamedMedia *call,
2327 EmpathyStreamedMediaWindow *self)
2329 empathy_streamed_media_window_stream_error (self, call, FALSE, code, msg,
2330 "camera-web", _("Can't establish video stream"));
2334 empathy_streamed_media_window_connected (gpointer user_data)
2336 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2337 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2338 EmpathyTpStreamedMedia *call;
2339 gboolean can_send_video;
2341 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2343 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2344 empathy_contact_can_voip_video (priv->contact);
2346 g_object_get (priv->handler, "tp-call", &call, NULL);
2348 tp_g_signal_connect_object (call, "notify::video-stream",
2349 G_CALLBACK (empathy_streamed_media_window_video_stream_changed_cb),
2352 if (empathy_tp_streamed_media_has_dtmf (call))
2353 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2355 if (priv->video_input == NULL)
2356 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
2358 priv->sending_video = can_send_video ?
2359 empathy_tp_streamed_media_is_sending_video (call) : FALSE;
2361 gtk_toggle_tool_button_set_active (
2362 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2363 priv->sending_video && priv->video_input != NULL);
2364 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2365 gtk_action_set_sensitive (priv->action_camera_on, can_send_video);
2367 gtk_action_set_sensitive (priv->redial, FALSE);
2368 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2370 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2372 empathy_streamed_media_window_update_avatars_visibility (call, self);
2374 g_object_unref (call);
2376 g_mutex_lock (priv->lock);
2378 priv->timer_id = g_timeout_add_seconds (1,
2379 empathy_streamed_media_window_update_timer, self);
2381 g_mutex_unlock (priv->lock);
2383 empathy_streamed_media_window_update_timer (self);
2385 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2391 /* Called from the streaming thread */
2393 empathy_streamed_media_window_src_added_cb (EmpathyStreamedMediaHandler *handler,
2394 GstPad *src, guint media_type, gpointer user_data)
2396 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2397 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2398 gboolean retval = FALSE;
2402 g_mutex_lock (priv->lock);
2404 if (priv->call_state != CONNECTED)
2406 g_timer_start (priv->timer);
2407 priv->timer_id = g_idle_add (empathy_streamed_media_window_connected, self);
2408 priv->call_state = CONNECTED;
2413 case TP_MEDIA_STREAM_TYPE_AUDIO:
2414 pad = empathy_streamed_media_window_get_audio_sink_pad (self);
2416 case TP_MEDIA_STREAM_TYPE_VIDEO:
2417 gtk_widget_hide (priv->remote_user_avatar_widget);
2418 gtk_widget_show (priv->video_output);
2419 pad = empathy_streamed_media_window_get_video_sink_pad (self);
2422 g_assert_not_reached ();
2428 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2429 g_warning ("Could not link %s sink pad",
2430 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2434 gst_object_unref (pad);
2438 /* If no sink could be linked, try to add fakesink to prevent the whole call
2443 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2445 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2447 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2448 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2449 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2451 gst_element_set_locked_state (fakesink, TRUE);
2452 gst_element_set_state (fakesink, GST_STATE_NULL);
2453 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2457 DEBUG ("Could not link real sink, linked fakesink instead");
2459 gst_object_unref (sinkpad);
2463 gst_object_unref (fakesink);
2468 g_mutex_unlock (priv->lock);
2474 empathy_streamed_media_window_sink_added_cb (EmpathyStreamedMediaHandler *handler,
2475 GstPad *sink, guint media_type, gpointer user_data)
2477 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2478 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2480 gboolean retval = FALSE;
2484 case TP_MEDIA_STREAM_TYPE_AUDIO:
2485 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2487 g_warning ("Could not add audio source to pipeline");
2491 pad = gst_element_get_static_pad (priv->audio_input, "src");
2494 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2495 g_warning ("Could not get source pad from audio source");
2499 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2501 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2502 g_warning ("Could not link audio source to farsight");
2506 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2508 g_warning ("Could not start audio source");
2509 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2510 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2516 case TP_MEDIA_STREAM_TYPE_VIDEO:
2517 if (priv->video_input != NULL)
2519 if (priv->video_tee != NULL)
2521 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2522 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2524 g_warning ("Could not link videp soure input pipeline");
2527 gst_object_unref (pad);
2534 g_assert_not_reached ();
2541 empathy_streamed_media_window_remove_video_input (EmpathyStreamedMediaWindow *self)
2543 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2544 GstElement *preview;
2546 disable_camera (self);
2548 DEBUG ("remove video input");
2549 preview = empathy_video_widget_get_element (
2550 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2552 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2553 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2554 gst_element_set_state (preview, GST_STATE_NULL);
2556 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2557 priv->video_tee, preview, NULL);
2559 g_object_unref (priv->video_input);
2560 priv->video_input = NULL;
2561 g_object_unref (priv->video_tee);
2562 priv->video_tee = NULL;
2563 gtk_widget_destroy (priv->video_preview);
2564 priv->video_preview = NULL;
2566 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2567 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
2568 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2572 start_call (EmpathyStreamedMediaWindow *self)
2574 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2576 priv->call_started = TRUE;
2577 empathy_streamed_media_handler_start_call (priv->handler,
2578 empathy_get_current_action_time ());
2580 if (empathy_streamed_media_handler_has_initial_video (priv->handler))
2582 /* Enable 'send video' buttons and display the preview */
2583 gtk_toggle_tool_button_set_active (
2584 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2589 empathy_streamed_media_window_bus_message (GstBus *bus, GstMessage *message,
2592 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2593 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2596 empathy_streamed_media_handler_bus_message (priv->handler, bus, message);
2598 switch (GST_MESSAGE_TYPE (message))
2600 case GST_MESSAGE_STATE_CHANGED:
2601 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2603 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2604 if (newstate == GST_STATE_PAUSED)
2605 empathy_streamed_media_window_setup_video_input (self);
2607 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2608 !priv->call_started)
2610 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2611 if (newstate == GST_STATE_PAUSED)
2613 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2614 priv->pipeline_playing = TRUE;
2616 if (priv->start_call_when_playing)
2621 case GST_MESSAGE_ERROR:
2623 GError *error = NULL;
2624 GstElement *gst_error;
2627 gst_message_parse_error (message, &error, &debug);
2628 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2630 g_message ("Element error: %s -- %s\n", error->message, debug);
2632 if (g_str_has_prefix (gst_element_get_name (gst_error),
2633 VIDEO_INPUT_ERROR_PREFIX))
2635 /* Remove the video input and continue */
2636 if (priv->video_input != NULL)
2637 empathy_streamed_media_window_remove_video_input (self);
2638 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2642 empathy_streamed_media_window_disconnected (self, TRUE);
2644 g_error_free (error);
2647 case GST_MESSAGE_UNKNOWN:
2648 case GST_MESSAGE_EOS:
2649 case GST_MESSAGE_WARNING:
2650 case GST_MESSAGE_INFO:
2651 case GST_MESSAGE_TAG:
2652 case GST_MESSAGE_BUFFERING:
2653 case GST_MESSAGE_STATE_DIRTY:
2654 case GST_MESSAGE_STEP_DONE:
2655 case GST_MESSAGE_CLOCK_PROVIDE:
2656 case GST_MESSAGE_CLOCK_LOST:
2657 case GST_MESSAGE_NEW_CLOCK:
2658 case GST_MESSAGE_STRUCTURE_CHANGE:
2659 case GST_MESSAGE_STREAM_STATUS:
2660 case GST_MESSAGE_APPLICATION:
2661 case GST_MESSAGE_ELEMENT:
2662 case GST_MESSAGE_SEGMENT_START:
2663 case GST_MESSAGE_SEGMENT_DONE:
2664 case GST_MESSAGE_DURATION:
2665 case GST_MESSAGE_ANY:
2674 empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
2675 EmpathyStreamedMediaWindow *window)
2677 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2679 if (empathy_tp_streamed_media_is_receiving_video (call))
2681 gtk_widget_hide (priv->remote_user_avatar_widget);
2682 gtk_widget_show (priv->video_output);
2686 gtk_widget_hide (priv->video_output);
2687 gtk_widget_show (priv->remote_user_avatar_widget);
2692 call_handler_notify_tp_streamed_media_cb (EmpathyStreamedMediaHandler *handler,
2694 EmpathyStreamedMediaWindow *self)
2696 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2697 EmpathyTpStreamedMedia *call;
2699 g_object_get (priv->handler, "tp-call", &call, NULL);
2703 tp_g_signal_connect_object (call, "audio-stream-error",
2704 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), self, 0);
2705 tp_g_signal_connect_object (call, "video-stream-error",
2706 G_CALLBACK (empathy_streamed_media_window_video_stream_error), self, 0);
2708 g_object_unref (call);
2712 empathy_streamed_media_window_realized_cb (GtkWidget *widget, EmpathyStreamedMediaWindow *window)
2714 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2715 EmpathyTpStreamedMedia *call;
2717 g_signal_connect (priv->handler, "conference-added",
2718 G_CALLBACK (empathy_streamed_media_window_conference_added_cb), window);
2719 g_signal_connect (priv->handler, "request-resource",
2720 G_CALLBACK (empathy_streamed_media_window_request_resource_cb), window);
2721 g_signal_connect (priv->handler, "closed",
2722 G_CALLBACK (empathy_streamed_media_window_channel_closed_cb), window);
2723 g_signal_connect (priv->handler, "src-pad-added",
2724 G_CALLBACK (empathy_streamed_media_window_src_added_cb), window);
2725 g_signal_connect (priv->handler, "sink-pad-added",
2726 G_CALLBACK (empathy_streamed_media_window_sink_added_cb), window);
2727 g_signal_connect (priv->handler, "stream-closed",
2728 G_CALLBACK (empathy_streamed_media_window_channel_stream_closed_cb), window);
2730 g_object_get (priv->handler, "tp-call", &call, NULL);
2733 tp_g_signal_connect_object (call, "audio-stream-error",
2734 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), window,
2736 tp_g_signal_connect_object (call, "video-stream-error",
2737 G_CALLBACK (empathy_streamed_media_window_video_stream_error), window,
2740 g_object_unref (call);
2744 /* tp-call doesn't exist yet, we'll connect signals once it has been
2746 g_signal_connect (priv->handler, "notify::tp-call",
2747 G_CALLBACK (call_handler_notify_tp_streamed_media_cb), window);
2750 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2754 empathy_streamed_media_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2755 EmpathyStreamedMediaWindow *window)
2757 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2759 if (priv->pipeline != NULL)
2761 if (priv->bus_message_source_id != 0)
2763 g_source_remove (priv->bus_message_source_id);
2764 priv->bus_message_source_id = 0;
2767 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2770 if (priv->call_state == CONNECTING)
2771 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2777 show_controls (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2780 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2782 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2787 gtk_widget_hide (priv->sidebar);
2788 gtk_widget_hide (menu);
2789 gtk_widget_hide (priv->vbox);
2790 gtk_widget_hide (priv->statusbar);
2791 gtk_widget_hide (priv->toolbar);
2795 if (priv->sidebar_was_visible_before_fs)
2796 gtk_widget_show (priv->sidebar);
2798 gtk_widget_show (menu);
2799 gtk_widget_show (priv->vbox);
2800 gtk_widget_show (priv->statusbar);
2801 gtk_widget_show (priv->toolbar);
2803 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2804 priv->original_height_before_fs);
2809 show_borders (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2811 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2813 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2814 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2815 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2816 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2818 if (priv->video_output != NULL)
2820 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2821 priv->video_output, TRUE, TRUE,
2822 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2826 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2827 priv->vbox, TRUE, TRUE,
2828 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2833 empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
2834 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window)
2836 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2838 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2839 gboolean set_fullscreen = event->new_window_state &
2840 GDK_WINDOW_STATE_FULLSCREEN;
2844 gboolean sidebar_was_visible;
2845 GtkAllocation allocation;
2846 gint original_width, original_height;
2848 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2849 original_width = allocation.width;
2850 original_height = allocation.height;
2852 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2854 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2855 priv->original_width_before_fs = original_width;
2856 priv->original_height_before_fs = original_height;
2858 if (priv->video_output_motion_handler_id == 0 &&
2859 priv->video_output != NULL)
2861 priv->video_output_motion_handler_id = g_signal_connect (
2862 G_OBJECT (priv->video_output), "motion-notify-event",
2863 G_CALLBACK (empathy_streamed_media_window_video_output_motion_notify),
2869 disconnect_video_output_motion_handler (window);
2872 empathy_streamed_media_window_fullscreen_set_fullscreen (priv->fullscreen,
2874 show_controls (window, set_fullscreen);
2875 show_borders (window, set_fullscreen);
2876 gtk_action_set_stock_id (priv->menu_fullscreen,
2877 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2878 priv->is_fullscreen = set_fullscreen;
2885 empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2886 EmpathyStreamedMediaWindow *window)
2888 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2890 int w, h, handle_size;
2891 GtkAllocation allocation, sidebar_allocation;
2893 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2894 w = allocation.width;
2895 h = allocation.height;
2897 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2899 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2900 if (gtk_toggle_button_get_active (toggle))
2902 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2903 gtk_widget_show (priv->sidebar);
2904 w += sidebar_allocation.width + handle_size;
2908 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2909 w -= sidebar_allocation.width + handle_size;
2910 gtk_widget_hide (priv->sidebar);
2913 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2916 gtk_window_resize (GTK_WINDOW (window), w, h);
2920 empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
2923 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2924 EmpathyTpStreamedMedia *call;
2926 priv->sending_video = (state == CAMERA_STATE_ON);
2928 if (state == CAMERA_STATE_PREVIEW ||
2929 state == CAMERA_STATE_ON)
2931 /* When we start sending video, we want to show the video preview by
2933 display_video_preview (window, TRUE);
2937 display_video_preview (window, FALSE);
2940 if (priv->call_state != CONNECTED)
2943 g_object_get (priv->handler, "tp-call", &call, NULL);
2944 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2945 empathy_tp_streamed_media_request_video_stream_direction (call, priv->sending_video);
2946 g_object_unref (call);
2950 empathy_streamed_media_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2951 EmpathyStreamedMediaWindow *window)
2953 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2956 active = (gtk_toggle_tool_button_get_active (toggle));
2960 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2962 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2966 /* TODO, Instead of setting the input volume to 0 we should probably
2967 * stop sending but this would cause the audio call to drop if both
2968 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2969 * in the future. GNOME #574574
2971 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2973 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2978 empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
2979 EmpathyStreamedMediaWindow *window)
2981 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2983 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2988 empathy_streamed_media_window_sidebar_shown_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_hangup_cb (gpointer object,
2999 EmpathyStreamedMediaWindow *window)
3001 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3003 empathy_streamed_media_handler_stop_call (priv->handler);
3005 if (empathy_streamed_media_window_disconnected (window, FALSE))
3006 gtk_widget_destroy (GTK_WIDGET (window));
3010 empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window)
3012 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3014 /* Remove error info bars */
3015 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3016 (GtkCallback) gtk_widget_destroy, NULL);
3018 create_video_output_widget (window);
3020 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3021 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), window);
3023 /* While the call was disconnected, the input volume might have changed.
3024 * However, since the audio_input source was destroyed, its volume has not
3025 * been updated during that time. That's why we manually update it here */
3026 empathy_streamed_media_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3028 priv->outgoing = TRUE;
3029 empathy_streamed_media_window_set_state_connecting (window);
3031 if (priv->pipeline_playing)
3032 start_call (window);
3034 /* call will be started when the pipeline is ready */
3035 priv->start_call_when_playing = TRUE;
3038 empathy_streamed_media_window_setup_avatars (window, priv->handler);
3040 gtk_action_set_sensitive (priv->redial, FALSE);
3041 gtk_widget_set_sensitive (priv->redial_button, FALSE);
3045 empathy_streamed_media_window_redial_cb (gpointer object,
3046 EmpathyStreamedMediaWindow *window)
3048 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3050 if (priv->call_state == CONNECTED)
3051 priv->call_state = REDIALING;
3053 empathy_streamed_media_handler_stop_call (priv->handler);
3055 if (priv->call_state != CONNECTED)
3056 empathy_streamed_media_window_restart_call (window);
3060 empathy_streamed_media_window_fullscreen_cb (gpointer object,
3061 EmpathyStreamedMediaWindow *window)
3063 empathy_streamed_media_window_fullscreen_toggle (window);
3067 empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window)
3069 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3071 if (priv->is_fullscreen)
3072 gtk_window_unfullscreen (GTK_WINDOW (window));
3074 gtk_window_fullscreen (GTK_WINDOW (window));
3078 empathy_streamed_media_window_video_button_press_cb (GtkWidget *video_output,
3079 GdkEventButton *event, EmpathyStreamedMediaWindow *window)
3081 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3083 empathy_streamed_media_window_video_menu_popup (window, event->button);
3091 empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
3092 GdkEventKey *event, EmpathyStreamedMediaWindow *window)
3094 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3096 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3098 /* Since we are in fullscreen mode, toggling will bring us back to
3100 empathy_streamed_media_window_fullscreen_toggle (window);
3108 empathy_streamed_media_window_video_output_motion_notify (GtkWidget *widget,
3109 GdkEventMotion *event, EmpathyStreamedMediaWindow *window)
3111 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3113 if (priv->is_fullscreen)
3115 empathy_streamed_media_window_fullscreen_show_popup (priv->fullscreen);
3122 empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
3126 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3128 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3130 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3131 button, gtk_get_current_event_time ());
3132 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3136 empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
3139 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3141 if (priv->context_id == 0)
3143 priv->context_id = gtk_statusbar_get_context_id (
3144 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
3148 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
3151 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
3156 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
3157 gdouble value, EmpathyStreamedMediaWindow *window)
3159 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3161 if (priv->audio_output == NULL)
3164 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3168 /* block all the signals related to camera control widgets. This is useful
3169 * when we are manually updating the UI and so don't want to fire the
3172 block_camera_control_signals (EmpathyStreamedMediaWindow *self)
3174 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3176 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
3177 tool_button_camera_off_toggled_cb, self);
3178 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
3179 tool_button_camera_preview_toggled_cb, self);
3180 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
3181 tool_button_camera_on_toggled_cb, self);
3182 g_signal_handlers_block_by_func (priv->action_camera_on,
3183 action_camera_change_cb, self);
3187 unblock_camera_control_signals (EmpathyStreamedMediaWindow *self)
3189 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3191 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
3192 tool_button_camera_off_toggled_cb, self);
3193 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
3194 tool_button_camera_preview_toggled_cb, self);
3195 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
3196 tool_button_camera_on_toggled_cb, self);
3197 g_signal_handlers_unblock_by_func (priv->action_camera_on,
3198 action_camera_change_cb, self);