aboutsummaryrefslogtreecommitdiff
path: root/include/capture
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-03-09 15:28:17 +0100
committerdec05eba <dec05eba@protonmail.com>2024-03-09 15:36:45 +0100
commit5e05bbbbcbd45298c48af2b56a33da93d15b8f44 (patch)
treeac5ba627a63a34bfce2977e3d62344cfab46dba5 /include/capture
parent3d9a7065280e64797c5a68c794a04d60fb3f767c (diff)
Refactor xcomposite
Move common code between cuda/vaapi implementations into xcomposite file. This also fixes limited/full range colors on nvidia.
Diffstat (limited to 'include/capture')
-rw-r--r--include/capture/capture.h5
-rw-r--r--include/capture/xcomposite.h46
-rw-r--r--include/capture/xcomposite_cuda.h8
-rw-r--r--include/capture/xcomposite_vaapi.h10
4 files changed, 55 insertions, 14 deletions
diff --git a/include/capture/capture.h b/include/capture/capture.h
index 43b5de5..f1d0467 100644
--- a/include/capture/capture.h
+++ b/include/capture/capture.h
@@ -12,6 +12,8 @@ typedef struct gsr_cuda gsr_cuda;
typedef struct AVFrame AVFrame;
typedef struct CUgraphicsResource_st *CUgraphicsResource;
typedef struct CUarray_st *CUarray;
+typedef struct CUctx_st *CUcontext;
+typedef struct CUstream_st *CUstream;
typedef struct gsr_capture gsr_capture;
@@ -58,4 +60,7 @@ bool gsr_capture_base_setup_vaapi_textures(gsr_capture_base *self, AVFrame *fram
bool gsr_capture_base_setup_cuda_textures(gsr_capture_base *base, AVFrame *frame, gsr_cuda_context *cuda_context, gsr_egl *egl, gsr_color_range color_range, gsr_source_color source_color, bool hdr);
void gsr_capture_base_stop(gsr_capture_base *self, gsr_egl *egl);
+bool drm_create_codec_context(const char *card_path, AVCodecContext *video_codec_context, bool hdr, VADisplay *va_dpy);
+bool cuda_create_codec_context(CUcontext cu_ctx, AVCodecContext *video_codec_context, CUstream *cuda_stream);
+
#endif /* GSR_CAPTURE_CAPTURE_H */
diff --git a/include/capture/xcomposite.h b/include/capture/xcomposite.h
new file mode 100644
index 0000000..222ff5b
--- /dev/null
+++ b/include/capture/xcomposite.h
@@ -0,0 +1,46 @@
+#ifndef GSR_CAPTURE_XCOMPOSITE_H
+#define GSR_CAPTURE_XCOMPOSITE_H
+
+#include "capture.h"
+#include "../egl.h"
+#include "../vec2.h"
+#include "../color_conversion.h"
+#include "../window_texture.h"
+
+typedef struct {
+ gsr_egl *egl;
+ Window window;
+ bool follow_focused; /* If this is set then |window| is ignored */
+ vec2i region_size; /* This is currently only used with |follow_focused| */
+ gsr_color_range color_range;
+} gsr_capture_xcomposite_params;
+
+typedef struct {
+ gsr_capture_base base;
+ gsr_capture_xcomposite_params params;
+ XEvent xev;
+
+ bool should_stop;
+ bool stop_is_error;
+ bool window_resized;
+ bool follow_focused_initialized;
+
+ Window window;
+ vec2i window_size;
+ vec2i texture_size;
+ double window_resize_timer;
+
+ WindowTexture window_texture;
+
+ Atom net_active_window_atom;
+} gsr_capture_xcomposite;
+
+void gsr_capture_xcomposite_init(gsr_capture_xcomposite *self, const gsr_capture_xcomposite_params *params);
+
+int gsr_capture_xcomposite_start(gsr_capture_xcomposite *self, AVCodecContext *video_codec_context, AVFrame *frame);
+void gsr_capture_xcomposite_stop(gsr_capture_xcomposite *self, AVCodecContext *video_codec_context);
+void gsr_capture_xcomposite_tick(gsr_capture_xcomposite *self, AVCodecContext *video_codec_context);
+bool gsr_capture_xcomposite_should_stop(gsr_capture_xcomposite *self, bool *err);
+int gsr_capture_xcomposite_capture(gsr_capture_xcomposite *self, AVFrame *frame);
+
+#endif /* GSR_CAPTURE_XCOMPOSITE_H */
diff --git a/include/capture/xcomposite_cuda.h b/include/capture/xcomposite_cuda.h
index 53b7c0d..b93c6de 100644
--- a/include/capture/xcomposite_cuda.h
+++ b/include/capture/xcomposite_cuda.h
@@ -2,14 +2,10 @@
#define GSR_CAPTURE_XCOMPOSITE_CUDA_H
#include "capture.h"
-#include "../egl.h"
-#include "../vec2.h"
+#include "xcomposite.h"
typedef struct {
- gsr_egl *egl;
- Window window;
- bool follow_focused; /* If this is set then |window| is ignored */
- vec2i region_size; /* This is currently only used with |follow_focused| */
+ gsr_capture_xcomposite_params base;
bool overclock;
} gsr_capture_xcomposite_cuda_params;
diff --git a/include/capture/xcomposite_vaapi.h b/include/capture/xcomposite_vaapi.h
index c6237e3..5d4b338 100644
--- a/include/capture/xcomposite_vaapi.h
+++ b/include/capture/xcomposite_vaapi.h
@@ -2,16 +2,10 @@
#define GSR_CAPTURE_XCOMPOSITE_VAAPI_H
#include "capture.h"
-#include "../egl.h"
-#include "../vec2.h"
-#include "../color_conversion.h"
+#include "xcomposite.h"
typedef struct {
- gsr_egl *egl;
- Window window;
- bool follow_focused; /* If this is set then |window| is ignored */
- vec2i region_size; /* This is currently only used with |follow_focused| */
- gsr_color_range color_range;
+ gsr_capture_xcomposite_params base;
} gsr_capture_xcomposite_vaapi_params;
gsr_capture* gsr_capture_xcomposite_vaapi_create(const gsr_capture_xcomposite_vaapi_params *params);