<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-ports.
</pre>
<p><a href="https://github.com/macports/macports-ports/commit/74492f28e0418de8cad65c41da126a03f7dc715c">https://github.com/macports/macports-ports/commit/74492f28e0418de8cad65c41da126a03f7dc715c</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new 74492f2 libsdl2: fix for dropping audio buffers
</span>74492f2 is described below
<span style='display:block; white-space:pre;color:#808000;'>commit 74492f28e0418de8cad65c41da126a03f7dc715c
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Sat Jun 8 21:15:30 2019 +1000
<span style='display:block; white-space:pre;color:#404040;'> libsdl2: fix for dropping audio buffers
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Applied upstream patch.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Closes: https://trac.macports.org/ticket/58551
</span>---
devel/libsdl2/Portfile | 5 +-
devel/libsdl2/files/dcb6c57df2fc.patch | 374 +++++++++++++++++++++++++++++++++
2 files changed, 378 insertions(+), 1 deletion(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/devel/libsdl2/Portfile b/devel/libsdl2/Portfile
</span><span style='display:block; white-space:pre;color:#808080;'>index bd260ca..5c51583 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/devel/libsdl2/Portfile
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/devel/libsdl2/Portfile
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -7,7 +7,7 @@ PortGroup xcodeversion 1.0
</span> name libsdl2
set my_name SDL2
version 2.0.9
<span style='display:block; white-space:pre;background:#ffe0e0;'>-revision 1
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+revision 2
</span> categories devel multimedia
platforms macosx freebsd
license zlib
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -32,6 +32,9 @@ patchfiles 5a95fbfd3617.patch
</span> # Fix library compatibility version
patchfiles-append d274fa9731b1.patch
<span style='display:block; white-space:pre;background:#e0ffe0;'>+# Fix dropping audio buffers, https://trac.macports.org/ticket/58551
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+patchfiles-append dcb6c57df2fc.patch
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> configure.args --without-x
build.args V=1
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/devel/libsdl2/files/dcb6c57df2fc.patch b/devel/libsdl2/files/dcb6c57df2fc.patch
</span>new file mode 100644
<span style='display:block; white-space:pre;color:#808080;'>index 0000000..27079af
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>--- /dev/null
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/devel/libsdl2/files/dcb6c57df2fc.patch
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -0,0 +1,374 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# HG changeset patch
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# User Ryan C. Gordon <icculus@icculus.org>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Date 1553531078 14400
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Node ID dcb6c57df2fc8fbf5b82d04782322f64658a5e0b
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+# Parent 36ee991073903add82a71be51943e3b650558c5a
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+Backed out changeset ffd52bb02bcc
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+This was meant to migrate CoreAudio onto the same SDL_RunAudio() path that
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+most other audio drivers are on, but it introduced a bug because it doesn't
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+deal with dropped audio buffers...and fixing that properly just introduces
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+latency.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+I might revisit this later, perhaps by reworking SDL_RunAudio to allow for
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+this sort of API better, or redesigning the whole subsystem or something, I
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+don't know. I'm not super-thrilled that this has to exist outside of the usual
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+codepaths, though.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+Fixes Bugzilla #4481.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+diff -r 36ee99107390 -r dcb6c57df2fc src/audio/SDL_audio.c
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+--- src/audio/SDL_audio.c Thu Mar 21 10:39:49 2019 -0400
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++++ src/audio/SDL_audio.c Mon Mar 25 12:24:38 2019 -0400
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -896,8 +896,6 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- current_audio.impl.PrepareToClose(device);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_audio.impl.FlushCapture(device);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_audio.impl.ThreadDeinit(device);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+diff -r 36ee99107390 -r dcb6c57df2fc src/audio/coreaudio/SDL_coreaudio.h
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+--- src/audio/coreaudio/SDL_coreaudio.h Thu Mar 21 10:39:49 2019 -0400
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++++ src/audio/coreaudio/SDL_coreaudio.h Mon Mar 25 12:24:38 2019 -0400
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -45,14 +45,16 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ struct SDL_PrivateAudioData
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_Thread *thread;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ AudioQueueRef audioQueue;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- int numAudioBuffers;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ AudioQueueBufferRef *audioBuffer;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ void *buffer;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ UInt32 bufferOffset;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ UInt32 bufferSize;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ AudioStreamBasicDescription strdesc;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_bool refill;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_AudioStream *capturestream;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_sem *ready_semaphore;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ char *thread_error;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_atomic_t shutdown;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #if MACOSX_COREAUDIO
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ AudioDeviceID deviceID;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #else
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+diff -r 36ee99107390 -r dcb6c57df2fc src/audio/coreaudio/SDL_coreaudio.m
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+--- src/audio/coreaudio/SDL_coreaudio.m Thu Mar 21 10:39:49 2019 -0400
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++++ src/audio/coreaudio/SDL_coreaudio.m Mon Mar 25 12:24:38 2019 -0400
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -26,7 +26,6 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #include "SDL_audio.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #include "SDL_hints.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-#include "SDL_timer.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #include "../SDL_audio_c.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #include "../SDL_sysaudio.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #include "SDL_coreaudio.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -410,27 +409,43 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ outputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SDL_AudioDevice *this = (SDL_AudioDevice *) inUserData;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_assert(inBuffer->mAudioDataBytesCapacity == this->hidden->bufferSize);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_memcpy(inBuffer->mAudioData, this->hidden->buffer, this->hidden->bufferSize);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_memset(this->hidden->buffer, '\0', this->hidden->bufferSize); /* zero out in case we have to fill again without new data. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- inBuffer->mAudioDataByteSize = this->hidden->bufferSize;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (SDL_AtomicGet(&this->hidden->shutdown)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return; /* don't do anything. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (!SDL_AtomicGet(&this->enabled) || SDL_AtomicGet(&this->paused)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* Supply silence if audio is not enabled or paused */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_memset(inBuffer->mAudioData, this->spec.silence, inBuffer->mAudioDataBytesCapacity);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ UInt32 remaining = inBuffer->mAudioDataBytesCapacity;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ Uint8 *ptr = (Uint8 *) inBuffer->mAudioData;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ while (remaining > 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ UInt32 len;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* Generate the data */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_LockMutex(this->mixer_lock);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ (*this->callbackspec.callback)(this->callbackspec.userdata,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->buffer, this->hidden->bufferSize);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_UnlockMutex(this->mixer_lock);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->bufferOffset = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ len = this->hidden->bufferSize - this->hidden->bufferOffset;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (len > remaining) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ len = remaining;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_memcpy(ptr, (char *)this->hidden->buffer +
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->bufferOffset, len);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ ptr = ptr + len;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ remaining -= len;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->bufferOffset += len;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ AudioQueueEnqueueBuffer(this->hidden->audioQueue, inBuffer, 0, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->refill = SDL_TRUE;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-static Uint8 *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-COREAUDIO_GetDeviceBuf(_THIS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- return this->hidden->buffer;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-COREAUDIO_WaitDevice(_THIS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- while (SDL_AtomicGet(&this->enabled) && !this->hidden->refill) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->refill = SDL_FALSE;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ inBuffer->mAudioDataByteSize = inBuffer->mAudioDataBytesCapacity;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -439,46 +454,36 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const AudioStreamPacketDescription *inPacketDescs )
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SDL_AudioDevice *this = (SDL_AudioDevice *) inUserData;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- if (SDL_AtomicGet(&this->enabled)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_AudioStream *stream = this->hidden->capturestream;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- if (SDL_AudioStreamPut(stream, inBuffer->mAudioData, inBuffer->mAudioDataByteSize) == -1) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- /* yikes, out of memory or something. I guess drop the buffer. Our WASAPI target kills the device in this case, though */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- AudioQueueEnqueueBuffer(this->hidden->audioQueue, inBuffer, 0, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->refill = SDL_TRUE;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-static int
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-COREAUDIO_CaptureFromDevice(_THIS, void *buffer, int buflen)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_AudioStream *stream = this->hidden->capturestream;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- while (SDL_AtomicGet(&this->enabled)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- const int avail = SDL_AudioStreamAvailable(stream);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- if (avail > 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- const int cpy = SDL_min(buflen, avail);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_AudioStreamGet(stream, buffer, cpy);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- return cpy;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- /* wait for more data, try again. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- while (SDL_AtomicGet(&this->enabled) && !this->hidden->refill) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->refill = SDL_FALSE;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (SDL_AtomicGet(&this->shutdown)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return; /* don't do anything. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- return 0; /* not enabled, giving up. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* ignore unless we're active. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (!SDL_AtomicGet(&this->paused) && SDL_AtomicGet(&this->enabled) && !SDL_AtomicGet(&this->paused)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ const Uint8 *ptr = (const Uint8 *) inBuffer->mAudioData;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ UInt32 remaining = inBuffer->mAudioDataByteSize;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ while (remaining > 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ UInt32 len = this->hidden->bufferSize - this->hidden->bufferOffset;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (len > remaining) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ len = remaining;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-COREAUDIO_FlushCapture(_THIS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, 1) == kCFRunLoopRunHandledSource) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- /* spin. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_memcpy((char *)this->hidden->buffer + this->hidden->bufferOffset, ptr, len);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ ptr += len;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ remaining -= len;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->bufferOffset += len;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (this->hidden->bufferOffset >= this->hidden->bufferSize) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_LockMutex(this->mixer_lock);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ (*this->callbackspec.callback)(this->callbackspec.userdata, this->hidden->buffer, this->hidden->bufferSize);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_UnlockMutex(this->mixer_lock);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->bufferOffset = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->refill = SDL_FALSE;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_AudioStreamClear(this->hidden->capturestream);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ AudioQueueEnqueueBuffer(this->hidden->audioQueue, inBuffer, 0, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -536,16 +541,25 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ update_audio_session(this, SDL_FALSE);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* if callback fires again, feed silence; don't call into the app. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_AtomicSet(&this->paused, 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (this->hidden->audioQueue) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ AudioQueueDispose(this->hidden->audioQueue, 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- if (this->hidden->capturestream) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_FreeAudioStream(this->hidden->capturestream);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (this->hidden->thread) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_AtomicSet(&this->hidden->shutdown, 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_WaitThread(this->hidden->thread, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (this->hidden->ready_semaphore) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_DestroySemaphore(this->hidden->ready_semaphore);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* AudioQueueDispose() frees the actual buffer objects. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SDL_free(this->hidden->audioBuffer);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_free(this->hidden->thread_error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SDL_free(this->hidden->buffer);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SDL_free(this->hidden);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -611,8 +625,6 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-/* this all happens in the audio thread, since it needs a separate runloop. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ static int
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ prepare_audioqueue(_THIS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -652,6 +664,19 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* Calculate the final parameters for this audio specification */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_CalculateAudioSpec(&this->spec);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* Allocate a sample buffer */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->bufferSize = this->spec.size;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->bufferOffset = iscapture ? 0 : this->hidden->bufferSize;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->buffer = SDL_malloc(this->hidden->bufferSize);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (this->hidden->buffer == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_OutOfMemory();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* Make sure we can feed the device a minimum amount of time */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ double MINIMUM_AUDIO_BUFFER_TIME_MS = 15.0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #if defined(__IPHONEOS__)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -666,7 +691,6 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ numAudioBuffers = ((int)SDL_ceil(MINIMUM_AUDIO_BUFFER_TIME_MS / msecs) * 2);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->numAudioBuffers = numAudioBuffers;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ this->hidden->audioBuffer = SDL_calloc(1, sizeof (AudioQueueBufferRef) * numAudioBuffers);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (this->hidden->audioBuffer == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ SDL_OutOfMemory();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -693,23 +717,29 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-COREAUDIO_ThreadInit(_THIS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++static int
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++audioqueue_thread(void *arg)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_AudioDevice *this = (SDL_AudioDevice *) arg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const int rc = prepare_audioqueue(this);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!rc) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- /* !!! FIXME: do this in RunAudio, and maybe block OpenDevice until ThreadInit finishes, too, to report an opening error */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_OpenedAudioDeviceDisconnected(this); /* oh well. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->thread_error = SDL_strdup(SDL_GetError());
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_SemPost(this->hidden->ready_semaphore);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-COREAUDIO_PrepareToClose(_THIS)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- /* run long enough to queue some silence, so we know our actual audio
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- has been played */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- CFRunLoopRunInMode(kCFRunLoopDefaultMode, (((this->spec.samples * 1000) / this->spec.freq) * 2) / 1000.0f, 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- AudioQueueStop(this->hidden->audioQueue, 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* init was successful, alert parent thread and start running... */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_SemPost(this->hidden->ready_semaphore);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ while (!SDL_AtomicGet(&this->hidden->shutdown)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (!this->iscapture) { /* Drain off any pending playback. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ const CFTimeInterval secs = (((this->spec.size / (SDL_AUDIO_BITSIZE(this->spec.format) / 8)) / this->spec.channels) / ((CFTimeInterval) this->spec.freq)) * 2.0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ CFRunLoopRunInMode(kCFRunLoopDefaultMode, secs, 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ static int
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -796,23 +826,28 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- /* Calculate the final parameters for this audio specification */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- SDL_CalculateAudioSpec(&this->spec);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+-
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- if (iscapture) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->capturestream = SDL_NewAudioStream(this->spec.format, this->spec.channels, this->spec.freq, this->spec.format, this->spec.channels, this->spec.freq);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- if (!this->hidden->capturestream) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- return -1; /* already set SDL_Error */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->bufferSize = this->spec.size;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- this->hidden->buffer = SDL_malloc(this->hidden->bufferSize);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- if (this->hidden->buffer == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- return SDL_OutOfMemory();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ /* This has to init in a new thread so it can get its own CFRunLoop. :/ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_AtomicSet(&this->hidden->shutdown, 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->ready_semaphore = SDL_CreateSemaphore(0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (!this->hidden->ready_semaphore) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return -1; /* oh well. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->thread = SDL_CreateThreadInternal(audioqueue_thread, "AudioQueue thread", 512 * 1024, this);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if (!this->hidden->thread) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_SemWait(this->hidden->ready_semaphore);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_DestroySemaphore(this->hidden->ready_semaphore);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ this->hidden->ready_semaphore = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ if ((this->hidden->thread != NULL) && (this->hidden->thread_error != NULL)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ SDL_SetError("%s", this->hidden->thread_error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ return (this->hidden->thread != NULL) ? 0 : -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ static void
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -832,12 +867,6 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ impl->OpenDevice = COREAUDIO_OpenDevice;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ impl->CloseDevice = COREAUDIO_CloseDevice;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ impl->Deinitialize = COREAUDIO_Deinitialize;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- impl->ThreadInit = COREAUDIO_ThreadInit;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- impl->WaitDevice = COREAUDIO_WaitDevice;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- impl->GetDeviceBuf = COREAUDIO_GetDeviceBuf;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- impl->PrepareToClose = COREAUDIO_PrepareToClose;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- impl->CaptureFromDevice = COREAUDIO_CaptureFromDevice;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+- impl->FlushCapture = COREAUDIO_FlushCapture;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #if MACOSX_COREAUDIO
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ impl->DetectDevices = COREAUDIO_DetectDevices;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+@@ -847,6 +876,7 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ impl->OnlyHasDefaultCaptureDevice = 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ #endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>++ impl->ProvidesOwnCallbackThread = 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ impl->HasCaptureSupport = 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 1; /* this audio target is available. */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span></pre><pre style='margin:0'>
</pre>