/
htl_main_rtmp_load_fast.cpp
160 lines (129 loc) · 5.01 KB
/
htl_main_rtmp_load_fast.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
/*
The MIT License (MIT)
Copyright (c) 2013-2015 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <htl_stdinc.hpp>
#include <getopt.h>
#include <stdlib.h>
#include <string>
using namespace std;
// project lib
#include <htl_core_log.hpp>
#include <htl_core_error.hpp>
#include <htl_app_rtmp_load.hpp>
#include <htl_app_rtmp_protocol.hpp>
#include <htl_main_utility.hpp>
#define DefaultDelaySeconds 1.0
#define DefaultRtmpUrl "rtmp://127.0.0.1:1935/live/livestream"
int discovery_options(int argc, char** argv,
bool& show_help, bool& show_version, string& url, int& threads,
double& startup, double& delay, double& error, double& report, int& count
){
int ret = ERROR_SUCCESS;
static option long_options[] = {
SharedOptions()
{0, 0, 0, 0}
};
int opt = 0;
int option_index = 0;
while((opt = getopt_long(argc, argv, "hvc:r:t:s:d:e:m:", long_options, &option_index)) != -1){
switch(opt){
ProcessSharedOptions()
default:
show_help = true;
break;
}
}
// check values
if(url == ""){
show_help = true;
return ret;
}
return ret;
}
void help(char** argv){
printf("%s, Copyright (c) 2013-2015 winlin\n", ProductRtmpName);
printf("srs.librtmp %d.%d.%d (https://github.com/winlinvip/srs.librtmp)\n\n",
srs_version_major(), srs_version_minor(), srs_version_revision());
printf(""
"Usage: %s <Options> <-u URL>\n"
"%s base on st(state-threads), support huge concurrency.\n"
"Options:\n"
ShowHelpPart1()
ShowHelpPart2()
"\n"
"Examples:\n"
"1. start a client\n"
" %s -c 1 -r %s\n"
"2. start 1000 clients\n"
" %s -c 1000 -r %s\n"
"3. start 10000 clients\n"
" %s -c 10000 -r %s\n"
"4. start 100000 clients\n"
" %s -c 100000 -r %s\n"
"\n"
"This program built for %s.\n"
"Report bugs to <%s>\n",
argv[0], argv[0],
DefaultThread, DefaultRtmpUrl, DefaultCount, // part1
(double)DefaultStartupSeconds, DefaultDelaySeconds, // part2
DefaultErrorSeconds, DefaultReportSeconds, // part2
argv[0], DefaultRtmpUrl, argv[0], DefaultRtmpUrl, argv[0], DefaultRtmpUrl, argv[0], DefaultRtmpUrl,
BuildPlatform, BugReportEmail);
exit(0);
}
int main(int argc, char** argv){
int ret = ERROR_SUCCESS;
printf("WARNING!!!\n"
"WARNING!!! we use FAST algorithm to read tcp data directly, \n"
"WARNING!!! may not work for some RTMP server, it's ok for SRS/GO-SRS.\n"
"WARNING!!!\n\n");
bool show_help = false, show_version = false;
string url; int threads = DefaultThread;
double start = DefaultStartupSeconds, delay = DefaultDelaySeconds, error = DefaultErrorSeconds;
double report = DefaultReportSeconds; int count = DefaultCount;
if((ret = discovery_options(argc, argv, show_help, show_version, url, threads, start, delay, error, report, count)) != ERROR_SUCCESS){
Error("discovery options failed. ret=%d", ret);
return ret;
}
Trace("params url=%s, threads=%d, start=%.2f, delay=%.2f, error=%.2f, report=%.2f, count=%d",
url.c_str(), threads, start, delay, error, report, count);
if(show_help){
help(argv);
}
if(show_version){
version();
}
StFarm farm;
if((ret = farm.Initialize(report)) != ERROR_SUCCESS){
Error("initialize the farm failed. ret=%d", ret);
return ret;
}
for(int i = 0; i < threads; i++){
StRtmpTaskFast* task = new StRtmpTaskFast();
if((ret = task->Initialize(url, start, delay, error, count)) != ERROR_SUCCESS){
Error("initialize task failed, url=%s, ret=%d", url.c_str(), ret);
return ret;
}
if((ret = farm.Spawn(task)) != ERROR_SUCCESS){
Error("st farm spwan task failed, ret=%d", ret);
return ret;
}
}
farm.WaitAll();
return 0;
}