From 9d727a841e5194892c4a54a42e800b7629b6ca95 Mon Sep 17 00:00:00 2001
From: Ralph Giles <giles@xiph.org>
Date: Fri, 2 Feb 2001 10:02:06 +0000
Subject: [PATCH] Try /dev/sound/dsp (the devfs default) before /dev/dsp in the
 oss output driver

also some esd doc cleanup


git-svn-id: http://svn.xiph.org/trunk/ao@1245 0101bb08-14d6-0310-b084-bc0e0c8e3800
---
 doc/DRIVERS              | 21 +++++++------------
 src/plugins/oss/ao_oss.c | 45 +++++++++++++++++++++++++++++++++-------
 2 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/doc/DRIVERS b/doc/DRIVERS
index a870250..a4f8db1 100644
--- a/doc/DRIVERS
+++ b/doc/DRIVERS
@@ -13,8 +13,8 @@ oss
 Open Sound System.  This is the audio driver system for
 Linux and Free/Net/OpenBSD as well as other UNIX-like systems.
     Option keys:
-        "dsp" - set the dsp device.  By default, this is
-                "/dev/dsp". 
+        "dsp" - set the dsp device.  By default, it tries
+                "/dev/sound/dsp", followed by "/dev/dsp". 
 
 irix
 ----
@@ -29,14 +29,6 @@ Solaris audio driver.  This was also inherited from the
 original libao.  Same caveats apply.
     Option keys: None.
 
-esd
----
-ESounD audio driver.  This driver by default connects to the ESounD
-Daemon on the localhost.
-    Option keys:
-        "host" - The hostname where esd is running.  This can include
-                 a port number after a colon, as in "whizbang.com:555".
-
 alsa
 ----
 Advanced Linux Sound Architecture.  This driver borrows some code from
@@ -52,11 +44,12 @@ it to the card.
  
 esd
 ---
-ESounD audio driver.  Uses libesd to communicate with the audio
-server.
+ESounD audio driver.  This driver by default connects to the ESounD
+Daemon on the localhost.
     Option keys:
-        "host" - Hostname where esd is running.  By default, this is
-                 the localhost.
+        "host" - The hostname where esd is running. by default sound
+		 is played on the local host. A port number can be
+		 specified after a colon, as in "whizbang.com:555".
 
 wav
 ---
diff --git a/src/plugins/oss/ao_oss.c b/src/plugins/oss/ao_oss.c
index 2aa81fa..3648553 100644
--- a/src/plugins/oss/ao_oss.c
+++ b/src/plugins/oss/ao_oss.c
@@ -75,8 +75,8 @@ void ao_oss_parse_options(ao_oss_internal_t *state, ao_option_t *options)
 		options = options->next;
 	}
 
-	if (state->dev == NULL)
-		state->dev = strdup("/dev/dsp");
+	/* otherwise, the NULL setting indicates the open()
+	   routine should choose something from hardwired defaults */
 }
 
 /*
@@ -102,12 +102,40 @@ ao_internal_t *plugin_open(uint_32 bits, uint_32 rate, uint_32 channels, ao_opti
 
 	/* Open the device driver */
 	
-	state->fd=open(state->dev,O_WRONLY);
-	if(state->fd < 0) 
-	{
-		fprintf(stderr,"libao - %s: Opening audio device %s\n",
-			strerror(errno), state->dev);
-		goto ERR;
+	if (state->dev != NULL) {
+		/* open the user-specified path */
+		state->fd=open(state->dev,O_WRONLY);
+		if(state->fd < 0) 
+		{
+			fprintf(stderr,"libao - %s: Opening audio device %s\n",
+				strerror(errno), state->dev);
+			goto ERR;
+		}
+	} else {
+		/* default: first try the devfs path */
+		state->dev = strdup("/dev/sound/dsp");
+		state->fd=open(state->dev,O_WRONLY);
+		if(state->fd < 0) 
+		{
+			/* no? then try the traditional path */
+			char *err = strdup(strerror(errno));
+			char *dev = strdup(state->dev);
+			free(state->dev);
+			state->dev = strdup("/dev/dsp");
+			state->fd=open(state->dev,O_WRONLY);
+			if(state->fd < 0) 
+			{
+				fprintf(stderr,
+					"libao - error: Could not open either default device:\n"
+					"  %s - %s\n"
+					"  %s - %s\n",
+					err, dev,
+					strerror(errno), state->dev);
+				free(err);
+				free(dev);
+				goto ERR;
+			}
+		}
 	}
 
 	switch (channels)
@@ -144,6 +172,7 @@ ao_internal_t *plugin_open(uint_32 bits, uint_32 rate, uint_32 channels, ao_opti
 	if(state != NULL)
 	{ 
 		if (state->fd >= 0) { close(state->fd); }
+		if (state->dev) { free(state->dev); }
 		free(state);
 	}
 
-- 
GitLab