mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2025-02-18 09:42:07 +01:00
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 #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.
33 lines
833 B
C
33 lines
833 B
C
#include "timespec_util.h"
|
|
#include <time.h>
|
|
|
|
void timespec_add(struct timespec *t, int64_t delta_ns) {
|
|
int delta_ns_low = delta_ns % TIMESPEC_NSEC_PER_SEC;
|
|
int delta_s_high = delta_ns / TIMESPEC_NSEC_PER_SEC;
|
|
|
|
t->tv_sec += delta_s_high;
|
|
|
|
t->tv_nsec += (long)delta_ns_low;
|
|
if (t->tv_nsec >= TIMESPEC_NSEC_PER_SEC) {
|
|
t->tv_nsec -= TIMESPEC_NSEC_PER_SEC;
|
|
++t->tv_sec;
|
|
}
|
|
}
|
|
|
|
bool timespec_less(struct timespec *t1, struct timespec *t2) {
|
|
if (t1->tv_sec != t2->tv_sec) {
|
|
return t1->tv_sec < t2->tv_sec;
|
|
}
|
|
return t1->tv_nsec < t2->tv_nsec;
|
|
}
|
|
|
|
bool timespec_is_zero(struct timespec *t) {
|
|
return t->tv_sec == 0 && t->tv_nsec == 0;
|
|
}
|
|
|
|
int64_t timespec_diff_ns(struct timespec *t1, struct timespec *t2) {
|
|
int64_t s = t1->tv_sec - t2->tv_sec;
|
|
int64_t ns = t1->tv_nsec - t2->tv_nsec;
|
|
|
|
return s * TIMESPEC_NSEC_PER_SEC + ns;
|
|
}
|