Repository navigation
libobs: Port the caption text wrap to obs-output - #1620
Merged
Merged
Conversation
RED for the port of libobs/obs-output-caption-text.c.h to the caption_text module of rust/obs-output. The safe core is a stub (todo!()): the CAPTION_* bounds, the four UTF-8 and whitespace helpers, text_row() and text_page(), each over a &[u8] that ends at its first NUL or at the end of the slice. A Row and a Page carry their text, how far the cursor moved, and whether they read the end of the slice. tests/output/caption_text.rs ports test_output_caption_text 1:1: its 32 cases under the same names, in the same order, with the same assertions. The C test drives obs_output_output_caption_text2(), which stays C; the port repeats its loop over text_page() (one page per call until the text runs out, and only a sole page may be empty) and ports its helpers (assert_valid_utf8, assert_pages_preserve, assert_single_page, assert_page_invariants). The "characterized, not endorsed" cases are kept as such. Edge cases: the constants; the length of every lead byte and the edges of each range; continuation bytes; whitespace and newlines over every byte value; the cursor of a row (leading whitespace consumed with no row, a wrap, a newline, a hard wrap, the end of the text); a NUL inside the slice; invalid bytes after column 32 and before a newline; the wrap at the last whitespace and at a tab; the 128-byte row and the CAPTION_PAGE_BYTES page; the cursor of a page after 15 rows; whitespace between a full page and more text; and runs of invalid bytes and spaces far longer than a page. Three proptests: the queue ends and every page keeps the bounds on weighted random bytes; a page that did not read the end of a prefix is the page of the whole text; and raw bytes of every value, up to 20000, panic nowhere. The tests are a module of the existing core category binary, obs-tests-core; no new test binary. soldr cargo test -p obs-data --test obs-tests-core output::caption_text:: fails 48 of 49 with "not yet implemented"; only the constants pass. Refs obs-rust#1617
Ports libobs/obs-output-caption-text.c.h, the caption text wrap and pagination, to the caption_text module of rust/obs-output. obs_output_output_caption_text2() (still C) turns its text into pages, one call per page until the text runs out; libobs-with-rust drops the C file and links the Rust shim in its place. Safe core (src/caption_text.rs): the four helpers (caption_utf8_continuation, caption_utf8_char_length, caption_is_newline and caption_utf8_whitespace), text_row() and text_page() over a &[u8] that ends at its first NUL or at the end of the slice. Row and Page carry the text (in fixed buffers of CAPTION_LINE_BYTES and CAPTION_PAGE_BYTES), the bytes consumed, and whether they read the end of the slice. Byte for byte the C, including the five behaviours test_output_caption_text marks "characterized, not endorsed" (an invalid byte dropped so words join, no empty rows for blank lines, trailing whitespace kept, a row ending in a space with whitespace at columns 32 and 33, C0 and DEL as spaces), the 128-byte row bound and the cursor that always moves forward on a non-empty page. The text is untrusted (obs-websocket SendStreamCaption), so the module denies clippy's indexing_slicing, arithmetic_side_effects, unwrap_used, expect_used, panic, todo, unimplemented and unreachable: every read is a checked get, every write a bounded copy, every addition saturating. Shim (src/ffi/output_caption_text.rs): obs_output_caption_text_page, with the C signature, writes the page and its NUL (bytes 0 to the length, the bytes the C writes) and moves the cursor. The core takes a slice, and measuring the whole rest of the string on every call would read the text once per page where the C reads only what a page needs. So the shim gives the core a window, up to the NUL or 2048 bytes, and doubles it while the page reads the end of a window that is not the end of the string. A call reads about what the C reads and never past the NUL. A null text, *text or page returns 0 (the C would crash; libobs never passes one). C side: caption_text_page() becomes obs_output_caption_text_page(), with external linkage, declared in obs-internal.h without EXPORT, and obs-output.c.h calls it by that name. The file leaves libobs.core-output for its own group, libobs.ported-output-caption-text (LIBOBS_PORTED_ SOURCES), whose PCH is obs-internal.h and string.h. The symbol is in rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt; it is hidden in both libobs builds and there is no rust-exports.d fragment. The exported symbol sets are unchanged. Oracle (oracle/output_caption_text.c): the original file with the page function renamed, plus wrappers around its static functions and the CAPTION_* values. Tier 3 (tests/output/caption_text_parity.rs): the bounds; the helpers over every byte value and every first two bytes; the row against caption_text_row() (return value, every byte of the row buffer, cursor) from the start of each row; and the page against the oracle page after page as obs_output_output_caption_text2() calls it (return value, the whole page buffer, the cursor, the queued pages), with the shim's own window and with windows of 1 to 7 bytes that make it retry. Inputs: the characterization inputs, runs of every lead byte, skips far past the window, and proptests over weighted text up to 800 words, raw bytes of every value up to 4000, and long text up to 12000 words. Intentional differences: none. Docs: rust/README.md rows and the naming.md row. Fixes obs-rust#1617
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1617 (PR 2 of 2; PR 1, #1618, moved the wrap into
libobs/obs-output-caption-text.c.hand extendedtest_output_caption_textto 32 cases)What and why
This PR ports
libobs/obs-output-caption-text.c.h, the caption text wrap and pagination, to thecaption_textmodule ofrust/obs-output(#1567, #1603).obs_output_output_caption_text2()turns the text it is given into caption pages, one call per page until the text runs out. A page has up to 15 rows of up to 32 characters. The pages go on to libcaption, so the port has to be byte-identical: a different wrap point would be visible to viewers.libobs-with-rustdrops the C file and links the Rust shim in its place.src/caption_text.rs):utf8_continuation,utf8_char_length,is_newline,utf8_whitespace), plustext_row()andtext_page(). Each takes a&[u8]that ends at its first NUL or at the end of the slice.RowandPagehold the text in fixed buffers ofCAPTION_LINE_BYTESandCAPTION_PAGE_BYTES. They also record how many bytes the cursor consumed, and whether the call read the end of the slice.test_output_caption_textmarks "characterized, not endorsed":SendStreamCaption, caption plugins), so the module denies clippy'sindexing_slicing,arithmetic_side_effects,unwrap_used,expect_used,panic,todo,unimplementedandunreachable. Every read is a checkedget, every write a bounded copy, and every addition saturating. I checked that the lints fire: a probe indexing and adding inside the module fails clippy.cfg, nounsafe.src/ffi/output_caption_text.rs):obs_output_caption_text_pagehas the C signature. It writes the page and its NUL (bytes 0 to the length, the same bytes the C writes) and moves the cursor.text_page_with_windowis Rust-mangled (hidden by_ZN*). The parity test drives it with windows of 1 to 7 bytes so that most calls retry.caption_text_page()becomesobs_output_caption_text_page()with external linkage. It is declared inobs-internal.hwithoutEXPORT, andobs-output.c.hcalls it by that name. The other five functions staystatic.obs-output-caption-text.c.hleaveslibobs.core-outputfor its own group,libobs.ported-output-caption-text, listed insource-sets.json(LIBOBS_PORTED_SOURCES). Its PCH,libobs-ported-output-caption-text.pch.h, isobs-internal.hplusstring.h.rust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt. It is notEXPORT, so there is norust-exports.dfragment.nmshowst obs_output_caption_text_pagein bothlibobs.sobuilds. The exported symbol sets are unchanged.oracle/output_caption_text.c): the original file, unmodified, with the page function renamed. It addsoracle_output_caption_text_*wrappers around its static functions, and theCAPTION_*values.text,*textorpagereturns 0 and writes nothing, where the C would dereference it. libobs never passes one.test_output_caption_text(32 cases) linksOBS::libobsand drives the publicobs_output_output_caption_text2(). That makes it the end-to-end proof: in mode ON it runs the Rust port through real libobs.RED → GREEN
2788b6f2elibobs: Add Tier 1 tests for the caption text wrap port. The core istodo!().soldr cargo test -p obs-data --test obs-tests-core output::caption_text::fails 48 of 49 with "not yet implemented"; only the constants test passes.tests/output/caption_text.rs) portstest_output_caption_text1:1: the 32 cases under the same names, in the same order, with the same assertions.obs_output_output_caption_text2()stays C. The tests repeat its loop overtext_page(): one page per call until the text runs out, and only a sole page may be empty.assert_valid_utf8,assert_pages_preserve,assert_single_pageandassert_page_invariants.CAPTION_PAGE_BYTESpage;text_row()on suffixes.obs-tests-core. No new test binary:ci/test_binary_cap.pypasses.9585ad379libobs: Port the caption text wrap to obs-output.output::caption_textpasses 57/57 (49 Tier 1, 8 Tier 3). The wholeobs-tests-corebinary passes 397/397.tests/output/caption_text_parity.rs), comparing against the C oracle:CAPTION_*bounds;caption_text_row()againsttext_row()from the start of each row: the return value, every byte of the row buffer (both start filled with the same pattern, so a stray write shows) and the cursor;obs_output_output_caption_text2()calls it: the return value, the whole page buffer, the cursor after each call, and the queued pages. Each input runs with the shim's own window and with windows of 1 to 7 bytes.caption_any_input_ends;CAPTION_LINE_BYTES, page ≤CAPTION_PAGE_BYTES, and a cursor that moves forward and stays inside the text.chars == LINE_CHARScomparisons), then restored it.caption_word_wrap,caption_page_edge_481,caption_utf8_2byte_at_wrap,caption_utf8_3byte_at_edge,caption_utf8_4byte_at_edge,caption_invalid_bytes_take_no_column,caption_word_of_33,caption_space_at_column_32,caption_row_and_page_byte_bound,caption_full_page_then_whitespace,caption_any_input_ends). 4 are edge cases or the bounds proptest, and 5 are Tier 3 parity tests. Every failure was a test assertion; nothing panicked in the core, even with rows over 128 bytes.libobs-with-rustrebuilt:test_output_caption_textfailed the same 11 cases in mode ON (21/32 passed) and passed 32/32 in mode OFF.output::caption_text(Tier 1 and 3, every proptest) passes 57/57 under AddressSanitizer, with no reports. The Rust side was built with-Zsanitizer=address, and the C oracle with-fsanitize=address. The page and row buffers and the input string are heap buffers of exactly their C sizes, so a write past the page or a read past the NUL would show.ENABLE_RUST_LIBOBS=OFFandON). Each tree runs the full cmocka suite againstlibobs(OFF) and againstlibobs-with-rust(ON):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)libobsweretest_audio_controls(inmeter_callback_order_test) andtest_deinterlace_2x_field_order. Neither uses captions. The run overlapped the Rust lane's build, and both passed three of three reruns once nothing else was running. No test was skipped or not run.test_output_caption_textpasses 32/32 in all four runs, and again three times each in a focused run.lddshows each run loading the intendedlibobs.so.libobs.ported-output-caption-text+.h.cis linked intolibobsand not intolibobs-with-rust: the C statics are inlibobsonly. The export lists are also identical across the two lanes.CMocka_DIR, and ctest ran withLD_LIBRARY_PATHpointing at itslib.ci/local_gate.py:--lane lint: passed.--lane cross: passed.--lane cross-release: passed.--lane rust-test: passed (obs-tests-core397/397, the obs-util harness 740/740, includingexport_list).ci/test_build_groups.py,ci/test_naming.py,ci/test_ported_sources.py,ci/test_rust_scope.py,ci/test_binary_cap.py,ci/test_cmocka_includes.py: OK.Checklist
master(or the description starts with a Stacked: note)test_output_caption_textlanded in libobs: Move the caption text wrap into obs-output-caption-text.c #1618)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable