Repository navigation
Conversation
Query kAudioDevicePropertyIOThreadOSWorkgroup for each stream's output and input device during setup() and cache the result in CoreStreamData. Add a C-ABI entry point, audiounit_stream_get_workgroup, returning a retained os_workgroup_t so auxiliary threads that cooperate on a stream's audio deadline (e.g. audioipc's cross-process callback dispatch thread) can join the workgroup. Introduces a small RAII WorkGroup wrapper over os_workgroup_t to manage the +1 retain transferred from CoreAudio and from the capi. Query failures are non-fatal: older OS versions and some virtual devices do not publish a workgroup.
| // Querying a second time should return a fresh retained reference, | ||
| // not the same pointer invalidated. Both must be released. | ||
| let wg2 = unsafe { crate::capi::audiounit_stream_get_workgroup(stream) }; | ||
| assert!(!wg2.is_null()); |
There was a problem hiding this comment.
Should assert_eq!(wq, wq2) be added here?
I am a bit confused about why we need two calls here without checking the two handle are same or not. os_release returns void, so nothing can be checked. Since internal ref-count for the Property::IOThreadOSWorkgroup handle is not detectable I guess, the ref-count imbalance can only be caught under ASAN build.
There was a problem hiding this comment.
Added assert_eq!(wg, wg2) and clarified the comment: both calls return the same cached workgroup pointer, with a separate retained reference that must be released for each call. The equality check verifies identity; it does not itself prove refcount balance, so sanitizer coverage remains useful.
I also merged current trailblazer and resolved the import conflict with the ringbuf update, preserving the new ringbuf imports and the WorkGroup import. Formatting, Clippy, and both focused workgroup tests pass locally with access to the real output device; the positive workgroup case ran rather than taking the no-device/no-workgroup skip path.
Thanks for the reviews. Once CI is green on the updated branch, is there anything else needed before merging?
CI update: the macOS 14/15 stable jobs and AddressSanitizer passed on the updated branch (both push and PR runs). ThreadSanitizer failed in the existing ringbuf consumer-cache path during device-unplug tests: input/output callbacks reach BufferManager::available_frames / consumer operations and race on the cached index. The current upstream commit 4b6a206 has the same report in its September 22 nightly run. This remains a real unresolved sanitizer report; the workflow marks the nightly job experimental (continue-on-error).
Current PR job: https://github.com/mozilla/cubeb-coreaudio-rs/actions/runs/36868009366/job/110388304641
Upstream baseline: https://github.com/mozilla/cubeb-coreaudio-rs/actions/runs/35798561451/job/106983421589
Query kAudioDevicePropertyIOThreadOSWorkgroup for each stream's output and input device during setup() and cache the result in CoreStreamData. Add a C-ABI entry point, audiounit_stream_get_workgroup, returning a retained os_workgroup_t so auxiliary threads that cooperate on a stream's audio deadline (e.g. audioipc's cross-process callback dispatch thread) can join the workgroup.
Introduces a small RAII WorkGroup wrapper over os_workgroup_t to manage the +1 retain transferred from CoreAudio and from the capi. Query failures are non-fatal: older OS versions and some virtual devices do not publish a workgroup.