forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 2e2ed698a69459f7ce472eabcbc01b00a0916d3fFiltered to crates/engine/src/playback.rsClear filter

2026-08-10

✨ feat(library): every audio stream is a row, and the picked one plays and exportsAhmet Kaan Gümüş · ecb5e06
✨ feat(library): every audio stream is a row, and the picked one plays and exports

A file with one audio track per language is one row per track now, not one row
per file. The engine carries the pick end to end: a source is a (file, audio
stream) pair, .edith v3 writes the stream on the source line, playback opens it
and — the trap this closes — the export copies *that* stream's packets rather
than always stream 0.

Streams that cannot go on the timeline are listed greyed with the reason
instead of hidden: a codec we cannot read, or a rate/layout that cannot share
one output device and one copied AAC track with the rest of the timeline (there
is no resampler here and no AAC encoder to write a join with). place_stream_at
is the one door a row goes through, and it refuses those in the engine's own
words.

- v2 and v1 files still load: no stream field means stream 0, which is all
  those dialects could play; saving either writes v3.
- Waveform peaks are keyed by file *and* stream, so two tracks of one file
  cannot draw each other's envelope.
- Library swatches and clip tints follow the *file*, so a file's streams share
  one colour in the panel and on the lanes.
- assets/test_multilang.mp4: two AAC 44.1k stereo streams (und, fra), the shape
  real multi-language media has and the one where a second stream is placeable.
🐛 fix(engine): NTSC frame rates survive the sample tableAhmet Kaan Gümüş · 3f81ef8
🐛 fix(engine): NTSC frame rates survive the sample table

`mp4 0.14`'s `Mp4Track::frame_rate` divides the sample count by whole
milliseconds before the float cast, so 24000/1001 read back as a flat
23.0: the picture the audio-sample master clock asked for was 4 % out and
the drift grew with the film — five minutes of it by the end of a
two-hour one. The frame rate now comes off the stts totals in f64, which
is exactly `timescale / delta` for a constant table and an average for a
spread one.

The same truncation lived at the writing end (a 90 kHz clock cannot count
23.976 fps in whole ticks), so the muxer picks a timescale that can:
90 kHz wherever it divides exactly — every integer rate, so those exports
are byte for byte what they were — and `round(fps * 1001)` over 1001
ticks otherwise, which is exact for the whole NTSC family. The hardware
encoder gets that same rational instead of a rounded `fps * 1000`.

The video edit list is honoured now too, the way the audio one always
was — but only what it really trims: a `media_time` equal to the first
`ctts` offset is the B-frame composition delay, not a cut, and reading it
as one throws two real frames away.

A file whose audio we cannot decode at all (an AC-3 remux) played silent
with the reason on stderr; the session carries it now and the window says
NO AUDIO in its notice bar.
🐛 fix(engine): a refused project load cannot hang on its own decoderAhmet Kaan Gümüş · 771cd4a
🐛 fix(engine): a refused project load cannot hang on its own decoder

`open_project` starts decoding source 0 before it validates anything, so
by the time a later source is refused that worker has filled the
two-frame channel and parked in `send`. The receiver and the worker were
two locals, and locals drop in reverse order of declaration: the worker
joined a decode thread that only the receiver beside it could ever wake.
The app froze on a bad project file instead of showing the error.

The two are one value now. `FrameStream` holds the receiver first and
the worker second, and Rust drops fields in declaration order, so the
disconnect always precedes the join -- in an early return, on an unwind,
and in call sites not written yet. Nothing on the seek path changes:
`start_span` still installs the new receiver and parks the old worker in
the retire list without ever joining.

The device moves below the validation for the same reason. Its feeder
thread outlives the `Audio` value and only a session's `drop` retires
it, so a refusal above that line left a PipeWire stream and a thread
behind for a project that never opened.

