Repository navigation
Add interop with raw COM interfaces - #71
Merged
Merged
Conversation
AudioClient::from_iaudioclient takes an IAudioClient that the caller has activated itself, for example through ActivateAudioInterfaceAsync with a device path from the WinRT MediaDevice and DeviceInformation classes. The streaming code then works as it does for a client from a Device. IAudioClient is re-exported so that callers do not need a dependency on a matching version of the windows crate. The device tests cover the path end to end, activating from the endpoint id and rendering a short stream. The rate assertion that streams.rs had moves to support.rs so both can use it.
Three escape hatches for reaching what the library does not wrap: * Device::as_immdevice, for activating any endpoint service. IAudioEndpointVolume was unreachable before this, while HardwareSupport::volume reported that the endpoint has it. * AudioClient::as_iaudioclient, for newer interface versions such as IAudioClient3. * Handle::as_handle, for waiting on the stream event alongside other handles with WaitForMultipleObjects. All three are safe. Every method of these interfaces, and every function that takes a raw handle, is already unsafe in the windows crate, so the accessors are not what makes misuse possible. What does need care is documented on each: going behind the cached stream state of an AudioClient, the apartment rules of an IMMDevice, and the borrowed lifetime of the event handle. IMMDevice is re-exported next to IAudioClient. HANDLE is not, since rustdoc names its page after the type, and on Windows that page would overwrite the one for this crate's own Handle. The device tests cover each accessor by reaching something the library has no wrapper for.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The activation test constructs an invalid GUID path, causing the new activation tests to fail.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adds raw COM interop and support for wrapping externally activated IAudioClient instances for WinRT integration.
Changes:
- Adds raw interface and handle accessors.
- Re-exports
IAudioClientandIMMDevice. - Adds activation and interop tests.
- Documents the new capabilities.
| File | Description |
|---|---|
tests/device/support.rs |
Centralizes rate assertions. |
tests/device/streams.rs |
Uses shared rate assertions. |
tests/device/raw.rs |
Tests raw interface and handle access. |
tests/device/main.rs |
Registers new test modules. |
tests/device/activation.rs |
Tests externally activated clients. |
src/lib.rs |
Re-exports COM interfaces. |
src/api.rs |
Adds external client construction and raw accessors. |
README.md |
Documents interop support. |
Cargo.toml |
Enables required Windows test features. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
A new readme section on where WASAPI sits among the Windows audio APIs, why there is no second set of device types for WinRT, and how to enumerate with WinRT and hand the activated interface to from_iaudioclient instead. The raw accessors are named in the supported functionality list, since they are an inventory item rather than anything specific to WinRT.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Makes the crate usable alongside the WASAPI interfaces it does not wrap, for the WinRT case
discussed in #69.
AudioClient::from_iaudioclientwraps anIAudioClientactivated elsewhere, for examplethrough
ActivateAudioInterfaceAsyncwith a device path from WinRT.Device::as_immdevice,AudioClient::as_iaudioclientandHandle::as_handlehand out thewrapped interface or handle.
IAudioEndpointVolumeandIAudioClient3had no way in before.IAudioClientandIMMDeviceare re-exported, so callers need no matchingwindowsdependency.