MCPcopy Create free account
hub / github.com/LibreVR/Revive / ovr_GetAudioDeviceOutWaveId

Function ovr_GetAudioDeviceOutWaveId

Revive/REV_CAPI_Audio.cpp:89–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89OVR_PUBLIC_FUNCTION(ovrResult) ovr_GetAudioDeviceOutWaveId(UINT* deviceOutId)
90{
91 REV_TRACE(ovr_GetAudioDeviceOutWaveId);
92
93 if (!deviceOutId)
94 return ovrError_InvalidParameter;
95
96 // Query and cache the result
97 static UINT cachedId = 0;
98 if (!cachedId)
99 {
100 MMRESULT mmr;
101 char endpoint[OVR_AUDIO_MAX_DEVICE_STR_SIZE] = {};
102 vr::ETrackedPropertyError error = vr::TrackedProp_Success;
103 uint32_t size = vr::VRSystem()->GetStringTrackedDeviceProperty(
104 vr::k_unTrackedDeviceIndex_Hmd,
105 vr::Prop_Audio_DefaultPlaybackDeviceId_String,
106 endpoint, OVR_AUDIO_MAX_DEVICE_STR_SIZE, &error);
107 if (error != vr::TrackedProp_Success)
108 {
109 // Return the default without caching so we can attempt again later
110 mmr = waveOutMessage((HWAVEOUT)UIntToPtr(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)deviceOutId, NULL);
111 return mmr == MMSYSERR_NOERROR ? ovrSuccess : ovrError_AudioDeviceNotFound;
112 }
113
114 WCHAR strEndpointIdKey[OVR_AUDIO_MAX_DEVICE_STR_SIZE] = {};
115 if (size > OVR_AUDIO_MAX_DEVICE_STR_SIZE)
116 return ovrError_InsufficientArraySize;
117 if (!MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED, endpoint, size, strEndpointIdKey, OVR_AUDIO_MAX_DEVICE_STR_SIZE))
118 return ovrError_MemoryAllocationFailure;
119
120 // Get the size of the endpoint ID string.
121 size_t cbEndpointIdKey = size * sizeof(WCHAR);
122
123 // Each for-loop iteration below compares the endpoint ID
124 // string of the audio endpoint device to the endpoint ID
125 // string of an enumerated waveOut device. If the strings
126 // match, then we've found the waveOut device that is
127 // assigned to the specified device role.
128 UINT waveOutId;
129 UINT cWaveOutDevices = waveOutGetNumDevs();
130 WCHAR strEndpointId[OVR_AUDIO_MAX_DEVICE_STR_SIZE] = {};
131 for (waveOutId = 0; waveOutId < cWaveOutDevices; waveOutId++)
132 {
133 size_t cbEndpointId = 0;
134
135 // Get the size (including the terminating null) of
136 // the endpoint ID string of the waveOut device.
137 mmr = waveOutMessage((HWAVEOUT)UIntToPtr(waveOutId),
138 DRV_QUERYFUNCTIONINSTANCEIDSIZE,
139 (DWORD_PTR)&cbEndpointId, NULL);
140 if (mmr != MMSYSERR_NOERROR ||
141 cbEndpointIdKey != cbEndpointId) // do sizes match?
142 {
143 continue; // not a matching device
144 }
145
146 // Get the endpoint ID string for this waveOut device.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected