Move card path to egl struct, use egl struct for monitor enumeration

This commit is contained in:
dec05eba
2024-02-09 00:23:52 +01:00
parent 463393a0c0
commit 3eb7bae12c
15 changed files with 92 additions and 135 deletions

View File

@@ -11,7 +11,6 @@ typedef struct {
gsr_egl *egl; gsr_egl *egl;
const char *display_to_capture; /* if this is "screen", then the first monitor is captured. A copy is made of this */ const char *display_to_capture; /* if this is "screen", then the first monitor is captured. A copy is made of this */
gsr_gpu_info gpu_inf; gsr_gpu_info gpu_inf;
const char *card_path; /* reference */
} gsr_capture_kms_cuda_params; } gsr_capture_kms_cuda_params;
gsr_capture* gsr_capture_kms_cuda_create(const gsr_capture_kms_cuda_params *params); gsr_capture* gsr_capture_kms_cuda_create(const gsr_capture_kms_cuda_params *params);

View File

@@ -12,7 +12,6 @@ typedef struct {
gsr_egl *egl; gsr_egl *egl;
const char *display_to_capture; /* if this is "screen", then the first monitor is captured. A copy is made of this */ const char *display_to_capture; /* if this is "screen", then the first monitor is captured. A copy is made of this */
gsr_gpu_info gpu_inf; gsr_gpu_info gpu_inf;
const char *card_path; /* reference */
bool wayland; bool wayland;
bool hdr; bool hdr;
gsr_color_range color_range; gsr_color_range color_range;

View File

@@ -4,13 +4,9 @@
#include "capture.h" #include "capture.h"
#include "../egl.h" #include "../egl.h"
#include "../vec2.h" #include "../vec2.h"
#include <X11/X.h>
typedef struct _XDisplay Display;
typedef struct { typedef struct {
gsr_egl *egl; gsr_egl *egl;
Display *dpy;
Window window; Window window;
bool follow_focused; /* If this is set then |window| is ignored */ bool follow_focused; /* If this is set then |window| is ignored */
vec2i region_size; /* This is currently only used with |follow_focused| */ vec2i region_size; /* This is currently only used with |follow_focused| */

View File

@@ -5,17 +5,12 @@
#include "../egl.h" #include "../egl.h"
#include "../vec2.h" #include "../vec2.h"
#include "../color_conversion.h" #include "../color_conversion.h"
#include <X11/X.h>
typedef struct _XDisplay Display;
typedef struct { typedef struct {
gsr_egl *egl; gsr_egl *egl;
Display *dpy;
Window window; Window window;
bool follow_focused; /* If this is set then |window| is ignored */ bool follow_focused; /* If this is set then |window| is ignored */
vec2i region_size; /* This is currently only used with |follow_focused| */ vec2i region_size; /* This is currently only used with |follow_focused| */
const char *card_path; /* reference */
gsr_color_range color_range; gsr_color_range color_range;
} gsr_capture_xcomposite_vaapi_params; } gsr_capture_xcomposite_vaapi_params;

View File

@@ -146,6 +146,7 @@ typedef struct {
gsr_x11 x11; gsr_x11 x11;
gsr_wayland wayland; gsr_wayland wayland;
char card_path[128];
int fd; int fd;
uint32_t x; uint32_t x;
@@ -234,7 +235,7 @@ bool gsr_egl_load(gsr_egl *self, Display *dpy, bool wayland);
void gsr_egl_unload(gsr_egl *self); void gsr_egl_unload(gsr_egl *self);
/* wayland protocol capture, does not include kms capture */ /* wayland protocol capture, does not include kms capture */
bool gsr_egl_supports_wayland_capture(gsr_egl *self); bool gsr_egl_supports_wayland_capture(const gsr_egl *self);
bool gsr_egl_start_capture(gsr_egl *self, const char *monitor_to_capture); bool gsr_egl_start_capture(gsr_egl *self, const char *monitor_to_capture);
void gsr_egl_update(gsr_egl *self); void gsr_egl_update(gsr_egl *self);
void gsr_egl_cleanup_frame(gsr_egl *self); void gsr_egl_cleanup_frame(gsr_egl *self);

View File

@@ -43,8 +43,9 @@ typedef struct {
double clock_get_monotonic_seconds(void); double clock_get_monotonic_seconds(void);
typedef void (*active_monitor_callback)(const gsr_monitor *monitor, void *userdata); typedef void (*active_monitor_callback)(const gsr_monitor *monitor, void *userdata);
void for_each_active_monitor_output(void *connection, gsr_connection_type connection_type, active_monitor_callback callback, void *userdata); void for_each_active_monitor_output_x11(Display *display, active_monitor_callback callback, void *userdata);
bool get_monitor_by_name(void *connection, gsr_connection_type connection_type, const char *name, gsr_monitor *monitor); void for_each_active_monitor_output(const gsr_egl *egl, 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);
bool gl_get_gpu_info(gsr_egl *egl, gsr_gpu_info *info); bool gl_get_gpu_info(gsr_egl *egl, gsr_gpu_info *info);

View File

@@ -152,7 +152,7 @@ static int gsr_capture_kms_cuda_start(gsr_capture *cap, AVCodecContext *video_co
} }
cap_kms->using_wayland_capture = true; cap_kms->using_wayland_capture = true;
} else { } else {
int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.card_path); int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.egl->card_path);
if(kms_init_res != 0) { if(kms_init_res != 0) {
gsr_capture_kms_cuda_stop(cap, video_codec_context); gsr_capture_kms_cuda_stop(cap, video_codec_context);
return kms_init_res; return kms_init_res;
@@ -163,9 +163,9 @@ static int gsr_capture_kms_cuda_start(gsr_capture *cap, AVCodecContext *video_co
cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture), cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture),
0 0
}; };
for_each_active_monitor_output((void*)cap_kms->params.card_path, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata); for_each_active_monitor_output(cap_kms->params.egl, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata);
if(!get_monitor_by_name((void*)cap_kms->params.card_path, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) { if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_cuda_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture); fprintf(stderr, "gsr error: gsr_capture_kms_cuda_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_cuda_stop(cap, video_codec_context); gsr_capture_kms_cuda_stop(cap, video_codec_context);
return -1; return -1;
@@ -239,9 +239,6 @@ static bool cuda_register_opengl_texture(gsr_capture_kms_cuda *cap_kms) {
static void gsr_capture_kms_cuda_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) { static void gsr_capture_kms_cuda_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) {
gsr_capture_kms_cuda *cap_kms = cap->priv; gsr_capture_kms_cuda *cap_kms = cap->priv;
// TODO:
cap_kms->params.egl->glClear(GL_COLOR_BUFFER_BIT);
if(!cap_kms->created_hw_frame) { if(!cap_kms->created_hw_frame) {
cap_kms->created_hw_frame = true; cap_kms->created_hw_frame = true;
@@ -398,6 +395,8 @@ static int gsr_capture_kms_cuda_capture(gsr_capture *cap, AVFrame *frame) {
(void)frame; (void)frame;
gsr_capture_kms_cuda *cap_kms = cap->priv; gsr_capture_kms_cuda *cap_kms = cap->priv;
cap_kms->params.egl->glClear(GL_COLOR_BUFFER_BIT);
for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) { for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) {
if(cap_kms->kms_response.fds[i].fd > 0) if(cap_kms->kms_response.fds[i].fd > 0)
close(cap_kms->kms_response.fds[i].fd); close(cap_kms->kms_response.fds[i].fd);

View File

@@ -58,8 +58,8 @@ static void gsr_capture_kms_vaapi_stop(gsr_capture *cap, AVCodecContext *video_c
static bool drm_create_codec_context(gsr_capture_kms_vaapi *cap_kms, AVCodecContext *video_codec_context) { static bool drm_create_codec_context(gsr_capture_kms_vaapi *cap_kms, AVCodecContext *video_codec_context) {
char render_path[128]; char render_path[128];
if(!gsr_card_path_get_render_path(cap_kms->params.card_path, render_path)) { if(!gsr_card_path_get_render_path(cap_kms->params.egl->card_path, render_path)) {
fprintf(stderr, "gsr error: failed to get /dev/dri/renderDXXX file from %s\n", cap_kms->params.card_path); fprintf(stderr, "gsr error: failed to get /dev/dri/renderDXXX file from %s\n", cap_kms->params.egl->card_path);
return false; return false;
} }
@@ -146,7 +146,7 @@ static int gsr_capture_kms_vaapi_start(gsr_capture *cap, AVCodecContext *video_c
} }
cap_kms->using_wayland_capture = true; cap_kms->using_wayland_capture = true;
} else { } else {
int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.card_path); int kms_init_res = gsr_kms_client_init(&cap_kms->kms_client, cap_kms->params.egl->card_path);
if(kms_init_res != 0) { if(kms_init_res != 0) {
gsr_capture_kms_vaapi_stop(cap, video_codec_context); gsr_capture_kms_vaapi_stop(cap, video_codec_context);
return kms_init_res; return kms_init_res;
@@ -157,9 +157,9 @@ static int gsr_capture_kms_vaapi_start(gsr_capture *cap, AVCodecContext *video_c
cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture), cap_kms->params.display_to_capture, strlen(cap_kms->params.display_to_capture),
0, 0,
}; };
for_each_active_monitor_output((void*)cap_kms->params.card_path, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata); for_each_active_monitor_output(cap_kms->params.egl, GSR_CONNECTION_DRM, monitor_callback, &monitor_callback_userdata);
if(!get_monitor_by_name((void*)cap_kms->params.card_path, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) { if(!get_monitor_by_name(cap_kms->params.egl, GSR_CONNECTION_DRM, cap_kms->params.display_to_capture, &monitor)) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture); fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_start: failed to find monitor by name \"%s\"\n", cap_kms->params.display_to_capture);
gsr_capture_kms_vaapi_stop(cap, video_codec_context); gsr_capture_kms_vaapi_stop(cap, video_codec_context);
return -1; return -1;
@@ -193,9 +193,6 @@ static uint32_t fourcc(uint32_t a, uint32_t b, uint32_t c, uint32_t d) {
static void gsr_capture_kms_vaapi_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) { static void gsr_capture_kms_vaapi_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) {
gsr_capture_kms_vaapi *cap_kms = cap->priv; gsr_capture_kms_vaapi *cap_kms = cap->priv;
// TODO:
cap_kms->params.egl->glClear(GL_COLOR_BUFFER_BIT);
if(!cap_kms->created_hw_frame) { if(!cap_kms->created_hw_frame) {
cap_kms->created_hw_frame = true; cap_kms->created_hw_frame = true;
@@ -462,6 +459,8 @@ static void gsr_capture_kms_vaapi_set_hdr_metadata(gsr_capture_kms_vaapi *cap_km
static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) { static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) {
gsr_capture_kms_vaapi *cap_kms = cap->priv; gsr_capture_kms_vaapi *cap_kms = cap->priv;
cap_kms->params.egl->glClear(GL_COLOR_BUFFER_BIT);
for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) { for(int i = 0; i < cap_kms->kms_response.num_fds; ++i) {
if(cap_kms->kms_response.fds[i].fd > 0) if(cap_kms->kms_response.fds[i].fd > 0)
close(cap_kms->kms_response.fds[i].fd); close(cap_kms->kms_response.fds[i].fd);

View File

@@ -189,7 +189,7 @@ static bool ffmpeg_create_cuda_contexts(gsr_capture_nvfbc *cap_nvfbc, AVCodecCon
static int gsr_capture_nvfbc_start(gsr_capture *cap, AVCodecContext *video_codec_context) { static int gsr_capture_nvfbc_start(gsr_capture *cap, AVCodecContext *video_codec_context) {
gsr_capture_nvfbc *cap_nvfbc = cap->priv; gsr_capture_nvfbc *cap_nvfbc = cap->priv;
if(!gsr_cuda_load(&cap_nvfbc->cuda, cap_nvfbc->params.dpy, cap_nvfbc->params.overclock)) if(!gsr_cuda_load(&cap_nvfbc->cuda, cap_nvfbc->params.egl->x11.dpy, cap_nvfbc->params.overclock))
return -1; return -1;
if(!gsr_capture_nvfbc_load_library(cap)) { if(!gsr_capture_nvfbc_load_library(cap)) {
@@ -269,8 +269,8 @@ static int gsr_capture_nvfbc_start(gsr_capture *cap, AVCodecContext *video_codec
goto error_cleanup; goto error_cleanup;
} }
uint32_t tracking_width = XWidthOfScreen(DefaultScreenOfDisplay(cap_nvfbc->params.dpy)); uint32_t tracking_width = XWidthOfScreen(DefaultScreenOfDisplay(cap_nvfbc->params.egl->x11.dpy));
uint32_t tracking_height = XHeightOfScreen(DefaultScreenOfDisplay(cap_nvfbc->params.dpy)); uint32_t tracking_height = XHeightOfScreen(DefaultScreenOfDisplay(cap_nvfbc->params.egl->x11.dpy));
tracking_type = strcmp(cap_nvfbc->params.display_to_capture, "screen") == 0 ? NVFBC_TRACKING_SCREEN : NVFBC_TRACKING_OUTPUT; tracking_type = strcmp(cap_nvfbc->params.display_to_capture, "screen") == 0 ? NVFBC_TRACKING_SCREEN : NVFBC_TRACKING_OUTPUT;
if(tracking_type == NVFBC_TRACKING_OUTPUT) { if(tracking_type == NVFBC_TRACKING_OUTPUT) {
if(!status_params.bXRandRAvailable) { if(!status_params.bXRandRAvailable) {

View File

@@ -154,12 +154,12 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv; gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
if(cap_xcomp->params.follow_focused) { if(cap_xcomp->params.follow_focused) {
cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.dpy, "_NET_ACTIVE_WINDOW", False); cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.egl->x11.dpy, "_NET_ACTIVE_WINDOW", False);
if(!cap_xcomp->net_active_window_atom) { if(!cap_xcomp->net_active_window_atom) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start failed: failed to get _NET_ACTIVE_WINDOW atom\n"); fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start failed: failed to get _NET_ACTIVE_WINDOW atom\n");
return -1; return -1;
} }
cap_xcomp->window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); cap_xcomp->window = get_focused_window(cap_xcomp->params.egl->x11.dpy, cap_xcomp->net_active_window_atom);
} else { } else {
cap_xcomp->window = cap_xcomp->params.window; cap_xcomp->window = cap_xcomp->params.window;
} }
@@ -169,7 +169,7 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
XWindowAttributes attr; XWindowAttributes attr;
attr.width = 0; attr.width = 0;
attr.height = 0; attr.height = 0;
if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->window, &attr) && !cap_xcomp->params.follow_focused) { if(!XGetWindowAttributes(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, &attr) && !cap_xcomp->params.follow_focused) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start failed: invalid window id: %lu\n", cap_xcomp->window); fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start failed: invalid window id: %lu\n", cap_xcomp->window);
return -1; return -1;
} }
@@ -178,12 +178,12 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
cap_xcomp->window_size.y = max_int(attr.height, 0); cap_xcomp->window_size.y = max_int(attr.height, 0);
if(cap_xcomp->params.follow_focused) if(cap_xcomp->params.follow_focused)
XSelectInput(cap_xcomp->params.dpy, DefaultRootWindow(cap_xcomp->params.dpy), PropertyChangeMask); XSelectInput(cap_xcomp->params.egl->x11.dpy, DefaultRootWindow(cap_xcomp->params.egl->x11.dpy), PropertyChangeMask);
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask);
cap_xcomp->params.egl->eglSwapInterval(cap_xcomp->params.egl->egl_display, 0); cap_xcomp->params.egl->eglSwapInterval(cap_xcomp->params.egl->egl_display, 0);
if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.dpy, cap_xcomp->window, cap_xcomp->params.egl) != 0 && !cap_xcomp->params.follow_focused) { if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, cap_xcomp->params.egl) != 0 && !cap_xcomp->params.follow_focused) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start: failed to get window texture for window %ld\n", cap_xcomp->window); fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start: failed to get window texture for window %ld\n", cap_xcomp->window);
return -1; return -1;
} }
@@ -214,7 +214,7 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v
return -1; return -1;
} }
if(!gsr_cuda_load(&cap_xcomp->cuda, cap_xcomp->params.dpy, cap_xcomp->params.overclock)) { if(!gsr_cuda_load(&cap_xcomp->cuda, cap_xcomp->params.egl->x11.dpy, cap_xcomp->params.overclock)) {
gsr_capture_xcomposite_cuda_stop(cap, video_codec_context); gsr_capture_xcomposite_cuda_stop(cap, video_codec_context);
return -1; return -1;
} }
@@ -262,22 +262,19 @@ static void gsr_capture_xcomposite_cuda_stop(gsr_capture *cap, AVCodecContext *v
gsr_cuda_unload(&cap_xcomp->cuda); gsr_cuda_unload(&cap_xcomp->cuda);
if(cap_xcomp->params.dpy) { if(cap_xcomp->params.egl->x11.dpy) {
// TODO: This causes a crash, why? maybe some other library dlclose xlib and that also happened to unload this??? // TODO: This causes a crash, why? maybe some other library dlclose xlib and that also happened to unload this???
//XCloseDisplay(cap_xcomp->dpy); //XCloseDisplay(cap_xcomp->dpy);
cap_xcomp->params.dpy = NULL; cap_xcomp->params.egl->x11.dpy = NULL;
} }
} }
static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) { static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) {
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv; gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT);
bool init_new_window = false; bool init_new_window = false;
while(XPending(cap_xcomp->params.dpy)) { while(XPending(cap_xcomp->params.egl->x11.dpy)) {
XNextEvent(cap_xcomp->params.dpy, &cap_xcomp->xev); XNextEvent(cap_xcomp->params.egl->x11.dpy, &cap_xcomp->xev);
switch(cap_xcomp->xev.type) { switch(cap_xcomp->xev.type) {
case DestroyNotify: { case DestroyNotify: {
@@ -321,17 +318,17 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v
} }
if(init_new_window) { if(init_new_window) {
Window focused_window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); Window focused_window = get_focused_window(cap_xcomp->params.egl->x11.dpy, cap_xcomp->net_active_window_atom);
if(focused_window != cap_xcomp->window || !cap_xcomp->follow_focused_initialized) { if(focused_window != cap_xcomp->window || !cap_xcomp->follow_focused_initialized) {
cap_xcomp->follow_focused_initialized = true; cap_xcomp->follow_focused_initialized = true;
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, 0); XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, 0);
cap_xcomp->window = focused_window; cap_xcomp->window = focused_window;
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask);
XWindowAttributes attr; XWindowAttributes attr;
attr.width = 0; attr.width = 0;
attr.height = 0; attr.height = 0;
if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->window, &attr)) if(!XGetWindowAttributes(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, &attr))
fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_tick failed: invalid window id: %lu\n", cap_xcomp->window); fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_tick failed: invalid window id: %lu\n", cap_xcomp->window);
cap_xcomp->window_size.x = max_int(attr.width, 0); cap_xcomp->window_size.x = max_int(attr.width, 0);
@@ -339,7 +336,7 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v
cap_xcomp->window_resized = true; cap_xcomp->window_resized = true;
window_texture_deinit(&cap_xcomp->window_texture); window_texture_deinit(&cap_xcomp->window_texture);
window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.dpy, cap_xcomp->window, cap_xcomp->params.egl); // TODO: Do not do the below window_texture_on_resize after this window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, cap_xcomp->params.egl); // TODO: Do not do the below window_texture_on_resize after this
cap_xcomp->texture_size.x = 0; cap_xcomp->texture_size.x = 0;
cap_xcomp->texture_size.y = 0; cap_xcomp->texture_size.y = 0;
@@ -424,6 +421,9 @@ static bool gsr_capture_xcomposite_cuda_should_stop(gsr_capture *cap, bool *err)
static int gsr_capture_xcomposite_cuda_capture(gsr_capture *cap, AVFrame *frame) { static int gsr_capture_xcomposite_cuda_capture(gsr_capture *cap, AVFrame *frame) {
gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv; gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv;
cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT);
vec2i source_pos = { 0, 0 }; vec2i source_pos = { 0, 0 };
vec2i source_size = cap_xcomp->texture_size; vec2i source_size = cap_xcomp->texture_size;

View File

@@ -66,8 +66,8 @@ static Window get_focused_window(Display *display, Atom net_active_window_atom)
static bool drm_create_codec_context(gsr_capture_xcomposite_vaapi *cap_xcomp, AVCodecContext *video_codec_context) { static bool drm_create_codec_context(gsr_capture_xcomposite_vaapi *cap_xcomp, AVCodecContext *video_codec_context) {
char render_path[128]; char render_path[128];
if(!gsr_card_path_get_render_path(cap_xcomp->params.card_path, render_path)) { if(!gsr_card_path_get_render_path(cap_xcomp->params.egl->card_path, render_path)) {
fprintf(stderr, "gsr error: failed to get /dev/dri/renderDXXX file from %s\n", cap_xcomp->params.card_path); fprintf(stderr, "gsr error: failed to get /dev/dri/renderDXXX file from %s\n", cap_xcomp->params.egl->card_path);
return false; return false;
} }
@@ -117,12 +117,12 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext *
gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv; gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv;
if(cap_xcomp->params.follow_focused) { if(cap_xcomp->params.follow_focused) {
cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.dpy, "_NET_ACTIVE_WINDOW", False); cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.egl->x11.dpy, "_NET_ACTIVE_WINDOW", False);
if(!cap_xcomp->net_active_window_atom) { if(!cap_xcomp->net_active_window_atom) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start failed: failed to get _NET_ACTIVE_WINDOW atom\n"); fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start failed: failed to get _NET_ACTIVE_WINDOW atom\n");
return -1; return -1;
} }
cap_xcomp->window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); cap_xcomp->window = get_focused_window(cap_xcomp->params.egl->x11.dpy, cap_xcomp->net_active_window_atom);
} else { } else {
cap_xcomp->window = cap_xcomp->params.window; cap_xcomp->window = cap_xcomp->params.window;
} }
@@ -130,7 +130,7 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext *
/* TODO: Do these in tick, and allow error if follow_focused */ /* TODO: Do these in tick, and allow error if follow_focused */
XWindowAttributes attr; XWindowAttributes attr;
if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->params.window, &attr) && !cap_xcomp->params.follow_focused) { if(!XGetWindowAttributes(cap_xcomp->params.egl->x11.dpy, cap_xcomp->params.window, &attr) && !cap_xcomp->params.follow_focused) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start failed: invalid window id: %lu\n", cap_xcomp->params.window); fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start failed: invalid window id: %lu\n", cap_xcomp->params.window);
return -1; return -1;
} }
@@ -139,10 +139,10 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext *
cap_xcomp->window_size.y = max_int(attr.height, 0); cap_xcomp->window_size.y = max_int(attr.height, 0);
if(cap_xcomp->params.follow_focused) if(cap_xcomp->params.follow_focused)
XSelectInput(cap_xcomp->params.dpy, DefaultRootWindow(cap_xcomp->params.dpy), PropertyChangeMask); XSelectInput(cap_xcomp->params.egl->x11.dpy, DefaultRootWindow(cap_xcomp->params.egl->x11.dpy), PropertyChangeMask);
// TODO: Get select and add these on top of it and then restore at the end. Also do the same in other xcomposite // TODO: Get select and add these on top of it and then restore at the end. Also do the same in other xcomposite
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->params.window, StructureNotifyMask | ExposureMask); XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->params.window, StructureNotifyMask | ExposureMask);
if(!cap_xcomp->params.egl->eglExportDMABUFImageQueryMESA) { if(!cap_xcomp->params.egl->eglExportDMABUFImageQueryMESA) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start: could not find eglExportDMABUFImageQueryMESA\n"); fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start: could not find eglExportDMABUFImageQueryMESA\n");
@@ -156,7 +156,7 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext *
/* Disable vsync */ /* Disable vsync */
cap_xcomp->params.egl->eglSwapInterval(cap_xcomp->params.egl->egl_display, 0); cap_xcomp->params.egl->eglSwapInterval(cap_xcomp->params.egl->egl_display, 0);
if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.dpy, cap_xcomp->params.window, cap_xcomp->params.egl) != 0 && !cap_xcomp->params.follow_focused) { if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.egl->x11.dpy, cap_xcomp->params.window, cap_xcomp->params.egl) != 0 && !cap_xcomp->params.follow_focused) {
fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start: failed to get window texture for window %ld\n", cap_xcomp->params.window); fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start: failed to get window texture for window %ld\n", cap_xcomp->params.window);
return -1; return -1;
} }
@@ -198,13 +198,12 @@ static uint32_t fourcc(uint32_t a, uint32_t b, uint32_t c, uint32_t d) {
static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) { static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext *video_codec_context, AVFrame **frame) {
gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv; gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv;
// TODO:
cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f); cap_xcomp->params.egl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT); cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT);
bool init_new_window = false; bool init_new_window = false;
while(XPending(cap_xcomp->params.dpy)) { while(XPending(cap_xcomp->params.egl->x11.dpy)) {
XNextEvent(cap_xcomp->params.dpy, &cap_xcomp->xev); XNextEvent(cap_xcomp->params.egl->x11.dpy, &cap_xcomp->xev);
switch(cap_xcomp->xev.type) { switch(cap_xcomp->xev.type) {
case DestroyNotify: { case DestroyNotify: {
@@ -248,17 +247,17 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext *
} }
if(init_new_window) { if(init_new_window) {
Window focused_window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); Window focused_window = get_focused_window(cap_xcomp->params.egl->x11.dpy, cap_xcomp->net_active_window_atom);
if(focused_window != cap_xcomp->window || !cap_xcomp->follow_focused_initialized) { if(focused_window != cap_xcomp->window || !cap_xcomp->follow_focused_initialized) {
cap_xcomp->follow_focused_initialized = true; cap_xcomp->follow_focused_initialized = true;
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, 0); XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, 0);
cap_xcomp->window = focused_window; cap_xcomp->window = focused_window;
XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); XSelectInput(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask);
XWindowAttributes attr; XWindowAttributes attr;
attr.width = 0; attr.width = 0;
attr.height = 0; attr.height = 0;
if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->window, &attr)) if(!XGetWindowAttributes(cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, &attr))
fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_tick failed: invalid window id: %lu\n", cap_xcomp->window); fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_tick failed: invalid window id: %lu\n", cap_xcomp->window);
cap_xcomp->window_size.x = max_int(attr.width, 0); cap_xcomp->window_size.x = max_int(attr.width, 0);
@@ -266,7 +265,7 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext *
cap_xcomp->window_resized = true; cap_xcomp->window_resized = true;
window_texture_deinit(&cap_xcomp->window_texture); window_texture_deinit(&cap_xcomp->window_texture);
window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.dpy, cap_xcomp->window, cap_xcomp->params.egl); // TODO: Do not do the below window_texture_on_resize after this window_texture_init(&cap_xcomp->window_texture, cap_xcomp->params.egl->x11.dpy, cap_xcomp->window, cap_xcomp->params.egl); // TODO: Do not do the below window_texture_on_resize after this
cap_xcomp->texture_size.x = 0; cap_xcomp->texture_size.x = 0;
cap_xcomp->texture_size.y = 0; cap_xcomp->texture_size.y = 0;

