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

Stan Seibert volsung at xiph.org
Sat Oct 4 08:08:13 PDT 2003



volsung     03/10/04 11:08:13

  Modified:    src/plugins/oss ao_oss.c
  Log:
  Patch from Warren Dukes <shank at mercury.chem.pitt.edu> to check return
  values from OSS writes to ensure all the data was written.  Closes bug
  460.

Revision  Changes    Path
1.15      +26 -4     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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ao_oss.c	23 Sep 2003 14:22:55 -0000	1.14
+++ ao_oss.c	4 Oct 2003 15:08:12 -0000	1.15
@@ -59,6 +59,7 @@
 typedef struct ao_oss_internal {
         char *dev;
         int fd;
+	int buf_size;
 } ao_oss_internal;
 
 
@@ -219,6 +220,16 @@
 
         /* Now set all of the parameters */
 
+	internal->buf_size = -1;
+	if ((ioctl(internal->fd,SNDCTL_DSP_GETBLKSIZE,
+				&(internal->buf_size)) < 0) ||
+			internal->buf_size<=0 )
+	{
+		fprintf(stderr, "libao - OSS cannot get buffer size for "
+				" devince\n");
+		goto ERR;
+	}
+
         switch (format->channels)
         {
         case 1: tmp = 0;
@@ -281,12 +292,23 @@
 int ao_plugin_play(ao_device *device, const char *output_samples, 
                 uint_32 num_bytes)
 {
+	int ret;
+	int send;
         ao_oss_internal *internal = (ao_oss_internal *) device->internal;
 
-	if (write(internal->fd, output_samples, num_bytes) < 0)
-		return 0;
-	else
-		return 1;
+	while(num_bytes > 0) {
+		send = num_bytes>internal->buf_size?
+			internal->buf_size:num_bytes;
+		ret = write(internal->fd, output_samples, send);
+
+		if (ret <= 0)
+			return 0;
+
+		num_bytes-=ret;
+		output_samples+=ret;
+	}
+
+	return 1;
 }
 
 

<p><p>--- >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