-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
170 lines (154 loc) · 5.23 KB
/
main.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "Config.h"
#include "http/WhipClient.h"
#include "Logger.h"
#include "Pipeline.h"
#include <chrono>
#include <csignal>
#include <cstdint>
#include <getopt.h>
#include <glib-2.0/glib.h>
namespace
{
::option longOptions[] = {{"udpSourceAddress", required_argument, nullptr, 'a'},
{"udpSourcePort", required_argument, nullptr, 'p'},
{"whipEndpointUrl", required_argument, nullptr, 'u'},
{"whipEndpointAuthKey", required_argument, nullptr, 'k'},
{"udpSourceQueueMinTime", required_argument, nullptr, 'd'},
{"restreamAddress", required_argument, nullptr, 'r'},
{"restreamPort", required_argument, nullptr, 'o'},
{"showTimer", no_argument, nullptr, 't'},
{"srtTransport", no_argument, nullptr, 's'},
{"tsDemuxLatency", required_argument, nullptr, 0},
{"jitterBufferLatency", required_argument, nullptr, 0},
{"srtSourceLatency", required_argument, nullptr, 0},
{"h264EncodeBitrate", required_argument, nullptr, 'b'},
{"no-audio", no_argument, nullptr, 0},
{"no-video", no_argument, nullptr, 0},
{"bypass-audio", no_argument, nullptr, 0},
{"bypass-video", no_argument, nullptr, 0},
{nullptr, no_argument, nullptr, 0}};
const auto shortOptions = "a:p:u:k:d:r:o:b:ts";
const char* usageString = "Usage: whip-mpegts [OPTION]\n"
" -a, --udpSourceAddress STRING\n"
" -p, --udpSourcePort INT\n"
" -u, --whipEndpointUrl STRING\n"
" -k, --whipEndpointAuthKey STRING\n"
" -d, --udpSourceQueueMinTime INT ms\n"
" -r, --restreamAddress STRING\n"
" -o, --restreamPort INT\n"
" -b, --h264EncodeBitrate INT (Kb)\n"
" -t, --showTimer\n"
" -s, --srtTransport\n"
" --tsDemuxLatency INT\n"
" --jitterBufferLatency INT\n"
" --srtSourceLatency INT\n"
" --no-audio\n"
" --no-video\n"
" --bypass-audio\n"
" --bypass-video\n";
GMainLoop* mainLoop = nullptr;
std::unique_ptr<Pipeline> pipeline;
void intSignalHandler(int32_t)
{
if (pipeline)
{
pipeline->stop();
}
g_main_loop_quit(mainLoop);
}
} // namespace
int32_t main(int32_t argc, char** argv)
{
{
struct sigaction sigactionData = {};
sigactionData.sa_handler = intSignalHandler;
sigactionData.sa_flags = 0;
sigemptyset(&sigactionData.sa_mask);
sigaction(SIGINT, &sigactionData, nullptr);
}
Config config;
int32_t getOptResult;
int32_t optIndex;
while ((getOptResult = getopt_long(argc, argv, shortOptions, longOptions, &optIndex)) != -1)
{
switch (getOptResult)
{
case 'a':
config.udpSourceAddress_ = optarg;
break;
case 'p':
config.udpSourcePort_ = std::strtoul(optarg, nullptr, 10);
break;
case 'u':
config.whipEndpointUrl_ = optarg;
break;
case 'k':
config.whipEndpointAuthKey_ = optarg;
break;
case 'd':
config.udpSourceQueueMinTime_ = std::chrono::milliseconds(std::strtoull(optarg, nullptr, 10));
break;
case 'r':
config.restreamAddress_ = optarg;
break;
case 'o':
config.restreamPort_ = std::strtoul(optarg, nullptr, 10);
break;
case 'b':
config.h264encodeBitrate = std::strtoul(optarg, nullptr, 10);
break;
case 't':
config.showTimer_ = true;
break;
case 's':
config.srtTransport_ = true;
break;
case 0:
break;
default:
break;
}
switch (optIndex)
{
case 9:
config.tsDemuxLatency_ = std::strtoul(optarg, nullptr, 10);
break;
case 10:
config.jitterBufferLatency_ = std::strtoul(optarg, nullptr, 10);
break;
case 11:
config.srtSourceLatency_ = std::strtoul(optarg, nullptr, 10);
break;
case 12:
config.h264encodeBitrate = std::strtoul(optarg, nullptr, 10);
break;
case 13:
config.audio_ = false;
break;
case 14:
config.video_ = false;
break;
case 15:
config.bypass_audio_ = true;
break;
case 16:
config.bypass_video_ = true;
break;
default:
break;
}
}
if (config.whipEndpointUrl_.empty() || config.udpSourcePort_ == 0 ||
(!config.restreamAddress_.empty() && config.restreamPort_ == 0))
{
printf("%s\n", usageString);
return 1;
}
Logger::log("Config:\n%s", config.toString().c_str());
mainLoop = g_main_loop_new(nullptr, FALSE);
http::WhipClient whipClient(config.whipEndpointUrl_, config.whipEndpointAuthKey_);
pipeline = std::make_unique<Pipeline>(whipClient, config);
pipeline->run();
g_main_loop_run(mainLoop);
return 0;
}