Repository navigation
obs-scene: Port the scene audio action ramp core - #1842
Conversation
|
Coordinator note: the Windows Tier 2 failure is caused by this PR, not a flake. (run 39868571554, job 120139189967) Either avoid the |
|
Agreed, thanks. The fix is in progress: obs-scene does the front erase of the action darray itself (same bytes as C's |
f691c82 to
bbacba6
Compare
RED for the port of libobs/obs-scene-audio-actions.c.h, the core of the scene item visibility audio ramp, to a new module, audio_actions, of rust/obs-scene. The safe core is a stub (todo!()): ItemAction (the queued visibility and time), Applied (the actions consumed, the visibility after them and the hides among them), frame() (the frame of the tick an action falls on), apply() (obs_scene_audio_actions_apply(), over the queue in order, with an optional gain buffer), tick_duration() and action_due() (obs_scene_audio_action_due()). tests/scene/audio_actions.rs ports test_scene_audio_action_steps 1:1, under the same case names (steps_*), in the same order, with the same steps and expectations: all 17 cases. A small model repeats the C item side around the core: the queue, the visibility, the active references and the child removal at 0, apply_scene_item_volume() and process_all_audio_actions(). The buffer has one gain past the tick, which no case may write. New edge cases (edge_*): the frame helper (late, exact, one ns before, ts 0, rate 0, u64::MAX), the window wrapping at the end of the u64 range, the core reading no further than the first action past the tick, the exact 1.0 and 0.0 gains, and the two intentional differences: with ts 0 and a buffer the fill stops at the buffer end (the C writes past it), and a rate of 0 makes every action due (the C divides by 0). soldr cargo test -p obs-data --test obs-tests-core scene::audio_actions fails 22 of 23 with "not yet implemented". The one that passes, steps_volume_without_actions, never reaches the core. Refs obs-rust#1814
Ports libobs/obs-scene-audio-actions.c.h, the core of the scene item visibility audio ramp (obs-rust#1825), to the audio_actions module of rust/obs-scene. The item side stays C in obs-scene-item-audio-actions.c.h: actions_mutex, the active reference dropped per hide and obs_source_remove_active_child(), apply_scene_item_volume() and process_all_audio_actions(). The hybrid libobs drops the C core and links the Rust shims in its place. Safe core (src/audio_actions.rs): apply() reads the queue in order, places each action on frame floor((timestamp - ts) * rate / 1e9) through util_mul_div64 as the C computes it on each host, a late one on frame 0, stops at the first one on frame 1024 or later (with ts 0 it takes them all), fills the gain buffer with the visibility before each change and the rest of the tick with the last one, and returns the actions consumed (a prefix), the visibility and the hide count. action_due() is the window, ts plus 1024 frames in ns rounded down, with the C's wrapping sum. It keeps no state, takes no lock, and denies clippy's panic, indexing and arithmetic lints. obs-scene does not depend on obs-util: util_mul_div64 and the darray erase are written out in this crate. test_scene_bounds_place_rust links the staticlib for obs-scene alone, and the obs-util objects bring in that crate's system libraries (libuuid, GIO, winmm and the base log handler on Windows), which that test does not link. Shim (src/ffi/scene_audio_actions.rs): obs_scene_audio_actions_apply() and obs_scene_audio_action_due() keep the C signatures. The queue is the item's obs_scene_item_action_array_t, mirrored with the layout of struct darray and read in place. The consumed actions are erased from the front one at a time, each as the C's da_erase(*actions, i--) with i 0 does (num minus one, then a memmove of the rest down by one item), so the memory left in the array, stale items included, is the C's. The erase allocates and frees nothing. *visible is written only when an action was consumed. Kept, characterized, not endorsed (obs-rust#1815): actions out of time order are left out of the buffer but counted; the loop and the window stop at the first action that is not due; the window rounds the tick down to whole ns (44.1 kHz); every hide is counted, without bound; with ts 0 every action is applied. Intentional differences, where C has undefined behaviour and libobs never gets there: with ts 0 and a buffer, the C writes past the 1024 gains, and the Rust writes the same gains inside them and none past them; obs_scene_audio_action_due() with a rate of 0 (the C divides by 0) returns true, as apply() puts every action on frame 0 at rate 0; a null queue or visibility does nothing and returns 0; on MSVC x64, where the C's 128-bit util_mul_div64 faults (a rate above 1 GHz), the core saturates. C side: the file leaves libobs.core-source for its own group, libobs.ported-scene-audio-actions (LIBOBS_PORTED_SOURCES), whose PCH is obs-scene-audio-actions.h with media-io/audio-io.h and util/util_uint64.h. The two functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. The exported symbol sets are unchanged (1766). test_scene_audio_action_steps still compiles the C core into itself, unchanged; test_scene_audio_actions, test_preview_only_hide, test_group_hide_transition_audio, test_group_active_refs and test_item_transition_empty_source see the swap through the real libobs. ci/test_ported_sources.py checks the group on every host. Tier 1 scene::audio_actions passes 23/23. Refs obs-rust#1814
Oracle (oracle/scene_audio_actions.c): the original obs-scene-audio-actions.c.h, unmodified, with its two functions renamed to oracle_*, plus the layout of struct item_action, of obs_scene_item_action_array_t and AUDIO_OUTPUT_FRAMES. da_erase and util_mul_div64 stay the header inlines, so the oracle erases with the C's darray code and the shim with the Rust port. Tier 3 (tests/scene/audio_actions_parity.rs): each run gives both sides the same queue (the same bytes in the same capacity, padding and spare slots included), visibility, tick, rate and gain buffer, and compares the hide count, the visibility, the darray (array not moved, num, capacity and every byte of the capacity), the gains bit for bit with a guard gain past the tick, and the window for every action's time. Runs: - the layout; - every queue of up to 3 actions over 8 chosen times (before the tick, frames 0, 1, 511, the last ns of 1023, 1024 and 2000, and the first time where since * rate wraps a u64), with each start visibility, with and without a buffer, at 48 and 44.1 kHz, on a tick and with ts 0: 69 904 runs; - 20 000 random queues of up to 40 actions in any time order, at 0, near the tick, near u64::MAX and at the wrap points, ticks at 0, near 0, anywhere and near u64::MAX, and rates from 8000 to 192000 plus 0, 1, odd ones, 1 GHz and (not on MSVC) rates where util_mul_div64 wraps; - 20 000 random windows, at the edge of the window too. Excluded, the intentional differences: with ts 0 and a buffer the C writes past the tick, so the oracle gets a buffer large enough for its writes or, past 64 Ki gains, runs once with no buffer (the state) and once on the queue up to its first action past the tick (the gains, which are what the C writes inside the tick); the Rust side may not write the guard. A rate of 0 in the window and a null queue or visibility are checked on the Rust side only. Mutation check (done once, not committed): 27 of 29 mutants fail Tier 3 or Tier 1. Core: a late action not clamped; frame 1024 counted as this tick; ts 0 breaking like a tick (steps_process_all then loops, the rest fail); a show counted as a hide; a span filled with the new visibility; the tail always 1.0; one frame late; a one-step product instead of util_mul_div64 (caught by the wrap-point times); util_mul_div64 as exact 128-bit math on every host; the visibility before a change not updated; frame_num not advanced; two hides per hide; <= in the window; no ts 0 case in the window; a 1023-frame window; a saturating window sum; rate 0 not due. Shim: no move on erase; one move of the rest by the consumed count (same items, different bytes left); one action too few erased; the visibility not written back; the start not read from *visible; the buffer ignored; the rate ignored; 0 hides returned; the window's arguments swapped; the queue read backwards. The two survivors are equivalent: a fill that writes one frame more (the next fill or the tail always rewrites that frame), and the erase without its num 0 check (the move is then of 0 items). Refs obs-rust#1814
The rust/README.md rows for rust/obs-scene (crate table and port table) now include libobs/obs-scene-audio-actions.c.h. The port row lists what stays C, how the shim reaches the item's queue, what the characterization pins and the port keeps, the intentional differences (ts 0 with a buffer stops at the buffer end; a rate of 0 makes every action due; a null queue or visibility does nothing), the MSVC overflow above 1 GHz, what Tier 3 compares, and why there is no _rust variant of the steps test. The naming.md row (libobs/obs-scene*.c.h) already covers the file. Fixes obs-rust#1814
bbacba6 to
a6d2da3
Compare
|
Coordinator: rebased onto master after #1848 landed. The conflicts in |
Fixes #1814 (PR 3 of 3; #1815 moved the scene item visibility audio ramp into
libobs/obs-scene-audio-actions.c.hand addedtest_scene_audio_actionsandtest_scene_audio_action_steps; #1825 split it into a core on the item's fields and the C item side)What and why
This PR ports
libobs/obs-scene-audio-actions.c.h, the core of the scene item visibility audio ramp, to a newaudio_actionsmodule ofrust/obs-scene(#444, phase 6). When an item whose source has audio is shown or hidden,obs_sceneitem_set_visible()queues an action with the time of the call. The audio thread applies it on the sample of the scene's audio tick that the time falls on, through a 0/1 gain buffer, and drops one active reference per hide. The frontend, obs-websocket (SetSceneItemEnabled), scripts, hotkeys and scene item transitions all reach it, but only as a bool and a time that libobs takes itself.The item side stays C in
obs-scene-item-audio-actions.c.h:actions_mutex, the active reference dropped per hide,obs_source_remove_active_child(),apply_scene_item_volume()andprocess_all_audio_actions(). So does the mixing inobs-scene.c.h. The hybrid libobs drops the C core and links the Rust shims in its place.src/audio_actions.rs):apply(actions, visible, ts, rate, buf) -> Applied { consumed, visible, hides }.floor((timestamp - ts) * rate / 1e9), throughutil_mul_div64as the C computes it on each host. A late action goes on frame 0.ts0 it takes them all.action_due(timestamp, ts, rate)is the window:tsplus 1024 frames in ns, rounded down, with the C's wrapping sum.cfg, whichutil_mul_div64formula the C compiles (MSVC x64's 128-bit one or the wrapping one), is insrc/platform/, as the lint requires.arithmetic_side_effects,indexing_slicing,unwrap_used,expect_used,panic,todo,unimplementedandunreachable. Nounsafe.src/ffi/scene_audio_actions.rs):obs_scene_audio_actions_apply()andobs_scene_audio_action_due(), with the C signatures.obs_scene_item_action_array_t, mirrored with the layout ofstruct darrayand read in place.struct item_actionis mirrored too, and the layout test checks both against the C.da_erase(*actions, i--)withi0 does (darray_erase()inutil/darray.h:numminus one, then a memmove of the rest down by one item). So the memory left in the array is the C's byte for byte, the stale bytes pastnumincluded. A single move of the rest by the consumed count would leave the same items but different bytes, and the mutation check catches it. The erase allocates and frees nothing.obs-utildependency.obs-scenedoes not depend onobs-util:util_mul_div64and the darray erase are written out in the crate.test_scene_bounds_place_rustlinkslibobs_rust-staticforobs-scenealone, and the obs-util objects bring in that crate's system libraries (the first push of this PR used obs-util, and that test then failed to link on Windows:timeBeginPeriod,UuidCreate, the base log handler). On Linux,nm -uon the linked test shows no obs-util, uuid or GIO symbol, and no obs-scene object in the staticlib references obs-util.*visibleis written only when an action was consumed, as in the C.actions_mutexaround the call, on the audio thread, or on the video thread for a preview-only scene. The shims take no lock and call nothing in libobs.obs-scene-audio-actions.c.hleaveslibobs.core-sourcefor its own group,libobs.ported-scene-audio-actions, listed insource-sets.json(LIBOBS_PORTED_SOURCES). Its PCH,libobs-ported-scene-audio-actions.pch.h, isobs-scene-audio-actions.hwithmedia-io/audio-io.handutil/util_uint64.h. The only change to the file is that include and its header comment. The block oflibobs.pch.hthat names it now names the item side, the group member that still uses the header.test_scene_audio_action_stepsstill compiles the C core into itself, unchanged.ci/test_ported_sources.pychecks the group on Linux, Windows and macOS, and that the item side stays in production.obs-scene-audio-actions.hwithoutEXPORT, so the shims are hidden:rust-hidden.txt, thelocal:list ofrust-exports.map, andrust-unexports-macos.txt.nmshows them as local (t) in all three libraries. The exported symbol sets are unchanged (1766).oracle/scene_audio_actions.c): the original file, unmodified, with the two functions renamed tooracle_*, plus the layout ofstruct item_action, ofobs_scene_item_action_array_tandAUDIO_OUTPUT_FRAMES.da_eraseandutil_mul_div64stay the header inlines, so the oracle runs the C's own darray code and arithmetic.ts0 (no tick) every action is applied.rust/README.mdrow). They are all where C has undefined behaviour, and libobs never gets there:ts0 with a buffer. The C fill is not bounded by the tick and writes past the 1024 gains. The Rust makes the same writes inside the buffer and none past it. libobs passests0 only with a NULL buffer.obs_scene_audio_action_due(). The C divides by 0. The Rust returns true, becauseapply()puts every action on frame 0 at rate 0. libobs calls it only with the audio rate. For every rate other than 0, the result is the C's.util_mul_div64is 128-bit math that faults when the quotient does not fit in 64 bits, which needs a rate above 1 GHz. The Rust saturates.rust/README.mdrows and the crate's Cargodescription. Thedocs/rust-port/naming.mdrow (libobs/obs-scene*.c.h) already covers the file. Nodocs/features.mdline: there is no user-visible change.test_scene_audio_actions,test_preview_only_hide,test_group_hide_transition_audio,test_group_active_refsandtest_item_transition_empty_sourcelinkOBS::libobs. In the hybrid libobs they run the Rust core through the real scene, on the audio thread and the preview-only video tick.There is no
_rustvariant oftest_scene_audio_action_stepslinked againstlibobs_rust-static, astest_scene_bounds_place_rusthas. I tried it while the shim still used obs-util, and it did not link (libuuid, then GIO). It is not part of this port, so Tier 3 is the direct comparison on every OS.RED → GREEN
887ca6f8fobs-scene: Add Tier 1 tests for the scene audio action ramp port. The core istodo!().soldr cargo test -p obs-data --test obs-tests-core scene::audio_actionsfails 22 of 23 with "not yet implemented". The one that passes,steps_volume_without_actions, never reaches the core.tests/scene/audio_actions.rs) portstest_scene_audio_action_steps1:1: all 17 cases (steps_*), under the same names, in the same order, with the same steps and expectations. A small model repeats the C item side around the core: the queue, the visibility, the active references and the child removal at 0,apply_scene_item_volume()andprocess_all_audio_actions(). The buffer has one gain past the tick, which no case may write.edge_*):ts0, rate 0,u64::MAX;u64range;ts0 fill stops at the buffer end, and a rate of 0 makes every action due.obs-tests-core. No new test binary.77f7672daobs-scene: Port the scene audio action ramp core.scene::audio_actionspasses 23/23.2563d278aobs-scene: Check the scene audio action ramp port against the C(tests/scene/audio_actions_parity.rs).arraynot moved,num,capacity, and every byte of the capacity;ts0: 69 904 runs. The times are before the tick, frames 0, 1, 511, the last ns of 1023, 1024 and 2000, and the first time wheresince * ratewraps au64;u64::MAXand at the wrap points;u64::MAX;util_mul_div64wraps;ts0 and a buffer the C writes past the tick. So the oracle gets a buffer large enough for its writes. Past 64 Ki gains, it runs twice instead: once with no buffer (the state), and once on the queue up to its first action past the tick (the gains, which are exactly what the C writes inside the tick). The Rust side may not write the guard. A rate of 0 in the window, and a null queue or visibility, are checked on the Rust side only.ts0 breaking like a tick (steps_process_allthen loops forever, and 3 Tier 1 cases and both queue parity tests fail); a show counted as a hide; a span filled with the new visibility; the tail always 1.0; one frame late; a one-step product instead ofutil_mul_div64;util_mul_div64as exact 128-bit math on every host; the visibility before a change not updated; the frame not advanced; two hides per hide;<=in the window; nots0 case in the window; a 1023-frame window; a saturating window sum; rate 0 not due.*visible; the buffer ignored; the rate ignored; 0 hides returned; the window's arguments swapped; the queue read backwards.num0 check: the move is then of 0 items.HYBRIDtree withOBS_BUILD_C_REFERENCE=ON. Fullctest -j4, headless (private Xvfb with-noreset, private D-Bus, fresh HOME):HYBRID,OBS_BUILD_C_REFERENCE=ONHYBRID,OBS_BUILD_C_REFERENCE=ONnmshows both functions as local (t) in both libraries.OBS_LIBOBS_BACKEND=Cwas last run before the obs-util change, on the base with libobs, frontend: Take a NULL protocol in the output protocol lookups #1828: 377/377, IDENTICAL (1766). The obs-util change touches only Rust, which that lane does not build.test_scene_bounds_place_rust16/16, with no obs-util symbol in the binary and no undefineduuid, GIO or base log symbol (nm -u).test_scene_audio_actions4/4,test_scene_audio_action_steps17/17,test_preview_only_hide6/6,test_group_hide_transition_audio4/4,test_group_active_refs10/10,test_item_transition_empty_source4/4.soldr cargo test -p obs-data --test obs-tests-core scene::passes 100/100 (29 of them new: 23 Tier 1, 6 Tier 3), and the wholeobs-tests-corebinary passes 757/757.test_scene_audio_actionson its own, with the machine under heavy load from other builds (load average 22 to 24): the hybrid failed once inshow_over_other_item, and the C-backend libobs, which has no Rust in it, failed once inhide_over_other_item. In both, a change landed on sample 0 of a tick: the known flake of that test under load, which a separate fix covers. Run alone again, it passed. On the final base it passes in full ctest and on its own.uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.ci/test_build_groups.pyandci/test_ported_sources.pypass.Windows/macOS: not built there. The core and the shim have no host conditional. The parity test leaves out, on MSVC only, the rates above 1 GHz where
util_mul_div64faults.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 (not applicable: no warning or flag change)