Commit dc80d86a authored by Vivien Didelot's avatar Vivien Didelot Committed by Gerrit Code Review

gnome: rework the switch source functions

- Refactor the logic inside the getter functions for the input source
  functions.
- Use the glib everywhere.
- Remove some memory leaks.
- Add a sflphone_toggle_camera() function to switch between the
  active_device and the none.

Change-Id: Iae83c5b4922722c8914ba9339c6d53b8e9ef53d8
Refs: #45417
parent 1e07ba05
......@@ -1014,30 +1014,42 @@ sflphone_call_state_changed(callable_obj_t * c, const gchar * description, const
}
#ifdef SFL_VIDEO
char *
gchar *
sflphone_get_display(void)
{
int width = gdk_screen_width();
int height = gdk_screen_height();
char *display = getenv("DISPLAY");
char resource[256];
sprintf(resource, "display://%s %dx%d", display, width, height);
return g_strdup(resource);
return g_strdup_printf("display://%s %dx%d", display, width, height);
}
gchar *
sflphone_get_active_video(void)
{
gchar *device = dbus_get_active_video_device();
gchar *resource = g_strconcat("v4l2://", device, NULL);
g_free(device);
return resource;
}
gchar *
sflphone_get_video_none(void)
{
return g_strconcat("file://", ICONS_DIR, "/sflphone.png", NULL);
}
void
sflphone_toggle_screenshare(void)
{
static gboolean screenshare = TRUE;
gchar *resource;
gchar *resource = NULL;
if (screenshare) {
resource = sflphone_get_display();
} else {
gchar *device = dbus_get_active_video_device();
resource = g_strconcat("v4l2://", device, NULL);
g_free(device);
resource = sflphone_get_active_video();
}
if (dbus_switch_video_input(resource)) {
......@@ -1049,4 +1061,27 @@ sflphone_toggle_screenshare(void)
g_free(resource);
}
void
sflphone_toggle_camera(void)
{
static gboolean camera_toggle = TRUE;
gchar *resource = NULL;
if (camera_toggle) {
resource = sflphone_get_video_none();
} else {
resource = sflphone_get_active_video();
}
if (dbus_switch_video_input(resource)) {
g_debug("switched video input to '%s'", resource);
camera_toggle = !camera_toggle;
} else {
g_error("failed to switch to resource '%s'\n", resource);
}
g_free(resource);
}
#endif
......@@ -261,8 +261,14 @@ void sflphone_srtp_sdes_off(callable_obj_t * c, SFLPhoneClient *client);
void sflphone_fill_conference_list(SFLPhoneClient *client);
char *sflphone_get_display(void);
gchar * sflphone_get_display(void);
gchar * sflphone_get_active_video(void);
gchar * sflphone_get_video_none(void);
void sflphone_toggle_screenshare(void);
void sflphone_toggle_camera(void);
#endif
......@@ -691,23 +691,20 @@ call_screenshare(G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED SFLPhoneClient *
static void
call_switch_video_input(G_GNUC_UNUSED GtkWidget *widget, gchar *device)
{
gboolean switched;
gchar *resource;
gchar *resource = NULL;
if (g_strcmp0(device, "None") == 0) {
resource = g_strconcat("file://", ICONS_DIR "/sflphone.png", NULL);
switched = dbus_switch_video_input(resource);
resource = sflphone_get_video_none();
} else if (g_strcmp0(device, "Screen") == 0) {
resource = sflphone_get_display();
switched = dbus_switch_video_input(resource);
} else {
dbus_set_active_video_device(device);
resource = g_strconcat("v4l2://", device, NULL);
switched = dbus_switch_video_input(resource);
resource = g_strconcat("v4l2://", device, NULL);
}
if (!switched)
g_warning("Failed to switch to '%s' (MRL '%s')\n", device, resource);
if (!dbus_switch_video_input(resource))
g_error("failed to switch to '%s' (MRL '%s')\n", device, resource);
g_free(resource);
}
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment