[xiph-cvs] cvs commit: ao/src/plugins/oss ao_oss.c

Stan Seibert volsung at xiph.org
Thu Aug 9 17:32:21 PDT 2001



volsung     01/08/09 17:32:21

  Modified:    src/plugins/oss ao_oss.c
  Log:
  - Fixed memory leak during plugin_test phase.
  - Fixed problem caused by the OSS emulation in ALSA.  open() would block
  if the dsp was already in use, causing the driver autodetect code to
  stall.

Revision  Changes    Path
1.9       +13 -6     ao/src/plugins/oss/ao_oss.c

Index: ao_oss.c
===================================================================
RCS file: /usr/local/cvsroot/ao/src/plugins/oss/ao_oss.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ao_oss.c	2001/08/04 22:43:38	1.8
+++ ao_oss.c	2001/08/10 00:32:20	1.9
@@ -68,15 +68,16 @@
  * open either the devfs device or the traditional device and return a
  * file handle.  Also strdup() path to the selected device into
  * *dev_path.  Assumes that *dev_path does not need to be free()'ed
- * initially.
+ * initially.  The extra_open_flags allows additional flags to be
+ * passed to open() if needed.
  */
-int _open_default_oss_device (char **dev_path)
+int _open_default_oss_device (char **dev_path, int extra_open_flags)
 {
         int fd;
 
         /* default: first try the devfs path */
         *dev_path = strdup("/dev/sound/dsp");
-	fd = open(*dev_path, O_WRONLY);
+	fd = open(*dev_path, O_WRONLY | extra_open_flags);
 
         if(fd < 0) 
         {
@@ -85,7 +86,7 @@
                 char *dev = strdup(*dev_path);
                 free(*dev_path);
                 *dev_path = strdup("/dev/dsp");
-		fd = open(*dev_path,O_WRONLY);
+		fd = open(*dev_path, O_WRONLY | extra_open_flags);
 
                 if(fd < 0) 
                 {
@@ -111,9 +112,15 @@
         char *dev_path;
         int fd;
 
-	if ( (fd = _open_default_oss_device(&dev_path)) < 0 )
+	/* OSS emulation in ALSA will by default cause the open() call
+	   to block if the dsp is in use.  This will freeze the default
+	   driver detection unless the O_NONBLOCK flag is passed to 
+	   open().  We cannot use this flag when we actually open the
+	   device for writing because then we will overflow the buffer. */
+	if ( (fd = _open_default_oss_device(&dev_path, O_NONBLOCK)) < 0 )
                 return 0; /* Cannot use this plugin with default parameters */
         else {
+		free(dev_path);
                 close(fd);
                 return 1; /* This plugin works in default mode */
         }
@@ -178,7 +185,7 @@
                 }
 
         } else {
-		internal->fd = _open_default_oss_device(&internal->dev);
+		internal->fd = _open_default_oss_device(&internal->dev, 0);
                 if (internal->fd < 0)
                         return 0;  /* Cannot open default device */
         }

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list