diff --git a/app/src/cli.c b/app/src/cli.c index 6a45d430..9e07e912 100644 --- a/app/src/cli.c +++ b/app/src/cli.c @@ -3,10 +3,11 @@ #include #include #include +#include #include #include "config.h" -#include "recorder.h" +#include "scrcpy.h" #include "util/log.h" #include "util/str_util.h" @@ -382,10 +383,10 @@ parse_rotation(const char *s, uint8_t *rotation) { static bool parse_window_position(const char *s, int16_t *position) { // special value for "auto" - static_assert(WINDOW_POSITION_UNDEFINED == -0x8000, "unexpected value"); + static_assert(SC_WINDOW_POSITION_UNDEFINED == -0x8000, "unexpected value"); if (!strcmp(s, "auto")) { - *position = WINDOW_POSITION_UNDEFINED; + *position = SC_WINDOW_POSITION_UNDEFINED; return true; } @@ -414,7 +415,7 @@ parse_window_dimension(const char *s, uint16_t *dimension) { } static bool -parse_port_range(const char *s, struct port_range *port_range) { +parse_port_range(const char *s, struct sc_port_range *port_range) { long values[2]; size_t count = parse_integers_arg(s, 2, values, 0, 0xFFFF, "port"); if (!count) { @@ -480,20 +481,20 @@ parse_log_level(const char *s, enum sc_log_level *log_level) { } static bool -parse_record_format(const char *optarg, enum recorder_format *format) { +parse_record_format(const char *optarg, enum sc_record_format *format) { if (!strcmp(optarg, "mp4")) { - *format = RECORDER_FORMAT_MP4; + *format = SC_RECORD_FORMAT_MP4; return true; } if (!strcmp(optarg, "mkv")) { - *format = RECORDER_FORMAT_MKV; + *format = SC_RECORD_FORMAT_MKV; return true; } LOGE("Unsupported format: %s (expected mp4 or mkv)", optarg); return false; } -static enum recorder_format +static enum sc_record_format guess_record_format(const char *filename) { size_t len = strlen(filename); if (len < 4) { @@ -501,10 +502,10 @@ guess_record_format(const char *filename) { } const char *ext = &filename[len - 4]; if (!strcmp(ext, ".mp4")) { - return RECORDER_FORMAT_MP4; + return SC_RECORD_FORMAT_MP4; } if (!strcmp(ext, ".mkv")) { - return RECORDER_FORMAT_MKV; + return SC_RECORD_FORMAT_MKV; } return 0; } diff --git a/app/src/main.c b/app/src/main.c index 7d7ddb82..202c217c 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -1,5 +1,6 @@ #include "scrcpy.h" +#include #include #include #include diff --git a/app/src/recorder.c b/app/src/recorder.c index 465b24e8..76edbd03 100644 --- a/app/src/recorder.c +++ b/app/src/recorder.c @@ -63,7 +63,7 @@ recorder_queue_clear(struct recorder_queue *queue) { bool recorder_init(struct recorder *recorder, const char *filename, - enum recorder_format format, + enum sc_record_format format, struct size declared_frame_size) { recorder->filename = SDL_strdup(filename); if (!recorder->filename) { @@ -105,10 +105,10 @@ recorder_destroy(struct recorder *recorder) { } static const char * -recorder_get_format_name(enum recorder_format format) { +recorder_get_format_name(enum sc_record_format format) { switch (format) { - case RECORDER_FORMAT_MP4: return "mp4"; - case RECORDER_FORMAT_MKV: return "matroska"; + case SC_RECORD_FORMAT_MP4: return "mp4"; + case SC_RECORD_FORMAT_MKV: return "matroska"; default: return NULL; } } diff --git a/app/src/recorder.h b/app/src/recorder.h index 4f5d526c..bc87a23b 100644 --- a/app/src/recorder.h +++ b/app/src/recorder.h @@ -8,14 +8,9 @@ #include "config.h" #include "common.h" +#include "scrcpy.h" #include "util/queue.h" -enum recorder_format { - RECORDER_FORMAT_AUTO, - RECORDER_FORMAT_MP4, - RECORDER_FORMAT_MKV, -}; - struct record_packet { AVPacket packet; struct record_packet *next; @@ -25,7 +20,7 @@ struct recorder_queue QUEUE(struct record_packet); struct recorder { char *filename; - enum recorder_format format; + enum sc_record_format format; AVFormatContext *ctx; struct size declared_frame_size; bool header_written; @@ -46,7 +41,7 @@ struct recorder { bool recorder_init(struct recorder *recorder, const char *filename, - enum recorder_format format, struct size declared_frame_size); + enum sc_record_format format, struct size declared_frame_size); void recorder_destroy(struct recorder *recorder); diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index cde6c27f..5a88122d 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -8,6 +8,8 @@ #include #ifdef _WIN32 +// not needed here, but winsock2.h must never be included AFTER windows.h +# include # include #endif diff --git a/app/src/scrcpy.h b/app/src/scrcpy.h index f2760152..d7eb2f58 100644 --- a/app/src/scrcpy.h +++ b/app/src/scrcpy.h @@ -2,13 +2,30 @@ #define SCRCPY_H #include +#include #include #include "config.h" -#include "common.h" -#include "input_manager.h" -#include "recorder.h" -#include "util/log.h" + +enum sc_log_level { + SC_LOG_LEVEL_DEBUG, + SC_LOG_LEVEL_INFO, + SC_LOG_LEVEL_WARN, + SC_LOG_LEVEL_ERROR, +}; + +enum sc_record_format { + SC_RECORD_FORMAT_AUTO, + SC_RECORD_FORMAT_MP4, + SC_RECORD_FORMAT_MKV, +}; + +struct sc_port_range { + uint16_t first; + uint16_t last; +}; + +#define SC_WINDOW_POSITION_UNDEFINED (-0x8000) struct scrcpy_options { const char *serial; @@ -19,15 +36,15 @@ struct scrcpy_options { const char *render_driver; const char *codec_options; enum sc_log_level log_level; - enum recorder_format record_format; - struct port_range port_range; + enum sc_record_format record_format; + struct sc_port_range port_range; uint16_t max_size; uint32_t bit_rate; uint16_t max_fps; int8_t lock_video_orientation; uint8_t rotation; - int16_t window_x; // WINDOW_POSITION_UNDEFINED for "auto" - int16_t window_y; // WINDOW_POSITION_UNDEFINED for "auto" + int16_t window_x; // SC_WINDOW_POSITION_UNDEFINED for "auto" + int16_t window_y; // SC_WINDOW_POSITION_UNDEFINED for "auto" uint16_t window_width; uint16_t window_height; uint16_t display_id; @@ -55,7 +72,7 @@ struct scrcpy_options { .render_driver = NULL, \ .codec_options = NULL, \ .log_level = SC_LOG_LEVEL_INFO, \ - .record_format = RECORDER_FORMAT_AUTO, \ + .record_format = SC_RECORD_FORMAT_AUTO, \ .port_range = { \ .first = DEFAULT_LOCAL_PORT_RANGE_FIRST, \ .last = DEFAULT_LOCAL_PORT_RANGE_LAST, \ @@ -65,8 +82,8 @@ struct scrcpy_options { .max_fps = 0, \ .lock_video_orientation = DEFAULT_LOCK_VIDEO_ORIENTATION, \ .rotation = 0, \ - .window_x = WINDOW_POSITION_UNDEFINED, \ - .window_y = WINDOW_POSITION_UNDEFINED, \ + .window_x = SC_WINDOW_POSITION_UNDEFINED, \ + .window_y = SC_WINDOW_POSITION_UNDEFINED, \ .window_width = 0, \ .window_height = 0, \ .display_id = 0, \ diff --git a/app/src/screen.c b/app/src/screen.c index 66a1163b..4cee61b0 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -8,6 +8,7 @@ #include "common.h" #include "compat.h" #include "icon.xpm" +#include "scrcpy.h" #include "tiny_xpm.h" #include "video_buffer.h" #include "util/lock.h" @@ -257,9 +258,9 @@ screen_init_rendering(struct screen *screen, const char *window_title, window_flags |= SDL_WINDOW_BORDERLESS; } - int x = window_x != WINDOW_POSITION_UNDEFINED + int x = window_x != SC_WINDOW_POSITION_UNDEFINED ? window_x : (int) SDL_WINDOWPOS_UNDEFINED; - int y = window_y != WINDOW_POSITION_UNDEFINED + int y = window_y != SC_WINDOW_POSITION_UNDEFINED ? window_y : (int) SDL_WINDOWPOS_UNDEFINED; screen->window = SDL_CreateWindow(window_title, x, y, window_size.width, window_size.height, diff --git a/app/src/screen.h b/app/src/screen.h index aa6218f7..4c3a593e 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -9,8 +9,6 @@ #include "common.h" #include "opengl.h" -#define WINDOW_POSITION_UNDEFINED (-0x8000) - struct video_buffer; struct screen { @@ -76,7 +74,7 @@ void screen_init(struct screen *screen); // initialize screen, create window, renderer and texture (window is hidden) -// window_x and window_y accept WINDOW_POSITION_UNDEFINED +// window_x and window_y accept SC_WINDOW_POSITION_UNDEFINED bool screen_init_rendering(struct screen *screen, const char *window_title, struct size frame_size, bool always_on_top, diff --git a/app/src/server.c b/app/src/server.c index fb498d63..05b2cf91 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -143,7 +143,7 @@ listen_on_port(uint16_t port) { static bool enable_tunnel_reverse_any_port(struct server *server, - struct port_range port_range) { + struct sc_port_range port_range) { uint16_t port = port_range.first; for (;;) { if (!enable_tunnel_reverse(server->serial, port)) { @@ -189,7 +189,7 @@ enable_tunnel_reverse_any_port(struct server *server, static bool enable_tunnel_forward_any_port(struct server *server, - struct port_range port_range) { + struct sc_port_range port_range) { server->tunnel_forward = true; uint16_t port = port_range.first; for (;;) { @@ -217,7 +217,7 @@ enable_tunnel_forward_any_port(struct server *server, } static bool -enable_tunnel_any_port(struct server *server, struct port_range port_range, +enable_tunnel_any_port(struct server *server, struct sc_port_range port_range, bool force_adb_forward) { if (!force_adb_forward) { // Attempt to use "adb reverse" diff --git a/app/src/server.h b/app/src/server.h index 2215d817..254afe30 100644 --- a/app/src/server.h +++ b/app/src/server.h @@ -9,6 +9,7 @@ #include "config.h" #include "command.h" #include "common.h" +#include "scrcpy.h" #include "util/log.h" #include "util/net.h" @@ -20,7 +21,7 @@ struct server { socket_t server_socket; // only used if !tunnel_forward socket_t video_socket; socket_t control_socket; - struct port_range port_range; + struct sc_port_range port_range; uint16_t local_port; // selected from port_range bool tunnel_enabled; bool tunnel_forward; // use "adb forward" instead of "adb reverse" @@ -47,7 +48,7 @@ struct server_params { enum sc_log_level log_level; const char *crop; const char *codec_options; - struct port_range port_range; + struct sc_port_range port_range; uint16_t max_size; uint32_t bit_rate; uint16_t max_fps; diff --git a/app/src/util/log.h b/app/src/util/log.h index 8c5c7dee..5955c7fb 100644 --- a/app/src/util/log.h +++ b/app/src/util/log.h @@ -3,13 +3,6 @@ #include -enum sc_log_level { - SC_LOG_LEVEL_DEBUG, - SC_LOG_LEVEL_INFO, - SC_LOG_LEVEL_WARN, - SC_LOG_LEVEL_ERROR, -}; - #define LOGV(...) SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__) #define LOGD(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__) #define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__) diff --git a/app/tests/test_cli.c b/app/tests/test_cli.c index 2a1e2607..07974361 100644 --- a/app/tests/test_cli.c +++ b/app/tests/test_cli.c @@ -1,4 +1,5 @@ #include +#include #include "cli.h" #include "common.h" @@ -83,7 +84,7 @@ static void test_options(void) { assert(opts->port_range.last == 1236); assert(!strcmp(opts->push_target, "/sdcard/Movies")); assert(!strcmp(opts->record_filename, "file")); - assert(opts->record_format == RECORDER_FORMAT_MKV); + assert(opts->record_format == SC_RECORD_FORMAT_MKV); assert(opts->render_expired_frames); assert(!strcmp(opts->serial, "0123456789abcdef")); assert(opts->show_touches); @@ -118,7 +119,7 @@ static void test_options2(void) { assert(!opts->control); assert(!opts->display); assert(!strcmp(opts->record_filename, "file.mp4")); - assert(opts->record_format == RECORDER_FORMAT_MP4); + assert(opts->record_format == SC_RECORD_FORMAT_MP4); } int main(void) {