cache: add passthroughs to allow shallow copies of data
This commit is contained in:
@@ -98,4 +98,15 @@ rational AudioWaveformCache::length() const
|
||||
return len;
|
||||
}
|
||||
|
||||
void AudioWaveformCache::SetPassthrough(PlaybackCache *cache)
|
||||
{
|
||||
AudioWaveformCache *c = static_cast<AudioWaveformCache*>(cache);
|
||||
waveforms_ = c->waveforms_;
|
||||
for (const TimeRange &r : c->GetValidatedRanges()) {
|
||||
Validate(r);
|
||||
}
|
||||
SetParameters(c->GetParameters());
|
||||
SetSavingEnabled(c->IsSavingEnabled());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
|
||||
rational length() const;
|
||||
|
||||
virtual void SetPassthrough(PlaybackCache *cache) override;
|
||||
|
||||
private:
|
||||
class TimeRangeWithWaveform : public TimeRange
|
||||
{
|
||||
|
||||
@@ -64,6 +64,21 @@ void FrameHashCache::ValidateTime(const rational &time)
|
||||
Validate(TimeRange(time, time + timebase_));
|
||||
}
|
||||
|
||||
QString FrameHashCache::GetValidCacheFilename(const rational &time) const
|
||||
{
|
||||
if (IsFrameCached(time)) {
|
||||
return CachePathName(time);
|
||||
} else if (!GetPassthroughs().empty()) {
|
||||
for (const Passthrough &p : GetPassthroughs()) {
|
||||
if (p.Contains(time)) {
|
||||
return CachePathName(GetCacheDirectory(), p.cache, time, timebase_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool FrameHashCache::SaveCacheFrame(const int64_t &time, FramePtr frame) const
|
||||
{
|
||||
return SaveCacheFrame(GetCacheDirectory(), GetUuid(), time, frame);
|
||||
@@ -224,6 +239,12 @@ FramePtr FrameHashCache::LoadCacheFrame(const QString &fn)
|
||||
return frame;
|
||||
}
|
||||
|
||||
void FrameHashCache::SetPassthrough(PlaybackCache *cache)
|
||||
{
|
||||
super::SetPassthrough(cache);
|
||||
SetTimebase(static_cast<FrameHashCache*>(cache)->GetTimebase());
|
||||
}
|
||||
|
||||
void FrameHashCache::LoadStateEvent(QDataStream &stream)
|
||||
{
|
||||
uint32_t version;
|
||||
|
||||
@@ -48,14 +48,7 @@ public:
|
||||
return GetValidatedRanges().contains(time);
|
||||
}
|
||||
|
||||
QString GetValidCacheFilename(const rational &time) const
|
||||
{
|
||||
if (IsFrameCached(time)) {
|
||||
return CachePathName(time);
|
||||
} else {
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
QString GetValidCacheFilename(const rational &time) const;
|
||||
|
||||
static bool SaveCacheFrame(const QString& filename, FramePtr frame);
|
||||
bool SaveCacheFrame(const int64_t &time, FramePtr frame) const;
|
||||
@@ -65,6 +58,8 @@ public:
|
||||
FramePtr LoadCacheFrame(const int64_t &time) const;
|
||||
static FramePtr LoadCacheFrame(const QString& fn);
|
||||
|
||||
virtual void SetPassthrough(PlaybackCache *cache) override;
|
||||
|
||||
protected:
|
||||
virtual void LoadStateEvent(QDataStream &stream) override;
|
||||
virtual void SaveStateEvent(QDataStream &stream) override;
|
||||
|
||||
@@ -36,6 +36,10 @@ void PlaybackCache::Invalidate(const TimeRange &r)
|
||||
|
||||
validated_.remove(r);
|
||||
|
||||
if (!passthroughs_.empty()) {
|
||||
TimeRangeList::util_remove(&passthroughs_, r);
|
||||
}
|
||||
|
||||
InvalidateEvent(r);
|
||||
|
||||
emit Invalidated(r);
|
||||
@@ -72,14 +76,14 @@ void PlaybackCache::LoadState()
|
||||
|
||||
LoadStateEvent(s);
|
||||
|
||||
int count;
|
||||
s >> count;
|
||||
|
||||
switch (version) {
|
||||
case 1:
|
||||
validated_.clear();
|
||||
{
|
||||
int valid_count, pass_count;
|
||||
|
||||
for (int i=0; i<count; i++) {
|
||||
validated_.clear();
|
||||
s >> valid_count;
|
||||
for (int i=0; i<valid_count; i++) {
|
||||
int in_num, in_den, out_num, out_den;
|
||||
|
||||
s >> in_num;
|
||||
@@ -89,8 +93,27 @@ void PlaybackCache::LoadState()
|
||||
|
||||
validated_.insert(TimeRange(rational(in_num, in_den), rational(out_num, out_den)));
|
||||
}
|
||||
|
||||
passthroughs_.clear();
|
||||
s >> pass_count;
|
||||
for (int i=0; i<pass_count; i++) {
|
||||
QUuid id;
|
||||
int in_num, in_den, out_num, out_den;
|
||||
|
||||
s >> in_num;
|
||||
s >> in_den;
|
||||
s >> out_num;
|
||||
s >> out_den;
|
||||
s >> id;
|
||||
|
||||
Passthrough p = TimeRange(rational(in_num, in_den), rational(out_num, out_den));
|
||||
p.cache = id;
|
||||
passthroughs_.append(p);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
@@ -100,7 +123,7 @@ void PlaybackCache::SaveState()
|
||||
{
|
||||
QDir cache_dir = GetThisCacheDirectory();
|
||||
QFile f(cache_dir.filePath(QStringLiteral("state")));
|
||||
if (validated_.isEmpty()) {
|
||||
if (validated_.isEmpty() && passthroughs_.isEmpty()) {
|
||||
if (f.exists()) {
|
||||
f.remove();
|
||||
}
|
||||
@@ -123,6 +146,16 @@ void PlaybackCache::SaveState()
|
||||
s << r.out().denominator();
|
||||
}
|
||||
|
||||
s << passthroughs_.size();
|
||||
|
||||
for (const Passthrough &p : passthroughs_) {
|
||||
s << p.in().numerator();
|
||||
s << p.in().denominator();
|
||||
s << p.out().numerator();
|
||||
s << p.out().denominator();
|
||||
s << p.cache;
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
@@ -155,6 +188,21 @@ void PlaybackCache::Draw(QPainter *p, const rational &start, double scale, const
|
||||
}
|
||||
}
|
||||
|
||||
void PlaybackCache::SetPassthrough(PlaybackCache *cache)
|
||||
{
|
||||
for (const TimeRange &r : cache->GetValidatedRanges()) {
|
||||
Passthrough p = r;
|
||||
p.cache = cache->GetUuid();
|
||||
passthroughs_.push_back(p);
|
||||
}
|
||||
|
||||
passthroughs_.append(cache->GetPassthroughs());
|
||||
|
||||
if (saving_enabled_) {
|
||||
SaveState();
|
||||
}
|
||||
}
|
||||
|
||||
void PlaybackCache::InvalidateAll()
|
||||
{
|
||||
Invalidate(TimeRange(0, RATIONAL_MAX));
|
||||
@@ -211,6 +259,10 @@ TimeRangeList PlaybackCache::GetInvalidatedRanges(TimeRange intersecting) const
|
||||
invalidated.remove(range);
|
||||
}
|
||||
|
||||
foreach (const TimeRange &range, passthroughs_) {
|
||||
invalidated.remove(range);
|
||||
}
|
||||
|
||||
return invalidated;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,22 @@ public:
|
||||
bool IsSavingEnabled() const { return saving_enabled_; }
|
||||
void SetSavingEnabled(bool e) { saving_enabled_ = e; }
|
||||
|
||||
virtual void SetPassthrough(PlaybackCache *cache);
|
||||
|
||||
QMutex *mutex() { return &mutex_; }
|
||||
|
||||
class Passthrough : public TimeRange
|
||||
{
|
||||
public:
|
||||
Passthrough(const TimeRange &r) :
|
||||
TimeRange(r)
|
||||
{}
|
||||
|
||||
QUuid cache;
|
||||
};
|
||||
|
||||
const QVector<Passthrough> &GetPassthroughs() const { return passthroughs_; }
|
||||
|
||||
public slots:
|
||||
void InvalidateAll();
|
||||
|
||||
@@ -116,6 +130,8 @@ private:
|
||||
|
||||
QMutex mutex_;
|
||||
|
||||
QVector<Passthrough> passthroughs_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user