Recreate surface every frame :(

This commit is contained in:
dec05eba 2023-04-10 23:21:07 +02:00
parent 6d75615e1d
commit 32459991c0

View File

@ -40,6 +40,7 @@ typedef struct {
VASurfaceID input_surface; VASurfaceID input_surface;
VABufferID buffer_id; VABufferID buffer_id;
VARectangle input_region; VARectangle input_region;
bool context_created;
} gsr_capture_kms_vaapi; } gsr_capture_kms_vaapi;
static int max_int(int a, int b) { static int max_int(int a, int b) {
@ -173,14 +174,6 @@ static void gsr_capture_kms_vaapi_tick(gsr_capture *cap, AVCodecContext *video_c
cap_kms->stop_is_error = true; cap_kms->stop_is_error = true;
return; return;
} }
VAStatus va_status = vaCreateConfig(cap_kms->va_dpy, VAProfileNone, VAEntrypointVideoProc, NULL, 0, &cap_kms->config_id);
if(va_status != VA_STATUS_SUCCESS) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_tick: vaCreateConfig failed: %d\n", va_status);
cap_kms->should_stop = true;
cap_kms->stop_is_error = true;
return;
}
} }
} }
@ -202,10 +195,6 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) {
VASurfaceID target_surface_id = (uintptr_t)frame->data[3]; VASurfaceID target_surface_id = (uintptr_t)frame->data[3];
static bool dd = false;
if(!dd) {
dd = true;
if(cap_kms->dmabuf_fd > 0) { if(cap_kms->dmabuf_fd > 0) {
close(cap_kms->dmabuf_fd); close(cap_kms->dmabuf_fd);
cap_kms->dmabuf_fd = 0; cap_kms->dmabuf_fd = 0;
@ -225,11 +214,18 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) {
cap_kms->kms_size.x = kms_response.data.fd.width; cap_kms->kms_size.x = kms_response.data.fd.width;
cap_kms->kms_size.y = kms_response.data.fd.height; cap_kms->kms_size.y = kms_response.data.fd.height;
static bool cc = false; if(!cap_kms->context_created) {
if(!cc) { cap_kms->context_created = true;
cc = true;
VAStatus va_status = vaCreateContext(cap_kms->va_dpy, cap_kms->config_id, cap_kms->kms_size.x, cap_kms->kms_size.y, VA_PROGRESSIVE, &target_surface_id, 1, &cap_kms->context_id); VAStatus va_status = vaCreateConfig(cap_kms->va_dpy, VAProfileNone, VAEntrypointVideoProc, NULL, 0, &cap_kms->config_id);
if(va_status != VA_STATUS_SUCCESS) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_tick: vaCreateConfig failed: %d\n", va_status);
cap_kms->should_stop = true;
cap_kms->stop_is_error = true;
return -1;
}
va_status = vaCreateContext(cap_kms->va_dpy, cap_kms->config_id, cap_kms->kms_size.x, cap_kms->kms_size.y, VA_PROGRESSIVE, &target_surface_id, 1, &cap_kms->context_id);
if(va_status != VA_STATUS_SUCCESS) { if(va_status != VA_STATUS_SUCCESS) {
fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_capture: vaCreateContext failed: %d\n", va_status); fprintf(stderr, "gsr error: gsr_capture_kms_vaapi_capture: vaCreateContext failed: %d\n", va_status);
cap_kms->should_stop = true; cap_kms->should_stop = true;
@ -314,14 +310,13 @@ static int gsr_capture_kms_vaapi_capture(gsr_capture *cap, AVFrame *frame) {
cap_kms->stop_is_error = true; cap_kms->stop_is_error = true;
return -1; return -1;
} }
}
// Clear texture with black background because the source texture (window_texture_get_opengl_texture_id(&cap_kms->window_texture)) // Clear texture with black background because the source texture (window_texture_get_opengl_texture_id(&cap_kms->window_texture))
// might be smaller than cap_kms->target_texture_id // might be smaller than cap_kms->target_texture_id
// TODO: // TODO:
//cap_kms->egl.glClearTexImage(cap_kms->target_texture_id, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); //cap_kms->egl.glClearTexImage(cap_kms->target_texture_id, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
VAStatus va_status = vaBeginPicture(cap_kms->va_dpy, cap_kms->context_id, target_surface_id); va_status = vaBeginPicture(cap_kms->va_dpy, cap_kms->context_id, target_surface_id);
if(va_status != VA_STATUS_SUCCESS) { if(va_status != VA_STATUS_SUCCESS) {
static bool error_printed = false; static bool error_printed = false;
if(!error_printed) { if(!error_printed) {