[xiph-commits] r3727 - libsydneyaudio/trunk/src
j at svn.annodex.net
j at svn.annodex.net
Mon Oct 13 04:08:58 PDT 2008
Author: j
Date: 2008-10-13 04:08:57 -0700 (Mon, 13 Oct 2008)
New Revision: 3727
Modified:
libsydneyaudio/trunk/src/sydney_audio_alsa.c
libsydneyaudio/trunk/src/sydney_audio_mac.c
libsydneyaudio/trunk/src/sydney_audio_waveapi.c
Log:
implement sa_stream_drain in waveapi, alsa and mac backend, fixes #428
Modified: libsydneyaudio/trunk/src/sydney_audio_alsa.c
===================================================================
--- libsydneyaudio/trunk/src/sydney_audio_alsa.c 2008-10-10 11:46:07 UTC (rev 3726)
+++ libsydneyaudio/trunk/src/sydney_audio_alsa.c 2008-10-13 11:08:57 UTC (rev 3727)
@@ -539,7 +539,34 @@
}
+int
+sa_stream_drain(sa_stream_t *s)
+{
+ if (s == NULL || s->output_unit == NULL) {
+ return SA_ERROR_NO_INIT;
+ }
+ while (1) {
+ pthread_mutex_lock(&s->mutex);
+ sa_buf * b;
+ size_t used = 0;
+ for (b = s->bl_head; b != NULL; b = b->next) {
+ used += b->end - b->start;
+ }
+ pthread_mutex_unlock(&s->mutex);
+
+ if (used == 0) {
+ break;
+ }
+
+ struct timespec ts = {0, 1000000};
+ nanosleep(&ts, NULL);
+ }
+ return SA_SUCCESS;
+}
+
+
+
/*
* -----------------------------------------------------------------------------
* Extension functions
@@ -703,7 +730,6 @@
UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
-UNSUPPORTED(int sa_stream_drain(sa_stream_t *s))
const char *sa_strerror(int code) { return NULL; }
Modified: libsydneyaudio/trunk/src/sydney_audio_mac.c
===================================================================
--- libsydneyaudio/trunk/src/sydney_audio_mac.c 2008-10-10 11:46:07 UTC (rev 3726)
+++ libsydneyaudio/trunk/src/sydney_audio_mac.c 2008-10-13 11:08:57 UTC (rev 3727)
@@ -590,7 +590,34 @@
}
+int
+sa_stream_drain(sa_stream_t *s)
+{
+ if (s == NULL || s->output_unit == NULL) {
+ return SA_ERROR_NO_INIT;
+ }
+ while (1) {
+ pthread_mutex_lock(&s->mutex);
+ sa_buf * b;
+ size_t used = 0;
+ for (b = s->bl_head; b != NULL; b = b->next) {
+ used += b->end - b->start;
+ }
+ pthread_mutex_unlock(&s->mutex);
+
+ if (used == 0) {
+ break;
+ }
+
+ struct timespec ts = {0, 1000000};
+ nanosleep(&ts, NULL);
+ }
+ return SA_SUCCESS;
+}
+
+
+
/*
* -----------------------------------------------------------------------------
* Extension functions
@@ -691,7 +718,6 @@
UNSUPPORTED(int sa_stream_pwrite(sa_stream_t *s, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
UNSUPPORTED(int sa_stream_pwrite_ni(sa_stream_t *s, unsigned int channel, const void *data, size_t nbytes, int64_t offset, sa_seek_t whence))
UNSUPPORTED(int sa_stream_get_read_size(sa_stream_t *s, size_t *size))
-UNSUPPORTED(int sa_stream_drain(sa_stream_t *s))
const char *sa_strerror(int code) { return NULL; }
Modified: libsydneyaudio/trunk/src/sydney_audio_waveapi.c
===================================================================
--- libsydneyaudio/trunk/src/sydney_audio_waveapi.c 2008-10-10 11:46:07 UTC (rev 3726)
+++ libsydneyaudio/trunk/src/sydney_audio_waveapi.c 2008-10-13 11:08:57 UTC (rev 3727)
@@ -296,7 +296,22 @@
return SA_SUCCESS;
}
+/** Block until all audio has been played */
+int sa_stream_drain(sa_stream_t *s) {
+ ERROR_IF_NO_INIT(s);
+
+ /* wait for all blocks to complete */
+ EnterCriticalSection(&(s->waveCriticalSection));
+ while(s->waveFreeBlockCount < BLOCK_COUNT) {
+ LeaveCriticalSection(&(s->waveCriticalSection));
+ Sleep(10);
+ EnterCriticalSection(&(s->waveCriticalSection));
+ }
+ LeaveCriticalSection(&(s->waveCriticalSection));
+ return SA_SUCCESS;
+}
+
/*
* -----------------------------------------------------------------------------
* Private WAVE API specific functions
@@ -674,8 +689,5 @@
/** Query how much can be written without blocking */
UNSUPPORTED(int sa_stream_get_write_size(sa_stream_t *s, size_t *size))
-/** Block until all audio has been played */
-UNSUPPORTED(int sa_stream_drain(sa_stream_t *s))
-
/** Return a human readable error */
const char *sa_strerror(int code);
More information about the commits
mailing list