Repository navigation
libobs: Port the PulseAudio stream flags to obs-audio-monitoring - #1513
Merged
Merged
Conversation
RED for the port of libobs/audio-monitoring/pulse/pulseaudio-stream-flags.c.h to the new crate obs-audio-monitoring (naming.md: obs-<area> after the libobs directory, audio-monitoring/). The safe core's functions are todo!() stubs. The cases mirror test_pulse_monitor_flags and test_pulse_monitor_backlog 1:1, the backlog test's queue model included, plus edge cases: the exact flags, a null id and near misses of "default", event bits outside both masks, type 0x30, other facilities, the window boundary, the slack rule, and two characterized C quirks (a sample at time 0 opens no window; the unsigned arithmetic wraps). They run as a module of the core category binary, obs-tests-core. soldr cargo test -p obs-data --test obs-tests-core audio_monitoring:: fails 19 of 21 with "not yet implemented"; the two constant checks pass. Refs obs-rust#1512
libobs/audio-monitoring/pulse/pulseaudio-stream-flags.c.h moves to rust/obs-audio-monitoring, a new crate for libobs/audio-monitoring/ (naming.md row added). pulseaudio_monitor_stream_flags, pulseaudio_monitor_reset_on_sink_event and pulseaudio_monitor_backlog_excess are the safe core (pulse_stream_flags.rs) with C ABI shims in src/ffi/; libobs-rust re-exports them. The C file has no EXPORT, so the shims are hidden (rust-hidden.txt, rust-exports.map, rust-unexports-macos.txt). They build on every host and are called only on Linux and FreeBSD with ENABLE_PULSEAUDIO. The C file leaves libobs.pulse for its own ported group, libobs.ported-pulse, with a PCH of just <string.h> and its header, listed as LIBOBS_PULSE_PORTED_SOURCES and added under ENABLE_PULSEAUDIO in os-linux.cmake and os-freebsd.cmake. rust/tools/ported_sources.py (the Tier 2 object check) and obs-build's C variant read the new list. The <pulse/def.h> values are Rust constants. The oracle compiles the original C against libpulse's header where it is installed, else against a stand-in (oracle/pulse-shim/pulse/def.h) with the same values, so cargo test needs no libpulse. A test compares the constants with the oracle's and the struct layout with the C header. test_pulse_monitor_flags and test_pulse_monitor_backlog compile the C into themselves and stay unchanged; Tier 3 parity is the proof of the swap: fixed cases and proptests over device ids, sink events and backlog runs (wrapping clocks and targets included). Intentional difference: a null backlog returns 0 (C dereferences it). Fixes obs-rust#1512
This was referenced Oct 20, 2026
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 22, 2026
…-monitor-format.c (obs-rust#1698) Behavior-neutral extraction before the Rust port: the PulseAudio monitor's sample format, channel map and volume code, the arithmetic of catching up after a stall, and the feedback-loop device match move from pulseaudio-output.c.h and pulseaudio-wrapper.c.h into pulseaudio-monitor-format.c.h, with their declarations in pulseaudio-monitor-format.h (no EXPORT), as pulseaudio-stream-flags.h did before obs-rust#1513. - pulseaudio_channels_to_obs_speakers(), pulseaudio_to_obs_audio_format() and pulseaudio_channel_map() move verbatim and lose their static. - process_byte/s16/s32/float move verbatim and stay static. process_volume() becomes pulseaudio_monitor_process_volume(), which takes the format and channel count instead of the file-local struct audio_monitor. - The spec fallbacks in pulseaudio_sink_info() become pulseaudio_monitor_sink_format() and pulseaudio_monitor_sink_channels(). The caller logs when they differ from the sink's spec, which is exactly when it logged before (each fallback is itself supported). - drop_backlog()'s arithmetic becomes pulseaudio_monitor_queued_bytes() and pulseaudio_monitor_drop_split(). The pa_stream_* calls, the tlength choice and the log stay. pa_timeval_age() is still called only while playing; 0 otherwise, which subtracts nothing, as before. - devices_match()'s comparison becomes pulseaudio_monitor_devices_match(), with the default sink's name passed in. devices_match() stays in pulseaudio-wrapper.c.h and calls get_default_id() once when either id is "default", as before (it never did for neither, at most once for both). The file joins libobs.pulse (Linux and FreeBSD, ENABLE_PULSEAUDIO), in alphabetical order, and its includes join libobs-pulse.pch.h. The exported symbols are unchanged; the new functions are local. test_pulse_default_id compiles pulseaudio-wrapper.c.h, so it now compiles the new file next to it (CMake and the obs-build manifest). New characterization test test_pulse_monitor_format, which compiles the moved file (C only, no server, ASan and UBSan). It pins every pa_sample_format_t and the played fallback, every channel count 0-255, each layout's channel map (positions past the count included) and the libpulse ABI numbers, the volume per format at 0, 0.1, 0.25, 0.5, just under 1 and 1 (U8 truncation, S32's 24 bits through the float, other formats untouched), that exactly frames * channels samples are written, the queued-bytes and drop arithmetic at every frame remainder, and the device match with "default" on either side, an empty default, names ending in .monitor, and NULL. Characterized, not endorsed: above a volume of 1 (Advanced Audio Properties allows +26 dB), U8, S16 and S32 convert the scaled sample back without a clamp. Out of range that is undefined behaviour (in practice it wraps), so only in-range results are pinned; the fix follows before the port. Refs obs-rust#1697
6 of 7 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 22, 2026
…nitoring (obs-rust#1721) * libobs: Add Tier 1 tests for the PulseAudio monitor format port The next unit of obs-audio-monitoring is audio-monitoring/pulse/pulseaudio-monitor-format.c.h: the monitoring stream's sample format and channel map, the volume it applies in the sink format (with the integer saturation from obs-rust#1709), the catch-up arithmetic after a stall, and the feedback-loop device match. This adds the safe core's API as pulse_format, with the libpulse and libobs enum values it uses and todo!() bodies, and its Tier 1 tests in the existing core category binary (obs-tests-core, no new binary). The 12 cases of test_pulse_monitor_format are ported 1:1, one test each under the C case's name, guard samples included. New cases: layouts, counts and formats far out of range, the sample sizes, the clamp bounds themselves and the first values inside them, NaN and infinite volumes (Rust's own result; NaN is undefined in C), a buffer shorter than frames * channels, the wrapping of the queued-bytes sum and difference, a zero frame size, and device ids that nearly match, are not UTF-8 or say "default" with no default sink. audio_monitoring::pulse_format fails 20 of 20 with "not yet implemented". Refs obs-rust#1697 * libobs: Port the PulseAudio monitor format and volume to obs-audio-monitoring The safe core, pulse_format, takes the sink format and channel count to the OBS format, speaker layout and channel map, picks the fallback spec (FLOAT32LE, stereo), applies the volume per format, does the queued-bytes and drop-split arithmetic, and matches a source against the monitoring output's .monitor device. Sample buffers are byte slices, read and written in native order, so no alignment is needed. The volume is the C's f32 arithmetic with the saturation of obs-rust#1709 written out as the C's comparisons, so in-range results are the truncated product, bit for bit. The module denies clippy's panic, indexing and arithmetic lints; util_mul_div64 is computed without obs_util's panics (the divisor is a constant). The nine functions get #[no_mangle] shims with the C signatures, uint_fast8_t and uint_fast32_t at the host's width and pa_channel_map mirrored, all hidden like obs-rust#1513's. The C file moves from libobs.pulse to its own group, libobs.ported-pulse-format, listed under LIBOBS_PULSE_PORTED_SOURCES, so only the C targets compile it. The exported symbols are unchanged. Tier 3 compares the shims with the original C (oracle/pulse_format.c) byte for byte: every test_pulse_monitor_format input, then proptests over formats, channel counts, layouts, random sample buffers with guards, volumes from 0 to 20, the backlog numbers and device ids. The oracle reads libpulse's headers where installed, else stand-ins with the same values. Intentional differences, all inputs that crash the C: map[8..] (indeterminate in C) is PA_CHANNEL_POSITION_INVALID, and a null sample buffer, a zero frame size and a "default" id with a null default sink do nothing, drop nothing and do not match. Fixes obs-rust#1697
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 #1512
What and why
This PR ports
libobs/audio-monitoring/pulse/pulseaudio-stream-flags.c.hto a new crate,rust/obs-audio-monitoring. The file has three functions:pulseaudio_monitor_stream_flagspulseaudio_monitor_reset_on_sink_eventpulseaudio_monitor_backlog_excessAll three are pure.
pulseaudio-output.ccalls them.libobs-with-rustdrops the C file and links the Rust shims.obs-<area>, named after the libobs directory, and that a new libobs area gets a new row. The file is inlibobs/audio-monitoring/, so the crate isobs-audio-monitoring, with the rowlibobs/audio-monitoring/→rust/obs-audio-monitoring. It is notobs-media-io, because that crate's row islibobs/media-io/.ci/test_naming.pypasses. The crate is a plain rlib, a dependency oflibobs-rust, withdeny(unsafe_code)outsideffi.src/pulse_stream_flags.rs):stream_flags(Option<&[u8]>):Noneis the C's null id.reset_on_sink_event(...).Backlog::excess(...): it uses the C's wrappinguint64_tarithmetic.<pulse/def.h>values are Rust constants. The core has no libpulse dependency and no hostcfg.src/ffi/pulse_stream_flags.rs):#[repr(C)] pulseaudio_monitor_backlog.c_uint. All their values are non-negative and fit in 32 bits.EXPORT, so the three symbols are hidden: they are listed inrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt, and there is norust-exports.dfragment. This is the same as the scene-bounds port (libobs: Port obs_bounds_fit_scale to Rust #1486).ENABLE_PULSEAUDIOcall them, so Windows and macOS need nothing special.libobs.pulseforlibobs.ported-pulse. Its PCH,libobs-ported-pulse.pch.h, holds only<string.h>and the file's own header, so the oracle and the C tests compile the file without the core.LIBOBS_PULSE_PORTED_SOURCESinsource-sets.json. It is added tolibobsonly, underENABLE_PULSEAUDIO, inos-linux.cmakeandos-freebsd.cmake. This mirrorsLIBOBS_HEVC_PORTED_SOURCES.rust/tools/ported_sources.py, which drives the Tier 2 "compiled into libobs, not into libobs-with-rust" object check (new--without-pulse, test extended), and obs-build's Linux C variant.libobs-pulse.pch.hloses the moved file's<string.h>section. The remaining pulse files get it throughobs-internal.h, and the C lane builds.oracle/pulse_stream_flags.c): it renames the three functions with#defines, includes the original file, and exports the def values and the struct layout.pulseaudio-stream-flags.hincludes<pulse/def.h>, and the Fast Gate runner installs onlyuuid-dev. The oracle therefore has a stand-in,oracle/pulse-shim/pulse/def.h, in the spirit oforacle/sse-shimand the vendored uthash.__has_include_next), the stand-in forwards to it and defines nothing. The oracle then uses libpulse's own values, and the parity test checks the Rust constants against them._Static_asserts.-Wpedantic -Werrorwith GCC and Clang in both modes.backlogreturns 0. C dereferences it, and its only caller never passes null. It is listed in the parity test header and in therust/README.mdrow. Nothing else differs, quirks included (both are pinned in Tier 1):now_ns == 0opens no window;uint64_t.test_pulse_monitor_flagsandtest_pulse_monitor_backlogcompile the C into themselves and are unchanged. They still pass in every lane, but they cannot see the swap, so Tier 3 is the swap's proof, as with scene-bounds. (The issue says the backlog test has 3 cases; it has 6, and all 6 are mirrored.)RED → GREEN
e3c06e7cflibobs: Add Tier 1 tests for the PulseAudio stream flags port. The safe core hastodo!()bodies.soldr cargo test -p obs-data --test obs-tests-core audio_monitoring::fails 19 of 21 tests with "not yet implemented". The two constant checks pass.tests/audio_monitoring/pulse_flags.rs,pulse_backlog.rs) mirrors both cmocka tests 1:1, including the backlog test's queue model (steady, 3.2 s and 0.6 s stalls, drift, bursty source, draining spike). New cases:"default";PA_INVALID_INDEXon both sides;obs-tests-core, registered inobs-data/tests/core.rsand in the testing-policy category table. There is no new test binary:ci/test_binary_cap.pyreports 8 of 8.d873d7852libobs: Port the PulseAudio stream flags to obs-audio-monitoring.audio_monitoring::passes 28/28, and the wholeobs-tests-corebinary passes (149/149).struct pulseaudio_monitor_backlog, compared with the C header. The 13 def values and the two backlog constants are compared with the oracle. Locally the oracle used libpulse's header.tests/audio_monitoring/pulse_parity.rs):"default", near misses, any bytes), sink events (facility, type and stray high bits, or anyu32; colliding indexes includingPA_INVALID_INDEX), and backlog runs of up to 200 steps from a zero or arbitrary state, with a clock that mostly advances by up to a packet, sometimes by exactly the window or one ns short of it, and sometimes jumps or wraps;max→min: 4 failures;<→<=: 5;sink_idx != PA_INVALID_INDEXguard: 3. The first run caught this one only in the fixed cases, so I weighted the event strategy toward sink events. Its minimal input isevent = 0x20, event_idx = sink_idx = PA_INVALID_INDEX;"default"matched as a prefix: 3.ENABLE_PULSEAUDIO=ON. Each tree runs the cmocka tests againstlibobs(OFF) andlibobs-with-rust(ON):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)test_pulse_monitor_flagsandtest_pulse_monitor_backlogpass in all four, and so do the PipeWire end-to-end monitoring tests (test_pulse_monitor_device,test_pulse_monitor_reset*,test_pulse_stream_restart,test_pulse_two_sources).libobs.ported-pulse+.h.c.ois linked intolibobsand not intolibobs-with-rust. In both libraries the three symbols are local (t).ci/local_gate.py:--lane lint(clang-format, gersemi, rustfmt, clippy-D warnings, Dylints, ifdef ratchet, test-binary cap): passed.--lane cross(clippy and Dylints forx86_64-pc-windows-msvcandaarch64-apple-darwin, plus a link of every test binary, oracle included): passed.--lane cross-release(aarch64-pc-windows-msvc,x86_64-apple-darwin,aarch64-unknown-linux-gnu): passed.--lane rust-test(soldr cargo test --workspace --locked, plus a--no-runlink forx86_64-pc-windows-gnu): passed.obs-tests-core149/149, and the obs-util harness 637/637, including theexport_listcheck that every shim is exported or hidden.ci/test_build_groups.py,ci/test_naming.py,ci/test_ported_sources.pyandci/test_rust_scope.py: OK.Checklist
master(or the description starts with a Stacked: note)test_pulse_monitor_flagsandtest_pulse_monitor_backlog)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable