Skip to content
Snippets Groups Projects
Commit 9c667bfb authored by Josh Siegle's avatar Josh Siegle
Browse files

Add before stopping and starting audio callbacks in order to avoid threading errors on OS X

parent 73f66d8d
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -155,13 +155,54 @@ void AudioComponent::stopDevice()
void AudioComponent::beginCallbacks()
{
if (!isPlaying)
{
//const MessageManagerLock mmLock;
MessageManagerLock mml (Thread::getCurrentThread());
if (mml.lockWasGained())
{
std::cout << "AUDIO COMPONENT GOT THAT LOCK!" << std::endl;
} else {
std::cout << "AUDIO COMPONENT COULDN'T GET THE LOCK...RETURNING." << std::endl;
return;
}
MessageManager* mm = MessageManager::getInstance();
if (mm->isThisTheMessageThread())
std::cout << "THIS IS THE MESSAGE THREAD -- AUDIO COMPONENT" << std::endl;
else
std::cout << "NOT THE MESSAGE THREAD -- AUDIO COMPONENT" << std::endl;
restartDevice();
//const MessageManagerLock mmLock; // add a lock to prevent crashes
int64_t ms = Time::getCurrentTime().toMilliseconds();
while(Time::getCurrentTime().toMilliseconds() - ms < 50)
{
// pause to let things finish up
}
std::cout << std::endl << "Adding audio callback." << std::endl;
deviceManager.addAudioCallback(graphPlayer);
isPlaying = true;
} else {
std::cout << "beginCallbacks was called while acquisition was active." << std::endl;
}
int64_t ms = Time::getCurrentTime().toMilliseconds();
while(Time::getCurrentTime().toMilliseconds() - ms < 50)
{
// pause to let things finish up
}
}
......@@ -169,12 +210,36 @@ void AudioComponent::endCallbacks()
{
// const MessageManagerLock mmLock; // add a lock to prevent crashes
MessageManagerLock mml (Thread::getCurrentThread());
if (mml.lockWasGained())
{
std::cout << "AUDIO COMPONENT GOT THAT LOCK!" << std::endl;
}
MessageManager* mm = MessageManager::getInstance();
if (mm->isThisTheMessageThread())
std::cout << "THIS IS THE MESSAGE THREAD -- AUDIO COMPONENT" << std::endl;
else
std::cout << "NOT THE MESSAGE THREAD -- AUDIO COMPONENT" << std::endl;
std::cout << std::endl << "Removing audio callback." << std::endl;
deviceManager.removeAudioCallback(graphPlayer);
isPlaying = false;
stopDevice();
int64_t ms = Time::getCurrentTime().toMilliseconds();
while(Time::getCurrentTime().toMilliseconds() - ms < 50)
{
// pause to let things finish up
}
}
......@@ -625,12 +625,39 @@ void ControlPanel::buttonClicked(Button* button)
if (graph->enableProcessors())
{
//const MessageManagerLock mmLock;
MessageManager* mm = MessageManager::getInstance();
if (mm->isThisTheMessageThread())
std::cout << "THIS IS THE MESSAGE THREAD -- CONTROL PANEL" << std::endl;
else
std::cout << "NOT THE MESSAGE THREAD -- CONTROL PANEL" << std::endl;
//mm->stopDispatchLoop();
//if (mm->currentThreadHasLockedMessageManager())
// std::cout << "We have the lock." << std::endl;
//else
// std::cout << "We DO NOT have the lock." << std::endl;
//Thread* thread = Thread::getCurrentThread();
//if (thread != nullptr)
// std::cout << "Starting callbacks from thread named " << thread->getThreadId() << std::endl;
//else
// std::cout << "Current thread is null" << std::endl;
MessageManagerLock mml (Thread::getCurrentThread());
if (mml.lockWasGained())
{
std::cout << "GOT THAT LOCK!" << std::endl;
std::cout << "CONTROL PANEL GOT THAT LOCK!" << std::endl;
} else {
std::cout << "COULDN'T GET THE LOCK, RETURNING...!" << std::endl;
return;
}
//std::cout << "Enabling processors from " << getThreadName() << " thread." << std::endl;
......@@ -642,9 +669,14 @@ void ControlPanel::buttonClicked(Button* button)
//graph->getRecordNode()->setParameter(1,10.0f);
stopTimer();
startTimer(250); // refresh every 250 ms
audio->beginCallbacks();
masterClock->start();
startTimer(250); // refresh every 250 ms
// mm->runDispatchLoop();
}
}
......@@ -666,18 +698,32 @@ void ControlPanel::buttonClicked(Button* button)
{
//const MessageManagerLock mmLock;
Thread* thread = Thread::getCurrentThread();
if (thread != nullptr)
std::cout << "Stopping callbacks from thread named " << thread->getThreadId() << std::endl;
else
std::cout << "Current thread is null" << std::endl;
MessageManagerLock mml (Thread::getCurrentThread());
if (mml.lockWasGained())
{
std::cout << "GOT THAT LOCK!" << std::endl;
std::cout << "CONTROL PANEL GOT THAT LOCK!" << std::endl;
} else {
std::cout << "COULDN'T GET THE LOCK...RETURNING!" << std::endl;
return;
}
//std::cout << "Disabling processors from " << getThreadName() << " thread." << std::endl;
std::cout << "Control panel requesting to end callbacks." << std::endl;
audio->endCallbacks();
std::cout << "Control panel requesting to disable processors." << std::endl;
graph->disableProcessors();
refreshMeters();
masterClock->stop();
stopTimer();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment