Remove frame counter from scrcpy.c and add a new FPS counter, logging as INFO the measured frame rate every second (on new frame).master
parent
c6c17af840
commit
38e6682875
@ -0,0 +1,62 @@
|
||||
#include "fpscounter.h"
|
||||
|
||||
#include <SDL2/SDL_timer.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
void fps_counter_init(struct fps_counter *counter) {
|
||||
counter->started = SDL_FALSE;
|
||||
// no need to initialize the other fields, they are meaningful only when
|
||||
// started is true
|
||||
}
|
||||
|
||||
void fps_counter_start(struct fps_counter *counter) {
|
||||
counter->started = SDL_TRUE;
|
||||
counter->slice_start = SDL_GetTicks();
|
||||
counter->nr_rendered = 0;
|
||||
#ifdef SKIP_FRAMES
|
||||
counter->nr_skipped = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void fps_counter_stop(struct fps_counter *counter) {
|
||||
counter->started = SDL_FALSE;
|
||||
}
|
||||
|
||||
static void display_fps(struct fps_counter *counter) {
|
||||
#ifdef SKIP_FRAMES
|
||||
if (counter->nr_skipped) {
|
||||
LOGI("%d fps (+%d frames skipped)", counter->nr_rendered, counter->nr_skipped);
|
||||
} else {
|
||||
#endif
|
||||
LOGI("%d fps", counter->nr_rendered);
|
||||
#ifdef SKIP_FRAMES
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void check_expired(struct fps_counter *counter) {
|
||||
Uint32 now = SDL_GetTicks();
|
||||
if (now - counter->slice_start >= 1000) {
|
||||
display_fps(counter);
|
||||
// add a multiple of one second
|
||||
Uint32 elapsed_slices = (now - counter->slice_start) / 1000;
|
||||
counter->slice_start += 1000 * elapsed_slices;
|
||||
counter->nr_rendered = 0;
|
||||
#ifdef SKIP_FRAMES
|
||||
counter->nr_skipped = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void fps_counter_add_rendered_frame(struct fps_counter *counter) {
|
||||
check_expired(counter);
|
||||
++counter->nr_rendered;
|
||||
}
|
||||
|
||||
#ifdef SKIP_FRAMES
|
||||
void fps_counter_add_skipped_frame(struct fps_counter *counter) {
|
||||
check_expired(counter);
|
||||
++counter->nr_skipped;
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,26 @@
|
||||
#ifndef FPSCOUNTER_H
|
||||
#define FPSCOUNTER_H
|
||||
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
struct fps_counter {
|
||||
SDL_bool started;
|
||||
Uint32 slice_start; // initialized by SDL_GetTicks()
|
||||
int nr_rendered;
|
||||
#ifdef SKIP_FRAMES
|
||||
int nr_skipped;
|
||||
#endif
|
||||
};
|
||||
|
||||
void fps_counter_init(struct fps_counter *counter);
|
||||
void fps_counter_start(struct fps_counter *counter);
|
||||
void fps_counter_stop(struct fps_counter *counter);
|
||||
|
||||
void fps_counter_add_rendered_frame(struct fps_counter *counter);
|
||||
#ifdef SKIP_FRAMES
|
||||
void fps_counter_add_skipped_frame(struct fps_counter *counter);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue