From b19730b1f5aabf75a2e827b6ce0aaa7301686943 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 23 Sep 2022 02:55:18 -0700 Subject: [PATCH] nodes: store time with accelerated jobs Fixes #2031 --- app/node/audio/pan/pan.cpp | 4 +--- app/node/audio/volume/volume.cpp | 4 +--- app/node/math/math/mathbase.cpp | 2 +- app/node/project/footage/footage.cpp | 2 +- app/node/traverser.cpp | 22 +++++++++++----------- app/node/traverser.h | 6 +++--- app/render/job/footagejob.h | 7 ++++++- app/render/job/samplejob.h | 11 +++++++++-- app/render/renderprocessor.cpp | 6 +++--- app/render/renderprocessor.h | 2 +- 10 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/node/audio/pan/pan.cpp b/app/node/audio/pan/pan.cpp index 77e194506..434480dd9 100644 --- a/app/node/audio/pan/pan.cpp +++ b/app/node/audio/pan/pan.cpp @@ -64,8 +64,6 @@ QString PanNode::Description() const void PanNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const { - Q_UNUSED(globals) - // Create a sample job SampleBuffer samples = value[kSamplesInput].toSamples(); if (samples.is_allocated()) { @@ -85,7 +83,7 @@ void PanNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeV table->Push(NodeValue(NodeValue::kSamples, samples, this)); } else { // Requires job - table->Push(NodeValue::kSamples, SampleJob(kSamplesInput, value), this); + table->Push(NodeValue::kSamples, SampleJob(globals.time(), kSamplesInput, value), this); } } else { // Pass right through diff --git a/app/node/audio/volume/volume.cpp b/app/node/audio/volume/volume.cpp index 81a2306a7..7fe0a888a 100644 --- a/app/node/audio/volume/volume.cpp +++ b/app/node/audio/volume/volume.cpp @@ -63,8 +63,6 @@ QString VolumeNode::Description() const void VolumeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const { - Q_UNUSED(globals) - // Create a sample job SampleBuffer buffer = value[kSamplesInput].toSamples(); @@ -80,7 +78,7 @@ void VolumeNode::Value(const NodeValueRow &value, const NodeGlobals &globals, No table->Push(NodeValue::kSamples, QVariant::fromValue(buffer), this); } else { // Requires job - SampleJob job(kSamplesInput, value); + SampleJob job(globals.time(), kSamplesInput, value); job.Insert(kVolumeInput, value); table->Push(NodeValue::kSamples, QVariant::fromValue(job), this); } diff --git a/app/node/math/math/mathbase.cpp b/app/node/math/math/mathbase.cpp index 14045b054..7f3c12440 100644 --- a/app/node/math/math/mathbase.cpp +++ b/app/node/math/math/mathbase.cpp @@ -410,7 +410,7 @@ void MathNodeBase::ValueInternal(Operation operation, Pairing pairing, const QSt output->Push(NodeValue::kSamples, QVariant::fromValue(buffer), this); } else { - SampleJob job(val_a.type() == NodeValue::kSamples ? val_a : val_b); + SampleJob job(globals.time(), val_a.type() == NodeValue::kSamples ? val_a : val_b); job.Insert(number_param, NodeValue(NodeValue::kFloat, number, this)); output->Push(NodeValue::kSamples, QVariant::fromValue(job), this); } diff --git a/app/node/project/footage/footage.cpp b/app/node/project/footage/footage.cpp index 21b837704..cbc600779 100644 --- a/app/node/project/footage/footage.cpp +++ b/app/node/project/footage/footage.cpp @@ -265,7 +265,7 @@ void Footage::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeV // Push each stream as a footage job for (int i=0; i()) { @@ -374,7 +374,7 @@ void NodeTraverser::ResolveJobs(NodeValue &val, const TimeRange &range) ShaderJob job = val.value(); - PreProcessRow(range, job.GetValues()); + PreProcessRow(job.GetValues()); VideoParams tex_params = GetCacheVideoParams(); tex_params.set_channel_count(GetChannelCountFromJob(job)); @@ -389,7 +389,7 @@ void NodeTraverser::ResolveJobs(NodeValue &val, const TimeRange &range) TexturePtr tex = CreateTexture(tex_params); - ProcessShader(tex, val.source(), range, job); + ProcessShader(tex, val.source(), job); val.set_value(tex); @@ -407,7 +407,7 @@ void NodeTraverser::ResolveJobs(NodeValue &val, const TimeRange &range) TexturePtr tex = CreateTexture(upload_params); - PreProcessRow(range, job.GetValues()); + PreProcessRow(job.GetValues()); ProcessFrameGeneration(tex, val.source(), job); if (!job.GetColorspace().isEmpty()) { @@ -440,7 +440,7 @@ void NodeTraverser::ResolveJobs(NodeValue &val, const TimeRange &range) if (job.type() == Track::kVideo) { - rational footage_time = Footage::AdjustTimeByLoopMode(range.in(), loop_mode_, job.length(), job.video_params().video_type(), job.video_params().frame_rate_as_time_base()); + rational footage_time = Footage::AdjustTimeByLoopMode(job.time().in(), loop_mode_, job.length(), job.video_params().video_type(), job.video_params().frame_rate_as_time_base()); TexturePtr tex; @@ -473,8 +473,8 @@ void NodeTraverser::ResolveJobs(NodeValue &val, const TimeRange &range) } else if (job.type() == Track::kAudio) { - SampleBuffer buffer = CreateSampleBuffer(GetCacheAudioParams(), range.length()); - ProcessAudioFootage(buffer, job, range); + SampleBuffer buffer = CreateSampleBuffer(GetCacheAudioParams(), job.time().length()); + ProcessAudioFootage(buffer, job, job.time()); val.set_value(buffer); } @@ -483,7 +483,7 @@ void NodeTraverser::ResolveJobs(NodeValue &val, const TimeRange &range) SampleJob job = val.value(); SampleBuffer output_buffer = CreateSampleBuffer(job.samples().audio_params(), job.samples().sample_count()); - ProcessSamples(output_buffer, val.source(), range, job); + ProcessSamples(output_buffer, val.source(), job.time(), job); val.set_value(QVariant::fromValue(output_buffer)); } @@ -491,7 +491,7 @@ void NodeTraverser::ResolveJobs(NodeValue &val, const TimeRange &range) } } -void NodeTraverser::PreProcessRow(const TimeRange &range, NodeValueRow &row) +void NodeTraverser::PreProcessRow(NodeValueRow &row) { QByteArray cached_node_hash; @@ -500,7 +500,7 @@ void NodeTraverser::PreProcessRow(const TimeRange &range, NodeValueRow &row) // Jobs will almost always be submitted with one of these types NodeValue &val = it.value(); - ResolveJobs(val, range); + ResolveJobs(val); } } diff --git a/app/node/traverser.h b/app/node/traverser.h index bde1733ae..308ab675c 100644 --- a/app/node/traverser.h +++ b/app/node/traverser.h @@ -93,7 +93,7 @@ protected: virtual void ProcessAudioFootage(SampleBuffer &destination, const FootageJob &stream, const TimeRange &input_time){} - virtual void ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob& job){} + virtual void ProcessShader(TexturePtr destination, const Node *node, const ShaderJob& job){} virtual void ProcessColorTransform(TexturePtr destination, const Node *node, const ColorTransformJob& job){} @@ -140,7 +140,7 @@ protected: CancelAtom *GetCancelPointer() const { return cancel_; } void SetCancelPointer(CancelAtom *cancel) { cancel_ = cancel; } - void ResolveJobs(NodeValue &value, const TimeRange &range); + void ResolveJobs(NodeValue &value); Block *GetCurrentBlock() const { @@ -150,7 +150,7 @@ protected: Decoder::LoopMode loop_mode() const { return loop_mode_; } private: - void PreProcessRow(const TimeRange &range, NodeValueRow &row); + void PreProcessRow(NodeValueRow &row); TexturePtr CreateDummyTexture(const VideoParams &p); diff --git a/app/render/job/footagejob.h b/app/render/job/footagejob.h index 319be8a38..3684fa999 100644 --- a/app/render/job/footagejob.h +++ b/app/render/job/footagejob.h @@ -33,7 +33,8 @@ public: { } - FootageJob(const QString& decoder, const QString& filename, Track::Type type, const rational& length) : + FootageJob(const TimeRange &time, const QString& decoder, const QString& filename, Track::Type type, const rational& length) : + time_(time), decoder_(decoder), filename_(filename), type_(type), @@ -96,7 +97,11 @@ public: length_ = length; } + const TimeRange &time() const { return time_; } + private: + TimeRange time_; + QString decoder_; QString filename_; diff --git a/app/render/job/samplejob.h b/app/render/job/samplejob.h index 15fd71dc9..03bc00e6e 100644 --- a/app/render/job/samplejob.h +++ b/app/render/job/samplejob.h @@ -23,6 +23,7 @@ #include "acceleratedjob.h" #include "codec/samplebuffer.h" +#include "common/timerange.h" namespace olive { @@ -32,14 +33,16 @@ public: { } - SampleJob(const NodeValue& value) + SampleJob(const TimeRange &time, const NodeValue& value) { samples_ = value.toSamples(); + time_ = time; } - SampleJob(const QString& from, const NodeValueRow& row) + SampleJob(const TimeRange &time, const QString& from, const NodeValueRow& row) { samples_ = row[from].toSamples(); + time_ = time; } const SampleBuffer &samples() const @@ -52,9 +55,13 @@ public: return samples_.is_allocated(); } + const TimeRange &time() const { return time_; } + private: SampleBuffer samples_; + TimeRange time_; + }; } diff --git a/app/render/renderprocessor.cpp b/app/render/renderprocessor.cpp index 426b0a9ed..1c6f49fe6 100644 --- a/app/render/renderprocessor.cpp +++ b/app/render/renderprocessor.cpp @@ -54,7 +54,7 @@ TexturePtr RenderProcessor::GenerateTexture(const rational &time, const rational NodeValue tex_val = table.Get(NodeValue::kTexture); - ResolveJobs(tex_val, range); + ResolveJobs(tex_val); return tex_val.toTexture(); } @@ -226,7 +226,7 @@ void RenderProcessor::Run() NodeValue sample_val = table.Get(NodeValue::kSamples); - ResolveJobs(sample_val, time); + ResolveJobs(sample_val); SampleBuffer samples = sample_val.toSamples(); if (samples.is_allocated()) { @@ -522,7 +522,7 @@ void RenderProcessor::ProcessAudioFootage(SampleBuffer &destination, const Foota } } -void RenderProcessor::ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob &job) +void RenderProcessor::ProcessShader(TexturePtr destination, const Node *node, const ShaderJob &job) { if (!render_ctx_) { return; diff --git a/app/render/renderprocessor.h b/app/render/renderprocessor.h index a537ccf89..6738a605c 100644 --- a/app/render/renderprocessor.h +++ b/app/render/renderprocessor.h @@ -48,7 +48,7 @@ protected: virtual void ProcessAudioFootage(SampleBuffer &destination, const FootageJob &stream, const TimeRange &input_time) override; - virtual void ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob& job) override; + virtual void ProcessShader(TexturePtr destination, const Node *node, const ShaderJob& job) override; virtual void ProcessSamples(SampleBuffer &destination, const Node *node, const TimeRange &range, const SampleJob &job) override;