Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support device change notifications #34

Open
liautaud opened this issue Sep 24, 2024 · 1 comment
Open

Support device change notifications #34

liautaud opened this issue Sep 24, 2024 · 1 comment

Comments

@liautaud
Copy link

liautaud commented Sep 24, 2024

Hi Henrik,

Thanks a lot for this crate, it's been super helpful!

Currently, when recording from a device, if that device gets disconnected (e.g. a USB microphone gets unplugged), the recording loop crashes at the next call to audio_client.get_next_nbr_frames() or audio_client.read_from_device(). The recommended fix seems to be to listen to device change notifications to synchronously detect when the device disappears and to retry recording with a different device.

The crate already supports registering audio session notifications, so I feel it would be reasonable to also support registering device change notifications. Looking over the Win32 documentation, this seems to require:

Also, it seems like AudioSessionControl doesn't support unregistering session notifications. Is that intentional?

@HEnquist
Copy link
Owner

This would be a useful addition. But don't you get a call to OnSessionDisconnected with value DisconnectReasonDeviceRemoval when unplugging a device?
https://learn.microsoft.com/en-us/windows/win32/api/audiopolicy/nf-audiopolicy-iaudiosessionevents-onsessiondisconnected

There is no particular reason for not implementing unregistering, except that nobody has asked for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants