From 3d7663f417d92d20576ccc7fe455d11e25ebf5a9 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 7 Apr 2022 09:31:15 -0300 Subject: [PATCH] linux-pipewire: Explicitly enumerate portal capture types This is very much like previous commit, but there's a catch: there already was an enumeration in place, which is replaced in this commit. The obs_pw_capture_type enum was introduced before splitting the portal code into a separate file, and the enum itself is specific to the screencast portal, so the appropriate place to enumerate it is in portal.h. For completude, PORTAL_CAPTURE_TYPE_VIRTUAL was added to the enum, even though we never used, and probably never will. The values are still the same, since both the old and this new enum were extracted from the screencast portal [1]. https://github.com/flatpak/xdg-desktop-portal/blob/main/data/org.freedesktop.portal.ScreenCast.xml#L290-300 --- plugins/linux-pipewire/pipewire-capture.c | 17 ++++++++++------- plugins/linux-pipewire/pipewire.c | 15 +++++++++------ plugins/linux-pipewire/pipewire.h | 11 ++++------- plugins/linux-pipewire/portal.h | 6 ++++++ 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/plugins/linux-pipewire/pipewire-capture.c b/plugins/linux-pipewire/pipewire-capture.c index 70f03164c..130771491 100644 --- a/plugins/linux-pipewire/pipewire-capture.c +++ b/plugins/linux-pipewire/pipewire-capture.c @@ -38,12 +38,14 @@ static const char *pipewire_window_capture_get_name(void *data) static void *pipewire_desktop_capture_create(obs_data_t *settings, obs_source_t *source) { - return obs_pipewire_create(DESKTOP_CAPTURE, settings, source); + return obs_pipewire_create(PORTAL_CAPTURE_TYPE_MONITOR, settings, + source); } static void *pipewire_window_capture_create(obs_data_t *settings, obs_source_t *source) { - return obs_pipewire_create(WINDOW_CAPTURE, settings, source); + return obs_pipewire_create(PORTAL_CAPTURE_TYPE_WINDOW, settings, + source); } static void pipewire_capture_destroy(void *data) @@ -63,18 +65,19 @@ static void pipewire_capture_get_defaults(obs_data_t *settings) static obs_properties_t *pipewire_capture_get_properties(void *data) { - enum obs_pw_capture_type capture_type; + enum portal_capture_type capture_type; obs_pipewire_data *obs_pw = data; capture_type = obs_pipewire_get_capture_type(obs_pw); switch (capture_type) { - case DESKTOP_CAPTURE: + case PORTAL_CAPTURE_TYPE_MONITOR: return obs_pipewire_get_properties(data, "PipeWireSelectMonitor"); - case WINDOW_CAPTURE: + case PORTAL_CAPTURE_TYPE_WINDOW: return obs_pipewire_get_properties(data, "PipeWireSelectWindow"); + case PORTAL_CAPTURE_TYPE_VIRTUAL: default: return NULL; } @@ -116,9 +119,9 @@ void pipewire_capture_load(void) { uint32_t available_capture_types = portal_get_available_capture_types(); bool desktop_capture_available = - (available_capture_types & DESKTOP_CAPTURE) != 0; + (available_capture_types & PORTAL_CAPTURE_TYPE_MONITOR) != 0; bool window_capture_available = - (available_capture_types & WINDOW_CAPTURE) != 0; + (available_capture_types & PORTAL_CAPTURE_TYPE_WINDOW) != 0; if (available_capture_types == 0) { blog(LOG_INFO, "[pipewire] No captures available"); diff --git a/plugins/linux-pipewire/pipewire.c b/plugins/linux-pipewire/pipewire.c index f07f22a13..616640d54 100644 --- a/plugins/linux-pipewire/pipewire.c +++ b/plugins/linux-pipewire/pipewire.c @@ -106,7 +106,7 @@ struct _obs_pipewire_data { gs_texture_t *texture; } cursor; - enum obs_pw_capture_type capture_type; + enum portal_capture_type capture_type; struct obs_video_info video_info; bool negotiated; @@ -151,13 +151,16 @@ static void update_pw_versions(obs_pipewire_data *obs_pw, const char *version) blog(LOG_WARNING, "[pipewire] failed to parse server version"); } -static const char *capture_type_to_string(enum obs_pw_capture_type capture_type) +static const char *capture_type_to_string(enum portal_capture_type capture_type) { switch (capture_type) { - case DESKTOP_CAPTURE: + case PORTAL_CAPTURE_TYPE_MONITOR: return "desktop"; - case WINDOW_CAPTURE: + case PORTAL_CAPTURE_TYPE_WINDOW: return "window"; + case PORTAL_CAPTURE_TYPE_VIRTUAL: + default: + return "unknown"; } return "unknown"; } @@ -1400,7 +1403,7 @@ static bool reload_session_cb(obs_properties_t *properties, /* obs_source_info methods */ -void *obs_pipewire_create(enum obs_pw_capture_type capture_type, +void *obs_pipewire_create(enum portal_capture_type capture_type, obs_data_t *settings, obs_source_t *source) { obs_pipewire_data *obs_pw = bzalloc(sizeof(obs_pipewire_data)); @@ -1535,7 +1538,7 @@ void obs_pipewire_video_render(obs_pipewire_data *obs_pw, gs_effect_t *effect) } } -enum obs_pw_capture_type +enum portal_capture_type obs_pipewire_get_capture_type(obs_pipewire_data *obs_pw) { return obs_pw->capture_type; diff --git a/plugins/linux-pipewire/pipewire.h b/plugins/linux-pipewire/pipewire.h index 88ec76f37..ebdf27292 100644 --- a/plugins/linux-pipewire/pipewire.h +++ b/plugins/linux-pipewire/pipewire.h @@ -23,14 +23,11 @@ #include #include +#include "portal.h" + typedef struct _obs_pipewire_data obs_pipewire_data; -enum obs_pw_capture_type { - DESKTOP_CAPTURE = 1, - WINDOW_CAPTURE = 2, -}; - -void *obs_pipewire_create(enum obs_pw_capture_type capture_type, +void *obs_pipewire_create(enum portal_capture_type capture_type, obs_data_t *settings, obs_source_t *source); void obs_pipewire_destroy(obs_pipewire_data *obs_pw); @@ -50,5 +47,5 @@ uint32_t obs_pipewire_get_width(obs_pipewire_data *obs_pw); uint32_t obs_pipewire_get_height(obs_pipewire_data *obs_pw); void obs_pipewire_video_render(obs_pipewire_data *obs_pw, gs_effect_t *effect); -enum obs_pw_capture_type +enum portal_capture_type obs_pipewire_get_capture_type(obs_pipewire_data *obs_pw); diff --git a/plugins/linux-pipewire/portal.h b/plugins/linux-pipewire/portal.h index 8e4456af1..85ad56732 100644 --- a/plugins/linux-pipewire/portal.h +++ b/plugins/linux-pipewire/portal.h @@ -23,6 +23,12 @@ #include #include +enum portal_capture_type { + PORTAL_CAPTURE_TYPE_MONITOR = 1 << 0, + PORTAL_CAPTURE_TYPE_WINDOW = 1 << 1, + PORTAL_CAPTURE_TYPE_VIRTUAL = 1 << 2, +}; + enum portal_cursor_mode { PORTAL_CURSOR_MODE_HIDDEN = 1 << 0, PORTAL_CURSOR_MODE_EMBEDDED = 1 << 1,