[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce latency by 1 frame #646

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct args {
const char *serial;
const char *crop;
const char *record_filename;
const char *window_title;
enum recorder_format record_format;
bool fullscreen;
bool no_control;
Expand Down Expand Up @@ -103,6 +104,9 @@ static void usage(const char *arg0) {
" -v, --version\n"
" Print the version of scrcpy.\n"
"\n"
" --window-title text\n"
" Set a custom window title.\n"
"\n"
"Shortcuts:\n"
"\n"
" Ctrl+f\n"
Expand Down Expand Up @@ -295,6 +299,7 @@ guess_record_format(const char *filename) {
}

#define OPT_RENDER_EXPIRED_FRAMES 1000
#define OPT_WINDOW_TITLE 1001

static bool
parse_args(struct args *args, int argc, char *argv[]) {
Expand All @@ -316,6 +321,8 @@ parse_args(struct args *args, int argc, char *argv[]) {
{"show-touches", no_argument, NULL, 't'},
{"turn-screen-off", no_argument, NULL, 'S'},
{"version", no_argument, NULL, 'v'},
{"window-title", required_argument, NULL,
OPT_WINDOW_TITLE},
{NULL, 0, NULL, 0 },
};
int c;
Expand Down Expand Up @@ -378,6 +385,9 @@ parse_args(struct args *args, int argc, char *argv[]) {
case OPT_RENDER_EXPIRED_FRAMES:
args->render_expired_frames = true;
break;
case OPT_WINDOW_TITLE:
args->window_title = optarg;
break;
default:
// getopt prints the error message on stderr
return false;
Expand Down Expand Up @@ -434,6 +444,7 @@ main(int argc, char *argv[]) {
.serial = NULL,
.crop = NULL,
.record_filename = NULL,
.window_title = NULL,
.record_format = 0,
.help = false,
.version = false,
Expand Down Expand Up @@ -478,6 +489,7 @@ main(int argc, char *argv[]) {
.crop = args.crop,
.port = args.port,
.record_filename = args.record_filename,
.window_title = args.window_title,
.record_format = args.record_format,
.max_size = args.max_size,
.bit_rate = args.bit_rate,
Expand Down
5 changes: 4 additions & 1 deletion app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ scrcpy(const struct scrcpy_options *options) {
controller_started = true;
}

if (!screen_init_rendering(&screen, device_name, frame_size,
const char *window_title =
options->window_title ? options->window_title : device_name;

if (!screen_init_rendering(&screen, window_title, frame_size,
options->always_on_top)) {
goto end;
}
Expand Down
1 change: 1 addition & 0 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct scrcpy_options {
const char *serial;
const char *crop;
const char *record_filename;
const char *window_title;
enum recorder_format record_format;
uint16_t port;
uint16_t max_size;
Expand Down
4 changes: 2 additions & 2 deletions app/src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ create_texture(SDL_Renderer *renderer, struct size frame_size) {
}

bool
screen_init_rendering(struct screen *screen, const char *device_name,
screen_init_rendering(struct screen *screen, const char *window_title,
struct size frame_size, bool always_on_top) {
screen->frame_size = frame_size;

Expand All @@ -152,7 +152,7 @@ screen_init_rendering(struct screen *screen, const char *device_name,
#endif
}

screen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED,
screen->window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
window_size.width, window_size.height,
window_flags);
Expand Down
2 changes: 1 addition & 1 deletion app/src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ screen_init(struct screen *screen);

// initialize screen, create window, renderer and texture (window is hidden)
bool
screen_init_rendering(struct screen *screen, const char *device_name,
screen_init_rendering(struct screen *screen, const char *window_title,
struct size frame_size, bool always_on_top);

// show the window
Expand Down