We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4605 - WASAPI_WaitDevice hang
Summary: WASAPI_WaitDevice hang
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: audio (show other bugs)
Version: HG 2.1
Hardware: x86 Windows 7
: P2 blocker
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.10
Depends on:
Blocks:
 
Reported: 2019-04-23 10:23 UTC by Matt Brocklehurst
Modified: 2019-06-08 20:42 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Brocklehurst 2019-04-23 10:23:32 UTC
Hi

We've noticed that if you are playing audio on Windows via the WASAPI interface and you unplug and reconnect the device a few times the program hangs.

We've debugged the problem down to

static void
WASAPI_WaitDevice(_THIS)
{
    
   ... snip ...
 if (WaitForSingleObjectEx(this->hidden->event, INFINITE, FALSE) == WAIT_OBJECT_0) {
   ... snip ...
}

This WaitForSingleObjectEx does not havbe a time out defined, so it hangs there forever.

Our suggested fix we found was to include a time out of say 200mSec 

	DWORD eventRet = WaitForSingleObjectEx(this->hidden->event, 200, FALSE);
		if (eventRet == WAIT_OBJECT_0) {
            const UINT32 maxpadding = this->spec.samples;
            UINT32 padding = 0;
            if (!WasapiFailed(this, IAudioClient_GetCurrentPadding(this->hidden->client, &padding))) {
                /*SDL_Log("WASAPI EVENT! padding=%u maxpadding=%u", (unsigned int)padding, (unsigned int)maxpadding);*/
                if (padding <= maxpadding) {
                    break;
                }
            }
        }
	else if (eventRet != WAIT_TIMEOUT)
	{
            /*SDL_Log("WASAPI FAILED EVENT!");*/
            IAudioClient_Stop(this->hidden->client);
            SDL_OpenedAudioDeviceDisconnected(this);
        }

We have done quite a bit of testing with this fix in place on various hardware configurations and it seems to have resolved the issue.

Many thanks in advance

Regards

Matt Brocklehurst,
Inspired Gaming.
Comment 1 Ryan C. Gordon 2019-05-18 18:48:54 UTC
Tagging a bunch of bugs with "target-2.0.10" so we have a clear list of things to address before a 2.0.10 release.

Please note that "addressing" one of these bugs might mean deciding to defer on it until after 2.0.10, or resolving it as WONTFIX, etc. This is just here to tell us we should look at it carefully, and soon.

If you have new information or feedback on this issue, this is a good time to add it to the conversation, as we're likely to be paying attention to this specific report in the next few days/weeks.

Thanks!

--ryan.
Comment 2 Sam Lantinga 2019-06-08 20:42:13 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/bfd1b2fc6e2f