mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-05 22:30:29 +00:00
audio: add a SDL_GetPhysicalAudioDevice method, for mapping logical to physical device ids
This commit is contained in:
parent
a5a0667a80
commit
6cba25187f
6 changed files with 33 additions and 0 deletions
|
|
@ -759,6 +759,21 @@ extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDevic
|
||||||
*/
|
*/
|
||||||
extern SDL_DECLSPEC bool SDLCALL SDL_IsAudioDevicePhysical(SDL_AudioDeviceID devid);
|
extern SDL_DECLSPEC bool SDLCALL SDL_IsAudioDevicePhysical(SDL_AudioDeviceID devid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the physical audio device associated with a logical audio device.
|
||||||
|
*
|
||||||
|
* If `devid` is already a physical device, this function returns `devid`.
|
||||||
|
* If `devid` is an invalid device, it returns 0.
|
||||||
|
*
|
||||||
|
* \param devid the device ID to query.
|
||||||
|
* \returns the physical device ID, or 0 on error.
|
||||||
|
*
|
||||||
|
* \threadsafety It is safe to call this function from any thread.
|
||||||
|
*
|
||||||
|
* \since This function is available since SDL 3.5.0.
|
||||||
|
*/
|
||||||
|
extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_GetPhysicalAudioDevice(SDL_AudioDeviceID devid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if an audio device is a playback device (instead of recording).
|
* Determine if an audio device is a playback device (instead of recording).
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -538,6 +538,20 @@ static SDL_AudioDevice *ObtainPhysicalAudioDeviceDefaultAllowed(SDL_AudioDeviceI
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_AudioDeviceID SDL_GetPhysicalAudioDevice(SDL_AudioDeviceID devid)
|
||||||
|
{
|
||||||
|
if (SDL_IsAudioDevicePhysical(devid)) {
|
||||||
|
return devid;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_AudioDeviceID result = 0;
|
||||||
|
SDL_AudioDevice *device = ObtainPhysicalAudioDeviceDefaultAllowed(devid);
|
||||||
|
if (device) {
|
||||||
|
result = device->instance_id;
|
||||||
|
ReleaseAudioDevice(device);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
// this assumes you hold the _physical_ device lock for this logical device! This will not unlock the lock or close the physical device!
|
// this assumes you hold the _physical_ device lock for this logical device! This will not unlock the lock or close the physical device!
|
||||||
// It also will not unref the physical device, since we might be shutting down; SDL_CloseAudioDevice handles the unref.
|
// It also will not unref the physical device, since we might be shutting down; SDL_CloseAudioDevice handles the unref.
|
||||||
static void DestroyLogicalAudioDevice(SDL_LogicalAudioDevice *logdev)
|
static void DestroyLogicalAudioDevice(SDL_LogicalAudioDevice *logdev)
|
||||||
|
|
|
||||||
|
|
@ -1290,3 +1290,4 @@ _SDL_LoadJPG
|
||||||
_SDL_HasSVE2
|
_SDL_HasSVE2
|
||||||
_SDL_GamepadHasCapSense
|
_SDL_GamepadHasCapSense
|
||||||
_SDL_GetGamepadCapSense
|
_SDL_GetGamepadCapSense
|
||||||
|
_SDL_GetPhysicalAudioDevice
|
||||||
|
|
|
||||||
|
|
@ -1291,6 +1291,7 @@ SDL3_0.0.0 {
|
||||||
SDL_HasSVE2;
|
SDL_HasSVE2;
|
||||||
SDL_GamepadHasCapSense;
|
SDL_GamepadHasCapSense;
|
||||||
SDL_GetGamepadCapSense;
|
SDL_GetGamepadCapSense;
|
||||||
|
SDL_GetPhysicalAudioDevice;
|
||||||
# extra symbols go here (don't modify this line)
|
# extra symbols go here (don't modify this line)
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1317,3 +1317,4 @@
|
||||||
#define SDL_HasSVE2 SDL_HasSVE2_REAL
|
#define SDL_HasSVE2 SDL_HasSVE2_REAL
|
||||||
#define SDL_GamepadHasCapSense SDL_GamepadHasCapSense_REAL
|
#define SDL_GamepadHasCapSense SDL_GamepadHasCapSense_REAL
|
||||||
#define SDL_GetGamepadCapSense SDL_GetGamepadCapSense_REAL
|
#define SDL_GetGamepadCapSense SDL_GetGamepadCapSense_REAL
|
||||||
|
#define SDL_GetPhysicalAudioDevice SDL_GetPhysicalAudioDevice_REAL
|
||||||
|
|
|
||||||
|
|
@ -1325,3 +1325,4 @@ SDL_DYNAPI_PROC(SDL_Surface*,SDL_LoadJPG,(const char *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(bool,SDL_HasSVE2,(void),(),return)
|
SDL_DYNAPI_PROC(bool,SDL_HasSVE2,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(bool,SDL_GamepadHasCapSense,(SDL_Gamepad *a,SDL_GamepadCapSenseType b),(a,b),return)
|
SDL_DYNAPI_PROC(bool,SDL_GamepadHasCapSense,(SDL_Gamepad *a,SDL_GamepadCapSenseType b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(bool,SDL_GetGamepadCapSense,(SDL_Gamepad *a,SDL_GamepadCapSenseType b),(a,b),return)
|
SDL_DYNAPI_PROC(bool,SDL_GetGamepadCapSense,(SDL_Gamepad *a,SDL_GamepadCapSenseType b),(a,b),return)
|
||||||
|
SDL_DYNAPI_PROC(SDL_AudioDeviceID,SDL_GetPhysicalAudioDevice,(SDL_AudioDeviceID a),(a),return)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue