d39161f753
It allows to send the video stream to /dev/videoN, so that it can be captured (like a webcam) by any v4l2-capable tool. PR #2232 <https://github.com/Genymobile/scrcpy/pull/2232> PR #2233 <https://github.com/Genymobile/scrcpy/pull/2233> PR #2268 <https://github.com/Genymobile/scrcpy/pull/2268> Co-authored-by: Romain Vimont <rom@rom1v.com>
116 lines
3.2 KiB
C
116 lines
3.2 KiB
C
#include "scrcpy.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <unistd.h>
|
|
#include <libavformat/avformat.h>
|
|
#ifdef HAVE_V4L2
|
|
# include <libavdevice/avdevice.h>
|
|
#endif
|
|
#define SDL_MAIN_HANDLED // avoid link error on Linux Windows Subsystem
|
|
#include <SDL2/SDL.h>
|
|
|
|
#include "cli.h"
|
|
#include "util/log.h"
|
|
|
|
static void
|
|
print_version(void) {
|
|
fprintf(stderr, "scrcpy %s\n\n", SCRCPY_VERSION);
|
|
|
|
fprintf(stderr, "dependencies:\n");
|
|
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);
|
|
#ifdef HAVE_V4L2
|
|
fprintf(stderr, " - libavdevice %d.%d.%d\n", LIBAVDEVICE_VERSION_MAJOR,
|
|
LIBAVDEVICE_VERSION_MINOR,
|
|
LIBAVDEVICE_VERSION_MICRO);
|
|
#endif
|
|
}
|
|
|
|
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");
|
|
return SDL_LOG_PRIORITY_INFO;
|
|
}
|
|
}
|
|
|
|
|
|
int
|
|
main(int argc, char *argv[]) {
|
|
#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
|
|
|
|
struct scrcpy_cli_args args = {
|
|
.opts = SCRCPY_OPTIONS_DEFAULT,
|
|
.help = false,
|
|
.version = false,
|
|
};
|
|
|
|
#ifndef NDEBUG
|
|
args.opts.log_level = SC_LOG_LEVEL_DEBUG;
|
|
#endif
|
|
|
|
if (!scrcpy_parse_args(&args, argc, argv)) {
|
|
return 1;
|
|
}
|
|
|
|
SDL_LogPriority sdl_log = convert_log_level_to_sdl(args.opts.log_level);
|
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, sdl_log);
|
|
|
|
if (args.help) {
|
|
scrcpy_print_usage(argv[0]);
|
|
return 0;
|
|
}
|
|
|
|
if (args.version) {
|
|
print_version();
|
|
return 0;
|
|
}
|
|
|
|
LOGI("scrcpy " SCRCPY_VERSION " <https://github.com/Genymobile/scrcpy>");
|
|
|
|
#ifdef SCRCPY_LAVF_REQUIRES_REGISTER_ALL
|
|
av_register_all();
|
|
#endif
|
|
|
|
#ifdef HAVE_V4L2
|
|
if (args.opts.v4l2_device) {
|
|
avdevice_register_all();
|
|
}
|
|
#endif
|
|
|
|
if (avformat_network_init()) {
|
|
return 1;
|
|
}
|
|
|
|
int res = scrcpy(&args.opts) ? 0 : 1;
|
|
|
|
avformat_network_deinit(); // ignore failure
|
|
|
|
return res;
|
|
}
|