Recovering from an Invalid-Device Error (Spatial Sound)
Many of the methods of the Microsoft Spatial Audio API, such as ISpatialAudioClient, ISpatialAudioObjectRenderStream, and ISpatialAudioObject, return error codes if the audio endpoint device that the client application is using becomes invalid or the spatial audio rendering format is changed on the endpoint. These error codes indicates that the endpoint device has been unplugged, or that the audio hardware or associated hardware resources have been reconfigured, disabled, removed, spatial audio mode is changed or otherwise made unavailable for use. Frequently, the application can recover from this error.
Error codes that indicate an invalid-device error include the following:
Strategies for handling invalid-device errors
The recommended strategy for recovering from an invalid-device error depends on whether the application automatically selects a specific device based on internal requirements or it allows the user to explicitly select a device from a list of available devices.
Default audio device
If the application automatically selects the default device, use the following steps to recover.
- Release the ISpatialAudioObjectRenderStream and ISpatialAudioClient interface and any other spatial audio interfaces that are used for rendering.
- Call IMMDeviceEnumerator::GetDefaultAudioEndpoint to get the current default audio device.
- Attempt to activate ISpatialAudioClient on the audio device.
- Activate ISpatialAudioObjectRenderStream.
Specifically selected audio device
If the application selects a specific audio device, use the following steps to recover.
- Release the ISpatialAudioObjectRenderStream interface and any other spatial audio interfaces that are used for rendering, but don't release ISpatialAudioClient.
- Use the current ISpatialAudioClient instance to activate ISpatialAudioObjectRenderStream.
Note that for both strategies listed above, the same steps can be applied to applications that use the ISpatialAudioObjectRenderStreamForMetadata or ISpatialAudioObjectRenderStreamForHrtf interfaces. Simply replace ISpatialAudioObjectRenderStream in the above steps with the metadata or Hrtf interfaces.
- [Recovering from an Invalid-Device Error](recovering-from-an-invalid-device-error.md) [Stream Management](stream-management.md)