audio thread locking fixes

This commit is contained in:
Charles J. Cliffe 2015-02-11 21:35:27 -05:00
parent cbde77e0f1
commit 261d2dbe5f
2 changed files with 26 additions and 2 deletions

View File

@ -166,9 +166,22 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
std::cout << "Audio buffer underflow.." << (src->underflowCount++) << std::endl; std::cout << "Audio buffer underflow.." << (src->underflowCount++) << std::endl;
} }
if (src->terminated || !src->active) {
if (src->currentInput) {
src->currentInput->decRefCount();
src->currentInput = NULL;
}
return 1;
}
if (!src->currentInput) { if (!src->currentInput) {
if (src->inputQueue->empty()) {
return 0;
}
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated || !src->active) { if (src->terminated || !src->active) {
src->currentInput->decRefCount();
src->currentInput = NULL;
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -188,6 +201,8 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
} }
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated || !src->active) { if (src->terminated || !src->active) {
src->currentInput->decRefCount();
src->currentInput = NULL;
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -207,6 +222,8 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
} }
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated || !src->active) { if (src->terminated || !src->active) {
src->currentInput->decRefCount();
src->currentInput = NULL;
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -228,6 +245,8 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
} }
src->inputQueue->pop(src->currentInput); src->inputQueue->pop(src->currentInput);
if (src->terminated || !src->active) { if (src->terminated || !src->active) {
src->currentInput->decRefCount();
src->currentInput = NULL;
return 1; return 1;
} }
src->audioQueuePtr = 0; src->audioQueuePtr = 0;
@ -336,12 +355,12 @@ void AudioThread::setupDevice(int deviceId) {
dac.closeStream(); dac.closeStream();
} }
active = true;
if (deviceId != -1) { if (deviceId != -1) {
active = true;
dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts); dac.openStream(&parameters, NULL, RTAUDIO_FLOAT32, sampleRate, &bufferFrames, &audioCallback, (void *) this, &opts);
dac.startStream(); dac.startStream();
} else { } else {
active = false;
AudioThreadInput *dummy; AudioThreadInput *dummy;
while (!inputQueue->empty()) { // flush queue while (!inputQueue->empty()) { // flush queue
inputQueue->pop(dummy); inputQueue->pop(dummy);
@ -487,6 +506,7 @@ void AudioThread::setActive(bool state) {
AudioThreadCommand command; AudioThreadCommand command;
command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE; command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE;
command.int_value = -1; command.int_value = -1;
cmdQueue.push(command);
} }
#endif #endif

View File

@ -26,6 +26,10 @@
#define USE_MIXER 1 #define USE_MIXER 1
#endif #endif
#ifdef __WINDOWS_DS__
#define USE_MIXER 1
#endif
class AudioThreadInput: public ReferenceCounter { class AudioThreadInput: public ReferenceCounter {
public: public:
long long frequency; long long frequency;