STAT: Refine tcUrl for SRT/RTC. v5.0.54

pull/3160/head
winlin 2 years ago
parent d877c0b76f
commit 9c6774b644

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="include" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-c include.conf" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" WORKING_DIR="file://$CMakeCurrentBuildDir$/../../../" PASS_PARENT_ENVS_2="true" PROJECT_NAME="srs" TARGET_NAME="srs" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="srs" RUN_TARGET_NAME="srs">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="log-file" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-c conf/log-file.conf" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" WORKING_DIR="file://$CMakeCurrentBuildDir$/../../../" PASS_PARENT_ENVS_2="true" PROJECT_NAME="srs" TARGET_NAME="srs" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="srs" RUN_TARGET_NAME="srs">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="srt" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-c conf/srt.conf" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" WORKING_DIR="file://$CMakeCurrentBuildDir$/../../../" PASS_PARENT_ENVS_2="true" PROJECT_NAME="srs" TARGET_NAME="srs" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="srs" RUN_TARGET_NAME="srs"> <configuration default="false" name="srt" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="-c conf/clion-srt.conf" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" WORKING_DIR="file://$CMakeCurrentBuildDir$/../../../" PASS_PARENT_ENVS_2="true" PROJECT_NAME="srs" TARGET_NAME="srs" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="srs" RUN_TARGET_NAME="srs">
<method v="2"> <method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" /> <option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method> </method>

@ -12,7 +12,7 @@ http_server {
http_api { http_api {
enabled on; enabled on;
listen 1985; listen 8080;
} }
stats { stats {
network 0; network 0;

@ -0,0 +1,53 @@
# SRT config.
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
http_api {
enabled on;
listen 8080;
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
srt_server {
enabled on;
listen 10080;
maxbw 1000000000;
connect_timeout 4000;
peerlatency 0;
recvlatency 0;
latency 0;
tsbpdmode off;
tlpktdrop off;
sendbuf 2000000;
recvbuf 2000000;
}
# @doc https://github.com/ossrs/srs/issues/1147#issuecomment-577607026
vhost __defaultVhost__ {
srt {
enabled on;
srt_to_rtmp on;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
}
# For SRT to use vhost.
vhost srs.srt.com.cn {
}
stats {
network 0;
disk sda sdb xvda xvdb;
}

@ -29,6 +29,20 @@ rtc_server {
candidate $CANDIDATE; candidate $CANDIDATE;
} }
srt_server {
enabled on;
listen 10080;
maxbw 1000000000;
connect_timeout 4000;
peerlatency 0;
recvlatency 0;
latency 0;
tsbpdmode off;
tlpktdrop off;
sendbuf 2000000;
recvbuf 2000000;
}
vhost __defaultVhost__ { vhost __defaultVhost__ {
rtc { rtc {
enabled on; enabled on;
@ -44,5 +58,9 @@ vhost __defaultVhost__ {
hls { hls {
enabled on; enabled on;
} }
srt {
enabled on;
srt_to_rtmp on;
}
} }

@ -7,6 +7,7 @@ The changelog for SRS.
## SRS 5.0 Changelog ## SRS 5.0 Changelog
* v5.0, 2022-08-30, STAT: Refine tcUrl for SRT/RTC. v5.0.54
* v5.0, 2022-08-30, Refactor: Extract SrsNetworkKbps from SrsKbps. v5.0.53 * v5.0, 2022-08-30, Refactor: Extract SrsNetworkKbps from SrsKbps. v5.0.53
* v5.0, 2022-08-30, Remove bandwidth check because falsh is disabled. v5.0.52 * v5.0, 2022-08-30, Remove bandwidth check because falsh is disabled. v5.0.52
* v5.0, 2022-08-30, Refactor: Use compositor for ISrsKbpsDelta. v5.0.51 * v5.0, 2022-08-30, Refactor: Use compositor for ISrsKbpsDelta. v5.0.51

@ -584,6 +584,8 @@ scApp.filter('sc_filter_streamURL', function(){
const pos = v.url.lastIndexOf('/'); const pos = v.url.lastIndexOf('/');
const stream = pos < 0 ? '' : v.url.substr(pos); const stream = pos < 0 ? '' : v.url.substr(pos);
// Use name or extract from url.
const streamName = v.name ? v.name : stream;
const pos2 = v.tcUrl.indexOf('?'); const pos2 = v.tcUrl.indexOf('?');
const tcUrl = pos2 < 0 ? v.tcUrl : v.tcUrl.substr(0, pos2); const tcUrl = pos2 < 0 ? v.tcUrl : v.tcUrl.substr(0, pos2);
@ -591,7 +593,7 @@ scApp.filter('sc_filter_streamURL', function(){
let params = pos2 < 0 ? '' : v.tcUrl.substr(pos2); let params = pos2 < 0 ? '' : v.tcUrl.substr(pos2);
if (params === '?vhost=__defaultVhost__' || params === '?domain=__defaultVhost__') params = ''; if (params === '?vhost=__defaultVhost__' || params === '?domain=__defaultVhost__') params = '';
return `${tcUrl}${stream}${params}`; return `${tcUrl}${streamName}${params}`;
}; };
}); });

@ -12,6 +12,7 @@
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>流名称</th> <th>流名称</th>
<th>URL</th>
<th>Vhost</th> <th>Vhost</th>
<th>状态</th> <th>状态</th>
<th>在线人数</th> <th>在线人数</th>
@ -24,6 +25,7 @@
<tr ng-repeat="stream in streams"> <tr ng-repeat="stream in streams">
<td><a href="javascript:void(0)" ng-click="gogogo('/streams/' + stream.id)">{{stream.id}}</a></td> <td><a href="javascript:void(0)" ng-click="gogogo('/streams/' + stream.id)">{{stream.id}}</a></td>
<td>{{stream.name| sc_filter_less}}</td> <td>{{stream.name| sc_filter_less}}</td>
<td>{{stream |sc_filter_streamURL}}</td>
<td><a href="javascript:void(0)" ng-click="gogogo('/vhosts/' + stream.vhost)">{{stream.owner.name}}</a></td> <td><a href="javascript:void(0)" ng-click="gogogo('/vhosts/' + stream.vhost)">{{stream.owner.name}}</a></td>
<td>{{stream.publish.active| sc_filter_has_stream}}</td> <td>{{stream.publish.active| sc_filter_has_stream}}</td>
<td>{{stream.clients}}人</td> <td>{{stream.clients}}人</td>

@ -12,6 +12,7 @@
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>Name</th> <th>Name</th>
<th>URL</th>
<th>Vhost</th> <th>Vhost</th>
<th>Status</th> <th>Status</th>
<th>Clients</th> <th>Clients</th>
@ -24,6 +25,7 @@
<tr ng-repeat="stream in streams"> <tr ng-repeat="stream in streams">
<td><a href="javascript:void(0)" ng-click="gogogo('/streams/' + stream.id)">{{stream.id}}</a></td> <td><a href="javascript:void(0)" ng-click="gogogo('/streams/' + stream.id)">{{stream.id}}</a></td>
<td>{{stream.name| sc_filter_less}}</td> <td>{{stream.name| sc_filter_less}}</td>
<td>{{stream |sc_filter_streamURL}}</td>
<td><a href="javascript:void(0)" ng-click="gogogo('/vhosts/' + stream.vhost)">{{stream.owner.name}}</a></td> <td><a href="javascript:void(0)" ng-click="gogogo('/vhosts/' + stream.vhost)">{{stream.owner.name}}</a></td>
<td>{{stream.publish.active| sc_filter_has_stream}}</td> <td>{{stream.publish.active| sc_filter_has_stream}}</td>
<td>{{stream.clients}}人</td> <td>{{stream.clients}}人</td>

@ -72,6 +72,10 @@ srs_error_t SrsHlsStream::serve_m3u8_ctx(ISrsHttpResponseWriter* w, ISrsHttpMess
{ {
string ctx = r->query_get(SRS_CONTEXT_IN_HLS); string ctx = r->query_get(SRS_CONTEXT_IN_HLS);
// Correct the app and stream by path, which is created from template.
// @remark Be careful that the stream has extension now, might cause identify fail.
req->stream = srs_path_basename(r->path());
// Always make the ctx alive now. // Always make the ctx alive now.
alive(ctx, req); alive(ctx, req);

@ -523,6 +523,10 @@ srs_error_t SrsLiveStream::update_auth(SrsLiveSource* s, SrsRequest* r)
srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) srs_error_t SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
// Correct the app and stream by path, which is created from template.
// @remark Be careful that the stream has extension now, might cause identify fail.
req->stream = srs_path_basename(r->path());
if ((err = http_hooks_on_play(r)) != srs_success) { if ((err = http_hooks_on_play(r)) != srs_success) {
return srs_error_wrap(err, "http hook"); return srs_error_wrap(err, "http hook");
@ -588,7 +592,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
SrsHttpConn* hc = dynamic_cast<SrsHttpConn*>(hr->connection()); SrsHttpConn* hc = dynamic_cast<SrsHttpConn*>(hr->connection());
// update client ip // update client ip
req->ip = hc->remote_ip(); req->ip = hc->remote_ip();
// update the statistic when source disconveried. // update the statistic when source disconveried.
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();

@ -263,7 +263,7 @@ srs_error_t SrsMpegtsSrtConn::do_cycle()
// Detect streamid of srt to request. // Detect streamid of srt to request.
SrtMode mode = SrtModePull; SrtMode mode = SrtModePull;
if (! srs_srt_streamid_to_request(streamid, mode, req_)) { if (!srs_srt_streamid_to_request(streamid, mode, req_)) {
return srs_error_new(ERROR_SRT_CONN, "invalid srt streamid=%s", streamid.c_str()); return srs_error_new(ERROR_SRT_CONN, "invalid srt streamid=%s", streamid.c_str());
} }
@ -288,9 +288,6 @@ srs_error_t SrsMpegtsSrtConn::do_cycle()
return srs_error_wrap(err, "on connect"); return srs_error_wrap(err, "on connect");
} }
// Build the tcUrl which is vhost/app.
req_->tcUrl = srs_generate_tc_url(req_->host, req_->vhost, req_->app, req_->port);
if (mode == SrtModePush) { if (mode == SrtModePush) {
err = publishing(); err = publishing();
} else if (mode == SrtModePull) { } else if (mode == SrtModePull) {

@ -139,5 +139,9 @@ bool srs_srt_streamid_to_request(const std::string& streamid, SrtMode& mode, Srs
request->param = stream_with_params.substr(pos + 1); request->param = stream_with_params.substr(pos + 1);
} }
request->host = srs_get_public_internet_address();
if (request->vhost.empty()) request->vhost = request->host;
request->tcUrl = srs_generate_tc_url("srt", request->host, request->vhost, request->app, request->port);
return ret; return ret;
} }

@ -9,6 +9,6 @@
#define VERSION_MAJOR 5 #define VERSION_MAJOR 5
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 53 #define VERSION_REVISION 54
#endif #endif

@ -111,7 +111,7 @@ srs_error_t SrsBasicRtmpClient::do_connect_app(string local_ip, bool debug)
// generate the tcUrl // generate the tcUrl
std::string param = ""; std::string param = "";
std::string target_vhost = req->vhost; std::string target_vhost = req->vhost;
std::string tc_url = srs_generate_tc_url(req->host, req->vhost, req->app, req->port); std::string tc_url = srs_generate_tc_url("rtmp", req->host, req->vhost, req->app, req->port);
// replace the tcUrl in request, // replace the tcUrl in request,
// which will replace the tc_url in client.connect_app(). // which will replace the tc_url in client.connect_app().

@ -1544,6 +1544,7 @@ void SrsRequest::strip()
SrsRequest* SrsRequest::as_http() SrsRequest* SrsRequest::as_http()
{ {
schema = "http"; schema = "http";
tcUrl = srs_generate_tc_url(schema, host, vhost, app, port);
return this; return this;
} }

@ -175,9 +175,9 @@ long srs_random()
return random(); return random();
} }
string srs_generate_tc_url(string host, string vhost, string app, int port) string srs_generate_tc_url(string schema, string host, string vhost, string app, int port)
{ {
string tcUrl = "rtmp://"; string tcUrl = schema + "://";
if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) { if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
tcUrl += host.empty() ? SRS_CONSTS_RTMP_DEFAULT_VHOST : host; tcUrl += host.empty() ? SRS_CONSTS_RTMP_DEFAULT_VHOST : host;
@ -324,10 +324,9 @@ string srs_generate_stream_url(string vhost, string app, string stream)
if (SRS_CONSTS_RTMP_DEFAULT_VHOST != vhost){ if (SRS_CONSTS_RTMP_DEFAULT_VHOST != vhost){
url += vhost; url += vhost;
} }
url += "/"; url += "/" + app;
url += app; // Note that we ignore any extension.
url += "/"; url += "/" + srs_path_filename(stream);
url += stream;
return url; return url;
} }

@ -76,7 +76,7 @@ extern long srs_random();
* generate the tcUrl without param. * generate the tcUrl without param.
* @remark Use host as tcUrl.vhost if vhost is default vhost. * @remark Use host as tcUrl.vhost if vhost is default vhost.
*/ */
extern std::string srs_generate_tc_url(std::string host, std::string vhost, std::string app, int port); extern std::string srs_generate_tc_url(std::string schema, std::string host, std::string vhost, std::string app, int port);
/** /**
* Generate the stream with param. * Generate the stream with param.

@ -581,15 +581,15 @@ VOID TEST(ProtocolUtilityTest, GenerateTcUrl)
string ip; string vhost; string app; int port; string tcUrl; string param; string ip; string vhost; string app; int port; string tcUrl; string param;
ip = "127.0.0.1"; vhost = "__defaultVhost__"; app = "live"; port = 1935; ip = "127.0.0.1"; vhost = "__defaultVhost__"; app = "live"; port = 1935;
tcUrl = srs_generate_tc_url(ip, vhost, app, port); tcUrl = srs_generate_tc_url("rtmp", ip, vhost, app, port);
EXPECT_STREQ("rtmp://127.0.0.1/live", tcUrl.c_str()); EXPECT_STREQ("rtmp://127.0.0.1/live", tcUrl.c_str());
ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 1935; ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 1935;
tcUrl = srs_generate_tc_url(ip, vhost, app, port); tcUrl = srs_generate_tc_url("rtmp", ip, vhost, app, port);
EXPECT_STREQ("rtmp://demo/live", tcUrl.c_str()); EXPECT_STREQ("rtmp://demo/live", tcUrl.c_str());
ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 19351; ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 19351;
tcUrl = srs_generate_tc_url(ip, vhost, app, port); tcUrl = srs_generate_tc_url("rtmp", ip, vhost, app, port);
EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str()); EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str());
} }
@ -7023,3 +7023,15 @@ VOID TEST(ProtocolKbpsTest, RAWStatisticSugar)
} }
} }
VOID TEST(ProtocolKbpsTest, StreamIdentify)
{
EXPECT_STREQ("/live/livestream", srs_generate_stream_url("", "live", "livestream").c_str());
EXPECT_STREQ("/live/livestream", srs_generate_stream_url("", "live", "livestream.flv").c_str());
EXPECT_STREQ("/live/livestream", srs_generate_stream_url("", "live", "livestream.m3u8").c_str());
EXPECT_STREQ("/live/livestream", srs_generate_stream_url("__defaultVhost__", "live", "livestream").c_str());
EXPECT_STREQ("ossrs.io/live/livestream", srs_generate_stream_url("ossrs.io", "live", "livestream").c_str());
EXPECT_STREQ("ossrs.io/live/livestream", srs_generate_stream_url("ossrs.io", "live", "livestream.flv").c_str());
EXPECT_STREQ("ossrs.io/live/livestream", srs_generate_stream_url("ossrs.io", "live", "livestream.m3u8").c_str());
}

@ -423,7 +423,7 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest)
SrsRequest req; SrsRequest req;
EXPECT_TRUE(srs_srt_streamid_to_request("#!::r=live/livestream?key1=val1,key2=val2", mode, &req)); EXPECT_TRUE(srs_srt_streamid_to_request("#!::r=live/livestream?key1=val1,key2=val2", mode, &req));
EXPECT_EQ(mode, SrtModePull); EXPECT_EQ(mode, SrtModePull);
EXPECT_STREQ(req.vhost.c_str(), ""); EXPECT_STREQ(req.vhost.c_str(), srs_get_public_internet_address().c_str());
EXPECT_STREQ(req.app.c_str(), "live"); EXPECT_STREQ(req.app.c_str(), "live");
EXPECT_STREQ(req.stream.c_str(), "livestream"); EXPECT_STREQ(req.stream.c_str(), "livestream");
EXPECT_STREQ(req.param.c_str(), "key1=val1&key2=val2"); EXPECT_STREQ(req.param.c_str(), "key1=val1&key2=val2");
@ -445,7 +445,7 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest)
SrsRequest req; SrsRequest req;
EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=live/livestream?key1=val1,key2=val2", mode, &req)); EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=live/livestream?key1=val1,key2=val2", mode, &req));
EXPECT_EQ(mode, SrtModePull); EXPECT_EQ(mode, SrtModePull);
EXPECT_STREQ(req.vhost.c_str(), ""); EXPECT_STREQ(req.vhost.c_str(), srs_get_public_internet_address().c_str());
EXPECT_STREQ(req.app.c_str(), "live"); EXPECT_STREQ(req.app.c_str(), "live");
EXPECT_STREQ(req.stream.c_str(), "livestream"); EXPECT_STREQ(req.stream.c_str(), "livestream");
EXPECT_STREQ(req.param.c_str(), "key1=val1&key2=val2"); EXPECT_STREQ(req.param.c_str(), "key1=val1&key2=val2");

Loading…
Cancel
Save