diff --git a/avisynth_filter/src/frame_handler.cpp b/avisynth_filter/src/frame_handler.cpp index e84f2c5..e3384ca 100644 --- a/avisynth_filter/src/frame_handler.cpp +++ b/avisynth_filter/src/frame_handler.cpp @@ -11,24 +11,28 @@ namespace SynthFilter { auto FrameHandler::AddInputSample(IMediaSample *inputSample) -> HRESULT { HRESULT hr; - _addInputSampleCv.wait(_filter.m_csReceive, [this]() -> bool { - if (_isFlushing) { - return true; - } + { + std::shared_lock sharedSourceLock(_sourceMutex); - if (_nextSourceFrameNb <= Environment::GetInstance().GetInitialSrcBuffer()) { - return true; - } + _addInputSampleCv.wait(sharedSourceLock, [this]() -> bool { + if (_isFlushing) { + return true; + } - UpdateExtraSrcBuffer(); + if (_nextSourceFrameNb <= Environment::GetInstance().GetInitialSrcBuffer()) { + return true; + } - // at least NUM_SRC_FRAMES_PER_PROCESSING source frames are needed in queue for stop time calculation - if (static_cast(_sourceFrames.size()) < NUM_SRC_FRAMES_PER_PROCESSING + _extraSrcBuffer) { - return true; - } + UpdateExtraSrcBuffer(); - return _nextSourceFrameNb <= _maxRequestedFrameNb; - }); + // at least NUM_SRC_FRAMES_PER_PROCESSING source frames are needed in queue for stop time calculation + if (static_cast(_sourceFrames.size()) < NUM_SRC_FRAMES_PER_PROCESSING + _extraSrcBuffer) { + return true; + } + + return _nextSourceFrameNb <= _maxRequestedFrameNb; + }); + } if (_isFlushing || _isStopping) { Environment::GetInstance().Log(L"Reject input sample due to flush or stop"); diff --git a/vapoursynth_filter/src/frame_handler.cpp b/vapoursynth_filter/src/frame_handler.cpp index ec7089d..21d818c 100644 --- a/vapoursynth_filter/src/frame_handler.cpp +++ b/vapoursynth_filter/src/frame_handler.cpp @@ -11,24 +11,28 @@ namespace SynthFilter { auto FrameHandler::AddInputSample(IMediaSample *inputSample) -> HRESULT { HRESULT hr; - _addInputSampleCv.wait(_filter.m_csReceive, [this]() -> bool { - if (_isFlushing) { - return true; - } + { + std::shared_lock sharedSourceLock(_sourceMutex); - if (_nextSourceFrameNb <= Environment::GetInstance().GetInitialSrcBuffer()) { - return true; - } + _addInputSampleCv.wait(sharedSourceLock, [this]() -> bool { + if (_isFlushing) { + return true; + } - UpdateExtraSrcBuffer(); + if (_nextSourceFrameNb <= Environment::GetInstance().GetInitialSrcBuffer()) { + return true; + } - // at least NUM_SRC_FRAMES_PER_PROCESSING source frames are needed in queue for stop time calculation - if (static_cast(_sourceFrames.size()) < NUM_SRC_FRAMES_PER_PROCESSING + _extraSrcBuffer) { - return true; - } + UpdateExtraSrcBuffer(); - return _nextSourceFrameNb <= _lastUsedSourceFrameNb + Environment::GetInstance().GetInitialSrcBuffer() + NUM_SRC_FRAMES_PER_PROCESSING; - }); + // at least NUM_SRC_FRAMES_PER_PROCESSING source frames are needed in queue for stop time calculation + if (static_cast(_sourceFrames.size()) < NUM_SRC_FRAMES_PER_PROCESSING + _extraSrcBuffer) { + return true; + } + + return _nextSourceFrameNb <= _lastUsedSourceFrameNb + Environment::GetInstance().GetInitialSrcBuffer() + NUM_SRC_FRAMES_PER_PROCESSING; + }); + } if (_isFlushing || _isStopping) { Environment::GetInstance().Log(L"Reject input sample due to flush or stop");