Search code examples
c++winapicomcore-audiowasapi

How to test for equality of audio sessions


I am trying to use the Windows Audio Session API to locate the default audio session within the enumeration of current audio sessions. Currently I have a reference to the IAudioSessionControl of the default session of the audio render endpoint in the eConsole role as well as an IAudioSessionEnumerator object that enumerates the audio sessions of this default endpoint, but I need to be able to compare the IAudioSessionControl object that I have for equality with the IAudioSessionControl objects returned by IAudioSessionEnumerator::GetSession.

I was hoping that I could test for equality by comparing the IAudioSessionControl pointers for equality. This works when I obtain the IAudioSessionControl for the default session multiple times using IAudioClient::GetService. Unfortunately, this pointer returned by IAudioClient::GetService does not appear in the enumeration of audio sessions by the IAudioSessionEnumerator. Also, obtaining the default audio session multiple times via the IAudioSessionManager::GetAudioSessionControl route does not yield identical IAudioSessionControl pointers even when using the same audio session GUID (GUID_NULL) and CrossProcessSession value.

How do I test for equality of audio sessions given two IAudioSessionControl pointers? Is it possible to obtain the audio session GUID and process identifier of a given IAudioSessionControl object?


Solution

  • Look at the IAudioSessionControl2::GetSessionIdentifier API, that's what the audio subsystem uses to persist session volumes. If you want to distinguish sessions at runtime (two instances of the same app running at the same time), check the GetSessionInstanceIdentifier API.