cache: save states to disk
This commit is contained in:
@@ -193,6 +193,32 @@ FramePtr FrameHashCache::LoadCacheFrame(const QString &fn)
|
||||
return frame;
|
||||
}
|
||||
|
||||
void FrameHashCache::LoadStateEvent(QDataStream &stream)
|
||||
{
|
||||
uint32_t version;
|
||||
int num, den;
|
||||
|
||||
stream >> version;
|
||||
|
||||
switch (version) {
|
||||
case 1:
|
||||
stream >> num;
|
||||
stream >> den;
|
||||
timebase_ = rational(num, den);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FrameHashCache::SaveStateEvent(QDataStream &stream)
|
||||
{
|
||||
uint32_t version = 1;
|
||||
|
||||
stream << version;
|
||||
|
||||
stream << timebase_.numerator();
|
||||
stream << timebase_.denominator();
|
||||
}
|
||||
|
||||
rational FrameHashCache::ToTime(const int64_t &ts) const
|
||||
{
|
||||
return Timecode::timestamp_to_time(ts, timebase_);
|
||||
|
||||
@@ -65,6 +65,10 @@ public:
|
||||
FramePtr LoadCacheFrame(const int64_t &time) const;
|
||||
static FramePtr LoadCacheFrame(const QString& fn);
|
||||
|
||||
protected:
|
||||
virtual void LoadStateEvent(QDataStream &stream) override;
|
||||
virtual void SaveStateEvent(QDataStream &stream) override;
|
||||
|
||||
private:
|
||||
rational ToTime(const int64_t &ts) const;
|
||||
int64_t ToTimestamp(const rational &ts, Timecode::Rounding rounding = Timecode::kRound) const;
|
||||
|
||||
@@ -60,6 +60,77 @@ QDir PlaybackCache::GetThisCacheDirectory(const QString &cache_path, const QUuid
|
||||
return QDir(cache_path).filePath(cache_id.toString());
|
||||
}
|
||||
|
||||
void PlaybackCache::LoadState()
|
||||
{
|
||||
QDir cache_dir = GetThisCacheDirectory();
|
||||
QFile f(cache_dir.filePath(QStringLiteral("state")));
|
||||
if (f.open(QFile::ReadOnly)) {
|
||||
QDataStream s(&f);
|
||||
|
||||
uint32_t version;
|
||||
s >> version;
|
||||
|
||||
LoadStateEvent(s);
|
||||
|
||||
int count;
|
||||
s >> count;
|
||||
|
||||
switch (version) {
|
||||
case 1:
|
||||
validated_.clear();
|
||||
|
||||
for (int i=0; i<count; i++) {
|
||||
int in_num, in_den, out_num, out_den;
|
||||
|
||||
s >> in_num;
|
||||
s >> in_den;
|
||||
s >> out_num;
|
||||
s >> out_den;
|
||||
|
||||
validated_.insert(TimeRange(rational(in_num, in_den), rational(out_num, out_den)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
void PlaybackCache::SaveState()
|
||||
{
|
||||
QDir cache_dir = GetThisCacheDirectory();
|
||||
QFile f(cache_dir.filePath(QStringLiteral("state")));
|
||||
if (validated_.isEmpty()) {
|
||||
if (f.exists()) {
|
||||
f.remove();
|
||||
}
|
||||
} else {
|
||||
if (FileFunctions::DirectoryIsValid(cache_dir)) {
|
||||
if (f.open(QFile::WriteOnly)) {
|
||||
QDataStream s(&f);
|
||||
|
||||
uint32_t version = 1;
|
||||
s << version;
|
||||
|
||||
SaveStateEvent(s);
|
||||
|
||||
s << validated_.size();
|
||||
|
||||
for (const TimeRange &r : validated_) {
|
||||
s << r.in().numerator();
|
||||
s << r.in().denominator();
|
||||
s << r.out().numerator();
|
||||
s << r.out().denominator();
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlaybackCache::InvalidateAll()
|
||||
{
|
||||
Invalidate(TimeRange(0, RATIONAL_MAX));
|
||||
|
||||
@@ -74,6 +74,9 @@ public:
|
||||
kPreviewsOnly
|
||||
};
|
||||
|
||||
void LoadState();
|
||||
void SaveState();
|
||||
|
||||
public slots:
|
||||
void InvalidateAll();
|
||||
|
||||
@@ -91,6 +94,10 @@ protected:
|
||||
|
||||
virtual void InvalidateEvent(const TimeRange& range);
|
||||
|
||||
virtual void LoadStateEvent(QDataStream &stream){}
|
||||
|
||||
virtual void SaveStateEvent(QDataStream &stream){}
|
||||
|
||||
Project* GetProject() const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -345,6 +345,10 @@ void PreviewAutoCacher::ConnectToNodeCache(Node *node)
|
||||
this,
|
||||
&PreviewAutoCacher::AudioInvalidatedFromCache);
|
||||
|
||||
node->video_frame_cache()->LoadState();
|
||||
node->audio_playback_cache()->LoadState();
|
||||
node->thumbnail_cache()->LoadState();
|
||||
|
||||
// Copy invalidated ranges and start rendering if necessary
|
||||
if (node->video_frame_cache()->IsAutomatic()) {
|
||||
VideoAutoCacheEnableChangedFromNode(node, true);
|
||||
@@ -382,6 +386,10 @@ void PreviewAutoCacher::DisconnectFromNodeCache(Node *node)
|
||||
this,
|
||||
&PreviewAutoCacher::AudioInvalidatedFromCache);
|
||||
|
||||
node->video_frame_cache()->SaveState();
|
||||
node->audio_playback_cache()->SaveState();
|
||||
node->thumbnail_cache()->SaveState();
|
||||
|
||||
if (node->video_frame_cache()->IsAutomatic()) {
|
||||
VideoAutoCacheEnableChangedFromNode(node, false);
|
||||
}
|
||||
@@ -841,6 +849,9 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
|
||||
for (int i=copied_project_.nodes().size(); i<graph->nodes().size(); i++) {
|
||||
AddNode(graph->nodes().at(i));
|
||||
}
|
||||
for (int i=0; i<graph->nodes().size(); i++) {
|
||||
graph->nodes().at(i)->ConnectedToPreviewEvent();
|
||||
}
|
||||
|
||||
// Find copied viewer node
|
||||
copied_viewer_node_ = static_cast<ViewerOutput*>(copy_map_.value(viewer_node_));
|
||||
|
||||
Reference in New Issue
Block a user