mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-03 22:58:51 +00:00
init installer only when it's used
This commit is contained in:
parent
3722c4ddfc
commit
ec95645950
3 changed files with 30 additions and 19 deletions
|
@ -70,8 +70,7 @@ SDL_bool installer_init(struct installer *installer, const char* serial) {
|
||||||
installer->serial = SDL_strdup(serial);
|
installer->serial = SDL_strdup(serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(adopi)
|
installer->initialized = SDL_TRUE;
|
||||||
// installer->initialized = SDL_TRUE;
|
|
||||||
|
|
||||||
installer->stopped = SDL_FALSE;
|
installer->stopped = SDL_FALSE;
|
||||||
return SDL_TRUE;
|
return SDL_TRUE;
|
||||||
|
@ -82,6 +81,8 @@ void installer_destroy(struct installer *installer) {
|
||||||
SDL_DestroyMutex(installer->mutex);
|
SDL_DestroyMutex(installer->mutex);
|
||||||
apk_queue_destroy(&installer->queue);
|
apk_queue_destroy(&installer->queue);
|
||||||
SDL_free((void *) installer->serial);
|
SDL_free((void *) installer->serial);
|
||||||
|
installer->initialized = SDL_FALSE;
|
||||||
|
installer->stopped = SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_bool installer_push_apk(struct installer *installer, const char* apk) {
|
SDL_bool installer_push_apk(struct installer *installer, const char* apk) {
|
||||||
|
|
|
@ -25,9 +25,20 @@ struct installer {
|
||||||
SDL_mutex *mutex;
|
SDL_mutex *mutex;
|
||||||
SDL_cond *event_cond;
|
SDL_cond *event_cond;
|
||||||
SDL_bool stopped;
|
SDL_bool stopped;
|
||||||
|
SDL_bool initialized;
|
||||||
struct apk_queue queue;
|
struct apk_queue queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define INSTALLER_INITIALIZER { \
|
||||||
|
.serial = NULL, \
|
||||||
|
.thread = NULL, \
|
||||||
|
.mutex = NULL, \
|
||||||
|
.event_cond = NULL, \
|
||||||
|
.stopped = SDL_FALSE, \
|
||||||
|
.initialized = SDL_FALSE \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SDL_bool installer_init(struct installer *installer, const char* serial);
|
SDL_bool installer_init(struct installer *installer, const char* serial);
|
||||||
void installer_destroy(struct installer *installer);
|
void installer_destroy(struct installer *installer);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ static struct screen screen = SCREEN_INITIALIZER;
|
||||||
static struct frames frames;
|
static struct frames frames;
|
||||||
static struct decoder decoder;
|
static struct decoder decoder;
|
||||||
static struct controller controller;
|
static struct controller controller;
|
||||||
static struct installer installer;
|
static struct installer installer = INSTALLER_INITIALIZER;
|
||||||
|
|
||||||
static struct input_manager input_manager = {
|
static struct input_manager input_manager = {
|
||||||
.controller = &controller,
|
.controller = &controller,
|
||||||
|
@ -105,7 +105,15 @@ static void event_loop(void) {
|
||||||
input_manager_process_mouse_button(&input_manager, &event.button);
|
input_manager_process_mouse_button(&input_manager, &event.button);
|
||||||
break;
|
break;
|
||||||
case SDL_DROPFILE:
|
case SDL_DROPFILE:
|
||||||
// TODO(adopi) init here
|
|
||||||
|
if (!installer.initialized) {
|
||||||
|
SDL_bool init_ok = installer_init(&installer, server.serial);
|
||||||
|
if (init_ok && installer_start(&installer)) {
|
||||||
|
goto push;
|
||||||
|
}
|
||||||
|
installer_destroy(&installer);
|
||||||
|
}
|
||||||
|
push:
|
||||||
installer_push_apk(&installer, event.drop.file);
|
installer_push_apk(&installer, event.drop.file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -173,16 +181,6 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
|
||||||
goto finally_destroy_controller;
|
goto finally_destroy_controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(adopi) init the installer when we really want to use it
|
|
||||||
if (!installer_init(&installer, serial)) {
|
|
||||||
ret = SDL_FALSE;
|
|
||||||
goto finally_stop_and_join_installer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!installer_start(&installer)) {
|
|
||||||
ret = SDL_FALSE;
|
|
||||||
goto finally_destroy_installer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!screen_init_rendering(&screen, device_name, frame_size)) {
|
if (!screen_init_rendering(&screen, device_name, frame_size)) {
|
||||||
ret = SDL_FALSE;
|
ret = SDL_FALSE;
|
||||||
|
@ -198,13 +196,14 @@ finally_stop_and_join_controller:
|
||||||
controller_join(&controller);
|
controller_join(&controller);
|
||||||
finally_destroy_controller:
|
finally_destroy_controller:
|
||||||
controller_destroy(&controller);
|
controller_destroy(&controller);
|
||||||
finally_stop_and_join_installer:
|
|
||||||
installer_stop(&installer);
|
|
||||||
installer_join(&installer);
|
|
||||||
finally_destroy_installer:
|
|
||||||
installer_destroy(&installer);
|
|
||||||
finally_stop_decoder:
|
finally_stop_decoder:
|
||||||
decoder_stop(&decoder);
|
decoder_stop(&decoder);
|
||||||
|
// stop installer
|
||||||
|
if (installer.initialized) {
|
||||||
|
installer_stop(&installer);
|
||||||
|
installer_join(&installer);
|
||||||
|
installer_destroy(&installer);
|
||||||
|
}
|
||||||
// stop the server before decoder_join() to wake up the decoder
|
// stop the server before decoder_join() to wake up the decoder
|
||||||
server_stop(&server);
|
server_stop(&server);
|
||||||
decoder_join(&decoder);
|
decoder_join(&decoder);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue