remove hashtraverser

This commit is contained in:
itsmattkc
2022-05-09 18:22:32 -07:00
parent 0f99d8a662
commit 0538c01f45
15 changed files with 42 additions and 542 deletions
-2
View File
@@ -38,8 +38,6 @@ set(OLIVE_SOURCES
node/globals.h
node/graph.cpp
node/graph.h
node/hashtraverser.cpp
node/hashtraverser.h
node/inputdragger.cpp
node/inputdragger.h
node/inputimmediate.cpp
-158
View File
@@ -1,158 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "hashtraverser.h"
#include <QUuid>
#include "common/filefunctions.h"
namespace olive {
#define super NodeTraverser
HashTraverser::HashTraverser() :
hash_(QCryptographicHash::Sha1) // Appears to be the fastest hashing algorithm
{
}
QByteArray HashTraverser::GetHash(const Node *node, const Node::ValueHint &hint, const VideoParams &params, const TimeRange &range)
{
// Reset hash
hash_.reset();
texture_ids_.clear();
// Set params throughout traverser
SetCacheVideoParams(params);
// Embed video parameters into this hash
Hash(params.effective_width());
Hash(params.effective_height());
Hash(params.format());
Hash(params.interlacing());
//Hash(reference);
// Our overrides will generate a hash from this
NodeValueTable table = GenerateTable(node, hint, range);
NodeValue final_value = GenerateRowValueElement(hint, NodeValue::kTexture, &table);
HashNodeValue(final_value);
// Return the hash
return hash_.result();
}
void HashTraverser::ProcessVideoFootage(TexturePtr destination, const FootageJob &stream, const rational &input_time)
{
Hash(FileFunctions::GetUniqueFileIdentifier(stream.filename()));
Hash(stream.loop_mode());
Hash(stream.video_params().stream_index());
Hash(stream.video_params().colorspace());
Hash(stream.video_params().premultiplied_alpha());
Hash(GetCacheVideoParams().divider());
Hash(stream.video_params().video_type() == VideoParams::kVideoTypeStill ? 0 : input_time);
Hash(stream.video_params().video_type());
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::ProcessAudioFootage(SampleBuffer &destination, const FootageJob &stream, const TimeRange &input_time)
{
}
void HashTraverser::ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob &job)
{
HashGenerateJob(node, &job);
Hash(job.GetShaderID());
Hash(job.GetIterativeInput());
Hash(job.GetIterationCount());
for (auto it=job.GetInterpolationMap().cbegin(); it!=job.GetInterpolationMap().cend(); it++) {
Hash(it.key());
Hash(it.value());
}
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::ProcessColorTransform(TexturePtr destination, const Node *node, const ColorTransformJob &job)
{
Hash(job.GetColorProcessor()->id());
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::ProcessSamples(SampleBuffer &destination, const Node *node, const TimeRange &range, const SampleJob &job)
{
}
void HashTraverser::ProcessFrameGeneration(TexturePtr destination, const Node *node, const GenerateJob &job)
{
HashGenerateJob(node, &job);
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::HashGenerateJob(const Node *node, const GenerateJob *job)
{
Hash(node->id());
Hash(job->GetAlphaChannelRequired());
for (auto it=job->GetValues().cbegin(); it!=job->GetValues().cend(); it++) {
Hash(it.key());
HashNodeValue(it.value());
}
}
void HashTraverser::Hash(const QByteArray &array)
{
hash_.addData(array);
}
void HashTraverser::Hash(const QString &string)
{
hash_.addData(string.toUtf8());
}
void HashTraverser::HashNodeValue(const NodeValue &value)
{
NodeValue::Type value_type = value.type();
if (value_type == NodeValue::kSamples || value_type == NodeValue::kTexture) {
QByteArray id_for_buffer;
if (value_type == NodeValue::kTexture) {
TexturePtr texture = value.toTexture();
id_for_buffer = texture_ids_.value(texture.get());
}
if (!id_for_buffer.isEmpty()) {
Hash(id_for_buffer);
}
} else {
Hash(NodeValue::ValueToBytes(value));
}
}
template<typename T>
void HashTraverser::Hash(T value)
{
hash_.addData(reinterpret_cast<const char*>(&value), sizeof(value));
}
}
-70
View File
@@ -1,70 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef HASHTRAVERSER_H
#define HASHTRAVERSER_H
#include "traverser.h"
namespace olive {
class HashTraverser : public NodeTraverser
{
public:
HashTraverser();
QByteArray GetHash(const Node *node, const Node::ValueHint &hint, const VideoParams &params, const TimeRange &range);
protected:
virtual void ProcessVideoFootage(TexturePtr destination, const FootageJob &stream, const rational &input_time) override;
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 ProcessColorTransform(TexturePtr destination, const Node *node, const ColorTransformJob& job) override;
virtual void ProcessSamples(SampleBuffer &destination, const Node *node, const TimeRange &range, const SampleJob &job) override;
virtual void ProcessFrameGeneration(TexturePtr destination, const Node *node, const GenerateJob& job) override;
private:
void HashGenerateJob(const Node *node, const GenerateJob *job);
void HashFootageJob();
template <typename T>
void Hash(T value);
void Hash(const QByteArray &array);
void Hash(const QString &string);
void HashNodeValue(const NodeValue &value);
QCryptographicHash hash_;
QHash<void*, QByteArray> texture_ids_;
};
}
#endif // HASHTRAVERSER_H
-48
View File
@@ -92,54 +92,6 @@ QString NodeValue::ValueToString(Type data_type, const QVariant &value, bool val
}
}
template<typename T>
QByteArray ValueToBytesInternal(const QVariant &v)
{
QByteArray bytes;
int size_of_type = sizeof(T);
bytes.resize(size_of_type);
T raw_val = v.value<T>();
memcpy(bytes.data(), &raw_val, static_cast<size_t>(size_of_type));
return bytes;
}
QByteArray NodeValue::ValueToBytes(NodeValue::Type type, const QVariant &value)
{
switch (type) {
case kInt: return ValueToBytesInternal<int64_t>(value);
case kFloat: return ValueToBytesInternal<double>(value);
case kColor: return ValueToBytesInternal<Color>(value);
case kText: return value.toString().toUtf8();
case kBoolean: return ValueToBytesInternal<bool>(value);
case kFont: return value.toString().toUtf8();
case kFile: return value.toString().toUtf8();
case kMatrix: return ValueToBytesInternal<QMatrix4x4>(value);
case kRational: return ValueToBytesInternal<rational>(value);
case kVec2: return ValueToBytesInternal<QVector2D>(value);
case kVec3: return ValueToBytesInternal<QVector3D>(value);
case kVec4: return ValueToBytesInternal<QVector4D>(value);
case kCombo: return ValueToBytesInternal<int>(value);
case kBezier: return ValueToBytesInternal<Bezier>(value);
case kVideoParams:
return value.value<VideoParams>().toBytes();
case kAudioParams:
return value.value<AudioParams>().toBytes();
// These types have no persistent input
case kNone:
case kTexture:
case kSamples:
case kDataTypeCount:
break;
}
return QByteArray();
}
QVector<QVariant> NodeValue::split_normal_value_into_track_values(Type type, const QVariant &value)
{
QVector<QVariant> vals(get_number_of_keyframe_tracks(type));
-9
View File
@@ -257,15 +257,6 @@ public:
static QVariant StringToValue(Type data_type, const QString &string, bool value_is_a_key_track);
/**
* @brief Convert a value from a NodeParam into bytes
*/
static QByteArray ValueToBytes(Type type, const QVariant& value);
static QByteArray ValueToBytes(const NodeValue &value)
{
return ValueToBytes(value.type(), value.data_);
}
static QVector<QVariant> split_normal_value_into_track_values(Type type, const QVariant &value);
static QVariant combine_track_values_into_normal_value(Type type, const QVector<QVariant>& split);