X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=oss_write.c;h=35f7b6280115ec53bf88d5f2e303e34f8cc45d98;hp=5b910742e3ada1ac084bac89183d3b8e75d03852;hb=2ba45411ace62b419ce03a085491077deea38878;hpb=5414dfd4356e63634f1a4e94382d14e200759d18 diff --git a/oss_write.c b/oss_write.c index 5b910742..35f7b628 100644 --- a/oss_write.c +++ b/oss_write.c @@ -189,6 +189,7 @@ static int oss_post_select(__a_unused struct sched *s, void *context) size_t frames, bytes; int ret; char *data; + audio_buf_info abi; ret = task_get_notification(wn->task); if (ret < 0) @@ -220,6 +221,15 @@ static int oss_post_select(__a_unused struct sched *s, void *context) ret = 0; if (!FD_ISSET(powd->fd, &s->wfds)) goto out; + /* get maximal number of bytes that can be written */ + ret = ioctl(powd->fd, SNDCTL_DSP_GETOSPACE, &abi); + if (ret >= 0) { + size_t max_frames = abi.bytes / powd->bytes_per_frame; + if (max_frames == 0) + goto out; + /* cap number of frames to avoid sound artefacts */ + frames = PARA_MIN(frames, max_frames); + } ret = xwrite(powd->fd, data, frames * powd->bytes_per_frame); if (ret < 0) goto out;