winlin

change to 0.9.37, for http api/stream

@@ -67,10 +67,11 @@ http_api { @@ -67,10 +67,11 @@ http_api {
67 http_stream { 67 http_stream {
68 # whether http streaming service is enabled. 68 # whether http streaming service is enabled.
69 # default: off 69 # default: off
70 - enabled on; 70 + enabled on;
71 # the http streaming port 71 # the http streaming port
72 - # default: 80  
73 - listen 80; 72 + # @remark, if use lower port, for instance 80, user must start srs by root.
  73 + # default: 8080
  74 + listen 8080;
74 } 75 }
75 76
76 ############################################################################################# 77 #############################################################################################
@@ -416,10 +416,11 @@ RTMP_OBJS="${MODULE_OBJS[@]}" @@ -416,10 +416,11 @@ RTMP_OBJS="${MODULE_OBJS[@]}"
416 MODULE_ID="APP" 416 MODULE_ID="APP"
417 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP") 417 MODULE_DEPENDS=("CORE" "KERNEL" "RTMP")
418 ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS}) 418 ModuleLibIncs=(${LibSTRoot} ${LibHttpParserRoot} ${SRS_OBJS})
419 -MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_client" "srs_app_socket" "srs_app_source" 419 +MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_socket" "srs_app_source"
420 "srs_app_codec" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" 420 "srs_app_codec" "srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder"
421 "srs_app_http" "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" 421 "srs_app_http" "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log"
422 - "srs_app_config" "srs_app_pithy_print" "srs_app_reload") 422 + "srs_app_config" "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api"
  423 + "srs_app_http_conn")
423 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh 424 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
424 APP_OBJS="${MODULE_OBJS[@]}" 425 APP_OBJS="${MODULE_OBJS[@]}"
425 # 426 #
@@ -1466,6 +1466,79 @@ double SrsConfig::get_hls_window(string vhost) @@ -1466,6 +1466,79 @@ double SrsConfig::get_hls_window(string vhost)
1466 return ::atof(conf->arg0().c_str()); 1466 return ::atof(conf->arg0().c_str());
1467 } 1467 }
1468 1468
  1469 +SrsConfDirective* SrsConfig::get_http_api()
  1470 +{
  1471 + return root->get("http_api");
  1472 +}
  1473 +
  1474 +bool SrsConfig::get_http_api_enabled()
  1475 +{
  1476 + SrsConfDirective* conf = get_http_api();
  1477 +
  1478 + if (!conf) {
  1479 + return false;
  1480 + }
  1481 +
  1482 + conf = conf->get("enabled");
  1483 + if (conf && conf->arg0() == "on") {
  1484 + return true;
  1485 + }
  1486 +
  1487 + return false;
  1488 +}
  1489 +
  1490 +int SrsConfig::get_http_api_listen()
  1491 +{
  1492 + SrsConfDirective* conf = get_http_api();
  1493 +
  1494 + if (conf) {
  1495 + conf = conf->get("listen");
  1496 +
  1497 + if (conf && !conf->arg0().empty()) {
  1498 + return ::atoi(conf->arg0().c_str());
  1499 + }
  1500 + }
  1501 +
  1502 + return 1985;
  1503 +}
  1504 +
  1505 +SrsConfDirective* SrsConfig::get_http_stream()
  1506 +{
  1507 + return root->get("http_stream");
  1508 +}
  1509 +
  1510 +bool SrsConfig::get_http_stream_enabled()
  1511 +{
  1512 + SrsConfDirective* conf = get_http_stream();
  1513 +
  1514 + if (!conf) {
  1515 + return false;
  1516 + }
  1517 +
  1518 + conf = conf->get("enabled");
  1519 +
  1520 + if (conf && conf->arg0() == "on") {
  1521 + return true;
  1522 + }
  1523 +
  1524 + return false;
  1525 +}
  1526 +
  1527 +int SrsConfig::get_http_stream_listen()
  1528 +{
  1529 + SrsConfDirective* conf = get_http_stream();
  1530 +
  1531 + if (conf) {
  1532 + conf = conf->get("listen");
  1533 +
  1534 + if (conf && !conf->arg0().empty()) {
  1535 + return ::atoi(conf->arg0().c_str());
  1536 + }
  1537 + }
  1538 +
  1539 + return 8080;
  1540 +}
  1541 +
