| 175 | } |
| 176 | |
| 177 | OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceInWaveId(UINT* deviceInId) |
| 178 | { |
| 179 | REV_TRACE(ovr_GetAudioDeviceInWaveId); |
| 180 | |
| 181 | if (!deviceInId) |
| 182 | return ovrError_InvalidParameter; |
| 183 | |
| 184 | // Query and cache the result |
| 185 | static UINT cachedId = 0; |
| 186 | if (!cachedId) |
| 187 | { |
| 188 | MMRESULT mmr; |
| 189 | char endpoint[OVR_AUDIO_MAX_DEVICE_STR_SIZE] = {}; |
| 190 | vr::ETrackedPropertyError error = vr::TrackedProp_Success; |
| 191 | uint32_t size = vr::VRSystem()->GetStringTrackedDeviceProperty( |
| 192 | vr::k_unTrackedDeviceIndex_Hmd, |
| 193 | vr::Prop_Audio_DefaultRecordingDeviceId_String, |
| 194 | endpoint, OVR_AUDIO_MAX_DEVICE_STR_SIZE, &error); |
| 195 | if (error != vr::TrackedProp_Success) |
| 196 | { |
| 197 | // Return the default without caching so we can attempt again later |
| 198 | mmr = waveInMessage((HWAVEIN)UIntToPtr(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)deviceInId, NULL); |
| 199 | return mmr == MMSYSERR_NOERROR ? ovrSuccess : ovrError_AudioDeviceNotFound; |
| 200 | } |
| 201 | |
| 202 | WCHAR strEndpointIdKey[OVR_AUDIO_MAX_DEVICE_STR_SIZE] = {}; |
| 203 | if (size > OVR_AUDIO_MAX_DEVICE_STR_SIZE) |
| 204 | return ovrError_InsufficientArraySize; |
| 205 | if (!MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, endpoint, size, strEndpointIdKey, OVR_AUDIO_MAX_DEVICE_STR_SIZE)) |
| 206 | return ovrError_MemoryAllocationFailure; |
| 207 | |
| 208 | // Get the size of the endpoint ID string. |
| 209 | size_t cbEndpointIdKey = size * sizeof(WCHAR); |
| 210 | |
| 211 | // Each for-loop iteration below compares the endpoint ID |
| 212 | // string of the audio endpoint device to the endpoint ID |
| 213 | // string of an enumerated waveOut device. If the strings |
| 214 | // match, then we've found the waveIn device that is |
| 215 | // assigned to the specified device role. |
| 216 | UINT waveInId; |
| 217 | UINT cWaveInDevices = waveInGetNumDevs(); |
| 218 | WCHAR strEndpointId[OVR_AUDIO_MAX_DEVICE_STR_SIZE] = {}; |
| 219 | for (waveInId = 0; waveInId < cWaveInDevices; waveInId++) |
| 220 | { |
| 221 | size_t cbEndpointId = 0; |
| 222 | |
| 223 | // Get the size (including the terminating null) of |
| 224 | // the endpoint ID string of the waveOut device. |
| 225 | mmr = waveInMessage((HWAVEIN)UIntToPtr(waveInId), |
| 226 | DRV_QUERYFUNCTIONINSTANCEIDSIZE, |
| 227 | (DWORD_PTR)&cbEndpointId, NULL); |
| 228 | if (mmr != MMSYSERR_NOERROR || |
| 229 | cbEndpointIdKey != cbEndpointId) // do sizes match? |
| 230 | { |
| 231 | continue; // not a matching device |
| 232 | } |
| 233 | |
| 234 | // Get the endpoint ID string for this waveOut device. |
nothing calls this directly
no outgoing calls
no test coverage detected