2018-01-23 23:32:29 +08:00
|
|
|
#include "scrcpy.h"
|
|
|
|
|
2020-06-20 04:04:06 +08:00
|
|
|
#include <assert.h>
|
2019-03-03 06:52:22 +08:00
|
|
|
#include <stdbool.h>
|
2018-01-23 23:32:29 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2019-03-28 02:37:44 +08:00
|
|
|
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
2018-01-23 23:32:29 +08:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
2021-01-09 02:18:02 +08:00
|
|
|
#include "common.h"
|
2019-12-09 04:35:19 +08:00
|
|
|
#include "cli.h"
|
2019-11-24 18:53:00 +08:00
|
|
|
#include "util/log.h"
|
2018-02-01 18:44:09 +08:00
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
static void
|
|
|
|
print_version(void) {
|
2018-11-12 21:09:11 +08:00
|
|
|
fprintf(stderr, "scrcpy %s\n\n", SCRCPY_VERSION);
|
2018-02-07 22:01:19 +08:00
|
|
|
|
|
|
|
fprintf(stderr, "dependencies:\n");
|
2019-03-03 03:09:56 +08:00
|
|
|
fprintf(stderr, " - SDL %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION,
|
|
|
|
SDL_PATCHLEVEL);
|
|
|
|
fprintf(stderr, " - libavcodec %d.%d.%d\n", LIBAVCODEC_VERSION_MAJOR,
|
|
|
|
LIBAVCODEC_VERSION_MINOR,
|
|
|
|
LIBAVCODEC_VERSION_MICRO);
|
|
|
|
fprintf(stderr, " - libavformat %d.%d.%d\n", LIBAVFORMAT_VERSION_MAJOR,
|
|
|
|
LIBAVFORMAT_VERSION_MINOR,
|
|
|
|
LIBAVFORMAT_VERSION_MICRO);
|
|
|
|
fprintf(stderr, " - libavutil %d.%d.%d\n", LIBAVUTIL_VERSION_MAJOR,
|
|
|
|
LIBAVUTIL_VERSION_MINOR,
|
|
|
|
LIBAVUTIL_VERSION_MICRO);
|
2018-02-07 22:01:19 +08:00
|
|
|
}
|
|
|
|
|
2020-05-25 03:51:40 +08:00
|
|
|
static SDL_LogPriority
|
|
|
|
convert_log_level_to_sdl(enum sc_log_level level) {
|
|
|
|
switch (level) {
|
|
|
|
case SC_LOG_LEVEL_DEBUG:
|
|
|
|
return SDL_LOG_PRIORITY_DEBUG;
|
|
|
|
case SC_LOG_LEVEL_INFO:
|
|
|
|
return SDL_LOG_PRIORITY_INFO;
|
|
|
|
case SC_LOG_LEVEL_WARN:
|
|
|
|
return SDL_LOG_PRIORITY_WARN;
|
|
|
|
case SC_LOG_LEVEL_ERROR:
|
|
|
|
return SDL_LOG_PRIORITY_ERROR;
|
|
|
|
default:
|
|
|
|
assert(!"unexpected log level");
|
2020-06-03 00:18:58 +08:00
|
|
|
return SDL_LOG_PRIORITY_INFO;
|
2020-05-25 03:51:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-03 03:09:56 +08:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
2018-03-13 17:20:09 +08:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
// disable buffering, we want logs immediately
|
|
|
|
// even line buffering (setvbuf() with mode _IOLBF) is not sufficient
|
|
|
|
setbuf(stdout, NULL);
|
|
|
|
setbuf(stderr, NULL);
|
|
|
|
#endif
|
2019-12-10 04:53:38 +08:00
|
|
|
|
2019-12-09 04:35:19 +08:00
|
|
|
struct scrcpy_cli_args args = {
|
2019-11-07 05:06:54 +08:00
|
|
|
.opts = SCRCPY_OPTIONS_DEFAULT,
|
2019-03-03 06:52:22 +08:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
2018-01-23 23:32:29 +08:00
|
|
|
};
|
2019-11-07 05:06:54 +08:00
|
|
|
|
2020-05-25 03:51:40 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
args.opts.log_level = SC_LOG_LEVEL_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
2019-12-09 04:35:19 +08:00
|
|
|
if (!scrcpy_parse_args(&args, argc, argv)) {
|
2018-01-23 23:32:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-05-25 03:51:40 +08:00
|
|
|
SDL_LogPriority sdl_log = convert_log_level_to_sdl(args.opts.log_level);
|
2020-06-03 00:21:01 +08:00
|
|
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, sdl_log);
|
2020-05-25 03:51:40 +08:00
|
|
|
|
2018-02-01 18:44:09 +08:00
|
|
|
if (args.help) {
|
2019-12-09 04:35:19 +08:00
|
|
|
scrcpy_print_usage(argv[0]);
|
2018-02-01 18:44:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-07 19:37:53 +08:00
|
|
|
if (args.version) {
|
2018-02-07 22:01:19 +08:00
|
|
|
print_version();
|
2018-02-07 19:37:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-31 07:55:43 +08:00
|
|
|
LOGI("scrcpy " SCRCPY_VERSION " <https://github.com/Genymobile/scrcpy>");
|
|
|
|
|
2019-02-16 22:04:32 +08:00
|
|
|
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
2018-01-23 23:32:29 +08:00
|
|
|
av_register_all();
|
2018-08-10 00:18:22 +08:00
|
|
|
#endif
|
2018-01-23 23:32:29 +08:00
|
|
|
|
|
|
|
if (avformat_network_init()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-07 05:06:54 +08:00
|
|
|
int res = scrcpy(&args.opts) ? 0 : 1;
|
2018-01-23 23:32:29 +08:00
|
|
|
|
|
|
|
avformat_network_deinit(); // ignore failure
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|