#include <CoreAudio/CoreAudio.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/DefaultAudioOutput.h>
-#include <semaphore.h>
struct osx_buffer {
float *buffer;
long size;
short *ptr;
AudioUnit output;
char play;
- sem_t *semaphore;
osx_buffer *from; /* Current buffers */
osx_buffer *to;
unsigned samplerate;
(*ptrptr)->buffer = NULL;
ptrptr = &(*ptrptr)->next;
/* This buffer is ready for filling (of course, it is empty!) */
- sem_post(powd->semaphore);
}
*ptrptr = powd->from = powd->to;
}
dest = outOutputData->mBuffers[i].mData;
while (m > 0) {
if ((n = powd->from->remaining) <= 0) {
+ PARA_INFO_LOG("%s", "buffer underrun\n");
/* no more bytes in the current read buffer! */
while ((n = powd->from->remaining) <= 0)
/* wait for the results */
/* remember all done work */
m -= n;
powd->from->ptr += n;
- if ((powd->from->remaining -= n) <= 0) {
- /* tell that there's a buffer to fill */
- sem_post(powd->semaphore);
+ if ((powd->from->remaining -= n) <= 0)
powd->from = powd->from->next;
- }
}
}
return 0;
Component comp;
AURenderCallbackStruct inputCallback = {osx_callback, powd};
AudioStreamBasicDescription format;
- char s[10];
- int m, ret;
+ int ret;
struct writer_node_group *wng = wn->wng;
struct osx_write_args_info *conf = wn->conf;
kAudioUnitScope_Input, 0, &format,
sizeof(AudioStreamBasicDescription)))
goto e2;
- /* init the semaphore */
- strcpy(s, "/mpg123-0000");
- do {
- for (m = 10;; m--)
- if( (s[m]++) <= '9')
- break;
- else
- s[m] = '0';
- } while ((powd->semaphore = sem_open(s, O_CREAT | O_EXCL, 0644, 0))
- == (sem_t *)SEM_FAILED);
init_buffers(powd);
ret = -E_ADD_CALLBACK;
if (AudioUnitSetProperty(powd->output, kAudioUnitProperty_SetRenderCallback,
AudioUnitUninitialize(powd->output);
CloseComponent(powd->output);
destroy_buffers(powd);
- sem_close(powd->semaphore);
free(powd);
}