Repository navigation
Add audio session GUID and session display name and icon setters - #77
Conversation
|
Thanks for this! Before I review the rest, I have one request about the API shape. I think adding an extra argument to the existing init method that can simply be left at None is a quite mild change, and it is better than ending up with multiple very similar init methods. So please add I will go through the rest as soon as I have some time. |
|
Thanks for the review! Done in the new commit: Checked: fmt, clippy Ran it under windows and still works. Happy to squash the two commits if you prefer. |
|
Thanks, that looks good. One small thing: the new doc example on |
|
Actually, scratch that. It's a tiny fix, so I'll do it myself: squash everything into one commit (keeping you as the author) and push it to your branch. No need to do anything on your side. |
initialize_client takes a new last parameter, session_guid: Option<GUID>, which is passed to IAudioClient::Initialize as the AudioSessionGuid. None keeps the default session, so existing callers only need to add None. Separate GUIDs put streams of one process in separate sessions, with separate volume mixer entries. AudioSessionControl::set_display_name and set_icon_path wrap IAudioSessionControl::SetDisplayName and SetIconPath, matching the existing getters. Adds the named_sessions example and device tests for the round trips. Co-Authored-By: Claude Opus 5.5 <[email protected]>
60db9a5 to
880652b
Compare
|
Edit: See #81 (comment) |
Add audio session GUID and session display name/icon setters
What
AudioClient::initialize_client_in_session(wavefmt, direction, stream_mode, session_guid: &GUID):same as
initialize_client, but passessession_guidas theAudioSessionGuidargument ofIAudioClient::Initialize(whichinitialize_clientleaves null).initialize_clientnow delegates to thesame private function with
None, so its behaviour is unchanged.AudioSessionControl::set_display_name(&str)andAudioSessionControl::set_icon_path(&str): wrapIAudioSessionControl::SetDisplayName/SetIconPath, next to the existingget_display_name/get_icon_path.The event context is null.
named_sessions: two sine streams from one process, each in its own session with its own name, so thevolume mixer shows two named entries that can be adjusted separately.
tests/device/streams.rs: two clients with the same GUID share a session (a name set via one isread back via the other, while a client in a different GUID sees an empty name), and the icon path round trips.
Why
An application that plays several independent streams (e.g. per-source audio) wants one volume mixer entry per
stream, each with a meaningful name. Today that needs raw
IAudioClient::InitializeandIAudioSessionControl::SetDisplayNamecalls viaas_iaudioclient, which means reimplementing the stream flag andcached state logic of
initialize_client.Compatibility
Additive only: no existing signature changes. MSRV unaffected.
Testing
cargo fmt --check,cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo docwithRUSTDOCFLAGS=-D warnings: clean (cross-built forx86_64-pc-windows-gnu).cargo test --workspace --all-targetsunder Wine: pass.icon path round trips, session instance ids carry the GUID), and the
named_sessionsexample ran its 20 s cleanly.named_sessionsexample (release build) plays both streams, and the volume mixershows them as two separate entries, named "wasapi-rs high tone" and "wasapi-rs low tone" as set via
set_display_name, whose volumescan be adjusted independently. The same holds for a downstream
application that opens two streams through
initialize_client_in_session+set_display_name(nounsafeon itsside).
cargo test --features device-tests --test device -- --test-threads=1).🤖 Generated with Claude Code