cleanup debugging code and implement _dropBufferedAudio()
git-svn-id: https://svn.musicpd.org/mpd/trunk@3090 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
b9bcfeaf49
commit
6b36bf7964
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include "../log.h"
|
#include "../log.h"
|
||||||
|
|
||||||
#define BUFFER_SIZE 8192
|
#define BUFFER_SIZE 4096
|
||||||
|
|
||||||
typedef struct _OsxData {
|
typedef struct _OsxData {
|
||||||
AudioUnit au;
|
AudioUnit au;
|
||||||
@ -98,32 +98,37 @@ static void osx_finishDriver(AudioOutput * audioOutput) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void osx_dropBufferedAudio(AudioOutput * audioOutput) {
|
static void osx_dropBufferedAudio(AudioOutput * audioOutput) {
|
||||||
/* not implemented yet */
|
OsxData * od = (OsxData *)audioOutput->data;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&od->mutex);
|
||||||
|
od->go = 0;
|
||||||
|
od->len = 0;
|
||||||
|
pthread_mutex_unlock(&od->mutex);
|
||||||
|
|
||||||
|
/*if(od->started) {
|
||||||
|
AudioOutputUnitStop(od->au);
|
||||||
|
od->started = 0;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void osx_closeDevice(AudioOutput * audioOutput) {
|
static void osx_closeDevice(AudioOutput * audioOutput) {
|
||||||
OsxData * od = (OsxData *) audioOutput->data;
|
OsxData * od = (OsxData *) audioOutput->data;
|
||||||
|
|
||||||
DEBUG("entering osx_closeDevice\n");
|
|
||||||
|
|
||||||
pthread_mutex_lock(&od->mutex);
|
pthread_mutex_lock(&od->mutex);
|
||||||
od->go = 0;
|
od->go = 0;
|
||||||
while(od->len) {
|
while(od->len) {
|
||||||
DEBUG("osx_closeDevice: cond_wait\n");
|
|
||||||
pthread_cond_wait(&od->condition, &od->mutex);
|
pthread_cond_wait(&od->condition, &od->mutex);
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&od->mutex);
|
pthread_mutex_unlock(&od->mutex);
|
||||||
|
|
||||||
DEBUG("stopping au\n");
|
if(od->started) {
|
||||||
|
AudioOutputUnitStop(od->au);
|
||||||
|
od->started = 0;
|
||||||
|
}
|
||||||
|
|
||||||
AudioOutputUnitStop(od->au);
|
|
||||||
|
|
||||||
DEBUG("closing au\n");
|
|
||||||
CloseComponent(od->au);
|
CloseComponent(od->au);
|
||||||
AudioUnitUninitialize(od->au);
|
AudioUnitUninitialize(od->au);
|
||||||
|
|
||||||
DEBUG("Leaving osx_closeDevice\n");
|
|
||||||
|
|
||||||
audioOutput->open = 0;
|
audioOutput->open = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +166,6 @@ static OSStatus osx_render(void * vdata,
|
|||||||
bytesToCopy -= bytes;
|
bytesToCopy -= bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(bytesToCopy);
|
|
||||||
memcpy(buffer->mData+curpos, od->buffer+od->pos, bytesToCopy);
|
memcpy(buffer->mData+curpos, od->buffer+od->pos, bytesToCopy);
|
||||||
od->pos += bytesToCopy;
|
od->pos += bytesToCopy;
|
||||||
curpos += bytesToCopy;
|
curpos += bytesToCopy;
|
||||||
@ -193,21 +197,17 @@ static int osx_openDevice(AudioOutput * audioOutput) {
|
|||||||
desc.componentFlags = 0;
|
desc.componentFlags = 0;
|
||||||
desc.componentFlagsMask = 0;
|
desc.componentFlagsMask = 0;
|
||||||
|
|
||||||
DEBUG("finding component\n");
|
|
||||||
|
|
||||||
comp = FindNextComponent(NULL, &desc);
|
comp = FindNextComponent(NULL, &desc);
|
||||||
if(comp == 0) {
|
if(comp == 0) {
|
||||||
ERROR("Error finding OS X component\n");
|
ERROR("Error finding OS X component\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("opening component\n");
|
|
||||||
if(OpenAComponent(comp, &od->au) != noErr) {
|
if(OpenAComponent(comp, &od->au) != noErr) {
|
||||||
ERROR("Unable to open OS X component\n");
|
ERROR("Unable to open OS X component\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("initializing au\n");
|
|
||||||
if(AudioUnitInitialize(od->au) != 0) {
|
if(AudioUnitInitialize(od->au) != 0) {
|
||||||
CloseComponent(od->au);
|
CloseComponent(od->au);
|
||||||
ERROR("Unable to initialuze OS X audio unit\n");
|
ERROR("Unable to initialuze OS X audio unit\n");
|
||||||
@ -217,7 +217,6 @@ static int osx_openDevice(AudioOutput * audioOutput) {
|
|||||||
callback.inputProc = osx_render;
|
callback.inputProc = osx_render;
|
||||||
callback.inputProcRefCon = od;
|
callback.inputProcRefCon = od;
|
||||||
|
|
||||||
DEBUG("set callback\n");
|
|
||||||
if(AudioUnitSetProperty(od->au, kAudioUnitProperty_SetRenderCallback,
|
if(AudioUnitSetProperty(od->au, kAudioUnitProperty_SetRenderCallback,
|
||||||
kAudioUnitScope_Input, 0,
|
kAudioUnitScope_Input, 0,
|
||||||
&callback, sizeof(callback)) != 0)
|
&callback, sizeof(callback)) != 0)
|
||||||
@ -238,7 +237,6 @@ static int osx_openDevice(AudioOutput * audioOutput) {
|
|||||||
streamDesc.mChannelsPerFrame = audioFormat->channels;
|
streamDesc.mChannelsPerFrame = audioFormat->channels;
|
||||||
streamDesc.mBitsPerChannel = audioFormat->bits;
|
streamDesc.mBitsPerChannel = audioFormat->bits;
|
||||||
|
|
||||||
DEBUG("set format\n");
|
|
||||||
if(AudioUnitSetProperty(od->au, kAudioUnitProperty_StreamFormat,
|
if(AudioUnitSetProperty(od->au, kAudioUnitProperty_StreamFormat,
|
||||||
kAudioUnitScope_Input, 0,
|
kAudioUnitScope_Input, 0,
|
||||||
&streamDesc, sizeof(streamDesc)) != 0)
|
&streamDesc, sizeof(streamDesc)) != 0)
|
||||||
@ -249,20 +247,11 @@ static int osx_openDevice(AudioOutput * audioOutput) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("start\n");
|
|
||||||
int err = AudioOutputUnitStart(od->au);
|
|
||||||
if(err) {
|
|
||||||
ERROR("unable to start audio output: %i\n", err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
od->go = 1;
|
|
||||||
od->pos = 0;
|
od->pos = 0;
|
||||||
od->len = 0;
|
od->len = 0;
|
||||||
|
|
||||||
audioOutput->open = 1;
|
audioOutput->open = 1;
|
||||||
|
|
||||||
DEBUG("opened OS X device\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,6 +260,16 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
|||||||
int bytesToCopy;
|
int bytesToCopy;
|
||||||
int curpos;
|
int curpos;
|
||||||
|
|
||||||
|
if(!od->started) {
|
||||||
|
od->go = 1;
|
||||||
|
od->started = 1;
|
||||||
|
int err = AudioOutputUnitStart(od->au);
|
||||||
|
if(err) {
|
||||||
|
ERROR("unable to start audio output: %i\n", err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&od->mutex);
|
pthread_mutex_lock(&od->mutex);
|
||||||
|
|
||||||
curpos = od->pos+od->len;
|
curpos = od->pos+od->len;
|
||||||
@ -278,10 +277,6 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
|||||||
|
|
||||||
while(size) {
|
while(size) {
|
||||||
while(od->len >= BUFFER_SIZE) {
|
while(od->len >= BUFFER_SIZE) {
|
||||||
if(curpos!=od->pos) {
|
|
||||||
DEBUG("%i != %i\n", curpos, od->pos);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
pthread_cond_signal(&od->condition);
|
pthread_cond_signal(&od->condition);
|
||||||
pthread_cond_wait(&od->condition, &od->mutex);
|
pthread_cond_wait(&od->condition, &od->mutex);
|
||||||
}
|
}
|
||||||
@ -299,7 +294,6 @@ static int osx_play(AudioOutput * audioOutput, char * playChunk, int size) {
|
|||||||
bytesToCopy -= bytes;
|
bytesToCopy -= bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(bytesToCopy);
|
|
||||||
memcpy(od->buffer+curpos, playChunk, bytesToCopy);
|
memcpy(od->buffer+curpos, playChunk, bytesToCopy);
|
||||||
curpos += bytesToCopy;
|
curpos += bytesToCopy;
|
||||||
playChunk += bytesToCopy;
|
playChunk += bytesToCopy;
|
||||||
|
Loading…
Reference in New Issue
Block a user