From 76ed0200b4f1fee2f12940fcedecf27259bc3666 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 19 Mar 2022 12:06:07 +0800 Subject: [PATCH] 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 9fe6174c3f..377a7840c1 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 6b6ee5dd7a..f79423e1e6 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 7d02206372..5343d51f48 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 981cb43bba..3b9460e255 100644 --- a/trunk/src/srt/srt_conn.hpp +++ b/trunk/src/srt/srt_conn.hpp @@ -37,6 +37,7 @@ class srt_conn { 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 @@ class srt_conn { 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 5b7743c55f..2ef1bdcf8c 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 b3865b0c5e..d6c72bea58 100644 --- a/trunk/src/srt/srt_handle.hpp +++ b/trunk/src/srt/srt_handle.hpp @@ -37,7 +37,7 @@ class srt_handle { //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