-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
93 lines (79 loc) · 2.31 KB
/
Copy pathmain.cpp
File metadata and controls
93 lines (79 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <v4l2vnc/VNCServer.h>
#include <v4l2vnc/V4L2VNCServer.h>
#include <v4l2vnc/Logging.h>
#include <signal.h>
#include <iostream>
using namespace v4l2vnc;
void printHelpAndExit()
{
std::string_view msg =
"[h] [-i input_device] [-p port] [-l listen_address] [-W capture_width] [-H capture_height] [-n server_name] [-v verbosity]\n"
" -v verbosity - Must be one of 'trace', 'debug', 'info', 'warning', 'error', 'critical'\n";
std::cout << msg;
exit( 0 );
}
int intOrQuite( const char* source, const char* ps )
{
int ret;
if ( auto ec = std::from_chars( source, source + strlen( source ), ret ); ec.ec != std::errc{} )
{
spdlog::critical( ps );
exit( -1 );
}
return ret;
}
// global for interruption handler
static std::shared_ptr<V4L2VNCServer> server;
void on_signal( int sig )
{
if ( server && sig == SIGINT || sig == SIGTERM )
{
logger()->info( "Terminating gracefully..." );
server->stop();
}
}
int main( int argc,char** argv )
{
V4L2VNCServer::Params params;
params.bpp = v4l2vnc::VNCServer::BytesPerPixel::TrueColor;
int c;
while ( ( c = getopt( argc, argv, "i:p:l:W:H:n:v:h" ) ) > 0 )
{
switch ( c )
{
case 'i':
params.inputDevice = optarg;
break;
case 'p':
params.port = intOrQuite( optarg, "Invalid port" );
break;
case 'l':
params.listen = strdup( optarg );
break;
case 'W':
params.width = intOrQuite( optarg, "Invalid width" );
break;
case 'H':
params.height = intOrQuite( optarg, "Invalid height" );
break;
case 'n':
params.desktopName = strdup( optarg );
break;
case 'v':
logger()->set_level( spdlog::level::from_str( optarg ) );
break;
case 'h':
printHelpAndExit();
}
}
server = std::make_shared<V4L2VNCServer>( params );
if ( auto ec = server->init(); ec )
{
spdlog::critical( "Failed to init server: {}", ec.message() );
return -1;
}
signal( SIGINT, on_signal );
signal( SIGTERM, on_signal );
server->run();
return 0;
}