Add session and device peak metering, and device change notifications - #61
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
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/HardwareSupportAPIs and expose session identifiers/display metadata onAudioSessionControl. - Add
DeviceEnumerator::register_notification_callbackwithDeviceEventCallbacks, with automatic unregister on drop. - Update docs and examples (
processesenhanced with peak metering; newdevice_notificationsexample).
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.
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.
There was a problem hiding this comment.
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 makingRegisterNotifications’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.
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.
Adds peak metering for sessions and devices, and notifications for device changes. Closes #31 and #34.
AudioMeterInformationwith peak value, per-channel peaks and channel count, reachable from anAudioSessionControlor aDeviceHardwareSupportfor querying which functions a device implements in hardwareAudioSessionControlDeviceEnumerator::register_notification_callbackwithDeviceEventCallbacksfor devices added, removed, state changed, property changed and default changed, unregistered on dropdevice_notificationsexample, and device peaks added toprocesses