1469 SrsConfDirective* SrsConfig::get_refer(string vhost) 1542 SrsConfDirective* SrsConfig::get_refer(string vhost)
1470 { 1543 {
1471 SrsConfDirective* conf = get_vhost(vhost); 1544 SrsConfDirective* conf = get_vhost(vhost);
@@ -156,6 +156,7 @@ public: @@ -156,6 +156,7 @@ public:
156 virtual bool get_atc(std::string vhost); 156 virtual bool get_atc(std::string vhost);
157 virtual double get_queue_length(std::string vhost); 157 virtual double get_queue_length(std::string vhost);
158 virtual SrsConfDirective* get_forward(std::string vhost); 158 virtual SrsConfDirective* get_forward(std::string vhost);
  159 +// hls section
159 private: 160 private:
160 virtual SrsConfDirective* get_hls(std::string vhost); 161 virtual SrsConfDirective* get_hls(std::string vhost);
161 public: 162 public:
@@ -163,6 +164,20 @@ public: @@ -163,6 +164,20 @@ public:
163 virtual std::string get_hls_path(std::string vhost); 164 virtual std::string get_hls_path(std::string vhost);
164 virtual double get_hls_fragment(std::string vhost); 165 virtual double get_hls_fragment(std::string vhost);
165 virtual double get_hls_window(std::string vhost); 166 virtual double get_hls_window(std::string vhost);
  167 +// http api section
  168 +private:
  169 + virtual SrsConfDirective* get_http_api();
  170 +public:
  171 + virtual bool get_http_api_enabled();
  172 + virtual int get_http_api_listen();
  173 +// http stream section
  174 +private:
  175 + virtual SrsConfDirective* get_http_stream();
  176 +public:
  177 + virtual bool get_http_stream_enabled();
  178 + virtual int get_http_stream_listen();
  179 +// others
  180 +public:
166 virtual SrsConfDirective* get_refer(std::string vhost); 181 virtual SrsConfDirective* get_refer(std::string vhost);
167 virtual SrsConfDirective* get_refer_play(std::string vhost); 182 virtual SrsConfDirective* get_refer_play(std::string vhost);
168 virtual SrsConfDirective* get_refer_publish(std::string vhost); 183 virtual SrsConfDirective* get_refer_publish(std::string vhost);
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_app_http_api.hpp>
  25 +
  26 +SrsHttpApi::SrsHttpApi() {
  27 +}
  28 +
  29 +SrsHttpApi::~SrsHttpApi() {
  30 +}
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_APP_HTTP_API_HPP
  25 +#define SRS_APP_HTTP_API_HPP
  26 +
  27 +/*
  28 +#include <srs_app_http_api.hpp>
  29 +*/
  30 +
  31 +#include <srs_core.hpp>
  32 +
  33 +class SrsHttpApi
  34 +{
  35 +public:
  36 + SrsHttpApi();
  37 + virtual ~SrsHttpApi();
  38 +};
  39 +
  40 +#endif
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_app_http_conn.hpp>
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_APP_HTTP_CONN_HPP
  25 +#define SRS_APP_HTTP_CONN_HPP
  26 +
  27 +/*
  28 +#include <srs_app_http_conn.hpp>
  29 +*/
  30 +
  31 +#include <srs_core.hpp>
  32 +
  33 +class SrsHttpConn
  34 +{
  35 +public:
  36 + SrsHttpConn();
  37 + virtual ~SrsHttpConn();
  38 +};
  39 +
  40 +#endif
1 -/*  
2 -The MIT License (MIT)  
3 -  
4 -Copyright (c) 2013-2014 winlin  
5 -  
6 -Permission is hereby granted, free of charge, to any person obtaining a copy of  
7 -this software and associated documentation files (the "Software"), to deal in  
8 -the Software without restriction, including without limitation the rights to  
9 -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of  
10 -the Software, and to permit persons to whom the Software is furnished to do so,  
11 -subject to the following conditions:  
12 -  
13 -The above copyright notice and this permission notice shall be included in all  
14 -copies or substantial portions of the Software.  
15 -  
16 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
17 -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS  
18 -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR  
19 -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER  
20 -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN  
21 -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
22 -*/  
23 -  
24 -#include <srs_app_client.hpp>  
25 -  
26 -#include <arpa/inet.h>  
27 -#include <stdlib.h>  
28 -  
29 -using namespace std;  
30 -  
31 -#include <srs_kernel_error.hpp>  
32 -#include <srs_kernel_log.hpp>  
33 -#include <srs_protocol_rtmp.hpp>  
34 -#include <srs_protocol_rtmp_stack.hpp>  
35 -#include <srs_core_autofree.hpp>  
36 -#include <srs_app_source.hpp>  
37 -#include <srs_app_server.hpp>  
38 -#include <srs_app_pithy_print.hpp>  
39 -#include <srs_app_config.hpp>  
40 -#include <srs_app_refer.hpp>  
41 -#include <srs_app_hls.hpp>  
42 -#include <srs_app_http.hpp>  
43 -#include <srs_app_bandwidth.hpp>  
44 -#include <srs_app_socket.hpp>  
45 -  
46 -SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)  
47 - : SrsConnection(srs_server, client_stfd)  
48 -{  
49 - ip = NULL;  
50 - req = new SrsRequest();  
51 - res = new SrsResponse();  
52 - skt = new SrsSocket(client_stfd);  
53 - rtmp = new SrsRtmpServer(skt);  
54 - refer = new SrsRefer();  
55 -#ifdef SRS_HTTP_CALLBACK  
56 - http_hooks = new SrsHttpHooks();  
57 -#endif  
58 - bandwidth = new SrsBandwidth();  
59 -  
60 - _srs_config->subscribe(this);  
61 -}  
62 -  
63 -SrsClient::~SrsClient()  
64 -{  
65 - _srs_config->unsubscribe(this);  
66 -  
67 - srs_freepa(ip);  
68 - srs_freep(req);  
69 - srs_freep(res);  
70 - srs_freep(rtmp);  
71 - srs_freep(skt);  
72 - srs_freep(refer);  
73 -#ifdef SRS_HTTP_CALLBACK  
74 - srs_freep(http_hooks);  
75 -#endif  
76 - srs_freep(bandwidth);  
77 -}  
78 -  
79 -// TODO: return detail message when error for client.  
80 -int SrsClient::do_cycle()  
81 -{  
82 - int ret = ERROR_SUCCESS;  
83 -  
84 - if ((ret = get_peer_ip()) != ERROR_SUCCESS) {  
85 - srs_error("get peer ip failed. ret=%d", ret);  
86 - return ret;  
87 - }  
88 - srs_trace("get peer ip success. ip=%s, send_to=%"PRId64", recv_to=%"PRId64"",  
89 - ip, SRS_SEND_TIMEOUT_US, SRS_RECV_TIMEOUT_US);  
90 -  
91 - rtmp->set_recv_timeout(SRS_RECV_TIMEOUT_US);  
92 - rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US);  
93 -  
94 - if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {  
95 - srs_error("rtmp handshake failed. ret=%d", ret);  
96 - return ret;  
97 - }  
98 - srs_verbose("rtmp handshake success");  
99 -  
100 - if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) {  
101 - srs_error("rtmp connect vhost/app failed. ret=%d", ret);  
102 - return ret;  
103 - }  
104 - srs_verbose("rtmp connect app success");  
105 -  
106 - // discovery vhost, resolve the vhost from config  
107 - SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);  
108 - if (parsed_vhost) {  
109 - req->vhost = parsed_vhost->arg0();  
110 - }  
111 -  
112 - srs_info("discovery app success. schema=%s, vhost=%s, port=%s, app=%s",  
113 - req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str());  
114 -  
115 - if (req->schema.empty() || req->vhost.empty() || req->port.empty() || req->app.empty()) {  
116 - ret = ERROR_RTMP_REQ_TCURL;  
117 - srs_error("discovery tcUrl failed. "  
118 - "tcUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, ret=%d",  
119 - req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str(), ret);  
120 - return ret;  
121 - }  
122 -  
123 - // check vhost  
124 - if ((ret = check_vhost()) != ERROR_SUCCESS) {  
125 - srs_error("check vhost failed. ret=%d", ret);  
126 - return ret;  
127 - }  
128 - srs_verbose("check vhost success.");  
129 -  
130 - srs_trace("rtmp connect app success. "  
131 - "tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s",  
132 - req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),  
133 - req->schema.c_str(), req->vhost.c_str(), req->port.c_str(),  
134 - req->app.c_str());  
135 -  
136 - ret = service_cycle();  
137 - on_close();  
138 -  
139 - return ret;  
140 -}  
141 -  
142 -int SrsClient::on_reload_vhost_removed(string vhost)  
143 -{  
144 - int ret = ERROR_SUCCESS;  
145 -  
146 - if (req->vhost != vhost) {  
147 - return ret;  
148 - }  
149 -  
150 - // if the vhost connected is removed, disconnect the client.  
151 - srs_trace("vhost %s removed/disabled, close client url=%s",  
152 - vhost.c_str(), req->get_stream_url().c_str());  
153 -  
154 - srs_close_stfd(stfd);  
155 -  
156 - return ret;  
157 -}  
158 -  
159 -int SrsClient::service_cycle()  
160 -{  
161 - int ret = ERROR_SUCCESS;  
162 -  
163 - if ((ret = rtmp->set_window_ack_size(2.5 * 1000 * 1000)) != ERROR_SUCCESS) {  
164 - srs_error("set window acknowledgement size failed. ret=%d", ret);  
165 - return ret;  
166 - }  
167 - srs_verbose("set window acknowledgement size success");  
168 -  
169 - if ((ret = rtmp->set_peer_bandwidth(2.5 * 1000 * 1000, 2)) != ERROR_SUCCESS) {  
170 - srs_error("set peer bandwidth failed. ret=%d", ret);  
171 - return ret;  
172 - }  
173 - srs_verbose("set peer bandwidth success");  
174 -  
175 - // do bandwidth test if connect to the vhost which is for bandwidth check.  
176 - if (_srs_config->get_bw_check_enabled(req->vhost)) {  
177 - return bandwidth->bandwidth_test(req, stfd, rtmp);  
178 - }  
179 -  
180 - if ((ret = rtmp->response_connect_app(req)) != ERROR_SUCCESS) {  
181 - srs_error("response connect app failed. ret=%d", ret);  
182 - return ret;  
183 - }  
184 - srs_verbose("response connect app success");  
185 -  
186 - if ((ret = rtmp->on_bw_done()) != ERROR_SUCCESS) {  
187 - srs_error("on_bw_done failed. ret=%d", ret);  
188 - return ret;  
189 - }  
190 - srs_verbose("on_bw_done success");  
191 -  
192 - while (true) {  
193 - ret = stream_service_cycle();  
194 -  
195 - // stream service must terminated with error, never success.  
196 - srs_assert(ret != ERROR_SUCCESS);  
197 -  
198 - // when not system control error, fatal error, return.  
199 - if (!srs_is_system_control_error(ret)) {  
200 - if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {  
201 - srs_error("stream service cycle failed. ret=%d", ret);  
202 - }  
203 - return ret;  
204 - }  
205 -  
206 - // for republish, continue service  
207 - if (ret == ERROR_CONTROL_REPUBLISH) {  
208 - // set timeout to a larger value, wait for encoder to republish.  
209 - rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TIMEOUT_US);  
210 - rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TIMEOUT_US);  
211 -  
212 - srs_trace("control message(unpublish) accept, retry stream service.");  
213 - continue;  
214 - }  
215 -  
216 - // for "some" system control error,  
217 - // logical accept and retry stream service.  
218 - if (ret == ERROR_CONTROL_RTMP_CLOSE) {  
219 - // set timeout to a larger value, for user paused.  
220 - rtmp->set_recv_timeout(SRS_PAUSED_RECV_TIMEOUT_US);  
221 - rtmp->set_send_timeout(SRS_PAUSED_SEND_TIMEOUT_US);  
222 -  
223 - srs_trace("control message(close) accept, retry stream service.");  
224 - continue;  
225 - }  
226 -  
227 - // for other system control message, fatal error.  
228 - srs_error("control message(%d) reject as error. ret=%d", ret, ret);  
229 - return ret;  
230 - }  
231 -  
232 - return ret;  
233 -}  
234 -  
235 -int SrsClient::stream_service_cycle()  
236 -{  
237 - int ret = ERROR_SUCCESS;  
238 -  
239 - SrsClientType type;  
240 - if ((ret = rtmp->identify_client(res->stream_id, type, req->stream)) != ERROR_SUCCESS) {  
241 - srs_error("identify client failed. ret=%d", ret);  
242 - return ret;  
243 - }  
244 - req->strip();  
245 - srs_trace("identify client success. type=%s, stream_name=%s",  
246 - srs_client_type_string(type).c_str(), req->stream.c_str());  
247 -  
248 - // client is identified, set the timeout to service timeout.  
249 - rtmp->set_recv_timeout(SRS_RECV_TIMEOUT_US);  
250 - rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US);  
251 -  
252 - // set chunk size to larger.  
253 - int chunk_size = _srs_config->get_chunk_size(req->vhost);  
254 - if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) {  
255 - srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret);  
256 - return ret;  
257 - }  
258 - srs_trace("set chunk_size=%d success", chunk_size);  
259 -  
260 - // find a source to serve.  
261 - SrsSource* source = SrsSource::find(req);  
262 - srs_assert(source != NULL);  
263 -  
264 - // check publish available.  
265 - if (type != SrsClientPlay && !source->can_publish()) {  
266 - ret = ERROR_SYSTEM_STREAM_BUSY;  
267 - srs_warn("stream %s is already publishing. ret=%d",  
268 - req->get_stream_url().c_str(), ret);  
269 - // to delay request  
270 - st_usleep(SRS_STREAM_BUSY_SLEEP_US);  
271 - return ret;  
272 - }  
273 -  
274 - bool enabled_cache = _srs_config->get_gop_cache(req->vhost);  
275 - srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);  
276 - source->set_cache(enabled_cache);  
277 -  
278 - switch (type) {  
279 - case SrsClientPlay: {  
280 - srs_verbose("start to play stream %s.", req->stream.c_str());  
281 -  
282 - if ((ret = rtmp->start_play(res->stream_id)) != ERROR_SUCCESS) {  
283 - srs_error("start to play stream failed. ret=%d", ret);  
284 - return ret;  
285 - }  
286 - if ((ret = on_play()) != ERROR_SUCCESS) {  
287 - srs_error("http hook on_play failed. ret=%d", ret);  
288 - return ret;  
289 - }  
290 - srs_info("start to play stream %s success", req->stream.c_str());  
291 - ret = playing(source);  
292 - on_stop();  
293 - return ret;  
294 - }  
295 - case SrsClientFMLEPublish: {  
296 - srs_verbose("FMLE start to publish stream %s.", req->stream.c_str());  
297 -  
298 - if ((ret = rtmp->start_fmle_publish(res->stream_id)) != ERROR_SUCCESS) {  
299 - srs_error("start to publish stream failed. ret=%d", ret);  
300 - return ret;  
301 - }  
302 - if ((ret = on_publish()) != ERROR_SUCCESS) {  
303 - srs_error("http hook on_publish failed. ret=%d", ret);  
304 - return ret;  
305 - }  
306 - srs_info("start to publish stream %s success", req->stream.c_str());  
307 - ret = fmle_publish(source);  
308 - source->on_unpublish();  
309 - on_unpublish();  
310 - return ret;  
311 - }  
312 - case SrsClientFlashPublish: {  
313 - srs_verbose("flash start to publish stream %s.", req->stream.c_str());  
314 -  
315 - if ((ret = rtmp->start_flash_publish(res->stream_id)) != ERROR_SUCCESS) {  
316 - srs_error("flash start to publish stream failed. ret=%d", ret);  
317 - return ret;  
318 - }  
319 - if ((ret = on_publish()) != ERROR_SUCCESS) {  
320 - srs_error("http hook on_publish failed. ret=%d", ret);  
321 - return ret;  
322 - }  
323 - srs_info("flash start to publish stream %s success", req->stream.c_str());  
324 - ret = flash_publish(source);  
325 - source->on_unpublish();  
326 - on_unpublish();  
327 - return ret;  
328 - }  
329 - default: {  
330 - ret = ERROR_SYSTEM_CLIENT_INVALID;  
331 - srs_info("invalid client type=%d. ret=%d", type, ret);  
332 - return ret;  
333 - }  
334 - }  
335 -  
336 - return ret;  
337 -}  
338 -  
339 -int SrsClient::check_vhost()  
340 -{  
341 - int ret = ERROR_SUCCESS;  
342 -  
343 - srs_assert(req != NULL);  
344 -  
345 - SrsConfDirective* vhost = _srs_config->get_vhost(req->vhost);  
346 - if (vhost == NULL) {  
347 - ret = ERROR_RTMP_VHOST_NOT_FOUND;  
348 - srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret);  
349 - return ret;  
350 - }  
351 -  
352 - if (!_srs_config->get_vhost_enabled(req->vhost)) {  
353 - ret = ERROR_RTMP_VHOST_NOT_FOUND;  
354 - srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);  
355 - return ret;  
356 - }  
357 -  
358 - if (req->vhost != vhost->arg0()) {  
359 - srs_trace("vhost change from %s to %s", req->vhost.c_str(), vhost->arg0().c_str());  
360 - req->vhost = vhost->arg0();  
361 - }  
362 -  
363 - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer(req->vhost))) != ERROR_SUCCESS) {  
364 - srs_error("check refer failed. ret=%d", ret);  
365 - return ret;  
366 - }  
367 - srs_verbose("check refer success.");  
368 -  
369 - if ((ret = on_connect()) != ERROR_SUCCESS) {  
370 - return ret;  
371 - }  
372 -  
373 - return ret;  
374 -}  
375 -  
376 -int SrsClient::playing(SrsSource* source)  
377 -{  
378 - int ret = ERROR_SUCCESS;  
379 -  
380 - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) {  
381 - srs_error("check play_refer failed. ret=%d", ret);  
382 - return ret;  
383 - }  
384 - srs_verbose("check play_refer success.");  
385 -  
386 - SrsConsumer* consumer = NULL;  
387 - if ((ret = source->create_consumer(consumer)) != ERROR_SUCCESS) {  
388 - srs_error("create consumer failed. ret=%d", ret);  
389 - return ret;  
390 - }  
391 -  
392 - srs_assert(consumer != NULL);  
393 - SrsAutoFree(SrsConsumer, consumer, false);  
394 - srs_verbose("consumer created success.");  
395 -  
396 - rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_US);  
397 -  
398 - SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER);  
399 -  
400 - while (true) {  
401 - pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000);  
402 -  
403 - // switch to other st-threads.  
404 - st_usleep(0);  
405 -  
406 - // read from client.  
407 - int ctl_msg_ret = ERROR_SUCCESS;  
408 - if (true) {  
409 - SrsCommonMessage* msg = NULL;  
410 - ctl_msg_ret = ret = rtmp->recv_message(&msg);  
411 -  
412 - srs_verbose("play loop recv message. ret=%d", ret);  
413 - if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {  
414 - if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {  
415 - srs_error("recv client control message failed. ret=%d", ret);  
416 - }  
417 - return ret;  
418 - }  
419 - if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) {  
420 - if (!srs_is_system_control_error(ret)) {  
421 - srs_error("process play control message failed. ret=%d", ret);  
422 - }  
423 - return ret;  
424 - }  
425 - }  
426 -  
427 - // get messages from consumer.  
428 - SrsSharedPtrMessage** msgs = NULL;  
429 - int count = 0;  
430 - if ((ret = consumer->get_packets(0, msgs, count)) != ERROR_SUCCESS) {  
431 - srs_error("get messages from consumer failed. ret=%d", ret);  
432 - return ret;  
433 - }  
434 -  
435 - // reportable  
436 - if (pithy_print.can_print()) {  
437 - srs_trace("-> time=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",  
438 - pithy_print.get_age(), ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());  
439 - }  
440 -  
441 - if (count <= 0) {  
442 - srs_verbose("no packets in queue.");  
443 - continue;  
444 - }  
445 - SrsAutoFree(SrsSharedPtrMessage*, msgs, true);  
446 -  
447 - // sendout messages  
448 - for (int i = 0; i < count; i++) {  
449 - SrsSharedPtrMessage* msg = msgs[i];  
450 -  
451 - // the send_message will free the msg,  
452 - // so set the msgs[i] to NULL.  
453 - msgs[i] = NULL;  
454 -  
455 - if ((ret = rtmp->send_message(msg)) != ERROR_SUCCESS) {  
456 - srs_error("send message to client failed. ret=%d", ret);  
457 - return ret;  
458 - }  
459 - }  
460 - }  
461 -  
462 - return ret;  
463 -}  
464 -  
465 -int SrsClient::fmle_publish(SrsSource* source)  
466 -{  
467 - int ret = ERROR_SUCCESS;  
468 -  
469 - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) {  
470 - srs_error("fmle check publish_refer failed. ret=%d", ret);  
471 - return ret;  
472 - }  
473 - srs_verbose("fmle check publish_refer success.");  
474 -  
475 - SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);  
476 -  
477 - // notify the hls to prepare when publish start.  
478 - if ((ret = source->on_publish(req)) != ERROR_SUCCESS) {  
479 - srs_error("fmle hls on_publish failed. ret=%d", ret);  
480 - return ret;  
481 - }  
482 - srs_verbose("fmle hls on_publish success.");  
483 -  
484 - while (true) {  
485 - // switch to other st-threads.  
486 - st_usleep(0);  
487 -  
488 - SrsCommonMessage* msg = NULL;  
489 - if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {  
490 - srs_error("fmle recv identify client message failed. ret=%d", ret);  
491 - return ret;  
492 - }  
493 -  
494 - SrsAutoFree(SrsCommonMessage, msg, false);  
495 -  
496 - pithy_print.set_age(msg->header.timestamp);  
497 -  
498 - // reportable  
499 - if (pithy_print.can_print()) {  
500 - srs_trace("<- time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",  
501 - pithy_print.get_age(), rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());  
502 - }  
503 -  
504 - // process UnPublish event.  
505 - if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {  
506 - if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {  
507 - srs_error("fmle decode unpublish message failed. ret=%d", ret);  
508 - return ret;  
509 - }  
510 -  
511 - SrsPacket* pkt = msg->get_packet();  
512 - if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {  
513 - SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt);  
514 - if ((ret = rtmp->fmle_unpublish(res->stream_id, unpublish->transaction_id)) != ERROR_SUCCESS) {  
515 - return ret;  
516 - }  
517 - return ERROR_CONTROL_REPUBLISH;  
518 - }  
519 -  
520 - srs_trace("fmle ignore AMF0/AMF3 command message.");  
521 - continue;  
522 - }  
523 -  
524 - // video, audio, data message  
525 - if ((ret = process_publish_message(source, msg)) != ERROR_SUCCESS) {  
526 - srs_error("fmle process publish message failed. ret=%d", ret);  
527 - return ret;  
528 - }  
529 - }  
530 -  
531 - return ret;  
532 -}  
533 -  
534 -int SrsClient::flash_publish(SrsSource* source)  
535 -{  
536 - int ret = ERROR_SUCCESS;  
537 -  
538 - if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) {  
539 - srs_error("flash check publish_refer failed. ret=%d", ret);  
540 - return ret;  
541 - }  
542 - srs_verbose("flash check publish_refer success.");  
543 -  
544 - SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);  
545 -  
546 - // notify the hls to prepare when publish start.  
547 - if ((ret = source->on_publish(req)) != ERROR_SUCCESS) {  
548 - srs_error("flash hls on_publish failed. ret=%d", ret);  
549 - return ret;  
550 - }  
551 - srs_verbose("flash hls on_publish success.");  
552 -  
553 - while (true) {  
554 - // switch to other st-threads.  
555 - st_usleep(0);  
556 -  
557 - SrsCommonMessage* msg = NULL;  
558 - if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {  
559 - if (!srs_is_client_gracefully_close(ret)) {  
560 - srs_error("flash recv identify client message failed. ret=%d", ret);  
561 - }  
562 - return ret;  
563 - }  
564 -  
565 - SrsAutoFree(SrsCommonMessage, msg, false);  
566 -  
567 - pithy_print.set_age(msg->header.timestamp);  
568 -  
569 - // reportable  
570 - if (pithy_print.can_print()) {  
571 - srs_trace("<- time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",  
572 - pithy_print.get_age(), rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());  
573 - }  
574 -  
575 - // process UnPublish event.  
576 - if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {  
577 - if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {  
578 - srs_error("flash decode unpublish message failed. ret=%d", ret);  
579 - return ret;  
580 - }  
581 -  
582 - // flash unpublish.  
583 - // TODO: maybe need to support republish.  
584 - srs_trace("flash flash publish finished.");  
585 - return ERROR_CONTROL_REPUBLISH;  
586 - }  
587 -  
588 - // video, audio, data message  
589 - if ((ret = process_publish_message(source, msg)) != ERROR_SUCCESS) {  
590 - srs_error("flash process publish message failed. ret=%d", ret);  
591 - return ret;  
592 - }  
593 - }  
594 -  
595 - return ret;  
596 -}  
597 -  
598 -int SrsClient::process_publish_message(SrsSource* source, SrsCommonMessage* msg)  
599 -{  
600 - int ret = ERROR_SUCCESS;  
601 -  
602 - // process audio packet  
603 - if (msg->header.is_audio()) {  
604 - if ((ret = source->on_audio(msg)) != ERROR_SUCCESS) {  
605 - srs_error("source process audio message failed. ret=%d", ret);  
606 - return ret;  
607 - }  
608 - }  
609 - // process video packet  
610 - if (msg->header.is_video()) {  
611 - if ((ret = source->on_video(msg)) != ERROR_SUCCESS) {  
612 - srs_error("source process video message failed. ret=%d", ret);  
613 - return ret;  
614 - }  
615 - }  
616 -  
617 - // process onMetaData  
618 - if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {  
619 - if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {  
620 - srs_error("decode onMetaData message failed. ret=%d", ret);  
621 - return ret;  
622 - }  
623 -  
624 - SrsPacket* pkt = msg->get_packet();  
625 - if (dynamic_cast<SrsOnMetaDataPacket*>(pkt)) {  
626 - SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt);  
627 - if ((ret = source->on_meta_data(msg, metadata)) != ERROR_SUCCESS) {  
628 - srs_error("source process onMetaData message failed. ret=%d", ret);  
629 - return ret;  
630 - }  
631 - srs_trace("process onMetaData message success.");  
632 - return ret;  
633 - }  
634 -  
635 - srs_trace("ignore AMF0/AMF3 data message.");  
636 - return ret;  
637 - }  
638 -  
639 - return ret;  
640 -}  
641 -  
642 -int SrsClient::get_peer_ip()  
643 -{  
644 - int ret = ERROR_SUCCESS;  
645 -  
646 - int fd = st_netfd_fileno(stfd);  
647 -  
648 - // discovery client information  
649 - sockaddr_in addr;  
650 - socklen_t addrlen = sizeof(addr);  
651 - if (getpeername(fd, (sockaddr*)&addr, &addrlen) == -1) {  
652 - ret = ERROR_SOCKET_GET_PEER_NAME;  
653 - srs_error("discovery client information failed. ret=%d", ret);  
654 - return ret;  
655 - }  
656 - srs_verbose("get peer name success.");  
657 -  
658 - // ip v4 or v6  
659 - char buf[INET6_ADDRSTRLEN];  
660 - memset(buf, 0, sizeof(buf));  
661 -  
662 - if ((inet_ntop(addr.sin_family, &addr.sin_addr, buf, sizeof(buf))) == NULL) {  
663 - ret = ERROR_SOCKET_GET_PEER_IP;  
664 - srs_error("convert client information failed. ret=%d", ret);  
665 - return ret;  
666 - }  
667 - srs_verbose("get peer ip of client ip=%s, fd=%d", buf, fd);  
668 -  
669 - ip = new char[strlen(buf) + 1];  
670 - strcpy(ip, buf);  
671 -  
672 - srs_verbose("get peer ip success. ip=%s, fd=%d", ip, fd);  
673 -  
674 - return ret;  
675 -}  
676 -  
677 -int SrsClient::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg)  
678 -{  
679 - int ret = ERROR_SUCCESS;  
680 -  
681 - if (!msg) {  
682 - srs_verbose("ignore all empty message.");  
683 - return ret;  
684 - }  
685 - SrsAutoFree(SrsCommonMessage, msg, false);  
686 -  
687 - if (!msg->header.is_amf0_command() && !msg->header.is_amf3_command()) {  
688 - srs_info("ignore all message except amf0/amf3 command.");  
689 - return ret;  
690 - }  
691 -  
692 - if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {  
693 - srs_error("decode the amf0/amf3 command packet failed. ret=%d", ret);  
694 - return ret;  
695 - }  
696 - srs_info("decode the amf0/amf3 command packet success.");  
697 -  
698 - SrsCloseStreamPacket* close = dynamic_cast<SrsCloseStreamPacket*>(msg->get_packet());  
699 - if (close) {  
700 - ret = ERROR_CONTROL_RTMP_CLOSE;  
701 - srs_trace("system control message: rtmp close stream. ret=%d", ret);  
702 - return ret;  
703 - }  
704 -  
705 - SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(msg->get_packet());  
706 - if (!pause) {  
707 - srs_info("ignore all amf0/amf3 command except pause.");  
708 - return ret;  
709 - }  
710 -  
711 - if ((ret = rtmp->on_play_client_pause(res->stream_id, pause->is_pause)) != ERROR_SUCCESS) {  
712 - srs_error("rtmp process play client pause failed. ret=%d", ret);  
713 - return ret;  
714 - }  
715 -  
716 - if ((ret = consumer->on_play_client_pause(pause->is_pause)) != ERROR_SUCCESS) {  
717 - srs_error("consumer process play client pause failed. ret=%d", ret);  
718 - return ret;  
719 - }  
720 - srs_info("process pause success, is_pause=%d, time=%d.", pause->is_pause, pause->time_ms);  
721 -  
722 - return ret;  
723 -}  
724 -  
725 -int SrsClient::on_connect()  
726 -{  
727 - int ret = ERROR_SUCCESS;  
728 -  
729 -#ifdef SRS_HTTP_CALLBACK  
730 - // HTTP: on_connect  
731 - SrsConfDirective* on_connect = _srs_config->get_vhost_on_connect(req->vhost);  
732 - if (!on_connect) {  
733 - srs_info("ignore the empty http callback: on_connect");  
734 - return ret;  
735 - }  
736 -  
737 - for (int i = 0; i < (int)on_connect->args.size(); i++) {  
738 - std::string url = on_connect->args.at(i);  
739 - if ((ret = http_hooks->on_connect(url, connection_id, ip, req)) != ERROR_SUCCESS) {  
740 - srs_error("hook client on_connect failed. url=%s, ret=%d", url.c_str(), ret);  
741 - return ret;  
742 - }  
743 - }  
744 -#endif  
745 -  
746 - return ret;  
747 -}  
748 -  
749 -void SrsClient::on_close()  
750 -{  
751 -#ifdef SRS_HTTP_CALLBACK  
752 - // whatever the ret code, notify the api hooks.  
753 - // HTTP: on_close  
754 - SrsConfDirective* on_close = _srs_config->get_vhost_on_close(req->vhost);  
755 - if (!on_close) {  
756 - srs_info("ignore the empty http callback: on_close");  
757 - return;  
758 - }  
759 -  
760 - for (int i = 0; i < (int)on_close->args.size(); i++) {  
761 - std::string url = on_close->args.at(i);  
762 - http_hooks->on_close(url, connection_id, ip, req);  
763 - }  
764 -#endif  
765 -}  
766 -  
767 -int SrsClient::on_publish()  
768 -{  
769 - int ret = ERROR_SUCCESS;  
770 -  
771 -#ifdef SRS_HTTP_CALLBACK  
772 - // HTTP: on_publish  
773 - SrsConfDirective* on_publish = _srs_config->get_vhost_on_publish(req->vhost);  
774 - if (!on_publish) {  
775 - srs_info("ignore the empty http callback: on_publish");  
776 - return ret;  
777 - }  
778 -  
779 - for (int i = 0; i < (int)on_publish->args.size(); i++) {  
780 - std::string url = on_publish->args.at(i);  
781 - if ((ret = http_hooks->on_publish(url, connection_id, ip, req)) != ERROR_SUCCESS) {  
782 - srs_error("hook client on_publish failed. url=%s, ret=%d", url.c_str(), ret);  
783 - return ret;  
784 - }  
785 - }  
786 -#endif  
787 -  
788 - return ret;  
789 -}  
790 -  
791 -void SrsClient::on_unpublish()  
792 -{  
793 -#ifdef SRS_HTTP_CALLBACK  
794 - // whatever the ret code, notify the api hooks.  
795 - // HTTP: on_unpublish  
796 - SrsConfDirective* on_unpublish = _srs_config->get_vhost_on_unpublish(req->vhost);  
797 - if (!on_unpublish) {  
798 - srs_info("ignore the empty http callback: on_unpublish");  
799 - return;  
800 - }  
801 -  
802 - for (int i = 0; i < (int)on_unpublish->args.size(); i++) {  
803 - std::string url = on_unpublish->args.at(i);  
804 - http_hooks->on_unpublish(url, connection_id, ip, req);  
805 - }  
806 -#endif  
807 -}  
808 -  
809 -int SrsClient::on_play()  
810 -{  
811 - int ret = ERROR_SUCCESS;  
812 -  
813 -#ifdef SRS_HTTP_CALLBACK  
814 - // HTTP: on_play  
815 - SrsConfDirective* on_play = _srs_config->get_vhost_on_play(req->vhost);  
816 - if (!on_play) {  
817 - srs_info("ignore the empty http callback: on_play");  
818 - return ret;  
819 - }  
820 -  
821 - for (int i = 0; i < (int)on_play->args.size(); i++) {  
822 - std::string url = on_play->args.at(i);  
823 - if ((ret = http_hooks->on_play(url, connection_id, ip, req)) != ERROR_SUCCESS) {  
824 - srs_error("hook client on_play failed. url=%s, ret=%d", url.c_str(), ret);  
825 - return ret;  
826 - }  
827 - }  
828 -#endif  
829 -  
830 - return ret;  
831 -}  
832 -  
833 -void SrsClient::on_stop()  
834 -{  
835 -#ifdef SRS_HTTP_CALLBACK  
836 - // whatever the ret code, notify the api hooks.  
837 - // HTTP: on_stop  
838 - SrsConfDirective* on_stop = _srs_config->get_vhost_on_stop(req->vhost);  
839 - if (!on_stop) {  
840 - srs_info("ignore the empty http callback: on_stop");  
841 - return;  
842 - }  
843 -  
844 - for (int i = 0; i < (int)on_stop->args.size(); i++) {  
845 - std::string url = on_stop->args.at(i);  
846 - http_hooks->on_stop(url, connection_id, ip, req);  
847 - }  
848 -#endif  
849 -} 1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_app_rtmp_conn.hpp>
  25 +
  26 +#include <arpa/inet.h>
  27 +#include <stdlib.h>
  28 +
  29 +using namespace std;
  30 +
  31 +#include <srs_kernel_error.hpp>
  32 +#include <srs_kernel_log.hpp>
  33 +#include <srs_protocol_rtmp.hpp>
  34 +#include <srs_protocol_rtmp_stack.hpp>
  35 +#include <srs_core_autofree.hpp>
  36 +#include <srs_app_source.hpp>
  37 +#include <srs_app_server.hpp>
  38 +#include <srs_app_pithy_print.hpp>
  39 +#include <srs_app_config.hpp>
  40 +#include <srs_app_refer.hpp>
  41 +#include <srs_app_hls.hpp>
  42 +#include <srs_app_http.hpp>
  43 +#include <srs_app_bandwidth.hpp>
  44 +#include <srs_app_socket.hpp>
  45 +
  46 +SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
  47 + : SrsConnection(srs_server, client_stfd)
  48 +{
  49 + ip = NULL;
  50 + req = new SrsRequest();
  51 + res = new SrsResponse();
  52 + skt = new SrsSocket(client_stfd);
  53 + rtmp = new SrsRtmpServer(skt);
  54 + refer = new SrsRefer();
  55 +#ifdef SRS_HTTP_CALLBACK
  56 + http_hooks = new SrsHttpHooks();
  57 +#endif
  58 + bandwidth = new SrsBandwidth();
  59 +
  60 + _srs_config->subscribe(this);
  61 +}
  62 +
  63 +SrsClient::~SrsClient()
  64 +{
  65 + _srs_config->unsubscribe(this);
  66 +
  67 + srs_freepa(ip);
  68 + srs_freep(req);
  69 + srs_freep(res);
  70 + srs_freep(rtmp);
  71 + srs_freep(skt);
  72 + srs_freep(refer);
  73 +#ifdef SRS_HTTP_CALLBACK
  74 + srs_freep(http_hooks);
  75 +#endif
  76 + srs_freep(bandwidth);
  77 +}
  78 +
  79 +// TODO: return detail message when error for client.
  80 +int SrsClient::do_cycle()
  81 +{
  82 + int ret = ERROR_SUCCESS;
  83 +
  84 + if ((ret = get_peer_ip()) != ERROR_SUCCESS) {
  85 + srs_error("get peer ip failed. ret=%d", ret);
  86 + return ret;
  87 + }
  88 + srs_trace("get peer ip success. ip=%s, send_to=%"PRId64", recv_to=%"PRId64"",
  89 + ip, SRS_SEND_TIMEOUT_US, SRS_RECV_TIMEOUT_US);
  90 +
  91 + rtmp->set_recv_timeout(SRS_RECV_TIMEOUT_US);
  92 + rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US);
  93 +
  94 + if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
  95 + srs_error("rtmp handshake failed. ret=%d", ret);
  96 + return ret;
  97 + }
  98 + srs_verbose("rtmp handshake success");
  99 +
  100 + if ((ret = rtmp->connect_app(req)) != ERROR_SUCCESS) {
  101 + srs_error("rtmp connect vhost/app failed. ret=%d", ret);
  102 + return ret;
  103 + }
  104 + srs_verbose("rtmp connect app success");
  105 +
  106 + // discovery vhost, resolve the vhost from config
  107 + SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req->vhost);
  108 + if (parsed_vhost) {
  109 + req->vhost = parsed_vhost->arg0();
  110 + }
  111 +
  112 + srs_info("discovery app success. schema=%s, vhost=%s, port=%s, app=%s",
  113 + req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str());
  114 +
  115 + if (req->schema.empty() || req->vhost.empty() || req->port.empty() || req->app.empty()) {
  116 + ret = ERROR_RTMP_REQ_TCURL;
  117 + srs_error("discovery tcUrl failed. "
  118 + "tcUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, ret=%d",
  119 + req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str(), ret);
  120 + return ret;
  121 + }
  122 +
  123 + // check vhost
  124 + if ((ret = check_vhost()) != ERROR_SUCCESS) {
  125 + srs_error("check vhost failed. ret=%d", ret);
  126 + return ret;
  127 + }
  128 + srs_verbose("check vhost success.");
  129 +
  130 + srs_trace("rtmp connect app success. "
  131 + "tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s",
  132 + req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
  133 + req->schema.c_str(), req->vhost.c_str(), req->port.c_str(),
  134 + req->app.c_str());
  135 +
  136 + ret = service_cycle();
  137 + on_close();
  138 +
  139 + return ret;
  140 +}
  141 +
  142 +int SrsClient::on_reload_vhost_removed(string vhost)
  143 +{
  144 + int ret = ERROR_SUCCESS;
  145 +
  146 + if (req->vhost != vhost) {
  147 + return ret;
  148 + }
  149 +
  150 + // if the vhost connected is removed, disconnect the client.
  151 + srs_trace("vhost %s removed/disabled, close client url=%s",
  152 + vhost.c_str(), req->get_stream_url().c_str());
  153 +
  154 + srs_close_stfd(stfd);
  155 +
  156 + return ret;
  157 +}
  158 +
  159 +int SrsClient::service_cycle()
  160 +{
  161 + int ret = ERROR_SUCCESS;
  162 +
  163 + if ((ret = rtmp->set_window_ack_size(2.5 * 1000 * 1000)) != ERROR_SUCCESS) {
  164 + srs_error("set window acknowledgement size failed. ret=%d", ret);
  165 + return ret;
  166 + }
  167 + srs_verbose("set window acknowledgement size success");
  168 +
  169 + if ((ret = rtmp->set_peer_bandwidth(2.5 * 1000 * 1000, 2)) != ERROR_SUCCESS) {
  170 + srs_error("set peer bandwidth failed. ret=%d", ret);
  171 + return ret;
  172 + }
  173 + srs_verbose("set peer bandwidth success");
  174 +
  175 + // do bandwidth test if connect to the vhost which is for bandwidth check.
  176 + if (_srs_config->get_bw_check_enabled(req->vhost)) {
  177 + return bandwidth->bandwidth_test(req, stfd, rtmp);
  178 + }
  179 +
  180 + if ((ret = rtmp->response_connect_app(req)) != ERROR_SUCCESS) {
  181 + srs_error("response connect app failed. ret=%d", ret);
  182 + return ret;
  183 + }
  184 + srs_verbose("response connect app success");
  185 +
  186 + if ((ret = rtmp->on_bw_done()) != ERROR_SUCCESS) {
  187 + srs_error("on_bw_done failed. ret=%d", ret);
  188 + return ret;
  189 + }
  190 + srs_verbose("on_bw_done success");
  191 +
  192 + while (true) {
  193 + ret = stream_service_cycle();
  194 +
  195 + // stream service must terminated with error, never success.
  196 + srs_assert(ret != ERROR_SUCCESS);
  197 +
  198 + // when not system control error, fatal error, return.
  199 + if (!srs_is_system_control_error(ret)) {
  200 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
  201 + srs_error("stream service cycle failed. ret=%d", ret);
  202 + }
  203 + return ret;
  204 + }
  205 +
  206 + // for republish, continue service
  207 + if (ret == ERROR_CONTROL_REPUBLISH) {
  208 + // set timeout to a larger value, wait for encoder to republish.
  209 + rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TIMEOUT_US);
  210 + rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TIMEOUT_US);
  211 +
  212 + srs_trace("control message(unpublish) accept, retry stream service.");
  213 + continue;
  214 + }
  215 +
  216 + // for "some" system control error,
  217 + // logical accept and retry stream service.
  218 + if (ret == ERROR_CONTROL_RTMP_CLOSE) {
  219 + // set timeout to a larger value, for user paused.
  220 + rtmp->set_recv_timeout(SRS_PAUSED_RECV_TIMEOUT_US);
  221 + rtmp->set_send_timeout(SRS_PAUSED_SEND_TIMEOUT_US);
  222 +
  223 + srs_trace("control message(close) accept, retry stream service.");
  224 + continue;
  225 + }
  226 +
  227 + // for other system control message, fatal error.
  228 + srs_error("control message(%d) reject as error. ret=%d", ret, ret);
  229 + return ret;
  230 + }
  231 +
  232 + return ret;
  233 +}
  234 +
  235 +int SrsClient::stream_service_cycle()
  236 +{
  237 + int ret = ERROR_SUCCESS;
  238 +
  239 + SrsClientType type;
  240 + if ((ret = rtmp->identify_client(res->stream_id, type, req->stream)) != ERROR_SUCCESS) {
  241 + srs_error("identify client failed. ret=%d", ret);
  242 + return ret;
  243 + }
  244 + req->strip();
  245 + srs_trace("identify client success. type=%s, stream_name=%s",
  246 + srs_client_type_string(type).c_str(), req->stream.c_str());
  247 +
  248 + // client is identified, set the timeout to service timeout.
  249 + rtmp->set_recv_timeout(SRS_RECV_TIMEOUT_US);
  250 + rtmp->set_send_timeout(SRS_SEND_TIMEOUT_US);
  251 +
  252 + // set chunk size to larger.
  253 + int chunk_size = _srs_config->get_chunk_size(req->vhost);
  254 + if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) {
  255 + srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret);
  256 + return ret;
  257 + }
  258 + srs_trace("set chunk_size=%d success", chunk_size);
  259 +
  260 + // find a source to serve.
  261 + SrsSource* source = SrsSource::find(req);
  262 + srs_assert(source != NULL);
  263 +
  264 + // check publish available.
  265 + if (type != SrsClientPlay && !source->can_publish()) {
  266 + ret = ERROR_SYSTEM_STREAM_BUSY;
  267 + srs_warn("stream %s is already publishing. ret=%d",
  268 + req->get_stream_url().c_str(), ret);
  269 + // to delay request
  270 + st_usleep(SRS_STREAM_BUSY_SLEEP_US);
  271 + return ret;
  272 + }
  273 +
  274 + bool enabled_cache = _srs_config->get_gop_cache(req->vhost);
  275 + srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
  276 + source->set_cache(enabled_cache);
  277 +
  278 + switch (type) {
  279 + case SrsClientPlay: {
  280 + srs_verbose("start to play stream %s.", req->stream.c_str());
  281 +
  282 + if ((ret = rtmp->start_play(res->stream_id)) != ERROR_SUCCESS) {
  283 + srs_error("start to play stream failed. ret=%d", ret);
  284 + return ret;
  285 + }
  286 + if ((ret = on_play()) != ERROR_SUCCESS) {
  287 + srs_error("http hook on_play failed. ret=%d", ret);
  288 + return ret;
  289 + }
  290 + srs_info("start to play stream %s success", req->stream.c_str());
  291 + ret = playing(source);
  292 + on_stop();
  293 + return ret;
  294 + }
  295 + case SrsClientFMLEPublish: {
  296 + srs_verbose("FMLE start to publish stream %s.", req->stream.c_str());
  297 +
  298 + if ((ret = rtmp->start_fmle_publish(res->stream_id)) != ERROR_SUCCESS) {
  299 + srs_error("start to publish stream failed. ret=%d", ret);
  300 + return ret;
  301 + }
  302 + if ((ret = on_publish()) != ERROR_SUCCESS) {
  303 + srs_error("http hook on_publish failed. ret=%d", ret);
  304 + return ret;
  305 + }
  306 + srs_info("start to publish stream %s success", req->stream.c_str());
  307 + ret = fmle_publish(source);
  308 + source->on_unpublish();
  309 + on_unpublish();
  310 + return ret;
  311 + }
  312 + case SrsClientFlashPublish: {
  313 + srs_verbose("flash start to publish stream %s.", req->stream.c_str());
  314 +
  315 + if ((ret = rtmp->start_flash_publish(res->stream_id)) != ERROR_SUCCESS) {
  316 + srs_error("flash start to publish stream failed. ret=%d", ret);
  317 + return ret;
  318 + }
  319 + if ((ret = on_publish()) != ERROR_SUCCESS) {
  320 + srs_error("http hook on_publish failed. ret=%d", ret);
  321 + return ret;
  322 + }
  323 + srs_info("flash start to publish stream %s success", req->stream.c_str());
  324 + ret = flash_publish(source);
  325 + source->on_unpublish();
  326 + on_unpublish();
  327 + return ret;
  328 + }
  329 + default: {
  330 + ret = ERROR_SYSTEM_CLIENT_INVALID;
  331 + srs_info("invalid client type=%d. ret=%d", type, ret);
  332 + return ret;
  333 + }
  334 + }
  335 +
  336 + return ret;
  337 +}
  338 +
  339 +int SrsClient::check_vhost()
  340 +{
  341 + int ret = ERROR_SUCCESS;
  342 +
  343 + srs_assert(req != NULL);
  344 +
  345 + SrsConfDirective* vhost = _srs_config->get_vhost(req->vhost);
  346 + if (vhost == NULL) {
  347 + ret = ERROR_RTMP_VHOST_NOT_FOUND;
  348 + srs_error("vhost %s not found. ret=%d", req->vhost.c_str(), ret);
  349 + return ret;
  350 + }
  351 +
  352 + if (!_srs_config->get_vhost_enabled(req->vhost)) {
  353 + ret = ERROR_RTMP_VHOST_NOT_FOUND;
  354 + srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);
  355 + return ret;
  356 + }
  357 +
  358 + if (req->vhost != vhost->arg0()) {
  359 + srs_trace("vhost change from %s to %s", req->vhost.c_str(), vhost->arg0().c_str());
  360 + req->vhost = vhost->arg0();
  361 + }
  362 +
  363 + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer(req->vhost))) != ERROR_SUCCESS) {
  364 + srs_error("check refer failed. ret=%d", ret);
  365 + return ret;
  366 + }
  367 + srs_verbose("check refer success.");
  368 +
  369 + if ((ret = on_connect()) != ERROR_SUCCESS) {
  370 + return ret;
  371 + }
  372 +
  373 + return ret;
  374 +}
  375 +
  376 +int SrsClient::playing(SrsSource* source)
  377 +{
  378 + int ret = ERROR_SUCCESS;
  379 +
  380 + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_play(req->vhost))) != ERROR_SUCCESS) {
  381 + srs_error("check play_refer failed. ret=%d", ret);
  382 + return ret;
  383 + }
  384 + srs_verbose("check play_refer success.");
  385 +
  386 + SrsConsumer* consumer = NULL;
  387 + if ((ret = source->create_consumer(consumer)) != ERROR_SUCCESS) {
  388 + srs_error("create consumer failed. ret=%d", ret);
  389 + return ret;
  390 + }
  391 +
  392 + srs_assert(consumer != NULL);
  393 + SrsAutoFree(SrsConsumer, consumer, false);
  394 + srs_verbose("consumer created success.");
  395 +
  396 + rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_US);
  397 +
  398 + SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER);
  399 +
  400 + while (true) {
  401 + pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000);
  402 +
  403 + // switch to other st-threads.
  404 + st_usleep(0);
  405 +
  406 + // read from client.
  407 + int ctl_msg_ret = ERROR_SUCCESS;
  408 + if (true) {
  409 + SrsCommonMessage* msg = NULL;
  410 + ctl_msg_ret = ret = rtmp->recv_message(&msg);
  411 +
  412 + srs_verbose("play loop recv message. ret=%d", ret);
  413 + if (ret != ERROR_SUCCESS && ret != ERROR_SOCKET_TIMEOUT) {
  414 + if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
  415 + srs_error("recv client control message failed. ret=%d", ret);
  416 + }
  417 + return ret;
  418 + }
  419 + if ((ret = process_play_control_msg(consumer, msg)) != ERROR_SUCCESS) {
  420 + if (!srs_is_system_control_error(ret)) {
  421 + srs_error("process play control message failed. ret=%d", ret);
  422 + }
  423 + return ret;
  424 + }
  425 + }
  426 +
  427 + // get messages from consumer.
  428 + SrsSharedPtrMessage** msgs = NULL;
  429 + int count = 0;
  430 + if ((ret = consumer->get_packets(0, msgs, count)) != ERROR_SUCCESS) {
  431 + srs_error("get messages from consumer failed. ret=%d", ret);
  432 + return ret;
  433 + }
  434 +
  435 + // reportable
  436 + if (pithy_print.can_print()) {
  437 + srs_trace("-> time=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
  438 + pithy_print.get_age(), ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
  439 + }
  440 +
  441 + if (count <= 0) {
  442 + srs_verbose("no packets in queue.");
  443 + continue;
  444 + }
  445 + SrsAutoFree(SrsSharedPtrMessage*, msgs, true);
  446 +
  447 + // sendout messages
  448 + for (int i = 0; i < count; i++) {
  449 + SrsSharedPtrMessage* msg = msgs[i];
  450 +
  451 + // the send_message will free the msg,
  452 + // so set the msgs[i] to NULL.
  453 + msgs[i] = NULL;
  454 +
  455 + if ((ret = rtmp->send_message(msg)) != ERROR_SUCCESS) {
  456 + srs_error("send message to client failed. ret=%d", ret);
  457 + return ret;
  458 + }
  459 + }
  460 + }
  461 +
  462 + return ret;
  463 +}
  464 +
  465 +int SrsClient::fmle_publish(SrsSource* source)
  466 +{
  467 + int ret = ERROR_SUCCESS;
  468 +
  469 + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) {
  470 + srs_error("fmle check publish_refer failed. ret=%d", ret);
  471 + return ret;
  472 + }
  473 + srs_verbose("fmle check publish_refer success.");
  474 +
  475 + SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
  476 +
  477 + // notify the hls to prepare when publish start.
  478 + if ((ret = source->on_publish(req)) != ERROR_SUCCESS) {
  479 + srs_error("fmle hls on_publish failed. ret=%d", ret);
  480 + return ret;
  481 + }
  482 + srs_verbose("fmle hls on_publish success.");
  483 +
  484 + while (true) {
  485 + // switch to other st-threads.
  486 + st_usleep(0);
  487 +
  488 + SrsCommonMessage* msg = NULL;
  489 + if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
  490 + srs_error("fmle recv identify client message failed. ret=%d", ret);
  491 + return ret;
  492 + }
  493 +
  494 + SrsAutoFree(SrsCommonMessage, msg, false);
  495 +
  496 + pithy_print.set_age(msg->header.timestamp);
  497 +
  498 + // reportable
  499 + if (pithy_print.can_print()) {
  500 + srs_trace("<- time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
  501 + pithy_print.get_age(), rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
  502 + }
  503 +
  504 + // process UnPublish event.
  505 + if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
  506 + if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {
  507 + srs_error("fmle decode unpublish message failed. ret=%d", ret);
  508 + return ret;
  509 + }
  510 +
  511 + SrsPacket* pkt = msg->get_packet();
  512 + if (dynamic_cast<SrsFMLEStartPacket*>(pkt)) {
  513 + SrsFMLEStartPacket* unpublish = dynamic_cast<SrsFMLEStartPacket*>(pkt);
  514 + if ((ret = rtmp->fmle_unpublish(res->stream_id, unpublish->transaction_id)) != ERROR_SUCCESS) {
  515 + return ret;
  516 + }
  517 + return ERROR_CONTROL_REPUBLISH;
  518 + }
  519 +
  520 + srs_trace("fmle ignore AMF0/AMF3 command message.");
  521 + continue;
  522 + }
  523 +
  524 + // video, audio, data message
  525 + if ((ret = process_publish_message(source, msg)) != ERROR_SUCCESS) {
  526 + srs_error("fmle process publish message failed. ret=%d", ret);
  527 + return ret;
  528 + }
  529 + }
  530 +
  531 + return ret;
  532 +}
  533 +
  534 +int SrsClient::flash_publish(SrsSource* source)
  535 +{
  536 + int ret = ERROR_SUCCESS;
  537 +
  538 + if ((ret = refer->check(req->pageUrl, _srs_config->get_refer_publish(req->vhost))) != ERROR_SUCCESS) {
  539 + srs_error("flash check publish_refer failed. ret=%d", ret);
  540 + return ret;
  541 + }
  542 + srs_verbose("flash check publish_refer success.");
  543 +
  544 + SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
  545 +
  546 + // notify the hls to prepare when publish start.
  547 + if ((ret = source->on_publish(req)) != ERROR_SUCCESS) {
  548 + srs_error("flash hls on_publish failed. ret=%d", ret);
  549 + return ret;
  550 + }
  551 + srs_verbose("flash hls on_publish success.");
  552 +
  553 + while (true) {
  554 + // switch to other st-threads.
  555 + st_usleep(0);
  556 +
  557 + SrsCommonMessage* msg = NULL;
  558 + if ((ret = rtmp->recv_message(&msg)) != ERROR_SUCCESS) {
  559 + if (!srs_is_client_gracefully_close(ret)) {
  560 + srs_error("flash recv identify client message failed. ret=%d", ret);
  561 + }
  562 + return ret;
  563 + }
  564 +
  565 + SrsAutoFree(SrsCommonMessage, msg, false);
  566 +
  567 + pithy_print.set_age(msg->header.timestamp);
  568 +
  569 + // reportable
  570 + if (pithy_print.can_print()) {
  571 + srs_trace("<- time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
  572 + pithy_print.get_age(), rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
  573 + }
  574 +
  575 + // process UnPublish event.
  576 + if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) {
  577 + if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {
  578 + srs_error("flash decode unpublish message failed. ret=%d", ret);
  579 + return ret;
  580 + }
  581 +
  582 + // flash unpublish.
  583 + // TODO: maybe need to support republish.
  584 + srs_trace("flash flash publish finished.");
  585 + return ERROR_CONTROL_REPUBLISH;
  586 + }
  587 +
  588 + // video, audio, data message
  589 + if ((ret = process_publish_message(source, msg)) != ERROR_SUCCESS) {
  590 + srs_error("flash process publish message failed. ret=%d", ret);
  591 + return ret;
  592 + }
  593 + }
  594 +
  595 + return ret;
  596 +}
  597 +
  598 +int SrsClient::process_publish_message(SrsSource* source, SrsCommonMessage* msg)
  599 +{
  600 + int ret = ERROR_SUCCESS;
  601 +
  602 + // process audio packet
  603 + if (msg->header.is_audio()) {
  604 + if ((ret = source->on_audio(msg)) != ERROR_SUCCESS) {
  605 + srs_error("source process audio message failed. ret=%d", ret);
  606 + return ret;
  607 + }
  608 + }
  609 + // process video packet
  610 + if (msg->header.is_video()) {
  611 + if ((ret = source->on_video(msg)) != ERROR_SUCCESS) {
  612 + srs_error("source process video message failed. ret=%d", ret);
  613 + return ret;
  614 + }
  615 + }
  616 +
  617 + // process onMetaData
  618 + if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) {
  619 + if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {
  620 + srs_error("decode onMetaData message failed. ret=%d", ret);
  621 + return ret;
  622 + }
  623 +
  624 + SrsPacket* pkt = msg->get_packet();
  625 + if (dynamic_cast<SrsOnMetaDataPacket*>(pkt)) {
  626 + SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt);
  627 + if ((ret = source->on_meta_data(msg, metadata)) != ERROR_SUCCESS) {
  628 + srs_error("source process onMetaData message failed. ret=%d", ret);
  629 + return ret;
  630 + }
  631 + srs_trace("process onMetaData message success.");
  632 + return ret;
  633 + }
  634 +
  635 + srs_trace("ignore AMF0/AMF3 data message.");
  636 + return ret;
  637 + }
  638 +
  639 + return ret;
  640 +}
  641 +
  642 +int SrsClient::get_peer_ip()
  643 +{
  644 + int ret = ERROR_SUCCESS;
  645 +
  646 + int fd = st_netfd_fileno(stfd);
  647 +
  648 + // discovery client information
  649 + sockaddr_in addr;
  650 + socklen_t addrlen = sizeof(addr);
  651 + if (getpeername(fd, (sockaddr*)&addr, &addrlen) == -1) {
  652 + ret = ERROR_SOCKET_GET_PEER_NAME;
  653 + srs_error("discovery client information failed. ret=%d", ret);
  654 + return ret;
  655 + }
  656 + srs_verbose("get peer name success.");
  657 +
  658 + // ip v4 or v6
  659 + char buf[INET6_ADDRSTRLEN];
  660 + memset(buf, 0, sizeof(buf));
  661 +
  662 + if ((inet_ntop(addr.sin_family, &addr.sin_addr, buf, sizeof(buf))) == NULL) {
  663 + ret = ERROR_SOCKET_GET_PEER_IP;
  664 + srs_error("convert client information failed. ret=%d", ret);
  665 + return ret;
  666 + }
  667 + srs_verbose("get peer ip of client ip=%s, fd=%d", buf, fd);
  668 +
  669 + ip = new char[strlen(buf) + 1];
  670 + strcpy(ip, buf);
  671 +
  672 + srs_verbose("get peer ip success. ip=%s, fd=%d", ip, fd);
  673 +
  674 + return ret;
  675 +}
  676 +
  677 +int SrsClient::process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg)
  678 +{
  679 + int ret = ERROR_SUCCESS;
  680 +
  681 + if (!msg) {
  682 + srs_verbose("ignore all empty message.");
  683 + return ret;
  684 + }
  685 + SrsAutoFree(SrsCommonMessage, msg, false);
  686 +
  687 + if (!msg->header.is_amf0_command() && !msg->header.is_amf3_command()) {
  688 + srs_info("ignore all message except amf0/amf3 command.");
  689 + return ret;
  690 + }
  691 +
  692 + if ((ret = msg->decode_packet(rtmp->get_protocol())) != ERROR_SUCCESS) {
  693 + srs_error("decode the amf0/amf3 command packet failed. ret=%d", ret);
  694 + return ret;
  695 + }
  696 + srs_info("decode the amf0/amf3 command packet success.");
  697 +
  698 + SrsCloseStreamPacket* close = dynamic_cast<SrsCloseStreamPacket*>(msg->get_packet());
  699 + if (close) {
  700 + ret = ERROR_CONTROL_RTMP_CLOSE;
  701 + srs_trace("system control message: rtmp close stream. ret=%d", ret);
  702 + return ret;
  703 + }
  704 +
  705 + SrsPausePacket* pause = dynamic_cast<SrsPausePacket*>(msg->get_packet());
  706 + if (!pause) {
  707 + srs_info("ignore all amf0/amf3 command except pause.");
  708 + return ret;
  709 + }
  710 +
  711 + if ((ret = rtmp->on_play_client_pause(res->stream_id, pause->is_pause)) != ERROR_SUCCESS) {
  712 + srs_error("rtmp process play client pause failed. ret=%d", ret);
  713 + return ret;
  714 + }
  715 +
  716 + if ((ret = consumer->on_play_client_pause(pause->is_pause)) != ERROR_SUCCESS) {
  717 + srs_error("consumer process play client pause failed. ret=%d", ret);
  718 + return ret;
  719 + }
  720 + srs_info("process pause success, is_pause=%d, time=%d.", pause->is_pause, pause->time_ms);
  721 +
  722 + return ret;
  723 +}
  724 +
  725 +int SrsClient::on_connect()
  726 +{
  727 + int ret = ERROR_SUCCESS;
  728 +
  729 +#ifdef SRS_HTTP_CALLBACK
  730 + // HTTP: on_connect
  731 + SrsConfDirective* on_connect = _srs_config->get_vhost_on_connect(req->vhost);
  732 + if (!on_connect) {
  733 + srs_info("ignore the empty http callback: on_connect");
  734 + return ret;
  735 + }
  736 +
  737 + for (int i = 0; i < (int)on_connect->args.size(); i++) {
  738 + std::string url = on_connect->args.at(i);
  739 + if ((ret = http_hooks->on_connect(url, connection_id, ip, req)) != ERROR_SUCCESS) {
  740 + srs_error("hook client on_connect failed. url=%s, ret=%d", url.c_str(), ret);
  741 + return ret;
  742 + }
  743 + }
  744 +#endif
  745 +
  746 + return ret;
  747 +}
  748 +
  749 +void SrsClient::on_close()
  750 +{
  751 +#ifdef SRS_HTTP_CALLBACK
  752 + // whatever the ret code, notify the api hooks.
  753 + // HTTP: on_close
  754 + SrsConfDirective* on_close = _srs_config->get_vhost_on_close(req->vhost);
  755 + if (!on_close) {
  756 + srs_info("ignore the empty http callback: on_close");
  757 + return;
  758 + }
  759 +
  760 + for (int i = 0; i < (int)on_close->args.size(); i++) {
  761 + std::string url = on_close->args.at(i);
  762 + http_hooks->on_close(url, connection_id, ip, req);
  763 + }
  764 +#endif
  765 +}
  766 +
  767 +int SrsClient::on_publish()
  768 +{
  769 + int ret = ERROR_SUCCESS;
  770 +
  771 +#ifdef SRS_HTTP_CALLBACK
  772 + // HTTP: on_publish
  773 + SrsConfDirective* on_publish = _srs_config->get_vhost_on_publish(req->vhost);
  774 + if (!on_publish) {
  775 + srs_info("ignore the empty http callback: on_publish");
  776 + return ret;
  777 + }
  778 +
  779 + for (int i = 0; i < (int)on_publish->args.size(); i++) {
  780 + std::string url = on_publish->args.at(i);
  781 + if ((ret = http_hooks->on_publish(url, connection_id, ip, req)) != ERROR_SUCCESS) {
  782 + srs_error("hook client on_publish failed. url=%s, ret=%d", url.c_str(), ret);
  783 + return ret;
  784 + }
  785 + }
  786 +#endif
  787 +
  788 + return ret;
  789 +}
  790 +
  791 +void SrsClient::on_unpublish()
  792 +{
  793 +#ifdef SRS_HTTP_CALLBACK
  794 + // whatever the ret code, notify the api hooks.
  795 + // HTTP: on_unpublish
  796 + SrsConfDirective* on_unpublish = _srs_config->get_vhost_on_unpublish(req->vhost);
  797 + if (!on_unpublish) {
  798 + srs_info("ignore the empty http callback: on_unpublish");
  799 + return;
  800 + }
  801 +
  802 + for (int i = 0; i < (int)on_unpublish->args.size(); i++) {
  803 + std::string url = on_unpublish->args.at(i);
  804 + http_hooks->on_unpublish(url, connection_id, ip, req);
  805 + }
  806 +#endif
  807 +}
  808 +
  809 +int SrsClient::on_play()
  810 +{
  811 + int ret = ERROR_SUCCESS;
  812 +
  813 +#ifdef SRS_HTTP_CALLBACK
  814 + // HTTP: on_play
  815 + SrsConfDirective* on_play = _srs_config->get_vhost_on_play(req->vhost);
  816 + if (!on_play) {
  817 + srs_info("ignore the empty http callback: on_play");
  818 + return ret;
  819 + }
  820 +
  821 + for (int i = 0; i < (int)on_play->args.size(); i++) {
  822 + std::string url = on_play->args.at(i);
  823 + if ((ret = http_hooks->on_play(url, connection_id, ip, req)) != ERROR_SUCCESS) {
  824 + srs_error("hook client on_play failed. url=%s, ret=%d", url.c_str(), ret);
  825 + return ret;
  826 + }
  827 + }
  828 +#endif
  829 +
  830 + return ret;
  831 +}
  832 +
  833 +void SrsClient::on_stop()
  834 +{
  835 +#ifdef SRS_HTTP_CALLBACK
  836 + // whatever the ret code, notify the api hooks.
  837 + // HTTP: on_stop
  838 + SrsConfDirective* on_stop = _srs_config->get_vhost_on_stop(req->vhost);
  839 + if (!on_stop) {
  840 + srs_info("ignore the empty http callback: on_stop");
  841 + return;
  842 + }
  843 +
  844 + for (int i = 0; i < (int)on_stop->args.size(); i++) {
  845 + std::string url = on_stop->args.at(i);
  846 + http_hooks->on_stop(url, connection_id, ip, req);
  847 + }
  848 +#endif
  849 +
  850 + return;
  851 +}
