From 0c036e04350bed53651bfe6552032df29e845be9 Mon Sep 17 00:00:00 2001 From: "Alex.CR" Date: Sat, 29 Jan 2022 01:07:01 -0600 Subject: [PATCH 1/7] SRT: Reduce the SRT bug by limit the max times for retry. --- trunk/src/srt/srt_conn.cpp | 9 ++++++++- trunk/src/srt/srt_conn.hpp | 2 ++ trunk/src/srt/srt_handle.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/trunk/src/srt/srt_conn.cpp b/trunk/src/srt/srt_conn.cpp index bbcf96244..dc2e97cac 100644 --- a/trunk/src/srt/srt_conn.cpp +++ b/trunk/src/srt/srt_conn.cpp @@ -122,7 +122,8 @@ 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) { + _streamid(streamid), + write_fail_cnt_(0) { get_streamid_info(streamid, _mode, _url_subpath); _update_timestamp = now_ms(); @@ -195,7 +196,13 @@ int srt_conn::write(unsigned char* data, int len) { ret = srt_send(_conn_fd, (char*)data, len); if (ret <= 0) { srt_log_error("srt write error:%d, socket fd:%d", ret, _conn_fd); + write_fail_cnt_++; return ret; } + write_fail_cnt_ = 0; return ret; } + +int srt_conn::get_write_fail_count() { + return write_fail_cnt_; +} \ No newline at end of file diff --git a/trunk/src/srt/srt_conn.hpp b/trunk/src/srt/srt_conn.hpp index 110e45913..44fa9bd17 100644 --- a/trunk/src/srt/srt_conn.hpp +++ b/trunk/src/srt/srt_conn.hpp @@ -44,6 +44,7 @@ public: void update_timestamp(long long now_ts); long long get_last_ts(); + int get_write_fail_count(); private: SRTSOCKET _conn_fd; @@ -52,6 +53,7 @@ private: std::string _vhost; int _mode; long long _update_timestamp; + int write_fail_cnt_; }; typedef std::shared_ptr SRT_CONN_PTR; diff --git a/trunk/src/srt/srt_handle.cpp b/trunk/src/srt/srt_handle.cpp index dcb1a007c..20547d673 100644 --- a/trunk/src/srt/srt_handle.cpp +++ b/trunk/src/srt/srt_handle.cpp @@ -26,6 +26,7 @@ static long long MONITOR_TIMEOUT = 5000; const unsigned int DEF_DATA_SIZE = 188*7; const long long CHECK_ALIVE_INTERVAL = 5*1000; const long long CHECK_ALIVE_TIMEOUT = 5*1000; +static const int SRT_WRTIE_FAIL_MAX = 10; long long srt_now_ms = 0; @@ -216,6 +217,7 @@ void srt_handle::handle_push_data(SRT_SOCKSTATUS status, const std::string& subp srt_log_info("receive data size(%d) from pusher(%d) to pullers, count:%d", ret, conn_fd, streamid_iter->second.size()); + std::vector remove_vec; for (auto puller_iter = streamid_iter->second.begin(); puller_iter != streamid_iter->second.end(); puller_iter++) { @@ -228,6 +230,17 @@ void srt_handle::handle_push_data(SRT_SOCKSTATUS status, const std::string& subp srt_log_info("send data size(%d) to puller fd:%d", write_ret, puller_iter->first); if (write_ret > 0) { puller_iter->second->update_timestamp(srt_now_ms); + } else { + if (player_conn->get_write_fail_count() > SRT_WRTIE_FAIL_MAX) { + remove_vec.push_back(puller_iter->first); + } + } + } + + for (auto item : remove_vec) { + streamid_iter->second.erase(item); + if (streamid_iter->second.empty()) { + _streamid_map.erase(streamid_iter); } } From bdf6540c89560918dad10821ad6669ddaa4c2a9a Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 29 Jan 2022 15:08:56 +0800 Subject: [PATCH 2/7] SRT: Reduce the SRT bug by limit the max times for retry. (#2896). v4.0.234 --- trunk/doc/CHANGELOG.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index fe188d3ab..9d71ea673 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-01-29, Merge [#2896](https://github.com/ossrs/srs/pull/2896): SRT: Reduce the SRT bug by limit the max times for retry. (#2896). v4.0.234 * v4.0, 2022-01-23, Merge [#2886](https://github.com/ossrs/srs/pull/2886): Fix bug when free addrinfo. (#2886). v4.0.233 * v4.0, 2022-01-22, Merge [#2887](https://github.com/ossrs/srs/pull/2887): Fix memory leak in SrsMetaCache. (#2887). v4.0.232 * v4.0, 2022-01-21, Support docker image for [lighthouse](https://hub.docker.com/r/ossrs/lighthouse). v4.0.231 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 0749778fb..699be66f0 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 233 +#define VERSION_REVISION 234 #endif From ba0b62fd376c9ebe309116b0beea9f73eefe173d Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 30 Jan 2022 21:08:43 +0800 Subject: [PATCH 3/7] For docker, always use the console for logging. v4.0.235 --- trunk/conf/docker.conf | 2 ++ trunk/doc/CHANGELOG.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/trunk/conf/docker.conf b/trunk/conf/docker.conf index dc7a2368b..f4ae9cd35 100644 --- a/trunk/conf/docker.conf +++ b/trunk/conf/docker.conf @@ -3,6 +3,8 @@ listen 1935; max_connections 1000; +# For docker, please use docker logs to manage the logs of SRS. +# See https://docs.docker.com/config/containers/logging/ srs_log_tank console; daemon off; http_api { diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 9d71ea673..2e3987154 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-01-30, For docker, always use the console for logging. v4.0.235 * v4.0, 2022-01-29, Merge [#2896](https://github.com/ossrs/srs/pull/2896): SRT: Reduce the SRT bug by limit the max times for retry. (#2896). v4.0.234 * v4.0, 2022-01-23, Merge [#2886](https://github.com/ossrs/srs/pull/2886): Fix bug when free addrinfo. (#2886). v4.0.233 * v4.0, 2022-01-22, Merge [#2887](https://github.com/ossrs/srs/pull/2887): Fix memory leak in SrsMetaCache. (#2887). v4.0.232 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 699be66f0..492dbb742 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 234 +#define VERSION_REVISION 235 #endif From 1d4fac0dbc890dc0471cbfd5520f2e17a4c075b2 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 30 Jan 2022 22:36:01 +0800 Subject: [PATCH 4/7] Refine docker console, preview by players at the same server. v4.0.236 --- trunk/doc/CHANGELOG.md | 1 + trunk/research/console/js/srs.console.js | 6 +++++- trunk/src/core/srs_core_version4.hpp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 2e3987154..84beda9b2 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-01-30, Refine docker console, preview by players at the same server. v4.0.236 * v4.0, 2022-01-30, For docker, always use the console for logging. v4.0.235 * v4.0, 2022-01-29, Merge [#2896](https://github.com/ossrs/srs/pull/2896): SRT: Reduce the SRT bug by limit the max times for retry. (#2896). v4.0.234 * v4.0, 2022-01-23, Merge [#2886](https://github.com/ossrs/srs/pull/2886): Fix bug when free addrinfo. (#2886). v4.0.233 diff --git a/trunk/research/console/js/srs.console.js b/trunk/research/console/js/srs.console.js index 95c3a5d11..e463ea827 100644 --- a/trunk/research/console/js/srs.console.js +++ b/trunk/research/console/js/srs.console.js @@ -570,7 +570,7 @@ scApp.filter('sc_filter_style_error', function(){ scApp.filter('sc_filter_preview_url', ['$sc_server', function($sc_server){ return function(v){ - var page = $sc_server.schema + "://ossrs.net/players/srs_player.html"; + var page = $sc_server.schema + `://${$sc_server.host}:${$sc_server.http}/players/srs_player.html`; var http = $sc_server.http[$sc_server.http.length - 1]; var query = "vhost=" + v.owner.name + "&app=" + v.app + "&stream=" + v.name + ".flv"; query += "&server=" + $sc_server.host +"&port=" + http + "&autostart=true&schema=" + $sc_server.schema; @@ -685,6 +685,10 @@ scApp.provider("$sc_server", [function(){ } else { self.port = $location.port(); } + + if ($location.search().http) { + self.http = [$location.search().http]; + } } }; return self; diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 492dbb742..0549c1821 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 235 +#define VERSION_REVISION 236 #endif From a4a231e396faf3946a5d6168829ebdafd1e95389 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 30 Jan 2022 22:37:26 +0800 Subject: [PATCH 5/7] Release v4.0-b5, 4.0 beta5, v4.0.236, 144416 lines. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9722a7c33..8a263c80d 100755 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ A big THANK YOU goes to: ## Releases +* 2022-01-30, Release [v4.0-b5](https://github.com/ossrs/srs/releases/tag/v4.0-b5), v4.0-b5, 4.0 beta5, v4.0.236, 144416 lines. * 2022-01-17, Release [v4.0-b4](https://github.com/ossrs/srs/releases/tag/v4.0-b4), v4.0-b4, 4.0 beta4, v4.0.230, 144393 lines. * 2022-01-13, Release [v4.0-b3](https://github.com/ossrs/srs/releases/tag/v4.0-b3), v4.0-b3, 4.0 beta3, v4.0.229, 144393 lines. * 2022-01-03, Release [v4.0-b2](https://github.com/ossrs/srs/releases/tag/v4.0-b2), v4.0-b2, 4.0 beta2, v4.0.215, 144278 lines. From 290c3b95a5b443b409689ae24217b3af31dcb105 Mon Sep 17 00:00:00 2001 From: Haibo Chen Date: Thu, 3 Feb 2022 15:05:09 +0800 Subject: [PATCH 6/7] Fix bug when the value of http header is empty (#2888) * Fix bug when the value of http header is empty * add utest --- trunk/src/protocol/srs_service_http_conn.cpp | 10 +++++----- trunk/src/utest/srs_utest_http.cpp | 21 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/trunk/src/protocol/srs_service_http_conn.cpp b/trunk/src/protocol/srs_service_http_conn.cpp index 785ef3f2d..81fad1565 100644 --- a/trunk/src/protocol/srs_service_http_conn.cpp +++ b/trunk/src/protocol/srs_service_http_conn.cpp @@ -263,12 +263,12 @@ int SrsHttpParser::on_header_value(http_parser* parser, const char* at, size_t l if (length > 0) { obj->field_value.append(at, (int)length); - } - // When header parsed, we must save the position of start for body, - // because we have to consume the header in buffer. - // @see https://github.com/ossrs/srs/issues/1508 - obj->p_header_tail = at; + // When header parsed, we must save the position of start for body, + // because we have to consume the header in buffer. + // @see https://github.com/ossrs/srs/issues/1508 + obj->p_header_tail = at; + } srs_info("Header value(%d bytes): %.*s", (int)length, (int)length, at); return 0; diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index 3968e958b..6167de5ff 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -143,6 +143,16 @@ string mock_http_response2(int status, string content) return ss.str(); } +string mock_http_response3(int status, string content) +{ + stringstream ss; + ss << "HTTP/1.1 " << status << " " << srs_generate_http_status_text(status) << "\r\n" + << "Server:" << "\r\n" + << "\r\n" + << content; + return ss.str(); +} + bool is_string_contain(string substr, string str) { return (string::npos != str.find(substr)); @@ -528,6 +538,17 @@ VOID TEST(ProtocolHTTPTest, ClientRequest) EXPECT_STREQ("Hello, world!", res.c_str()); srs_freep(msg); } + + // Normal case, with empty server. + if(true) { + MockBufferIO io; io.append(mock_http_response3(200, "Hello, world!")); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); + ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); + string res; HELPER_ASSERT_SUCCESS(msg->body_read_all(res)); + EXPECT_EQ(200, msg->status_code()); + EXPECT_STREQ("Hello, world!", res.c_str()); + srs_freep(msg); + } } VOID TEST(ProtocolHTTPTest, ResponseHTTPError) From dcf565bba141cbbf8b540d092686b68a3aba0b16 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 3 Feb 2022 15:07:37 +0800 Subject: [PATCH 7/7] Fix bug when the value of http header is empty. (#2888). v4.0.237 --- trunk/doc/CHANGELOG.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 84beda9b2..f5d195181 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-02-03, Merge [#2888](https://github.com/ossrs/srs/pull/2888): Fix bug when the value of http header is empty. (#2888). v4.0.237 * v4.0, 2022-01-30, Refine docker console, preview by players at the same server. v4.0.236 * v4.0, 2022-01-30, For docker, always use the console for logging. v4.0.235 * v4.0, 2022-01-29, Merge [#2896](https://github.com/ossrs/srs/pull/2896): SRT: Reduce the SRT bug by limit the max times for retry. (#2896). v4.0.234 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 0549c1821..8459194d4 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 236 +#define VERSION_REVISION 237 #endif