changeset 3048:c269a0351b53

ported OSS4
author Michal Lipski <tallica@o2.pl>
date Fri, 17 Apr 2009 17:31:14 +0200
parents 4434b4c4a715
children 9ec8a613a1d6
files src/OSS4/OSS4.c src/OSS4/OSS4.h src/OSS4/audio.c
diffstat 3 files changed, 108 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/OSS4/OSS4.c	Fri Apr 17 16:17:10 2009 +0300
+++ b/src/OSS4/OSS4.c	Fri Apr 17 17:31:14 2009 +0200
@@ -57,7 +57,7 @@
                      G_CALLBACK(gtk_widget_destroyed), &dialog);
 }
 
-static void oss_init(void)
+static OutputPluginInitStatus oss_init(void)
 {
     mcs_handle_t *db;
 
@@ -81,9 +81,19 @@
         aud_cfg_db_get_int(db, "OSS", "saved_volume", &vol);
         aud_cfg_db_close(db);
     }
-        //volume gets saved anyway, but is ignored unless "saved_volume" is true
-        if(!oss_cfg.save_volume)
-            vol=0x6464;  //maximum
+    
+    //volume gets saved anyway, but is ignored unless "saved_volume" is true
+    if(!oss_cfg.save_volume)
+        vol = 0x6464;  //maximum
+            
+    if (!oss_hardware_present())
+    {
+        return OUTPUT_PLUGIN_INIT_NO_DEVICES;
+    }
+    else
+    {
+        return OUTPUT_PLUGIN_INIT_FOUND_DEVICES;
+    }
 }
 
 static void oss_cleanup(void)
@@ -101,7 +111,8 @@
 }
 
 static OutputPlugin oss4_op = {
-    .description = "OSS4 Output Plugin",                      /* Description */
+    .description = "OSS4 Output Plugin",
+    .probe_priority = 1,
     .init = oss_init,
     .cleanup = oss_cleanup,
     .about = oss_about,
--- a/src/OSS4/OSS4.h	Fri Apr 17 16:17:10 2009 +0300
+++ b/src/OSS4/OSS4.h	Fri Apr 17 17:31:14 2009 +0200
@@ -49,7 +49,7 @@
 extern OSSConfig oss_cfg;
 int vol;
 void oss_configure(void);
-
+int oss_hardware_present(void);
 void oss_get_volume(int *l, int *r);
 void oss_set_volume(int l, int r);
 
--- a/src/OSS4/audio.c	Fri Apr 17 16:17:10 2009 +0300
+++ b/src/OSS4/audio.c	Fri Apr 17 17:31:14 2009 +0200
@@ -19,7 +19,8 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-extern void close_mixer_device();
+static void oss_describe_error();
+static void close_mixer_device();
 
 #include <glib.h>
 #include <string.h>
@@ -35,7 +36,8 @@
 
 #define NFRAGS		32
 
-static gint fd = 0;
+static gint fd = -1, mixerfd = -1;
+static oss_sysinfo sysinfo;
 static char *buffer;
 static gboolean going, prebuffer, paused, unpause, do_pause, remove_prebuffer;
 static gint device_buffer_used, buffer_size, prebuffer_size, blk_size;
@@ -83,6 +85,82 @@
  */
 struct format_info output;
 
+int oss_hardware_present()
+{    
+    /*
+     * Open the mixer device used for calling SNDCTL_SYSINFO and
+     * SNDCTL_AUDIOINFO.
+     */
+    if ((mixerfd = open("/dev/mixer", O_RDWR, 0)) == -1)
+    {
+        perror("/dev/mixer");
+        oss_describe_error();
+        close_mixer_device();
+        
+        return 0;
+    }
+
+    if (ioctl(mixerfd, SNDCTL_SYSINFO, &sysinfo) == -1)
+    {
+        perror("SNDCTL_SYSINFO");
+        oss_describe_error();
+        close_mixer_device();
+
+        return 0;
+    }
+    else
+    {
+        close_mixer_device();
+        
+        if (sysinfo.numaudios > 0)
+        {
+            return 1;
+        }
+        else
+        {
+            return 0;
+        }
+    }
+}
+
+static void
+oss_describe_error()
+{
+    switch (errno)
+    {
+        case ENXIO:
+            fprintf(stderr, "OSS has not detected any supported sound hardware in your system.\n");
+            break;
+            
+        case EINVAL:
+            fprintf(stderr, "Error: OSS version 4.0 or later is required\n");
+            break;
+
+        case ENODEV:
+            fprintf(stderr, "The device file was found in /dev but\n"
+            "OSS is not loaded. You need to load it by executing\n"
+            "the soundon command.\n");
+            break;
+
+        case ENOSPC:
+            fprintf(stderr, "Your system cannot allocate memory for the device\n"
+            "buffers. Reboot your machine and try again.\n");
+            break;
+
+        case ENOENT:
+            fprintf(stderr, "The device file is missing from /dev.\n"
+            "Perhaps you have not installed and started Open Sound System yet\n");
+            break;
+
+        case EBUSY:
+            fprintf(stderr, "The device is busy. There is some other application\n"
+            "using it.\n");
+            break;
+
+        default:
+             fprintf(stderr, "Unknown OSS error.\n");
+    }
+}
 
 static void
 oss_calc_device_buffer_used(void)
@@ -734,6 +812,15 @@
 void
 close_mixer_device()
 {
+    if (fd != -1)
+    {
+        close(fd);
+        fd = -1;
+    }
+    
+    if (mixerfd != -1)
+    {
+        close(mixerfd);
+        mixerfd = -1;
+    }
 }
-
-