View File

@@ -456,29 +456,15 @@ void gsr_color_conversion_draw(gsr_color_conversion *self, unsigned int texture_
} }
void gsr_color_conversion_clear(gsr_color_conversion *self) { void gsr_color_conversion_clear(gsr_color_conversion *self) {
float color1[4]; float color1[4] = {0.0f, 0.0f, 0.0f, 1.0f};
float color2[4]; float color2[4] = {0.0f, 0.0f, 0.0f, 1.0f};
switch(self->params.destination_color) { switch(self->params.destination_color) {
case GSR_DESTINATION_COLOR_BGR: { case GSR_DESTINATION_COLOR_BGR: {
color1[0] = 0.0f;
color1[1] = 0.0f;
color1[2] = 0.0f;
color1[3] = 1.0f;
color2[0] = 0.0f;
color2[1] = 0.0f;
color2[2] = 0.0f;
color2[3] = 1.0f;
break; break;
} }
case GSR_DESTINATION_COLOR_NV12: case GSR_DESTINATION_COLOR_NV12:
case GSR_DESTINATION_COLOR_P010: { case GSR_DESTINATION_COLOR_P010: {
color1[0] = 0.0f;
color1[1] = 0.0f;
color1[2] = 0.0f;
color1[3] = 1.0f;
color2[0] = 0.5f; color2[0] = 0.5f;
color2[1] = 0.5f; color2[1] = 0.5f;
color2[2] = 0.0f; color2[2] = 0.0f;

View File

@@ -555,7 +555,7 @@ void gsr_egl_unload(gsr_egl *self) {
memset(self, 0, sizeof(gsr_egl)); memset(self, 0, sizeof(gsr_egl));
} }
bool gsr_egl_supports_wayland_capture(gsr_egl *self) { bool gsr_egl_supports_wayland_capture(const gsr_egl *self) {
// TODO: wlroots capture is broken right now (black screen) on amd and multiple monitors // TODO: wlroots capture is broken right now (black screen) on amd and multiple monitors
// so it has to be disabled right now. Find out why it happens and fix it. // so it has to be disabled right now. Find out why it happens and fix it.
(void)self; (void)self;

View File

@@ -1350,7 +1350,7 @@ static bool is_xwayland(Display *display) {
return true; return true;
bool xwayland_found = false; bool xwayland_found = false;
for_each_active_monitor_output(display, GSR_CONNECTION_X11, xwayland_check_callback, &xwayland_found); for_each_active_monitor_output_x11(display, xwayland_check_callback, &xwayland_found);
return xwayland_found; return xwayland_found;
} }
@@ -1404,7 +1404,7 @@ static void list_supported_video_codecs() {
fflush(stdout); fflush(stdout);
} }
static gsr_capture* create_capture_impl(const char *window_str, const char *screen_region, bool wayland, gsr_gpu_info gpu_inf, gsr_egl &egl, char *card_path, Display *dpy, int fps, bool overclock, VideoCodec video_codec, gsr_color_range color_range) { static gsr_capture* create_capture_impl(const char *window_str, const char *screen_region, bool wayland, gsr_gpu_info gpu_inf, gsr_egl &egl, int fps, bool overclock, VideoCodec video_codec, gsr_color_range color_range) {
vec2i region_size = { 0, 0 }; vec2i region_size = { 0, 0 };
Window src_window_id = None; Window src_window_id = None;
bool follow_focused = false; bool follow_focused = false;
@@ -1440,7 +1440,7 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
if(gsr_egl_supports_wayland_capture(&egl)) { if(gsr_egl_supports_wayland_capture(&egl)) {
for_each_active_monitor_output(&egl, GSR_CONNECTION_WAYLAND, get_first_output, &first_output); for_each_active_monitor_output(&egl, GSR_CONNECTION_WAYLAND, get_first_output, &first_output);
} else { } else {
for_each_active_monitor_output(card_path, GSR_CONNECTION_DRM, get_first_output, &first_output); for_each_active_monitor_output(&egl, GSR_CONNECTION_DRM, get_first_output, &first_output);
} }
if(first_output.output_name) { if(first_output.output_name) {
@@ -1460,22 +1460,24 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
} }
} else { } else {
gsr_monitor gmon; gsr_monitor gmon;
if(!get_monitor_by_name(card_path, GSR_CONNECTION_DRM, window_str, &gmon)) { if(!get_monitor_by_name(&egl, GSR_CONNECTION_DRM, window_str, &gmon)) {
fprintf(stderr, "gsr error: display \"%s\" not found, expected one of:\n", window_str); fprintf(stderr, "gsr error: display \"%s\" not found, expected one of:\n", window_str);
fprintf(stderr, " \"screen\"\n"); fprintf(stderr, " \"screen\"\n");
for_each_active_monitor_output(card_path, GSR_CONNECTION_DRM, monitor_output_callback_print, NULL); for_each_active_monitor_output(&egl, GSR_CONNECTION_DRM, monitor_output_callback_print, NULL);
_exit(1); _exit(1);
} }
} }
} else { } else {
if(strcmp(window_str, "screen") != 0 && strcmp(window_str, "screen-direct") != 0 && strcmp(window_str, "screen-direct-force") != 0) { if(strcmp(window_str, "screen") != 0 && strcmp(window_str, "screen-direct") != 0 && strcmp(window_str, "screen-direct-force") != 0) {
gsr_monitor gmon; gsr_monitor gmon;
if(!get_monitor_by_name(dpy, GSR_CONNECTION_X11, window_str, &gmon)) { if(!get_monitor_by_name(&egl, GSR_CONNECTION_X11, window_str, &gmon)) {
const int screens_width = XWidthOfScreen(DefaultScreenOfDisplay(egl.x11.dpy));
const int screens_height = XWidthOfScreen(DefaultScreenOfDisplay(egl.x11.dpy));
fprintf(stderr, "gsr error: display \"%s\" not found, expected one of:\n", window_str); fprintf(stderr, "gsr error: display \"%s\" not found, expected one of:\n", window_str);
fprintf(stderr, " \"screen\" (%dx%d+%d+%d)\n", XWidthOfScreen(DefaultScreenOfDisplay(dpy)), XHeightOfScreen(DefaultScreenOfDisplay(dpy)), 0, 0); fprintf(stderr, " \"screen\" (%dx%d+%d+%d)\n", screens_width, screens_height, 0, 0);
fprintf(stderr, " \"screen-direct\" (%dx%d+%d+%d)\n", XWidthOfScreen(DefaultScreenOfDisplay(dpy)), XHeightOfScreen(DefaultScreenOfDisplay(dpy)), 0, 0); fprintf(stderr, " \"screen-direct\" (%dx%d+%d+%d)\n", screens_width, screens_height, 0, 0);
fprintf(stderr, " \"screen-direct-force\" (%dx%d+%d+%d)\n", XWidthOfScreen(DefaultScreenOfDisplay(dpy)), XHeightOfScreen(DefaultScreenOfDisplay(dpy)), 0, 0); fprintf(stderr, " \"screen-direct-force\" (%dx%d+%d+%d)\n", screens_width, screens_height, 0, 0);
for_each_active_monitor_output(dpy, GSR_CONNECTION_X11, monitor_output_callback_print, NULL); for_each_active_monitor_output(&egl, GSR_CONNECTION_X11, monitor_output_callback_print, NULL);
_exit(1); _exit(1);
} }
} }
@@ -1487,7 +1489,6 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
kms_params.egl = &egl; kms_params.egl = &egl;
kms_params.display_to_capture = window_str; kms_params.display_to_capture = window_str;
kms_params.gpu_inf = gpu_inf; kms_params.gpu_inf = gpu_inf;
kms_params.card_path = card_path;
capture = gsr_capture_kms_cuda_create(&kms_params); capture = gsr_capture_kms_cuda_create(&kms_params);
if(!capture) if(!capture)
_exit(1); _exit(1);
@@ -1509,7 +1510,7 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
gsr_egl_unload(&egl); gsr_egl_unload(&egl);
gsr_capture_nvfbc_params nvfbc_params; gsr_capture_nvfbc_params nvfbc_params;
nvfbc_params.dpy = dpy; nvfbc_params.egl->x11.dpy = egl.x11.dpy;
nvfbc_params.display_to_capture = capture_target; nvfbc_params.display_to_capture = capture_target;
nvfbc_params.fps = fps; nvfbc_params.fps = fps;
nvfbc_params.pos = { 0, 0 }; nvfbc_params.pos = { 0, 0 };
@@ -1525,7 +1526,6 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
kms_params.egl = &egl; kms_params.egl = &egl;
kms_params.display_to_capture = window_str; kms_params.display_to_capture = window_str;
kms_params.gpu_inf = gpu_inf; kms_params.gpu_inf = gpu_inf;
kms_params.card_path = card_path;
kms_params.wayland = wayland; kms_params.wayland = wayland;
kms_params.hdr = video_codec_is_hdr(video_codec); kms_params.hdr = video_codec_is_hdr(video_codec);
kms_params.color_range = color_range; kms_params.color_range = color_range;
@@ -1549,28 +1549,13 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
if(!capture) { if(!capture) {
switch(gpu_inf.vendor) { switch(gpu_inf.vendor) {
case GSR_GPU_VENDOR_AMD: { case GSR_GPU_VENDOR_AMD:
gsr_capture_xcomposite_vaapi_params xcomposite_params;
xcomposite_params.egl = &egl;
xcomposite_params.dpy = dpy;
xcomposite_params.window = src_window_id;
xcomposite_params.follow_focused = follow_focused;
xcomposite_params.region_size = region_size;
xcomposite_params.card_path = card_path;
xcomposite_params.color_range = color_range;
capture = gsr_capture_xcomposite_vaapi_create(&xcomposite_params);
if(!capture)
_exit(1);
break;
}
case GSR_GPU_VENDOR_INTEL: { case GSR_GPU_VENDOR_INTEL: {
gsr_capture_xcomposite_vaapi_params xcomposite_params; gsr_capture_xcomposite_vaapi_params xcomposite_params;
xcomposite_params.egl = &egl; xcomposite_params.egl = &egl;
xcomposite_params.dpy = dpy;
xcomposite_params.window = src_window_id; xcomposite_params.window = src_window_id;
xcomposite_params.follow_focused = follow_focused; xcomposite_params.follow_focused = follow_focused;
xcomposite_params.region_size = region_size; xcomposite_params.region_size = region_size;
xcomposite_params.card_path = card_path;
xcomposite_params.color_range = color_range; xcomposite_params.color_range = color_range;
capture = gsr_capture_xcomposite_vaapi_create(&xcomposite_params); capture = gsr_capture_xcomposite_vaapi_create(&xcomposite_params);
if(!capture) if(!capture)
@@ -1580,7 +1565,6 @@ static gsr_capture* create_capture_impl(const char *window_str, const char *scre
case GSR_GPU_VENDOR_NVIDIA: { case GSR_GPU_VENDOR_NVIDIA: {
gsr_capture_xcomposite_cuda_params xcomposite_params; gsr_capture_xcomposite_cuda_params xcomposite_params;
xcomposite_params.egl = &egl; xcomposite_params.egl = &egl;
xcomposite_params.dpy = dpy;
xcomposite_params.window = src_window_id; xcomposite_params.window = src_window_id;
xcomposite_params.follow_focused = follow_focused; xcomposite_params.follow_focused = follow_focused;
xcomposite_params.region_size = region_size; xcomposite_params.region_size = region_size;
@@ -1895,11 +1879,10 @@ int main(int argc, char **argv) {
fprintf(stderr, "Info: overclocking is not possible on nvidia on wayland, ignoring option\n"); fprintf(stderr, "Info: overclocking is not possible on nvidia on wayland, ignoring option\n");
} }
char card_path[128]; egl.card_path[0] = '\0';
card_path[0] = '\0';
if(wayland || gpu_inf.vendor != GSR_GPU_VENDOR_NVIDIA) { if(wayland || gpu_inf.vendor != GSR_GPU_VENDOR_NVIDIA) {
// TODO: Allow specifying another card, and in other places // TODO: Allow specifying another card, and in other places
if(!gsr_get_valid_card_path(card_path)) { if(!gsr_get_valid_card_path(egl.card_path)) {
fprintf(stderr, "Error: no /dev/dri/cardX device found\n"); fprintf(stderr, "Error: no /dev/dri/cardX device found\n");
_exit(2); _exit(2);
} }
@@ -2041,7 +2024,7 @@ int main(int argc, char **argv) {
const bool video_codec_auto = strcmp(video_codec_to_use, "auto") == 0; const bool video_codec_auto = strcmp(video_codec_to_use, "auto") == 0;
if(video_codec_auto) { if(video_codec_auto) {
if(gpu_inf.vendor == GSR_GPU_VENDOR_INTEL) { if(gpu_inf.vendor == GSR_GPU_VENDOR_INTEL) {
const AVCodec *h264_codec = find_h264_encoder(gpu_inf.vendor, card_path); const AVCodec *h264_codec = find_h264_encoder(gpu_inf.vendor, egl.card_path);
if(!h264_codec) { if(!h264_codec) {
fprintf(stderr, "Info: using hevc encoder because a codec was not specified and your gpu does not support h264\n"); fprintf(stderr, "Info: using hevc encoder because a codec was not specified and your gpu does not support h264\n");
video_codec_to_use = "hevc"; video_codec_to_use = "hevc";
@@ -2052,7 +2035,7 @@ int main(int argc, char **argv) {
video_codec = VideoCodec::H264; video_codec = VideoCodec::H264;
} }
} else { } else {
const AVCodec *h265_codec = find_h265_encoder(gpu_inf.vendor, card_path); const AVCodec *h265_codec = find_h265_encoder(gpu_inf.vendor, egl.card_path);
if(h265_codec && fps > 60) { if(h265_codec && fps > 60) {
fprintf(stderr, "Warning: recording at higher fps than 60 with hevc might result in recording at a very low fps. If this happens, switch to h264\n"); fprintf(stderr, "Warning: recording at higher fps than 60 with hevc might result in recording at a very low fps. If this happens, switch to h264\n");
@@ -2084,15 +2067,15 @@ int main(int argc, char **argv) {
const AVCodec *video_codec_f = nullptr; const AVCodec *video_codec_f = nullptr;
switch(video_codec) { switch(video_codec) {
case VideoCodec::H264: case VideoCodec::H264:
video_codec_f = find_h264_encoder(gpu_inf.vendor, card_path); video_codec_f = find_h264_encoder(gpu_inf.vendor, egl.card_path);
break; break;
case VideoCodec::HEVC: case VideoCodec::HEVC:
case VideoCodec::HEVC_HDR: case VideoCodec::HEVC_HDR:
video_codec_f = find_h265_encoder(gpu_inf.vendor, card_path); video_codec_f = find_h265_encoder(gpu_inf.vendor, egl.card_path);
break; break;
case VideoCodec::AV1: case VideoCodec::AV1:
case VideoCodec::AV1_HDR: case VideoCodec::AV1_HDR:
video_codec_f = find_av1_encoder(gpu_inf.vendor, card_path); video_codec_f = find_av1_encoder(gpu_inf.vendor, egl.card_path);
break; break;
} }
@@ -2102,7 +2085,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Warning: selected video codec h264 is not supported, trying hevc instead\n"); fprintf(stderr, "Warning: selected video codec h264 is not supported, trying hevc instead\n");
video_codec_to_use = "hevc"; video_codec_to_use = "hevc";
video_codec = VideoCodec::HEVC; video_codec = VideoCodec::HEVC;
video_codec_f = find_h265_encoder(gpu_inf.vendor, card_path); video_codec_f = find_h265_encoder(gpu_inf.vendor, egl.card_path);
break; break;
} }
case VideoCodec::HEVC: case VideoCodec::HEVC:
@@ -2110,7 +2093,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Warning: selected video codec hevc is not supported, trying h264 instead\n"); fprintf(stderr, "Warning: selected video codec hevc is not supported, trying h264 instead\n");
video_codec_to_use = "h264"; video_codec_to_use = "h264";
video_codec = VideoCodec::H264; video_codec = VideoCodec::H264;
video_codec_f = find_h264_encoder(gpu_inf.vendor, card_path); video_codec_f = find_h264_encoder(gpu_inf.vendor, egl.card_path);
break; break;
} }
case VideoCodec::AV1: case VideoCodec::AV1:
@@ -2118,7 +2101,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "Warning: selected video codec av1 is not supported, trying h264 instead\n"); fprintf(stderr, "Warning: selected video codec av1 is not supported, trying h264 instead\n");
video_codec_to_use = "h264"; video_codec_to_use = "h264";
video_codec = VideoCodec::H264; video_codec = VideoCodec::H264;
video_codec_f = find_h264_encoder(gpu_inf.vendor, card_path); video_codec_f = find_h264_encoder(gpu_inf.vendor, egl.card_path);
break; break;
} }
} }
@@ -2153,7 +2136,7 @@ int main(int argc, char **argv) {
_exit(2); _exit(2);
} }
gsr_capture *capture = create_capture_impl(window_str, screen_region, wayland, gpu_inf, egl, card_path, dpy, fps, overclock, video_codec, color_range); gsr_capture *capture = create_capture_impl(window_str, screen_region, wayland, gpu_inf, egl, fps, overclock, video_codec, color_range);
const bool is_livestream = is_livestream_path(filename); const bool is_livestream = is_livestream_path(filename);
// (Some?) livestreaming services require at least one audio track to work. // (Some?) livestreaming services require at least one audio track to work.

View File

@@ -24,7 +24,7 @@ static const XRRModeInfo* get_mode_info(const XRRScreenResources *sr, RRMode id)
return NULL; return NULL;
} }
static void for_each_active_monitor_output_x11(Display *display, active_monitor_callback callback, void *userdata) { void for_each_active_monitor_output_x11(Display *display, active_monitor_callback callback, void *userdata) {
XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display)); XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display));
if(!screen_res) if(!screen_res)
return; return;
@@ -99,7 +99,7 @@ static bool connector_get_property_by_name(int drmfd, drmModeConnectorPtr props,
return false; return false;
} }
static void for_each_active_monitor_output_wayland(gsr_egl *egl, active_monitor_callback callback, void *userdata) { static void for_each_active_monitor_output_wayland(const gsr_egl *egl, active_monitor_callback callback, void *userdata) {
if(!gsr_egl_supports_wayland_capture(egl)) if(!gsr_egl_supports_wayland_capture(egl))
return; return;
@@ -119,8 +119,8 @@ static void for_each_active_monitor_output_wayland(gsr_egl *egl, active_monitor_
} }
} }
static void for_each_active_monitor_output_drm(const char *drm_card_path, active_monitor_callback callback, void *userdata) { static void for_each_active_monitor_output_drm(const gsr_egl *egl, active_monitor_callback callback, void *userdata) {
int fd = open(drm_card_path, O_RDONLY); int fd = open(egl->card_path, O_RDONLY);
if(fd == -1) if(fd == -1)
return; return;
@@ -176,16 +176,16 @@ static void for_each_active_monitor_output_drm(const char *drm_card_path, active
close(fd); close(fd);
} }
void for_each_active_monitor_output(void *connection, gsr_connection_type connection_type, 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) {
switch(connection_type) { switch(connection_type) {
case GSR_CONNECTION_X11: case GSR_CONNECTION_X11:
for_each_active_monitor_output_x11(connection, callback, userdata); for_each_active_monitor_output_x11(egl->x11.dpy, callback, userdata);
break; break;
case GSR_CONNECTION_WAYLAND: case GSR_CONNECTION_WAYLAND:
for_each_active_monitor_output_wayland(connection, callback, userdata); for_each_active_monitor_output_wayland(egl, callback, userdata);
break; break;
case GSR_CONNECTION_DRM: case GSR_CONNECTION_DRM:
for_each_active_monitor_output_drm(connection, callback, userdata); for_each_active_monitor_output_drm(egl, callback, userdata);
break; break;
} }
} }
@@ -199,13 +199,13 @@ static void get_monitor_by_name_callback(const gsr_monitor *monitor, void *userd
} }
} }
bool get_monitor_by_name(void *connection, gsr_connection_type connection_type, const char *name, gsr_monitor *monitor) { bool get_monitor_by_name(const gsr_egl *egl, gsr_connection_type connection_type, const char *name, gsr_monitor *monitor) {
get_monitor_by_name_userdata userdata; get_monitor_by_name_userdata userdata;
userdata.name = name; userdata.name = name;
userdata.name_len = strlen(name); userdata.name_len = strlen(name);
userdata.monitor = monitor; userdata.monitor = monitor;
userdata.found_monitor = false; userdata.found_monitor = false;
for_each_active_monitor_output(connection, connection_type, get_monitor_by_name_callback, &userdata); for_each_active_monitor_output(egl, connection_type, get_monitor_by_name_callback, &userdata);
return userdata.found_monitor; return userdata.found_monitor;
} }