Skip to content

libobs: Count image memory, keep every slideshow slide - #2289

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/image-mem-usage
Oct 26, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/image-mem-usage

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2279

What and why

Upstream obsproject/obs-studio#14076. gs_image_file_ex_init() passes NULL for the memory counter (since the image-file API change in upstream c3046ec). So every Image source reports 0 bytes, and the original Image Slide Show's 400 MiB MAX_MEM_USAGE cap never applies: every slide stays decoded in memory.

Counter (C and Rust, with parity). gs_image_file_ex_init() counts into image->mem_usage again, as upstream PR 14078 does. The obs-graphics port does the same. It keeps the count aside while init resets the image, and a failed load counts nothing, as the C does (its free zeroes the image). The parity test against the original C covers the counter for the real GIF fixtures.

Original slideshow. With only the counter fixed, the original slideshow would drop every slide past the cap from its list, as it did before the API change. That would be a visible change for existing scenes. Measured: a 12-picture slideshow shows 7 slides. The slideshow now keeps every slide:

  • In list order, slides up to the cap are loaded when the list is read, as today.

  • Each slide past the cap is decoded once, so it still sizes the slideshow, then released. It stays in the list "on demand".

  • An on-demand slide is loaded only while it is one of these:

    • the current slide;
    • the slide before or after it;
    • the slide a transition is leaving;
    • in random order, the slide picked to come next. That slide is picked one slide early, so it can be loaded before it is shown.

    It is released once it is none of these.

  • Those slides decode on a task queue, as the reworked slideshow (obs-slideshow-mk2.c.h) does.

  • A slide about to be shown waits for its decode, or is decoded then if it was not loaded. It gets its texture before the transition draws it, so a fade has both pictures.

Order, slide timing, random order, hotkeys and media controls (next, previous, restart, stop) do not change. A slideshow under the cap runs exactly as before: no on-demand slides, no extra rand() calls.

Newer slideshows (slideshow_v2, the reworked slideshow) are unaffected. They already load slides on demand and never read the counter. Image sources only report their memory; nothing else reads it.

image-source gains image_source_ready_slide(), used by the slideshow. The slideshow test fixtures that build obs-slideshow.c.h gain stubs for it and for image_source_preload_image().

RED → GREEN

  • RED commit: test: Check image memory use and slideshow cap, run on master a7f12c3 (as 4e23861, before the rebase; the tests are the same). It fails on C, hybrid and libobs-c-reference:
    • test_image_file: the counter is 0 (0 != 24 for the 3x2 PNG, 0 != 16 for the still GIF, 0 != 2576 for the animated GIF, and under 4 MiB for a 1024x1024 PNG the test writes at run time, so the branch adds no image files). Same in the Rust mirror (cargo test -p obs-graphics --test obs-tests-graphics image_file: 4 failed, left: 0).
    • test_slideshow_mem_cap (real image-source and obs-transitions modules, core video, 12 generated 4096x4096 PNGs): all 12 pictures stay loaded, 5 of them past the cap (the limit is 3). In all 4 cases.
    • With only the counter fixed: total_files 7 != 12. The slideshow drops the 5 slides past the cap.
  • GREEN (head 7fa52fb14, rebased on origin/master ff9adbf; RED is b7a5ae2b0). Tests and gates ran on da4e333b5, which differs only in the formatting of tests.d/test_slideshow_mem_cap.cmake; lint ran again on both commits:
    • Image-related and slideshow cmocka tests: 12/12 on C, hybrid and libobs-c-reference, none skipped. These are test_image_*, test_slideshow_* (with test_slideshow_mem_cap), test_ws_image_mime and test_cube_lut.
    • test_slideshow_mem_cap steps through every slide with Next and Previous, a fade, random order and a folder. Each slide is shown at its size, the slideshow keeps the taller last picture's height, and at most 3 slides past the cap are loaded at once.
    • Rust image_file tests including the parity test: 18/18.
    • Exported libobs symbol sets are identical on all three lanes.
    • test_slideshow_mem_cap is registered in tests.d, like test_stinger_media_duration, because it loads plugin modules. The test graph's facts and the Rust native runner have no image-source or obs-transitions module, and an unknown graph requirement fails native_test_graph_replaces_legacy_utility_definitions. It takes about 105 s under llvmpipe, so it has a 300 s timeout.
    • Local gates: --test-diff origin/master ok, --lane lint ok (on RED and head), --lane cross ok.
  • Real app: not run. The slideshow test drives the real modules with core video under Xvfb.

Checklist

  • Base is master
  • 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
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Sources and filters)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): none. The C and the port count the same, and the parity test checks it.

