-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Control how many frames are captured per second #74
Conversation
2d7833c
to
7082afa
Compare
I can confirm that this PR helps a lot on 4k screen, nice job 👍 For reference, if I run with I can only feel that the mouse lag is almost gone at the value Just curious, @zsolt-donca what value did you end up using? |
@maximbaz I'm glad it works for you as well! I ended up using EDIT: I just tested with |
2624956
to
2c1d532
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me for the most part. I'll test this PR soon.
I just realized that in certain places I am not respecting the contribution guide on line length:
I will soon update my PR to fix this. |
BTW, your FreeBSD builds are failing, which we need to resolve before we can merge this. Mako fixes your issues with libepoll-shim on FreeBSD. You need to do this in the meson.build: https://github.com/emersion/mako/blob/dbd9c2bc98ef0cec7801a049f4bf8d61f7be36d0/meson.build#L32-L36 And you need to edit the .builds/freebsd.yml to include this: |
@danshick sorry about that, I wasn't paying attention to the automated builds linked in here. Thanks for info on how to fix it as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the logic looks good to me. Here are some comments to improve readability and style.
Also needs a rebase on top of master. |
Yup looks like a good idea to me |
Thanks for all of your work on this and your patience with us through these reviews and redesigns. |
d60a805
to
9acf4eb
Compare
I rebased the entire branch on the current master. Introduced the key
Note that the sample config had an error and was using Also note that I could not test the log statements and, in particular, the fps measurement after doing this rebase because of #91 . Will retest everything once that's fixed. |
@zsolt-donca You can comment out xdg-desktop-portal-wlr/src/core/config.c Line 62 in 07154bb
|
I rebased this branch once again on the latest master. I also changed a defensive check with an actual assertion as suggested by @emersion . I also found a minor issue with how the fps measurements were logged, as it was printing the elapsed time threshold instead of the actual elapsed time (f6c44ca). I think the timing varies also because we are capturing a frame only if there is damage. Sample log with the new code:
I also retested all functionality that I could think of, including the new ones with the config file (e.g. the CLI argument takes precedence over the config file, if both are missing then there is no limit). This should now addres all feedback that I received so far. What should be the next step? Should I squash all my commits into a single one so that it can be merged? |
Yup, exactly what I'd expect.
Thanks!
Yeah, normally at this point, I'd do an interactive rebase to try to reduce the overall number of commits. We tend towards a rebase and merge strategy, and for a reasonably big PR, it is okay if it comes over as more than one commit. I'd want @emersion to take a final look and I'll start running your PR as a daily driver for a couple of days to make sure I don't bump into any major bugs, but I think this should be approved and merged shortly. Edit: I've installed your branch as my system version of xdpw. So far so good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, thanks!
@zsolt-donca, can you rebase and split your work into logical commits?
@danshick, if testing goes well, feel free to merge!
@emersion thanks again for the review! Are you guys okay with me squashing the whole thing into a single commit for this pull request? I can't reasonably think of a better way, especially now that the master branch has support for config files. Just a small question: what should I set in |
OK. There are a few unrelated style changes, but it's no big deal.
We can always adjust it if/when we decide to ship it. |
@zsolt-donca Lemme know when you've done any last minute cleanup/squashing and I'll merge this. I haven't seen any crashing or issues over the past couple of days. |
The goal is to control the rate of capture while in screencast, as it can represent a performance issue and can cause input lag and the feeling of having a laggy mouse. This commit addresses the issue reported in emersion#66. The code measures the time elapsed to make a single screen capture, and calculates how much to wait for the next capture to achieve the targeted frame rate. To delay the capturing of the next frame, the code introduces timers into the event loop based on the event loop in https://github.com/emersion/mako Added a command-line argument and an entry in the config file as well for the max FPS. The default value is 0, meaning no rate control. Added code to measure the average FPS every 5 seconds and print it with DEBUG level.
I just squashed the whole thing into a single commit. This should be it from me. I'd appreciate if you could give feedback on the commit message, in particular if it is okay with regards to the contributing guide. |
Ah, thanks for taking the time to write a good commit message, greatly appreciated! Yes, it looks good to me. Since @danshick gave their greenlight, let's just merge this :) Thanks a lot! |
We're happy to have your contributions! |
Addresses #66 by introducing an optional command-line argument to limit the number of frames captured per second, as the mouse lag issue becomes less noticeable if the frame rate is smaller. The argument represents the targeted frames-per-second value (e.g. pass
-f 10
for 10 FPS).The implementation took inspiration from https://github.com/any1/wayvnc, but no code was copied other than the file
include/time-util.h
.The actual FPS value can be lower than the targeted one because xdg-desktop-portal-wlr uses the
zwlr_screencopy_frame_v1_copy_with_damage
function (emphasis onwith_damage
), which waits until the screen changes.The implementation differs from that of wayvnc that it does not try to "smooth" the capture rate over time, and it always uses the capture time of the last frame as its best estimate for how much time to sleep for current frame, and in order to reach the targeted FPS value. Let me know if there is interest in implementing this - for one, I am not sure if its worth it, and especially on possible implications with regards to xdp only capturing the frame on damage, which can make the measured "time to capture" value vary significantly, and could impact the smoothing negatively (which expects the values to be predictable).
Another difference when compared to wayvnc's implementation is that this code simply suspends the current thread with
usleep
, while wayvnc uses a more sophisticated timer-based solution based on the author's own library https://github.com/any1/aml.With regards to testing, it seems to (approximately) produce the given targeted FPS value for me, at least as long as I keep changing the screen contents (by moving the mouse, for example). For example, when running with
xdg-desktop-portal-wlr -l DEBUG -f 10
, it produced these logs for me:Another example with
-f 20
: