cache: reimplemented disk manager to enforce limit in preferences
This commit is contained in:
@@ -34,6 +34,14 @@
|
|||||||
|
|
||||||
OLIVE_NAMESPACE_ENTER
|
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)
|
QByteArray FrameHashCache::GetHash(const rational &time)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(lock());
|
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 {
|
struct HashTimePair {
|
||||||
rational time;
|
rational time;
|
||||||
QByteArray hash;
|
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 FrameHashCache::CachePathName(const QByteArray& hash)
|
||||||
{
|
{
|
||||||
QString ext = GetFormatExtension();
|
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);
|
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);
|
return cache_dir.filePath(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,7 @@ class FrameHashCache : public PlaybackCache
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
FrameHashCache(QObject* parent = nullptr) :
|
FrameHashCache(QObject* parent = nullptr);
|
||||||
PlaybackCache(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray GetHash(const rational& time);
|
QByteArray GetHash(const rational& time);
|
||||||
|
|
||||||
@@ -82,8 +79,6 @@ public slots:
|
|||||||
protected:
|
protected:
|
||||||
virtual void LengthChangedEvent(const rational& old, const rational& newlen) override;
|
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;
|
virtual void ShiftEvent(const rational& from, const rational& to) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -91,6 +86,9 @@ private:
|
|||||||
|
|
||||||
rational timebase_;
|
rational timebase_;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void HashDeleted(const QByteArray& hash);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
OLIVE_NAMESPACE_EXIT
|
OLIVE_NAMESPACE_EXIT
|
||||||
|
|||||||
Reference in New Issue
Block a user