aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs/audioOutput_osx.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audioOutputs/audioOutput_osx.c81
1 files changed, 55 insertions, 26 deletions
diff --git a/src/audioOutputs/audioOutput_osx.c b/src/audioOutputs/audioOutput_osx.c
index 5ed4bc5bf..c1098d97c 100644
--- a/src/audioOutputs/audioOutput_osx.c
+++ b/src/audioOutputs/audioOutput_osx.c
@@ -25,6 +25,7 @@
#include <pthread.h>
#include "../log.h"
+#include "../utils.h"
typedef struct _OsxData {
AudioUnit au;
@@ -34,7 +35,6 @@ typedef struct _OsxData {
int bufferSize;
int pos;
int len;
- int go;
int started;
} OsxData;
@@ -46,7 +46,6 @@ static OsxData * newOsxData() {
ret->pos = 0;
ret->len = 0;
- ret->go = 0;
ret->started = 0;
ret->buffer = NULL;
ret->bufferSize = 0;
@@ -104,7 +103,6 @@ static void osx_dropBufferedAudio(AudioOutput * audioOutput) {
pthread_mutex_lock(&od->mutex);
od->len = 0;
- od->go = 0;
pthread_mutex_unlock(&od->mutex);
}
@@ -112,7 +110,6 @@ static void osx_closeDevice(AudioOutput * audioOutput) {
OsxData * od = (OsxData *) audioOutput->data;
pthread_mutex_lock(&od->mutex);
- od->go = 0;
while(od->len) {
pthread_cond_wait(&od->condition, &od->mutex);
}
@@ -141,18 +138,42 @@ static OSStatus osx_render(void * vdata,
int bytesToCopy;
int curpos = 0;
- pthread_mutex_lock(&od->mutex);
-
- while((od->go || od->len) && bufferSize) {
- while(od->go && od->len < bufferSize &&
- od->len < od->bufferSize)
- {
- pthread_cond_signal(&od->condition);
- pthread_cond_wait(&od->condition, &od->mutex);
+ /*DEBUG("osx_render: enter : %i\n", (int)bufferList->mNumberBuffers);
+ DEBUG("osx_render: ioActionFlags: %p\n", ioActionFlags);
+ if(ioActionFlags) {
+ if(*ioActionFlags & kAudioUnitRenderAction_PreRender) {
+ DEBUG("prerender\n");
+ }
+ if(*ioActionFlags & kAudioUnitRenderAction_PostRender) {
+ DEBUG("post render\n");
+ }
+ if(*ioActionFlags & kAudioUnitRenderAction_OutputIsSilence) {
+ DEBUG("post render\n");
+ }
+ if(*ioActionFlags & kAudioOfflineUnitRenderAction_Preflight) {
+ DEBUG("prefilight\n");
+ }
+ if(*ioActionFlags & kAudioOfflineUnitRenderAction_Render) {
+ DEBUG("render\n");
+ }
+ if(*ioActionFlags & kAudioOfflineUnitRenderAction_Complete) {
+ DEBUG("complete\n");
}
+ }*/
+
+ //while(bufferSize) {
+ //DEBUG("osx_render: lock\n");
+ pthread_mutex_lock(&od->mutex);
+ //DEBUG("%i:%i\n", bufferSize, od->len);
+ //while(od->go && od->len < bufferSize &&
+ // od->len < od->bufferSize)
+ //{
+ // DEBUG("osx_render: wait\n");
+ // pthread_cond_wait(&od->condition, &od->mutex);
+ //}
bytesToCopy = od->len < bufferSize ? od->len : bufferSize;
- bufferSize -= bytesToCopy;
+ bufferSize = bytesToCopy;
od->len -= bytesToCopy;
if(od->pos+bytesToCopy > od->bufferSize) {
@@ -168,13 +189,18 @@ static OSStatus osx_render(void * vdata,
curpos += bytesToCopy;
if(od->pos >= od->bufferSize) od->pos = 0;
- }
+ //DEBUG("osx_render: unlock\n");
+ pthread_mutex_unlock(&od->mutex);
+ pthread_cond_signal(&od->condition);
+ //}
- buffer->mDataByteSize -= bufferSize;
+ buffer->mDataByteSize = bufferSize;
- pthread_cond_signal(&od->condition);
- pthread_mutex_unlock(&od->mutex);
+ if(!bufferSize) {
+ my_usleep(1000);
+ }
+ //DEBUG("osx_render: leave\n");
return 0;
}
@@ -260,8 +286,9 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
int bytesToCopy;
int curpos;
+ //DEBUG("osx_play: enter\n");
+
if(!od->started) {
- od->go = 1;
od->started = 1;
int err = AudioOutputUnitStart(od->au);
if(err) {
@@ -272,12 +299,15 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
pthread_mutex_lock(&od->mutex);
- curpos = od->pos+od->len;
- if(curpos >= od->bufferSize) curpos -= od->bufferSize;
-
while(size) {
- while(od->len >= od->bufferSize) {
- pthread_cond_signal(&od->condition);
+ //DEBUG("osx_play: lock\n");
+ curpos = od->pos+od->len;
+ if(curpos >= od->bufferSize) curpos -= od->bufferSize;
+
+ bytesToCopy = od->bufferSize < size ? od->bufferSize : size;
+
+ while(od->len > od->bufferSize-bytesToCopy) {
+ //DEBUG("osx_play: wait\n");
pthread_cond_wait(&od->condition, &od->mutex);
}
@@ -298,12 +328,11 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
curpos += bytesToCopy;
playChunk += bytesToCopy;
- if(curpos >= od->bufferSize) curpos = 0;
}
-
- pthread_cond_signal(&od->condition);
+ //DEBUG("osx_play: unlock\n");
pthread_mutex_unlock(&od->mutex);
+ //DEBUG("osx_play: leave\n");
return 0;
}