-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (43 loc) · 1.37 KB
/
Copy pathmain.cpp
File metadata and controls
51 lines (43 loc) · 1.37 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
#include "rtp/control_server.h"
#include "rtp/forwarder.h"
#include <csignal>
#include <iostream>
#include <string>
namespace {
volatile std::sig_atomic_t g_stop = 0;
void OnSignal(int) { g_stop = 1; }
} // namespace
int main(int argc, char** argv) {
uint16_t control_port = 9000;
for (int i = 1; i < argc; ++i) {
const std::string a = argv[i];
if ((a == "--control-port" || a == "-p") && i + 1 < argc) {
control_port = static_cast<uint16_t>(std::stoi(argv[++i]));
} else if (a == "--help" || a == "-h") {
std::cout << "Usage: rtp_forwarder [--control-port PORT]\n"
<< " Minimal RTP forwarder + G.711 transcoder.\n"
<< " Control protocol is line-oriented TCP on PORT (default 9000).\n";
return 0;
} else {
std::cerr << "unknown arg: " << a << "\n";
return 2;
}
}
std::signal(SIGINT, OnSignal);
std::signal(SIGTERM, OnSignal);
rtp::RtpForwarder fwd;
rtp::ControlServer ctl(&fwd);
if (!ctl.Start("0.0.0.0", control_port)) {
std::cerr << "failed to bind control port " << control_port << "\n";
return 1;
}
std::cout << "rtp_forwarder control=0.0.0.0:" << control_port << "\n"
<< "waiting for room commands from the Go service...\n";
while (!g_stop) {
ctl.ServeOnce(50);
fwd.Poll(50);
}
ctl.Stop();
std::cout << "stopped\n" << fwd.Dump() << "\n";
return 0;
}