Skip to content

Commit

Permalink
Fix frametiming for kmsgrab and x11grab
Browse files Browse the repository at this point in the history
This commit computes the time of the next screen capture based on the
current frame's theoretical time point instead of the actual capture
time. This should be slightly more precise and lead to better frame
timing.
  • Loading branch information
gschintgen committed Mar 30, 2024
1 parent ae71a6a commit b8f6c4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/platform/linux/kmsgrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,10 @@ namespace platf {
std::this_thread::sleep_for(1ns);
now = std::chrono::steady_clock::now();
}
next_frame = now + delay;
next_frame += delay;
if (next_frame < now) { // some major slowdown happened; we couldn't keep up
next_frame = now + delay;
}

std::shared_ptr<platf::img_t> img_out;
auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor);
Expand Down Expand Up @@ -1422,7 +1425,10 @@ namespace platf {
std::this_thread::sleep_for(1ns);
now = std::chrono::steady_clock::now();
}
next_frame = now + delay;
next_frame += delay;
if (next_frame < now) { // some major slowdown happened; we couldn't keep up
next_frame = now + delay;
}

std::shared_ptr<platf::img_t> img_out;
auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor);
Expand Down
5 changes: 4 additions & 1 deletion src/platform/linux/x11grab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,10 @@ namespace platf {
std::this_thread::sleep_for(1ns);
now = std::chrono::steady_clock::now();
}
next_frame = now + delay;
next_frame += delay;
if (next_frame < now) { // some major slowdown happened; we couldn't keep up
next_frame = now + delay;
}

std::shared_ptr<platf::img_t> img_out;
auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor);
Expand Down

0 comments on commit b8f6c4d

Please sign in to comment.