began node hashing for improved cache

This commit is contained in:
itsmattkc
2019-09-02 12:06:24 +10:00
parent f2972651af
commit b563b9e783
7 changed files with 106 additions and 24 deletions
+44 -18
View File
@@ -97,6 +97,18 @@ void MediaInput::SetFootage(Footage *f)
footage_input_->set_value(PtrToValue(f));
}
void MediaInput::Hash(QCryptographicHash *hash, const rational &time)
{
Node::Hash(hash, time);
// Use frame value from Decoder
if (SetupDecoder()) {
hash->addData(QString::number(decoder_->GetTimestampFromTime(time)).toUtf8());
// FIXME: Add OCIO data
// FIXME: Add alpha association value
}
}
QVariant MediaInput::Value(NodeOutput *output, const rational &time)
{
// FIXME: Hardcoded value
@@ -111,27 +123,11 @@ QVariant MediaInput::Value(NodeOutput *output, const rational &time)
return 0;
}
// Get currently selected Footage
Footage* footage = ValueToPtr<Footage>(footage_input_->get_value(time));
// If no footage is selected, return nothing
if (footage == nullptr) {
// Make sure decoder is set up
if (!SetupDecoder()) {
return 0;
}
// Otherwise try to get frame of footage from decoder
// Determine which decoder to use
if (decoder_ == nullptr
&& (decoder_ = Decoder::CreateFromID(footage->decoder())) == nullptr) {
return 0;
}
if (decoder_->stream() == nullptr) {
// FIXME: Hardcoded stream 0
decoder_->set_stream(footage->stream(0));
}
// Get frame from Decoder
FramePtr frame = decoder_->Retrieve(time);
@@ -247,3 +243,33 @@ QVariant MediaInput::Value(NodeOutput *output, const rational &time)
return 0;
}
bool MediaInput::SetupDecoder()
{
if (decoder_ != nullptr) {
return true;
}
// Get currently selected Footage
Footage* footage = ValueToPtr<Footage>(footage_input_->get_value(0));
// If no footage is selected, return nothing
if (footage == nullptr) {
return false;
}
// Otherwise try to get frame of footage from decoder
// Determine which decoder to use
if (decoder_ == nullptr
&& (decoder_ = Decoder::CreateFromID(footage->decoder())) == nullptr) {
return false;
}
if (decoder_->stream() == nullptr) {
// FIXME: Hardcoded stream 0
decoder_->set_stream(footage->stream(0));
}
return true;
}
+6
View File
@@ -51,10 +51,16 @@ public:
void SetFootage(Footage* f);
virtual void Hash(QCryptographicHash *hash, const rational &time) override;
protected:
virtual QVariant Value(NodeOutput* output, const rational& time) override;
private:
bool SetupDecoder();
NodeInput* footage_input_;
NodeInput* matrix_input_;
+23
View File
@@ -279,6 +279,29 @@ bool Node::OutputsTo(Node *n)
return false;
}
void Node::Hash(QCryptographicHash *hash, NodeOutput* from, const rational &time)
{
// Add this Node's ID
hash->addData(id().toUtf8());
// Add each value
QList<NodeParam*> params = parameters();
foreach (NodeParam* param, params) {
if (param->type() == NodeParam::kInput && !param->IsConnected()) {
// Get the value at this time
QVariant v = static_cast<NodeInput*>(param)->get_value(time);
hash->addData(v.toByteArray()); // FIXME: Does this work on all value types?
}
}
// Add each dependency node
QList<NodeDependency> deps = RunDependencies(from, time);
foreach (const NodeDependency& dep, deps) {
// Hash the connected node
dep.node()->parent()->Hash(hash, dep.node(), time);
}
}
QVariant Node::PtrToValue(void *ptr)
{
return reinterpret_cast<quintptr>(ptr);
+6
View File
@@ -21,6 +21,7 @@
#ifndef NODE_H
#define NODE_H
#include <QCryptographicHash>
#include <QMutex>
#include <QObject>
@@ -147,6 +148,11 @@ public:
*/
bool OutputsTo(Node* n);
/**
* @brief Add's unique information about this Node at the given time to a QCryptographicHash
*/
virtual void Hash(QCryptographicHash* hash, NodeOutput *from, const rational& time);
/**
* @brief Convert a pointer to a value that can be sent between NodeParams
*/