Display and control your Android device
Define macros wrappers for logs
Romain Vimont3ed80a1fac06
diff --git a/app/src/command.c b/app/src/command.cindex 401cefe0..266704b7 100644--- a/app/src/command.c+++ b/app/src/command.c@@ -3,7 +3,8 @@#include <stdio.h>#include <stdlib.h>#include <string.h>-#include <SDL2/SDL_log.h>++#include "log.h"#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))@@ -67,15 +68,15 @@ process_t adb_push(const char *serial, const char *local, const char *remote) {SDL_bool process_check_success(process_t proc, const char *name) {if (proc == PROCESS_NONE) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not execute \"%s\"", name);+ LOGE("Could not execute \"%s\"", name);return SDL_FALSE;}exit_code_t exit_code;if (!cmd_simple_wait(proc, &exit_code)) {if (exit_code != NO_EXIT_CODE) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "\"%s\" returned with value %" PRIexitcode, name, exit_code);+ LOGE("\"%s\" returned with value %" PRIexitcode, name, exit_code);} else {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "\"%s\" exited unexpectedly", name);+ LOGE("\"%s\" exited unexpectedly", name);}return SDL_FALSE;}diff --git a/app/src/controlevent.c b/app/src/controlevent.cindex 4e5517c4..e88ab936 100644--- a/app/src/controlevent.c+++ b/app/src/controlevent.c@@ -1,9 +1,9 @@#include "controlevent.h"-#include <SDL2/SDL_log.h>#include <SDL2/SDL_stdinc.h>#include "lockutil.h"+#include "log.h"static inline void write16(Uint8 *buf, Uint16 value) {buf[0] = value >> 8;@@ -56,7 +56,7 @@ int control_event_serialize(const struct control_event *event, unsigned char *bubuf[1] = event->command_event.action;return 2;default:- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown event type: %u", (unsigned) event->type);+ LOGW("Unknown event type: %u", (unsigned) event->type);return 0;}}diff --git a/app/src/controller.c b/app/src/controller.cindex 5f32aa98..8f5bddf8 100644--- a/app/src/controller.c+++ b/app/src/controller.c@@ -1,6 +1,7 @@#include "controller.h"#include "lockutil.h"+#include "log.h"SDL_bool controller_init(struct controller *controller, TCPsocket video_socket) {if (!control_event_queue_init(&controller->queue)) {@@ -65,7 +66,7 @@ static int run_controller(void *data) {struct control_event event;while (control_event_queue_take(&controller->queue, &event)) {if (!process_event(controller, &event)) {- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Cannot write event to socket");+ LOGD("Cannot write event to socket");goto end;}}@@ -76,11 +77,11 @@ end:}SDL_bool controller_start(struct controller *controller) {- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Starting controller thread");+ LOGD("Starting controller thread");controller->thread = SDL_CreateThread(run_controller, "controller", controller);if (!controller->thread) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not start controller thread");+ LOGC("Could not start controller thread");return SDL_FALSE;}diff --git a/app/src/decoder.c b/app/src/decoder.cindex 75bf9351..afab344c 100644--- a/app/src/decoder.c+++ b/app/src/decoder.c@@ -10,6 +10,7 @@#include "events.h"#include "frames.h"#include "lockutil.h"+#include "log.h"#include "netutil.h"#define BUFSIZE 0x10000@@ -38,39 +39,39 @@ static int run_decoder(void *data) {AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);if (!codec) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "H.264 decoder not found");+ LOGE("H.264 decoder not found");return -1;}AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);if (!codec_ctx) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate decoder context");+ LOGC("Could not allocate decoder context");return -1;}if (avcodec_open2(codec_ctx, codec, NULL) < 0) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not open H.264 codec");+ LOGE("Could not open H.264 codec");ret = -1;goto run_finally_free_codec_ctx;}AVFormatContext *format_ctx = avformat_alloc_context();if (!format_ctx) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate format context");+ LOGC("Could not allocate format context");ret = -1;goto run_finally_close_codec;}unsigned char *buffer = av_malloc(BUFSIZE);if (!buffer) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate buffer");+ LOGC("Could not allocate buffer");ret = -1;goto run_finally_free_format_ctx;}AVIOContext *avio_ctx = avio_alloc_context(buffer, BUFSIZE, 0, decoder, read_packet, NULL, NULL);if (!avio_ctx) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate avio context");+ LOGC("Could not allocate avio context");// avformat_open_input takes ownership of 'buffer'// so only free the buffer before avformat_open_input()av_free(buffer);@@ -82,7 +83,7 @@ static int run_decoder(void *data) {//const char *url = "tcp://127.0.0.1:1234";if (avformat_open_input(&format_ctx, NULL, NULL, NULL) < 0) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not open video stream");+ LOGE("Could not open video stream");ret = -1;goto run_finally_free_avio_ctx;}@@ -100,7 +101,7 @@ static int run_decoder(void *data) {int got_picture;int len = avcodec_decode_video2(codec_ctx, decoder->frames->decoding_frame, &got_picture, &packet);if (len < 0) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not decode video packet: %d", len);+ LOGE("Could not decode video packet: %d", len);goto run_quit;}if (got_picture) {@@ -112,11 +113,11 @@ static int run_decoder(void *data) {#elseint ret;if ((ret = avcodec_send_packet(codec_ctx, &packet)) < 0) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not send video packet: %d", ret);+ LOGE("Could not send video packet: %d", ret);goto run_quit;}if ((ret = avcodec_receive_frame(codec_ctx, decoder->frames->decoding_frame)) < 0) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not receive video frame: %d", ret);+ LOGE("Could not receive video frame: %d", ret);goto run_quit;}@@ -124,7 +125,7 @@ static int run_decoder(void *data) {#endif}- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "End of frames");+ LOGD("End of frames");run_quit:avformat_close_input(&format_ctx);@@ -146,11 +147,11 @@ void decoder_init(struct decoder *decoder, struct frames *frames, TCPsocket vide}SDL_bool decoder_start(struct decoder *decoder) {- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Starting decoder thread");+ LOGD("Starting decoder thread");decoder->thread = SDL_CreateThread(run_decoder, "video_decoder", decoder);if (!decoder->thread) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not start decoder thread");+ LOGC("Could not start decoder thread");return SDL_FALSE;}diff --git a/app/src/device.c b/app/src/device.cindex 8324faeb..c1dd7a5d 100644--- a/app/src/device.c+++ b/app/src/device.c@@ -1,9 +1,10 @@#include "device.h"+#include "log.h"SDL_bool device_read_info(TCPsocket device_socket, char *device_name, struct size *size) {unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];if (SDLNet_TCP_Recv(device_socket, buf, sizeof(buf)) <= 0) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not retrieve device information");+ LOGE("Could not retrieve device information");return SDL_FALSE;}buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0'; // in case the client sends garbagediff --git a/app/src/frames.c b/app/src/frames.cindex db1333dd..1730e565 100644--- a/app/src/frames.c+++ b/app/src/frames.c@@ -1,13 +1,13 @@#include "frames.h"#include <SDL2/SDL_assert.h>-#include <SDL2/SDL_log.h>#include <SDL2/SDL_mutex.h>#include <libavutil/avutil.h>#include <libavformat/avformat.h>#include "config.h"#include "lockutil.h"+#include "log.h"SDL_bool frames_init(struct frames *frames) {if (!(frames->decoding_frame = av_frame_alloc())) {@@ -69,7 +69,7 @@ SDL_bool frames_offer_decoded_frame(struct frames *frames) {}#elseif (!frames->rendering_frame_consumed) {- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Skip frame");+ LOGD("Skip frame");}#endifdiff --git a/app/src/lockutil.c b/app/src/lockutil.cindex dd026f3c..67183d71 100644--- a/app/src/lockutil.c+++ b/app/src/lockutil.c@@ -1,31 +1,32 @@#include <stdlib.h>-#include <SDL2/SDL_log.h>#include <SDL2/SDL_mutex.h>+#include "log.h"+void mutex_lock(SDL_mutex *mutex) {if (SDL_LockMutex(mutex)) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not lock mutex");+ LOGC("Could not lock mutex");abort();}}void mutex_unlock(SDL_mutex *mutex) {if (SDL_UnlockMutex(mutex)) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not unlock mutex");+ LOGC("Could not unlock mutex");abort();}}void cond_wait(SDL_cond *cond, SDL_mutex *mutex) {if (SDL_CondWait(cond, mutex)) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not wait on condition");+ LOGC("Could not wait on condition");abort();}}void cond_signal(SDL_cond *cond) {if (SDL_CondSignal(cond)) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not signal a condition");+ LOGC("Could not signal a condition");abort();}}diff --git a/app/src/log.h b/app/src/log.hnew file mode 100644index 00000000..7e5435c5--- /dev/null+++ b/app/src/log.h@@ -0,0 +1,12 @@+#ifndef LOG_H+#define LOG_H++#include <SDL2/SDL_log.h>++#define LOGD(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)+#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)+#define LOGW(...) SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)+#define LOGE(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)+#define LOGC(...) SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)++#endifdiff --git a/app/src/main.c b/app/src/main.cindex 852815e1..0a87fe55 100644--- a/app/src/main.c+++ b/app/src/main.c@@ -7,6 +7,7 @@#include <SDL2/SDL_net.h>#include "config.h"+#include "log.h"struct args {const char *serial;@@ -122,16 +123,16 @@ static int parse_args(struct args *args, int argc, char *argv[]) {case 'p': {char *endptr;if (*optarg == '\0') {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port parameter is empty");+ LOGE("Invalid port parameter is empty");return -1;}long value = strtol(optarg, &endptr, 0);if (*endptr != '\0') {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s", optarg);+ LOGE("Invalid port: %s", optarg);return -1;}if (value & ~0xffff) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Port out of range: %ld", value);+ LOGE("Port out of range: %ld", value);return -1;}args->port = (Uint16) value;@@ -140,16 +141,16 @@ static int parse_args(struct args *args, int argc, char *argv[]) {case 'm': {char *endptr;if (*optarg == '\0') {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Max size parameter is empty");+ LOGE("Max size parameter is empty");return -1;}long value = strtol(optarg, &endptr, 0);if (*endptr != '\0') {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid max size: %s", optarg);+ LOGE("Invalid max size: %s", optarg);return -1;}if (value & ~0xffff) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Max size must be between 0 and 65535: %ld", value);+ LOGE("Max size must be between 0 and 65535: %ld", value);return -1;}args->max_size = (Uint16) value;@@ -158,14 +159,14 @@ static int parse_args(struct args *args, int argc, char *argv[]) {case 'b': {char *endptr;if (*optarg == '\0') {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Bit-rate parameter is empty");+ LOGE("Bit-rate parameter is empty");return -1;}long value = strtol(optarg, &endptr, 0);int mul = 1;if (*endptr != '\0') {if (optarg == endptr) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid bit-rate: %s", optarg);+ LOGE("Invalid bit-rate: %s", optarg);return -1;}if ((*endptr == 'M' || *endptr == 'm') && endptr[1] == '\0') {@@ -173,12 +174,12 @@ static int parse_args(struct args *args, int argc, char *argv[]) {} else if ((*endptr == 'K' || *endptr == 'k') && endptr[1] == '\0') {mul = 1000;} else {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid bit-rate unit: %s", optarg);+ LOGE("Invalid bit-rate unit: %s", optarg);return -1;}}if (value < 0 || ((Uint32) -1) / mul < value) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Bitrate must be positive and less than 2^32: %s", optarg);+ LOGE("Bitrate must be positive and less than 2^32: %s", optarg);return -1;}args->bit_rate = (Uint32) value * mul;@@ -195,7 +196,7 @@ static int parse_args(struct args *args, int argc, char *argv[]) {args->serial = argv[index++];}if (index < argc) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unexpected additional argument: %s", argv[index]);+ LOGE("Unexpected additional argument: %s", argv[index]);return -1;}return 0;diff --git a/app/src/netutil.c b/app/src/netutil.cindex 79ec108f..b3054587 100644--- a/app/src/netutil.c+++ b/app/src/netutil.c@@ -2,23 +2,25 @@#include <SDL2/SDL_net.h>+#include "log.h"+// contrary to SDLNet_TCP_Send and SDLNet_TCP_Recv, SDLNet_TCP_Accept is non-blocking// so we need to block before calling itTCPsocket server_socket_accept(TCPsocket server_socket, Uint32 timeout_ms) {SDLNet_SocketSet set = SDLNet_AllocSocketSet(1);if (!set) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate socket set");+ LOGC("Could not allocate socket set");return NULL;}if (SDLNet_TCP_AddSocket(set, server_socket) == -1) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not add socket to set");+ LOGC("Could not add socket to set");SDLNet_FreeSocketSet(set);return NULL;}if (SDLNet_CheckSockets(set, timeout_ms) != 1) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No connection to accept");+ LOGE("No connection to accept");SDLNet_FreeSocketSet(set);return NULL;}diff --git a/app/src/scrcpy.c b/app/src/scrcpy.cindex afa3d485..b6158737 100644--- a/app/src/scrcpy.c+++ b/app/src/scrcpy.c@@ -15,6 +15,7 @@#include "device.h"#include "events.h"#include "frames.h"+#include "log.h"#include "lockutil.h"#include "netutil.h"#include "screen.h"@@ -40,7 +41,7 @@ static void count_frame(void) {long now = timestamp_ms();++nbframes;if (now - ts > 1000) {- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%d fps", nbframes);+ LOGD("%d fps", nbframes);ts = now;nbframes = 0;}@@ -51,10 +52,10 @@ static void event_loop(void) {while (SDL_WaitEvent(&event)) {switch (event.type) {case EVENT_DECODER_STOPPED:- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Video decoder stopped");+ LOGD("Video decoder stopped");return;case SDL_QUIT:- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "User requested to quit");+ LOGD("User requested to quit");return;case EVENT_NEW_FRAME:if (!screen.has_frame) {@@ -167,7 +168,7 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 bevent_loop();- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "quit...");+ LOGD("quit...");screen_destroy(&screen);finally_stop_and_join_controller:controller_stop(&controller);diff --git a/app/src/screen.c b/app/src/screen.cindex 57a827b1..638b57f4 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -5,13 +5,14 @@#include "icon.xpm"#include "lockutil.h"+#include "log.h"#include "tinyxpm.h"#define DISPLAY_MARGINS 96SDL_bool sdl_init_and_configure(void) {if (SDL_Init(SDL_INIT_VIDEO)) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL: %s", SDL_GetError());+ LOGC("Could not initialize SDL: %s", SDL_GetError());return SDL_FALSE;}@@ -19,13 +20,13 @@ SDL_bool sdl_init_and_configure(void) {// Bilinear resizingif (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Could not enable bilinear filtering");+ LOGW("Could not enable bilinear filtering");}#if SDL_VERSION_ATLEAST(2, 0, 5)// Handle a click to gain focus as any other clickif (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Could not enable mouse focus clickthrough");+ LOGW("Could not enable mouse focus clickthrough");}#endif@@ -73,7 +74,7 @@ static SDL_bool get_preferred_display_bounds(struct size *bounds) {# define GET_DISPLAY_BOUNDS(i, r) SDL_GetDisplayBounds((i), (r))#endifif (GET_DISPLAY_BOUNDS(0, &rect)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Could not get display usable bounds: %s", SDL_GetError());+ LOGW("Could not get display usable bounds: %s", SDL_GetError());return SDL_FALSE;}@@ -137,37 +138,37 @@ SDL_bool screen_init_rendering(struct screen *screen, const char *device_name, sscreen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,window_size.width, window_size.height, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);if (!screen->window) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not create window: %s", SDL_GetError());+ LOGC("Could not create window: %s", SDL_GetError());return SDL_FALSE;}screen->renderer = SDL_CreateRenderer(screen->window, -1, SDL_RENDERER_ACCELERATED);if (!screen->renderer) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not create renderer: %s", SDL_GetError());+ LOGC("Could not create renderer: %s", SDL_GetError());screen_destroy(screen);return SDL_FALSE;}if (SDL_RenderSetLogicalSize(screen->renderer, frame_size.width, frame_size.height)) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not set renderer logical size: %s", SDL_GetError());+ LOGE("Could not set renderer logical size: %s", SDL_GetError());screen_destroy(screen);return SDL_FALSE;}SDL_Surface *icon = read_xpm(icon_xpm);if (!icon) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load icon: %s", SDL_GetError());+ LOGE("Could not load icon: %s", SDL_GetError());screen_destroy(screen);return SDL_FALSE;}SDL_SetWindowIcon(screen->window, icon);SDL_FreeSurface(icon);- SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Initial texture: %" PRIu16 "x%" PRIu16, frame_size.width, frame_size.height);+ LOGI("Initial texture: %" PRIu16 "x%" PRIu16, frame_size.width, frame_size.height);screen->texture = SDL_CreateTexture(screen->renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,frame_size.width, frame_size.height);if (!screen->texture) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not create texture: %s", SDL_GetError());+ LOGC("Could not create texture: %s", SDL_GetError());screen_destroy(screen);return SDL_FALSE;}@@ -196,7 +197,7 @@ void screen_destroy(struct screen *screen) {static SDL_bool prepare_for_frame(struct screen *screen, struct size new_frame_size) {if (screen->frame_size.width != new_frame_size.width || screen->frame_size.height != new_frame_size.height) {if (SDL_RenderSetLogicalSize(screen->renderer, new_frame_size.width, new_frame_size.height)) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not set renderer logical size: %s", SDL_GetError());+ LOGE("Could not set renderer logical size: %s", SDL_GetError());return SDL_FALSE;}@@ -213,12 +214,12 @@ static SDL_bool prepare_for_frame(struct screen *screen, struct size new_frame_sscreen->frame_size = new_frame_size;- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "New texture: %" PRIu16 "x%" PRIu16,+ LOGD("New texture: %" PRIu16 "x%" PRIu16,screen->frame_size.width, screen->frame_size.height);screen->texture = SDL_CreateTexture(screen->renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,new_frame_size.width, new_frame_size.height);if (!screen->texture) {- SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not create texture: %s", SDL_GetError());+ LOGC("Could not create texture: %s", SDL_GetError());return SDL_FALSE;}}@@ -262,7 +263,7 @@ void screen_switch_fullscreen(struct screen *screen) {}Uint32 new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP;if (SDL_SetWindowFullscreen(screen->window, new_mode)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Could not switch fullscreen mode: %s", SDL_GetError());+ LOGW("Could not switch fullscreen mode: %s", SDL_GetError());return;}@@ -272,7 +273,7 @@ void screen_switch_fullscreen(struct screen *screen) {SDL_SetWindowSize(screen->window, screen->windowed_window_size.width, screen->windowed_window_size.height);}- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Switched to %s mode", screen->fullscreen ? "fullscreen" : "windowed");+ LOGD("Switched to %s mode", screen->fullscreen ? "fullscreen" : "windowed");screen_render(screen);}@@ -280,13 +281,13 @@ void screen_resize_to_fit(struct screen *screen) {if (!screen->fullscreen) {struct size optimal_size = get_optimal_window_size(screen, screen->frame_size);SDL_SetWindowSize(screen->window, optimal_size.width, optimal_size.height);- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Resized to optimal size");+ LOGD("Resized to optimal size");}}void screen_resize_to_pixel_perfect(struct screen *screen) {if (!screen->fullscreen) {SDL_SetWindowSize(screen->window, screen->frame_size.width, screen->frame_size.height);- SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Resized to pixel-perfect");+ LOGD("Resized to pixel-perfect");}}diff --git a/app/src/screencontrol.c b/app/src/screencontrol.cindex 20f173fc..aca62729 100644--- a/app/src/screencontrol.c+++ b/app/src/screencontrol.c@@ -1,8 +1,7 @@#include "screencontrol.h"-#include <SDL2/SDL_log.h>-#include "convert.h"+#include "log.h"static struct point get_mouse_point(void) {int x;@@ -32,14 +31,14 @@ static void send_keycode(struct controller *controller, enum android_keycode key};if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send %s (DOWN)", name);+ LOGW("Cannot send %s (DOWN)", name);return;}// send UP eventcontrol_event.keycode_event.action = AKEY_EVENT_ACTION_UP;if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send %s (UP)", name);+ LOGW("Cannot send %s (UP)", name);}}@@ -75,7 +74,7 @@ static void turn_screen_on(struct controller *controller) {},};if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot turn screen on");+ LOGW("Cannot turn screen on");}}@@ -99,7 +98,7 @@ void screencontrol_handle_text_input(struct controller *controller,strncpy(control_event.text_event.text, event->text, TEXT_MAX_LENGTH);control_event.text_event.text[TEXT_MAX_LENGTH] = '\0';if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send text event");+ LOGW("Cannot send text event");}}@@ -154,7 +153,7 @@ void screencontrol_handle_key(struct controller *controller,struct control_event control_event;if (input_key_from_sdl_to_android(event, &control_event)) {if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send control event");+ LOGW("Cannot send control event");}}}@@ -169,7 +168,7 @@ void screencontrol_handle_mouse_motion(struct controller *controller,struct control_event control_event;if (mouse_motion_from_sdl_to_android(event, screen->frame_size, &control_event)) {if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send mouse motion event");+ LOGW("Cannot send mouse motion event");}}}@@ -184,7 +183,7 @@ void screencontrol_handle_mouse_button(struct controller *controller,struct control_event control_event;if (mouse_button_from_sdl_to_android(event, screen->frame_size, &control_event)) {if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send mouse button event");+ LOGW("Cannot send mouse button event");}}}@@ -199,7 +198,7 @@ void screencontrol_handle_mouse_wheel(struct controller *controller,struct control_event control_event;if (mouse_wheel_from_sdl_to_android(event, position, &control_event)) {if (!controller_push_event(controller, &control_event)) {- SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send wheel button event");+ LOGW("Cannot send wheel button event");}}}diff --git a/app/src/server.c b/app/src/server.cindex bcc0967a..333285f9 100644--- a/app/src/server.c+++ b/app/src/server.c@@ -1,9 +1,10 @@#include "server.h"-#include <SDL2/SDL_log.h>#include <SDL2/SDL_net.h>#include <errno.h>#include <stdint.h>++#include "log.h"#include "netutil.h"#define SOCKET_NAME "scrcpy"@@ -46,7 +47,7 @@ static process_t execute_server(const char *serial, Uint16 max_size, Uint32 bit_static void terminate_server(process_t server) {if (!cmd_terminate(server)) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not terminate server: %s", strerror(errno));+ LOGE("Could not terminate server: %s", strerror(errno));}}@@ -80,7 +81,7 @@ SDL_bool server_start(struct server *server, const char *serial, Uint16 local_poserver->server_socket = listen_on_port(local_port);if (!server->server_socket) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not listen on port %" PRIu16, local_port);+ LOGE("Could not listen on port %" PRIu16, local_port);disable_tunnel(serial);return SDL_FALSE;}diff --git a/app/src/sys/win/command.c b/app/src/sys/win/command.cindex 031f77e2..4269cf0f 100644--- a/app/src/sys/win/command.c+++ b/app/src/sys/win/command.c@@ -1,6 +1,6 @@#include "../../command.h"-#include <SDL2/SDL_log.h>+#include "../../log.h"#include "../../strutil.h"HANDLE cmd_execute(const char *path, const char *const argv[]) {@@ -16,7 +16,7 @@ HANDLE cmd_execute(const char *path, const char *const argv[]) {char cmd[256];size_t ret = xstrjoin(cmd, argv, ' ', sizeof(cmd));if (ret >= sizeof(cmd)) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Command too long (%" PRIsizet " chars)", sizeof(cmd) - 1);+ LOGE("Command too long (%" PRIsizet " chars)", sizeof(cmd) - 1);return NULL;}diff --git a/app/src/tinyxpm.c b/app/src/tinyxpm.cindex cf782818..dafe6cac 100644--- a/app/src/tinyxpm.c+++ b/app/src/tinyxpm.c@@ -3,6 +3,8 @@#include <stdio.h>#include <stdlib.h>+#include "log.h"+struct index {char c;Uint32 color;@@ -69,7 +71,7 @@ SDL_Surface *read_xpm(char *xpm[]) {// parse imageUint32 *pixels = SDL_malloc(4 * width * height);if (!pixels) {- SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate icon memory");+ LOGE("Could not allocate icon memory");return NULL;}for (int y = 0; y < height; ++y) {