src/audio/xaudio2/SDL_xaudio2.c
changeset 5593 ab22ca13c47f
parent 5592 2e88d0742f4d
child 5615 5e060b67c73d
     1.1 --- a/src/audio/xaudio2/SDL_xaudio2.c	Thu Aug 04 01:07:09 2011 -0400
     1.2 +++ b/src/audio/xaudio2/SDL_xaudio2.c	Thu Aug 04 00:31:11 2011 -0400
     1.3 @@ -24,35 +24,9 @@
     1.4  #include "../SDL_audio_c.h"
     1.5  #include "SDL_assert.h"
     1.6  
     1.7 -#define INITGUID 1
     1.8 +#define INITGUID 1
     1.9  #include "SDL_xaudio2.h"
    1.10  
    1.11 -/* !!! FIXME: this is a cut and paste of SDL_FreeUnixAudioDevices(),
    1.12 - * !!! FIXME:  which is more proof this needs to be managed in SDL_audio.c
    1.13 - * !!! FIXME:  and not in drivers.
    1.14 - */
    1.15 -static void
    1.16 -FreeXAudio2AudioDevices(char ***devices, int *devCount)
    1.17 -{
    1.18 -    int i = *devCount;
    1.19 -    if ((i > 0) && (*devices != NULL)) {
    1.20 -        while (i--) {
    1.21 -            SDL_free((*devices)[i]);
    1.22 -        }
    1.23 -    }
    1.24 -
    1.25 -    if (*devices != NULL) {
    1.26 -        SDL_free(*devices);
    1.27 -    }
    1.28 -
    1.29 -    *devices = NULL;
    1.30 -    *devCount = 0;
    1.31 -}
    1.32 -
    1.33 -
    1.34 -static char **outputDevices = NULL;
    1.35 -static int outputDeviceCount = 0;
    1.36 -
    1.37  static __inline__ char *
    1.38  utf16_to_utf8(const WCHAR *S)
    1.39  {
    1.40 @@ -61,59 +35,38 @@
    1.41                              (SDL_wcslen(S)+1)*sizeof(WCHAR));
    1.42  }
    1.43  
    1.44 -static int
    1.45 -XAUDIO2_DetectDevices(int iscapture)
    1.46 +static void
    1.47 +XAUDIO2_DetectDevices(int iscapture, SDL_AddAudioDevice addfn)
    1.48  {
    1.49      IXAudio2 *ixa2 = NULL;
    1.50      UINT32 devcount = 0;
    1.51      UINT32 i = 0;
    1.52      void *ptr = NULL;
    1.53  
    1.54 -    if (!iscapture) {
    1.55 -        FreeXAudio2AudioDevices(&outputDevices, &outputDeviceCount);
    1.56 -    }
    1.57 -
    1.58      if (iscapture) {
    1.59          SDL_SetError("XAudio2: capture devices unsupported.");
    1.60 -        return 0;
    1.61 +        return;
    1.62      } else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
    1.63          SDL_SetError("XAudio2: XAudio2Create() failed.");
    1.64 -        return 0;
    1.65 +        return;
    1.66      } else if (IXAudio2_GetDeviceCount(ixa2, &devcount) != S_OK) {
    1.67          SDL_SetError("XAudio2: IXAudio2::GetDeviceCount() failed.");
    1.68          IXAudio2_Release(ixa2);
    1.69 -        return 0;
    1.70 -    } else if ((ptr = SDL_malloc(sizeof (char *) * devcount)) == NULL) {
    1.71 -        SDL_OutOfMemory();
    1.72 -        IXAudio2_Release(ixa2);
    1.73 -        return 0;
    1.74 +        return;
    1.75      }
    1.76  
    1.77 -    outputDevices = (char **) ptr;
    1.78      for (i = 0; i < devcount; i++) {
    1.79          XAUDIO2_DEVICE_DETAILS details;
    1.80          if (IXAudio2_GetDeviceDetails(ixa2, i, &details) == S_OK) {
    1.81              char *str = utf16_to_utf8(details.DisplayName);
    1.82              if (str != NULL) {
    1.83 -                outputDevices[outputDeviceCount++] = str;
    1.84 +                addfn(str);
    1.85 +                SDL_free(str);  /* addfn() made a copy of the string. */
    1.86              }
    1.87          }
    1.88      }
    1.89  
    1.90      IXAudio2_Release(ixa2);
    1.91 -
    1.92 -    return outputDeviceCount;
    1.93 -}
    1.94 -
    1.95 -static const char *
    1.96 -XAUDIO2_GetDeviceName(int index, int iscapture)
    1.97 -{
    1.98 -    if ((!iscapture) && (index < outputDeviceCount)) {
    1.99 -        return outputDevices[index];
   1.100 -    }
   1.101 -
   1.102 -    SDL_SetError("XAudio2: No such device");
   1.103 -    return NULL;
   1.104  }
   1.105  
   1.106  static void STDMETHODCALLTYPE
   1.107 @@ -436,7 +389,6 @@
   1.108  
   1.109      /* Set the function pointers */
   1.110      impl->DetectDevices = XAUDIO2_DetectDevices;
   1.111 -    impl->GetDeviceName = XAUDIO2_GetDeviceName;
   1.112      impl->OpenDevice = XAUDIO2_OpenDevice;
   1.113      impl->PlayDevice = XAUDIO2_PlayDevice;
   1.114      impl->WaitDevice = XAUDIO2_WaitDevice;