Implement the --no-window flag

Disable decoder, screen (display), file_handler and controller when
--no-window is requested.

<https://github.com/Genymobile/scrcpy/pull/418>
This commit is contained in:
Romain Vimont 2019-03-02 18:06:29 +01:00
parent 421a1141e2
commit 89812e4eee

View file

@ -217,19 +217,25 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
goto finally_destroy_server; goto finally_destroy_server;
} }
if (!video_buffer_init(&video_buffer)) { SDL_bool display = !options->no_window;
server_stop(&server);
ret = SDL_FALSE;
goto finally_destroy_server;
}
if (!file_handler_init(&file_handler, server.serial)) { struct decoder *dec = NULL;
ret = SDL_FALSE; if (display) {
server_stop(&server); if (!video_buffer_init(&video_buffer)) {
goto finally_destroy_video_buffer; server_stop(&server);
} ret = SDL_FALSE;
goto finally_destroy_server;
}
decoder_init(&decoder, &video_buffer); if (!file_handler_init(&file_handler, server.serial)) {
ret = SDL_FALSE;
server_stop(&server);
goto finally_destroy_video_buffer;
}
decoder_init(&decoder, &video_buffer);
dec = &decoder;
}
struct recorder *rec = NULL; struct recorder *rec = NULL;
if (record) { if (record) {
@ -246,7 +252,7 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
av_log_set_callback(av_log_callback); av_log_set_callback(av_log_callback);
stream_init(&stream, device_socket, &decoder, rec); stream_init(&stream, device_socket, dec, rec);
// now we consumed the header values, the socket receives the video stream // now we consumed the header values, the socket receives the video stream
// start the stream // start the stream
@ -256,19 +262,25 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
goto finally_destroy_recorder; goto finally_destroy_recorder;
} }
if (!controller_init(&controller, device_socket)) { if (display) {
ret = SDL_FALSE; if (!controller_init(&controller, device_socket)) {
goto finally_stop_stream; ret = SDL_FALSE;
} goto finally_stop_stream;
}
if (!controller_start(&controller)) { if (!controller_start(&controller)) {
ret = SDL_FALSE; ret = SDL_FALSE;
goto finally_destroy_controller; goto finally_destroy_controller;
} }
if (!screen_init_rendering(&screen, device_name, frame_size, options->always_on_top)) { if (!screen_init_rendering(&screen, device_name, frame_size, options->always_on_top)) {
ret = SDL_FALSE; ret = SDL_FALSE;
goto finally_stop_and_join_controller; goto finally_stop_and_join_controller;
}
if (options->fullscreen) {
screen_switch_fullscreen(&screen);
}
} }
if (options->show_touches) { if (options->show_touches) {
@ -276,20 +288,20 @@ SDL_bool scrcpy(const struct scrcpy_options *options) {
show_touches_waited = SDL_TRUE; show_touches_waited = SDL_TRUE;
} }
if (options->fullscreen) {
screen_switch_fullscreen(&screen);
}
ret = event_loop(); ret = event_loop();
LOGD("quit..."); LOGD("quit...");
screen_destroy(&screen); screen_destroy(&screen);
finally_stop_and_join_controller: finally_stop_and_join_controller:
controller_stop(&controller); if (display) {
controller_join(&controller); controller_stop(&controller);
controller_join(&controller);
}
finally_destroy_controller: finally_destroy_controller:
controller_destroy(&controller); if (display) {
controller_destroy(&controller);
}
finally_stop_stream: finally_stop_stream:
stream_stop(&stream); stream_stop(&stream);
// stop the server before stream_join() to wake up the stream // stop the server before stream_join() to wake up the stream
@ -300,11 +312,15 @@ finally_destroy_recorder:
recorder_destroy(&recorder); recorder_destroy(&recorder);
} }
finally_destroy_file_handler: finally_destroy_file_handler:
file_handler_stop(&file_handler); if (display) {
file_handler_join(&file_handler); file_handler_stop(&file_handler);
file_handler_destroy(&file_handler); file_handler_join(&file_handler);
file_handler_destroy(&file_handler);
}
finally_destroy_video_buffer: finally_destroy_video_buffer:
video_buffer_destroy(&video_buffer); if (display) {
video_buffer_destroy(&video_buffer);
}
finally_destroy_server: finally_destroy_server:
if (options->show_touches) { if (options->show_touches) {
if (!show_touches_waited) { if (!show_touches_waited) {