mirror of
https://repo.dec05eba.com/gpu-screen-recorder
synced 2026-03-31 09:07:13 +09:00
Revert recent time framing and performance changes as it affects slower devices badly
This commit is contained in:
@@ -400,7 +400,7 @@ int gsr_kms_client_replace_connection(gsr_kms_client *self) {
|
||||
}
|
||||
|
||||
if(response.version != GSR_KMS_PROTOCOL_VERSION) {
|
||||
fprintf(stderr, "gsr error: gsr_kms_client_replace_connection: expected gsr-kms-server protocol version to be %u, but it's %u\n", GSR_KMS_PROTOCOL_VERSION, response.version);
|
||||
fprintf(stderr, "gsr error: gsr_kms_client_replace_connection: expected gsr-kms-server protocol version to be %u, but it's %u. please reinstall gpu screen recorder\n", GSR_KMS_PROTOCOL_VERSION, response.version);
|
||||
/*close_fds(response);*/
|
||||
return -1;
|
||||
}
|
||||
@@ -435,7 +435,7 @@ int gsr_kms_client_get_kms(gsr_kms_client *self, gsr_kms_response *response) {
|
||||
}
|
||||
|
||||
if(response->version != GSR_KMS_PROTOCOL_VERSION) {
|
||||
fprintf(stderr, "gsr error: gsr_kms_client_get_kms: expected gsr-kms-server protocol version to be %u, but it's %u\n", GSR_KMS_PROTOCOL_VERSION, response->version);
|
||||
fprintf(stderr, "gsr error: gsr_kms_client_get_kms: expected gsr-kms-server protocol version to be %u, but it's %u. please reinstall gpu screen recorder\n", GSR_KMS_PROTOCOL_VERSION, response->version);
|
||||
/*close_fds(response);*/
|
||||
strcpy(response->err_msg, "mismatching protocol version");
|
||||
return -1;
|
||||
|
||||
@@ -528,7 +528,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
if(request.version != GSR_KMS_PROTOCOL_VERSION) {
|
||||
fprintf(stderr, "kms server error: expected gpu screen recorder protocol version to be %u, but it's %u\n", GSR_KMS_PROTOCOL_VERSION, request.version);
|
||||
fprintf(stderr, "kms server error: expected gpu screen recorder protocol version to be %u, but it's %u. please reinstall gpu screen recorder\n", GSR_KMS_PROTOCOL_VERSION, request.version);
|
||||
/*
|
||||
if(request.new_connection_fd > 0)
|
||||
close(request.new_connection_fd);
|
||||
|
||||
@@ -570,15 +570,6 @@ static int gsr_capture_kms_capture(gsr_capture *cap, AVFrame *frame, gsr_color_c
|
||||
if(!capture_is_combined_plane)
|
||||
capture_pos = (vec2i){drm_fd->x, drm_fd->y};
|
||||
|
||||
// TODO: Hack!! cursor flickers without this when using vaapi copy on wayland.
|
||||
// There is probably some sync issue between opengl and vaapi. It flickers more when capture fps is lower.
|
||||
// Remove this when that has been figured out. Same for the below glFlush && glFinish
|
||||
const int hack_iterations = max_int(1, roundf(1000.0 / (double)self->params.fps));
|
||||
for(int i = 0; i < hack_iterations; ++i) {
|
||||
self->params.egl->glFlush();
|
||||
self->params.egl->glFinish();
|
||||
}
|
||||
|
||||
/* Fast opengl free path */
|
||||
if(self->monitor_rotation == GSR_MONITOR_ROT_0 && video_codec_context_is_vaapi(self->video_codec_context) && self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD) {
|
||||
int fds[4];
|
||||
@@ -599,20 +590,12 @@ static int gsr_capture_kms_capture(gsr_capture *cap, AVFrame *frame, gsr_color_c
|
||||
self->params.egl->eglDestroyImage(self->params.egl->egl_display, image);
|
||||
}
|
||||
|
||||
self->params.egl->glFlush();
|
||||
self->params.egl->glFinish();
|
||||
|
||||
gsr_color_conversion_draw(color_conversion, self->external_texture_fallback ? self->external_input_texture_id : self->input_texture_id,
|
||||
target_pos, self->capture_size,
|
||||
capture_pos, self->capture_size,
|
||||
texture_rotation, self->external_texture_fallback);
|
||||
}
|
||||
|
||||
for(int i = 0; i < hack_iterations; ++i) {
|
||||
self->params.egl->glFlush();
|
||||
self->params.egl->glFinish();
|
||||
}
|
||||
|
||||
if(self->params.record_cursor) {
|
||||
gsr_kms_response_item *cursor_drm_fd = find_cursor_drm_if_on_monitor(self, drm_fd->connector_id, capture_is_combined_plane);
|
||||
// The cursor is handled by x11 on x11 instead of using the cursor drm plane because on prime systems with a dedicated nvidia gpu
|
||||
@@ -625,10 +608,8 @@ static int gsr_capture_kms_capture(gsr_capture *cap, AVFrame *frame, gsr_color_c
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < hack_iterations; ++i) {
|
||||
self->params.egl->glFlush();
|
||||
self->params.egl->glFinish();
|
||||
}
|
||||
|
||||
gsr_capture_kms_cleanup_kms_fds(self);
|
||||
|
||||
|
||||
@@ -334,9 +334,6 @@ static int gsr_capture_portal_capture(gsr_capture *cap, AVFrame *frame, gsr_colo
|
||||
return 0;
|
||||
}
|
||||
|
||||
self->params.egl->glFlush();
|
||||
self->params.egl->glFinish();
|
||||
|
||||
const vec2i target_pos = { max_int(0, frame->width / 2 - self->capture_size.x / 2), max_int(0, frame->height / 2 - self->capture_size.y / 2) };
|
||||
|
||||
// TODO: Handle region crop
|
||||
|
||||
@@ -258,9 +258,6 @@ static int gsr_capture_xcomposite_capture(gsr_capture *cap, AVFrame *frame, gsr_
|
||||
|
||||
const vec2i target_pos = { max_int(0, frame->width / 2 - self->texture_size.x / 2), max_int(0, frame->height / 2 - self->texture_size.y / 2) };
|
||||
|
||||
self->params.egl->glFlush();
|
||||
self->params.egl->glFinish();
|
||||
|
||||
/* Fast opengl free path */
|
||||
if(video_codec_context_is_vaapi(self->video_codec_context) && self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD) {
|
||||
vaapi_copy_egl_image_to_video_surface(self->params.egl, self->window_texture.image, (vec2i){0, 0}, self->texture_size, target_pos, self->texture_size, self->video_codec_context, frame);
|
||||
|
||||
51
src/main.cpp
51
src/main.cpp
@@ -944,7 +944,7 @@ static void open_video_hardware(AVCodecContext *codec_context, VideoQuality vide
|
||||
// TODO: More quality options
|
||||
//av_dict_set_int(&options, "low_power", 1, 0);
|
||||
// Improves performance but increases vram
|
||||
av_dict_set_int(&options, "async_depth", 8, 0);
|
||||
//av_dict_set_int(&options, "async_depth", 8, 0);
|
||||
|
||||
if(codec_context->codec_id == AV_CODEC_ID_H264) {
|
||||
// Removed because it causes stutter in games for some people
|
||||
@@ -3158,6 +3158,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
double fps_start_time = clock_get_monotonic_seconds();
|
||||
double frame_timer_start = fps_start_time - target_fps; // We want to capture the first frame immediately
|
||||
int fps_counter = 0;
|
||||
int damage_fps_counter = 0;
|
||||
|
||||
@@ -3368,6 +3369,8 @@ int main(int argc, char **argv) {
|
||||
});
|
||||
}
|
||||
|
||||
// Set update_fps to 24 to test if duplicate/delayed frames cause video/audio desync or too fast/slow video.
|
||||
const double update_fps = fps + 190;
|
||||
bool should_stop_error = false;
|
||||
|
||||
int64_t video_pts_counter = 0;
|
||||
@@ -3389,8 +3392,6 @@ int main(int argc, char **argv) {
|
||||
if(is_monitor_capture)
|
||||
gsr_damage_set_target_monitor(&damage, window_str.c_str());
|
||||
|
||||
double last_capture_seconds = clock_get_monotonic_seconds();
|
||||
|
||||
while(running) {
|
||||
const double frame_start = clock_get_monotonic_seconds();
|
||||
|
||||
@@ -3425,6 +3426,7 @@ int main(int argc, char **argv) {
|
||||
damaged = true;
|
||||
|
||||
// TODO: Readd wayland sync warning when removing this
|
||||
if(framerate_mode != FramerateMode::CONTENT)
|
||||
damaged = true;
|
||||
|
||||
if(damaged)
|
||||
@@ -3432,6 +3434,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
++fps_counter;
|
||||
const double time_now = clock_get_monotonic_seconds();
|
||||
const double frame_timer_elapsed = time_now - frame_timer_start;
|
||||
const double elapsed = time_now - fps_start_time;
|
||||
if (elapsed >= 1.0) {
|
||||
if(verbose) {
|
||||
@@ -3442,31 +3445,30 @@ int main(int argc, char **argv) {
|
||||
damage_fps_counter = 0;
|
||||
}
|
||||
|
||||
const double this_video_frame_time = clock_get_monotonic_seconds() - paused_time_offset;
|
||||
const double time_since_last_frame_captured_seconds = this_video_frame_time - last_capture_seconds;
|
||||
const bool force_frame_capture = time_since_last_frame_captured_seconds >= damage_timeout_seconds;
|
||||
if((damaged || force_frame_capture) && !paused) {
|
||||
last_capture_seconds = this_video_frame_time;
|
||||
|
||||
double frame_time_overflow = frame_timer_elapsed - target_fps;
|
||||
if (frame_time_overflow >= 0.0 && damaged) {
|
||||
gsr_damage_clear(&damage);
|
||||
if(capture->clear_damage)
|
||||
capture->clear_damage(capture);
|
||||
frame_time_overflow = std::min(frame_time_overflow, target_fps);
|
||||
frame_timer_start = time_now - frame_time_overflow;
|
||||
|
||||
// TODO: Dont do this if no damage?
|
||||
const double this_video_frame_time = clock_get_monotonic_seconds() - paused_time_offset;
|
||||
const int64_t expected_frames = std::round((this_video_frame_time - record_start_time) / target_fps);
|
||||
const int num_frames = framerate_mode == FramerateMode::CONSTANT ? std::max((int64_t)0LL, expected_frames - video_pts_counter) : 1;
|
||||
|
||||
if(num_frames > 0 && !paused) {
|
||||
egl.glClear(0);
|
||||
gsr_capture_capture(capture, video_frame, &color_conversion);
|
||||
gsr_egl_swap_buffers(&egl);
|
||||
|
||||
gsr_video_encoder_copy_textures_to_frame(video_encoder, video_frame);
|
||||
|
||||
if(hdr && !hdr_metadata_set && replay_buffer_size_secs == -1 && add_hdr_metadata_to_video_stream(capture, video_stream))
|
||||
hdr_metadata_set = true;
|
||||
|
||||
const int64_t expected_frames = std::round((this_video_frame_time - record_start_time) / target_fps);
|
||||
const int num_missed_frames = std::max((int64_t)1LL, expected_frames - video_pts_counter);
|
||||
|
||||
// TODO: Check if duplicate frame can be saved just by writing it with a different pts instead of sending it again
|
||||
const int num_frames_to_encode = framerate_mode == FramerateMode::CONSTANT ? num_missed_frames : 1;
|
||||
for(int i = 0; i < num_frames_to_encode; ++i) {
|
||||
for(int i = 0; i < num_frames; ++i) {
|
||||
if(framerate_mode == FramerateMode::CONSTANT) {
|
||||
video_frame->pts = video_pts_counter + i;
|
||||
} else {
|
||||
@@ -3487,7 +3489,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
video_pts_counter += num_frames_to_encode;
|
||||
video_pts_counter += num_frames;
|
||||
}
|
||||
}
|
||||
|
||||
if(toggle_pause == 1) {
|
||||
@@ -3519,17 +3522,11 @@ int main(int argc, char **argv) {
|
||||
save_replay_async(video_codec_context, VIDEO_STREAM_INDEX, audio_tracks, frame_data_queue, frames_erased, filename, container_format, file_extension, write_output_mutex, date_folders, hdr, capture);
|
||||
}
|
||||
|
||||
const double time_at_frame_end = clock_get_monotonic_seconds() - paused_time_offset;
|
||||
const double time_elapsed_total = time_at_frame_end - record_start_time;
|
||||
const double time_at_next_frame = (video_pts_counter + 1) * target_fps;
|
||||
const double time_to_next_frame = time_at_next_frame - time_elapsed_total;
|
||||
|
||||
const double frame_end = clock_get_monotonic_seconds();
|
||||
const double frame_time = frame_end - frame_start;
|
||||
if(time_to_next_frame > 0.0)
|
||||
av_usleep(time_to_next_frame * 1000.0 * 1000.0);
|
||||
else if(frame_time < target_fps)
|
||||
usleep(2.8 * 1000.0); // 2.8 milliseconds
|
||||
double frame_end = clock_get_monotonic_seconds();
|
||||
double frame_sleep_fps = 1.0 / update_fps;
|
||||
double sleep_time = frame_sleep_fps - (frame_end - frame_start);
|
||||
if(sleep_time > 0.0)
|
||||
av_usleep(sleep_time * 1000.0 * 1000.0);
|
||||
}
|
||||
|
||||
running = 0;
|
||||
|
||||
Reference in New Issue
Block a user