From d2a071f0412f7086f0fe7af8a80f039a7ea4535d Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 11 Feb 2020 19:32:46 +0800 Subject: [PATCH 01/27] Add TODO for incompatible APIs of librtmp --- trunk/src/libs/srs_librtmp.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/trunk/src/libs/srs_librtmp.hpp b/trunk/src/libs/srs_librtmp.hpp index 9184c1840..9f2044647 100644 --- a/trunk/src/libs/srs_librtmp.hpp +++ b/trunk/src/libs/srs_librtmp.hpp @@ -1105,6 +1105,7 @@ extern void srs_hijack_io_destroy(srs_hijack_io_t ctx); * create socket, not connect yet. * @param owner, the rtmp context which create this socket. * @return 0, success; otherswise, failed. + * TODO: FIXME: Incompatible API for https://github.com/ossrs/srs/blob/2.0release/trunk/src/libs/srs_librtmp.hpp#L989 */ extern int srs_hijack_io_create_socket(srs_hijack_io_t ctx, srs_rtmp_t owner); /** @@ -1156,6 +1157,7 @@ extern int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_s /** * whether the timeout is never timeout in ms. * @return 0, with timeout specified; otherwise, never timeout. + * TODO: FIXME: Incompatible API for https://github.com/ossrs/srs/blob/2.0release/trunk/src/libs/srs_librtmp.hpp#L1039 */ extern int srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm); /** From ce4123f250faf06fc429db92889e5101daf2e074 Mon Sep 17 00:00:00 2001 From: "Alex.CR" Date: Thu, 13 Feb 2020 03:02:54 -0600 Subject: [PATCH 02/27] rtmp tcp listen port bugs in srt2rtmp (#1602) * update srt2rtmp about rtmp listen tcp port * update srt2rtmp about rtmp listen tcp port --- trunk/src/srt/srt_to_rtmp.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/trunk/src/srt/srt_to_rtmp.cpp b/trunk/src/srt/srt_to_rtmp.cpp index 729e3e970..13e83056d 100644 --- a/trunk/src/srt/srt_to_rtmp.cpp +++ b/trunk/src/srt/srt_to_rtmp.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -207,11 +208,22 @@ rtmp_client::rtmp_client(std::string key_path):_key_path(key_path) } char url_sz[128]; + std::vector ip_ports = _srs_config->get_listens(); + int port = 0; + std::string ip; + + for (auto item : ip_ports) { + srs_parse_endpoint(item, ip, port); + if (port != 0) { + break; + } + } + port = (port == 0) ? 1935 : port; if (_vhost == DEF_VHOST) { - sprintf(url_sz, "rtmp://127.0.0.1/%s/%s", + sprintf(url_sz, "rtmp://127.0.0.1:%d/%s/%s", port, _appname.c_str(), _streamname.c_str()); } else { - sprintf(url_sz, "rtmp://127.0.0.1/%s?vhost=%s/%s", + sprintf(url_sz, "rtmp://127.0.0.1:%d/%s?vhost=%s/%s", port, _appname.c_str(), _vhost.c_str(), _streamname.c_str()); } From 21c2cb6512fb93fd3f2ccb57ffe9ec6fd8081998 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 14 Feb 2020 11:17:19 +0800 Subject: [PATCH 03/27] Update issue template --- .github/ISSUE_TEMPLATE | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE index a797cb02c..fa6f266ec 100644 --- a/.github/ISSUE_TEMPLATE +++ b/.github/ISSUE_TEMPLATE @@ -16,6 +16,10 @@ assignees: '' ``` xxxxxxxxxxxx ``` +1. SRS的配置如下(Config): +``` +xxxxxxxxxxxx +``` **重现(Replay)** From 23324cde31f9f2ec9909ca634675f1d289d21957 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 14 Feb 2020 21:57:02 +0800 Subject: [PATCH 04/27] Migrating streaming service from ossrs.net to r.ossrs.net --- trunk/research/players/js/srs.page.js | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/trunk/research/players/js/srs.page.js b/trunk/research/players/js/srs.page.js index 0fd37b2ad..be4f6ffeb 100755 --- a/trunk/research/players/js/srs.page.js +++ b/trunk/research/players/js/srs.page.js @@ -43,6 +43,12 @@ function user_extra_params(query, params) { var server = (query.server == undefined)? window.location.hostname:query.server; var vhost = (query.vhost == undefined)? window.location.hostname:query.vhost; + // Note that ossrs.net provides only web service, + // that is migrating to r.ossrs.net + if (vhost == "ossrs.net") { + vhost = "r.ossrs.net"; + } + for (var key in query.user_query) { if (key == 'app' || key == 'autostart' || key == 'dir' || key == 'filename' || key == 'host' || key == 'hostname' @@ -78,6 +84,12 @@ function build_default_rtmp_url() { var app = (!query.app)? "live":query.app; var stream = (!query.stream)? "livestream":query.stream; + // Note that ossrs.net provides only web service, + // that is migrating to r.ossrs.net + if (vhost == "ossrs.net") { + vhost = "r.ossrs.net"; + } + var queries = []; if (server != vhost && vhost != "__defaultVhost__") { queries.push("vhost=" + vhost); @@ -102,6 +114,12 @@ function build_default_publish_rtmp_url() { var app = (!query.app)? "live":query.app; var stream = (!query.stream)? "demo":query.stream; + // Note that ossrs.net provides only web service, + // that is migrating to r.ossrs.net + if (vhost == "ossrs.net") { + vhost = "r.ossrs.net"; + } + var queries = []; if (server != vhost && vhost != "__defaultVhost__") { queries.push("vhost=" + vhost); @@ -127,6 +145,12 @@ function build_default_bandwidth_rtmp_url() { var app = (!query.app)? "app":query.app; var key = (!query.key)? "35c9b402c12a7246868752e2878f7e0e":query.key; + // Note that ossrs.net provides only web service, + // that is migrating to r.ossrs.net + if (vhost == "ossrs.net") { + vhost = "r.ossrs.net"; + } + return "rtmp://" + server + ":" + port + "/" + app + "?key=" + key + "&vhost=" + vhost; } @@ -141,6 +165,12 @@ function build_default_bandwidth_rtmp_url() { function build_default_hls_url() { var query = parse_query_string(); + // Note that ossrs.net provides only web service, + // that is migrating to r.ossrs.net + if (query.hls_vhost == "ossrs.net") { + query.hls_vhost = "r.ossrs.net"; + } + // for http, use hls_vhost to override server if specified. var server = window.location.hostname; if (query.server != undefined) { From 4276bea4630e90b9ee3dcb0e205d1d163b843e32 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 14 Feb 2020 22:00:58 +0800 Subject: [PATCH 05/27] Migrating streaming service from ossrs.net to r.ossrs.net --- trunk/research/players/js/srs.page.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trunk/research/players/js/srs.page.js b/trunk/research/players/js/srs.page.js index be4f6ffeb..cc9c9df59 100755 --- a/trunk/research/players/js/srs.page.js +++ b/trunk/research/players/js/srs.page.js @@ -48,6 +48,9 @@ function user_extra_params(query, params) { if (vhost == "ossrs.net") { vhost = "r.ossrs.net"; } + if (server == "ossrs.net") { + server = "r.ossrs.net"; + } for (var key in query.user_query) { if (key == 'app' || key == 'autostart' || key == 'dir' @@ -89,6 +92,9 @@ function build_default_rtmp_url() { if (vhost == "ossrs.net") { vhost = "r.ossrs.net"; } + if (server == "ossrs.net") { + server = "r.ossrs.net"; + } var queries = []; if (server != vhost && vhost != "__defaultVhost__") { @@ -119,6 +125,9 @@ function build_default_publish_rtmp_url() { if (vhost == "ossrs.net") { vhost = "r.ossrs.net"; } + if (server == "ossrs.net") { + server = "r.ossrs.net"; + } var queries = []; if (server != vhost && vhost != "__defaultVhost__") { @@ -150,6 +159,9 @@ function build_default_bandwidth_rtmp_url() { if (vhost == "ossrs.net") { vhost = "r.ossrs.net"; } + if (server == "ossrs.net") { + server = "r.ossrs.net"; + } return "rtmp://" + server + ":" + port + "/" + app + "?key=" + key + "&vhost=" + vhost; } From 131acf5bb014eb4883bbe13e2b9f836081602985 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 14 Feb 2020 23:04:01 +0800 Subject: [PATCH 06/27] For #1595, migrating streaming from ossrs.net to r.ossrs.net. 3.0.117 --- README.md | 2 ++ trunk/src/core/srs_core_version3.hpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fb12cdf0..896e8ad90 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-14, For [#1595][bug #1595], migrating streaming from ossrs.net to r.ossrs.net. 3.0.117 * v3.0, 2020-02-05, For [#665][bug #665], fix HTTP-FLV reloading bug. 3.0.116 * v3.0, 2020-02-05, For [#1592][bug #1592], fix terminal echo off by redirect process stdin. 3.0.115 * v3.0, 2020-02-04, For [#1186][bug #1186], refactor security check. 3.0.114 @@ -1646,6 +1647,7 @@ Winlin [bug #1186]: https://github.com/ossrs/srs/issues/1186 [bug #1592]: https://github.com/ossrs/srs/issues/1592 [bug #665]: https://github.com/ossrs/srs/issues/665 +[bug #1595]: https://github.com/ossrs/srs/issues/1595 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 7b51a0991..c8793a0a8 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 116 +#define SRS_VERSION3_REVISION 117 #endif From 16173194b93ff2a1c8b7d7ff791dd8a46af81c9a Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 14 Feb 2020 23:05:54 +0800 Subject: [PATCH 07/27] Release 3.0-beta1, r3.0b1, 3.0.117 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 896e8ad90..905febbb7 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-14, [3.0 beta1(3.0.117)][r3.0b1] released. 121964 lines. * v3.0, 2020-02-14, For [#1595][bug #1595], migrating streaming from ossrs.net to r.ossrs.net. 3.0.117 * v3.0, 2020-02-05, For [#665][bug #665], fix HTTP-FLV reloading bug. 3.0.116 * v3.0, 2020-02-05, For [#1592][bug #1592], fix terminal echo off by redirect process stdin. 3.0.115 @@ -738,6 +739,7 @@ For previous versions, please read: ## Releases +* 2020-02-14, [Release v3.0-b1][r3.0b1], 3.0 beta1, 3.0.117, 121964 lines. * 2020-02-02, [Release v3.0-b0][r3.0b0], 3.0 beta0, 3.0.112, 121709 lines. * 2020-01-21, [Release v3.0-a9][r3.0a9], 3.0 alpha9, 3.0.105, 121577 lines. * 2020-01-10, [Release v3.0-a8][r3.0a8], 3.0 alpha8, 3.0.97, 121555 lines. @@ -1652,6 +1654,7 @@ Winlin [exo #828]: https://github.com/google/ExoPlayer/pull/828 +[r3.0b1]: https://github.com/ossrs/srs/releases/tag/v3.0-b1 [r3.0b0]: https://github.com/ossrs/srs/releases/tag/v3.0-b0 [r3.0a9]: https://github.com/ossrs/srs/releases/tag/v3.0-a9 [r3.0a8]: https://github.com/ossrs/srs/releases/tag/v3.0-a8 From 1604fcf35af86ae72111de273b451cceaeb28cde Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 16 Feb 2020 13:31:03 +0800 Subject: [PATCH 08/27] Update authors --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 905febbb7..5d6f6b8d4 100755 --- a/README.md +++ b/README.md @@ -1085,21 +1085,20 @@ Remark: There are two types of people that have contributed to the SRS project: -* AUTHORS: Contribute important features. Names of all authors responsed in NetConnection.connect and metadata. -* CONTRIBUTORS: Submit patches, report bugs, add translations, help answer newbie questions, and generally make SRS much better. +* Maintainers: Contribute important features. Names of all authors responsed in NetConnection.connect and metadata. +* [Contributors][authors]: Submit patches, report bugs, add translations, help answer newbie questions, and generally make SRS much better. -About all AUTHORS and CONTRIBUTORS, read [AUTHORS.txt][authors]. +Maintainers of SRS project: + +* Winlin: All areas of streaming server and documents. +* Wenjie: The focus of his work is on the [HDS](https://github.com/simple-rtmp-server/srs/wiki/v2_CN_DeliveryHDS) module. +* Runner365: The focus of his work is on the [SRT](https://github.com/simple-rtmp-server/srs/wiki/v4_CN_SRTWiki) module. A big THANK YOU goes to: * All friends of SRS for [big supports][bigthanks]. * Genes amd Mabbott for creating [st][st]([state-threads][st2]). -* Michael Talyanksy for introducing us to use st. -* Roman Arutyunyan for creating [nginx-rtmp][nginx-rtmp] for SRS to refer to. -* Joyent for creating [http-parser][http-parser] for http-api for SRS. -* Igor Sysoev for creating [nginx][nginx] for SRS to refer to. -* [FFMPEG][FFMPEG] and [libx264][libx264] group for SRS to use as transcoder. -* Guido van Rossum for creating Python for api-server for SRS. +* Michael Talyanksy for introducing ST to us. ## Mirrors From 80795640774037c635a97671c94899aa59af91d3 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 16 Feb 2020 13:39:25 +0800 Subject: [PATCH 09/27] Update maintainers --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5d6f6b8d4..5fe56a314 100755 --- a/README.md +++ b/README.md @@ -1085,20 +1085,20 @@ Remark: There are two types of people that have contributed to the SRS project: -* Maintainers: Contribute important features. Names of all authors responsed in NetConnection.connect and metadata. +* Maintainers: Contribute and maintain important features. Names will send in streaming metadata. * [Contributors][authors]: Submit patches, report bugs, add translations, help answer newbie questions, and generally make SRS much better. Maintainers of SRS project: -* Winlin: All areas of streaming server and documents. -* Wenjie: The focus of his work is on the [HDS](https://github.com/simple-rtmp-server/srs/wiki/v2_CN_DeliveryHDS) module. -* Runner365: The focus of his work is on the [SRT](https://github.com/simple-rtmp-server/srs/wiki/v4_CN_SRTWiki) module. +* [Winlin](https://github.com/winlinvip): All areas of streaming server and documents. +* [Wenjie](https://github.com/wenjiegit): The focus of his work is on the [HDS](https://github.com/simple-rtmp-server/srs/wiki/v2_CN_DeliveryHDS) module. +* [Runner365](https://github.com/runner365): The focus of his work is on the [SRT](https://github.com/simple-rtmp-server/srs/wiki/v4_CN_SRTWiki) module. A big THANK YOU goes to: * All friends of SRS for [big supports][bigthanks]. * Genes amd Mabbott for creating [st][st]([state-threads][st2]). -* Michael Talyanksy for introducing ST to us. +* [Michael Talyanksy](https://github.com/michaeltalyansky) for introducing ST to us. ## Mirrors @@ -1171,8 +1171,8 @@ Winlin [authors]: https://github.com/ossrs/srs/blob/develop/AUTHORS.txt [bigthanks]: https://github.com/ossrs/srs/wiki/v1_CN_Product#bigthanks [st]: https://github.com/winlinvip/state-threads -[st2]: http://sourceforge.net/projects/state-threads/ -[state-threads]: http://sourceforge.net/projects/state-threads/ +[st2]: https://github.com/ossrs/state-threads/tree/srs +[state-threads]: https://github.com/ossrs/state-threads/tree/srs [nginx-rtmp]: https://github.com/arut/nginx-rtmp-module [http-parser]: https://github.com/joyent/http-parser [nginx]: http://nginx.org/ From 304b92cc36abbd14a3d0e98ce0ccd64eb7cd4e4e Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 16 Feb 2020 13:41:47 +0800 Subject: [PATCH 10/27] Update maintainers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fe56a314..9b6f31f00 100755 --- a/README.md +++ b/README.md @@ -1085,7 +1085,7 @@ Remark: There are two types of people that have contributed to the SRS project: -* Maintainers: Contribute and maintain important features. Names will send in streaming metadata. +* Maintainers: Contribute and maintain important features. SRS always remembers and thanks you by writing your names in stream metadata. * [Contributors][authors]: Submit patches, report bugs, add translations, help answer newbie questions, and generally make SRS much better. Maintainers of SRS project: From 4e7e9809f3be3c08f8ce40bf92d5795612f96e43 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 16 Feb 2020 22:35:40 +0800 Subject: [PATCH 11/27] Fix bash script bug for macOS, eventhough we don't support it. --- trunk/auto/options.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 8c7cdae51..ad89f882d 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -204,6 +204,10 @@ Remark: END } +function ignore_option() { + echo "ignore option \"$option\"" +} + function parse_user_option() { case "$option" in -h) help=yes ;; @@ -293,18 +297,16 @@ function parse_user_option() { --with-hls) SRS_HLS=YES ;; --with-dvr) SRS_DVR=YES ;; - --without-stream-caster) ;& - --without-ingest) ;& - --without-ssl) ;& - --without-stat) ;& - --without-transcode) ;& - --without-http-callback) ;& - --without-http-server) ;& - --without-http-api) ;& - --without-hls) ;& - --without-dvr) - echo "ignore option \"$option\"" - ;; + --without-stream-caster) ignore_option ;; + --without-ingest) ignore_option ;; + --without-ssl) ignore_option ;; + --without-stat) ignore_option ;; + --without-transcode) ignore_option ;; + --without-http-callback) ignore_option ;; + --without-http-server) ignore_option ;; + --without-http-api) ignore_option ;; + --without-hls) ignore_option ;; + --without-dvr) ignore_option ;; *) echo "$0: error: invalid option \"$option\"" From 5be69d290f9504f3562cdc3c0a0e037a3154a9d0 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 17 Feb 2020 11:53:04 +0800 Subject: [PATCH 12/27] For #1601, flush async on_dvr/on_hls events before stop. 3.0.118 --- README.md | 2 ++ trunk/src/app/srs_app_async_call.cpp | 48 ++++++++++++++++++++-------- trunk/src/app/srs_app_async_call.hpp | 3 ++ trunk/src/app/srs_app_dvr.cpp | 12 ++++--- trunk/src/app/srs_app_rtmp_conn.cpp | 2 +- trunk/src/core/srs_core_version3.hpp | 2 +- 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 9b6f31f00..7e94b13bd 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-17, For [#1601][bug #1601], flush async on_dvr/on_hls events before stop. 3.0.118 * v3.0, 2020-02-14, [3.0 beta1(3.0.117)][r3.0b1] released. 121964 lines. * v3.0, 2020-02-14, For [#1595][bug #1595], migrating streaming from ossrs.net to r.ossrs.net. 3.0.117 * v3.0, 2020-02-05, For [#665][bug #665], fix HTTP-FLV reloading bug. 3.0.116 @@ -1649,6 +1650,7 @@ Winlin [bug #1592]: https://github.com/ossrs/srs/issues/1592 [bug #665]: https://github.com/ossrs/srs/issues/665 [bug #1595]: https://github.com/ossrs/srs/issues/1595 +[bug #1601]: https://github.com/ossrs/srs/issues/1601 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_async_call.cpp b/trunk/src/app/srs_app_async_call.cpp index 42df06b5d..271964d99 100644 --- a/trunk/src/app/srs_app_async_call.cpp +++ b/trunk/src/app/srs_app_async_call.cpp @@ -40,6 +40,7 @@ SrsAsyncCallWorker::SrsAsyncCallWorker() { trd = new SrsDummyCoroutine(); wait = srs_cond_new(); + lock = srs_mutex_new(); } SrsAsyncCallWorker::~SrsAsyncCallWorker() @@ -54,6 +55,7 @@ SrsAsyncCallWorker::~SrsAsyncCallWorker() tasks.clear(); srs_cond_destroy(wait); + srs_mutex_destroy(lock); } srs_error_t SrsAsyncCallWorker::execute(ISrsAsyncCallTask* t) @@ -87,6 +89,7 @@ srs_error_t SrsAsyncCallWorker::start() void SrsAsyncCallWorker::stop() { + flush_tasks(); srs_cond_signal(wait); trd->stop(); } @@ -103,23 +106,40 @@ srs_error_t SrsAsyncCallWorker::cycle() if (tasks.empty()) { srs_cond_wait(wait); } - - std::vector copy = tasks; - tasks.clear(); - - std::vector::iterator it; - for (it = copy.begin(); it != copy.end(); ++it) { - ISrsAsyncCallTask* task = *it; - - if ((err = task->call()) != srs_success) { - srs_warn("ignore task failed %s", srs_error_desc(err).c_str()); - srs_freep(err); - } - srs_freep(task); - } + + flush_tasks(); } return err; } +void SrsAsyncCallWorker::flush_tasks() +{ + srs_error_t err = srs_success; + + // Avoid the async call blocking other coroutines. + std::vector copy; + if (true) { + SrsLocker(lock); + + if (tasks.empty()) { + return; + } + + copy = tasks; + tasks.clear(); + } + + std::vector::iterator it; + for (it = copy.begin(); it != copy.end(); ++it) { + ISrsAsyncCallTask* task = *it; + + if ((err = task->call()) != srs_success) { + srs_warn("ignore task failed %s", srs_error_desc(err).c_str()); + srs_freep(err); + } + srs_freep(task); + } +} + diff --git a/trunk/src/app/srs_app_async_call.hpp b/trunk/src/app/srs_app_async_call.hpp index 4576f312e..7cc183f4a 100644 --- a/trunk/src/app/srs_app_async_call.hpp +++ b/trunk/src/app/srs_app_async_call.hpp @@ -61,6 +61,7 @@ private: protected: std::vector tasks; srs_cond_t wait; + srs_mutex_t lock; public: SrsAsyncCallWorker(); virtual ~SrsAsyncCallWorker(); @@ -73,6 +74,8 @@ public: // Interface ISrsReusableThreadHandler public: virtual srs_error_t cycle(); +private: + virtual void flush_tasks(); }; #endif diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index aca14581a..cb281e7bd 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -740,8 +740,6 @@ srs_error_t SrsDvrSessionPlan::on_publish() void SrsDvrSessionPlan::on_unpublish() { - SrsDvrPlan::on_unpublish(); - // support multiple publish. if (!dvr_enabled) { return; @@ -754,6 +752,10 @@ void SrsDvrSessionPlan::on_unpublish() } dvr_enabled = false; + + // We should notify the on_dvr, then stop the async. + // @see https://github.com/ossrs/srs/issues/1601 + SrsDvrPlan::on_unpublish(); } SrsDvrSegmentPlan::SrsDvrSegmentPlan() @@ -815,14 +817,16 @@ void SrsDvrSegmentPlan::on_unpublish() { srs_error_t err = srs_success; - SrsDvrPlan::on_unpublish(); - if ((err = segment->close()) != srs_success) { srs_warn("ignore err %s", srs_error_desc(err).c_str()); srs_freep(err); } dvr_enabled = false; + + // We should notify the on_dvr, then stop the async. + // @see https://github.com/ossrs/srs/issues/1601 + SrsDvrPlan::on_unpublish(); } srs_error_t SrsDvrSegmentPlan::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format) diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 5ffe4b0cd..98bfcd5fc 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -406,7 +406,7 @@ srs_error_t SrsRtmpConn::service_cycle() rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TIMEOUT); rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TIMEOUT); - srs_trace("rtmp: retry for republish"); + srs_info("rtmp: retry for republish"); srs_freep(err); continue; } diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index c8793a0a8..4ddcca91c 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 117 +#define SRS_VERSION3_REVISION 118 #endif From df3ec15cd10b472e429c79ff8447aab4df02ad88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E7=AB=8B=E6=96=B0?= Date: Mon, 17 Feb 2020 18:08:16 +0800 Subject: [PATCH 13/27] Fix checking the completion of one frame data in RTSP RTP stream --- trunk/src/app/srs_app_rtsp.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 051071b49..4488b6d98 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -94,11 +94,14 @@ srs_error_t SrsRtpConn::on_udp_packet(const sockaddr* from, const int fromlen, c } cache->copy(&pkt); cache->payload->append(pkt.payload->bytes(), pkt.payload->length()); - if (!cache->completed && pprint->can_print()) { + if (pprint->can_print()) { srs_trace("<- " SRS_CONSTS_LOG_STREAM_CASTER " rtsp: rtp chunked %dB, age=%d, vt=%d/%u, sts=%u/%#x/%#x, paylod=%dB", nb_buf, pprint->age(), cache->version, cache->payload_type, cache->sequence_number, cache->timestamp, cache->ssrc, cache->payload->length() ); + } + + if (!cache->completed){ return err; } } else { @@ -645,6 +648,7 @@ srs_error_t SrsRtspConn::connect() std::string output = output_template; output = srs_string_replace(output, "[app]", app); output = srs_string_replace(output, "[stream]", rtsp_stream); + url = output; } // connect host. From f4c7b882c59592675a040fa07aba628cef9d6711 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 09:53:40 +0800 Subject: [PATCH 14/27] For #1579, define signals for fast/grace quit and upgrade --- trunk/src/app/srs_app_server.cpp | 10 +++++----- trunk/src/app/srs_app_server.hpp | 5 +++-- trunk/src/kernel/srs_kernel_consts.hpp | 11 +++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 8768ff642..71af22927 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -395,7 +395,7 @@ srs_error_t SrsSignalManager::start() sa.sa_handler = SrsSignalManager::sig_catcher; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; - sigaction(SRS_SIGNAL_GRACEFULLY_QUIT, &sa, NULL); + sigaction(SRS_SIGNAL_FAST_QUIT, &sa, NULL); sa.sa_handler = SrsSignalManager::sig_catcher; sigemptyset(&sa.sa_mask); @@ -407,8 +407,8 @@ srs_error_t SrsSignalManager::start() sa.sa_flags = 0; sigaction(SRS_SIGNAL_REOPEN_LOG, &sa, NULL); - srs_trace("signal installed, reload=%d, reopen=%d, grace_quit=%d", - SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_GRACEFULLY_QUIT); + srs_trace("signal installed, reload=%d, reopen=%d, fast_quit=%d", + SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_FAST_QUIT); if ((err = trd->start()) != srs_success) { return srs_error_wrap(err, "signal manager"); @@ -863,8 +863,8 @@ void SrsServer::on_signal(int signo) #endif } - if ((signo == SIGINT || signo == SRS_SIGNAL_GRACEFULLY_QUIT) && !signal_gracefully_quit) { - srs_trace("sig=%d, user terminate program, gracefully quit", signo); + if ((signo == SIGINT || signo == SRS_SIGNAL_FAST_QUIT) && !signal_gracefully_quit) { + srs_trace("sig=%d, user terminate program, fast quit", signo); signal_gracefully_quit = true; return; } diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index fd8cbe3ad..5ab4f011f 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -260,12 +260,13 @@ public: // The signal manager convert signal to io message, // whatever, we will got the signo like the orignal signal(int signo) handler. // @param signo the signal number from user, where: - // SRS_SIGNAL_GRACEFULLY_QUIT, the SIGTERM, dispose then quit. + // SRS_SIGNAL_FAST_QUIT, the SIGTERM, do essential dispose then quit. + // SRS_SIGNAL_GRACEFULLY_QUIT, the SIGQUIT, do careful dispose then quit. // SRS_SIGNAL_REOPEN_LOG, the SIGUSR1, reopen the log file. // SRS_SIGNAL_RELOAD, the SIGHUP, reload the config. // SRS_SIGNAL_PERSISTENCE_CONFIG, application level signal, persistence config to file. // @remark, for SIGINT: - // no gmc, directly exit. + // no gmc, fast quit, do essential dispose then quit. // for gmc, set the variable signal_gmc_stop, the cycle will return and cleanup for gmc. // @remark, maybe the HTTP RAW API will trigger the on_signal() also. virtual void on_signal(int signo); diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index b470c644e..aa2860f3a 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -124,8 +124,15 @@ #define SRS_SIGNAL_RELOAD SIGHUP // Reopen the log file. #define SRS_SIGNAL_REOPEN_LOG SIGUSR1 -// The signal for srs to gracefully quit, do dispose then exit. -#define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM +// For gracefully upgrade, start new SRS and gracefully quit old one. +// @see https://github.com/ossrs/srs/issues/1579 +// TODO: Not implemented. +#define SRS_SIGNAL_UPGRADE SIGUSR2 +// The signal for srs to fast quit, do essential dispose then exit. +#define SRS_SIGNAL_FAST_QUIT SIGTERM +// The signal for srs to gracefully quit, do carefully dispose then exit. +// TODO: FIXME: Not implemented. +#define SRS_SIGNAL_GRACEFULLY_QUIT SIGQUIT // The application level signals. // Persistence the config in memory to config file. From e6c329293c72f353aa674b9002235c8292535523 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 15:07:15 +0800 Subject: [PATCH 15/27] Refine log --- trunk/src/kernel/srs_kernel_consts.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index aa2860f3a..a1a946e62 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -131,6 +131,7 @@ // The signal for srs to fast quit, do essential dispose then exit. #define SRS_SIGNAL_FAST_QUIT SIGTERM // The signal for srs to gracefully quit, do carefully dispose then exit. +// @see https://github.com/ossrs/srs/issues/1579 // TODO: FIXME: Not implemented. #define SRS_SIGNAL_GRACEFULLY_QUIT SIGQUIT @@ -153,7 +154,7 @@ // Downloading speed-up, play to edge, ingest from origin #define SRS_CONSTS_LOG_EDGE_PLAY "EIG" // Uploading speed-up, publish to edge, foward to origin -#define SRS_CONSTS_LOG_EDGE_PUBLISH "EFW" +#define SRS_CONSTS_LOG_EDGE_PUBLISH "EPB" // The edge/origin forwarder. #define SRS_CONSTS_LOG_FOWARDER "FWR" // Play stream on edge/origin. From 3c597545b1dbf8938e56ffb4bebce68409c07e16 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 19:59:47 +0800 Subject: [PATCH 16/27] For #1579, support gracefully quit. 3.0.119 --- README.md | 2 + trunk/conf/full.conf | 4 ++ trunk/etc/init.d/srs | 18 +++++- trunk/src/app/srs_app_config.cpp | 14 +++- trunk/src/app/srs_app_config.hpp | 2 + trunk/src/app/srs_app_ffmpeg.cpp | 2 +- trunk/src/app/srs_app_server.cpp | 88 ++++++++++++++++++++++---- trunk/src/app/srs_app_server.hpp | 4 ++ trunk/src/core/srs_core_version3.hpp | 2 +- trunk/src/kernel/srs_kernel_consts.hpp | 1 - 10 files changed, 120 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7e94b13bd..c99ca714b 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit. 3.0.119 * v3.0, 2020-02-17, For [#1601][bug #1601], flush async on_dvr/on_hls events before stop. 3.0.118 * v3.0, 2020-02-14, [3.0 beta1(3.0.117)][r3.0b1] released. 121964 lines. * v3.0, 2020-02-14, For [#1595][bug #1595], migrating streaming from ossrs.net to r.ossrs.net. 3.0.117 @@ -1651,6 +1652,7 @@ Winlin [bug #665]: https://github.com/ossrs/srs/issues/665 [bug #1595]: https://github.com/ossrs/srs/issues/1595 [bug #1601]: https://github.com/ossrs/srs/issues/1601 +[bug #1579]: https://github.com/ossrs/srs/issues/1579 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index c1e268ad8..137d91884 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -73,6 +73,10 @@ work_dir ./; # default: off asprocess off; +# for gracefully quit, final wait for cleanup in milliseconds. +# default: 3200 +grace_final_wait 3200; + ############################################################################################# # heartbeat/stats sections ############################################################################################# diff --git a/trunk/etc/init.d/srs b/trunk/etc/init.d/srs index 7e749044d..0e2afca4b 100755 --- a/trunk/etc/init.d/srs +++ b/trunk/etc/init.d/srs @@ -178,6 +178,18 @@ logrotate() { return 0 } +grace() { + # not start, exit + load_process_info + if [[ 0 -ne $? ]]; then failed_msg "SRS not start."; return 0; fi + + ok_msg "Gracefully quit for SRS(pid ${srs_pid})..." + kill -s SIGQUIT ${srs_pid} + + ok_msg "Gracefully quit" + return 0 +} + menu() { case "$1" in start) @@ -199,10 +211,14 @@ menu() { rotate) logrotate ;; + grace) + grace + ;; *) - echo "Usage: $0 {start|stop|status|restart|reload|rotate}" + echo "Usage: $0 {start|stop|status|restart|reload|rotate|grace}" echo " reload Apply log file by not restarting SRS" echo " rotate For log rotate, to send SIGUSR1 to SRS to reopen the log file." + echo " grace For gracefully quit, to send SIGQUIT to SRS." return 1 ;; esac diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 79a5b5caf..363ad358b 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3487,7 +3487,7 @@ srs_error_t SrsConfig::check_normal_config() && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" && n != "http_server" && n != "stream_caster" && n != "utc_time" && n != "work_dir" && n != "asprocess" - && n != "ff_log_level" + && n != "ff_log_level" && n != "grace_final_wait" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4050,6 +4050,18 @@ bool SrsConfig::get_asprocess() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +srs_utime_t SrsConfig::get_grace_final_wait() +{ + static srs_utime_t DEFAULT = 3200 * SRS_UTIME_MILLISECONDS; + + SrsConfDirective* conf = root->get("grace_final_wait"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return (srs_utime_t)(::atol(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); +} + vector SrsConfig::get_stream_casters() { srs_assert(root); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index e814b8777..3c04c3bdb 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -468,6 +468,8 @@ public: virtual std::string get_work_dir(); // Whether use asprocess mode. virtual bool get_asprocess(); + // Get the final wait in ms for gracefully quit. + virtual srs_utime_t get_grace_final_wait(); // stream_caster section public: // Get all stream_caster in config file. diff --git a/trunk/src/app/srs_app_ffmpeg.cpp b/trunk/src/app/srs_app_ffmpeg.cpp index e9c87a70e..1cde4f5f9 100644 --- a/trunk/src/app/srs_app_ffmpeg.cpp +++ b/trunk/src/app/srs_app_ffmpeg.cpp @@ -230,7 +230,7 @@ srs_error_t SrsFFMPEG::start() params.push_back(ffmpeg); // input params - for (int i = 0; i < iparams.size(); i++) { + for (int i = 0; i < (int)iparams.size(); i++) { string iparam = iparams.at(i); if (!iparam.empty()) { params.push_back(iparam); diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 71af22927..4c0a4b2fb 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -396,6 +396,11 @@ srs_error_t SrsSignalManager::start() sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SRS_SIGNAL_FAST_QUIT, &sa, NULL); + + sa.sa_handler = SrsSignalManager::sig_catcher; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SRS_SIGNAL_GRACEFULLY_QUIT, &sa, NULL); sa.sa_handler = SrsSignalManager::sig_catcher; sigemptyset(&sa.sa_mask); @@ -407,8 +412,8 @@ srs_error_t SrsSignalManager::start() sa.sa_flags = 0; sigaction(SRS_SIGNAL_REOPEN_LOG, &sa, NULL); - srs_trace("signal installed, reload=%d, reopen=%d, fast_quit=%d", - SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_FAST_QUIT); + srs_trace("signal installed, reload=%d, reopen=%d, fast_quit=%d, grace_quit=%d", + SRS_SIGNAL_RELOAD, SRS_SIGNAL_REOPEN_LOG, SRS_SIGNAL_FAST_QUIT, SRS_SIGNAL_GRACEFULLY_QUIT); if ((err = trd->start()) != srs_success) { return srs_error_wrap(err, "signal manager"); @@ -465,6 +470,7 @@ SrsServer::SrsServer() signal_reload = false; signal_persistence_config = false; signal_gmc_stop = false; + signal_fast_quit = false; signal_gracefully_quit = false; pid_fd = -1; @@ -533,6 +539,44 @@ void SrsServer::dispose() #endif } +void SrsServer::gracefully_dispose() +{ + _srs_config->unsubscribe(this); + + // prevent fresh clients. + close_listeners(SrsListenerRtmpStream); + close_listeners(SrsListenerHttpApi); + close_listeners(SrsListenerHttpStream); + close_listeners(SrsListenerMpegTsOverUdp); + close_listeners(SrsListenerRtsp); + close_listeners(SrsListenerFlv); + + // Fast stop to notify FFMPEG to quit, wait for a while then fast kill. + ingester->stop(); + + // Wait for connections to quit. + // While gracefully quiting, user can requires SRS to fast quit. + int wait_step = 1; + while (!conns.empty() && !signal_fast_quit) { + for (int i = 0; i < wait_step && !conns.empty() && !signal_fast_quit; i++) { + srs_usleep(1000 * SRS_UTIME_MILLISECONDS); + } + + wait_step = (wait_step * 2) % 33; + srs_trace("wait for %d conns to quit", conns.size()); + } + + // dispose the source for hls and dvr. + _srs_sources->dispose(); + +#ifdef SRS_AUTO_MEM_WATCH + srs_memory_report(); +#endif + + srs_usleep(_srs_config->get_grace_final_wait()); + srs_trace("final wait for another %dms", srsu2msi(_srs_config->get_grace_final_wait())); +} + srs_error_t SrsServer::initialize(ISrsServerCycle* ch) { srs_error_t err = srs_success; @@ -807,19 +851,33 @@ srs_error_t SrsServer::cycle() srs_warn("sleep a long time for system st-threads to cleanup."); srs_usleep(3 * 1000 * 1000); srs_warn("system quit"); -#else - // normally quit with neccessary cleanup by dispose(). + + return err; +#endif + + // quit normally. srs_warn("main cycle terminated, system quit normally."); - dispose(); + + // fast quit, do some essential cleanup. + if (signal_fast_quit) { + dispose(); + srs_trace("srs disposed"); + } + + // gracefully quit, do carefully cleanup. + if (signal_gracefully_quit) { + gracefully_dispose(); + srs_trace("srs gracefully quit"); + } + srs_trace("srs terminated"); // for valgrind to detect. srs_freep(_srs_config); srs_freep(_srs_log); - + exit(0); -#endif - + return err; } @@ -863,8 +921,14 @@ void SrsServer::on_signal(int signo) #endif } - if ((signo == SIGINT || signo == SRS_SIGNAL_FAST_QUIT) && !signal_gracefully_quit) { + if ((signo == SIGINT || signo == SRS_SIGNAL_FAST_QUIT) && !signal_fast_quit) { srs_trace("sig=%d, user terminate program, fast quit", signo); + signal_fast_quit = true; + return; + } + + if (signo == SRS_SIGNAL_GRACEFULLY_QUIT && !signal_gracefully_quit) { + srs_trace("sig=%d, user start gracefully quit", signo); signal_gracefully_quit = true; return; } @@ -909,9 +973,9 @@ srs_error_t SrsServer::do_cycle() return srs_error_new(ERROR_ASPROCESS_PPID, "asprocess ppid changed from %d to %d", ppid, ::getppid()); } - // gracefully quit for SIGINT or SIGTERM. - if (signal_gracefully_quit) { - srs_trace("cleanup for gracefully terminate."); + // gracefully quit for SIGINT or SIGTERM or SIGQUIT. + if (signal_fast_quit || signal_gracefully_quit) { + srs_trace("cleanup for quit signal fast=%d, grace=%d", signal_fast_quit, signal_gracefully_quit); return err; } diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 5ab4f011f..28154600e 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -227,6 +227,7 @@ private: bool signal_reload; bool signal_persistence_config; bool signal_gmc_stop; + bool signal_fast_quit; bool signal_gracefully_quit; // Parent pid for asprocess. int ppid; @@ -241,6 +242,9 @@ private: // When SIGTERM, SRS should do cleanup, for example, // to stop all ingesters, cleanup HLS and dvr. virtual void dispose(); + // Close listener to stop accepting new connections, + // then wait and quit when all connections finished. + virtual void gracefully_dispose(); // server startup workflow, @see run_master() public: // Initialize server with callback handler ch. diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 4ddcca91c..c27634123 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 118 +#define SRS_VERSION3_REVISION 119 #endif diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index a1a946e62..208765ae7 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -132,7 +132,6 @@ #define SRS_SIGNAL_FAST_QUIT SIGTERM // The signal for srs to gracefully quit, do carefully dispose then exit. // @see https://github.com/ossrs/srs/issues/1579 -// TODO: FIXME: Not implemented. #define SRS_SIGNAL_GRACEFULLY_QUIT SIGQUIT // The application level signals. From 58b40478b67c956ab9accc016f18a45898692bac Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 22:15:12 +0800 Subject: [PATCH 17/27] For #1579, support force gracefully quit. 3.0.120 --- README.md | 1 + trunk/conf/full.conf | 9 ++++++++- trunk/src/app/srs_app_config.cpp | 14 +++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_server.cpp | 9 ++++++++- trunk/src/core/srs_core_version3.hpp | 2 +- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c99ca714b..9bb47c208 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-18, For [#1579][bug #1579], support force gracefully quit. 3.0.120 * v3.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit. 3.0.119 * v3.0, 2020-02-17, For [#1601][bug #1601], flush async on_dvr/on_hls events before stop. 3.0.118 * v3.0, 2020-02-14, [3.0 beta1(3.0.117)][r3.0b1] released. 121964 lines. diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 137d91884..e535e84ce 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -73,9 +73,16 @@ work_dir ./; # default: off asprocess off; -# for gracefully quit, final wait for cleanup in milliseconds. +# For gracefully quit, final wait for cleanup in milliseconds. +# @see https://github.com/ossrs/srs/issues/1579#issuecomment-587414898 # default: 3200 grace_final_wait 3200; +# Whether force gracefully quit, never fast quit. +# By default, SIGTERM which means fast quit, is sent by K8S, so we need to +# force SRS to treat SIGTERM as gracefully quit for gray release or canary. +# @see https://github.com/ossrs/srs/issues/1579#issuecomment-587475077 +# default: off +force_grace_quit off; ############################################################################################# # heartbeat/stats sections diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 363ad358b..ea517ff7f 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3487,7 +3487,7 @@ srs_error_t SrsConfig::check_normal_config() && n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms" && n != "http_server" && n != "stream_caster" && n != "utc_time" && n != "work_dir" && n != "asprocess" - && n != "ff_log_level" && n != "grace_final_wait" + && n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4062,6 +4062,18 @@ srs_utime_t SrsConfig::get_grace_final_wait() return (srs_utime_t)(::atol(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); } +bool SrsConfig::is_force_grace_quit() +{ + static bool DEFAULT = false; + + SrsConfDirective* conf = root->get("force_grace_quit"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_FALSE(conf->arg0()); +} + vector SrsConfig::get_stream_casters() { srs_assert(root); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 3c04c3bdb..d835bf846 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -470,6 +470,8 @@ public: virtual bool get_asprocess(); // Get the final wait in ms for gracefully quit. virtual srs_utime_t get_grace_final_wait(); + // Whether force to gracefully quit, never fast quit. + virtual bool is_force_grace_quit(); // stream_caster section public: // Get all stream_caster in config file. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 4c0a4b2fb..22d0f857e 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -920,7 +920,14 @@ void SrsServer::on_signal(int signo) #endif #endif } - + + // For K8S, force to gracefully quit for gray release or canary. + // @see https://github.com/ossrs/srs/issues/1595#issuecomment-587473037 + if (signo == SRS_SIGNAL_FAST_QUIT && _srs_config->is_force_grace_quit()) { + srs_trace("force gracefully quit, signo=%d", signo); + signo = SRS_SIGNAL_GRACEFULLY_QUIT; + } + if ((signo == SIGINT || signo == SRS_SIGNAL_FAST_QUIT) && !signal_fast_quit) { srs_trace("sig=%d, user terminate program, fast quit", signo); signal_fast_quit = true; diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index c27634123..4e9f290ae 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 119 +#define SRS_VERSION3_REVISION 120 #endif From d87f58a61163d7a933c0edd478f206b2a17aedf3 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 22:16:28 +0800 Subject: [PATCH 18/27] For #1579, support gracefully quit and force to. 4.0.5 --- README.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da76c363a..53fbc2005 100755 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit and force to. 4.0.5 * v4.0, 2020-02-13, SRT supports detail config for [DynamicEncoding](https://github.com/runner365/srt_encoder). 4.0.4 * v4.0, 2020-02-04, Update project code. 4.0.3 * v4.0, 2020-01-26, Allow use libsrt.so for SRT is MPL license. 4.0.2 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 208807ee9..7677a2d67 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION4_HPP #define SRS_CORE_VERSION4_HPP -#define SRS_VERSION4_REVISION 4 +#define SRS_VERSION4_REVISION 5 #endif From dc0f804452a5f8d4a919b43d59a06cb296b3aff7 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 23:37:11 +0800 Subject: [PATCH 19/27] For #1579, support start/final wait for gracefully quit. 3.0.121 --- README.md | 1 + trunk/conf/full.conf | 6 ++++++ trunk/src/app/srs_app_config.cpp | 13 +++++++++++++ trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_server.cpp | 6 +++++- trunk/src/core/srs_core_version3.hpp | 2 +- 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bb47c208..eb7664c91 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 3.0.121 * v3.0, 2020-02-18, For [#1579][bug #1579], support force gracefully quit. 3.0.120 * v3.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit. 3.0.119 * v3.0, 2020-02-17, For [#1601][bug #1601], flush async on_dvr/on_hls events before stop. 3.0.118 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index e535e84ce..65d5ddb48 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -73,6 +73,12 @@ work_dir ./; # default: off asprocess off; +# For gracefully quit, wait for a while then close listeners, +# because K8S notify SRS with SIGQUIT and update Service simultaneously, +# maybe there is some new connections incoming before Service updated. +# @see https://github.com/ossrs/srs/issues/1595#issuecomment-587516567 +# default: 2300 +grace_start_wait 2300; # For gracefully quit, final wait for cleanup in milliseconds. # @see https://github.com/ossrs/srs/issues/1579#issuecomment-587414898 # default: 3200 diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index ea517ff7f..3c0af54de 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3488,6 +3488,7 @@ srs_error_t SrsConfig::check_normal_config() && n != "http_server" && n != "stream_caster" && n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit" + && n != "grace_start_wait" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4050,6 +4051,18 @@ bool SrsConfig::get_asprocess() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +srs_utime_t SrsConfig::get_grace_start_wait() +{ + static srs_utime_t DEFAULT = 2300 * SRS_UTIME_MILLISECONDS; + + SrsConfDirective* conf = root->get("grace_start_wait"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return (srs_utime_t)(::atol(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); +} + srs_utime_t SrsConfig::get_grace_final_wait() { static srs_utime_t DEFAULT = 3200 * SRS_UTIME_MILLISECONDS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index d835bf846..2bd2882b3 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -468,6 +468,8 @@ public: virtual std::string get_work_dir(); // Whether use asprocess mode. virtual bool get_asprocess(); + // Get the start wait in ms for gracefully quit. + virtual srs_utime_t get_grace_start_wait(); // Get the final wait in ms for gracefully quit. virtual srs_utime_t get_grace_final_wait(); // Whether force to gracefully quit, never fast quit. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 22d0f857e..b82cb9197 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -543,6 +543,10 @@ void SrsServer::gracefully_dispose() { _srs_config->unsubscribe(this); + // Always wait for a while to start. + srs_usleep(_srs_config->get_grace_start_wait()); + srs_trace("start wait for %dms", srsu2msi(_srs_config->get_grace_start_wait())); + // prevent fresh clients. close_listeners(SrsListenerRtmpStream); close_listeners(SrsListenerHttpApi); @@ -574,7 +578,7 @@ void SrsServer::gracefully_dispose() #endif srs_usleep(_srs_config->get_grace_final_wait()); - srs_trace("final wait for another %dms", srsu2msi(_srs_config->get_grace_final_wait())); + srs_trace("final wait for %dms", srsu2msi(_srs_config->get_grace_final_wait())); } srs_error_t SrsServer::initialize(ISrsServerCycle* ch) diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 4e9f290ae..ac541b5e4 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 120 +#define SRS_VERSION3_REVISION 121 #endif From ad3cfbfd2c321b6a67106dc4cce374722c818f7d Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 18 Feb 2020 23:39:40 +0800 Subject: [PATCH 20/27] For #1579, support start/final wait for gracefully quit. 4.0.6 --- README.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cc57334b..628a135f6 100755 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 4.0.6 * v4.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit and force to. 4.0.5 * v4.0, 2020-02-13, SRT supports detail config for [DynamicEncoding](https://github.com/runner365/srt_encoder). 4.0.4 * v4.0, 2020-02-04, Update project code. 4.0.3 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 7677a2d67..8e9e26875 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION4_HPP #define SRS_CORE_VERSION4_HPP -#define SRS_VERSION4_REVISION 5 +#define SRS_VERSION4_REVISION 6 #endif From 1d01ef499d0be5be068c74c8d35439b96bd2ee3a Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 20 Feb 2020 01:06:33 +0800 Subject: [PATCH 21/27] For #1579, support rolling update of k8s. 4.0.7 --- README.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 628a135f6..99dd9e68f 100755 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-02-19, For [#1579][bug #1579], support rolling update of k8s. 4.0.7 * v4.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 4.0.6 * v4.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit and force to. 4.0.5 * v4.0, 2020-02-13, SRT supports detail config for [DynamicEncoding](https://github.com/runner365/srt_encoder). 4.0.4 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 8e9e26875..f6717ca54 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION4_HPP #define SRS_CORE_VERSION4_HPP -#define SRS_VERSION4_REVISION 6 +#define SRS_VERSION4_REVISION 7 #endif From 4a69499f2c989c6748517a6efdd8c490ca7c4b4b Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 21 Feb 2020 23:11:09 +0800 Subject: [PATCH 22/27] Fix bug for librtmp client ipv4/ipv6 socket. 3.0.122 --- README.md | 1 + trunk/src/core/srs_core_version3.hpp | 2 +- trunk/src/libs/srs_lib_simple_socket.cpp | 45 +++++++++++++++++------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index eb7664c91..4f4ee7545 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-21, Fix bug for librtmp client ipv4/ipv6 socket. 3.0.122 * v3.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 3.0.121 * v3.0, 2020-02-18, For [#1579][bug #1579], support force gracefully quit. 3.0.120 * v3.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit. 3.0.119 diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index ac541b5e4..801fd91fe 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 121 +#define SRS_VERSION3_REVISION 122 #endif diff --git a/trunk/src/libs/srs_lib_simple_socket.cpp b/trunk/src/libs/srs_lib_simple_socket.cpp index d67a48308..59adf2278 100644 --- a/trunk/src/libs/srs_lib_simple_socket.cpp +++ b/trunk/src/libs/srs_lib_simple_socket.cpp @@ -77,8 +77,11 @@ #ifndef SRS_HIJACK_IO struct SrsBlockSyncSocket { + int family; SOCKET fd; - int family; + SOCKET fdv4; + SOCKET fdv6; + // Bytes transmit. int64_t rbytes; int64_t sbytes; // The send/recv timeout in ms. @@ -86,15 +89,26 @@ struct SrsBlockSyncSocket int64_t stm; SrsBlockSyncSocket() { + family = AF_UNSPEC; stm = rtm = SRS_UTIME_NO_TIMEOUT; rbytes = sbytes = 0; SOCKET_RESET(fd); + SOCKET_RESET(fdv4); + SOCKET_RESET(fdv6); SOCKET_SETUP(); } virtual ~SrsBlockSyncSocket() { - SOCKET_CLOSE(fd); + if (SOCKET_VALID(fd)) { + SOCKET_CLOSE(fd); + } + if (SOCKET_VALID(fdv4)) { + SOCKET_CLOSE(fdv4); + } + if (SOCKET_VALID(fdv6)) { + SOCKET_CLOSE(fdv6); + } SOCKET_CLEANUP(); } }; @@ -112,19 +126,17 @@ int srs_hijack_io_create_socket(srs_hijack_io_t ctx, srs_rtmp_t owner) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - skt->family = AF_INET6; - skt->fd = ::socket(skt->family, SOCK_STREAM, 0); // Try IPv6 first. - if (!SOCKET_VALID(skt->fd)) { - skt->family = AF_INET; - skt->fd = ::socket(skt->family, SOCK_STREAM, 0); // Try IPv4 instead, if IPv6 fails. - } - if (!SOCKET_VALID(skt->fd)) { + skt->family = AF_UNSPEC; + skt->fdv4 = ::socket(AF_INET, SOCK_STREAM, 0); + skt->fdv6 = ::socket(AF_INET6, SOCK_STREAM, 0); + if (!SOCKET_VALID(skt->fdv4) && !SOCKET_VALID(skt->fdv4)) { return ERROR_SOCKET_CREATE; } // No TCP cache. int v = 1; - setsockopt(skt->fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)); + setsockopt(skt->fdv4, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)); + setsockopt(skt->fdv6, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)); return ERROR_SUCCESS; } @@ -137,7 +149,7 @@ int srs_hijack_io_connect(srs_hijack_io_t ctx, const char* server_ip, int port) addrinfo hints; memset(&hints, 0, sizeof(hints)); - hints.ai_family = skt->family; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; addrinfo* r = NULL; @@ -145,7 +157,16 @@ int srs_hijack_io_connect(srs_hijack_io_t ctx, const char* server_ip, int port) if(getaddrinfo(server_ip, sport, (const addrinfo*)&hints, &r)) { return ERROR_SOCKET_CONNECT; } - + + skt->family = r->ai_family; + if (r->ai_family == AF_INET6) { + skt->fd = skt->fdv6; + SOCKET_RESET(skt->fdv6); + } else { + skt->fd = skt->fdv4; + SOCKET_RESET(skt->fdv4); + } + if(::connect(skt->fd, r->ai_addr, r->ai_addrlen) < 0){ return ERROR_SOCKET_CONNECT; } From 20b9d6ab026620cdcc773725169ac745bcea6802 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 21 Feb 2020 23:51:40 +0800 Subject: [PATCH 23/27] For #1598, support SLB health checking by TCP. 3.0.123 --- README.md | 2 ++ trunk/conf/full.conf | 4 ++++ trunk/src/app/srs_app_caster_flv.cpp | 6 +++++- trunk/src/app/srs_app_config.cpp | 14 +++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_rtsp.cpp | 3 +++ trunk/src/app/srs_app_server.cpp | 4 ++++ trunk/src/core/srs_core_version3.hpp | 2 +- 8 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f4ee7545..e72c4e14f 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-02-21, For [#1598][bug #1598], support SLB health checking by TCP. 3.0.123 * v3.0, 2020-02-21, Fix bug for librtmp client ipv4/ipv6 socket. 3.0.122 * v3.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 3.0.121 * v3.0, 2020-02-18, For [#1579][bug #1579], support force gracefully quit. 3.0.120 @@ -1656,6 +1657,7 @@ Winlin [bug #1595]: https://github.com/ossrs/srs/issues/1595 [bug #1601]: https://github.com/ossrs/srs/issues/1601 [bug #1579]: https://github.com/ossrs/srs/issues/1579 +[bug #1598]: https://github.com/ossrs/srs/issues/1598 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 65d5ddb48..b56f27fbc 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -72,6 +72,10 @@ work_dir ./; # @reamrk do not support reload. # default: off asprocess off; +# Whether client empty IP is ok, for example, health checking by SLB. +# If ok(on), we will ignore this connection without warnings or errors. +# default: on +empty_ip_ok on; # For gracefully quit, wait for a while then close listeners, # because K8S notify SRS with SIGQUIT and update Service simultaneously, diff --git a/trunk/src/app/srs_app_caster_flv.cpp b/trunk/src/app/srs_app_caster_flv.cpp index 7526921cc..d6f3150f7 100644 --- a/trunk/src/app/srs_app_caster_flv.cpp +++ b/trunk/src/app/srs_app_caster_flv.cpp @@ -76,8 +76,12 @@ srs_error_t SrsAppCasterFlv::initialize() srs_error_t SrsAppCasterFlv::on_tcp_client(srs_netfd_t stfd) { srs_error_t err = srs_success; - + string ip = srs_get_peer_ip(srs_netfd_fileno(stfd)); + if (ip.empty() && !_srs_config->empty_ip_ok()) { + srs_warn("empty ip for fd=%d", srs_netfd_fileno(stfd)); + } + SrsHttpConn* conn = new SrsDynamicHttpConn(this, stfd, http_mux, ip); conns.push_back(conn); diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 3c0af54de..3eb7483a5 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3488,7 +3488,7 @@ srs_error_t SrsConfig::check_normal_config() && n != "http_server" && n != "stream_caster" && n != "utc_time" && n != "work_dir" && n != "asprocess" && n != "ff_log_level" && n != "grace_final_wait" && n != "force_grace_quit" - && n != "grace_start_wait" + && n != "grace_start_wait" && n != "empty_ip_ok" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4051,6 +4051,18 @@ bool SrsConfig::get_asprocess() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +bool SrsConfig::empty_ip_ok() +{ + static bool DEFAULT = true; + + SrsConfDirective* conf = root->get("empty_ip_ok"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_TRUE(conf->arg0()); +} + srs_utime_t SrsConfig::get_grace_start_wait() { static srs_utime_t DEFAULT = 2300 * SRS_UTIME_MILLISECONDS; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 2bd2882b3..0b94470da 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -468,6 +468,8 @@ public: virtual std::string get_work_dir(); // Whether use asprocess mode. virtual bool get_asprocess(); + // Whether empty client IP is ok. + virtual bool empty_ip_ok(); // Get the start wait in ms for gracefully quit. virtual srs_utime_t get_grace_start_wait(); // Get the final wait in ms for gracefully quit. diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 051071b49..62ebfdcd1 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -243,6 +243,9 @@ srs_error_t SrsRtspConn::do_cycle() // retrieve ip of client. std::string ip = srs_get_peer_ip(srs_netfd_fileno(stfd)); + if (ip.empty() && !_srs_config->empty_ip_ok()) { + srs_warn("empty ip for fd=%d", srs_netfd_fileno(stfd)); + } srs_trace("rtsp: serve %s", ip.c_str()); // consume all rtsp messages. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index b82cb9197..632ff9fc5 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -1237,6 +1237,10 @@ srs_error_t SrsServer::accept_client(SrsListenerType type, srs_netfd_t stfd) SrsConnection* conn = NULL; if ((err = fd2conn(type, stfd, &conn)) != srs_success) { + if (srs_error_code(err) == ERROR_SOCKET_GET_PEER_IP && _srs_config->empty_ip_ok()) { + srs_close_stfd(stfd); srs_error_reset(err); + return srs_success; + } return srs_error_wrap(err, "fd2conn"); } srs_assert(conn); diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 801fd91fe..c871670b0 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 122 +#define SRS_VERSION3_REVISION 123 #endif From 67d78dff0e283ec3c031211225cffc7432f54db9 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 21 Feb 2020 23:56:40 +0800 Subject: [PATCH 24/27] For #1598, support SLB health checking by TCP. 4.0.8 --- README.md | 1 + trunk/src/core/srs_core_version4.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46194a505..56658c3dc 100755 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-02-21, For [#1598][bug #1598], support SLB health checking by TCP. 4.0.8 * v4.0, 2020-02-19, For [#1579][bug #1579], support rolling update of k8s. 4.0.7 * v4.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 4.0.6 * v4.0, 2020-02-18, For [#1579][bug #1579], support gracefully quit and force to. 4.0.5 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index f6717ca54..f5d2ad53c 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION4_HPP #define SRS_CORE_VERSION4_HPP -#define SRS_VERSION4_REVISION 7 +#define SRS_VERSION4_REVISION 8 #endif From 90afd06c85fb76e81f6a9d9931649fffde1713b0 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 25 Feb 2020 13:22:44 +0800 Subject: [PATCH 25/27] For #1615, support default app(live) for vmix SRT. 4.0.9 --- README.md | 2 ++ trunk/conf/full.conf | 3 +++ trunk/src/app/srs_app_config.cpp | 17 ++++++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/core/srs_core_version4.hpp | 2 +- trunk/src/srt/srt_conn.cpp | 4 +++- 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 56658c3dc..bec6c8de6 100755 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-02-25, For [#1615][bug #1615], support default app(live) for vmix SRT. 4.0.9 * v4.0, 2020-02-21, For [#1598][bug #1598], support SLB health checking by TCP. 4.0.8 * v4.0, 2020-02-19, For [#1579][bug #1579], support rolling update of k8s. 4.0.7 * v4.0, 2020-02-18, For [#1579][bug #1579], support start/final wait for gracefully quit. 4.0.6 @@ -1685,6 +1686,7 @@ Winlin [bug #1601]: https://github.com/ossrs/srs/issues/1601 [bug #1579]: https://github.com/ossrs/srs/issues/1579 [bug #1598]: https://github.com/ossrs/srs/issues/1598 +[bug #1615]: https://github.com/ossrs/srs/issues/1615 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 3352538b6..928925e00 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -290,6 +290,9 @@ srt_server { connect_timeout 4000; peerlatency 300; recvlatency 300; + # Default app for vmix, see https://github.com/ossrs/srs/pull/1615 + # default: live + default_app live; } ############################################################################################# diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 89f3da8b5..0eaabb4c9 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3529,7 +3529,8 @@ srs_error_t SrsConfig::check_normal_config() if (n != "enabled" && n != "listen" && n != "maxbw" && n != "mss" && n != "latency" && n != "recvlatency" && n != "peerlatency" && n != "tlpkdrop" && n != "connect_timeout" - && n != "sendbuf" && n != "recvbuf" && n != "payloadsize") { + && n != "sendbuf" && n != "recvbuf" && n != "payloadsize" + && n != "default_app") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal srt_stream.%s", n.c_str()); } } @@ -6893,6 +6894,20 @@ int SrsConfig::get_srto_payloadsize() { return atoi(conf->arg0().c_str()); } +string SrsConfig::get_default_app_name() { + static string DEFAULT = "live"; + SrsConfDirective* conf = root->get("srt_server"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("default_app"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + return conf->arg0(); +} + bool SrsConfig::get_http_stream_enabled() { SrsConfDirective* conf = root->get("http_server"); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 17bcd4963..dde708f8e 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -623,6 +623,8 @@ public: virtual int get_srto_recvbuf(); // SRTO_PAYLOADSIZE virtual int get_srto_payloadsize(); + // Get the default app. + virtual std::string get_default_app_name(); // http_hooks section private: diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index f5d2ad53c..da3e2b804 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION4_HPP #define SRS_CORE_VERSION4_HPP -#define SRS_VERSION4_REVISION 8 +#define SRS_VERSION4_REVISION 9 #endif diff --git a/trunk/src/srt/srt_conn.cpp b/trunk/src/srt/srt_conn.cpp index 4ea90bda1..e2f18af27 100644 --- a/trunk/src/srt/srt_conn.cpp +++ b/trunk/src/srt/srt_conn.cpp @@ -3,6 +3,8 @@ #include "stringex.hpp" #include +#include + bool is_streamid_valid(const std::string& streamid) { if (streamid.empty()) { return false; @@ -71,7 +73,7 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_ if (pos != 0) { pos = streamid.find("/"); if (pos == streamid.npos) { - url_subpath = "live/" + streamid; + url_subpath = _srs_config->get_default_app_name() + "/" + streamid; return true; } url_subpath = streamid; From 04d0620ddeffeb640167e0a7ee7877bdae25d6ca Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 25 Feb 2020 13:45:05 +0800 Subject: [PATCH 26/27] For #1615, fix build failed and srt api issue --- trunk/src/core/srs_core_mem_watch.cpp | 2 +- trunk/src/protocol/srs_protocol_utility.cpp | 2 +- trunk/src/srt/srt_server.cpp | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/trunk/src/core/srs_core_mem_watch.cpp b/trunk/src/core/srs_core_mem_watch.cpp index 701795fa9..dbc6c9411 100644 --- a/trunk/src/core/srs_core_mem_watch.cpp +++ b/trunk/src/core/srs_core_mem_watch.cpp @@ -74,7 +74,7 @@ void srs_memory_report() std::map::iterator it; for (it = _srs_ptrs.begin(); it != _srs_ptrs.end(); ++it) { SrsMemoryObject* obj = it->second; - printf(" %s: %#"PRIx64", %dB\n", obj->category.c_str(), (int64_t)obj->ptr, obj->size); + printf(" %s: %#" PRIx64 ", %dB\n", obj->category.c_str(), (int64_t)obj->ptr, obj->size); total += obj->size; } diff --git a/trunk/src/protocol/srs_protocol_utility.cpp b/trunk/src/protocol/srs_protocol_utility.cpp index 28141f625..251d69854 100644 --- a/trunk/src/protocol/srs_protocol_utility.cpp +++ b/trunk/src/protocol/srs_protocol_utility.cpp @@ -122,7 +122,7 @@ void srs_discovery_tc_url(string tcUrl, string& schema, string& host, string& vh srs_vhost_resolve(vhost, stream, param); // Ignore when the param only contains the default vhost. - if (param == "?vhost="SRS_CONSTS_RTMP_DEFAULT_VHOST) { + if (param == "?vhost=" SRS_CONSTS_RTMP_DEFAULT_VHOST) { param = ""; } } diff --git a/trunk/src/srt/srt_server.cpp b/trunk/src/srt/srt_server.cpp index 3a17a0a8b..eb41866e0 100644 --- a/trunk/src/srt/srt_server.cpp +++ b/trunk/src/srt/srt_server.cpp @@ -256,7 +256,11 @@ void srt_server::on_work() } } } + + // @see 2020-01-28 https://github.com/Haivision/srt/commit/b8c70ec801a56bea151ecce9c09c4ebb720c2f68#diff-fb66028e8746fea578788532533a296bR786 +#if SRT_VERSION_MAJOR > 1 || SRT_VERSION_MINOR > 4 || SRT_VERSION_PATCH > 1 srt_epoll_clear_usocks(_pollid); +#endif } SrtServerAdapter::SrtServerAdapter() From bbdbcf173cbe983817424782d8dcd4ad96f64c70 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 26 Feb 2020 09:06:53 +0800 Subject: [PATCH 27/27] For #1615, refactor the version and API for SRT. --- trunk/src/srt/srt_server.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/trunk/src/srt/srt_server.cpp b/trunk/src/srt/srt_server.cpp index eb41866e0..7576d3bf5 100644 --- a/trunk/src/srt/srt_server.cpp +++ b/trunk/src/srt/srt_server.cpp @@ -257,8 +257,9 @@ void srt_server::on_work() } } - // @see 2020-01-28 https://github.com/Haivision/srt/commit/b8c70ec801a56bea151ecce9c09c4ebb720c2f68#diff-fb66028e8746fea578788532533a296bR786 -#if SRT_VERSION_MAJOR > 1 || SRT_VERSION_MINOR > 4 || SRT_VERSION_PATCH > 1 + // New API at 2020-01-28, >1.4.1 + // @see https://github.com/Haivision/srt/commit/b8c70ec801a56bea151ecce9c09c4ebb720c2f68#diff-fb66028e8746fea578788532533a296bR786 +#if (SRT_VERSION_MAJOR<<24 | SRT_VERSION_MINOR<<16 | SRT_VERSION_PATCH<<8) > 0x01040100 srt_epoll_clear_usocks(_pollid); #endif }