Skip to content
Snippets Groups Projects
Commit dc80d86a authored by Vivien Didelot's avatar Vivien Didelot Committed by Gerrit Code Review
Browse files

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
Branches
Tags
No related merge requests found
...@@ -1014,30 +1014,42 @@ sflphone_call_state_changed(callable_obj_t * c, const gchar * description, const ...@@ -1014,30 +1014,42 @@ sflphone_call_state_changed(callable_obj_t * c, const gchar * description, const
} }
#ifdef SFL_VIDEO #ifdef SFL_VIDEO
char * gchar *
sflphone_get_display(void) sflphone_get_display(void)
{ {
int width = gdk_screen_width(); int width = gdk_screen_width();
int height = gdk_screen_height(); int height = gdk_screen_height();
char *display = getenv("DISPLAY"); char *display = getenv("DISPLAY");
char resource[256];
sprintf(resource, "display://%s %dx%d", display, width, height); return g_strdup_printf("display://%s %dx%d", display, width, height);
return g_strdup(resource); }
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 void
sflphone_toggle_screenshare(void) sflphone_toggle_screenshare(void)
{ {
static gboolean screenshare = TRUE; static gboolean screenshare = TRUE;
gchar *resource; gchar *resource = NULL;
if (screenshare) { if (screenshare) {
resource = sflphone_get_display(); resource = sflphone_get_display();
} else { } else {
gchar *device = dbus_get_active_video_device(); resource = sflphone_get_active_video();
resource = g_strconcat("v4l2://", device, NULL);
g_free(device);
} }
if (dbus_switch_video_input(resource)) { if (dbus_switch_video_input(resource)) {
...@@ -1049,4 +1061,27 @@ sflphone_toggle_screenshare(void) ...@@ -1049,4 +1061,27 @@ sflphone_toggle_screenshare(void)
g_free(resource); 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 #endif
...@@ -261,8 +261,14 @@ void sflphone_srtp_sdes_off(callable_obj_t * c, SFLPhoneClient *client); ...@@ -261,8 +261,14 @@ void sflphone_srtp_sdes_off(callable_obj_t * c, SFLPhoneClient *client);
void sflphone_fill_conference_list(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_screenshare(void);
void sflphone_toggle_camera(void);
#endif #endif
...@@ -691,23 +691,20 @@ call_screenshare(G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED SFLPhoneClient * ...@@ -691,23 +691,20 @@ call_screenshare(G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED SFLPhoneClient *
static void static void
call_switch_video_input(G_GNUC_UNUSED GtkWidget *widget, gchar *device) call_switch_video_input(G_GNUC_UNUSED GtkWidget *widget, gchar *device)
{ {
gboolean switched; gchar *resource = NULL;
gchar *resource;
if (g_strcmp0(device, "None") == 0) { if (g_strcmp0(device, "None") == 0) {
resource = g_strconcat("file://", ICONS_DIR "/sflphone.png", NULL); resource = sflphone_get_video_none();
switched = dbus_switch_video_input(resource);
} else if (g_strcmp0(device, "Screen") == 0) { } else if (g_strcmp0(device, "Screen") == 0) {
resource = sflphone_get_display(); resource = sflphone_get_display();
switched = dbus_switch_video_input(resource);
} else { } else {
dbus_set_active_video_device(device); dbus_set_active_video_device(device);
resource = g_strconcat("v4l2://", device, NULL); resource = g_strconcat("v4l2://", device, NULL);
switched = dbus_switch_video_input(resource);
} }
if (!switched) if (!dbus_switch_video_input(resource))
g_warning("Failed to switch to '%s' (MRL '%s')\n", device, resource); g_error("failed to switch to '%s' (MRL '%s')\n", device, resource);
g_free(resource); g_free(resource);
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment