From 7bbbb4539244e3a4efe074fe3c8512a241aa215c Mon Sep 17 00:00:00 2001 From: Stan Seibert <volsung@xiph.org> Date: Sat, 4 Oct 2003 15:08:12 +0000 Subject: [PATCH] Patch from Warren Dukes <shank@mercury.chem.pitt.edu> to check return values from OSS writes to ensure all the data was written. Closes bug 460. git-svn-id: http://svn.xiph.org/trunk/ao@5401 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- src/plugins/oss/ao_oss.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/plugins/oss/ao_oss.c b/src/plugins/oss/ao_oss.c index 1647369..c7615bb 100644 --- a/src/plugins/oss/ao_oss.c +++ b/src/plugins/oss/ao_oss.c @@ -59,6 +59,7 @@ static ao_info ao_oss_info = typedef struct ao_oss_internal { char *dev; int fd; + int buf_size; } ao_oss_internal; @@ -219,6 +220,16 @@ int ao_plugin_open(ao_device *device, ao_sample_format *format) /* 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_open(ao_device *device, ao_sample_format *format) 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; } -- GitLab