From 037077bb56408d3f982fa7de5fd587d0d611e579 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Mon, 26 Feb 2024 11:45:34 +0100 Subject: [PATCH] screen-cast-stream-src: Always advertise support for BGRA Some clients - notably the Gstreamer vapostproc element when using Intel GPUs - only support BGRA, not BGRx. We already assume that we can support this format for window screen casts, and even in case of failure we now have a re-negotiation fallback in place. Thus it's pretty safe to support it for all screen cast types. The possible duplication in case of window screen casts doesn't seem to be a problem for either Pipewire or existing clients like OBS. Note that the implementation lays the foundation to make it easy to add more formats in the future. Part-of: --- src/backends/meta-screen-cast-stream-src.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c index fe3bca889..9fc872e2b 100644 --- a/src/backends/meta-screen-cast-stream-src.c +++ b/src/backends/meta-screen-cast-stream-src.c @@ -992,10 +992,9 @@ build_format_params (MetaScreenCastStreamSrc *src, MetaScreenCast *screen_cast = meta_screen_cast_session_get_screen_cast (session); GArray *modifiers; - CoglPixelFormat preferred_cogl_format = - meta_screen_cast_stream_src_get_preferred_format (src); - enum spa_video_format preferred_spa_video_format; - enum spa_video_format spa_video_formats[2]; + CoglPixelFormat preferred_cogl_format; + enum spa_video_format preferred_spa_video_format = 0; + enum spa_video_format spa_video_formats[G_N_ELEMENTS (supported_formats)]; int n_spa_video_formats = 0; struct spa_rectangle default_size = DEFAULT_SIZE; struct spa_rectangle min_size = MIN_SIZE; @@ -1022,14 +1021,16 @@ build_format_params (MetaScreenCastStreamSrc *src, min_size = max_size = default_size = SPA_RECTANGLE (width, height); } - if (preferred_cogl_format != DEFAULT_COGL_PIXEL_FORMAT && - spa_video_format_from_cogl_pixel_format (preferred_cogl_format, + preferred_cogl_format = meta_screen_cast_stream_src_get_preferred_format (src); + if (spa_video_format_from_cogl_pixel_format (preferred_cogl_format, &preferred_spa_video_format)) - { - spa_video_formats[n_spa_video_formats++] = preferred_spa_video_format; - } + spa_video_formats[n_spa_video_formats++] = preferred_spa_video_format; - spa_video_formats[n_spa_video_formats++] = SPA_VIDEO_FORMAT_BGRx; + for (i = 0; i < G_N_ELEMENTS (supported_formats); i++) + { + if (supported_formats[i].spa_video_format != preferred_spa_video_format) + spa_video_formats[n_spa_video_formats++] = supported_formats[i].spa_video_format; + } g_assert (n_spa_video_formats > 0 && n_spa_video_formats <= G_N_ELEMENTS (spa_video_formats));