aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/capture/capture.h24
-rw-r--r--include/capture/kms.h2
-rw-r--r--include/capture/nvfbc.h2
-rw-r--r--include/capture/portal.h1
-rw-r--r--include/capture/xcomposite.h2
-rw-r--r--include/codec_query/codec_query.h23
-rw-r--r--include/codec_query/nvenc.h8
-rw-r--r--include/codec_query/vaapi.h8
-rw-r--r--include/codec_query/vulkan.h8
-rw-r--r--include/color_conversion.h6
-rw-r--r--include/damage.h1
-rw-r--r--include/defs.h5
-rw-r--r--include/egl.h61
-rw-r--r--include/encoder/video/cuda.h16
-rw-r--r--include/encoder/video/nvenc.h16
-rw-r--r--include/encoder/video/video.h18
-rw-r--r--include/encoder/video/vulkan.h15
-rw-r--r--include/image_writer.h31
-rw-r--r--include/pipewire_audio.h128
-rw-r--r--include/pipewire_video.h (renamed from include/pipewire.h)44
-rw-r--r--include/sound.hpp21
-rw-r--r--include/utils.h24
-rw-r--r--include/vec2.h4
-rw-r--r--include/window/window.h37
-rw-r--r--include/window/window_wayland.h8
-rw-r--r--include/window/window_x11.h10
26 files changed, 396 insertions, 127 deletions
diff --git a/include/capture/capture.h b/include/capture/capture.h
index 7c8887d..634eee0 100644
--- a/include/capture/capture.h
+++ b/include/capture/capture.h
@@ -9,37 +9,43 @@
typedef struct AVCodecContext AVCodecContext;
typedef struct AVStream AVStream;
typedef struct AVFrame AVFrame;
-typedef struct gsr_capture gsr_capture;
typedef struct AVMasteringDisplayMetadata AVMasteringDisplayMetadata;
typedef struct AVContentLightMetadata AVContentLightMetadata;
+typedef struct gsr_capture gsr_capture;
+
+typedef struct {
+ int width;
+ int height;
+ int fps;
+ AVCodecContext *video_codec_context; /* can be NULL */
+ AVFrame *frame; /* can be NULL, but will never be NULL if |video_codec_context| is set */
+} gsr_capture_metadata;
struct gsr_capture {
/* These methods should not be called manually. Call gsr_capture_* instead */
- int (*start)(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame *frame);
+ int (*start)(gsr_capture *cap, gsr_capture_metadata *capture_metadata);
void (*on_event)(gsr_capture *cap, gsr_egl *egl); /* can be NULL */
void (*tick)(gsr_capture *cap); /* can be NULL. If there is an event then |on_event| is called before this */
bool (*should_stop)(gsr_capture *cap, bool *err); /* can be NULL. If NULL, return false */
- int (*capture)(gsr_capture *cap, AVFrame *frame, gsr_color_conversion *color_conversion);
- gsr_source_color (*get_source_color)(gsr_capture *cap);
+ int (*capture)(gsr_capture *cap, gsr_capture_metadata *capture_metadata, gsr_color_conversion *color_conversion);
bool (*uses_external_image)(gsr_capture *cap); /* can be NULL. If NULL, return false */
bool (*set_hdr_metadata)(gsr_capture *cap, AVMasteringDisplayMetadata *mastering_display_metadata, AVContentLightMetadata *light_metadata); /* can be NULL. If NULL, return false */
uint64_t (*get_window_id)(gsr_capture *cap); /* can be NULL. Returns 0 if unknown */
bool (*is_damaged)(gsr_capture *cap); /* can be NULL */
void (*clear_damage)(gsr_capture *cap); /* can be NULL */
- void (*destroy)(gsr_capture *cap, AVCodecContext *video_codec_context);
+ void (*destroy)(gsr_capture *cap);
void *priv; /* can be NULL */
bool started;
};
-int gsr_capture_start(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame *frame);
+int gsr_capture_start(gsr_capture *cap, gsr_capture_metadata *capture_metadata);
void gsr_capture_on_event(gsr_capture *cap, gsr_egl *egl);
void gsr_capture_tick(gsr_capture *cap);
bool gsr_capture_should_stop(gsr_capture *cap, bool *err);
-int gsr_capture_capture(gsr_capture *cap, AVFrame *frame, gsr_color_conversion *color_conversion);
-gsr_source_color gsr_capture_get_source_color(gsr_capture *cap);
+int gsr_capture_capture(gsr_capture *cap, gsr_capture_metadata *capture_metadata, gsr_color_conversion *color_conversion);
bool gsr_capture_uses_external_image(gsr_capture *cap);
bool gsr_capture_set_hdr_metadata(gsr_capture *cap, AVMasteringDisplayMetadata *mastering_display_metadata, AVContentLightMetadata *light_metadata);
-void gsr_capture_destroy(gsr_capture *cap, AVCodecContext *video_codec_context);
+void gsr_capture_destroy(gsr_capture *cap);
#endif /* GSR_CAPTURE_CAPTURE_H */
diff --git a/include/capture/kms.h b/include/capture/kms.h
index f19e462..bf1ba62 100644
--- a/include/capture/kms.h
+++ b/include/capture/kms.h
@@ -10,6 +10,8 @@ typedef struct {
gsr_color_range color_range;
bool hdr;
bool record_cursor;
+ int fps;
+ vec2i output_resolution;
} gsr_capture_kms_params;
gsr_capture* gsr_capture_kms_create(const gsr_capture_kms_params *params);
diff --git a/include/capture/nvfbc.h b/include/capture/nvfbc.h
index 95ca88d..90da7fa 100644
--- a/include/capture/nvfbc.h
+++ b/include/capture/nvfbc.h
@@ -14,7 +14,7 @@ typedef struct {
gsr_color_depth color_depth;
gsr_color_range color_range;
bool record_cursor;
- bool use_software_video_encoder;
+ vec2i output_resolution;
} gsr_capture_nvfbc_params;
gsr_capture* gsr_capture_nvfbc_create(const gsr_capture_nvfbc_params *params);
diff --git a/include/capture/portal.h b/include/capture/portal.h
index 2e2c6f2..3989b98 100644
--- a/include/capture/portal.h
+++ b/include/capture/portal.h
@@ -11,6 +11,7 @@ typedef struct {
bool restore_portal_session;
/* If this is set to NULL then this defaults to $XDG_CONFIG_HOME/gpu-screen-recorder/restore_token ($XDG_CONFIG_HOME defaults to $HOME/.config) */
const char *portal_session_token_filepath;
+ vec2i output_resolution;
} gsr_capture_portal_params;
gsr_capture* gsr_capture_portal_create(const gsr_capture_portal_params *params);
diff --git a/include/capture/xcomposite.h b/include/capture/xcomposite.h
index 8c87404..45eb481 100644
--- a/include/capture/xcomposite.h
+++ b/include/capture/xcomposite.h
@@ -8,10 +8,10 @@ typedef struct {
gsr_egl *egl;
unsigned long 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;
bool record_cursor;
gsr_color_depth color_depth;
+ vec2i output_resolution;
} gsr_capture_xcomposite_params;
gsr_capture* gsr_capture_xcomposite_create(const gsr_capture_xcomposite_params *params);
diff --git a/include/codec_query/codec_query.h b/include/codec_query/codec_query.h
new file mode 100644
index 0000000..316217d
--- /dev/null
+++ b/include/codec_query/codec_query.h
@@ -0,0 +1,23 @@
+#ifndef GSR_CODEC_QUERY_H
+#define GSR_CODEC_QUERY_H
+
+#include <stdbool.h>
+
+typedef struct {
+ bool supported;
+ bool low_power;
+} gsr_supported_video_codec;
+
+typedef struct {
+ gsr_supported_video_codec h264;
+ gsr_supported_video_codec hevc;
+ gsr_supported_video_codec hevc_hdr;
+ gsr_supported_video_codec hevc_10bit;
+ gsr_supported_video_codec av1;
+ gsr_supported_video_codec av1_hdr;
+ gsr_supported_video_codec av1_10bit;
+ gsr_supported_video_codec vp8;
+ gsr_supported_video_codec vp9;
+} gsr_supported_video_codecs;
+
+#endif /* GSR_CODEC_QUERY_H */
diff --git a/include/codec_query/nvenc.h b/include/codec_query/nvenc.h
new file mode 100644
index 0000000..c01acf6
--- /dev/null
+++ b/include/codec_query/nvenc.h
@@ -0,0 +1,8 @@
+#ifndef GSR_CODEC_QUERY_NVENC_H
+#define GSR_CODEC_QUERY_NVENC_H
+
+#include "codec_query.h"
+
+bool gsr_get_supported_video_codecs_nvenc(gsr_supported_video_codecs *video_codecs, bool cleanup);
+
+#endif /* GSR_CODEC_QUERY_NVENC_H */
diff --git a/include/codec_query/vaapi.h b/include/codec_query/vaapi.h
new file mode 100644
index 0000000..60bdeca
--- /dev/null
+++ b/include/codec_query/vaapi.h
@@ -0,0 +1,8 @@
+#ifndef GSR_CODEC_QUERY_VAAPI_H
+#define GSR_CODEC_QUERY_VAAPI_H
+
+#include "codec_query.h"
+
+bool gsr_get_supported_video_codecs_vaapi(gsr_supported_video_codecs *video_codecs, const char *card_path, bool cleanup);
+
+#endif /* GSR_CODEC_QUERY_VAAPI_H */
diff --git a/include/codec_query/vulkan.h b/include/codec_query/vulkan.h
new file mode 100644
index 0000000..bb06c6b
--- /dev/null
+++ b/include/codec_query/vulkan.h
@@ -0,0 +1,8 @@
+#ifndef GSR_CODEC_QUERY_VULKAN_H
+#define GSR_CODEC_QUERY_VULKAN_H
+
+#include "codec_query.h"
+
+bool gsr_get_supported_video_codecs_vulkan(gsr_supported_video_codecs *video_codecs, const char *card_path, bool cleanup);
+
+#endif /* GSR_CODEC_QUERY_VULKAN_H */
diff --git a/include/color_conversion.h b/include/color_conversion.h
index 236bfbd..b80be21 100644
--- a/include/color_conversion.h
+++ b/include/color_conversion.h
@@ -22,7 +22,8 @@ typedef enum {
typedef enum {
GSR_DESTINATION_COLOR_NV12, /* YUV420, BT709, 8-bit */
- GSR_DESTINATION_COLOR_P010 /* YUV420, BT2020, 10-bit */
+ GSR_DESTINATION_COLOR_P010, /* YUV420, BT2020, 10-bit */
+ GSR_DESTINATION_COLOR_RGB8
} gsr_destination_color;
typedef struct {
@@ -33,7 +34,6 @@ typedef struct {
typedef struct {
gsr_egl *egl;
- gsr_source_color source_color;
gsr_destination_color destination_color;
unsigned int destination_textures[2];
@@ -57,7 +57,7 @@ typedef struct {
int gsr_color_conversion_init(gsr_color_conversion *self, const gsr_color_conversion_params *params);
void gsr_color_conversion_deinit(gsr_color_conversion *self);
-void gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture);
+void gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_id, vec2i source_pos, vec2i source_size, vec2i texture_pos, vec2i texture_size, float rotation, bool external_texture, gsr_source_color source_color);
void gsr_color_conversion_clear(gsr_color_conversion *self);
#endif /* GSR_COLOR_CONVERSION_H */
diff --git a/include/damage.h b/include/damage.h
index 7229418..4b10e58 100644
--- a/include/damage.h
+++ b/include/damage.h
@@ -17,6 +17,7 @@ typedef enum {
typedef struct {
gsr_egl *egl;
+ Display *display;
bool track_cursor;
gsr_damage_track_type track_type;
diff --git a/include/defs.h b/include/defs.h
index 8fd2ddc..76e798e 100644
--- a/include/defs.h
+++ b/include/defs.h
@@ -13,6 +13,11 @@ typedef struct {
gsr_gpu_vendor vendor;
int gpu_version; /* 0 if unknown */
bool is_steam_deck;
+
+ /* Only currently set for Mesa. 0 if unknown format */
+ int driver_major;
+ int driver_minor;
+ int driver_patch;
} gsr_gpu_info;
typedef enum {
diff --git a/include/egl.h b/include/egl.h
index 3fdbf48..8a2b6c2 100644
--- a/include/egl.h
+++ b/include/egl.h
@@ -10,6 +10,8 @@
#include "vec2.h"
#include "defs.h"
+typedef struct gsr_window gsr_window;
+
#ifdef _WIN64
typedef signed long long int khronos_intptr_t;
typedef unsigned long long int khronos_uintptr_t;
@@ -102,11 +104,13 @@ typedef void(*__GLXextFuncPtr)(void);
#define GL_RG 0x8227
#define GL_RGB 0x1907
#define GL_RGBA 0x1908
+#define GL_RGB8 0x8051
#define GL_RGBA8 0x8058
#define GL_R8 0x8229
#define GL_RG8 0x822B
#define GL_R16 0x822A
#define GL_RG16 0x822C
+#define GL_RGB16 0x8054
#define GL_UNSIGNED_BYTE 0x1401
#define GL_COLOR_BUFFER_BIT 0x00004000
#define GL_TEXTURE_WRAP_S 0x2802
@@ -131,6 +135,7 @@ typedef void(*__GLXextFuncPtr)(void);
#define GL_VENDOR 0x1F00
#define GL_RENDERER 0x1F01
+#define GL_VERSION 0x1F02
#define GL_COMPILE_STATUS 0x8B81
#define GL_INFO_LOG_LENGTH 0x8B84
@@ -151,54 +156,11 @@ typedef int (*FUNC_eglQueryDisplayAttribEXT)(EGLDisplay dpy, int32_t attribute,
typedef const char* (*FUNC_eglQueryDeviceStringEXT)(void *device, int32_t name);
typedef int (*FUNC_eglQueryDmaBufModifiersEXT)(EGLDisplay dpy, int32_t format, int32_t max_modifiers, uint64_t *modifiers, int *external_only, int32_t *num_modifiers);
-#define GSR_MAX_OUTPUTS 32
-
-typedef struct {
- char *name;
- vec2i pos;
- vec2i size;
- uint32_t connector_id;
- gsr_monitor_rotation rotation;
- uint32_t monitor_identifier; /* crtc id */
-} gsr_x11_output;
-
-typedef struct {
- Display *dpy;
- Window window;
- gsr_x11_output outputs[GSR_MAX_OUTPUTS];
- int num_outputs;
- XEvent xev;
-} gsr_x11;
-
-typedef struct {
- uint32_t wl_name;
- void *output;
- vec2i pos;
- vec2i size;
- int32_t transform;
- char *name;
-} gsr_wayland_output;
-
-typedef struct {
- void *dpy;
- void *window;
- void *registry;
- void *surface;
- void *compositor;
- gsr_wayland_output outputs[GSR_MAX_OUTPUTS];
- int num_outputs;
-} gsr_wayland;
-
typedef enum {
GSR_GL_CONTEXT_TYPE_EGL,
GSR_GL_CONTEXT_TYPE_GLX
} gsr_gl_context_type;
-typedef enum {
- GSR_DISPLAY_SERVER_X11,
- GSR_DISPLAY_SERVER_WAYLAND
-} gsr_display_server;
-
typedef struct gsr_egl gsr_egl;
struct gsr_egl {
void *egl_library;
@@ -206,6 +168,7 @@ struct gsr_egl {
void *gl_library;
gsr_gl_context_type context_type;
+ gsr_window *window;
EGLDisplay egl_display;
EGLSurface egl_surface;
@@ -217,8 +180,6 @@ struct gsr_egl {
gsr_gpu_info gpu_info;
- gsr_x11 x11;
- gsr_wayland wayland;
char card_path[128];
int32_t (*eglGetError)(void);
@@ -313,17 +274,15 @@ struct gsr_egl {
void (*glUniform2f)(int location, float v0, float v1);
void (*glDebugMessageCallback)(GLDEBUGPROC callback, const void *userParam);
void (*glScissor)(int x, int y, int width, int height);
+ void (*glReadPixels)(int x, int y, int width, int height, unsigned int format, unsigned int type, void *pixels);
+ void* (*glMapBuffer)(unsigned int target, unsigned int access);
+ unsigned char (*glUnmapBuffer)(unsigned int target);
};
-bool gsr_egl_load(gsr_egl *self, Display *dpy, bool wayland, bool is_monitor_capture);
+bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture, bool enable_debug);
void gsr_egl_unload(gsr_egl *self);
-/* Returns true if an event is available */
-bool gsr_egl_process_event(gsr_egl *self);
/* Does opengl swap with egl or glx, depending on which one is active */
void gsr_egl_swap_buffers(gsr_egl *self);
-gsr_display_server gsr_egl_get_display_server(const gsr_egl *self);
-XEvent* gsr_egl_get_event_data(gsr_egl *self);
-
#endif /* GSR_EGL_H */
diff --git a/include/encoder/video/cuda.h b/include/encoder/video/cuda.h
deleted file mode 100644
index 6d32e09..0000000
--- a/include/encoder/video/cuda.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef GSR_ENCODER_VIDEO_CUDA_H
-#define GSR_ENCODER_VIDEO_CUDA_H
-
-#include "video.h"
-
-typedef struct gsr_egl gsr_egl;
-
-typedef struct {
- gsr_egl *egl;
- bool overclock;
- gsr_color_depth color_depth;
-} gsr_video_encoder_cuda_params;
-
-gsr_video_encoder* gsr_video_encoder_cuda_create(const gsr_video_encoder_cuda_params *params);
-
-#endif /* GSR_ENCODER_VIDEO_CUDA_H */
diff --git a/include/encoder/video/nvenc.h b/include/encoder/video/nvenc.h
new file mode 100644
index 0000000..d4a906b
--- /dev/null
+++ b/include/encoder/video/nvenc.h
@@ -0,0 +1,16 @@
+#ifndef GSR_ENCODER_VIDEO_NVENC_H
+#define GSR_ENCODER_VIDEO_NVENC_H
+
+#include "video.h"
+
+typedef struct gsr_egl gsr_egl;
+
+typedef struct {
+ gsr_egl *egl;
+ bool overclock;
+ gsr_color_depth color_depth;
+} gsr_video_encoder_nvenc_params;
+
+gsr_video_encoder* gsr_video_encoder_nvenc_create(const gsr_video_encoder_nvenc_params *params);
+
+#endif /* GSR_ENCODER_VIDEO_NVENC_H */
diff --git a/include/encoder/video/video.h b/include/encoder/video/video.h
index 899357a..49f48bd 100644
--- a/include/encoder/video/video.h
+++ b/include/encoder/video/video.h
@@ -8,22 +8,9 @@ typedef struct gsr_video_encoder gsr_video_encoder;
typedef struct AVCodecContext AVCodecContext;
typedef struct AVFrame AVFrame;
-typedef struct {
- bool h264;
- bool hevc;
- bool hevc_hdr;
- bool hevc_10bit;
- bool av1;
- bool av1_hdr;
- bool av1_10bit;
- bool vp8;
- bool vp9;
-} gsr_supported_video_codecs;
-
struct gsr_video_encoder {
- gsr_supported_video_codecs (*get_supported_codecs)(gsr_video_encoder *encoder, bool cleanup);
bool (*start)(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame);
- void (*copy_textures_to_frame)(gsr_video_encoder *encoder, AVFrame *frame); /* Can be NULL */
+ void (*copy_textures_to_frame)(gsr_video_encoder *encoder, AVFrame *frame, gsr_color_conversion *color_conversion); /* Can be NULL */
/* |textures| should be able to fit 2 elements */
void (*get_textures)(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color);
void (*destroy)(gsr_video_encoder *encoder, AVCodecContext *video_codec_context);
@@ -32,9 +19,8 @@ struct gsr_video_encoder {
bool started;
};
-gsr_supported_video_codecs gsr_video_encoder_get_supported_codecs(gsr_video_encoder *encoder, bool cleanup);
bool gsr_video_encoder_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame);
-void gsr_video_encoder_copy_textures_to_frame(gsr_video_encoder *encoder, AVFrame *frame);
+void gsr_video_encoder_copy_textures_to_frame(gsr_video_encoder *encoder, AVFrame *frame, gsr_color_conversion *color_conversion);
void gsr_video_encoder_get_textures(gsr_video_encoder *encoder, unsigned int *textures, int *num_textures, gsr_destination_color *destination_color);
void gsr_video_encoder_destroy(gsr_video_encoder *encoder, AVCodecContext *video_codec_context);
diff --git a/include/encoder/video/vulkan.h b/include/encoder/video/vulkan.h
new file mode 100644
index 0000000..383fc4f
--- /dev/null
+++ b/include/encoder/video/vulkan.h
@@ -0,0 +1,15 @@
+#ifndef GSR_ENCODER_VIDEO_VULKAN_H
+#define GSR_ENCODER_VIDEO_VULKAN_H
+
+#include "video.h"
+
+typedef struct gsr_egl gsr_egl;
+
+typedef struct {
+ gsr_egl *egl;
+ gsr_color_depth color_depth;
+} gsr_video_encoder_vulkan_params;
+
+gsr_video_encoder* gsr_video_encoder_vulkan_create(const gsr_video_encoder_vulkan_params *params);
+
+#endif /* GSR_ENCODER_VIDEO_VULKAN_H */
diff --git a/include/image_writer.h b/include/image_writer.h
new file mode 100644
index 0000000..79f549e
--- /dev/null
+++ b/include/image_writer.h
@@ -0,0 +1,31 @@
+#ifndef GSR_IMAGE_WRITER_H
+#define GSR_IMAGE_WRITER_H
+
+#include <stdbool.h>
+
+typedef struct gsr_egl gsr_egl;
+
+typedef enum {
+ GSR_IMAGE_FORMAT_JPEG,
+ GSR_IMAGE_FORMAT_PNG
+} gsr_image_format;
+
+typedef enum {
+ GSR_IMAGE_WRITER_SOURCE_OPENGL
+} gsr_image_writer_source;
+
+typedef struct {
+ gsr_image_writer_source source;
+ gsr_egl *egl;
+ int width;
+ int height;
+ unsigned int texture;
+} gsr_image_writer;
+
+bool gsr_image_writer_init(gsr_image_writer *self, gsr_image_writer_source source, gsr_egl *egl, int width, int height);
+void gsr_image_writer_deinit(gsr_image_writer *self);
+
+/* Quality is between 1 and 100 where 100 is the max quality. Quality doesn't apply to lossless formats */
+bool gsr_image_writer_write_to_file(gsr_image_writer *self, const char *filepath, gsr_image_format image_format, int quality);
+
+#endif /* GSR_IMAGE_WRITER_H */
diff --git a/include/pipewire_audio.h b/include/pipewire_audio.h
new file mode 100644
index 0000000..e2ffd49
--- /dev/null
+++ b/include/pipewire_audio.h
@@ -0,0 +1,128 @@
+#ifndef GSR_PIPEWIRE_AUDIO_H
+#define GSR_PIPEWIRE_AUDIO_H
+
+#include <pipewire/thread-loop.h>
+#include <pipewire/context.h>
+#include <pipewire/core.h>
+#include <spa/utils/hook.h>
+
+#include <stdbool.h>
+
+#define GSR_PIPEWIRE_AUDIO_MAX_STREAM_NODES 128
+#define GSR_PIPEWIRE_AUDIO_MAX_PORTS 256
+#define GSR_PIPEWIRE_AUDIO_MAX_REQUESTED_LINKS 32
+#define GSR_PIPEWIRE_AUDIO_MAX_VIRTUAL_SINKS 32
+
+typedef enum {
+ GSR_PIPEWIRE_AUDIO_NODE_TYPE_STREAM_OUTPUT, /* Application audio */
+ GSR_PIPEWIRE_AUDIO_NODE_TYPE_STREAM_INPUT, /* Audio recording input */
+ GSR_PIPEWIRE_AUDIO_NODE_TYPE_SINK_OR_SOURCE /* Audio output or input device or combined (virtual) sink */
+} gsr_pipewire_audio_node_type;
+
+typedef struct {
+ uint32_t id;
+ char *name;
+ gsr_pipewire_audio_node_type type;
+} gsr_pipewire_audio_node;
+
+typedef enum {
+ GSR_PIPEWIRE_AUDIO_PORT_DIRECTION_INPUT,
+ GSR_PIPEWIRE_AUDIO_PORT_DIRECTION_OUTPUT
+} gsr_pipewire_audio_port_direction;
+
+typedef struct {
+ uint32_t id;
+ uint32_t node_id;
+ gsr_pipewire_audio_port_direction direction;
+ char *name;
+} gsr_pipewire_audio_port;
+
+typedef enum {
+ GSR_PIPEWIRE_AUDIO_LINK_INPUT_TYPE_STREAM, /* Application */
+ GSR_PIPEWIRE_AUDIO_LINK_INPUT_TYPE_SINK /* Combined (virtual) sink */
+} gsr_pipewire_audio_link_input_type;
+
+typedef struct {
+ char **output_names;
+ int num_output_names;
+ char *input_name;
+ bool inverted;
+ gsr_pipewire_audio_node_type output_type;
+ gsr_pipewire_audio_link_input_type input_type;
+} gsr_pipewire_audio_requested_link;
+
+typedef struct {
+ struct pw_thread_loop *thread_loop;
+ struct pw_context *context;
+ struct pw_core *core;
+ struct spa_hook core_listener;
+ struct pw_registry *registry;
+ struct spa_hook registry_listener;
+ int server_version_sync;
+
+ gsr_pipewire_audio_node stream_nodes[GSR_PIPEWIRE_AUDIO_MAX_STREAM_NODES];
+ int num_stream_nodes;
+
+ gsr_pipewire_audio_port ports[GSR_PIPEWIRE_AUDIO_MAX_PORTS];
+ int num_ports;
+
+ gsr_pipewire_audio_requested_link requested_links[GSR_PIPEWIRE_AUDIO_MAX_REQUESTED_LINKS];
+ int num_requested_links;
+
+ struct pw_proxy *virtual_sink_proxies[GSR_PIPEWIRE_AUDIO_MAX_VIRTUAL_SINKS];
+ int num_virtual_sink_proxies;
+} gsr_pipewire_audio;
+
+bool gsr_pipewire_audio_init(gsr_pipewire_audio *self);
+void gsr_pipewire_audio_deinit(gsr_pipewire_audio *self);
+
+bool gsr_pipewire_audio_create_virtual_sink(gsr_pipewire_audio *self, const char *name);
+
+/*
+ This function links audio source outputs from applications that match the name |app_names| to the input
+ that matches the name |stream_name_input|.
+ If an application or a new application starts outputting audio after this function is called and the app name matches
+ then it will automatically link the audio sources.
+ |app_names| and |stream_name_input| are case-insensitive matches.
+*/
+bool gsr_pipewire_audio_add_link_from_apps_to_stream(gsr_pipewire_audio *self, const char **app_names, int num_app_names, const char *stream_name_input);
+/*
+ This function links audio source outputs from all applications except the ones that match the name |app_names| to the input
+ that matches the name |stream_name_input|.
+ If an application or a new application starts outputting audio after this function is called and the app name doesn't match
+ then it will automatically link the audio sources.
+ |app_names| and |stream_name_input| are case-insensitive matches.
+*/
+bool gsr_pipewire_audio_add_link_from_apps_to_stream_inverted(gsr_pipewire_audio *self, const char **app_names, int num_app_names, const char *stream_name_input);
+
+/*
+ This function links audio source outputs from applications that match the name |app_names| to the input
+ that matches the name |sink_name_input|.
+ If an application or a new application starts outputting audio after this function is called and the app name matches
+ then it will automatically link the audio sources.
+ |app_names| and |sink_name_input| are case-insensitive matches.
+*/
+bool gsr_pipewire_audio_add_link_from_apps_to_sink(gsr_pipewire_audio *self, const char **app_names, int num_app_names, const char *sink_name_input);
+/*
+ This function links audio source outputs from all applications except the ones that match the name |app_names| to the input
+ that matches the name |sink_name_input|.
+ If an application or a new application starts outputting audio after this function is called and the app name doesn't match
+ then it will automatically link the audio sources.
+ |app_names| and |sink_name_input| are case-insensitive matches.
+*/
+bool gsr_pipewire_audio_add_link_from_apps_to_sink_inverted(gsr_pipewire_audio *self, const char **app_names, int num_app_names, const char *sink_name_input);
+
+/*
+ This function links audio source outputs from devices that match the name |source_names| to the input
+ that matches the name |sink_name_input|.
+ If a device or a new device starts outputting audio after this function is called and the device name matches
+ then it will automatically link the audio sources.
+ |source_names| and |sink_name_input| are case-insensitive matches.
+*/
+bool gsr_pipewire_audio_add_link_from_sources_to_sink(gsr_pipewire_audio *self, const char **source_names, int num_source_names, const char *sink_name_input);
+
+/* Return true to continue */
+typedef bool (*gsr_pipewire_audio_app_query_callback)(const char *app_name, void *userdata);
+void gsr_pipewire_audio_for_each_app(gsr_pipewire_audio *self, gsr_pipewire_audio_app_query_callback callback, void *userdata);
+
+#endif /* GSR_PIPEWIRE_AUDIO_H */
diff --git a/include/pipewire.h b/include/pipewire_video.h
index 1908e2d..92622b8 100644
--- a/include/pipewire.h
+++ b/include/pipewire_video.h
@@ -1,5 +1,5 @@
-#ifndef GSR_PIPEWIRE_H
-#define GSR_PIPEWIRE_H
+#ifndef GSR_PIPEWIRE_VIDEO_H
+#define GSR_PIPEWIRE_VIDEO_H
#include <stdbool.h>
#include <stdint.h>
@@ -8,9 +8,9 @@
#include <spa/utils/hook.h>
#include <spa/param/video/format.h>
-#define GSR_PIPEWIRE_MAX_MODIFIERS 1024
-#define GSR_PIPEWIRE_NUM_VIDEO_FORMATS 6
-#define GSR_PIPEWIRE_DMABUF_MAX_PLANES 4
+#define GSR_PIPEWIRE_VIDEO_MAX_MODIFIERS 1024
+#define GSR_PIPEWIRE_VIDEO_MAX_VIDEO_FORMATS 12
+#define GSR_PIPEWIRE_VIDEO_DMABUF_MAX_PLANES 4
typedef struct gsr_egl gsr_egl;
@@ -18,23 +18,23 @@ typedef struct {
int major;
int minor;
int micro;
-} gsr_pipewire_data_version;
+} gsr_pipewire_video_data_version;
typedef struct {
uint32_t fps_num;
uint32_t fps_den;
-} gsr_pipewire_video_info;
+} gsr_pipewire_video_video_info;
typedef struct {
int fd;
uint32_t offset;
int32_t stride;
-} gsr_pipewire_dmabuf_data;
+} gsr_pipewire_video_dmabuf_data;
typedef struct {
int x, y;
int width, height;
-} gsr_pipewire_region;
+} gsr_pipewire_video_region;
typedef struct {
enum spa_video_format format;
@@ -82,31 +82,31 @@ typedef struct {
uint32_t width, height;
} crop;
- gsr_video_format supported_video_formats[GSR_PIPEWIRE_NUM_VIDEO_FORMATS];
+ gsr_video_format supported_video_formats[GSR_PIPEWIRE_VIDEO_MAX_VIDEO_FORMATS];
- gsr_pipewire_data_version server_version;
- gsr_pipewire_video_info video_info;
- gsr_pipewire_dmabuf_data dmabuf_data[GSR_PIPEWIRE_DMABUF_MAX_PLANES];
+ gsr_pipewire_video_data_version server_version;
+ gsr_pipewire_video_video_info video_info;
+ gsr_pipewire_video_dmabuf_data dmabuf_data[GSR_PIPEWIRE_VIDEO_DMABUF_MAX_PLANES];
size_t dmabuf_num_planes;
bool no_modifiers_fallback;
bool external_texture_fallback;
- uint64_t modifiers[GSR_PIPEWIRE_MAX_MODIFIERS];
+ uint64_t modifiers[GSR_PIPEWIRE_VIDEO_MAX_MODIFIERS];
size_t num_modifiers;
-} gsr_pipewire;
+} gsr_pipewire_video;
/*
|capture_cursor| only applies to when capturing a window or region.
In other cases |pipewire_node|'s setup will determine if the cursor is included.
Note that the cursor is not guaranteed to be shown even if set to true, it depends on the wayland compositor.
*/
-bool gsr_pipewire_init(gsr_pipewire *self, int pipewire_fd, uint32_t pipewire_node, int fps, bool capture_cursor, gsr_egl *egl);
-void gsr_pipewire_deinit(gsr_pipewire *self);
+bool gsr_pipewire_video_init(gsr_pipewire_video *self, int pipewire_fd, uint32_t pipewire_node, int fps, bool capture_cursor, gsr_egl *egl);
+void gsr_pipewire_video_deinit(gsr_pipewire_video *self);
-/* |dmabuf_data| should be at least GSR_PIPEWIRE_DMABUF_MAX_PLANES in size */
-bool gsr_pipewire_map_texture(gsr_pipewire *self, gsr_texture_map texture_map, gsr_pipewire_region *region, gsr_pipewire_region *cursor_region, gsr_pipewire_dmabuf_data *dmabuf_data, int *num_dmabuf_data, uint32_t *fourcc, uint64_t *modifiers, bool *using_external_image);
-bool gsr_pipewire_is_damaged(gsr_pipewire *self);
-void gsr_pipewire_clear_damage(gsr_pipewire *self);
+/* |dmabuf_data| should be at least GSR_PIPEWIRE_VIDEO_DMABUF_MAX_PLANES in size */
+bool gsr_pipewire_video_map_texture(gsr_pipewire_video *self, gsr_texture_map texture_map, gsr_pipewire_video_region *region, gsr_pipewire_video_region *cursor_region, gsr_pipewire_video_dmabuf_data *dmabuf_data, int *num_dmabuf_data, uint32_t *fourcc, uint64_t *modifiers, bool *using_external_image);
+bool gsr_pipewire_video_is_damaged(gsr_pipewire_video *self);
+void gsr_pipewire_video_clear_damage(gsr_pipewire_video *self);
-#endif /* GSR_PIPEWIRE_H */
+#endif /* GSR_PIPEWIRE_VIDEO_H */
diff --git a/include/sound.hpp b/include/sound.hpp
index 7bcc120..215e167 100644
--- a/include/sound.hpp
+++ b/include/sound.hpp
@@ -26,7 +26,7 @@ typedef struct {
unsigned int frames;
} SoundDevice;
-struct AudioInput {
+struct AudioDevice {
std::string name;
std::string description;
};
@@ -34,10 +34,22 @@ struct AudioInput {
struct AudioDevices {
std::string default_output;
std::string default_input;
- std::vector<AudioInput> audio_inputs;
+ std::vector<AudioDevice> audio_inputs;
+};
+
+enum class AudioInputType {
+ DEVICE,
+ APPLICATION
+};
+
+struct AudioInput {
+ std::string name;
+ AudioInputType type = AudioInputType::DEVICE;
+ bool inverted = false;
};
struct MergedAudioInputs {
+ std::string track_name;
std::vector<AudioInput> audio_inputs;
};
@@ -48,9 +60,7 @@ typedef enum {
} AudioFormat;
/*
- Get a sound device by name, returning the device into the @device parameter.
- The device should be closed with @sound_device_close after it has been used
- to clean up internal resources.
+ Get a sound device by name, returning the device into the |device| parameter.
Returns 0 on success, or a negative value on failure.
*/
int sound_device_get_by_name(SoundDevice *device, const char *device_name, const char *description, unsigned int num_channels, unsigned int period_frame_size, AudioFormat audio_format);
@@ -64,5 +74,6 @@ void sound_device_close(SoundDevice *device);
int sound_device_read_next_chunk(SoundDevice *device, void **buffer, double timeout_sec, double *latency_seconds);
AudioDevices get_pulseaudio_inputs();
+bool pulseaudio_server_is_pipewire();
#endif /* GPU_SCREEN_RECORDER_H */
diff --git a/include/utils.h b/include/utils.h
index 92eb851..f9b41b9 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -7,6 +7,8 @@
#include <stdbool.h>
#include <stdint.h>
+#define CONNECTOR_TYPE_COUNTS 32
+
typedef struct AVCodecContext AVCodecContext;
typedef struct AVFrame AVFrame;
@@ -27,17 +29,31 @@ typedef struct {
bool found_monitor;
} get_monitor_by_name_userdata;
+typedef struct {
+ int type;
+ int count;
+ int count_active;
+} drm_connector_type_count;
+
double clock_get_monotonic_seconds(void);
+bool generate_random_characters(char *buffer, int buffer_size, const char *alphabet, size_t alphabet_size);
+bool generate_random_characters_standard_alphabet(char *buffer, int buffer_size);
typedef void (*active_monitor_callback)(const gsr_monitor *monitor, void *userdata);
void for_each_active_monitor_output_x11_not_cached(Display *display, active_monitor_callback callback, void *userdata);
-void for_each_active_monitor_output_x11(const gsr_egl *egl, active_monitor_callback callback, void *userdata);
-void for_each_active_monitor_output(const gsr_egl *egl, gsr_connection_type connection_type, active_monitor_callback callback, void *userdata);
+void for_each_active_monitor_output(const gsr_window *window, const char *card_path, gsr_connection_type connection_type, active_monitor_callback callback, void *userdata);
bool get_monitor_by_name(const gsr_egl *egl, gsr_connection_type connection_type, const char *name, gsr_monitor *monitor);
-gsr_monitor_rotation drm_monitor_get_display_server_rotation(const gsr_egl *egl, const gsr_monitor *monitor);
+gsr_monitor_rotation drm_monitor_get_display_server_rotation(const gsr_window *window, const gsr_monitor *monitor);
+
+int get_connector_type_by_name(const char *name);
+drm_connector_type_count* drm_connector_types_get_index(drm_connector_type_count *type_counts, int *num_type_counts, int connector_type);
+uint32_t monitor_identifier_from_type_and_count(int monitor_type_index, int monitor_type_count);
bool gl_get_gpu_info(gsr_egl *egl, gsr_gpu_info *info);
+bool version_greater_than(int major, int minor, int patch, int other_major, int other_minor, int other_patch);
+bool gl_driver_version_greater_than(const gsr_gpu_info *gpu_info, int major, int minor, int patch);
+bool try_card_has_valid_plane(const char *card_path);
/* |output| should be at least 128 bytes in size */
bool gsr_get_valid_card_path(gsr_egl *egl, char *output, bool is_monitor_capture);
/* |render_path| should be at least 128 bytes in size */
@@ -51,4 +67,6 @@ bool video_codec_context_is_vaapi(AVCodecContext *video_codec_context);
bool vaapi_copy_drm_planes_to_video_surface(AVCodecContext *video_codec_context, AVFrame *video_frame, vec2i source_pos, vec2i source_size, vec2i dest_pos, vec2i dest_size, uint32_t format, vec2i size, const int *fds, const uint32_t *offsets, const uint32_t *pitches, const uint64_t *modifiers, int num_planes);
bool vaapi_copy_egl_image_to_video_surface(gsr_egl *egl, EGLImage image, vec2i source_pos, vec2i source_size, vec2i dest_pos, vec2i dest_size, AVCodecContext *video_codec_context, AVFrame *video_frame);
+vec2i scale_keep_aspect_ratio(vec2i from, vec2i to);
+
#endif /* GSR_UTILS_H */
diff --git a/include/vec2.h b/include/vec2.h
index 3e33cfb..8fd3858 100644
--- a/include/vec2.h
+++ b/include/vec2.h
@@ -9,4 +9,8 @@ typedef struct {
float x, y;
} vec2f;
+typedef struct {
+ double x, y;
+} vec2d;
+
#endif /* VEC2_H */
diff --git a/include/window/window.h b/include/window/window.h
new file mode 100644
index 0000000..7839f6a
--- /dev/null
+++ b/include/window/window.h
@@ -0,0 +1,37 @@
+#ifndef GSR_WINDOW_H
+#define GSR_WINDOW_H
+
+#include "../utils.h"
+#include <stdbool.h>
+
+typedef union _XEvent XEvent;
+typedef struct gsr_window gsr_window;
+
+typedef enum {
+ GSR_DISPLAY_SERVER_X11,
+ GSR_DISPLAY_SERVER_WAYLAND
+} gsr_display_server;
+
+struct gsr_window {
+ void (*destroy)(gsr_window *self);
+ /* Returns true if an event is available */
+ bool (*process_event)(gsr_window *self);
+ XEvent* (*get_event_data)(gsr_window *self); /* can be NULL */
+ gsr_display_server (*get_display_server)(void);
+ void* (*get_display)(gsr_window *self);
+ void* (*get_window)(gsr_window *self);
+ void (*for_each_active_monitor_output_cached)(const gsr_window *self, active_monitor_callback callback, void *userdata);
+ void *priv;
+};
+
+void gsr_window_destroy(gsr_window *self);
+
+/* Returns true if an event is available */
+bool gsr_window_process_event(gsr_window *self);
+XEvent* gsr_window_get_event_data(gsr_window *self);
+gsr_display_server gsr_window_get_display_server(const gsr_window *self);
+void* gsr_window_get_display(gsr_window *self);
+void* gsr_window_get_window(gsr_window *self);
+void gsr_window_for_each_active_monitor_output_cached(const gsr_window *self, active_monitor_callback callback, void *userdata);
+
+#endif /* GSR_WINDOW_H */
diff --git a/include/window/window_wayland.h b/include/window/window_wayland.h
new file mode 100644
index 0000000..3535b0f
--- /dev/null
+++ b/include/window/window_wayland.h
@@ -0,0 +1,8 @@
+#ifndef GSR_WINDOW_WAYLAND_H
+#define GSR_WINDOW_WAYLAND_H
+
+#include "window.h"
+
+gsr_window* gsr_window_wayland_create(void);
+
+#endif /* GSR_WINDOW_WAYLAND_H */
diff --git a/include/window/window_x11.h b/include/window/window_x11.h
new file mode 100644
index 0000000..e0c2948
--- /dev/null
+++ b/include/window/window_x11.h
@@ -0,0 +1,10 @@
+#ifndef GSR_WINDOW_X11_H
+#define GSR_WINDOW_X11_H
+
+#include "window.h"
+
+typedef struct _XDisplay Display;
+
+gsr_window* gsr_window_x11_create(Display *display);
+
+#endif /* GSR_WINDOW_X11_H */