From 4d09b8caae8e39a3b7eed4e0f71a65c6dfc6387f Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 5 Jan 2022 08:29:20 +0800 Subject: [PATCH] When reopening segment, never update the duration. (#2717). v4.0.219 --- trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_dvr.cpp | 14 ++++++++++++-- trunk/src/app/srs_app_dvr.hpp | 2 ++ trunk/src/core/srs_core_version4.hpp | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index f7f97ffe1..7eb0775d3 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-01-05, For [#2717](https://github.com/ossrs/srs/issues/2717): When reopening segment, never update the duration. (#2717). v4.0.219 * v4.0, 2021-01-04, Discover api server and ip as candidates. v4.0.218 * v4.0, 2021-01-04, Install test-on self-sign certificate. v4.0.217 * v4.0, 2021-01-03, For [#2824](https://github.com/ossrs/srs/issues/2824): Support config in_docker to fix the detect fail. (#2824). v4.0.216 diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index 1675e12c6..bd06f84b3 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -745,6 +745,7 @@ SrsDvrSegmentPlan::SrsDvrSegmentPlan() { cduration = 0; wait_keyframe = false; + reopening_segment_ = false; } SrsDvrSegmentPlan::~SrsDvrSegmentPlan() @@ -845,6 +846,12 @@ srs_error_t SrsDvrSegmentPlan::on_video(SrsSharedPtrMessage* shared_video, SrsFo srs_error_t SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg) { srs_error_t err = srs_success; + + // When reopening the segment, never update the duration, because there is actually no media data. + // @see https://github.com/ossrs/srs/issues/2717 + if (reopening_segment_) { + return err; + } srs_assert(segment); @@ -879,8 +886,11 @@ srs_error_t SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg) return srs_error_wrap(err, "segment open"); } - // update sequence header - if ((err = hub->on_dvr_request_sh()) != srs_success) { + // When update sequence header, set the reopening state to prevent infinitely recursive call. + reopening_segment_ = true; + err = hub->on_dvr_request_sh(); + reopening_segment_ = false; + if (err != srs_success) { return srs_error_wrap(err, "request sh"); } diff --git a/trunk/src/app/srs_app_dvr.hpp b/trunk/src/app/srs_app_dvr.hpp index 212616b92..79e1964a9 100644 --- a/trunk/src/app/srs_app_dvr.hpp +++ b/trunk/src/app/srs_app_dvr.hpp @@ -198,6 +198,8 @@ private: // in config, in srs_utime_t srs_utime_t cduration; bool wait_keyframe; + // Whether reopening the DVR file. + bool reopening_segment_; public: SrsDvrSegmentPlan(); virtual ~SrsDvrSegmentPlan(); diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 5c2a4e8d1..224d67031 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -9,6 +9,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 218 +#define VERSION_REVISION 219 #endif