Repository navigation
obs-media-io: real-time audio thread on Linux through the Realtime portal or rtkit (Refs #5770) - #5781
Merged
Conversation
…ks (RED, Refs #5770) Tier 1 against a fake host: direct SCHED_RR, then the Realtime portal, then rtkit, then high priority; RLIMIT_RTTIME and the SIGXCPU guard before any real-time request; no request a service cannot grant; one probe per process; the startup log line. The core is todo!() here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rtal or rtkit (Refs #5770) The audio thread asks, in PipeWire module-rt's order, for SCHED_RR directly (RLIMIT_RTPRIO), then through the Realtime portal (also covers Flatpak), then rtkit, and falls back to high priority. A request the service cannot grant is skipped; one probe per process is cached. Before any real-time request the process gets RLIMIT_RTTIME (soft half of rtkit's maximum) and a SIGXCPU guard that demotes the audio thread to SCHED_OTHER|SCHED_RESET_ON_FORK, so a catch-up burst after a long stall costs real-time priority instead of OBS being killed at the hard limit. The audio thread logs the result once at start, and the demotion once. D-Bus goes through GIO (obs-util ffi::dbus_realtime, gio feature) with a 500 ms timeout and no bus autolaunch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
vpacher
enabled auto-merge
November 26, 2026 13:01
This was referenced Nov 26, 2026
Closed
This was referenced Nov 27, 2026
Closed
KelboLive
pushed a commit
to KelboLive/obs-studio
that referenced
this pull request
Nov 29, 2026
…rust#5790) (obs-rust#5791) libc::gettid is a glibc 2.30 wrapper, so libobs.so stopped linking on the AppImage's manylinux_2_28 image (glibc 2.28): the scheduled release run's AppImage build fails with "libobs.so.30: undefined reference to `gettid'" since obs-rust#5781. The raw syscall needs no glibc wrapper. Co-Authored-By: Claude Opus 5.5 <[email protected]> Ci-Attestation: {"at":1795725241,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":234,"stamp":"3bcefdc08b2120936926609bb273d4f6","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725241,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":234,"stamp":"b001a04d767ec0f66a57a311853759fb","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725241,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":234,"stamp":"3fc2a7930fcdfc65e1271469b746c849","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725241,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":234,"stamp":"500b8d807b91ff85d3f2e7c326d7e003","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725004,"gate":"general/all/client-lint","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"c8fa83b578c9995321946acacdce8b20","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725241,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":234,"stamp":"bedfc9bd7635f1817e776286113346c0","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"ef3052f9bcfafb33f20fb88d9e391272","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"117ebdfb54d7b6ea0cc134c5b27d67ce","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"7c9893e3926cd66e4707fdbec204e59b","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"063189a768b3978195af9397c4157ba9","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"dba0c77a70773b822e994dd05a86750d","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"95ea859dcd2fc68b035871ef8a5fac54","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"56e9ea1533efe393b85cd4d6cbb00464","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"7e864f82a5a6e4cb234f1839a291acce","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"ec5e6f18cf18facecbcf9921874573c4","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"bccfae2a0921ead89f35c14ac662a97a","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725004,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"620559cd4e3b8a629dae336e4917c790","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725005,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"e0cfb0721679f88a05ab7250db0b650ff9983ba8444ba9d5d4aaf9723005fd1f","lane":"client-lint","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":218,"stamp":"069f76ba0067f5f2cc78340fac03884d","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Ci-Attestation: {"at":1795725867,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"950b476384f27bc4f6597382dba91cea1abac64387df2b42ed1bb76c87ab7ddd","lane":"client-test-x86_64-unknown-linux-gnu","parents":["529d2d9fd151535e37f3b482df01c7b2dfe71667"],"secs":625,"stamp":"6bc187e2f4af66126b5216fb6ef6e2e5","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d","v":1,"via":"run"} Client-Checks: {"checks":{"base":"529d2d9fd151535e37f3b482df01c7b2dfe71667","coverage":"all-tracked-applicable-files","diff":["rust/obs-media-io/src/platform/linux.rs"],"head":"e12a6e5e776d2d5d5f9ebab8874731bf2cba1eef","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"3111c3be86c17d67ad7a37f26814a652443330b6e5a0d5c8dbd7eb3cc5222b43","tree":"c684dbbee78fd6f4fb56ec0f49a847219e7ffb7d"}}
KelboLive
pushed a commit
to KelboLive/obs-studio
that referenced
this pull request
Nov 29, 2026
…bs-rust#5819) * ci(sanitizers): require TSan not to sleep at exit (RED, Refs obs-rust#5814) The harness test requires atexit_sleep_ms=0 in TSAN_OPTIONS. It fails on master, where TSan sleeps 1 s at exit while GLib's GDBus worker thread runs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * ci(sanitizers): stop TSan's 1 s sleep at exit (GREEN, Fixes obs-rust#5814) TSan sleeps atexit_sleep_ms (default 1000) at exit while another thread runs. Since obs-rust#5781, every test process whose audio thread asks D-Bus for real-time priority keeps GLib's GDBus worker thread until exit, so each waited 1 s in the nightly tsan job. The OBS threads stop in obs_shutdown(); the threads left at exit belong to GLib (suppressed in tsan.supp) and llvmpipe. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
Refs #5770. Part of #5768 (thread priority on Linux and macOS, discussion #5458).
Change
On Linux, the audio thread now asks for real-time priority when it starts, as the Windows audio thread joins MMCSS "Audio".
Order (as PipeWire's
module-rt):SCHED_RRdirectly, whenRLIMIT_RTPRIOallows it;org.freedesktop.portal.Realtimeportal on the session bus (also covers Flatpak);MinNiceLevelif that is higher).Priority 20, clamped to
RLIMIT_RTPRIOorMaxRealtimePriority. A request that the service cannot grant (limit 0) is not sent.RLIMIT_RTTIMEand the guard. The portal and rtkit grant real time only with a process-wideRLIMIT_RTTIME.os_sleepto_ns_fastreturns at once when the target has passed, so after a long stall the audio thread mixes many ticks without blocking. Without protection, the kernel would sendSIGXCPU, thenSIGKILL. Before any real-time request (the direct path included, because an in-process PipeWire client can set the limit too):RTTimeUSecMax, the soft limit half of it;SIGXCPUhandler puts the registered audio threads back toSCHED_OTHER|SCHED_RESET_ON_FORK, then calls the previous handler, if any.OBS loses real-time priority but keeps running.
Cost: one probe per process, cached. D-Bus calls have a 500 ms timeout, and a bus whose socket is missing is not connected (no autolaunch), so Tier 2 tests and headless runs return at once.
Log: one line when the audio thread starts (for example
audio thread: real-time priority 20 through rtkit, ordefault priority (...)with the reason for each method), and one warning if the guard demotes the thread.Structure:
obs-media-io/src/thread_priority.rs: the host-neutral decision, behind aRealtimeHosttrait for every side effect.obs-media-io/src/platform/linux.rs: the Linux host (rlimits, scheduler,SIGXCPUguard).AudioThreadClassmoves out ofunix.rson Linux; macOS and the BSDs keep the empty stub (macOS: perf: obs-media-io: time-constraint policy for the audio thread on macOS #5771).obs-util/src/ffi/dbus_realtime.rs: GIO calls,gio-gated like the screensaver inhibit code. obs-media-io gets agiofeature, whichlibobs-rust'sgiofeature turns on.RED → GREEN
RED b594343: 13 Tier 1 tests in
tests/audio/thread_priority.rs, against a fake host that records every call. They cover:All 13 fail at
todo!().GREEN af34772: all pass. Media-io harness 416/416 on macOS, and on Linux with and without the
giofeature. Clippy is clean in both feature sets, and./lintpasses (Linux).Tier 2 and Tier 3 do not apply: there is no C original. Tier 2 builds hybrid libobs with
gioon, so every audio test there makes the probe once (no bus in the container, so it returns at once).Real check (Linux desktop, Arch, kernel 7.2)
A local probe: the media-io test binary with
gio, which starts a real audio thread through the public audio-output API. It ran as a user-manager unit, like a desktop app. It is not the OBS app, which is why this PR saysRefs.default priority (the Realtime portal: no real-time priority allowed; rtkit: ...ServiceUnknown...)SCHED_OTHERreal-time priority 20 through rtkit (the Realtime portal: no real-time priority allowed)SCHED_RR|SCHED_RESET_ON_FORK, 20real-time priority 20 through the Realtime portalSCHED_RR|SCHED_RESET_ON_FORK, 20SIGSTOP60 s,SIGCONTSCHED_OTHER|SCHED_RESET_ON_FORKThe stall check found a bug before this PR. A demotion to plain
SCHED_OTHERfails withEPERM, because clearingSCHED_RESET_ON_FORKneedsCAP_SYS_NICE. The thread then stayed real-time and the process was killed at the hard limit (exit 137). The handler now keeps the flag.From an SSH session, rtkit answers
AccessDenied: its polkit policy hasallow_any=no, so remote sessions are refused. A remote or headless start therefore logsdefault prioritywith that reason.Not checked:
audio_threadprofiler line from obs-media-io: register the audio thread as a profiler root with its tick period (Fixes #5769) #5774 before and after under load.Test cost
13 new tests with a fake host: each takes under 1 ms, uses no threads of its own, and touches no process state.
Ledger
docs/features.md, Audio: "Real-time audio thread".🤖 Generated with Claude Code