From 44ac873100de5660ee56d1427cd3090aea4f7cb0 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 3 Sep 2021 10:22:31 +0200 Subject: [PATCH] wlgrab: Fix ram (software encoding) snapshot --- sunshine/platform/linux/wayland.cpp | 25 ++++++++++++++++--------- sunshine/platform/linux/wayland.h | 2 +- sunshine/platform/linux/wlgrab.cpp | 3 +-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sunshine/platform/linux/wayland.cpp b/sunshine/platform/linux/wayland.cpp index 65f845a5..44be6dc1 100644 --- a/sunshine/platform/linux/wayland.cpp +++ b/sunshine/platform/linux/wayland.cpp @@ -164,11 +164,14 @@ void dmabuf_t::frame( std::uint32_t obj_count) { auto next_frame = get_next_frame(); - next_frame->sd.fourcc = format; - next_frame->sd.width = width; - next_frame->sd.height = height; - next_frame->sd.modifier = (((std::uint64_t)high) << 32) | low; - next_frame->obj_count = obj_count; + next_frame->sd.fourcc = format; + next_frame->sd.width = width; + next_frame->sd.height = height; + next_frame->sd.modifier = (((std::uint64_t)high) << 32) | low; + next_frame->sd.obj_count = obj_count; + + next_frame->close_fds = true; + std::fill_n(next_frame->sd.fds + obj_count, 4 - obj_count, -1); } void dmabuf_t::object( @@ -212,11 +215,15 @@ void dmabuf_t::cancel( } void frame_t::destroy() { - for(auto x = 0; x < obj_count; ++x) { - close(sd.fds[x]); + if(!close_fds) { + return; } - - obj_count = 0; + for(auto x = 0; x < 4; ++x) { + if(sd.fds[x] >= 0) { + close(sd.fds[x]); + } + } + close_fds = false; } std::vector> monitors(const char *display_name) { diff --git a/sunshine/platform/linux/wayland.h b/sunshine/platform/linux/wayland.h index 34d7a365..bf138a0a 100644 --- a/sunshine/platform/linux/wayland.h +++ b/sunshine/platform/linux/wayland.h @@ -23,7 +23,7 @@ class frame_t { public: egl::surface_descriptor_t sd; - std::uint32_t obj_count; + bool close_fds = false; void destroy(); }; diff --git a/sunshine/platform/linux/wlgrab.cpp b/sunshine/platform/linux/wlgrab.cpp index 592594ae..2e2320a1 100644 --- a/sunshine/platform/linux/wlgrab.cpp +++ b/sunshine/platform/linux/wlgrab.cpp @@ -261,10 +261,9 @@ public: img->sequence = sequence; img->sd = current_frame->sd; - img->sd.obj_count = current_frame->obj_count; // Prevent dmabuf from closing the file descriptors. - current_frame->obj_count = 0; + current_frame->close_fds = false; return platf::capture_e::ok; }