changeset 74:11d45400f5ed trunk

[svn] The mixer device isn't opened and closed for every action now, instead it gets opened as soon as needed and closed if it's not needed anymore. This fixes a lot of bugs with the mixer of the OSS plugin, including the one that settigns the volume on OpenBSD via OSS didn't work at all.
author js
date Mon, 02 Oct 2006 11:29:31 -0700
parents fdfe583c3110
children a4320fd56b6f
files ChangeLog src/OSS/audio.c src/OSS/mixer.c
diffstat 3 files changed, 40 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Oct 02 10:49:55 2006 -0700
+++ b/ChangeLog	Mon Oct 02 11:29:31 2006 -0700
@@ -1,3 +1,10 @@
+2006-10-02 17:49:55 +0000  Jonathan Schleifer <js@h3c.de>
+  revision [146]
+  Reverted cuesheet.c to revision 104 because it was broken with rev 144.
+  trunk/src/cue/cuesheet.c |    4 +++-
+  1 file changed, 3 insertions(+), 1 deletion(-)
+
+
 2006-10-01 07:57:11 +0000  William Pitcock <nenolod@nenolod.net>
   revision [144]
   - clarify is_our_file()... however, it's still a tad borked
--- a/src/OSS/audio.c	Mon Oct 02 10:49:55 2006 -0700
+++ b/src/OSS/audio.c	Mon Oct 02 11:29:31 2006 -0700
@@ -19,6 +19,8 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+extern void close_mixer_device();
+
 #include <glib.h>
 #include <audacious/util.h>
 #include <string.h>
@@ -497,6 +499,8 @@
     oss_free_convert_buffer();
     wr_index = 0;
     rd_index = 0;
+
+    close_mixer_device();
 }
 
 void
--- a/src/OSS/mixer.c	Mon Oct 02 10:49:55 2006 -0700
+++ b/src/OSS/mixer.c	Mon Oct 02 11:29:31 2006 -0700
@@ -19,7 +19,6 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-
 #include <glib.h>
 #include <stdio.h>
 #include <string.h>
@@ -31,12 +30,16 @@
 
 #include "OSS.h"
 
+static int fd = -1;
 
-static char *
-get_mixer_device(void)
+static int
+open_mixer_device()
 {
     char *name;
 
+    if (fd != -1)
+        return 0;
+
     if (oss_cfg.use_alt_mixer_device && oss_cfg.alt_mixer_device)
         name = g_strdup(oss_cfg.alt_mixer_device);
     else if (oss_cfg.mixer_device > 0)
@@ -44,52 +47,47 @@
     else
         name = g_strdup(DEV_MIXER);
 
-    return name;
+    if ((fd = open(name, O_RDWR)) == -1) {
+        g_free(name);
+        return 1;
+    }
+    g_free(name);
+
+    return 0;
 }
 
 void
 oss_get_volume(int *l, int *r)
 {
-    int fd, v, devs;
+    int v, devs;
     long cmd;
-    gchar *devname;
-
-    devname = get_mixer_device();
-    fd = open(devname, O_RDONLY);
-    g_free(devname);
 
     /*
      * We dont show any errors if this fails, as this is called
      * rather often
      */
-    if (fd != -1) {
+    if (!open_mixer_device()) {
         ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
         if ((devs & SOUND_MASK_PCM) && (oss_cfg.use_master == 0))
             cmd = SOUND_MIXER_READ_PCM;
         else if ((devs & SOUND_MASK_VOLUME) && (oss_cfg.use_master == 1))
             cmd = SOUND_MIXER_READ_VOLUME;
-        else {
-            close(fd);
+        else
             return;
-        }
+
         ioctl(fd, cmd, &v);
         *r = (v & 0xFF00) >> 8;
         *l = (v & 0x00FF);
-        close(fd);
     }
 }
 
 void
 oss_set_volume(int l, int r)
 {
-    int fd, v, devs;
+    int v, devs;
     long cmd;
-    gchar *devname;
 
-    devname = get_mixer_device();
-    fd = open(devname, O_RDONLY);
-
-    if (fd != -1) {
+    if (!open_mixer_device()) {
         ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs);
         if ((devs & SOUND_MASK_PCM) && (oss_cfg.use_master == 0))
             cmd = SOUND_MIXER_WRITE_PCM;
@@ -101,10 +99,16 @@
         }
         v = (r << 8) | l;
         ioctl(fd, cmd, &v);
-        close(fd);
     }
     else
-        g_warning("oss_set_volume(): Failed to open mixer device (%s): %s",
-                  devname, strerror(errno));
-    g_free(devname);
+        g_warning("Failed to open mixer device: %s", strerror(errno));
 }
+
+void
+close_mixer_device()
+{
+    if (fd != -1) {
+        close(fd);
+        fd = -1;
+    }
+}