Skip to content

Media codecs crate: the bundled-FFmpeg ABI, PCM decode, speed audio and the encoder leave plx_media (P2 of the URI-first carve) - #1271

Merged
GLinnik21 merged 4 commits into
mainfrom
uri-first/p2-media-codecs
Nov 7, 2026
Merged

GLinnik21 merged 4 commits into
mainfrom
uri-first/p2-media-codecs

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Summary

Carve step P2 of the URI-first plan (v4, Part 4). Behaviour: none (one dev-trigger-only exception, below).

  • New workspace crate plx_media_codecs (rust-modules/media-codecs/, byte-identical to the integration branch): the bundled
    FFmpeg binding (the four dynlib! tables, load_libraries, every OFF_* offset table, the pinned-major fence), the PCM decode
    and converter (pcm), the speed-audio DSP and SpeedDecoder, the Venc encoder, and the subtitle extraction
    (subtitle: image decode; subtitle_extract: manifest, Scan, and the cancellable job half that nothing in plx_media calls
    until P3/P4). It names base and playback_contract only (new layer [media_codecs] in ci/module-layers.ini).
  • plx_media::ff, ff_pcm and speed_audio become facades: pub use plx_media_codecs::{ffi::*, pcm::*, SpeedDecoder, Venc}.
    The demux, the HLS/AVIO transports, the Annex-B conversion, the IRAP/Keyframe items of Playback: a Dolby Vision resume or seek that lands on a CRA plays the HDR10 base layer #1263 and the DV rewrite stay in
    media/src/ff.rs (they are the Feed's, P4). 113 items left ff.rs, 18 left ff_pcm.rs, all of speed_audio.rs.
  • Subtitle extraction exists once (lead's decision: dedupe by item, keep main's subtitle files; the rewired shape arrives with
    P3+P4). Removed from media, callers pointed at the codecs / contract item:
    open_sub_decoder, sub_canvas, rect_pixels, rect_to_indexed, rects_within_budget, PALETTE_BYTES, decode_bitmap
    (ff_subs.rs now maps the codec's owned BitmapDisplay to the store's SubRects, as integ's bitmap_cue does);
    Scan (ff_subside.rs); WINDOW_NS, SCAN_NS, FINGERPRINT, fingerprint, Anchor, playhead_of, delta_exact,
    delta_assumed, pacing_parks, judged_clock, ReadCfg, RunEnd (to plx_playback_contract::subtitle); Spec and
    CLOCK_ONLY in player/subside.rs (re-exported from the contract under the old names); the header/font scan of
    begin_ass_sources (now collect_manifest); the host FFmpeg test fixture HostFfmpeg/bind_host_ffmpeg.
  • Shared files (sweep: p2-sweep.md): Makefile, CI workflow, ci/check-deps.sh, ci/list-caps.ini, ci/module-layers.ini, the
    ci/test_*.py pins, tools/build-bench.py, docs and the quoted cargo test -p ... lines name the new crate; ci/ffabi-*,
    tools/ffabi-dump.sh and the bind-tv-lib-abi / fw-compat-reviewer prose point at media-codecs/src/ffi.rs.

Behaviour delta (dev triggers only): ff::boot() now returns when the libraries load with a wrong major (the ABI fence), so
the ffprobe dev-trigger probe no longer runs against offsets the build does not know. Shipped builds have no probe.
Spec gains PartialEq/Eq and a Debug that omits the URL.

Content size (non-whitespace bytes of .rs, tr -d '[:space:]'; base 97e4388, head e839887)

crate before after delta
plx_media (rust-modules/media/src) 5,705,568 5,586,403 -119,165
plx_media_codecs (new) 0 131,031 +131,031
plx_playback_contract 177,456 177,456 +0
application (rust-modules/src) 3,772,827 3,772,833 +6

Net +11,866: the codec crate's subtitle_extract job half (Job, AvioInput, ReadSeek: 15,495 B for the whole file, unused
until P3/P4), host_test_support (1,211 B) and the crate's public surface. Per file in plx_media:

file before after delta
ff.rs 348,804 301,346 -47,458
ff_pcm.rs 42,342 30,594 -11,748
speed_audio.rs 48,277 268 -48,009
ff_subs.rs 21,215 15,143 -6,072
ff_subside.rs 38,793 34,462 -4,331
ff_image_subtitle_tests.rs 16,271 15,402 -869
player/subside.rs 26,264 25,421 -843

Stated duplicates (kept in media; each is deleted by the PR named)

media item counterpart why it stays deleted by
SideStop + impl (media/src/ff_subside.rs) plx_playback_contract::subtitle::SideStop the contract's registers closures (publish_curl(wake)); media's registers an Arc<curlio::Abort> and a raw *mut HttpStream whose drop order against SideIo is a use-after-free guard. Switching needs a SideIo change P4 (SideIo moves into the caption runner)
SideIo, SideDemux, open_side, seek_video, scan_keyframes, read_once, Delivery (ff_subside.rs) plx_media_codecs::subtitle_extract::{Job, AvioInput, ReadSeek} (Job::open/seek_video/scan_keyframes/next) same role, different shape (direct AVIO over SideIo vs a ReadSeek trait object); the caller is player/subside.rs's thread P3 + P4 (job port, plx_play_feed::side_reader)
SubTracks::open/close/decode, SubKind (ff_subs.rs) subtitle_extract::ImageDecoders, TrackInfo, DecodeKind SubTracks is owned by the main demux loop in ff.rs; ImageDecoders by the job P3 (DemuxSession)
read_cb, seek_cb, AVSEEK_SIZE, stream_language (media/src/ff.rs) the private copies in subtitle_extract.rs integ keeps a copy in the codec crate AND in the Feed's ff.rs P4 (ff.rs moves to play-feed)

Not duplicates (same name only): ff::boot (wraps curlio::boot and plx_media_codecs::ffi::boot), Clock in ass_source.rs
and ffi_host.rs, Job in ass/mailbox.rs, the gcd test helpers.

Exceptions to "byte-identical to integ" (p2-sweep.md has the reasons)

media/src/ff.rs, ff_pcm.rs (hand-derived); ci/ffabi-assert.c (player/vp9_hdr.rs path kept; integ's "ffi.rs's SpeedDecoder"
is false, the item is in speed_decoder.rs); .agents/agents/fw-compat-reviewer.md (path updates only); ff_subside.rs,
ff_subs.rs, ff_image_subtitle_tests.rs, player/subside.rs, player/shared.rs and one decision test (main's files with the
deduped items removed). Three comments in media-codecs/** (lib.rs:1, ffi.rs:512, speed_audio.rs:6) name plx_play_feed
(P4's crate) because the crate is integ's text.

Verification

Gates ran on the committed tree (git status --short empty before and after):

  • make check: exit 0 (cargo, python, rest and harness stages all ok); plx_media_codecs: test result: ok. 23 passed; 0 failed;
    plx_media: test result: ok. 2397 passed; 0 failed; 84 ignored; plxnative-modules: 1337 passed;
    plx_playback_contract: 40 passed. The full test result: list is in p2b-final.log in the lane dir.
  • make check-nodef: exit 0. bash ci/check-deps.sh: all gates green, no ci/allow/ line added or changed.
  • ci/check-module-layers.py, ci/check-list-caps.py, ci/check-rust-inputs.py, ci/test_{build_bench,ci_split,no_host_staticlib, test_fast,build_not_always_dirty}.py: green.
  • fw-compat-reviewer on origin/main...carve/p2: source-only verdict, nothing in the source changes whether the binary starts;
    the ELF half (fwcompat matrix, ci/check-elf.sh, the 15 DT_NEEDED / 319 undefined-symbol baseline) is ungraded because the lane
    has no ARM build: CI's firmware-load-matrix step grades it. The four dynlib! blocks, load_libraries order and the ABI fence
    are textually unchanged; no new #[link], extern "C" import, dlopen or build.rs; tools/fwcompat.py --inventory shows
    the bundled SONAMEs collide with no firmware's own copy. Its five findings (the reviewer-prompt hunk, three ffabi-assert.c
    comments, stale ff.rs prose, forward references in the codec crate, the boot() delta) are fixed or stated above.
  • One pr-reviewer pass on 97e43889d...e83988795: four findings, fixed in 37b84ed (ci/check-deps.sh keeps the codec crate out of
    MACHINES as the sans-IO guide lists it; ff.rs's header describes what stays; an unused P4-only speed_audio re-export dropped;
    this table). After 37b84ed: check-deps green, make check-nodef exit 0, plx_media test result: ok. 2140 passed; 0 failed
    (make test-crate, no hostsim), plx_appkit 934 passed; 0 failed.
  • Not run here: the ARM cross-build (CI), the TV (no behaviour change).

Build benchmark (make build-bench --runs 3, same Mac, base then head, no load warnings)

Scenario main 97e4388 (median) P2 e839887 (median) delta
No-op host test build 34.2 s 40.6 s +6.4 s
Edit leaf (plx_base cbuf.rs), non-incremental 59.7 s 66.6 s +6.9 s
Edit leaf (plx_machine landgate.rs), non-incremental 58.3 s 60.9 s +2.6 s
Edit leaf (plx_platform devcaps.rs), non-incremental 52.2 s 59.8 s +7.6 s
Edit leaf (plx_gfx overdraw.rs), non-incremental 35.5 s 38.8 s +3.3 s
Edit leaf (plx_net stream_redirect.rs), non-incremental 47.5 s 50.8 s +3.3 s
Edit leaf (plx_ui dwell.rs), non-incremental 33.9 s 37.5 s +3.6 s
Edit leaf (plx_plex retry.rs), non-incremental 46.6 s 51.0 s +4.4 s
Edit leaf (plx_telemetry window.rs), non-incremental 43.8 s 47.5 s +3.7 s
Edit leaf (plx_data tape.rs), non-incremental 41.7 s 48.3 s +6.6 s
Edit leaf (plx_session scripted.rs), non-incremental 29.6 s 32.0 s +2.4 s
Edit leaf (plx_media units.rs), non-incremental 34.0 s 38.2 s +4.2 s
Edit leaf (plx_appkit skip_pill.rs), non-incremental 30.1 s 32.4 s +2.3 s
Edit leaf (plx_screens clock_readout.rs), non-incremental 26.3 s 27.4 s +1.1 s
Edit leaf (app coldstart.rs), non-incremental 16.5 s 18.4 s +1.9 s
Edit hub (plx_ui lib.rs), non-incremental 26.5 s 27.9 s +1.4 s
Edit leaf (plx_base cbuf.rs), incremental 514.2 s not run —
Edit hub (plx_ui lib.rs), incremental 130.0 s not run —
Unit suite run (default features) 80.1 s 68.8 s -11.3 s
ARM staticlib rebuild (touch lib.rs) 38.0 s 25.5 s -12.5 s

The two incremental rows were not run on the head (the full run exceeds the two-hour job limit; the P1 PR made the same cut).
Every non-incremental host leaf edit is 1-8 s slower (median): the new crate is one more unit on the path from each lower
layer to plx_media; the cause per row is not attributed further. The unit suite run and the ARM staticlib relink are faster,
within this bench's spread on those rows (base ARM max 51.8 s). ARM archive 119.5 -> 119.7 MiB. Target dirs 70.5 -> 73.9 GB.
Evidence: bench-base-97e43889d.{txt,json}, bench-p2-e83988795.{txt,json}.

Related: #1064

🤖 Generated with Claude Code

GLinnik21 and others added 4 commits November 7, 2026 07:13
…d_audio.rs keep the demux residual over the codec facade

Work in progress, not a gate candidate: the shared-file sweep (Makefile, ci pins,
module-layers, list-caps, docs) and the subtitle rewire are not done; see
handoff-p2.md in the lane directory. media-codecs is byte-identical to integ.
Compiles: cargo check -p plx_media --lib --tests, check --lib --no-default-features.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the contract; shared-file sweep

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at review fixes

plx_media_codecs takes the bundled-FFmpeg ABI, PCM decode, speed audio, SpeedDecoder
and Venc; media keeps the demux over a facade. Subtitle extraction exists once:
ff_subs.rs, ff_subside.rs, player/subside.rs and ff.rs call the codecs and
playback-contract items instead of carrying copies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s what is left; no P4-only re-export

- ci/check-deps.sh: the codec crate is fork-scoped like integ, not a machine (sans-io-guide's list agrees).
- media ff.rs //!: the ABI and venc moved to plx_media_codecs::{ffi, venc}; the header now describes the
  demuxer that stays and points there.
- speed_audio.rs: drop the force_speed_decoder_for_test re-export no caller uses until P4.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit 279b66d into main Nov 7, 2026
29 checks passed
@GLinnik21
GLinnik21 deleted the uri-first/p2-media-codecs branch November 7, 2026 07:51
GLinnik21 added a commit that referenced this pull request Nov 7, 2026
Every P2 path keeps integ's version (integ is the superset: the rewired subtitle
files, play-feed's ff_pcm, the play crates in every list). Taken from main: the
comment and doc fixes integ lacked (Makefile and ffabi-assert.c point at
media-codecs/src/{ffi,speed_decoder}.rs; the quoted crate lists and the
module-layers table name media_codecs), with module-layers.md's paragraph saying
the demux is play-feed's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant