fix: make BT A2DP output exclusive to one process

The A2DP output is a single unmixed PCM stream. A second process
opening audio while a stream was active would reconfigure the SBC
encoder and media clock under the owner and interleave both apps' PCM
into one ring, garbling playback (e.g. launching DOOM destabilized
Music). Add ClaimOutput/ReleaseOutput pid ownership: the first opener
gets the BT sink, later openers fall back to the HDA mixer, and only
the owner can tear the stream down. The scheduler releases ownership
on process exit so a killed app cannot leak the claim.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-07-10 12:41:17 +02:00
co-authored by Claude Fable 5
parent 9519e174c0
commit 928fe0bbed
5 changed files with 75 additions and 14 deletions
+6
View File
@@ -24,6 +24,7 @@
#include <Api/Heap.hpp>
#include <Api/LibSyscall.hpp>
#include <Drivers/Audio/Mixer.hpp>
#include <Drivers/USB/Bluetooth/A2dp.hpp>
#include <Ipc/Ipc.hpp>
// Assembly: context switch with CR3 and FPU state parameters
@@ -1104,6 +1105,11 @@ namespace Sched {
// and its ring buffer don't leak when an app forgets to audio_close.
Drivers::Audio::Mixer::CleanupProcess(exitingPid);
// Release the Bluetooth A2DP output if this process owned it, so a
// killed app cannot leave the output claimed forever (no-op when the
// process was not the owner).
Drivers::USB::Bluetooth::A2dp::ReleaseOutput(exitingPid);
// Release process-scoped IPC handles/mappings before tearing down the address space.
Ipc::CleanupProcessSlot(slot, exitingPid, proc.pml4Phys);
montauk::abi::CleanupHeapForSlot(slot, proc.pml4Phys);