-
Notifications
You must be signed in to change notification settings - Fork 128
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
[RFC] Implement CUBEB_STREAM_PREF_EXCLUSIVE #415
base: master
Are you sure you want to change the base?
Conversation
This line also causes an access violation for some reason (when uncommented): https://github.com/kinetiknz/cubeb/pull/415/files#diff-2f55f506bd2dd918b7b8c6ceec8aee0dR1671 |
Thanks for the PR. I think we'd add support for this as long as the changes are non-invasive and a new test is added to ensure the functionality isn't accidentally broken -- we won't use this inside Firefox, so without tests it'll end up broken fairly quickly. I do wonder whether the user cases are better addressed via IAudioClient3 as discussed in issue #324 (although that's Windows 10 only). To clarify, is the reason you want this feature for lower latency? For the PR:
|
dcbfb62
to
6cc175e
Compare
@kinetiknz Thanks for your quick response! Changes I made:
I took a look at quick look at Not sure if That's all I know at the moment :/ |
Regarding the tests: I'd suggest just adding them to EDIT: Sorry for the massive diff in |
It's only used on the capture side, not playback.
Sounds good. |
2dc3a03
to
f04624e
Compare
Fixed |
The indenting is a bit weird in the latest version. I noticed the LOG change, what are you getting in mix_params->layout? Also still curious re paragraph 2 of: https://github.com/kinetiknz/cubeb/pull/415#issuecomment-364810077 |
|
Sorry, I meant the question about why you want this functionality vs IAudioClient3's lower latency shared mode. I had a quick look and have a few pointers for where to look next to get this working. There's some sample code with explananations at https://blogs.msdn.microsoft.com/matthew_van_eerde/2009/04/03/sample-wasapi-exclusive-mode-event-driven-playback-app-including-the-hd-audio-alignment-dance/ that might be useful. Testing with test_sanity (simplest test; plays a tone - updated to pass the exclusive pref flag), IAudioClient::Initialize fails with AUDCLNT_E_BUFFER_SIZE_ERROR. Since we're passing 0 for the hnsPeriodicity (MSDN says this must be non-zero for exclusive + event streams), that's probably the first thing to fix. From the linked blog post above, the other thing we'll likely need to handle is the "alignment dance" to calculate buffer sizing compatible with the harder. |
Sorry, for some reason I interpreted paragraph two meaning point two (entirely my fault).
We should probably handle this, yes. Although I'll have to find a test case that requires that. Thanks for your patience. |
@kinetiknz Fixed |
We're having a look at |
When it's available, it's probably superior. If only for the fact that it runs in shared mode |
Would you mind running it under a debugger and providing more details? With your latest changes and test_sanity passing the exclusive flag, IAudioClient::Initialize now returns AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED, which will need to be addressed by the "alignment dance" stuff I mentioned earlier. |
Turns out they crash at different sections now. test_audioCaused by:
Error Message:
Library Function
test_sanityCaused by:
Error Message:
Library Function:
Hope this helps! |
Right, so you're getting past the AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED issue somehow. Did you alter the stream params in the test or are we testing different versions of the code? Anyway, if I hardcode suitable buffer sizing to avoid AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED, I hit the same crash in stream_start_one_side. That was tricky to track down... it turns out IAudioClient's initialized with AUDCLNT_SHAREMODE_EXCLUSIVE care if COM is still initialized (they hold a reference to some global/thread-specific COM data and use it during IAudioClient::Start). The cubeb tests never initialize COM, so we were relying on the auto_com initialization inside cubeb_wasapi.cpp. Since COM wasn't initialized at a higher level (meaning auto_com would just shuffle a ref count), auto_com completely destroys the COM global data each time... since the IAudioClient is holding a reference to this (and uses it in AUDCLNT_SHAREMODE_EXCLUSIVE mode), it becomes invalid and crashes. I note that wasapi_stream_start/stop are missing auto_com, but adding them doesn't help because the IAudioClient still holds the reference to the old, destroyed COM global data. So I think the correct fix for this is to initialize COM in the cubeb tests, and to document that COM must be initialized before calling cubeb APIs. That may also mean the auto_com stuff becomes completely obsolete. |
Next issue to address: after adding a variant of auto_com to test/common.h and using it inside test_tone, the stream starts and stops as expected, but the data_callback is never called, so no tone is produced and the test's assert fails. Looks like this is caused by cubeb's calls to IAudioRenderClient::GetBuffer not yet handling exclusive-mode streams. |
No, I didn't. Anyway I implemented the alignment dance now, not sure if it works properly though.
Thanks for figuring this one out! I added a
Sorry but I can't reproduce this for some reason :/ Also added my version of |
Possibly for the same reason you didn't hit the buffer alignment issues... your hardware/configuration might happen to be compatible with the configuration requested (or more flexible in accepting configurations). So we'll need to test this with various configurations and shake out the remaining issues. |
@kinetiknz Yeah, my audio setup is kinda weird (USB microphone with a builtin "sound card" and a headset out) :/ |
So any pointers regarding what I can still do to move this along? |
Either (or both) extensive testing to shake out what else needs adjusting or reviewing all of the IAudioClient/IAudioRenderClient/IAudioCaptureClient APIs to see what restrictions they have for exclusive mode. As mentioned in an earlier comment, GetBuffer fails with some configurations as the code is now. |
Rebased. Also did some further testing with the devices available to me. So I'm kinda unsure what to do next. |
I need to find some time to debug the next issue, I guess. In the mean time:
|
What's the state of this PR? |
It's never been finished and it doesn't apply anymore, there's been a lot of changes since then to the WASAPI backend. I wonder how useful are exclusive streams these days. |
Well, exclusive WASAPI in Cubeb reduces latency by a lot, so that's why it's very useful. |
A bad attempt at supporting Exclusive mode.
Issues:
Some of the changes are probably not necessary (e.g. the
CLSCTX_ALL
stuff).If someone had some ideas regarding what I'm doing wrong, help would be greatly appreciated!