From 210cdf04be7e112305625b059b62ea206229c207 Mon Sep 17 00:00:00 2001 From: loveforever <31402829+zhouxiaojun2008@users.noreply.github.com> Date: Sat, 19 Mar 2022 08:24:06 +0800 Subject: [PATCH 1/4] SRT: url supports multiple QueryStrings (#2908) * SRT: parse srt url to supports multiple QueryStrings.(#2893) * SRT: url supports multiple QueryStrings by comma-separated key-value pairs with no nesting (#2893) * SRT: url supports multiple QueryStrings by comma-separated key-value pairs with no nesting (#2893) * SRT: Add comments for url. * Add utest for SRT URL parsing. * Update README. Co-authored-by: winlin --- trunk/configure | 2 +- trunk/doc/CHANGELOG.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- trunk/src/srt/srt_conn.cpp | 125 +++++++++++++++++---------- trunk/src/srt/srt_conn.hpp | 2 +- trunk/src/srt/srt_handle.cpp | 14 +-- trunk/src/utest/srs_utest_srt.cpp | 79 +++++++++++++++++ trunk/src/utest/srs_utest_srt.hpp | 16 ++++ 8 files changed, 182 insertions(+), 59 deletions(-) create mode 100644 trunk/src/utest/srs_utest_srt.cpp create mode 100644 trunk/src/utest/srs_utest_srt.hpp diff --git a/trunk/configure b/trunk/configure index 5c28041be..d26771137 100755 --- a/trunk/configure +++ b/trunk/configure @@ -407,7 +407,7 @@ fi if [ $SRS_UTEST = YES ]; then MODULE_FILES=("srs_utest" "srs_utest_amf0" "srs_utest_protocol" "srs_utest_kernel" "srs_utest_core" "srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload" - "srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc") + "srs_utest_mp4" "srs_utest_service" "srs_utest_app" "srs_utest_rtc" "srs_utest_srt") ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot}) if [[ $SRS_RTC == YES ]]; then ModuleLibIncs+=(${LibSrtpRoot}) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index bbdd18531..9fe6174c3 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2022-03-19, Merge [#2908](https://github.com/ossrs/srs/pull/2908): SRT: url supports multiple QueryStrings (#2908). v4.0.250 * v4.0, 2022-03-17, SRT: Support debug and run with CLion. v4.0.249 * v4.0, 2022-03-15, Merge [#2966](https://github.com/ossrs/srs/pull/2966): Bugfix: Fix rtcp nack blp encode bug (#2966). v4.0.248 * v4.0, 2022-03-07, RTC: Identify the WebRTC publisher in param for hooks. v4.0.247 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 553ceeff9..6b6ee5dd7 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 249 +#define VERSION_REVISION 250 #endif diff --git a/trunk/src/srt/srt_conn.cpp b/trunk/src/srt/srt_conn.cpp index dc2e97cac..b933a9578 100644 --- a/trunk/src/srt/srt_conn.cpp +++ b/trunk/src/srt/srt_conn.cpp @@ -10,6 +10,7 @@ #include "srt_log.hpp" #include +#include #include bool is_streamid_valid(const std::string& streamid) { @@ -24,20 +25,20 @@ bool is_streamid_valid(const std::string& streamid) { int mode; std::string subpath; + std::string vhost; - bool ret = get_streamid_info(streamid, mode, subpath); + // Parse the stream info from streamid, see https://github.com/ossrs/srs/issues/2893 + bool ret = get_streamid_info(streamid, mode, vhost, subpath); if (!ret) { return false; } - - if ((mode != PUSH_SRT_MODE) && (mode != PULL_SRT_MODE)) { - return false; - } std::vector info_vec; string_split(subpath, "/", info_vec); - if (info_vec.size() < 2) {//it must be appname/stream at least. + // TODO: FIXME: Should fail at parsing the original SRT URL. + if (info_vec.size() != 2) { + srt_log_warn("path format must be appname/stream?key=value..."); return false; } @@ -69,12 +70,11 @@ bool get_key_value(const std::string& info, std::string& key, std::string& value return true; } -//eg. streamid=#!::h:live/livestream,m:publish -bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_subpath) { - std::vector info_vec; - std::string real_streamid; - - mode = PUSH_SRT_MODE; +// See streamid of https://github.com/ossrs/srs/issues/2893 +// TODO: FIMXE: We should parse SRT streamid to URL object, rather than a HTTP url subpath. +bool get_streamid_info(const std::string& streamid, int& mode, std::string& vhost, std::string& url_subpath) +{ + mode = PULL_SRT_MODE; size_t pos = streamid.find("#!::"); if (pos != 0) { @@ -86,36 +86,72 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_ url_subpath = streamid; return true; } + + //SRT url supports multiple QueryStrings, which are passed to RTMP to realize authentication and other capabilities + //@see https://github.com/ossrs/srs/issues/2893 + std::string params; + std::string real_streamid; real_streamid = streamid.substr(4); - string_split(real_streamid, ",", info_vec); - if (info_vec.size() < 2) { + std::map query; + srs_parse_query_string(real_streamid, query); + for (std::map::iterator it = query.begin(); it != query.end(); ++it) { + if (it->first == "h") { + std::string host = it->second; + + // Compatible with previous style, see https://github.com/ossrs/srs/issues/2893#compatible + size_t r0 = host.find("/"); + size_t r1 = host.rfind("/"); + if (r0 != std::string::npos && r0 != std::string::npos) { + if (r0 != r1) { + // We got vhost in host. + url_subpath = host.substr(r0 + 1); + host = host.substr(0, r0); + + params.append("vhost="); + params.append(host); + params.append("&"); + vhost = host; + } else { + // Only stream in host. + url_subpath = host; + } + } else { + // Now we get the host as vhost. + params.append("vhost="); + params.append(host); + params.append("&"); + vhost = host; + } + } else if (it->first == "r") { + url_subpath = it->second; + } else if (it->first == "m") { + std::string mode_str = it->second; // support m=publish or m=request + std::transform(it->second.begin(), it->second.end(), mode_str.begin(), ::tolower); + if (mode_str == "publish") { + mode = PUSH_SRT_MODE; + } else if (mode_str == "request") { + mode = PULL_SRT_MODE; + } else { + srt_log_warn("unknown mode_str:%s", mode_str.c_str()); + return false; + } + } else { + params.append(it->first); + params.append("="); + params.append(it->second); + params.append("&"); + } + } + + if (url_subpath.empty()) { return false; } - for (size_t index = 0; index < info_vec.size(); index++) { - std::string key; - std::string value; - - bool ret = get_key_value(info_vec[index], key, value); - if (!ret) { - continue; - } - - if (key == "h") { - url_subpath = value;//eg. h=live/stream - } else if (key == "m") { - std::string mode_str = string_lower(value);//m=publish or m=request - if (mode_str == "publish") { - mode = PUSH_SRT_MODE; - } else if (mode_str == "request") { - mode = PULL_SRT_MODE; - } else { - mode = PUSH_SRT_MODE; - } - } else {//not suport - continue; - } + if (!params.empty()) { + url_subpath.append("?"); + url_subpath.append(params); + url_subpath.pop_back(); // remove last '&' } return true; @@ -123,19 +159,16 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_ srt_conn::srt_conn(SRTSOCKET conn_fd, const std::string& streamid):_conn_fd(conn_fd), _streamid(streamid), - write_fail_cnt_(0) { - get_streamid_info(streamid, _mode, _url_subpath); + write_fail_cnt_(0) +{ + get_streamid_info(streamid, _mode, _vhost, _url_subpath); _update_timestamp = now_ms(); - - std::vector path_vec; - - string_split(_url_subpath, "/", path_vec); - if (path_vec.size() >= 3) { - _vhost = path_vec[0]; - } else { + + if (_vhost.empty()) { _vhost = "__default_host__"; } + srt_log_trace("srt connect construct streamid:%s, mode:%d, subpath:%s, vhost:%s", streamid.c_str(), _mode, _url_subpath.c_str(), _vhost.c_str()); } diff --git a/trunk/src/srt/srt_conn.hpp b/trunk/src/srt/srt_conn.hpp index 44fa9bd17..981cb43bb 100644 --- a/trunk/src/srt/srt_conn.hpp +++ b/trunk/src/srt/srt_conn.hpp @@ -26,7 +26,7 @@ bool is_streamid_valid(const std::string& streamid); bool get_key_value(const std::string& info, std::string& key, std::string& value); -bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_subpash); +bool get_streamid_info(const std::string& streamid, int& mode, std::string& vhost, std::string& url_subpash); class srt_conn { public: diff --git a/trunk/src/srt/srt_handle.cpp b/trunk/src/srt/srt_handle.cpp index 4d4ccd34e..5b7743c55 100644 --- a/trunk/src/srt/srt_handle.cpp +++ b/trunk/src/srt/srt_handle.cpp @@ -349,10 +349,7 @@ void srt_handle::handle_pull_data(SRT_SOCKSTATUS status, const std::string& subp void srt_handle::handle_srt_socket(SRT_SOCKSTATUS status, SRTSOCKET conn_fd) { - std::string subpath; - int mode; auto conn_ptr = get_srt_conn(conn_fd); - if (!conn_ptr) { if (status != SRTS_CLOSED) { srt_log_error("handle_srt_socket find srt connection error, fd:%d, status:%d", @@ -360,13 +357,10 @@ void srt_handle::handle_srt_socket(SRT_SOCKSTATUS status, SRTSOCKET conn_fd) } return; } - bool ret = get_streamid_info(conn_ptr->get_streamid(), mode, subpath); - if (!ret) { - conn_ptr->close(); - conn_ptr = nullptr; - return; - } - + + std::string subpath = conn_ptr->get_subpath(); + + int mode = conn_ptr->get_mode(); if (mode == PUSH_SRT_MODE) { switch (status) { diff --git a/trunk/src/utest/srs_utest_srt.cpp b/trunk/src/utest/srs_utest_srt.cpp new file mode 100644 index 000000000..6a7c2830b --- /dev/null +++ b/trunk/src/utest/srs_utest_srt.cpp @@ -0,0 +1,79 @@ +// +// Copyright (c) 2013-2021 Winlin +// +// SPDX-License-Identifier: MIT +// +#include + +#include +#include + +#include +using namespace std; + +VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) { + int mode; string vhost; string subpath; + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath)); + EXPECT_EQ(PULL_SRT_MODE, mode); + EXPECT_STREQ("", vhost.c_str()); + EXPECT_STREQ("live/livestream?key1=value1&key2=value2", subpath.c_str()); + } + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::h=host.com,r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath)); + EXPECT_EQ(PULL_SRT_MODE, mode); + EXPECT_STREQ("host.com", vhost.c_str()); + EXPECT_STREQ("live/livestream?vhost=host.com&key1=value1&key2=value2", subpath.c_str()); + } +} + +VOID TEST(ProtocolSrtTest, SrtGetStreamInfoMethod) { + int mode; string vhost; string subpath; + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,m=request", mode, vhost, subpath)); + EXPECT_EQ(PULL_SRT_MODE, mode); + EXPECT_STREQ("live/livestream", subpath.c_str()); + } + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,m=publish", mode, vhost, subpath)); + EXPECT_EQ(PUSH_SRT_MODE, mode); + EXPECT_STREQ("live/livestream", subpath.c_str()); + } +} + +VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) { + int mode; string vhost; string subpath; + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::h=live/livestream,m=request", mode, vhost, subpath)); + EXPECT_EQ(PULL_SRT_MODE, mode); + EXPECT_STREQ("", vhost.c_str()); + EXPECT_STREQ("live/livestream", subpath.c_str()); + } + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::h=live/livestream,m=publish", mode, vhost, subpath)); + EXPECT_EQ(PUSH_SRT_MODE, mode); + EXPECT_STREQ("", vhost.c_str()); + EXPECT_STREQ("live/livestream", subpath.c_str()); + } + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::h=srs.srt.com.cn/live/livestream,m=request", mode, vhost, subpath)); + EXPECT_EQ(PULL_SRT_MODE, mode); + EXPECT_STREQ("srs.srt.com.cn", vhost.c_str()); + EXPECT_STREQ("live/livestream?vhost=srs.srt.com.cn", subpath.c_str()); + } + + if (true) { + EXPECT_TRUE(get_streamid_info("#!::h=srs.srt.com.cn/live/livestream,m=publish", mode, vhost, subpath)); + EXPECT_EQ(PUSH_SRT_MODE, mode); + EXPECT_STREQ("srs.srt.com.cn", vhost.c_str()); + EXPECT_STREQ("live/livestream?vhost=srs.srt.com.cn", subpath.c_str()); + } +} + diff --git a/trunk/src/utest/srs_utest_srt.hpp b/trunk/src/utest/srs_utest_srt.hpp new file mode 100644 index 000000000..63c0a663a --- /dev/null +++ b/trunk/src/utest/srs_utest_srt.hpp @@ -0,0 +1,16 @@ +// +// Copyright (c) 2013-2021 Winlin +// +// SPDX-License-Identifier: MIT +// + +#ifndef SRS_UTEST_SRT_HPP +#define SRS_UTEST_SRT_HPP + +/* +#include +*/ +#include + +#endif + From 41e35155f7bedeb62ea9b22137788dd457a1ac74 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 19 Mar 2022 09:04:51 +0800 Subject: [PATCH 2/4] SRT: Compatible with previous auth querystring. #2908 --- trunk/src/srt/srt_conn.cpp | 15 +++++++++++++-- trunk/src/utest/srs_utest_srt.cpp | 22 ++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/trunk/src/srt/srt_conn.cpp b/trunk/src/srt/srt_conn.cpp index b933a9578..7d0220637 100644 --- a/trunk/src/srt/srt_conn.cpp +++ b/trunk/src/srt/srt_conn.cpp @@ -11,6 +11,7 @@ #include #include +#include #include bool is_streamid_valid(const std::string& streamid) { @@ -93,16 +94,23 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& vhos std::string real_streamid; real_streamid = streamid.substr(4); + // Compatible with previous auth querystring, like this one: + // srt://127.0.0.1:10080?streamid=#!::h=live/livestream?secret=xxx,m=publish + real_streamid = srs_string_replace(real_streamid, "?", ","); + std::map query; srs_parse_query_string(real_streamid, query); for (std::map::iterator it = query.begin(); it != query.end(); ++it) { if (it->first == "h") { std::string host = it->second; - // Compatible with previous style, see https://github.com/ossrs/srs/issues/2893#compatible size_t r0 = host.find("/"); size_t r1 = host.rfind("/"); if (r0 != std::string::npos && r0 != std::string::npos) { + // Compatible with previous style, see https://github.com/ossrs/srs/issues/2893#compatible + // srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=publish + // srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=request + // srt://127.0.0.1:10080?streamid=#!::h=srs.srt.com.cn/live/livestream,m=publish if (r0 != r1) { // We got vhost in host. url_subpath = host.substr(r0 + 1); @@ -117,7 +125,10 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& vhos url_subpath = host; } } else { - // Now we get the host as vhost. + // New URL style, see https://github.com/ossrs/srs/issues/2893#solution + // srt://host.com:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2 + // srt://1.2.3.4:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2 + // srt://1.2.3.4:10080?streamid=#!::r=app/stream,key1=value1,key2=value2 params.append("vhost="); params.append(host); params.append("&"); diff --git a/trunk/src/utest/srs_utest_srt.cpp b/trunk/src/utest/srs_utest_srt.cpp index 6a7c2830b..7d420a22c 100644 --- a/trunk/src/utest/srs_utest_srt.cpp +++ b/trunk/src/utest/srs_utest_srt.cpp @@ -12,9 +12,8 @@ using namespace std; VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) { - int mode; string vhost; string subpath; - if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath)); EXPECT_EQ(PULL_SRT_MODE, mode); EXPECT_STREQ("", vhost.c_str()); @@ -22,6 +21,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) { } if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::h=host.com,r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath)); EXPECT_EQ(PULL_SRT_MODE, mode); EXPECT_STREQ("host.com", vhost.c_str()); @@ -30,15 +30,15 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) { } VOID TEST(ProtocolSrtTest, SrtGetStreamInfoMethod) { - int mode; string vhost; string subpath; - if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,m=request", mode, vhost, subpath)); EXPECT_EQ(PULL_SRT_MODE, mode); EXPECT_STREQ("live/livestream", subpath.c_str()); } if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::r=live/livestream,m=publish", mode, vhost, subpath)); EXPECT_EQ(PUSH_SRT_MODE, mode); EXPECT_STREQ("live/livestream", subpath.c_str()); @@ -46,9 +46,8 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoMethod) { } VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) { - int mode; string vhost; string subpath; - if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::h=live/livestream,m=request", mode, vhost, subpath)); EXPECT_EQ(PULL_SRT_MODE, mode); EXPECT_STREQ("", vhost.c_str()); @@ -56,6 +55,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) { } if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::h=live/livestream,m=publish", mode, vhost, subpath)); EXPECT_EQ(PUSH_SRT_MODE, mode); EXPECT_STREQ("", vhost.c_str()); @@ -63,6 +63,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) { } if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::h=srs.srt.com.cn/live/livestream,m=request", mode, vhost, subpath)); EXPECT_EQ(PULL_SRT_MODE, mode); EXPECT_STREQ("srs.srt.com.cn", vhost.c_str()); @@ -70,10 +71,19 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoCompatible) { } if (true) { + int mode; string vhost; string subpath; EXPECT_TRUE(get_streamid_info("#!::h=srs.srt.com.cn/live/livestream,m=publish", mode, vhost, subpath)); EXPECT_EQ(PUSH_SRT_MODE, mode); EXPECT_STREQ("srs.srt.com.cn", vhost.c_str()); EXPECT_STREQ("live/livestream?vhost=srs.srt.com.cn", subpath.c_str()); } + + if (true) { + int mode; string vhost; string subpath; + EXPECT_TRUE(get_streamid_info("#!::h=live/livestream?secret=d6d2be37,m=publish", mode, vhost, subpath)); + EXPECT_EQ(PUSH_SRT_MODE, mode); + EXPECT_STREQ("", vhost.c_str()); + EXPECT_STREQ("live/livestream?secret=d6d2be37", subpath.c_str()); + } } From 76ed0200b4f1fee2f12940fcedecf27259bc3666 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 19 Mar 2022 12:06:07 +0800 Subject: [PATCH 3/4] SRT: Decouple publish with play url (#2893). v4.0.251 --- trunk/doc/CHANGELOG.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- trunk/src/srt/srt_conn.cpp | 11 +++++++++++ trunk/src/srt/srt_conn.hpp | 2 ++ trunk/src/srt/srt_handle.cpp | 25 +++++++++++++------------ trunk/src/srt/srt_handle.hpp | 2 +- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 9fe6174c3..377a7840c 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2022-03-19, For [#2893](https://github.com/ossrs/srs/pull/2893): SRT: Decouple publish with play url (#2893). v4.0.251 * v4.0, 2022-03-19, Merge [#2908](https://github.com/ossrs/srs/pull/2908): SRT: url supports multiple QueryStrings (#2908). v4.0.250 * v4.0, 2022-03-17, SRT: Support debug and run with CLion. v4.0.249 * v4.0, 2022-03-15, Merge [#2966](https://github.com/ossrs/srs/pull/2966): Bugfix: Fix rtcp nack blp encode bug (#2966). v4.0.248 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 6b6ee5dd7..f79423e1e 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 250 +#define VERSION_REVISION 251 #endif diff --git a/trunk/src/srt/srt_conn.cpp b/trunk/src/srt/srt_conn.cpp index 7d0220637..5343d51f4 100644 --- a/trunk/src/srt/srt_conn.cpp +++ b/trunk/src/srt/srt_conn.cpp @@ -219,6 +219,17 @@ std::string srt_conn::get_streamid() { return _streamid; } +std::string srt_conn::get_path() { + if (!_url_path.empty()) { + return _url_path; + } + + size_t pos = _url_subpath.find("?"); + _url_path = (pos != std::string::npos) ? _url_subpath.substr(0, pos) : _url_subpath; + + return _url_path; +} + std::string srt_conn::get_subpath() { return _url_subpath; } diff --git a/trunk/src/srt/srt_conn.hpp b/trunk/src/srt/srt_conn.hpp index 981cb43bb..3b9460e25 100644 --- a/trunk/src/srt/srt_conn.hpp +++ b/trunk/src/srt/srt_conn.hpp @@ -37,6 +37,7 @@ public: SRTSOCKET get_conn(); int get_mode(); std::string get_streamid(); + std::string get_path(); std::string get_subpath(); std::string get_vhost(); int read(unsigned char* data, int len); @@ -49,6 +50,7 @@ public: private: SRTSOCKET _conn_fd; std::string _streamid; + std::string _url_path; std::string _url_subpath; std::string _vhost; int _mode; diff --git a/trunk/src/srt/srt_handle.cpp b/trunk/src/srt/srt_handle.cpp index 5b7743c55..2ef1bdcf8 100644 --- a/trunk/src/srt/srt_handle.cpp +++ b/trunk/src/srt/srt_handle.cpp @@ -160,7 +160,7 @@ void srt_handle::add_newconn(SRT_CONN_PTR conn_ptr, int events) { srt_log_trace("srt h264 sei filter is %s.", _srs_config->get_srt_sei_filter() ? "enable" : "disable"); if (conn_ptr->get_mode() == PULL_SRT_MODE) { - add_new_puller(conn_ptr, conn_ptr->get_subpath()); + add_new_puller(conn_ptr, conn_ptr->get_path()); } else { if(add_new_pusher(conn_ptr) == false) { srt_log_trace("push connection is repeated and rejected, fd:%d, streamid:%s", @@ -179,7 +179,7 @@ void srt_handle::add_newconn(SRT_CONN_PTR conn_ptr, int events) { return; } -void srt_handle::handle_push_data(SRT_SOCKSTATUS status, const std::string& subpath, SRTSOCKET conn_fd) { +void srt_handle::handle_push_data(SRT_SOCKSTATUS status, const std::string& path, const std::string& subpath, SRTSOCKET conn_fd) { SRT_CONN_PTR srt_conn_ptr; unsigned char data[DEF_DATA_SIZE]; int ret; @@ -222,7 +222,7 @@ void srt_handle::handle_push_data(SRT_SOCKSTATUS status, const std::string& subp //send data to subscriber(players) //streamid, play map - auto streamid_iter = _streamid_map.find(subpath); + auto streamid_iter = _streamid_map.find(path); if (streamid_iter == _streamid_map.end()) {//no puler srt_log_info("receive data size(%d) from pusher(%d) but no puller", ret, conn_fd); return; @@ -294,8 +294,8 @@ void srt_handle::check_alive() { close_push_conn(conn_ptr->get_conn()); } else if (conn_ptr->get_mode() == PULL_SRT_MODE) { srt_log_warn("check alive close pull connection fd:%d, streamid:%s", - conn_ptr->get_conn(), conn_ptr->get_subpath().c_str()); - close_pull_conn(conn_ptr->get_conn(), conn_ptr->get_subpath()); + conn_ptr->get_conn(), conn_ptr->get_path().c_str()); + close_pull_conn(conn_ptr->get_conn(), conn_ptr->get_path()); } else { srt_log_error("check_alive get unkown srt mode:%d, fd:%d", conn_ptr->get_mode(), conn_ptr->get_conn()); @@ -309,7 +309,7 @@ void srt_handle::close_push_conn(SRTSOCKET srtsocket) { if (iter != _conn_map.end()) { SRT_CONN_PTR conn_ptr = iter->second; - auto push_iter = _push_conn_map.find(conn_ptr->get_subpath()); + auto push_iter = _push_conn_map.find(conn_ptr->get_path()); if (push_iter != _push_conn_map.end()) { _push_conn_map.erase(push_iter); } @@ -324,14 +324,14 @@ void srt_handle::close_push_conn(SRTSOCKET srtsocket) { } bool srt_handle::add_new_pusher(SRT_CONN_PTR conn_ptr) { - auto push_iter = _push_conn_map.find(conn_ptr->get_subpath()); + auto push_iter = _push_conn_map.find(conn_ptr->get_path()); if (push_iter != _push_conn_map.end()) { return false; } - _push_conn_map.insert(std::make_pair(conn_ptr->get_subpath(), conn_ptr)); + _push_conn_map.insert(std::make_pair(conn_ptr->get_path(), conn_ptr)); _conn_map.insert(std::make_pair(conn_ptr->get_conn(), conn_ptr)); - srt_log_trace("srt_handle add new pusher streamid:%s, subpath:%s", - conn_ptr->get_streamid().c_str(), conn_ptr->get_subpath().c_str()); + srt_log_trace("srt_handle add new pusher streamid:%s, subpath:%s, sid:%s", + conn_ptr->get_streamid().c_str(), conn_ptr->get_subpath().c_str(), conn_ptr->get_path().c_str()); return true; } @@ -358,6 +358,7 @@ void srt_handle::handle_srt_socket(SRT_SOCKSTATUS status, SRTSOCKET conn_fd) return; } + std::string path = conn_ptr->get_path(); std::string subpath = conn_ptr->get_subpath(); int mode = conn_ptr->get_mode(); @@ -366,7 +367,7 @@ void srt_handle::handle_srt_socket(SRT_SOCKSTATUS status, SRTSOCKET conn_fd) { case SRTS_CONNECTED: { - handle_push_data(status, subpath, conn_fd); + handle_push_data(status, path, subpath, conn_fd); break; } case SRTS_BROKEN: @@ -392,7 +393,7 @@ void srt_handle::handle_srt_socket(SRT_SOCKSTATUS status, SRTSOCKET conn_fd) { srt_log_warn("srt pull disconnected fd:%d, streamid:%s", conn_fd, conn_ptr->get_streamid().c_str()); - close_pull_conn(conn_fd, subpath); + close_pull_conn(conn_fd, path); break; } default: diff --git a/trunk/src/srt/srt_handle.hpp b/trunk/src/srt/srt_handle.hpp index b3865b0c5..d6c72bea5 100644 --- a/trunk/src/srt/srt_handle.hpp +++ b/trunk/src/srt/srt_handle.hpp @@ -37,7 +37,7 @@ private: //get srt conn object by srt socket SRT_CONN_PTR get_srt_conn(SRTSOCKET conn_srt_socket); - void handle_push_data(SRT_SOCKSTATUS status, const std::string& subpath, SRTSOCKET conn_fd); + void handle_push_data(SRT_SOCKSTATUS status, const std::string& path, const std::string& subpath, SRTSOCKET conn_fd); void handle_pull_data(SRT_SOCKSTATUS status, const std::string& subpath, SRTSOCKET conn_fd); //add new puller into puller list and conn_map From dbfa761aede77f30cba7952be7509e1a6db68577 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 19 Mar 2022 13:04:06 +0800 Subject: [PATCH 4/4] Release v4.0-b10, 4.0 beta10, v4.0.251, 144665 lines. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index daefeb1b6..014e857af 100755 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ A big THANK YOU goes to: ## Releases +* 2022-03-19, Release [v4.0-b10](https://github.com/ossrs/srs/releases/tag/v4.0-b10), v4.0-b10, 4.0 beta10, v4.0.251, 144665 lines. * 2022-02-15, Release [v4.0-b9](https://github.com/ossrs/srs/releases/tag/v4.0-b9), v4.0-b9, 4.0 beta9, v4.0.245, 144474 lines. * 2022-02-11, Release [v4.0-b8](https://github.com/ossrs/srs/releases/tag/v4.0-b8), v4.0-b8, 4.0 beta8, v4.0.241, 144445 lines. * 2022-02-09, Release [v4.0-b7](https://github.com/ossrs/srs/releases/tag/v4.0-b7), v4.0-b7, 4.0 beta7, v4.0.240, 144437 lines.