@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: not queuing yet. This PR edits existing C tests. test_image_file.c changes an existing assertion, assert_int_equal(image.mem_usage, 0) → the computed size, and rewrites the 'not endorsed' note. test_slideshow_empty.c and test_slideshow_manual_end.c also gain lines. AGENTS.md says to never edit existing C tests to make a change pass. Here the behavior change is intended (upstream #14076: count image memory), so the old characterization is meant to go, but that needs an explicit call.
Options:
(a) Keep the existing files untouched and put every new assertion, including mem_usage, in the new test_slideshow_mem_cap.c or a new test_image_file_mem.c. The old mem_usage == 0 case would then need the maintainer to retire it, since it would fail.
(b) The maintainer signs off on retiring that one characterization line.
@rdoupe, which do you prefer? I'll flag (b) to the maintainer. The rest (Rust image_file.rs + render test, the ledger line, the new mem-cap test and cmake) looks fine on a first pass; CI is 20 passed, 0 failed, 7 running.

@rdoupe

rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator Author

(b), please. The line it retires, assert_int_equal(image.mem_usage, 0), was the characterization of exactly this bug, marked "characterized, not endorsed", and the PR's purpose is to make it count. Keeping it and adding a contradicting test elsewhere (a) would only leave a failing test for someone else to retire.

The two slideshow test edits change no assertions. test_slideshow_empty.c and test_slideshow_manual_end.c only gain empty stubs for the new image-source exports (image_source_ready_slide, plus image_source_preload_image in one), because both link the slideshow without image-source. If you'd rather not touch those files at all, I can move the stubs into a shared test helper.

@zackees zackees added the human-review-needed Escalated: waits on the human maintainer label Oct 26, 2026
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Thanks. The argument for (b) is reasonable, and the stub-only slideshow edits are fine. Retiring an existing C assertion is the maintainer's call, though, so I've labelled this human-review-needed and I'm holding it out of the queue until they answer. No action needed from you meanwhile.

@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Needs decision in obs-rust Multiview Oct 26, 2026
gs_image_file_ex_init() leaves mem_usage at 0 for every picture, so
Image sources report no memory and the original Image Slide Show's
400 MiB cap never applies: every slide stays decoded.

test_image_file now expects the decoded size in mem_usage: 4 MiB for a
1024x1024 PNG it writes at run time, 24 bytes for the 3x2 PNG, 16 for
the still GIF and, for the animated GIF, the frame cache, every frame,
the current frame and the file. The Rust mirror in obs-graphics expects the same.

test_slideshow_mem_cap loads the real image-source and obs-transitions
modules and makes an original slideshow of 12 generated 4096x4096 PNGs
(64 MiB each decoded, so 7 reach the cap). It steps through every slide
with Next and Previous, a fade, random order and a folder, and checks
that each slide is shown at its size, that the slideshow is sized by the
taller last picture, and that no more than 3 pictures past the cap are
loaded at once. On master all 12 stay loaded; with only the counter
fixed, the slideshow drops the 5 slides past the cap.

Refs obs-rust#2279
gs_image_file_ex_init() passed NULL for the memory counter (since the
image file API break, upstream c3046ec), so every Image source reported
0 bytes and the original Image Slide Show's 400 MiB cap never applied:
all its slides stayed decoded. It now counts into image->mem_usage
again, in C and in the obs-graphics port (which keeps the count aside
while init resets the image, and counts nothing for a failed load).

Counting again would have made the original slideshow drop every slide
past the cap from its list, as it did before the break. It keeps them
now: slides are loaded in order up to the cap as before; each slide
past it is decoded once to size the slideshow and then loaded only
while it is the current slide, the one before or after it, the one a
transition is leaving or, in random order, the one picked to come next
(picked a slide early so it can be loaded first). Those decode on a
task queue, as in the reworked slideshow; a slide about to be shown
waits for its decode, or is decoded then, and gets its texture before
the transition draws it. Order, timing, random order, hotkeys and media
controls do not change, and a slideshow under the cap runs exactly as
before. The reworked slideshow (slideshow_v2) is unchanged.

test_slideshow_mem_cap waits for the slide on screen, not only for the
index, as a slide past the cap may still be decoding when the index
changes, and its fade is shorter. The slideshow test stubs gain
image_source_preload_image and image_source_ready_slide.

docs/features.md gets a line under fixed upstream bugs.

Fixes obs-rust#2279
@rdoupe
rdoupe force-pushed the fix/image-mem-usage branch from 6dce9eb to 94918ac Compare October 26, 2026 09:44
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Maintainer decision (researched and approved by the coordinator under the maintainer's instruction): option (b). The retired line, assert_int_equal(image.mem_usage, 0), characterized the #2279 bug and was marked 'characterized, not endorsed'. test_image_file.c is an obs-rust test (#1911), not upstream's, and this PR fixes the behavior on purpose in the C and the Rust together with a parity test, not as a port. Note: this backports upstream PR #14078, which is still open, so if upstream changes the counting before it merges, follow it. Optional follow-up: move the slideshow stubs into a shared test/cmocka/image-source-stubs. Queuing.

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: libobs: image sources report 0 bytes of memory, so the slideshow memory cap never applies (upstream #14076)

2 participants