Repository navigation
libobs: Move the caption text wrap into obs-output-caption-text.c - #1618
Merged
Merged
Conversation
Behavior-neutral extraction before the Rust port: the caption text wrap and pagination, caption_text_page() and the functions only it uses (caption_utf8_continuation, caption_utf8_char_length, caption_is_newline, caption_utf8_whitespace and caption_text_row), moves verbatim from libobs/obs-output.c.h into libobs/obs-output-caption-text.c.h. Everything stays static and unchanged. The new file joins libobs.core-output just before obs-output.c.h (alphabetical), so it is in the same translation unit as its caller, obs_output_output_caption_text2(). It calls nothing in obs-output.c.h, so it needs no forward declarations. No signature, header or exported symbol changes. caption_text_new() and obs_output_output_caption_text1/2() stay in obs-output.c.h: they allocate and queue the pages, and only the page text is part of the unit. New characterization cases in test_output_caption_text (the existing 12 are unchanged). Through the public API and real libobs, they pin each invalid UTF-8 form dropped one byte at a time (a lone continuation byte, C0/C1, E0 80-9F, ED A0-BF, F0 80-8F, F4 90+, F5-FF, sequences truncated by NUL or by ASCII) and the valid edges of each range; "", only spaces and only invalid bytes (one empty page); CR, LF, CRLF and blank lines; NBSP as a split point kept as two bytes; control bytes and DEL; words of 32 and 33 characters; whitespace at columns 32 and 33; a 2-byte character at the wrap; the 128-byte row and the CAPTION_PAGE_BYTES page; more than 15 rows; whitespace after a full page; and, over every byte value and pseudo-random input, that the call ends and every page keeps the row, page and UTF-8 bounds. The harness also destroys any harness a failed case left behind before obs_shutdown(), and the page check asserts after releasing the caption mutex. Before, an output left marked active made obs_shutdown() block, so any failed assertion, in the old cases too, hung instead of failing. Characterized, not endorsed: an invalid byte is dropped, not replaced, so the words on either side of it join; blank lines give no empty rows; whitespace before a newline or the end stays in the row; with whitespace at columns 32 and 33 the row ends with a space; every C0 control byte and DEL becomes a space inside a row. Refs 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.
Refs #1617 (PR 1 of the plan: the extraction and the characterization; the port follows)
What and why
Behaviour-neutral extraction before the Rust port, as the testing policy asks for part of a large file: the caption text wrap and pagination move verbatim from
libobs/obs-output.c.hintolibobs/obs-output-caption-text.c.h. The move comes with new characterization cases intest_output_caption_text. No Rust, no signature or behaviour change, and no header change.caption_text_page()and the functions only it uses:caption_utf8_continuation(),caption_utf8_char_length(),caption_is_newline(),caption_utf8_whitespace()andcaption_text_row(). All of it staysstatic. The moved lines are byte-for-byte the same:obs-output.c.hloses 141 lines, and the new file is those lines (less the blank line between them and the next function) plus the license header, the include and a comment.caption_text_new()andobs_output_output_caption_text1/2(). They allocate and queue the pages (including the rule that only the first page may be empty), and only the page text is part of the unit.add_caption()is the consumer and stays too.libobs.core-outputgroup just beforeobs-output.c.h(alphabetical), so it stays in the same translation unit as its caller and keeps internal linkage.obs-output.c.h, so it needs no forward declarations. It uses onlymemcpyand theCAPTION_*bounds fromobs-internal.h.libobs.pch.h, like every member of that group. No group, PCH,source-sets.jsonor CMake source list changes.obs-buildbuilds the same group file, so the Rust lane needs no change either.static.test_output_caption_textgoes through real libobs (the publicobs_output_output_caption_text2(), then the caption queue throughobs-internal.h), so in mode ON it will see the Rust swap directly. Its 12 existing cases are unchanged. It gets 20 new ones, and two harness changes that do not touch any case:main()destroys any still on it beforeobs_shutdown(). Before this, a failed assertion left its case beforeharness_destroy(), and the output it had marked active madeobs_shutdown()block, so any failure, old cases included, showed up as a hang instead of a failure;assert_page_invariants()collects the queued pages undercaption_mutexand checks them after unlocking, for the same reason.The 20 new cases:
"", only spaces (1, 8 and 100) and only invalid bytes each queue the single empty page.CAPTION_LINE_BYTES), and 15 of those rows make a page of exactlyCAPTION_PAGE_BYTES; one more character starts a second page. 16 short lines give 15 rows and a second page. Whitespace, NBSP and invalid bytes after a full page queue no empty second page.CAPTION_PAGE_BYTES, 1-15 rows, each row 1-128 bytes and at most 32 characters, starting with a non-whitespace character, no CR inside, well-formed UTF-8, and only a sole page may be empty.Characterized, not endorsed (comments in the test):
These are our own behaviours (the wrap that replaced the 128-byte truncation), not regressions. No bug filed.
RED → GREEN
e9c9d410dlibobs: Move the caption text wrap into obs-output-caption-text.c.test_output_caption_text: 32/32, run 3 times in each lane against both libraries, all passing. Also 32/32 with the test built with ASan and UBSan (leak detection on), with no reports. The moved functions themselves were also fuzzed standalone under ASan and UBSan (libFuzzer, about 27 million inputs, with an exact-size page buffer and checks for progress and empty pages), with no findings.obs-output-caption-text.c.hfail the test. Each one was built into libobs and run against the test. The mutants: the E0, ED, F0 and F4 second-byte ranges; F5-F7 accepted as leads; C0/C1 accepted as leads; DEL not whitespace; NBSP not whitespace; CR not a newline; the split recorded after the column check; interior whitespace copied instead of written as a space; NBSP written as a space; 14 rows a page; invalid bytes counted as columns.ENABLE_RUST_LIBOBS=OFFandON, full builds). Each runs the full cmocka suite againstlibobsand againstlibobs-with-rust, headless (private Xvfb, private D-Bus, fresh HOME):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)Nothing was skipped or failed to run. These runs are on master at #1615; a final rebase onto #1616 (Rust only,
rust/obs-scene) changed no C, and the lint lane passed again on it. The export lists are also identical across the two lanes, with the same count as master.test_output_caption_queueand the caption and ffmpeg output tests pass in all four, unchanged.uv run ci/local_gate.py --lane lint: passed.--lane cross: passed. clang-format 23.1 is clean on the changed files, andci/test_build_groups.pypasses (group order).Windows/macOS: not built there. The moved code has no host conditionals. The new cases are portable C in an existing all-platform test, use only
snprintf,memset,strcat,strchrand libobs'sbzalloc/brealloc/bfree, and no cmocka range assertions.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC (not applicable: no flag change)