Skip to content

Add session and device peak metering, and device change notifications - #61

Merged
HEnquist merged 5 commits into
masterfrom
session-meter-and-device-notifications
Aug 12, 2026
Merged

Add session and device peak metering, and device change notifications#61
HEnquist merged 5 commits into
masterfrom
session-meter-and-device-notifications

Conversation

@HEnquist

Copy link
Copy Markdown
Owner

Adds peak metering for sessions and devices, and notifications for device changes. Closes #31 and #34.

  • AudioMeterInformation with peak value, per-channel peaks and channel count, reachable from an AudioSessionControl or a Device
  • HardwareSupport for querying which functions a device implements in hardware
  • Display name, icon path and session identifiers on AudioSessionControl
  • DeviceEnumerator::register_notification_callback with DeviceEventCallbacks for devices added, removed, state changed, property changed and default changed, unregistered on drop
  • New device_notifications example, and device peaks added to processes

Add AudioMeterInformation wrapping IAudioMeterInformation, reachable
from an AudioSessionControl. Also add the display name, icon path and
session identifier getters, and extend the processes example to list
render devices and session peak levels.
Get an AudioMeterInformation for a whole endpoint device, and query
which functions the device implements in hardware.
Implement IMMNotificationClient and register it on the DeviceEnumerator,
with callbacks for devices being added, removed and changed state, for
device property changes, and for changes of the default device. The
notifications are unregistered when the returned registration is dropped.

Add a TryFrom<DEVICE_STATE> for DeviceState and use it in Device::get_state.

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.

Pull request overview

Adds new Core Audio wrappers and examples to support peak metering (sessions + devices) and endpoint device change notifications, expanding the crate’s observability and routing-awareness capabilities (per issues #31 and #34).

Changes:

  • Add AudioMeterInformation/HardwareSupport APIs and expose session identifiers/display metadata on AudioSessionControl.
  • Add DeviceEnumerator::register_notification_callback with DeviceEventCallbacks, with automatic unregister on drop.
  • Update docs and examples (processes enhanced with peak metering; new device_notifications example).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/events.rs Adds IMMNotificationClient wrapper (NotificationClient), device event callback plumbing, and tests.
src/api.rs Adds device/session peak metering APIs, device notification registration RAII type, and PWSTR-to-String helper.
README.md Documents new device notification capability and updates example descriptions.
examples/processes.rs Extends example to show render/capture devices and per-session/device peak levels.
examples/device_notifications.rs New example demonstrating device change notifications and default-device changes.
Cargo.toml Enables Windows bindings feature needed for IAudioMeterInformation (Endpoints).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/api.rs
Comment thread src/events.rs Outdated
A null device id means that there is no default device, while a string
that cannot be read is an error. Keep the two apart so that an unreadable
id is skipped instead of being reported as no device.

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/api.rs:438

  • This maps device notification registration failures to WasapiError::RegisterNotifications, whose error message currently says "Couldn't register session notifications". That makes device callback failures report a misleading message. Consider introducing a dedicated error variant for device notifications, or making RegisterNotifications’s message generic (e.g. "Couldn't register notifications") and reusing it for both session/device paths.
            Err(err) => Err(WasapiError::RegisterNotifications(err)),

RegisterNotifications is now returned for both session and device
notifications, so drop session from the message.
@HEnquist
HEnquist merged commit 63ad5a2 into master Aug 12, 2026
2 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.

Session enumeration/meter support

2 participants