Skip to content

Add interop with raw COM interfaces - #71

Merged
HEnquist merged 4 commits into
masterfrom
audioclient-from-raw
Oct 11, 2026
Merged

HEnquist merged 4 commits into
masterfrom
audioclient-from-raw

Conversation

@HEnquist

@HEnquist HEnquist commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Makes the crate usable alongside the WASAPI interfaces it does not wrap, for the WinRT case
discussed in #69.

  • AudioClient::from_iaudioclient wraps an IAudioClient activated elsewhere, for example
    through ActivateAudioInterfaceAsync with a device path from WinRT.
  • Device::as_immdevice, AudioClient::as_iaudioclient and Handle::as_handle hand out the
    wrapped interface or handle. IAudioEndpointVolume and IAudioClient3 had no way in before.
  • IAudioClient and IMMDevice are re-exported, so callers need no matching windows dependency.
  • Device tests for each, every one reaching something the crate has no wrapper for.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity

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 IAudioClient and IMMDevice.
  • 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.

Comment thread tests/device/activation.rs Resolved
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.
@HEnquist
HEnquist merged commit 8a2ae77 into master Oct 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants