2021-01-08 18:24:51 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-06-19 20:04:06 +00:00
|
|
|
#include <assert.h>
|
2019-03-02 22:52:22 +00:00
|
|
|
#include <stdbool.h>
|
2018-01-23 15:32:29 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <libavformat/avformat.h>
|
2021-04-03 22:10:44 +00:00
|
|
|
#ifdef HAVE_V4L2
|
|
|
|
# include <libavdevice/avdevice.h>
|
|
|
|
#endif
|
2019-03-27 18:37:44 +00:00
|
|
|
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
2018-01-23 15:32:29 +00:00
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
2019-12-08 20:35:19 +00:00
|
|
|
#include "cli.h"
|
2021-10-27 16:43:47 +00:00
|
|
|
#include "options.h"
|
|
|
|
#include "scrcpy.h"
|
2019-11-24 10:53:00 +00:00
|
|
|
#include "util/log.h"
|
2018-02-01 10:44:09 +00:00
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
static void
|
|
|
|
print_version(void) {
|
2022-01-27 20:12:46 +00:00
|
|
|
fprintf(stderr, "\ndependencies:\n");
|
2019-03-02 19:09:56 +00: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);
|
2021-04-03 22:10:44 +00:00
|
|
|
#ifdef HAVE_V4L2
|
|
|
|
fprintf(stderr, " - libavdevice %d.%d.%d\n", LIBAVDEVICE_VERSION_MAJOR,
|
|
|
|
LIBAVDEVICE_VERSION_MINOR,
|
|
|
|
LIBAVDEVICE_VERSION_MICRO);
|
|
|
|
#endif
|
2018-02-07 14:01:19 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 19:09:56 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[]) {
|
2018-03-13 09:20:09 +00: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-09 20:53:38 +00:00
|
|
|
|
2021-11-19 08:14:38 +00:00
|
|
|
printf("scrcpy " SCRCPY_VERSION
|
|
|
|
" <https://github.com/Genymobile/scrcpy>\n");
|
|
|
|
|
2019-12-08 20:35:19 +00:00
|
|
|
struct scrcpy_cli_args args = {
|
2021-10-27 16:43:47 +00:00
|
|
|
.opts = scrcpy_options_default,
|
2019-03-02 22:52:22 +00:00
|
|
|
.help = false,
|
|
|
|
.version = false,
|
2018-01-23 15:32:29 +00:00
|
|
|
};
|
2019-11-06 21:06:54 +00:00
|
|
|
|
2020-05-24 19:51:40 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
args.opts.log_level = SC_LOG_LEVEL_DEBUG;
|
|
|
|
#endif
|
|
|
|
|
2019-12-08 20:35:19 +00:00
|
|
|
if (!scrcpy_parse_args(&args, argc, argv)) {
|
2018-01-23 15:32:29 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-06-20 10:46:41 +00:00
|
|
|
sc_set_log_level(args.opts.log_level);
|
2020-05-24 19:51:40 +00:00
|
|
|
|
2018-02-01 10:44:09 +00:00
|
|
|
if (args.help) {
|
2019-12-08 20:35:19 +00:00
|
|
|
scrcpy_print_usage(argv[0]);
|
2018-02-01 10:44:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-07 11:37:53 +00:00
|
|
|
if (args.version) {
|
2018-02-07 14:01:19 +00:00
|
|
|
print_version();
|
2018-02-07 11:37:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-16 14:04:32 +00:00
|
|
|
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
2018-01-23 15:32:29 +00:00
|
|
|
av_register_all();
|
2018-08-09 16:18:22 +00:00
|
|
|
#endif
|
2018-01-23 15:32:29 +00:00
|
|
|
|
2021-04-03 22:10:44 +00:00
|
|
|
#ifdef HAVE_V4L2
|
|
|
|
if (args.opts.v4l2_device) {
|
|
|
|
avdevice_register_all();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-23 15:32:29 +00:00
|
|
|
if (avformat_network_init()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 21:06:54 +00:00
|
|
|
int res = scrcpy(&args.opts) ? 0 : 1;
|
2018-01-23 15:32:29 +00:00
|
|
|
|
|
|
|
avformat_network_deinit(); // ignore failure
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|