Files
oak-editor/engine/task/project/loadotio/loadotio.cpp
T
Mike-Solar 712badbaa7 build/ci: green builds and tests on all three platforms
Compiler hygiene (all platforms):
- Silence warnings across the tree: missing override, -Wreorder ctor
  init, -Wshadow, -Wsign-compare, missing switch cases, unused
  functions/captures, Qt 6.11 deprecations (QMouseEvent/QDropEvent
  accessors, qAsConst, Q_FOREACH over non-shared containers,
  AA_UseHighDpiPixmaps) and the .bak/ backup tree removal.
- Fix regressions from the cleanup: missing clip decls in
  capi/timeline.cpp, plugin.cpp rename fallout, panel setFocus
  ambiguity, QGraphicsItem::pos vs event->position(), duplicate
  k_push_button case, boolean test variable.

Windows:
- Qt portability: CommandLineParser is_set/add_option, QTimeZone
  systemTimeZone (QTimeZone::LocalTime is 6.11-only), k_progress_* enum.
- Linking: stop adding oakengine to OLIVE_LIBRARIES (import lib plus
  oakengine-obj caused multiple definitions); add OAKENGINE_STATIC so
  internal consumers no longer reference __imp_* stubs.
- oakengine.ver: export olive::Renderer typeinfo so liboakgl.so can be
  dlopened (Linux), DynamicRenderer no longer dlcloses backend libraries
  (crash in RenderManager's dtor calling into unmapped memory).
- OTIO runtime: copy DLLs next to every binary on Windows instead of
  relying on PATH (0xc0000135 in gtest discovery).
- Headless GL: the runner only has GDI OpenGL 1.1, killing every render
  worker. Deploy Mesa llvmpipe as opengl32sw.dll (Qt's software-GL
  channel) with QT_OPENGL=software, and let QT_OPENGL override the
  AA_UseDesktopOpenGL default. ExportTask fails fast after 8 consecutive
  undelivered frames instead of segfaulting or grinding forever;
  FFmpegEncoder::write_frame tolerates null frames.
- Tests: GetTempPathA+PID temp dirs, GetLongPathNameA for 8.3 names,
  forward-slash normalization when comparing project filenames.

Linux:
- Install libshaderc-dev so oakvulkan compiles GLSL (Vulkan tests).
- Accept UNORM floor-or-round (63/64) in the blit ping-pong test.
- Skip MainWindow construction test on the offscreen QPA (cannot paint
  QOpenGLWidget).

Also: oak_cli_transcode gets a 300s ctest timeout, worker logs GL
context version and LoadGraph/render_frame stages, and
docs/plans/eliminate-event-bridge-issues.md (English translation).
2026-08-04 21:34:31 +08:00

378 lines
11 KiB
C++

/***
Olive - Non-Linear Video Editor
Copyright (C) 2022 Olive Team
Modifications Copyright (C) 2025 mikesolar
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 "loadotio.h"
#ifdef USE_OTIO
#include <opentimelineio/clip.h>
#include <opentimelineio/externalReference.h>
#include <opentimelineio/gap.h>
#include <opentimelineio/serializableCollection.h>
#include <opentimelineio/timeline.h>
#include <opentimelineio/transition.h>
#include <QApplication>
#include <QFileInfo>
#include <QThread>
#include "coreengine.h"
#include "node/audio/volume/volume.h"
#include "node/block/clip/clip.h"
#include "node/block/gap/gap.h"
#include "node/block/transition/crossdissolve/crossdissolvetransition.h"
#include "node/distort/transform/transformdistortnode.h"
#include "node/generator/matrix/matrix.h"
#include "node/math/math/math.h"
#include "node/nodeundo.h"
#include "node/project/folder/folder.h"
#include "node/project/footage/footage.h"
#include "node/project/sequence/sequence.h"
#include "timeline/timelineundogeneral.h"
namespace olive
{
LoadOTIOTask::LoadOTIOTask(const QString &s)
: ProjectLoadBaseTask(s)
{
}
bool LoadOTIOTask::run()
{
OTIO::ErrorStatus es;
auto root = OTIO::SerializableObjectWithMetadata::from_json_file(
get_filename().toStdString(), &es);
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
set_error(
tr("Failed to load OpenTimelineIO from file \"%1\" \n\nOpenTimelineIO Error:\n\n%2")
.arg(get_filename(),
QString::fromStdString(es.full_description)));
return false;
}
project_ = new Project();
project_->initialize();
project_->set_modified(true);
std::vector<OTIO::Timeline *> timelines;
if (root->schema_name() == "SerializableCollection") {
// This is a number of timelines
std::vector<OTIO::SerializableObject::Retainer<OTIO::SerializableObject>>
&root_children =
static_cast<OTIO::SerializableCollection *>(root)->children();
timelines.resize(root_children.size());
for (size_t j = 0; j < root_children.size(); j++) {
timelines[j] =
static_cast<OTIO::Timeline *>(root_children[j].value);
}
} else if (root->schema_name() == "Timeline") {
// This is a single timeline
timelines.push_back(static_cast<OTIO::Timeline *>(root));
} else {
// Unknown root, we don't know what to do with this
set_error(tr("Unknown OpenTimelineIO root element"));
delete project_;
project_ = nullptr;
return false;
}
// Keep track of imported footage
QMap<QString, Footage *> imported_footage;
QMap<OTIO::Timeline *, Sequence *> timeline_sequnce_map;
// Variables used for loading bar
float number_of_clips = 0;
float clips_done = 0;
// Generate a list of sequences with the same names as the timelines.
// Assumes each timeline has a unique name.
int unnamed_sequence_count = 0;
for (auto timeline : timelines) {
Sequence *sequence = new Sequence();
if (!timeline->name().empty()) {
sequence->set_label(QString::fromStdString(timeline->name()));
} else {
// If the otio timeline does not provide a name, create a default one here
unnamed_sequence_count++;
QString label = tr("Sequence %1").arg(unnamed_sequence_count);
sequence->set_label(QString::fromStdString(label.toStdString()));
}
// Set default params incase they aren't edited.
sequence->set_default_parameters();
timeline_sequnce_map.insert(timeline, sequence);
// Get number of clips for loading bar
for (auto track : timeline->tracks()->children()) {
auto otio_track = static_cast<OTIO::Track *>(track.value);
number_of_clips += otio_track->children().size();
}
}
// Dialog has to be called from the main thread so we pass the list of sequences here.
bool accepted = false;
QMetaObject::invokeMethod(
EngineCore::instance(), "show_otio_import_dialog", Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, accepted),
Q_ARG(QList<Sequence *>, timeline_sequnce_map.values()));
if (!accepted) {
// Cancel to indicate to caller that this task did not complete and to simply dispose of it
Cancel();
qDeleteAll(timeline_sequnce_map); // Clear sequences
return true;
}
foreach (auto timeline, timeline_sequnce_map.keys()) {
Sequence *sequence = timeline_sequnce_map.value(timeline);
sequence->setParent(project_);
FolderAddChild(project_->root(), sequence).redo_now();
// Create a folder for this sequence's footage
Folder *sequence_footage = new Folder();
sequence_footage->set_label(QString::fromStdString(timeline->name()));
sequence_footage->setParent(project_);
FolderAddChild(project_->root(), sequence_footage).redo_now();
// Iterate through tracks
for (auto c : timeline->tracks()->children()) {
auto otio_track = static_cast<OTIO::Track *>(c.value);
// Create a new track
Track *track = nullptr;
// Determine what kind of track it is
if (otio_track->kind() == "Video" ||
otio_track->kind() == "Audio") {
Track::Type type;
if (otio_track->kind() == "Video") {
type = Track::k_video;
} else {
type = Track::k_audio;
}
// Create track
TimelineAddTrackCommand t(sequence->track_list(type));
t.redo_now();
track = t.track();
} else {
qWarning() << "Found unknown track type:"
<< otio_track->kind().c_str();
continue;
}
// Get clips from track
auto clip_map = otio_track->children();
if (es.outcome != OTIO::ErrorStatus::Outcome::OK) {
set_error(tr("Failed to load clip"));
return false;
}
Block *previous_block = nullptr;
bool prev_block_transition = false;
for (auto otio_block_retainer : clip_map) {
auto otio_block = otio_block_retainer.value;
Block *block = nullptr;
if (otio_block->schema_name() == "Clip") {
block = new ClipBlock();
} else if (otio_block->schema_name() == "Gap") {
block = new GapBlock();
} else if (otio_block->schema_name() == "Transition") {
// Todo: Look into OTIO supported transitions and add them to Olive
block = new CrossDissolveTransition();
} else {
// We don't know what this is yet, just create a gap for now so that *something* is there
qWarning() << "Found unknown block type:"
<< otio_block->schema_name().c_str();
block = new GapBlock();
}
block->setParent(project_);
block->set_label(QString::fromStdString(otio_block->name()));
track->append_block(block);
Rational start_time;
Rational duration;
if (otio_block->schema_name() == "Clip" ||
otio_block->schema_name() == "Gap") {
start_time = Rational::from_double(
static_cast<OTIO::Item *>(otio_block)
->source_range()
->start_time()
.to_seconds());
duration = Rational::from_double(
static_cast<OTIO::Item *>(otio_block)
->source_range()
->duration()
.to_seconds());
if (otio_block->schema_name() == "Clip") {
static_cast<ClipBlock *>(block)->set_media_in(
start_time);
}
block->set_length_and_media_out(duration);
}
// If the previous block was a transition, connect the current block to it
if (prev_block_transition) {
TransitionBlock *previous_transition_block =
static_cast<TransitionBlock *>(previous_block);
Node::connect_edge(
block, NodeInput(previous_transition_block,
TransitionBlock::k_in_block_input));
prev_block_transition = false;
}
if (otio_block->schema_name() == "Transition") {
TransitionBlock *transition_block =
static_cast<TransitionBlock *>(block);
OTIO::Transition *otio_block_transition =
static_cast<OTIO::Transition *>(otio_block);
// Set how far the transition eats into the previous clip
transition_block->set_offsets_and_length(
Rational::fromRationalTime(
otio_block_transition->in_offset()),
Rational::fromRationalTime(
otio_block_transition->out_offset()));
if (previous_block) {
Node::connect_edge(
previous_block,
NodeInput(transition_block,
TransitionBlock::k_out_block_input));
}
prev_block_transition = true;
// Add nodes to the graph and set up contexts
block->setParent(sequence->parent());
// Position transition in its own context
block->set_node_position_in_context(block, QPointF(0, 0));
}
if (otio_block->schema_name() == "Gap") {
// Add nodes to the graph and set up contexts
block->setParent(sequence->parent());
// Position transition in its own context
block->set_node_position_in_context(block, QPointF(0, 0));
}
// Update this after it's used but before any continue statements
previous_block = block;
if (otio_block->schema_name() == "Clip") {
auto otio_clip = static_cast<OTIO::Clip *>(otio_block);
if (!otio_clip->media_reference()) {
continue;
}
if (otio_clip->media_reference()->schema_name() ==
"ExternalReference") {
// Link footage
QString footage_url = QString::fromStdString(
static_cast<OTIO::ExternalReference *>(
otio_clip->media_reference())
->target_url());
Footage *probed_item;
if (imported_footage.contains(footage_url)) {
probed_item = imported_footage.value(footage_url);
} else {
probed_item = new Footage(footage_url);
imported_footage.insert(footage_url, probed_item);
probed_item->setParent(project_);
QFileInfo info(probed_item->filename());
probed_item->set_label(info.fileName());
FolderAddChild add(sequence_footage, probed_item);
add.redo_now();
}
// Add nodes to the graph and set up contexts
block->setParent(sequence->parent());
// Position clip in its own context
block->set_node_position_in_context(block, QPointF(0, 0));
// Position footage in its context
block->set_node_position_in_context(probed_item,
QPointF(-2, 0));
if (track->type() == Track::k_video) {
TransformDistortNode *transform =
new TransformDistortNode();
transform->setParent(sequence->parent());
Node::connect_edge(
probed_item,
NodeInput(transform,
TransformDistortNode::k_texture_input));
Node::connect_edge(transform,
NodeInput(block,
ClipBlock::k_buffer_in));
block->set_node_position_in_context(transform,
QPointF(-1, 0));
} else {
VolumeNode *volume_node = new VolumeNode();
volume_node->setParent(sequence->parent());
Node::connect_edge(
probed_item,
NodeInput(volume_node,
VolumeNode::k_samples_input));
Node::connect_edge(volume_node,
NodeInput(block,
ClipBlock::k_buffer_in));
block->set_node_position_in_context(volume_node,
QPointF(-1, 0));
}
}
}
clips_done++;
emit progress_changed(clips_done / number_of_clips);
}
}
}
project_->moveToThread(qApp->thread());
return true;
}
}
#endif // USE_OTIO