From cc401d8999ed29f5dbc1e3f8e8594eca837fe15a Mon Sep 17 00:00:00 2001 From: sletz Date: Wed, 22 Nov 2006 16:09:12 +0000 Subject: [PATCH] Improve synchronous mode git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1305 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackAudioDriver.cpp | 23 ++++++++++++----------- common/JackDriver.cpp | 2 +- common/JackEngine.cpp | 21 ++++++++++++++------- common/JackEngine.h | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/common/JackAudioDriver.cpp b/common/JackAudioDriver.cpp index ae3ea0a4..952d1c29 100644 --- a/common/JackAudioDriver.cpp +++ b/common/JackAudioDriver.cpp @@ -191,17 +191,18 @@ int JackAudioDriver::ProcessSync() if (fIsMaster) { - fEngine->Process(fLastWaitUst); // fLastWaitUst is set in the "low level" layer - fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); - - if (ProcessSlaves() < 0) - jack_error("JackAudioDriver::ProcessSync ProcessSlaves error, engine may now behave abnormally!!"); - - if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) - jack_error("JackAudioDriver::ProcessSync SuspendRefNum error, engine may now behave abnormally!!"); - - if (Write() < 0) // Write output buffers for the current cycle - jack_error("Process: write error"); + if (fEngine->Process(fLastWaitUst)) { // fLastWaitUst is set in the "low level" layer + fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); + if (ProcessSlaves() < 0) + jack_error("JackAudioDriver::ProcessSync ProcessSlaves error, engine may now behave abnormally!!"); + if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) + jack_error("JackAudioDriver::ProcessSync SuspendRefNum error, engine may now behave abnormally!!"); + } else { // Graph not finished: do not activate it + jack_error("JackAudioDriver::ProcessSync: error"); + } + + if (Write() < 0) // Write output buffers for the current cycle + jack_error("Process: write error"); } else { fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); diff --git a/common/JackDriver.cpp b/common/JackDriver.cpp index 591601f2..9eb025b9 100644 --- a/common/JackDriver.cpp +++ b/common/JackDriver.cpp @@ -133,7 +133,7 @@ int JackDriver::Open(jack_nframes_t nframes, fEngineControl->fPeriodUsecs = (jack_time_t)floor((((float)nframes) / (float)samplerate) * 1000000.0f); if (fEngineControl->fTimeOutUsecs == 0) /* usecs; if zero, use 10 period size. */ - fEngineControl->fTimeOutUsecs = (jack_time_t)(10.f * fEngineControl->fPeriodUsecs); + fEngineControl->fTimeOutUsecs = (jack_time_t)(2.f * fEngineControl->fPeriodUsecs); fGraphManager->DirectConnect(fClientControl->fRefNum, fClientControl->fRefNum); // Connect driver to itself for sync diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index e313ea46..28ed46a8 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -98,8 +98,9 @@ int JackEngine::Close() // Graph management //------------------ -void JackEngine::Process(jack_time_t callback_usecs) -{ +bool JackEngine::Process(jack_time_t callback_usecs) +{ + bool res = true; // Transport fEngineControl->fTransport.CycleBegin(fEngineControl->fSampleRate, callback_usecs); @@ -114,26 +115,32 @@ void JackEngine::Process(jack_time_t callback_usecs) fLastSwitchUsecs = callback_usecs; if (fGraphManager->RunNextGraph()) // True if the graph actually switched to a new state fChannel->ClientNotify(ALL_CLIENTS, JackNotifyChannelInterface::kGraphOrderCallback, 0); - fSignal->SignalAll(); // Signal for threads waiting for next cycle + fSignal->SignalAll(); // Signal for threads waiting for next cycle + //jack_error("Process: finished!\n"); + res = true; } else { - JackLog("Process: graph not finished!\n"); + JackLog("Process: graph not finished!\n"); + //jack_error("Process: graph not finished!\n"); if (callback_usecs > fLastSwitchUsecs + fEngineControl->fTimeOutUsecs) { JackLog("Process: switch to next state %ld\n", long(callback_usecs - fLastSwitchUsecs)); //RemoveZombifiedClients(callback_usecs); TODO fLastSwitchUsecs = callback_usecs; if (fGraphManager->RunNextGraph()) fChannel->ClientNotify(ALL_CLIENTS, JackNotifyChannelInterface::kGraphOrderCallback, 0); - fSignal->SignalAll(); // Signal for threads waiting for next cycle + fSignal->SignalAll(); // Signal for threads waiting for next cycle + res = true; } else { JackLog("Process: waiting to switch %ld\n", long(callback_usecs - fLastSwitchUsecs)); if (callback_usecs < fLastSwitchUsecs + 2 * fEngineControl->fPeriodUsecs) // Signal XRun only for the first failling cycle CheckXRun(callback_usecs); - fGraphManager->RunCurrentGraph(); + fGraphManager->RunCurrentGraph(); + res = false; } } // Transport - fEngineControl->fTransport.CycleEnd(fClientTable, fEngineControl->fSampleRate, fEngineControl->fBufferSize); + fEngineControl->fTransport.CycleEnd(fClientTable, fEngineControl->fSampleRate, fEngineControl->fBufferSize); + return res; } /* diff --git a/common/JackEngine.h b/common/JackEngine.h index 63f2947b..59f7c817 100644 --- a/common/JackEngine.h +++ b/common/JackEngine.h @@ -96,7 +96,7 @@ class JackEngine int SetTimebaseCallback(int refnum, int conditional); // Graph - void Process(jack_time_t callback_usecs); + bool Process(jack_time_t callback_usecs); void ZombifyClient(int refnum); // Notifications -- 2.11.4.GIT