Skip to content

rust: Port output caption plan #3074

Closed

Description

@vpacher

Unit

libobs/obs-output.c.h: the caption plan of add_caption(), which puts a queued caption into an encoded video packet. The plan covers:

  • which carrier the codec gets (AVC SEI, HEVC suffix SEI, AV1 metadata OBU, or none);
  • the packet priority gate;
  • the length of the HEVC Annex B start code;
  • which CEA-608 triplets from the queue go into the CEA-708 frame (cc_type, padding, zero and parity);
  • the first byte of the HEVC suffix SEI NAL unit header.

The plan moves to libobs/obs-output-caption.c.h and is ported to rust/obs-output (module output_caption, next to output_pause and output_reconnect).

Phase and position

Phase 2 libobs core, outputs (core-output group). It comes after the output pause plan (#3020) and the encoder pause checks (#3033), which have merged. Tracking: #4.

Dependencies and existing tests

  • Depends on nothing open.
  • Existing tests that see the function through the real libobs: test_output_caption_codec (bug: libobs: add_caption() leaks a packet copy for each caption on a codec other than h264, hevc or av1 #1777: a codec with no carrier still drains the queue and frees everything; h264 as the control), test_output_caption_queue and test_caption_unmappable.
  • No characterization of the plan on its own yet. test_output_caption_steps (cmocka, the moved file on its own) lands first. It pins:
    • the carrier for h264, hevc, av1 and other codecs;
    • priority 0, 1 and 2;
    • the start code length for a 3-byte and a 4-byte start code, and for none;
    • the triplet filter: each cc_type, 0x8080, 0x0000, bad parity in either byte, valid pairs;
    • the HEVC header byte with the low bit set and clear.

Notes

  • What moves are the decisions on plain values. obs-output.c.h keeps:

    • the caption track lookup and its log;
    • the deque pops and bzalloc/bfree;
    • every libcaption call (sei_*, cea708_*, caption_frame_*, metadata_obu, extract_buffer_from_sei);
    • the packet DARRAY, obs_encoder_packet_release(), and the order of every call.

    eia608_parity_varify() is a libcaption inline; the port computes the same parity and Tier 3 compares the two.

  • The caption text from obs_output_output_caption_text2() (which obs-websocket's SendStreamCaption reaches) goes through caption_frame_from_text(), which stays in C. The ported filter sees only the CEA-608 triplets that sources queue with obs_output_caption().

  • Kept, characterized, not endorsed:

    • an AVC caption SEI goes after the whole packet, not before the first VCL NAL unit (the C's TODO);
    • a codec with no carrier still drains one caption from the queue and returns false.
  • Possible intentional difference, for a decision before the port: the HEVC start code check and the 2-byte header read do not look at the packet size. A packet of under 6 bytes is read past its end. The port would take the size and treat a short packet as "no start code" (no caption, as for a missing start code). The input is the encoder's own output (trusted local), so this is a normal public bug per SECURITY.md.

  • One slice. The packet layout (the reference count, the old data, then the start code, header and SEI) is darray pushes around libcaption output, so it stays in C. A later slice can take it if a plan for it proves worthwhile.

Activity

  1. vpacher commented on Oct 30, 2026

    @vpacher
    MemberAuthor

    Claiming: #3074.

    Plan (one PR, in this order):

    1. Behaviour-neutral extraction: the plan's decisions move from add_caption() to libobs/obs-output-caption.c.h as hidden functions on plain values, declared in libobs/obs-output-caption.h without EXPORT. add_caption() keeps every libcaption call, deque pop, allocation and packet step in its order.
    2. Characterization: test_output_caption_steps (cmocka, the moved file on its own), with the cases listed in the issue.
    3. RED: rust/obs-output module output_caption with stubs, Tier 1 tests, and Tier 3 parity against the oracle build of the moved file (carrier, gate, start code, triplet filter including the parity bit, HEVC header byte).
    4. GREEN: the port, swapped into the hybrid libobs, with Tier 2 running the new test against both the hybrid libobs and the C reference.

    The short HEVC packet read (issue, last note) stays as the C does unless it is decided as an intentional difference; I will ask for that with Decision needed: before GREEN if it is still open.

    Draft PR within 48 h.

  2. added
    ready
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions