Skip to content

Display and control your Android device

Use SDL_bool return type instead of int

Romain Vimont37d88b8a6a42
diff --git a/app/src/decoder.c b/app/src/decoder.c
index d74b4d1d..926de94f 100644
--- a/app/src/decoder.c
+++ b/app/src/decoder.c
@@ -148,16 +148,16 @@ run_finally_free_codec_ctx:
return ret;
}
-int decoder_start(struct decoder *decoder) {
+SDL_bool decoder_start(struct decoder *decoder) {
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Starting decoder thread");
decoder->thread = SDL_CreateThread(run_decoder, "video_decoder", decoder);
if (!decoder->thread) {
SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "Could not start decoder thread");
- return -1;
+ return SDL_FALSE;
}
- return 0;
+ return SDL_TRUE;
}
void decoder_join(struct decoder *decoder) {
diff --git a/app/src/decoder.h b/app/src/decoder.h
index 78f2dbd7..4d4f9191 100644
--- a/app/src/decoder.h
+++ b/app/src/decoder.h
@@ -16,7 +16,7 @@ struct decoder {
SDL_bool skip_frames;
};
-int decoder_start(struct decoder *decoder);
+SDL_bool decoder_start(struct decoder *decoder);
void decoder_join(struct decoder *decoder);
#endif
diff --git a/app/src/frames.c b/app/src/frames.c
index f64e8e03..7d240ca3 100644
--- a/app/src/frames.c
+++ b/app/src/frames.c
@@ -4,7 +4,7 @@
#include <libavutil/avutil.h>
#include <libavformat/avformat.h>
-int frames_init(struct frames *frames) {
+SDL_bool frames_init(struct frames *frames) {
if (!(frames->decoding_frame = av_frame_alloc())) {
goto error_0;
}
@@ -23,7 +23,7 @@ int frames_init(struct frames *frames) {
frames->rendering_frame_consumed = SDL_TRUE;
- return 0;
+ return SDL_TRUE;
error_3:
SDL_DestroyMutex(frames->mutex);
@@ -32,7 +32,7 @@ error_2:
error_1:
av_frame_free(&frames->decoding_frame);
error_0:
- return -1;
+ return SDL_FALSE;
}
void frames_destroy(struct frames *frames) {
diff --git a/app/src/frames.h b/app/src/frames.h
index cf2217d9..1d73af53 100644
--- a/app/src/frames.h
+++ b/app/src/frames.h
@@ -16,7 +16,7 @@ struct frames {
SDL_bool rendering_frame_consumed;
};
-int frames_init(struct frames *frames);
+SDL_bool frames_init(struct frames *frames);
void frames_destroy(struct frames *frames);
void frames_swap(struct frames *frames);
diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c
index df7b80fd..8c7b5c79 100644
--- a/app/src/scrcpy.c
+++ b/app/src/scrcpy.c
@@ -56,8 +56,8 @@ int main(int argc, char *argv[]) {
.port = DEFAULT_LOCAL_PORT,
};
if (parse_args(&args, argc, argv)) {
- return -1;
+ return 1;
}
- return show_screen(args.serial, args.port);
+ return show_screen(args.serial, args.port) ? 0 : 1;
}
diff --git a/app/src/screen.c b/app/src/screen.c
index 4b7200d1..96bb0a2a 100644
--- a/app/src/screen.c
+++ b/app/src/screen.c
@@ -213,8 +213,8 @@ static int wait_for_success(process_t proc, const char *name) {
return 0;
}
-int show_screen(const char *serial, Uint16 local_port) {
- int ret = 0;
+SDL_bool show_screen(const char *serial, Uint16 local_port) {
+ SDL_bool ret = 0;
const char *server_jar_path = getenv("SCRCPY_SERVER_JAR");
if (!server_jar_path) {
@@ -222,12 +222,12 @@ int show_screen(const char *serial, Uint16 local_port) {
}
process_t push_proc = adb_push(serial, server_jar_path, "/data/local/tmp/");
if (wait_for_success(push_proc, "adb push")) {
- return -1;
+ return SDL_FALSE;
}
process_t reverse_tunnel_proc = adb_reverse(serial, SOCKET_NAME, local_port);
if (wait_for_success(reverse_tunnel_proc, "adb reverse")) {
- return -1;
+ return SDL_FALSE;
}
TCPsocket server_socket = listen_on_port(local_port);
@@ -239,7 +239,7 @@ int show_screen(const char *serial, Uint16 local_port) {
// server will connect to our socket
process_t server = start_server(serial);
if (server == PROCESS_NONE) {
- ret = -1;
+ ret = SDL_FALSE;
SDLNet_TCP_Close(server_socket);
goto screen_finally_adb_reverse_remove;
}
@@ -252,7 +252,7 @@ int show_screen(const char *serial, Uint16 local_port) {
SDLNet_TCP_Close(server_socket);
if (!device_socket) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not accept video socket: %s", SDL_GetError());
- ret = -1;
+ ret = SDL_FALSE;
stop_server(server);
goto screen_finally_adb_reverse_remove;
}
@@ -265,14 +265,14 @@ int show_screen(const char *serial, Uint16 local_port) {
// to init the window immediately
if (!read_initial_device_info(device_socket, device_name, &frame_size)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not retrieve initial screen size");
- ret = -1;
+ ret = SDL_FALSE;
SDLNet_TCP_Close(device_socket);
stop_server(server);
goto screen_finally_adb_reverse_remove;
}
- if (frames_init(&frames)) {
- ret = -1;
+ if (!frames_init(&frames)) {
+ ret = SDL_FALSE;
SDLNet_TCP_Close(device_socket);
stop_server(server);
goto screen_finally_adb_reverse_remove;
@@ -284,8 +284,8 @@ int show_screen(const char *serial, Uint16 local_port) {
// now we consumed the width and height values, the socket receives the video stream
// start the decoder
- if (decoder_start(&decoder)) {
- ret = -1;
+ if (!decoder_start(&decoder)) {
+ ret = SDL_FALSE;
SDLNet_TCP_Close(device_socket);
stop_server(server);
goto screen_finally_destroy_frames;
@@ -293,7 +293,7 @@ int show_screen(const char *serial, Uint16 local_port) {
if (SDL_Init(SDL_INIT_VIDEO)) {
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL: %s", SDL_GetError());
- ret = -1;
+ ret = SDL_FALSE;
goto screen_finally_stop_decoder;
}
atexit(SDL_Quit);
@@ -308,20 +308,20 @@ int show_screen(const char *serial, Uint16 local_port) {
window_size.width, window_size.height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (!window) {
SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "Could not create window: %s", SDL_GetError());
- ret = -1;
+ ret = SDL_FALSE;
goto screen_finally_stop_decoder;
}
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (!renderer) {
SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Could not create renderer: %s", SDL_GetError());
- ret = -1;
+ ret = SDL_FALSE;
goto screen_finally_destroy_window;
}
if (SDL_RenderSetLogicalSize(renderer, frame_size.width, frame_size.height)) {
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Could not set renderer logical size: %s", SDL_GetError());
- ret = -1;
+ ret = SDL_FALSE;
goto screen_finally_destroy_renderer;
}
@@ -329,7 +329,7 @@ int show_screen(const char *serial, Uint16 local_port) {
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, frame_size.width, frame_size.height);
if (!texture) {
SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Could not create texture: %s", SDL_GetError());
- ret = -1;
+ ret = SDL_FALSE;
goto screen_finally_destroy_renderer;
}
diff --git a/app/src/screen.h b/app/src/screen.h
index 5b517480..ba679b55 100644
--- a/app/src/screen.h
+++ b/app/src/screen.h
@@ -3,6 +3,6 @@
#include <SDL2/SDL.h>
-int show_screen(const char *serial, Uint16 local_port);
+SDL_bool show_screen(const char *serial, Uint16 local_port);
#endif