Skip to content

Commit

Permalink
Fixed device enumeration.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Mar 26, 2018
1 parent 9cbe0ee commit d4b9eac
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions mojoal.c
Expand Up @@ -935,38 +935,44 @@ static const ALCchar *calculate_sdl_device_list(const int iscapture)
#define DEVICE_LIST_BUFFER_SIZE 512
static ALCchar playback_list[DEVICE_LIST_BUFFER_SIZE];
static ALCchar capture_list[DEVICE_LIST_BUFFER_SIZE];
ALCchar list[DEVICE_LIST_BUFFER_SIZE];
const int numdevs = SDL_GetNumAudioDevices(iscapture);
ALCchar *final_list = iscapture ? capture_list : playback_list;
ALCchar *ptr = list;
ALCchar *ptr = final_list;
int numdevs;
size_t avail = DEVICE_LIST_BUFFER_SIZE;
size_t cpy;
int i;

/* default device is always available. */
cpy = SDL_strlcpy(ptr, iscapture ? DEFAULT_CAPTURE_DEVICE : DEFAULT_PLAYBACK_DEVICE, avail);
SDL_assert(cpy < avail);
SDL_assert((cpy+1) < avail);
ptr += cpy + 1; /* skip past null char. */
avail -= cpy + 1;

if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
return final_list;
return NULL;
}

numdevs = SDL_GetNumAudioDevices(iscapture);

for (i = 0; i < numdevs; i++) {
const char *devname = SDL_GetAudioDeviceName(i, iscapture);
const size_t devnamelen = SDL_strlen(devname);
/* if we're out of space, we just have to drop devices we can't cram in the buffer. */
if (avail > (devnamelen + 2)) {
cpy = SDL_strlcpy(ptr, devname, avail);
SDL_assert(cpy == (devnamelen + 1));
SDL_assert(cpy < avail);
SDL_assert(cpy == devnamelen);
SDL_assert((cpy+1) < avail);
ptr += cpy + 1; /* skip past null char. */
avail -= cpy + 1;
}
}

SDL_assert(avail >= 1);
*ptr = '\0';
avail--;

SDL_memcpy(final_list, list, DEVICE_LIST_BUFFER_SIZE - avail);
SDL_QuitSubSystem(SDL_INIT_AUDIO);

return final_list;

#undef DEVICE_LIST_BUFFER_SIZE
Expand Down

0 comments on commit d4b9eac

Please sign in to comment.