SerenityOS / serenity

The Serenity Operating System 🐞
https://serenityos.org
BSD 2-Clause "Simplified" License
29.64k stars 3.15k forks source link

AudioServer: Handle missing audio device gracefully #24631

Closed kleinesfilmroellchen closed 4 days ago

kleinesfilmroellchen commented 5 days ago

On several platforms, we don't yet have audio support, so audio devices are missing. Instead of having AudioServer crash repeatedly, and not having the ability to open any app that relies on it, we should instead handle missing devices gracefully. This implementation is minimal, audio device hotplugging support and such should be implemented together with multi-device support. AudioServer will start up and seem to function normally without an audio device, but it will pretend the device has a sample rate of 44.1 kHz and all audio input is discarded.

kleinesfilmroellchen commented 4 days ago

@nico I am still not sure how a dummy event loop that drops events is better than the solution I have implemented here. We need to open both IPC servers to not make clients crash, we need to respond to some requests to not make clients hang or behave weirdly, and in the future I'd like to allow some functionality to continue working under these conditions, like recording back the audio output. (As a point of comparison: you can still use localhost without a physical NIC)

nico commented 4 days ago

It seems simpler to me from a distance since only main.cpp needs to know about that case then, and Mixer (and the whole audio subsystem) has clear invariants: Audio code only runs if there are audio devices. Now it can kinda seep in anywhere.

But eh, if you like it as is, as long as you keep it running, whatever :)

Thanks for fixing a crash!