Adjusted default choice of audio driver.

If a driver can definitely see available devices, it is chosen. Otherwise,
 we'll take the first driver that initializes but saw no devices...this might
 be because it can't enumerate them, or there really aren't any available.

This prevents the dsp driver from hogging control when there are no /dev/dsp*
 nodes (for example, on a Linux box with ALSA and no OSS emulation).

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403400
This commit is contained in:
Ryan C. Gordon 2009-01-01 07:54:58 +00:00
parent 6611747b8f
commit 0e24b20c3b
20 changed files with 44 additions and 17 deletions

View file

@ -589,6 +589,8 @@ SDL_AudioInit(const char *driver_name)
int i = 0;
int initialized = 0;
int tried_to_init = 0;
int rc = 0;
int best_choice = -1;
if (SDL_WasInit(SDL_INIT_AUDIO)) {
SDL_AudioQuit(); /* shutdown driver if already running. */
@ -614,7 +616,25 @@ SDL_AudioInit(const char *driver_name)
SDL_memset(&current_audio, 0, sizeof(current_audio));
current_audio.name = backend->name;
current_audio.desc = backend->desc;
initialized = backend->init(&current_audio.impl);
rc = backend->init(&current_audio.impl);
if (rc == 2) { /* init'd, and devices available. Take it! */
initialized = 1;
best_choice = i;
} else if (rc == 1) { /* init'd, but can't see any devices. */
current_audio.impl.Deinitialize();
if (best_choice == -1) {
best_choice = i;
}
}
}
/* No definite choice. Pick one that works but can't promise a device. */
if ((!initialized) && (best_choice != -1)) {
const AudioBootStrap *backend = bootstrap[best_choice];
SDL_memset(&current_audio, 0, sizeof(current_audio));
current_audio.name = backend->name;
current_audio.desc = backend->desc;
initialized = (backend->init(&current_audio.impl) > 0);
}
if (!initialized) {

View file

@ -607,7 +607,7 @@ ALSA_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = ALSA_Deinitialize;
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */
return 1;
return 1; /* !!! FIXME: return 2 once device enum is implemented. */
}

View file

@ -444,7 +444,7 @@ BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = BSDAUDIO_Deinitialize;
build_device_lists();
return 1;
return (outputDeviceCount > 0) ? 2 : 1;
}

View file

@ -524,7 +524,7 @@ DMA_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = DMA_Deinitialize;
build_device_lists();
return 1;
return (outputDeviceCount > 0) ? 2 : 1;
}
AudioBootStrap DMA_bootstrap = {

View file

@ -381,7 +381,7 @@ DSP_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = DSP_Deinitialize;
build_device_lists();
return 1;
return (outputDeviceCount > 0) ? 2 : 1;
}

View file

@ -341,7 +341,7 @@ ESD_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = ESD_Deinitialize;
impl->OnlyHasDefaultOutputDevice = 1;
return 1;
return 2; /* return 2 (definitely have a "device"). */
}

View file

@ -329,7 +329,7 @@ COREAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->OnlyHasDefaultOutputDevice = 1;
impl->HasCaptureSupport = 0; /* still needs to be written */
return 1;
return 2; /* defitely have an audio device. */
}
AudioBootStrap COREAUDIOIPHONE_bootstrap = {

View file

@ -589,7 +589,7 @@ COREAUDIO_Init(SDL_AudioDriverImpl * impl)
build_device_lists(); /* do an initial check for devices... */
return 1;
return (outputDeviceCount > 0) ? 2 : 1;
}
AudioBootStrap COREAUDIO_bootstrap = {

View file

@ -338,7 +338,7 @@ MINTDMA8_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = 1;
impl->SkipMixerLock = 1;
return 1;
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap MINTAUDIO_DMA8_bootstrap = {

View file

@ -433,7 +433,7 @@ MINTGSXB_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = 1;
impl->SkipMixerLock = 1;
return 1;
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap MINTAUDIO_GSXB_bootstrap = {

View file

@ -390,7 +390,7 @@ MINTMCSN_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = 1;
impl->SkipMixerLock = 1;
return 1;
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap MINTAUDIO_MCSN_bootstrap = {

View file

@ -297,7 +297,7 @@ MINTSTFA_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = 1;
impl->SkipMixerLock = 1;
return 1;
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap MINTAUDIO_STFA_bootstrap = {

View file

@ -490,7 +490,7 @@ MINTXBIOS_Init(SDL_AudioDriverImpl * impl)
impl->ProvidesOwnCallbackThread = 1;
impl->SkipMixerLock = 1;
return 1;
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {

View file

@ -398,7 +398,7 @@ NAS_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = NAS_Deinitialize;
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: is this true? */
return 1;
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap NAS_bootstrap = {

View file

@ -120,7 +120,7 @@ NDSAUD_Init(SDL_AudioDriverImpl * impl)
impl->OnlyHasDefaultOutputDevice = 1;
impl->OnlyHasDefaultInputDevice = 1;
return 1;
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap NDSAUD_bootstrap = {

View file

@ -434,6 +434,7 @@ NTO_OpenDevice(_THIS, const char *devname, int iscapture)
static int
NTO_Init(SDL_AudioDriverImpl * impl)
{
/* !!! FIXME: not right for device enum? */
/* See if we can open a nonblocking channel. */
snd_pcm_t *handle = NULL;
int rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
@ -455,7 +456,8 @@ NTO_Init(SDL_AudioDriverImpl * impl)
impl->CloseDevice = NTO_CloseDevice;
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: add device enum! */
return 1;
/* !!! FIXME: device enum might make this 1. */
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap QNXNTOAUDIO_bootstrap = {

View file

@ -528,6 +528,7 @@ PAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
static int
PAUDIO_Init(SDL_AudioDriverImpl * impl)
{
/* !!! FIXME: not right for device enum? */
int fd = OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
if (fd < 0) {
SDL_SetError("PAUDIO: Couldn't open audio device");
@ -543,7 +544,8 @@ PAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->CloseDevice = DSP_CloseDevice;
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: add device enum! */
return 1;
/* !!! FIXME: device enum might make this 1. */
return 2; /* 2 == definitely has an audio device. */
}
AudioBootStrap PAUDIO_bootstrap = {

View file

@ -380,6 +380,7 @@ PULSEAUDIO_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = PULSEAUDIO_Deinitialize;
impl->OnlyHasDefaultOutputDevice = 1;
/* !!! FIXME: should test if server is available here, return 2 if so. */
return 1;
}

View file

@ -327,6 +327,7 @@ WINWAVEOUT_Init(SDL_AudioDriverImpl * impl)
impl->CloseDevice = WINWAVEOUT_CloseDevice;
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Is this true? */
/* !!! FIXME: not right for device enum? */
return 1;
}

View file

@ -508,6 +508,7 @@ DSOUND_Init(SDL_AudioDriverImpl * impl)
impl->Deinitialize = DSOUND_Deinitialize;
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME */
/* !!! FIXME: not right for device enum? */
return 1;
}