Tests: dropping a stream whose frames nobody took returns instead of
hanging (10 s bound; hangs if the two fields are swapped), and the
refusal path itself with enough sources that the park is certain -- 60 s
hang before the fix, 0.04 s after.
✨ feat(timeline): two lanes, waveforms, group-scoped selectionAhmet Kaan Gümüş · 591afa3
✨ feat(timeline): two lanes, waveforms, group-scoped selection

V1 and A1 get a fixed header column and a bed of their own, both offset
by the same constants the ruler now is, so one x maps to one moment in
all three rows. Clips are placed at their own start rather than queued
edge to edge: a lift leaves a hole and the bare bed showing through it
is how a gap looks.

Audio clips paint their source's min/max envelope, cached per file and
normalised to its own loudest sample -- the fixtures peak near an eighth
of full scale and would otherwise draw as a flat line. A click marks the
whole group and acts on the half it landed on, which is what makes a
detached half separately deletable.

Two actions the lane model owed a key: Regroup rejoins what a Cut split,
Lift removes one half and leaves the gap. Both auto-list in the
keybindings overlay and are rebindable like the rest.

`PlaybackSession::lane_clips` is the one engine addition: link ids and
source ranges are what a two-lane front-end draws with, and no existing
accessor carries either.
✨ feat(engine): real silent AAC for export gaps, link + overflow guardsAhmet Kaan Gümüş · 301e29b
✨ feat(engine): real silent AAC for export gaps, link + overflow guards

Grafts the losing candidate's hand-written AAC-LC silence into the
offset-placed lanes: a gap in the audio lane is copied as max_sfb=0
access units (4 bytes mono, 7 stereo, verified against our own decoder)
instead of being spent as stts duration on the packet in front of it.
That retires the 23 ms leading-gap misplacement, so every packet is one
1024-frame sample table entry again and the muxer takes no duration.

from_parts becomes the release-active untrusted door it claims to be:
per-cause errors, an end-overflow bound, and the grouping rules -- a
link id names at most one clip per lane, and a pair covers one span.
The parser bounds the same overflow by line number, `place` strips the
incoming group id, and the two lane surgeries (`clear`, `open_room`)
drop the id from what they cut, which is where duplicates came from.
🔊 feat(audio): volume and mute for the monitoring outputAhmet Kaan Gümüş · bb07bdc
🔊 feat(audio): volume and mute for the monitoring output

One knob down the stack: `ao_set_volume(handle, gain)` scales the samples
in the RT callback, and mute is a gain of 0.0. Not the stream's PipeWire
volume control -- WirePlumber persists every Props change into its restore
state (measured on this box: the bucket gains `mute:true` ~2 s later), so
a mute keypress would have become "edith has no sound" in tomorrow's
system mixer, which is the bug 9ab4ebd just finished removing.

Volume and mute stay independent: turning the level down while muted must
not be what makes sound come out. The button says both at once.

Mute is not pause -- the frames are still consumed, so the device clock,
and with it the picture, runs straight through.

The keybindings card's row list now scrolls inside a cap, which is the
upgrade path its own ponytail named: three more actions no longer fit a
360 px window, and now no number of them can stop fitting.
✨ feat(engine): video+audio lanes with offset-placed clips, gaps, .edith v2Ahmet Kaan Gümüş · 59eb78e
✨ feat(engine): video+audio lanes with offset-placed clips, gaps, .edith v2

Project gains two lanes; a Clip now carries `start` (its timeline
placement) and `link` (group id), so a gap is simply the absence of a
placement rather than an object anyone has to keep in sync. Moves and
trims become arithmetic on start/in_frame; the lane invariant (sorted,
non-overlapping) is checked in from_parts, at the .edith parser, and
asserted after every mutation.

split cuts every lane and hands the two sides fresh group ids; regroup
is its exact inverse. delete still ripples both lanes (the app keeps its
behaviour), lift removes one placement and leaves a hole, place is the
per-lane overwrite that can make one.

