Changeset 91597 in vbox for trunk/src/VBox/ValidationKit/utils
- Timestamp:
- Oct 6, 2021 4:23:40 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 147315
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp
r91577 r91597 38 38 # include <alsa/version.h> 39 39 # include "DrvHostAudioAlsaStubs.h" 40 #endif 41 #ifdef RT_OS_WINDOWS 42 # include <iprt/win/windows.h> 43 # include <iprt/win/audioclient.h> 44 # include <endpointvolume.h> /* For IAudioEndpointVolume. */ 45 # include <audiopolicy.h> /* For IAudioSessionManager. */ 46 # include <AudioSessionTypes.h> 47 # include <Mmdeviceapi.h> 40 48 #endif 41 49 … … 136 144 # undef ALSA_CHECK_ERR_RET 137 145 138 #else /* !VBOX_WITH_AUDIO_ALSA */ 139 140 #if 0 141 CoInitialize(NULL); 142 CLSID CLSID_const MMDeviceEnumerator =_uuidof(MMDeviceEnumerator); 143 IID IID_const IMMDeviceEnumerator = uuidof(IMMDeviceEnumerator); 144 IMMDeviceEnumerator* pEnumerator; 145 HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator); 146 IMMDevice *pDevice; 147 hr = pEnumerator->GetDefaultAudioEndpoint(EDataFlow::eRender, ERole::eConsole, &pDevice); 148 IAudioSessionManager *pManager; 149 IID IID_const IMMAudioSessionManager = uuidof(IAudioSessionManager); 150 hr = pDevice->Activate(IID_IMMAudioSessionManager, CLSCTX_ALL, NULL, (void**)&pManager); 151 ISimpleAudioVolume *pSimpleAudioVolume; 152 hr = pManager->GetSimpleAudioVolume(NULL, true, &pSimpleAudioVolume); 153 pSimpleAudioVolume->SetMasterVolume(1.0); 146 #elif defined(RT_OS_WINDOWS) 147 148 HRESULT hr; 149 150 # define WASAPI_CHECK_HR_RET(a_Text) \ 151 if (FAILED(hr)) \ 152 { \ 153 AssertLogRelMsgFailed(a_Text); \ 154 return VERR_GENERAL_FAILURE; \ 155 } 156 157 hr = CoInitialize(NULL); 158 IMMDeviceEnumerator* pIEnumerator = NULL; 159 hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void **)&pIEnumerator); 160 WASAPI_CHECK_HR_RET(("WASAPI: Unable to create IMMDeviceEnumerator, hr=%Rhrc", hr)); 161 162 IMMDevice *pIMMDevice = NULL; 163 hr = pIEnumerator->GetDefaultAudioEndpoint(EDataFlow::eRender, ERole::eConsole, &pIMMDevice); 164 WASAPI_CHECK_HR_RET(("WASAPI: Unable to get audio endpoint, hr=%Rhrc", hr)); 165 pIEnumerator->Release(); 166 167 IAudioEndpointVolume *pIAudioEndpointVolume = NULL; 168 hr = pIMMDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_ALL, NULL, (void **)&pIAudioEndpointVolume); 169 WASAPI_CHECK_HR_RET(("WASAPI: Unable to activate audio endpoint volume, hr=%Rhrc", hr)); 170 pIMMDevice->Release(); 171 172 float dbMin, dbMax, dbInc; 173 hr = pIAudioEndpointVolume->GetVolumeRange(&dbMin, &dbMax, &dbInc); 174 WASAPI_CHECK_HR_RET(("WASAPI: Unable to get volume range, hr=%Rhrc", hr)); 175 176 float const dbSteps = (dbMax - dbMin) / dbInc; 177 float const dbStepsPerPercent = (dbSteps * dbInc) / 100; 178 float const dbVol = dbMin + (dbStepsPerPercent * (float(RT_MIN(uVolPercent, 100.0)))); 179 180 hr = pIAudioEndpointVolume->SetMasterVolumeLevel(dbVol, NULL); 181 WASAPI_CHECK_HR_RET(("WASAPI: Unable to set master volume level, hr=%Rhrc", hr)); 182 pIAudioEndpointVolume->Release(); 183 184 return VINF_SUCCESS; 185 186 # undef WASAPI_CHECK_HR_RET 187 188 #else 189 190 RT_NOREF(uVolPercent); 191 /** @todo Port other platforms. */ 192 return VERR_NOT_SUPPORTED; 154 193 #endif 155 156 RT_NOREF(uVolPercent);157 #endif /* VBOX_WITH_AUDIO_ALSA */158 159 /** @todo Port other platforms. */160 return VERR_NOT_SUPPORTED;161 194 } 162 195
Note:
See TracChangeset
for help on using the changeset viewer.