| 10 | #include <Mmdeviceapi.h> |
| 11 | |
| 12 | ovrResult AudioEndPointToGuid(char* deviceStrBuffer, int deviceStrSize, GUID* deviceGuid) |
| 13 | { |
| 14 | if (!deviceGuid) |
| 15 | return ovrError_InvalidParameter; |
| 16 | |
| 17 | if (deviceStrSize > OVR_AUDIO_MAX_DEVICE_STR_SIZE) |
| 18 | return ovrError_InsufficientArraySize; |
| 19 | |
| 20 | WCHAR strEndpointId[OVR_AUDIO_MAX_DEVICE_STR_SIZE]; |
| 21 | if (!MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, deviceStrBuffer, deviceStrSize, strEndpointId, OVR_AUDIO_MAX_DEVICE_STR_SIZE)) |
| 22 | return ovrError_MemoryAllocationFailure; |
| 23 | |
| 24 | Microsoft::WRL::ComPtr<IMMDeviceEnumerator> pEnumerator; |
| 25 | const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator); |
| 26 | const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator); |
| 27 | HRESULT hr = CoCreateInstance( |
| 28 | CLSID_MMDeviceEnumerator, nullptr, |
| 29 | CLSCTX_ALL, IID_IMMDeviceEnumerator, |
| 30 | &pEnumerator); |
| 31 | if (FAILED(hr)) |
| 32 | return ovrError_AudioComError; |
| 33 | |
| 34 | Microsoft::WRL::ComPtr<IMMDevice> pDevice; |
| 35 | hr = pEnumerator->GetDevice(strEndpointId, &pDevice); |
| 36 | if (FAILED(hr)) |
| 37 | { |
| 38 | return ovrError_AudioOutputDeviceNotFound; |
| 39 | } |
| 40 | |
| 41 | Microsoft::WRL::ComPtr<IPropertyStore> pPropertyStore; |
| 42 | hr = pDevice->OpenPropertyStore(STGM_READ, &pPropertyStore); |
| 43 | if (FAILED(hr)) |
| 44 | { |
| 45 | return ovrError_AccessDenied; |
| 46 | } |
| 47 | |
| 48 | PROPVARIANT pv; |
| 49 | hr = pPropertyStore->GetValue(PKEY_AudioEndpoint_GUID, &pv); |
| 50 | if (FAILED(hr)) |
| 51 | { |
| 52 | return ovrError_AccessDenied; |
| 53 | } |
| 54 | |
| 55 | hr = IIDFromString(pv.pwszVal, deviceGuid); |
| 56 | if (FAILED(hr)) |
| 57 | return ovrError_RuntimeException; |
| 58 | return ovrSuccess; |
| 59 | } |
| 60 | |
| 61 | ovrResult GetDefaultAudioEndpoint(EDataFlow endpoint, WCHAR deviceStrBuffer[OVR_AUDIO_MAX_DEVICE_STR_SIZE]) |
| 62 | { |
no outgoing calls
no test coverage detected