@@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */ 22 */
23 23
24 -#ifndef SRS_APP_CLIENT_HPP  
25 -#define SRS_APP_CLIENT_HPP 24 +#ifndef SRS_APP_RTMP_CONN_HPP
  25 +#define SRS_APP_RTMP_CONN_HPP
26 26
27 /* 27 /*
28 -#include <srs_app_client.hpp> 28 +#include <srs_app_rtmp_conn.hpp>
29 */ 29 */
30 30
31 #include <srs_core.hpp> 31 #include <srs_core.hpp>
@@ -35,7 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -35,7 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 35
36 #include <srs_kernel_log.hpp> 36 #include <srs_kernel_log.hpp>
37 #include <srs_kernel_error.hpp> 37 #include <srs_kernel_error.hpp>
38 -#include <srs_app_client.hpp> 38 +#include <srs_app_rtmp_conn.hpp>
39 #include <srs_app_config.hpp> 39 #include <srs_app_config.hpp>
40 #include <srs_kernel_utility.hpp> 40 #include <srs_kernel_utility.hpp>
41 41
@@ -118,7 +118,7 @@ int SrsListener::listen(int _port) @@ -118,7 +118,7 @@ int SrsListener::listen(int _port)
118 } 118 }
119 srs_verbose("create st listen thread success."); 119 srs_verbose("create st listen thread success.");
120 120
121 - srs_trace("server started, listen at port=%d, fd=%d", port, fd); 121 + srs_trace("server started, listen at port=%d, type=%d, fd=%d", port, type, fd);
122 122
123 return ret; 123 return ret;
124 } 124 }
@@ -301,7 +301,29 @@ int SrsServer::listen() @@ -301,7 +301,29 @@ int SrsServer::listen()
301 301
302 int port = ::atoi(conf->args.at(i).c_str()); 302 int port = ::atoi(conf->args.at(i).c_str());
303 if ((ret = listener->listen(port)) != ERROR_SUCCESS) { 303 if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
304 - srs_error("listen at port %d failed. ret=%d", port, ret); 304 + srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret);
  305 + return ret;
  306 + }
  307 + }
  308 +
  309 + if (_srs_config->get_http_api_enabled()) {
  310 + SrsListener* listener = new SrsListener(this, SrsListenerHttpApi);
  311 + listeners.push_back(listener);
  312 +
  313 + int port = _srs_config->get_http_api_listen();
  314 + if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
  315 + srs_error("HTTP api listen at port %d failed. ret=%d", port, ret);
  316 + return ret;
  317 + }
  318 + }
  319 +
  320 + if (_srs_config->get_http_stream_enabled()) {
  321 + SrsListener* listener = new SrsListener(this, SrsListenerHttpStream);
  322 + listeners.push_back(listener);
  323 +
  324 + int port = _srs_config->get_http_stream_listen();
  325 + if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
  326 + srs_error("HTTP stream listen at port %d failed. ret=%d", port, ret);
305 return ret; 327 return ret;
306 } 328 }
307 } 329 }
@@ -413,6 +435,8 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) @@ -413,6 +435,8 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
413 SrsConnection* conn = NULL; 435 SrsConnection* conn = NULL;
414 if (type == SrsListenerStream) { 436 if (type == SrsListenerStream) {
415 conn = new SrsClient(this, client_stfd); 437 conn = new SrsClient(this, client_stfd);
  438 + } else if (type == SrsListenerHttpApi) {
  439 + } else if (type == SrsListenerHttpStream) {
416 } else { 440 } else {
417 // TODO: FIXME: handler others 441 // TODO: FIXME: handler others
418 } 442 }
@@ -42,7 +42,8 @@ class SrsConnection; @@ -42,7 +42,8 @@ class SrsConnection;
42 enum SrsListenerType 42 enum SrsListenerType
43 { 43 {
44 SrsListenerStream = 0, 44 SrsListenerStream = 0,
45 - SrsListenerApi 45 + SrsListenerHttpApi,
  46 + SrsListenerHttpStream
46 }; 47 };
47 48
48 class SrsListener : public ISrsThreadHandler 49 class SrsListener : public ISrsThreadHandler
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "36" 34 +#define VERSION_REVISION "37"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "srs" 37 #define RTMP_SIG_SRS_KEY "srs"
1 file 1 file
2 - main readonly separator,  
3 - ..\main\srs_main_server.cpp,  
4 - ..\main\srs_main_bandcheck.cpp,  
5 - auto readonly separator,  
6 - ..\..\objs\srs_auto_headers.hpp,  
7 - libs readonly separator,  
8 - ..\libs\srs_librtmp.hpp,  
9 - ..\libs\srs_librtmp.cpp,  
10 - ..\libs\srs_lib_simple_socket.hpp,  
11 - ..\libs\srs_lib_simple_socket.cpp,  
12 - core readonly separator,  
13 - ..\core\srs_core.hpp,  
14 - ..\core\srs_core.cpp,  
15 - ..\core\srs_core_autofree.hpp,  
16 - ..\core\srs_core_autofree.cpp,  
17 - kernel readonly separator,  
18 - ..\kernel\srs_kernel_buffer.hpp,  
19 - ..\kernel\srs_kernel_buffer.cpp,  
20 - ..\kernel\srs_kernel_error.hpp,  
21 - ..\kernel\srs_kernel_error.cpp,  
22 - ..\kernel\srs_kernel_log.hpp,  
23 - ..\kernel\srs_kernel_log.cpp,  
24 - ..\kernel\srs_kernel_stream.hpp,  
25 - ..\kernel\srs_kernel_stream.cpp,  
26 - ..\kernel\srs_kernel_utility.hpp,  
27 - ..\kernel\srs_kernel_utility.cpp,  
28 - rtmp-protocol readonly separator,  
29 - ..\rtmp\srs_protocol_amf0.hpp,  
30 - ..\rtmp\srs_protocol_amf0.cpp,  
31 - ..\rtmp\srs_protocol_handshake.hpp,  
32 - ..\rtmp\srs_protocol_handshake.cpp,  
33 - ..\rtmp\srs_protocol_io.hpp,  
34 - ..\rtmp\srs_protocol_io.cpp,  
35 - ..\rtmp\srs_protocol_rtmp.hpp,  
36 - ..\rtmp\srs_protocol_rtmp.cpp,  
37 - ..\rtmp\srs_protocol_rtmp_stack.hpp,  
38 - ..\rtmp\srs_protocol_rtmp_stack.cpp,  
39 - ..\rtmp\srs_protocol_utility.hpp,  
40 - ..\rtmp\srs_protocol_utility.cpp,  
41 - app readonly separator,  
42 - ..\app\srs_app_bandwidth.hpp,  
43 - ..\app\srs_app_bandwidth.cpp,  
44 - ..\app\srs_app_client.hpp,  
45 - ..\app\srs_app_client.cpp,  
46 - ..\app\srs_app_codec.hpp,  
47 - ..\app\srs_app_codec.cpp,  
48 - ..\app\srs_app_conn.hpp,  
49 - ..\app\srs_app_conn.cpp,  
50 - ..\app\srs_app_config.hpp,  
51 - ..\app\srs_app_config.cpp,  
52 - ..\app\srs_app_encoder.hpp,  
53 - ..\app\srs_app_encoder.cpp,  
54 - ..\app\srs_app_forward.hpp,  
55 - ..\app\srs_app_forward.cpp,  
56 - ..\app\srs_app_hls.hpp,  
57 - ..\app\srs_app_hls.cpp,  
58 - ..\app\srs_app_http.hpp,  
59 - ..\app\srs_app_http.cpp,  
60 - ..\app\srs_app_log.hpp,  
61 - ..\app\srs_app_log.cpp,  
62 - ..\app\srs_app_refer.hpp,  
63 - ..\app\srs_app_refer.cpp,  
64 - ..\app\srs_app_reload.hpp,  
65 - ..\app\srs_app_reload.cpp,  
66 - ..\app\srs_app_pithy_print.hpp,  
67 - ..\app\srs_app_pithy_print.cpp,  
68 - ..\app\srs_app_thread.hpp,  
69 - ..\app\srs_app_thread.cpp,  
70 - ..\app\srs_app_server.hpp,  
71 - ..\app\srs_app_server.cpp,  
72 - ..\app\srs_app_st.hpp,  
73 - ..\app\srs_app_st.cpp,  
74 - ..\app\srs_app_socket.hpp,  
75 - ..\app\srs_app_socket.cpp,  
76 - ..\app\srs_app_source.hpp,  
77 - ..\app\srs_app_source.cpp,  
78 - utest readonly separator,  
79 - ..\utest\srs_utest.hpp,  
80 - ..\utest\srs_utest.cpp,  
81 - ..\utest\srs_utest_amf0.hpp,  
82 - ..\utest\srs_utest_amf0.cpp,  
83 - ..\utest\srs_utest_handshake.hpp,  
84 - ..\utest\srs_utest_handshake.cpp,  
85 - research readonly separator,  
86 - ..\..\research\librtmp\srs_play.c,  
87 - ..\..\research\librtmp\srs_publish.c,  
88 - ..\..\research\hls\ts_info.cc; 2 + main readonly separator,
  3 + ..\main\srs_main_server.cpp,
  4 + ..\main\srs_main_bandcheck.cpp,
  5 + auto readonly separator,
  6 + ..\..\objs\srs_auto_headers.hpp,
  7 + libs readonly separator,
  8 + ..\libs\srs_librtmp.hpp,
  9 + ..\libs\srs_librtmp.cpp,
  10 + ..\libs\srs_lib_simple_socket.hpp,
  11 + ..\libs\srs_lib_simple_socket.cpp,
  12 + core readonly separator,
  13 + ..\core\srs_core.hpp,
  14 + ..\core\srs_core.cpp,
  15 + ..\core\srs_core_autofree.hpp,
  16 + ..\core\srs_core_autofree.cpp,
  17 + kernel readonly separator,
  18 + ..\kernel\srs_kernel_buffer.hpp,
  19 + ..\kernel\srs_kernel_buffer.cpp,
  20 + ..\kernel\srs_kernel_error.hpp,
  21 + ..\kernel\srs_kernel_error.cpp,
  22 + ..\kernel\srs_kernel_log.hpp,
  23 + ..\kernel\srs_kernel_log.cpp,
  24 + ..\kernel\srs_kernel_stream.hpp,
  25 + ..\kernel\srs_kernel_stream.cpp,
  26 + ..\kernel\srs_kernel_utility.hpp,
  27 + ..\kernel\srs_kernel_utility.cpp,
  28 + rtmp-protocol readonly separator,
  29 + ..\rtmp\srs_protocol_amf0.hpp,
  30 + ..\rtmp\srs_protocol_amf0.cpp,
  31 + ..\rtmp\srs_protocol_handshake.hpp,
  32 + ..\rtmp\srs_protocol_handshake.cpp,
  33 + ..\rtmp\srs_protocol_io.hpp,
  34 + ..\rtmp\srs_protocol_io.cpp,
  35 + ..\rtmp\srs_protocol_rtmp.hpp,
  36 + ..\rtmp\srs_protocol_rtmp.cpp,
  37 + ..\rtmp\srs_protocol_rtmp_stack.hpp,
  38 + ..\rtmp\srs_protocol_rtmp_stack.cpp,
  39 + ..\rtmp\srs_protocol_utility.hpp,
  40 + ..\rtmp\srs_protocol_utility.cpp,
  41 + app readonly separator,
  42 + ..\app\srs_app_bandwidth.hpp,
  43 + ..\app\srs_app_bandwidth.cpp,
  44 + ..\app\srs_app_codec.hpp,
  45 + ..\app\srs_app_codec.cpp,
  46 + ..\app\srs_app_conn.hpp,
  47 + ..\app\srs_app_conn.cpp,
  48 + ..\app\srs_app_config.hpp,
  49 + ..\app\srs_app_config.cpp,
  50 + ..\app\srs_app_encoder.hpp,
  51 + ..\app\srs_app_encoder.cpp,
  52 + ..\app\srs_app_forward.hpp,
  53 + ..\app\srs_app_forward.cpp,
  54 + ..\app\srs_app_hls.hpp,
  55 + ..\app\srs_app_hls.cpp,
  56 + ..\app\srs_app_http.hpp,
  57 + ..\app\srs_app_http.cpp,
  58 + ..\app\srs_app_http_api.hpp,
  59 + ..\app\srs_app_http_api.cpp,
  60 + ..\app\srs_app_http_conn.hpp,
  61 + ..\app\srs_app_http_conn.cpp,
  62 + ..\app\srs_app_log.hpp,
  63 + ..\app\srs_app_log.cpp,
  64 + ..\app\srs_app_refer.hpp,
  65 + ..\app\srs_app_refer.cpp,
  66 + ..\app\srs_app_reload.hpp,
  67 + ..\app\srs_app_reload.cpp,
  68 + ..\app\srs_app_rtmp_conn.hpp,
  69 + ..\app\srs_app_rtmp_conn.cpp,
  70 + ..\app\srs_app_pithy_print.hpp,
  71 + ..\app\srs_app_pithy_print.cpp,
  72 + ..\app\srs_app_thread.hpp,
  73 + ..\app\srs_app_thread.cpp,
  74 + ..\app\srs_app_server.hpp,
  75 + ..\app\srs_app_server.cpp,
  76 + ..\app\srs_app_st.hpp,
  77 + ..\app\srs_app_st.cpp,
  78 + ..\app\srs_app_socket.hpp,
  79 + ..\app\srs_app_socket.cpp,
  80 + ..\app\srs_app_source.hpp,
  81 + ..\app\srs_app_source.cpp,
  82 + utest readonly separator,
  83 + ..\utest\srs_utest.hpp,
  84 + ..\utest\srs_utest.cpp,
  85 + ..\utest\srs_utest_amf0.hpp,
  86 + ..\utest\srs_utest_amf0.cpp,
  87 + ..\utest\srs_utest_handshake.hpp,
  88 + ..\utest\srs_utest_handshake.cpp,
  89 + research readonly separator,
  90 + ..\..\research\librtmp\srs_play.c,
  91 + ..\..\research\librtmp\srs_publish.c,
  92 + ..\..\research\hls\ts_info.cc;
89 93
90 mainconfig 94 mainconfig
91 - "" = "MAIN"; 95 + "" = "MAIN";
92 96