1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 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 "traverser.h"
#include "node.h"
OLIVE_NAMESPACE_ENTER
NodeValueDatabase NodeTraverser::GenerateDatabase(const Node* node, const TimeRange &range)
{
NodeValueDatabase database;
// We need to insert tables into the database for each input
QList<NodeInput*> inputs = node->GetInputsIncludingArrays();
foreach (NodeInput* input, inputs) {
if (IsCancelled()) {
return NodeValueDatabase();
}
TimeRange input_time = node->InputTimeAdjustment(input, range);
database.Insert(input, ProcessInput(input, input_time));
}
AddGlobalsToDatabase(database, range);
return database;
}
NodeValueTable NodeTraverser::ProcessInput(NodeInput* input, const TimeRange& range)
{
if (input->is_connected()) {
// Value will equal something from the connected node, follow it
return GenerateTable(input->get_connected_node(), range);
} else if (!input->IsArray()) {
// Push onto the table the value at this time from the input
QVariant input_value = input->get_value_at_time(range.in());
NodeValueTable table;
table.Push(input->data_type(), input_value, input->parentNode());
return table;
}
return NodeValueTable();
}
NodeValueTable NodeTraverser::GenerateTable(const Node *n, const TimeRange& range)
{
if (n->IsTrack()) {
// If the range is not wholly contained in this Block, we'll need to do some extra processing
return GenerateBlockTable(static_cast<const TrackOutput*>(n), range);
}
// FIXME: Cache certain values here if we've already processed them before
// Generate database of input values of node
NodeValueDatabase database = GenerateDatabase(n, range);
// By this point, the node should have all the inputs it needs to render correctly
NodeValueTable table = n->Value(database);
PostProcessTable(n, range, table);
return table;
}
NodeValueTable NodeTraverser::GenerateTable(const Node *n, const rational &in, const rational &out)
{
return GenerateTable(n, TimeRange(in, out));
}
NodeValueTable NodeTraverser::GenerateBlockTable(const TrackOutput *track, const TimeRange &range)
{
// By default, just follow the in point
Block* active_block = track->BlockAtTime(range.in());
NodeValueTable table;
if (active_block) {
table = GenerateTable(active_block, range);
}
return table;
}
QVariant NodeTraverser::ProcessVideoFootage(StreamPtr stream, const rational &input_time)
{
Q_UNUSED(stream)
Q_UNUSED(input_time)
return QVariant();
}
QVariant NodeTraverser::ProcessAudioFootage(StreamPtr stream, const TimeRange &input_time)
{
Q_UNUSED(stream)
Q_UNUSED(input_time)
return QVariant();
}
QVariant NodeTraverser::ProcessShader(const Node *node, const TimeRange &range, const ShaderJob &job)
{
Q_UNUSED(node)
Q_UNUSED(range)
Q_UNUSED(job)
return QVariant();
}
QVariant NodeTraverser::ProcessSamples(const Node *node, const TimeRange &range, const SampleJob &job)
{
Q_UNUSED(node)
Q_UNUSED(range)
Q_UNUSED(job)
return QVariant();
}
QVariant NodeTraverser::ProcessFrameGeneration(const Node *node, const GenerateJob &job)
{
Q_UNUSED(node)
Q_UNUSED(job)
return QVariant();
}
QVariant NodeTraverser::GetCachedFrame(const Node *node, const rational &time)
{
Q_UNUSED(node)
Q_UNUSED(time)
return QVariant();
}
void NodeTraverser::AddGlobalsToDatabase(NodeValueDatabase &db, const TimeRange& range)
{
// Insert global variables
NodeValueTable global;
global.Push(NodeParam::kFloat, range.in().toDouble(), nullptr, QStringLiteral("time_in"));
global.Push(NodeParam::kFloat, range.out().toDouble(), nullptr, QStringLiteral("time_out"));
db.Insert(QStringLiteral("global"), global);
}
void NodeTraverser::PostProcessTable(const Node *node, const TimeRange &range, NodeValueTable &output_params)
{
bool got_cached_frame = false;
// Convert footage to image/sample buffers
QVariant cached_frame = GetCachedFrame(node, range.in());
if (!cached_frame.isNull()) {
output_params.Push(NodeParam::kTexture, cached_frame, node);
// No more to do here
got_cached_frame = true;
}
// Strip out any jobs or footage
QList<NodeValue> video_footage_to_retrieve;
QList<NodeValue> audio_footage_to_retrieve;
QList<NodeValue> shader_jobs_to_run;
QList<NodeValue> sample_jobs_to_run;
QList<NodeValue> generate_jobs_to_run;
for (int i=0; i<output_params.Count(); i++) {
const NodeValue& v = output_params.at(i);
QList<NodeValue>* take_this_value_list = nullptr;
if (v.type() == NodeParam::kFootage) {
StreamPtr s = v.data().value<StreamPtr>();
if (s) {
if (s->type() == Stream::kVideo
|| s->type() == Stream::kImage) {
take_this_value_list = &video_footage_to_retrieve;
} else if (s->type() == Stream::kAudio) {
take_this_value_list = &audio_footage_to_retrieve;
}
}
} else if (v.type() == NodeParam::kShaderJob) {
take_this_value_list = &shader_jobs_to_run;
} else if (v.type() == NodeParam::kSampleJob) {
take_this_value_list = &sample_jobs_to_run;
} else if (v.type() == NodeParam::kGenerateJob) {
take_this_value_list = &generate_jobs_to_run;
}
if (take_this_value_list) {
take_this_value_list->append(output_params.TakeAt(i));
i--;
}
}
if (!got_cached_frame) {
// Retrieve video frames
foreach (const NodeValue& v, video_footage_to_retrieve) {
QVariant value = ProcessVideoFootage(v.data().value<StreamPtr>(), range.in());
if (!value.isNull()) {
output_params.Push(NodeParam::kTexture, value, node);
}
}
// Run shaders
foreach (const NodeValue& v, shader_jobs_to_run) {
QVariant value = ProcessShader(node, range, v.data().value<ShaderJob>());
if (!value.isNull()) {
output_params.Push(NodeParam::kTexture, value, node);
}
}
// Run generate jobs
foreach (const NodeValue& v, generate_jobs_to_run) {
QVariant value = ProcessFrameGeneration(node, v.data().value<GenerateJob>());
if (!value.isNull()) {
output_params.Push(NodeParam::kTexture, value, node);
}
}
}
// Retrieve audio samples
foreach (const NodeValue& v, audio_footage_to_retrieve) {
QVariant value = ProcessAudioFootage(v.data().value<StreamPtr>(), range);
if (!value.isNull()) {
output_params.Push(NodeParam::kSamples, value, node);
}
}
// Run any accelerated shader jobs
foreach (const NodeValue& v, sample_jobs_to_run) {
QVariant value = ProcessSamples(node, range, v.data().value<SampleJob>());
if (!value.isNull()) {
output_params.Push(NodeParam::kSamples, value, node);
}
}
}
OLIVE_NAMESPACE_EXIT
|