From 4125f41d1f0479a686939302f96ef7b2e3c2cc9d Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Sat, 9 Oct 2021 19:13:11 -0700 Subject: [PATCH] cache: fixed on-demand cache --- app/common/timerange.cpp | 3 ++- app/common/timerange.h | 12 ++++++++++++ app/render/previewautocacher.cpp | 21 +++++++++------------ app/render/previewautocacher.h | 5 +++++ app/widget/viewer/viewer.cpp | 2 +- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/app/common/timerange.cpp b/app/common/timerange.cpp index 91758fc64..e98da1bb0 100644 --- a/app/common/timerange.cpp +++ b/app/common/timerange.cpp @@ -296,7 +296,8 @@ TimeRangeListFrameIterator::TimeRangeListFrameIterator(const TimeRangeList &list list_(list), timebase_(timebase), index_(-1), - size_(-1) + size_(-1), + custom_range_(false) { if (!list_.isEmpty() && timebase_.isNull()) { qCritical() << "TimeRangeListFrameIterator created with null timebase but non-empty list, this will likely lead to infinite loops"; diff --git a/app/common/timerange.h b/app/common/timerange.h index 846818084..ef1627d8e 100644 --- a/app/common/timerange.h +++ b/app/common/timerange.h @@ -228,6 +228,16 @@ public: list_.insert(list); } + bool IsCustomRange() const + { + return custom_range_; + } + + void SetCustomRange(bool e) + { + custom_range_ = e; + } + private: void UpdateIndexIfNecessary(); @@ -241,6 +251,8 @@ private: int size_; + bool custom_range_; + }; uint qHash(const TimeRange& r, uint seed = 0); diff --git a/app/render/previewautocacher.cpp b/app/render/previewautocacher.cpp index 20764ac46..36fb9289f 100644 --- a/app/render/previewautocacher.cpp +++ b/app/render/previewautocacher.cpp @@ -487,8 +487,6 @@ void PreviewAutoCacher::SetPlayhead(const rational &playhead) cache_range_ = TimeRange(playhead - Config::Current()[QStringLiteral("DiskCacheBehind")].value(), playhead + Config::Current()[QStringLiteral("DiskCacheAhead")].value()); - use_custom_range_ = false; - RequeueFrames(); } @@ -717,19 +715,17 @@ void PreviewAutoCacher::RequeueFrames() if (viewer_node_ && viewer_node_->video_frame_cache()->HasInvalidatedRanges(viewer_node_->GetVideoLength()) && hash_tasks_.isEmpty() - && (viewer_node_->GetVideoAutoCacheEnabled() || use_custom_range_)) { - TimeRange using_range; - - if (use_custom_range_) { - using_range = custom_autocache_range_; - use_custom_range_ = false; - } else { - using_range = cache_range_; - } + && (viewer_node_->GetVideoAutoCacheEnabled() || use_custom_range_) + && !IsRenderingCustomRange()) { + TimeRange using_range = use_custom_range_ ? custom_autocache_range_ : cache_range_; TimeRangeList invalidated = viewer_node_->video_frame_cache()->GetInvalidatedRanges(using_range); queued_frame_iterator_ = TimeRangeListFrameIterator(invalidated, viewer_node_->video_frame_cache()->GetTimebase()); + queued_frame_iterator_.SetCustomRange(use_custom_range_); + + use_custom_range_ = false; + TryRender(); } } @@ -773,7 +769,8 @@ void PreviewAutoCacher::ForceCacheRange(const TimeRange &range) use_custom_range_ = true; custom_autocache_range_ = range; - RequeueFrames(); + // Re-hash these frames and start rendering + StartCachingVideoRange(range); } void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node) diff --git a/app/render/previewautocacher.h b/app/render/previewautocacher.h index 0387f7204..f85dfe7c1 100644 --- a/app/render/previewautocacher.h +++ b/app/render/previewautocacher.h @@ -94,6 +94,11 @@ public: void CancelVideoTasks(bool and_wait_for_them_to_finish = false); void CancelAudioTasks(bool and_wait_for_them_to_finish = false); + bool IsRenderingCustomRange() const + { + return queued_frame_iterator_.IsCustomRange() && queued_frame_iterator_.HasNext(); + } + private: void TryRender(); diff --git a/app/widget/viewer/viewer.cpp b/app/widget/viewer/viewer.cpp index 9d3d976f0..627613e40 100644 --- a/app/widget/viewer/viewer.cpp +++ b/app/widget/viewer/viewer.cpp @@ -600,7 +600,7 @@ void ViewerWidget::UpdateTextureFromNode() nonqueue_watchers_.append(watcher); // Clear queue because we want this frame more than any others - if (!GetConnectedNode()->GetVideoAutoCacheEnabled()) { + if (!GetConnectedNode()->GetVideoAutoCacheEnabled() && !auto_cacher_.IsRenderingCustomRange()) { ClearVideoAutoCacherQueue(); }