mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Our log filled up due to thousands of WASAPI errors #410

Closed anhnht3 closed 2 years ago

anhnht3 commented 2 years ago

Hi, Is it possible to change this log_error to log_debug?

"[WASAPI] Failed to retrieve internal buffer from playback device in preparation for writing to the device."

mackron commented 2 years ago

That log message is posted when some error occurs when trying to get a pointer to write to the internal buffer. If this fails, nothing can be output to the device. That's an error, not a debug message. What's the value of hr when this is happening? If you can't put a break point on there, I've updated the dev branch to print the error code. I've also updated the dev branch to handle AUDCLNT_E_BUFFER_ERROR so you might want to try the dev branch anyway.

anhnht3 commented 2 years ago

When user unplugs a device while we are writing to it, it's expected that miniaudio can't get the internal buffer, we handle this case ourself and switch to a different device if available. However, since miniaudio writes log inside the data loop, the error message is repeated many times and flooded our logs (each change of device will create around 20 MB of log messages). The HR value is: HRESULT = -2004287484

mackron commented 2 years ago

OK, that error is AUDCLNT_E_DEVICE_INVALIDATED and the description from MSDN is as follows (which is consistent with your description):

The audio endpoint device has been unplugged, or the audio hardware or associated hardware resources have been reconfigured, disabled, removed, or otherwise made unavailable for use.

The correct thing for miniaudio to do is to stop the device. The underlying issue here is a bug that I introduced in a recent refactor to the WASAPI backend where the writing to the device would always return MA_SUCCESS. I've fixed this in the dev branch so it should now be less frequent. Will get this released very soon.

mackron commented 2 years ago

This has been released.