Mercurial > sdl-ios-xcode
changeset 2938:2929ed239d2a
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).
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 01 Jan 2009 07:54:58 +0000 |
parents | 017d4334accf |
children | 084e5b4fc5be |
files | src/audio/SDL_audio.c src/audio/alsa/SDL_alsa_audio.c src/audio/bsd/SDL_bsdaudio.c src/audio/dma/SDL_dmaaudio.c src/audio/dsp/SDL_dspaudio.c src/audio/esd/SDL_esdaudio.c src/audio/iphoneos/SDL_coreaudio_iphone.c src/audio/macosx/SDL_coreaudio.c src/audio/mint/SDL_mintaudio_dma8.c src/audio/mint/SDL_mintaudio_gsxb.c src/audio/mint/SDL_mintaudio_mcsn.c src/audio/mint/SDL_mintaudio_stfa.c src/audio/mint/SDL_mintaudio_xbios.c src/audio/nas/SDL_nasaudio.c src/audio/nds/SDL_ndsaudio.c src/audio/nto/SDL_nto_audio.c src/audio/paudio/SDL_paudio.c src/audio/pulseaudio/SDL_pulseaudio.c src/audio/windib/SDL_dibaudio.c src/audio/windx5/SDL_dx5audio.c |
diffstat | 20 files changed, 44 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audio/SDL_audio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/SDL_audio.c Thu Jan 01 07:54:58 2009 +0000 @@ -589,6 +589,8 @@ 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_memset(¤t_audio, 0, sizeof(current_audio)); current_audio.name = backend->name; current_audio.desc = backend->desc; - initialized = backend->init(¤t_audio.impl); + rc = backend->init(¤t_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(¤t_audio, 0, sizeof(current_audio)); + current_audio.name = backend->name; + current_audio.desc = backend->desc; + initialized = (backend->init(¤t_audio.impl) > 0); } if (!initialized) {
--- a/src/audio/alsa/SDL_alsa_audio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/alsa/SDL_alsa_audio.c Thu Jan 01 07:54:58 2009 +0000 @@ -607,7 +607,7 @@ impl->Deinitialize = ALSA_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Add device enum! */ - return 1; + return 1; /* !!! FIXME: return 2 once device enum is implemented. */ }
--- a/src/audio/bsd/SDL_bsdaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/bsd/SDL_bsdaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -444,7 +444,7 @@ impl->Deinitialize = BSDAUDIO_Deinitialize; build_device_lists(); - return 1; + return (outputDeviceCount > 0) ? 2 : 1; }
--- a/src/audio/dma/SDL_dmaaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/dma/SDL_dmaaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -524,7 +524,7 @@ impl->Deinitialize = DMA_Deinitialize; build_device_lists(); - return 1; + return (outputDeviceCount > 0) ? 2 : 1; } AudioBootStrap DMA_bootstrap = {
--- a/src/audio/dsp/SDL_dspaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/dsp/SDL_dspaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -381,7 +381,7 @@ impl->Deinitialize = DSP_Deinitialize; build_device_lists(); - return 1; + return (outputDeviceCount > 0) ? 2 : 1; }
--- a/src/audio/esd/SDL_esdaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/esd/SDL_esdaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -341,7 +341,7 @@ impl->Deinitialize = ESD_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; - return 1; + return 2; /* return 2 (definitely have a "device"). */ }
--- a/src/audio/iphoneos/SDL_coreaudio_iphone.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/iphoneos/SDL_coreaudio_iphone.c Thu Jan 01 07:54:58 2009 +0000 @@ -329,7 +329,7 @@ impl->OnlyHasDefaultOutputDevice = 1; impl->HasCaptureSupport = 0; /* still needs to be written */ - return 1; + return 2; /* defitely have an audio device. */ } AudioBootStrap COREAUDIOIPHONE_bootstrap = {
--- a/src/audio/macosx/SDL_coreaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/macosx/SDL_coreaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -589,7 +589,7 @@ build_device_lists(); /* do an initial check for devices... */ - return 1; + return (outputDeviceCount > 0) ? 2 : 1; } AudioBootStrap COREAUDIO_bootstrap = {
--- a/src/audio/mint/SDL_mintaudio_dma8.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/mint/SDL_mintaudio_dma8.c Thu Jan 01 07:54:58 2009 +0000 @@ -338,7 +338,7 @@ impl->ProvidesOwnCallbackThread = 1; impl->SkipMixerLock = 1; - return 1; + return 2; /* 2 == definitely has an audio device. */ } AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
--- a/src/audio/mint/SDL_mintaudio_gsxb.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/mint/SDL_mintaudio_gsxb.c Thu Jan 01 07:54:58 2009 +0000 @@ -433,7 +433,7 @@ impl->ProvidesOwnCallbackThread = 1; impl->SkipMixerLock = 1; - return 1; + return 2; /* 2 == definitely has an audio device. */ } AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
--- a/src/audio/mint/SDL_mintaudio_mcsn.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/mint/SDL_mintaudio_mcsn.c Thu Jan 01 07:54:58 2009 +0000 @@ -390,7 +390,7 @@ impl->ProvidesOwnCallbackThread = 1; impl->SkipMixerLock = 1; - return 1; + return 2; /* 2 == definitely has an audio device. */ } AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
--- a/src/audio/mint/SDL_mintaudio_stfa.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/mint/SDL_mintaudio_stfa.c Thu Jan 01 07:54:58 2009 +0000 @@ -297,7 +297,7 @@ impl->ProvidesOwnCallbackThread = 1; impl->SkipMixerLock = 1; - return 1; + return 2; /* 2 == definitely has an audio device. */ } AudioBootStrap MINTAUDIO_STFA_bootstrap = {
--- a/src/audio/mint/SDL_mintaudio_xbios.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/mint/SDL_mintaudio_xbios.c Thu Jan 01 07:54:58 2009 +0000 @@ -490,7 +490,7 @@ impl->ProvidesOwnCallbackThread = 1; impl->SkipMixerLock = 1; - return 1; + return 2; /* 2 == definitely has an audio device. */ } AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
--- a/src/audio/nas/SDL_nasaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/nas/SDL_nasaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -398,7 +398,7 @@ impl->Deinitialize = NAS_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: is this true? */ - return 1; + return 2; /* 2 == definitely has an audio device. */ } AudioBootStrap NAS_bootstrap = {
--- a/src/audio/nds/SDL_ndsaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/nds/SDL_ndsaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -120,7 +120,7 @@ impl->OnlyHasDefaultOutputDevice = 1; impl->OnlyHasDefaultInputDevice = 1; - return 1; + return 2; /* 2 == definitely has an audio device. */ } AudioBootStrap NDSAUD_bootstrap = {
--- a/src/audio/nto/SDL_nto_audio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/nto/SDL_nto_audio.c Thu Jan 01 07:54:58 2009 +0000 @@ -434,6 +434,7 @@ 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 @@ 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 = {
--- a/src/audio/paudio/SDL_paudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/paudio/SDL_paudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -528,6 +528,7 @@ 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 @@ 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 = {
--- a/src/audio/pulseaudio/SDL_pulseaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -380,6 +380,7 @@ impl->Deinitialize = PULSEAUDIO_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; + /* !!! FIXME: should test if server is available here, return 2 if so. */ return 1; }
--- a/src/audio/windib/SDL_dibaudio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/windib/SDL_dibaudio.c Thu Jan 01 07:54:58 2009 +0000 @@ -327,6 +327,7 @@ impl->CloseDevice = WINWAVEOUT_CloseDevice; impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Is this true? */ + /* !!! FIXME: not right for device enum? */ return 1; }
--- a/src/audio/windx5/SDL_dx5audio.c Wed Dec 31 08:05:21 2008 +0000 +++ b/src/audio/windx5/SDL_dx5audio.c Thu Jan 01 07:54:58 2009 +0000 @@ -508,6 +508,7 @@ impl->Deinitialize = DSOUND_Deinitialize; impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME */ + /* !!! FIXME: not right for device enum? */ return 1; }