From e574b1a1ccb5bdf2905ac653af95acc843f2d191 Mon Sep 17 00:00:00 2001 From: Crend King <975235+CrendKing@users.noreply.github.com> Date: Thu, 1 Jul 2021 17:44:57 -0700 Subject: [PATCH] Increase extraSourceBuffer faster in case of drought Bump version --- avisynth_filter/src/frame_handler.h | 1 - filter_common/src/constants.h | 2 +- filter_common/src/frame_handler_common.cpp | 22 +++++++--------------- filter_common/src/input_pin.cpp | 6 +++++- filter_common/src/version.h | 2 +- vapoursynth_filter/src/frame_handler.cpp | 4 +++- vapoursynth_filter/src/frame_handler.h | 1 - 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/avisynth_filter/src/frame_handler.h b/avisynth_filter/src/frame_handler.h index c7ae84c..fb9ffcc 100644 --- a/avisynth_filter/src/frame_handler.h +++ b/avisynth_filter/src/frame_handler.h @@ -21,7 +21,6 @@ class FrameHandler { auto BeginFlush() -> void; auto EndFlush(const std::function &interim) -> void; auto StartWorker() -> void; - auto TerminalFlush() -> void; auto GetInputBufferSize() const -> int; constexpr auto GetSourceFrameNb() const -> int { return _nextSourceFrameNb; } constexpr auto GetOutputFrameNb() const -> int { return _nextOutputFrameNb; } diff --git a/filter_common/src/constants.h b/filter_common/src/constants.h index a8e4601..3b14438 100644 --- a/filter_common/src/constants.h +++ b/filter_common/src/constants.h @@ -20,7 +20,7 @@ static const GUID MEDIASUBTYPE_YV24 = FOURCCMap(' // interface version 7 = AviSynth+ 3.5 static constexpr const int MINIMUM_AVISYNTH_PLUS_INTERFACE_VERSION = 7; -static constexpr const double EXTRA_SOURCE_BUFFER_CHANGE_THRESHOLD = 0.05; +static constexpr const double EXTRA_SOURCE_BUFFER_CHANGE_THRESHOLD = 0.1; static constexpr const int MAXIMUM_EXTRA_SOURCE_BUFFER = 14; /* diff --git a/filter_common/src/frame_handler_common.cpp b/filter_common/src/frame_handler_common.cpp index 15fd68c..e633425 100644 --- a/filter_common/src/frame_handler_common.cpp +++ b/filter_common/src/frame_handler_common.cpp @@ -17,7 +17,12 @@ FrameHandler::FrameHandler(CSynthFilter &filter) FrameHandler::~FrameHandler() { if (_workerThread.joinable()) { _isStopping = true; - TerminalFlush(); + + BeginFlush(); + EndFlush([]() -> void { + MainFrameServer::GetInstance().StopScript(); + }); + _workerThread.join(); } } @@ -29,25 +34,12 @@ auto FrameHandler::StartWorker() -> void { } } -auto FrameHandler::TerminalFlush() -> void { - BeginFlush(); - EndFlush([]() -> void { - /* - * Stop the script after worker threads are paused and before flushing is done so that no new frame request (GetSourceFrame()) happens. - * And since _isFlushing is still on, existing frame request should also just drain instead of block. - * - * If no stop here, since AddInputSample() no longer adds frame, existing GetSourceFrame() calls will stuck forever. - */ - MainFrameServer::GetInstance().StopScript(); - }); -} - auto FrameHandler::UpdateExtraSourceBuffer() -> void { if (const int sourceAvgFps = MainFrameServer::GetInstance().GetSourceAvgFrameRate(); _currentInputFrameRate > 0 && _nextSourceFrameNb % (sourceAvgFps / FRAME_RATE_SCALE_FACTOR) == 0) { if (const double ratio = static_cast(_currentInputFrameRate) / sourceAvgFps; ratio < 1 - EXTRA_SOURCE_BUFFER_CHANGE_THRESHOLD) { - _extraSourceBuffer = min(_extraSourceBuffer, MAXIMUM_EXTRA_SOURCE_BUFFER) + 1; + _extraSourceBuffer = min(_extraSourceBuffer, MAXIMUM_EXTRA_SOURCE_BUFFER) + 2; } else if (ratio > 1 + EXTRA_SOURCE_BUFFER_CHANGE_THRESHOLD) { _extraSourceBuffer = max(_extraSourceBuffer, 1) - 1; } diff --git a/filter_common/src/input_pin.cpp b/filter_common/src/input_pin.cpp index 113781b..e2636e2 100644 --- a/filter_common/src/input_pin.cpp +++ b/filter_common/src/input_pin.cpp @@ -91,7 +91,11 @@ auto CSynthFilterInputPin::Active() -> HRESULT { auto CSynthFilterInputPin::Inactive() -> HRESULT { _filter._isReadyToReceive = false; - _filter.frameHandler->TerminalFlush(); + + _filter.frameHandler->BeginFlush(); + _filter.frameHandler->EndFlush([this]() -> void { + MainFrameServer::GetInstance().ReloadScript(_filter.m_pInput->CurrentMediaType(), true); + }); return __super::Inactive(); } diff --git a/filter_common/src/version.h b/filter_common/src/version.h index 34b6a77..4655dee 100644 --- a/filter_common/src/version.h +++ b/filter_common/src/version.h @@ -29,7 +29,7 @@ namespace SynthFilter { #define FILTER_NAME_WIDE WIDEN(FILTER_NAME_BASE) #define FILTER_VERSION_MAJOR 1 #define FILTER_VERSION_MINOR 1 -#define FILTER_VERSION_PATCH 4 +#define FILTER_VERSION_PATCH 5 #define FILTER_VERSION_STRING STRINGIZE(FILTER_VERSION_MAJOR) "." STRINGIZE(FILTER_VERSION_MINOR) "." STRINGIZE(FILTER_VERSION_PATCH) FILTER_VARIANT " # " FILTER_GIT_HASH } diff --git a/vapoursynth_filter/src/frame_handler.cpp b/vapoursynth_filter/src/frame_handler.cpp index 73a231c..98ddf53 100644 --- a/vapoursynth_filter/src/frame_handler.cpp +++ b/vapoursynth_filter/src/frame_handler.cpp @@ -347,7 +347,9 @@ auto FrameHandler::PrepareOutputSample(ATL::CComPtr &sample, int o Format::WriteSample(_filter._outputVideoFormat, outputFrame, outputBuffer); if (const ATL::CComQIPtr outputSampleSideData(sample); outputSampleSideData != nullptr) { - _sourceFrames[sourceFrameNb].hdrSideData->WriteTo(outputSampleSideData); + const decltype(_sourceFrames)::const_iterator iter = _sourceFrames.find(sourceFrameNb); + ASSERT(iter != _sourceFrames.end()); + iter->second.hdrSideData->WriteTo(outputSampleSideData); } RefreshOutputFrameRates(outputFrameNb); diff --git a/vapoursynth_filter/src/frame_handler.h b/vapoursynth_filter/src/frame_handler.h index 1394bd8..9d8a627 100644 --- a/vapoursynth_filter/src/frame_handler.h +++ b/vapoursynth_filter/src/frame_handler.h @@ -21,7 +21,6 @@ class FrameHandler { auto BeginFlush() -> void; auto EndFlush(const std::function &interim) -> void; auto StartWorker() -> void; - auto TerminalFlush() -> void; auto GetInputBufferSize() const -> int; constexpr auto GetSourceFrameNb() const -> int { return _nextSourceFrameNb; } constexpr auto GetOutputFrameNb() const -> int { return _nextOutputFrameNb; }