diff options
author | Chris Robinson <[email protected]> | 2016-01-21 01:05:29 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-01-21 01:05:29 -0800 |
commit | bbd2876afb5265517d25e78d7dcaf7ccb494af0f (patch) | |
tree | e40fb1aec10be14fbba95e6f8d53b53aa0bd7106 /Alc/backends | |
parent | 3395b361fa59374c1c022ce1cc8c203f5d70f356 (diff) |
Improve the OSS enumeration code
Diffstat (limited to 'Alc/backends')
-rw-r--r-- | Alc/backends/oss.c | 134 |
1 files changed, 71 insertions, 63 deletions
diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 9ca92410..1e286791 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -52,7 +52,7 @@ #define SOUND_MIXER_WRITE MIXER_WRITE #endif -#if defined(SOUND_VERSION) && (SOUND_VERSION) < 0x040000 +#if defined(SOUND_VERSION) && (SOUND_VERSION < 0x040000) #define ALC_OSS_COMPAT #endif #ifndef SNDCTL_AUDIOINFO @@ -85,126 +85,134 @@ static struct oss_device oss_capture = { NULL }; -#ifdef ALC_OSS_COMPAT +#ifdef ALC_OSS_COMPAT -static void ALCossListPopulate(struct oss_device *playback, struct oss_device *capture) -{ - ; /* Stub */ -} - -static void ALCossListFree(struct oss_device *list) +static void ALCossListPopulate(struct oss_device *UNUSED(playback), struct oss_device *UNUSED(capture)) { - ; /* Stub */ } #else -static void ALCossListAppend(struct oss_device *list, char *handle, size_t hlen, char *path, size_t plen) { - struct oss_device *t; - struct oss_device *p; - void *m; +static void ALCossListAppend(struct oss_device *list, const char *handle, size_t hlen, const char *path, size_t plen) +{ + struct oss_device *next; + struct oss_device *last; size_t i; - if (list == NULL || handle == NULL || path == NULL || plen == 0 || path[0] == '\0') + + if(plen == 0 || path[0] == '\0') return; + /* skip the first item "OSS Default" */ - p = list; - t = list->next; + last = list; + next = list->next; #ifdef ALC_OSS_DEVNODE_TRUC - for (i = 0; i < plen; i++) - if (path[i] == '.') + for(i = 0;i < plen;i++) + { + if(path[i] == '.') { - if (strncmp(path + i, handle + hlen + i - plen, plen - i) == 0) + if(strncmp(path + i, handle + hlen + i - plen, plen - i) == 0) hlen = hlen + i - plen; plen = i; } + } +#else + (void)i; #endif - if (handle == NULL || hlen == 0 || handle[0] == '\0') { + if(handle[0] == '\0') + { handle = path; hlen = plen; } - while (t != NULL && strncmp(t->path, path, plen) != 0) { - p = t; - t = t->next; + + while(next != NULL) + { + if(strncmp(next->path, path, plen) == 0) + return; + last = next; + next = next->next; } - if (t != NULL) - return; - m = malloc(sizeof(struct oss_device) + hlen + plen + 2); - t = (struct oss_device *)m; - t->handle = (char *)((uintptr_t)m + sizeof(struct oss_device)); - t->path = stpncpy((char *)t->handle, handle, hlen) + 1; - ((char *)t->handle)[hlen] = '\0'; - strncpy((char *)t->path, path, plen); - ((char *)t->path)[plen] = '\0'; - t->next = NULL; - p->next = t; + + next = (struct oss_device*)malloc(sizeof(struct oss_device) + hlen + plen + 2); + next->handle = (char*)(next + 1); + next->path = next->handle + hlen + 1; + next->next = NULL; + last->next = next; + + strncpy((char*)next->handle, handle, hlen); + ((char*)next->handle)[hlen] = '\0'; + strncpy((char*)next->path, path, plen); + ((char*)next->path)[plen] = '\0'; + + TRACE("Got device \"%s\", \"%s\"\n", next->handle, next->path); } static void ALCossListPopulate(struct oss_device *playback, struct oss_device *capture) { struct oss_sysinfo si; struct oss_audioinfo ai; - int fd; - int i; - if ((fd = open("/dev/mixer", O_RDONLY)) < 0) + int fd, i; + + if((fd=open("/dev/mixer", O_RDONLY)) < 0) { ERR("Could not open /dev/mixer\n"); return; } - if (ioctl(fd, SNDCTL_SYSINFO, &si) == -1) + if(ioctl(fd, SNDCTL_SYSINFO, &si) == -1) { - ERR("SNDCTL_SYSINFO\n"); - goto err; + ERR("SNDCTL_SYSINFO failed: %s\n", strerror(errno)); + goto done; } - for (i = 0; i < si.numaudios; i++) + for(i = 0;i < si.numaudios;i++) { - char *handle; + const char *handle; size_t len; + ai.dev = i; - if (ioctl(fd, SNDCTL_AUDIOINFO, &ai) == -1) + if(ioctl(fd, SNDCTL_AUDIOINFO, &ai) == -1) { - ERR("SNDCTL_SYSINFO\n"); + ERR("SNDCTL_AUDIOINFO (%d) failed: %s\n", i, strerror(errno)); continue; } - if (ai.handle[0] == '\0') + if(ai.handle[0]) { - len = strnlen(ai.name, sizeof(ai.name)); - handle = ai.name; + len = strnlen(ai.handle, sizeof(ai.handle)); + handle = ai.handle; } else { - len = strnlen(ai.handle, sizeof(ai.handle)); - handle = ai.handle; + len = strnlen(ai.name, sizeof(ai.name)); + handle = ai.name; } - if ((ai.caps & DSP_CAP_INPUT) && capture != NULL) + if((ai.caps&DSP_CAP_INPUT) && capture != NULL) ALCossListAppend(capture, handle, len, ai.devnode, strnlen(ai.devnode, sizeof(ai.devnode))); - if ((ai.caps & DSP_CAP_OUTPUT) && playback != NULL) + if((ai.caps&DSP_CAP_OUTPUT) && playback != NULL) ALCossListAppend(playback, handle, len, ai.devnode, strnlen(ai.devnode, sizeof(ai.devnode))); } + +done: close(fd); - return; -err: - if (fd >= 0) - close(fd); - return; } +#endif + static void ALCossListFree(struct oss_device *list) { - struct oss_device *cur, *t; - if (list == NULL) + struct oss_device *cur; + if(list == NULL) return; + + /* skip the first item "OSS Default" */ cur = list->next; list->next = NULL; - while (cur != NULL) + + while(cur != NULL) { - t = cur->next; + struct oss_device *next = cur->next; free(cur); - cur = t; + cur = next; } } -#endif - static int log2i(ALCuint x) { int y = 0; |