diff --git a/ChangeLog b/ChangeLog index 0fee1f4a..3006b9f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,10 @@ Fernando Lopez-Lezcano Jackdmp changes log --------------------------- +2008-04-28 Stephane Letz + + * Add exceptions management to distinguish drivers recoverable errors from non recoverable ones. Will be used in special threaded drivers (for network). + 2008-04-25 Stephane Letz * Correct JackServerGlobals::Init: now check is server is already started. diff --git a/common/JackAudioDriver.cpp b/common/JackAudioDriver.cpp index d0eceee4..2a6f688d 100644 --- a/common/JackAudioDriver.cpp +++ b/common/JackAudioDriver.cpp @@ -30,6 +30,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackPort.h" #include "JackGraphManager.h" #include "JackEngine.h" +#include "JackException.h" #include namespace Jack @@ -175,7 +176,12 @@ int JackAudioDriver::Write() int JackAudioDriver::Process() { - return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync(); + try { + return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync(); + } catch (JackException e) { + e.PrintMessage(); + return -1; + } } /* @@ -186,13 +192,13 @@ synchronize to the end of client graph execution. int JackAudioDriver::ProcessAsync() { if (Read() < 0) { // Read input buffers for the current cycle - jack_error("ProcessAsync: read error"); - return 0; + jack_error("ProcessAsync: read error, skip cycle"); + return -1; } if (Write() < 0) { // Write output buffers from the previous cycle - jack_error("ProcessAsync: write error"); - return 0; + jack_error("ProcessAsync: write error, skip cycle"); + return -1; } if (fIsMaster) { @@ -215,8 +221,8 @@ output buffers computed at the *current cycle* are used. int JackAudioDriver::ProcessSync() { if (Read() < 0) { // Read input buffers for the current cycle - jack_error("ProcessSync: read error"); - return 0; + jack_error("ProcessSync: read error, skip cycle"); + return -1; } if (fIsMaster) { @@ -231,9 +237,11 @@ int JackAudioDriver::ProcessSync() jack_error("ProcessSync: error"); } - if (Write() < 0) // Write output buffers for the current cycle - jack_error("ProcessSync: write error"); - + if (Write() < 0) { // Write output buffers for the current cycle + jack_error("ProcessSync: write error, skip cycle"); + return -1; + } + } else { fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); } diff --git a/common/JackDummyDriver.cpp b/common/JackDummyDriver.cpp index 79f7f8f7..c73abd2c 100644 --- a/common/JackDummyDriver.cpp +++ b/common/JackDummyDriver.cpp @@ -21,7 +21,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackDummyDriver.h" #include "JackEngineControl.h" #include "JackGraphManager.h" -#include "driver_interface.h" #include "JackDriverLoader.h" #include "JackThreadedDriver.h" #include diff --git a/common/JackFreewheelDriver.cpp b/common/JackFreewheelDriver.cpp index 9f5029d5..c84cc9ab 100644 --- a/common/JackFreewheelDriver.cpp +++ b/common/JackFreewheelDriver.cpp @@ -36,8 +36,10 @@ int JackFreewheelDriver::Process() fLastWaitUst = GetMicroSeconds(); fEngine->Process(fLastWaitUst); fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); // Signal all clients - if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, 10 * 1000000) < 0) // Wait for all clients to finish for 10 sec + if (fGraphManager->SuspendRefNum(fClientControl, fSynchroTable, 10 * 1000000) < 0) { // Wait for all clients to finish for 10 sec jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); + return -1; + } } else { fGraphManager->ResumeRefNum(fClientControl, fSynchroTable); // Signal all clients if (fEngineControl->fSyncMode) { diff --git a/common/JackThread.h b/common/JackThread.h index 8954bc6a..c0542e93 100644 --- a/common/JackThread.h +++ b/common/JackThread.h @@ -86,6 +86,15 @@ class JackThread virtual int AcquireRealTime() = 0; virtual int AcquireRealTime(int priority) = 0; virtual int DropRealTime() = 0; + + virtual bool GetRunning() + { + return fRunning; + } + virtual void SetRunning(bool state) + { + fRunning = state; + } virtual void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX... {} diff --git a/common/JackThreadedDriver.cpp b/common/JackThreadedDriver.cpp index 8f58c19e..e7d45e21 100644 --- a/common/JackThreadedDriver.cpp +++ b/common/JackThreadedDriver.cpp @@ -27,6 +27,7 @@ #include "JackGlobals.h" #include "JackClient.h" #include "JackEngineControl.h" +#include "JackException.h" namespace Jack { @@ -86,7 +87,15 @@ int JackThreadedDriver::Stop() bool JackThreadedDriver::Execute() { - return (Process() == 0); + try { + // Keep running even in case of error + Process(); + return true; + } catch (JackException e) { + e.PrintMessage(); + jack_error("Driver is stopped"); + return false; + } } bool JackThreadedDriver::Init() @@ -94,4 +103,21 @@ bool JackThreadedDriver::Init() return fDriver->Init(); } +bool JackRestartThreadedDriver::Execute() +{ + while (fThread->GetRunning()) { + try { + // Keep running even in case of error + while (true) { + Process(); + } + } catch (JackException e) { + e.PrintMessage(); + jack_log("Driver is restarted..."); + Init(); + } + } + return false; +} + } // end of namespace diff --git a/common/JackThreadedDriver.h b/common/JackThreadedDriver.h index 7c339a48..759574b5 100644 --- a/common/JackThreadedDriver.h +++ b/common/JackThreadedDriver.h @@ -34,7 +34,7 @@ namespace Jack class JackThreadedDriver : public JackDriverClientInterface, public JackRunnableInterface { - private: + protected: JackThread* fThread; JackDriverClient* fDriver; @@ -143,11 +143,25 @@ class JackThreadedDriver : public JackDriverClientInterface, public JackRunnable } // JackRunnableInterface interface - bool Execute(); - bool Init(); + virtual bool Execute(); + virtual bool Init(); }; +class JackRestartThreadedDriver : public JackThreadedDriver +{ + public: + + JackRestartThreadedDriver(JackDriverClient* driver):JackThreadedDriver(driver) + {} + virtual ~JackRestartThreadedDriver() + {} + + // JackRunnableInterface interface + virtual bool Execute(); +}; + + } // end of namespace diff --git a/macosx/JackCoreAudioDriver.cpp b/macosx/JackCoreAudioDriver.cpp index c4ca1839..6a6a9048 100644 --- a/macosx/JackCoreAudioDriver.cpp +++ b/macosx/JackCoreAudioDriver.cpp @@ -25,7 +25,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackClientControl.h" #include "JackDriverLoader.h" #include "JackGlobals.h" -#include "driver_interface.h" #include namespace Jack