Adjusted default choice of audio driver.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 01 Jan 2009 07:54:58 +0000
changeset 29382929ed239d2a
parent 2937 017d4334accf
child 2939 084e5b4fc5be
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).
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
     1.1 --- a/src/audio/SDL_audio.c	Wed Dec 31 08:05:21 2008 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Thu Jan 01 07:54:58 2009 +0000
     1.3 @@ -589,6 +589,8 @@
     1.4      int i = 0;
     1.5      int initialized = 0;
     1.6      int tried_to_init = 0;
     1.7 +    int rc = 0;
     1.8 +    int best_choice = -1;
     1.9  
    1.10      if (SDL_WasInit(SDL_INIT_AUDIO)) {
    1.11          SDL_AudioQuit();        /* shutdown driver if already running. */
    1.12 @@ -614,7 +616,25 @@
    1.13          SDL_memset(&current_audio, 0, sizeof(current_audio));
    1.14          current_audio.name = backend->name;
    1.15          current_audio.desc = backend->desc;
    1.16 -        initialized = backend->init(&current_audio.impl);
    1.17 +        rc = backend->init(&current_audio.impl);
    1.18 +        if (rc == 2) {  /* init'd, and devices available. Take it! */
    1.19 +            initialized = 1;
    1.20 +            best_choice = i;
    1.21 +        } else if (rc == 1) { /* init'd, but can't see any devices. */
    1.22 +            current_audio.impl.Deinitialize();
    1.23 +            if (best_choice == -1) {
    1.24 +                best_choice = i;
    1.25 +            }
    1.26 +        }
    1.27 +    }
    1.28 +
    1.29 +    /* No definite choice. Pick one that works but can't promise a device. */
    1.30 +    if ((!initialized) && (best_choice != -1)) {
    1.31 +        const AudioBootStrap *backend = bootstrap[best_choice];
    1.32 +        SDL_memset(&current_audio, 0, sizeof(current_audio));
    1.33 +        current_audio.name = backend->name;
    1.34 +        current_audio.desc = backend->desc;
    1.35 +        initialized = (backend->init(&current_audio.impl) > 0);
    1.36      }
    1.37  
    1.38      if (!initialized) {
     2.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Wed Dec 31 08:05:21 2008 +0000
     2.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Thu Jan 01 07:54:58 2009 +0000
     2.3 @@ -607,7 +607,7 @@
     2.4      impl->Deinitialize = ALSA_Deinitialize;
     2.5      impl->OnlyHasDefaultOutputDevice = 1;       /* !!! FIXME: Add device enum! */
     2.6  
     2.7 -    return 1;
     2.8 +    return 1;  /* !!! FIXME: return 2 once device enum is implemented. */
     2.9  }
    2.10  
    2.11  
     3.1 --- a/src/audio/bsd/SDL_bsdaudio.c	Wed Dec 31 08:05:21 2008 +0000
     3.2 +++ b/src/audio/bsd/SDL_bsdaudio.c	Thu Jan 01 07:54:58 2009 +0000
     3.3 @@ -444,7 +444,7 @@
     3.4      impl->Deinitialize = BSDAUDIO_Deinitialize;
     3.5  
     3.6      build_device_lists();
     3.7 -    return 1;
     3.8 +    return (outputDeviceCount > 0) ? 2 : 1;
     3.9  }
    3.10  
    3.11  
     4.1 --- a/src/audio/dma/SDL_dmaaudio.c	Wed Dec 31 08:05:21 2008 +0000
     4.2 +++ b/src/audio/dma/SDL_dmaaudio.c	Thu Jan 01 07:54:58 2009 +0000
     4.3 @@ -524,7 +524,7 @@
     4.4      impl->Deinitialize = DMA_Deinitialize;
     4.5  
     4.6      build_device_lists();
     4.7 -    return 1;
     4.8 +    return (outputDeviceCount > 0) ? 2 : 1;
     4.9  }
    4.10  
    4.11  AudioBootStrap DMA_bootstrap = {
     5.1 --- a/src/audio/dsp/SDL_dspaudio.c	Wed Dec 31 08:05:21 2008 +0000
     5.2 +++ b/src/audio/dsp/SDL_dspaudio.c	Thu Jan 01 07:54:58 2009 +0000
     5.3 @@ -381,7 +381,7 @@
     5.4      impl->Deinitialize = DSP_Deinitialize;
     5.5  
     5.6      build_device_lists();
     5.7 -    return 1;
     5.8 +    return (outputDeviceCount > 0) ? 2 : 1;
     5.9  }
    5.10  
    5.11  
     6.1 --- a/src/audio/esd/SDL_esdaudio.c	Wed Dec 31 08:05:21 2008 +0000
     6.2 +++ b/src/audio/esd/SDL_esdaudio.c	Thu Jan 01 07:54:58 2009 +0000
     6.3 @@ -341,7 +341,7 @@
     6.4      impl->Deinitialize = ESD_Deinitialize;
     6.5      impl->OnlyHasDefaultOutputDevice = 1;
     6.6  
     6.7 -    return 1;
     6.8 +    return 2;  /* return 2 (definitely have a "device"). */
     6.9  }
    6.10  
    6.11  
     7.1 --- a/src/audio/iphoneos/SDL_coreaudio_iphone.c	Wed Dec 31 08:05:21 2008 +0000
     7.2 +++ b/src/audio/iphoneos/SDL_coreaudio_iphone.c	Thu Jan 01 07:54:58 2009 +0000
     7.3 @@ -329,7 +329,7 @@
     7.4      impl->OnlyHasDefaultOutputDevice = 1;
     7.5      impl->HasCaptureSupport = 0;        /* still needs to be written */
     7.6  
     7.7 -    return 1;
     7.8 +    return 2;  /* defitely have an audio device. */
     7.9  }
    7.10  
    7.11  AudioBootStrap COREAUDIOIPHONE_bootstrap = {
     8.1 --- a/src/audio/macosx/SDL_coreaudio.c	Wed Dec 31 08:05:21 2008 +0000
     8.2 +++ b/src/audio/macosx/SDL_coreaudio.c	Thu Jan 01 07:54:58 2009 +0000
     8.3 @@ -589,7 +589,7 @@
     8.4  
     8.5      build_device_lists();       /* do an initial check for devices... */
     8.6  
     8.7 -    return 1;
     8.8 +    return (outputDeviceCount > 0) ? 2 : 1;
     8.9  }
    8.10  
    8.11  AudioBootStrap COREAUDIO_bootstrap = {
     9.1 --- a/src/audio/mint/SDL_mintaudio_dma8.c	Wed Dec 31 08:05:21 2008 +0000
     9.2 +++ b/src/audio/mint/SDL_mintaudio_dma8.c	Thu Jan 01 07:54:58 2009 +0000
     9.3 @@ -338,7 +338,7 @@
     9.4      impl->ProvidesOwnCallbackThread = 1;
     9.5      impl->SkipMixerLock = 1;
     9.6  
     9.7 -    return 1;
     9.8 +    return 2;  /* 2 == definitely has an audio device. */
     9.9  }
    9.10  
    9.11  AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
    10.1 --- a/src/audio/mint/SDL_mintaudio_gsxb.c	Wed Dec 31 08:05:21 2008 +0000
    10.2 +++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Thu Jan 01 07:54:58 2009 +0000
    10.3 @@ -433,7 +433,7 @@
    10.4      impl->ProvidesOwnCallbackThread = 1;
    10.5      impl->SkipMixerLock = 1;
    10.6  
    10.7 -    return 1;
    10.8 +    return 2;  /* 2 == definitely has an audio device. */
    10.9  }
   10.10  
   10.11  AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
    11.1 --- a/src/audio/mint/SDL_mintaudio_mcsn.c	Wed Dec 31 08:05:21 2008 +0000
    11.2 +++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Thu Jan 01 07:54:58 2009 +0000
    11.3 @@ -390,7 +390,7 @@
    11.4      impl->ProvidesOwnCallbackThread = 1;
    11.5      impl->SkipMixerLock = 1;
    11.6  
    11.7 -    return 1;
    11.8 +    return 2;  /* 2 == definitely has an audio device. */
    11.9  }
   11.10  
   11.11  AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
    12.1 --- a/src/audio/mint/SDL_mintaudio_stfa.c	Wed Dec 31 08:05:21 2008 +0000
    12.2 +++ b/src/audio/mint/SDL_mintaudio_stfa.c	Thu Jan 01 07:54:58 2009 +0000
    12.3 @@ -297,7 +297,7 @@
    12.4      impl->ProvidesOwnCallbackThread = 1;
    12.5      impl->SkipMixerLock = 1;
    12.6  
    12.7 -    return 1;
    12.8 +    return 2;  /* 2 == definitely has an audio device. */
    12.9  }
   12.10  
   12.11  AudioBootStrap MINTAUDIO_STFA_bootstrap = {
    13.1 --- a/src/audio/mint/SDL_mintaudio_xbios.c	Wed Dec 31 08:05:21 2008 +0000
    13.2 +++ b/src/audio/mint/SDL_mintaudio_xbios.c	Thu Jan 01 07:54:58 2009 +0000
    13.3 @@ -490,7 +490,7 @@
    13.4      impl->ProvidesOwnCallbackThread = 1;
    13.5      impl->SkipMixerLock = 1;
    13.6  
    13.7 -    return 1;
    13.8 +    return 2;  /* 2 == definitely has an audio device. */
    13.9  }
   13.10  
   13.11  AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
    14.1 --- a/src/audio/nas/SDL_nasaudio.c	Wed Dec 31 08:05:21 2008 +0000
    14.2 +++ b/src/audio/nas/SDL_nasaudio.c	Thu Jan 01 07:54:58 2009 +0000
    14.3 @@ -398,7 +398,7 @@
    14.4      impl->Deinitialize = NAS_Deinitialize;
    14.5      impl->OnlyHasDefaultOutputDevice = 1;       /* !!! FIXME: is this true? */
    14.6  
    14.7 -    return 1;
    14.8 +    return 2;  /* 2 == definitely has an audio device. */
    14.9  }
   14.10  
   14.11  AudioBootStrap NAS_bootstrap = {
    15.1 --- a/src/audio/nds/SDL_ndsaudio.c	Wed Dec 31 08:05:21 2008 +0000
    15.2 +++ b/src/audio/nds/SDL_ndsaudio.c	Thu Jan 01 07:54:58 2009 +0000
    15.3 @@ -120,7 +120,7 @@
    15.4      impl->OnlyHasDefaultOutputDevice = 1;
    15.5      impl->OnlyHasDefaultInputDevice = 1;
    15.6  
    15.7 -    return 1;
    15.8 +    return 2;  /* 2 == definitely has an audio device. */
    15.9  }
   15.10  
   15.11  AudioBootStrap NDSAUD_bootstrap = {
    16.1 --- a/src/audio/nto/SDL_nto_audio.c	Wed Dec 31 08:05:21 2008 +0000
    16.2 +++ b/src/audio/nto/SDL_nto_audio.c	Thu Jan 01 07:54:58 2009 +0000
    16.3 @@ -434,6 +434,7 @@
    16.4  static int
    16.5  NTO_Init(SDL_AudioDriverImpl * impl)
    16.6  {
    16.7 +    /* !!! FIXME: not right for device enum? */
    16.8      /*  See if we can open a nonblocking channel. */
    16.9      snd_pcm_t *handle = NULL;
   16.10      int rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
   16.11 @@ -455,7 +456,8 @@
   16.12      impl->CloseDevice = NTO_CloseDevice;
   16.13      impl->OnlyHasDefaultOutputDevice = 1;       /* !!! FIXME: add device enum! */
   16.14  
   16.15 -    return 1;
   16.16 +    /* !!! FIXME: device enum might make this 1. */
   16.17 +    return 2;  /* 2 == definitely has an audio device. */
   16.18  }
   16.19  
   16.20  AudioBootStrap QNXNTOAUDIO_bootstrap = {
    17.1 --- a/src/audio/paudio/SDL_paudio.c	Wed Dec 31 08:05:21 2008 +0000
    17.2 +++ b/src/audio/paudio/SDL_paudio.c	Thu Jan 01 07:54:58 2009 +0000
    17.3 @@ -528,6 +528,7 @@
    17.4  static int
    17.5  PAUDIO_Init(SDL_AudioDriverImpl * impl)
    17.6  {
    17.7 +    /* !!! FIXME: not right for device enum? */
    17.8      int fd = OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
    17.9      if (fd < 0) {
   17.10          SDL_SetError("PAUDIO: Couldn't open audio device");
   17.11 @@ -543,7 +544,8 @@
   17.12      impl->CloseDevice = DSP_CloseDevice;
   17.13      impl->OnlyHasDefaultOutputDevice = 1;       /* !!! FIXME: add device enum! */
   17.14  
   17.15 -    return 1;
   17.16 +    /* !!! FIXME: device enum might make this 1. */
   17.17 +    return 2;  /* 2 == definitely has an audio device. */
   17.18  }
   17.19  
   17.20  AudioBootStrap PAUDIO_bootstrap = {
    18.1 --- a/src/audio/pulseaudio/SDL_pulseaudio.c	Wed Dec 31 08:05:21 2008 +0000
    18.2 +++ b/src/audio/pulseaudio/SDL_pulseaudio.c	Thu Jan 01 07:54:58 2009 +0000
    18.3 @@ -380,6 +380,7 @@
    18.4      impl->Deinitialize = PULSEAUDIO_Deinitialize;
    18.5      impl->OnlyHasDefaultOutputDevice = 1;
    18.6  
    18.7 +    /* !!! FIXME: should test if server is available here, return 2 if so. */
    18.8      return 1;
    18.9  }
   18.10  
    19.1 --- a/src/audio/windib/SDL_dibaudio.c	Wed Dec 31 08:05:21 2008 +0000
    19.2 +++ b/src/audio/windib/SDL_dibaudio.c	Thu Jan 01 07:54:58 2009 +0000
    19.3 @@ -327,6 +327,7 @@
    19.4      impl->CloseDevice = WINWAVEOUT_CloseDevice;
    19.5      impl->OnlyHasDefaultOutputDevice = 1;       /* !!! FIXME: Is this true? */
    19.6  
    19.7 +    /* !!! FIXME: not right for device enum? */
    19.8      return 1;
    19.9  }
   19.10  
    20.1 --- a/src/audio/windx5/SDL_dx5audio.c	Wed Dec 31 08:05:21 2008 +0000
    20.2 +++ b/src/audio/windx5/SDL_dx5audio.c	Thu Jan 01 07:54:58 2009 +0000
    20.3 @@ -508,6 +508,7 @@
    20.4      impl->Deinitialize = DSOUND_Deinitialize;
    20.5      impl->OnlyHasDefaultOutputDevice = 1;       /* !!! FIXME */
    20.6  
    20.7 +    /* !!! FIXME: not right for device enum? */
    20.8      return 1;
    20.9  }
   20.10