A video gap plays as black frames from a worker that opens no file --
same channel, backpressure, cancel and retire path as a decoder -- and
exports as encoded black. An audio gap is synthesised zero chunks, real
ones, so the master clock keeps counting through it; on the export side
it is spent as stts duration on the packet beside it, since there is no
AAC encoder to make silence with.

.edith v2 writes one line per placement per lane; v1 files still load,
as fully-grouped gapless lanes, and save as v2.

2026-08-09

⚡ perf(playback): retire cancelled workers off the seek pathAhmet Kaan Gümüş · 3adbaf7
⚡ perf(playback): retire cancelled workers off the seek path

Joining the outgoing decode worker inline made a seek pay whatever VA-API
init that worker was still inside -- 98.4 ms worst case against 1.6 ms
before the join landed, i.e. a scrub capped at ~10 seeks/s with a visible
hitch per step.

Cancelled workers now go into a retire list instead. Every seek sweeps it,
dropping only the ones whose thread has already returned (`is_finished`,
never a wait), and the session's drop joins whatever is left along with the
running worker -- so the exit guarantee is untouched: no decode worker
outlives its session, and none can be inside libva when Mesa's atexit
handlers run.

Worst seek back to 4.7-6.1 ms over three drill runs. Open+drop stays at
~13.5 ms, which is the same join as before and a session drops rarely.
Retire list peaked at 16 under a back-to-back 20-seek loop -- a UI scrub
leaves far more time between steps.
🐛 fix(decode): join workers on drop — Mesa atexit race killed exiting processesAhmet Kaan Gümüş · 9276137
🐛 fix(decode): join workers on drop — Mesa atexit race killed exiting processes

A decode worker was spawned detached and nothing ever waited for it, so a
process could exit while a worker sat inside `vaInitialize`. Mesa frees its
process name from an `atexit` handler and the worker then reads it back
NULL: SIGSEGV at exit, 9 runs in 20 of the saveload suite.

`DecodeSession::open_worker` now hands the caller a `Worker` that owns the
`JoinHandle`; dropping or replacing one cancels and joins. `PlaybackSession`
holds one, so a seek, a clip boundary and the session's own drop all wait
for the worker they abandon. The worker also checks the cancel flag before
and after opening the hardware session, so a cancelled one never enters
VA-API init at all. Public `open`/`open_at`/`open_range` are unchanged.
✨ feat(engine): .veproj save/load — relocatable, validated, atomicAhmet Kaan Gümüş · ac60b80
✨ feat(engine): .veproj save/load — relocatable, validated, atomic

A project file is line-based text: `veproj 1`, an optional playhead, one
`source` line per file and one `clip` line per range. Text because a path is
bytes on this platform and a JSON string could not carry one losslessly, so the
path field is byte-escaped instead; paths under the project's own directory are
written relative to it, which makes a folder of media plus its .veproj movable
anywhere. The parser is strict and every refusal names its 1-based line, and
writing goes through .part + rename as an export does.

Loading is a new session, never a mutation of the old one: source 0 defines the
timeline, every other source passes the same checks import applies (in the same
words), and every clip has to still fit inside the file it plays from -- a
source that vanished or shrank is a refusal that names it, not a silently
shorter timeline. Sources no clip plays from are pruned at save, so an import
that was undone cannot leave a file behind that blocks a future load.
✨ feat(engine): multi-source traversal, import validation, cross-source exportAhmet Kaan Gümüş · 68b0ca2
✨ feat(engine): multi-source traversal, import validation, cross-source export

Wave 2 of the import slice, two packages merged at one seam.

Playback traversal (S3): next_clip/seek open each clip against
project.sources()[clip.source]; audio switches to open_multi_segments over
the (source, start, end) triples segments_from now yields. New
PlaybackSession::import validates dimensions, fps and audio params against
the timeline before appending, and reseeks unconditionally so a running
audio worker learns the appended tail. clip_spans_by_source() added for the
app's per-source tint.

