summaryrefslogtreecommitdiffstats
path: root/src/oss-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-07-11 23:21:32 +0000
committerLennart Poettering <lennart@poettering.net>2004-07-11 23:21:32 +0000
commitd4e0d51c157dea740d35089f077451b6ec7b11a5 (patch)
treea2f5db27d4b460c511bffeeedd05708b0b6e6354 /src/oss-util.c
parent216591d95e00a0cb771088dad9a752efead55e10 (diff)
make module-oss-* use modargs
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@63 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/oss-util.c')
-rw-r--r--src/oss-util.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/oss-util.c b/src/oss-util.c
index 9c4f55ca..f1e07017 100644
--- a/src/oss-util.c
+++ b/src/oss-util.c
@@ -4,9 +4,63 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "oss-util.h"
+int pa_oss_open(const char *device, int *mode, int* pcaps) {
+ int fd = -1;
+ assert(device && mode && (*mode == O_RDWR || *mode == O_RDONLY || *mode == O_WRONLY));
+
+ if (*mode == O_RDWR) {
+ if ((fd = open(device, O_RDWR|O_NDELAY)) >= 0) {
+ int dcaps, *tcaps;
+ ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
+
+ tcaps = pcaps ? pcaps : &dcaps;
+
+ if (ioctl(fd, SNDCTL_DSP_GETCAPS, tcaps) < 0) {
+ fprintf(stderr, __FILE__": SNDCTL_DSP_GETCAPS: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ if (*tcaps & DSP_CAP_DUPLEX)
+ return fd;
+
+ close(fd);
+ }
+
+ if ((fd = open(device, (*mode = O_WRONLY)|O_NDELAY)) < 0) {
+ if ((fd = open(device, (*mode = O_RDONLY)|O_NDELAY)) < 0) {
+ fprintf(stderr, __FILE__": open('%s'): %s\n", device, strerror(errno));
+ goto fail;
+ }
+ }
+ } else {
+ if ((fd = open(device, *mode|O_NDELAY)) < 0) {
+ fprintf(stderr, __FILE__": open('%s'): %s\n", device, strerror(errno));
+ goto fail;
+ }
+ }
+
+ if (pcaps) {
+ if (ioctl(fd, SNDCTL_DSP_GETCAPS, pcaps) < 0) {
+ fprintf(stderr, "SNDCTL_DSP_GETCAPS: %s\n", strerror(errno));
+ goto fail;
+ }
+ }
+
+ return fd;
+
+fail:
+ if (fd >= 0)
+ close(fd);
+ return fd;
+}
+
int pa_oss_auto_format(int fd, struct pa_sample_spec *ss) {
int format, channels, speed;