views:

241

answers:

1

I've been playing around with Vista's CoreAudio stuff, in particular IAudionSessionEvents, with the goal of monitoring the default audio session for changes to volume caused by loaded code.

However, it looks like as soon as you install an IAudioSessionEvents listener SndVol lists the program with all associated volume controls. As a good portion of the time no code has been loaded that will actually play anything, this is less than ideal.

Basically, is there some way to monitor the default audio session without causing SndVol to list it?

A solution for Vista is preferred, but something depending on new apis provided in Windows 7 is better than nothing.


Larry Osterman pointed out the ISessionManager2 and IAudioSessionNotification interfaces added in Windows 7. However, I never receive notice of new session. Is anyone aware of gotchas or problems with this API under Windows 7 build 7000?

Code registering IAudioSessionNotifications, omitting lots of error checking code*:

BOOL success = false;
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
IAudioSessionManager2* pManager = NULL;
IClassFactory* pFactory = NULL;

hr = CoInitialize(NULL);

hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);

hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);

pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&pManager);

listener = NULL;

hr = CoGetClassObject(CLSID_CustomFactory, CLSCTX_ALL, NULL, __uuidof(IClassFactory), (void**)&pFactory);

hr = pFactory->CreateInstance(NULL, __uuidof(IAudioSessionNotification), (void**)&listener);

hr = pManager->RegisterSessionNotification(listener);

*While not the purpose of this question, constructive critic of my COM code is welcome.

+1  A: 

If you want to monitor the audio session stuff, you should use the IAudioSessionManager interface to retrieve your IAudioSessionControl object. A session only shows up in SndVol when it transitions from the inactive to the active state - that happens when when someone calls IAudioClient::Start() - as long as you don't call IAudioClient::Start you shouldn't get a session slider.

In Windows 7, there are a new set of APIs (IAudioSessionManager2) that allow you to listen for session creation and destruction.

Also for Windows 7, there is the AUDCLNT_SESSIONFLAGS_HIDE flag (the documentation for this hasn't been updated yet but it's in the headers)

Larry Osterman
I'm most certainly not calling IAudioClient:Start(), yet the session shows up in SndVol. I looks like installing an event handler via IAudioSessionControl::RegisterAudioSessionNotification(...) activates a session. At least on windows 7 build 7000.
Kevin Montrose
IAudioSessionManager2::RegisterSessionNotification() doesn't seem to work. I get no notice of new sessions from any process, including the installing one. Are there some gotchas you know of for this?Running on Windows 7 build 7000.
Kevin Montrose
I don't know why it wouldn't work - that's the same mechanism that sndvol uses internally - we just made the API public.
Larry Osterman
I'll assume I'm screwing up my use of it then.
Kevin Montrose