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 4224

Summary: [Patch] [WinRT] Call PrepDevice during SDL_OpenAudioDevice, not on the audio thread
Product: SDL Reporter: Ethan Lee <flibitijibibo>
Component: audioAssignee: Ethan Lee <flibitijibibo>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: Windows 10   
Attachments: Patch to fix WASAPI device init for WinRT
Patch to fix WASAPI device init for WinRT [v2]
Patch to fix WASAPI device init for WinRT [v3]

Description Ethan Lee 2018-08-09 14:48:32 UTC
Created attachment 3277 [details]
Patch to fix WASAPI device init for WinRT

Attached is a patch that fixes a whole bunch of WASAPI WinRT bugs at once. All it does is move PrepDevice away from the thread and into the ActivateDevice routine, waiting until the async call is complete to do so. It's not the most pleasant thing in the world but the bugs that happen if we _don't_ do this are significantly worse.
Comment 1 Ethan Lee 2018-09-17 19:24:01 UTC
Created attachment 3305 [details]
Patch to fix WASAPI device init for WinRT [v2]

Patch has been updated to use the 'isrecovery' parameter from WASAPI_ActivateDevice. This is necessary for supporting multichannel audio when the requested channel count does not match the device's native channel count.
Comment 2 Sam Lantinga 2018-09-24 23:47:21 UTC
This code will spin forever if ActivateCompleted() fails. Can you update the patch to handle that case?
Comment 3 Ethan Lee 2018-09-25 05:46:06 UTC
Created attachment 3311 [details]
Patch to fix WASAPI device init for WinRT [v3]

Patch has been updated to do all of the ActivateResult work on the main thread. This should prevent infinite spinning and is probably safer in other ways as well. Tested on Xbone and Windows 10.
Comment 4 Sam Lantinga 2018-09-26 02:50:05 UTC
Looks good, thanks!
https://hg.libsdl.org/SDL/rev/09e314140a28