Cross-source export (S4): export::start drops its source path argument --
Project::sources() is the only path truth now -- and is pub so a test can
build a multi-source Project without a session. Each clip opens its own
ClipDecoder; the audio pass carries one bresenham accumulator across source
joins.

Seam: PlaybackSession::path is gone. It was kept only to feed export_to,
which no longer takes a path, so the field and its initialiser go with it.
✨ feat(engine): multi-source model + segmented multi-file audioAhmet Kaan Gümüş · 5593a9f
✨ feat(engine): multi-source model + segmented multi-file audio

Wave 1 of the import slice: the timeline model and the audio backend both
learn about several source files. Nothing user-visible yet — every clip is
still source 0 until playback/export traversal lands.

S1 — project.rs model + mechanical call-site fixes:
- Clip gains `source: usize` (Clip stays Copy, so clipboard/undo semantics
  are untouched); Project gains an append-only `sources: Vec<PathBuf>`.
- Import splits in two: `import(path) -> usize` is dedup-only and pushes no
  history, `append_clip(source_idx, frame_count) -> bool` pushes the one
  snapshot — an import stays exactly one undo step, and append_clip refuses
  an unknown index.
- Dedup key is fs::canonicalize with a raw-path fallback, so Project stays
  pure data and an unreadable path still gets an index.
- cut/paste carry the source through `..self.clips[idx]` struct-update.
- `segments_from` now yields (source, start, end) triples; playback.rs and
  export.rs strip the index and keep feeding the single-source audio fns.

S2 — audio.rs Track/probe/bit-exact joins:
- New private `Track` resolves one source once (reader, copied stts, own
  priming, params, sample_count).
- `open_multi_segments` / `copy_multi_segments` take the source triples;
  `open_segments` / `copy_segments` are now one-source wrappers, so every
  existing call site compiles unchanged.
- Each source contributes its own priming and length; the timeline sample
  counter and the bresenham rounding debt both run continuously across a
  source join, and the extra priming packet stays the first segment's alone.
- `AudioSession::probe(path) -> Option<AudioProbe>` exposes the fields
  import validation needs.
- Cross-source decode is bit-exact against single-file open_at on both
  sides of a join (max abs diff 0e0).
✨ feat(engine): export — edit list to mp4, HW encode with SW fallbackAhmet Kaan Gümüş · 86d5c15
✨ feat(engine): export — edit list to mp4, HW encode with SW fallback

Worker thread per export: decodes each clip straight to I420 (never through
DecodeSession, which only speaks BGRA), feeds one encoder chosen once --
VA-API plugin unless VE_SW_ENC=1 or the plugin is unavailable, rusty_h264
Fast/CBR otherwise -- and muxes the access units as they come. Audio is
copied packet for packet, so the file has to be opened before the first
video sample is written.

Cancel and every error path delete the partial file; progress is a permille
atomic a render loop can read without a lock.

mux: the movie timescale moves to 90 kHz. mp4 0.14 converts each sample
duration into the movie timescale with its own integer division, so 1 kHz
lost 0.33 ms per frame and made a 4.000 s export announce 3.960 s.
✨ feat: copy/paste clips at playheadAhmet Kaan Gümüş · aae5734
✨ feat: copy/paste clips at playhead

Project::paste splices a clip in at a timeline position, splitting the
clip under it when the position is mid-clip and appending past the end.
One history snapshot, so one undo takes a paste back.

PlaybackSession::clip_at hands a clip out for copying and paste_at goes
through the same edit() reseek as delete/undo. The app keeps an
Option<Clip> clipboard on ctrl+c / ctrl+v.
🧹 chore(playback): S6 follow-ups — epsilon frame conversion, drop dead frames()Ahmet Kaan Gümüş · 79c1a91
🧹 chore(playback): S6 follow-ups — epsilon frame conversion, drop dead frames()

