stoneface86 / trackerboy

Game Boy / Game Boy Color music tracker
https://www.trackerboy.org
MIT License
113 stars 5 forks source link

hangs when disconnecting device using pulseaudio backend #3

Closed stoneface86 closed 3 years ago

stoneface86 commented 3 years ago

This is a known issue, and may be a problem with miniaudio, but I'll leave this issue here in case anyone else has the same problem.

When playing out to a device using the pulseaudio backend, and the device is disconnected, the render continues as if the device was operating normally. What should happen is that the render is aborted, and an error message is displayed to the user. Since we do not get an error, the device is still used and results in a deadlock (hang) when trying to use it again. Miniaudio does not report an error when stopping the device, so there is no way to know if the device disconnected.

A possible workaround would be to implement a watchdog in the render function, such that if the buffer remains full for more than 1 second or so, consider the device inoperable and abort the render.

I have posted an issue in the miniaudio repo, will update when I hear back from the maintainer.

stoneface86 commented 3 years ago

So apparently the device is "suspended" when this happens and pulseaudio does stream routing, so miniaudio considers the device still running. A recent commit fixes this issue, by invoking the stopCallback when suspended but it requires MA_DEBUG to be defined. For now, we'll stick with the watchdog workaround, but I'll leave this issue open until a better solution is found.

The dev plans on adding an event system for things like starting, stopping and switching, so hopefully that system will work better for us once it's implemented.