From fa93c8a91b6ea6ce82e61b05c0c3b96da9c589c7 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 17 Feb 2022 20:10:09 +0100 Subject: [PATCH 1/2] Move FPS counter start/stop logs This will allow to print the same logs for every start/stop call. PR #3030 --- app/src/fps_counter.c | 2 ++ app/src/input_manager.c | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/fps_counter.c b/app/src/fps_counter.c index 41ffeaaf4e..8531282149 100644 --- a/app/src/fps_counter.c +++ b/app/src/fps_counter.c @@ -117,6 +117,7 @@ sc_fps_counter_start(struct sc_fps_counter *counter) { counter->thread_started = true; } + LOGI("FPS counter started"); return true; } @@ -124,6 +125,7 @@ void sc_fps_counter_stop(struct sc_fps_counter *counter) { set_started(counter, false); sc_cond_signal(&counter->state_cond); + LOGI("FPS counter stopped"); } bool diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 89ac450df8..bba3665c7c 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -247,13 +247,9 @@ switch_fps_counter_state(struct sc_fps_counter *fps_counter) { // is no ToCToU issue if (sc_fps_counter_is_started(fps_counter)) { sc_fps_counter_stop(fps_counter); - LOGI("FPS counter stopped"); } else { - if (sc_fps_counter_start(fps_counter)) { - LOGI("FPS counter started"); - } else { - LOGE("FPS counter starting failed"); - } + sc_fps_counter_start(fps_counter); + // Any error is already logged } } From 4b018be78907eec4d85e24e64402e1fbb5860aea Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 17 Feb 2022 20:08:41 +0100 Subject: [PATCH 2/2] Add --print-fps to enable FPS counter on start The FPS counter could be enabled/disabled via MOD+i. Add a command line option to enable it on start. This is consistent with other features like --turn-screen-off or --fullscreen. Fixes #468 PR #3030 --- README.md | 9 +++++++++ app/scrcpy.1 | 4 ++++ app/src/cli.c | 10 ++++++++++ app/src/options.c | 1 + app/src/options.h | 1 + app/src/scrcpy.c | 1 + app/src/screen.c | 5 +++++ app/src/screen.h | 2 ++ 8 files changed, 33 insertions(+) diff --git a/README.md b/README.md index dbbc4d71df..1139092fa0 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,15 @@ scrcpy --max-fps 15 This is officially supported since Android 10, but may work on earlier versions. +The actual capture framerate may be printed to the console: + +``` +scrcpy --print-fps +``` + +It may also be enabled or disabled at any time with MOD+i. + + #### Crop The device screen may be cropped to mirror only part of the screen. diff --git a/app/scrcpy.1 b/app/scrcpy.1 index 13a9a97afa..62cfe0042f 100644 --- a/app/scrcpy.1 +++ b/app/scrcpy.1 @@ -211,6 +211,10 @@ Inject alpha characters and space as text events instead of key events. This avoids issues when combining multiple keys to enter special characters, but breaks the expected behavior of alpha keys in games (typically WASD). +.TP +.B "\-\-print\-fps +Start FPS counter, to print framerate logs to the console. It can be started or stopped at any time with MOD+i. + .TP .BI "\-\-push\-target " path Set the target directory for pushing files to the device by drag & drop. It is passed as\-is to "adb push". diff --git a/app/src/cli.c b/app/src/cli.c index eb28b1d74c..ab2d7d1091 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -55,6 +55,7 @@ #define OPT_NO_DOWNSIZE_ON_ERROR 1035 #define OPT_OTG 1036 #define OPT_NO_CLEANUP 1037 +#define OPT_PRINT_FPS 1038 struct sc_option { char shortopt; @@ -336,6 +337,12 @@ static const struct sc_option options[] = { "special character, but breaks the expected behavior of alpha " "keys in games (typically WASD).", }, + { + .longopt_id = OPT_PRINT_FPS, + .longopt = "print-fps", + .text = "Start FPS counter, to print framerate logs to the console. " + "It can be started or stopped at any time with MOD+i.", + }, { .longopt_id = OPT_PUSH_TARGET, .longopt = "push-target", @@ -1547,6 +1554,9 @@ parse_args_with_getopt(struct scrcpy_cli_args *args, int argc, char *argv[], case OPT_NO_CLEANUP: opts->cleanup = false; break; + case OPT_PRINT_FPS: + opts->start_fps_counter = true; + break; case OPT_OTG: #ifdef HAVE_USB opts->otg = true; diff --git a/app/src/options.c b/app/src/options.c index 5a717df577..6651020f3e 100644 --- a/app/src/options.c +++ b/app/src/options.c @@ -63,4 +63,5 @@ const struct scrcpy_options scrcpy_options_default = { .select_tcpip = false, .select_usb = false, .cleanup = true, + .start_fps_counter = false, }; diff --git a/app/src/options.h b/app/src/options.h index f96edb22a2..f63e5c429c 100644 --- a/app/src/options.h +++ b/app/src/options.h @@ -138,6 +138,7 @@ struct scrcpy_options { bool select_usb; bool select_tcpip; bool cleanup; + bool start_fps_counter; }; extern const struct scrcpy_options scrcpy_options_default; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 8c4920d626..3ed1d24910 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -588,6 +588,7 @@ scrcpy(struct scrcpy_options *options) { .rotation = options->rotation, .mipmaps = options->mipmaps, .fullscreen = options->fullscreen, + .start_fps_counter = options->start_fps_counter, .buffering_time = options->display_buffer, }; diff --git a/app/src/screen.c b/app/src/screen.c index 2b1c52999e..c233cf6e41 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -386,6 +386,7 @@ sc_screen_init(struct sc_screen *screen, screen->req.width = params->window_width; screen->req.height = params->window_height; screen->req.fullscreen = params->fullscreen; + screen->req.start_fps_counter = params->start_fps_counter; static const struct sc_video_buffer_callbacks cbs = { .on_new_frame = sc_video_buffer_on_new_frame, @@ -562,6 +563,10 @@ sc_screen_show_initial_window(struct sc_screen *screen) { sc_screen_switch_fullscreen(screen); } + if (screen->req.start_fps_counter) { + sc_fps_counter_start(&screen->fps_counter); + } + SDL_ShowWindow(screen->window); } diff --git a/app/src/screen.h b/app/src/screen.h index 12b8816c66..222e418f80 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -35,6 +35,7 @@ struct sc_screen { uint16_t width; uint16_t height; bool fullscreen; + bool start_fps_counter; } req; SDL_Window *window; @@ -93,6 +94,7 @@ struct sc_screen_params { bool mipmaps; bool fullscreen; + bool start_fps_counter; sc_tick buffering_time; };