secs_to_frame with 1e-6 epsilon: bare truncation landed one frame
early for boundary seconds (122.999... -> 122); floor semantics kept
for mid-frame positions. frames() getter had zero callers since the
app moved to try_frame().
✨ feat(playback): edit-list traversal — timeline frames, cut/delete/undoAhmet Kaan Gümüş · 7d2251c
✨ feat(playback): edit-list traversal — timeline frames, cut/delete/undo

PlaybackSession owns a Project. try_frame() rewrites every frame index from
source to timeline and reopens the next clip's range when a worker ends, so a
timeline of clips plays as one contiguous sequence; is_eos() is the real end.
seek() maps timeline seconds through the edit list and feeds the audio worker
one segment list for the whole rest of the timeline, so clip joins are gapless.
cut_at is metadata only, delete_clip/undo reseek onto the new mapping.

frames() stays for now: the app switches to try_frame in the UI slice.
✨ feat(playback): seek — rebuild workers, epoch-guarded feeder, clock re-anchorAhmet Kaan Gümüş · e4ca3bd
✨ feat(playback): seek — rebuild workers, epoch-guarded feeder, clock re-anchor

PlaybackSession::seek(secs) replaces both decode workers instead of
steering them: a fresh channel cannot hold a stale frame, and it works
after EOF where the old workers have already exited.

The audio device stays open across a seek. An epoch counter, bumped and
flushed while holding the device lock and re-checked by the feeder inside
that same lock right before every write, is what stops a superseded feeder
from landing stale PCM behind the flush. `fed` is re-based on the device
position, which keeps counting across a flush, so the audio-EOF test stays
exact.
✨ feat(engine): seek primitives — video open_at, ao_flush, audio open_atAhmet Kaan Gümüş · 96ae365
✨ feat(engine): seek primitives — video open_at, ao_flush, audio open_at

Lane 1 of the seek slice; PlaybackSession orchestration comes next.

- demux/decode: stss sync lookup, DecodeSession::open_at decodes from
  the keyframe and discards to the target; Frame.index stays absolute.
  HW plugin ABI: vh_open renamed vh_open_at(path, target) — discards
  skip the vaGetImage readback; measured seek cost 65ms HW / 222ms SW
- engine-audio: ao_flush drains the ring consumer-side in the RT
  callback (one-shot atomic), stale PCM unplayable even when paused;
  played-position atomics untouched so clock math survives
- audio: open_at walks stts, 2-packet AAC pre-roll (MDCT overlap
  reconstructed exactly — verified 0-diff before the first PNS band),
  sample-exact trim; priming skip and seek discard unified. AAC seek
  is deliberately not bit-exact: symphonia's PNS noise LCG state
  depends on packet history; bounded <1e-3 by test instead
🐛 fix(playback): dead audio output froze the clock foreverAhmet Kaan Gümüş · 752c6a0
🐛 fix(playback): dead audio output froze the clock forever

Verifier finding: feed() noticed the plugin dying (write -> None) but
only set fed_all; tick()'s switch-to-wall needed position >= fed,
which a frozen position can never satisfy. Explicit died flag now
hands the timeline to wall time on the next tick.
✨ feat(playback): A/V session — audio-master clock, real-speed video, space to pauseAhmet Kaan Gümüş · 63e6964
✨ feat(playback): A/V session — audio-master clock, real-speed video, space to pause

engine::playback::PlaybackSession wires DecodeSession + AudioSession +
AoSession + PlaybackClock together behind open/play/pause/toggle/now/tick.
A feeder thread pours decoded chunks into the device ring; tick() polls the
device position into the clock and switches to wall time at audio EOF.
Every audio failure (no track, no plugin, no daemon) degrades to a
wall-paced silent session.

The app renders against the clock: drain every due frame, show the last
(drop-when-behind), hold one that is early. Space toggles playback.