2017-12-12 22:12:07 +08:00
|
|
|
#include "screen.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
|
|
|
#define DEFAULT_LOCAL_PORT 27183
|
|
|
|
|
|
|
|
struct args {
|
|
|
|
const char *serial;
|
|
|
|
Uint16 port;
|
|
|
|
};
|
|
|
|
|
|
|
|
int parse_args(struct args *args, int argc, char *argv[]) {
|
|
|
|
int c;
|
|
|
|
while ((c = getopt(argc, argv, "p:")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'p': {
|
|
|
|
char *endptr;
|
|
|
|
long int value = strtol(optarg, &endptr, 0);
|
|
|
|
if (*optarg == '\0' || *endptr != '\0') {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid port: %s\n", optarg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (value & ~0xffff) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Port out of range: %ld\n", value);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
args->port = (Uint16) value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// getopt prints the error message on stderr
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = optind;
|
|
|
|
if (index < argc) {
|
|
|
|
args->serial = argv[index++];
|
|
|
|
}
|
|
|
|
if (index < argc) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unexpected additional argument: %s\n", argv[index]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
av_register_all();
|
|
|
|
avformat_network_init();
|
|
|
|
SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG);
|
|
|
|
|
|
|
|
struct args args = {
|
|
|
|
.serial = NULL,
|
|
|
|
.port = DEFAULT_LOCAL_PORT,
|
|
|
|
};
|
|
|
|
if (parse_args(&args, argc, argv)) {
|
2017-12-15 18:27:11 +08:00
|
|
|
return 1;
|
2017-12-12 22:12:07 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 18:27:11 +08:00
|
|
|
return show_screen(args.serial, args.port) ? 0 : 1;
|
2017-12-12 22:12:07 +08:00
|
|
|
}
|