finished hashing algorithm for cache
This commit is contained in:
@@ -96,18 +96,22 @@ QVariant RendererProcessor::Value(NodeOutput* output, const rational& time)
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString fn = CachePathName(time);
|
||||
if (QFileInfo::exists(fn)) {
|
||||
auto in = OIIO::ImageInput::open(fn.toStdString());
|
||||
// Find frame in map
|
||||
if (time_hash_map_.contains(time)) {
|
||||
QString fn = CachePathName(time_hash_map_[time]);
|
||||
|
||||
if (in) {
|
||||
in->read_image(PixelService::GetPixelFormatInfo(format_).oiio_desc, cache_frame_load_buffer_.data());
|
||||
if (QFileInfo::exists(fn)) {
|
||||
auto in = OIIO::ImageInput::open(fn.toStdString());
|
||||
|
||||
in->close();
|
||||
if (in) {
|
||||
in->read_image(PixelService::GetPixelFormatInfo(format_).oiio_desc, cache_frame_load_buffer_.data());
|
||||
|
||||
master_texture_->Upload(cache_frame_load_buffer_.data());
|
||||
in->close();
|
||||
|
||||
return QVariant::fromValue(master_texture_);
|
||||
master_texture_->Upload(cache_frame_load_buffer_.data());
|
||||
|
||||
return QVariant::fromValue(master_texture_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,6 +126,8 @@ void RendererProcessor::Release()
|
||||
|
||||
void RendererProcessor::InvalidateCache(NodeInput* from, const rational &start_range, const rational &end_range)
|
||||
{
|
||||
Q_UNUSED(from)
|
||||
|
||||
qDebug() << "[RendererProcessor] Cache invalidated between"
|
||||
<< start_range.toDouble()
|
||||
<< "and"
|
||||
@@ -136,17 +142,12 @@ void RendererProcessor::InvalidateCache(NodeInput* from, const rational &start_r
|
||||
for (rational r=true_start_range;r<=end_range;r+=timebase_) {
|
||||
if (!cache_queue_.contains(r)) {
|
||||
cache_queue_.append(r);
|
||||
|
||||
QString fn = CachePathName(r);
|
||||
if (QFileInfo::exists(fn)) {
|
||||
QFile(fn).remove();
|
||||
}
|
||||
}
|
||||
|
||||
time_hash_map_.remove(r);
|
||||
}
|
||||
|
||||
CacheNext();
|
||||
|
||||
Node::InvalidateCache(from, start_range, end_range);
|
||||
}
|
||||
|
||||
void RendererProcessor::SetTimebase(const rational &timebase)
|
||||
@@ -209,7 +210,7 @@ void RendererProcessor::Start()
|
||||
threads_.resize(background_thread_count);
|
||||
|
||||
for (int i=0;i<threads_.size();i++) {
|
||||
threads_[i] = std::make_shared<RendererProcessThread>(ctx, effective_width_, effective_height_, format_, mode_);
|
||||
threads_[i] = std::make_shared<RendererProcessThread>(this, ctx, effective_width_, effective_height_, format_, mode_);
|
||||
threads_[i]->StartThread(QThread::LowPriority);
|
||||
|
||||
// Ensure this connection is "Queued" so that it always runs in this object's threaded rather than any of the
|
||||
@@ -300,16 +301,21 @@ void RendererProcessor::CacheNext()
|
||||
caching_ = true;
|
||||
}
|
||||
|
||||
QString RendererProcessor::CachePathName(const rational &time)
|
||||
QString RendererProcessor::CachePathName(const QByteArray &hash)
|
||||
{
|
||||
QDir this_cache_dir = QDir(GetMediaCacheLocation()).filePath(cache_id_);
|
||||
this_cache_dir.mkpath(".");
|
||||
|
||||
QString filename = QString("%1.%2.exr").arg(QString::number(time.numerator()), QString::number(time.denominator()));
|
||||
QString filename = QString("%1.exr").arg(QString(hash.toHex()));
|
||||
|
||||
return this_cache_dir.filePath(filename);
|
||||
}
|
||||
|
||||
bool RendererProcessor::HasHash(const QByteArray &hash)
|
||||
{
|
||||
return QFileInfo::exists(CachePathName(hash));
|
||||
}
|
||||
|
||||
void RendererProcessor::CalculateEffectiveDimensions()
|
||||
{
|
||||
effective_width_ = width_ / divider_;
|
||||
@@ -322,14 +328,16 @@ void RendererProcessor::ThreadCallback()
|
||||
// Threads are all done now, time to proceed
|
||||
caching_ = false;
|
||||
|
||||
RenderTexturePtr texture = texture_input_->get_value(cache_frame_).value<RenderTexturePtr>();
|
||||
RenderTexturePtr texture = master_thread_->texture();
|
||||
|
||||
if (texture != nullptr) {
|
||||
QString fn = CachePathName(cache_frame_);
|
||||
QString fn = CachePathName(master_thread_->hash());
|
||||
download_threads_[last_download_thread_%download_threads_.size()]->Queue(texture, fn, cache_frame_);
|
||||
last_download_thread_++;
|
||||
}
|
||||
|
||||
time_hash_map_.insert(cache_frame_, master_thread_->hash());
|
||||
|
||||
CacheNext();
|
||||
}
|
||||
}
|
||||
@@ -347,7 +355,7 @@ void RendererProcessor::ThreadRequestSibling(NodeDependency dep)
|
||||
void RendererProcessor::DownloadThreadFinished(const rational& time)
|
||||
{
|
||||
// Check if we just downloaded (akak finished caching) the frame we're currently on
|
||||
if (time == last_requested_time_ && texture_output_->IsConnected()) {
|
||||
if (texture_output_->IsConnected() && time == last_requested_time_) {
|
||||
// Send invalidate cache signal to all nodes connected to the texture output
|
||||
QVector<NodeEdgePtr> edges = texture_output()->edges();
|
||||
|
||||
|
||||
@@ -83,6 +83,11 @@ public:
|
||||
|
||||
void SetDivider(const int& divider);
|
||||
|
||||
/**
|
||||
* @brief Return whether a frame with this hash already exists
|
||||
*/
|
||||
bool HasHash(const QByteArray& hash);
|
||||
|
||||
/**
|
||||
* @brief Return current instance of a RenderThread (or nullptr if there is none)
|
||||
*
|
||||
@@ -126,7 +131,7 @@ private:
|
||||
/**
|
||||
* @brief Return the path of the cached image at this time
|
||||
*/
|
||||
QString CachePathName(const rational& time);
|
||||
QString CachePathName(const QByteArray &hash);
|
||||
|
||||
/**
|
||||
* @brief Internal list of RenderProcessThreads
|
||||
@@ -175,6 +180,8 @@ private:
|
||||
|
||||
RenderTexturePtr master_texture_;
|
||||
|
||||
QMap<rational, QByteArray> time_hash_map_;
|
||||
|
||||
private slots:
|
||||
void ThreadCallback();
|
||||
|
||||
|
||||
@@ -20,12 +20,16 @@
|
||||
|
||||
#include "rendererprocessthread.h"
|
||||
|
||||
RendererProcessThread::RendererProcessThread(QOpenGLContext *share_ctx,
|
||||
#include "renderer.h"
|
||||
|
||||
RendererProcessThread::RendererProcessThread(RendererProcessor* parent,
|
||||
QOpenGLContext *share_ctx,
|
||||
const int &width,
|
||||
const int &height,
|
||||
const olive::PixelFormat &format,
|
||||
const olive::RenderMode &mode) :
|
||||
RendererThreadBase(share_ctx, width, height, format, mode)
|
||||
RendererThreadBase(share_ctx, width, height, format, mode),
|
||||
parent_(parent)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -56,6 +60,16 @@ bool RendererProcessThread::Queue(const NodeDependency& dep, bool wait)
|
||||
return true;
|
||||
}
|
||||
|
||||
const QByteArray &RendererProcessThread::hash()
|
||||
{
|
||||
return hash_;
|
||||
}
|
||||
|
||||
RenderTexturePtr RendererProcessThread::texture()
|
||||
{
|
||||
return texture_;
|
||||
}
|
||||
|
||||
void RendererProcessThread::ProcessLoop()
|
||||
{
|
||||
while (!Cancelled()) {
|
||||
@@ -71,20 +85,27 @@ void RendererProcessThread::ProcessLoop()
|
||||
NodeOutput* output_to_process = path_.node();
|
||||
Node* node_to_process = output_to_process->parent();
|
||||
|
||||
QList<NodeDependency> deps = node_to_process->RunDependencies(output_to_process, path_.time());
|
||||
// Check hash
|
||||
QCryptographicHash hasher(QCryptographicHash::Sha1);
|
||||
node_to_process->Hash(&hasher, output_to_process, path_.time());
|
||||
hash_ = hasher.result();
|
||||
|
||||
// Ask for other threads to run these deps while we're here
|
||||
if (!deps.isEmpty()) {
|
||||
for (int i=1;i<deps.size();i++) {
|
||||
emit RequestSibling(deps.at(i));
|
||||
if (!parent_->HasHash(hash_)) {
|
||||
QList<NodeDependency> deps = node_to_process->RunDependencies(output_to_process, path_.time());
|
||||
|
||||
// Ask for other threads to run these deps while we're here
|
||||
if (!deps.isEmpty()) {
|
||||
for (int i=1;i<deps.size();i++) {
|
||||
emit RequestSibling(deps.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Get the requested value
|
||||
texture_ = output_to_process->get_value(path_.time()).value<RenderTexturePtr>();
|
||||
|
||||
render_instance()->context()->functions()->glFinish();
|
||||
}
|
||||
|
||||
// Get the requested value
|
||||
output_to_process->get_value(path_.time());
|
||||
|
||||
render_instance()->context()->functions()->glFinish();
|
||||
|
||||
emit FinishedPath();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,14 @@
|
||||
|
||||
#include "rendererthreadbase.h"
|
||||
|
||||
class RendererProcessor;
|
||||
|
||||
class RendererProcessThread : public RendererThreadBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RendererProcessThread(QOpenGLContext* share_ctx,
|
||||
RendererProcessThread(RendererProcessor* parent,
|
||||
QOpenGLContext* share_ctx,
|
||||
const int& width,
|
||||
const int& height,
|
||||
const olive::PixelFormat& format,
|
||||
@@ -35,6 +38,10 @@ public:
|
||||
|
||||
bool Queue(const NodeDependency &dep, bool wait);
|
||||
|
||||
const QByteArray& hash();
|
||||
|
||||
RenderTexturePtr texture();
|
||||
|
||||
protected:
|
||||
virtual void ProcessLoop() override;
|
||||
|
||||
@@ -44,10 +51,16 @@ signals:
|
||||
void FinishedPath();
|
||||
|
||||
private:
|
||||
RendererProcessor* parent_;
|
||||
|
||||
NodeDependency path_;
|
||||
|
||||
rational time_;
|
||||
|
||||
QByteArray hash_;
|
||||
|
||||
RenderTexturePtr texture_;
|
||||
|
||||
};
|
||||
|
||||
using RendererProcessThreadPtr = std::shared_ptr<RendererProcessThread>;
|
||||
|
||||
Reference in New Issue
Block a user