From 8d4ff03b7feab7123dd5483f16ff282fddbb425d Mon Sep 17 00:00:00 2001 From: CapsLock Date: Fri, 1 Feb 2019 22:53:24 +0100 Subject: [PATCH 1/3] Added a new option : -n/--no-window This option allows scrcpy to be run headless : we can now use scrcpy only for screen recording as an example --- app/src/main.c | 13 ++++++++++++- app/src/scrcpy.c | 8 +++++++- app/src/scrcpy.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index 0603fef5d0..877c3ca317 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -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; @@ -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" @@ -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'}, @@ -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:fnhm:p:r:s:tv", long_options, NULL)) != -1) { switch (c) { case 'b': if (!parse_bit_rate(optarg, &args->bit_rate)) { @@ -232,6 +239,9 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { case 'f': args->fullscreen = SDL_TRUE; break; + case 'n': + args->no_window = SDL_TRUE; + break; case 'h': args->help = SDL_TRUE; break; @@ -324,6 +334,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; diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 0e9bcba070..e5e40600d6 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -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, @@ -80,7 +82,9 @@ 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); + } } if (!screen_update_frame(&screen, &frames)) { return SDL_FALSE; @@ -237,6 +241,8 @@ SDL_bool scrcpy(const struct scrcpy_options *options) { screen_switch_fullscreen(&screen); } + no_window = options->no_window; + ret = event_loop(); LOGD("quit..."); diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index 89945e6cbe..eacc7e09a4 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -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); From 3eaf39fda7601d3baba2344d2f87bd854a759340 Mon Sep 17 00:00:00 2001 From: CapsLock Date: Wed, 6 Feb 2019 00:45:59 +0100 Subject: [PATCH 2/3] Fixed some issues mentioned in comments --- app/src/main.c | 15 ++++++++++----- app/src/scrcpy.c | 8 +++++--- app/src/screen.h | 2 ++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index 877c3ca317..c6989b6a2f 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -215,7 +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'}, + {"no-window", no_argument, NULL, 'n'}, {"help", no_argument, NULL, 'h'}, {"max-size", required_argument, NULL, 'm'}, {"port", required_argument, NULL, 'p'}, @@ -226,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:fnhm: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)) { @@ -239,9 +239,6 @@ static SDL_bool parse_args(struct args *args, int argc, char *argv[]) { case 'f': args->fullscreen = SDL_TRUE; break; - case 'n': - args->no_window = SDL_TRUE; - break; case 'h': args->help = SDL_TRUE; break; @@ -250,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; @@ -273,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]); diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index e5e40600d6..a807aef27d 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -82,6 +82,7 @@ static SDL_bool event_loop(void) { if (!screen.has_frame) { screen.has_frame = SDL_TRUE; // this is the very first frame, show the window + if (!no_window) { screen_show_window(&screen); } @@ -145,6 +146,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)) { @@ -208,7 +211,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)) { @@ -237,11 +239,11 @@ 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); } - no_window = options->no_window; + ret = event_loop(); LOGD("quit..."); diff --git a/app/src/screen.h b/app/src/screen.h index 13103eaa6f..757717a101 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -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 { \ @@ -32,6 +33,7 @@ struct screen { }, \ .has_frame = SDL_FALSE, \ .fullscreen = SDL_FALSE, \ + .no_window = SDL_FALSE, \ } // init SDL and set appropriate hints From 0ad9dc16336a5edd118ce6e523840804d417b1d5 Mon Sep 17 00:00:00 2001 From: CapsLock Date: Wed, 6 Feb 2019 09:43:50 +0100 Subject: [PATCH 3/3] Added a log message telling when scrcpy is initialized --- app/src/scrcpy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index a807aef27d..15dcbc598d 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -66,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