feat(render,app): footage decode lands (M12 P0) + UI density pass

engine:
- oakrender eval footage hook decodes via oakcodec (JobSpec::Footage
  carries filename/stream); ticket/ffi/manager wiring, real-media
  decode test with programmatically generated MPEG-2
- oakrender bridge/codec.rs + node.rs: direct oakcodec/oaknode calls;
  the crate's dlsym module is gone (project_deep_copy/sync_copy remain
  documented always-fail stubs — never implemented in oaknode)
- oakaudio waveform/decoder path adjustments for the decode hook

app (gpui + gpui_widgets):
- menu bar scrubbing: hovering another top-level title while a menu is
  open switches to it; popup width is content-aware (CJK-aware) instead
  of fixed 160px
- density pass: window rem 16 -> 14px, menu rows 26 -> 22px, dock tabs
  32 -> 26px, viewer transport tightened
- open/import/save-as use the native platform file dialogs
  (prompt_for_paths / prompt_for_new_path; multi-select import);
  MockEngine records imported footage for tests
- project explorer Tree/Icons toggle is localized (explorer.tree /
  explorer.icons widget keys)
This commit is contained in:
2026-08-13 18:16:10 +08:00
parent 3625e37081
commit 5afa95c80e
227 changed files with 5851 additions and 65946 deletions
+2
View File
@@ -74,6 +74,8 @@ extern "C" {
) -> *mut c_void;
pub fn oakcore_audioparams_free(params: *mut c_void);
pub fn oakcore_audioparams_sample_rate(params: *const c_void) -> c_int;
/// `oakcore_audioparams_set_time_base` (host-provided).
pub fn oakcore_audioparams_set_time_base(params: *mut c_void, num: c_int, den: c_int);
pub fn oakcore_audioparams_channel_layout(params: *const c_void) -> u64;
pub fn oakcore_audioparams_format(params: *const c_void) -> c_int;
}
+10
View File
@@ -134,6 +134,8 @@ pub fn oakrender_ticket_render_audio(
mode: c_int,
cb: Option<unsafe extern "C" fn(CHandle, *mut c_void)>,
userdata: *mut c_void,
montage: *const oakrender::ffi::OakMontageClip,
montage_count: c_int,
) -> CHandle {
unsafe {
oakrender::ffi::ticket::oakrender_ticket_render_audio(
@@ -146,10 +148,18 @@ pub fn oakrender_ticket_render_audio(
mode,
cb,
userdata,
montage,
montage_count,
)
}
}
/// `oakrender_audio_samples_free` — release the samples block returned
/// by `oakrender_ticket_get_samples` (NULL no-op).
pub fn oakrender_audio_samples_free(samples: *mut c_void) {
unsafe { oakrender::ffi::ticket::oakrender_audio_samples_free(samples) }
}
/// Direct call into the `oakrender` crate (single-lib unification; the
/// `#[no_mangle]` export stays for the external C ABI).
pub fn oakrender_ticket_wait(ticket: CHandle) -> c_int {
+1
View File
@@ -79,6 +79,7 @@ pub mod node;
pub mod plugin;
pub mod render;
pub mod task;
pub mod testmedia;
pub mod timeline;
pub mod undo;
pub mod worker;
+363 -23
View File
@@ -117,6 +117,13 @@ struct RendererBox {
/// Unboxed output node handle (borrowed): a sequence, or any node the
/// module can evaluate (footage, generator, ...).
output_node: CHandle,
/// 1 when `output_node` is a sequence (its montage is built at render
/// time); 0 when it is a single node.
is_sequence: bool,
/// Footage spec resolved at create time (M12 P0): the filename +
/// video stream when `output_node` is a footage node. The
/// single-footage render path feeds these to the render ticket.
footage: Option<FootageSpec>,
/// Output width.
width: c_int,
/// Output height.
@@ -133,6 +140,14 @@ struct RendererBox {
last_error: String,
}
/// Resolved single-footage spec (filename + media stream).
struct FootageSpec {
/// Footage file path.
filename: String,
/// Media stream index (0 = first video stream).
stream_index: c_int,
}
/// Borrow the renderer box (NULL → Invalid).
unsafe fn renderer(ptr: *const OakEngineRenderer) -> Result<&'static RendererBox> {
unsafe {
@@ -188,6 +203,7 @@ unsafe fn make_video_params(b: &RendererBox) -> Result<CHandle> {
/// non-positive geometry/rate or a pixel format outside the oakcore enum.
unsafe fn make_renderer_box(
output_node: CHandle,
is_sequence: bool,
width: c_int,
height: c_int,
pixel_format: c_int,
@@ -210,8 +226,17 @@ unsafe fn make_renderer_box(
return Ok(std::ptr::null_mut());
}
let _ = crate::handle::read_cstr(output_colorspace); // resolved by the module at render time
// M12 P0: resolve the footage spec when the bound node is a
// footage node (single-node renderers only).
let footage = if !is_sequence {
resolve_footage(output_node).ok()
} else {
None
};
let boxed = Box::new(RendererBox {
output_node,
is_sequence,
footage,
width,
height,
pixel_format,
@@ -224,6 +249,214 @@ unsafe fn make_renderer_box(
}
}
/// Resolve `node` as a footage node: `(filename, stream_index)` when it
/// carries footage, an error otherwise.
unsafe fn resolve_footage(node: CHandle) -> Result<FootageSpec> {
unsafe {
let mut buf = [0 as c_char; 4096];
let rc = crate::bridge::node::oaknode_footage_filename(node, buf.as_mut_ptr(), buf.len() as c_int);
if rc < 0 {
return Err(Error::Failed("node is not footage".into()));
}
let filename = crate::handle::read_cstr(buf.as_ptr());
Ok(FootageSpec {
filename,
stream_index: 0,
})
}
}
/// Resolve a clip's media: `(filename, stream_index)` via the clip's
/// graph node → its upstream footage.
unsafe fn clip_media(clip: CHandle) -> Option<(String, c_int)> {
unsafe {
let node = crate::bridge::node::oaknode_block_as_node(clip);
if node.is_null() {
return None;
}
let mut footage = CHandle::null();
if crate::bridge::node::oaknode_node_find_input_footage(node, &mut footage) != 0
|| footage.is_null()
{
return None;
}
let mut buf = [0 as c_char; 4096];
if crate::bridge::node::oaknode_footage_filename(
footage,
buf.as_mut_ptr(),
buf.len() as c_int,
) < 0
{
return None;
}
let filename = crate::handle::read_cstr(buf.as_ptr());
Some((filename, 0))
}
}
/// Build the audio montage for `b` over `range` (M12 P1): every audio
/// clip overlapping the range, media times resolved from the clip
/// ranges, audio stream index 1. Returns the POD array plus the filename
/// CStrings that must outlive the render call.
unsafe fn build_audio_montage(
b: &RendererBox,
range: oakcore_rs::TimeRange,
) -> (Vec<MontagePod>, Vec<std::ffi::CString>) {
use crate::bridge::node as n;
unsafe {
let mut pods = Vec::new();
let mut names = Vec::new();
let seq = b.output_node;
let mut audio: c_int = 0;
let _ = n::oaknode_sequence_get_track_count(seq, 1, &mut audio);
let is_clip = |block: CHandle| {
let mut kind: c_int = 0;
n::oaknode_block_get_kind(block, &mut kind) == 0 && kind == 1
};
for track_index in 0..audio {
let mut track = CHandle::null();
if n::oaknode_sequence_get_track_at(seq, 1, track_index, &mut track) != 0
|| track.is_null()
{
continue;
}
let mut block_count: c_int = 0;
if n::oaknode_track_get_block_count(track, &mut block_count) != 0 {
continue;
}
for block_index in 0..block_count {
let mut block = CHandle::null();
if n::oaknode_track_get_block_at(track, block_index, &mut block) != 0
|| block.is_null()
|| !is_clip(block)
{
continue;
}
let mut in_num: c_int = 0;
let mut in_den: c_int = 0;
let mut out_num: c_int = 0;
let mut out_den: c_int = 0;
let mut mi_num: c_int = 0;
let mut mi_den: c_int = 0;
if n::oaknode_block_get_in(block, &mut in_num, &mut in_den) != 0
|| n::oaknode_block_get_out(block, &mut out_num, &mut out_den) != 0
|| n::oaknode_clip_get_media_in(block, &mut mi_num, &mut mi_den) != 0
{
continue;
}
let in_time = oakcore_rs::Rational::new(in_num as i64, in_den as i64);
let out_time = oakcore_rs::Rational::new(out_num as i64, out_den as i64);
if out_time <= range.in_() || in_time >= range.out() {
continue;
}
let Some((filename, _)) = clip_media(block) else {
continue;
};
let media_in = oakcore_rs::Rational::new(mi_num as i64, mi_den as i64);
let name = std::ffi::CString::new(filename).unwrap_or_default();
let ptr = name.as_ptr();
names.push(name);
pods.push(MontagePod {
filename: ptr,
stream_index: 1, // audio stream
in_num: in_time.numerator(),
in_den: in_time.denominator(),
out_num: out_time.numerator(),
out_den: out_time.denominator(),
media_in_num: media_in.numerator(),
media_in_den: media_in.denominator(),
gain: 1.0,
});
}
}
(pods, names)
}
}
/// The `OakMontageClip` POD the render module's ticket reads.
type MontagePod = oakrender::ffi::OakMontageClip;
/// Build the video montage for `b` at sequence time `time` (rational):
/// every clip covering `time` on video tracks, ordered bottom-to-top
/// (track index 0 is topmost → pushed last), media times resolved from
/// the clip ranges. Returns the POD array plus the filename CStrings
/// that must outlive the render call.
unsafe fn build_video_montage(
b: &RendererBox,
time: oakcore_rs::Rational,
) -> (Vec<MontagePod>, Vec<std::ffi::CString>) {
use crate::bridge::node as n;
unsafe {
let mut pods = Vec::new();
let mut names = Vec::new();
let seq = b.output_node;
let mut video: c_int = 0;
let _ = n::oaknode_sequence_get_track_count(seq, 0, &mut video);
// Clip-blocks only (gaps skipped), track index 0 = topmost.
let is_clip = |block: CHandle| {
let mut kind: c_int = 0;
n::oaknode_block_get_kind(block, &mut kind) == 0 && kind == 1
};
for track_index in (0..video).rev() {
let mut track = CHandle::null();
if n::oaknode_sequence_get_track_at(seq, 0, track_index, &mut track) != 0
|| track.is_null()
{
continue;
}
let mut block_count: c_int = 0;
if n::oaknode_track_get_block_count(track, &mut block_count) != 0 {
continue;
}
for block_index in 0..block_count {
let mut block = CHandle::null();
if n::oaknode_track_get_block_at(track, block_index, &mut block) != 0
|| block.is_null()
|| !is_clip(block)
{
continue;
}
let mut in_num: c_int = 0;
let mut in_den: c_int = 0;
let mut out_num: c_int = 0;
let mut out_den: c_int = 0;
let mut mi_num: c_int = 0;
let mut mi_den: c_int = 0;
if n::oaknode_block_get_in(block, &mut in_num, &mut in_den) != 0
|| n::oaknode_block_get_out(block, &mut out_num, &mut out_den) != 0
|| n::oaknode_clip_get_media_in(block, &mut mi_num, &mut mi_den) != 0
{
continue;
}
let in_time = oakcore_rs::Rational::new(in_num as i64, in_den as i64);
let out_time = oakcore_rs::Rational::new(out_num as i64, out_den as i64);
if time < in_time || time >= out_time {
continue;
}
let Some((filename, stream_index)) = clip_media(block) else {
continue;
};
let media_in = oakcore_rs::Rational::new(mi_num as i64, mi_den as i64);
let name = std::ffi::CString::new(filename).unwrap_or_default();
let ptr = name.as_ptr();
names.push(name);
pods.push(MontagePod {
filename: ptr,
stream_index,
in_num: in_time.numerator(),
in_den: in_time.denominator(),
out_num: out_time.numerator(),
out_den: out_time.denominator(),
media_in_num: media_in.numerator(),
media_in_den: media_in.denominator(),
gain: 1.0,
});
}
}
(pods, names)
}
}
/// `oakengine_renderer_create` — NULL for invalid arguments.
#[no_mangle]
pub unsafe extern "C" fn oakengine_renderer_create(
@@ -242,6 +475,7 @@ pub unsafe extern "C" fn oakengine_renderer_create(
let seq_handle = unbox(seq)?;
make_renderer_box(
seq_handle,
true,
width,
height,
pixel_format,
@@ -275,6 +509,7 @@ pub unsafe extern "C" fn oakengine_renderer_create_for_node(
let node_handle = unbox(node)?;
make_renderer_box(
node_handle,
false,
width,
height,
pixel_format,
@@ -326,6 +561,11 @@ pub unsafe extern "C" fn oakengine_renderer_last_error(
}
/// `oakengine_renderer_render_frame` — synchronous frame render.
///
/// M12 P0: a sequence renderer resolves the timeline into a montage
/// (video clips covering the timestamp, composited track 0 on top); a
/// footage renderer decodes its bound footage. Both run inside the
/// render ticket's producer.
#[no_mangle]
pub unsafe extern "C" fn oakengine_renderer_render_frame(
self_: *mut OakEngineRenderer,
@@ -334,12 +574,14 @@ pub unsafe extern "C" fn oakengine_renderer_render_frame(
guard_ptr(|| unsafe {
let b = renderer_mut(self_)?;
let video_params = make_video_params(b)?;
let params = OakVideoTicketParams {
let time =
oakcore_rs::Rational::new(timestamp * i64::from(b.frame_rate_den), i64::from(b.frame_rate_num));
let mut params = OakVideoTicketParams {
output_node: b.output_node,
video_params,
audio_params: std::ptr::null(),
time_num: timestamp * i64::from(b.frame_rate_den),
time_den: i64::from(b.frame_rate_num),
time_num: time.numerator(),
time_den: time.denominator(),
color_manager: CHandle::null(),
mode: b.mode,
force_width: b.width,
@@ -351,8 +593,30 @@ pub unsafe extern "C" fn oakengine_renderer_render_frame(
force_color_output: CHandle::null(),
force_color_transform: CHandle::null(),
cache: CHandle::null(),
footage_filename: std::ptr::null(),
footage_stream: 0,
montage: std::ptr::null(),
montage_count: 0,
};
// M12 P0: sequence renderers resolve the montage; footage
// renderers pass the resolved spec. Both stay alive until the
// synchronous ticket call copies them.
let mut keep_alive: Vec<std::ffi::CString> = Vec::new();
let mut montage: Vec<MontagePod> = Vec::new();
if b.is_sequence {
(montage, keep_alive) = build_video_montage(b, time);
if !montage.is_empty() {
params.montage = montage.as_ptr();
params.montage_count = montage.len() as c_int;
}
} else if let Some(footage) = &b.footage {
let name = std::ffi::CString::new(footage.filename.clone()).unwrap_or_default();
params.footage_filename = name.as_ptr();
params.footage_stream = footage.stream_index;
keep_alive.push(name);
}
let ticket = r::oakrender_ticket_render_frame(&params, None, std::ptr::null_mut());
let _ = (&keep_alive, &montage);
let mut vp = video_params;
crate::bridge::common::oakcommon_videoparams_free(&mut vp);
if ticket.is_null() {
@@ -387,17 +651,34 @@ pub unsafe extern "C" fn oakengine_renderer_render_audio(
let start_num = start_timestamp * i64::from(b.frame_rate_den);
let end_num = (start_timestamp + length_timestamp) * i64::from(b.frame_rate_den);
let den = i64::from(b.frame_rate_num);
let range = oakcore_rs::TimeRange::new(
oakcore_rs::Rational::new(start_num, den),
oakcore_rs::Rational::new(end_num, den),
);
// M12 P1: resolve the audio montage (audio-track clips covering
// the range) and the output format.
let (pods, names) = build_audio_montage(b, range);
let mut keep: Vec<std::ffi::CString> = names;
let params = crate::bridge::audio::oakcore_audioparams_create(48000, 0x3, 10); // packed F32 stereo
crate::bridge::audio::oakcore_audioparams_set_time_base(params, 1, 48000);
let ticket = r::oakrender_ticket_render_audio(
b.output_node,
start_num,
den,
end_num,
den,
std::ptr::null(),
params as *const c_void,
b.mode,
None,
std::ptr::null_mut(),
if pods.is_empty() {
std::ptr::null()
} else {
pods.as_ptr()
},
pods.len() as c_int,
);
crate::bridge::audio::oakcore_audioparams_free(params);
if ticket.is_null() {
b.last_error = "audio render ticket submission failed".into();
return Ok(std::ptr::null_mut());
@@ -407,9 +688,22 @@ pub unsafe extern "C" fn oakengine_renderer_render_audio(
let get_rc = r::oakrender_ticket_get_samples(ticket, &mut samples);
let mut t = ticket;
r::oakrender_ticket_free(&mut t);
let _ = (wait_rc, get_rc, samples);
b.last_error = "audio rendering is not implemented by the render module".into();
Ok(std::ptr::null_mut())
let _ = &keep;
if wait_rc != 0 || get_rc != 0 || samples.is_null() {
b.last_error = "audio render failed".into();
return Ok(std::ptr::null_mut());
}
let raw = samples as *const oakrender::ffi::OakAudioSamplesOut;
let boxed = AudioSamplesBox {
data: (*raw).data.clone(),
frame_count: (*raw).frame_count as i64,
sample_rate: (*raw).sample_rate,
channel_layout: (*raw).channel_layout,
channel_count: (*raw).channel_count,
};
r::oakrender_audio_samples_free(samples);
b.last_error.clear();
Ok(Box::into_raw(Box::new(boxed)) as *mut OakEngineAudioBuffer)
})
}
@@ -537,41 +831,87 @@ pub unsafe extern "C" fn oakengine_frame_free(self_: *mut OakEngineFrame) {
}
// ---------------------------------------------------------------------------
// OakEngineAudioBuffer accessors (no crate backing — always empty)
// OakEngineAudioBuffer accessors (M12 P1: rendered audio samples)
// ---------------------------------------------------------------------------
/// `oakengine_audio_sample_rate` — 0 (no crate samples accessor).
#[no_mangle]
pub unsafe extern "C" fn oakengine_audio_sample_rate(_self_: *const OakEngineAudioBuffer) -> c_int {
0
/// The buffer box: the rendered interleaved f32 samples plus format.
struct AudioSamplesBox {
/// Interleaved samples.
data: Box<[f32]>,
/// Frame count.
frame_count: i64,
/// Sample rate (Hz).
sample_rate: c_int,
/// Channel layout mask.
channel_layout: u64,
/// Channel count.
channel_count: c_int,
}
/// `oakengine_audio_channel_count` — 0.
/// `oakengine_audio_sample_rate`.
#[no_mangle]
pub unsafe extern "C" fn oakengine_audio_sample_rate(self_: *const OakEngineAudioBuffer) -> c_int {
unsafe {
if self_.is_null() {
return 0;
}
let b = self_ as *const AudioSamplesBox;
(*b).sample_rate
}
}
/// `oakengine_audio_channel_count`.
#[no_mangle]
pub unsafe extern "C" fn oakengine_audio_channel_count(
_self_: *const OakEngineAudioBuffer,
self_: *const OakEngineAudioBuffer,
) -> c_int {
0
unsafe {
if self_.is_null() {
return 0;
}
let b = self_ as *const AudioSamplesBox;
(*b).channel_count
}
}
/// `oakengine_audio_sample_count` — 0.
/// `oakengine_audio_sample_count` — interleaved frame count.
#[no_mangle]
pub unsafe extern "C" fn oakengine_audio_sample_count(_self_: *const OakEngineAudioBuffer) -> i64 {
0
pub unsafe extern "C" fn oakengine_audio_sample_count(self_: *const OakEngineAudioBuffer) -> i64 {
unsafe {
if self_.is_null() {
return 0;
}
let b = self_ as *const AudioSamplesBox;
(*b).frame_count
}
}
/// `oakengine_audio_data` — NULL.
/// `oakengine_audio_data` — pointer to the interleaved samples (channel
/// index ignored: interleaved layout).
#[no_mangle]
pub unsafe extern "C" fn oakengine_audio_data(
_self_: *const OakEngineAudioBuffer,
self_: *const OakEngineAudioBuffer,
_channel: c_int,
) -> *const f32 {
std::ptr::null()
unsafe {
if self_.is_null() {
return std::ptr::null();
}
let b = &*(self_ as *const AudioSamplesBox);
b.data.as_ptr()
}
}
/// `oakengine_audio_free` — NULL no-op.
/// `oakengine_audio_free` — release the buffer box.
#[no_mangle]
pub unsafe extern "C" fn oakengine_audio_free(_self_: *mut OakEngineAudioBuffer) {}
pub unsafe extern "C" fn oakengine_audio_free(self_: *mut OakEngineAudioBuffer) {
unsafe {
if self_.is_null() {
return;
}
drop(Box::from_raw(self_ as *mut AudioSamplesBox));
}
}
// ---------------------------------------------------------------------------
// Color management
+64
View File
@@ -0,0 +1,64 @@
// 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/>.
//! Test-media generation facade export (M12 P0).
//!
//! `oakengine_testmedia_write_clip` encodes a small MPEG-2 clip of known
//! content through the engine's own FFmpeg (oakcodec's encoder). App
//! tests call this instead of linking oakcodec directly: the app test
//! binary already loads `liboakengine` (which statically embeds FFmpeg),
//! and a second FFmpeg copy in the test binary duplicates the
//! AVFoundation Objective-C classes and crashes the encoder's device
//! probing.
use std::ffi::{c_char, c_int};
use crate::error::Error;
use crate::handle::guard_int;
/// `oakengine_testmedia_write_clip` — encode `frame_count` frames of the
/// known test pattern (left half red / right half blue on frame 0) into
/// `path` (MPEG-2 in an MP4 container, `fps` frames per second).
///
/// Returns 0 on success; a negative `OAKENGINE_E_*` otherwise (invalid
/// arguments or an encoder failure). Only used by tests and tooling.
#[no_mangle]
pub extern "C" fn oakengine_testmedia_write_clip(
path: *const c_char,
width: c_int,
height: c_int,
frame_count: c_int,
fps: c_int,
) -> c_int {
guard_int(|| unsafe {
if path.is_null() {
return Err(Error::Invalid);
}
let path_str = crate::handle::read_cstr(path);
if path_str.is_empty() || width <= 0 || height <= 0 || frame_count <= 0 || fps <= 0 {
return Err(Error::Invalid);
}
oakcodec::testmedia::write_test_clip(
std::path::Path::new(&path_str),
width,
height,
frame_count,
fps,
)
.map_err(|e| Error::Failed(format!("test clip encode failed: {e:?}")))?;
Ok(0)
})
}
+320 -35
View File
@@ -1785,6 +1785,48 @@ pub unsafe extern "C" fn oakengine_sequence_add_footage_clip(
media_in: i64,
) -> *mut OakEngineClip {
guard_ptr(|| unsafe {
add_footage_clip_impl(seq, footage, track_type, track_index, in_, out, media_in, true)
})
}
/// `oakengine_sequence_add_footage_clip_ex` — like
/// `oakengine_sequence_add_footage_clip`, but skips the same-project
/// check (M12 P0).
///
/// Sequences created through `oakengine_sequence_new` live in their own
/// scratch project (documented deviation: the module's whole-subgraph
/// transfer cannot remap the ids held inside behaviors, so project
/// membership is not established in the module world). The plain export
/// therefore rejects every footage clip as "different projects". The
/// `_ex` variant accepts the module reality: the check is unenforceable
/// and only the handle validity is required.
#[no_mangle]
pub unsafe extern "C" fn oakengine_sequence_add_footage_clip_ex(
seq: *mut OakEngineSequence,
footage: *mut OakEngineFootage,
track_type: c_int,
track_index: c_int,
in_: i64,
out: i64,
media_in: i64,
) -> *mut OakEngineClip {
guard_ptr(|| unsafe {
add_footage_clip_impl(seq, footage, track_type, track_index, in_, out, media_in, false)
})
}
/// Shared implementation of the footage-clip placement.
unsafe fn add_footage_clip_impl(
seq: *mut OakEngineSequence,
footage: *mut OakEngineFootage,
track_type: c_int,
track_index: c_int,
in_: i64,
out: i64,
media_in: i64,
strict_project: bool,
) -> Result<*mut OakEngineClip> {
unsafe {
set_seq_error("");
let sequence = match unbox(seq) {
Ok(h) => h,
@@ -1804,18 +1846,22 @@ pub unsafe extern "C" fn oakengine_sequence_add_footage_clip(
set_seq_error("clips are only supported on video and audio tracks");
return Ok(std::ptr::null_mut());
}
// Same-project check.
// Same-project check. The `_ex` variant skips it: sequences
// created through `oakengine_sequence_new` live in their own
// scratch project (documented deviation), so the strict check
// can never pass and only handle validity is enforceable.
let mut seq_project = CHandle::null();
let seq_node = n::oaknode_sequence_as_node(sequence);
let rc = n::oaknode_node_get_project(seq_node, &mut seq_project);
let mut foot_project = CHandle::null();
let rc2 = n::oaknode_node_get_project(footage_h, &mut foot_project);
release_handle(seq_node);
if rc != 0
|| rc2 != 0
|| seq_project.is_null()
|| foot_project.is_null()
|| seq_project.ctx != foot_project.ctx
if strict_project
&& (rc != 0
|| rc2 != 0
|| seq_project.is_null()
|| foot_project.is_null()
|| seq_project.ctx != foot_project.ctx)
{
release_handle(seq_project);
release_handle(foot_project);
@@ -1878,35 +1924,61 @@ pub unsafe extern "C" fn oakengine_sequence_add_footage_clip(
len_den as c_int,
))?;
let mut children: Vec<CHandle> = Vec::new();
let add_cmd = n::oaknode_command_create_add_node(seq_project_of(sequence), clip);
if add_cmd.is_null() {
release_handle(list);
set_seq_error("node add command failed");
return Ok(std::ptr::null_mut());
}
children.push(add_cmd);
// The module clip has no `buffer_in` input (only media/speed/reverse/
// pitch/loop inputs), so the footage connection cannot be built; the
// whole add fails like the C++ would on a bad edge.
let clip_node = n::oaknode_block_as_node(clip);
let mut edge = CHandle::null();
let rc = n::oaknode_node_connect_undoable(
footage_h,
clip_node,
c"buffer_in".as_ptr(),
&mut edge,
);
release_handle(clip_node);
if rc != 0 {
for child in &children {
release_handle(*child);
// The `_ex` variant connects a footage node created directly in
// the sequence's scratch project (graph edges cannot cross
// projects; the real-project footage node stays untouched for
// the project browser). The module clip declares its texture
// input as `tex_in` (the C++-era `buffer_in` name does not exist
// here); the graph's connect validates the input side only, so
// the footage edge builds even though the footage node has no
// declared output.
//
// Order matters: the place command ADOPTS the block into the
// sequence's project (remapping the block handle's node id), so
// the footage edge is created only after the block is placed —
// the edge needs the clip's final (project, id).
let scratch_footage = if !strict_project {
let scratch = seq_project_of(sequence);
let mut out = CHandle::null();
if !scratch.is_null() {
let mut fbuf = [0 as c_char; 4096];
if n::oaknode_footage_filename(
footage_h,
fbuf.as_mut_ptr(),
fbuf.len() as c_int,
) >= 0
{
let fname = crate::handle::read_cstr(fbuf.as_ptr());
let fc = std::ffi::CString::new(fname).unwrap_or_default();
out = n::oaknode_footage_create(scratch, fc.as_ptr());
}
release_handle(scratch);
}
release_handle(list);
set_seq_error("footage connection failed: module clips have no buffer input");
return Ok(std::ptr::null_mut());
out
} else {
CHandle::null()
};
let mut children: Vec<CHandle> = Vec::new();
// The `_ex` variant skips the graph add-node command: it would
// move the clip entry into the sequence's project under a fresh
// id while leaving the caller's clip handle stale, which then
// breaks the place command's adoption (the entry is already
// gone). The place command's `adopt_block` performs the move
// itself and remaps the block handle; on undo the block is
// simply left as an orphan node in the sequence's project.
if strict_project {
let add_cmd = n::oaknode_command_create_add_node(seq_project_of(sequence), clip);
if add_cmd.is_null() {
release_handle(list);
if !scratch_footage.is_null() {
release_handle(scratch_footage);
}
set_seq_error("node add command failed");
return Ok(std::ptr::null_mut());
}
children.push(add_cmd);
}
children.push(edge);
let place_cmd =
tl::oaktimeline_place_block_command(list, track_index, clip, in_num, in_den);
if place_cmd.is_null() {
@@ -1914,17 +1986,42 @@ pub unsafe extern "C" fn oakengine_sequence_add_footage_clip(
release_handle(*child);
}
release_handle(list);
if !scratch_footage.is_null() {
release_handle(scratch_footage);
}
set_seq_error("place block command failed");
return Ok(std::ptr::null_mut());
}
children.push(place_cmd);
release_handle(list);
// The commands hold borrowed clones of `list` (no addref), so the
// handle must stay alive until the group push has executed the
// redos; released right after.
if let Err(e) = push_multi_commands(&children, "Add Clip") {
release_handle(list);
set_seq_error(&format!("failed to push add-clip command: {:?}", e));
return Err(e);
}
release_handle(list);
if !scratch_footage.is_null() {
let clip_node = n::oaknode_block_as_node(clip);
let mut edge = CHandle::null();
let rc = n::oaknode_node_connect_undoable(
scratch_footage,
clip_node,
c"tex_in".as_ptr(),
&mut edge,
);
release_handle(clip_node);
release_handle(scratch_footage);
if rc != 0 || edge.is_null() {
set_seq_error("footage connection failed");
return Ok(std::ptr::null_mut());
}
let edge_box = box_handle::<OakEngineClipboard>(edge);
push_or_run(edge_box, c"Add Clip".as_ptr())?;
}
Ok(box_handle::<OakEngineClip>(clip))
})
}
}
/// Borrowed project handle of a sequence (temporary; caller releases).
@@ -2111,6 +2208,50 @@ pub unsafe extern "C" fn oakengine_clip_as_node(self_: *const OakEngineClip) ->
})
}
/// `oakengine_clip_get_media_filename` — the clip's upstream footage
/// filename (two-stage buf/size; M12 P4 — the waveform decorator needs
/// the media file). Negative error when the clip has no media.
#[no_mangle]
pub unsafe extern "C" fn oakengine_clip_get_media_filename(
self_: *const OakEngineClip,
buf: *mut c_char,
buf_size: c_int,
) -> c_int {
guard_int(|| unsafe {
if self_.is_null() {
return Err(Error::Invalid);
}
let h = unbox(self_)?;
let Some((filename, _)) = timeline_clip_media(h) else {
return Err(Error::NotFound);
};
let rc = crate::handle::write_string(&filename, buf, buf_size);
Ok(string_result(rc))
})
}
/// Resolve a clip's media `(filename, stream)` through its graph node's
/// upstream footage (the same walk `crates::render` performs for the
/// montage).
unsafe fn timeline_clip_media(clip: CHandle) -> Option<(String, c_int)> {
unsafe {
let node = n::oaknode_block_as_node(clip);
if node.is_null() {
return None;
}
let mut footage = CHandle::null();
if n::oaknode_node_find_input_footage(node, &mut footage) != 0 || footage.is_null() {
return None;
}
let mut buf = [0 as c_char; 4096];
if n::oaknode_footage_filename(footage, buf.as_mut_ptr(), buf.len() as c_int) < 0 {
return None;
}
let filename = crate::handle::read_cstr(buf.as_ptr());
Some((filename, 1))
}
}
/* ---- Editing primitives, round 2: split / ripple delete / trim / move ---- */
/// `oakengine_sequence_split_clip` — split the addressed clip at `time`.
@@ -2429,6 +2570,150 @@ pub unsafe extern "C" fn oakengine_sequence_move_clip(
})
}
/// `oakengine_sequence_move_clip_to_track` — move a clip to a different
/// track at `new_in` (frame units in the sequence's timebase) as ONE
/// undoable entry (M12 P4, cross-track move): the source spot becomes a
/// gap and the clip is placed on the destination track.
///
/// The destination track must already exist and hold clips of the same
/// type (video ↔ video, audio ↔ audio).
#[no_mangle]
pub unsafe extern "C" fn oakengine_sequence_move_clip_to_track(
seq: *mut OakEngineSequence,
track_type: c_int,
track_index: c_int,
clip_index: c_int,
dest_track_index: c_int,
new_in: i64,
) -> c_int {
guard(|| unsafe {
set_seq_error("");
let sequence = match unbox(seq) {
Ok(h) => h,
Err(_) => {
set_seq_error("invalid arguments");
return Err(Error::Invalid);
}
};
if track_type < TRACK_TYPE_VIDEO
|| track_type > TRACK_TYPE_SUBTITLE
|| new_in < 0
|| dest_track_index < 0
{
set_seq_error("invalid arguments");
return Err(Error::Invalid);
}
let mut list = CHandle::null();
Error::from_module(n::oaknode_sequence_get_track_list(
sequence, track_type, &mut list,
))?;
let clip = clip_at_index(list, track_index, clip_index);
if clip.is_null() {
set_seq_error(&format!(
"no clip at track {} index {}",
track_index, clip_index
));
return Err(Error::NotFound);
}
let mut track = CHandle::null();
let rc = n::oaknode_block_get_track(clip, &mut track);
if rc != 0 || track.is_null() {
set_seq_error(&format!(
"no clip at track {} index {}",
track_index, clip_index
));
return Err(Error::NotFound);
}
let mut track_count: c_int = 0;
Error::from_module(n::oaknode_tracklist_get_track_count(
list, &mut track_count,
))?;
if dest_track_index >= track_count {
set_seq_error(&format!(
"destination track {} out of range ({} tracks)",
dest_track_index, track_count
));
return Err(Error::NotFound);
}
let tb = seq_time_base(sequence)?;
let (new_in_num, new_in_den) = ts_to_rational(new_in, tb);
// One undoable entry: gap the source, re-home the block's in
// point, place on the destination. (The module stores a block's
// position on the block itself, so the place command alone would
// keep the old in point.)
let mut children: Vec<CHandle> = Vec::new();
let gap_cmd = tl::oaktimeline_replace_block_with_gap_command(track, clip);
if gap_cmd.is_null() {
set_seq_error("replace-with-gap command failed");
return Err(Error::Failed("gap command failed".into()));
}
children.push(gap_cmd);
let mut old_num: c_int = 0;
let mut old_den: c_int = 0;
Error::from_module(n::oaknode_block_get_in(clip, &mut old_num, &mut old_den))?;
let data = Box::into_raw(Box::new(BlockInCmdData {
block: clip,
old_num,
old_den,
new_num: new_in_num as c_int,
new_den: new_in_den as c_int,
}));
let in_cmd = vtable_command(block_in_redo, block_in_undo, block_in_free, data as *mut c_void)?;
children.push(in_cmd);
let place_cmd = tl::oaktimeline_place_block_command(
list,
dest_track_index,
clip,
new_in_num,
new_in_den,
);
if place_cmd.is_null() {
set_seq_error("place-block command failed");
return Err(Error::Failed("place command failed".into()));
}
children.push(place_cmd);
// The commands hold borrowed clones of `list`/`track`/`clip` (no
// addref); keep them alive until the redos run.
push_multi_commands(&children, "Move Clip to Track")
})
}
/// Vtable data for the block-in re-home step of a cross-track move.
struct BlockInCmdData {
/// The block (borrowed; alive with the sequence).
block: CHandle,
/// Original in point.
old_num: c_int,
/// Original in point denominator.
old_den: c_int,
/// Placement in point.
new_num: c_int,
/// Placement in point denominator.
new_den: c_int,
}
/// `BlockInCmdData` redo: re-home the block's in point.
unsafe extern "C" fn block_in_redo(data: *mut c_void) {
unsafe {
let d = &*(data as *const BlockInCmdData);
n::oaknode_block_set_in(d.block, d.new_num, d.new_den);
}
}
/// `BlockInCmdData` undo: restore the original in point.
unsafe extern "C" fn block_in_undo(data: *mut c_void) {
unsafe {
let d = &*(data as *const BlockInCmdData);
n::oaknode_block_set_in(d.block, d.old_num, d.old_den);
}
}
/// `BlockInCmdData` free.
unsafe extern "C" fn block_in_free(data: *mut c_void) {
unsafe { drop(Box::from_raw(data as *mut BlockInCmdData)) };
}
/* ---- Batch editing (timeline panel) -------------------------------------- */
/// `oakengine_sequence_split_clips` — split every given clip at `time_ts`,