[xiph-commits] r3728 - libsydneyaudio/trunk/src
j at svn.annodex.net
j at svn.annodex.net
Mon Oct 13 04:12:01 PDT 2008
Author: j
Date: 2008-10-13 04:12:01 -0700 (Mon, 13 Oct 2008)
New Revision: 3728
Modified:
libsydneyaudio/trunk/src/sydney_audio_alsa.c
libsydneyaudio/trunk/src/sydney_audio_mac.c
libsydneyaudio/trunk/src/sydney_audio_waveapi.c
Log:
report actually working free space in sa_stream_get_write_size (mac, alsa) impelment sa_stream_get_write_size for waveapi patch by kinetik, fixes #427
Modified: libsydneyaudio/trunk/src/sydney_audio_alsa.c
===================================================================
--- libsydneyaudio/trunk/src/sydney_audio_alsa.c 2008-10-13 11:08:57 UTC (rev 3727)
+++ libsydneyaudio/trunk/src/sydney_audio_alsa.c 2008-10-13 11:12:01 UTC (rev 3728)
@@ -458,13 +458,12 @@
pthread_mutex_lock(&s->mutex);
/*
- * Sum up the used portions of our buffers and subtract that from
- * the pre-defined max allowed allocation.
+ * The sum of the free space in the tail buffer plus the size of any new
+ * buffers represents the write space available before blocking.
*/
- for (b = s->bl_head; b != NULL; b = b->next) {
- used += b->end - b->start;
- }
- *size = BUF_SIZE * BUF_LIMIT - used;
+ unsigned int avail = s->bl_tail->size - s->bl_tail->end;
+ avail += (BUF_LIMIT - s->n_bufs) * BUF_SIZE;
+ *size = avail;
pthread_mutex_unlock(&s->mutex);
return SA_SUCCESS;
Modified: libsydneyaudio/trunk/src/sydney_audio_mac.c
===================================================================
--- libsydneyaudio/trunk/src/sydney_audio_mac.c 2008-10-13 11:08:57 UTC (rev 3727)
+++ libsydneyaudio/trunk/src/sydney_audio_mac.c 2008-10-13 11:12:01 UTC (rev 3728)
@@ -510,15 +510,12 @@
pthread_mutex_lock(&s->mutex);
/*
- * Sum up the used portions of our buffers and subtract that from
- * the pre-defined max allowed allocation.
+ * The sum of the free space in the tail buffer plus the size of any new
+ * buffers represents the write space available before blocking.
*/
- sa_buf * b;
- size_t used = 0;
- for (b = s->bl_head; b != NULL; b = b->next) {
- used += b->end - b->start;
- }
- *size = BUF_SIZE * BUF_LIMIT - used;
+ unsigned int avail = s->bl_tail->size - s->bl_tail->end;
+ avail += (BUF_LIMIT - s->n_bufs) * BUF_SIZE;
+ *size = avail;
pthread_mutex_unlock(&s->mutex);
return SA_SUCCESS;
Modified: libsydneyaudio/trunk/src/sydney_audio_waveapi.c
===================================================================
--- libsydneyaudio/trunk/src/sydney_audio_waveapi.c 2008-10-13 11:08:57 UTC (rev 3727)
+++ libsydneyaudio/trunk/src/sydney_audio_waveapi.c 2008-10-13 11:12:01 UTC (rev 3728)
@@ -195,6 +195,26 @@
return status;
}
+/** Query how much can be written without blocking */
+int sa_stream_get_write_size(sa_stream_t *s, size_t *size) {
+ unsigned int avail;
+ WAVEHDR* current;
+
+ ERROR_IF_NO_INIT(s);
+
+ EnterCriticalSection(&(s->waveCriticalSection));
+ avail = s->waveFreeBlockCount * BLOCK_SIZE;
+ if (s->waveFreeBlockCount != BLOCK_COUNT) {
+ current = &(s->waveBlocks[s->waveCurrentBlock]);
+ avail += BLOCK_SIZE - current->dwUser;
+ }
+ LeaveCriticalSection(&(s->waveCriticalSection));
+
+ *size = avail;
+
+ return SA_SUCCESS;
+}
+
/** Close/destroy everything */
int sa_stream_destroy(sa_stream_t *s) {
int status;
@@ -686,8 +706,6 @@
/** Query how much can be read without blocking */
UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
-/** Query how much can be written without blocking */
-UNSUPPORTED(int sa_stream_get_write_size(sa_stream_t *s, size_t *size))
/** Return a human readable error */
const char *sa_strerror(int code);
More information about the commits
mailing list