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

Added a new option : -n/--no-window #418

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 17 additions & 1 deletion app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct args {
const char *crop;
const char *record_filename;
SDL_bool fullscreen;
SDL_bool no_window;
SDL_bool help;
SDL_bool version;
SDL_bool show_touches;
Expand Down Expand Up @@ -50,6 +51,11 @@ static void usage(const char *arg0) {
" is preserved.\n"
" Default is %d%s.\n"
"\n"
" -n, --no-window\n"
" Do not show window. This is useful, as an example\n"
" combined with -r/--record option to record screen without displaying\n"
" video feedback\n"
"\n"
" -p, --port port\n"
" Set the TCP port the client listens on.\n"
" Default is %d.\n"
Expand Down Expand Up @@ -209,6 +215,7 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
{"bit-rate", required_argument, NULL, 'b'},
{"crop", required_argument, NULL, 'c'},
{"fullscreen", no_argument, NULL, 'f'},
{"no-window", no_argument, NULL, 'n'},
{"help", no_argument, NULL, 'h'},
{"max-size", required_argument, NULL, 'm'},
{"port", required_argument, NULL, 'p'},
Expand All @@ -219,7 +226,7 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
{NULL, 0, NULL, 0 },
};
int c;
while ((c = getopt_long(argc, argv, "b:c:fhm:p:r:s:tv", long_options, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "b:c:fhm:np:r:s:tv", long_options, NULL)) != -1) {
switch (c) {
case 'b':
if (!parse_bit_rate(optarg, &args->bit_rate)) {
Expand All @@ -240,6 +247,9 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
return SDL_FALSE;
}
break;
case 'n':
args->no_window = SDL_TRUE;
break;
case 'p':
if (!parse_port(optarg, &args->port)) {
return SDL_FALSE;
Expand All @@ -263,6 +273,11 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) {
}
}

if (args->no_window && args->record_filename == NULL) {
LOGE("Nothing to do: you asked to have no video feedback (by providing --no_window/-n argument) and did not specified a filename where video feed should be saved (--record/-r argument)");
return SDL_FALSE;
}

int index = optind;
if (index < argc) {
LOGE("Unexpected additional argument: %s", argv[index]);
Expand Down Expand Up @@ -324,6 +339,7 @@ int main(int argc, char *argv[]) {
.bit_rate = args.bit_rate,
.show_touches = args.show_touches,
.fullscreen = args.fullscreen,
.no_window = args.no_window
};
int res = scrcpy(&options) ? 0 : 1;

Expand Down
15 changes: 12 additions & 3 deletions app/src/scrcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static struct controller controller;
static struct file_handler file_handler;
static struct recorder recorder;

SDL_bool no_window;

static struct input_manager input_manager = {
.controller = &controller,
.frames = &frames,
Expand Down Expand Up @@ -64,6 +66,7 @@ static SDL_bool is_apk(const char *file) {
}

static SDL_bool event_loop(void) {
LOGI("scrcpy initialized");
#ifdef CONTINUOUS_RESIZING_WORKAROUND
SDL_AddEventWatch(event_watcher, NULL);
#endif
Expand All @@ -80,7 +83,10 @@ static SDL_bool event_loop(void) {
if (!screen.has_frame) {
screen.has_frame = SDL_TRUE;
// this is the very first frame, show the window
screen_show_window(&screen);

if (!no_window) {
screen_show_window(&screen);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can skip code far earlier, you may not even need to initialize SDL nor decode frames at all if you have no window.

}
if (!screen_update_frame(&screen, &frames)) {
return SDL_FALSE;
Expand Down Expand Up @@ -141,6 +147,8 @@ static void wait_show_touches(process_t process) {

SDL_bool scrcpy(const struct scrcpy_options *options) {
SDL_bool send_frame_meta = !!options->record_filename;
no_window = options->no_window;

if (!server_start(&server, options->serial, options->port,
options->max_size, options->bit_rate, options->crop,
send_frame_meta)) {
Expand Down Expand Up @@ -204,7 +212,6 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
}

decoder_init(&decoder, &frames, device_socket, rec);

// now we consumed the header values, the socket receives the video stream
// start the decoder
if (!decoder_start(&decoder)) {
Expand Down Expand Up @@ -233,10 +240,12 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
show_touches_waited = SDL_TRUE;
}

if (options->fullscreen) {
if (!no_window && options->fullscreen) {
screen_switch_fullscreen(&screen);
}



ret = event_loop();
LOGD("quit...");

Expand Down
1 change: 1 addition & 0 deletions app/src/scrcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct scrcpy_options {
Uint32 bit_rate;
SDL_bool show_touches;
SDL_bool fullscreen;
SDL_bool no_window;
};

SDL_bool scrcpy(const struct scrcpy_options *options);
Expand Down
2 changes: 2 additions & 0 deletions app/src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct screen {
struct size windowed_window_size;
SDL_bool has_frame;
SDL_bool fullscreen;
SDL_bool no_window;
};

#define SCREEN_INITIALIZER { \
Expand All @@ -32,6 +33,7 @@ struct screen {
}, \
.has_frame = SDL_FALSE, \
.fullscreen = SDL_FALSE, \
.no_window = SDL_FALSE, \
}

// init SDL and set appropriate hints
Expand Down