renderer: use shared backend when caching
I think there was an earlier commit with a similar name but turns out I'd only done foundational work in that commit and never actually properly set it up. Of course once I did, there were several issues that needed fixing to make it work correctly, but now it works as expected. Heavily optimizes larger projects by allowing cache jobs to only copy what has changed.
This commit is contained in:
@@ -113,19 +113,20 @@ void RenderBackend::ClearVideoQueue()
|
||||
render_queue_.clear();
|
||||
}
|
||||
|
||||
QFuture<QVector<QByteArray> > RenderBackend::Hash(const QVector<rational> ×)
|
||||
RenderTicketPtr RenderBackend::Hash(const QVector<rational> ×)
|
||||
{
|
||||
return QtConcurrent::run(&pool_, [this](const QVector<rational> &t){
|
||||
QVector<QByteArray> hashes(t.size());
|
||||
if (!viewer_node_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (int i=0;i<hashes.size();i++) {
|
||||
hashes[i] = HashNode(copied_viewer_node_->texture_input()->get_connected_node(),
|
||||
video_params_,
|
||||
t.at(i));
|
||||
}
|
||||
RenderTicketPtr ticket = std::make_shared<RenderTicket>(RenderTicket::kTypeHash,
|
||||
QVariant::fromValue(times));
|
||||
|
||||
return hashes;
|
||||
}, times);
|
||||
render_queue_.push_back(ticket);
|
||||
|
||||
QMetaObject::invokeMethod(this, "RunNextJob", Qt::QueuedConnection);
|
||||
|
||||
return ticket;
|
||||
}
|
||||
|
||||
RenderTicketPtr RenderBackend::RenderFrame(const rational &time)
|
||||
@@ -135,7 +136,7 @@ RenderTicketPtr RenderBackend::RenderFrame(const rational &time)
|
||||
}
|
||||
|
||||
RenderTicketPtr ticket = std::make_shared<RenderTicket>(RenderTicket::kTypeVideo,
|
||||
TimeRange(time, time));
|
||||
QVariant::fromValue(time));
|
||||
|
||||
render_queue_.push_back(ticket);
|
||||
|
||||
@@ -151,7 +152,7 @@ RenderTicketPtr RenderBackend::RenderAudio(const TimeRange &r)
|
||||
}
|
||||
|
||||
RenderTicketPtr ticket = std::make_shared<RenderTicket>(RenderTicket::kTypeAudio,
|
||||
r);
|
||||
QVariant::fromValue(r));
|
||||
|
||||
render_queue_.push_back(ticket);
|
||||
|
||||
@@ -215,6 +216,11 @@ void RenderBackend::NodeGraphChanged(NodeInput *source)
|
||||
for (int i=0; i<graph_update_queue_.size(); i++) {
|
||||
NodeInput* queued_input = graph_update_queue_.at(i);
|
||||
|
||||
// If this input is already queued, nothing to be done
|
||||
if (source == queued_input) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this dependency graph is already queued
|
||||
if (source->parentNode()->OutputsTo(queued_input, true)) {
|
||||
// In which case, no further copy is necessary
|
||||
@@ -300,7 +306,7 @@ void RenderBackend::RunNextJob()
|
||||
|
||||
worker->SetVideoParams(video_params_);
|
||||
worker->SetAudioParams(audio_params_);
|
||||
worker->SetVideoDownloadMatrix(video_download_matrix_);
|
||||
worker->SetVideoDownloadMatrix(video_dwnload_matrix_);
|
||||
worker->SetRenderMode(render_mode_);
|
||||
if (preview_job_time_) {
|
||||
worker->EnablePreviewGeneration(viewer_node_->audio_playback_cache(), preview_job_time_);
|
||||
@@ -311,13 +317,21 @@ void RenderBackend::RunNextJob()
|
||||
render_queue_.pop_front();
|
||||
|
||||
switch (ticket->GetType()) {
|
||||
case RenderTicket::kTypeHash:
|
||||
QtConcurrent::run(&pool_,
|
||||
worker,
|
||||
&RenderWorker::Hash,
|
||||
ticket,
|
||||
copied_viewer_node_,
|
||||
ticket->GetTime().value<QVector<rational> >());
|
||||
break;
|
||||
case RenderTicket::kTypeVideo:
|
||||
QtConcurrent::run(&pool_,
|
||||
worker,
|
||||
&RenderWorker::RenderFrame,
|
||||
ticket,
|
||||
copied_viewer_node_,
|
||||
ticket->GetTime().in());
|
||||
ticket->GetTime().value<rational>());
|
||||
break;
|
||||
case RenderTicket::kTypeAudio:
|
||||
QtConcurrent::run(&pool_,
|
||||
@@ -325,7 +339,7 @@ void RenderBackend::RunNextJob()
|
||||
&RenderWorker::RenderAudio,
|
||||
ticket,
|
||||
copied_viewer_node_,
|
||||
ticket->GetTime());
|
||||
ticket->GetTime().value<TimeRange>());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -337,27 +351,25 @@ void RenderBackend::RunNextJob()
|
||||
}
|
||||
}
|
||||
|
||||
//#define PRINT_UPDATE_QUEUE_INFO
|
||||
void RenderBackend::ProcessUpdateQueue()
|
||||
{
|
||||
#ifdef PRINT_UPDATE_QUEUE_INFO
|
||||
qint64 t = QDateTime::currentMSecsSinceEpoch();
|
||||
qDebug() << "Processing update queue of" << graph_update_queue_.size() << "elements:";
|
||||
#endif
|
||||
|
||||
while (!graph_update_queue_.isEmpty()) {
|
||||
CopyNodeInputValue(graph_update_queue_.takeFirst());
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray RenderBackend::HashNode(const Node *n, const VideoParams ¶ms, const rational &time)
|
||||
{
|
||||
QCryptographicHash hasher(QCryptographicHash::Sha1);
|
||||
|
||||
// Embed video parameters into this hash
|
||||
hasher.addData(reinterpret_cast<const char*>(¶ms.effective_width()), sizeof(int));
|
||||
hasher.addData(reinterpret_cast<const char*>(¶ms.effective_height()), sizeof(int));
|
||||
hasher.addData(reinterpret_cast<const char*>(¶ms.format()), sizeof(PixelFormat::Format));
|
||||
|
||||
if (n) {
|
||||
n->Hash(hasher, time);
|
||||
NodeInput* i = graph_update_queue_.takeFirst();
|
||||
#ifdef PRINT_UPDATE_QUEUE_INFO
|
||||
qDebug() << " " << i->parentNode()->id() << i->id();
|
||||
#endif
|
||||
CopyNodeInputValue(i);
|
||||
}
|
||||
|
||||
return hasher.result();
|
||||
#ifdef PRINT_UPDATE_QUEUE_INFO
|
||||
qDebug() << "Update queue took:" << (QDateTime::currentMSecsSinceEpoch() - t);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RenderBackend::WorkerFinished()
|
||||
@@ -386,6 +398,7 @@ void RenderBackend::CopyNodeInputValue(NodeInput *input)
|
||||
// Copy the standard/keyframe values between these two inputs
|
||||
NodeInput::CopyValues(input,
|
||||
our_copy,
|
||||
false,
|
||||
false);
|
||||
|
||||
// Handle connections
|
||||
|
||||
@@ -69,12 +69,10 @@ public:
|
||||
|
||||
void ProcessUpdateQueue();
|
||||
|
||||
static QByteArray HashNode(const Node* n, const VideoParams& params, const rational& time);
|
||||
|
||||
/**
|
||||
* @brief Asynchronously generate a hash at a given time
|
||||
*/
|
||||
QFuture<QVector<QByteArray> > Hash(const QVector<rational> ×);
|
||||
RenderTicketPtr Hash(const QVector<rational> ×);
|
||||
|
||||
/**
|
||||
* @brief Asynchronously generate a frame at a given time
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
RenderTicket::RenderTicket(Type type, const TimeRange &time) :
|
||||
RenderTicket::RenderTicket(Type type, const QVariant &time) :
|
||||
finished_(false),
|
||||
cancelled_(false),
|
||||
time_(time),
|
||||
|
||||
@@ -35,13 +35,14 @@ class RenderTicket : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Type {
|
||||
kTypeHash,
|
||||
kTypeVideo,
|
||||
kTypeAudio
|
||||
};
|
||||
|
||||
RenderTicket(Type type, const TimeRange& time);
|
||||
RenderTicket(Type type, const QVariant& time);
|
||||
|
||||
const TimeRange& GetTime() const
|
||||
const QVariant& GetTime() const
|
||||
{
|
||||
return time_;
|
||||
}
|
||||
@@ -82,7 +83,7 @@ private:
|
||||
|
||||
QWaitCondition wait_;
|
||||
|
||||
TimeRange time_;
|
||||
QVariant time_;
|
||||
|
||||
Type type_;
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
#include "renderworker.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QThread>
|
||||
|
||||
#include "audio/audiovisualwaveform.h"
|
||||
#include "common/functiontimer.h"
|
||||
#include "config/config.h"
|
||||
#include "node/block/clip/clip.h"
|
||||
#include "task/conform/conform.h"
|
||||
#include "renderbackend.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -40,6 +40,37 @@ RenderWorker::RenderWorker(RenderBackend* parent) :
|
||||
{
|
||||
}
|
||||
|
||||
void RenderWorker::Hash(RenderTicketPtr ticket, ViewerOutput *viewer, const QVector<rational> ×)
|
||||
{
|
||||
QVector<QByteArray> hashes(times.size());
|
||||
|
||||
for (int i=0;i<hashes.size();i++) {
|
||||
hashes[i] = HashNode(viewer->texture_input()->get_connected_node(),
|
||||
video_params_,
|
||||
times.at(i));
|
||||
}
|
||||
|
||||
ticket->Finish(QVariant::fromValue(hashes));
|
||||
|
||||
emit FinishedJob();
|
||||
}
|
||||
|
||||
QByteArray RenderWorker::HashNode(const Node *n, const VideoParams ¶ms, const rational &time)
|
||||
{
|
||||
QCryptographicHash hasher(QCryptographicHash::Sha1);
|
||||
|
||||
// Embed video parameters into this hash
|
||||
hasher.addData(reinterpret_cast<const char*>(¶ms.effective_width()), sizeof(int));
|
||||
hasher.addData(reinterpret_cast<const char*>(¶ms.effective_height()), sizeof(int));
|
||||
hasher.addData(reinterpret_cast<const char*>(¶ms.format()), sizeof(PixelFormat::Format));
|
||||
|
||||
if (n) {
|
||||
n->Hash(hasher, time);
|
||||
}
|
||||
|
||||
return hasher.result();
|
||||
}
|
||||
|
||||
void RenderWorker::RenderFrame(RenderTicketPtr ticket, ViewerOutput* viewer, const rational &time)
|
||||
{
|
||||
NodeValueTable table = ProcessInput(viewer->texture_input(),
|
||||
@@ -237,7 +268,7 @@ QVariant RenderWorker::ProcessFrameGeneration(const Node* node, const GenerateJo
|
||||
QVariant RenderWorker::GetCachedFrame(const Node* node, const rational& time)
|
||||
{
|
||||
if (node->id() == QStringLiteral("org.olivevideoeditor.Olive.videoinput")) {
|
||||
QByteArray hash = RenderBackend::HashNode(node, video_params(), time);
|
||||
QByteArray hash = HashNode(node, video_params(), time);
|
||||
|
||||
QString fn = FrameHashCache::CachePathName(hash);
|
||||
|
||||
|
||||
@@ -84,6 +84,8 @@ public:
|
||||
preview_job_time_ = job_time;
|
||||
}
|
||||
|
||||
void Hash(RenderTicketPtr ticket, ViewerOutput* viewer, const QVector<rational>& times);
|
||||
|
||||
/**
|
||||
* @brief Render the frame at this time
|
||||
*
|
||||
@@ -146,6 +148,8 @@ signals:
|
||||
private:
|
||||
DecoderPtr ResolveDecoderFromInput(StreamPtr stream);
|
||||
|
||||
static QByteArray HashNode(const Node* n, const VideoParams& params, const rational& time);
|
||||
|
||||
RenderBackend* parent_;
|
||||
|
||||
VideoParams video_params_;
|
||||
|
||||
Reference in New Issue
Block a user