Use SDL_bool return type instead of int

Many functions returned an int to indicate their success. For clarity,
use SDL_bool instead.
This commit is contained in:
Romain Vimont 2017-12-15 11:27:11 +01:00
parent 2b44052f80
commit 37d88b8a6a
7 changed files with 27 additions and 27 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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) {

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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