-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WASAPI code improvements #8316
WASAPI code improvements #8316
Conversation
Build fails because VS2017 on the build server is too old. Seems to be the same error as reported here: Apparently it can be worked around by defining |
The AudioCommon CMakeLists file should also be modified to handle the use of WIL. |
I normally steer clear of CMake, so will
be valid syntax? The other part about adding |
b061e72
to
92eed7e
Compare
I have fixed CMake definitions (and tested them), also reworded all mentioned comments. Also I added one more commits, because I just noticed a |
So with build machine now migrated to Visual Studio 2019, and build succeeding, any blockers preventing from merging this in? |
92eed7e
to
4cfdde4
Compare
Rebased on latest master and used the most up to date WIL. Doesn't bring any improvements to the PR but I think it makes sense to start off the most up to date submodule. |
4cfdde4
to
7e9bd6c
Compare
Pushed a tiny change, since I noticed |
d525349
to
edf85fa
Compare
Updated |
edf85fa
to
1c89ff7
Compare
Rebased on latest master due to conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code seems fine, untested.
1c89ff7
to
228e5d8
Compare
I've rebased against the latest master since I updated WIL to the newest version - makes sense to keep it up to date if it's to become a submodule. However, since looks like this is not getting merged anytime soon and I really want to use WIL in other PR's, maybe I should split the commit adding WIL as submodule as a separate PR so I don't stall waiting for this to be merged? |
228e5d8
to
0fdef8c
Compare
Not sure how others are coming along with testing and their reviews; but if that still takes a while it probably isn't a bad idea to pull it out into its own PR. |
Postponed until #8427 gets merged. |
#8427 has now been merged :) |
0fdef8c
to
654616f
Compare
Rebased on latest master. Thankfully, all I had to do was remove the commit added WIL since it's now merged in separately! |
btw, thanks for adding WIL! |
Do you see any other places where WIL could be used in this PR? For COM pointers I personally prefer WRL because it is included in Windows headers, and so it is used here. EDIT: |
Shame I had not seen this before starting my WASAPI works (nor anyone told me), though it's not very encouraging to see this still pending given over a year has passed and I have a lot more changes. |
@Filoppi , let's leave this PR specifically for WASAPI resource management improvements. |
…rly, not just S_OK
This fixes numerous resource leaks, as not every return path cleaned every created resource Now they are all managed automatically and "commited" to WASAPIStream class fields only after it's certain they initialized properly
…ching WASAPI handler thread
…e sense of safety
This skips a potentially costly loop if volume is 100% or 0%, as for former there is no need for volume adjustment, while latter can be solved by specifying a AUDCLNT_BUFFERFLAGS_SILENT flag
…n to greatly reduce code duplication
Never said to not keep this even if merging is gonna be annoying. I think the only improvement that mine doesn't have is converting to the new ComPtr. I should have fixed all memory leaks and resource management stuff, plus the deadlocks (which weren't exclusive to WASAPI). |
654616f
to
cb854d7
Compare
Merge conflicts resolved. I decided against using
|
Does this PR fix the dreaded audio issues on Wasapi? |
This PR brings numerous improvements to WASAPI code in Dolphin, improving code readability as well as fixing numerous issues.
As a preparation, WIL has been added, since it's very useful for ensuring proper RAII-based destruction for several WinAPI types - in my case it was proper scoped calls to
CoUninitialize
and proper destruction of previously leaking (in some cases)PROPVARIANT
.All COM objects have been moved to use WRL, which ensures their proper release. Previously, there were numerous code paths where functions would return without cleaning up their COM objects, effectively leaking references.
device->GetId(&device_id);
was present in several places, never using the return value nor freeing it - leaking memory for no reason.Thread synchronization model for WASAPI Handler thread has been simplified by not detaching said thread. Not only it improved code readability, but also fixed a spinlock occuring if
WASAPIStream::SetRunning(true)
failed in any way - a following call toWASAPIStream::SetRunning(false)
would then spin endlessly checking form_stopped
. Now this boolean is gone, and so is the problem.std::string_view
is now used where applicable. I opted for constructing astd::string
out ofstd::string_view
inHandleWinAPI
, because it happens in code path which is taken relatively rarely - in a perfect case it's never taken.I modified
SoundLoop
not to do volume adjustment unless absolutely necessary, saving on a relatively costly loop. For 100% volume, volume adjustment is not needed, and for 0% volume aAUDCLNT_BUFFERFLAGS_SILENT
is now specified instead of zeroing the buffer. I also removed several nullptr checks which were not thread safe anyway, so only brought a false sense of safety.