Fix stuttering on Windows

This commit is contained in:
loki
2021-07-26 14:37:57 +02:00
parent d9f7952710
commit a87782b025

View File

@@ -619,11 +619,15 @@ void captureThread(
delay = std::min(delay, capture_ctxs.back().delay); delay = std::min(delay, capture_ctxs.back().delay);
} }
auto now = std::chrono::steady_clock::now();
auto &img = *round_robin++; auto &img = *round_robin++;
while(img.use_count() > 1) {} while(img.use_count() > 1) {}
auto now = std::chrono::steady_clock::now();
while(next_frame > now) {
now = std::chrono::steady_clock::now();
}
next_frame = now + delay;
auto status = disp->snapshot(img.get(), 1000ms, display_cursor); auto status = disp->snapshot(img.get(), 1000ms, display_cursor);
switch(status) { switch(status) {
case platf::capture_e::reinit: { case platf::capture_e::reinit: {
@@ -695,11 +699,6 @@ void captureThread(
capture_ctx->images->raise(img); capture_ctx->images->raise(img);
++capture_ctx; ++capture_ctx;
}) })
if(next_frame > now) {
std::this_thread::sleep_until(next_frame);
}
next_frame += delay;
} }
} }
@@ -1004,10 +1003,6 @@ void encode_run(
return; return;
} }
auto delay = std::chrono::floor<std::chrono::nanoseconds>(1s) / config.framerate;
auto next_frame = std::chrono::steady_clock::now();
auto frame = session->device->frame; auto frame = session->device->frame;
auto shutdown_event = mail->event<bool>(mail::shutdown); auto shutdown_event = mail->event<bool>(mail::shutdown);
@@ -1026,11 +1021,8 @@ void encode_run(
idr_events->pop(); idr_events->pop();
} }
std::this_thread::sleep_until(next_frame); if(!frame->key_frame || images->peek()) {
next_frame += delay; if(auto img = images->pop(100ms)) {
if(images->peek()) {
if(auto img = images->pop(delay)) {
session->device->convert(*img); session->device->convert(*img);
} }
else if(images->running()) { else if(images->running()) {
@@ -1492,7 +1484,7 @@ retry:
config_max_ref_frames.videoFormat = 1; config_max_ref_frames.videoFormat = 1;
config_autoselect.videoFormat = 1; config_autoselect.videoFormat = 1;
retry_hevc: retry_hevc:
auto max_ref_frames_hevc = validate_config(disp, encoder, config_max_ref_frames); auto max_ref_frames_hevc = validate_config(disp, encoder, config_max_ref_frames);
auto autoselect_hevc = validate_config(disp, encoder, config_autoselect); auto autoselect_hevc = validate_config(disp, encoder, config_autoselect);