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:
parent
2b44052f80
commit
37d88b8a6a
7 changed files with 27 additions and 27 deletions
|
@ -148,16 +148,16 @@ run_finally_free_codec_ctx:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int decoder_start(struct decoder *decoder) {
|
SDL_bool decoder_start(struct decoder *decoder) {
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Starting decoder thread");
|
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Starting decoder thread");
|
||||||
|
|
||||||
decoder->thread = SDL_CreateThread(run_decoder, "video_decoder", decoder);
|
decoder->thread = SDL_CreateThread(run_decoder, "video_decoder", decoder);
|
||||||
if (!decoder->thread) {
|
if (!decoder->thread) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "Could not start 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) {
|
void decoder_join(struct decoder *decoder) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct decoder {
|
||||||
SDL_bool skip_frames;
|
SDL_bool skip_frames;
|
||||||
};
|
};
|
||||||
|
|
||||||
int decoder_start(struct decoder *decoder);
|
SDL_bool decoder_start(struct decoder *decoder);
|
||||||
void decoder_join(struct decoder *decoder);
|
void decoder_join(struct decoder *decoder);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <libavutil/avutil.h>
|
#include <libavutil/avutil.h>
|
||||||
#include <libavformat/avformat.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())) {
|
if (!(frames->decoding_frame = av_frame_alloc())) {
|
||||||
goto error_0;
|
goto error_0;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ int frames_init(struct frames *frames) {
|
||||||
|
|
||||||
frames->rendering_frame_consumed = SDL_TRUE;
|
frames->rendering_frame_consumed = SDL_TRUE;
|
||||||
|
|
||||||
return 0;
|
return SDL_TRUE;
|
||||||
|
|
||||||
error_3:
|
error_3:
|
||||||
SDL_DestroyMutex(frames->mutex);
|
SDL_DestroyMutex(frames->mutex);
|
||||||
|
@ -32,7 +32,7 @@ error_2:
|
||||||
error_1:
|
error_1:
|
||||||
av_frame_free(&frames->decoding_frame);
|
av_frame_free(&frames->decoding_frame);
|
||||||
error_0:
|
error_0:
|
||||||
return -1;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void frames_destroy(struct frames *frames) {
|
void frames_destroy(struct frames *frames) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct frames {
|
||||||
SDL_bool rendering_frame_consumed;
|
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_destroy(struct frames *frames);
|
||||||
|
|
||||||
void frames_swap(struct frames *frames);
|
void frames_swap(struct frames *frames);
|
||||||
|
|
|
@ -56,8 +56,8 @@ int main(int argc, char *argv[]) {
|
||||||
.port = DEFAULT_LOCAL_PORT,
|
.port = DEFAULT_LOCAL_PORT,
|
||||||
};
|
};
|
||||||
if (parse_args(&args, argc, argv)) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,8 +213,8 @@ static int wait_for_success(process_t proc, const char *name) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int show_screen(const char *serial, Uint16 local_port) {
|
SDL_bool show_screen(const char *serial, Uint16 local_port) {
|
||||||
int ret = 0;
|
SDL_bool ret = 0;
|
||||||
|
|
||||||
const char *server_jar_path = getenv("SCRCPY_SERVER_JAR");
|
const char *server_jar_path = getenv("SCRCPY_SERVER_JAR");
|
||||||
if (!server_jar_path) {
|
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/");
|
process_t push_proc = adb_push(serial, server_jar_path, "/data/local/tmp/");
|
||||||
if (wait_for_success(push_proc, "adb push")) {
|
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);
|
process_t reverse_tunnel_proc = adb_reverse(serial, SOCKET_NAME, local_port);
|
||||||
if (wait_for_success(reverse_tunnel_proc, "adb reverse")) {
|
if (wait_for_success(reverse_tunnel_proc, "adb reverse")) {
|
||||||
return -1;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPsocket server_socket = listen_on_port(local_port);
|
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
|
// server will connect to our socket
|
||||||
process_t server = start_server(serial);
|
process_t server = start_server(serial);
|
||||||
if (server == PROCESS_NONE) {
|
if (server == PROCESS_NONE) {
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
SDLNet_TCP_Close(server_socket);
|
SDLNet_TCP_Close(server_socket);
|
||||||
goto screen_finally_adb_reverse_remove;
|
goto screen_finally_adb_reverse_remove;
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ int show_screen(const char *serial, Uint16 local_port) {
|
||||||
SDLNet_TCP_Close(server_socket);
|
SDLNet_TCP_Close(server_socket);
|
||||||
if (!device_socket) {
|
if (!device_socket) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not accept video socket: %s", SDL_GetError());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not accept video socket: %s", SDL_GetError());
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
stop_server(server);
|
stop_server(server);
|
||||||
goto screen_finally_adb_reverse_remove;
|
goto screen_finally_adb_reverse_remove;
|
||||||
}
|
}
|
||||||
|
@ -265,14 +265,14 @@ int show_screen(const char *serial, Uint16 local_port) {
|
||||||
// to init the window immediately
|
// to init the window immediately
|
||||||
if (!read_initial_device_info(device_socket, device_name, &frame_size)) {
|
if (!read_initial_device_info(device_socket, device_name, &frame_size)) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not retrieve initial screen size");
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not retrieve initial screen size");
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
SDLNet_TCP_Close(device_socket);
|
SDLNet_TCP_Close(device_socket);
|
||||||
stop_server(server);
|
stop_server(server);
|
||||||
goto screen_finally_adb_reverse_remove;
|
goto screen_finally_adb_reverse_remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frames_init(&frames)) {
|
if (!frames_init(&frames)) {
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
SDLNet_TCP_Close(device_socket);
|
SDLNet_TCP_Close(device_socket);
|
||||||
stop_server(server);
|
stop_server(server);
|
||||||
goto screen_finally_adb_reverse_remove;
|
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
|
// now we consumed the width and height values, the socket receives the video stream
|
||||||
// start the decoder
|
// start the decoder
|
||||||
if (decoder_start(&decoder)) {
|
if (!decoder_start(&decoder)) {
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
SDLNet_TCP_Close(device_socket);
|
SDLNet_TCP_Close(device_socket);
|
||||||
stop_server(server);
|
stop_server(server);
|
||||||
goto screen_finally_destroy_frames;
|
goto screen_finally_destroy_frames;
|
||||||
|
@ -293,7 +293,7 @@ int show_screen(const char *serial, Uint16 local_port) {
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
if (SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL: %s", SDL_GetError());
|
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL: %s", SDL_GetError());
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
goto screen_finally_stop_decoder;
|
goto screen_finally_stop_decoder;
|
||||||
}
|
}
|
||||||
atexit(SDL_Quit);
|
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);
|
window_size.width, window_size.height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
||||||
if (!window) {
|
if (!window) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "Could not create window: %s", SDL_GetError());
|
SDL_LogCritical(SDL_LOG_CATEGORY_SYSTEM, "Could not create window: %s", SDL_GetError());
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
goto screen_finally_stop_decoder;
|
goto screen_finally_stop_decoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
if (!renderer) {
|
if (!renderer) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Could not create renderer: %s", SDL_GetError());
|
SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Could not create renderer: %s", SDL_GetError());
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
goto screen_finally_destroy_window;
|
goto screen_finally_destroy_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_RenderSetLogicalSize(renderer, frame_size.width, frame_size.height)) {
|
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());
|
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;
|
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);
|
SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, frame_size.width, frame_size.height);
|
||||||
if (!texture) {
|
if (!texture) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Could not create texture: %s", SDL_GetError());
|
SDL_LogCritical(SDL_LOG_CATEGORY_RENDER, "Could not create texture: %s", SDL_GetError());
|
||||||
ret = -1;
|
ret = SDL_FALSE;
|
||||||
goto screen_finally_destroy_renderer;
|
goto screen_finally_destroy_renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
int show_screen(const char *serial, Uint16 local_port);
|
SDL_bool show_screen(const char *serial, Uint16 local_port);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue