Skip to content

rust: Add CEA-608 roll-up emitter spike (experimental) - #741

Closed
chriscoveries wants to merge 4 commits into
obs-rust:masterfrom
chriscoveries:draft/cea608-rollup
Closed

chriscoveries wants to merge 4 commits into
obs-rust:masterfrom
chriscoveries:draft/cea608-rollup

Conversation

@chriscoveries

@chriscoveries chriscoveries commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GOOD MORNING OBSRUSTEES! 👋 Hi @zackees, hi everyone! We're still recovering on CI, but we're back in the game a little. @rdoupe, judging by how fast your fixes land, your CI must be the size of a small moon. 🌕

Draft, and incomplete. This is an isolated proof of concept. It isn't wired into OBS. We'd like to know whether a Rust caption encoder is a direction you'd want. Our own CI is still in the repair shop (see our note on #699), so the results below are from local runs on our Mac.

Three frames of the crate's roll-up output, decoded and rendered by FFmpeg

Real output: the crate's emitted byte pairs written to an SCC file, then decoded by FFmpeg's eia_608 decoder and rendered over a black frame. In the third frame the first line has rolled off the top of the three-row window. This is not a screenshot of OBS.

Problem

OBS sends CEA-608 captions today through vendored libcaption, in C. A live-caption source (for example, on-device speech recognition) needs a small, testable piece that turns words into correctly paced 608 roll-up byte pairs. That piece doesn't exist in Rust.

What this PR adds

A new standalone crate, rust/obs-captions, with a CEA-608 roll-up pair scheduler:

  • odd-parity generation, checking and stripping for 608 byte pairs;
  • the basic North American character table, matching vendored libcaption;
  • channel 1 EDM, RU2, RU3, CR and bottom-row PAC, with control codes sent twice as the spec requires;
  • two-row and three-row roll-up windows;
  • word spacing, 32-column wrapping, chunking of words longer than a row, and rejection of characters it can't map;
  • integer 30 fps scheduling, and 60 fps scheduling on alternate pictures;
  • atomic words: a word that's rejected (an unmappable character, a bad timestamp, or a frame index past the representable limit) leaves the scheduler exactly as it was. It returns FrameIndexOverflow instead of wrapping the frame counter.

Evidence

Local runs on an Apple Silicon Mac at this PR's head (9a812e8e1):

  • soldr cargo test -p obs-captions --locked, in debug and in release: 21 tests pass. 11 are decode-back tests: a test-side decoder reads the emitted pairs back and checks text, parity, pacing, wrapping and errors, and one compares golden pairs with libcaption's encodings. The other 10 are the new rejection and frame-limit tests.
  • On the test-only commit (62b17af5b, before the fix), 8 of the 10 new tests fail in both debug and release. One example: rejecting A*B used to advance the timestamp, so the next valid word failed as non-monotonic. The other 2 are guard tests that pass either way.
  • cargo clippy --all-targets -D warnings and cargo fmt --check: clean.
  • The image above: 94 scheduled pairs for four 32-column lines, decoded by FFmpeg 9.0.2's eia_608 decoder and rendered with libass.
  • Fork CI: not run, because our CI is still recovering. Upstream PR CI is the first CI run.

Not done (why this is a draft)

  • No OBS integration. There's no C ABI or libobs call site. It doesn't read OBS's caption queue or timing, doesn't put pairs into encoder output (H.264/H.265/AV1 caption payloads), and has no muxer, output, UI or packaging hooks.
  • Partial 608. No RU4, pop-on, paint-on or text modes. No channels 2–4 or field 2. No styling, tabs or the full control set, no special or extended characters, no XDS and no CEA-708. No 29.97/59.94 fractional scheduling, and no explicit flush/clear API.
  • No full CMake/OBS build was run locally. Only the crate's own tests and clippy.

Compatibility & risk

  • A new crate only. No C or C++ files change, and nothing links it yet, so OBS behaviour is unchanged.
  • RollupError gained a FrameIndexOverflow variant. Nothing outside the crate matches on it yet.
  • Cargo.lock gains one obs-captions entry.

Status

Draft. Opened so upstream PR CI can run it, and for direction. Updated with the atomic-rejection fix and its tests. If you'd like this kept, the next step is a small C ABI and one call site that feeds it caption text.


Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.

Add an obs-captions crate that schedules parity-correct RU2/RU3 cc_data pairs at 30 and 60 fps, with decode-back coverage for pacing and wrapping.

This is an isolated emitter spike; it does not connect the pairs to OBS caption output or implement the wider CEA-608 feature set.
Ten regression tests for the roll-up scheduler: a rejected word must leave the timestamp, queue and cursor unchanged; invalid and very large timestamps must fail without partial output; and the last representable 30 and 60 fps frame slots must be usable without the cursor wrapping.
word() advanced the accepted timestamp before validating the word's characters, so a rejected word could make the next valid word fail as non-monotonic. Stage each word and commit its pairs, cursor and timestamp together only after it schedules successfully. Check the frame conversion before narrowing to u32 and use a u64 internal cursor, so a word that would cross the representable frame limit fails as FrameIndexOverflow without emitting part of itself.
@zackees

zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member

Review from the maintainer side. I read the body, the comments, the diff at 9a812e8e1, and issue #753, and checked CI. I did not build it myself.

CI. 13 pass, 7 skipped, 0 failing, and the branch merges cleanly (no rebase needed).

Code (read, not run). The scheduling logic reads correctly to me: parity, the basic-NA table, double-sent control codes, 32-column wrapping with a carriage return, chunking of long words, and the 30/60 fps cadence. word() stages the word and commits only on success, which is the right fix for the earlier timestamp bug, and the FrameIndexOverflow bound is handled with u32::try_from.

Gaps.

  1. RED then GREEN: the history is spike, then 62b17af5b (tests, failing), then 9a812e8e1 (fix), which is the right shape for the fix. The original spike has no RED commit; for a new crate that is minor.
  2. The only comparison with libcaption is golden pairs in a test. Our policy's differential tier would run the same inputs through vendored libcaption (via obs-c-oracle) and compare pairs. That is the strongest check for a crate that claims to mirror libcaption.
  3. lib.rs and the module docs cite spikes/2026-10-12/rollup, which is not in this repo, and Cargo.toml says "CEA-608/708" while 708 is not implemented. Please fix both so the docs match the code.
  4. Integer 30/60 fps only. Real streams are often 29.97/59.94. That is listed under not done, so just noting it matters for any real integration.
  5. Rollup::word with an empty string still emits a separator space when col != 0. Probably harmless, but it should be a deliberate choice with a test.

Verdict: (c) needs a maintainer decision. The code is a sound spike, but the real question is direction: whether obs-rust wants a new Rust caption encoder next to the vendored libcaption path, which you also ask in #753. That is not something I should decide in a PR comment, so I am taking it to the repo owner and will post the answer here and on #753. It stays a draft for now; until then the useful, safe work is item 2 and the doc fixes in item 3.

@zackees

zackees commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Decision: yes we want this. You are gated and may proceed as designed.

🫡

@zackees

zackees commented Oct 25, 2026

Copy link
Copy Markdown
Member

Coordinator check-in, @chriscoveries: there's been no activity here since the maintainer's review about 9 days ago. Are you still working on this? If you've moved on, say "handed off to the coordinator" and I'll keep the mechanical work (rebases, list conflicts, formatting) moving. Anything in the review that needs a design change stays with you.

@obs-rust-project-manager obs-rust-project-manager Bot moved this from Stalled to In progress in obs-rust Multiview Oct 25, 2026
The docs cited spikes/2026-10-12/rollup, which is not in this repo, and
Cargo.toml advertised CEA-708 although only 608 is implemented. Point the
docs at the original C spike without the broken path and describe the crate
as CEA-608.
@zackees

zackees commented Oct 28, 2026

Copy link
Copy Markdown
Member

Coordinator tick: the maintainer approved this on 2026-10-17 and there has been no activity for 11 days, so I took over the mechanical part of the review's gap 3 (doc fixes) and pushed a8e86cf44 to draft/cea608-rollup as a fixup.

What changed:

  • lib.rs and rollup.rs no longer cite spikes/2026-10-12/rollup, which is not in this repo; they now refer to the original C spike harness without a broken path.
  • Cargo.toml now says "CEA-608 caption emission" instead of "CEA-608/708" since 708 is not implemented.

Gap 2 (the libcaption differential tier via obs-c-oracle) is not mechanical and stays with the author. If you've moved on, say "handed off to the coordinator" and I'll keep the mechanical work moving; anything needing a design change stays with you.

@obs-rust-project-manager obs-rust-project-manager Bot moved this from In progress to Needs fix in obs-rust Multiview Oct 28, 2026
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member

Status from the coordinator, @chriscoveries — the branch is red for one reason, and it is not the docs fixup I pushed on 2026-10-28 (a8e86cf44 only touched the crate description and two doc comments). Run 40650878305 on that head fails Format 🔍 / checks, Fast Gate ⚡ and CI Gate ✅ on the RUST-005 one-test-binary-per-category cap, which master gained after your last run passed on 2026-10-15.

Both jobs run the same inventory check (ci/local_gate.py → check_test_binary_inventory → ci/test_binary_cap.py + ci/test_ci_toml.py). The gate says:

RuntimeError: obs-captions:obs_captions (lib): consolidate coverage into a selected category binary; disable the old unit harness only after preserving its tests
obs-captions:rollup_atomic (test): consolidate coverage into a selected category binary; disable the old unit harness only after preserving its tests
obs-captions:rollup_decode (test): consolidate coverage into a selected category binary; disable the old unit harness only after preserving its tests
workspace: 11 test binaries (category budget 8)

and Format 🔍 / checks adds the ci.toml half:

FAIL: test_declared_test_binaries_are_the_workspace_test_targets
AssertionError: Items in the second set but not the first:
 'obs-captions:lib'
 'obs-captions:test:rollup_decode'
 'obs-captions:test:rollup_atomic'

What that means in practice: the crate's three targets are not in ci.toml's [rust.tests].binaries (8 entries, one amalgamated binary per selected category — see docs/rust-port/testing-policy.md, RUST-005), and adding three more entries would still leave the workspace at 11 against a budget of 8. So the fix is not a ledger line: the caption coverage has to move into one of the eight category binaries (a CATEGORY_OWNERS entry in ci/test_binary_cap.py for whichever category owns it, i.e. keep the four categories' util/media owners as they are and disable obs-captions' own lib and integration harnesses after moving their tests across), or the crate has to be parked until the budget is revisited.

I am not doing that one myself — which category owns caption tests is a structure decision in your spike, not a mechanical fixup, and you are the author. If you would rather hand the mechanical part over, say handed off to the coordinator and I will take it (rebases, list conflicts, formatting, and the harness consolidation against whatever owner you name).

Two standing things, unchanged from my 2026-10-27 note on #743/#742: this is still a draft, and the question there — are you finishing the CEA-608 roll-up, or should I report the spike to the maintainer as dormant — is still open.

@chriscoveries

Copy link
Copy Markdown
Contributor Author

Closing. Per #2414, captions go out of tree as a plugin, so this in-core emitter isn't needed. Sorry for leaving it silent for two weeks; life got in the way. Thanks for the doc fixup.

@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants