mirror of
https://github.com/Genymobile/scrcpy
synced 2025-08-31 06:15:25 +00:00
Improve framerate counting
The FPS counter was called only on new frames, so it could not print values regularly, especially when there are very few FPS (when the device surface does not change). To the extreme, it was never able to display 0 fps. Add a separate thread to print framerate every second.
This commit is contained in:
@@ -172,16 +172,19 @@ set_screen_power_mode(struct controller *controller,
|
||||
}
|
||||
|
||||
static void
|
||||
switch_fps_counter_state(struct video_buffer *vb) {
|
||||
mutex_lock(vb->mutex);
|
||||
if (vb->fps_counter.started) {
|
||||
switch_fps_counter_state(struct fps_counter *fps_counter) {
|
||||
// the started state can only be written from the current thread, so there
|
||||
// is no ToCToU issue
|
||||
if (fps_counter_is_started(fps_counter)) {
|
||||
fps_counter_stop(fps_counter);
|
||||
LOGI("FPS counter stopped");
|
||||
fps_counter_stop(&vb->fps_counter);
|
||||
} else {
|
||||
LOGI("FPS counter started");
|
||||
fps_counter_start(&vb->fps_counter);
|
||||
if (fps_counter_start(fps_counter)) {
|
||||
LOGI("FPS counter started");
|
||||
} else {
|
||||
LOGE("FPS counter starting failed");
|
||||
}
|
||||
}
|
||||
mutex_unlock(vb->mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -339,7 +342,9 @@ input_manager_process_key(struct input_manager *input_manager,
|
||||
return;
|
||||
case SDLK_i:
|
||||
if (ctrl && !meta && !shift && !repeat && down) {
|
||||
switch_fps_counter_state(input_manager->video_buffer);
|
||||
struct fps_counter *fps_counter =
|
||||
input_manager->video_buffer->fps_counter;
|
||||
switch_fps_counter_state(fps_counter);
|
||||
}
|
||||
return;
|
||||
case SDLK_n:
|
||||
|
Reference in New Issue
Block a user