cache: reimplemented disk manager to enforce limit in preferences
This commit is contained in:
@@ -34,6 +34,14 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
FrameHashCache::FrameHashCache(QObject *parent) :
|
||||
PlaybackCache(parent)
|
||||
{
|
||||
if (DiskManager::instance()) {
|
||||
connect(DiskManager::instance(), &DiskManager::DeletedFrame, this, &FrameHashCache::HashDeleted);
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray FrameHashCache::GetHash(const rational &time)
|
||||
{
|
||||
QMutexLocker locker(lock());
|
||||
@@ -318,19 +326,6 @@ void FrameHashCache::LengthChangedEvent(const rational &old, const rational &new
|
||||
}
|
||||
}
|
||||
|
||||
void FrameHashCache::InvalidateEvent(const TimeRange &r)
|
||||
{
|
||||
QMap<rational, QByteArray>::iterator i = time_hash_map_.begin();
|
||||
|
||||
while (i != time_hash_map_.end()) {
|
||||
if (i.key() >= r.in() && i.key() < r.out()) {
|
||||
i = time_hash_map_.erase(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HashTimePair {
|
||||
rational time;
|
||||
QByteArray hash;
|
||||
@@ -372,6 +367,29 @@ void FrameHashCache::ShiftEvent(const rational &from, const rational &to)
|
||||
}
|
||||
}
|
||||
|
||||
void FrameHashCache::HashDeleted(const QByteArray &hash)
|
||||
{
|
||||
QMutexLocker locker(lock());
|
||||
|
||||
TimeRangeList invalidated;
|
||||
|
||||
QMap<rational, QByteArray>::const_iterator i;
|
||||
for (i=time_hash_map_.constBegin(); i!=time_hash_map_.constEnd(); i++) {
|
||||
if (i.value() == hash) {
|
||||
TimeRange r(i.key(), i.key() + timebase_);
|
||||
|
||||
NoLockInvalidate(r);
|
||||
invalidated.InsertTimeRange(r);
|
||||
}
|
||||
}
|
||||
|
||||
locker.unlock();
|
||||
|
||||
foreach (const TimeRange& r, invalidated) {
|
||||
emit Invalidated(r);
|
||||
}
|
||||
}
|
||||
|
||||
QString FrameHashCache::CachePathName(const QByteArray& hash)
|
||||
{
|
||||
QString ext = GetFormatExtension();
|
||||
@@ -381,6 +399,9 @@ QString FrameHashCache::CachePathName(const QByteArray& hash)
|
||||
|
||||
QString filename = QStringLiteral("%1%2").arg(QString(hash.mid(1).toHex()), ext);
|
||||
|
||||
// Register that in some way this hash has been accessed
|
||||
DiskManager::instance()->Accessed(hash);
|
||||
|
||||
return cache_dir.filePath(filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,10 +35,7 @@ class FrameHashCache : public PlaybackCache
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FrameHashCache(QObject* parent = nullptr) :
|
||||
PlaybackCache(parent)
|
||||
{
|
||||
}
|
||||
FrameHashCache(QObject* parent = nullptr);
|
||||
|
||||
QByteArray GetHash(const rational& time);
|
||||
|
||||
@@ -82,8 +79,6 @@ public slots:
|
||||
protected:
|
||||
virtual void LengthChangedEvent(const rational& old, const rational& newlen) override;
|
||||
|
||||
virtual void InvalidateEvent(const TimeRange& range) override;
|
||||
|
||||
virtual void ShiftEvent(const rational& from, const rational& to) override;
|
||||
|
||||
private:
|
||||
@@ -91,6 +86,9 @@ private:
|
||||
|
||||
rational timebase_;
|
||||
|
||||
private slots:
|
||||
void HashDeleted(const QByteArray& hash);
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
Reference in New Issue
Block a user