mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
oss: support hot-unplug on FreeBSD
Patch by Hans Petter Selasky <hselasky@FreeBSD.org> ref: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=194727#c27 Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/277>
This commit is contained in:
parent
a9d1afbefd
commit
ef8fa7c997
2 changed files with 67 additions and 52 deletions
|
|
@ -40,6 +40,7 @@
|
|||
#include "oss-util.h"
|
||||
|
||||
int pa_oss_open(const char *device, int *mode, int* pcaps) {
|
||||
static const int nonblock_io = 1;
|
||||
int fd = -1;
|
||||
int caps;
|
||||
char *t;
|
||||
|
|
@ -89,6 +90,10 @@ int pa_oss_open(const char *device, int *mode, int* pcaps) {
|
|||
}
|
||||
|
||||
success:
|
||||
if (ioctl(fd, FIONBIO, &nonblock_io) < 0) {
|
||||
pa_log("FIONBIO: %s", pa_cstrerror(errno));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
t = pa_sprintf_malloc(
|
||||
"%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
||||
|
|
@ -295,41 +300,35 @@ int pa_oss_set_volume(int fd, unsigned long mixer, const pa_sample_spec *ss, con
|
|||
}
|
||||
|
||||
static int get_device_number(const char *dev) {
|
||||
const char *p, *e;
|
||||
const char *p;
|
||||
const char *e;
|
||||
char *rp = NULL;
|
||||
int r;
|
||||
int r = -1;
|
||||
|
||||
if (!(p = rp = pa_readlink(dev))) {
|
||||
#ifdef ENOLINK
|
||||
if (errno != EINVAL && errno != ENOLINK) {
|
||||
#else
|
||||
if (errno != EINVAL) {
|
||||
#endif
|
||||
r = -1;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (errno != EINVAL && errno != ENOLINK)
|
||||
return -2;
|
||||
p = dev;
|
||||
}
|
||||
|
||||
if ((e = strrchr(p, '/')))
|
||||
p = e+1;
|
||||
/* find the last forward slash */
|
||||
while ((e = strrchr(p, '/')))
|
||||
p = e + 1;
|
||||
|
||||
if (p == 0) {
|
||||
r = 0;
|
||||
goto finish;
|
||||
/* collect unit number at end, if any */
|
||||
while (*p) {
|
||||
if (*p >= '0' && *p <= '9') {
|
||||
if (r < 0)
|
||||
r = 0;
|
||||
else
|
||||
r *= 10;
|
||||
r += *p - '0';
|
||||
} else {
|
||||
r = -1;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
p = strchr(p, 0) -1;
|
||||
|
||||
if (*p >= '0' && *p <= '9') {
|
||||
r = *p - '0';
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = -1;
|
||||
|
||||
finish:
|
||||
pa_xfree(rp);
|
||||
return r;
|
||||
}
|
||||
|
|
@ -339,7 +338,7 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
|
|||
int n, r = -1;
|
||||
int b = 0;
|
||||
|
||||
if ((n = get_device_number(dev)) < 0)
|
||||
if ((n = get_device_number(dev)) == -2)
|
||||
return -1;
|
||||
|
||||
if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) &&
|
||||
|
|
@ -405,10 +404,10 @@ int pa_oss_open_mixer_for_device(const char *device) {
|
|||
char *fn;
|
||||
int fd;
|
||||
|
||||
if ((n = get_device_number(device)) < 0)
|
||||
if ((n = get_device_number(device)) == -2)
|
||||
return -1;
|
||||
|
||||
if (n == 0)
|
||||
if (n == -1)
|
||||
if ((fd = open_mixer("/dev/mixer")) >= 0)
|
||||
return fd;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue