From d4b035815c18f178ae58f6a270bf6e30176cf740 Mon Sep 17 00:00:00 2001 From: columbarius Date: Thu, 17 Sep 2020 00:57:04 +0200 Subject: [PATCH] Offer video modifier --- include/screencast_common.h | 1 + src/screencast/pipewire_screencast.c | 60 ++++++++++++++++++++-------- src/screencast/wlr_screencopy.c | 1 + 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/include/screencast_common.h b/include/screencast_common.h index 483f2e8e..5de8f4ba 100644 --- a/include/screencast_common.h +++ b/include/screencast_common.h @@ -60,6 +60,7 @@ struct xdpw_screencopy_frame { void *data; uint32_t fourcc; + uint64_t modifier; struct gbm_bo *bo; uint32_t offset; int fd; diff --git a/src/screencast/pipewire_screencast.c b/src/screencast/pipewire_screencast.c index cea27ef3..7f941bb6 100644 --- a/src/screencast/pipewire_screencast.c +++ b/src/screencast/pipewire_screencast.c @@ -220,22 +220,50 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) { 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_CHOICE_ENUM_Id(n_formats + 1, - format, format, format_without_alpha), - SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle( - &SPA_RECTANGLE(cast->xdpw_frames.simple_frame.width, cast->xdpw_frames.simple_frame.height), - &SPA_RECTANGLE(1, 1), - &SPA_RECTANGLE(4096, 4096)), - // variable framerate - SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&SPA_FRACTION(0, 1)), - SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_CHOICE_RANGE_Fraction( - &SPA_FRACTION(cast->framerate, 1), - &SPA_FRACTION(1, 1), - &SPA_FRACTION(cast->framerate, 1))); + logprint(DEBUG, "pipewire: Supported format %d", format); + + const struct spa_pod *param; + switch (cast->type) { + case XDPW_INSTANCE_SCP_SHM: + 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_CHOICE_ENUM_Id(n_formats + 1, + format, format, format_without_alpha), + SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle( + &SPA_RECTANGLE(cast->xdpw_frames.simple_frame.width, cast->xdpw_frames.simple_frame.height), + &SPA_RECTANGLE(1, 1), + &SPA_RECTANGLE(4096, 4096)), + // variable framerate + SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&SPA_FRACTION(0, 1)), + SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_CHOICE_RANGE_Fraction( + &SPA_FRACTION(cast->framerate, 1), + &SPA_FRACTION(1, 1), + &SPA_FRACTION(cast->framerate, 1))); + break; + case XDPW_INSTANCE_SCP_DMABUF: + 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_CHOICE_ENUM_Id(n_formats + 1, + format, format, format_without_alpha), + SPA_FORMAT_VIDEO_modifier, SPA_POD_CHOICE_ENUM_Long(1,cast->xdpw_frames.screencopy_frame.modifier), + SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle( + &SPA_RECTANGLE(cast->xdpw_frames.simple_frame.width, cast->xdpw_frames.simple_frame.height), + &SPA_RECTANGLE(1, 1), + &SPA_RECTANGLE(4096, 4096)), + // variable framerate + SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&SPA_FRACTION(0, 1)), + SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_CHOICE_RANGE_Fraction( + &SPA_FRACTION(cast->framerate, 1), + &SPA_FRACTION(1, 1), + &SPA_FRACTION(cast->framerate, 1))); + break; + default: + abort(); + } pw_stream_add_listener(cast->stream, &cast->stream_listener, &pwr_stream_events, cast); diff --git a/src/screencast/wlr_screencopy.c b/src/screencast/wlr_screencopy.c index 9ba3699b..33d35e57 100644 --- a/src/screencast/wlr_screencopy.c +++ b/src/screencast/wlr_screencopy.c @@ -93,6 +93,7 @@ static void wlr_frame_linux_dmabuf(void *data, cast->xdpw_frames.screencopy_frame.size = cast->xdpw_frames.screencopy_frame.stride * height; cast->xdpw_frames.screencopy_frame.offset = gbm_bo_get_offset(cast->xdpw_frames.screencopy_frame.bo, 0); cast->xdpw_frames.screencopy_frame.fd = gbm_bo_get_fd(cast->xdpw_frames.screencopy_frame.bo); + cast->xdpw_frames.screencopy_frame.modifier = gbm_bo_get_modifier(cast->xdpw_frames.screencopy_frame.bo); } else { logprint(TRACE,"wlroots: dmabuf buffer exists"); }