workspace: kebab-case crates, app under crates/oak-app, shared versions
CI / Build & test (Windows) (push) Failing after 7s
CI / Build & test (Windows) (push) Failing after 7s
All crates take the oak-* kebab-case naming (oak-audio, oak-codec, oak-common, oak-core, oak-ffmpeg-link, oak-node, oak-otio, oak-plugin, oak-render, oak-storage, oak-task, oak-timeline, oak-undo), with the lib identifiers rewritten (oakrender:: -> oak_render::, oakcore_rs:: -> oak_core::, ...) across all 226 referencing files. The GUI application moves from the workspace root into crates/oak-app/: src/, build.rs (paths fixed for the new location) and tests/ travel with it, the root Cargo.toml becomes workspace-only ([workspace] + workspace.package + profiles), and the app package inherits the workspace version. The screenshots example becomes a standalone crate examples/simple_player/ with its own Cargo.toml. Every crate now inherits the single workspace version (version.workspace = true), and the workflows' crate paths and the build docs follow the renames. Validated with a clean cargo check --workspace.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak 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/>.
|
||||
|
||||
//! Interchange-format dispatch for the OTIO tasks.
|
||||
//!
|
||||
//! `LoadOTIOTask` / `SaveOTIOTask` accept both OpenTimelineIO JSON
|
||||
//! (`.otio`) and FCPXML (`.fcpxml`) documents. The format is inferred from
|
||||
//! the filename extension (case-insensitive), so the frozen C ABI
|
||||
//! (`include/task/project.h`) needs no format parameter: the filename
|
||||
//! passed to `oaktask_create_project_load_otio` /
|
||||
//! `oaktask_create_project_save_otio` selects the codec. Format handling
|
||||
//! ends at the `oakotio` parse/serialize call in each task — the
|
||||
//! track/clip/footage building is shared between both formats.
|
||||
//!
|
||||
//! No OTIO or FCPXML type crosses the oaktask C ABI (README decision #6).
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
|
||||
/// The interchange formats the OTIO tasks can read and write.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum InterchangeFormat {
|
||||
/// OpenTimelineIO JSON (`.otio`).
|
||||
OtioJson,
|
||||
/// Final Cut Pro XML (`.fcpxml`).
|
||||
Fcpxml,
|
||||
}
|
||||
|
||||
/// The filename extensions each format dispatches on.
|
||||
pub const SUPPORTED_EXTENSIONS: &str = ".otio, .fcpxml";
|
||||
|
||||
impl InterchangeFormat {
|
||||
/// Dispatch on a filename's extension (case-insensitive).
|
||||
///
|
||||
/// `foo.OTIO` and `foo.FcpXml` select the same format as `foo.otio` /
|
||||
/// `foo.fcpxml`; any other extension (or a filename without one) is
|
||||
/// `Error::Failed` with a message naming the supported extensions.
|
||||
pub fn of(filename: &str) -> Result<InterchangeFormat> {
|
||||
let ext = Path::new(filename)
|
||||
.extension()
|
||||
.map(|e| e.to_string_lossy().into_owned())
|
||||
.unwrap_or_default();
|
||||
match ext.to_ascii_lowercase().as_str() {
|
||||
"otio" => Ok(InterchangeFormat::OtioJson),
|
||||
"fcpxml" => Ok(InterchangeFormat::Fcpxml),
|
||||
_ => Err(Error::Failed(format!(
|
||||
"Unknown project file format for \"{filename}\" (supported: {SUPPORTED_EXTENSIONS})"
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,454 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak 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/>.
|
||||
|
||||
//! `ProjectImportTask`, mirroring `src/task/src/project/import/import.h`.
|
||||
//!
|
||||
//! Imports media files into a folder of a project. Produces an undoable
|
||||
//! [`oak_undo::undocommand::UndoCommand`] (taken via `take_command()`),
|
||||
//! tracks per-file import failures, and supports an optional image-sequence
|
||||
//! confirmation callback.
|
||||
//!
|
||||
//! **Single-lib note**: the node-graph manipulation went through the
|
||||
//! deleted oaknode C ABI; it now goes through the direct oaknode domain
|
||||
//! operations in [`crate::nodeops`] (folder/footage creation, probing via
|
||||
//! the oakcodec decoder registry, undo command construction). The folder
|
||||
//! and project are domain references (`Arc<Mutex<Project>>` + `NodeId`)
|
||||
//! instead of borrowed `CHandle`s.
|
||||
//!
|
||||
//! CPP-PARITY: src/task/src/project/import/import.h
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use oak_common::configstore::ConfigStore;
|
||||
use oak_common::videoparams::VideoType;
|
||||
use oak_undo::undocommand::UndoCommand;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::nodeops::{self, NodeRef, ProjectRef};
|
||||
use crate::task::{Task, TaskBehavior};
|
||||
|
||||
/// Callback used to confirm whether a detected image sequence should be
|
||||
/// imported as a sequence rather than individual frames, mirroring
|
||||
/// `ImageSequenceConfirmFn` in import.h.
|
||||
pub type ImageSequenceConfirmFn = Box<dyn FnMut(&str, &str) -> bool + Send>;
|
||||
|
||||
/// A project-import task. Borrows the destination folder and project.
|
||||
pub struct ProjectImportTask {
|
||||
/// The shared task base.
|
||||
pub base: Task,
|
||||
/// Destination folder (project + folder node id).
|
||||
pub folder: NodeRef,
|
||||
/// Destination project.
|
||||
pub project: ProjectRef,
|
||||
/// Media filenames to import.
|
||||
pub filenames: Vec<String>,
|
||||
/// The undo command produced by the task, taken via `take_command`.
|
||||
command: Option<UndoCommand>,
|
||||
/// Files that failed to import.
|
||||
invalid_files: Vec<String>,
|
||||
/// Imported footage, taken via `get_imported_footage`.
|
||||
imported_footage: Vec<NodeRef>,
|
||||
/// Optional image-sequence confirmation callback.
|
||||
image_sequence_confirm: Option<ImageSequenceConfirmFn>,
|
||||
/// Total number of files to import (directories counted recursively).
|
||||
file_count: usize,
|
||||
/// Image-sequence files already decided not to be imported as sequences.
|
||||
image_sequence_ignore_files: Vec<String>,
|
||||
}
|
||||
|
||||
impl ProjectImportTask {
|
||||
/// Create an import task for the given folder/project and filenames.
|
||||
/// The old `folder: CHandle` / `project: CHandle` signature is replaced
|
||||
/// by the domain [`NodeRef`] folder and [`ProjectRef`] project
|
||||
/// (single-lib unification).
|
||||
pub fn new(
|
||||
base: Task,
|
||||
folder: NodeRef,
|
||||
project: ProjectRef,
|
||||
filenames: Vec<String>,
|
||||
image_sequence_confirm: Option<ImageSequenceConfirmFn>,
|
||||
file_count: usize,
|
||||
) -> ProjectImportTask {
|
||||
ProjectImportTask {
|
||||
base,
|
||||
folder,
|
||||
project,
|
||||
filenames,
|
||||
command: None,
|
||||
invalid_files: Vec::new(),
|
||||
imported_footage: Vec::new(),
|
||||
image_sequence_confirm,
|
||||
file_count,
|
||||
image_sequence_ignore_files: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Take ownership of the produced undo command; `Err(Error::State)` if
|
||||
/// the task has not run yet.
|
||||
pub fn take_command(&mut self) -> Result<UndoCommand> {
|
||||
self.command.take().ok_or(Error::State)
|
||||
}
|
||||
|
||||
/// Number of files that failed to import.
|
||||
pub fn get_invalid_file_count(&self) -> usize {
|
||||
self.invalid_files.len()
|
||||
}
|
||||
|
||||
/// Whether any file failed to import.
|
||||
pub fn has_invalid_files(&self) -> bool {
|
||||
!self.invalid_files.is_empty()
|
||||
}
|
||||
|
||||
/// The imported footage at `index` as a domain [`NodeRef`];
|
||||
/// `Err(Error::NotFound)` if out of range. (The deleted C ABI handed
|
||||
/// out addref'd handles; the domain reference is a plain clone.)
|
||||
pub fn get_imported_footage(&self, index: usize) -> Result<NodeRef> {
|
||||
self.imported_footage.get(index).cloned().ok_or(Error::NotFound)
|
||||
}
|
||||
|
||||
/// Total number of imported footage entries.
|
||||
pub fn get_file_count(&self) -> usize {
|
||||
self.imported_footage.len()
|
||||
}
|
||||
|
||||
/// Set the image-sequence confirmation callback.
|
||||
pub fn set_image_sequence_confirm_callback(&mut self, cb: ImageSequenceConfirmFn) {
|
||||
self.image_sequence_confirm = Some(cb);
|
||||
}
|
||||
|
||||
/// The number of files counted at construction (progress denominator).
|
||||
pub fn file_count(&self) -> usize {
|
||||
self.file_count
|
||||
}
|
||||
|
||||
fn import(
|
||||
&mut self,
|
||||
task: &mut Task,
|
||||
folder: NodeRef,
|
||||
entries: &mut Vec<String>,
|
||||
counter: &mut usize,
|
||||
parent_command: &mut UndoCommand,
|
||||
) {
|
||||
let atom = task.get_cancel_atom();
|
||||
let mut i = 0;
|
||||
while i < entries.len() {
|
||||
if task.is_cancelled() {
|
||||
break;
|
||||
}
|
||||
|
||||
let file_path = &entries[i];
|
||||
|
||||
if Path::new(file_path).is_dir() {
|
||||
// Create a folder corresponding to the directory and recurse.
|
||||
let entry_list: Vec<String> = match std::fs::read_dir(file_path) {
|
||||
Ok(rd) => rd
|
||||
.filter_map(|e| e.ok())
|
||||
.map(|e| e.path().to_string_lossy().into_owned())
|
||||
.collect(),
|
||||
Err(_) => Vec::new(),
|
||||
};
|
||||
|
||||
if !entry_list.is_empty() {
|
||||
if let Some(folder_id) = nodeops::folder_create(&self.project) {
|
||||
nodeops::set_node_label(&self.project, folder_id, &basename_of(file_path));
|
||||
self.add_item_to_folder(
|
||||
folder.clone(),
|
||||
(self.project.clone(), folder_id),
|
||||
parent_command,
|
||||
);
|
||||
let mut sub_entries = entry_list;
|
||||
self.import(
|
||||
task,
|
||||
(self.project.clone(), folder_id),
|
||||
&mut sub_entries,
|
||||
counter,
|
||||
parent_command,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let Some(footage) = nodeops::footage_create(&self.project, None) else {
|
||||
i += 1;
|
||||
continue;
|
||||
};
|
||||
|
||||
// Mirror the C++ cancel-atom dance around the probe: the
|
||||
// footage behavior's own cancellation flag tracks the
|
||||
// task's atom during the probe and is cleared afterwards.
|
||||
nodeops::footage_set_cancelled(&self.project, footage, true);
|
||||
nodeops::footage_set_cancelled(&self.project, footage, atom.is_cancelled());
|
||||
let ok = nodeops::footage_set_filename(&self.project, footage, file_path);
|
||||
nodeops::footage_set_cancelled(&self.project, footage, false);
|
||||
|
||||
if ok && nodeops::footage_is_valid(&self.project, footage) {
|
||||
nodeops::set_node_label(&self.project, footage, &basename_of(file_path));
|
||||
|
||||
// See if this footage is an image sequence.
|
||||
self.validate_image_sequence(
|
||||
task,
|
||||
(self.project.clone(), footage),
|
||||
entries,
|
||||
i,
|
||||
);
|
||||
|
||||
// Create the undoable command that adds the item.
|
||||
self.add_item_to_folder(
|
||||
folder.clone(),
|
||||
(self.project.clone(), footage),
|
||||
parent_command,
|
||||
);
|
||||
|
||||
self.imported_footage.push((self.project.clone(), footage));
|
||||
} else {
|
||||
self.invalid_files.push(file_path.clone());
|
||||
|
||||
// Remove the invalid footage from the graph; the remove
|
||||
// command takes ownership on redo and deletes the node
|
||||
// when the command is destroyed.
|
||||
let mut remove =
|
||||
nodeops::remove_node_command(self.project.clone(), footage);
|
||||
remove.redo_now();
|
||||
}
|
||||
|
||||
*counter += 1;
|
||||
task.emit_progress(*counter as f64 / self.file_count.max(1) as f64);
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn add_item_to_folder(&self, folder: NodeRef, item: NodeRef, command: &mut UndoCommand) {
|
||||
let child = nodeops::folder_add_child_command(folder, item);
|
||||
command.multi_add_child(child);
|
||||
}
|
||||
|
||||
fn validate_image_sequence(
|
||||
&mut self,
|
||||
task: &mut Task,
|
||||
footage: NodeRef,
|
||||
info_list: &mut Vec<String>,
|
||||
index: usize,
|
||||
) {
|
||||
let filename = nodeops::footage_filename(&footage.0, footage.1);
|
||||
if filename.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Direct oakcodec calls (single-lib unification).
|
||||
let digit_count = oak_codec::decoder::get_image_sequence_digit_count(&filename);
|
||||
if digit_count <= 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
if self
|
||||
.image_sequence_ignore_files
|
||||
.iter()
|
||||
.any(|f| f == &filename)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if !self.item_is_still_image_footage_only(&footage) {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(mut video_stream) = nodeops::footage_video_params(&footage.0, footage.1, 0)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let width = video_stream.width();
|
||||
let height = video_stream.height();
|
||||
|
||||
// Direct oakcodec call (single-lib unification).
|
||||
let seq_index = oak_codec::decoder::get_image_sequence_index(&filename);
|
||||
|
||||
let prev_fn = transform_sequence_filename(&filename, seq_index - 1, digit_count);
|
||||
let next_fn = transform_sequence_filename(&filename, seq_index + 1, digit_count);
|
||||
|
||||
let previous_file = nodeops::footage_create(&self.project, Some(&prev_fn));
|
||||
let next_file = nodeops::footage_create(&self.project, Some(&next_fn));
|
||||
|
||||
let prev_matches = previous_file.is_some_and(|f| {
|
||||
nodeops::footage_set_filename(&self.project, f, &prev_fn)
|
||||
&& self.compare_still_image_size(&(self.project.clone(), f), width, height)
|
||||
});
|
||||
let next_matches = next_file.is_some_and(|f| {
|
||||
nodeops::footage_set_filename(&self.project, f, &next_fn)
|
||||
&& self.compare_still_image_size(&(self.project.clone(), f), width, height)
|
||||
});
|
||||
|
||||
if prev_matches || next_matches {
|
||||
// Ask the user whether this is really a sequence (default: no).
|
||||
let is_sequence = match self.image_sequence_confirm.as_mut() {
|
||||
Some(cb) => cb(&filename, &filename),
|
||||
None => false,
|
||||
};
|
||||
|
||||
let start_index = get_image_sequence_limit(&filename, seq_index, false, digit_count);
|
||||
let end_index = get_image_sequence_limit(&filename, seq_index, true, digit_count);
|
||||
|
||||
for j in start_index..=end_index {
|
||||
let entry_fn = transform_sequence_filename(&filename, j, digit_count);
|
||||
|
||||
if is_sequence {
|
||||
// Remove later entries of this sequence from the import
|
||||
// list (they are imported as one footage). The C++
|
||||
// `info_list.size()` is re-evaluated after each erase.
|
||||
let mut k = index + 1;
|
||||
while k < info_list.len() {
|
||||
if info_list[k] == entry_fn {
|
||||
info_list.remove(k);
|
||||
break;
|
||||
}
|
||||
k += 1;
|
||||
}
|
||||
} else {
|
||||
self.image_sequence_ignore_files.push(entry_fn);
|
||||
}
|
||||
}
|
||||
|
||||
if is_sequence {
|
||||
video_stream.set_video_type(VideoType::ImageSequence);
|
||||
|
||||
// Direct config read (single-lib unification).
|
||||
if let Ok(rate) = ConfigStore::instance().get(None, "DefaultSequenceFrameRate") {
|
||||
if let Some((num, den)) = parse_rational(&rate) {
|
||||
if den != 0 {
|
||||
video_stream.set_time_base(num, den);
|
||||
video_stream.set_frame_rate(den, num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
video_stream.set_start_time(start_index);
|
||||
video_stream.set_duration(end_index - start_index + 1);
|
||||
nodeops::footage_set_video_params(&footage.0, footage.1, 0, &video_stream);
|
||||
}
|
||||
}
|
||||
|
||||
// The probe footage was only created for comparison; remove it.
|
||||
for probe in [previous_file, next_file].into_iter().flatten() {
|
||||
let mut remove = nodeops::remove_node_command(self.project.clone(), probe);
|
||||
remove.redo_now();
|
||||
}
|
||||
|
||||
let _ = task;
|
||||
}
|
||||
|
||||
fn item_is_still_image_footage_only(&self, footage: &NodeRef) -> bool {
|
||||
// The oaknode domain footage records probed streams; a single
|
||||
// stream is the closest domain equivalent of the C++
|
||||
// `total_stream_count == 1` check. The oaknode video params carry
|
||||
// no `video_type`, so the `kVideoTypeStill` check collapses to
|
||||
// "one stream with valid dimensions".
|
||||
if nodeops::footage_total_stream_count(&footage.0, footage.1) != 1 {
|
||||
return false;
|
||||
}
|
||||
|
||||
let Some(vp) = nodeops::footage_video_params(&footage.0, footage.1, 0) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
vp.is_valid() && vp.video_type() == VideoType::Video
|
||||
}
|
||||
|
||||
fn compare_still_image_size(&self, footage: &NodeRef, width: i32, height: i32) -> bool {
|
||||
if !self.item_is_still_image_footage_only(footage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let Some(stream) = nodeops::footage_video_params(&footage.0, footage.1, 0) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
stream.width() == width && stream.height() == height
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskBehavior for ProjectImportTask {
|
||||
/// Import each filename via the direct oaknode domain operations
|
||||
/// ([`crate::nodeops`]), collecting an undo command, imported footage,
|
||||
/// and per-file failures.
|
||||
fn run(&mut self, task: &mut Task) -> Result<()> {
|
||||
let mut command = UndoCommand::multi();
|
||||
|
||||
let mut counter = 0;
|
||||
let mut entries = self.filenames.clone();
|
||||
let folder = (self.folder.0.clone(), self.folder.1);
|
||||
self.import(task, folder, &mut entries, &mut counter, &mut command);
|
||||
|
||||
if task.is_cancelled() {
|
||||
self.command = None;
|
||||
return Err(Error::Cancelled);
|
||||
}
|
||||
self.command = Some(command);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Count files recursively (directories recurse; anything else counts 1),
|
||||
/// mirroring `count_files_recursive` in import.cpp.
|
||||
fn basename_of(path: &str) -> String {
|
||||
Path::new(path)
|
||||
.file_name()
|
||||
.map(|n| n.to_string_lossy().into_owned())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Substitute `number` into the trailing-digit field of an image-sequence
|
||||
/// filename (mirrors `oakcodec_decoder_transform_image_sequence_file_name`).
|
||||
fn transform_sequence_filename(filename: &str, number: i64, digit_count: i32) -> String {
|
||||
let width = digit_count.max(0) as usize;
|
||||
match filename.rfind('.') {
|
||||
Some(dot) => {
|
||||
// The digits are the `width` chars immediately before the
|
||||
// extension; they are replaced by `number`.
|
||||
let digits_start = dot.saturating_sub(width);
|
||||
let prefix = &filename[..digits_start];
|
||||
format!(
|
||||
"{prefix}{:0width$}{}",
|
||||
number,
|
||||
&filename[dot..],
|
||||
width = width
|
||||
)
|
||||
}
|
||||
None => format!("{filename}{:0width$}", number, width = width),
|
||||
}
|
||||
}
|
||||
|
||||
/// Walk the index from `start` in the given direction while the transformed
|
||||
/// filename exists (mirrors `get_image_sequence_limit` in import.cpp).
|
||||
fn get_image_sequence_limit(start_fn: &str, start: i64, up: bool, digit_count: i32) -> i64 {
|
||||
let mut current = start;
|
||||
loop {
|
||||
let test_index = if up { current + 1 } else { current - 1 };
|
||||
let test_filename = transform_sequence_filename(start_fn, test_index, digit_count);
|
||||
if !Path::new(&test_filename).exists() {
|
||||
break;
|
||||
}
|
||||
current = test_index;
|
||||
}
|
||||
current
|
||||
}
|
||||
|
||||
/// Parse a "num/den" frame-rate string.
|
||||
fn parse_rational(s: &str) -> Option<(i32, i32)> {
|
||||
let mut parts = s.trim().split('/');
|
||||
let num: i32 = parts.next()?.trim().parse().ok()?;
|
||||
let den: i32 = parts.next()?.trim().parse().ok()?;
|
||||
Some((num, den))
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak 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/>.
|
||||
|
||||
//! `ProjectLoadBaseTask` / `ProjectLoadTask`, mirroring
|
||||
//! `src/task/src/project/load/load.h`.
|
||||
//!
|
||||
//! Loads an `.oakproj` file into a new `oak_node::project::Project`. The
|
||||
//! base task holds the filename and produces the project on
|
||||
//! `take_project()`; `ProjectLoadTask` is the concrete (OTIO-less) loader.
|
||||
//! The project itself is loaded through the direct Rust serializer
|
||||
//! (`oak_node::serializer::load` — single-lib unification; the old oaknode
|
||||
//! serializer C ABI with its per-code result mapping is gone, so the
|
||||
//! version/result-code ladder collapses into the error message the XML
|
||||
//! path used).
|
||||
//!
|
||||
//! CPP-PARITY: src/task/src/project/load/load.h
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use oak_node::project::Project;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::task::{Task, TaskBehavior};
|
||||
|
||||
/// The base project-load task: owns a source filename and yields a loaded
|
||||
/// project via [`ProjectLoadBaseTask::take_project`].
|
||||
pub struct ProjectLoadBaseTask {
|
||||
/// The shared task base.
|
||||
pub base: Task,
|
||||
/// Absolute project filename to load.
|
||||
pub filename: String,
|
||||
/// The loaded project, produced by the task and taken via `take_project`.
|
||||
loaded_project: Option<Arc<Mutex<Project>>>,
|
||||
}
|
||||
|
||||
impl ProjectLoadBaseTask {
|
||||
/// Create a base load task for the given filename.
|
||||
pub fn new(base: Task, filename: String) -> ProjectLoadBaseTask {
|
||||
ProjectLoadBaseTask {
|
||||
base,
|
||||
filename,
|
||||
loaded_project: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Take ownership of the loaded project. Returns `Err(Error::State)` if
|
||||
/// the task has not loaded a project yet.
|
||||
pub fn take_project(&mut self) -> Result<Arc<Mutex<Project>>> {
|
||||
self.loaded_project.take().ok_or(Error::State)
|
||||
}
|
||||
|
||||
/// Store the loaded project (called by `run`).
|
||||
pub(crate) fn store_project(&mut self, project: Arc<Mutex<Project>>) {
|
||||
self.loaded_project = Some(project);
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskBehavior for ProjectLoadBaseTask {
|
||||
/// Load the project from `filename` via the direct oaknode serializer
|
||||
/// (`oak_node::serializer::load`), storing the resulting project.
|
||||
fn run(&mut self, task: &mut Task) -> Result<()> {
|
||||
let xml = match std::fs::read_to_string(&self.filename) {
|
||||
Ok(xml) => xml,
|
||||
Err(e) => {
|
||||
task.set_error(&format!(
|
||||
"Failed to read file \"{}\" for reading.",
|
||||
self.filename
|
||||
));
|
||||
let _ = e;
|
||||
return Err(Error::Failed("Failed to load project".to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
let project = match oak_node::serializer::load(&xml) {
|
||||
Ok(project) => project,
|
||||
Err(e) => {
|
||||
task.set_error(&format!(
|
||||
"Failed to read XML document. File may be corrupt. Error was: {e}"
|
||||
));
|
||||
return Err(Error::Failed("Failed to load project".to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
{
|
||||
let mut guard = project.lock().unwrap_or_else(|e| e.into_inner());
|
||||
guard.set_filename(&self.filename);
|
||||
}
|
||||
|
||||
self.store_project(project);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// The concrete native project loader (no OTIO path).
|
||||
pub struct ProjectLoadTask {
|
||||
/// The shared task base.
|
||||
pub base: ProjectLoadBaseTask,
|
||||
}
|
||||
|
||||
impl TaskBehavior for ProjectLoadTask {
|
||||
fn run(&mut self, task: &mut Task) -> Result<()> {
|
||||
<ProjectLoadBaseTask as TaskBehavior>::run(&mut self.base, task)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak 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/>.
|
||||
|
||||
//! `LoadOTIOTask`, mirroring `src/task/src/project/loadotio/loadotio.h`.
|
||||
//!
|
||||
//! Loads an OpenTimelineIO (`.otio`) or FCPXML (`.fcpxml`) file into a new
|
||||
//! project, with a configurable import-confirmation callback. The format
|
||||
//! is dispatched from the filename extension (see
|
||||
//! [`crate::project::format`]); the document is parsed with the pure-Rust
|
||||
//! `oakotio` binding (see `README` decision #6).
|
||||
//!
|
||||
//! **Single-lib note**: the project is built through the direct oaknode
|
||||
//! domain operations in [`crate::nodeops`] (`Project::new()` +
|
||||
//! `Project::initialize()`, factory-created sequence/folder/footage/
|
||||
//! block/track nodes, graph connections) instead of the deleted oaknode /
|
||||
//! oaktimeline C ABIs. Track creation uses the task-local
|
||||
//! [`crate::nodeops::add_track_command`] (see its docs for the
|
||||
//! oaktimeline-migration note). The loaded project is an
|
||||
//! `Arc<Mutex<oak_node::project::Project>>` stored on the base task
|
||||
//! (`take_project()`).
|
||||
//!
|
||||
//! CPP-PARITY: src/task/src/project/loadotio/loadotio.cpp
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use oak_node::id::NodeId;
|
||||
use oak_node::track::TrackType;
|
||||
use oak_otio::Serializable;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::nodeops::{self, NodeRef, ProjectRef};
|
||||
use crate::project::format::InterchangeFormat;
|
||||
use crate::project::load::ProjectLoadBaseTask;
|
||||
use crate::task::{Task, TaskBehavior};
|
||||
|
||||
/// Callback used to confirm whether the sequences of an OTIO document should
|
||||
/// be imported, mirroring `ImportConfirmFn` in loadotio.h (receives the
|
||||
/// sequence labels in order; return true to accept).
|
||||
pub type ImportConfirmFn = Box<dyn FnMut(&[String]) -> bool + Send>;
|
||||
|
||||
/// Global import-confirmation callback, mirroring the C++ static
|
||||
/// `LoadOTIOTask::confirm_callback_` (loadotio.h). When unset, everything is
|
||||
/// imported (the headless default).
|
||||
static CONFIRM_CALLBACK: Mutex<Option<ImportConfirmFn>> = Mutex::new(None);
|
||||
|
||||
/// Register (or clear, with `None`) the global import-confirmation callback.
|
||||
///
|
||||
/// CPP-PARITY: src/task/src/project/loadotio/loadotio.h
|
||||
/// (`LoadOTIOTask::set_import_confirm_callback`)
|
||||
pub fn set_import_confirm_callback(cb: Option<ImportConfirmFn>) {
|
||||
*CONFIRM_CALLBACK.lock().unwrap() = cb;
|
||||
}
|
||||
|
||||
/// An OTIO project loader.
|
||||
pub struct LoadOTIOTask {
|
||||
/// The base load task (owns the filename and yields the project).
|
||||
pub base: ProjectLoadBaseTask,
|
||||
}
|
||||
|
||||
impl LoadOTIOTask {
|
||||
/// Create an OTIO loader for the given base load task.
|
||||
pub fn new(base: ProjectLoadBaseTask) -> LoadOTIOTask {
|
||||
LoadOTIOTask { base }
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskBehavior for LoadOTIOTask {
|
||||
/// Load and parse the document (`oakotio`), then convert it into the
|
||||
/// project stored on the base task.
|
||||
fn run(&mut self, task: &mut Task) -> Result<()> {
|
||||
// Dispatch the interchange format from the filename extension.
|
||||
// Format handling ends here: `parse_timelines` returns one
|
||||
// `oak_otio::Timeline` per sequence whatever the source format, so
|
||||
// the project building below is shared between `.otio` and
|
||||
// `.fcpxml` (C++ parity for the track/clip/footage code).
|
||||
let format = match InterchangeFormat::of(&self.base.filename) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
if let Error::Failed(msg) = &e {
|
||||
task.set_error(msg);
|
||||
}
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
let timelines = parse_timelines(task, &self.base.filename, format)?;
|
||||
|
||||
// Build the project directly through the oaknode domain model
|
||||
// (the deleted `oaknode_project_init` stub is gone).
|
||||
let project: ProjectRef = oak_node::project::Project::new();
|
||||
{
|
||||
let mut guard = project.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Err(e) = guard.initialize() {
|
||||
let _ = e;
|
||||
task.set_error("Failed to create project");
|
||||
return Err(Error::Failed("Failed to create project".to_string()));
|
||||
}
|
||||
guard.set_modified(true);
|
||||
}
|
||||
|
||||
// Keep track of imported footage
|
||||
let mut imported_footage: HashMap<String, NodeRef> = HashMap::new();
|
||||
|
||||
// Generate a list of sequences with the same names as the timelines.
|
||||
// Assumes each timeline has a unique name.
|
||||
let mut unnamed_sequence_count = 0;
|
||||
let mut sequences: Vec<NodeRef> = Vec::new();
|
||||
|
||||
// Variables used for loading bar
|
||||
let mut number_of_clips: f64 = 0.0;
|
||||
|
||||
for timeline in &timelines {
|
||||
let Some(sequence) = nodeops::sequence_create(&project) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let label = if !timeline.name().is_empty() {
|
||||
timeline.name().to_string()
|
||||
} else {
|
||||
// If the otio timeline does not provide a name, create a
|
||||
// default one here.
|
||||
unnamed_sequence_count += 1;
|
||||
format!("Sequence {unnamed_sequence_count}")
|
||||
};
|
||||
nodeops::set_node_label(&project, sequence, &label);
|
||||
|
||||
// Get number of clips for loading bar
|
||||
for track in timeline.tracks().children() {
|
||||
if let Some(otio_track) = track.as_track() {
|
||||
number_of_clips += otio_track.children().len() as f64;
|
||||
}
|
||||
}
|
||||
|
||||
sequences.push((project.clone(), sequence));
|
||||
}
|
||||
if number_of_clips <= 0.0 {
|
||||
number_of_clips = 1.0;
|
||||
}
|
||||
|
||||
// Ask the user which sequences to import (facade callback; headless
|
||||
// default accepts everything).
|
||||
let sequence_names: Vec<String> = sequences
|
||||
.iter()
|
||||
.map(|(p, s)| nodeops::node_label(p, *s))
|
||||
.collect();
|
||||
let mut confirm = CONFIRM_CALLBACK.lock().unwrap().take();
|
||||
let accepted = match confirm.as_mut() {
|
||||
Some(cb) => cb(&sequence_names),
|
||||
None => true,
|
||||
};
|
||||
|
||||
if !accepted {
|
||||
// Cancel to indicate to caller that this task did not complete
|
||||
// and to simply dispose of it. The project is never handed to the
|
||||
// base task (the C++ base-task destructor does the same).
|
||||
task.cancel();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let root_folder = {
|
||||
let guard = project.lock().unwrap_or_else(|e| e.into_inner());
|
||||
guard.root
|
||||
};
|
||||
let mut clips_done = 0.0f64;
|
||||
|
||||
for (timeline, (_, sequence)) in timelines.iter().zip(&sequences) {
|
||||
let sequence_node = *sequence;
|
||||
|
||||
let mut add_seq = nodeops::folder_add_child_command(
|
||||
(project.clone(), root_folder),
|
||||
(project.clone(), sequence_node),
|
||||
);
|
||||
add_seq.redo_now();
|
||||
|
||||
// Create a folder for this sequence's footage
|
||||
let sequence_footage = nodeops::folder_create(&project);
|
||||
if let Some(folder_id) = sequence_footage {
|
||||
nodeops::set_node_label(&project, folder_id, timeline.name());
|
||||
let mut add_folder = nodeops::folder_add_child_command(
|
||||
(project.clone(), root_folder),
|
||||
(project.clone(), folder_id),
|
||||
);
|
||||
add_folder.redo_now();
|
||||
}
|
||||
|
||||
// Iterate through tracks
|
||||
for track_composable in timeline.tracks().children() {
|
||||
let Some(otio_track) = track_composable.as_track() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Determine what kind of track it is
|
||||
let track_type = match otio_track.kind() {
|
||||
"Video" => TrackType::Video,
|
||||
"Audio" => TrackType::Audio,
|
||||
other => {
|
||||
eprintln!("Found unknown track type: {other}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new track
|
||||
let Some(track_list) =
|
||||
nodeops::sequence_track_list(&project, sequence_node, track_type)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let mut add_track =
|
||||
nodeops::add_track_command(project.clone(), track_list);
|
||||
add_track.redo_now();
|
||||
|
||||
let track_count = nodeops::tracklist_track_count(&project, track_list);
|
||||
let track = if track_count > 0 {
|
||||
nodeops::tracklist_track_at(&project, track_list, track_count - 1)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let Some(track) = track else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Get clips from track
|
||||
let mut previous_block: Option<NodeId> = None;
|
||||
let mut prev_block_transition = false;
|
||||
|
||||
for otio_block in otio_track.children() {
|
||||
if task.is_cancelled() {
|
||||
break;
|
||||
}
|
||||
|
||||
let block_kind = match otio_block.schema_name() {
|
||||
"Clip" => nodeops::BlockKind::Clip,
|
||||
"Gap" => nodeops::BlockKind::Gap,
|
||||
"Transition" => {
|
||||
// Todo: Look into OTIO supported transitions and add
|
||||
// them to Oak.
|
||||
nodeops::BlockKind::Transition
|
||||
}
|
||||
other => {
|
||||
// We don't know what this is yet, just create a gap
|
||||
// for now so that *something* is there.
|
||||
eprintln!("Found unknown block type: {other}");
|
||||
nodeops::BlockKind::Gap
|
||||
}
|
||||
};
|
||||
let Some(block) = nodeops::block_create(&project, block_kind) else {
|
||||
continue;
|
||||
};
|
||||
let block_node = block;
|
||||
nodeops::set_node_label(&project, block_node, otio_block.name());
|
||||
nodeops::track_append_block(&project, track, block_node);
|
||||
|
||||
if otio_block.schema_name() == "Clip" || otio_block.schema_name() == "Gap" {
|
||||
if let Some(source_range) = otio_block.source_range() {
|
||||
let start_seconds = source_range.start_time().to_seconds();
|
||||
let duration_seconds = source_range.duration().to_seconds();
|
||||
|
||||
let start_time = oak_core::Rational::from_double(start_seconds);
|
||||
let duration = oak_core::Rational::from_double(duration_seconds);
|
||||
|
||||
if otio_block.schema_name() == "Clip" {
|
||||
nodeops::clip_set_media_in(
|
||||
&project,
|
||||
block_node,
|
||||
start_time.numerator(),
|
||||
start_time.denominator(),
|
||||
);
|
||||
}
|
||||
nodeops::block_set_length_and_media_out(
|
||||
&project,
|
||||
block_node,
|
||||
duration.numerator(),
|
||||
duration.denominator(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If the previous block was a transition, connect the
|
||||
// current block to it.
|
||||
if prev_block_transition {
|
||||
if let Some(prev) = previous_block {
|
||||
nodeops::node_connect(
|
||||
&project,
|
||||
block_node,
|
||||
prev,
|
||||
nodeops::TRANSITION_IN_BLOCK_INPUT,
|
||||
);
|
||||
}
|
||||
prev_block_transition = false;
|
||||
}
|
||||
|
||||
if let Some(otio_transition) = otio_block.as_transition() {
|
||||
// Set how far the transition eats into the previous
|
||||
// clip.
|
||||
let in_offset = otio_transition.in_offset().to_rational();
|
||||
let out_offset = otio_transition.out_offset().to_rational();
|
||||
nodeops::transition_set_offsets_and_length(
|
||||
&project,
|
||||
block_node,
|
||||
in_offset.numerator(),
|
||||
in_offset.denominator(),
|
||||
out_offset.numerator(),
|
||||
out_offset.denominator(),
|
||||
);
|
||||
|
||||
if let Some(prev) = previous_block {
|
||||
nodeops::node_connect(
|
||||
&project,
|
||||
prev,
|
||||
block_node,
|
||||
nodeops::TRANSITION_OUT_BLOCK_INPUT,
|
||||
);
|
||||
}
|
||||
prev_block_transition = true;
|
||||
|
||||
// Position transition in its own context.
|
||||
set_own_context_position(&project, block_node);
|
||||
}
|
||||
|
||||
if otio_block.schema_name() == "Gap" {
|
||||
// Position gap in its own context.
|
||||
set_own_context_position(&project, block_node);
|
||||
}
|
||||
|
||||
// Update this after it's used but before any continue
|
||||
// statements.
|
||||
previous_block = Some(block_node);
|
||||
|
||||
if otio_block.schema_name() == "Clip" {
|
||||
let Some(otio_clip) = otio_block.as_clip() else {
|
||||
continue;
|
||||
};
|
||||
let Some(media_reference) = otio_clip.media_reference() else {
|
||||
continue;
|
||||
};
|
||||
if let Some(external) = media_reference.as_external_reference() {
|
||||
// Link footage
|
||||
let footage_url = external.target_url().to_string();
|
||||
|
||||
let probed_item: Option<NodeRef> =
|
||||
if let Some(existing) = imported_footage.get(&footage_url) {
|
||||
Some(existing.clone())
|
||||
} else {
|
||||
let created =
|
||||
nodeops::footage_create(&project, Some(&footage_url));
|
||||
if let Some(created) = created {
|
||||
imported_footage.insert(
|
||||
footage_url.clone(),
|
||||
(project.clone(), created),
|
||||
);
|
||||
|
||||
let label = Path::new(&footage_url)
|
||||
.file_name()
|
||||
.map(|n| n.to_string_lossy().into_owned())
|
||||
.unwrap_or_default();
|
||||
nodeops::set_node_label(&project, created, &label);
|
||||
|
||||
if let Some(folder_id) = sequence_footage {
|
||||
let mut add_footage =
|
||||
nodeops::folder_add_child_command(
|
||||
(project.clone(), folder_id),
|
||||
(project.clone(), created),
|
||||
);
|
||||
add_footage.redo_now();
|
||||
}
|
||||
}
|
||||
created.map(|id| (project.clone(), id))
|
||||
};
|
||||
|
||||
if let Some((_, probed_id)) = probed_item {
|
||||
// Position clip in its own context.
|
||||
set_own_context_position(&project, block_node);
|
||||
|
||||
// Position footage in its context.
|
||||
nodeops::node_set_context_position(
|
||||
&project, block_node, probed_id, -2.0, 0.0, false,
|
||||
);
|
||||
|
||||
// Record the clip-footage link in the domain
|
||||
// model (the C++ finds footage through the
|
||||
// input chain; the Rust clip records it).
|
||||
nodeops::clip_set_footage(&project, block_node, probed_id);
|
||||
|
||||
if track_type == TrackType::Video {
|
||||
if let Some(transform) = factory_create(
|
||||
&project,
|
||||
nodeops::TRANSFORM_TYPE_ID,
|
||||
) {
|
||||
nodeops::node_connect(
|
||||
&project,
|
||||
probed_id,
|
||||
transform,
|
||||
"tex_in",
|
||||
);
|
||||
nodeops::node_connect(
|
||||
&project,
|
||||
transform,
|
||||
block_node,
|
||||
nodeops::CLIP_TEXTURE_INPUT,
|
||||
);
|
||||
nodeops::node_set_context_position(
|
||||
&project, block_node, transform, -1.0, 0.0, false,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if let Some(volume) =
|
||||
factory_create(&project, nodeops::VOLUME_TYPE_ID)
|
||||
{
|
||||
nodeops::node_connect(
|
||||
&project,
|
||||
probed_id,
|
||||
volume,
|
||||
"samples_in",
|
||||
);
|
||||
nodeops::node_connect(
|
||||
&project,
|
||||
volume,
|
||||
block_node,
|
||||
nodeops::CLIP_TEXTURE_INPUT,
|
||||
);
|
||||
nodeops::node_set_context_position(
|
||||
&project, block_node, volume, -1.0, 0.0, false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clips_done += 1.0;
|
||||
task.emit_progress(clips_done / number_of_clips);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.base.store_project(project);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a node from the factory registry (`oaknode_factory_create_from_id`).
|
||||
fn factory_create(project: &ProjectRef, type_id: &str) -> Option<NodeId> {
|
||||
let meta = oak_node::factory::Factory::global().find(type_id)?;
|
||||
let (core, behavior) = (meta.create)();
|
||||
let mut guard = project.lock().unwrap_or_else(|e| e.into_inner());
|
||||
Some(guard.graph.add_node(core, behavior))
|
||||
}
|
||||
|
||||
/// Set the node's position in its own context (the C++
|
||||
/// `set_own_context_position` helper in loadotio.cpp).
|
||||
fn set_own_context_position(project: &ProjectRef, node: NodeId) {
|
||||
nodeops::node_set_context_position(project, node, node, 0.0, 0.0, false);
|
||||
}
|
||||
|
||||
/// Parse the document into one `oak_otio::Timeline` per sequence, dispatching
|
||||
/// on the filename extension:
|
||||
///
|
||||
/// - `.otio`: OpenTimelineIO JSON. A `Timeline` root yields one timeline, a
|
||||
/// `SerializableCollection` yields one timeline per `Timeline` child, and
|
||||
/// any other root is the C++ "Unknown OpenTimelineIO root element" error.
|
||||
/// - `.fcpxml`: FCPXML (`oak_otio::fcpxml`), one timeline per `<sequence>`.
|
||||
///
|
||||
/// Format handling ends here — the caller builds the project from the
|
||||
/// returned timelines regardless of the source format (C++ parity), so the
|
||||
/// track/clip/footage code never forks.
|
||||
fn parse_timelines(
|
||||
task: &mut Task,
|
||||
filename: &str,
|
||||
format: InterchangeFormat,
|
||||
) -> Result<Vec<oak_otio::Timeline>> {
|
||||
match format {
|
||||
InterchangeFormat::OtioJson => {
|
||||
let root = oak_otio::from_json_file(filename).map_err(|e| {
|
||||
task.set_error(&format!(
|
||||
"Failed to load OpenTimelineIO from file \"{}\" \n\nOpenTimelineIO Error:\n\n{}",
|
||||
filename, e
|
||||
));
|
||||
Error::Failed("Failed to load OpenTimelineIO".to_string())
|
||||
})?;
|
||||
match &root {
|
||||
Serializable::SerializableCollection(collection) => Ok(collection
|
||||
.children()
|
||||
.iter()
|
||||
.filter_map(|child| child.as_timeline().cloned())
|
||||
.collect()),
|
||||
Serializable::Timeline(timeline) => Ok(vec![timeline.clone()]),
|
||||
_ => {
|
||||
task.set_error("Unknown OpenTimelineIO root element");
|
||||
Err(Error::Failed(
|
||||
"Unknown OpenTimelineIO root element".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
InterchangeFormat::Fcpxml => oak_otio::from_fcpxml_file(filename).map_err(|e| {
|
||||
task.set_error(&format!(
|
||||
"Failed to load FCPXML from file \"{}\" \n\nFCPXML Error:\n\n{}",
|
||||
filename, e
|
||||
));
|
||||
Error::Failed("Failed to load FCPXML".to_string())
|
||||
}),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak 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/>.
|
||||
|
||||
//! `ProjectSaveTask`, mirroring `src/task/src/project/save/save.h`.
|
||||
//!
|
||||
//! Serializes a borrowed `oak_node::project::Project` to an `.oakproj` file
|
||||
//! via the direct Rust serializer (`oak_node::serializer::save` —
|
||||
//! single-lib unification; the old oaknode serializer C ABI with its
|
||||
//! overwrite/compression result ladder is gone, so the overwrite-as-else
|
||||
//! path collapses into a plain write). Optionally writes to an override
|
||||
//! filename.
|
||||
//!
|
||||
//! CPP-PARITY: src/task/src/project/save/save.h
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use oak_node::project::Project;
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::task::{Task, TaskBehavior};
|
||||
|
||||
/// A project-save task. Borrows its project and never takes ownership.
|
||||
pub struct ProjectSaveTask {
|
||||
/// The shared task base.
|
||||
pub base: Task,
|
||||
/// Borrowed project to save (`Arc<Mutex<Project>>`).
|
||||
pub project: Arc<Mutex<Project>>,
|
||||
/// Optional override filename; when empty the project's own filename is
|
||||
/// used.
|
||||
pub override_filename: Option<String>,
|
||||
/// Whether to compress the serialized output. The direct serializer has
|
||||
/// no compression mode (the old C ABI compression path is gone), so
|
||||
/// this flag is retained for API parity but ignored.
|
||||
pub use_compression: bool,
|
||||
}
|
||||
|
||||
impl ProjectSaveTask {
|
||||
/// Set the output filename override.
|
||||
pub fn set_override_filename(&mut self, filename: &str) {
|
||||
self.override_filename = Some(filename.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskBehavior for ProjectSaveTask {
|
||||
/// Serialize the project via the direct oaknode serializer
|
||||
/// (`oak_node::serializer::save`) to the resolved filename.
|
||||
fn run(&mut self, task: &mut Task) -> Result<()> {
|
||||
let using_filename = match &self.override_filename {
|
||||
Some(name) => name.clone(),
|
||||
None => self
|
||||
.project
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
.filename()
|
||||
.to_string(),
|
||||
};
|
||||
|
||||
if using_filename.is_empty() {
|
||||
task.set_error("Project has no filename to save to.");
|
||||
return Err(Error::Failed(
|
||||
"Project has no filename to save to.".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let xml = match oak_node::serializer::save(
|
||||
&self.project.lock().unwrap_or_else(|e| e.into_inner()),
|
||||
) {
|
||||
Ok(xml) => xml,
|
||||
Err(e) => {
|
||||
let _ = e;
|
||||
task.set_error("Failed to write XML data.");
|
||||
return Err(Error::Failed("Failed to save project".to_string()));
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(e) = std::fs::write(&using_filename, xml) {
|
||||
task.set_error(&format!("Failed to open file for writing: {e}"));
|
||||
return Err(Error::Failed("Failed to save project".to_string()));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,447 @@
|
||||
// Oak Video Editor - Non-Linear Video Editor
|
||||
// Copyright (C) 2026 Oak 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/>.
|
||||
|
||||
//! `SaveOTIOTask`, mirroring `src/task/src/project/saveotio/saveotio.h`.
|
||||
//!
|
||||
//! Serializes a borrowed project to an OpenTimelineIO (`.otio`) or FCPXML
|
||||
//! (`.fcpxml`) file through the pure-Rust `oakotio` binding (see `README`
|
||||
//! decision #6): the project's sequences become `OTIO::Timeline`s
|
||||
//! (`serialize_timeline` / `serialize_track` / `serialize_track_list`),
|
||||
//! exactly like the C++ `serialize_*` helpers. The format is dispatched
|
||||
//! from the filename extension (see [`crate::project::format`]) at the
|
||||
//! final write only — the serialization itself is shared.
|
||||
//!
|
||||
//! **Single-lib note**: the project graph is read through the direct
|
||||
//! oaknode domain operations in [`crate::nodeops`] (folder children,
|
||||
//! sequence track lists, track blocks, footage parameters) instead of the
|
||||
//! deleted oaknode C ABI stubs; the project is an
|
||||
//! `Arc<Mutex<oak_node::project::Project>>` instead of a borrowed `CHandle`.
|
||||
//!
|
||||
//! CPP-PARITY: src/task/src/project/saveotio/saveotio.cpp
|
||||
|
||||
use oak_core::Rational;
|
||||
use oak_node::id::NodeId;
|
||||
use oak_node::track::TrackType;
|
||||
use oak_otio::{
|
||||
Clip, Composable, ExternalReference, Gap, MediaReference, RationalTime, Serializable,
|
||||
SerializableCollection, TimeRange, Timeline, Track, Transition,
|
||||
};
|
||||
|
||||
use crate::error::{Error, Result};
|
||||
use crate::nodeops::{self, ProjectRef};
|
||||
use crate::project::format::InterchangeFormat;
|
||||
use crate::task::{Task, TaskBehavior};
|
||||
|
||||
/// `Rational(INT_MIN)` — the initial "no track yet" maximum length
|
||||
/// (`RATIONAL_MIN` in saveotio.cpp).
|
||||
fn rational_min() -> Rational {
|
||||
Rational::new(-2147483647, 1)
|
||||
}
|
||||
|
||||
/// An OTIO project-save task. Borrows its project.
|
||||
pub struct SaveOTIOTask {
|
||||
/// The shared task base.
|
||||
pub base: Task,
|
||||
/// Borrowed project to save (domain project).
|
||||
pub project: ProjectRef,
|
||||
/// Output OTIO filename.
|
||||
pub filename: String,
|
||||
}
|
||||
|
||||
impl SaveOTIOTask {
|
||||
/// Serialize one sequence into an `OTIO::Timeline`; `None` when the
|
||||
/// sequence has no usable frame rate or a track fails to serialize.
|
||||
///
|
||||
/// CPP-PARITY: saveotio.cpp (SaveOTIOTask::serialize_timeline)
|
||||
fn serialize_timeline(project: &ProjectRef, sequence: NodeId) -> Option<Timeline> {
|
||||
let mut otio_timeline =
|
||||
Timeline::new(nodeops::node_label(project, sequence));
|
||||
|
||||
// Direct video-params value type (single-lib unification); absent
|
||||
// params leave rate at 0.0 → the documented `None` path.
|
||||
let (num, den) = nodeops::sequence_video_params(project, sequence, 0)
|
||||
.map(|vp| vp.frame_rate())
|
||||
.unwrap_or((0, 1));
|
||||
let mut rate = 0.0f64;
|
||||
if den != 0 {
|
||||
rate = num as f64 / den as f64;
|
||||
}
|
||||
if rate.is_nan() || rate <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let video_list = nodeops::sequence_track_list(project, sequence, TrackType::Video);
|
||||
let audio_list = nodeops::sequence_track_list(project, sequence, TrackType::Audio);
|
||||
|
||||
if let Some(list) = video_list {
|
||||
if !Self::serialize_track_list(project, list, &mut otio_timeline, rate) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
if let Some(list) = audio_list {
|
||||
if !Self::serialize_track_list(project, list, &mut otio_timeline, rate) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
Some(otio_timeline)
|
||||
}
|
||||
|
||||
/// Serialize all tracks of one track list (video or audio) into the
|
||||
/// timeline. Each track is padded to the list's maximum track length.
|
||||
///
|
||||
/// CPP-PARITY: saveotio.cpp (SaveOTIOTask::serialize_track_list)
|
||||
fn serialize_track_list(
|
||||
project: &ProjectRef,
|
||||
list: NodeId,
|
||||
otio_timeline: &mut Timeline,
|
||||
sequence_rate: f64,
|
||||
) -> bool {
|
||||
let mut max_track_length = rational_min();
|
||||
|
||||
let track_count = nodeops::tracklist_track_count(project, list);
|
||||
|
||||
for i in 0..track_count {
|
||||
if let Some(track) = nodeops::tracklist_track_at(project, list, i) {
|
||||
let length = nodeops::track_length(project, track);
|
||||
if length > max_track_length {
|
||||
max_track_length = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i in 0..track_count {
|
||||
let Some(track) = nodeops::tracklist_track_at(project, list, i) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let Some(otio_track) =
|
||||
Self::serialize_track(project, track, sequence_rate, max_track_length)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
otio_timeline
|
||||
.tracks_mut()
|
||||
.append_child(Composable::Track(otio_track));
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
/// Serialize one track: a `Track` whose kind matches the native track
|
||||
/// type, one OTIO block per native block, plus a trailing `Gap` when the
|
||||
/// track is shorter than `max_track_length`.
|
||||
///
|
||||
/// CPP-PARITY: saveotio.cpp (SaveOTIOTask::serialize_track)
|
||||
fn serialize_track(
|
||||
project: &ProjectRef,
|
||||
track: NodeId,
|
||||
sequence_rate: f64,
|
||||
max_track_length: Rational,
|
||||
) -> Option<Track> {
|
||||
let track_type = nodeops::track_type(project, track)?;
|
||||
|
||||
let kind = match track_type {
|
||||
TrackType::Video => "Video",
|
||||
TrackType::Audio => "Audio",
|
||||
TrackType::Subtitle => {
|
||||
eprintln!(
|
||||
"Don't know OTIO track kind for native type {}",
|
||||
track_type.to_c()
|
||||
);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let mut otio_track = Track::new(kind);
|
||||
|
||||
let block_count = nodeops::track_block_count(project, track);
|
||||
|
||||
for i in 0..block_count {
|
||||
let Some(block) = nodeops::track_block_at(project, track, i) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let kind = nodeops::block_kind(project, block);
|
||||
|
||||
let otio_block: Option<Composable> = match kind {
|
||||
nodeops::BlockKind::Clip => {
|
||||
let mut otio_clip = Clip::new(nodeops::node_label(project, block));
|
||||
|
||||
otio_clip.set_source_range(TimeRange::new(
|
||||
RationalTime::from_rational(block_in_of(project, block), sequence_rate),
|
||||
RationalTime::from_rational(block_length_of(project, block), sequence_rate),
|
||||
));
|
||||
|
||||
let media = nodeops::node_find_input_footage(project, block);
|
||||
if let Some(media) = media {
|
||||
let available_range = if track_type == TrackType::Video {
|
||||
// OTIO ExternalReference uses the source clips
|
||||
// frame rate (or sample rate) as opposed to the
|
||||
// sequences rate.
|
||||
let (source_frame_rate, duration) =
|
||||
nodeops::footage_video_params(project, media, 0)
|
||||
.map(|vp| {
|
||||
let (num, den) = vp.frame_rate();
|
||||
let rate = if den != 0 {
|
||||
num as f64 / den as f64
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
(rate, vp.duration() as f64)
|
||||
})
|
||||
.unwrap_or((0.0, 0.0));
|
||||
TimeRange::new(
|
||||
RationalTime::new(0.0, source_frame_rate),
|
||||
RationalTime::new(duration, source_frame_rate),
|
||||
)
|
||||
} else {
|
||||
TimeRange::new(
|
||||
RationalTime::new(0.0, 48000.0),
|
||||
RationalTime::new(0.0, 48000.0),
|
||||
)
|
||||
};
|
||||
|
||||
let media_url = nodeops::footage_filename(project, media);
|
||||
if !media_url.is_empty() {
|
||||
otio_clip.set_media_reference(MediaReference::ExternalReference(
|
||||
ExternalReference::new(media_url, Some(available_range)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Some(Composable::Clip(otio_clip))
|
||||
}
|
||||
nodeops::BlockKind::Gap => Some(Composable::Gap(Gap::new(
|
||||
TimeRange::new(
|
||||
RationalTime::from_rational(block_in_of(project, block), 24.0),
|
||||
RationalTime::from_rational(block_length_of(project, block), 24.0),
|
||||
),
|
||||
nodeops::node_label(project, block),
|
||||
))),
|
||||
nodeops::BlockKind::Transition => {
|
||||
let mut otio_transition =
|
||||
Transition::new(nodeops::node_label(project, block));
|
||||
|
||||
let n = transition_offset_of(project, block, true);
|
||||
otio_transition.set_in_offset(RationalTime::from_rational(n, 24.0));
|
||||
let n = transition_offset_of(project, block, false);
|
||||
otio_transition.set_out_offset(RationalTime::from_rational(n, 24.0));
|
||||
|
||||
Some(Composable::Transition(otio_transition))
|
||||
}
|
||||
nodeops::BlockKind::Other => None,
|
||||
};
|
||||
|
||||
let Some(otio_block) = otio_block else {
|
||||
// We shouldn't ever get here, but catch without crashing if
|
||||
// we ever do.
|
||||
return None;
|
||||
};
|
||||
|
||||
otio_track.append_child(otio_block);
|
||||
}
|
||||
|
||||
// All OTIO tracks must have the same duration so we add a Gap to
|
||||
// fill the remaining time.
|
||||
let duration = track_duration(&otio_track);
|
||||
let duration_seconds = duration.clone().to_seconds();
|
||||
if duration_seconds < max_track_length.to_f64() {
|
||||
let time_left = max_track_length.to_f64() - duration_seconds;
|
||||
|
||||
let gap = Gap::new(
|
||||
TimeRange::new(duration, RationalTime::new(time_left, 1.0)),
|
||||
"",
|
||||
);
|
||||
otio_track.append_child(Composable::Gap(gap));
|
||||
}
|
||||
|
||||
Some(otio_track)
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskBehavior for SaveOTIOTask {
|
||||
/// Serialize the project to OTIO/FCPXML via `oakotio` and write the file.
|
||||
fn run(&mut self, task: &mut Task) -> Result<()> {
|
||||
// Dispatch the interchange format from the filename extension.
|
||||
// Format handling ends at the write below — the serialization
|
||||
// produces `oak_otio::Timeline`s and is shared between `.otio` and
|
||||
// `.fcpxml` (C++ parity for the serialize_* helpers).
|
||||
let format = match InterchangeFormat::of(&self.filename) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
if let Error::Failed(msg) = &e {
|
||||
task.set_error(msg);
|
||||
}
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
// Collect sequences from the root folder (non-recursive, matching
|
||||
// the original list_children_of_type behavior closely enough for
|
||||
// OTIO).
|
||||
let root = {
|
||||
let guard = self.project.lock().unwrap_or_else(|e| e.into_inner());
|
||||
guard.root
|
||||
};
|
||||
if !root.valid() {
|
||||
task.set_error("Project contains no sequences to export.");
|
||||
return Err(Error::Failed(
|
||||
"Project contains no sequences to export.".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let mut sequences: Vec<NodeId> = Vec::new();
|
||||
{
|
||||
let guard = self.project.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(entry) = guard.graph.get(root) else {
|
||||
task.set_error("Project contains no sequences to export.");
|
||||
return Err(Error::Failed(
|
||||
"Project contains no sequences to export.".to_string(),
|
||||
));
|
||||
};
|
||||
let Some(folder) = entry
|
||||
.behavior
|
||||
.as_any()
|
||||
.and_then(|a| a.downcast_ref::<oak_node::folder::FolderBehavior>())
|
||||
else {
|
||||
task.set_error("Project contains no sequences to export.");
|
||||
return Err(Error::Failed(
|
||||
"Project contains no sequences to export.".to_string(),
|
||||
));
|
||||
};
|
||||
for child in &folder.children {
|
||||
if let Some(child_entry) = guard.graph.get(*child) {
|
||||
if child_entry.behavior.type_id() == nodeops::SEQUENCE_TYPE_ID {
|
||||
sequences.push(*child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if sequences.is_empty() {
|
||||
task.set_error("Project contains no sequences to export.");
|
||||
return Err(Error::Failed(
|
||||
"Project contains no sequences to export.".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
let mut serialized: Vec<Timeline> = Vec::with_capacity(sequences.len());
|
||||
for sequence in &sequences {
|
||||
match Self::serialize_timeline(&self.project, *sequence) {
|
||||
Some(timeline) => serialized.push(timeline),
|
||||
None => {
|
||||
task.set_error(&format!(
|
||||
"Failed to serialize sequence \"{}\"",
|
||||
nodeops::node_label(&self.project, *sequence)
|
||||
));
|
||||
return Err(Error::Failed("Failed to serialize sequence".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write the serialized timelines, dispatching on the format: OTIO
|
||||
// JSON writes a `Timeline` root for one sequence or a
|
||||
// `SerializableCollection` for several; FCPXML writes all timelines
|
||||
// into one document (one `<project>` per timeline).
|
||||
let result: std::result::Result<(), String> = match format {
|
||||
InterchangeFormat::OtioJson => {
|
||||
if serialized.len() == 1 {
|
||||
serialized[0]
|
||||
.to_json_file(&self.filename)
|
||||
.map_err(|e| e.to_string())
|
||||
} else {
|
||||
// Serialize all into a SerializableCollection.
|
||||
let collection = SerializableCollection::new(
|
||||
"Sequences",
|
||||
serialized.into_iter().map(Serializable::Timeline).collect(),
|
||||
);
|
||||
Serializable::SerializableCollection(collection)
|
||||
.to_json_file(&self.filename)
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
}
|
||||
InterchangeFormat::Fcpxml => {
|
||||
oak_otio::to_fcpxml_file(&serialized, &self.filename).map_err(|e| e.to_string())
|
||||
}
|
||||
};
|
||||
|
||||
result.map_err(|e| {
|
||||
let (label, what) = match format {
|
||||
InterchangeFormat::OtioJson => (
|
||||
"Failed to save OpenTimelineIO to file",
|
||||
"Failed to save OpenTimelineIO",
|
||||
),
|
||||
InterchangeFormat::Fcpxml => {
|
||||
("Failed to save FCPXML to file", "Failed to save FCPXML")
|
||||
}
|
||||
};
|
||||
task.set_error(&format!("{label} \"{}\": {e}", self.filename));
|
||||
Error::Failed(what.to_string())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// The block's in point as a `Rational` (default 0/1 when unset).
|
||||
fn block_in_of(project: &ProjectRef, block: NodeId) -> Rational {
|
||||
nodeops::block_in(project, block)
|
||||
}
|
||||
|
||||
/// The block's length as a `Rational` (default 0/1 when unset).
|
||||
fn block_length_of(project: &ProjectRef, block: NodeId) -> Rational {
|
||||
nodeops::block_length(project, block)
|
||||
}
|
||||
|
||||
/// A transition's in (`in_offset == true`) or out offset as a `Rational`.
|
||||
fn transition_offset_of(project: &ProjectRef, block: NodeId, in_offset: bool) -> Rational {
|
||||
if in_offset {
|
||||
nodeops::transition_in_offset(project, block)
|
||||
} else {
|
||||
nodeops::transition_out_offset(project, block)
|
||||
}
|
||||
}
|
||||
|
||||
/// The serialized track's duration as an `OTIO::RationalTime` — the sum of
|
||||
/// its children's source-range durations, keeping the first child's rate
|
||||
/// (the C++ `otio_track->duration(&es)` result for contiguous children).
|
||||
fn track_duration(track: &Track) -> RationalTime {
|
||||
let mut acc: Option<RationalTime> = None;
|
||||
for child in track.children() {
|
||||
let duration = match child
|
||||
.as_clip()
|
||||
.and_then(|c| c.source_range())
|
||||
.map(|r| r.duration())
|
||||
.or_else(|| {
|
||||
child
|
||||
.as_gap()
|
||||
.and_then(|g| g.source_range())
|
||||
.map(|r| r.duration())
|
||||
}) {
|
||||
Some(d) => d,
|
||||
// Transitions occupy no time.
|
||||
None => RationalTime::new(0.0, 1.0),
|
||||
};
|
||||
match acc {
|
||||
None => acc = Some(duration),
|
||||
Some(a) => {
|
||||
let rate = a.rate();
|
||||
let value = a.value() + duration.rescaled_to(rate).value();
|
||||
acc = Some(RationalTime::new(value, rate));
|
||||
}
|
||||
}
|
||||
}
|
||||
acc.unwrap_or_else(RationalTime::invalid_time)
|
||||
}
|
||||
Reference in New Issue
Block a user