several adjustments to node caching system
This commit is contained in:
@@ -36,7 +36,8 @@ RendererProcessor::RendererProcessor() :
|
||||
width_(0),
|
||||
height_(0),
|
||||
divider_(1),
|
||||
caching_(false)
|
||||
caching_(false),
|
||||
last_requested_time_(-1)
|
||||
{
|
||||
texture_input_ = new NodeInput("tex_in");
|
||||
texture_input_->add_data_input(NodeInput::kTexture);
|
||||
@@ -78,6 +79,8 @@ void RendererProcessor::SetCacheName(const QString &s)
|
||||
QVariant RendererProcessor::Value(NodeOutput* output, const rational& time)
|
||||
{
|
||||
if (output == texture_output_) {
|
||||
last_requested_time_ = time;
|
||||
|
||||
if (!texture_input_->IsConnected()) {
|
||||
// Nothing is connected - nothing to show or render
|
||||
return 0;
|
||||
@@ -117,7 +120,7 @@ void RendererProcessor::Release()
|
||||
Stop();
|
||||
}
|
||||
|
||||
void RendererProcessor::InvalidateCache(const rational &start_range, const rational &end_range)
|
||||
void RendererProcessor::InvalidateCache(NodeInput* from, const rational &start_range, const rational &end_range)
|
||||
{
|
||||
qDebug() << "[RendererProcessor] Cache invalidated between"
|
||||
<< start_range.toDouble()
|
||||
@@ -133,12 +136,17 @@ void RendererProcessor::InvalidateCache(const rational &start_range, const ratio
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CacheNext();
|
||||
|
||||
Node::InvalidateCache(start_range, end_range);
|
||||
Node::InvalidateCache(from, start_range, end_range);
|
||||
}
|
||||
|
||||
void RendererProcessor::SetTimebase(const rational &timebase)
|
||||
@@ -216,6 +224,8 @@ void RendererProcessor::Start()
|
||||
// Create download thread
|
||||
download_threads_[i] = std::make_shared<RendererDownloadThread>(ctx, effective_width_, effective_height_, format_, mode_);
|
||||
download_threads_[i]->StartThread(QThread::LowPriority);
|
||||
|
||||
connect(download_threads_[i].get(), SIGNAL(Downloaded(const rational&)), this, SLOT(DownloadThreadFinished(const rational&)));
|
||||
}
|
||||
|
||||
last_download_thread_ = 0;
|
||||
@@ -314,13 +324,9 @@ void RendererProcessor::ThreadCallback()
|
||||
|
||||
RenderTexturePtr texture = texture_input_->get_value(cache_frame_).value<RenderTexturePtr>();
|
||||
|
||||
QString fn = CachePathName(cache_frame_);
|
||||
if (texture == nullptr) {
|
||||
if (QFileInfo::exists(fn)) {
|
||||
QFile(fn).remove();
|
||||
}
|
||||
} else {
|
||||
download_threads_[last_download_thread_%download_threads_.size()]->Queue(texture, fn);
|
||||
if (texture != nullptr) {
|
||||
QString fn = CachePathName(cache_frame_);
|
||||
download_threads_[last_download_thread_%download_threads_.size()]->Queue(texture, fn, cache_frame_);
|
||||
last_download_thread_++;
|
||||
}
|
||||
|
||||
@@ -338,6 +344,23 @@ 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()) {
|
||||
// Send invalidate cache signal to all nodes connected to the texture output
|
||||
QVector<NodeEdgePtr> edges = texture_output()->edges();
|
||||
|
||||
texture_output_->ClearCachedValue();
|
||||
|
||||
foreach (NodeEdgePtr edge, edges) {
|
||||
edge->input()->parent()->InvalidateCache(edge->input(),
|
||||
time,
|
||||
time);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RendererThreadBase* RendererProcessor::CurrentThread()
|
||||
{
|
||||
return dynamic_cast<RendererThreadBase*>(QThread::currentThread());
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
virtual void Release() override;
|
||||
|
||||
virtual void InvalidateCache(const rational &start_range, const rational &end_range) override;
|
||||
virtual void InvalidateCache(NodeInput *from, const rational &start_range, const rational &end_range) override;
|
||||
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
@@ -171,6 +171,8 @@ private:
|
||||
QVector<RendererDownloadThreadPtr> download_threads_;
|
||||
int last_download_thread_;
|
||||
|
||||
rational last_requested_time_;
|
||||
|
||||
RenderTexturePtr master_texture_;
|
||||
|
||||
private slots:
|
||||
@@ -178,6 +180,8 @@ private slots:
|
||||
|
||||
void ThreadRequestSibling(NodeDependency dep);
|
||||
|
||||
void DownloadThreadFinished(const rational &time);
|
||||
|
||||
};
|
||||
|
||||
#endif // RENDERER_H
|
||||
|
||||
@@ -16,12 +16,13 @@ RendererDownloadThread::RendererDownloadThread(QOpenGLContext *share_ctx,
|
||||
{
|
||||
}
|
||||
|
||||
void RendererDownloadThread::Queue(RenderTexturePtr texture, const QString& fn)
|
||||
void RendererDownloadThread::Queue(RenderTexturePtr texture, const QString& fn, const rational& time)
|
||||
{
|
||||
texture_queue_lock_.lock();
|
||||
|
||||
texture_queue_.append(texture);
|
||||
download_filenames_.append(fn);
|
||||
texture_times_.append(time);
|
||||
|
||||
wait_cond_.wakeAll();
|
||||
|
||||
@@ -37,6 +38,7 @@ void RendererDownloadThread::ProcessLoop()
|
||||
|
||||
RenderTexturePtr working_texture;
|
||||
QString working_filename;
|
||||
rational working_time;
|
||||
|
||||
int buffer_size = PixelService::GetBufferSize(render_instance()->format(),
|
||||
render_instance()->width(),
|
||||
@@ -62,6 +64,7 @@ void RendererDownloadThread::ProcessLoop()
|
||||
|
||||
working_texture = texture_queue_.takeFirst();
|
||||
working_filename = download_filenames_.takeFirst();
|
||||
working_time = texture_times_.takeFirst();
|
||||
|
||||
texture_queue_lock_.unlock();
|
||||
|
||||
@@ -101,7 +104,7 @@ void RendererDownloadThread::ProcessLoop()
|
||||
out->close();
|
||||
}
|
||||
|
||||
qDebug() << this << "saved" << working_filename;
|
||||
emit Downloaded(working_time);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,10 @@ public:
|
||||
const olive::PixelFormat& format,
|
||||
const olive::RenderMode& mode);
|
||||
|
||||
void Queue(RenderTexturePtr texture, const QString &fn);
|
||||
void Queue(RenderTexturePtr texture, const QString &fn, const rational &time);
|
||||
|
||||
signals:
|
||||
void Downloaded(const rational& time);
|
||||
|
||||
protected:
|
||||
virtual void ProcessLoop() override;
|
||||
@@ -25,6 +28,8 @@ private:
|
||||
|
||||
QVector<QString> download_filenames_;
|
||||
|
||||
QVector<rational> texture_times_;
|
||||
|
||||
QMutex texture_queue_lock_;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user