Skip to content

Add audio session GUID and session display name and icon setters - #77

Merged
HEnquist merged 1 commit into
HEnquist:masterfrom
exi:session-guid-display-name
Oct 24, 2026
Merged

HEnquist merged 1 commit into
HEnquist:masterfrom
exi:session-guid-display-name

Conversation

@exi

@exi exi commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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 passes session_guid as the AudioSessionGuid argument of
    IAudioClient::Initialize (which initialize_client leaves null). initialize_client now delegates to the
    same private function with None, so its behaviour is unchanged.
  • AudioSessionControl::set_display_name(&str) and AudioSessionControl::set_icon_path(&str): wrap
    IAudioSessionControl::SetDisplayName / SetIconPath, next to the existing get_display_name / get_icon_path.
    The event context is null.
  • New example named_sessions: two sine streams from one process, each in its own session with its own name, so the
    volume mixer shows two named entries that can be adjusted separately.
  • Device tests in tests/device/streams.rs: two clients with the same GUID share a session (a name set via one is
    read back via the other, while a client in a different GUID sees an empty name), and the icon path round trips.
  • README: feature list line and example table row.

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::Initialize and
IAudioSessionControl::SetDisplayName calls via as_iaudioclient, which means reimplementing the stream flag and
cached 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 doc with RUSTDOCFLAGS=-D warnings: clean (cross-built for x86_64-pc-windows-gnu).
  • cargo test --workspace --all-targets under Wine: pass.
  • Under Wine with a PulseAudio null sink: the new API's behaviour (shared GUID shares the name, other GUID does not,
    icon path round trips, session instance ids carry the GUID), and the named_sessions example ran its 20 s cleanly.
  • Manually on real Windows: the named_sessions example (release build) plays both streams, and the volume mixer
    shows them as two separate entries, named "wasapi-rs high tone" and "wasapi-rs low tone" as set via set_display_name, whose volumes
    can be adjusted independently. The same holds for a downstream
    application that opens two streams through initialize_client_in_session + set_display_name (no unsafe on its
    side).
  • Not run: the device suite on a real Windows machine with VB-Cable (cargo test --features device-tests --test device -- --test-threads=1).

🤖 Generated with Claude Code

@HEnquist

Copy link
Copy Markdown
Owner

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 session_guid: Option<GUID> directly to initialize_client and remove initialize_client_in_session. None keeps the default session. It's a breaking change, but it's easily fixed since existing callers only need to add a None. That also lets you drop the private initialize helper.

I will go through the rest as soon as I have some time.

@exi

exi commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

Done in the new commit: initialize_client now takes session_guid: Option<GUID> as its last parameter (None = the default session, documented in the method docs with an example), and initialize_client_in_session plus the private helper are gone. All examples, doc examples and the device tests were updated (None everywhere, Some(guid) in named_sessions and the session tests).

Checked: fmt, clippy -D warnings (all targets, all features), cargo doc with -D warnings, and cargo test (cross-built for x86_64-pc-windows-gnu, run under Wine);
named_sessions also ran against a PulseAudio sink under Wine.

Ran it under windows and still works.

Happy to squash the two commits if you prefer.

@HEnquist

Copy link
Copy Markdown
Owner

Thanks, that looks good. One small thing: the new doc example on initialize_client still passes an extra None (five arguments), so cargo test --doc fails to compile it. Cross-compiled test runs skip doctests, which is probably why it didn't show up. And yes please, squash it all into one commit along with that fix, then I'm happy to merge.

@HEnquist

Copy link
Copy Markdown
Owner

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]>
@HEnquist
HEnquist force-pushed the session-guid-display-name branch from 60db9a5 to 880652b Compare October 24, 2026 20:48
@HEnquist
HEnquist merged commit 9941c69 into HEnquist:master Oct 24, 2026
3 checks passed
@HEnquist HEnquist mentioned this pull request Oct 24, 2026
@LastExceed

LastExceed commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Edit: See #81 (comment)

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.

3 participants