oss: parse device names correctly on FreeBSD

This fixes devices being named just "/dev/dspN" instead of actual
soundcard names.

Also synchronizes some things like the unsigned type with the
detect module.

Loosely based on patch by lightside <lightside@gmx.com>.

ref: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=245156

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/277>
This commit is contained in:
Greg V 2020-04-03 14:23:34 +03:00 committed by PulseAudio Marge Bot
parent ef8fa7c997
commit 0f70a6f519

View file

@ -352,8 +352,8 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
} }
while (!feof(f)) { while (!feof(f)) {
char line[64]; char line[1024] = { 0 };
int device; unsigned device;
if (!fgets(line, sizeof(line), f)) if (!fgets(line, sizeof(line), f))
break; break;
@ -361,26 +361,29 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
line[strcspn(line, "\r\n")] = 0; line[strcspn(line, "\r\n")] = 0;
if (!b) { if (!b) {
b = pa_streq(line, "Audio devices:"); b = pa_streq(line, "Audio devices:") || pa_streq(line, "Installed devices:");
continue; continue;
} }
if (line[0] == 0) if (line[0] == 0)
break; break;
if (sscanf(line, "%i: ", &device) != 1) if (sscanf(line, "%u: ", &device) != 1 && sscanf(line, "pcm%u: ", &device) != 1)
continue; continue;
if (device == n) { if (device == n) {
char *k = strchr(line, ':'); char *k = strchr(line, ':');
pa_assert(k); pa_assert(k);
k++; k++;
k += strspn(k, " "); k += strspn(k, " <");
if (pa_endswith(k, " (DUPLEX)")) if (pa_endswith(k, " (DUPLEX)"))
k[strlen(k)-9] = 0; k[strlen(k)-9] = 0;
pa_strlcpy(name, k, l); k[strcspn(k, ">")] = 0;
// Include the number to disambiguate devices with the same name
pa_snprintf(name, l, "%u - %s", device, k);
r = 0; r = 0;
break; break;
} }