chiark / gitweb /
Uniform audio command back end now rate limited.
[disorder] / lib / mixer-oss.c
index 7ab73a2f10ca616549533ce2a30b00986dc45c9b..a4ee419c18d7f671a3bdbfc958ed486b9ea20c6c 100644 (file)
@@ -1,42 +1,43 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2004, 2007 Richard Kettlewell
+ * Copyright (C) 2004, 2007, 2008 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+/** @file lib/mixer-oss.c
+ * @brief OSS mixer support
+ *
+ * Mono output devices aren't explicitly supported (but may work
+ * nonetheless).
  */
 
-#include <config.h>
-#include "types.h"
+#include "common.h"
+
+#if HAVE_SYS_SOUNDCARD_H
 
-#include <stdio.h>
-#include <string.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <stdlib.h>
 #include <errno.h>
 #include <stddef.h>
 #include <sys/ioctl.h>
+#include <sys/soundcard.h>
 
 #include "configuration.h"
 #include "mixer.h"
 #include "log.h"
 #include "syscalls.h"
-
-#if HAVE_SYS_SOUNDCARD_H
-#include <sys/soundcard.h>
+#include "mem.h"
 
 /* documentation does not match implementation! */
 #ifndef SOUND_MIXER_READ
 # define SOUND_MIXER_WRITE(x) MIXER_WRITE(x)
 #endif
 
+/** @brief Channel names */
 static const char *channels[] = SOUND_DEVICE_NAMES;
 
+/** @brief Convert channel name to number */
 static int mixer_channel(const char *c) {
   unsigned n;
   
@@ -61,35 +64,24 @@ static int mixer_channel(const char *c) {
   }
 }
 
-static int oss_validate_channel(const char *c) {
-  if(mixer_channel(c) != -1)
-    return 1;
-  else
-    return 0;
-}
-
-static int oss_validate_device(const char *d) {
-  struct stat sb;
-
-  if(stat(d, &sb) < 0) {
-    error(errno, "%s", d);
-    return 0;
-  }
-  if(!S_ISCHR(sb.st_mode)) {
-    error(0, "%s: not a character device", d);
-    return 0;
-  }
-  return 1;
-}
-
+/** @brief Open the OSS mixer device and return its fd */
 static int oss_do_open(void) {
   int fd;
   
-  if((fd = open(config->mixer, O_RDWR, 0)) < 0)
-    error(errno, "error opening %s", config->mixer);
+  if((fd = open(config->mixer, O_RDWR, 0)) < 0) {
+    static char *reported;
+
+    if(!reported || strcmp(reported, config->mixer)) {
+      if(reported)
+       xfree(reported);
+      reported = xstrdup(config->mixer);
+      error(errno, "error opening %s", config->mixer);
+    }
+  }
   return fd;
 }
 
+/** @brief Get the OSS mixer setting */
 static int oss_do_get(int *left, int *right, int fd, int ch) {
   int r;
   
@@ -103,6 +95,7 @@ static int oss_do_get(int *left, int *right, int fd, int ch) {
   return 0;
 }
 
+/** @brief Get OSS volume */
 static int oss_get(int *left, int *right) {
   int ch, fd;
 
@@ -121,6 +114,7 @@ static int oss_get(int *left, int *right) {
     return -1;
 }
 
+/** @brief Set OSS volume */
 static int oss_set(int *left, int *right) {
   int ch, fd, r;
 
@@ -146,10 +140,9 @@ static int oss_set(int *left, int *right) {
     return -1;
 }
 
+/** @brief OSS mixer vtable */
 const struct mixer mixer_oss = {
   BACKEND_OSS,
-  oss_validate_device,
-  oss_validate_channel,
   oss_get,
   oss_set,
   "/dev/mixer",