Created
July 18, 2021 18:15
-
-
Save nowrep/b1ccfa54caaf6c79e6a909ea879d590a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
index 56dbd2e..b3b510c 100644 | |
--- a/CMakeLists.txt | |
+++ b/CMakeLists.txt | |
@@ -40,6 +40,7 @@ if (BUILD_PLUGIN) | |
add_library(linux-vkcapture MODULE ${PLUGIN_SOURCES}) | |
target_link_libraries(linux-vkcapture libobs obs-frontend-api ${X11_xcb_LIB} ${X11_xcb_xfixes_LIB}) | |
set_target_properties(linux-vkcapture PROPERTIES PREFIX "") | |
+ set_target_properties(linux-vkcapture PROPERTIES C_STANDARD 11) | |
target_include_directories(linux-vkcapture PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>) | |
if (COMMAND install_obs_plugin_with_data) | |
diff --git a/src/capture.c b/src/capture.c | |
index 674d161..837279a 100644 | |
--- a/src/capture.c | |
+++ b/src/capture.c | |
@@ -111,7 +111,7 @@ void capture_init_shtex( | |
struct iovec io = { | |
.iov_base = &td, | |
- .iov_len = sizeof(struct capture_texture_data), | |
+ .iov_len = CAPTURE_TEXTURE_DATA_SIZE, | |
}; | |
msg.msg_iov = &io; | |
msg.msg_iovlen = 1; | |
diff --git a/src/capture.h b/src/capture.h | |
index d2da060..67b2ce9 100644 | |
--- a/src/capture.h | |
+++ b/src/capture.h | |
@@ -20,6 +20,7 @@ with this program. If not, see <https://www.gnu.org/licenses/> | |
#include <stdint.h> | |
#include <stdbool.h> | |
+#include <assert.h> | |
#ifndef DRM_FORMAT_XRGB8888 | |
#define fourcc_code(a, b, c, d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ | |
@@ -30,15 +31,19 @@ with this program. If not, see <https://www.gnu.org/licenses/> | |
#endif | |
struct capture_texture_data { | |
- int width; | |
- int height; | |
- int format; | |
- int stride; | |
- int offset; | |
+ int32_t width; | |
+ int32_t height; | |
+ int32_t format; | |
+ int32_t stride; | |
+ int32_t offset; | |
uint64_t modifier; | |
uint32_t winid; | |
- bool flip; | |
-}; | |
+ uint8_t flip; | |
+ uint8_t padding[256]; | |
+} __attribute__((packed)); | |
+ | |
+#define CAPTURE_TEXTURE_DATA_SIZE 289 | |
+static_assert(sizeof(struct capture_texture_data) == CAPTURE_TEXTURE_DATA_SIZE, "size mismatch"); | |
void capture_init(); | |
void capture_update_socket(); | |
diff --git a/src/vkcapture.c b/src/vkcapture.c | |
index b864453..8655dcc 100644 | |
--- a/src/vkcapture.c | |
+++ b/src/vkcapture.c | |
@@ -67,7 +67,7 @@ static void vkcapture_cleanup_client(vkcapture_source_t *ctx) | |
ctx->buf_fd = -1; | |
} | |
- memset(&ctx->data, 0, sizeof(struct capture_texture_data)); | |
+ memset(&ctx->data, 0, CAPTURE_TEXTURE_DATA_SIZE); | |
#if HAVE_X11_XCB | |
ctx->root_winid = 0; | |
@@ -207,7 +207,7 @@ static void vkcapture_source_video_tick(void *data, float seconds) | |
struct msghdr msg = {0}; | |
struct iovec io = { | |
.iov_base = &ctx->data, | |
- .iov_len = sizeof(struct capture_texture_data), | |
+ .iov_len = CAPTURE_TEXTURE_DATA_SIZE, | |
}; | |
msg.msg_iov = &io; | |
msg.msg_iovlen = 1; | |
@@ -238,7 +238,7 @@ static void vkcapture_source_video_tick(void *data, float seconds) | |
int buf_fd = *((int *)CMSG_DATA(cmsgh)); | |
- if (io.iov_len != sizeof(struct capture_texture_data)) { | |
+ if (io.iov_len != CAPTURE_TEXTURE_DATA_SIZE) { | |
close(buf_fd); | |
return; | |
} | |
@@ -260,9 +260,10 @@ static void vkcapture_source_video_tick(void *data, float seconds) | |
obs_enter_graphics(); | |
const uint32_t stride = ctx->data.stride; | |
const uint32_t offset = ctx->data.offset; | |
+ const uint64_t modifier = ctx->data.modifier; | |
ctx->texture = gs_texture_create_from_dmabuf(ctx->data.width, ctx->data.height, | |
ctx->data.format, GS_BGRX, 1, &ctx->buf_fd, &stride, &offset, | |
- ctx->data.modifier != DRM_FORMAT_MOD_INVALID ? &ctx->data.modifier : NULL); | |
+ modifier != DRM_FORMAT_MOD_INVALID ? &modifier : NULL); | |
obs_leave_graphics(); | |
if (!ctx->texture) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment