forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 2e2ed698a69459f7ce472eabcbc01b00a0916d3f

2026-08-09

✨ 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(engine-hw): vh_enc_* — VA-API H.264 encode with Mesa slice-header fixupAhmet Kaan Gümüş · b75c83e
✨ feat(engine-hw): vh_enc_* — VA-API H.264 encode with Mesa slice-header fixup

The plugin grows an encode half beside the decode one:
vh_enc_open/vh_enc_frame/vh_enc_drain/vh_enc_close, and engine::hw
gains HwEncoder behind a SEPARATE symbol table. That separation is the
point -- a libengine_hw.so predating this commit must keep decoding, so
the four new symbols must not join the decode Plugin struct where a
missing one would take decode down with them. Absent symbols just mean
HwEncoder::open returns None and the caller falls back to the
rusty_h264 software encoder.

Measured on radeonsi (Mesa 26.1.5): 3.98 ms/frame at
1280x720 CBR 4 Mbps including the I420->NV12 upload, against 25.6
ms/frame for rusty_h264 Fast at the same size -- 6.4x. Profile Main,
level 4, LowDelay so there are no B-frames and coded order is display
order; radeonsi exposes no VAEntrypointEncSliceLP for H.264 so
low_power stays off. One reusable DMA-BUF frame carries every picture
because BlockingMode::Blocking plus a poll() in each entry point syncs
the coded and recon promises before returning. Non-16-aligned sizes
allocate aligned surfaces, carry the true size in the SPS crop, and
replicate the edge pixel into the padding rather than shipping gbm
garbage there.

The one ugly part is fix_slice_nal_headers. cros-codecs supplies no
VAEncPackedHeaderH264_Slice, and Mesa fills forbidden_zero_bit /
nal_ref_idc / nal_unit_type only from a packed slice header, so every
slice NAL leaves the encoder with a 0x00 header byte and both ffmpeg
and rusty_h264 refuse the stream. Patching that single byte per slice
makes both decode it fully. An all-zero header byte is never valid
H.264, so the rewrite is a no-op on drivers that write it properly
(Intel iHD, which cros-codecs was built against). Marked ponytail; the
real fix is a packed slice header in vendor/cros-codecs.
✨ feat(engine): export lane 1 — mux module, AAC packet copyAhmet Kaan Gümüş · 5ce68fe
✨ feat(engine): export lane 1 — mux module, AAC packet copy

mux.rs is the write side of demux.rs: split_annex_b/nal_type feed a
repack to 4-byte-length-prefixed samples (mp4 0.14 hardcodes
length_size_minus_one=3), SPS/PPS/AUD/SEI stripped out of the sample
bytes, is_sync taken from an actual NAL type 5 rather than GOP
arithmetic. Mp4Muxer::create wants the parameter sets up front, so
mux::parameter_sets pulls them out of a buffered first access unit
before the muxer exists. Timescales are 90000 video / sample_rate audio
/ 1000 movie, per-frame duration (90000/fps).round(), and mp4 0.14
ignores Mp4Sample::start_time on write -- timing is duration
accumulation only. An SPS shorter than 4 bytes panics inside the crate
(avc1.rs indexes sps[1..3]), so create rejects that and the other
degenerate shapes up front instead.

Audio is copied, not re-encoded: there is no pure-Rust AAC encoder and
mp4 0.14 has no PCM MediaConfig, so the only honest option is to hand
the source packets back through verbatim.
AudioSession::copy_segments does that -- stts walk to packet ids, no
decode, bytes straight from read_sample. Cut points do not land on
1024-sample boundaries (23.2 ms packets vs 33.3 ms frames), so a
bresenham accumulator picks the packet run per segment and keeps the
cumulative A/V offset under 512 samples, proven by induction over the
carry and measured over 200 random join lists. The first segment starts
one packet early to feed the 1024-sample priming drop; interior
segments do not, because an extra head packet there is 23 ms of
pre-cut audio at every join and it would not fix the missing MDCT
predecessor anyway. That artifact is documented at the seam.
🐛 fix(audio): stop the pause leaking into the playback clockAhmet Kaan Gümüş · bffc034
🐛 fix(audio): stop the pause leaking into the playback clock

The graph clock keeps ticking while our stream is inactive, so the first
process callback after a resume reported a position a whole pause ahead
of what the device had played -- and the master clock jumped by exactly
that much. Measured on test_av.mp4: a 300 ms pause moved the timeline
+0.32 s, a 1000 ms pause +1.045 s, linear, with the audio itself carrying
on from where it stopped. Video then raced to catch a clock the ear could
not follow.

Fold the inactive stretch into a skew instead of the position, so
ao_position keeps meaning "samples actually played" across a pause -- the
comparison `played_out` already assumed.

This is what tests/playback.rs:88 audio_video_plays_at_real_speed has
been red on: a true positive, not a load-sensitive margin. It fails 2/3
at --test-threads=1 as well; whether it lands under the 0.7 s bound was
decided by how much the audio clock lagged in the first 2 s (1.79 s ->
pass, 1.98 s -> fail), which offsets the constant jump.
✨ 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(app): clips lane — cut/delete/undo, drag-scrubAhmet Kaan Gümüş · 5372bfd
✨ feat(app): clips lane — cut/delete/undo, drag-scrub

- clips lane: one box per clip, proportional widths, click-select,
  ACCENT-tinted selection; plain divs keep spacebar focus
- keys c (cut at playhead) / x or delete / z (undo) + drawn buttons;
  is_held guards all four against auto-repeat editing
- drag-scrub on the root div (gpui has no mouse capture — release
  outside the window is caught by clearing scrub on a moved event
  with no left button); throttle: seek only on frame change + 100ms,
  always commit on release
- cached duration deleted — timeline_duration() dynamic, so delete
  shrinks ruler and timecode immediately
✨ 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(engine): clips primitives — edit-list model, bounded decode, segmented audioAhmet Kaan Gümüş · e75a7ba
✨ feat(engine): clips primitives — edit-list model, bounded decode, segmented audio

Lane 1 of the clips slice; PlaybackSession traversal comes next.

- project.rs: Clip/Project — cut (metadata-only, refuses no-op
  splits), delete (closes gap, keeps ≥1 clip), undo snapshots,
  timeline↔source mapping with boundary sweep tests
- decode: open_range(start, end) — both backends stop after end-1,
  empty/inverted ranges disconnect cleanly without spawning a worker
- audio: open_segments — one worker walks the edit list; segments
  bit-exact vs equivalent seeks, joins gapless by contiguity assert,
  head+tail trim inside a single AAC packet handled
🐛 fix(engine-audio): paused seek ate 1.49s of post-seek audioAhmet Kaan Gümüş · e259516
🐛 fix(engine-audio): paused seek ate 1.49s of post-seek audio

S6 verifier finding: ao_flush is consumed only by the next RT
callback; while paused there are none, so the new feeder filled the
ring behind the pending flag and the first post-resume callback
drained the new stream's head (measured 151 underruns = 1.49s = ring
capacity, audio then 1.5s ahead of picture).

ao_write now refuses samples while a flush is pending (accept()
mirrors consume(); feeder's retry loop parks until the RT thread
takes the flag). Probe re-run: paused seek 86 underruns = no-drop
baseline; mid-play unchanged at 130.
✨ feat(app): click-to-seek ruler, post-EOF restartAhmet Kaan Gümüş · 14821ab
✨ feat(app): click-to-seek ruler, post-EOF restart

Ruler takes a left click and seeks to the fraction of its own box that was
hit; an invisible overlay canvas records those bounds at prepaint because a
mouse listener only ever sees the window position. Player::seek clears the
app-side EOF flags (held/eos/done) and raises pending_seek, which keeps the
repaint loop alive while paused until the target frame is displayed. Space
and the transport button restart from zero once the timeline is finished.
✨ 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
✨ feat(app): editor-shell UI — transport, timecode, playhead rulerAhmet Kaan Gümüş · 1c1f5e0
✨ feat(app): editor-shell UI — transport, timecode, playhead ruler

Shell C chrome around the picture: filename header, letterboxed video
region, and a fixed-height bottom panel with the transport row (drawn
play/pause glyph, HH:MM:SS:FF readout), a read-only playhead ruler and
two empty track lanes for the clips slice.

Play state is read from the clock every render -- no shadow flag -- and
the readout clamps to frame_count/frame_rate, since the clock keeps
running past the last frame once wall time takes over at audio EOF.
The button is a plain div, so the root's own focus handler wins the
click and the space bar keeps working after a press; the toggle
handlers notify, which also replaces the animation frame as the thing
that repaints a paused (or finished) timeline.
🐛 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.
✨ feat(engine): audio decode, PipeWire output plugin, playback clockAhmet Kaan Gümüş · 229a569
✨ feat(engine): audio decode, PipeWire output plugin, playback clock

Wave 1 of the audio slice — three independent modules, app wiring
comes next:

- audio.rs: AAC-LC via standalone symphonia AacDecoder over the
  existing mp4 demuxer; priming trim read from the container elst
  (verified against ffprobe); channel identity pinned by
  zero-crossing tests on the 440/880 Hz fixture
- engine-audio: dlopen'd PipeWire cdylib (ao_* C ABI). App binary
  keeps zero libpipewire linkage; daemon absent fails open() in ~1ms.
  Fill capped at 1024 frames/callback: uncapped, PipeWire hands the
  sink-sized buffer and the position clock steps 256ms at a time.
  Stream time rate is 1/48000 regardless of stream rate — position
  is rescaled or the clock runs 8.8% fast on 44.1k content
- clock.rs: PlaybackClock, audio-driven with wall fallback; audio
  positions relative to last re-anchor so restarted streams re-sync;
  paused == frozen exactly, all re-anchoring through one path
🔧 chore: add A/V test fixture to gen_fixturesAhmet Kaan Gümüş · fc06b75
🔧 chore: add A/V test fixture to gen_fixtures

Stereo AAC with distinct L/R frequencies (440/880 Hz) so channel
mapping mistakes are audible; 1 Hz volume pulse makes A/V drift
visible against the burned-in frame counter.
🎉 feat: MVP decode pipeline — mp4 → H.264 → gpui previewAhmet Kaan Gümüş · 0acbf8d
🎉 feat: MVP decode pipeline — mp4 → H.264 → gpui preview

- engine: mp4 demux → Annex-B, rusty_h264 software decode, BT.601
  I420→BGRA; decode on worker thread behind a bounded channel
- engine-hw: optional VA-API decode plugin (cros-codecs) behind a
  C ABI, dlopen'd at runtime with silent software fallback; the app
  binary keeps zero libva/gbm/drm linkage so it runs on any distro
- app: gpui window, per-frame RenderImage swap + drop_image
- vendor/: cros-libva + cros-codecs with 3 LOCAL PATCH fixes (libva
  1.23 struct init, radeonsi 64x64 min context, pub surface()) —
  upstream is dormant, so vendor/ is adopted code, not a temp fork
- fixtures are gitignored; scripts/gen_fixtures.sh regenerates them