diff options
author | Stefan Hacker <dd0t@users.sourceforge.net> | 2011-08-21 16:33:37 +0400 |
---|---|---|
committer | Stefan Hacker <dd0t@users.sourceforge.net> | 2011-08-21 16:39:59 +0400 |
commit | aed5c1ec8b26711bf33025a2b2bcdff4c08835e4 (patch) | |
tree | c0333885c5717fe9096f11aaf854f2ccc6ea7103 /src/mumble/WASAPI.cpp | |
parent | 72185ae8e8a7b34e890fdf65ebe3445607874974 (diff) |
Split up and refactor WASAPIOutput::setVolumes function to get rid of
excesive indentation.
Diffstat (limited to 'src/mumble/WASAPI.cpp')
-rw-r--r-- | src/mumble/WASAPI.cpp | 98 |
1 files changed, 63 insertions, 35 deletions
diff --git a/src/mumble/WASAPI.cpp b/src/mumble/WASAPI.cpp index 1c26571ce..21ad99725 100644 --- a/src/mumble/WASAPI.cpp +++ b/src/mumble/WASAPI.cpp @@ -650,41 +650,7 @@ void WASAPIOutput::setVolumes(IMMDevice *pDevice, bool talking) { for (int i=0;i<max;++i) { IAudioSessionControl *pControl = NULL; if (SUCCEEDED(hr = pEnumerator->GetSession(i, &pControl))) { - IAudioSessionControl2 *pControl2 = NULL; - if (SUCCEEDED(hr = pControl->QueryInterface(bIsWin7 ? __uuidof(IAudioSessionControl2) : __uuidof(IVistaAudioSessionControl2), (void **) &pControl2))) { - DWORD pid; - if (SUCCEEDED(hr = pControl2->GetProcessId(&pid)) && (pid != dwMumble)) { - AudioSessionState ass; - if (SUCCEEDED(hr = pControl2->GetState(&ass)) && (ass != AudioSessionStateExpired)) { - GUID group; - if (SUCCEEDED(hr = pControl2->GetGroupingParam(&group))) { - QUuid quuid(group); - if (! seen.contains(quuid)) { - seen.insert(quuid); - ISimpleAudioVolume *pVolume = NULL; - if (SUCCEEDED(hr = pControl2->QueryInterface(__uuidof(ISimpleAudioVolume), (void **) &pVolume))) { - BOOL bMute = TRUE; - bool keep = false; - if (SUCCEEDED(hr = pVolume->GetMute(&bMute)) && ! bMute) { - float fVolume = 1.0f; - if (SUCCEEDED(hr = pVolume->GetMasterVolume(&fVolume)) && ! qFuzzyCompare(fVolume,0.0f)) { - float fSetVolume = fVolume * g.s.fOtherVolume; - if (SUCCEEDED(hr = pVolume->SetMasterVolume(fSetVolume, NULL))) { - hr = pVolume->GetMasterVolume(&fSetVolume); - qmVolumes.insert(pVolume, VolumePair(fVolume,fSetVolume)); - keep = true; - } - } - } - if (! keep) - pVolume->Release(); - } - } - } - } - } - pControl2->Release(); - } + setVolumeForSessionControl(pControl, dwMumble, seen); pControl->Release(); } } @@ -697,6 +663,68 @@ void WASAPIOutput::setVolumes(IMMDevice *pDevice, bool talking) { } } +bool WASAPIOutput::setVolumeForSessionControl2(IAudioSessionControl2 *control2, const DWORD mumblePID, QSet<QUuid> &seen) { + HRESULT hr; + DWORD pid; + + // Don't set the volume for our own control + if (FAILED(hr = control2->GetProcessId(&pid)) || (pid == mumblePID)) + return true; + + // Don't work on expired audio sessions + AudioSessionState ass; + if (FAILED(hr = control2->GetState(&ass)) || (ass == AudioSessionStateExpired)) + return false; + + // Don't act twice on the same session + GUID group; + if (FAILED(hr = control2->GetGroupingParam(&group))) + return false; + + QUuid quuid(group); + if (seen.contains(quuid)) + return true; + + seen.insert(quuid); + + // Adjust volume + ISimpleAudioVolume *pVolume = NULL; + if (FAILED(hr = control2->QueryInterface(__uuidof(ISimpleAudioVolume), (void **) &pVolume))) + return false; + + BOOL bMute = TRUE; + bool keep = false; + if (SUCCEEDED(hr = pVolume->GetMute(&bMute)) && ! bMute) { + float fVolume = 1.0f; + if (SUCCEEDED(hr = pVolume->GetMasterVolume(&fVolume)) && ! qFuzzyCompare(fVolume,0.0f)) { + float fSetVolume = fVolume * g.s.fOtherVolume; + if (SUCCEEDED(hr = pVolume->SetMasterVolume(fSetVolume, NULL))) { + hr = pVolume->GetMasterVolume(&fSetVolume); + qmVolumes.insert(pVolume, VolumePair(fVolume,fSetVolume)); + keep = true; + } + } + } + + if (! keep) + pVolume->Release(); + + return true; +} + +bool WASAPIOutput::setVolumeForSessionControl(IAudioSessionControl *control, const DWORD mumblePID, QSet<QUuid> &seen) { + HRESULT hr; + IAudioSessionControl2 *pControl2 = NULL; + + if (!SUCCEEDED(hr = control->QueryInterface(bIsWin7 ? __uuidof(IAudioSessionControl2) : __uuidof(IVistaAudioSessionControl2), (void **) &pControl2))) + return false; + + bool result = setVolumeForSessionControl2(pControl2, mumblePID, seen); + + pControl2->Release(); + return result; +} + void WASAPIOutput::run() { HRESULT hr; IMMDeviceEnumerator *pEnumerator = NULL; |