-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cc
57 lines (48 loc) · 1.4 KB
/
main.cc
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
#include "StreamServer.h"
#include "BaseCamera.h"
#include <signal.h>
// usb camera id (default camera is -1)
#define DEFAULT_CAMERA -1
// #define DEFAULT_CAMERA "http://192.168.1.20:8080/video"
std::vector<std::shared_ptr<iit::StreamServer>> server_list;
//! handle ctrl+c
inline void signal_intrupt_handle(int var)
{
// Server->stop();
for (auto &server : server_list)
{
server->stop();
}
}
int main(int argc, char const *argv[])
{
// handle intrupt signal to elegantly close server.
signal(SIGINT, signal_intrupt_handle);
// vector of cameras
std::vector<std::shared_ptr<BaseCamera>> camera_list;
// if no args are passed, use default usb camera
if (argc < 2)
{
camera_list.push_back(std::make_shared<BaseCamera>(DEFAULT_CAMERA, 640,480, false));
}
else
{
// add camera for each index passed in command line argument
for (int i = 1; i < argc; i++)
{
camera_list.push_back(std::make_shared<BaseCamera>(atoi(argv[i]),640,480, false));
}
}
// create server for each camera and bind it to port 8080,8081 ... so on
int port = 8080;
for (auto &camera : camera_list)
{
server_list.push_back(std::make_shared<iit::StreamServer>(port++, camera));
}
// wait for server to close properly
for (auto &server : server_list)
{
server->start();
}
return 0;
}