cache: use disk states to share caches

This commit is contained in:
itsmattkc
2022-06-05 19:47:33 -07:00
parent 13299d0a3b
commit 25699ef05b
14 changed files with 109 additions and 50 deletions
+6 -2
View File
@@ -215,7 +215,9 @@ void ClipBlock::RequestInvalidatedForCache(PlaybackCache *cache, const TimeRange
{
if ((range.in() == RATIONAL_MIN && range.out() == RATIONAL_MAX) || !range.length().isNull()) {
// Request only this range
emit cache->Request(range.Intersected(max_range));
TimeRange r = range.Intersected(max_range);
cache->Invalidate(r);
emit cache->Request(r);
} else {
// Request all ranges currently marked as invalid
TimeRangeList invalid = cache->GetInvalidatedRanges(max_range);
@@ -232,7 +234,9 @@ void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int
// If signal is from texture input, transform all times from media time to sequence time
if (from == kBufferIn) {
// Render caches where necessary
RequestInvalidatedFromConnected(range);
if (AreCachesEnabled()) {
RequestInvalidatedFromConnected(range);
}
// Adjust range from media time to sequence time
TimeRange adj;
+4
View File
@@ -39,6 +39,10 @@ void NodeGraph::Clear()
{
// By deleting the last nodes first, we assume that nodes that are most important are deleted last
// (e.g. Project's ColorManager or ProjectSettingsNode.
for (auto it=node_children_.cbegin(); it!=node_children_.cend(); it++) {
(*it)->SetCachesEnabled(false);
}
while (!node_children_.isEmpty()) {
delete node_children_.last();
}
+14 -12
View File
@@ -48,8 +48,8 @@ Node::Node() :
can_be_deleted_(true),
override_color_(-1),
folder_(nullptr),
cache_result_(false),
flags_(kNone)
flags_(kNone),
caches_enabled_(true)
{
AddInput(kEnabledInput, NodeValue::kBoolean, true);
@@ -942,16 +942,18 @@ void Node::InvalidateCache(const TimeRange &range, const QString &from, int elem
Q_UNUSED(from)
Q_UNUSED(element)
if (range.in() != range.out()) {
TimeRange vr = range.Intersected(GetVideoCacheRange());
if (vr.length() != 0) {
video_frame_cache()->Invalidate(vr);
thumbnail_cache()->Invalidate(vr);
}
TimeRange ar = range.Intersected(GetAudioCacheRange());
if (ar.length() != 0) {
audio_playback_cache()->Invalidate(ar);
waveform_cache()->Invalidate(ar);
if (AreCachesEnabled()) {
if (range.in() != range.out()) {
TimeRange vr = range.Intersected(GetVideoCacheRange());
if (vr.length() != 0) {
video_frame_cache()->Invalidate(vr);
thumbnail_cache()->Invalidate(vr);
}
TimeRange ar = range.Intersected(GetAudioCacheRange());
if (ar.length() != 0) {
audio_playback_cache()->Invalidate(ar);
waveform_cache()->Invalidate(ar);
}
}
}
+5 -12
View File
@@ -355,6 +355,9 @@ public:
void CopyCacheUuidsFrom(Node *n);
bool AreCachesEnabled() const { return caches_enabled_; }
void SetCachesEnabled(bool e) { caches_enabled_ = e; }
virtual QString GetInputName(const QString& id) const;
void SetInputName(const QString& id, const QString& name);
@@ -930,16 +933,6 @@ public:
folder_ = folder;
}
bool GetCacheTextures() const
{
return cache_result_;
}
void SetCacheTextures(bool e)
{
cache_result_ = e;
}
class ArrayRemoveCommand : public UndoCommand
{
public:
@@ -1405,8 +1398,6 @@ private:
Folder* folder_;
bool cache_result_;
QMap<InputElementPair, ValueHint> value_hints_;
PositionMap context_positions_;
@@ -1423,6 +1414,8 @@ private:
AudioPlaybackCache *audio_cache_;
AudioWaveformCache *waveform_cache_;
bool caches_enabled_;
private slots:
/**
* @brief Slot when a keyframe's time changes to keep the keyframes correctly sorted by time
-2
View File
@@ -47,8 +47,6 @@ Footage::Footage(const QString &filename) :
valid_(false),
cancelled_(nullptr)
{
SetCacheTextures(true);
PrependInput(kLoopModeInput, NodeValue::kCombo, 0, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
PrependInput(kFilenameInput, NodeValue::kFile, InputFlags(kInputFlagNotConnectable | kInputFlagNotKeyframable));
@@ -90,7 +90,11 @@ ProjectSerializer220403::LoadData ProjectSerializer220403::Load(Project *project
qWarning() << "Failed to find node with ID" << id;
reader->skipCurrentElement();
} else {
// Disable cache while node is being loaded (we'll re-enable it later)
node->SetCachesEnabled(false);
LoadNode(node, xml_node_data, reader);
node->setParent(project);
}
}
@@ -312,6 +316,11 @@ ProjectSerializer220403::LoadData ProjectSerializer220403::Load(Project *project
}
}
// Re-enable caches
for (Node *n : project->nodes()) {
n->SetCachesEnabled(true);
}
return load_data;
}
+4 -1
View File
@@ -101,9 +101,12 @@ NodeValue NodeTraverser::GenerateRowValueElement(const Node *node, const QString
NodeValue value = table->TakeAt(value_index);
if (value.type() == NodeValue::kTexture) {
QMutexLocker locker(node->video_frame_cache()->mutex());
node->video_frame_cache()->LoadState();
QString cache = node->video_frame_cache()->GetValidCacheFilename(time.in());
if (!cache.isEmpty()) {
qDebug() << "pushing cache job";
value.set_value(CacheJob(cache, value.data()));
}
}