Cleaned up audio device detection. Cleared out a lot of cut-and-paste.
This commit is contained in:
parent
46bb3d8770
commit
8e6153c36b
11 changed files with 221 additions and 549 deletions
|
@ -50,91 +50,23 @@
|
|||
#define BSD_AUDIO_DRIVER_DESC "Native OpenBSD audio"
|
||||
#endif
|
||||
|
||||
/* Open the audio device for playback, and don't block if busy */
|
||||
/* #define USE_BLOCKING_WRITES */
|
||||
|
||||
/* Use timer for synchronization */
|
||||
/* #define USE_TIMER_SYNC */
|
||||
|
||||
/* #define DEBUG_AUDIO */
|
||||
/* #define DEBUG_AUDIO_STREAM */
|
||||
|
||||
#ifdef USE_BLOCKING_WRITES
|
||||
#define OPEN_FLAGS_OUTPUT O_WRONLY
|
||||
#define OPEN_FLAGS_INPUT O_RDONLY
|
||||
#else
|
||||
#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
|
||||
#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
|
||||
#endif
|
||||
|
||||
/* !!! FIXME: so much cut and paste with dsp target... */
|
||||
static char **outputDevices = NULL;
|
||||
static int outputDeviceCount = 0;
|
||||
static char **inputDevices = NULL;
|
||||
static int inputDeviceCount = 0;
|
||||
|
||||
static inline void
|
||||
free_device_list(char ***devs, int *count)
|
||||
{
|
||||
SDL_FreeUnixAudioDevices(devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_list(int iscapture, char ***devs, int *count)
|
||||
{
|
||||
const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
|
||||
free_device_list(devs, count);
|
||||
SDL_EnumUnixAudioDevices(flags, 0, NULL, devs, count);
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_device_lists(void)
|
||||
{
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
free_device_lists(void)
|
||||
{
|
||||
free_device_list(&outputDevices, &outputDeviceCount);
|
||||
free_device_list(&inputDevices, &inputDeviceCount);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
BSDAUDIO_Deinitialize(void)
|
||||
{
|
||||
free_device_lists();
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
BSDAUDIO_DetectDevices(int iscapture)
|
||||
static void
|
||||
BSDAUDIO_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
|
||||
{
|
||||
if (iscapture) {
|
||||
build_device_list(1, &inputDevices, &inputDeviceCount);
|
||||
return inputDeviceCount;
|
||||
} else {
|
||||
build_device_list(0, &outputDevices, &outputDeviceCount);
|
||||
return outputDeviceCount;
|
||||
}
|
||||
|
||||
return 0; /* shouldn't ever hit this. */
|
||||
}
|
||||
|
||||
static const char *
|
||||
BSDAUDIO_GetDeviceName(int index, int iscapture)
|
||||
{
|
||||
if ((iscapture) && (index < inputDeviceCount)) {
|
||||
return inputDevices[index];
|
||||
} else if ((!iscapture) && (index < outputDeviceCount)) {
|
||||
return outputDevices[index];
|
||||
}
|
||||
|
||||
SDL_SetError("No such device");
|
||||
return NULL;
|
||||
SDL_EnumUnixAudioDevices(iscapture, 0, NULL, addfn);
|
||||
}
|
||||
|
||||
|
||||
|
@ -318,12 +250,11 @@ BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
|||
/* We don't care what the devname is...we'll try to open anything. */
|
||||
/* ...but default to first name in the list... */
|
||||
if (devname == NULL) {
|
||||
if (((iscapture) && (inputDeviceCount == 0)) ||
|
||||
((!iscapture) && (outputDeviceCount == 0))) {
|
||||
devname = SDL_GetAudioDeviceName(0, iscapture);
|
||||
if (devname == NULL) {
|
||||
SDL_SetError("No such audio device");
|
||||
return 0;
|
||||
}
|
||||
devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
|
||||
}
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
|
@ -434,7 +365,6 @@ BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|||
{
|
||||
/* Set the function pointers */
|
||||
impl->DetectDevices = BSDAUDIO_DetectDevices;
|
||||
impl->GetDeviceName = BSDAUDIO_GetDeviceName;
|
||||
impl->OpenDevice = BSDAUDIO_OpenDevice;
|
||||
impl->PlayDevice = BSDAUDIO_PlayDevice;
|
||||
impl->WaitDevice = BSDAUDIO_WaitDevice;
|
||||
|
@ -442,8 +372,6 @@ BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
|
|||
impl->CloseDevice = BSDAUDIO_CloseDevice;
|
||||
impl->Deinitialize = BSDAUDIO_Deinitialize;
|
||||
|
||||
build_device_lists();
|
||||
|
||||
return 1; /* this audio target is available. */
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue