Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!

I'm writing a program to monitor the sound volume of windows 7 applications, C++.

What's working:
I enumerate all existing audio sessions with GetSessionEnumerator and GetSession.
For each session, I register session control notifications to know what happens to each session (using RegisterAudioSessionNotification with IAudioSessionEvents).
Notifications work correctly (if I change the volume of an app, I get the volumechanged notification in my program for its associated session).

My problem:
When I quit an application making sound, I expect the OnSessionDisconnected event to trigger. That's not the case, so I have no way to know when to remove audio sessions from my list! Please note that the session is still "valid" somehow (I can mute it programmatically, or change its volume without runtime errors).

However, if I re-enumerate all audio sessions like in the first step, this session does not appear in the list...
Sndvol knows when a session temrinates, as it removes it from its mix control list. How can I achieve the same?

Does anyone have an idea? Thank you very much!
Posted
Updated 4-Jun-16 21:59pm

My idea is: "Read the fine documentation".

Microsoft writes: "When notifications are no longer needed, the client can call the IAudioSessionControl::UnregisterAudioSessionNotification method to terminate the notifications."

So you need to do it, or the resource is staying in use. (it is common practice that the release the accessed resources)
 
Share this answer
 
Comments
Alban Deruaz 14-Nov-14 14:36pm    
Thanks for your answer.
The thing is I don't know when the session is finished, and I therefore need the notifications to tell me when it's the case. If I unregister them then I won't have any information on that.
I know this is a couple years late, but I just ran into this frustrating problem as well. I combed through a lot of documentation and eventually found this:

"...there is no expiration mechanism enforced by the audio system on the session control objects. A session control is valid as long as the application has a reference to the session control..." (link).

If the audio system doesn't control session lifetime, then the OnSessionDisconnected event must not be the right approach to detecting the end of a session's life.

This implies that you need to look outside of the audio system for information about whether an audio session is still needed. In my program I release audio sessions when the process they are associated with exits, which seems to work well. You can get the relevant process ID from the IAudioSessionControl2 interface. I'm using a C# wrapper around the core audio APIs, so I detect process expiration by subscribing to the Process.Exited event (link).

I hope this helps!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900