[openal] Runtime devices management

Chris Robinson chris.kcat at gmail.com
Fri Sep 9 12:48:56 EDT 2016


On 09/09/2016 05:38 AM, alberto box wrote:
> Moreover, the device change is not recognized even re-initializing openal
> at runtime.

Currently, OpenAL Soft does not implement any preferred-device tracking. 
When a device is opened, the returned ALCdevice is tied to that output 
or input device.

Part of the problem is that the OpenAL API has no method to deal with 
such behavior. The best it could do is secretly move playback or capture 
to a different device and continue to report the old device's name, but 
that could cause unintended consequences. The alternative is to simply 
not report the name of the device being used, so if it moves it won't 
need to change anything... but then the app can't tell the user what 
device is actually being used.

> 2. Is there a way to be notified when a device status changes at runtime?

You can check to see if a device has been disconnected using the 
ALC_EXT_disconnect extension:

https://icculus.org/alextreg/wiki/ALC_EXT_disconnect

Essentially, you periodically check the device's connection status:

ALCint connected;
alcGetIntegerv(device, ALC_CONNECTED, 1, &connected);
if(!connected)
{
    /* We've been lost! */
}

When the device has been disconnected, it will not play or record any 
more samples, and it will never reconnect on its own, even if the device 
is reconnected. You'll need to close the device handle and open a new 
one if you want to keep playing/recording (there has been talk about 
allowing alcResetDeviceSOFT to try to restore playback/capture from a 
previously-disconnected device, although this behavior is not currently 
implemented).

> 3. Is there a way to make openal initialization (following the first one)
> aware of new devices status?

This is ultimately down to the system. At least when using OpenAL Soft 
directly, every enumeration request is passed on to the underlying API 
(mmdevapi, dsound) to get a fresh list of device names each time. If the 
underlying API doesn't update its internal list of available devices, 
OpenAL Soft won't know about any changes either.

If you're using the router (the OpenAL32.dll provided by Creative's 
installer, with soft_oal.dll to provide the OpenAL Soft devices), then 
that may be caching the device list so it never asks OpenAL Soft to 
recheck the devices. You'll have to use the OpenAL Soft DLL directly to 
work around that, if that's what's happening.


More information about the openal mailing list