src/audio/nas/SDL_nasaudio.c
branchSDL-ryan-multiple-audio-device
changeset 3846 66fb40445587
parent 3825 76c5a414b996
     1.1 --- a/src/audio/nas/SDL_nasaudio.c	Tue Oct 17 08:04:51 2006 +0000
     1.2 +++ b/src/audio/nas/SDL_nasaudio.c	Tue Oct 17 09:09:21 2006 +0000
     1.3 @@ -97,12 +97,10 @@
     1.4  
     1.5  #ifdef SDL_AUDIO_DRIVER_NAS_DYNAMIC
     1.6  
     1.7 -static int library_load_count = 0;
     1.8 -
     1.9  static void
    1.10  UnloadNASLibrary(void)
    1.11  {
    1.12 -    if ((nas_handle != NULL) && (--library_load_count == 0)) {
    1.13 +    if (nas_handle != NULL) {
    1.14          SDL_UnloadObject(nas_handle);
    1.15          nas_handle = NULL;
    1.16      }
    1.17 @@ -112,7 +110,7 @@
    1.18  LoadNASLibrary(void)
    1.19  {
    1.20      int retval = 0;
    1.21 -    if (library_load_count++ == 0) {
    1.22 +    if (nas_handle == NULL) {
    1.23          nas_handle = SDL_LoadObject(nas_library);
    1.24          if (nas_handle == NULL) {
    1.25              /* Copy error string so we can use it in a new SDL_SetError(). */
    1.26 @@ -120,8 +118,6 @@
    1.27              size_t len = SDL_strlen(origerr) + 1;
    1.28              char *err = (char *) alloca(len);
    1.29              SDL_strlcpy(err, origerr, len);
    1.30 -
    1.31 -            library_load_count--;
    1.32              retval = -1;
    1.33              SDL_SetError("NAS: SDL_LoadObject('%s') failed: %s\n",
    1.34                            nas_library, err);
    1.35 @@ -151,21 +147,6 @@
    1.36  
    1.37  #endif /* SDL_AUDIO_DRIVER_NAS_DYNAMIC */
    1.38  
    1.39 -static int
    1.40 -NAS_Available(void)
    1.41 -{
    1.42 -    int available = 0;
    1.43 -    if (LoadNASLibrary() >= 0) {
    1.44 -        AuServer *aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
    1.45 -        if (aud != NULL) {
    1.46 -            available = 1;
    1.47 -            NAS_AuCloseServer(aud);
    1.48 -        }
    1.49 -        UnloadNASLibrary();
    1.50 -    }
    1.51 -    return available;
    1.52 -}
    1.53 -
    1.54  /* This function waits until it is possible to write a full sound buffer */
    1.55  static void
    1.56  NAS_WaitDevice(_THIS)
    1.57 @@ -223,7 +204,6 @@
    1.58          }
    1.59          SDL_free(this->hidden);
    1.60          this2 = this->hidden = NULL;
    1.61 -        UnloadNASLibrary();
    1.62      }
    1.63  }
    1.64  
    1.65 @@ -316,11 +296,6 @@
    1.66      }
    1.67      SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    1.68  
    1.69 -    if (LoadNASLibrary() < 0) {
    1.70 -        NAS_CloseDevice(this);
    1.71 -        return 0;
    1.72 -    }
    1.73 -
    1.74      /* Try for a closest match on audio format */
    1.75      format = 0;
    1.76      for (test_format = SDL_FirstAudioFormat(this->spec.format);
    1.77 @@ -390,23 +365,40 @@
    1.78      return 1;
    1.79  }
    1.80  
    1.81 +static void
    1.82 +NAS_Deinitialize(void)
    1.83 +{
    1.84 +    UnloadNASLibrary();
    1.85 +}
    1.86 +
    1.87  static int
    1.88  NAS_Init(SDL_AudioDriverImpl *impl)
    1.89  {
    1.90 +    if (LoadNASLibrary() < 0) {
    1.91 +        return 0;
    1.92 +    } else {
    1.93 +        AuServer *aud = NAS_AuOpenServer("", 0, NULL, 0, NULL, NULL);
    1.94 +        if (aud == NULL) {
    1.95 +            SDL_SetError("NAS: AuOpenServer() failed (no audio server?)");
    1.96 +            return 0;
    1.97 +        }
    1.98 +        NAS_AuCloseServer(aud);
    1.99 +    }
   1.100 +
   1.101      /* Set the function pointers */
   1.102      impl->OpenDevice = NAS_OpenDevice;
   1.103      impl->PlayDevice = NAS_PlayDevice;
   1.104      impl->WaitDevice = NAS_WaitDevice;
   1.105      impl->GetDeviceBuf = NAS_GetDeviceBuf;
   1.106      impl->CloseDevice = NAS_CloseDevice;
   1.107 +    impl->Deinitialize = NAS_Deinitialize;
   1.108      impl->OnlyHasDefaultOutputDevice = 1;  /* !!! FIXME: is this true? */
   1.109  
   1.110      return 1;
   1.111  }
   1.112  
   1.113  AudioBootStrap NAS_bootstrap = {
   1.114 -    NAS_DRIVER_NAME, "Network Audio System",
   1.115 -    NAS_Available, NAS_Init, 0
   1.116 +    NAS_DRIVER_NAME, "Network Audio System", NAS_Init, 0
   1.117  };
   1.118  
   1.119  /* vi: set ts=4 sw=4 expandtab: */