code: conform traverser buffer creation

Helps ensure parity between traverser and render processor
This commit is contained in:
itsmattkc
2022-05-03 17:10:03 -07:00
parent 0e490b94e5
commit 6512774b86
9 changed files with 155 additions and 243 deletions
+10 -20
View File
@@ -58,7 +58,7 @@ QByteArray HashTraverser::GetHash(const Node *node, const Node::ValueHint &hint,
return hash_.result();
}
TexturePtr HashTraverser::ProcessVideoFootage(const FootageJob &stream, const rational &input_time)
void HashTraverser::ProcessVideoFootage(TexturePtr destination, const FootageJob &stream, const rational &input_time)
{
Hash(FileFunctions::GetUniqueFileIdentifier(stream.filename()));
Hash(stream.loop_mode());
@@ -69,24 +69,20 @@ TexturePtr HashTraverser::ProcessVideoFootage(const FootageJob &stream, const ra
Hash(stream.video_params().video_type() == VideoParams::kVideoTypeStill ? 0 : input_time);
Hash(stream.video_params().video_type());
TexturePtr texture = super::ProcessVideoFootage(stream, input_time);
texture_ids_.insert(texture.get(), hash_.result());
return texture;
texture_ids_.insert(destination.get(), hash_.result());
}
SampleBufferPtr HashTraverser::ProcessAudioFootage(const FootageJob &stream, const TimeRange &input_time)
void HashTraverser::ProcessAudioFootage(SampleBufferPtr destination, const FootageJob &stream, const TimeRange &input_time)
{
Hash(FileFunctions::GetUniqueFileIdentifier(stream.filename()));
Hash(stream.loop_mode());
Hash(stream.audio_params().stream_index());
Hash(input_time);
SampleBufferPtr buf = super::ProcessAudioFootage(stream, input_time);
texture_ids_.insert(buf.get(), hash_.result());
return buf;
texture_ids_.insert(destination.get(), hash_.result());
}
TexturePtr HashTraverser::ProcessShader(const Node *node, const TimeRange &range, const ShaderJob &job)
void HashTraverser::ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob &job)
{
HashGenerateJob(node, &job);
@@ -99,25 +95,19 @@ TexturePtr HashTraverser::ProcessShader(const Node *node, const TimeRange &range
Hash(it.value());
}
TexturePtr texture = super::ProcessShader(node, range, job);
texture_ids_.insert(texture.get(), hash_.result());
return texture;
texture_ids_.insert(destination.get(), hash_.result());
}
SampleBufferPtr HashTraverser::ProcessSamples(const Node *node, const TimeRange &range, const SampleJob &job)
void HashTraverser::ProcessSamples(SampleBufferPtr destination, const Node *node, const TimeRange &range, const SampleJob &job)
{
SampleBufferPtr buf = super::ProcessSamples(node, range, job);
texture_ids_.insert(buf.get(), hash_.result());
return buf;
texture_ids_.insert(destination.get(), hash_.result());
}
TexturePtr HashTraverser::ProcessFrameGeneration(const Node *node, const GenerateJob &job)
void HashTraverser::ProcessFrameGeneration(TexturePtr destination, const Node *node, const GenerateJob &job)
{
HashGenerateJob(node, &job);
TexturePtr texture = super::ProcessFrameGeneration(node, job);
texture_ids_.insert(texture.get(), hash_.result());
return texture;
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::HashGenerateJob(const Node *node, const GenerateJob *job)
+5 -5
View File
@@ -33,15 +33,15 @@ public:
QByteArray GetHash(const Node *node, const Node::ValueHint &hint, const VideoParams &params, const TimeRange &range);
protected:
virtual TexturePtr ProcessVideoFootage(const FootageJob &stream, const rational &input_time) override;
virtual void ProcessVideoFootage(TexturePtr destination, const FootageJob &stream, const rational &input_time) override;
virtual SampleBufferPtr ProcessAudioFootage(const FootageJob &stream, const TimeRange &input_time) override;
virtual void ProcessAudioFootage(SampleBufferPtr destination, const FootageJob &stream, const TimeRange &input_time) override;
virtual TexturePtr ProcessShader(const Node *node, const TimeRange &range, const ShaderJob& job) override;
virtual void ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob& job) override;
virtual SampleBufferPtr ProcessSamples(const Node *node, const TimeRange &range, const SampleJob &job) override;
virtual void ProcessSamples(SampleBufferPtr destination, const Node *node, const TimeRange &range, const SampleJob &job) override;
virtual TexturePtr ProcessFrameGeneration(const Node *node, const GenerateJob& job) override;
virtual void ProcessFrameGeneration(TexturePtr destination, const Node *node, const GenerateJob& job) override;
private:
void HashGenerateJob(const Node *node, const GenerateJob *job);
+42 -88
View File
@@ -287,67 +287,6 @@ NodeValueTable NodeTraverser::GenerateBlockTable(const Track *track, const TimeR
return table;
}
TexturePtr NodeTraverser::ProcessVideoFootage(const FootageJob &stream, const rational &input_time)
{
Q_UNUSED(input_time)
// Create dummy texture with footage params
return CreateDummyTexture(stream.video_params());
}
SampleBufferPtr NodeTraverser::ProcessAudioFootage(const FootageJob& stream, const TimeRange &input_time)
{
Q_UNUSED(stream)
Q_UNUSED(input_time)
return SampleBuffer::Create();
}
TexturePtr NodeTraverser::ProcessShader(const Node *node, const TimeRange &range, const ShaderJob &job)
{
Q_UNUSED(node)
Q_UNUSED(range)
Q_UNUSED(job)
// Create dummy texture with sequence params
VideoParams tex_params = video_params_;
tex_params.set_channel_count(GetChannelCountFromJob(job));
return CreateDummyTexture(tex_params);
}
SampleBufferPtr NodeTraverser::ProcessSamples(const Node *node, const TimeRange &range, const SampleJob &job)
{
Q_UNUSED(node)
Q_UNUSED(range)
Q_UNUSED(job)
return SampleBuffer::Create();
}
TexturePtr NodeTraverser::ProcessFrameGeneration(const Node *node, const GenerateJob &job)
{
Q_UNUSED(node)
Q_UNUSED(job)
// Create dummy texture with sequence params
VideoParams tex_params = video_params_;
tex_params.set_channel_count(GetChannelCountFromJob(job));
return CreateDummyTexture(tex_params);
}
void NodeTraverser::SaveCachedTexture(const QByteArray &hash, TexturePtr texture)
{
Q_UNUSED(hash)
Q_UNUSED(texture)
}
TexturePtr NodeTraverser::GetCachedTexture(const QByteArray& hash)
{
Q_UNUSED(hash)
return nullptr;
}
QVector2D NodeTraverser::GenerateResolution() const
{
return QVector2D(video_params_.square_pixel_width(), video_params_.height());
@@ -357,20 +296,6 @@ void NodeTraverser::PreProcessRow(const TimeRange &range, NodeValueRow &row)
{
QByteArray cached_node_hash;
// Convert footage to image/sample buffers
/*if (CanCacheFrames() && node->GetCacheTextures()) {
// This node is set to cache the result, see if we can retrieved a previously cached version
cached_node_hash = RenderManager::Hash(node, hint, GetCacheVideoParams(), range.in());
TexturePtr cached_frame = GetCachedTexture(cached_node_hash);
if (cached_frame) {
output_params.Push(NodeValue::kTexture, QVariant::fromValue(cached_frame), node);
// No more to do here
got_cached_frame = true;
}
}*/
// Resolve any jobs
for (auto it=row.begin(); it!=row.end(); it++) {
// Jobs will almost always be submitted with one of these types
@@ -382,45 +307,74 @@ void NodeTraverser::PreProcessRow(const TimeRange &range, NodeValueRow &row)
if (v.canConvert<ShaderJob>()) {
ShaderJob job = v.value<ShaderJob>();
PreProcessRow(range, job.GetValues());
val.set_data(QVariant::fromValue(ProcessShader(val.source(), range, job)));
VideoParams tex_params = GetCacheVideoParams();
tex_params.set_channel_count(GetChannelCountFromJob(job));
TexturePtr tex = CreateTexture(tex_params);
ProcessShader(tex, val.source(), range, job);
val.set_data(QVariant::fromValue(tex));
} else if (v.canConvert<GenerateJob>()) {
GenerateJob job = v.value<GenerateJob>();
PreProcessRow(range, job.GetValues());
val.set_data(QVariant::fromValue(ProcessFrameGeneration(val.source(), job)));
VideoParams tex_params = GetCacheVideoParams();
tex_params.set_channel_count(GetChannelCountFromJob(job));
if (job.GetRequestedFormat() != VideoParams::kFormatInvalid) {
tex_params.set_format(job.GetRequestedFormat());
}
TexturePtr tex = CreateTexture(tex_params);
ProcessFrameGeneration(tex, val.source(), job);
val.set_data(QVariant::fromValue(tex));
} else if (v.canConvert<FootageJob>()) {
FootageJob job = v.value<FootageJob>();
if (job.type() == Track::kVideo) {
rational footage_time = Footage::AdjustTimeByLoopMode(range.in(), job.loop_mode(), job.length(), job.video_params().video_type(), job.video_params().frame_rate_as_time_base());
TexturePtr tex;
if (footage_time.isNaN()) {
// Push dummy texture
val.set_data(QVariant::fromValue(CreateDummyTexture(job.video_params())));
tex = CreateDummyTexture(job.video_params());
} else {
val.set_data(QVariant::fromValue(ProcessVideoFootage(job, footage_time)));
VideoParams managed_params = job.video_params();
managed_params.set_format(GetCacheVideoParams().format());
tex = CreateTexture(job.video_params());
ProcessVideoFootage(tex, job, footage_time);
}
val.set_data(QVariant::fromValue(tex));
} else if (job.type() == Track::kAudio) {
val.set_data(QVariant::fromValue(ProcessAudioFootage(job, range)));
SampleBufferPtr buffer = CreateSampleBuffer(GetCacheAudioParams(), range.length());
ProcessAudioFootage(buffer, job, range);
val.set_data(QVariant::fromValue(buffer));
}
} else if (v.canConvert<SampleJob>()) {
val.set_data(QVariant::fromValue(ProcessSamples(val.source(), range, v.value<SampleJob>())));
SampleJob job = v.value<SampleJob>();
SampleBufferPtr output_buffer = CreateSampleBuffer(job.samples()->audio_params(), job.samples()->sample_count());
ProcessSamples(output_buffer, val.source(), range, job);
val.set_data(QVariant::fromValue(output_buffer));
}
}
}
/*if (CanCacheFrames() && node->GetCacheTextures() && !got_cached_frame) {
// Save cached texture
SaveCachedTexture(cached_node_hash, output_params.Get(NodeValue::kTexture).value<TexturePtr>());
}*/
}
TexturePtr NodeTraverser::CreateDummyTexture(const VideoParams &p)
+31 -7
View File
@@ -65,6 +65,16 @@ public:
video_params_ = params;
}
const AudioParams& GetCacheAudioParams() const
{
return audio_params_;
}
void SetCacheAudioParams(const AudioParams& params)
{
audio_params_ = params;
}
static int GetChannelCountFromJob(const GenerateJob& job);
protected:
@@ -72,19 +82,31 @@ protected:
virtual NodeValueTable GenerateBlockTable(const Track *track, const TimeRange& range);
virtual TexturePtr ProcessVideoFootage(const FootageJob &stream, const rational &input_time);
virtual void ProcessVideoFootage(TexturePtr destination, const FootageJob &stream, const rational &input_time){}
virtual SampleBufferPtr ProcessAudioFootage(const FootageJob &stream, const TimeRange &input_time);
virtual void ProcessAudioFootage(SampleBufferPtr destination, const FootageJob &stream, const TimeRange &input_time){}
virtual TexturePtr ProcessShader(const Node *node, const TimeRange &range, const ShaderJob& job);
virtual void ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob& job){}
virtual SampleBufferPtr ProcessSamples(const Node *node, const TimeRange &range, const SampleJob &job);
virtual void ProcessSamples(SampleBufferPtr destination, const Node *node, const TimeRange &range, const SampleJob &job){}
virtual TexturePtr ProcessFrameGeneration(const Node *node, const GenerateJob& job);
virtual void ProcessFrameGeneration(TexturePtr destination, const Node *node, const GenerateJob& job){}
virtual TexturePtr GetCachedTexture(const QByteArray& hash);
virtual TexturePtr CreateTexture(const VideoParams &p)
{
return CreateDummyTexture(p);
}
virtual void SaveCachedTexture(const QByteArray& hash, TexturePtr texture);
virtual SampleBufferPtr CreateSampleBuffer(const AudioParams &params, int sample_count)
{
// Return dummy by default
return SampleBuffer::Create();
}
SampleBufferPtr CreateSampleBuffer(const AudioParams &params, const rational &length)
{
return CreateSampleBuffer(params, params.time_to_samples(length));
}
virtual bool CanCacheFrames()
{
@@ -115,6 +137,8 @@ private:
VideoParams video_params_;
AudioParams audio_params_;
const QAtomicInt *cancel_;
};