Skip to content

libobs: Ignore video levels that are not positive - #2270

Merged
rdoupe merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/video-levels-range
Oct 25, 2026
Merged

rdoupe merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/video-levels-range

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

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 / white and white / 80 in 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.
  • Behavior change to note: libobs now gives the levels their defaults when graphics come up. Before this, nothing in libobs set sdr_white_level or hdr_nominal_peak_level. obs is zero-allocated, and the getters return 300 and 1000 only while graphics are down. So between obs_reset_video() and the first obs_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 that obs.h documents and the frontend uses. This changes what obs_get_video_sdr_white_level() and obs_get_video_hdr_nominal_peak_level() return in that window:
    • The app is not affected. OBSBasic::ResetVideo() calls obs_set_video_levels() from the profile right after every successful video reset.
    • A libobs user that never calls 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.
  • This changes an existing test (it needs maintainer sign-off). test_video_output_formats never 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.
  • Nothing else writes either field. Grep of libobs/: only obs_set_video_levels() and now obs_init_graphics(). obs-video.c.h and obs-source.c.h read hdr_nominal_peak_level directly; the rest go through the getters.
  • Rust side: the getters and the setter exist only in C, also in the hybrid libobs. The ported code takes the level as an argument and stores nothing: obs-scene render_plan::multiplier and obs-source deinterlace_draw::multiplier, plus their FFI shims. Those ports read it from the C getter, so they see the checked value.
  • A negative number in a profile reaches libobs as about 4.29e9, because the frontend reads it with 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.
  • Upstream OBS has the same code. There is no upstream issue for it.

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.

Build Case Result
RED 5f0e60e05 test_video_levels_range: C, hybrid and libobs-c-reference 4 of 5 fail: levels read 0/0 instead of 300/1000, and a bad level is stored with no warning (for example obs_set_video_levels(0, 700) gives 0/700, want 200/700)
RED 5f0e60e05 test_video_output_formats: all three fails: I010 colorspace 4 range 1: plane 0 sample 0 is 64, want 431 (the box is black)
GREEN 6f1f309b9 the new test plus related tests (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 _rust variants) C 15/15, hybrid 18/18, libobs-c-reference 18/18
GREEN 6f1f309b9 full ctest C 470/470. Hybrid 488/489: test_pulse_monitor_device failed (a known load flake) and passed 1/1 when run alone. No skips on either lane.

RED → GREEN

  • RED commit: 5f0e60e05 test: Check obs_set_video_levels on bad levels. The new test_video_levels_range (real libobs, graphics up) fails 4 of 5 on C, hybrid and libobs-c-reference. Only valid_pairs_stored_exactly passes. The updated test_video_output_formats fails on all three, because the Rec. 2100 rows are black.
  • GREEN: 6f1f309b9. test_video_levels_range 5/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 cross were run at 95a7d2455, which has the same libobs code. --lane lint was rerun at 6f1f309b9. All ok.
  • After the rebases: at 08f61d2cd (on 760f8e6), the new test and the related tests pass (C 15/15, hybrid 18/18, libobs-c-reference 18/18), exports are 1766 on all three and identical, and --lane lint is ok. The final head is RED 2c8e650 and GREEN 6ec0270, on 067f850, which only changes the frontend. There, test_video_levels_range and test_video_output_formats pass on C.
  • Real app (UI, protocol output or logging changes): not run. The only log change is the new warning for a bad level. The app sets valid levels from the profile right after each video reset, so nothing changes for it.

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_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
rdoupe force-pushed the fix/video-levels-range branch from 6ec0270 to 0d4a516 Compare October 25, 2026 00:08
@rdoupe
rdoupe enabled auto-merge October 25, 2026 00:09
@rdoupe
rdoupe added this pull request to the merge queue Oct 25, 2026
Merged via the queue into obs-rust:master with commit 5c0450c Oct 25, 2026
35 checks passed
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Oct 25, 2026
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.

libobs: obs_set_video_levels accepts 0, negative and NaN white levels

1 participant