From 566fb7c1a02c04d1f2e7032822c51b3c2ff137af Mon Sep 17 00:00:00 2001 From: columbarius Date: Thu, 27 May 2021 20:45:19 +0200 Subject: [PATCH] screencast: pipewire add import_wl_shm_buffer function This function lets us create a wl_buffer from any shared memory filedescriptor. --- include/screencast_common.h | 2 ++ src/screencast/screencast_common.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/screencast_common.h b/include/screencast_common.h index 9b5ce66..ebbc1c4 100644 --- a/include/screencast_common.h +++ b/include/screencast_common.h @@ -123,6 +123,8 @@ struct xdpw_wlr_output { void randname(char *buf); int anonymous_shm_open(void); +struct wl_buffer *import_wl_shm_buffer(struct xdpw_screencast_instance *cast, int fd, + enum wl_shm_format fmt, int width, int height, int stride); enum spa_video_format xdpw_format_pw_from_wl_shm(enum wl_shm_format format); enum spa_video_format xdpw_format_pw_strip_alpha(enum spa_video_format format); diff --git a/src/screencast/screencast_common.c b/src/screencast/screencast_common.c index 915a585..d161d17 100644 --- a/src/screencast/screencast_common.c +++ b/src/screencast/screencast_common.c @@ -36,6 +36,23 @@ int anonymous_shm_open(void) { return -1; } +struct wl_buffer *import_wl_shm_buffer(struct xdpw_screencast_instance *cast, int fd, + enum wl_shm_format fmt, int width, int height, int stride) { + struct xdpw_screencast_context *ctx = cast->ctx; + int size = stride * height; + + if (fd < 0) { + return NULL; + } + + struct wl_shm_pool *pool = wl_shm_create_pool(ctx->shm, fd, size); + struct wl_buffer *buffer = + wl_shm_pool_create_buffer(pool, 0, width, height, stride, fmt); + wl_shm_pool_destroy(pool); + + return buffer; +} + enum spa_video_format xdpw_format_pw_from_wl_shm(enum wl_shm_format format) { switch (format) { case WL_SHM_FORMAT_ARGB8888: