Define macros wrappers for logs
Use macros to wrap SDL_Log* functions with the "application" category.
This commit is contained in:
parent
d45ef1a295
commit
3ed80a1fac
16 changed files with 105 additions and 81 deletions
|
@ -3,7 +3,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <SDL2/SDL_log.h>
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
#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) {
|
SDL_bool process_check_success(process_t proc, const char *name) {
|
||||||
if (proc == PROCESS_NONE) {
|
if (proc == PROCESS_NONE) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not execute \"%s\"", name);
|
LOGE("Could not execute \"%s\"", name);
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
exit_code_t exit_code;
|
exit_code_t exit_code;
|
||||||
if (!cmd_simple_wait(proc, &exit_code)) {
|
if (!cmd_simple_wait(proc, &exit_code)) {
|
||||||
if (exit_code != NO_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 {
|
} else {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "\"%s\" exited unexpectedly", name);
|
LOGE("\"%s\" exited unexpectedly", name);
|
||||||
}
|
}
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#include "controlevent.h"
|
#include "controlevent.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_log.h>
|
|
||||||
#include <SDL2/SDL_stdinc.h>
|
#include <SDL2/SDL_stdinc.h>
|
||||||
|
|
||||||
#include "lockutil.h"
|
#include "lockutil.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
static inline void write16(Uint8 *buf, Uint16 value) {
|
static inline void write16(Uint8 *buf, Uint16 value) {
|
||||||
buf[0] = value >> 8;
|
buf[0] = value >> 8;
|
||||||
|
@ -56,7 +56,7 @@ int control_event_serialize(const struct control_event *event, unsigned char *bu
|
||||||
buf[1] = event->command_event.action;
|
buf[1] = event->command_event.action;
|
||||||
return 2;
|
return 2;
|
||||||
default:
|
default:
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Unknown event type: %u", (unsigned) event->type);
|
LOGW("Unknown event type: %u", (unsigned) event->type);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
|
||||||
#include "lockutil.h"
|
#include "lockutil.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
SDL_bool controller_init(struct controller *controller, TCPsocket video_socket) {
|
SDL_bool controller_init(struct controller *controller, TCPsocket video_socket) {
|
||||||
if (!control_event_queue_init(&controller->queue)) {
|
if (!control_event_queue_init(&controller->queue)) {
|
||||||
|
@ -65,7 +66,7 @@ static int run_controller(void *data) {
|
||||||
struct control_event event;
|
struct control_event event;
|
||||||
while (control_event_queue_take(&controller->queue, &event)) {
|
while (control_event_queue_take(&controller->queue, &event)) {
|
||||||
if (!process_event(controller, &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;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,11 +77,11 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_bool controller_start(struct controller *controller) {
|
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);
|
controller->thread = SDL_CreateThread(run_controller, "controller", controller);
|
||||||
if (!controller->thread) {
|
if (!controller->thread) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not start controller thread");
|
LOGC("Could not start controller thread");
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "frames.h"
|
#include "frames.h"
|
||||||
#include "lockutil.h"
|
#include "lockutil.h"
|
||||||
|
#include "log.h"
|
||||||
#include "netutil.h"
|
#include "netutil.h"
|
||||||
|
|
||||||
#define BUFSIZE 0x10000
|
#define BUFSIZE 0x10000
|
||||||
|
@ -38,39 +39,39 @@ static int run_decoder(void *data) {
|
||||||
|
|
||||||
AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "H.264 decoder not found");
|
LOGE("H.264 decoder not found");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);
|
AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);
|
||||||
if (!codec_ctx) {
|
if (!codec_ctx) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate decoder context");
|
LOGC("Could not allocate decoder context");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (avcodec_open2(codec_ctx, codec, NULL) < 0) {
|
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;
|
ret = -1;
|
||||||
goto run_finally_free_codec_ctx;
|
goto run_finally_free_codec_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFormatContext *format_ctx = avformat_alloc_context();
|
AVFormatContext *format_ctx = avformat_alloc_context();
|
||||||
if (!format_ctx) {
|
if (!format_ctx) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate format context");
|
LOGC("Could not allocate format context");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto run_finally_close_codec;
|
goto run_finally_close_codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *buffer = av_malloc(BUFSIZE);
|
unsigned char *buffer = av_malloc(BUFSIZE);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate buffer");
|
LOGC("Could not allocate buffer");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto run_finally_free_format_ctx;
|
goto run_finally_free_format_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVIOContext *avio_ctx = avio_alloc_context(buffer, BUFSIZE, 0, decoder, read_packet, NULL, NULL);
|
AVIOContext *avio_ctx = avio_alloc_context(buffer, BUFSIZE, 0, decoder, read_packet, NULL, NULL);
|
||||||
if (!avio_ctx) {
|
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'
|
// avformat_open_input takes ownership of 'buffer'
|
||||||
// so only free the buffer before avformat_open_input()
|
// so only free the buffer before avformat_open_input()
|
||||||
av_free(buffer);
|
av_free(buffer);
|
||||||
|
@ -82,7 +83,7 @@ static int run_decoder(void *data) {
|
||||||
|
|
||||||
//const char *url = "tcp://127.0.0.1:1234";
|
//const char *url = "tcp://127.0.0.1:1234";
|
||||||
if (avformat_open_input(&format_ctx, NULL, NULL, NULL) < 0) {
|
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;
|
ret = -1;
|
||||||
goto run_finally_free_avio_ctx;
|
goto run_finally_free_avio_ctx;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +101,7 @@ static int run_decoder(void *data) {
|
||||||
int got_picture;
|
int got_picture;
|
||||||
int len = avcodec_decode_video2(codec_ctx, decoder->frames->decoding_frame, &got_picture, &packet);
|
int len = avcodec_decode_video2(codec_ctx, decoder->frames->decoding_frame, &got_picture, &packet);
|
||||||
if (len < 0) {
|
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;
|
goto run_quit;
|
||||||
}
|
}
|
||||||
if (got_picture) {
|
if (got_picture) {
|
||||||
|
@ -112,11 +113,11 @@ static int run_decoder(void *data) {
|
||||||
#else
|
#else
|
||||||
int ret;
|
int ret;
|
||||||
if ((ret = avcodec_send_packet(codec_ctx, &packet)) < 0) {
|
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;
|
goto run_quit;
|
||||||
}
|
}
|
||||||
if ((ret = avcodec_receive_frame(codec_ctx, decoder->frames->decoding_frame)) < 0) {
|
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;
|
goto run_quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ static int run_decoder(void *data) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "End of frames");
|
LOGD("End of frames");
|
||||||
|
|
||||||
run_quit:
|
run_quit:
|
||||||
avformat_close_input(&format_ctx);
|
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_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);
|
decoder->thread = SDL_CreateThread(run_decoder, "video_decoder", decoder);
|
||||||
if (!decoder->thread) {
|
if (!decoder->thread) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not start decoder thread");
|
LOGC("Could not start decoder thread");
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
SDL_bool device_read_info(TCPsocket device_socket, char *device_name, struct size *size) {
|
SDL_bool device_read_info(TCPsocket device_socket, char *device_name, struct size *size) {
|
||||||
unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];
|
unsigned char buf[DEVICE_NAME_FIELD_LENGTH + 4];
|
||||||
if (SDLNet_TCP_Recv(device_socket, buf, sizeof(buf)) <= 0) {
|
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;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0'; // in case the client sends garbage
|
buf[DEVICE_NAME_FIELD_LENGTH - 1] = '\0'; // in case the client sends garbage
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include "frames.h"
|
#include "frames.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_assert.h>
|
#include <SDL2/SDL_assert.h>
|
||||||
#include <SDL2/SDL_log.h>
|
|
||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
#include <libavutil/avutil.h>
|
#include <libavutil/avutil.h>
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "lockutil.h"
|
#include "lockutil.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
SDL_bool 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())) {
|
||||||
|
@ -69,7 +69,7 @@ SDL_bool frames_offer_decoded_frame(struct frames *frames) {
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!frames->rendering_frame_consumed) {
|
if (!frames->rendering_frame_consumed) {
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Skip frame");
|
LOGD("Skip frame");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,32 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <SDL2/SDL_log.h>
|
|
||||||
#include <SDL2/SDL_mutex.h>
|
#include <SDL2/SDL_mutex.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
void mutex_lock(SDL_mutex *mutex) {
|
void mutex_lock(SDL_mutex *mutex) {
|
||||||
if (SDL_LockMutex(mutex)) {
|
if (SDL_LockMutex(mutex)) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not lock mutex");
|
LOGC("Could not lock mutex");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mutex_unlock(SDL_mutex *mutex) {
|
void mutex_unlock(SDL_mutex *mutex) {
|
||||||
if (SDL_UnlockMutex(mutex)) {
|
if (SDL_UnlockMutex(mutex)) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not unlock mutex");
|
LOGC("Could not unlock mutex");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cond_wait(SDL_cond *cond, SDL_mutex *mutex) {
|
void cond_wait(SDL_cond *cond, SDL_mutex *mutex) {
|
||||||
if (SDL_CondWait(cond, mutex)) {
|
if (SDL_CondWait(cond, mutex)) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not wait on condition");
|
LOGC("Could not wait on condition");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cond_signal(SDL_cond *cond) {
|
void cond_signal(SDL_cond *cond) {
|
||||||
if (SDL_CondSignal(cond)) {
|
if (SDL_CondSignal(cond)) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not signal a condition");
|
LOGC("Could not signal a condition");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
app/src/log.h
Normal file
12
app/src/log.h
Normal file
|
@ -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__)
|
||||||
|
|
||||||
|
#endif
|
|
@ -7,6 +7,7 @@
|
||||||
#include <SDL2/SDL_net.h>
|
#include <SDL2/SDL_net.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
struct args {
|
struct args {
|
||||||
const char *serial;
|
const char *serial;
|
||||||
|
@ -122,16 +123,16 @@ static int parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
case 'p': {
|
case 'p': {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
if (*optarg == '\0') {
|
if (*optarg == '\0') {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port parameter is empty");
|
LOGE("Invalid port parameter is empty");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
long value = strtol(optarg, &endptr, 0);
|
long value = strtol(optarg, &endptr, 0);
|
||||||
if (*endptr != '\0') {
|
if (*endptr != '\0') {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s", optarg);
|
LOGE("Invalid port: %s", optarg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (value & ~0xffff) {
|
if (value & ~0xffff) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Port out of range: %ld", value);
|
LOGE("Port out of range: %ld", value);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
args->port = (Uint16) value;
|
args->port = (Uint16) value;
|
||||||
|
@ -140,16 +141,16 @@ static int parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
case 'm': {
|
case 'm': {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
if (*optarg == '\0') {
|
if (*optarg == '\0') {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Max size parameter is empty");
|
LOGE("Max size parameter is empty");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
long value = strtol(optarg, &endptr, 0);
|
long value = strtol(optarg, &endptr, 0);
|
||||||
if (*endptr != '\0') {
|
if (*endptr != '\0') {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid max size: %s", optarg);
|
LOGE("Invalid max size: %s", optarg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (value & ~0xffff) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
args->max_size = (Uint16) value;
|
args->max_size = (Uint16) value;
|
||||||
|
@ -158,14 +159,14 @@ static int parse_args(struct args *args, int argc, char *argv[]) {
|
||||||
case 'b': {
|
case 'b': {
|
||||||
char *endptr;
|
char *endptr;
|
||||||
if (*optarg == '\0') {
|
if (*optarg == '\0') {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Bit-rate parameter is empty");
|
LOGE("Bit-rate parameter is empty");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
long value = strtol(optarg, &endptr, 0);
|
long value = strtol(optarg, &endptr, 0);
|
||||||
int mul = 1;
|
int mul = 1;
|
||||||
if (*endptr != '\0') {
|
if (*endptr != '\0') {
|
||||||
if (optarg == endptr) {
|
if (optarg == endptr) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid bit-rate: %s", optarg);
|
LOGE("Invalid bit-rate: %s", optarg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ((*endptr == 'M' || *endptr == 'm') && endptr[1] == '\0') {
|
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') {
|
} else if ((*endptr == 'K' || *endptr == 'k') && endptr[1] == '\0') {
|
||||||
mul = 1000;
|
mul = 1000;
|
||||||
} else {
|
} else {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid bit-rate unit: %s", optarg);
|
LOGE("Invalid bit-rate unit: %s", optarg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value < 0 || ((Uint32) -1) / mul < value) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
args->bit_rate = (Uint32) value * mul;
|
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++];
|
args->serial = argv[index++];
|
||||||
}
|
}
|
||||||
if (index < argc) {
|
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 -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -2,23 +2,25 @@
|
||||||
|
|
||||||
#include <SDL2/SDL_net.h>
|
#include <SDL2/SDL_net.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
// contrary to SDLNet_TCP_Send and SDLNet_TCP_Recv, SDLNet_TCP_Accept is non-blocking
|
// contrary to SDLNet_TCP_Send and SDLNet_TCP_Recv, SDLNet_TCP_Accept is non-blocking
|
||||||
// so we need to block before calling it
|
// so we need to block before calling it
|
||||||
TCPsocket server_socket_accept(TCPsocket server_socket, Uint32 timeout_ms) {
|
TCPsocket server_socket_accept(TCPsocket server_socket, Uint32 timeout_ms) {
|
||||||
SDLNet_SocketSet set = SDLNet_AllocSocketSet(1);
|
SDLNet_SocketSet set = SDLNet_AllocSocketSet(1);
|
||||||
if (!set) {
|
if (!set) {
|
||||||
SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate socket set");
|
LOGC("Could not allocate socket set");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDLNet_TCP_AddSocket(set, server_socket) == -1) {
|
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);
|
SDLNet_FreeSocketSet(set);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDLNet_CheckSockets(set, timeout_ms) != 1) {
|
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);
|
SDLNet_FreeSocketSet(set);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "frames.h"
|
#include "frames.h"
|
||||||
|
#include "log.h"
|
||||||
#include "lockutil.h"
|
#include "lockutil.h"
|
||||||
#include "netutil.h"
|
#include "netutil.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
@ -40,7 +41,7 @@ static void count_frame(void) {
|
||||||
long now = timestamp_ms();
|
long now = timestamp_ms();
|
||||||
++nbframes;
|
++nbframes;
|
||||||
if (now - ts > 1000) {
|
if (now - ts > 1000) {
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%d fps", nbframes);
|
LOGD("%d fps", nbframes);
|
||||||
ts = now;
|
ts = now;
|
||||||
nbframes = 0;
|
nbframes = 0;
|
||||||
}
|
}
|
||||||
|
@ -51,10 +52,10 @@ static void event_loop(void) {
|
||||||
while (SDL_WaitEvent(&event)) {
|
while (SDL_WaitEvent(&event)) {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case EVENT_DECODER_STOPPED:
|
case EVENT_DECODER_STOPPED:
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Video decoder stopped");
|
LOGD("Video decoder stopped");
|
||||||
return;
|
return;
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "User requested to quit");
|
LOGD("User requested to quit");
|
||||||
return;
|
return;
|
||||||
case EVENT_NEW_FRAME:
|
case EVENT_NEW_FRAME:
|
||||||
if (!screen.has_frame) {
|
if (!screen.has_frame) {
|
||||||
|
@ -167,7 +168,7 @@ SDL_bool scrcpy(const char *serial, Uint16 local_port, Uint16 max_size, Uint32 b
|
||||||
|
|
||||||
event_loop();
|
event_loop();
|
||||||
|
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "quit...");
|
LOGD("quit...");
|
||||||
screen_destroy(&screen);
|
screen_destroy(&screen);
|
||||||
finally_stop_and_join_controller:
|
finally_stop_and_join_controller:
|
||||||
controller_stop(&controller);
|
controller_stop(&controller);
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
|
|
||||||
#include "icon.xpm"
|
#include "icon.xpm"
|
||||||
#include "lockutil.h"
|
#include "lockutil.h"
|
||||||
|
#include "log.h"
|
||||||
#include "tinyxpm.h"
|
#include "tinyxpm.h"
|
||||||
|
|
||||||
#define DISPLAY_MARGINS 96
|
#define DISPLAY_MARGINS 96
|
||||||
|
|
||||||
SDL_bool sdl_init_and_configure(void) {
|
SDL_bool sdl_init_and_configure(void) {
|
||||||
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());
|
LOGC("Could not initialize SDL: %s", SDL_GetError());
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +20,13 @@ SDL_bool sdl_init_and_configure(void) {
|
||||||
|
|
||||||
// Bilinear resizing
|
// Bilinear resizing
|
||||||
if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
|
if (!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)
|
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
||||||
// Handle a click to gain focus as any other click
|
// Handle a click to gain focus as any other click
|
||||||
if (!SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1")) {
|
if (!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
|
#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))
|
# define GET_DISPLAY_BOUNDS(i, r) SDL_GetDisplayBounds((i), (r))
|
||||||
#endif
|
#endif
|
||||||
if (GET_DISPLAY_BOUNDS(0, &rect)) {
|
if (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;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,37 +138,37 @@ SDL_bool screen_init_rendering(struct screen *screen, const char *device_name, s
|
||||||
screen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
screen->window = SDL_CreateWindow(device_name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
window_size.width, window_size.height, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
window_size.width, window_size.height, SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE);
|
||||||
if (!screen->window) {
|
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;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
screen->renderer = SDL_CreateRenderer(screen->window, -1, SDL_RENDERER_ACCELERATED);
|
screen->renderer = SDL_CreateRenderer(screen->window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
if (!screen->renderer) {
|
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);
|
screen_destroy(screen);
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_RenderSetLogicalSize(screen->renderer, frame_size.width, frame_size.height)) {
|
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);
|
screen_destroy(screen);
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface *icon = read_xpm(icon_xpm);
|
SDL_Surface *icon = read_xpm(icon_xpm);
|
||||||
if (!icon) {
|
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);
|
screen_destroy(screen);
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
SDL_SetWindowIcon(screen->window, icon);
|
SDL_SetWindowIcon(screen->window, icon);
|
||||||
SDL_FreeSurface(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,
|
screen->texture = SDL_CreateTexture(screen->renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
|
||||||
frame_size.width, frame_size.height);
|
frame_size.width, frame_size.height);
|
||||||
if (!screen->texture) {
|
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);
|
screen_destroy(screen);
|
||||||
return SDL_FALSE;
|
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) {
|
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 (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)) {
|
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;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,12 +214,12 @@ static SDL_bool prepare_for_frame(struct screen *screen, struct size new_frame_s
|
||||||
|
|
||||||
screen->frame_size = new_frame_size;
|
screen->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->frame_size.width, screen->frame_size.height);
|
||||||
screen->texture = SDL_CreateTexture(screen->renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
|
screen->texture = SDL_CreateTexture(screen->renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING,
|
||||||
new_frame_size.width, new_frame_size.height);
|
new_frame_size.width, new_frame_size.height);
|
||||||
if (!screen->texture) {
|
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;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,7 +263,7 @@ void screen_switch_fullscreen(struct screen *screen) {
|
||||||
}
|
}
|
||||||
Uint32 new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
Uint32 new_mode = screen->fullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
if (SDL_SetWindowFullscreen(screen->window, new_mode)) {
|
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;
|
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_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);
|
screen_render(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,13 +281,13 @@ void screen_resize_to_fit(struct screen *screen) {
|
||||||
if (!screen->fullscreen) {
|
if (!screen->fullscreen) {
|
||||||
struct size optimal_size = get_optimal_window_size(screen, screen->frame_size);
|
struct size optimal_size = get_optimal_window_size(screen, screen->frame_size);
|
||||||
SDL_SetWindowSize(screen->window, optimal_size.width, optimal_size.height);
|
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) {
|
void screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||||
if (!screen->fullscreen) {
|
if (!screen->fullscreen) {
|
||||||
SDL_SetWindowSize(screen->window, screen->frame_size.width, screen->frame_size.height);
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#include "screencontrol.h"
|
#include "screencontrol.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_log.h>
|
|
||||||
|
|
||||||
#include "convert.h"
|
#include "convert.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
static struct point get_mouse_point(void) {
|
static struct point get_mouse_point(void) {
|
||||||
int x;
|
int x;
|
||||||
|
@ -32,14 +31,14 @@ static void send_keycode(struct controller *controller, enum android_keycode key
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!controller_push_event(controller, &control_event)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send UP event
|
// send UP event
|
||||||
control_event.keycode_event.action = AKEY_EVENT_ACTION_UP;
|
control_event.keycode_event.action = AKEY_EVENT_ACTION_UP;
|
||||||
if (!controller_push_event(controller, &control_event)) {
|
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)) {
|
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);
|
strncpy(control_event.text_event.text, event->text, TEXT_MAX_LENGTH);
|
||||||
control_event.text_event.text[TEXT_MAX_LENGTH] = '\0';
|
control_event.text_event.text[TEXT_MAX_LENGTH] = '\0';
|
||||||
if (!controller_push_event(controller, &control_event)) {
|
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;
|
struct control_event control_event;
|
||||||
if (input_key_from_sdl_to_android(event, &control_event)) {
|
if (input_key_from_sdl_to_android(event, &control_event)) {
|
||||||
if (!controller_push_event(controller, &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;
|
struct control_event control_event;
|
||||||
if (mouse_motion_from_sdl_to_android(event, screen->frame_size, &control_event)) {
|
if (mouse_motion_from_sdl_to_android(event, screen->frame_size, &control_event)) {
|
||||||
if (!controller_push_event(controller, &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;
|
struct control_event control_event;
|
||||||
if (mouse_button_from_sdl_to_android(event, screen->frame_size, &control_event)) {
|
if (mouse_button_from_sdl_to_android(event, screen->frame_size, &control_event)) {
|
||||||
if (!controller_push_event(controller, &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;
|
struct control_event control_event;
|
||||||
if (mouse_wheel_from_sdl_to_android(event, position, &control_event)) {
|
if (mouse_wheel_from_sdl_to_android(event, position, &control_event)) {
|
||||||
if (!controller_push_event(controller, &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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_log.h>
|
|
||||||
#include <SDL2/SDL_net.h>
|
#include <SDL2/SDL_net.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
#include "netutil.h"
|
#include "netutil.h"
|
||||||
|
|
||||||
#define SOCKET_NAME "scrcpy"
|
#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) {
|
static void terminate_server(process_t server) {
|
||||||
if (!cmd_terminate(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_po
|
||||||
|
|
||||||
server->server_socket = listen_on_port(local_port);
|
server->server_socket = listen_on_port(local_port);
|
||||||
if (!server->server_socket) {
|
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);
|
disable_tunnel(serial);
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../../command.h"
|
#include "../../command.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_log.h>
|
#include "../../log.h"
|
||||||
#include "../../strutil.h"
|
#include "../../strutil.h"
|
||||||
|
|
||||||
HANDLE cmd_execute(const char *path, const char *const argv[]) {
|
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];
|
char cmd[256];
|
||||||
size_t ret = xstrjoin(cmd, argv, ' ', sizeof(cmd));
|
size_t ret = xstrjoin(cmd, argv, ' ', sizeof(cmd));
|
||||||
if (ret >= 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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
struct index {
|
struct index {
|
||||||
char c;
|
char c;
|
||||||
Uint32 color;
|
Uint32 color;
|
||||||
|
@ -69,7 +71,7 @@ SDL_Surface *read_xpm(char *xpm[]) {
|
||||||
// parse image
|
// parse image
|
||||||
Uint32 *pixels = SDL_malloc(4 * width * height);
|
Uint32 *pixels = SDL_malloc(4 * width * height);
|
||||||
if (!pixels) {
|
if (!pixels) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate icon memory");
|
LOGE("Could not allocate icon memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
|
|
Loading…
Reference in a new issue