diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-07-21 19:12:24 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-07-21 19:12:24 +0200 |
commit | 8b0723a4f20b115c8d3394bcdf24b60b4895a345 (patch) | |
tree | 31f872fcbcfb611091a7d6911ce3320df2f980dd /src/capture | |
parent | a1d31a5cf0b90d3afabc57d5a6f4ccdfb1eeb054 (diff) |
Fix window capture
Diffstat (limited to 'src/capture')
-rw-r--r-- | src/capture/kms_cuda.c | 4 | ||||
-rw-r--r-- | src/capture/kms_vaapi.c | 43 | ||||
-rw-r--r-- | src/capture/xcomposite_cuda.c | 60 | ||||
-rw-r--r-- | src/capture/xcomposite_vaapi.c | 44 |
4 files changed, 55 insertions, 96 deletions
diff --git a/src/capture/kms_cuda.c b/src/capture/kms_cuda.c index e8a4212..c1d272e 100644 --- a/src/capture/kms_cuda.c +++ b/src/capture/kms_cuda.c @@ -163,8 +163,8 @@ static int gsr_capture_kms_cuda_start(gsr_capture *cap, AVCodecContext *video_co cap_kms->capture_pos = monitor.pos; cap_kms->capture_size = monitor.size; - video_codec_context->width = max_int(2, even_number_ceil(cap_kms->capture_size.x)); - video_codec_context->height = max_int(2, even_number_ceil(cap_kms->capture_size.y)); + video_codec_context->width = max_int(2, cap_kms->capture_size.x & ~1); + video_codec_context->height = max_int(2, cap_kms->capture_size.y & ~1); /* Disable vsync */ cap_kms->params.egl->eglSwapInterval(cap_kms->params.egl->egl_display, 0); diff --git a/src/capture/kms_vaapi.c b/src/capture/kms_vaapi.c index 5348509..75bd378 100644 --- a/src/capture/kms_vaapi.c +++ b/src/capture/kms_vaapi.c @@ -32,7 +32,6 @@ typedef enum { typedef struct { gsr_capture_kms_vaapi_params params; - Display *dpy; XEvent xev; bool should_stop; @@ -160,7 +159,7 @@ static void monitor_callback(const gsr_monitor *monitor, void *userdata) { monitor_callback_userdata->rotation = monitor->crt_info->rotation; for(int i = 0; i < monitor->crt_info->noutput && monitor_callback_userdata->cap_kms->monitor_id.num_connector_ids < MAX_CONNECTOR_IDS; ++i) { int nprop = 0; - Atom *props = XRRListOutputProperties(monitor_callback_userdata->cap_kms->dpy, monitor->crt_info->outputs[i], &nprop); + Atom *props = XRRListOutputProperties(monitor_callback_userdata->cap_kms->params.dpy, monitor->crt_info->outputs[i], &nprop); if(!props) continue; @@ -174,7 +173,7 @@ static void monitor_callback(const gsr_monitor *monitor, void *userdata) { unsigned long bytes_after = 0; unsigned long nitems = 0; unsigned char *prop = NULL; - XRRGetOutputProperty(monitor_callback_userdata->cap_kms->dpy, monitor->crt_info->outputs[i], + XRRGetOutputProperty(monitor_callback_userdata->cap_kms->params.dpy, monitor->crt_info->outputs[i], monitor_callback_userdata->randr_connector_id_atom, 0, 128, false, false, AnyPropertyType, &type, &format, &nitems, &bytes_after, &prop); @@ -212,7 +211,7 @@ static int gsr_capture_kms_vaapi_start(gsr_capture *cap, AVCodecContext *video_c return -1; } - void *connection = cap_kms->params.wayland ? (void*)cap_kms->params.card_path : (void*)cap_kms->dpy; + void *connection = cap_kms->params.wayland ? (void*)cap_kms->params.card_path : (void*)cap_kms->params.dpy; const gsr_connection_type connection_type = cap_kms->params.wayland ? GSR_CONNECTION_DRM : GSR_CONNECTION_X11; MonitorCallbackUserdata monitor_callback_userdata = { @@ -229,13 +228,13 @@ static int gsr_capture_kms_vaapi_start(gsr_capture *cap, AVCodecContext *video_c cap_kms->screen_size.x = 0; cap_kms->screen_size.y = 0; } else { - const Atom randr_connector_id_atom = XInternAtom(cap_kms->dpy, "CONNECTOR_ID", False); + const Atom randr_connector_id_atom = XInternAtom(cap_kms->params.dpy, "CONNECTOR_ID", False); monitor_callback_userdata.randr_connector_id_atom = randr_connector_id_atom; monitor_callback_userdata.wayland = false; for_each_active_monitor_output(connection, connection_type, monitor_callback, &monitor_callback_userdata); - cap_kms->screen_size.x = WidthOfScreen(DefaultScreenOfDisplay(cap_kms->dpy)); - cap_kms->screen_size.y = HeightOfScreen(DefaultScreenOfDisplay(cap_kms->dpy)); + cap_kms->screen_size.x = WidthOfScreen(DefaultScreenOfDisplay(cap_kms->params.dpy)); + cap_kms->screen_size.y = HeightOfScreen(DefaultScreenOfDisplay(cap_kms->params.dpy)); } gsr_monitor monitor; @@ -276,13 +275,13 @@ static int gsr_capture_kms_vaapi_start(gsr_capture *cap, AVCodecContext *video_c return -1; } - if(cap_kms->dpy && !cap_kms->params.wayland) { - if(gsr_cursor_init(&cap_kms->cursor, cap_kms->params.egl, cap_kms->dpy) != 0) { + if(cap_kms->params.dpy && !cap_kms->params.wayland) { + if(gsr_cursor_init(&cap_kms->cursor, cap_kms->params.egl, cap_kms->params.dpy) != 0) { gsr_capture_kms_vaapi_stop(cap, video_codec_context); return -1; } - gsr_cursor_change_window_target(&cap_kms->cursor, DefaultRootWindow(cap_kms->dpy)); + gsr_cursor_change_window_target(&cap_kms->cursor, DefaultRootWindow(cap_kms->params.dpy)); gsr_cursor_update(&cap_kms->cursor, &cap_kms->xev); } @@ -301,9 +300,9 @@ static void gsr_capture_kms_vaapi_tick(gsr_capture *cap, AVCodecContext *video_c // TODO: cap_kms->params.egl->glClear(GL_COLOR_BUFFER_BIT); - if(cap_kms->dpy && !cap_kms->params.wayland) { - while(XPending(cap_kms->dpy)) { - XNextEvent(cap_kms->dpy, &cap_kms->xev); + if(cap_kms->params.dpy && !cap_kms->params.wayland) { + while(XPending(cap_kms->params.dpy)) { + XNextEvent(cap_kms->params.dpy, &cap_kms->xev); gsr_cursor_update(&cap_kms->cursor, &cap_kms->xev); } } @@ -610,7 +609,7 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) { } } - if(cap_kms->dpy && !cap_kms->params.wayland) { + if(cap_kms->params.dpy && !cap_kms->params.wayland) { gsr_cursor_tick(&cap_kms->cursor); } @@ -627,7 +626,7 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) { capture_pos, capture_size, texture_rotation); - if(cap_kms->dpy && !cap_kms->params.wayland) { + if(cap_kms->params.dpy && !cap_kms->params.wayland) { gsr_color_conversion_draw(&cap_kms->color_conversion, cap_kms->cursor.texture_id, cursor_capture_pos, (vec2i){cap_kms->cursor.size.x, cap_kms->cursor.size.y}, (vec2i){0, 0}, (vec2i){cap_kms->cursor.size.x, cap_kms->cursor.size.y}, @@ -686,11 +685,6 @@ static void gsr_capture_kms_vaapi_stop(gsr_capture *cap, AVCodecContext *video_c av_buffer_unref(&video_codec_context->hw_frames_ctx); gsr_kms_client_deinit(&cap_kms->kms_client); - if(cap_kms->dpy) { - // TODO: This causes a crash, why? maybe some other library dlclose xlib and that also happened to unload this??? - //XCloseDisplay(cap_kms->dpy); - cap_kms->dpy = NULL; - } } static void gsr_capture_kms_vaapi_destroy(gsr_capture *cap, AVCodecContext *video_codec_context) { @@ -722,14 +716,6 @@ gsr_capture* gsr_capture_kms_vaapi_create(const gsr_capture_kms_vaapi_params *pa return NULL; } - Display *display = XOpenDisplay(NULL); - if(!params->wayland && !display) { - fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_create failed: XOpenDisplay failed\n"); - free(cap); - free(cap_kms); - return NULL; - } - const char *display_to_capture = strdup(params->display_to_capture); if(!display_to_capture) { /* TODO XCloseDisplay */ @@ -738,7 +724,6 @@ gsr_capture* gsr_capture_kms_vaapi_create(const gsr_capture_kms_vaapi_params *pa return NULL; } - cap_kms->dpy = display; cap_kms->params = *params; cap_kms->params.display_to_capture = display_to_capture; diff --git a/src/capture/xcomposite_cuda.c b/src/capture/xcomposite_cuda.c index 9867f84..7ed64ab 100644 --- a/src/capture/xcomposite_cuda.c +++ b/src/capture/xcomposite_cuda.c @@ -9,7 +9,6 @@ typedef struct { gsr_capture_xcomposite_cuda_params params; - Display *dpy; XEvent xev; bool should_stop; @@ -158,12 +157,12 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v gsr_capture_xcomposite_cuda *cap_xcomp = cap->priv; if(cap_xcomp->params.follow_focused) { - cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->dpy, "_NET_ACTIVE_WINDOW", False); + cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.dpy, "_NET_ACTIVE_WINDOW", False); 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"); return -1; } - cap_xcomp->window = get_focused_window(cap_xcomp->dpy, cap_xcomp->net_active_window_atom); + cap_xcomp->window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); } else { cap_xcomp->window = cap_xcomp->params.window; } @@ -173,7 +172,7 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v XWindowAttributes attr; attr.width = 0; attr.height = 0; - if(!XGetWindowAttributes(cap_xcomp->dpy, cap_xcomp->window, &attr) && !cap_xcomp->params.follow_focused) { + if(!XGetWindowAttributes(cap_xcomp->params.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); return -1; } @@ -182,13 +181,13 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v cap_xcomp->window_size.y = max_int(attr.height, 0); if(cap_xcomp->params.follow_focused) - XSelectInput(cap_xcomp->dpy, DefaultRootWindow(cap_xcomp->dpy), PropertyChangeMask); + XSelectInput(cap_xcomp->params.dpy, DefaultRootWindow(cap_xcomp->params.dpy), PropertyChangeMask); - XSelectInput(cap_xcomp->dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); + XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); cap_xcomp->params.egl->eglSwapInterval(cap_xcomp->params.egl->egl_display, 0); - if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->dpy, cap_xcomp->window, cap_xcomp->params.egl) != 0 && !cap_xcomp->params.follow_focused) { - fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start: failed get window texture for window %ld\n", cap_xcomp->window); + 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) { + fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_start: failed to get window texture for window %ld\n", cap_xcomp->window); return -1; } @@ -200,15 +199,15 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v cap_xcomp->params.egl->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &cap_xcomp->texture_size.y); cap_xcomp->params.egl->glBindTexture(GL_TEXTURE_2D, 0); - cap_xcomp->texture_size.x = max_int(2, even_number_ceil(cap_xcomp->texture_size.x)); - cap_xcomp->texture_size.y = max_int(2, even_number_ceil(cap_xcomp->texture_size.y)); + cap_xcomp->texture_size.x = max_int(2, cap_xcomp->texture_size.x & ~1); + cap_xcomp->texture_size.y = max_int(2, cap_xcomp->texture_size.y & ~1); video_codec_context->width = cap_xcomp->texture_size.x; video_codec_context->height = cap_xcomp->texture_size.y; if(cap_xcomp->params.region_size.x > 0 && cap_xcomp->params.region_size.y > 0) { - video_codec_context->width = max_int(2, even_number_ceil(cap_xcomp->params.region_size.x)); - video_codec_context->height = max_int(2, even_number_ceil(cap_xcomp->params.region_size.y)); + video_codec_context->width = max_int(2, cap_xcomp->params.region_size.x & ~1); + video_codec_context->height = max_int(2, cap_xcomp->params.region_size.y & ~1); } cap_xcomp->target_texture_id = gl_create_texture(cap_xcomp, video_codec_context->width, video_codec_context->height); @@ -218,7 +217,7 @@ static int gsr_capture_xcomposite_cuda_start(gsr_capture *cap, AVCodecContext *v return -1; } - if(!gsr_cuda_load(&cap_xcomp->cuda, cap_xcomp->dpy, cap_xcomp->params.overclock)) { + if(!gsr_cuda_load(&cap_xcomp->cuda, cap_xcomp->params.dpy, cap_xcomp->params.overclock)) { gsr_capture_xcomposite_cuda_stop(cap, video_codec_context); return -1; } @@ -266,10 +265,10 @@ static void gsr_capture_xcomposite_cuda_stop(gsr_capture *cap, AVCodecContext *v gsr_cuda_unload(&cap_xcomp->cuda); - if(cap_xcomp->dpy) { + if(cap_xcomp->params.dpy) { // TODO: This causes a crash, why? maybe some other library dlclose xlib and that also happened to unload this??? //XCloseDisplay(cap_xcomp->dpy); - cap_xcomp->dpy = NULL; + cap_xcomp->params.dpy = NULL; } } @@ -279,8 +278,8 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT); bool init_new_window = false; - while(XPending(cap_xcomp->dpy)) { - XNextEvent(cap_xcomp->dpy, &cap_xcomp->xev); + while(XPending(cap_xcomp->params.dpy)) { + XNextEvent(cap_xcomp->params.dpy, &cap_xcomp->xev); switch(cap_xcomp->xev.type) { case DestroyNotify: { @@ -324,17 +323,17 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v } if(init_new_window) { - Window focused_window = get_focused_window(cap_xcomp->dpy, cap_xcomp->net_active_window_atom); + Window focused_window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); if(focused_window != cap_xcomp->window || !cap_xcomp->follow_focused_initialized) { cap_xcomp->follow_focused_initialized = true; - XSelectInput(cap_xcomp->dpy, cap_xcomp->window, 0); + XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, 0); cap_xcomp->window = focused_window; - XSelectInput(cap_xcomp->dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); + XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); XWindowAttributes attr; attr.width = 0; attr.height = 0; - if(!XGetWindowAttributes(cap_xcomp->dpy, cap_xcomp->window, &attr)) + if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->window, &attr)) 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); @@ -342,7 +341,7 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v cap_xcomp->window_resized = true; window_texture_deinit(&cap_xcomp->window_texture); - window_texture_init(&cap_xcomp->window_texture, cap_xcomp->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.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.y = 0; @@ -352,8 +351,8 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v cap_xcomp->params.egl->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &cap_xcomp->texture_size.y); cap_xcomp->params.egl->glBindTexture(GL_TEXTURE_2D, 0); - cap_xcomp->texture_size.x = min_int(video_codec_context->width, max_int(2, even_number_ceil(cap_xcomp->texture_size.x))); - cap_xcomp->texture_size.y = min_int(video_codec_context->height, max_int(2, even_number_ceil(cap_xcomp->texture_size.y))); + cap_xcomp->texture_size.x = min_int(video_codec_context->width, max_int(2, cap_xcomp->texture_size.x & ~1)); + cap_xcomp->texture_size.y = min_int(video_codec_context->height, max_int(2, cap_xcomp->texture_size.y & ~1)); } } @@ -375,8 +374,8 @@ static void gsr_capture_xcomposite_cuda_tick(gsr_capture *cap, AVCodecContext *v cap_xcomp->params.egl->glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &cap_xcomp->texture_size.y); cap_xcomp->params.egl->glBindTexture(GL_TEXTURE_2D, 0); - cap_xcomp->texture_size.x = min_int(video_codec_context->width, max_int(2, even_number_ceil(cap_xcomp->texture_size.x))); - cap_xcomp->texture_size.y = min_int(video_codec_context->height, max_int(2, even_number_ceil(cap_xcomp->texture_size.y))); + cap_xcomp->texture_size.x = min_int(video_codec_context->width, max_int(2, cap_xcomp->texture_size.x & ~1)); + cap_xcomp->texture_size.y = min_int(video_codec_context->height, max_int(2, cap_xcomp->texture_size.y & ~1)); if(!cap_xcomp->created_hw_frame) { cap_xcomp->created_hw_frame = true; @@ -500,15 +499,6 @@ gsr_capture* gsr_capture_xcomposite_cuda_create(const gsr_capture_xcomposite_cud return NULL; } - Display *display = XOpenDisplay(NULL); - if(!display) { - fprintf(stderr, "gsr error: gsr_capture_xcomposite_cuda_create failed: XOpenDisplay failed\n"); - free(cap); - free(cap_xcomp); - return NULL; - } - - cap_xcomp->dpy = display; cap_xcomp->params = *params; *cap = (gsr_capture) { diff --git a/src/capture/xcomposite_vaapi.c b/src/capture/xcomposite_vaapi.c index 4b1d9c4..4ca5d7b 100644 --- a/src/capture/xcomposite_vaapi.c +++ b/src/capture/xcomposite_vaapi.c @@ -13,7 +13,6 @@ typedef struct { gsr_capture_xcomposite_vaapi_params params; - Display *dpy; XEvent xev; bool should_stop; @@ -123,12 +122,12 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext * gsr_capture_xcomposite_vaapi *cap_xcomp = cap->priv; if(cap_xcomp->params.follow_focused) { - cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->dpy, "_NET_ACTIVE_WINDOW", False); + cap_xcomp->net_active_window_atom = XInternAtom(cap_xcomp->params.dpy, "_NET_ACTIVE_WINDOW", False); 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"); return -1; } - cap_xcomp->window = get_focused_window(cap_xcomp->dpy, cap_xcomp->net_active_window_atom); + cap_xcomp->window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); } else { cap_xcomp->window = cap_xcomp->params.window; } @@ -136,7 +135,7 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext * /* TODO: Do these in tick, and allow error if follow_focused */ XWindowAttributes attr; - if(!XGetWindowAttributes(cap_xcomp->dpy, cap_xcomp->params.window, &attr) && !cap_xcomp->params.follow_focused) { + if(!XGetWindowAttributes(cap_xcomp->params.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); return -1; } @@ -145,10 +144,10 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext * cap_xcomp->window_size.y = max_int(attr.height, 0); if(cap_xcomp->params.follow_focused) - XSelectInput(cap_xcomp->dpy, DefaultRootWindow(cap_xcomp->dpy), PropertyChangeMask); + XSelectInput(cap_xcomp->params.dpy, DefaultRootWindow(cap_xcomp->params.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 - XSelectInput(cap_xcomp->dpy, cap_xcomp->params.window, StructureNotifyMask | ExposureMask); + XSelectInput(cap_xcomp->params.dpy, cap_xcomp->params.window, StructureNotifyMask | ExposureMask); if(!cap_xcomp->params.egl->eglExportDMABUFImageQueryMESA) { fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start: could not find eglExportDMABUFImageQueryMESA\n"); @@ -162,8 +161,8 @@ static int gsr_capture_xcomposite_vaapi_start(gsr_capture *cap, AVCodecContext * /* Disable vsync */ cap_xcomp->params.egl->eglSwapInterval(cap_xcomp->params.egl->egl_display, 0); - if(window_texture_init(&cap_xcomp->window_texture, cap_xcomp->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 get window texture for window %ld\n", cap_xcomp->params.window); + 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) { + fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_start: failed to get window texture for window %ld\n", cap_xcomp->params.window); return -1; } @@ -202,8 +201,8 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext * //cap_xcomp->params.egl->glClear(GL_COLOR_BUFFER_BIT); bool init_new_window = false; - while(XPending(cap_xcomp->dpy)) { - XNextEvent(cap_xcomp->dpy, &cap_xcomp->xev); + while(XPending(cap_xcomp->params.dpy)) { + XNextEvent(cap_xcomp->params.dpy, &cap_xcomp->xev); switch(cap_xcomp->xev.type) { case DestroyNotify: { @@ -247,17 +246,17 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext * } if(init_new_window) { - Window focused_window = get_focused_window(cap_xcomp->dpy, cap_xcomp->net_active_window_atom); + Window focused_window = get_focused_window(cap_xcomp->params.dpy, cap_xcomp->net_active_window_atom); if(focused_window != cap_xcomp->window || !cap_xcomp->follow_focused_initialized) { cap_xcomp->follow_focused_initialized = true; - XSelectInput(cap_xcomp->dpy, cap_xcomp->window, 0); + XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, 0); cap_xcomp->window = focused_window; - XSelectInput(cap_xcomp->dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); + XSelectInput(cap_xcomp->params.dpy, cap_xcomp->window, StructureNotifyMask | ExposureMask); XWindowAttributes attr; attr.width = 0; attr.height = 0; - if(!XGetWindowAttributes(cap_xcomp->dpy, cap_xcomp->window, &attr)) + if(!XGetWindowAttributes(cap_xcomp->params.dpy, cap_xcomp->window, &attr)) 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); @@ -265,7 +264,7 @@ static void gsr_capture_xcomposite_vaapi_tick(gsr_capture *cap, AVCodecContext * cap_xcomp->window_resized = true; window_texture_deinit(&cap_xcomp->window_texture); - window_texture_init(&cap_xcomp->window_texture, cap_xcomp->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.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.y = 0; @@ -590,12 +589,6 @@ static void gsr_capture_xcomposite_vaapi_stop(gsr_capture *cap, AVCodecContext * av_buffer_unref(&video_codec_context->hw_device_ctx); if(video_codec_context->hw_frames_ctx) av_buffer_unref(&video_codec_context->hw_frames_ctx); - - if(cap_xcomp->dpy) { - // TODO: This causes a crash, why? maybe some other library dlclose xlib and that also happened to unload this??? - //XCloseDisplay(cap_xcomp->dpy); - cap_xcomp->dpy = NULL; - } } static void gsr_capture_xcomposite_vaapi_destroy(gsr_capture *cap, AVCodecContext *video_codec_context) { @@ -624,15 +617,6 @@ gsr_capture* gsr_capture_xcomposite_vaapi_create(const gsr_capture_xcomposite_va return NULL; } - Display *display = XOpenDisplay(NULL); - if(!display) { - fprintf(stderr, "gsr error: gsr_capture_xcomposite_vaapi_create failed: XOpenDisplay failed\n"); - free(cap); - free(cap_xcomp); - return NULL; - } - - cap_xcomp->dpy = display; cap_xcomp->params = *params; *cap = (gsr_capture) { |