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
+36 -5
View File
@@ -177,15 +177,46 @@ FramePtr FrameHashCache::LoadCacheFrame(const QString &fn)
}
file.setFrameBuffer(framebuffer);
file.readPixels(dw.min.y, dw.max.y);
} catch (const std::exception &e) {
qCritical() << "Failed to read cache frame:" << e.what();
// Not an EXR, maybe it's a JPEG?
QImage img;
// Clear frame to signal that nothing was loaded
frame = nullptr;
if (img.load(fn, "jpg")) {
// Assume this frame is corrupt in some way and delete it
QMetaObject::invokeMethod(DiskManager::instance(), "DeleteSpecificFile", Q_ARG(QString, fn));
// FIXME: Hardcoded
const int div = 1;
const VideoParams::Format image_format = VideoParams::kFormatUnsigned8;
const int channel_count = 4;
const rational par(1, 1);
frame = Frame::Create();
frame->set_video_params(VideoParams(img.width() * div,
img.height() * div,
image_format,
channel_count,
par,
VideoParams::kInterlaceNone,
div));
frame->allocate();
for (int i=0; i<img.height(); i++) {
memcpy(frame->data() + frame->linesize_bytes() * i,
img.bits() + img.bytesPerLine() * i,
frame->width() * frame->video_params().GetBytesPerPixel());
}
} else {
qCritical() << "Failed to read cache frame:" << e.what();
// Clear frame to signal that nothing was loaded
frame = nullptr;
// Assume this frame is corrupt in some way and delete it
QMetaObject::invokeMethod(DiskManager::instance(), "DeleteSpecificFile", Q_ARG(QString, fn));
}
}
}
+11 -2
View File
@@ -39,6 +39,8 @@ void PlaybackCache::Invalidate(const TimeRange &r)
InvalidateEvent(r);
emit Invalidated(r);
SaveState();
}
Node *PlaybackCache::parent() const
@@ -89,8 +91,6 @@ void PlaybackCache::LoadState()
}
f.close();
f.close();
}
}
@@ -165,6 +165,8 @@ void PlaybackCache::Validate(const TimeRange &r, bool signal)
if (signal) {
emit Validated(r);
}
SaveState();
}
void PlaybackCache::InvalidateEvent(const TimeRange &)
@@ -182,6 +184,13 @@ PlaybackCache::PlaybackCache(QObject *parent) :
uuid_ = QUuid::createUuid();
}
void PlaybackCache::SetUuid(const QUuid &u)
{
uuid_ = u;
LoadState();
}
TimeRangeList PlaybackCache::GetInvalidatedRanges(TimeRange intersecting) const
{
TimeRangeList invalidated;
+6 -1
View File
@@ -22,6 +22,7 @@
#define PLAYBACKCACHE_H
#include <QDir>
#include <QMutex>
#include <QObject>
#include <QPainter>
#include <QUuid>
@@ -42,7 +43,7 @@ public:
PlaybackCache(QObject* parent = nullptr);
const QUuid &GetUuid() const { return uuid_; }
void SetUuid(const QUuid &u) { uuid_ = u; }
void SetUuid(const QUuid &u);
TimeRangeList GetInvalidatedRanges(TimeRange intersecting) const;
TimeRangeList GetInvalidatedRanges(const rational &length) const
@@ -78,6 +79,8 @@ public:
return QFontMetrics(QFont()).height()/4;
}
QMutex *mutex() { return &mutex_; }
public slots:
void InvalidateAll();
@@ -106,6 +109,8 @@ private:
QUuid uuid_;
QMutex mutex_;
};
}
+3 -8
View File
@@ -269,6 +269,9 @@ void PreviewAutoCacher::AddNode(Node *node)
// Add to project
copy->setParent(&copied_project_);
// Disable caches for copy
copy->SetCachesEnabled(false);
// Copy cache UUIDs
copy->CopyCacheUuidsFrom(node);
@@ -380,10 +383,6 @@ void PreviewAutoCacher::ConnectToNodeCache(Node *node)
&PlaybackCache::CancelAll,
this,
&PreviewAutoCacher::CancelForCache);
node->video_frame_cache()->LoadState();
node->audio_playback_cache()->LoadState();
node->thumbnail_cache()->LoadState();
}
void PreviewAutoCacher::DisconnectFromNodeCache(Node *node)
@@ -417,10 +416,6 @@ void PreviewAutoCacher::DisconnectFromNodeCache(Node *node)
&PlaybackCache::CancelAll,
this,
&PreviewAutoCacher::CancelForCache);
node->video_frame_cache()->SaveState();
node->audio_playback_cache()->SaveState();
node->thumbnail_cache()->SaveState();
}
void PreviewAutoCacher::UpdateGraphChangeValue()
+2
View File
@@ -74,6 +74,8 @@ TexturePtr Renderer::InterlaceTexture(TexturePtr top, TexturePtr bottom, const V
QVariant Renderer::GetDefaultShader()
{
QMutexLocker locker(&color_cache_mutex_);
if (default_shader_.isNull()) {
default_shader_ = CreateNativeShader(ShaderCode(QString(), QString()));
}
+8 -4
View File
@@ -253,21 +253,25 @@ DecoderPtr RenderProcessor::ResolveDecoderFromInput(const QString& decoder_id, c
qint64 file_last_modified = QFileInfo(stream.filename()).lastModified().toMSecsSinceEpoch();
if (!decoder.decoder || decoder.last_modified != file_last_modified) {
DecoderPtr dec = nullptr;
if (decoder.decoder && decoder.last_modified == file_last_modified) {
dec = decoder.decoder;
} else {
// No decoder
decoder.decoder = Decoder::CreateFromID(decoder_id);
decoder.decoder = dec = Decoder::CreateFromID(decoder_id);
decoder.last_modified = file_last_modified;
decoder_cache_->insert(stream, decoder);
locker.unlock();
if (!decoder.decoder->Open(stream)) {
if (!dec->Open(stream)) {
qWarning() << "Failed to open decoder for" << stream.filename()
<< "::" << stream.stream();
return nullptr;
}
}
return decoder.decoder;
return dec;
}
void RenderProcessor::Process(RenderTicketPtr ticket, Renderer *render_ctx, DecoderCache *decoder_cache, ShaderCache *shader_cache)