From 26b6bf69aab8e805d3fe5dacc8053bdb6eed5358 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 3 May 2020 16:33:45 +0200 Subject: [PATCH] Advertise format with alpha channel stripped --- include/screencast_common.h | 4 +++- src/screencast/pipewire_screencast.c | 16 ++++++++++++---- src/screencast/screencast_common.c | 20 +++++++++++++++++--- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/screencast_common.h b/include/screencast_common.h index a129a46..ea40d40 100644 --- a/include/screencast_common.h +++ b/include/screencast_common.h @@ -108,6 +108,8 @@ struct xdpw_wlr_output { }; void randname(char *buf); -uint32_t xdpw_format_pw_from_wl_shm(void *data); +enum spa_video_format xdpw_format_pw_from_wl_shm( + struct xdpw_screencast_instance *cast); +enum spa_video_format xdpw_format_pw_strip_alpha(enum spa_video_format format); #endif /* SCREENCAST_COMMON_H */ diff --git a/src/screencast/pipewire_screencast.c b/src/screencast/pipewire_screencast.c index 8ed643c..f88af91 100644 --- a/src/screencast/pipewire_screencast.c +++ b/src/screencast/pipewire_screencast.c @@ -141,7 +141,6 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) { pw_loop_enter(state->pw_loop); - const struct spa_pod *params[1]; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); @@ -163,11 +162,20 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) { pw_loop_add_event(state->pw_loop, pwr_on_event, cast); logprint(DEBUG, "pipewire: registered event %p", cast->event); - params[0] = spa_pod_builder_add_object(&b, + enum spa_video_format format = xdpw_format_pw_from_wl_shm(cast); + enum spa_video_format format_without_alpha = + xdpw_format_pw_strip_alpha(format); + uint32_t n_formats = 1; + if (format_without_alpha != SPA_VIDEO_FORMAT_UNKNOWN) { + n_formats++; + } + + const struct spa_pod *param = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video), SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw), - SPA_FORMAT_VIDEO_format, SPA_POD_Id(xdpw_format_pw_from_wl_shm(cast)), + SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(n_formats + 1, + format, format, format_without_alpha), SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle( &SPA_RECTANGLE(cast->simple_frame.width, cast->simple_frame.height), &SPA_RECTANGLE(1, 1), @@ -187,7 +195,7 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) { PW_ID_ANY, (PW_STREAM_FLAG_DRIVER | PW_STREAM_FLAG_MAP_BUFFERS), - params, 1); + ¶m, 1); } diff --git a/src/screencast/screencast_common.c b/src/screencast/screencast_common.c index f80e77e..a7162fe 100644 --- a/src/screencast/screencast_common.c +++ b/src/screencast/screencast_common.c @@ -12,9 +12,8 @@ void randname(char *buf) { } } -enum spa_video_format xdpw_format_pw_from_wl_shm(void *data) { - struct xdpw_screencast_instance *cast = data; - +enum spa_video_format xdpw_format_pw_from_wl_shm( + struct xdpw_screencast_instance *cast) { if (cast->ctx->forced_pixelformat) { if (strcmp(cast->ctx->forced_pixelformat, "BGRx") == 0) { return SPA_VIDEO_FORMAT_BGRx; @@ -47,3 +46,18 @@ enum spa_video_format xdpw_format_pw_from_wl_shm(void *data) { abort(); } } + +enum spa_video_format xdpw_format_pw_strip_alpha(enum spa_video_format format) { + switch (format) { + case SPA_VIDEO_FORMAT_BGRA: + return SPA_VIDEO_FORMAT_BGRx; + case SPA_VIDEO_FORMAT_ABGR: + return SPA_VIDEO_FORMAT_xBGR; + case SPA_VIDEO_FORMAT_RGBA: + return SPA_VIDEO_FORMAT_RGBx; + case SPA_VIDEO_FORMAT_ARGB: + return SPA_VIDEO_FORMAT_xRGB; + default: + return SPA_VIDEO_FORMAT_UNKNOWN; + } +}