From d6e11706eca9fc94f5751fe53aaa4521279b48c8 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:46:05 +0800 Subject: [PATCH 01/17] Fix disconnect RTSP connection has assertion, resulting in program exit --- trunk/src/app/srs_app_rtsp.cpp | 20 ++++++++++++++++++-- trunk/src/app/srs_app_rtsp.hpp | 5 ++++- trunk/src/app/srs_app_server.cpp | 1 + trunk/src/app/srs_app_server.hpp | 3 ++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 4488b6d98..2577f3128 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -240,6 +240,11 @@ srs_error_t SrsRtspConn::serve() return err; } +std::string SrsRtspConn::remote_ip() +{ + return ""; +} + srs_error_t SrsRtspConn::do_cycle() { srs_error_t err = srs_success; @@ -681,6 +686,7 @@ SrsRtspCaster::SrsRtspCaster(SrsConfDirective* c) output = _srs_config->get_stream_caster_output(c); local_port_min = _srs_config->get_stream_caster_rtp_port_min(c); local_port_max = _srs_config->get_stream_caster_rtp_port_max(c); + manager = new SrsCoroutineManager(); } SrsRtspCaster::~SrsRtspCaster() @@ -688,10 +694,20 @@ SrsRtspCaster::~SrsRtspCaster() std::vector::iterator it; for (it = clients.begin(); it != clients.end(); ++it) { SrsRtspConn* conn = *it; - srs_freep(conn); + manager->remove(conn); } clients.clear(); used_ports.clear(); + + srs_freep(manager); +} + +srs_error_t SrsRtspCaster::initialize() +{ + srs_error_t err = srs_success; + if ((err = manager->start()) != srs_success) { + return srs_error_wrap(err, "start manager"); + } } srs_error_t SrsRtspCaster::alloc_port(int* pport) @@ -744,6 +760,6 @@ void SrsRtspCaster::remove(SrsRtspConn* conn) } srs_info("rtsp: remove connection from caster."); - srs_freep(conn); + manager->remove(conn); } diff --git a/trunk/src/app/srs_app_rtsp.hpp b/trunk/src/app/srs_app_rtsp.hpp index 7bbd52651..0ca748535 100644 --- a/trunk/src/app/srs_app_rtsp.hpp +++ b/trunk/src/app/srs_app_rtsp.hpp @@ -100,7 +100,7 @@ public: }; // The rtsp connection serve the fd. -class SrsRtspConn : public ISrsCoroutineHandler +class SrsRtspConn : public ISrsCoroutineHandler, public ISrsConnection { private: std::string output_template; @@ -143,6 +143,7 @@ public: virtual ~SrsRtspConn(); public: virtual srs_error_t serve(); + virtual std::string remote_ip(); private: virtual srs_error_t do_cycle(); // internal methods @@ -179,6 +180,7 @@ private: std::map used_ports; private: std::vector clients; + SrsCoroutineManager* manager; public: SrsRtspCaster(SrsConfDirective* c); virtual ~SrsRtspCaster(); @@ -188,6 +190,7 @@ public: virtual srs_error_t alloc_port(int* pport); // Free the alloced rtp port. virtual void free_port(int lpmin, int lpmax); + virtual srs_error_t initialize(); // Interface ISrsTcpHandler public: virtual srs_error_t on_tcp_client(srs_netfd_t stfd); diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 61eeb2309..2edc525aa 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -179,6 +179,7 @@ SrsRtspListener::SrsRtspListener(SrsServer* svr, SrsListenerType t, SrsConfDirec srs_assert(type == SrsListenerRtsp); if (type == SrsListenerRtsp) { caster = new SrsRtspCaster(c); + caster->initialize(); } } diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index fd8cbe3ad..f43d7fc04 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -50,6 +50,7 @@ class ISrsUdpHandler; class SrsUdpListener; class SrsTcpListener; class SrsAppCasterFlv; +class SrsRtspCaster; class SrsCoroutineManager; // The listener type for server to identify the connection, @@ -107,7 +108,7 @@ class SrsRtspListener : virtual public SrsListener, virtual public ISrsTcpHandle { private: SrsTcpListener* listener; - ISrsTcpHandler* caster; + SrsRtspCaster* caster; public: SrsRtspListener(SrsServer* svr, SrsListenerType t, SrsConfDirective* c); virtual ~SrsRtspListener(); From ea305790df6c2f23b19f8e4b228ab8ae812253a8 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 26 Feb 2020 16:38:06 +0800 Subject: [PATCH 02/17] For #1579, refactor log for gracefully quit. --- trunk/src/app/srs_app_server.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 632ff9fc5..9cffa3250 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -554,9 +554,11 @@ void SrsServer::gracefully_dispose() close_listeners(SrsListenerMpegTsOverUdp); close_listeners(SrsListenerRtsp); close_listeners(SrsListenerFlv); + srs_trace("listeners closed"); // Fast stop to notify FFMPEG to quit, wait for a while then fast kill. ingester->stop(); + srs_trace("ingesters stopped"); // Wait for connections to quit. // While gracefully quiting, user can requires SRS to fast quit. @@ -572,6 +574,7 @@ void SrsServer::gracefully_dispose() // dispose the source for hls and dvr. _srs_sources->dispose(); + srs_trace("source disposed"); #ifdef SRS_AUTO_MEM_WATCH srs_memory_report(); From b525fc65aa3e79215da3b64510af38048feeb19a Mon Sep 17 00:00:00 2001 From: Xiaofeng Wang Date: Tue, 3 Mar 2020 21:05:49 +0800 Subject: [PATCH 03/17] Remove unused ip variable * "inet addr" is not compatible with rhel/centos 7+; * ifconfig has been replaced by ip-utils in newer distro; --- trunk/configure | 1 - 1 file changed, 1 deletion(-) diff --git a/trunk/configure b/trunk/configure index d233f66db..8ba25a8ba 100755 --- a/trunk/configure +++ b/trunk/configure @@ -730,7 +730,6 @@ fi # next step ##################################################################################### if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then - ip=`ifconfig|grep "inet addr"| grep -v "127.0.0.1"|awk '{print $2}'|awk -F ':' 'NR==1 {print $2}'` echo "" echo "You can run 3rdparty applications:" if [ $SRS_HTTP_CALLBACK = YES ]; then From d5bbf84439ed4aefcdc7f0a549b629ccf4780339 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 5 Mar 2020 11:34:16 +0800 Subject: [PATCH 04/17] Release 3.0b2, 3.0.123 --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e72c4e14f..da2fed7f8 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-05, [3.0 beta2(3.0.123)][r3.0b2] released. 122170 lines. * 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 @@ -745,6 +746,7 @@ For previous versions, please read: ## Releases +* 2020-03-05, [Release v3.0-b2][r3.0b2], 3.0 beta2, 3.0.123, 122170 lines. * 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. @@ -1662,6 +1664,7 @@ Winlin [exo #828]: https://github.com/google/ExoPlayer/pull/828 +[r3.0b2]: https://github.com/ossrs/srs/releases/tag/v3.0-b2 [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 From 41acf9ca8e37e6dfd0d4be6e8abfbcb2d14b152d Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 7 Mar 2020 22:25:19 +0800 Subject: [PATCH 05/17] For #1631, support sei_filter for SRT. 4.0.11 --- README.md | 4 ++++ trunk/src/core/srs_core_version4.hpp | 2 +- trunk/src/srt/srt_to_rtmp.cpp | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87f6be55f..fffccb183 100755 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-03-07, For [#1631][bug #1631], support sei_filter for SRT. 4.0.11 * v4.0, 2020-03-01, For [#1621][bug #1621], support mix_correct for aggregate aac for SRT. 4.0.10 * 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 @@ -1691,6 +1692,9 @@ Winlin [bug #1621]: https://github.com/ossrs/srs/issues/1621 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx +[bug #1631]: https://github.com/ossrs/srs/issues/1631 +[bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx + [exo #828]: https://github.com/google/ExoPlayer/pull/828 [r3.0b1]: https://github.com/ossrs/srs/releases/tag/v3.0-b1 diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 548632cf5..45b47d69a 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 10 +#define SRS_VERSION4_REVISION 11 #endif diff --git a/trunk/src/srt/srt_to_rtmp.cpp b/trunk/src/srt/srt_to_rtmp.cpp index 0842a7e7f..f36a353ee 100644 --- a/trunk/src/srt/srt_to_rtmp.cpp +++ b/trunk/src/srt/srt_to_rtmp.cpp @@ -460,6 +460,7 @@ srs_error_t rtmp_client::on_ts_video(std::shared_ptr avs_ptr, uint64_ continue; } + // TODO: FIXME: Should cache this config, it's better not to get it for each video frame. if (_srs_config->get_srt_sei_filter()) { if (nal_unit_type == SrsAvcNaluTypeSEI) { continue; From dcb0553cc8c3e495d3d3b4ecad676409954f3945 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 7 Mar 2020 22:35:11 +0800 Subject: [PATCH 06/17] For #1612, fix crash bug for RTSP. 4.0.12 --- README.md | 2 ++ trunk/src/app/srs_app_rtsp.cpp | 1 + trunk/src/app/srs_app_server.cpp | 2 ++ trunk/src/core/srs_core_version4.hpp | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fffccb183..dc6abcfb5 100755 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ For previous versions, please read: ## V4 changes +* v4.0, 2020-03-07, For [#1612][bug #1612], fix crash bug for RTSP. 4.0.12 * v4.0, 2020-03-07, For [#1631][bug #1631], support sei_filter for SRT. 4.0.11 * v4.0, 2020-03-01, For [#1621][bug #1621], support mix_correct for aggregate aac for SRT. 4.0.10 * v4.0, 2020-02-25, For [#1615][bug #1615], support default app(live) for vmix SRT. 4.0.9 @@ -1693,6 +1694,7 @@ Winlin [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [bug #1631]: https://github.com/ossrs/srs/issues/1631 +[bug #1612]: https://github.com/ossrs/srs/issues/1612 [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_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 3dcf20213..c81c71c78 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -242,6 +242,7 @@ srs_error_t SrsRtspConn::serve() std::string SrsRtspConn::remote_ip() { + // TODO: FIXME: Implement it. return ""; } diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 0a904d514..c35c27a42 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -179,6 +179,8 @@ SrsRtspListener::SrsRtspListener(SrsServer* svr, SrsListenerType t, SrsConfDirec srs_assert(type == SrsListenerRtsp); if (type == SrsListenerRtsp) { caster = new SrsRtspCaster(c); + + // TODO: FIXME: Must check error. caster->initialize(); } } diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 45b47d69a..98f2899e1 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 11 +#define SRS_VERSION4_REVISION 12 #endif From 48be5b6245651120ae02394ba0edd9977f35652a Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 7 Mar 2020 22:37:12 +0800 Subject: [PATCH 07/17] Update authors --- AUTHORS.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 6755f273b..352376b94 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -53,4 +53,6 @@ CONTRIBUTORS ordered by first contribution. * alphonsetai * Michael.Ma * lam2003 -* runner365 \ No newline at end of file +* runner365 +* XiaofengWang +* XiaLixin \ No newline at end of file From 5586c2a128fa469263b8837ae2fc07f390c8ea97 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 7 Mar 2020 22:42:23 +0800 Subject: [PATCH 08/17] For #1612, refactor return value for RTSP initialize. --- trunk/src/app/srs_app_rtsp.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index c81c71c78..8c6967115 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -712,6 +712,7 @@ srs_error_t SrsRtspCaster::initialize() if ((err = manager->start()) != srs_success) { return srs_error_wrap(err, "start manager"); } + return err; } srs_error_t SrsRtspCaster::alloc_port(int* pport) From 927c0c8e398e9fbc0d2e43f19b60f4cdb805b5e4 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Mar 2020 19:04:52 +0800 Subject: [PATCH 09/17] For #1634, fix quit by accident SIGTERM while killing FFMPEG. 3.0.124 --- README.md | 2 ++ trunk/src/app/srs_app_process.cpp | 4 ++++ trunk/src/app/srs_app_server.cpp | 7 ++++--- trunk/src/core/srs_core_version3.hpp | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index da2fed7f8..ca451c970 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-11, For [#1634][bug #1634], fix quit by accident SIGTERM while killing FFMPEG. 3.0.124 * v3.0, 2020-03-05, [3.0 beta2(3.0.123)][r3.0b2] released. 122170 lines. * 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 @@ -1660,6 +1661,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 #1634]: https://github.com/ossrs/srs/issues/1634 [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_process.cpp b/trunk/src/app/srs_app_process.cpp index 8ccc1b72e..0f12f493d 100644 --- a/trunk/src/app/srs_app_process.cpp +++ b/trunk/src/app/srs_app_process.cpp @@ -248,6 +248,10 @@ srs_error_t SrsProcess::start() // parent. if (pid > 0) { + // Wait for a while for process to really started. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597568840 + srs_usleep(10 * SRS_UTIME_MILLISECONDS); + is_started = true; srs_trace("fored process, pid=%d, bin=%s, stdout=%s, stderr=%s, argv=%s", pid, bin.c_str(), stdout_file.c_str(), stderr_file.c_str(), actual_cli.c_str()); diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 9cffa3250..99724f993 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -892,6 +892,7 @@ srs_error_t SrsServer::cycle() void SrsServer::on_signal(int signo) { if (signo == SRS_SIGNAL_RELOAD) { + srs_trace("reload config, signo=%d", signo); signal_reload = true; return; } @@ -899,7 +900,7 @@ void SrsServer::on_signal(int signo) #ifndef SRS_AUTO_GPERF_MC if (signo == SRS_SIGNAL_REOPEN_LOG) { _srs_log->reopen(); - srs_warn("reopen log file"); + srs_warn("reopen log file, signo=%d", signo); return; } #endif @@ -907,7 +908,7 @@ void SrsServer::on_signal(int signo) #ifdef SRS_AUTO_GPERF_MC if (signo == SRS_SIGNAL_REOPEN_LOG) { signal_gmc_stop = true; - srs_warn("for gmc, the SIGUSR1 used as SIGINT"); + srs_warn("for gmc, the SIGUSR1 used as SIGINT, signo=%d", signo); return; } #endif @@ -919,7 +920,7 @@ void SrsServer::on_signal(int signo) if (signo == SIGINT) { #ifdef SRS_AUTO_GPERF_MC - srs_trace("gmc is on, main cycle will terminate normally."); + srs_trace("gmc is on, main cycle will terminate normally, signo=%d", signo); signal_gmc_stop = true; #else #ifdef SRS_AUTO_MEM_WATCH diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index c871670b0..982408222 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 123 +#define SRS_VERSION3_REVISION 124 #endif From 66b194cd63c12b4de54ed75c422960144e9ea0e1 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Mar 2020 19:08:36 +0800 Subject: [PATCH 10/17] For #1634, refactor encoder process management. --- trunk/src/app/srs_app_encoder.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index 346bd2715..b2164ebde 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -94,15 +94,17 @@ srs_error_t SrsEncoder::cycle() srs_error_t err = srs_success; while (true) { - if ((err = do_cycle()) != srs_success) { - srs_warn("Encoder: Ignore error, %s", srs_error_desc(err).c_str()); - srs_error_reset(err); - } - + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 if ((err = trd->pull()) != srs_success) { err = srs_error_wrap(err, "encoder"); break; } + + if ((err = do_cycle()) != srs_success) { + srs_warn("Encoder: Ignore error, %s", srs_error_desc(err).c_str()); + srs_error_reset(err); + } srs_usleep(SRS_RTMP_ENCODER_CIMS); } From c78595c1fa4eacab4b41458289b03d043dd631c2 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Mar 2020 19:19:17 +0800 Subject: [PATCH 11/17] For #1634, refactor encoder output, support timestamp variables. --- trunk/src/app/srs_app_encoder.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index b2164ebde..1f4aae4ee 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -33,6 +33,7 @@ using namespace std; #include #include #include +#include // for encoder to detect the dead loop static std::vector _transcoded_url; @@ -284,6 +285,7 @@ srs_error_t SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, Sr output = srs_string_replace(output, "[stream]", req->stream); output = srs_string_replace(output, "[param]", req->param); output = srs_string_replace(output, "[engine]", engine->arg0()); + output = srs_path_build_timestamp(output); std::string log_file = SRS_CONSTS_NULL_FILE; // disabled // write ffmpeg info to log file. From 0290009b4edf6c1b4e3a50dc7a896b1e56a78ddb Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Mar 2020 19:27:26 +0800 Subject: [PATCH 12/17] Refine readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca451c970..c5ef94865 100755 --- a/README.md +++ b/README.md @@ -1662,7 +1662,7 @@ Winlin [bug #1579]: https://github.com/ossrs/srs/issues/1579 [bug #1598]: https://github.com/ossrs/srs/issues/1598 [bug #1634]: https://github.com/ossrs/srs/issues/1634 -[bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx +[bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy [exo #828]: https://github.com/google/ExoPlayer/pull/828 From c61c2a939fffb13f33298645f44ef4e3b4fe33d3 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Mar 2020 19:33:55 +0800 Subject: [PATCH 13/17] For #1634, refactor output with datetime for ingest/encoder/exec. 3.0.125 --- README.md | 1 + trunk/conf/full.conf | 30 ++++++++++++++++++++++++++++ trunk/src/app/srs_app_ingest.cpp | 1 + trunk/src/app/srs_app_ng_exec.cpp | 2 ++ trunk/src/core/srs_core_version3.hpp | 2 +- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c5ef94865..ae034b22d 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-11, For [#1634][bug #1634], refactor output with datetime for ingest/encoder/exec. 3.0.125 * v3.0, 2020-03-11, For [#1634][bug #1634], fix quit by accident SIGTERM while killing FFMPEG. 3.0.124 * v3.0, 2020-03-05, [3.0 beta2(3.0.123)][r3.0b2] released. 122170 lines. * v3.0, 2020-02-21, For [#1598][bug #1598], support SLB health checking by TCP. 3.0.123 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index b56f27fbc..f25a84073 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -978,6 +978,16 @@ vhost exec.srs.com { # [tcUrl] the client request tcUrl. # [swfUrl] the client request swfUrl. # [pageUrl] the client request pageUrl. + # we also support datetime variables. + # [2006], replace this const to current year. + # [01], replace this const to current month. + # [02], replace this const to current date. + # [15], replace this const to current hour. + # [04], replace this const to current minute. + # [05], replace this const to current second. + # [999], replace this const to current millisecond. + # [timestamp],replace this const to current UNIX timestamp in ms. + # @remark we use golang time format "2006-01-02 15:04:05.999" as "[2006]-[01]-[02]_[15].[04].[05]_[999]" # @remark empty to ignore this exec. publish ./objs/ffmpeg/bin/ffmpeg -f flv -i [url] -c copy -y ./[stream].flv; } @@ -1331,6 +1341,16 @@ vhost ingest.srs.com { # output stream. variables: # [vhost] current vhost which start the ingest. # [port] system RTMP stream port. + # we also support datetime variables. + # [2006], replace this const to current year. + # [01], replace this const to current month. + # [02], replace this const to current date. + # [15], replace this const to current hour. + # [04], replace this const to current minute. + # [05], replace this const to current second. + # [999], replace this const to current millisecond. + # [timestamp],replace this const to current UNIX timestamp in ms. + # @remark we use golang time format "2006-01-02 15:04:05.999" as "[2006]-[01]-[02]_[15].[04].[05]_[999]" output rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream; } } @@ -1519,6 +1539,16 @@ vhost example.transcode.srs.com { # [app] the input stream app. # [stream] the input stream name. # [engine] the transcode engine name. + # we also support datetime variables. + # [2006], replace this const to current year. + # [01], replace this const to current month. + # [02], replace this const to current date. + # [15], replace this const to current hour. + # [04], replace this const to current minute. + # [05], replace this const to current second. + # [999], replace this const to current millisecond. + # [timestamp],replace this const to current UNIX timestamp in ms. + # @remark we use golang time format "2006-01-02 15:04:05.999" as "[2006]-[01]-[02]_[15].[04].[05]_[999]" output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine]; } } diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index c98ed7d04..addbd9bc2 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -382,6 +382,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* // ie. rtmp://localhost:1935/live/livestream_sd output = srs_string_replace(output, "[vhost]", vhost->arg0()); output = srs_string_replace(output, "[port]", srs_int2str(port)); + output = srs_path_build_timestamp(output); if (output.empty()) { return srs_error_new(ERROR_ENCODER_NO_OUTPUT, "empty output url, ingest=%s", ingest->arg0().c_str()); } diff --git a/trunk/src/app/srs_app_ng_exec.cpp b/trunk/src/app/srs_app_ng_exec.cpp index a1e613c8e..17941a00c 100644 --- a/trunk/src/app/srs_app_ng_exec.cpp +++ b/trunk/src/app/srs_app_ng_exec.cpp @@ -219,6 +219,8 @@ string SrsNgExec::parse(SrsRequest* req, string tmpl) output = srs_string_replace(output, "[tcUrl]", req->tcUrl); output = srs_string_replace(output, "[swfUrl]", req->swfUrl); output = srs_string_replace(output, "[pageUrl]", req->pageUrl); + + output = srs_path_build_timestamp(output); if (output.find("[url]") != string::npos) { string url = srs_generate_rtmp_url(req->host, req->port, req->host, req->vhost, req->app, req->stream, req->param); diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 982408222..8a69c55d2 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 124 +#define SRS_VERSION3_REVISION 125 #endif From 6c55fd3e4bc9cb158e445908a6a1191c3150ff0e Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Mar 2020 19:42:42 +0800 Subject: [PATCH 14/17] For #1634, refactor output with datetime for ingest/encoder/exec. 3.0.125 --- trunk/src/app/srs_app_ng_exec.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/trunk/src/app/srs_app_ng_exec.cpp b/trunk/src/app/srs_app_ng_exec.cpp index 17941a00c..18d719e78 100644 --- a/trunk/src/app/srs_app_ng_exec.cpp +++ b/trunk/src/app/srs_app_ng_exec.cpp @@ -35,6 +35,7 @@ using namespace std; #include #include #include +#include SrsNgExec::SrsNgExec() { From c1e07d6a961513a0466a8740f50798cddda08ea3 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 12 Mar 2020 08:59:13 +0800 Subject: [PATCH 15/17] For #1634, always check status in thread loop. 3.0.126 --- README.md | 1 + trunk/src/app/srs_app_edge.cpp | 25 ++++++++++++++----------- trunk/src/app/srs_app_forward.cpp | 12 +++++++----- trunk/src/app/srs_app_http_stream.cpp | 4 ++-- trunk/src/app/srs_app_ingest.cpp | 12 +++++++----- trunk/src/app/srs_app_ng_exec.cpp | 14 ++++++++------ trunk/src/app/srs_app_rtmp_conn.cpp | 15 +++++++-------- trunk/src/core/srs_core_version3.hpp | 2 +- 8 files changed, 47 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index ae034b22d..123a1b39b 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-12, For [#1634][bug #1634], always check status in thread loop. 3.0.126 * v3.0, 2020-03-11, For [#1634][bug #1634], refactor output with datetime for ingest/encoder/exec. 3.0.125 * v3.0, 2020-03-11, For [#1634][bug #1634], fix quit by accident SIGTERM while killing FFMPEG. 3.0.124 * v3.0, 2020-03-05, [3.0 beta2(3.0.123)][r3.0b2] released. 122170 lines. diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 8a0592dcf..8c057af51 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -234,15 +234,17 @@ srs_error_t SrsEdgeIngester::cycle() srs_error_t err = srs_success; while (true) { + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "edge ingester"); + } + if ((err = do_cycle()) != srs_success) { srs_warn("EdgeIngester: Ignore error, %s", srs_error_desc(err).c_str()); srs_freep(err); } - - if ((err = trd->pull()) != srs_success) { - return srs_error_wrap(err, "edge ingester"); - } - + srs_usleep(SRS_EDGE_INGESTER_CIMS); } @@ -314,7 +316,6 @@ srs_error_t SrsEdgeIngester::ingest(string& redirect) redirect = ""; while (true) { - srs_error_t err = srs_success; if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "thread quit"); } @@ -534,14 +535,16 @@ srs_error_t SrsEdgeForwarder::cycle() srs_error_t err = srs_success; while (true) { - if ((err = do_cycle()) != srs_success) { - return srs_error_wrap(err, "do cycle"); - } - + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "thread pull"); } - + + if ((err = do_cycle()) != srs_success) { + return srs_error_wrap(err, "do cycle"); + } + srs_usleep(SRS_EDGE_FORWARDER_CIMS); } diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index 339d12bde..882d33a8c 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -181,15 +181,17 @@ srs_error_t SrsForwarder::cycle() srs_error_t err = srs_success; while (true) { + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "forwarder"); + } + if ((err = do_cycle()) != srs_success) { srs_warn("Forwarder: Ignore error, %s", srs_error_desc(err).c_str()); srs_freep(err); } - - if ((err = trd->pull()) != srs_success) { - return srs_error_wrap(err, "forwarder"); - } - + srs_usleep(SRS_FORWARDER_CIMS); } diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 7a0688fff..fb7bd54b3 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -646,13 +646,13 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess // TODO: free and erase the disabled entry after all related connections is closed. // TODO: FXIME: Support timeout for player, quit infinite-loop. while (entry->enabled) { - pprint->elapse(); - // Whether client closed the FD. if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "recv thread"); } + pprint->elapse(); + // get messages from consumer. // each msg in msgs.msgs must be free, for the SrsMessageArray never free them. int count = 0; diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index addbd9bc2..44987f16c 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -201,15 +201,17 @@ srs_error_t SrsIngester::cycle() srs_error_t err = srs_success; while (!disposed) { + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 + if ((err = trd->pull()) != srs_success) { + return srs_error_wrap(err, "ingester"); + } + if ((err = do_cycle()) != srs_success) { srs_warn("Ingester: Ignore error, %s", srs_error_desc(err).c_str()); srs_freep(err); } - - if ((err = trd->pull()) != srs_success) { - return srs_error_wrap(err, "ingester"); - } - + srs_usleep(SRS_AUTO_INGESTER_CIMS); } diff --git a/trunk/src/app/srs_app_ng_exec.cpp b/trunk/src/app/srs_app_ng_exec.cpp index 18d719e78..30ebc5ecb 100644 --- a/trunk/src/app/srs_app_ng_exec.cpp +++ b/trunk/src/app/srs_app_ng_exec.cpp @@ -83,16 +83,18 @@ srs_error_t SrsNgExec::cycle() srs_error_t err = srs_success; while (true) { - if ((err = do_cycle()) != srs_success) { - srs_warn("EXEC: Ignore error, %s", srs_error_desc(err).c_str()); - srs_freep(err); - } - + // We always check status first. + // @see https://github.com/ossrs/srs/issues/1634#issuecomment-597571561 if ((err = trd->pull()) != srs_success) { err = srs_error_wrap(err, "ng exec cycle"); break; } - + + if ((err = do_cycle()) != srs_success) { + srs_warn("EXEC: Ignore error, %s", srs_error_desc(err).c_str()); + srs_freep(err); + } + srs_usleep(SRS_RTMP_EXEC_CIMS); } diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 98bfcd5fc..c7e943337 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -381,7 +381,6 @@ srs_error_t SrsRtmpConn::service_cycle() } while (true) { - srs_error_t err = srs_success; if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "rtmp: thread quit"); } @@ -704,14 +703,14 @@ srs_error_t SrsRtmpConn::do_playing(SrsSource* source, SrsConsumer* consumer, Sr srsu2msi(send_min_interval), srsu2msi(mw_sleep), mw_enabled, realtime, tcp_nodelay); while (true) { - // collect elapse for pithy print. - pprint->elapse(); - // when source is set to expired, disconnect it. if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "rtmp: thread quit"); } - + + // collect elapse for pithy print. + pprint->elapse(); + // to use isolate thread to recv, can improve about 33% performance. // @see: https://github.com/ossrs/srs/issues/196 // @see: https://github.com/ossrs/srs/issues/217 @@ -872,12 +871,12 @@ srs_error_t SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* int64_t nb_msgs = 0; uint64_t nb_frames = 0; while (true) { - pprint->elapse(); - if ((err = trd->pull()) != srs_success) { return srs_error_wrap(err, "rtmp: thread quit"); } - + + pprint->elapse(); + // cond wait for timeout. if (nb_msgs == 0) { // when not got msgs, wait for a larger timeout. diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 8a69c55d2..acedd7db1 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 125 +#define SRS_VERSION3_REVISION 126 #endif From ed41ca867b955b61a04ffc69b3325e30dca6764c Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 12 Mar 2020 10:11:41 +0800 Subject: [PATCH 16/17] For #1594, detect and disable daemon for docker. 3.0.127 --- README.md | 2 ++ trunk/conf/full.conf | 4 +++ trunk/src/app/srs_app_config.cpp | 14 +++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/core/srs_core_version3.hpp | 2 +- trunk/src/main/srs_main_server.cpp | 49 ++++++++++++++++++++++++++-- 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 123a1b39b..9ea5a8614 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-12, For [#1594][bug #1594], detect and disable daemon for docker. 3.0.127 * v3.0, 2020-03-12, For [#1634][bug #1634], always check status in thread loop. 3.0.126 * v3.0, 2020-03-11, For [#1634][bug #1634], refactor output with datetime for ingest/encoder/exec. 3.0.125 * v3.0, 2020-03-11, For [#1634][bug #1634], fix quit by accident SIGTERM while killing FFMPEG. 3.0.124 @@ -1664,6 +1665,7 @@ Winlin [bug #1579]: https://github.com/ossrs/srs/issues/1579 [bug #1598]: https://github.com/ossrs/srs/issues/1598 [bug #1634]: https://github.com/ossrs/srs/issues/1634 +[bug #1594]: https://github.com/ossrs/srs/issues/1594 [bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index f25a84073..95defe80f 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -93,6 +93,10 @@ grace_final_wait 3200; # @see https://github.com/ossrs/srs/issues/1579#issuecomment-587475077 # default: off force_grace_quit off; +# Whether disable daemon for docker. +# If on, it will set daemon to off in docker, even daemon is on. +# default: on +disable_daemon_for_docker on; ############################################################################################# # heartbeat/stats sections diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 3eb7483a5..80d03383d 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 != "empty_ip_ok" + && n != "grace_start_wait" && n != "empty_ip_ok" && n != "disable_daemon_for_docker" ) { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str()); } @@ -4099,6 +4099,18 @@ bool SrsConfig::is_force_grace_quit() return SRS_CONF_PERFER_FALSE(conf->arg0()); } +bool SrsConfig::disable_daemon_for_docker() +{ + static bool DEFAULT = true; + + SrsConfDirective* conf = root->get("disable_daemon_for_docker"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + + return SRS_CONF_PERFER_TRUE(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 0b94470da..7669632cc 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -476,6 +476,8 @@ public: virtual srs_utime_t get_grace_final_wait(); // Whether force to gracefully quit, never fast quit. virtual bool is_force_grace_quit(); + // Whether disable daemon for docker. + virtual bool disable_daemon_for_docker(); // stream_caster section public: // Get all stream_caster in config file. diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index acedd7db1..878dd8730 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 126 +#define SRS_VERSION3_REVISION 127 #endif diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 25cfbaf30..aa90f2711 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -48,6 +48,7 @@ using namespace std; #include #include #include +#include // pre-declare srs_error_t run(SrsServer* svr); @@ -350,6 +351,36 @@ string srs_getenv(const char* name) return ""; } +// Detect docker by https://stackoverflow.com/a/41559867 +srs_error_t srs_detect_docker(bool* is_docker) +{ + srs_error_t err = srs_success; + + *is_docker = false; + + SrsFileReader fr; + if ((err = fr.open("/proc/1/cgroup")) != srs_success) { + return err; + } + + ssize_t nn; + char buf[1024]; + if ((err = fr.read(buf, sizeof(buf), &nn)) != srs_success) { + return err; + } + + if (nn <= 0) { + return err; + } + + string s(buf, nn); + if (srs_string_contains(s, "/docker")) { + *is_docker = true; + } + + return err; +} + srs_error_t run(SrsServer* svr) { srs_error_t err = srs_success; @@ -358,9 +389,23 @@ srs_error_t run(SrsServer* svr) if ((err = svr->initialize(NULL)) != srs_success) { return srs_error_wrap(err, "server initialize"); } - + + // Load daemon from config, disable it for docker. + // @see https://github.com/ossrs/srs/issues/1594 + bool in_daemon = _srs_config->get_daemon(); + if (in_daemon && _srs_config->disable_daemon_for_docker()) { + bool is_docker = false; + err = srs_detect_docker(&is_docker); + srs_error_reset(err); // Ignore any error while detecting docker. + + if (is_docker) { + srs_warn("disable daemon for docker"); + in_daemon = false; + } + } + // If not daemon, directly run master. - if (!_srs_config->get_daemon()) { + if (!in_daemon) { if ((err = run_master(svr)) != srs_success) { return srs_error_wrap(err, "run master"); } From 4b395f6e164e57cb1a61613161e90c25191416da Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 12 Mar 2020 11:55:37 +0800 Subject: [PATCH 17/17] Fix #1630, disable cache for stream changing, and drop dup header. 3.0.128 --- README.md | 2 + trunk/src/app/srs_app_source.cpp | 55 ++++++++++++++++++++++++---- trunk/src/app/srs_app_source.hpp | 11 ++++++ trunk/src/core/srs_core_version3.hpp | 2 +- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9ea5a8614..d843ac0f8 100755 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-03-12, For [#1630][bug #1630], disable cache for stream changing, and drop dup header. 3.0.128 * v3.0, 2020-03-12, For [#1594][bug #1594], detect and disable daemon for docker. 3.0.127 * v3.0, 2020-03-12, For [#1634][bug #1634], always check status in thread loop. 3.0.126 * v3.0, 2020-03-11, For [#1634][bug #1634], refactor output with datetime for ingest/encoder/exec. 3.0.125 @@ -1666,6 +1667,7 @@ Winlin [bug #1598]: https://github.com/ossrs/srs/issues/1598 [bug #1634]: https://github.com/ossrs/srs/issues/1634 [bug #1594]: https://github.com/ossrs/srs/issues/1594 +[bug #1630]: https://github.com/ossrs/srs/issues/1630 [bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index f5acb05da..3473909eb 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1506,6 +1506,7 @@ void SrsOriginHub::destroy_forwarders() SrsMetaCache::SrsMetaCache() { meta = video = audio = NULL; + previous_video = previous_audio = NULL; vformat = new SrsRtmpFormat(); aformat = new SrsRtmpFormat(); } @@ -1516,6 +1517,13 @@ SrsMetaCache::~SrsMetaCache() } void SrsMetaCache::dispose() +{ + clear(); + srs_freep(previous_video); + srs_freep(previous_audio); +} + +void SrsMetaCache::clear() { srs_freep(meta); srs_freep(video); @@ -1570,6 +1578,28 @@ srs_error_t SrsMetaCache::dumps(SrsConsumer* consumer, bool atc, SrsRtmpJitterAl return err; } +SrsSharedPtrMessage* SrsMetaCache::previous_vsh() +{ + return previous_video; +} + +SrsSharedPtrMessage* SrsMetaCache::previous_ash() +{ + return previous_audio; +} + +void SrsMetaCache::update_previous_vsh() +{ + srs_freep(previous_video); + previous_video = video? video->copy() : NULL; +} + +void SrsMetaCache::update_previous_ash() +{ + srs_freep(previous_audio); + previous_audio = audio? audio->copy() : NULL; +} + srs_error_t SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPacket* metadata, bool& updated) { updated = false; @@ -1636,6 +1666,7 @@ srs_error_t SrsMetaCache::update_ash(SrsSharedPtrMessage* msg) { srs_freep(audio); audio = msg->copy(); + update_previous_ash(); return aformat->on_audio(msg); } @@ -1643,6 +1674,7 @@ srs_error_t SrsMetaCache::update_vsh(SrsSharedPtrMessage* msg) { srs_freep(video); video = msg->copy(); + update_previous_vsh(); return vformat->on_video(msg); } @@ -2138,9 +2170,9 @@ srs_error_t SrsSource::on_audio_imp(SrsSharedPtrMessage* msg) // whether consumer should drop for the duplicated sequence header. bool drop_for_reduce = false; - if (is_sequence_header && meta->ash() && _srs_config->get_reduce_sequence_header(req->vhost)) { - if (meta->ash()->size == msg->size) { - drop_for_reduce = srs_bytes_equals(meta->ash()->payload, msg->payload, msg->size); + if (is_sequence_header && meta->previous_ash() && _srs_config->get_reduce_sequence_header(req->vhost)) { + if (meta->previous_ash()->size == msg->size) { + drop_for_reduce = srs_bytes_equals(meta->previous_ash()->payload, msg->payload, msg->size); srs_warn("drop for reduce sh audio, size=%d", msg->size); } } @@ -2257,9 +2289,9 @@ srs_error_t SrsSource::on_video_imp(SrsSharedPtrMessage* msg) // whether consumer should drop for the duplicated sequence header. bool drop_for_reduce = false; - if (is_sequence_header && meta->vsh() && _srs_config->get_reduce_sequence_header(req->vhost)) { - if (meta->vsh()->size == msg->size) { - drop_for_reduce = srs_bytes_equals(meta->vsh()->payload, msg->payload, msg->size); + if (is_sequence_header && meta->previous_vsh() && _srs_config->get_reduce_sequence_header(req->vhost)) { + if (meta->previous_vsh()->size == msg->size) { + drop_for_reduce = srs_bytes_equals(meta->previous_vsh()->payload, msg->payload, msg->size); srs_warn("drop for reduce sh video, size=%d", msg->size); } } @@ -2415,6 +2447,10 @@ srs_error_t SrsSource::on_publish() // reset the mix queue. mix_queue->clear(); + + // Reset the metadata cache, to make VLC happy when disable/enable stream. + // @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448 + meta->clear(); // detect the monotonically again. is_monotonically_increase = true; @@ -2450,7 +2486,12 @@ void SrsSource::on_unpublish() // donot clear the sequence header, for it maybe not changed, // when drop dup sequence header, drop the metadata also. gop_cache->clear(); - + + // Reset the metadata cache, to make VLC happy when disable/enable stream. + // @see https://github.com/ossrs/srs/issues/1630#issuecomment-597979448 + meta->update_previous_vsh(); + meta->update_previous_ash(); + srs_trace("cleanup when unpublish"); _can_publish = true; diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 8cb79f478..f93bc314d 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -407,8 +407,10 @@ private: SrsSharedPtrMessage* meta; // The cached video sequence header, for example, sps/pps for h.264. SrsSharedPtrMessage* video; + SrsSharedPtrMessage* previous_video; // The cached audio sequence header, for example, asc for aac. SrsSharedPtrMessage* audio; + SrsSharedPtrMessage* previous_audio; // The format for sequence header. SrsRtmpFormat* vformat; SrsRtmpFormat* aformat; @@ -418,6 +420,8 @@ public: public: // Dispose the metadata cache. virtual void dispose(); + // For each publishing, clear the metadata cache. + virtual void clear(); public: // Get the cached metadata. virtual SrsSharedPtrMessage* data(); @@ -431,6 +435,13 @@ public: // @param dm Whether dumps the metadata. // @param ds Whether dumps the sequence header. virtual srs_error_t dumps(SrsConsumer* consumer, bool atc, SrsRtmpJitterAlgorithm ag, bool dm, bool ds); +public: + // Previous exists sequence header. + virtual SrsSharedPtrMessage* previous_vsh(); + virtual SrsSharedPtrMessage* previous_ash(); + // Update previous sequence header, drop old one, set to new sequence header. + virtual void update_previous_vsh(); + virtual void update_previous_ash(); public: // Update the cached metadata by packet. virtual srs_error_t update_data(SrsMessageHeader* header, SrsOnMetaDataPacket* metadata, bool& updated); diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index 878dd8730..c3a667511 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 127 +#define SRS_VERSION3_REVISION 128 #endif