2021-01-08 19:24:51 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-06-19 22:04:06 +02:00
|
|
|
#include <assert.h>
|
2019-03-02 23:52:22 +01:00
|
|
|
#include <stdbool.h>
|
2018-01-23 16:32:29 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2021-04-04 00:10:44 +02:00
|
|
|
#ifdef HAVE_V4L2
|
|
|
|
# include <libavdevice/avdevice.h>
|
|
|
|
#endif
|
2019-03-27 19:37:44 +01:00
|
|
|
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
2018-01-23 16:32:29 +01:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
2019-12-08 21:35:19 +01:00
|
|
|
#include "cli.h"
|
2021-10-27 18:43:47 +02:00
|
|
|
#include "options.h"
|
|
|
|
#include "scrcpy.h"
|
2022-01-22 11:09:41 +01:00
|
|
|
#include "usb/scrcpy_otg.h"
|
2019-11-24 11:53:00 +01:00
|
|
|
#include "util/log.h"
|
2023-02-27 20:03:04 +01:00
|
|
|
#include "util/net.h"
|
2022-02-08 20:59:38 +01:00
|
|
|
#include "version.h"
|
2018-02-07 15:01:19 +01:00
|
|
|
|
2023-02-27 20:03:04 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include "util/str.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-02 20:09:56 +01:00
|
|
|
int
|
2022-10-23 14:15:25 +08:00
|
|
|
main_scrcpy(int argc, char *argv[]) {
|
|
|
|
#ifdef _WIN32
|
2018-03-13 10:20:09 +01:00
|
|
|
// 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-09 21:53:38 +01:00
|
|
|
|
2021-11-19 09:14:38 +01:00
|
|
|
printf("scrcpy " SCRCPY_VERSION
|
|
|
|
" <https://github.com/Genymobile/scrcpy>\n");
|
|
|
|
|
2019-12-08 21:35:19 +01:00
|
|
|
struct scrcpy_cli_args args = {
|
2021-10-27 18:43:47 +02:00
|
|
|
.opts = scrcpy_options_default,
|
2019-03-02 23:52:22 +01:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
2018-01-23 16:32:29 +01:00
|
|
|
};
|
2019-11-06 22:06:54 +01:00
|
|
|
|
2020-05-24 21:51:40 +02:00
|
|
|
#ifndef NDEBUG
|
|
|
|
args.opts.log_level = SC_LOG_LEVEL_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
2019-12-08 21:35:19 +01:00
|
|
|
if (!scrcpy_parse_args(&args, argc, argv)) {
|
2022-03-05 15:47:58 +01:00
|
|
|
return SCRCPY_EXIT_FAILURE;
|
2018-01-23 16:32:29 +01:00
|
|
|
}
|
|
|
|
|
2021-06-20 12:46:41 +02:00
|
|
|
sc_set_log_level(args.opts.log_level);
|
2020-05-24 21:51:40 +02:00
|
|
|
|
2018-02-01 11:44:09 +01:00
|
|
|
if (args.help) {
|
2019-12-08 21:35:19 +01:00
|
|
|
scrcpy_print_usage(argv[0]);
|
2022-03-05 15:47:58 +01:00
|
|
|
return SCRCPY_EXIT_SUCCESS;
|
2018-02-01 11:44:09 +01:00
|
|
|
}
|
|
|
|
|
2018-02-07 12:37:53 +01:00
|
|
|
if (args.version) {
|
2022-02-08 20:59:38 +01:00
|
|
|
scrcpy_print_version();
|
2022-03-05 15:47:58 +01:00
|
|
|
return SCRCPY_EXIT_SUCCESS;
|
2018-02-07 12:37:53 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 15:04:32 +01:00
|
|
|
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
2018-01-23 16:32:29 +01:00
|
|
|
av_register_all();
|
2018-08-09 18:18:22 +02:00
|
|
|
#endif
|
2018-01-23 16:32:29 +01:00
|
|
|
|
2021-04-04 00:10:44 +02:00
|
|
|
#ifdef HAVE_V4L2
|
|
|
|
if (args.opts.v4l2_device) {
|
|
|
|
avdevice_register_all();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-02-27 20:03:04 +01:00
|
|
|
if (!net_init()) {
|
2022-03-05 15:47:58 +01:00
|
|
|
return SCRCPY_EXIT_FAILURE;
|
2018-01-23 16:32:29 +01:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:49:42 +01:00
|
|
|
sc_log_configure();
|
|
|
|
|
2022-01-22 11:09:41 +01:00
|
|
|
#ifdef HAVE_USB
|
2022-03-05 15:47:58 +01:00
|
|
|
enum scrcpy_exit_code ret = args.opts.otg ? scrcpy_otg(&args.opts)
|
|
|
|
: scrcpy(&args.opts);
|
2022-01-22 11:09:41 +01:00
|
|
|
#else
|
2022-03-05 15:47:58 +01:00
|
|
|
enum scrcpy_exit_code ret = scrcpy(&args.opts);
|
2022-01-22 11:09:41 +01:00
|
|
|
#endif
|
2018-01-23 16:32:29 +01:00
|
|
|
|
2022-03-05 15:47:58 +01:00
|
|
|
return ret;
|
2018-01-23 16:32:29 +01:00
|
|
|
}
|
2022-10-23 14:15:25 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
#ifndef _WIN32
|
|
|
|
return main_scrcpy(argc, argv);
|
|
|
|
#else
|
|
|
|
(void) argc;
|
|
|
|
(void) argv;
|
|
|
|
int wargc;
|
|
|
|
wchar_t **wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
|
|
|
|
if (!wargv) {
|
|
|
|
LOG_OOM();
|
|
|
|
return SCRCPY_EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
char **argv_utf8 = malloc((wargc + 1) * sizeof(*argv_utf8));
|
|
|
|
if (!argv_utf8) {
|
|
|
|
LOG_OOM();
|
|
|
|
LocalFree(wargv);
|
|
|
|
return SCRCPY_EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
argv_utf8[wargc] = NULL;
|
|
|
|
|
|
|
|
for (int i = 0; i < wargc; ++i) {
|
|
|
|
argv_utf8[i] = sc_str_from_wchars(wargv[i]);
|
|
|
|
if (!argv_utf8[i]) {
|
|
|
|
LOG_OOM();
|
|
|
|
for (int j = 0; j < i; ++j) {
|
|
|
|
free(argv_utf8[j]);
|
|
|
|
}
|
|
|
|
LocalFree(wargv);
|
|
|
|
free(argv_utf8);
|
|
|
|
return SCRCPY_EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalFree(wargv);
|
|
|
|
|
|
|
|
int ret = main_scrcpy(wargc, argv_utf8);
|
|
|
|
|
|
|
|
for (int i = 0; i < wargc; ++i) {
|
|
|
|
free(argv_utf8[i]);
|
|
|
|
}
|
|
|
|
free(argv_utf8);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
#endif
|
|
|
|
}
|