wasapi: implement IMMNotificationClient for device change detection - #2538
wasapi: implement IMMNotificationClient for device change detection#25380x0003 wants to merge 1 commit into
Conversation
MaxKellermann
left a comment
There was a problem hiding this comment.
I didn't understand much of this because I'm not a Windows guy, but some things looked exceptionally ugly.
|
Refactored, should address all of your comments. |
0375758 to
8f417fb
Compare
|
Accidentally pushed fork's master to this branch, sorry for the spam. |
7c202df to
85611cd
Compare
|
The audio pop fixes should be in a separate PR now that I think about it, sorry about that. |
|
Hey, don't request another review if you havn't addressed all comments from the other review! |
bc7bbcb to
0806db3
Compare
|
I'm currently reading #1880 again, and I wonder how your change would be able to solve this problem. You added a try/catch block to WasapiMixer::GetVolume(), but this isn't where the crash of that bug report occurs. Are you really sure that your patch solves this crash bug? |
|
Oh damn, you are right, it doesn't. It solves crashes when the output is transfered to another device, not when there's nothing to output to. |
|
So it's a different crash bug? |
|
Wait, no, I take that back. Yes, yes it does solve that crash, from the issue too, along with output transfers (which is really the same as trying to output to nothing, if only for a very brief moment, now that I think about it) I did not properly test it though, the output was silently going to my monitor without me noticing, so it's a good thing you questioned me. I can confirm this really does work. |
|
Also, I'm anticipating you comment that #1408 has winmm output, not wasapi :) If you think that it doesn't really solve that issue - and to be fair it doesn't technically - feel free to drop it from the description. |
Really? Your fix that adds a try/catch to the main thread fixes a crash in the COM worker thread? |
|
Yes. Literally just tried again using the same repro steps: I tried with
No crashes in both instances. |
|
Wait, you wrote no crashes. But your first commit claims it fixes a crash bug! So what crash are we really talking about? |
No crashes with the changes from this PR applied. I can't get gdb to play well on windows, it says no backtrace after the crash (yes I am running a build with debug symbols), so no stack trace, sorry. The crash is reproducible in the exact same steps though, as I said. It could very well be that the "wasapi: detect default audio device changes" fixes it, but that shouldn't be the case, I worked on the problems separately and fixed the crash first, that's why they're separate commits... I'll try building without it in a moment. |
Then try with just the first commit. The commit message of your first commit claims it fixes a crash bug, and I want know which one and I want to verify whether that is really correct. |
|
Let me do more testing actually. |
|
Squashing makes no sense here. These are distinct changes, but I doubt that the "mixer" commit makese sense at all. |
|
I'm thinking so too looking it over again. I'll tackle it later. |
97780c5 to
9b99e29
Compare
|
You were right, mixer changes were superficial. Sorry for wasting your time on reviewing irrelevant code. |
But it's not a waste of time if you have learned something useful. I'm happy that you decided to improve MPD! Nothing is simple, just don't give up. |
|
Found a couple edge cases that have to do with setting explicit device: Converting to draft while I investigate. |
eec142d to
850d19e
Compare
|
I renamed the PR and squashed everything into one commit, since this is really more of an all-encompassing addition of the device change notification support that was completely missing before, that also happens to fix a couple of filed issues, rather than a targeted bugfix. Think this is the best I can do. Gonna run it for a while, see if there are any quirks, then mark for review. There is still one super niche issue left, in a FIXME comment in DeviceNotification.hxx. I can't figure out how to solve it, but it's more of an annoyance than anything. Maybe if someone smarter than me comes around they'll be able to fix it. |
Implement IMMNotificationClient via WasapiDeviceNotification to detect OnDefaultDeviceChanged and OnDeviceStateChanged events. The worker thread signals via AudioDeviceChanged, triggering an automatic reopen. Without this implementation, the wasapi output plugin doesn't perform automatic device switching, and crashes MPD when a device is disconnected while paused and playback is resumed.
|
fyi, I'll be offline for a week or so, so further review of your PRs will be delayed. |
Closes #1408
Closes #1880