Fix segfault for wlroots based capturing

This commit is contained in:
Loki
2021-08-29 09:34:00 +02:00
parent b80c4253f0
commit 06a1119512
3 changed files with 26 additions and 10 deletions
+5 -6
View File
@@ -168,7 +168,6 @@ void dmabuf_t::frame(
next_frame->width = width; next_frame->width = width;
next_frame->height = height; next_frame->height = height;
next_frame->obj_count = obj_count; next_frame->obj_count = obj_count;
next_frame->frame = frame;
} }
void dmabuf_t::object( void dmabuf_t::object(
@@ -192,6 +191,8 @@ void dmabuf_t::ready(
zwlr_export_dmabuf_frame_v1 *frame, zwlr_export_dmabuf_frame_v1 *frame,
std::uint32_t tv_sec_hi, std::uint32_t tv_sec_lo, std::uint32_t tv_nsec) { std::uint32_t tv_sec_hi, std::uint32_t tv_sec_lo, std::uint32_t tv_nsec) {
zwlr_export_dmabuf_frame_v1_destroy(frame);
current_frame->destroy(); current_frame->destroy();
current_frame = get_next_frame(); current_frame = get_next_frame();
@@ -201,6 +202,9 @@ void dmabuf_t::ready(
void dmabuf_t::cancel( void dmabuf_t::cancel(
zwlr_export_dmabuf_frame_v1 *frame, zwlr_export_dmabuf_frame_v1 *frame,
zwlr_export_dmabuf_frame_v1_cancel_reason reason) { zwlr_export_dmabuf_frame_v1_cancel_reason reason) {
zwlr_export_dmabuf_frame_v1_destroy(frame);
auto next_frame = get_next_frame(); auto next_frame = get_next_frame();
next_frame->destroy(); next_frame->destroy();
@@ -208,15 +212,10 @@ void dmabuf_t::cancel(
} }
void frame_t::destroy() { void frame_t::destroy() {
if(frame) {
zwlr_export_dmabuf_frame_v1_destroy(frame);
}
for(auto x = 0; x < obj_count; ++x) { for(auto x = 0; x < obj_count; ++x) {
close(fds[x]); close(fds[x]);
} }
frame = nullptr;
obj_count = 0; obj_count = 0;
} }
-2
View File
@@ -22,8 +22,6 @@ public:
std::uint32_t offsets[4]; std::uint32_t offsets[4];
std::uint32_t plane_indices[4]; std::uint32_t plane_indices[4];
zwlr_export_dmabuf_frame_v1 *frame;
void destroy(); void destroy();
}; };
+21 -2
View File
@@ -16,6 +16,21 @@ struct img_t : public platf::img_t {
} }
}; };
class frame_descriptor_t : public egl::img_descriptor_t {
public:
~frame_descriptor_t() {
reset();
}
void reset() {
std::for_each_n(fds, obj_count, [](int fd) {
close(fd);
});
obj_count = 0;
}
};
class wlr_t : public platf::display_t { class wlr_t : public platf::display_t {
public: public:
int init(platf::mem_type_e hwdevice_type, const std::string &display_name, int framerate) { int init(platf::mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
@@ -259,7 +274,8 @@ public:
return status; return status;
} }
auto img = (egl::img_descriptor_t *)img_out_base; auto img = (frame_descriptor_t *)img_out_base;
img->reset();
auto current_frame = dmabuf.current_frame; auto current_frame = dmabuf.current_frame;
@@ -275,11 +291,14 @@ public:
std::copy_n(std::begin(current_frame->offsets), current_frame->obj_count, img->offsets); std::copy_n(std::begin(current_frame->offsets), current_frame->obj_count, img->offsets);
std::copy_n(std::begin(current_frame->strides), current_frame->obj_count, img->strides); std::copy_n(std::begin(current_frame->strides), current_frame->obj_count, img->strides);
// Prevent dmabuf from closing the file descriptors.
current_frame->obj_count = 0;
return platf::capture_e::ok; return platf::capture_e::ok;
} }
std::shared_ptr<platf::img_t> alloc_img() override { std::shared_ptr<platf::img_t> alloc_img() override {
auto img = std::make_shared<egl::img_descriptor_t>(); auto img = std::make_shared<frame_descriptor_t>();
img->img_width = width; img->img_width = width;
img->img_height = height; img->img_height = height;