Repository navigation
libobs: Decide output slot steps on stored encoder - #2495
Merged
Merged
Conversation
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
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
enabled auto-merge
October 26, 2026 16:02
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.
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 #2491
What and why
Needs maintainer sign-off: the stand-in copies of
obs_output_set_video_encoder2()intest/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 inrust/obs-output/tests/output/output_slots.rs(Tier 1) and the stand-in sequences ofoutput_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()storesobs_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 theencoderargument instead of from the stored slot:if (encoder != NULL)created a caption track even when the reference failed and the slot stayed empty.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 logsobs_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_slotsmodule gives onlydefault_indexandscaled_axis_set, and this fix leaves those pure helpers alone. Whether there is an encoder in the slot is a pointer test, whichobs-output.c.hkeeps by design (module header ofrust/obs-output/src/output_slots.rs). So the fix is in C, and no Rust code or Tier 1 test changes. Therust/README.mdrow forobs-output-slots.c.hnow 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,graphicssuite intest-graph.json). Libobs runs an encoder's destroy callback only for an initialized encoder, so the test sets it up through a holder output andobs_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 NULLobs_encoder_set_scaled_sizelog lines throughbase_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
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_trackreportsslot 2 is empty but has a caption track.clearing_slot0_sets_no_size_on_nullreportsclearing slot 0 logged 1 NULL obs_encoder_set_scaled_size line(s).dying_encoder_at_slot0_with_sizereportsempty slot 0: caption track created, 1 NULL obs_encoder_set_scaled_size line(s).test_output_slot_stored_encoderpasses 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 includestest_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 crosspass. After the rebase onto master (test-only changes),--lane lintand the new test on all three lanes pass again.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 (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC