Skip to content

libobs: Decide output slot steps on stored encoder - #2495

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/output-slot-stored-encoder
Oct 26, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/output-slot-stored-encoder

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2491

What and why

Needs maintainer sign-off: the stand-in copies of obs_output_set_video_encoder2() in test/cmocka/test_output_slots_steps.c (e2e_video: "an encoder whose reference fails leaves the slot empty but still gets a caption track (characterized, not endorsed)"; e2e_video_preferred_size: "clearing index 0 with a scaled size ... logs a NULL parameter (characterized, not endorsed)") and the same cases in rust/obs-output/tests/output/output_slots.rs (Tier 1) and the stand-in sequences of output_slots_parity.rs (Tier 3) copy the caller as it was before this PR. They never call the real function, so they still pass, but on these two cases they no longer describe it. Their assertions are left unchanged here (AGENTS.md). Retiring those two lines is a follow-up for a maintainer to approve.

obs_output_set_video_encoder2() stores obs_encoder_get_ref(encoder) in the slot. That is NULL when the encoder is being destroyed (its last reference is gone), so the slot stays empty. But the function then made two decisions from the encoder argument instead of from the stored slot:

  1. Caption track for an empty slot. if (encoder != NULL) created a caption track even when the reference failed and the slot stayed empty.
  2. Spurious NULL warning. At index 0 with a preferred size, obs_encoder_set_scaled_size() was called on the stored slot even when it was NULL. That happens on every clear of video slot 0 on an output with a rescale size, and also after a failed reference. The call logs obs_encoder_set_scaled_size: Null 'encoder' parameter. obs_output_set_preferred_size2() already checks the slot before the same call.

The fix tests output->video_encoders[idx] in both places. A live encoder still gets its caption track and the preferred size, and clearing a slot still destroys its caption track.

Where the decisions live after #2475: both checks were still in C. The Rust output_slots module gives only default_index and scaled_axis_set, and this fix leaves those pure helpers alone. Whether there is an encoder in the slot is a pointer test, which obs-output.c.h keeps by design (module header of rust/obs-output/src/output_slots.rs). So the fix is in C, and no Rust code or Tier 1 test changes. The rust/README.md row for obs-output-slots.c.h now says both behaviours are fixed in the caller and are still pinned by the stand-ins.

Upstream OBS Studio master (libobs/obs-output.c, obs_output_set_video_encoder2()) has the same code. There is no upstream issue or fix.

New test test_output_slot_stored_encoder (real libobs, core video, Linux under xvfb-run, graphics suite in test-graph.json). Libobs runs an encoder's destroy callback only for an initialized encoder, so the test sets it up through a holder output and obs_output_initialize_encoders(). Its destroy callback runs after the last reference is gone, and it sets the encoder on another output, as a plugin holding a plain pointer can. The cases read the output's slots and caption tracks, and count the NULL obs_encoder_set_scaled_size log lines through base_set_log_handler().

  • live_encoder_gets_caption_track (control): a live encoder gets the slot and a caption track, and clearing the slot removes both.
  • dying_encoder_gets_no_caption_track: an encoder that is being destroyed, set at index 2, leaves no caption track.
  • live_encoder_takes_preferred_size (control): at index 0 the encoder takes the output's 32x32 preferred size, and nothing NULL is logged.
  • clearing_slot0_sets_no_size_on_null: clearing slot 0 on an output with a preferred size logs no NULL parameter.
  • dying_encoder_at_slot0_with_size: an encoder that is being destroyed, set at index 0 with a preferred size, leaves no caption track and logs no NULL parameter.

