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>
35 #include <telepathy-farstream/telepathy-farstream.h>
37 #include <farstream/fs-element-added-notifier.h>
38 #include <farstream/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_box_new (GTK_ORIENTATION_VERTICAL, 2);
375 GtkWidget *scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL, 0,
377 GtkWidget *label = gtk_label_new (label_text);
379 gtk_widget_set_sensitive (scale, FALSE);
381 gtk_container_add (GTK_CONTAINER (bin), vbox);
383 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
384 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
385 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
391 empathy_streamed_media_window_video_contrast_changed_cb (GtkAdjustment *adj,
392 EmpathyStreamedMediaWindow *self)
395 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
397 empathy_video_src_set_channel (priv->video_input,
398 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
402 empathy_streamed_media_window_video_brightness_changed_cb (GtkAdjustment *adj,
403 EmpathyStreamedMediaWindow *self)
406 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
408 empathy_video_src_set_channel (priv->video_input,
409 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
413 empathy_streamed_media_window_video_gamma_changed_cb (GtkAdjustment *adj,
414 EmpathyStreamedMediaWindow *self)
417 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
419 empathy_video_src_set_channel (priv->video_input,
420 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
425 empathy_streamed_media_window_create_video_input (EmpathyStreamedMediaWindow *self)
427 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
430 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
431 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
433 priv->video_contrast = empathy_streamed_media_window_create_video_input_add_slider (
434 self, _("Contrast"), hbox);
436 priv->video_brightness = empathy_streamed_media_window_create_video_input_add_slider (
437 self, _("Brightness"), hbox);
439 priv->video_gamma = empathy_streamed_media_window_create_video_input_add_slider (
440 self, _("Gamma"), hbox);
446 empathy_streamed_media_window_setup_video_input (EmpathyStreamedMediaWindow *self)
448 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
452 supported = empathy_video_src_get_supported_channels (priv->video_input);
454 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
456 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
458 gtk_adjustment_set_value (adj,
459 empathy_video_src_get_channel (priv->video_input,
460 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
462 g_signal_connect (G_OBJECT (adj), "value-changed",
463 G_CALLBACK (empathy_streamed_media_window_video_contrast_changed_cb), self);
465 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
468 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
470 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
472 gtk_adjustment_set_value (adj,
473 empathy_video_src_get_channel (priv->video_input,
474 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
476 g_signal_connect (G_OBJECT (adj), "value-changed",
477 G_CALLBACK (empathy_streamed_media_window_video_brightness_changed_cb), self);
478 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
481 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
483 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
485 gtk_adjustment_set_value (adj,
486 empathy_video_src_get_channel (priv->video_input,
487 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
489 g_signal_connect (G_OBJECT (adj), "value-changed",
490 G_CALLBACK (empathy_streamed_media_window_video_gamma_changed_cb), self);
491 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
496 empathy_streamed_media_window_mic_volume_changed_cb (GtkAdjustment *adj,
497 EmpathyStreamedMediaWindow *self)
499 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
502 volume = gtk_adjustment_get_value (adj)/100.0;
504 /* Don't store the volume because of muting */
505 if (volume > 0 || gtk_toggle_tool_button_get_active (
506 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
507 priv->volume = volume;
509 /* Ensure that the toggle button is active if the volume is > 0 and inactive
510 * if it's smaller than 0 */
511 if ((volume > 0) != gtk_toggle_tool_button_get_active (
512 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
513 gtk_toggle_tool_button_set_active (
514 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
516 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
521 empathy_streamed_media_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
522 gdouble level, EmpathyStreamedMediaWindow *window)
525 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
527 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
528 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
533 empathy_streamed_media_window_create_audio_input (EmpathyStreamedMediaWindow *self)
535 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
536 GtkWidget *hbox, *vbox, *label;
538 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
539 gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
541 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
542 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
544 priv->volume_scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL, 0,
546 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
547 label = gtk_label_new (_("Volume"));
549 priv->audio_input_adj = gtk_range_get_adjustment (
550 GTK_RANGE (priv->volume_scale));
551 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
552 (priv->audio_input));
553 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
555 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
556 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), self);
558 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
559 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
561 priv->volume_progress_bar = gtk_progress_bar_new ();
563 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
564 GTK_ORIENTATION_VERTICAL);
566 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
569 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
576 create_video_output_widget (EmpathyStreamedMediaWindow *self)
578 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
581 g_assert (priv->video_output == NULL);
582 g_assert (priv->pipeline != NULL);
584 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
585 priv->video_output = empathy_video_widget_new (bus);
587 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
588 priv->video_output, TRUE, TRUE, 0);
590 gtk_widget_add_events (priv->video_output,
591 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
592 g_signal_connect (G_OBJECT (priv->video_output), "button-press-event",
593 G_CALLBACK (empathy_streamed_media_window_video_button_press_cb), self);
595 g_object_unref (bus);
599 create_video_input (EmpathyStreamedMediaWindow *self)
601 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
603 g_assert (priv->video_input == NULL);
604 priv->video_input = empathy_video_src_new ();
605 gst_object_ref_sink (priv->video_input);
609 create_audio_input (EmpathyStreamedMediaWindow *self)
611 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
613 g_assert (priv->audio_input == NULL);
614 priv->audio_input = empathy_audio_src_new ();
615 gst_object_ref_sink (priv->audio_input);
617 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
618 G_CALLBACK (empathy_streamed_media_window_audio_input_level_changed_cb),
623 add_video_preview_to_pipeline (EmpathyStreamedMediaWindow *self)
625 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
628 g_assert (priv->video_preview != NULL);
629 g_assert (priv->pipeline != NULL);
630 g_assert (priv->video_input != NULL);
631 g_assert (priv->video_tee != NULL);
633 preview = empathy_video_widget_get_element (
634 EMPATHY_VIDEO_WIDGET (priv->video_preview));
636 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
638 g_warning ("Could not add video input to pipeline");
642 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee))
644 g_warning ("Could not add video tee to pipeline");
648 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
650 g_warning ("Could not add video preview to pipeline");
654 if (!gst_element_link (priv->video_input, priv->video_tee))
656 g_warning ("Could not link video input to video tee");
660 if (!gst_element_link (priv->video_tee, preview))
662 g_warning ("Could not link video tee to video preview");
668 create_video_preview (EmpathyStreamedMediaWindow *self)
670 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
673 g_assert (priv->video_preview == NULL);
674 g_assert (priv->video_tee == NULL);
676 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
678 priv->video_preview = empathy_video_widget_new_with_size (bus,
679 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
680 g_object_set (priv->video_preview,
686 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
687 priv->video_preview, TRUE, TRUE, 0);
689 priv->video_tee = gst_element_factory_make ("tee", NULL);
690 gst_object_ref_sink (priv->video_tee);
692 g_object_unref (bus);
696 play_camera (EmpathyStreamedMediaWindow *window,
699 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
703 if (priv->video_preview == NULL)
705 create_video_preview (window);
706 add_video_preview_to_pipeline (window);
710 state = GST_STATE_PLAYING;
712 state = GST_STATE_NULL;
714 preview = empathy_video_widget_get_element (
715 EMPATHY_VIDEO_WIDGET (priv->video_preview));
717 gst_element_set_state (preview, state);
718 gst_element_set_state (priv->video_input, state);
719 gst_element_set_state (priv->video_tee, state);
723 display_video_preview (EmpathyStreamedMediaWindow *self,
726 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
730 /* Display the preview and hide the self avatar */
731 DEBUG ("Show video preview");
733 play_camera (self, TRUE);
734 gtk_widget_show (priv->video_preview);
735 gtk_widget_hide (priv->self_user_avatar_widget);
739 /* Display the self avatar and hide the preview */
740 DEBUG ("Show self avatar");
742 if (priv->video_preview != NULL)
744 gtk_widget_hide (priv->video_preview);
745 play_camera (self, FALSE);
747 gtk_widget_show (priv->self_user_avatar_widget);
752 empathy_streamed_media_window_set_state_connecting (EmpathyStreamedMediaWindow *window)
754 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
756 empathy_streamed_media_window_status_message (window, _("Connecting…"));
757 priv->call_state = CONNECTING;
760 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
761 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
765 disable_camera (EmpathyStreamedMediaWindow *self)
767 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
769 if (priv->camera_state == CAMERA_STATE_OFF)
772 DEBUG ("Disable camera");
774 display_video_preview (self, FALSE);
776 if (priv->camera_state == CAMERA_STATE_ON)
777 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
779 block_camera_control_signals (self);
780 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
781 priv->tool_button_camera_on), FALSE);
782 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
783 priv->tool_button_camera_preview), FALSE);
785 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
786 priv->tool_button_camera_off), TRUE);
787 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
789 unblock_camera_control_signals (self);
791 priv->camera_state = CAMERA_STATE_OFF;
795 tool_button_camera_off_toggled_cb (GtkToggleToolButton *toggle,
796 EmpathyStreamedMediaWindow *self)
798 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
800 if (!gtk_toggle_tool_button_get_active (toggle))
802 if (priv->camera_state == CAMERA_STATE_OFF)
804 /* We can't change the state by disabling the button */
805 block_camera_control_signals (self);
806 gtk_toggle_tool_button_set_active (toggle, TRUE);
807 unblock_camera_control_signals (self);
813 disable_camera (self);
817 enable_preview (EmpathyStreamedMediaWindow *self)
819 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
821 if (priv->camera_state == CAMERA_STATE_PREVIEW)
824 DEBUG ("Enable preview");
826 if (priv->camera_state == CAMERA_STATE_ON)
828 /* preview is already displayed so we just have to stop sending */
829 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_PREVIEW);
833 display_video_preview (self, TRUE);
836 block_camera_control_signals (self);
837 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
838 priv->tool_button_camera_off), FALSE);
839 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
840 priv->tool_button_camera_on), FALSE);
842 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
843 priv->tool_button_camera_preview), TRUE);
844 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
845 CAMERA_STATE_PREVIEW);
846 unblock_camera_control_signals (self);
848 priv->camera_state = CAMERA_STATE_PREVIEW;
852 tool_button_camera_preview_toggled_cb (GtkToggleToolButton *toggle,
853 EmpathyStreamedMediaWindow *self)
855 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
857 if (!gtk_toggle_tool_button_get_active (toggle))
859 if (priv->camera_state == CAMERA_STATE_PREVIEW)
861 /* We can't change the state by disabling the button */
862 block_camera_control_signals (self);
863 gtk_toggle_tool_button_set_active (toggle, TRUE);
864 unblock_camera_control_signals (self);
870 enable_preview (self);
874 enable_camera (EmpathyStreamedMediaWindow *self)
876 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
878 if (priv->camera_state == CAMERA_STATE_ON)
881 if (priv->video_input == NULL)
883 DEBUG ("Can't enable camera, no input");
888 DEBUG ("Enable camera");
890 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_ON);
892 block_camera_control_signals (self);
893 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
894 priv->tool_button_camera_off), FALSE);
895 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
896 priv->tool_button_camera_preview), FALSE);
898 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
899 priv->tool_button_camera_on), TRUE);
900 gtk_radio_action_set_current_value (GTK_RADIO_ACTION (priv->action_camera_on),
902 unblock_camera_control_signals (self);
904 priv->camera_state = CAMERA_STATE_ON;
908 tool_button_camera_on_toggled_cb (GtkToggleToolButton *toggle,
909 EmpathyStreamedMediaWindow *self)
911 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
913 if (!gtk_toggle_tool_button_get_active (toggle))
915 if (priv->camera_state == CAMERA_STATE_ON)
917 /* We can't change the state by disabling the button */
918 block_camera_control_signals (self);
919 gtk_toggle_tool_button_set_active (toggle, TRUE);
920 unblock_camera_control_signals (self);
926 enable_camera (self);
930 action_camera_change_cb (GtkRadioAction *action,
931 GtkRadioAction *current,
932 EmpathyStreamedMediaWindow *self)
936 state = gtk_radio_action_get_current_value (current);
940 case CAMERA_STATE_OFF:
941 disable_camera (self);
944 case CAMERA_STATE_PREVIEW:
945 enable_preview (self);
948 case CAMERA_STATE_ON:
949 enable_camera (self);
953 g_assert_not_reached ();
958 create_pipeline (EmpathyStreamedMediaWindow *self)
960 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
963 g_assert (priv->pipeline == NULL);
965 priv->pipeline = gst_pipeline_new (NULL);
966 priv->pipeline_playing = FALSE;
968 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
969 priv->bus_message_source_id = gst_bus_add_watch (bus,
970 empathy_streamed_media_window_bus_message, self);
972 g_object_unref (bus);
977 empathy_streamed_media_window_init (EmpathyStreamedMediaWindow *self)
979 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
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_box_new (GTK_ORIENTATION_HORIZONTAL,
1040 CONTENT_HBOX_SPACING);
1041 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1042 CONTENT_HBOX_BORDER_WIDTH);
1043 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1045 /* remote user output frame */
1046 priv->remote_user_output_frame = gtk_frame_new (NULL);
1047 gtk_widget_set_size_request (priv->remote_user_output_frame,
1048 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1049 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1050 priv->remote_user_output_frame, TRUE, TRUE,
1051 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1053 priv->remote_user_output_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
1055 priv->remote_user_avatar_widget = gtk_image_new ();
1057 gtk_box_pack_start (GTK_BOX (priv->remote_user_output_hbox),
1058 priv->remote_user_avatar_widget, TRUE, TRUE, 0);
1060 gtk_container_add (GTK_CONTAINER (priv->remote_user_output_frame),
1061 priv->remote_user_output_hbox);
1063 /* self user output frame */
1064 priv->self_user_output_frame = gtk_frame_new (NULL);
1065 gtk_widget_set_size_request (priv->self_user_output_frame,
1066 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
1068 priv->self_user_output_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
1070 priv->self_user_avatar_widget = gtk_image_new ();
1071 gtk_box_pack_start (GTK_BOX (priv->self_user_output_hbox),
1072 priv->self_user_avatar_widget, TRUE, TRUE, 0);
1074 gtk_container_add (GTK_CONTAINER (priv->self_user_output_frame),
1075 priv->self_user_output_hbox);
1077 create_pipeline (self);
1078 create_video_output_widget (self);
1079 create_audio_input (self);
1080 create_video_input (self);
1082 priv->fsnotifier = fs_element_added_notifier_new ();
1083 fs_element_added_notifier_add (priv->fsnotifier, GST_BIN (priv->pipeline));
1085 /* The call will be started as soon the pipeline is playing */
1086 priv->start_call_when_playing = TRUE;
1088 priv->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
1089 gtk_box_pack_start (GTK_BOX (priv->content_hbox), priv->vbox,
1090 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1091 gtk_box_pack_start (GTK_BOX (priv->vbox), priv->self_user_output_frame,
1094 empathy_streamed_media_window_setup_toolbar (self);
1096 priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
1097 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
1098 g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
1099 G_CALLBACK (empathy_streamed_media_window_sidebar_toggled_cb), self);
1101 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
1103 h = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
1104 gtk_box_pack_end (GTK_BOX (priv->vbox), h, FALSE, FALSE, 3);
1105 gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
1107 priv->sidebar = ev_sidebar_new ();
1108 g_signal_connect (G_OBJECT (priv->sidebar),
1109 "hide", G_CALLBACK (empathy_streamed_media_window_sidebar_hidden_cb), self);
1110 g_signal_connect (G_OBJECT (priv->sidebar),
1111 "show", G_CALLBACK (empathy_streamed_media_window_sidebar_shown_cb), self);
1112 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1114 page = empathy_streamed_media_window_create_audio_input (self);
1115 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1116 _("Audio input"), page);
1118 page = empathy_streamed_media_window_create_video_input (self);
1119 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1120 _("Video input"), page);
1122 priv->dtmf_panel = empathy_dialpad_widget_new ();
1123 g_signal_connect (priv->dtmf_panel, "start-tone",
1124 G_CALLBACK (dtmf_start_tone_cb), self);
1125 g_signal_connect (priv->dtmf_panel, "stop-tone",
1126 G_CALLBACK (dtmf_stop_tone_cb), self);
1127 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1128 _("Dialpad"), priv->dtmf_panel);
1130 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1132 /* Put the details vbox in a scroll window as it can require a lot of
1133 * horizontal space. */
1134 scroll = gtk_scrolled_window_new (NULL, NULL);
1135 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1136 priv->details_vbox);
1138 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details",
1139 _("Details"), scroll);
1141 gtk_widget_show_all (top_vbox);
1143 gtk_widget_hide (priv->sidebar);
1145 priv->fullscreen = empathy_streamed_media_window_fullscreen_new (self);
1146 empathy_streamed_media_window_fullscreen_set_video_widget (priv->fullscreen,
1147 priv->video_output);
1148 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1149 "clicked", G_CALLBACK (empathy_streamed_media_window_fullscreen_cb), self);
1151 g_signal_connect (G_OBJECT (self), "realize",
1152 G_CALLBACK (empathy_streamed_media_window_realized_cb), self);
1154 g_signal_connect (G_OBJECT (self), "delete-event",
1155 G_CALLBACK (empathy_streamed_media_window_delete_cb), self);
1157 g_signal_connect (G_OBJECT (self), "window-state-event",
1158 G_CALLBACK (empathy_streamed_media_window_state_event_cb), self);
1160 g_signal_connect (G_OBJECT (self), "key-press-event",
1161 G_CALLBACK (empathy_streamed_media_window_key_press_cb), self);
1163 priv->timer = g_timer_new ();
1165 g_object_ref (priv->ui_manager);
1166 g_object_unref (gui);
1168 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1170 empathy_geometry_bind (GTK_WINDOW (self), "av-window");
1173 /* Instead of specifying a width and a height, we specify only one size. That's
1174 because we want a square avatar icon. */
1176 init_contact_avatar_with_size (EmpathyContact *contact,
1177 GtkWidget *image_widget,
1180 GdkPixbuf *pixbuf_avatar = NULL;
1182 if (contact != NULL)
1184 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1188 if (pixbuf_avatar == NULL)
1190 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1191 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1194 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1196 if (pixbuf_avatar != NULL)
1197 g_object_unref (pixbuf_avatar);
1201 set_window_title (EmpathyStreamedMediaWindow *self)
1203 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1206 /* translators: Call is a noun and %s is the contact name. This string
1207 * is used in the window title */
1208 tmp = g_strdup_printf (_("Call with %s"),
1209 empathy_contact_get_alias (priv->contact));
1210 gtk_window_set_title (GTK_WINDOW (self), tmp);
1215 contact_name_changed_cb (EmpathyContact *contact,
1216 GParamSpec *pspec, EmpathyStreamedMediaWindow *self)
1218 set_window_title (self);
1222 contact_avatar_changed_cb (EmpathyContact *contact,
1223 GParamSpec *pspec, GtkWidget *avatar_widget)
1226 GtkAllocation allocation;
1228 gtk_widget_get_allocation (avatar_widget, &allocation);
1229 size = allocation.height;
1233 /* the widget is not allocated yet, set a default size */
1234 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1235 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1238 init_contact_avatar_with_size (contact, avatar_widget, size);
1242 empathy_streamed_media_window_got_self_contact_cb (TpConnection *connection,
1243 EmpathyContact *contact, const GError *error, gpointer user_data,
1244 GObject *weak_object)
1246 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1247 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1249 init_contact_avatar_with_size (contact, priv->self_user_avatar_widget,
1250 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1252 g_signal_connect (contact, "notify::avatar",
1253 G_CALLBACK (contact_avatar_changed_cb), priv->self_user_avatar_widget);
1257 empathy_streamed_media_window_setup_avatars (EmpathyStreamedMediaWindow *self,
1258 EmpathyStreamedMediaHandler *handler)
1260 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1262 g_object_get (handler, "contact", &(priv->contact), NULL);
1264 if (priv->contact != NULL)
1266 TpConnection *connection;
1268 set_window_title (self);
1270 g_signal_connect (priv->contact, "notify::name",
1271 G_CALLBACK (contact_name_changed_cb), self);
1272 g_signal_connect (priv->contact, "notify::avatar",
1273 G_CALLBACK (contact_avatar_changed_cb),
1274 priv->remote_user_avatar_widget);
1276 /* Retreiving the self avatar */
1277 connection = empathy_contact_get_connection (priv->contact);
1278 empathy_tp_contact_factory_get_from_handle (connection,
1279 tp_connection_get_self_handle (connection),
1280 empathy_streamed_media_window_got_self_contact_cb, self, NULL, G_OBJECT (self));
1284 g_warning ("call handler doesn't have a contact");
1285 /* translators: Call is a noun. This string is used in the window
1287 gtk_window_set_title (GTK_WINDOW (self), _("Call"));
1289 /* Since we can't access the remote contact, we can't get a connection
1290 to it and can't get the self contact (and its avatar). This means
1291 that we have to manually set the self avatar. */
1292 init_contact_avatar_with_size (NULL, priv->self_user_avatar_widget,
1293 MIN (SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH));
1296 init_contact_avatar_with_size (priv->contact,
1297 priv->remote_user_avatar_widget,
1298 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1299 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1301 /* The remote avatar is shown by default and will be hidden when we receive
1302 video from the remote side. */
1303 gtk_widget_hide (priv->video_output);
1304 gtk_widget_show (priv->remote_user_avatar_widget);
1308 update_send_codec (EmpathyStreamedMediaWindow *self,
1311 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1318 codec = empathy_streamed_media_handler_get_send_audio_codec (priv->handler);
1319 widget = priv->acodec_encoding_label;
1323 codec = empathy_streamed_media_handler_get_send_video_codec (priv->handler);
1324 widget = priv->vcodec_encoding_label;
1330 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1331 gtk_label_set_text (GTK_LABEL (widget), tmp);
1336 send_audio_codec_notify_cb (GObject *object,
1340 EmpathyStreamedMediaWindow *self = user_data;
1342 update_send_codec (self, TRUE);
1346 send_video_codec_notify_cb (GObject *object,
1350 EmpathyStreamedMediaWindow *self = user_data;
1352 update_send_codec (self, FALSE);
1356 update_recv_codec (EmpathyStreamedMediaWindow *self,
1359 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1362 GString *str = NULL;
1366 codecs = empathy_streamed_media_handler_get_recv_audio_codecs (priv->handler);
1367 widget = priv->acodec_decoding_label;
1371 codecs = empathy_streamed_media_handler_get_recv_video_codecs (priv->handler);
1372 widget = priv->vcodec_decoding_label;
1378 for (l = codecs; l != NULL; l = g_list_next (l))
1380 FsCodec *codec = l->data;
1383 str = g_string_new (NULL);
1385 g_string_append (str, ", ");
1387 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1391 gtk_label_set_text (GTK_LABEL (widget), str->str);
1392 g_string_free (str, TRUE);
1396 recv_audio_codecs_notify_cb (GObject *object,
1400 EmpathyStreamedMediaWindow *self = user_data;
1402 update_recv_codec (self, TRUE);
1406 recv_video_codecs_notify_cb (GObject *object,
1410 EmpathyStreamedMediaWindow *self = user_data;
1412 update_recv_codec (self, FALSE);
1415 static const gchar *
1416 candidate_type_to_str (FsCandidate *candidate)
1418 switch (candidate->type)
1420 case FS_CANDIDATE_TYPE_HOST:
1422 case FS_CANDIDATE_TYPE_SRFLX:
1423 return "server reflexive";
1424 case FS_CANDIDATE_TYPE_PRFLX:
1425 return "peer reflexive";
1426 case FS_CANDIDATE_TYPE_RELAY:
1428 case FS_CANDIDATE_TYPE_MULTICAST:
1435 static const gchar *
1436 candidate_type_to_desc (FsCandidate *candidate)
1438 switch (candidate->type)
1440 case FS_CANDIDATE_TYPE_HOST:
1441 return _("The IP address as seen by the machine");
1442 case FS_CANDIDATE_TYPE_SRFLX:
1443 return _("The IP address as seen by a server on the Internet");
1444 case FS_CANDIDATE_TYPE_PRFLX:
1445 return _("The IP address of the peer as seen by the other side");
1446 case FS_CANDIDATE_TYPE_RELAY:
1447 return _("The IP address of a relay server");
1448 case FS_CANDIDATE_TYPE_MULTICAST:
1449 return _("The IP address of the multicast group");
1456 update_candidat_widget (EmpathyStreamedMediaWindow *self,
1459 FsCandidate *candidate)
1463 g_assert (candidate != NULL);
1464 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1465 candidate->port, candidate_type_to_str (candidate));
1467 gtk_label_set_text (GTK_LABEL (label), str);
1468 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1474 candidates_changed_cb (GObject *object,
1476 EmpathyStreamedMediaWindow *self)
1478 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1479 FsCandidate *candidate = NULL;
1481 if (type == FS_MEDIA_TYPE_VIDEO)
1483 /* Update remote candidate */
1484 candidate = empathy_streamed_media_handler_get_video_remote_candidate (
1487 update_candidat_widget (self, priv->video_remote_candidate_label,
1488 priv->video_remote_candidate_info_img, candidate);
1490 /* Update local candidate */
1491 candidate = empathy_streamed_media_handler_get_video_local_candidate (
1494 update_candidat_widget (self, priv->video_local_candidate_label,
1495 priv->video_local_candidate_info_img, candidate);
1499 /* Update remote candidate */
1500 candidate = empathy_streamed_media_handler_get_audio_remote_candidate (
1503 update_candidat_widget (self, priv->audio_remote_candidate_label,
1504 priv->audio_remote_candidate_info_img, candidate);
1506 /* Update local candidate */
1507 candidate = empathy_streamed_media_handler_get_audio_local_candidate (
1510 update_candidat_widget (self, priv->audio_local_candidate_label,
1511 priv->audio_local_candidate_info_img, candidate);
1516 empathy_streamed_media_window_constructed (GObject *object)
1518 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1519 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1520 EmpathyTpStreamedMedia *call;
1522 g_assert (priv->handler != NULL);
1524 g_object_get (priv->handler, "tp-call", &call, NULL);
1525 priv->outgoing = (call == NULL);
1527 g_object_unref (call);
1529 empathy_streamed_media_window_setup_avatars (self, priv->handler);
1530 empathy_streamed_media_window_set_state_connecting (self);
1532 if (!empathy_streamed_media_handler_has_initial_video (priv->handler))
1534 gtk_toggle_tool_button_set_active (
1535 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_off), TRUE);
1537 /* If call has InitialVideo, the preview will be started once the call has
1538 * been started (start_call()). */
1540 update_send_codec (self, TRUE);
1541 update_send_codec (self, FALSE);
1542 update_recv_codec (self, TRUE);
1543 update_recv_codec (self, FALSE);
1545 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1546 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1547 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1548 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1549 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1550 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1551 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1552 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1554 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1555 G_CALLBACK (candidates_changed_cb), self, 0);
1558 static void empathy_streamed_media_window_dispose (GObject *object);
1559 static void empathy_streamed_media_window_finalize (GObject *object);
1562 empathy_streamed_media_window_set_property (GObject *object,
1563 guint property_id, const GValue *value, GParamSpec *pspec)
1565 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1567 switch (property_id)
1569 case PROP_STREAMED_MEDIA_HANDLER:
1570 priv->handler = g_value_dup_object (value);
1573 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1578 empathy_streamed_media_window_get_property (GObject *object,
1579 guint property_id, GValue *value, GParamSpec *pspec)
1581 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (object);
1583 switch (property_id)
1585 case PROP_STREAMED_MEDIA_HANDLER:
1586 g_value_set_object (value, priv->handler);
1589 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1594 empathy_streamed_media_window_class_init (
1595 EmpathyStreamedMediaWindowClass *empathy_streamed_media_window_class)
1597 GObjectClass *object_class = G_OBJECT_CLASS (empathy_streamed_media_window_class);
1598 GParamSpec *param_spec;
1600 g_type_class_add_private (empathy_streamed_media_window_class,
1601 sizeof (EmpathyStreamedMediaWindowPriv));
1603 object_class->constructed = empathy_streamed_media_window_constructed;
1604 object_class->set_property = empathy_streamed_media_window_set_property;
1605 object_class->get_property = empathy_streamed_media_window_get_property;
1607 object_class->dispose = empathy_streamed_media_window_dispose;
1608 object_class->finalize = empathy_streamed_media_window_finalize;
1610 param_spec = g_param_spec_object ("handler",
1611 "handler", "The call handler",
1612 EMPATHY_TYPE_STREAMED_MEDIA_HANDLER,
1613 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1614 g_object_class_install_property (object_class,
1615 PROP_STREAMED_MEDIA_HANDLER, param_spec);
1619 empathy_streamed_media_window_video_stream_changed_cb (EmpathyTpStreamedMedia *call,
1620 GParamSpec *property, EmpathyStreamedMediaWindow *self)
1622 DEBUG ("video stream changed");
1623 empathy_streamed_media_window_update_avatars_visibility (call, self);
1627 empathy_streamed_media_window_dispose (GObject *object)
1629 EmpathyTpStreamedMedia *call;
1630 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1631 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1633 if (priv->dispose_has_run)
1636 priv->dispose_has_run = TRUE;
1638 g_object_get (priv->handler, "tp-call", &call, NULL);
1642 g_object_unref (call);
1645 if (priv->handler != NULL)
1647 empathy_streamed_media_handler_stop_call (priv->handler);
1648 g_object_unref (priv->handler);
1650 priv->handler = NULL;
1652 if (priv->bus_message_source_id != 0)
1654 g_source_remove (priv->bus_message_source_id);
1655 priv->bus_message_source_id = 0;
1658 if (priv->pipeline != NULL)
1659 g_object_unref (priv->pipeline);
1660 priv->pipeline = NULL;
1662 if (priv->video_input != NULL)
1663 g_object_unref (priv->video_input);
1664 priv->video_input = NULL;
1666 if (priv->audio_input != NULL)
1667 g_object_unref (priv->audio_input);
1668 priv->audio_input = NULL;
1670 if (priv->video_tee != NULL)
1671 g_object_unref (priv->video_tee);
1672 priv->video_tee = NULL;
1674 if (priv->fsnotifier != NULL)
1675 g_object_unref (priv->fsnotifier);
1676 priv->fsnotifier = NULL;
1678 if (priv->timer_id != 0)
1679 g_source_remove (priv->timer_id);
1682 if (priv->ui_manager != NULL)
1683 g_object_unref (priv->ui_manager);
1684 priv->ui_manager = NULL;
1686 if (priv->fullscreen != NULL)
1687 g_object_unref (priv->fullscreen);
1688 priv->fullscreen = NULL;
1690 if (priv->contact != NULL)
1692 g_signal_handlers_disconnect_by_func (priv->contact,
1693 contact_name_changed_cb, self);
1694 g_object_unref (priv->contact);
1695 priv->contact = NULL;
1698 tp_clear_object (&priv->sound_mgr);
1700 /* release any references held by the object here */
1701 if (G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose)
1702 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->dispose (object);
1706 disconnect_video_output_motion_handler (EmpathyStreamedMediaWindow *self)
1708 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1710 if (priv->video_output_motion_handler_id != 0)
1712 g_signal_handler_disconnect (G_OBJECT (priv->video_output),
1713 priv->video_output_motion_handler_id);
1714 priv->video_output_motion_handler_id = 0;
1719 empathy_streamed_media_window_finalize (GObject *object)
1721 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (object);
1722 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1724 disconnect_video_output_motion_handler (self);
1726 /* free any data held directly by the object here */
1727 g_mutex_free (priv->lock);
1729 g_timer_destroy (priv->timer);
1731 G_OBJECT_CLASS (empathy_streamed_media_window_parent_class)->finalize (object);
1735 EmpathyStreamedMediaWindow *
1736 empathy_streamed_media_window_new (EmpathyStreamedMediaHandler *handler)
1738 return EMPATHY_STREAMED_MEDIA_WINDOW (
1739 g_object_new (EMPATHY_TYPE_STREAMED_MEDIA_WINDOW, "handler", handler, NULL));
1743 empathy_streamed_media_window_conference_added_cb (EmpathyStreamedMediaHandler *handler,
1744 GstElement *conference, gpointer user_data)
1746 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1747 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1750 keyfile = fs_utils_get_default_element_properties (conference);
1751 if (keyfile != NULL)
1752 fs_element_added_notifier_set_properties_from_keyfile (priv->fsnotifier,
1755 gst_bin_add (GST_BIN (priv->pipeline), conference);
1757 gst_element_set_state (conference, GST_STATE_PLAYING);
1761 empathy_streamed_media_window_start_receiving_cb (EmpathyStreamedMediaHandler *handler,
1762 FsMediaType type,gpointer user_data)
1764 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1765 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1767 if (type != FS_MEDIA_TYPE_VIDEO)
1770 /* video and direction is send */
1771 return priv->video_input != NULL;
1775 empathy_streamed_media_window_reset_pipeline (EmpathyStreamedMediaWindow *self)
1777 GstStateChangeReturn state_change_return;
1778 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1780 if (priv->pipeline == NULL)
1783 if (priv->bus_message_source_id != 0)
1785 g_source_remove (priv->bus_message_source_id);
1786 priv->bus_message_source_id = 0;
1789 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1791 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1792 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1794 if (priv->pipeline != NULL)
1795 g_object_unref (priv->pipeline);
1796 priv->pipeline = NULL;
1798 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1799 empathy_streamed_media_window_mic_volume_changed_cb, self);
1801 if (priv->video_tee != NULL)
1802 g_object_unref (priv->video_tee);
1803 priv->video_tee = NULL;
1805 if (priv->video_preview != NULL)
1806 gtk_widget_destroy (priv->video_preview);
1807 priv->video_preview = NULL;
1809 priv->funnel = NULL;
1811 create_pipeline (self);
1812 /* Call will be started when user will hit the 'redial' button */
1813 priv->start_call_when_playing = FALSE;
1814 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1820 g_message ("Error: could not destroy pipeline. Closing call window");
1821 gtk_widget_destroy (GTK_WIDGET (self));
1828 reset_details_pane (EmpathyStreamedMediaWindow *self)
1830 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1832 /* translators: encoding video codec is unknown */
1833 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label),
1834 C_("codec", "Unknown"));
1835 /* translators: encoding audio codec is unknown */
1836 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label),
1837 C_("codec", "Unknown"));
1838 /* translators: decoding video codec is unknown */
1839 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label),
1840 C_("codec", "Unknown"));
1841 /* translators: decoding audio codec is unknown */
1842 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label),
1843 C_("codec", "Unknown"));
1847 empathy_streamed_media_window_disconnected (EmpathyStreamedMediaWindow *self,
1850 gboolean could_disconnect = FALSE;
1851 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1852 gboolean could_reset_pipeline;
1854 /* Leave full screen mode if needed */
1855 gtk_window_unfullscreen (GTK_WINDOW (self));
1857 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1859 could_reset_pipeline = empathy_streamed_media_window_reset_pipeline (self);
1861 if (priv->call_state == CONNECTING)
1862 empathy_sound_manager_stop (priv->sound_mgr,
1863 EMPATHY_SOUND_PHONE_OUTGOING);
1865 if (priv->call_state != REDIALING)
1866 priv->call_state = DISCONNECTED;
1868 if (could_reset_pipeline)
1870 g_mutex_lock (priv->lock);
1872 g_timer_stop (priv->timer);
1874 if (priv->timer_id != 0)
1875 g_source_remove (priv->timer_id);
1878 g_mutex_unlock (priv->lock);
1881 /* We are about to destroy the window, no need to update it or create
1882 * a video preview */
1885 empathy_streamed_media_window_status_message (self, _("Disconnected"));
1887 gtk_action_set_sensitive (priv->redial, TRUE);
1888 gtk_widget_set_sensitive (priv->redial_button, TRUE);
1890 /* Unsensitive the camera and mic button */
1891 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
1892 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
1893 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1895 /* Be sure that the mic button is enabled */
1896 gtk_toggle_tool_button_set_active (
1897 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1899 if (priv->camera_state == CAMERA_STATE_ON)
1901 /* Enable the 'preview' button as we are not sending atm. */
1902 gtk_toggle_tool_button_set_active (
1903 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_preview), TRUE);
1905 else if (priv->camera_state == CAMERA_STATE_PREVIEW)
1907 /* Restart the preview with the new pipeline. */
1908 display_video_preview (self, TRUE);
1911 gtk_progress_bar_set_fraction (
1912 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1914 /* destroy the video output; it will be recreated when we'll redial */
1915 disconnect_video_output_motion_handler (self);
1916 gtk_widget_destroy (priv->video_output);
1917 priv->video_output = NULL;
1919 gtk_widget_show (priv->remote_user_avatar_widget);
1921 reset_details_pane (self);
1923 priv->sending_video = FALSE;
1924 priv->call_started = FALSE;
1926 could_disconnect = TRUE;
1928 /* TODO: display the self avatar of the preview (depends if the "Always
1929 * Show Video Preview" is enabled or not) */
1932 return could_disconnect;
1937 empathy_streamed_media_window_channel_closed_cb (EmpathyStreamedMediaHandler *handler,
1940 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1941 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1943 if (empathy_streamed_media_window_disconnected (self, TRUE) &&
1944 priv->call_state == REDIALING)
1945 empathy_streamed_media_window_restart_call (self);
1950 empathy_streamed_media_window_channel_stream_closed_cb (EmpathyStreamedMediaHandler *handler,
1951 TfContent *content, gpointer user_data)
1953 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
1954 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
1957 g_object_get (content, "media-type", &media_type, NULL);
1960 * This assumes that there is only one video stream per channel...
1963 if (media_type == TP_MEDIA_STREAM_TYPE_VIDEO)
1965 if (priv->funnel != NULL)
1969 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
1970 (priv->video_output));
1972 gst_element_set_state (output, GST_STATE_NULL);
1973 gst_element_set_state (priv->funnel, GST_STATE_NULL);
1975 gst_bin_remove (GST_BIN (priv->pipeline), output);
1976 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1977 priv->funnel = NULL;
1980 else if (media_type == TP_MEDIA_STREAM_TYPE_AUDIO)
1982 if (priv->audio_output != NULL)
1984 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1986 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1987 priv->audio_output = NULL;
1992 /* Called with global lock held */
1994 empathy_streamed_media_window_get_video_sink_pad (EmpathyStreamedMediaWindow *self)
1996 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2000 if (priv->funnel == NULL)
2002 output = empathy_video_widget_get_element (EMPATHY_VIDEO_WIDGET
2003 (priv->video_output));
2005 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2009 g_warning ("Could not create fsfunnel");
2013 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2015 gst_object_unref (priv->funnel);
2016 priv->funnel = NULL;
2017 g_warning ("Could not add funnel to pipeline");
2021 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2023 g_warning ("Could not add the video output widget to the pipeline");
2027 if (!gst_element_link (priv->funnel, output))
2029 g_warning ("Could not link output sink to funnel");
2030 goto error_output_added;
2033 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2035 g_warning ("Could not start video sink");
2036 goto error_output_added;
2039 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2041 g_warning ("Could not start funnel");
2042 goto error_output_added;
2046 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2049 g_warning ("Could not get request pad from funnel");
2056 gst_element_set_locked_state (priv->funnel, TRUE);
2057 gst_element_set_locked_state (output, TRUE);
2059 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2060 gst_element_set_state (output, GST_STATE_NULL);
2062 gst_bin_remove (GST_BIN (priv->pipeline), output);
2063 gst_element_set_locked_state (output, FALSE);
2067 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2068 priv->funnel = NULL;
2073 /* Called with global lock held */
2075 empathy_streamed_media_window_get_audio_sink_pad (EmpathyStreamedMediaWindow *self)
2077 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2079 GstPadTemplate *template;
2081 if (priv->audio_output == NULL)
2083 priv->audio_output = empathy_audio_sink_new ();
2085 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2087 g_warning ("Could not add audio sink to pipeline");
2088 g_object_unref (priv->audio_output);
2089 goto error_add_output;
2092 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2094 g_warning ("Could not start audio sink");
2099 template = gst_element_class_get_pad_template (
2100 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2102 pad = gst_element_request_pad (priv->audio_output,
2103 template, NULL, NULL);
2107 g_warning ("Could not get sink pad from sink");
2114 gst_element_set_locked_state (priv->audio_output, TRUE);
2115 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2116 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2117 priv->audio_output = NULL;
2125 empathy_streamed_media_window_update_timer (gpointer user_data)
2127 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2128 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2132 time_ = g_timer_elapsed (priv->timer, NULL);
2134 /* Translators: number of minutes:seconds the caller has been connected */
2135 str = g_strdup_printf (_("Connected — %d:%02dm"), (int) time_ / 60,
2137 empathy_streamed_media_window_status_message (self, str);
2144 display_error (EmpathyStreamedMediaWindow *self,
2145 EmpathyTpStreamedMedia *call,
2149 const gchar *details)
2151 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2152 GtkWidget *info_bar;
2153 GtkWidget *content_area;
2160 /* Create info bar */
2161 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2164 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2166 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2168 /* hbox containing the image and the messages vbox */
2169 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2170 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2173 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2174 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2176 /* vbox containing the main message and the details expander */
2177 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2178 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2181 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2183 label = gtk_label_new (NULL);
2184 gtk_label_set_markup (GTK_LABEL (label), txt);
2185 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2186 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2189 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2192 if (details != NULL)
2194 GtkWidget *expander;
2196 expander = gtk_expander_new (_("Technical Details"));
2198 txt = g_strdup_printf ("<i>%s</i>", details);
2200 label = gtk_label_new (NULL);
2201 gtk_label_set_markup (GTK_LABEL (label), txt);
2202 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2203 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2206 gtk_container_add (GTK_CONTAINER (expander), label);
2207 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2210 g_signal_connect (info_bar, "response",
2211 G_CALLBACK (gtk_widget_destroy), NULL);
2213 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2214 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2215 gtk_widget_show_all (info_bar);
2219 media_stream_error_to_txt (EmpathyStreamedMediaWindow *self,
2220 EmpathyTpStreamedMedia *call,
2222 TpMediaStreamError error)
2224 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2231 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2233 return g_strdup_printf (
2234 _("%s's software does not understand any of the audio formats "
2235 "supported by your computer"),
2236 empathy_contact_get_alias (priv->contact));
2238 return g_strdup_printf (
2239 _("%s's software does not understand any of the video formats "
2240 "supported by your computer"),
2241 empathy_contact_get_alias (priv->contact));
2243 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2244 return g_strdup_printf (
2245 _("Can't establish a connection to %s. "
2246 "One of you might be on a network that does not allow "
2247 "direct connections."),
2248 empathy_contact_get_alias (priv->contact));
2250 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2251 return g_strdup (_("There was a failure on the network"));
2253 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2255 return g_strdup (_("The audio formats necessary for this call "
2256 "are not installed on your computer"));
2258 return g_strdup (_("The video formats necessary for this call "
2259 "are not installed on your computer"));
2261 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2262 cm = empathy_tp_streamed_media_get_connection_manager (call);
2264 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2265 "product=Telepathy&component=%s", cm);
2267 result = g_strdup_printf (
2268 _("Something unexpected happened in a Telepathy component. "
2269 "Please <a href=\"%s\">report this bug</a> and attach "
2270 "logs gathered from the 'Debug' window in the Help menu."), url);
2275 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2276 return g_strdup (_("There was a failure in the call engine"));
2278 case TP_MEDIA_STREAM_ERROR_EOS:
2279 return g_strdup (_("The end of the stream was reached"));
2281 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2288 empathy_streamed_media_window_stream_error (EmpathyStreamedMediaWindow *self,
2289 EmpathyTpStreamedMedia *call,
2298 desc = media_stream_error_to_txt (self, call, audio, code);
2301 /* No description, use the error message. That's not great as it's not
2302 * localized but it's better than nothing. */
2303 display_error (self, call, icon, title, msg, NULL);
2307 display_error (self, call, icon, title, desc, msg);
2313 empathy_streamed_media_window_audio_stream_error (EmpathyTpStreamedMedia *call,
2316 EmpathyStreamedMediaWindow *self)
2318 empathy_streamed_media_window_stream_error (self, call, TRUE, code, msg,
2319 "gnome-stock-mic", _("Can't establish audio stream"));
2323 empathy_streamed_media_window_video_stream_error (EmpathyTpStreamedMedia *call,
2326 EmpathyStreamedMediaWindow *self)
2328 empathy_streamed_media_window_stream_error (self, call, FALSE, code, msg,
2329 "camera-web", _("Can't establish video stream"));
2333 empathy_streamed_media_window_connected (gpointer user_data)
2335 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2336 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2337 EmpathyTpStreamedMedia *call;
2338 gboolean can_send_video;
2340 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2342 can_send_video = priv->video_input != NULL && priv->contact != NULL &&
2343 empathy_contact_can_voip_video (priv->contact);
2345 g_object_get (priv->handler, "tp-call", &call, NULL);
2347 tp_g_signal_connect_object (call, "notify::video-stream",
2348 G_CALLBACK (empathy_streamed_media_window_video_stream_changed_cb),
2351 if (empathy_tp_streamed_media_has_dtmf (call))
2352 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2354 if (priv->video_input == NULL)
2355 empathy_streamed_media_window_set_send_video (self, CAMERA_STATE_OFF);
2357 priv->sending_video = can_send_video ?
2358 empathy_tp_streamed_media_is_sending_video (call) : FALSE;
2360 gtk_toggle_tool_button_set_active (
2361 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on),
2362 priv->sending_video && priv->video_input != NULL);
2363 gtk_widget_set_sensitive (priv->tool_button_camera_on, can_send_video);
2364 gtk_action_set_sensitive (priv->action_camera_on, can_send_video);
2366 gtk_action_set_sensitive (priv->redial, FALSE);
2367 gtk_widget_set_sensitive (priv->redial_button, FALSE);
2369 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2371 empathy_streamed_media_window_update_avatars_visibility (call, self);
2373 g_object_unref (call);
2375 g_mutex_lock (priv->lock);
2377 priv->timer_id = g_timeout_add_seconds (1,
2378 empathy_streamed_media_window_update_timer, self);
2380 g_mutex_unlock (priv->lock);
2382 empathy_streamed_media_window_update_timer (self);
2384 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2390 /* Called from the streaming thread */
2392 empathy_streamed_media_window_src_added_cb (EmpathyStreamedMediaHandler *handler,
2393 GstPad *src, guint media_type, gpointer user_data)
2395 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2396 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2397 gboolean retval = FALSE;
2401 g_mutex_lock (priv->lock);
2403 if (priv->call_state != CONNECTED)
2405 g_timer_start (priv->timer);
2406 priv->timer_id = g_idle_add (empathy_streamed_media_window_connected, self);
2407 priv->call_state = CONNECTED;
2412 case TP_MEDIA_STREAM_TYPE_AUDIO:
2413 pad = empathy_streamed_media_window_get_audio_sink_pad (self);
2415 case TP_MEDIA_STREAM_TYPE_VIDEO:
2416 gtk_widget_hide (priv->remote_user_avatar_widget);
2417 gtk_widget_show (priv->video_output);
2418 pad = empathy_streamed_media_window_get_video_sink_pad (self);
2421 g_assert_not_reached ();
2427 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2428 g_warning ("Could not link %s sink pad",
2429 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2433 gst_object_unref (pad);
2437 /* If no sink could be linked, try to add fakesink to prevent the whole call
2442 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2444 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2446 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2447 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2448 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2450 gst_element_set_locked_state (fakesink, TRUE);
2451 gst_element_set_state (fakesink, GST_STATE_NULL);
2452 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2456 DEBUG ("Could not link real sink, linked fakesink instead");
2458 gst_object_unref (sinkpad);
2462 gst_object_unref (fakesink);
2467 g_mutex_unlock (priv->lock);
2473 empathy_streamed_media_window_sink_added_cb (EmpathyStreamedMediaHandler *handler,
2474 GstPad *sink, guint media_type, gpointer user_data)
2476 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2477 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2479 gboolean retval = FALSE;
2483 case TP_MEDIA_STREAM_TYPE_AUDIO:
2484 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2486 g_warning ("Could not add audio source to pipeline");
2490 pad = gst_element_get_static_pad (priv->audio_input, "src");
2493 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2494 g_warning ("Could not get source pad from audio source");
2498 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2500 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2501 g_warning ("Could not link audio source to farsight");
2505 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2507 g_warning ("Could not start audio source");
2508 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2509 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2515 case TP_MEDIA_STREAM_TYPE_VIDEO:
2516 if (priv->video_input != NULL)
2518 if (priv->video_tee != NULL)
2520 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2521 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2523 g_warning ("Could not link videp soure input pipeline");
2526 gst_object_unref (pad);
2533 g_assert_not_reached ();
2540 empathy_streamed_media_window_remove_video_input (EmpathyStreamedMediaWindow *self)
2542 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2543 GstElement *preview;
2545 disable_camera (self);
2547 DEBUG ("remove video input");
2548 preview = empathy_video_widget_get_element (
2549 EMPATHY_VIDEO_WIDGET (priv->video_preview));
2551 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2552 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2553 gst_element_set_state (preview, GST_STATE_NULL);
2555 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2556 priv->video_tee, preview, NULL);
2558 g_object_unref (priv->video_input);
2559 priv->video_input = NULL;
2560 g_object_unref (priv->video_tee);
2561 priv->video_tee = NULL;
2562 gtk_widget_destroy (priv->video_preview);
2563 priv->video_preview = NULL;
2565 gtk_widget_set_sensitive (priv->tool_button_camera_on, FALSE);
2566 gtk_action_set_sensitive (priv->action_camera_on, FALSE);
2567 gtk_widget_set_sensitive (priv->tool_button_camera_preview, FALSE);
2571 start_call (EmpathyStreamedMediaWindow *self)
2573 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2575 priv->call_started = TRUE;
2576 empathy_streamed_media_handler_start_call (priv->handler,
2577 empathy_get_current_action_time ());
2579 if (empathy_streamed_media_handler_has_initial_video (priv->handler))
2581 /* Enable 'send video' buttons and display the preview */
2582 gtk_toggle_tool_button_set_active (
2583 GTK_TOGGLE_TOOL_BUTTON (priv->tool_button_camera_on), TRUE);
2588 empathy_streamed_media_window_bus_message (GstBus *bus, GstMessage *message,
2591 EmpathyStreamedMediaWindow *self = EMPATHY_STREAMED_MEDIA_WINDOW (user_data);
2592 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2595 empathy_streamed_media_handler_bus_message (priv->handler, bus, message);
2597 switch (GST_MESSAGE_TYPE (message))
2599 case GST_MESSAGE_STATE_CHANGED:
2600 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2602 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2603 if (newstate == GST_STATE_PAUSED)
2604 empathy_streamed_media_window_setup_video_input (self);
2606 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2607 !priv->call_started)
2609 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2610 if (newstate == GST_STATE_PAUSED)
2612 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2613 priv->pipeline_playing = TRUE;
2615 if (priv->start_call_when_playing)
2620 case GST_MESSAGE_ERROR:
2622 GError *error = NULL;
2623 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 name = gst_element_get_name (gst_error);
2633 if (g_str_has_prefix (name, 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);
2645 g_error_free (error);
2648 case GST_MESSAGE_UNKNOWN:
2649 case GST_MESSAGE_EOS:
2650 case GST_MESSAGE_WARNING:
2651 case GST_MESSAGE_INFO:
2652 case GST_MESSAGE_TAG:
2653 case GST_MESSAGE_BUFFERING:
2654 case GST_MESSAGE_STATE_DIRTY:
2655 case GST_MESSAGE_STEP_DONE:
2656 case GST_MESSAGE_CLOCK_PROVIDE:
2657 case GST_MESSAGE_CLOCK_LOST:
2658 case GST_MESSAGE_NEW_CLOCK:
2659 case GST_MESSAGE_STRUCTURE_CHANGE:
2660 case GST_MESSAGE_STREAM_STATUS:
2661 case GST_MESSAGE_APPLICATION:
2662 case GST_MESSAGE_ELEMENT:
2663 case GST_MESSAGE_SEGMENT_START:
2664 case GST_MESSAGE_SEGMENT_DONE:
2665 case GST_MESSAGE_DURATION:
2666 case GST_MESSAGE_ANY:
2675 empathy_streamed_media_window_update_avatars_visibility (EmpathyTpStreamedMedia *call,
2676 EmpathyStreamedMediaWindow *window)
2678 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2680 if (empathy_tp_streamed_media_is_receiving_video (call))
2682 gtk_widget_hide (priv->remote_user_avatar_widget);
2683 gtk_widget_show (priv->video_output);
2687 gtk_widget_hide (priv->video_output);
2688 gtk_widget_show (priv->remote_user_avatar_widget);
2693 call_handler_notify_tp_streamed_media_cb (EmpathyStreamedMediaHandler *handler,
2695 EmpathyStreamedMediaWindow *self)
2697 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
2698 EmpathyTpStreamedMedia *call;
2700 g_object_get (priv->handler, "tp-call", &call, NULL);
2704 tp_g_signal_connect_object (call, "audio-stream-error",
2705 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), self, 0);
2706 tp_g_signal_connect_object (call, "video-stream-error",
2707 G_CALLBACK (empathy_streamed_media_window_video_stream_error), self, 0);
2709 g_object_unref (call);
2713 empathy_streamed_media_window_realized_cb (GtkWidget *widget, EmpathyStreamedMediaWindow *window)
2715 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2716 EmpathyTpStreamedMedia *call;
2718 g_signal_connect (priv->handler, "conference-added",
2719 G_CALLBACK (empathy_streamed_media_window_conference_added_cb), window);
2720 g_signal_connect (priv->handler, "start-receiving",
2721 G_CALLBACK (empathy_streamed_media_window_start_receiving_cb), window);
2722 g_signal_connect (priv->handler, "closed",
2723 G_CALLBACK (empathy_streamed_media_window_channel_closed_cb), window);
2724 g_signal_connect (priv->handler, "src-pad-added",
2725 G_CALLBACK (empathy_streamed_media_window_src_added_cb), window);
2726 g_signal_connect (priv->handler, "sink-pad-added",
2727 G_CALLBACK (empathy_streamed_media_window_sink_added_cb), window);
2728 g_signal_connect (priv->handler, "stream-closed",
2729 G_CALLBACK (empathy_streamed_media_window_channel_stream_closed_cb), window);
2731 g_object_get (priv->handler, "tp-call", &call, NULL);
2734 tp_g_signal_connect_object (call, "audio-stream-error",
2735 G_CALLBACK (empathy_streamed_media_window_audio_stream_error), window,
2737 tp_g_signal_connect_object (call, "video-stream-error",
2738 G_CALLBACK (empathy_streamed_media_window_video_stream_error), window,
2741 g_object_unref (call);
2745 /* tp-call doesn't exist yet, we'll connect signals once it has been
2747 g_signal_connect (priv->handler, "notify::tp-call",
2748 G_CALLBACK (call_handler_notify_tp_streamed_media_cb), window);
2751 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2755 empathy_streamed_media_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2756 EmpathyStreamedMediaWindow *window)
2758 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2760 if (priv->pipeline != NULL)
2762 if (priv->bus_message_source_id != 0)
2764 g_source_remove (priv->bus_message_source_id);
2765 priv->bus_message_source_id = 0;
2768 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2771 if (priv->call_state == CONNECTING)
2772 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2778 show_controls (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2781 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2783 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2788 gtk_widget_hide (priv->sidebar);
2789 gtk_widget_hide (menu);
2790 gtk_widget_hide (priv->vbox);
2791 gtk_widget_hide (priv->statusbar);
2792 gtk_widget_hide (priv->toolbar);
2796 if (priv->sidebar_was_visible_before_fs)
2797 gtk_widget_show (priv->sidebar);
2799 gtk_widget_show (menu);
2800 gtk_widget_show (priv->vbox);
2801 gtk_widget_show (priv->statusbar);
2802 gtk_widget_show (priv->toolbar);
2804 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2805 priv->original_height_before_fs);
2810 show_borders (EmpathyStreamedMediaWindow *window, gboolean set_fullscreen)
2812 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2814 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2815 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2816 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2817 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2819 if (priv->video_output != NULL)
2821 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2822 priv->video_output, TRUE, TRUE,
2823 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2827 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2828 priv->vbox, TRUE, TRUE,
2829 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2834 empathy_streamed_media_window_state_event_cb (GtkWidget *widget,
2835 GdkEventWindowState *event, EmpathyStreamedMediaWindow *window)
2837 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2839 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2840 gboolean set_fullscreen = event->new_window_state &
2841 GDK_WINDOW_STATE_FULLSCREEN;
2845 gboolean sidebar_was_visible;
2846 GtkAllocation allocation;
2847 gint original_width, original_height;
2849 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2850 original_width = allocation.width;
2851 original_height = allocation.height;
2853 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2855 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2856 priv->original_width_before_fs = original_width;
2857 priv->original_height_before_fs = original_height;
2859 if (priv->video_output_motion_handler_id == 0 &&
2860 priv->video_output != NULL)
2862 priv->video_output_motion_handler_id = g_signal_connect (
2863 G_OBJECT (priv->video_output), "motion-notify-event",
2864 G_CALLBACK (empathy_streamed_media_window_video_output_motion_notify),
2870 disconnect_video_output_motion_handler (window);
2873 empathy_streamed_media_window_fullscreen_set_fullscreen (priv->fullscreen,
2875 show_controls (window, set_fullscreen);
2876 show_borders (window, set_fullscreen);
2877 gtk_action_set_stock_id (priv->menu_fullscreen,
2878 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2879 priv->is_fullscreen = set_fullscreen;
2886 empathy_streamed_media_window_sidebar_toggled_cb (GtkToggleButton *toggle,
2887 EmpathyStreamedMediaWindow *window)
2889 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2891 int w, h, handle_size;
2892 GtkAllocation allocation, sidebar_allocation;
2894 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2895 w = allocation.width;
2896 h = allocation.height;
2898 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2900 gtk_widget_get_allocation (priv->sidebar, &sidebar_allocation);
2901 if (gtk_toggle_button_get_active (toggle))
2903 arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
2904 gtk_widget_show (priv->sidebar);
2905 w += sidebar_allocation.width + handle_size;
2909 arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
2910 w -= sidebar_allocation.width + handle_size;
2911 gtk_widget_hide (priv->sidebar);
2914 gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
2917 gtk_window_resize (GTK_WINDOW (window), w, h);
2921 empathy_streamed_media_window_set_send_video (EmpathyStreamedMediaWindow *window,
2924 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2925 EmpathyTpStreamedMedia *call;
2927 priv->sending_video = (state == CAMERA_STATE_ON);
2929 if (state == CAMERA_STATE_PREVIEW ||
2930 state == CAMERA_STATE_ON)
2932 /* When we start sending video, we want to show the video preview by
2934 display_video_preview (window, TRUE);
2938 display_video_preview (window, FALSE);
2941 if (priv->call_state != CONNECTED)
2944 g_object_get (priv->handler, "tp-call", &call, NULL);
2945 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
2946 empathy_tp_streamed_media_request_video_stream_direction (call, priv->sending_video);
2947 g_object_unref (call);
2951 empathy_streamed_media_window_mic_toggled_cb (GtkToggleToolButton *toggle,
2952 EmpathyStreamedMediaWindow *window)
2954 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2957 active = (gtk_toggle_tool_button_get_active (toggle));
2961 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2963 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
2967 /* TODO, Instead of setting the input volume to 0 we should probably
2968 * stop sending but this would cause the audio call to drop if both
2969 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
2970 * in the future. GNOME #574574
2972 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
2974 gtk_adjustment_set_value (priv->audio_input_adj, 0);
2979 empathy_streamed_media_window_sidebar_hidden_cb (EvSidebar *sidebar,
2980 EmpathyStreamedMediaWindow *window)
2982 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2984 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2989 empathy_streamed_media_window_sidebar_shown_cb (EvSidebar *sidebar,
2990 EmpathyStreamedMediaWindow *window)
2992 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
2994 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
2999 empathy_streamed_media_window_hangup_cb (gpointer object,
3000 EmpathyStreamedMediaWindow *window)
3002 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3004 empathy_streamed_media_handler_stop_call (priv->handler);
3006 if (empathy_streamed_media_window_disconnected (window, FALSE))
3007 gtk_widget_destroy (GTK_WIDGET (window));
3011 empathy_streamed_media_window_restart_call (EmpathyStreamedMediaWindow *window)
3013 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3015 /* Remove error info bars */
3016 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3017 (GtkCallback) gtk_widget_destroy, NULL);
3019 create_video_output_widget (window);
3021 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3022 G_CALLBACK (empathy_streamed_media_window_mic_volume_changed_cb), window);
3024 /* While the call was disconnected, the input volume might have changed.
3025 * However, since the audio_input source was destroyed, its volume has not
3026 * been updated during that time. That's why we manually update it here */
3027 empathy_streamed_media_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3029 priv->outgoing = TRUE;
3030 empathy_streamed_media_window_set_state_connecting (window);
3032 if (priv->pipeline_playing)
3033 start_call (window);
3035 /* call will be started when the pipeline is ready */
3036 priv->start_call_when_playing = TRUE;
3039 empathy_streamed_media_window_setup_avatars (window, priv->handler);
3041 gtk_action_set_sensitive (priv->redial, FALSE);
3042 gtk_widget_set_sensitive (priv->redial_button, FALSE);
3046 empathy_streamed_media_window_redial_cb (gpointer object,
3047 EmpathyStreamedMediaWindow *window)
3049 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3051 if (priv->call_state == CONNECTED)
3052 priv->call_state = REDIALING;
3054 empathy_streamed_media_handler_stop_call (priv->handler);
3056 if (priv->call_state != CONNECTED)
3057 empathy_streamed_media_window_restart_call (window);
3061 empathy_streamed_media_window_fullscreen_cb (gpointer object,
3062 EmpathyStreamedMediaWindow *window)
3064 empathy_streamed_media_window_fullscreen_toggle (window);
3068 empathy_streamed_media_window_fullscreen_toggle (EmpathyStreamedMediaWindow *window)
3070 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3072 if (priv->is_fullscreen)
3073 gtk_window_unfullscreen (GTK_WINDOW (window));
3075 gtk_window_fullscreen (GTK_WINDOW (window));
3079 empathy_streamed_media_window_video_button_press_cb (GtkWidget *video_output,
3080 GdkEventButton *event, EmpathyStreamedMediaWindow *window)
3082 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3084 empathy_streamed_media_window_video_menu_popup (window, event->button);
3092 empathy_streamed_media_window_key_press_cb (GtkWidget *video_output,
3093 GdkEventKey *event, EmpathyStreamedMediaWindow *window)
3095 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3097 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3099 /* Since we are in fullscreen mode, toggling will bring us back to
3101 empathy_streamed_media_window_fullscreen_toggle (window);
3109 empathy_streamed_media_window_video_output_motion_notify (GtkWidget *widget,
3110 GdkEventMotion *event, EmpathyStreamedMediaWindow *window)
3112 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3114 if (priv->is_fullscreen)
3116 empathy_streamed_media_window_fullscreen_show_popup (priv->fullscreen);
3123 empathy_streamed_media_window_video_menu_popup (EmpathyStreamedMediaWindow *window,
3127 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3129 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3131 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3132 button, gtk_get_current_event_time ());
3133 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3137 empathy_streamed_media_window_status_message (EmpathyStreamedMediaWindow *window,
3140 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3142 if (priv->context_id == 0)
3144 priv->context_id = gtk_statusbar_get_context_id (
3145 GTK_STATUSBAR (priv->statusbar), "voip call status messages");
3149 gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
3152 gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
3157 empathy_streamed_media_window_volume_changed_cb (GtkScaleButton *button,
3158 gdouble value, EmpathyStreamedMediaWindow *window)
3160 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (window);
3162 if (priv->audio_output == NULL)
3165 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3169 /* block all the signals related to camera control widgets. This is useful
3170 * when we are manually updating the UI and so don't want to fire the
3173 block_camera_control_signals (EmpathyStreamedMediaWindow *self)
3175 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3177 g_signal_handlers_block_by_func (priv->tool_button_camera_off,
3178 tool_button_camera_off_toggled_cb, self);
3179 g_signal_handlers_block_by_func (priv->tool_button_camera_preview,
3180 tool_button_camera_preview_toggled_cb, self);
3181 g_signal_handlers_block_by_func (priv->tool_button_camera_on,
3182 tool_button_camera_on_toggled_cb, self);
3183 g_signal_handlers_block_by_func (priv->action_camera_on,
3184 action_camera_change_cb, self);
3188 unblock_camera_control_signals (EmpathyStreamedMediaWindow *self)
3190 EmpathyStreamedMediaWindowPriv *priv = GET_PRIV (self);
3192 g_signal_handlers_unblock_by_func (priv->tool_button_camera_off,
3193 tool_button_camera_off_toggled_cb, self);
3194 g_signal_handlers_unblock_by_func (priv->tool_button_camera_preview,
3195 tool_button_camera_preview_toggled_cb, self);
3196 g_signal_handlers_unblock_by_func (priv->tool_button_camera_on,
3197 tool_button_camera_on_toggled_cb, self);
3198 g_signal_handlers_unblock_by_func (priv->action_camera_on,
3199 action_camera_change_cb, self);