cache: behavior improvements

This commit is contained in:
itsmattkc
2022-06-06 09:39:09 -07:00
parent 25699ef05b
commit dfc401b63c
5 changed files with 29 additions and 17 deletions
+9 -9
View File
@@ -192,39 +192,39 @@ void ClipBlock::RequestInvalidatedFromConnected(const TimeRange &range)
TimeRange max_range = InputTimeAdjustment(kBufferIn, -1, TimeRange(0, length()));
if (type == Track::kVideo) {
// Handle thumbnails
RequestInvalidatedForCache(connected->thumbnail_cache(), max_range, range);
RequestInvalidatedForCache(connected->thumbnail_cache(), max_range, range, true);
// Handle video cache
if (IsAutocaching()) {
RequestInvalidatedForCache(connected->video_frame_cache(), max_range, range);
}
RequestInvalidatedForCache(connected->video_frame_cache(), max_range, range, IsAutocaching());
} else if (type == Track::kAudio) {
// Handle waveforms
RequestInvalidatedForCache(connected->waveform_cache(), max_range, range);
RequestInvalidatedForCache(connected->waveform_cache(), max_range, range, true);
// Handle audio cache
if (IsAutocaching()) {
RequestInvalidatedForCache(connected->audio_playback_cache(), max_range, range);
}
RequestInvalidatedForCache(connected->audio_playback_cache(), max_range, range, IsAutocaching());
}
}
}
}
void ClipBlock::RequestInvalidatedForCache(PlaybackCache *cache, const TimeRange &max_range, const TimeRange &range)
void ClipBlock::RequestInvalidatedForCache(PlaybackCache *cache, const TimeRange &max_range, const TimeRange &range, bool request)
{
if ((range.in() == RATIONAL_MIN && range.out() == RATIONAL_MAX) || !range.length().isNull()) {
// Request only this range
TimeRange r = range.Intersected(max_range);
cache->Invalidate(r);
if (request) {
emit cache->Request(r);
}
} else {
// Request all ranges currently marked as invalid
if (request) {
TimeRangeList invalid = cache->GetInvalidatedRanges(max_range);
for (const TimeRange &r : invalid) {
emit cache->Request(r);
}
}
}
}
void ClipBlock::InvalidateCache(const TimeRange& range, const QString& from, int element, InvalidateCacheOptions options)
+1 -1
View File
@@ -196,7 +196,7 @@ private:
void RequestInvalidatedFromConnected(const TimeRange &range = TimeRange());
void RequestInvalidatedForCache(PlaybackCache *cache, const TimeRange &max_range, const TimeRange &range);
void RequestInvalidatedForCache(PlaybackCache *cache, const TimeRange &max_range, const TimeRange &range, bool request);
QVector<Block*> block_links_;
+2
View File
@@ -57,6 +57,8 @@ Node::Node() :
thumbnail_cache_ = new ThumbnailCache(this);
audio_cache_ = new AudioPlaybackCache(this);
waveform_cache_ = new AudioWaveformCache(this);
waveform_cache_->SetSavingEnabled(false);
}
Node::~Node()
+6 -1
View File
@@ -40,7 +40,9 @@ void PlaybackCache::Invalidate(const TimeRange &r)
emit Invalidated(r);
if (saving_enabled_) {
SaveState();
}
}
Node *PlaybackCache::parent() const
@@ -166,7 +168,9 @@ void PlaybackCache::Validate(const TimeRange &r, bool signal)
emit Validated(r);
}
if (saving_enabled_) {
SaveState();
}
}
void PlaybackCache::InvalidateEvent(const TimeRange &)
@@ -179,7 +183,8 @@ Project *PlaybackCache::GetProject() const
}
PlaybackCache::PlaybackCache(QObject *parent) :
QObject(parent)
QObject(parent),
saving_enabled_(true)
{
uuid_ = QUuid::createUuid();
}
+5
View File
@@ -79,6 +79,9 @@ public:
return QFontMetrics(QFont()).height()/4;
}
bool IsSavingEnabled() const { return saving_enabled_; }
void SetSavingEnabled(bool e) { saving_enabled_ = e; }
QMutex *mutex() { return &mutex_; }
public slots:
@@ -109,6 +112,8 @@ private:
QUuid uuid_;
bool saving_enabled_;
QMutex mutex_;
};