node: fixed issue with "taking" values from input tables

As opposed to simply leaving all values in the table, nodes can now "take"
values that they use to free up memory (e.g. "taking" input buffers if they're
used to produce an output buffer).

This is a fairly large change, expect regressions.
This commit is contained in:
itsmattkc
2020-04-16 23:12:05 +10:00
parent cc8699c0bc
commit 2f80be437a
30 changed files with 179 additions and 101 deletions
+4
View File
@@ -0,0 +1,4 @@
#ifndef TOHEX_H
#define TOHEX_H
#endif // TOHEX_H
+1
View File
@@ -390,6 +390,7 @@ void Core::DeclareTypesForQt()
qRegisterMetaType<OpenGLTexturePtr>(); qRegisterMetaType<OpenGLTexturePtr>();
qRegisterMetaType<OpenGLTextureCache::ReferencePtr>(); qRegisterMetaType<OpenGLTextureCache::ReferencePtr>();
qRegisterMetaType<NodeValueTable>(); qRegisterMetaType<NodeValueTable>();
qRegisterMetaType<NodeValueDatabase>();
qRegisterMetaType<FramePtr>(); qRegisterMetaType<FramePtr>();
qRegisterMetaType<SampleBufferPtr>(); qRegisterMetaType<SampleBufferPtr>();
qRegisterMetaType<AudioRenderingParams>(); qRegisterMetaType<AudioRenderingParams>();
+1 -1
View File
@@ -63,7 +63,7 @@ Node::Capabilities VolumeNode::GetCapabilities(const NodeValueDatabase &) const
return kSampleProcessor; return kSampleProcessor;
} }
NodeInput *VolumeNode::ProcessesSamplesFrom(const NodeValueDatabase &value) const NodeInput *VolumeNode::ProcessesSamplesFrom(const NodeValueDatabase &) const
{ {
return samples_input_; return samples_input_;
} }
+2 -3
View File
@@ -100,16 +100,15 @@ TimeRange ClipBlock::OutputTimeAdjustment(NodeInput *input, const TimeRange &inp
return Block::InputTimeAdjustment(input, input_time); return Block::InputTimeAdjustment(input, input_time);
} }
NodeValueTable ClipBlock::Value(const NodeValueDatabase &value) const NodeValueTable ClipBlock::Value(NodeValueDatabase &value) const
{ {
// We discard most values here except for the buffer we received // We discard most values here except for the buffer we received
NodeValueTable table;
NodeValue data = value[texture_input()].GetWithMeta(NodeParam::kBuffer); NodeValue data = value[texture_input()].GetWithMeta(NodeParam::kBuffer);
NodeValueTable table;
if (data.type() != NodeParam::kNone) { if (data.type() != NodeParam::kNone) {
table.Push(data); table.Push(data);
} }
return table; return table;
} }
+1 -1
View File
@@ -50,7 +50,7 @@ public:
virtual TimeRange OutputTimeAdjustment(NodeInput* input, const TimeRange& input_time) const override; virtual TimeRange OutputTimeAdjustment(NodeInput* input, const TimeRange& input_time) const override;
virtual NodeValueTable Value(const NodeValueDatabase& value) const override; virtual NodeValueTable Value(NodeValueDatabase& value) const override;
virtual void Retranslate() override; virtual void Retranslate() override;
+1 -1
View File
@@ -83,7 +83,7 @@ void TransformDistort::Retranslate()
anchor_input_->set_name(tr("Anchor Point")); anchor_input_->set_name(tr("Anchor Point"));
} }
NodeValueTable TransformDistort::Value(const NodeValueDatabase &value) const NodeValueTable TransformDistort::Value(NodeValueDatabase &value) const
{ {
QMatrix4x4 mat; QMatrix4x4 mat;
+1 -1
View File
@@ -40,7 +40,7 @@ public:
virtual void Retranslate() override; virtual void Retranslate() override;
virtual NodeValueTable Value(const NodeValueDatabase& value) const override; virtual NodeValueTable Value(NodeValueDatabase& value) const override;
private: private:
NodeInput* position_input_; NodeInput* position_input_;
+2 -1
View File
@@ -27,6 +27,7 @@
#include "common/bezier.h" #include "common/bezier.h"
#include "common/lerp.h" #include "common/lerp.h"
#include "common/tohex.h"
#include "common/xmlutils.h" #include "common/xmlutils.h"
#include "node.h" #include "node.h"
#include "output.h" #include "output.h"
@@ -306,7 +307,7 @@ QString NodeInput::ValueToString(const DataType& data_type, const QVariant &valu
} }
if (!value.isNull()) { if (!value.isNull()) {
qWarning() << "Failed to convert type" << QStringLiteral("%1").arg(data_type, 0, 16) << "to string"; qWarning() << "Failed to convert type" << ToHex(data_type) << "to string";
} }
/* fall through */ /* fall through */
+9 -2
View File
@@ -21,6 +21,7 @@
#include "media.h" #include "media.h"
#include "common/timecodefunctions.h" #include "common/timecodefunctions.h"
#include "common/tohex.h"
OLIVE_NAMESPACE_ENTER OLIVE_NAMESPACE_ENTER
@@ -54,9 +55,9 @@ void MediaInput::Retranslate()
footage_input_->set_name(tr("Footage")); footage_input_->set_name(tr("Footage"));
} }
NodeValueTable MediaInput::Value(const NodeValueDatabase &value) const NodeValueTable MediaInput::Value(NodeValueDatabase &value) const
{ {
NodeValueTable table = value.Merge(); NodeValueTable table;
if (connected_footage_) { if (connected_footage_) {
rational media_duration = Timecode::timestamp_to_time(connected_footage_->duration(), rational media_duration = Timecode::timestamp_to_time(connected_footage_->duration(),
@@ -65,6 +66,12 @@ NodeValueTable MediaInput::Value(const NodeValueDatabase &value) const
table.Push(NodeInput::kRational, QVariant::fromValue(media_duration), "length"); table.Push(NodeInput::kRational, QVariant::fromValue(media_duration), "length");
} }
// Push buffer to the top of the stack
NodeValue buffer = value[footage_input_].GetWithMeta(NodeParam::kSamples);
if (buffer.type() != NodeParam::kNone) {
table.Push(buffer);
}
return table; return table;
} }
+1 -1
View File
@@ -42,7 +42,7 @@ public:
virtual void Retranslate() override; virtual void Retranslate() override;
virtual NodeValueTable Value(const NodeValueDatabase& value) const override; virtual NodeValueTable Value(NodeValueDatabase& value) const override;
protected: protected:
NodeInput* footage_input_; NodeInput* footage_input_;
+1 -1
View File
@@ -51,7 +51,7 @@ QString TimeInput::Description() const
return tr("Generates the time (in seconds) at this frame"); return tr("Generates the time (in seconds) at this frame");
} }
NodeValueTable TimeInput::Value(const NodeValueDatabase &value) const NodeValueTable TimeInput::Value(NodeValueDatabase &value) const
{ {
NodeValueTable table = value.Merge(); NodeValueTable table = value.Merge();
+1 -1
View File
@@ -38,7 +38,7 @@ public:
virtual QString Category() const override; virtual QString Category() const override;
virtual QString Description() const override; virtual QString Description() const override;
virtual NodeValueTable Value(const NodeValueDatabase& value) const override; virtual NodeValueTable Value(NodeValueDatabase& value) const override;
}; };
+63 -43
View File
@@ -23,6 +23,7 @@
#include <QMatrix4x4> #include <QMatrix4x4>
#include <QVector2D> #include <QVector2D>
#include "common/tohex.h"
#include "render/color.h" #include "render/color.h"
OLIVE_NAMESPACE_ENTER OLIVE_NAMESPACE_ENTER
@@ -169,35 +170,47 @@ QString MathNode::ShaderFragmentCode(const NodeValueDatabase &input) const
operation); operation);
} }
NodeValue MathNode::InputValueFromTable(NodeInput *input, const NodeValueDatabase &db) const NodeValue MathNode::InputValueFromTable(NodeInput *input, NodeValueDatabase &db, bool take) const
{ {
if (input == param_a_in_ || input == param_b_in_) { if (input == param_a_in_ || input == param_b_in_) {
PairingCalculator calc(db[param_a_in_], db[param_b_in_]); PairingCalculator calc(db[param_a_in_], db[param_b_in_]);
if (input == param_a_in_) { NodeValue v = (input == param_a_in_)
return calc.GetMostLikelyValueA(); ? calc.GetMostLikelyValueA()
} else { : calc.GetMostLikelyValueB();
return calc.GetMostLikelyValueB();
if (take) {
db[input].Remove(v);
} }
return v;
} }
return Node::InputValueFromTable(input, db); return Node::InputValueFromTable(input, db, take);
} }
NodeValueTable MathNode::Value(const NodeValueDatabase &value) const NodeValueTable MathNode::Value(NodeValueDatabase &value) const
{ {
NodeValueTable output = value.Merge();
// Auto-detect what values to operate with // Auto-detect what values to operate with
// FIXME: Add manual override for this // FIXME: Add manual override for this
PairingCalculator calc(value[param_a_in_], value[param_b_in_]); PairingCalculator calc(value[param_a_in_], value[param_b_in_]);
if (!calc.FoundMostLikelyPairing()) { if (!calc.FoundMostLikelyPairing()
return output; || calc.GetMostLikelyPairing() == kPairSampleNumber
|| calc.GetMostLikelyPairing() == kPairTextureTexture
|| calc.GetMostLikelyPairing() == kPairTextureNumber
|| calc.GetMostLikelyPairing() == kPairTextureColor
|| calc.GetMostLikelyPairing() == kPairTextureMatrix) {
return value.Merge();
} }
NodeValue val_a = calc.GetMostLikelyValueA(); NodeValue val_a = calc.GetMostLikelyValueA();
value[param_a_in_].Remove(val_a);
NodeValue val_b = calc.GetMostLikelyValueB(); NodeValue val_b = calc.GetMostLikelyValueB();
value[param_b_in_].Remove(val_b);
NodeValueTable output = value.Merge();
switch (calc.GetMostLikelyPairing()) { switch (calc.GetMostLikelyPairing()) {
@@ -395,39 +408,44 @@ QVector<int> MathNode::PairingCalculator::GetPairLikelihood(const NodeValueTable
for (int i=0;i<table.Count();i++) { for (int i=0;i<table.Count();i++) {
NodeParam::DataType type = table.At(i).type(); NodeParam::DataType type = table.At(i).type();
int weight = i;
if (type & NodeParam::kVector) { if (type & NodeParam::kVector) {
likelihood.replace(kPairVecVec, i); likelihood.replace(kPairVecVec, weight);
likelihood.replace(kPairVecNumber, i); likelihood.replace(kPairVecNumber, weight);
likelihood.replace(kPairMatrixVec, i); likelihood.replace(kPairMatrixVec, weight);
} else if (type & NodeParam::kMatrix) { } else if (type & NodeParam::kMatrix) {
likelihood.replace(kPairMatrixMatrix, i); likelihood.replace(kPairMatrixMatrix, weight);
likelihood.replace(kPairMatrixVec, i); likelihood.replace(kPairMatrixVec, weight);
likelihood.replace(kPairTextureMatrix, i); likelihood.replace(kPairTextureMatrix, weight);
} else if (type & NodeParam::kColor) { } else if (type & NodeParam::kColor) {
likelihood.replace(kPairColorColor, i); likelihood.replace(kPairColorColor, weight);
likelihood.replace(kPairNumberColor, i); likelihood.replace(kPairNumberColor, weight);
likelihood.replace(kPairTextureColor, i); likelihood.replace(kPairTextureColor, weight);
} else if (type & NodeParam::kNumber) { } else if (type & NodeParam::kNumber) {
likelihood.replace(kPairNumberNumber, i); likelihood.replace(kPairNumberNumber, weight);
likelihood.replace(kPairVecNumber, i); likelihood.replace(kPairVecNumber, weight);
likelihood.replace(kPairNumberColor, i); likelihood.replace(kPairNumberColor, weight);
likelihood.replace(kPairTextureNumber, i); likelihood.replace(kPairTextureNumber, weight);
likelihood.replace(kPairSampleNumber, i); likelihood.replace(kPairSampleNumber, weight);
} else if (type & NodeParam::kSamples) { } else if (type & NodeParam::kSamples) {
likelihood.replace(kPairSampleSample, i); likelihood.replace(kPairSampleSample, weight);
likelihood.replace(kPairSampleNumber, i); likelihood.replace(kPairSampleNumber, weight);
} else if (type & NodeParam::kTexture) { } else if (type & NodeParam::kTexture) {
likelihood.replace(kPairTextureTexture, i); likelihood.replace(kPairTextureTexture, weight);
likelihood.replace(kPairTextureNumber, i); likelihood.replace(kPairTextureNumber, weight);
likelihood.replace(kPairTextureColor, i); likelihood.replace(kPairTextureColor, weight);
likelihood.replace(kPairTextureMatrix, i); likelihood.replace(kPairTextureMatrix, weight);
} }
} }
return likelihood; return likelihood;
} }
MathNode::Pairing MathNode::PairingCalculator::GetMostLikelyPairingInternal(const QVector<int> &a, const QVector<int> &b) MathNode::Pairing MathNode::PairingCalculator::GetMostLikelyPairingInternal(const QVector<int> &a,
const QVector<int> &b,
const int& weight_a,
const int& weight_b)
{ {
QVector<int> likelihoods(kPairCount); QVector<int> likelihoods(kPairCount);
@@ -435,15 +453,13 @@ MathNode::Pairing MathNode::PairingCalculator::GetMostLikelyPairingInternal(cons
if (a.at(i) == -1 || b.at(i) == -1) { if (a.at(i) == -1 || b.at(i) == -1) {
likelihoods.replace(i, -1); likelihoods.replace(i, -1);
} else { } else {
likelihoods.replace(i, a.at(i) + b.at(i)); likelihoods.replace(i, a.at(i) + weight_a + b.at(i) + weight_b);
} }
} }
Pairing pairing = kPairNone; Pairing pairing = kPairNone;
for (int i=0;i<likelihoods.size();i++) { for (int i=0;i<likelihoods.size();i++) {
//qDebug() << "Likelihood" << i << "is" << likelihoods.at(i);
if (likelihoods.at(i) > -1) { if (likelihoods.at(i) > -1) {
if (pairing == kPairNone if (pairing == kPairNone
|| likelihoods.at(i) > likelihoods.at(pairing)) { || likelihoods.at(i) > likelihoods.at(pairing)) {
@@ -495,18 +511,22 @@ float MathNode::RetrieveNumber(const NodeValue &val)
} }
} }
MathNode::PairingCalculator::PairingCalculator(const NodeValueTable &table_a, const NodeValueTable &table_b) MathNode::PairingCalculator::PairingCalculator(const NodeValueTable &table_a, const NodeValueTable &table_b) :
table_a_(table_a),
table_b_(table_b)
{ {
table_a_ = table_a;
table_b_ = table_b;
pair_likelihood_a_ = GetPairLikelihood(table_a_); pair_likelihood_a_ = GetPairLikelihood(table_a_);
pair_likelihood_b_ = GetPairLikelihood(table_b_); pair_likelihood_b_ = GetPairLikelihood(table_b_);
most_likely_pairing_ = GetMostLikelyPairingInternal(pair_likelihood_a_, pair_likelihood_b_);
most_likely_pairing_ = GetMostLikelyPairingInternal(pair_likelihood_a_,
pair_likelihood_b_,
qMax(0, table_b_.Count() - table_a_.Count()),
qMax(0, table_a_.Count() - table_b_.Count()));
} }
bool MathNode::PairingCalculator::FoundMostLikelyPairing() const bool MathNode::PairingCalculator::FoundMostLikelyPairing() const
{ {
return (most_likely_pairing_ >= 0 && most_likely_pairing_ < kPairCount); return (most_likely_pairing_ > kPairNone && most_likely_pairing_ < kPairCount);
} }
MathNode::Pairing MathNode::PairingCalculator::GetMostLikelyPairing() const MathNode::Pairing MathNode::PairingCalculator::GetMostLikelyPairing() const
@@ -514,17 +534,17 @@ MathNode::Pairing MathNode::PairingCalculator::GetMostLikelyPairing() const
return most_likely_pairing_; return most_likely_pairing_;
} }
NodeValue MathNode::PairingCalculator::GetMostLikelyValueA() const const NodeValue &MathNode::PairingCalculator::GetMostLikelyValueA() const
{ {
return GetMostLikelyValue(table_a_, pair_likelihood_a_); return GetMostLikelyValue(table_a_, pair_likelihood_a_);
} }
NodeValue MathNode::PairingCalculator::GetMostLikelyValueB() const const NodeValue &MathNode::PairingCalculator::GetMostLikelyValueB() const
{ {
return GetMostLikelyValue(table_b_, pair_likelihood_b_); return GetMostLikelyValue(table_b_, pair_likelihood_b_);
} }
NodeValue MathNode::PairingCalculator::GetMostLikelyValue(const NodeValueTable &table, const QVector<int> &likelihood) const const NodeValue& MathNode::PairingCalculator::GetMostLikelyValue(const NodeValueTable &table, const QVector<int> &likelihood) const
{ {
return table.At(likelihood.at(most_likely_pairing_)); return table.At(likelihood.at(most_likely_pairing_));
} }
+9 -9
View File
@@ -43,9 +43,9 @@ public:
virtual QString ShaderID(const NodeValueDatabase&) const override; virtual QString ShaderID(const NodeValueDatabase&) const override;
virtual QString ShaderFragmentCode(const NodeValueDatabase&) const override; virtual QString ShaderFragmentCode(const NodeValueDatabase&) const override;
virtual NodeValue InputValueFromTable(NodeInput* input, const NodeValueDatabase &db) const override; virtual NodeValue InputValueFromTable(NodeInput* input, NodeValueDatabase &db, bool take) const override;
virtual NodeValueTable Value(const NodeValueDatabase& value) const override; virtual NodeValueTable Value(NodeValueDatabase &value) const override;
virtual NodeInput* ProcessesSamplesFrom(const NodeValueDatabase &value) const override; virtual NodeInput* ProcessesSamplesFrom(const NodeValueDatabase &value) const override;
virtual void ProcessSamples(const NodeValueDatabase &values, const AudioRenderingParams& params, const SampleBufferPtr input, SampleBufferPtr output, int index) const override; virtual void ProcessSamples(const NodeValueDatabase &values, const AudioRenderingParams& params, const SampleBufferPtr input, SampleBufferPtr output, int index) const override;
@@ -87,26 +87,26 @@ private:
class PairingCalculator { class PairingCalculator {
public: public:
PairingCalculator(const NodeValueTable& table_a, const NodeValueTable& table_b); PairingCalculator(const NodeValueTable &table_a, const NodeValueTable &table_b);
bool FoundMostLikelyPairing() const; bool FoundMostLikelyPairing() const;
Pairing GetMostLikelyPairing() const; Pairing GetMostLikelyPairing() const;
NodeValue GetMostLikelyValueA() const; const NodeValue& GetMostLikelyValueA() const;
NodeValue GetMostLikelyValueB() const; const NodeValue& GetMostLikelyValueB() const;
private: private:
static Pairing GetMostLikelyPairingInternal(const QVector<int> &a, const QVector<int> &b); static Pairing GetMostLikelyPairingInternal(const QVector<int> &a, const QVector<int> &b, const int &weight_a, const int &weight_b);
static QVector<int> GetPairLikelihood(const NodeValueTable& table); static QVector<int> GetPairLikelihood(const NodeValueTable& table);
NodeValue GetMostLikelyValue(const NodeValueTable& table, const QVector<int>& likelihood) const; const NodeValue &GetMostLikelyValue(const NodeValueTable& table, const QVector<int>& likelihood) const;
Pairing most_likely_pairing_; Pairing most_likely_pairing_;
NodeValueTable table_a_; const NodeValueTable& table_a_;
NodeValueTable table_b_; const NodeValueTable& table_b_;
QVector<int> pair_likelihood_a_; QVector<int> pair_likelihood_a_;
+1 -1
View File
@@ -77,7 +77,7 @@ void TrigonometryNode::Retranslate()
method_in_->set_name(tr("Method")); method_in_->set_name(tr("Method"));
} }
NodeValueTable TrigonometryNode::Value(const NodeValueDatabase &value) const NodeValueTable TrigonometryNode::Value(NodeValueDatabase &value) const
{ {
float x = value[x_in_].Take(NodeParam::kFloat).toFloat(); float x = value[x_in_].Take(NodeParam::kFloat).toFloat();
+1 -1
View File
@@ -39,7 +39,7 @@ public:
virtual void Retranslate() override; virtual void Retranslate() override;
virtual NodeValueTable Value(const NodeValueDatabase& value) const override; virtual NodeValueTable Value(NodeValueDatabase &value) const override;
private: private:
enum Operation { enum Operation {
+7 -3
View File
@@ -148,7 +148,7 @@ void Node::AddParameter(NodeParam *param)
} }
} }
NodeValueTable Node::Value(const NodeValueDatabase &value) const NodeValueTable Node::Value(NodeValueDatabase &value) const
{ {
return value.Merge(); return value.Merge();
} }
@@ -616,7 +616,7 @@ NodeOutput *Node::output() const
return output_; return output_;
} }
NodeValue Node::InputValueFromTable(NodeInput *input, const NodeValueDatabase &db) const NodeValue Node::InputValueFromTable(NodeInput *input, NodeValueDatabase &db, bool take) const
{ {
NodeParam::DataType find_data_type = input->data_type(); NodeParam::DataType find_data_type = input->data_type();
@@ -626,7 +626,11 @@ NodeValue Node::InputValueFromTable(NodeInput *input, const NodeValueDatabase &d
} }
// Try to get a value from it // Try to get a value from it
return db[input].GetWithMeta(find_data_type); if (take) {
return db[input].TakeWithMeta(find_data_type);
} else {
return db[input].GetWithMeta(find_data_type);
}
} }
const QPointF &Node::GetPosition() const QPointF &Node::GetPosition()
+2 -2
View File
@@ -332,7 +332,7 @@ public:
* corresponding output if it's connected to one. If your node doesn't directly deal with time, the default behavior * corresponding output if it's connected to one. If your node doesn't directly deal with time, the default behavior
* of the NodeParam objects will handle everything related to it automatically. * of the NodeParam objects will handle everything related to it automatically.
*/ */
virtual NodeValueTable Value(const NodeValueDatabase& value) const; virtual NodeValueTable Value(NodeValueDatabase& value) const;
/** /**
* @brief Return whether a parameter with ID `id` has already been added to this Node * @brief Return whether a parameter with ID `id` has already been added to this Node
@@ -341,7 +341,7 @@ public:
NodeOutput* output() const; NodeOutput* output() const;
virtual NodeValue InputValueFromTable(NodeInput* input, const NodeValueDatabase& db) const; virtual NodeValue InputValueFromTable(NodeInput* input, NodeValueDatabase &db, bool take) const;
const QPointF& GetPosition(); const QPointF& GetPosition();
+1 -1
View File
@@ -72,7 +72,7 @@ NodeValueTable NodeTraverser::ProcessNode(const NodeDependency& dep)
// By this point, the node should have all the inputs it needs to render correctly // By this point, the node should have all the inputs it needs to render correctly
NodeValueTable table = node->Value(database); NodeValueTable table = node->Value(database);
ProcessNodeEvent(node, dep.range(), database, &table); ProcessNodeEvent(node, dep.range(), database, table);
return table; return table;
} }
+1 -1
View File
@@ -46,7 +46,7 @@ protected:
virtual void InputProcessingEvent(NodeInput*, const TimeRange&, NodeValueTable*){} virtual void InputProcessingEvent(NodeInput*, const TimeRange&, NodeValueTable*){}
virtual void ProcessNodeEvent(const Node*, const TimeRange&, const NodeValueDatabase&, NodeValueTable*){} virtual void ProcessNodeEvent(const Node*, const TimeRange&, NodeValueDatabase&, NodeValueTable&){}
}; };
+44 -11
View File
@@ -22,14 +22,24 @@
OLIVE_NAMESPACE_ENTER OLIVE_NAMESPACE_ENTER
NodeValueTable NodeValueDatabase::operator[](const QString &input_id) const NodeValueTable& NodeValueDatabase::operator[](const QString &input_id)
{ {
return tables_.value(input_id); return tables_[input_id];
} }
NodeValueTable NodeValueDatabase::operator[](const NodeInput *input) const NodeValueTable& NodeValueDatabase::operator[](const NodeInput *input)
{ {
return tables_.value(input->id()); return tables_[input->id()];
}
const NodeValueTable NodeValueDatabase::operator[](const QString &input_id) const
{
return tables_[input_id];
}
const NodeValueTable NodeValueDatabase::operator[](const NodeInput *input) const
{
return tables_[input->id()];
} }
void NodeValueDatabase::Insert(const QString &key, const NodeValueTable &value) void NodeValueDatabase::Insert(const QString &key, const NodeValueTable &value)
@@ -64,6 +74,11 @@ const QString &NodeValue::tag() const
return tag_; return tag_;
} }
bool NodeValue::operator==(const NodeValue &rhs) const
{
return type_ == rhs.type_ && tag_ == rhs.tag_ && data_ == rhs.data_;
}
const QVariant &NodeValue::data() const const QVariant &NodeValue::data() const
{ {
return data_; return data_;
@@ -71,9 +86,7 @@ const QVariant &NodeValue::data() const
QVariant NodeValueTable::Get(const NodeParam::DataType &type, const QString &tag) const QVariant NodeValueTable::Get(const NodeParam::DataType &type, const QString &tag) const
{ {
NodeValue v = GetWithMeta(type, tag); return GetWithMeta(type, tag).data();
return v.data();
} }
NodeValue NodeValueTable::GetWithMeta(const NodeParam::DataType &type, const QString &tag) const NodeValue NodeValueTable::GetWithMeta(const NodeParam::DataType &type, const QString &tag) const
@@ -88,16 +101,19 @@ NodeValue NodeValueTable::GetWithMeta(const NodeParam::DataType &type, const QSt
} }
QVariant NodeValueTable::Take(const NodeParam::DataType &type, const QString &tag) QVariant NodeValueTable::Take(const NodeParam::DataType &type, const QString &tag)
{
return TakeWithMeta(type, tag).data();
}
NodeValue NodeValueTable::TakeWithMeta(const NodeParam::DataType &type, const QString &tag)
{ {
int value_index = GetInternal(type, tag); int value_index = GetInternal(type, tag);
if (value_index >= 0) { if (value_index >= 0) {
QVariant val = values_.at(value_index).data(); return values_.takeAt(value_index);
values_.removeAt(value_index);
return val;
} }
return QVariant(); return NodeValue(NodeParam::kNone, QVariant());
} }
void NodeValueTable::Push(const NodeValue &value) void NodeValueTable::Push(const NodeValue &value)
@@ -125,6 +141,11 @@ const NodeValue &NodeValueTable::At(int index) const
return values_.at(index); return values_.at(index);
} }
NodeValue NodeValueTable::TakeAt(int index)
{
return values_.takeAt(index);
}
int NodeValueTable::Count() const int NodeValueTable::Count() const
{ {
return values_.size(); return values_.size();
@@ -143,6 +164,18 @@ bool NodeValueTable::Has(const NodeParam::DataType &type) const
return false; return false;
} }
void NodeValueTable::Remove(const NodeValue &v)
{
for (int i=values_.size() - 1;i>=0;i--) {
const NodeValue& compare = values_.at(i);
if (compare == v) {
values_.removeAt(i);
return;
}
}
}
bool NodeValueTable::isEmpty() const bool NodeValueTable::isEmpty() const
{ {
return values_.isEmpty(); return values_.isEmpty();
+11 -2
View File
@@ -37,6 +37,8 @@ public:
const QVariant& data() const; const QVariant& data() const;
const QString& tag() const; const QString& tag() const;
bool operator==(const NodeValue& rhs) const;
private: private:
NodeParam::DataType type_; NodeParam::DataType type_;
QVariant data_; QVariant data_;
@@ -52,13 +54,16 @@ public:
QVariant Get(const NodeParam::DataType& type, const QString& tag = QString()) const; QVariant Get(const NodeParam::DataType& type, const QString& tag = QString()) const;
NodeValue GetWithMeta(const NodeParam::DataType& type, const QString& tag = QString()) const; NodeValue GetWithMeta(const NodeParam::DataType& type, const QString& tag = QString()) const;
QVariant Take(const NodeParam::DataType& type, const QString& tag = QString()); QVariant Take(const NodeParam::DataType& type, const QString& tag = QString());
NodeValue TakeWithMeta(const NodeParam::DataType& type, const QString& tag = QString());
void Push(const NodeValue& value); void Push(const NodeValue& value);
void Push(const NodeParam::DataType& type, const QVariant& data, const QString& tag = QString()); void Push(const NodeParam::DataType& type, const QVariant& data, const QString& tag = QString());
void Prepend(const NodeValue& value); void Prepend(const NodeValue& value);
void Prepend(const NodeParam::DataType& type, const QVariant& data, const QString& tag = QString()); void Prepend(const NodeParam::DataType& type, const QVariant& data, const QString& tag = QString());
const NodeValue& At(int index) const; const NodeValue& At(int index) const;
NodeValue TakeAt(int index);
int Count() const; int Count() const;
bool Has(const NodeParam::DataType& type) const; bool Has(const NodeParam::DataType& type) const;
void Remove(const NodeValue& v);
bool isEmpty() const; bool isEmpty() const;
@@ -76,8 +81,11 @@ class NodeValueDatabase
public: public:
NodeValueDatabase() = default; NodeValueDatabase() = default;
NodeValueTable operator[](const QString& input_id) const; NodeValueTable& operator[](const QString& input_id);
NodeValueTable operator[](const NodeInput* input) const; NodeValueTable& operator[](const NodeInput* input);
const NodeValueTable operator[](const QString& input_id) const;
const NodeValueTable operator[](const NodeInput* input) const;
void Insert(const QString& key, const NodeValueTable &value); void Insert(const QString& key, const NodeValueTable &value);
void Insert(const NodeInput* key, const NodeValueTable& value); void Insert(const NodeInput* key, const NodeValueTable& value);
@@ -92,5 +100,6 @@ private:
OLIVE_NAMESPACE_EXIT OLIVE_NAMESPACE_EXIT
Q_DECLARE_METATYPE(OLIVE_NAMESPACE::NodeValueTable) Q_DECLARE_METATYPE(OLIVE_NAMESPACE::NodeValueTable)
Q_DECLARE_METATYPE(OLIVE_NAMESPACE::NodeValueDatabase)
#endif // VALUE_H #endif // VALUE_H
+2 -2
View File
@@ -44,7 +44,7 @@ void AudioWorker::FrameToValue(DecoderPtr decoder, StreamPtr stream, const TimeR
} }
} }
void AudioWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params_in, NodeValueTable *output_params) void AudioWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, NodeValueDatabase &input_params_in, NodeValueTable &output_params)
{ {
// Check if node processes samples // Check if node processes samples
if (!(node->GetCapabilities(input_params_in) & Node::kSampleProcessor)) { if (!(node->GetCapabilities(input_params_in) & Node::kSampleProcessor)) {
@@ -101,7 +101,7 @@ void AudioWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, c
i); i);
} }
output_params->Push(NodeParam::kSamples, QVariant::fromValue(output_buffer)); output_params.Push(NodeParam::kSamples, QVariant::fromValue(output_buffer));
} }
OLIVE_NAMESPACE_EXIT OLIVE_NAMESPACE_EXIT
+1 -1
View File
@@ -33,7 +33,7 @@ public:
protected: protected:
virtual void FrameToValue(DecoderPtr decoder, StreamPtr stream, const TimeRange &range, NodeValueTable* table) override; virtual void FrameToValue(DecoderPtr decoder, StreamPtr stream, const TimeRange &range, NodeValueTable* table) override;
virtual void RunNodeAccelerated(const Node *node, const TimeRange& range, const NodeValueDatabase& input_params, NodeValueTable* output_params) override; virtual void RunNodeAccelerated(const Node *node, const TimeRange& range, NodeValueDatabase& input_params, NodeValueTable& output_params) override;
private: private:
+3 -3
View File
@@ -200,7 +200,7 @@ void OpenGLProxy::Close()
ctx_ = nullptr; ctx_ = nullptr;
} }
void OpenGLProxy::RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable *output_params) void OpenGLProxy::RunNodeAccelerated(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable &output_params)
{ {
if (!(node->GetCapabilities(input_params) & Node::kShader)) { if (!(node->GetCapabilities(input_params) & Node::kShader)) {
return; return;
@@ -257,7 +257,7 @@ void OpenGLProxy::RunNodeAccelerated(const Node *node, const TimeRange &range, c
NodeInput* input = static_cast<NodeInput*>(param); NodeInput* input = static_cast<NodeInput*>(param);
// Get value from database at this input // Get value from database at this input
NodeValue meta_value = node->InputValueFromTable(input, input_params); NodeValue meta_value = node->InputValueFromTable(input, input_params, true);
const QVariant& value = meta_value.data(); const QVariant& value = meta_value.data();
NodeParam::DataType data_type; NodeParam::DataType data_type;
@@ -423,7 +423,7 @@ void OpenGLProxy::RunNodeAccelerated(const Node *node, const TimeRange &range, c
shader->release(); shader->release();
output_params->Push(NodeParam::kTexture, QVariant::fromValue(output_tex)); output_params.Push(NodeParam::kTexture, QVariant::fromValue(output_tex));
} }
void OpenGLProxy::TextureToBuffer(const QVariant &tex_in, void *buffer) void OpenGLProxy::TextureToBuffer(const QVariant &tex_in, void *buffer)
+1 -1
View File
@@ -65,7 +65,7 @@ public:
void FrameToValue(FramePtr frame, StreamPtr stream, NodeValueTable* table); void FrameToValue(FramePtr frame, StreamPtr stream, NodeValueTable* table);
void RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable* output_params); void RunNodeAccelerated(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable& output_params);
void TextureToBuffer(const QVariant& texture, void *buffer); void TextureToBuffer(const QVariant& texture, void *buffer);
+1 -1
View File
@@ -45,7 +45,7 @@ void OpenGLWorker::FrameToValue(DecoderPtr decoder, StreamPtr stream, const Time
} }
} }
void OpenGLWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable *output_params) void OpenGLWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable &output_params)
{ {
emit RequestRunNodeAccelerated(node, range, input_params, output_params); emit RequestRunNodeAccelerated(node, range, input_params, output_params);
} }
+2 -2
View File
@@ -40,14 +40,14 @@ public:
signals: signals:
void RequestFrameToValue(FramePtr frame, StreamPtr stream, NodeValueTable* table); void RequestFrameToValue(FramePtr frame, StreamPtr stream, NodeValueTable* table);
void RequestRunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable* output_params); void RequestRunNodeAccelerated(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable& output_params);
void RequestTextureToBuffer(const QVariant& texture, void *buffer); void RequestTextureToBuffer(const QVariant& texture, void *buffer);
protected: protected:
virtual void FrameToValue(DecoderPtr decoder, StreamPtr stream, const TimeRange &range, NodeValueTable* table) override; virtual void FrameToValue(DecoderPtr decoder, StreamPtr stream, const TimeRange &range, NodeValueTable* table) override;
virtual void RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable* output_params) override; virtual void RunNodeAccelerated(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable& output_params) override;
virtual void TextureToBuffer(const QVariant& texture, void *buffer) override; virtual void TextureToBuffer(const QVariant& texture, void *buffer) override;
+2 -2
View File
@@ -68,7 +68,7 @@ NodeValueTable RenderWorker::RenderInternal(const NodeDependency &path, const qi
return ProcessNode(path); return ProcessNode(path);
} }
void RenderWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable* output_params) void RenderWorker::RunNodeAccelerated(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable& output_params)
{ {
Q_UNUSED(node) Q_UNUSED(node)
Q_UNUSED(range) Q_UNUSED(range)
@@ -136,7 +136,7 @@ void RenderWorker::InputProcessingEvent(NodeInput* input, const TimeRange& input
} }
} }
void RenderWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable* output_params) void RenderWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable &output_params)
{ {
// Check if we have a shader for this output // Check if we have a shader for this output
RunNodeAccelerated(node, range, input_params, output_params); RunNodeAccelerated(node, range, input_params, output_params);
+2 -2
View File
@@ -57,7 +57,7 @@ protected:
virtual NodeValueTable RenderInternal(const NodeDependency& CurrentPath, const qint64& job_time); virtual NodeValueTable RenderInternal(const NodeDependency& CurrentPath, const qint64& job_time);
virtual void RunNodeAccelerated(const Node *node, const TimeRange& range, const NodeValueDatabase &input_params, NodeValueTable* output_params); virtual void RunNodeAccelerated(const Node *node, const TimeRange& range, NodeValueDatabase &input_params, NodeValueTable &output_params);
virtual void FrameToValue(DecoderPtr decoder, StreamPtr stream, const TimeRange &range, NodeValueTable* table) = 0; virtual void FrameToValue(DecoderPtr decoder, StreamPtr stream, const TimeRange &range, NodeValueTable* table) = 0;
@@ -65,7 +65,7 @@ protected:
virtual void InputProcessingEvent(NodeInput *input, const TimeRange &input_time, NodeValueTable* table) override; virtual void InputProcessingEvent(NodeInput *input, const TimeRange &input_time, NodeValueTable* table) override;
virtual void ProcessNodeEvent(const Node *node, const TimeRange &range, const NodeValueDatabase &input_params, NodeValueTable* output_params) override; virtual void ProcessNodeEvent(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable &output_params) override;
StreamPtr ResolveStreamFromInput(NodeInput* input); StreamPtr ResolveStreamFromInput(NodeInput* input);