From a81ef2709a30a255e6e47cf3064c6ed8ccb4fb91 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Mon, 15 Jan 2018 18:30:21 +0100 Subject: [PATCH] Check if the device supports playing/recording. From Tobias Kortkamp . Thanks. --- libsndio/sio_oss.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libsndio/sio_oss.c b/libsndio/sio_oss.c index 7199782..4b32f4a 100644 --- a/libsndio/sio_oss.c +++ b/libsndio/sio_oss.c @@ -264,6 +264,21 @@ sio_oss_getfd(const char *str, unsigned int mode, int nbio) DPERROR(path); return -1; } + + /* + * Check if the device supports playing/recording. + * Unfortunately, it's possible for devices to be opened RDWR + * even when they don't support playing/recording. + */ + if (mode & SIO_PLAY && ioctl(fd, SNDCTL_DSP_GETOSPACE, &bi) < 0) { + close(fd); + return -1; + } + if (mode & SIO_REC && ioctl(fd, SNDCTL_DSP_GETISPACE, &bi) < 0) { + close(fd); + return -1; + } + val = 1; if (ioctl(fd, SNDCTL_DSP_LOW_WATER, &val) < 0) { DPERROR("sio_oss_start: LOW_WATER");