aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2026-08-01 21:32:06 +0200
committerdec05eba <dec05eba@protonmail.com>2026-08-01 21:32:06 +0200
commitde8954256578e1805fc5b92a0719190de784d3c0 (patch)
tree58fad345f2906108b04d62b0f0a4ae3e4e32ce82 /include
parentcdb8493eed42c386919280b17bbd31b713a5ac35 (diff)
Move capture source parsing and capture creation from main.cpp into C modules
Capture sources are C structs with fixed size names and a growable array, and the lazily initialized kms client, night light and cursor globals are now owned by gsr_capture_deps.
Diffstat (limited to 'include')
-rw-r--r--include/recorder/capture_setup.h49
-rw-r--r--include/recorder/capture_source.h60
-rw-r--r--include/recorder/error.h2
3 files changed, 110 insertions, 1 deletions
diff --git a/include/recorder/capture_setup.h b/include/recorder/capture_setup.h
new file mode 100644
index 0000000..fd4b7e7
--- /dev/null
+++ b/include/recorder/capture_setup.h
@@ -0,0 +1,49 @@
+#ifndef GSR_RECORDER_CAPTURE_SETUP_H
+#define GSR_RECORDER_CAPTURE_SETUP_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include "../egl.h"
+#include "../cursor.h"
+#include "../kde_night_light.h"
+#include "../capture/capture.h"
+#include "../../kms/client/kms_client.h"
+#include "capture_source.h"
+#include "settings.h"
+
+#include <X11/Xlib.h>
+
+typedef struct {
+ gsr_kms_client kms_client;
+ bool kms_client_initialized;
+ gsr_kms_response kms_response;
+ gsr_kde_night_light *kde_night_light;
+ bool kde_night_light_initialized;
+ gsr_cursor x11_cursor;
+ Display *x11_cursor_display;
+} gsr_capture_deps;
+
+typedef struct {
+ gsr_capture *capture;
+ gsr_capture_metadata metadata;
+ gsr_capture_source *capture_source;
+} gsr_video_source;
+
+typedef struct {
+ gsr_video_source *items;
+ size_t num_items;
+} gsr_video_sources;
+
+void gsr_capture_deps_init(gsr_capture_deps *self);
+void gsr_capture_deps_init_cursor(gsr_capture_deps *self, gsr_egl *egl, bool record_cursor);
+void gsr_capture_deps_deinit(gsr_capture_deps *self);
+void gsr_capture_deps_cleanup_kms_fds(gsr_capture_deps *self);
+void gsr_capture_deps_update_kms(gsr_capture_deps *self);
+
+/* Returns a |gsr_error| value, or the error returned by gsr_capture_start. |video_size| is set to the size of all capture sources combined */
+int gsr_video_sources_create(gsr_video_sources *self, const gsr_recorder_settings *settings, gsr_egl *egl, gsr_capture_deps *deps, bool prefer_ximage, gsr_capture_sources *capture_sources, vec2i *video_size);
+void gsr_video_sources_update_with_real_video_size(gsr_video_sources *self, vec2i video_size);
+bool gsr_video_sources_uses_external_image(const gsr_video_sources *self);
+void gsr_video_sources_deinit(gsr_video_sources *self);
+
+#endif /* GSR_RECORDER_CAPTURE_SETUP_H */
diff --git a/include/recorder/capture_source.h b/include/recorder/capture_source.h
new file mode 100644
index 0000000..503c620
--- /dev/null
+++ b/include/recorder/capture_source.h
@@ -0,0 +1,60 @@
+#ifndef GSR_RECORDER_CAPTURE_SOURCE_H
+#define GSR_RECORDER_CAPTURE_SOURCE_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stddef.h>
+#include "../vec2.h"
+#include "../args_parser.h"
+#include "../capture/capture.h"
+#include "../capture/v4l2.h"
+
+#define GSR_CAPTURE_SOURCE_NAME_MAX_SIZE 256
+
+typedef enum {
+ VVEC2I_TYPE_PIXELS,
+ VVEC2I_TYPE_SCALAR
+} vvec2i_type;
+
+typedef struct {
+ int x;
+ int y;
+ vvec2i_type x_type;
+ vvec2i_type y_type;
+} vvec2i;
+
+typedef struct {
+ char name[GSR_CAPTURE_SOURCE_NAME_MAX_SIZE];
+ CaptureSourceType type;
+ gsr_capture_alignment halign;
+ gsr_capture_alignment valign;
+ gsr_capture_v4l2_pixfmt v4l2_pixfmt;
+ uint32_t flip;
+ vvec2i pos;
+ vvec2i size;
+ vec2i region_pos;
+ vec2i region_size;
+ bool region_set;
+ int64_t window_id;
+ int camera_fps;
+ vec2i camera_resolution;
+} gsr_capture_source;
+
+typedef struct {
+ gsr_capture_source *items;
+ size_t num_items;
+ size_t capacity_items;
+} gsr_capture_sources;
+
+void gsr_capture_source_init(gsr_capture_source *self, vec2i region_position, vec2i region_size);
+
+/* Returns a |gsr_error| value. Parses the -w option value, which may contain multiple capture sources separated by | */
+int gsr_capture_sources_parse(gsr_capture_sources *self, const char *capture_source_arg, vec2i region_position, vec2i region_size);
+void gsr_capture_sources_deinit(gsr_capture_sources *self);
+
+bool gsr_capture_sources_has_type(const gsr_capture_sources *self, CaptureSourceType type);
+bool gsr_capture_sources_has_damage_tracked_target(const gsr_capture_sources *self);
+bool gsr_capture_sources_has_region_set(const gsr_capture_sources *self);
+bool gsr_capture_sources_has_monitor_or_region(const gsr_capture_sources *self);
+
+#endif /* GSR_RECORDER_CAPTURE_SOURCE_H */
diff --git a/include/recorder/error.h b/include/recorder/error.h
index 75f1416..cfa83cd 100644
--- a/include/recorder/error.h
+++ b/include/recorder/error.h
@@ -9,7 +9,7 @@ extern "C" {
typedef enum {
GSR_ERROR_OK = 0,
GSR_ERROR_GENERIC = -1,
- GSR_ERROR_AUDIO_SETUP_FAILED = -2,
+ GSR_ERROR_UNSUPPORTED = -2,
GSR_ERROR_CAPTURE_FAILED = -3,
GSR_ERROR_VIDEO_CODEC_QUERY_FAILED = -11,
GSR_ERROR_OPENGL_LOAD_FAILED = -22,