From 39976ab7767c88644ba3fa59c7e0e626d79be6a9 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Tue, 7 Jul 2020 14:22:38 +0000 Subject: [PATCH] Allow the user to adjust the FPS limit --- include/screencopy.h | 2 ++ src/main.c | 9 ++++++++- src/screencopy.c | 3 +-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/screencopy.h b/include/screencopy.h index 5387ade..0f7aca9 100644 --- a/include/screencopy.h +++ b/include/screencopy.h @@ -68,6 +68,8 @@ struct screencopy { bool have_linux_dmabuf; uint32_t dmabuf_width, dmabuf_height; uint32_t fourcc; + + double rate_limit; }; void screencopy_init(struct screencopy* self); diff --git a/src/main.c b/src/main.c index c62d6c8..617ff54 100644 --- a/src/main.c +++ b/src/main.c @@ -571,6 +571,7 @@ int wayvnc_usage(FILE* stream, int rc) " -k,--keyboard= Select keyboard layout.\n" " -s,--seat= Select seat by name.\n" " -r,--render-cursor Enable overlay cursor rendering.\n" +" -f,--max-fps= Set the rate limit (default 30).\n" " -h,--help Get help (this text).\n" "\n"; @@ -628,8 +629,9 @@ int main(int argc, char* argv[]) const char* seat_name = NULL; bool overlay_cursor = false; + int max_rate = 30; - static const char* shortopts = "C:o:k:s:rh"; + static const char* shortopts = "C:o:k:s:rf:h"; int drm_fd = -1; static const struct option longopts[] = { @@ -638,6 +640,7 @@ int main(int argc, char* argv[]) { "keyboard", required_argument, NULL, 'k' }, { "seat", required_argument, NULL, 's' }, { "render-cursor", no_argument, NULL, 'r' }, + { "max-fps", required_argument, NULL, 'f' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; @@ -663,6 +666,9 @@ int main(int argc, char* argv[]) case 'r': overlay_cursor = true; break; + case 'f': + max_rate = atoi(optarg); + break; case 'h': return wayvnc_usage(stdout, 0); default: @@ -740,6 +746,7 @@ int main(int argc, char* argv[]) self.selected_output = out; self.selected_seat = seat; self.screencopy.wl_output = out->wl_output; + self.screencopy.rate_limit = max_rate; self.keyboard_backend.virtual_keyboard = zwp_virtual_keyboard_manager_v1_create_virtual_keyboard( diff --git a/src/screencopy.c b/src/screencopy.c index b47f650..4c8b8d6 100644 --- a/src/screencopy.c +++ b/src/screencopy.c @@ -32,7 +32,6 @@ #include "time-util.h" #include "usdt.h" -#define RATE_LIMIT 30.0 // Hz #define DELAY_SMOOTHER_TIME_CONSTANT 0.5 // s void screencopy_stop(struct screencopy* self) @@ -231,7 +230,7 @@ static int screencopy__start(struct screencopy* self, bool is_immediate_copy) uint64_t now = gettime_us(); double dt = (now - self->last_time) * 1.0e-6; - double time_left = (1.0 / RATE_LIMIT - dt - self->delay) * 1.0e3; + double time_left = (1.0 / self->rate_limit - dt - self->delay) * 1.0e3; self->status = SCREENCOPY_IN_PROGRESS;