Expand description
The extractor contract. Code outside the engine is supplied frames or audio and returns primitives that a project records as data sets.
An extractor runs ahead of time over a range, never while a frame renders. The host drives an
ExtractSession. It supplies each Need from its own decoders or renderer, hands each
Delivery to the extractor, and passes the extractor’s Emits back for the session to
validate. ExtractSession::finish returns sorted, validated data sets. Rust extractors
implement Extractor and run through drive; other surfaces wrap the same step machine.
Source frames are delivered display-oriented, contain-fit to at most size on the long edge
(delivered_size), as straight-alpha sRGB rgba8 or BT.709 luma8 (luma8_from_rgba8).
The module uses plain data only; the render path never calls it.
§A minimal extractor
The mean brightness of each timeline frame, as a scalars data set:
use alpha2_engine::extract::{
AudioInput, Descriptor, Emitter, ExtractRequest, ExtractSession, Extractor,
ExtractorError, Need, PassInfo, RunContext, SuppliedAudio, SuppliedFrame, Supplier,
VideoInput, delivered_size, drive,
};
use serde_json::json;
struct Brightness(Descriptor);
impl Extractor for Brightness {
fn describe(&self) -> &Descriptor {
&self.0
}
fn begin(&mut self, _context: &RunContext) -> Result<(), ExtractorError> {
Ok(())
}
fn pass(&mut self, _pass: &PassInfo) -> Result<(), ExtractorError> {
Ok(())
}
fn video(&mut self, frame: &VideoInput, out: &mut Emitter) -> Result<(), ExtractorError> {
let sum: u64 = frame.bytes.iter().map(|&value| u64::from(value)).sum();
let mean = sum as f32 / frame.bytes.len() as f32 / 255.0;
out.sample("level", frame.time, &[Some(mean)]);
Ok(())
}
fn audio(&mut self, _block: &AudioInput, _out: &mut Emitter) -> Result<(), ExtractorError> {
Ok(())
}
fn end(&mut self, _out: &mut Emitter) -> Result<(), ExtractorError> {
Ok(())
}
}
/// Grey frames; a host supplies decoded or rendered ones.
struct Grey;
impl Supplier for Grey {
fn frame(&mut self, need: &Need) -> Result<Option<SuppliedFrame>, String> {
let Need::TimelineFrame { time, size, .. } = need else {
return Err("timeline frames only".into());
};
let (width, height) = delivered_size((64, 36), *size);
let rgba = vec![128; (width * height * 4) as usize];
Ok(Some(SuppliedFrame { pts: *time, width, height, rgba }))
}
fn audio(&mut self, _need: &Need) -> Result<SuppliedAudio, String> {
Err("no audio".into())
}
}
let project = alpha2_model::Project::from_json(&json!({
"schema_version": 1, "id": "p", "name": "P",
"settings": { "width": 64, "height": 36, "frame_rate": { "num": 30, "den": 1 },
"sample_rate": 48_000 },
"sources": [], "timeline": { "tracks": [] }
}).to_string())?;
let descriptor: Descriptor = serde_json::from_value(json!({
"id": "com.example.brightness", "version": 1,
"input": { "media": "video", "from": ["timeline"], "format": "luma8" },
"outputs": [{ "name": "level", "kind": "scalars", "channels": ["y"] }]
}))?;
let request: ExtractRequest = serde_json::from_value(json!({
"extractor": "com.example.brightness", "version": 1,
"input": { "from": "timeline", "range": { "start": 0, "end": 12_000 }, "size": 32 },
"outputs": { "level": "brightness" }
}))?;
let session = ExtractSession::new(&project, &descriptor, request)?;
let sets = drive(session, &mut Brightness(descriptor), &mut Grey)?;
assert_eq!(sets[0].id.as_str(), "brightness");§Limits
- Outputs per descriptor:
MAX_EXTRACTOR_OUTPUTS; passes per request:MAX_EXTRACTOR_PASSES. - A delivered frame’s long edge when the descriptor names none:
DEFAULT_MAX_SIZE. - Frames per audio block:
BLOCK_FRAMES_RANGE,DEFAULT_BLOCK_FRAMESwhen unnamed. - Plugin manifest size:
MAX_MANIFEST_BYTES; artifacts and resources per manifest:MAX_PLUGIN_ARTIFACTS,MAX_PLUGIN_RESOURCES; file lengths:MAX_PLUGIN_ARTIFACT_BYTES,MAX_PLUGIN_RESOURCE_BYTES,MAX_PLUGIN_RESOURCES_TOTAL_BYTES. - Data sets per project:
alpha2_model::MAX_DATA_SETS; channels per output:alpha2_model::MAX_DATA_CHANNELS. - Values, words and intervals per data set:
alpha2_model::MAX_DATA_VALUES,alpha2_model::MAX_DATA_WORDS,alpha2_model::MAX_DATA_INTERVALS. - Data set ids, and labels, texts, speakers and channel names:
alpha2_model::MAX_DATA_ID_BYTES,alpha2_model::MAX_DATA_LABEL_BYTES. - Emitted values:
alpha2_model::MAX_DATA_COORDINATEfor points and similarity translation,alpha2_model::MAX_DATA_SCALARfor scalars and interval scores, and for similarityalpha2_model::MAX_DATA_ROTATION_DEGREESandalpha2_model::MAX_DATA_SCALE.
Structs§
- Audio
Input - An audio block handed to the extractor.
- Descriptor
- What an extractor declares, with its identity, the input it reads and the outputs it emits.
- Emitter
- Collects what an extractor emits for one call; the session validates it afterwards.
- Extract
Request - One run of an extractor.
- Extract
Session - One run of an extractor over a range, driven by the host.
- Extractor
Error - An extractor’s own failure, carried to the caller as is.
- Frame
Place - Where a supplier may write a frame’s pixels: memory the extractor offers.
- Output
Spec - One output an extractor emits.
- Pass
- One pass of a run, from a start time in one direction.
- Pass
Info - A pass beginning, as an extractor is told.
- Pass
Progress - How far one pass is, by deliveries and by time.
- Pinned
Resource - A file the manifest pins.
- Plugin
About - What an interface shows about a plugin: plain text, never markup, without control characters.
- Plugin
Artifact - One build of a plugin.
- Plugin
Manifest - A plugin’s manifest.
- Plugin
Resource - A file a plugin reads: pinned by the manifest, or supplied by the caller at load time.
- Request
Input - What a run reads.
- RunContext
- What the extractor is told when the run begins.
- Supplied
Audio - A supplied audio block: planar f32, channel after channel.
- Supplied
Frame - A supplied video frame: tightly packed straight-alpha sRGB RGBA8 at its delivered size.
- Supplied
Slot - A resource slot the caller fills at load time.
- Video
Input - A frame handed to the extractor.
Enums§
- Artifact
Kind - What kind of code an artifact is.
- Audio
Channels - Which channels delivered audio has.
- Audio
Format - How delivered audio is stored.
- Delivery
- An input handed to the extractor.
- Direction
- The direction of a pass.
- Drive
Error - Why a run did not complete.
- Emit
- One value an extractor emits.
- Frame
From - Where a source frame is asked for, relative to what the pass has seen.
- Input
From - Which clock an extractor reads on.
- Input
Spec - What an extractor reads.
- Manifest
Error - Why a manifest was refused.
- Need
- What the host must supply next.
- Plugin
Kind - The contract a plugin implements.
- Reference
- What a manifest’s
urlnames. - Request
Error - Why a session could not start.
- Resource
Source - Where a resource’s bytes come from.
- Session
Error - Why the session refused something.
- Slot
Shape - What the caller names for a slot.
- Stage
- The part of a run a progress report describes.
- Step
- What the session asks for or hands over next.
- Suggest
- How an output is usually used.
- Video
Format - How delivered video frames are packed.
Constants§
- BLOCK_
FRAMES_ RANGE - The range of
block_framesa descriptor may declare. - DEFAULT_
BLOCK_ FRAMES - Audio frames per delivered block when the descriptor gives none.
- DEFAULT_
MAX_ SIZE - The longest edge of a delivered video frame when the descriptor gives none.
- MAX_
ABOUT_ AUTHOR_ CHARS - The longest
about.author, in characters. - MAX_
ABOUT_ HOMEPAGE_ CHARS - The longest
about.homepage, in characters. - MAX_
ABOUT_ LICENSE_ CHARS - The longest
about.license, in characters. - MAX_
ABOUT_ NAME_ CHARS - The longest
about.name, in characters. - MAX_
ABOUT_ SUMMARY_ CHARS - The longest
about.summary, in characters. - MAX_
EXTRACTOR_ OUTPUTS - Most outputs one extractor declares.
- MAX_
EXTRACTOR_ PASSES - Most passes one request asks for.
- MAX_
MANIFEST_ BYTES - The longest manifest text accepted.
- MAX_
OUTPUT_ DESCRIPTION_ CHARS - The longest output
description, in characters. - MAX_
OUTPUT_ LABEL_ CHARS - The longest output
label, in characters. - MAX_
PLUGIN_ ARTIFACTS - Most artifacts one manifest lists.
- MAX_
PLUGIN_ ARTIFACT_ BYTES - The longest artifact a manifest may pin, in bytes.
- MAX_
PLUGIN_ RESOURCES - Most resources one manifest lists.
- MAX_
PLUGIN_ RESOURCES_ TOTAL_ BYTES - The most bytes a manifest’s resources may pin together.
- MAX_
PLUGIN_ RESOURCE_ BYTES - The longest resource a manifest may pin, in bytes: what a wasm module’s memory can address.
- MAX_
PLUGIN_ SLOTS - The most resource slots one manifest declares, inside
MAX_PLUGIN_RESOURCES. - MAX_
SLOT_ ACCEPT - The most file name suffixes one slot’s
acceptlists. - MAX_
SLOT_ ACCEPT_ BYTES - The longest file name suffix in a slot’s
accept, in bytes. - MAX_
SLOT_ NAME_ BYTES - The longest slot name, in bytes.
- PLUGIN_
MANIFEST_ SCHEMA_ ID - Where the plugin manifest schema is published.
- WASM_
TARGET - The target of a wasm artifact.
Traits§
- Extractor
- A function that is supplied frames or audio and returns primitives. Runs ahead of time over a range; what it emits is recorded as data sets.
- Supplier
- Supplies the inputs a session asks for: decoded and presented frames, or audio.
Functions§
- client_
context_ json - The run context as clients are told it at
begin. - delivered_
size - The size a frame of displayed size
(width, height)is delivered at for a requestsize: contain-fit so the long edge is at mostsize, never upscaled, each edge rounded half up and at least one pixel. - displayed_
size - The displayed size of a decoded frame, its visible rectangle widened by the pixel aspect ratio (rounded half up) and turned upright.
- drive
- Runs
extractorthroughsession, supplying inputs fromsupplier, and returns the session’s data sets. - emit_
from_ json - An emit as clients write it,
{ output, time, values }for samples (nulla lost channel),{ output, start, end, text, speaker? }for words, and for intervals{ output, start, end, label?, score? }. - is_
slot_ name - Whether
nameis a slot name: 1 to 64 ofA-Z a-z 0-9 . _ -, not starting with.. - luma8_
from_ rgba8 - BT.709 Y’ of straight-alpha sRGB-encoded RGBA8 pixels, rounded half up; alpha is ignored.
- mono_
downmix - The mixer’s mono fold of
planes, whose speakers arespeakers. Each plane is weighted by the mean of its stereo weights and summed in plane order.Nonefor no planes or too many. - present_
for_ extraction - A decoded frame presented on the CPU renderer as an extraction delivery: display-oriented,
contain-fit to at most
sizeon the long edge, straight-alpha sRGB RGBA8. HDR is tone-mapped with the default tone map. - present_
for_ extraction_ into present_for_extraction, writing the pixels into the memoryplacegives when it gives some; the returned frame’srgbais then empty.- progress_
json - A run’s progress as every surface reports it: the
stageit is in, thepassthat concerns, and that pass’scompleted,total,coveredandspan. - reference
- Reads a manifest’s
urlas a path under the manifest’s directory or anhttps:URL. - supply_
frame - Answers a frame need of
sessionfromsupplier, in memoryextractoroffers when it offers some: the supplier writes RGBA frames there, the session a frame’s luma;drivedoes this for every frame need.