From 97b81c62b77b28ee5b6299d80580826698ecb229 Mon Sep 17 00:00:00 2001 From: Haibo Chen Date: Thu, 4 Nov 2021 19:23:06 +0800 Subject: [PATCH 1/2] DVR: copy req from publish --- trunk/src/app/srs_app_dvr.cpp | 16 ++++++++++------ trunk/src/app/srs_app_dvr.hpp | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index f12ce74c52..5cb4732672 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -598,8 +598,12 @@ srs_error_t SrsDvrPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsReque return err; } -srs_error_t SrsDvrPlan::on_publish() +srs_error_t SrsDvrPlan::on_publish(SrsRequest* r) { + // @see https://github.com/ossrs/srs/issues/1613#issuecomment-960623359 + if (req) srs_freep(req); + req = r->copy(); + return srs_success; } @@ -687,11 +691,11 @@ SrsDvrSessionPlan::~SrsDvrSessionPlan() { } -srs_error_t SrsDvrSessionPlan::on_publish() +srs_error_t SrsDvrSessionPlan::on_publish(SrsRequest* r) { srs_error_t err = srs_success; - if ((err = SrsDvrPlan::on_publish()) != srs_success) { + if ((err = SrsDvrPlan::on_publish(r)) != srs_success) { return err; } @@ -762,11 +766,11 @@ srs_error_t SrsDvrSegmentPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, S return srs_success; } -srs_error_t SrsDvrSegmentPlan::on_publish() +srs_error_t SrsDvrSegmentPlan::on_publish(SrsRequest* r) { srs_error_t err = srs_success; - if ((err = SrsDvrPlan::on_publish()) != srs_success) { + if ((err = SrsDvrPlan::on_publish(r)) != srs_success) { return err; } @@ -954,7 +958,7 @@ srs_error_t SrsDvr::on_publish() return err; } - if ((err = plan->on_publish()) != srs_success) { + if ((err = plan->on_publish(req)) != srs_success) { return srs_error_wrap(err, "publish"); } diff --git a/trunk/src/app/srs_app_dvr.hpp b/trunk/src/app/srs_app_dvr.hpp index b4ed0b960e..6b8591ffd8 100644 --- a/trunk/src/app/srs_app_dvr.hpp +++ b/trunk/src/app/srs_app_dvr.hpp @@ -167,7 +167,7 @@ class SrsDvrPlan : public ISrsReloadHandler virtual ~SrsDvrPlan(); public: virtual srs_error_t initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r); - virtual srs_error_t on_publish(); + virtual srs_error_t on_publish(SrsRequest* r); virtual void on_unpublish(); virtual srs_error_t on_meta_data(SrsSharedPtrMessage* shared_metadata); virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format); @@ -187,7 +187,7 @@ class SrsDvrSessionPlan : public SrsDvrPlan SrsDvrSessionPlan(); virtual ~SrsDvrSessionPlan(); public: - virtual srs_error_t on_publish(); + virtual srs_error_t on_publish(SrsRequest* r); virtual void on_unpublish(); }; @@ -203,7 +203,7 @@ class SrsDvrSegmentPlan : public SrsDvrPlan virtual ~SrsDvrSegmentPlan(); public: virtual srs_error_t initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsRequest* r); - virtual srs_error_t on_publish(); + virtual srs_error_t on_publish(SrsRequest* r); virtual void on_unpublish(); virtual srs_error_t on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format); virtual srs_error_t on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format); From a377af8d36f9e08fc5b187d157f9a1c50c6fa78f Mon Sep 17 00:00:00 2001 From: Haibo Chen Date: Fri, 5 Nov 2021 14:43:24 +0800 Subject: [PATCH 2/2] DVR: copy req from publish --- trunk/src/app/srs_app_dvr.cpp | 12 ++++++++---- trunk/src/app/srs_app_dvr.hpp | 2 +- trunk/src/app/srs_app_source.cpp | 5 +++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index 5cb4732672..f6a031fb52 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -601,7 +601,7 @@ srs_error_t SrsDvrPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, SrsReque srs_error_t SrsDvrPlan::on_publish(SrsRequest* r) { // @see https://github.com/ossrs/srs/issues/1613#issuecomment-960623359 - if (req) srs_freep(req); + srs_freep(req); req = r->copy(); return srs_success; @@ -917,13 +917,14 @@ SrsDvr::~SrsDvr() _srs_config->unsubscribe(this); srs_freep(plan); + srs_freep(req); } srs_error_t SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r) { srs_error_t err = srs_success; - req = r; + req = r->copy(); hub = h; SrsConfDirective* conf = _srs_config->get_dvr_apply(r->vhost); @@ -949,7 +950,7 @@ srs_error_t SrsDvr::initialize(SrsOriginHub* h, SrsRequest* r) return err; } -srs_error_t SrsDvr::on_publish() +srs_error_t SrsDvr::on_publish(SrsRequest* r) { srs_error_t err = srs_success; @@ -958,9 +959,12 @@ srs_error_t SrsDvr::on_publish() return err; } - if ((err = plan->on_publish(req)) != srs_success) { + if ((err = plan->on_publish(r)) != srs_success) { return srs_error_wrap(err, "publish"); } + + srs_freep(req); + req = r->copy(); return err; } diff --git a/trunk/src/app/srs_app_dvr.hpp b/trunk/src/app/srs_app_dvr.hpp index 6b8591ffd8..6dca126310 100644 --- a/trunk/src/app/srs_app_dvr.hpp +++ b/trunk/src/app/srs_app_dvr.hpp @@ -237,7 +237,7 @@ class SrsDvr : public ISrsReloadHandler // publish stream event, // when encoder start to publish RTMP stream. // @param fetch_sequence_header whether fetch sequence from source. - virtual srs_error_t on_publish(); + virtual srs_error_t on_publish(SrsRequest* r); // the unpublish event., // when encoder stop(unpublish) to publish RTMP stream. virtual void on_unpublish(); diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index f691e41383..e5dc78c894 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1138,7 +1138,8 @@ srs_error_t SrsOriginHub::on_publish() return srs_error_wrap(err, "dash publish"); } - if ((err = dvr->on_publish()) != srs_success) { + // @see https://github.com/ossrs/srs/issues/1613#issuecomment-961657927 + if ((err = dvr->on_publish(req)) != srs_success) { return srs_error_wrap(err, "dvr publish"); } @@ -1401,7 +1402,7 @@ srs_error_t SrsOriginHub::on_reload_vhost_dvr(string vhost) } // start to publish by new plan. - if ((err = dvr->on_publish()) != srs_success) { + if ((err = dvr->on_publish(req)) != srs_success) { return srs_error_wrap(err, "dvr publish failed"); }