Skip to content

Commit

Permalink
SRT: Decouple publish with play url (#2893). v4.0.251
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 19, 2022
1 parent 41e3515 commit 76ed020
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 4
#define VERSION_MINOR 0
#define VERSION_REVISION 250
#define VERSION_REVISION 251

#endif
11 changes: 11 additions & 0 deletions trunk/src/srt/srt_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/srt/srt_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
25 changes: 13 additions & 12 deletions trunk/src/srt/srt_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
Expand Down Expand Up @@ -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<SRTSOCKET, SRT_CONN_PTR>
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;
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
Expand All @@ -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;
}

Expand All @@ -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();
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/srt/srt_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76ed020

Please sign in to comment.