VideoSender/options.h

78 lines
1.9 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <argp.h>
#include <iostream>
#include <filesystem>
const inline char *argp_program_version = "VideoSender";
const inline char *argp_program_bug_address = "<carl@uvos.xyz>";
static char doc[] = "Application that sends video4linux streams over the network with minimal latency";
static char args_doc[] = "";
static struct argp_option options[] =
{
{"device", 'd', "[PATH]", 0, "device to use" },
{"width", 'x', "[NUMBER]", 0, "Width at witch to capture frames from the camera"},
{"height", 'y', "[NUMBER]", 0, "Heigt at witch to capture frames from the camera"},
{"overlay", 'o', "[PATH]", 0, "Overlay file to use"},
{"mjpeg", 'j', 0, 0, "Use mjpeg as the capture format for the camera"},
{"addr", 'a', "[IP_ADDRESS]",0, "Ip address of the remote machine"},
{"port", 'p', "[PORT]", 0, "Port of the remote machine"},
{ 0 }
};
struct Config
{
std::string url = "10.0.0.1";
int port = 9874;
std::filesystem::path device = "/dev/video0";
int Xres = 640;
int Yres = 480;
std::filesystem::path overlay;
bool mjpeg = false;
};
static error_t parse_opt (int key, char *arg, struct argp_state *state)
{
Config *config = reinterpret_cast<Config*>(state->input);
try
{
switch (key)
{
case 'd':
config->device = arg;
break;
case 'x':
config->Xres = std::stoi(arg);
break;
case 'y':
config->Yres = std::stoi(arg);
break;
case 'o':
config->overlay = arg;
break;
case 'j':
config->mjpeg = true;
break;
case 'a':
config->url = arg;
break;
case 'p':
config->port = std::stoi(arg);
break;
default:
return ARGP_ERR_UNKNOWN;
}
}
catch(const std::invalid_argument& ex)
{
std::cout<<arg<<" passed for argument -"<<static_cast<char>(key)<<" is not a valid number.\n";
return ARGP_KEY_ERROR;
}
return 0;
}
static struct argp argp = {options, parse_opt, args_doc, doc};