mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-04 07:09:06 +00:00
wip
This commit is contained in:
parent
91e5e68582
commit
2f816fdfc2
4 changed files with 49 additions and 16 deletions
|
@ -1,2 +1,4 @@
|
||||||
#define EVENT_NEW_FRAME SDL_USEREVENT
|
#define EVENT_NEW_FRAME SDL_USEREVENT
|
||||||
#define EVENT_STREAM_STOPPED (SDL_USEREVENT + 1)
|
#define EVENT_STREAM_STOPPED (SDL_USEREVENT + 1)
|
||||||
|
#define EVENT_SERVER_CONNECTION_FAILED (SDL_USEREVENT + 2)
|
||||||
|
#define EVENT_SERVER_CONNECTED (SDL_USEREVENT + 3)
|
||||||
|
|
|
@ -217,6 +217,29 @@ event_loop(struct scrcpy *s, const struct scrcpy_options *options) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
await_for_server(void) {
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_WaitEvent(&event)) {
|
||||||
|
switch (event.type) {
|
||||||
|
case SDL_QUIT:
|
||||||
|
LOGD("User requested to quit");
|
||||||
|
return false;
|
||||||
|
case EVENT_SERVER_CONNECTION_FAILED:
|
||||||
|
LOGE("Server connection failed");
|
||||||
|
return false;
|
||||||
|
case EVENT_SERVER_CONNECTED:
|
||||||
|
LOGD("Server connected");
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGE("SDL_WaitEvent() error: %s", SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static SDL_LogPriority
|
static SDL_LogPriority
|
||||||
sdl_priority_from_av_level(int level) {
|
sdl_priority_from_av_level(int level) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
@ -264,20 +287,27 @@ stream_on_eos(struct stream *stream, void *userdata) {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
server_on_connection_failed(struct server *server, void *userdata) {
|
server_on_connection_failed(struct server *server, void *userdata) {
|
||||||
struct scrcpy *scrcpy = userdata;
|
(void) server;
|
||||||
|
(void) userdata;
|
||||||
|
|
||||||
|
PUSH_EVENT(EVENT_SERVER_CONNECTION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
server_on_connected(struct server *server, void *userdata) {
|
server_on_connected(struct server *server, void *userdata) {
|
||||||
struct scrcpy *scrcpy = userdata;
|
(void) server;
|
||||||
|
(void) userdata;
|
||||||
|
|
||||||
|
PUSH_EVENT(EVENT_SERVER_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
server_on_disconnected(struct server *server, void *userdata) {
|
server_on_disconnected(struct server *server, void *userdata) {
|
||||||
struct scrcpy *scrcpy = userdata;
|
(void) server;
|
||||||
|
(void) userdata;
|
||||||
|
|
||||||
|
LOGD("Server disconnected");
|
||||||
|
// Do nothing, will be managed by the "stream stopped" event
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -333,7 +363,7 @@ scrcpy(struct scrcpy_options *options) {
|
||||||
.on_connected = server_on_connected,
|
.on_connected = server_on_connected,
|
||||||
.on_disconnected = server_on_disconnected,
|
.on_disconnected = server_on_disconnected,
|
||||||
};
|
};
|
||||||
if (!server_init(&s->server, ¶ms, &cbs, s)) {
|
if (!server_init(&s->server, ¶ms, &cbs, NULL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,12 +385,13 @@ scrcpy(struct scrcpy_options *options) {
|
||||||
|
|
||||||
sdl_configure(options->display, options->disable_screensaver);
|
sdl_configure(options->display, options->disable_screensaver);
|
||||||
|
|
||||||
struct server_info info;
|
// Await for server without blocking Ctrl+C handling
|
||||||
|
if (!await_for_server()) {
|
||||||
if (!server_connect_to(&s->server, &info)) {
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct server_info *info = &s->server.info;
|
||||||
|
|
||||||
if (options->display && options->control) {
|
if (options->display && options->control) {
|
||||||
if (!file_handler_init(&s->file_handler, options->serial,
|
if (!file_handler_init(&s->file_handler, options->serial,
|
||||||
options->push_target)) {
|
options->push_target)) {
|
||||||
|
@ -384,7 +415,7 @@ scrcpy(struct scrcpy_options *options) {
|
||||||
if (!recorder_init(&s->recorder,
|
if (!recorder_init(&s->recorder,
|
||||||
options->record_filename,
|
options->record_filename,
|
||||||
options->record_format,
|
options->record_format,
|
||||||
info.frame_size)) {
|
info->frame_size)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
rec = &s->recorder;
|
rec = &s->recorder;
|
||||||
|
@ -430,11 +461,11 @@ scrcpy(struct scrcpy_options *options) {
|
||||||
|
|
||||||
if (options->display) {
|
if (options->display) {
|
||||||
const char *window_title =
|
const char *window_title =
|
||||||
options->window_title ? options->window_title : info.device_name;
|
options->window_title ? options->window_title : info->device_name;
|
||||||
|
|
||||||
struct screen_params screen_params = {
|
struct screen_params screen_params = {
|
||||||
.window_title = window_title,
|
.window_title = window_title,
|
||||||
.frame_size = info.frame_size,
|
.frame_size = info->frame_size,
|
||||||
.always_on_top = options->always_on_top,
|
.always_on_top = options->always_on_top,
|
||||||
.window_x = options->window_x,
|
.window_x = options->window_x,
|
||||||
.window_y = options->window_y,
|
.window_y = options->window_y,
|
||||||
|
@ -458,7 +489,7 @@ scrcpy(struct scrcpy_options *options) {
|
||||||
#ifdef HAVE_V4L2
|
#ifdef HAVE_V4L2
|
||||||
if (options->v4l2_device) {
|
if (options->v4l2_device) {
|
||||||
if (!sc_v4l2_sink_init(&s->v4l2_sink, options->v4l2_device,
|
if (!sc_v4l2_sink_init(&s->v4l2_sink, options->v4l2_device,
|
||||||
info.frame_size, options->v4l2_buffer)) {
|
info->frame_size, options->v4l2_buffer)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -361,6 +361,7 @@ connect_to_server(struct server *server, uint32_t attempts, sc_tick delay) {
|
||||||
// it worked!
|
// it worked!
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
// TODO use mutex + condvar + bool stopped
|
||||||
if (attempts) {
|
if (attempts) {
|
||||||
sc_mutex_lock(&server->mutex);
|
sc_mutex_lock(&server->mutex);
|
||||||
// Ignore timedwait return (spurious wake ups are harmless)
|
// Ignore timedwait return (spurious wake ups are harmless)
|
||||||
|
@ -437,9 +438,7 @@ static int
|
||||||
run_server_connect(void *data) {
|
run_server_connect(void *data) {
|
||||||
struct server *server = data;
|
struct server *server = data;
|
||||||
|
|
||||||
struct server_info info;
|
if (!server_connect_to(server, &server->info)) {
|
||||||
|
|
||||||
if (!server_connect_to(server, &info)) {
|
|
||||||
server->cbs->on_connection_failed(server, server->cbs_userdata);
|
server->cbs->on_connection_failed(server, server->cbs_userdata);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ struct server {
|
||||||
bool stopped;
|
bool stopped;
|
||||||
|
|
||||||
bool connected; // written by connect_thread
|
bool connected; // written by connect_thread
|
||||||
|
struct server_info info; // initialized once connected
|
||||||
|
|
||||||
sc_socket server_socket; // only used if !tunnel_forward
|
sc_socket server_socket; // only used if !tunnel_forward
|
||||||
sc_socket video_socket;
|
sc_socket video_socket;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue