only disk cache around the playhead
This commit is contained in:
@@ -115,13 +115,10 @@ void RenderBackend::InvalidateCache(const rational &start_range, const rational
|
||||
<< "and"
|
||||
<< end_range_adj.toDouble();
|
||||
|
||||
// Add the range to the list
|
||||
cache_queue_.InsertTimeRange(TimeRange(start_range_adj, end_range_adj));
|
||||
|
||||
// Queue value update
|
||||
QueueValueUpdate();
|
||||
|
||||
CacheNext();
|
||||
InvalidateCacheInternal(start_range_adj, end_range_adj);
|
||||
}
|
||||
|
||||
bool RenderBackend::Compile()
|
||||
@@ -356,6 +353,14 @@ const QVector<QThread *> &RenderBackend::threads()
|
||||
return threads_;
|
||||
}
|
||||
|
||||
void RenderBackend::InvalidateCacheInternal(const rational &start_range, const rational &end_range)
|
||||
{
|
||||
// Add the range to the list
|
||||
cache_queue_.InsertTimeRange(TimeRange(start_range, end_range));
|
||||
|
||||
CacheNext();
|
||||
}
|
||||
|
||||
void RenderBackend::CacheIDChangedEvent(const QString &id)
|
||||
{
|
||||
Q_UNUSED(id)
|
||||
|
||||
@@ -63,6 +63,8 @@ protected:
|
||||
*/
|
||||
virtual bool GenerateCacheIDInternal(QCryptographicHash& hash) = 0;
|
||||
|
||||
virtual void InvalidateCacheInternal(const rational &start_range, const rational &end_range);
|
||||
|
||||
virtual void CacheIDChangedEvent(const QString& id);
|
||||
|
||||
void SetError(const QString& error);
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <QtMath>
|
||||
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "config/config.h"
|
||||
#include "render/diskmanager.h"
|
||||
#include "render/diskmanager.h"
|
||||
#include "render/pixelservice.h"
|
||||
#include "videorenderworker.h"
|
||||
@@ -37,6 +39,7 @@ VideoRenderBackend::VideoRenderBackend(QObject *parent) :
|
||||
operating_mode_(VideoRenderWorker::kHashRenderCache),
|
||||
only_signal_last_frame_requested_(true)
|
||||
{
|
||||
connect(DiskManager::instance(), &DiskManager::DeletedFrame, this, &VideoRenderBackend::FrameRemovedFromDiskCache);
|
||||
}
|
||||
|
||||
bool VideoRenderBackend::InitInternal()
|
||||
@@ -142,10 +145,21 @@ void VideoRenderBackend::ConnectWorkerToThis(RenderWorker *processor)
|
||||
|
||||
video_processor->SetOperatingMode(operating_mode_);
|
||||
|
||||
connect(video_processor, &VideoRenderWorker::CompletedFrame, this, &VideoRenderBackend::ThreadCompletedFrame);
|
||||
connect(video_processor, &VideoRenderWorker::HashAlreadyBeingCached, this, &VideoRenderBackend::ThreadSkippedFrame);
|
||||
connect(video_processor, &VideoRenderWorker::CompletedDownload, this, &VideoRenderBackend::ThreadCompletedDownload);
|
||||
connect(video_processor, &VideoRenderWorker::HashAlreadyExists, this, &VideoRenderBackend::ThreadHashAlreadyExists);
|
||||
connect(video_processor, &VideoRenderWorker::CompletedFrame, this, &VideoRenderBackend::ThreadCompletedFrame, Qt::QueuedConnection);
|
||||
connect(video_processor, &VideoRenderWorker::HashAlreadyBeingCached, this, &VideoRenderBackend::ThreadSkippedFrame, Qt::QueuedConnection);
|
||||
connect(video_processor, &VideoRenderWorker::CompletedDownload, this, &VideoRenderBackend::ThreadCompletedDownload, Qt::QueuedConnection);
|
||||
connect(video_processor, &VideoRenderWorker::HashAlreadyExists, this, &VideoRenderBackend::ThreadHashAlreadyExists, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void VideoRenderBackend::InvalidateCacheInternal(const rational &start_range, const rational &end_range)
|
||||
{
|
||||
TimeRange invalidated(start_range, end_range);
|
||||
|
||||
missing_cache_.InsertTimeRange(invalidated);
|
||||
|
||||
emit RangeInvalidated(invalidated);
|
||||
|
||||
Requeue();
|
||||
}
|
||||
|
||||
VideoRenderFrameCache *VideoRenderBackend::frame_cache()
|
||||
@@ -172,6 +186,8 @@ const char *VideoRenderBackend::GetCachedFrame(const rational &time)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Requeue();
|
||||
|
||||
// Find frame in map
|
||||
QByteArray frame_hash = frame_cache_.TimeToHash(time);
|
||||
|
||||
@@ -220,8 +236,13 @@ TimeRange VideoRenderBackend::PopNextFrameFromQueue()
|
||||
snapped_in -= params_.time_base();
|
||||
}
|
||||
|
||||
TimeRange frame_range(snapped_in, snapped_in + params_.time_base());
|
||||
|
||||
// Remove this particular frame from the queue
|
||||
cache_queue_.RemoveTimeRange(TimeRange(snapped_in, snapped_in + params_.time_base()));
|
||||
cache_queue_.RemoveTimeRange(frame_range);
|
||||
|
||||
// Remove this particular frame from missing frames
|
||||
missing_cache_.RemoveTimeRange(frame_range);
|
||||
|
||||
// Return the snapped frame
|
||||
return TimeRange(snapped_in, snapped_in);
|
||||
@@ -293,6 +314,19 @@ void VideoRenderBackend::TruncateFrameCacheLength(const rational &length)
|
||||
frame_cache_.Truncate(length);
|
||||
}
|
||||
|
||||
void VideoRenderBackend::FrameRemovedFromDiskCache(const QByteArray &hash)
|
||||
{
|
||||
QList<rational> deleted_frames = frame_cache()->FramesWithHash(hash);
|
||||
|
||||
foreach (const rational& frame, deleted_frames) {
|
||||
TimeRange invalidated(frame, frame+params_.time_base());
|
||||
|
||||
missing_cache_.InsertTimeRange(invalidated);
|
||||
|
||||
emit RangeInvalidated(invalidated);
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoRenderBackend::TimeIsQueued(const TimeRange &time) const
|
||||
{
|
||||
return cache_queue_.ContainsTimeRange(time);
|
||||
@@ -314,3 +348,16 @@ bool VideoRenderBackend::SetFrameHash(const NodeDependency &dep, const QByteArra
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void VideoRenderBackend::Requeue()
|
||||
{
|
||||
cache_queue_.clear();
|
||||
|
||||
// Reset queue around the last time requested
|
||||
TimeRange queueable_range(last_time_requested_ - Config::Current()["DiskCacheBehind"].value<rational>(),
|
||||
last_time_requested_ + Config::Current()["DiskCacheAhead"].value<rational>());
|
||||
|
||||
cache_queue_ = missing_cache_.Intersects(queueable_range);
|
||||
|
||||
CacheNext();
|
||||
}
|
||||
|
||||
@@ -103,12 +103,16 @@ protected:
|
||||
|
||||
virtual void EmitCachedFrameReady(const rational &time, const QVariant& value, qint64 job_time) = 0;
|
||||
|
||||
virtual void InvalidateCacheInternal(const rational &start_range, const rational &end_range) override;
|
||||
|
||||
VideoRenderWorker::OperatingMode operating_mode_;
|
||||
|
||||
signals:
|
||||
void CachedFrameReady(const rational& time, QVariant value, qint64 job_time);
|
||||
void CachedTimeReady(const rational& time, qint64 job_time);
|
||||
|
||||
void RangeInvalidated(const TimeRange& range);
|
||||
|
||||
private:
|
||||
bool TimeIsQueued(const TimeRange &time) const;
|
||||
|
||||
@@ -116,12 +120,16 @@ private:
|
||||
|
||||
bool SetFrameHash(const NodeDependency& dep, const QByteArray& hash, const qint64& job_time);
|
||||
|
||||
void Requeue();
|
||||
|
||||
VideoRenderingParams params_;
|
||||
|
||||
QByteArray cache_frame_load_buffer_;
|
||||
|
||||
VideoRenderFrameCache frame_cache_;
|
||||
|
||||
TimeRangeList missing_cache_;
|
||||
|
||||
rational last_time_requested_;
|
||||
|
||||
bool only_signal_last_frame_requested_;
|
||||
@@ -134,6 +142,8 @@ private slots:
|
||||
|
||||
void TruncateFrameCacheLength(const rational& length);
|
||||
|
||||
void FrameRemovedFromDiskCache(const QByteArray& hash);
|
||||
|
||||
};
|
||||
|
||||
#endif // VIDEORENDERERBACKEND_H
|
||||
|
||||
Reference in New Issue
Block a user