Repository navigation
libobs: Ignore video levels that are not positive - #2270
Merged
Merged
Conversation
obs_set_video_levels() stores the SDR white level and the HDR nominal peak level without checking them, and libobs never gives them their documented defaults of 300 and 1000 nits once graphics are up: they read 0 until the frontend sets them. The draw paths divide by the SDR white level, so 0, a negative value, NaN or an infinity turns the scRGB multipliers into inf, NaN, 0 or a negative number. test_video_levels_range brings up libobs with graphics and checks the getters: 300 and 1000 before anything sets them; 0, -0, -1, NaN, +inf and -inf for either level, or both, are ignored with one warning each and the previous value stays, while a valid level in the same call is still stored; valid pairs, FLT_MAX and FLT_MIN among them, are stored exactly and log nothing. test_video_output_formats never sets the levels either, and its Rec. 2100 (PQ and HLG) rows pinned the box as black, the picture a white level of 0 gives. Those rows now expect the box drawn at the default of 300 nits, as measured on the C libobs with llvmpipe; the SDR rows do not change. Refs obs-rust#2209
obs_set_video_levels() stored the SDR white level and the HDR nominal peak level as given, and libobs never set them, so with graphics up they read 0 until the frontend called it. The draw paths divide by the SDR white level, so 0, a negative value, NaN or an infinity (from an edited profile, a plugin or a script) turned the scRGB multipliers into inf, NaN, 0 or a negative number and broke the picture. libobs now starts the levels at their documented defaults, 300 and 1000 nits, when graphics come up. This changes what the getters return between obs_reset_video() and the first obs_set_video_levels() call: a libobs user that never sets the levels and outputs Rec. 2100 now gets SDR sources at 300 nits instead of black. The frontend sets the levels right after every video reset, so the app does not change. obs_set_video_levels() checks each level on its own: one that is not finite and greater than 0 is ignored with a warning and the previous value stays, while a valid level in the same call is still stored. Every valid call stores the levels exactly as before. docs/features.md gets a line under fixed upstream bugs. Fixes obs-rust#2209
rdoupe
force-pushed
the
fix/video-levels-range
branch
from
October 25, 2026 00:08
6ec0270 to
0d4a516
Compare
rdoupe
enabled auto-merge
October 25, 2026 00:09
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 #2209
What and why
obs_set_video_levels()stored the SDR white level and the HDR nominal peak level as given. The draw paths divide by the SDR white level (80 / whiteandwhite / 80in the source, async, scene and deinterlace draws), so 0, a negative value, NaN or an infinity, from an edited profile, a plugin or a script, turned the scRGB multipliers into inf, NaN, 0 or a negative number. HDR and scRGB sources then drew solid white, black or garbage.obs_set_video_levels()(libobs/obs.c.h) checks each level on its own. A level that is not finite and greater than 0 is ignored with a warning (obs_set_video_levels: ignoring SDR white level ..., keeping ...) and the previous value stays. A valid level in the same call is still stored. Every valid call stores the levels exactly as before, FLT_MAX and FLT_MIN included.sdr_white_levelorhdr_nominal_peak_level.obsis zero-allocated, and the getters return 300 and 1000 only while graphics are down. So betweenobs_reset_video()and the firstobs_set_video_levels()call, both levels read 0, and "keep the previous value" would have kept 0.obs_init_graphics()now sets them to 300 and 1000 nits, the defaults thatobs.hdocuments and the frontend uses. This changes whatobs_get_video_sdr_white_level()andobs_get_video_hdr_nominal_peak_level()return in that window:OBSBasic::ResetVideo()callsobs_set_video_levels()from the profile right after every successful video reset.obs_set_video_levels()(a headless tool, or a test) gets different output. With Rec. 2100 (PQ or HLG) output, SDR sources used to come out black and now draw at 300 nits.test_video_output_formatsnever sets the levels, so its 16 Rec. 2100 rows (I010, P010, P216 and P416, PQ and HLG, both ranges) pinned the box as black, which is what a white level of 0 draws. The RED commit changes those rows to the values the box has at 300 nits, measured on the C libobs with llvmpipe, and adds a comment on why. The values are identical on C, hybrid and libobs-c-reference. The SDR, BGRA and RGBA rows do not change.libobs/: onlyobs_set_video_levels()and nowobs_init_graphics().obs-video.c.handobs-source.c.hreadhdr_nominal_peak_leveldirectly; the rest go through the getters.obs-scenerender_plan::multiplierandobs-sourcedeinterlace_draw::multiplier, plus their FFI shims. Those ports read it from the C getter, so they see the checked value.config_get_uint. That value is finite and positive, so it is still accepted. The Settings spin boxes allow only 80 to 480 and 400 to 10000 nits.Headless runs (private Xvfb, private D-Bus, fresh HOME,
ulimit -c 0, TMPDIR unset). The rows below were run on d9463ed; the later rebases are under RED → GREEN.test_video_levels_range: C, hybrid and libobs-c-referenceobs_set_video_levels(0, 700)gives 0/700, want 200/700)test_video_output_formats: all threeI010 colorspace 4 range 1: plane 0 sample 0 is 64, want 431(the box is black)test_video_output_formats,test_deinterlace_draw_plan_steps,test_deinterlace_mode_load,test_deinterlace_2x_field_order_*,test_scene_render_plan_steps,test_source_color_space_steps,test_filter_color_space,test_video_output_plan,test_pipewire_cursor_hdr,test_hevc, and the_rustvariants)test_pulse_monitor_devicefailed (a known load flake) and passed 1/1 when run alone. No skips on either lane.RED → GREEN
test: Check obs_set_video_levels on bad levels. The newtest_video_levels_range(real libobs, graphics up) fails 4 of 5 on C, hybrid and libobs-c-reference. Onlyvalid_pairs_stored_exactlypasses. The updatedtest_video_output_formatsfails on all three, because the Rec. 2100 rows are black.test_video_levels_range5/5 and the related tests pass on all three libraries. Full ctest: C 470/470, hybrid 489/489 counting the flake rerun, no skips. Exported symbols: 1766 for each of C libobs, hybrid libobs and libobs-c-reference, the same set.uv run ci/local_gate.py --test-diff origin/master(3702/3702, 6 skipped) and--lane crosswere run at 95a7d2455, which has the same libobs code.--lane lintwas rerun at 6f1f309b9. All ok.--lane lintis ok. The final head is RED 2c8e650 and GREEN 6ec0270, on 067f850, which only changes the frontend. There,test_video_levels_rangeandtest_video_output_formatspass on C.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