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
+473 -71
View File
@@ -22,8 +22,7 @@
//! `OakSubtitleParams`, `OakNodeBlock`) mirror the `{ctx, addref,
//! release, abi_version}` layout from `include/common/handle.h`, so the
//! codec module can store them by value and pass them straight across
//! the FFI boundary. Function signatures match the public headers
//! verbatim; symbols resolve at link time.
//! the FFI boundary.
//!
//! The oakcore audio parameters use a pointer-based C ABI instead of the
//! by-value handle convention: `oakcore_audioparams_*` take and return
@@ -32,6 +31,18 @@
//! pointers to the crate's handle structs; `oakcore_audioparams_time_base`
//! returns a newly allocated rational the caller must release with
//! `oakcore_rational_free`.
//!
//! # ABI discipline (single-lib era)
//!
//! The frozen `oakcommon` C ABI (see `crates/oakengine/include/common/`)
//! uses **out-pointer getters** and **instance handles** for the module
//! families. Earlier codec-era bridges declared value-style signatures
//! (C++-era headers); those declarations were wrong against the frozen
//! contract and are fixed here. To keep the crate's call sites
//! unchanged, each true ABI symbol is declared under `#[link_name]` with
//! its real signature and wrapped in an adapter of the old value-style
//! shape (an M12 P0 decode-path fix: the mismatch made every decoded
//! frame invalid).
use std::ffi::{c_char, c_int, c_void};
@@ -50,6 +61,10 @@ pub type OakSubtitleParams = CHandle;
/// only stores and forwards it).
pub type OakNodeBlock = CHandle;
/// Module instance handles (filefunctions / oiioutils take `self_`).
pub type OakFileFunctions = CHandle;
pub type OakOIIOUtils = CHandle;
// The handle structs are opaque refcounted handles pointing into a C
// library; the boxed objects are independently synchronized there, so
// moving a handle between threads is sound.
@@ -58,27 +73,48 @@ extern "C" {
/// `oakcommon_videoparams_init`.
pub fn oakcommon_videoparams_init() -> OakVideoParams;
/// `oakcommon_videoparams_init_basic`.
pub fn oakcommon_videoparams_init_basic(width: c_int, height: c_int) -> OakVideoParams;
/// `oakcommon_videoparams_init_with_time_base`.
pub fn oakcommon_videoparams_init_with_time_base(
#[link_name = "oakcommon_videoparams_init_basic"]
fn videoparams_init_basic_abi(
width: c_int,
height: c_int,
time_base_num: i64,
time_base_den: i64,
pixel_format: c_int,
nb_channels: c_int,
pixel_aspect_num: c_int,
pixel_aspect_den: c_int,
interlacing: c_int,
divider: c_int,
) -> OakVideoParams;
/// `oakcommon_videoparams_init_with_time_base`.
#[link_name = "oakcommon_videoparams_init_with_time_base"]
fn videoparams_init_with_time_base_abi(
width: c_int,
height: c_int,
time_base_num: c_int,
time_base_den: c_int,
pixel_format: c_int,
nb_channels: c_int,
pixel_aspect_num: c_int,
pixel_aspect_den: c_int,
interlacing: c_int,
divider: c_int,
) -> OakVideoParams;
/// `oakcommon_videoparams_free` (NULL/empty no-op).
pub fn oakcommon_videoparams_free(params: *mut OakVideoParams);
/// `oakcommon_videoparams_get_width`.
pub fn oakcommon_videoparams_get_width(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_width"]
fn videoparams_get_width_abi(params: OakVideoParams, width: *mut c_int) -> c_int;
/// `oakcommon_videoparams_get_height`.
pub fn oakcommon_videoparams_get_height(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_height"]
fn videoparams_get_height_abi(params: OakVideoParams, height: *mut c_int) -> c_int;
/// `oakcommon_videoparams_get_format`.
pub fn oakcommon_videoparams_get_format(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_format"]
fn videoparams_get_format_abi(params: OakVideoParams, format: *mut c_int) -> c_int;
/// `oakcommon_videoparams_get_time_base` (num/den out).
pub fn oakcommon_videoparams_get_time_base(
#[link_name = "oakcommon_videoparams_get_time_base"]
fn videoparams_get_time_base_abi(
params: OakVideoParams,
out_num: *mut i64,
out_den: *mut i64,
numerator: *mut c_int,
denominator: *mut c_int,
) -> c_int;
/// `oakcommon_videoparams_set_width`.
pub fn oakcommon_videoparams_set_width(params: OakVideoParams, width: c_int);
@@ -87,9 +123,15 @@ extern "C" {
/// `oakcommon_videoparams_set_format`.
pub fn oakcommon_videoparams_set_format(params: OakVideoParams, format: c_int);
/// `oakcommon_videoparams_get_is_valid`.
pub fn oakcommon_videoparams_get_is_valid(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_is_valid"]
fn videoparams_get_is_valid_abi(params: OakVideoParams, is_valid: *mut c_int) -> c_int;
/// `oakcommon_videoparams_equals`.
pub fn oakcommon_videoparams_equals(a: OakVideoParams, b: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_equals"]
fn videoparams_equals_abi(
params: OakVideoParams,
other: OakVideoParams,
equal: *mut c_int,
) -> c_int;
/// `oakcommon_videoparams_set_time_base`.
pub fn oakcommon_videoparams_set_time_base(params: OakVideoParams, num: i64, den: i64);
/// `oakcommon_videoparams_set_frame_rate`.
@@ -120,7 +162,8 @@ extern "C" {
/// `oakcommon_videoparams_set_enabled`.
pub fn oakcommon_videoparams_set_enabled(params: OakVideoParams, enabled: c_int);
/// `oakcommon_videoparams_static_get_bytes_per_pixel`.
pub fn oakcommon_videoparams_static_get_bytes_per_pixel(format: c_int) -> c_int;
#[link_name = "oakcommon_videoparams_static_get_bytes_per_pixel"]
fn videoparams_static_get_bytes_per_pixel_abi(format: c_int, channels: c_int) -> c_int;
/// `oakcommon_videoparams_frame_rate_as_time_base`.
pub fn oakcommon_videoparams_frame_rate_as_time_base(
frame_rate_num: i64,
@@ -129,32 +172,37 @@ extern "C" {
out_den: *mut i64,
);
/// `oakcommon_videoparams_get_stream_index`.
pub fn oakcommon_videoparams_get_stream_index(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_stream_index"]
fn videoparams_get_stream_index_abi(params: OakVideoParams, index: *mut c_int) -> c_int;
/// `oakcommon_videoparams_set_stream_index`.
pub fn oakcommon_videoparams_set_stream_index(params: OakVideoParams, index: c_int);
/// `oakcommon_videoparams_get_divider`.
pub fn oakcommon_videoparams_get_divider(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_divider"]
fn videoparams_get_divider_abi(params: OakVideoParams, divider: *mut c_int) -> c_int;
/// `oakcommon_videoparams_set_divider`.
pub fn oakcommon_videoparams_set_divider(params: OakVideoParams, divider: c_int);
// NOTE: the remaining video getters below take the value-style form the
// crate's existing bridge uses (the real oakcommon headers use out-pointer
// args); `get_frame_rate` needs both values so it keeps the out pair.
/// `oakcommon_videoparams_get_frame_rate` (frame-rate num/den out).
pub fn oakcommon_videoparams_get_frame_rate(
#[link_name = "oakcommon_videoparams_get_frame_rate"]
fn videoparams_get_frame_rate_abi(
params: OakVideoParams,
out_num: *mut c_int,
out_den: *mut c_int,
numerator: *mut c_int,
denominator: *mut c_int,
) -> c_int;
/// `oakcommon_videoparams_get_duration` (time-base units).
pub fn oakcommon_videoparams_get_duration(params: OakVideoParams) -> i64;
#[link_name = "oakcommon_videoparams_get_duration"]
fn videoparams_get_duration_abi(params: OakVideoParams, duration: *mut i64) -> c_int;
/// `oakcommon_videoparams_get_channel_count`.
pub fn oakcommon_videoparams_get_channel_count(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_channel_count"]
fn videoparams_get_channel_count_abi(params: OakVideoParams, count: *mut c_int) -> c_int;
/// `oakcommon_videoparams_get_color_primaries`.
pub fn oakcommon_videoparams_get_color_primaries(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_color_primaries"]
fn videoparams_get_color_primaries_abi(params: OakVideoParams, primaries: *mut c_int) -> c_int;
/// `oakcommon_videoparams_get_color_transfer`.
pub fn oakcommon_videoparams_get_color_transfer(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_color_transfer"]
fn videoparams_get_color_transfer_abi(params: OakVideoParams, transfer: *mut c_int) -> c_int;
/// `oakcommon_videoparams_get_interlacing` (`Interlacing` value).
pub fn oakcommon_videoparams_get_interlacing(params: OakVideoParams) -> c_int;
#[link_name = "oakcommon_videoparams_get_interlacing"]
fn videoparams_get_interlacing_abi(params: OakVideoParams, interlacing: *mut c_int) -> c_int;
/// `oakcore_audioparams_create` (pointer-based; timebase 1/sample_rate).
pub fn oakcore_audioparams_create(
sample_rate: c_int,
@@ -199,7 +247,11 @@ extern "C" {
/// `oakcore_rational_free` (NULL no-op).
pub fn oakcore_rational_free(rational: *mut c_void);
/// `oakcommon_subtitleparams_get_stream_index`.
pub fn oakcommon_subtitleparams_get_stream_index(params: OakSubtitleParams) -> c_int;
#[link_name = "oakcommon_subtitleparams_get_stream_index"]
fn subtitleparams_get_stream_index_abi(
params: OakSubtitleParams,
index: *mut c_int,
) -> c_int;
/// `oakcommon_subtitleparams_generate_ass_header`.
pub fn oakcommon_subtitleparams_generate_ass_header(
params: OakSubtitleParams,
@@ -212,13 +264,13 @@ extern "C" {
pub fn oakcommon_config_get_int(
group: *const c_char,
key: *const c_char,
default: c_int,
fallback: c_int,
) -> c_int;
/// `oakcommon_config_get_bool`.
pub fn oakcommon_config_get_bool(
group: *const c_char,
key: *const c_char,
default: c_int,
fallback: c_int,
) -> c_int;
/// `oakcommon_config_get` (two-stage string access).
pub fn oakcommon_config_get(
@@ -228,57 +280,407 @@ extern "C" {
buf_size: c_int,
) -> c_int;
/// `oakcommon_filefunctions_init`.
pub fn oakcommon_filefunctions_init();
pub fn oakcommon_filefunctions_init() -> OakFileFunctions;
/// `oakcommon_filefunctions_free`.
pub fn oakcommon_filefunctions_free(self_: *mut OakFileFunctions);
/// `oakcommon_filefunctions_get_configuration_location` (two-stage).
pub fn oakcommon_filefunctions_get_configuration_location(
#[link_name = "oakcommon_filefunctions_get_configuration_location"]
fn filefunctions_get_configuration_location_abi(
self_: OakFileFunctions,
buf: *mut c_char,
buf_size: c_int,
) -> c_int;
/// `oakcommon_filefunctions_get_unique_file_identifier`.
pub fn oakcommon_filefunctions_get_unique_file_identifier(path: *const c_char) -> i64;
#[link_name = "oakcommon_filefunctions_get_unique_file_identifier"]
fn filefunctions_get_unique_file_identifier_abi(
self_: OakFileFunctions,
filename: *const c_char,
buf: *mut c_char,
buf_size: c_int,
) -> c_int;
/// `oakcommon_filefunctions_get_application_path` (two-stage).
pub fn oakcommon_filefunctions_get_application_path(buf: *mut c_char, buf_size: c_int)
-> c_int;
/// `oakcommon_filefunctions_free` (frees an internally cached string).
pub fn oakcommon_filefunctions_free(ptr: *mut c_void);
#[link_name = "oakcommon_filefunctions_get_application_path"]
fn filefunctions_get_application_path_abi(
self_: OakFileFunctions,
buf: *mut c_char,
buf_size: c_int,
) -> c_int;
/// `oakcommon_colortransform_init_output`.
pub fn oakcommon_colortransform_init_output(
src_colorspace: c_int,
src_trc: c_int,
dst_colorspace: c_int,
dst_trc: c_int,
premultiplied: c_int,
chroma_coeffs: *const c_void,
) -> OakVideoParams;
/// `oakcommon_colortransform_get_output`.
pub fn oakcommon_colortransform_get_output(params: OakVideoParams, out: *mut OakVideoParams);
pub fn oakcommon_colortransform_init_output(output: *const c_char) -> OakVideoParams;
/// `oakcommon_colortransform_get_output` (two-stage string).
pub fn oakcommon_colortransform_get_output(
transform: OakVideoParams,
buf: *mut c_char,
buf_size: c_int,
) -> c_int;
/// `oakcommon_colortransform_free`.
pub fn oakcommon_colortransform_free(params: *mut OakVideoParams);
/// `oakcommon_ffmpegutils_get_native_sample_format`.
pub fn oakcommon_ffmpegutils_get_native_sample_format(sample_format: c_int) -> c_int;
#[link_name = "oakcommon_ffmpegutils_get_native_sample_format"]
fn ffmpegutils_get_native_sample_format_abi(smp_fmt: c_int, out: *mut c_int) -> c_int;
/// `oakcommon_ffmpegutils_get_compatible_pixel_format`.
pub fn oakcommon_ffmpegutils_get_compatible_pixel_format(format: c_int) -> c_int;
#[link_name = "oakcommon_ffmpegutils_get_compatible_pixel_format"]
fn ffmpegutils_get_compatible_pixel_format_abi(pix_fmt: c_int, out: *mut c_int) -> c_int;
/// `oakcommon_ffmpegutils_get_ffmpeg_pixel_format`.
pub fn oakcommon_ffmpegutils_get_ffmpeg_pixel_format(format: c_int) -> c_int;
/// `oakcommon_ffmpegutils_get_ffmpeg_sample_format`.
pub fn oakcommon_ffmpegutils_get_ffmpeg_sample_format(format: c_int) -> c_int;
/// `oakcommon_ffmpegutils_get_compatible_bridge_pixel_format`.
pub fn oakcommon_ffmpegutils_get_compatible_bridge_pixel_format(format: c_int) -> c_int;
/// `oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space`.
pub fn oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space(format: c_int) -> c_int;
/// `oakcommon_oiioutils_init`.
pub fn oakcommon_oiioutils_init();
/// `oakcommon_oiioutils_get_oiio_base_type_from_format`.
pub fn oakcommon_oiioutils_get_oiio_base_type_from_format(format: c_int) -> c_int;
/// `oakcommon_oiioutils_get_format_from_oiio_basetype`.
pub fn oakcommon_oiioutils_get_format_from_oiio_basetype(basetype: c_int) -> c_int;
/// `oakcommon_oiioutils_get_pixel_aspect_ratio` (num/den out).
pub fn oakcommon_oiioutils_get_pixel_aspect_ratio(
width: c_int,
height: c_int,
out_num: *mut c_int,
out_den: *mut c_int,
#[link_name = "oakcommon_ffmpegutils_get_ffmpeg_pixel_format"]
fn ffmpegutils_get_ffmpeg_pixel_format_abi(
pix_fmt: c_int,
channel_count: c_int,
out: *mut c_int,
) -> c_int;
/// `oakcommon_ffmpegutils_get_ffmpeg_sample_format`.
#[link_name = "oakcommon_ffmpegutils_get_ffmpeg_sample_format"]
fn ffmpegutils_get_ffmpeg_sample_format_abi(smp_fmt: c_int, out: *mut c_int) -> c_int;
/// `oakcommon_ffmpegutils_get_compatible_bridge_pixel_format`.
#[link_name = "oakcommon_ffmpegutils_get_compatible_bridge_pixel_format"]
fn ffmpegutils_get_compatible_bridge_pixel_format_abi(
pix_fmt: c_int,
maximum_pix_fmt: c_int,
out: *mut c_int,
) -> c_int;
/// `oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space`.
#[link_name = "oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space"]
fn ffmpegutils_convert_jpeg_space_to_regular_space_abi(
pix_fmt: c_int,
out: *mut c_int,
) -> c_int;
/// `oakcommon_oiioutils_init`.
pub fn oakcommon_oiioutils_init() -> OakOIIOUtils;
/// `oakcommon_oiioutils_free`.
pub fn oakcommon_oiioutils_free();
pub fn oakcommon_oiioutils_free(self_: *mut OakOIIOUtils);
/// `oakcommon_oiioutils_get_oiio_base_type_from_format`.
#[link_name = "oakcommon_oiioutils_get_oiio_base_type_from_format"]
fn oiioutils_get_oiio_base_type_from_format_abi(
self_: OakOIIOUtils,
pixel_format: c_int,
out_base_type: *mut c_int,
) -> c_int;
/// `oakcommon_oiioutils_get_format_from_oiio_basetype`.
#[link_name = "oakcommon_oiioutils_get_format_from_oiio_basetype"]
fn oiioutils_get_format_from_oiio_basetype_abi(
self_: OakOIIOUtils,
base_type: c_int,
out_pixel_format: *mut c_int,
) -> c_int;
/// `oakcommon_oiioutils_get_pixel_aspect_ratio` (num/den out).
#[link_name = "oakcommon_oiioutils_get_pixel_aspect_ratio"]
fn oiioutils_get_pixel_aspect_ratio_abi(
self_: OakOIIOUtils,
pixel_aspect_ratio: f64,
out_numerator: *mut c_int,
out_denominator: *mut c_int,
) -> c_int;
}
// ---------------------------------------------------------------------------
// Value-style adapters over the frozen out-pointer ABI (old call shapes)
// ---------------------------------------------------------------------------
/// `oakcommon_videoparams_init_basic` — value-style shape kept for call
/// sites; defaults: U8 format, 4 channels, 1:1 aspect, progressive,
/// divider 1.
pub fn oakcommon_videoparams_init_basic(
width: c_int,
height: c_int,
pixel_format: c_int,
nb_channels: c_int,
pixel_aspect_num: c_int,
pixel_aspect_den: c_int,
interlacing: c_int,
divider: c_int,
) -> OakVideoParams {
unsafe { videoparams_init_basic_abi(width, height, pixel_format, nb_channels, pixel_aspect_num, pixel_aspect_den, interlacing, divider) }
}
/// `oakcommon_videoparams_init_with_time_base` — value-style shape kept
/// for call sites.
pub fn oakcommon_videoparams_init_with_time_base(
width: c_int,
height: c_int,
time_base_num: c_int,
time_base_den: c_int,
pixel_format: c_int,
nb_channels: c_int,
pixel_aspect_num: c_int,
pixel_aspect_den: c_int,
interlacing: c_int,
divider: c_int,
) -> OakVideoParams {
unsafe {
videoparams_init_with_time_base_abi(
width,
height,
time_base_num,
time_base_den,
pixel_format,
nb_channels,
pixel_aspect_num,
pixel_aspect_den,
interlacing,
divider,
)
}
}
/// Value-style `oakcommon_videoparams_get_width`.
pub fn oakcommon_videoparams_get_width(params: OakVideoParams) -> c_int {
let mut w: c_int = 0;
unsafe { videoparams_get_width_abi(params, &mut w) };
w
}
/// Value-style `oakcommon_videoparams_get_height`.
pub fn oakcommon_videoparams_get_height(params: OakVideoParams) -> c_int {
let mut h: c_int = 0;
unsafe { videoparams_get_height_abi(params, &mut h) };
h
}
/// Value-style `oakcommon_videoparams_get_format`.
pub fn oakcommon_videoparams_get_format(params: OakVideoParams) -> c_int {
let mut f: c_int = -1;
unsafe { videoparams_get_format_abi(params, &mut f) };
f
}
/// Value-style `oakcommon_videoparams_get_is_valid`.
pub fn oakcommon_videoparams_get_is_valid(params: OakVideoParams) -> c_int {
let mut v: c_int = 0;
unsafe { videoparams_get_is_valid_abi(params, &mut v) };
v
}
/// Value-style `oakcommon_videoparams_equals` (1 when equal).
pub fn oakcommon_videoparams_equals(a: OakVideoParams, b: OakVideoParams) -> c_int {
let mut eq: c_int = 0;
unsafe { videoparams_equals_abi(a, b, &mut eq) };
eq
}
/// Value-style `oakcommon_videoparams_get_stream_index`.
pub fn oakcommon_videoparams_get_stream_index(params: OakVideoParams) -> c_int {
let mut i: c_int = -1;
unsafe { videoparams_get_stream_index_abi(params, &mut i) };
i
}
/// Value-style `oakcommon_videoparams_get_divider`.
pub fn oakcommon_videoparams_get_divider(params: OakVideoParams) -> c_int {
let mut d: c_int = 0;
unsafe { videoparams_get_divider_abi(params, &mut d) };
d
}
/// Value-style `oakcommon_videoparams_get_duration`.
pub fn oakcommon_videoparams_get_duration(params: OakVideoParams) -> i64 {
let mut d: i64 = 0;
unsafe { videoparams_get_duration_abi(params, &mut d) };
d
}
/// Value-style `oakcommon_videoparams_get_channel_count`.
pub fn oakcommon_videoparams_get_channel_count(params: OakVideoParams) -> c_int {
let mut c: c_int = 0;
unsafe { videoparams_get_channel_count_abi(params, &mut c) };
c
}
/// Value-style `oakcommon_videoparams_get_color_primaries`.
pub fn oakcommon_videoparams_get_color_primaries(params: OakVideoParams) -> c_int {
let mut p: c_int = 0;
unsafe { videoparams_get_color_primaries_abi(params, &mut p) };
p
}
/// Value-style `oakcommon_videoparams_get_color_transfer`.
pub fn oakcommon_videoparams_get_color_transfer(params: OakVideoParams) -> c_int {
let mut t: c_int = 0;
unsafe { videoparams_get_color_transfer_abi(params, &mut t) };
t
}
/// Value-style `oakcommon_videoparams_get_interlacing`.
pub fn oakcommon_videoparams_get_interlacing(params: OakVideoParams) -> c_int {
let mut i: c_int = 0;
unsafe { videoparams_get_interlacing_abi(params, &mut i) };
i
}
/// Value-style `oakcommon_videoparams_get_time_base` (num/den out as
/// `i64`, widened from the frozen `i32` outs).
pub fn oakcommon_videoparams_get_time_base(
params: OakVideoParams,
out_num: *mut i64,
out_den: *mut i64,
) -> c_int {
let mut num: c_int = 0;
let mut den: c_int = 0;
let rc = unsafe { videoparams_get_time_base_abi(params, &mut num, &mut den) };
if !out_num.is_null() {
unsafe { *out_num = num as i64 };
}
if !out_den.is_null() {
unsafe { *out_den = den as i64 };
}
rc
}
/// Value-style `oakcommon_videoparams_get_frame_rate` (num/den out).
pub fn oakcommon_videoparams_get_frame_rate(
params: OakVideoParams,
out_num: *mut c_int,
out_den: *mut c_int,
) -> c_int {
unsafe { videoparams_get_frame_rate_abi(params, out_num, out_den) }
}
/// Value-style `oakcommon_videoparams_static_get_bytes_per_pixel`
/// (4 channels assumed; the frozen ABI takes channels explicitly).
pub fn oakcommon_videoparams_static_get_bytes_per_pixel(format: c_int) -> c_int {
unsafe { videoparams_static_get_bytes_per_pixel_abi(format, 4) }
}
/// Value-style `oakcommon_subtitleparams_get_stream_index`.
pub fn oakcommon_subtitleparams_get_stream_index(params: OakSubtitleParams) -> c_int {
let mut i: c_int = -1;
unsafe { subtitleparams_get_stream_index_abi(params, &mut i) };
i
}
/// Value-style `oakcommon_ffmpegutils_get_native_sample_format`.
pub fn oakcommon_ffmpegutils_get_native_sample_format(sample_format: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { ffmpegutils_get_native_sample_format_abi(sample_format, &mut out) };
out
}
/// Value-style `oakcommon_ffmpegutils_get_compatible_pixel_format`.
pub fn oakcommon_ffmpegutils_get_compatible_pixel_format(format: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { ffmpegutils_get_compatible_pixel_format_abi(format, &mut out) };
out
}
/// Value-style `oakcommon_ffmpegutils_get_ffmpeg_pixel_format`
/// (4 channels assumed).
pub fn oakcommon_ffmpegutils_get_ffmpeg_pixel_format(format: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { ffmpegutils_get_ffmpeg_pixel_format_abi(format, 4, &mut out) };
out
}
/// Value-style `oakcommon_ffmpegutils_get_ffmpeg_sample_format`.
pub fn oakcommon_ffmpegutils_get_ffmpeg_sample_format(format: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { ffmpegutils_get_ffmpeg_sample_format_abi(format, &mut out) };
out
}
/// Value-style `oakcommon_ffmpegutils_get_compatible_bridge_pixel_format`
/// (no maximum constraint).
pub fn oakcommon_ffmpegutils_get_compatible_bridge_pixel_format(format: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { ffmpegutils_get_compatible_bridge_pixel_format_abi(format, -1, &mut out) };
out
}
/// Value-style `oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space`.
pub fn oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space(format: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { ffmpegutils_convert_jpeg_space_to_regular_space_abi(format, &mut out) };
out
}
/// The process-wide filefunctions instance (lazily created; freed on
/// process exit is not required — the singleton outlives all users).
fn filefunctions_instance() -> OakFileFunctions {
static FF: std::sync::OnceLock<OakFileFunctions> = std::sync::OnceLock::new();
*FF.get_or_init(|| unsafe { oakcommon_filefunctions_init() })
}
/// Value-style `oakcommon_filefunctions_get_application_path`
/// (two-stage string getter on the shared instance).
pub fn oakcommon_filefunctions_get_application_path(buf: *mut c_char, buf_size: c_int) -> c_int {
unsafe { filefunctions_get_application_path_abi(filefunctions_instance(), buf, buf_size) }
}
/// Value-style `oakcommon_filefunctions_get_configuration_location`.
pub fn oakcommon_filefunctions_get_configuration_location(
buf: *mut c_char,
buf_size: c_int,
) -> c_int {
unsafe {
filefunctions_get_configuration_location_abi(filefunctions_instance(), buf, buf_size)
}
}
/// Value-style `oakcommon_filefunctions_get_unique_file_identifier`
/// (the frozen ABI writes a string; the value-style call sites expect an
/// `i64`, so the string is folded into a stable 64-bit FNV hash).
pub fn oakcommon_filefunctions_get_unique_file_identifier(path: *const c_char) -> i64 {
let mut buf = [0 as c_char; 512];
// Two-stage contract: 0 = written, positive = required size, negative
// = error. The adapter's value-style call sites get the i64 fold.
let n = unsafe {
filefunctions_get_unique_file_identifier_abi(
filefunctions_instance(),
path,
buf.as_mut_ptr(),
buf.len() as c_int,
)
};
if n < 0 {
return 0;
}
let avail = if n == 0 { buf.len() } else { (n as usize).min(buf.len()) };
let bytes: Vec<u8> = buf[..avail]
.iter()
.take_while(|&&b| b != 0)
.map(|&b| b as u8)
.collect();
let mut hash: u64 = 0xcbf29ce484222325;
for &b in &bytes {
hash ^= b as u64;
hash = hash.wrapping_mul(0x100000001b3);
}
hash as i64
}
/// The process-wide oiioutils instance (lazily created).
fn oiioutils_instance() -> OakOIIOUtils {
static OU: std::sync::OnceLock<OakOIIOUtils> = std::sync::OnceLock::new();
*OU.get_or_init(|| unsafe { oakcommon_oiioutils_init() })
}
/// Value-style `oakcommon_oiioutils_get_oiio_base_type_from_format`.
pub fn oakcommon_oiioutils_get_oiio_base_type_from_format(format: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { oiioutils_get_oiio_base_type_from_format_abi(oiioutils_instance(), format, &mut out) };
out
}
/// Value-style `oakcommon_oiioutils_get_format_from_oiio_basetype`.
pub fn oakcommon_oiioutils_get_format_from_oiio_basetype(basetype: c_int) -> c_int {
let mut out: c_int = -1;
unsafe { oiioutils_get_format_from_oiio_basetype_abi(oiioutils_instance(), basetype, &mut out) };
out
}
/// Value-style `oakcommon_oiioutils_get_pixel_aspect_ratio`
/// (the frozen ABI takes the aspect ratio as `f64`; the value-style call
/// sites pass width/height and get num/den back).
pub fn oakcommon_oiioutils_get_pixel_aspect_ratio(
width: c_int,
height: c_int,
out_num: *mut c_int,
out_den: *mut c_int,
) -> c_int {
let ratio = if height != 0 {
f64::from(width) / f64::from(height)
} else {
1.0
};
unsafe {
oiioutils_get_pixel_aspect_ratio_abi(oiioutils_instance(), ratio, out_num, out_den)
}
}
+276 -81
View File
@@ -35,7 +35,9 @@ use std::ffi::{c_char, c_int, c_void, CStr};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Mutex, OnceLock};
use crate::bridge::common::{OakAudioParams, OakNodeBlock, OakSubtitleParams, OakVideoParams};
use crate::bridge::common::{
OakAudioParams, OakFileFunctions, OakNodeBlock, OakOIIOUtils, OakSubtitleParams, OakVideoParams,
};
use crate::bridge::render::{OakCancelAtom, OakCodecFrame, OakRenderRenderer, OakRenderTexture};
use crate::handle::OAKCODEC_ABI_VERSION;
@@ -119,12 +121,25 @@ pub extern "C" fn oakcommon_videoparams_init() -> OakVideoParams {
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_init_basic(width: c_int, height: c_int) -> OakVideoParams {
pub extern "C" fn oakcommon_videoparams_init_basic(
width: c_int,
height: c_int,
pixel_format: c_int,
nb_channels: c_int,
pixel_aspect_num: c_int,
pixel_aspect_den: c_int,
interlacing: c_int,
divider: c_int,
) -> OakVideoParams {
new_params_handle(MockParams {
width,
height,
divider: 1,
channel_count: 4, // internal RGBA pipeline layout
format: pixel_format,
channel_count: nb_channels,
pixel_aspect_num,
pixel_aspect_den,
interlacing,
divider,
..Default::default()
})
}
@@ -136,14 +151,24 @@ pub extern "C" fn oakcommon_videoparams_init_with_time_base(
height: c_int,
time_base_num: i64,
time_base_den: i64,
pixel_format: c_int,
nb_channels: c_int,
pixel_aspect_num: c_int,
pixel_aspect_den: c_int,
interlacing: c_int,
divider: c_int,
) -> OakVideoParams {
new_params_handle(MockParams {
width,
height,
time_base_num,
time_base_den,
divider: 1,
channel_count: 4, // internal RGBA pipeline layout
format: pixel_format,
channel_count: nb_channels,
pixel_aspect_num,
pixel_aspect_den,
interlacing,
divider,
..Default::default()
})
}
@@ -165,37 +190,52 @@ pub extern "C" fn oakcommon_videoparams_free(params: *mut OakVideoParams) {
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_width(params: OakVideoParams) -> c_int {
params_get(params.ctx).width
pub extern "C" fn oakcommon_videoparams_get_width(params: OakVideoParams, width: *mut c_int) -> c_int {
let w = params_get(params.ctx).width;
if width.is_null() {
return -1;
}
unsafe { *width = w };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_height(params: OakVideoParams) -> c_int {
params_get(params.ctx).height
pub extern "C" fn oakcommon_videoparams_get_height(params: OakVideoParams, height: *mut c_int) -> c_int {
let h = params_get(params.ctx).height;
if height.is_null() {
return -1;
}
unsafe { *height = h };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_format(params: OakVideoParams) -> c_int {
params_get(params.ctx).format
pub extern "C" fn oakcommon_videoparams_get_format(params: OakVideoParams, format: *mut c_int) -> c_int {
let f = params_get(params.ctx).format;
if format.is_null() {
return -1;
}
unsafe { *format = f };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_time_base(
params: OakVideoParams,
out_num: *mut i64,
out_den: *mut i64,
numerator: *mut c_int,
denominator: *mut c_int,
) -> c_int {
let p = params_get(params.ctx);
if !out_num.is_null() {
unsafe { *out_num = p.time_base_num };
if !numerator.is_null() {
unsafe { *numerator = p.time_base_num as c_int };
}
if !out_den.is_null() {
unsafe { *out_den = p.time_base_den };
if !denominator.is_null() {
unsafe { *denominator = p.time_base_den as c_int };
}
1
0
}
#[no_mangle]
@@ -218,20 +258,37 @@ pub extern "C" fn oakcommon_videoparams_set_format(params: OakVideoParams, forma
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_is_valid(params: OakVideoParams) -> c_int {
pub extern "C" fn oakcommon_videoparams_get_is_valid(params: OakVideoParams, is_valid: *mut c_int) -> c_int {
let p = params_get(params.ctx);
((p.width > 0) && (p.height > 0)) as c_int
let v = (p.width > 0 && p.height > 0) as c_int;
if is_valid.is_null() {
return -1;
}
unsafe { *is_valid = v };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_equals(a: OakVideoParams, b: OakVideoParams) -> c_int {
(params_get(a.ctx) == params_get(b.ctx)) as c_int
pub extern "C" fn oakcommon_videoparams_equals(
a: OakVideoParams,
b: OakVideoParams,
equal: *mut c_int,
) -> c_int {
let eq = (params_get(a.ctx) == params_get(b.ctx)) as c_int;
if equal.is_null() {
return -1;
}
unsafe { *equal = eq };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_static_get_bytes_per_pixel(format: c_int) -> c_int {
pub extern "C" fn oakcommon_videoparams_static_get_bytes_per_pixel(
format: c_int,
_channels: c_int,
) -> c_int {
// U10 packs to 4 bytes; U8 to 1; U16/F16 to 2; F32 to 4.
match format {
0 => 1, // U8
@@ -261,8 +318,16 @@ pub extern "C" fn oakcommon_videoparams_frame_rate_as_time_base(
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_stream_index(params: OakVideoParams) -> c_int {
params_get(params.ctx).stream_index
pub extern "C" fn oakcommon_videoparams_get_stream_index(
params: OakVideoParams,
index: *mut c_int,
) -> c_int {
let i = params_get(params.ctx).stream_index;
if index.is_null() {
return -1;
}
unsafe { *index = i };
0
}
#[no_mangle]
@@ -273,8 +338,16 @@ pub extern "C" fn oakcommon_videoparams_set_stream_index(params: OakVideoParams,
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_divider(params: OakVideoParams) -> c_int {
params_get(params.ctx).divider
pub extern "C" fn oakcommon_videoparams_get_divider(
params: OakVideoParams,
divider: *mut c_int,
) -> c_int {
let d = params_get(params.ctx).divider;
if divider.is_null() {
return -1;
}
unsafe { *divider = d };
0
}
#[no_mangle]
@@ -302,32 +375,72 @@ pub extern "C" fn oakcommon_videoparams_get_frame_rate(
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_duration(params: OakVideoParams) -> i64 {
params_get(params.ctx).duration
pub extern "C" fn oakcommon_videoparams_get_duration(
params: OakVideoParams,
duration: *mut i64,
) -> c_int {
let d = params_get(params.ctx).duration;
if duration.is_null() {
return -1;
}
unsafe { *duration = d };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_channel_count(params: OakVideoParams) -> c_int {
params_get(params.ctx).channel_count
pub extern "C" fn oakcommon_videoparams_get_channel_count(
params: OakVideoParams,
count: *mut c_int,
) -> c_int {
let c = params_get(params.ctx).channel_count;
if count.is_null() {
return -1;
}
unsafe { *count = c };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_color_primaries(params: OakVideoParams) -> c_int {
params_get(params.ctx).color_primaries
pub extern "C" fn oakcommon_videoparams_get_color_primaries(
params: OakVideoParams,
primaries: *mut c_int,
) -> c_int {
let p = params_get(params.ctx).color_primaries;
if primaries.is_null() {
return -1;
}
unsafe { *primaries = p };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_color_transfer(params: OakVideoParams) -> c_int {
params_get(params.ctx).color_trc
pub extern "C" fn oakcommon_videoparams_get_color_transfer(
params: OakVideoParams,
transfer: *mut c_int,
) -> c_int {
let t = params_get(params.ctx).color_trc;
if transfer.is_null() {
return -1;
}
unsafe { *transfer = t };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_videoparams_get_interlacing(params: OakVideoParams) -> c_int {
params_get(params.ctx).interlacing
pub extern "C" fn oakcommon_videoparams_get_interlacing(
params: OakVideoParams,
interlacing: *mut c_int,
) -> c_int {
let i = params_get(params.ctx).interlacing;
if interlacing.is_null() {
return -1;
}
unsafe { *interlacing = i };
0
}
#[no_mangle]
@@ -639,7 +752,14 @@ pub extern "C" fn oakcore_rational_free(rational: *mut c_void) {
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_subtitleparams_get_stream_index(_params: OakSubtitleParams) -> c_int {
pub extern "C" fn oakcommon_subtitleparams_get_stream_index(
_params: OakSubtitleParams,
index: *mut c_int,
) -> c_int {
if index.is_null() {
return -1;
}
unsafe { *index = 0 };
0
}
@@ -710,11 +830,14 @@ static FAKE_PATH: &[u8] = b"/mock/config/oak\0";
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_filefunctions_init() {}
pub extern "C" fn oakcommon_filefunctions_init() -> OakFileFunctions {
OakFileFunctions::null()
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_filefunctions_get_configuration_location(
_self_: OakFileFunctions,
buf: *mut c_char,
buf_size: c_int,
) -> c_int {
@@ -723,21 +846,38 @@ pub extern "C" fn oakcommon_filefunctions_get_configuration_location(
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_filefunctions_get_unique_file_identifier(path: *const c_char) -> i64 {
if path.is_null() {
return 0;
pub extern "C" fn oakcommon_filefunctions_get_unique_file_identifier(
_self_: OakFileFunctions,
path: *const c_char,
buf: *mut c_char,
buf_size: c_int,
) -> c_int {
if path.is_null() || buf.is_null() {
return -1;
}
unsafe { CStr::from_ptr(path) }
let hash = unsafe { CStr::from_ptr(path) }
.to_bytes()
.iter()
.fold(14695981039346656037u64, |acc, &b| {
(acc ^ b as u64).wrapping_mul(1099511628211)
}) as i64
});
let s = format!("{}", hash as i64);
let bytes = s.as_bytes();
let n = bytes.len() + 1;
if buf_size < n as c_int {
return n as c_int;
}
unsafe {
std::ptr::copy_nonoverlapping(bytes.as_ptr(), buf as *mut u8, bytes.len());
*buf.add(bytes.len()) = 0;
}
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_filefunctions_get_application_path(
_self_: OakFileFunctions,
buf: *mut c_char,
buf_size: c_int,
) -> c_int {
@@ -755,12 +895,7 @@ pub extern "C" fn oakcommon_filefunctions_free(_ptr: *mut c_void) {}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_colortransform_init_output(
_src_colorspace: c_int,
_src_trc: c_int,
_dst_colorspace: c_int,
_dst_trc: c_int,
_premultiplied: c_int,
_chroma_coeffs: *const c_void,
_output: *const c_char,
) -> OakVideoParams {
oakcommon_videoparams_init()
}
@@ -788,40 +923,82 @@ pub extern "C" fn oakcommon_colortransform_free(params: *mut OakVideoParams) {
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_ffmpegutils_get_native_sample_format(sample_format: c_int) -> c_int {
sample_format
pub extern "C" fn oakcommon_ffmpegutils_get_native_sample_format(
smp_fmt: c_int,
out: *mut c_int,
) -> c_int {
if out.is_null() {
return -1;
}
unsafe { *out = smp_fmt };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_ffmpegutils_get_compatible_pixel_format(format: c_int) -> c_int {
format
pub extern "C" fn oakcommon_ffmpegutils_get_compatible_pixel_format(
pix_fmt: c_int,
out: *mut c_int,
) -> c_int {
if out.is_null() {
return -1;
}
unsafe { *out = pix_fmt };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_ffmpegutils_get_ffmpeg_pixel_format(format: c_int) -> c_int {
format
pub extern "C" fn oakcommon_ffmpegutils_get_ffmpeg_pixel_format(
pix_fmt: c_int,
_channel_count: c_int,
out: *mut c_int,
) -> c_int {
if out.is_null() {
return -1;
}
unsafe { *out = pix_fmt };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_ffmpegutils_get_ffmpeg_sample_format(format: c_int) -> c_int {
format
pub extern "C" fn oakcommon_ffmpegutils_get_ffmpeg_sample_format(
smp_fmt: c_int,
out: *mut c_int,
) -> c_int {
if out.is_null() {
return -1;
}
unsafe { *out = smp_fmt };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_ffmpegutils_get_compatible_bridge_pixel_format(format: c_int) -> c_int {
format
pub extern "C" fn oakcommon_ffmpegutils_get_compatible_bridge_pixel_format(
pix_fmt: c_int,
_maximum_pix_fmt: c_int,
out: *mut c_int,
) -> c_int {
if out.is_null() {
return -1;
}
unsafe { *out = pix_fmt };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space(
format: c_int,
pix_fmt: c_int,
out: *mut c_int,
) -> c_int {
format
if out.is_null() {
return -1;
}
unsafe { *out = pix_fmt };
0
}
// ---------------------------------------------------------------------------
@@ -830,40 +1007,58 @@ pub extern "C" fn oakcommon_ffmpegutils_convert_jpeg_space_to_regular_space(
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_oiioutils_init() {}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_oiioutils_get_oiio_base_type_from_format(format: c_int) -> c_int {
format
pub extern "C" fn oakcommon_oiioutils_init() -> OakOIIOUtils {
OakOIIOUtils::null()
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_oiioutils_get_format_from_oiio_basetype(basetype: c_int) -> c_int {
basetype
pub extern "C" fn oakcommon_oiioutils_get_oiio_base_type_from_format(
_self_: OakOIIOUtils,
pixel_format: c_int,
out_base_type: *mut c_int,
) -> c_int {
if out_base_type.is_null() {
return -1;
}
unsafe { *out_base_type = pixel_format };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_oiioutils_get_format_from_oiio_basetype(
_self_: OakOIIOUtils,
base_type: c_int,
out_pixel_format: *mut c_int,
) -> c_int {
if out_pixel_format.is_null() {
return -1;
}
unsafe { *out_pixel_format = base_type };
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_oiioutils_get_pixel_aspect_ratio(
_width: c_int,
_height: c_int,
out_num: *mut c_int,
out_den: *mut c_int,
_self_: OakOIIOUtils,
_pixel_aspect_ratio: f64,
out_numerator: *mut c_int,
out_denominator: *mut c_int,
) -> c_int {
if !out_num.is_null() {
unsafe { *out_num = 1 };
if !out_numerator.is_null() {
unsafe { *out_numerator = 1 };
}
if !out_den.is_null() {
unsafe { *out_den = 1 };
if !out_denominator.is_null() {
unsafe { *out_denominator = 1 };
}
1
0
}
#[no_mangle]
#[cfg(test)]
pub extern "C" fn oakcommon_oiioutils_free() {}
pub extern "C" fn oakcommon_oiioutils_free(_self_: *mut OakOIIOUtils) {}
// ---------------------------------------------------------------------------
// oakrender_cancelatom_* (real in-memory cancel state)
+8 -3
View File
@@ -245,8 +245,12 @@ mod tests {
#[test]
fn unique_identifier_matches_bridge_hash() {
// The test stub computes an FNV-1a-64 of the path bytes.
let expected = format!("{}", fnv1a64(b"media.mp4") as i64);
// The frozen ABI returns the identifier as a string; the
// value-style adapter folds it into an FNV-1a-64. The test stub
// produces the decimal FNV of the path bytes, so the expected
// value is FNV of that decimal string.
let stub_id = fnv1a64(b"media.mp4") as i64;
let expected = format!("{}", fnv1a64(stub_id.to_string().as_bytes()) as i64);
assert_eq!(unique_file_identifier("media.mp4"), expected);
// Deterministic: same input, same id.
assert_eq!(
@@ -276,7 +280,8 @@ mod tests {
fn conform_filename_derivation_and_range() {
let m = ConformManager::instance();
let cache = temp_subdir("names");
let id = fnv1a64(b"media.mp4") as i64;
let stub_id = fnv1a64(b"media.mp4") as i64;
let id = fnv1a64(stub_id.to_string().as_bytes()) as i64;
let base = format!("{}-0.48000.0.3", id);
let f0 = m
.get_conform_filename(&cache, "media.mp4", 0, 48000, 0x3, 0, 0)
+2 -2
View File
@@ -795,7 +795,7 @@ mod tests {
if filename.ends_with("test_video.mp4") {
let mut desc = FootageDescription::new("fake");
let vp =
unsafe { oakcommon_videoparams_init_with_time_base(1920, 1080, 1001, 30000) };
unsafe { oakcommon_videoparams_init_with_time_base(1920, 1080, 1001, 30000, 0, 4, 1, 1, 0, 1) };
unsafe { oakcommon_videoparams_set_stream_index(vp.clone(), 0) };
desc.push_stream(StreamEntry::Video(vp));
Some(desc)
@@ -830,7 +830,7 @@ mod tests {
&self,
_p: &RetrieveVideoParams,
) -> crate::error::Result<Arc<Frame>> {
let params = unsafe { oakcommon_videoparams_init_basic(100, 50) };
let params = unsafe { oakcommon_videoparams_init_basic(100, 50, 0, 4, 1, 1, 0, 1) };
let frame = Arc::new(Frame::with_params(params));
if self.retain_frame {
// Keep an alias alive so the ffi decode sees a shared Arc.
+2 -2
View File
@@ -578,7 +578,7 @@ mod tests {
assert_eq!(rc, crate::error::OAKCODEC_OK);
// write_video with a real frame handle.
let params = unsafe { oakcommon_videoparams_init_basic(16, 16) };
let params = unsafe { oakcommon_videoparams_init_basic(16, 16, 0, 4, 1, 1, 0, 1) };
let mut fh = unsafe { oakcodec_frame_init_with_params(params) };
assert_eq!(
unsafe { oakcodec_frame_allocate(fh) },
@@ -705,7 +705,7 @@ mod tests {
assert_eq!(rc, OAKCODEC_E_INVALID);
// Writes before open -> E_STATE.
let params = unsafe { oakcommon_videoparams_init_basic(4, 4) };
let params = unsafe { oakcommon_videoparams_init_basic(4, 4, 0, 4, 1, 1, 0, 1) };
let mut fh = unsafe { oakcodec_frame_init_with_params(params) };
let rc = unsafe { oakcodec_encoder_write_video(h, fh) };
assert_eq!(rc, OAKCODEC_E_STATE);
+3 -3
View File
@@ -319,7 +319,7 @@ mod tests {
#[test]
fn frame_lifecycle_golden() {
let _g = crate::ffi::lock_tests();
let params = unsafe { oakcommon_videoparams_init_basic(100, 50) };
let params = unsafe { oakcommon_videoparams_init_basic(100, 50, 0, 4, 1, 1, 0, 1) };
let before = handle::alive_count();
let mut h = unsafe { oakcodec_frame_init_with_params(params) };
assert!(!h.is_null());
@@ -385,7 +385,7 @@ mod tests {
);
// init_basic(0, 0) is not valid -> allocate rejects with E_STATE.
let params = unsafe { oakcommon_videoparams_init_basic(0, 0) };
let params = unsafe { oakcommon_videoparams_init_basic(0, 0, 0, 4, 1, 1, 0, 1) };
let mut h = unsafe { oakcodec_frame_init_with_params(params) };
assert!(!h.is_null());
assert_eq!(
@@ -433,7 +433,7 @@ mod tests {
);
// set_params replaces the parameter set and recomputes line sizes.
let params = unsafe { oakcommon_videoparams_init_basic(100, 50) };
let params = unsafe { oakcommon_videoparams_init_basic(100, 50, 0, 4, 1, 1, 0, 1) };
let rc = unsafe { oakcodec_frame_set_params(h, params) };
assert_eq!(rc, crate::error::OAKCODEC_OK);
assert_eq!(unsafe { oakcodec_frame_width(h) }, 100);
+63 -43
View File
@@ -861,33 +861,29 @@ impl DecoderState {
let (w, h) = (f.width(), f.height());
// swscale cannot reliably output float RGBA on every build; prefer
// RGBAF32LE and fall back to RGBA64 (converted to f32 below).
let bytes =
match get_or_create_scaler(&mut video.scaler, src_format, w, h, Pixel::RGBAF32LE, w, h)
{
Ok(ctx) => {
let mut out = ffmpeg::frame::Video::empty();
ctx.run(&f, &mut out).map_err(ffmpeg_err)?;
let stride = out.stride(0);
convert_rgba_f32_le(&out.data(0), w, h, stride)
}
Err(_) => {
let ctx = get_or_create_scaler(
&mut video.scaler,
src_format,
w,
h,
Pixel::RGBA64LE,
w,
h,
)?;
let mut out = ffmpeg::frame::Video::empty();
ctx.run(&f, &mut out).map_err(ffmpeg_err)?;
let stride = out.stride(0);
convert_rgba64_to_f32(&out.data(0), w, h, stride)
}
};
// swscale cannot reliably output float RGBA on every build:
// float output is missing from some static FFmpeg swscale
// builds ("128bpp not supported by yuv2rgb"), and creating a
// float context there can abort instead of erroring — RGBA64 is
// REPORTED supported but still aborts, so only RGBAF32LE is
// probed (on the builds that have it, e.g. the system FFmpeg,
// it works); everything else takes the universal 8-bit RGBA
// path converted in Rust.
let supported = ffmpeg::software::scaling::support::output(Pixel::RGBAF32LE);
let (out_fmt, f32_ok) = if supported {
(Pixel::RGBAF32LE, true)
} else {
(Pixel::RGBA, false)
};
let ctx = get_or_create_scaler(&mut video.scaler, src_format, w, h, out_fmt, w, h)?;
let mut out = ffmpeg::frame::Video::empty();
ctx.run(&f, &mut out).map_err(ffmpeg_err)?;
let stride = out.stride(0);
let bytes = if f32_ok {
convert_rgba_f32_le(&out.data(0), w, h, stride)
} else {
convert_rgba8_to_f32(&out.data(0), w, h, stride)
};
Ok((w, h, bytes))
}
@@ -1427,6 +1423,27 @@ fn convert_rgba64_to_f32(data: &[u8], w: u32, h: u32, stride: usize) -> Vec<u8>
out
}
/// Copy a packed 8-bit RGBA buffer into F32 RGBA bytes (the universal
/// swscale fallback; M12 P0 — some static FFmpeg swscale builds lack
/// float output formats).
fn convert_rgba8_to_f32(data: &[u8], w: u32, h: u32, stride: usize) -> Vec<u8> {
let mut out = vec![0u8; (w as usize) * (h as usize) * PIXEL_F32_BYTES];
for y in 0..h as usize {
let row = &data[y * stride..y * stride + (w as usize) * 4];
let dst =
&mut out[y * (w as usize) * PIXEL_F32_BYTES..(y + 1) * (w as usize) * PIXEL_F32_BYTES];
for (px, src_px) in dst
.chunks_exact_mut(PIXEL_F32_BYTES)
.zip(row.chunks_exact(4))
{
for c in 0..4 {
px[c * 4..c * 4 + 4].copy_from_slice(&((src_px[c] as f32 / 255.0).to_le_bytes()));
}
}
}
out
}
/// Build an allocated [`Frame`] (F32, RGBA) from raw pixel bytes.
///
/// # CPP-PARITY
@@ -1439,7 +1456,7 @@ fn copy_rgba_f32_to_frame(
bytes: &[u8],
timestamp: Rational,
) -> crate::error::Result<Frame> {
let params = unsafe { oakcommon_videoparams_init_basic(width as i32, height as i32) };
let params = unsafe { oakcommon_videoparams_init_basic(width as i32, height as i32, 0, 4, 1, 1, 0, 1) };
unsafe {
oakcommon_videoparams_set_format(params.clone(), PixelFormat::F32 as i32);
oakcommon_videoparams_set_channel_count(params.clone(), VIDEO_CHANNELS);
@@ -1528,7 +1545,7 @@ fn probe_file(filename: &str, cancelled: Option<&OakCancelAtom>) -> Option<Foota
let frame_rate = stream.avg_frame_rate();
let tb = stream.time_base();
let vp = unsafe { oakcommon_videoparams_init_basic(1, 1) };
let vp = unsafe { oakcommon_videoparams_init_basic(1, 1, 0, 4, 1, 1, 0, 1) };
unsafe {
oakcommon_videoparams_set_stream_index(vp.clone(), i as i32);
oakcommon_videoparams_set_width(vp.clone(), (*raw).width);
@@ -1883,7 +1900,7 @@ impl EncoderState {
.unwrap_or_else(|| default_pixel_format_for_codec(codec_id));
encoder.set_format(pix_fmt);
let opened = encoder.open().map_err(ffmpeg_err)?;
let opened = encoder.open().map_err(|e| { eprintln!("DBG-AUD: audio open failed: {e:?}"); ffmpeg_err(e) })?;
stream.set_parameters(&opened);
let scaler = scaling::Context::get(
@@ -1931,8 +1948,11 @@ impl EncoderState {
if params.audio_bit_rate > 0 {
encoder.set_bit_rate(params.audio_bit_rate as usize);
}
let sample_fmt = sample_format_to_ffmpeg(params.audio_sample_format)
.unwrap_or_else(|| default_sample_format_for_codec(codec_id));
// The encoder always runs in the codec's native sample
// format (the params' delivery format is bridged by the
// resampler below); forcing an incompatible format here
// makes `open` fail with Invalid argument.
let sample_fmt = default_sample_format_for_codec(codec_id);
encoder.set_format(sample_fmt);
let opened = encoder.open().map_err(ffmpeg_err)?;
@@ -2000,15 +2020,15 @@ impl EncoderState {
.chunks_exact_mut(4)
.zip(row.chunks_exact(PIXEL_F32_BYTES))
{
for c in 0..4 {
let v = f32::from_le_bytes([
in_px[c * 4],
in_px[c * 4 + 1],
in_px[c * 4 + 2],
in_px[c * 4 + 3],
]);
out_px[c] = (v * 255.0).clamp(0.0, 1.0) as u8;
}
for c in 0..4 {
let v = f32::from_le_bytes([
in_px[c * 4],
in_px[c * 4 + 1],
in_px[c * 4 + 2],
in_px[c * 4 + 3],
]);
out_px[c] = (v * 255.0).clamp(0.0, 255.0) as u8;
}
}
}
@@ -2068,11 +2088,11 @@ impl EncoderState {
unsafe { std::slice::from_raw_parts(samples.as_ptr() as *const u8, samples.len() * 4) };
input.data_mut(0)[..bytes.len()].copy_from_slice(bytes);
let mut converted = audio.resampler.convert_to_frame(&input)?;
let mut converted = audio.resampler.convert_to_frame(&input).map_err(|e| { eprintln!("DBG-AUD: convert failed: {e:?}"); fail(format!("{e:?}")) })?;
converted.set_pts(Some(pts));
output.audio_pts += converted.samples() as i64;
audio.encoder.send_frame(&converted).map_err(ffmpeg_err)?;
audio.encoder.send_frame(&converted).map_err(|e| { eprintln!("DBG-AUD: send failed: {e:?}"); ffmpeg_err(e) })?;
drain_audio_packets(&mut output.output, audio)
}
+5 -5
View File
@@ -388,7 +388,7 @@ mod tests {
use crate::bridge::common::oakcommon_videoparams_init_basic;
fn frame(w: i32, h: i32) -> Frame {
let params = unsafe { oakcommon_videoparams_init_basic(w, h) };
let params = unsafe { oakcommon_videoparams_init_basic(w, h, 0, 4, 1, 1, 0, 1) };
Frame::with_params(params)
}
@@ -459,12 +459,12 @@ mod tests {
#[test]
fn set_params_recomputes_linesize_without_realloc() {
let params = unsafe { oakcommon_videoparams_init_basic(10, 10) };
let params = unsafe { oakcommon_videoparams_init_basic(10, 10, 0, 4, 1, 1, 0, 1) };
let mut f = Frame::with_params(params);
f.allocate().unwrap();
let before = f.allocated_size();
let wider = unsafe { oakcommon_videoparams_init_basic(100, 10) };
let wider = unsafe { oakcommon_videoparams_init_basic(100, 10, 0, 4, 1, 1, 0, 1) };
f.set_params(wider);
// linesize reflects the new width, but the buffer is untouched.
assert_eq!(f.linesize_bytes(), 4 * 128);
@@ -478,7 +478,7 @@ mod tests_extra {
use crate::bridge::common::oakcommon_videoparams_init_basic;
fn frame(w: i32, h: i32) -> Frame {
let params = unsafe { oakcommon_videoparams_init_basic(w, h) };
let params = unsafe { oakcommon_videoparams_init_basic(w, h, 0, 4, 1, 1, 0, 1) };
Frame::with_params(params)
}
@@ -513,7 +513,7 @@ mod tests_extra {
#[test]
fn pixel_format_from_unknown_code_is_invalid() {
let p = unsafe { oakcommon_videoparams_init_basic(1, 1) };
let p = unsafe { oakcommon_videoparams_init_basic(1, 1, 0, 4, 1, 1, 0, 1) };
unsafe { crate::bridge::common::oakcommon_videoparams_set_format(p.clone(), 99) };
let f = Frame::with_params(p);
assert_eq!(f.format(), PixelFormat::Invalid);
+6 -6
View File
@@ -157,7 +157,7 @@ mod tests {
assert_eq!(mgr.live_count(), 0);
assert_eq!(mgr.peak_count(), 0);
let params = unsafe { oakcommon_videoparams_init_basic(64, 64) };
let params = unsafe { oakcommon_videoparams_init_basic(64, 64, 0, 4, 1, 1, 0, 1) };
let frame = mgr.create_frame(params);
assert_eq!(mgr.live_count(), 1);
assert_eq!(mgr.peak_count(), 1);
@@ -172,14 +172,14 @@ mod tests {
#[test]
fn pool_reuses_compatible_frames() {
let mgr = FrameManager::new();
let params = unsafe { oakcommon_videoparams_init_basic(64, 64) };
let params = unsafe { oakcommon_videoparams_init_basic(64, 64, 0, 4, 1, 1, 0, 1) };
let f1 = mgr.create_frame(params);
mgr.return_frame(Arc::try_unwrap(f1).unwrap());
assert_eq!(mgr.live_count(), 0);
// A compatible request reuses the pooled buffer rather than
// allocating a new one.
let f2 = mgr.create_frame(unsafe { oakcommon_videoparams_init_basic(64, 64) });
let f2 = mgr.create_frame(unsafe { oakcommon_videoparams_init_basic(64, 64, 0, 4, 1, 1, 0, 1) });
assert_eq!(mgr.live_count(), 1);
assert_eq!(mgr.peak_count(), 1);
Arc::try_unwrap(f2).unwrap();
@@ -188,8 +188,8 @@ mod tests {
#[test]
fn peak_count_tracks_maximum() {
let mgr = FrameManager::new();
let p1 = unsafe { oakcommon_videoparams_init_basic(64, 64) };
let p2 = unsafe { oakcommon_videoparams_init_basic(128, 128) };
let p1 = unsafe { oakcommon_videoparams_init_basic(64, 64, 0, 4, 1, 1, 0, 1) };
let p2 = unsafe { oakcommon_videoparams_init_basic(128, 128, 0, 4, 1, 1, 0, 1) };
let a = mgr.create_frame(p1);
let b = mgr.create_frame(p2);
assert_eq!(mgr.live_count(), 2);
@@ -203,7 +203,7 @@ mod tests {
#[test]
fn clear_drops_pooled_frames() {
let mgr = FrameManager::new();
let params = unsafe { oakcommon_videoparams_init_basic(64, 64) };
let params = unsafe { oakcommon_videoparams_init_basic(64, 64, 0, 4, 1, 1, 0, 1) };
let f = mgr.create_frame(params);
mgr.return_frame(Arc::try_unwrap(f).unwrap());
assert_eq!(mgr.pool.lock().unwrap().len(), 1);
+1
View File
@@ -48,6 +48,7 @@ pub mod oiioframebridge;
pub mod planarfiledevice;
pub mod proxymanager;
pub mod task;
pub mod testmedia;
pub mod timecodemetadata;
#[cfg(test)]
+10 -3
View File
@@ -36,6 +36,7 @@ use crate::bridge::common::{
};
use crate::frame::Frame;
use oakcore_rs::Rational;
use std::ffi::c_int;
/// Fixed header size, in bytes, of an OIIO frame buffer.
///
@@ -221,8 +222,14 @@ pub fn oiio_buffer_to_frame(buffer: &[u8]) -> crate::error::Result<Frame> {
oakcommon_videoparams_init_with_time_base(
header.width,
header.height,
header.time_base_num,
header.time_base_den,
header.time_base_num as c_int,
header.time_base_den as c_int,
0,
4,
1,
1,
0,
1,
)
};
unsafe {
@@ -347,7 +354,7 @@ mod tests {
/// test-stub params pattern as `frame.rs`.
fn make_frame() -> Frame {
// SAFETY: test-stub videoparams; ownership moves into `with_params`.
let params = unsafe { oakcommon_videoparams_init_with_time_base(100, 50, 1, 30) };
let params = unsafe { oakcommon_videoparams_init_with_time_base(100, 50, 1, 30, 0, 4, 1, 1, 0, 1) };
unsafe { oakcommon_videoparams_set_format(params.clone(), 0) }; // U8
let mut frame = Frame::with_params(params);
frame.set_timestamp(Rational::new(5, 2));
+2 -1
View File
@@ -503,7 +503,8 @@ mod tests {
#[test]
fn proxy_filename_derivation() {
let cache = temp_subdir("fn");
let id = fnv1a64(b"media.mp4") as i64;
let stub_id = fnv1a64(b"media.mp4") as i64;
let id = fnv1a64(stub_id.to_string().as_bytes()) as i64;
let p = ProxyManager::proxy_params_default();
let f = ProxyManager::get_proxy_filename(&cache, "media.mp4", 0, &p).unwrap();
+36 -1
View File
@@ -80,7 +80,7 @@ fn h264_params(out: &std::path::Path) -> crate::encodingparams::EncodingParams {
/// Build an allocated F32-RGBA frame with a moving color pattern.
fn pattern_frame(i: i32) -> Frame {
let vp = unsafe { oakcommon_videoparams_init_basic(64, 64) };
let vp = unsafe { oakcommon_videoparams_init_basic(64, 64, 0, 4, 1, 1, 0, 1) };
unsafe { oakcommon_videoparams_set_format(vp.clone(), PixelFormat::F32 as i32) };
let mut f = Frame::with_params(vp);
f.set_timestamp(Rational::new(i as i64, 10));
@@ -264,3 +264,38 @@ fn audio_conform_writes_planar_pcm() {
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn testmedia_clip_probe_roundtrip() {
let out = std::env::temp_dir().join(format!("oakcodec_tm3_{}.mp4", std::process::id()));
crate::testmedia::write_test_clip(&out, 64, 64, 10, 10).expect("generate");
let d = FFmpegDecoder::new();
let s = CodecStream::with_block(out.to_string_lossy().into_owned(), 0, None);
d.open(&s).expect("open");
for t in [0i64, 3, 5, 9] {
let f = d
.retrieve_video_frame(&video_params(s.clone(), Rational::new(t, 10)))
.unwrap_or_else(|e| panic!("decode t={t}: {e:?}"));
let stride = f.linesize_bytes() as usize;
let data = f.data().unwrap();
let off = 32 * stride + 8 * 16;
let px = [
f32::from_le_bytes(data[off..off + 4].try_into().unwrap()),
f32::from_le_bytes(data[off + 4..off + 8].try_into().unwrap()),
f32::from_le_bytes(data[off + 8..off + 12].try_into().unwrap()),
f32::from_le_bytes(data[off + 12..off + 16].try_into().unwrap()),
];
println!("t={t}/10 px(8,32): {px:?}");
}
let _ = std::fs::remove_file(&out);
}
#[test]
fn testmedia_audio_track_encodes() {
let out = std::env::temp_dir().join(format!("oakcodec_tm_audio_{}.mp4", std::process::id()));
crate::testmedia::write_test_clip(&out, 64, 64, 10, 10).expect("generate with audio");
let d = FFmpegDecoder::new();
let desc = d.probe(&out.to_string_lossy(), None).expect("probe");
assert!(desc.audio_stream_count() >= 1, "audio stream present");
let _ = std::fs::remove_file(&out);
}
+133
View File
@@ -0,0 +1,133 @@
// 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/>.
//! Program-generated test media (M12 P0).
//!
//! Encodes a small H.264 clip of known content through the real FFmpeg
//! encoder — no network, no committed binary assets. Used by the
//! oakrender decode tests and the app's render e2e to prove that the
//! footage-decode path produces real pixels with known values.
//!
//! Content contract (what a decode must observe):
//! - frame 0: left half solid `[r, g, b]`, right half solid
//! `[b, r, g]` (transposed), alpha 1 everywhere;
//! - later frames: the color columns sweep right by one column per
//! frame, so per-frame content is distinguishable after decode.
//!
//! MPEG-2 is used instead of H.264: the H.264 default profile emits
//! B-frames, and this FFmpeg pairing's movenc writes B-frame streams
//! with mangled packet timestamps (decode seeks then fail). MPEG-2's
//! default encoder is B-frame-free and its streams round-trip cleanly.
//!
//! H.264/H.265 is lossy, so assertions downstream should use generous
//! tolerances (channel dominance rather than exact values).
use std::path::Path;
use oakcore_rs::{PixelFormat, Rational, SampleFormat};
use crate::bridge::common::{
oakcommon_videoparams_init_basic, oakcommon_videoparams_set_format,
};
use crate::encodingparams::EncodingParams;
use crate::encoder::create_from_params;
use crate::frame::Frame;
use crate::error::{Error, Result};
/// Encode `frame_count` frames of the known pattern into `out` (an MP4 at
/// `fps` frames per second, `width`x`height`, H.264).
pub fn write_test_clip(
out: &Path,
width: i32,
height: i32,
frame_count: i32,
fps: i32,
) -> Result<()> {
if width <= 0 || height <= 0 || frame_count <= 0 || fps <= 0 {
return Err(Error::Invalid);
}
let mut params = EncodingParams::default();
let name = out.as_os_str().as_encoded_bytes();
if name.len() >= params.filename.len() {
return Err(Error::Failed("output path too long".into()));
}
params.filename[..name.len()].copy_from_slice(name);
params.format = 2; // MPEG-4 video container
params.video_enabled = 1;
params.video_codec = 10; // MPEG-2 (B-frame-free; the H.264 B-frame streams hit a muxer timing bug)
params.video_width = width;
params.video_height = height;
params.video_time_base_num = 1;
params.video_time_base_den = fps;
params.video_pixel_format = PixelFormat::F32;
params.video_interlacing = 0;
params.video_pixel_aspect_num = 1;
params.video_pixel_aspect_den = 1;
// A stereo PCM audio track with a known 440 Hz sine (M12 P1: the
// audio-render path needs a decodable audio stream; PCM avoids
// codec sample-format negotiation issues in this FFmpeg pairing).
params.audio_enabled = 1;
params.audio_codec = 13; // PCM S16LE
params.audio_sample_rate = 48000;
params.audio_channel_layout = 0x3; // stereo
params.audio_sample_format = SampleFormat::F32;
let encoder = create_from_params(&params)
.ok_or_else(|| Error::Failed("no encoder for test clip params".into()))?;
encoder.configure(&params)?;
encoder.open()?;
for i in 0..frame_count {
encoder.write_video(&pattern_frame(i, width, height, fps))?;
}
// One second of 440 Hz sine (stereo, both channels identical).
let rate = 48000u32;
let mut tone: Vec<f32> = Vec::with_capacity(rate as usize * 2);
for i in 0..rate {
let v = (i as f32 * 440.0 * std::f32::consts::TAU / rate as f32).sin() * 0.5;
tone.push(v);
tone.push(v);
}
encoder.write_audio(&tone, rate as i32)?;
encoder.flush()
}
/// One frame of the known pattern (see module doc).
fn pattern_frame(i: i32, width: i32, height: i32, fps: i32) -> Frame {
let vp = unsafe { oakcommon_videoparams_init_basic(width, height, 0, 4, 1, 1, 0, 1) };
unsafe { oakcommon_videoparams_set_format(vp.clone(), PixelFormat::F32 as i32) };
let mut f = Frame::with_params(vp);
f.set_timestamp(Rational::new(i as i64, fps as i64));
f.allocate().expect("test frame allocation");
let linesize = f.linesize_bytes() as usize;
let data = f.data_mut().expect("test frame buffer");
let shift = (i * width / (2 * fps.max(1))) % width;
for y in 0..height as usize {
for x in 0..width as usize {
let off = y * linesize + x * 16;
let (r, g, b) = if (x as i32 + shift) % width < width / 2 {
(0.9f32, 0.15f32, 0.05f32)
} else {
(0.05f32, 0.2f32, 0.85f32)
};
data[off..off + 4].copy_from_slice(&r.to_le_bytes());
data[off + 4..off + 8].copy_from_slice(&g.to_le_bytes());
data[off + 8..off + 12].copy_from_slice(&b.to_le_bytes());
data[off + 12..off + 16].copy_from_slice(&1.0f32.to_le_bytes());
}
}
f
}