Session enumeration/meter support
Hi Henrik,
I'd like to be able to list out all processes currently outputting audio. It looks like the best way to do this is to access the IAudioSessionManager2 and IAudioSessionEnumerator for each device. I'd also like to check session activity so IAudioSessionControl2 and IAudioMeterInformation would be of interest as well. Taking pseduo code from Matthew van Eerde:
CoCreate(IMMDeviceEnumerator);
IMMDeviceEnumerator::GetDefaultAudioEndpoint;
IMMDevice::Activate(IAudioSessionManager2);
IAudioSessionManager2::GetSessionEnumerator;
for (each session) {
IAudioSessionEnumerator::GetSession
IAudioSessionControl::GetState
#if the state is anything but "active", skip to the next session
QI IAudioSessionControl to IAudioSessionControl2
IAudioSessionControl2::GetSessionIdentifier
QI IAudioSessionControl to IAudioMeterInformation
IAudioMeterInformation::GetPeakValue
#Log the session identifier and the peak value
}
I think keeping related interfaces (e.g. IAudioSessionManager and IAudioSessionManager2) separate helps from the point of view of sticking to the existing API, and cleaner handling cases where only one can instantiated (don't quite understand when/if that can happen). If that can be reliably combined though it would be quite nice. Do you know why so many of them are separated?
I'm happy to try implementing this in a few stages, but I wanted to check in first.
I don't know why the windows api is divided into so many little bits, but I would guess it's to keep backward compatibility since the apis have been expanded many times over the years.
I would be happy to accept a PR for this. I prefer to stay close to the windows apis and keep the separate things separate, this keeps things simple and it's easy to refer to the Microsoft docs for each separate IAudioSessionControlX etc.