From 95454b4ad9baee43abd1d11aa3587be4c09fa98f Mon Sep 17 00:00:00 2001 From: sletz Date: Wed, 22 Nov 2006 13:42:19 +0000 Subject: [PATCH] In synchronous mode, if the driver time out is reached, the server may get desynchronized (pending signal may arrive in later cycles), use a higher time out value use in driver, and warn the use of possible mis-behaviour in case of time out. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1303 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 5 +++++ common/JackAudioDriver.cpp | 18 ++++++++++++------ common/JackConstants.h | 2 +- common/JackDriver.cpp | 15 +++++++++------ common/JackDriver.h | 4 ++-- common/JackFreewheelDriver.cpp | 6 ++++-- common/JackThreadedDriver.h | 4 ++-- windows/JackPortAudioDriver.cpp | 2 +- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e1ac66a..b2452a11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ --------------------------- Jackdmp changes log --------------------------- + +2006-11-22 Stephane Letz + + * In synchronous mode, if the driver time out is reached, the server may get desynchronized (pending signal may arrive in later cycles), + use a higher time out value use in driver, and warn the use of possible mis-behaviour in case of time out. 2006-11-08 Stephane Letz diff --git a/common/JackAudioDriver.cpp b/common/JackAudioDriver.cpp index 30158b06..ae3ea0a4 100644 --- a/common/JackAudioDriver.cpp +++ b/common/JackAudioDriver.cpp @@ -189,14 +189,20 @@ int JackAudioDriver::ProcessSync() return 0; } - if (fIsMaster) { + if (fIsMaster) { + fEngine->Process(fLastWaitUst); // fLastWaitUst is set in the "low level" layer - fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); - ProcessSlaves(); - if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) - jack_error("JackAudioDriver::ProcessSync SuspendRefNum error"); + 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"); + jack_error("Process: write error"); + } else { fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); } diff --git a/common/JackConstants.h b/common/JackConstants.h index 9b6f8c66..84bdb5b4 100644 --- a/common/JackConstants.h +++ b/common/JackConstants.h @@ -19,7 +19,7 @@ #define PRINTDEBUG -#define VERSION "0.59" +#define VERSION "0.60" #define FORK_SERVER 1 diff --git a/common/JackDriver.cpp b/common/JackDriver.cpp index 6e3a67c3..0d0dae04 100644 --- a/common/JackDriver.cpp +++ b/common/JackDriver.cpp @@ -132,8 +132,8 @@ int JackDriver::Open(jack_nframes_t nframes, strcpy(fPlaybackDriverName, playback_driver_name); fEngineControl->fPeriodUsecs = (jack_time_t)floor((((float)nframes) / (float)samplerate) * 1000000.0f); - if (fEngineControl->fTimeOutUsecs == 0) /* usecs; if zero, use 2 period size. */ - fEngineControl->fTimeOutUsecs = (jack_time_t)(2.f * fEngineControl->fPeriodUsecs); + if (fEngineControl->fTimeOutUsecs == 0) /* usecs; if zero, use 10 period size. */ + fEngineControl->fTimeOutUsecs = (jack_time_t)(10.f * fEngineControl->fPeriodUsecs); fGraphManager->DirectConnect(fClientControl->fRefNum, fClientControl->fRefNum); // Connect driver to itself for sync @@ -192,13 +192,16 @@ void JackDriverClient::RemoveSlave(JackDriverInterface* slave) fSlaveList.remove(slave); } -void JackDriverClient::ProcessSlaves() -{ +int JackDriverClient::ProcessSlaves() +{ + int res = 0; list::const_iterator it; for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) { JackDriverInterface* slave = *it; - slave->Process(); - } + if ((res = slave->Process()) < 0) + return res; + } + return res; } } // end of namespace diff --git a/common/JackDriver.h b/common/JackDriver.h index a6b22869..14472457 100644 --- a/common/JackDriver.h +++ b/common/JackDriver.h @@ -78,7 +78,7 @@ class EXPORT JackDriverInterface virtual bool GetMaster() = 0; virtual void AddSlave(JackDriverInterface* slave) = 0; virtual void RemoveSlave(JackDriverInterface* slave) = 0; - virtual void ProcessSlaves() = 0; + virtual int ProcessSlaves() = 0; virtual bool IsRealTime() = 0; @@ -112,7 +112,7 @@ class EXPORT JackDriverClient : public JackDriverClientInterface virtual bool GetMaster(); virtual void AddSlave(JackDriverInterface* slave); virtual void RemoveSlave(JackDriverInterface* slave); - virtual void ProcessSlaves(); + virtual int ProcessSlaves(); }; /*! diff --git a/common/JackFreewheelDriver.cpp b/common/JackFreewheelDriver.cpp index 2fbe4233..d9cbd2a4 100644 --- a/common/JackFreewheelDriver.cpp +++ b/common/JackFreewheelDriver.cpp @@ -37,8 +37,10 @@ int JackFreewheelDriver::Process() } else { fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); // Signal all clients if (fEngineControl->fSyncMode) { - if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) - jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); + if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, fEngineControl->fTimeOutUsecs) < 0) { + jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); + return -1; + } } } return 0; diff --git a/common/JackThreadedDriver.h b/common/JackThreadedDriver.h index 3e09bb4d..60d302d6 100644 --- a/common/JackThreadedDriver.h +++ b/common/JackThreadedDriver.h @@ -117,9 +117,9 @@ class JackThreadedDriver : public JackDriverClientInterface, public JackRunnable { fDriver->RemoveSlave(slave); } - virtual void ProcessSlaves() + virtual int ProcessSlaves() { - fDriver->ProcessSlaves(); + return fDriver->ProcessSlaves(); } virtual void PrintState() diff --git a/windows/JackPortAudioDriver.cpp b/windows/JackPortAudioDriver.cpp index d829a0d9..8be42a6e 100644 --- a/windows/JackPortAudioDriver.cpp +++ b/windows/JackPortAudioDriver.cpp @@ -223,7 +223,7 @@ int JackPortAudioDriver::Render(const void* inputBuffer, void* outputBuffer, driver->fLastWaitUst = GetMicroSeconds(); // Take callback date here driver->fInputBuffer = (float**)inputBuffer; driver->fOutputBuffer = (float**)outputBuffer; - return driver->Process(); + return (driver->Process() == 0) ? paContinue : paAbort; } int JackPortAudioDriver::Read()