Repository navigation
Add auto-routed default device clients - #90
Conversation
AudioClient::new_default_device_client activates the default render or capture device through ActivateAudioInterfaceAsync with the DEVINTERFACE_AUDIO_* class as device path, so the stream follows the default device when it changes. Exclusive mode does not work on these clients. The format queries accept an exclusive format, but Initialize fails with E_INVALIDARG. This is documented and the error is passed through as it is. The activation and wait for the completion handler is moved into a helper shared with the application loopback client. Device::get_iaudioclient and DeviceEnumerator::get_default_device now say that a stream opened on the default device stays on that endpoint. Adds device tests for streaming and for the exclusive mode failure, and a playsine_autorouted example. Closes #89
| /// Get the default playback or capture device for the console role. | ||
| /// | ||
| /// This is the endpoint that is the default when it is called, | ||
| /// and a stream opened on it stays there when the default changes. | ||
| /// For a stream that follows the default device, | ||
| /// see [AudioClient::new_default_device_client]. | ||
| pub fn get_default_device(&self, direction: Direction) -> WasapiRes<Device> { | ||
| self.get_default_device_for_role(direction, Role::Console) | ||
| } |
There was a problem hiding this comment.
Consider using the wording "current default" for clarity (both in the docs and in the function name)
There was a problem hiding this comment.
Good suggestion, I updated the docstrings to make things more clear. I prefer to keep the method name though. A rename is a breaking change (and I think get_default_device_for_role is long enough as it is).
| /// ```no_run | ||
| /// use wasapi::{AudioClient, Direction, StreamMode, initialize_mta}; | ||
| /// | ||
| /// initialize_mta().ok().unwrap(); // Don't do this on a UI thread |
There was a problem hiding this comment.
This is redundant, ActivateAudioInterfaceAsync handles COM initialization internally
There was a problem hiding this comment.
I tried the example without the COM init call, and it fails with CO_E_NOTINITIALIZED. I checked the docs for ActivateAudioInterfaceAsync and I can't find anything about automatic COM initialization. Are you maybe mixing it up with the WinRT methods, or did you find something else in the docs?
There was a problem hiding this comment.
huh, could have sworn i had it working without explicit COM init once. I must be mixing things up then
There was a problem hiding this comment.
Could it be that you had a call to some WinRT method earlier in that code? IIUC that would have taken care of COM init, almost regardless of what method was called.
There was a problem hiding this comment.
possible. at the of the day there is no harm in calling CoInitialize multiple times, it just increments the ref count, so just disregard my comment
Adds
AudioClient::new_default_device_client, a client on the default render or capture device that follows the default when it changes (automatic stream routing). Closes #89.ActivateAudioInterfaceAsyncwith theDEVINTERFACE_AUDIO_*class as device path.initialize_clientfails withE_INVALIDARG. Documented, and the error is passed through.new_application_loopback_client.Device::get_iaudioclientandDeviceEnumerator::get_default_devicenow point out that a stream on the default device stays on that endpoint.playsine_autoroutedexample.