RED → GREEN

  • RED commit: 2b69815 (test: Check output slots act on the stored encoder, run before the rebase as c95a42df0, same tree change). The C build, hybrid libobs and libobs-c-reference give the same result: the 2 controls pass and 3 cases fail. dying_encoder_gets_no_caption_track reports slot 2 is empty but has a caption track. clearing_slot0_sets_no_size_on_null reports clearing slot 0 logged 1 NULL obs_encoder_set_scaled_size line(s). dying_encoder_at_slot0_with_size reports empty slot 0: caption track created, 1 NULL obs_encoder_set_scaled_size line(s).
  • GREEN: 5858925. test_output_slot_stored_encoder passes 5/5 on all three lanes, and all cases skip without a display. The affected ctest set (output|encoder|caption|multitrack|service_encoder|raw_output, which includes test_output_slots_steps) passes 58/58 on the C build, on hybrid libobs and against libobs-c-reference (rebuilt first), with no skips. The exported symbols are the same on all three (1766). Local gate on the pre-rebase GREEN (627014b4c): --lane lint, --test-diff origin/master (whole workspace, 4433 passed) and --lane cross pass. After the rebase onto master (test-only changes), --lane lint and the new test on all three lanes pass again.
  • Real app (UI, protocol output or logging changes): N/A. The change removes one debug-level log line. The frontend clears video encoders only through these setters, and the test covers that path against the real libobs.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

obs_output_set_video_encoder2() stores obs_encoder_get_ref(encoder),
which is NULL for an encoder that is being destroyed, but decides two
things from the encoder it was passed: an empty slot left by a failed
reference still gets a caption track, and clearing video slot 0 of an
output with a preferred size calls obs_encoder_set_scaled_size() on the
NULL slot, which logs a NULL parameter.

The test sets a real encoder from its own destroy callback (its last
reference is gone) on another output, and clears slot 0 of an output
with a preferred size, counting the NULL parameter lines through
base_set_log_handler(). Controls: a live encoder still gets its caption
track and the preferred size.

Refs obs-rust#2491
obs_output_set_video_encoder2() stores obs_encoder_get_ref(encoder) in
the slot, which is NULL when the encoder is being destroyed, but made
two decisions from the encoder it was passed: the slot got a caption
track whenever the argument was not NULL, and at index 0 the output's
preferred size went to obs_encoder_set_scaled_size() even for an empty
slot, so clearing video slot 0 of an output with a rescale size logged a
NULL parameter.

Test the stored slot in both places, as obs_output_set_preferred_size2()
already does before the same call. A live encoder still gets its caption
track and the preferred size. Upstream has the same code.

The stand-in callers of test_output_slots_steps and the Rust Tier 1 and
3 tests copy the caller as it was and keep pinning the old behaviour as
characterized, not endorsed; their assertions are unchanged.

Fixes obs-rust#2491
@rdoupe
rdoupe requested a review from zackees as a code owner October 26, 2026 15:56
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review and sign-off (same reasoning as #2289, which the maintainer approved): the fix belongs in obs-output.c.h. The caption track and the scaled size now key off the stored slot, so a failed reference leaves no caption track and no NULL log. The stand-in copies in test_output_slots_steps.c, output_slots.rs and output_slots_parity.rs pin the old caller ('characterized, not endorsed') and never call the real function. Leaving them unedited follows the no-C-test-edit rule and doesn't hide the fix, which test_output_slot_stored_encoder checks against the real libobs on all three lanes. RED then GREEN, and the ledger and README are updated. Queuing. I'll file a follow-up to retire the stale stand-ins.

@zackees
zackees enabled auto-merge October 26, 2026 16:02
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit aee720f Oct 26, 2026
36 checks passed
vpacher pushed a commit to vpacher/obs-studio that referenced this pull request Oct 26, 2026
…d caller (obs-rust#2500) (obs-rust#2507)

The stand-in copies in test_output_slots_steps.c (Tier 2), output_slots.rs
(Tier 1) and output_slots_parity.rs (Tier 3) still decided the caption
track and the preferred size on the argument, as before obs-rust#2495. They now
decide on the stored slot: an encoder whose reference fails gets no
caption track, and clearing index 0 sets no size. Maintainer sign-off for
the C test edit was given for obs-rust#2500.
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.

bug: obs_output_set_video_encoder2 tests the argument, not the stored slot

2 participants