From 6bb11a72d054cbbd112cb3ec96ff333c1cc721e9 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 4 Sep 2021 12:42:23 +0800 Subject: [PATCH] For #2282, #2181, Move DVR async worker from SrsDvrPlan to global. --- trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_dvr.cpp | 15 ++++----------- trunk/src/app/srs_app_dvr.hpp | 1 - trunk/src/app/srs_app_threads.cpp | 8 ++++++++ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 2c6588577..c541ea787 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -8,6 +8,7 @@ The changelog for SRS. ## SRS 4.0 Changelog +* v4.0, 2021-09-04, For [#2282](https://github.com/ossrs/srs/pull/2282), [#2181](https://github.com/ossrs/srs/issues/2181), Move DVR async worker from SrsDvrPlan to global. * v4.0, 2021-09-04, For [#2282](https://github.com/ossrs/srs/pull/2282), [#2181](https://github.com/ossrs/srs/issues/2181), Remove reload for dvr_apply. 4.0.160 * v4.0, 2021-08-28, RTC: Merge [#1859](https://github.com/ossrs/srs/pull/1859), Enhancement: Add param and stream to on_connect. 4.0.159 * v4.0, 2021-08-27, RTC: Merge [#2544](https://github.com/ossrs/srs/pull/2544), Support for multiple SPS/PPS, then pick the first one. 4.0.158 diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index 281f4aa6f..c17ae6fc7 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -566,6 +566,8 @@ string SrsDvrAsyncCallOnDvr::to_string() return ss.str(); } +extern SrsAsyncCallWorker* _srs_dvr_async; + SrsDvrPlan::SrsDvrPlan() { req = NULL; @@ -573,13 +575,11 @@ SrsDvrPlan::SrsDvrPlan() dvr_enabled = false; segment = NULL; - async = new SrsAsyncCallWorker(); } SrsDvrPlan::~SrsDvrPlan() { srs_freep(segment); - srs_freep(async); } srs_error_t SrsDvrPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r) @@ -599,18 +599,11 @@ srs_error_t SrsDvrPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsReque srs_error_t SrsDvrPlan::on_publish() { - srs_error_t err = srs_success; - - if ((err = async->start()) != srs_success) { - return srs_error_wrap(err, "async"); - } - - return err; + return srs_success; } void SrsDvrPlan::on_unpublish() { - async->stop(); } srs_error_t SrsDvrPlan::on_meta_data(SrsSharedPtrMessage* shared_metadata) @@ -663,7 +656,7 @@ srs_error_t SrsDvrPlan::on_reap_segment() SrsFragment* fragment = segment->current(); string fullpath = fragment->fullpath(); - if ((err = async->execute(new SrsDvrAsyncCallOnDvr(cid, req, fullpath))) != srs_success) { + if ((err = _srs_dvr_async->execute(new SrsDvrAsyncCallOnDvr(cid, req, fullpath))) != srs_success) { return srs_error_wrap(err, "reap segment"); } diff --git a/trunk/src/app/srs_app_dvr.hpp b/trunk/src/app/srs_app_dvr.hpp index 0e2b6c968..18ee450ee 100644 --- a/trunk/src/app/srs_app_dvr.hpp +++ b/trunk/src/app/srs_app_dvr.hpp @@ -161,7 +161,6 @@ public: protected: SrsOriginHub* hub; SrsDvrSegmenter* segment; - SrsAsyncCallWorker* async; bool dvr_enabled; public: SrsDvrPlan(); diff --git a/trunk/src/app/srs_app_threads.cpp b/trunk/src/app/srs_app_threads.cpp index c965d2eb2..64f779d8b 100644 --- a/trunk/src/app/srs_app_threads.cpp +++ b/trunk/src/app/srs_app_threads.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef SRS_RTC #include @@ -268,6 +269,7 @@ srs_error_t SrsCircuitBreaker::on_timer(srs_utime_t interval) } SrsCircuitBreaker* _srs_circuit_breaker = NULL; +SrsAsyncCallWorker* _srs_dvr_async = NULL; srs_error_t srs_thread_initialize() { @@ -408,6 +410,12 @@ srs_error_t srs_thread_initialize() _srs_pps_objs_rothers = new SrsPps(); #endif + // Create global async worker for DVR. + _srs_dvr_async = new SrsAsyncCallWorker(); + if ((err = _srs_dvr_async->start()) != srs_success) { + return srs_error_wrap(err, "dvr async"); + } + return err; }