| @@ -193,9 +193,9 @@ int JackAudioDriver::ProcessNull() | |||
| JackDriver::CycleTakeBeginTime(); | |||
| if (fEngineControl->fSyncMode) { | |||
| ProcessGraphSync(); | |||
| ProcessGraphSyncMaster(); | |||
| } else { | |||
| ProcessGraphAsync(); | |||
| ProcessGraphAsyncMaster(); | |||
| } | |||
| // Keep end cycle time | |||
| @@ -230,9 +230,9 @@ int JackAudioDriver::ProcessAsync() | |||
| // Process graph | |||
| if (fIsMaster) { | |||
| ProcessGraphAsync(); | |||
| ProcessGraphAsyncMaster(); | |||
| } else { | |||
| fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); | |||
| ProcessGraphAsyncSlave(); | |||
| } | |||
| // Keep end cycle time | |||
| @@ -255,12 +255,12 @@ int JackAudioDriver::ProcessSync() | |||
| // Process graph | |||
| if (fIsMaster) { | |||
| if (ProcessGraphSync() < 0) { | |||
| if (ProcessGraphSyncMaster() < 0) { | |||
| jack_error("JackAudioDriver::ProcessSync: process error, skip cycle..."); | |||
| goto end; | |||
| } | |||
| } else { | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { | |||
| if (ProcessGraphSyncSlave() < 0) { | |||
| jack_error("JackAudioDriver::ProcessSync: process error, skip cycle..."); | |||
| goto end; | |||
| } | |||
| @@ -279,27 +279,50 @@ end: | |||
| return 0; | |||
| } | |||
| void JackAudioDriver::ProcessGraphAsync() | |||
| void JackAudioDriver::ProcessGraphAsyncMaster() | |||
| { | |||
| // fBeginDateUst is set in the "low level" layer, fEndDateUst is from previous cycle | |||
| if (!fEngine->Process(fBeginDateUst, fEndDateUst)) | |||
| jack_error("JackAudioDriver::ProcessGraphAsync: Process error"); | |||
| fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); | |||
| if (ProcessSlaves() < 0) | |||
| jack_error("JackAudioDriver::ProcessGraphAsync: ProcessSlaves error"); | |||
| jack_error("JackAudioDriver::ProcessGraphAsyncMaster: Process error"); | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) | |||
| jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ResumeRefNum error"); | |||
| if (ProcessReadSlaves() < 0) | |||
| jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessReadSlaves error"); | |||
| if (ProcessWriteSlaves() < 0) | |||
| jack_error("JackAudioDriver::ProcessGraphAsyncMaster: ProcessWriteSlaves error"); | |||
| } | |||
| void JackAudioDriver::ProcessGraphAsyncSlave() | |||
| { | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) | |||
| jack_error("JackAudioDriver::ProcessGraphAsyncSlave: ResumeRefNum error"); | |||
| } | |||
| int JackAudioDriver::ProcessGraphSync() | |||
| int JackAudioDriver::ProcessGraphSyncMaster() | |||
| { | |||
| int res = 0; | |||
| // fBeginDateUst is set in the "low level" layer, fEndDateUst is from previous cycle | |||
| if (fEngine->Process(fBeginDateUst, fEndDateUst)) { | |||
| fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); | |||
| if (ProcessSlaves() < 0) { | |||
| jack_error("JackAudioDriver::ProcessGraphSync: ProcessSlaves error, engine may now behave abnormally!!"); | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { | |||
| jack_error("JackAudioDriver::ProcessGraphSyncMaster: ResumeRefNum error"); | |||
| res = -1; | |||
| } | |||
| if (ProcessReadSlaves() < 0) { | |||
| jack_error("JackAudioDriver::ProcessGraphSync: ProcessReadSlaves error, engine may now behave abnormally!!"); | |||
| res = -1; | |||
| } | |||
| if (ProcessWriteSlaves() < 0) { | |||
| jack_error("JackAudioDriver::ProcessGraphSync: ProcessWriteSlaves error, engine may now behave abnormally!!"); | |||
| res = -1; | |||
| } | |||
| if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { | |||
| jack_error("JackAudioDriver::ProcessGraphSync: SuspendRefNum error, engine may now behave abnormally!!"); | |||
| res = -1; | |||
| @@ -312,6 +335,11 @@ int JackAudioDriver::ProcessGraphSync() | |||
| return res; | |||
| } | |||
| int JackAudioDriver::ProcessGraphSyncSlave() | |||
| { | |||
| return fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); | |||
| } | |||
| int JackAudioDriver::Start() | |||
| { | |||
| int res = JackDriver::Start(); | |||
| @@ -35,8 +35,12 @@ class SERVER_EXPORT JackAudioDriver : public JackDriver | |||
| protected: | |||
| void ProcessGraphAsync(); | |||
| int ProcessGraphSync(); | |||
| void ProcessGraphAsyncMaster(); | |||
| void ProcessGraphAsyncSlave(); | |||
| int ProcessGraphSyncMaster(); | |||
| int ProcessGraphSyncSlave(); | |||
| void WaitUntilNextCycle(); | |||
| virtual int ProcessAsync(); | |||
| @@ -282,19 +282,42 @@ void JackDriver::RemoveSlave(JackDriverInterface* slave) | |||
| fSlaveList.remove(slave); | |||
| } | |||
| int JackDriver::ProcessSlaves() | |||
| int JackDriver::ProcessReadSlaves() | |||
| { | |||
| int res = 0; | |||
| list<JackDriverInterface*>::const_iterator it; | |||
| for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) { | |||
| JackDriverInterface* slave = *it; | |||
| if (slave->Process() < 0) | |||
| if (slave->ProcessRead() < 0) | |||
| res = -1; | |||
| } | |||
| return res; | |||
| } | |||
| int JackDriver::ProcessWriteSlaves() | |||
| { | |||
| int res = 0; | |||
| list<JackDriverInterface*>::const_iterator it; | |||
| for (it = fSlaveList.begin(); it != fSlaveList.end(); it++) { | |||
| JackDriverInterface* slave = *it; | |||
| if (slave->ProcessWrite() < 0) | |||
| res = -1; | |||
| } | |||
| return res; | |||
| } | |||
| int JackDriver::ProcessRead() | |||
| { | |||
| return 0; | |||
| } | |||
| int JackDriver::ProcessWrite() | |||
| { | |||
| return 0; | |||
| } | |||
| int JackDriver::Process() | |||
| { | |||
| return 0; | |||
| @@ -34,6 +34,7 @@ namespace Jack | |||
| class JackLockedEngine; | |||
| class JackGraphManager; | |||
| struct JackEngineControl; | |||
| class JackSlaveDriverInterface; | |||
| /*! | |||
| \brief The base interface for drivers. | |||
| @@ -91,10 +92,17 @@ class SERVER_EXPORT JackDriverInterface | |||
| virtual void SetMaster(bool onoff) = 0; | |||
| virtual bool GetMaster() = 0; | |||
| virtual void AddSlave(JackDriverInterface* slave) = 0; | |||
| virtual void RemoveSlave(JackDriverInterface* slave) = 0; | |||
| virtual std::list<JackDriverInterface*> GetSlaves() = 0; | |||
| virtual int ProcessSlaves() = 0; | |||
| virtual int ProcessReadSlaves() = 0; | |||
| virtual int ProcessWriteSlaves() = 0; | |||
| virtual int ProcessRead() = 0; | |||
| virtual int ProcessWrite() = 0; | |||
| virtual bool IsRealTime() const = 0; | |||
| virtual bool IsRunning() const = 0; | |||
| @@ -159,11 +167,11 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface | |||
| void AddSlave(JackDriverInterface* slave); | |||
| void RemoveSlave(JackDriverInterface* slave); | |||
| std::list<JackDriverInterface*> GetSlaves() | |||
| { | |||
| return fSlaveList; | |||
| } | |||
| int ProcessSlaves(); | |||
| virtual int Open(); | |||
| @@ -200,10 +208,17 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface | |||
| virtual int Write(); | |||
| virtual int Start(); | |||
| virtual int StartSlaves(); | |||
| virtual int Stop(); | |||
| virtual int StartSlaves(); | |||
| virtual int StopSlaves(); | |||
| int ProcessReadSlaves(); | |||
| int ProcessWriteSlaves(); | |||
| int ProcessRead(); | |||
| int ProcessWrite(); | |||
| virtual bool IsFixedBufferSize(); | |||
| virtual int SetBufferSize(jack_nframes_t buffer_size); | |||
| virtual int SetSampleRate(jack_nframes_t sample_rate); | |||
| @@ -217,6 +232,19 @@ class SERVER_EXPORT JackDriver : public JackDriverClientInterface | |||
| }; | |||
| /* | |||
| class SERVER_EXPORT JackSlaveDriverInterface | |||
| { | |||
| public: | |||
| virtual int ProcessRead() { return 0; } | |||
| virtual int ProcessWrite() { return 0; } | |||
| }; | |||
| */ | |||
| } // end of namespace | |||
| #endif | |||
| @@ -28,26 +28,72 @@ namespace Jack | |||
| int JackFreewheelDriver::Process() | |||
| { | |||
| if (fIsMaster) { | |||
| jack_log("JackFreewheelDriver::Process master %lld", fEngineControl->fTimeOutUsecs); | |||
| JackDriver::CycleTakeBeginTime(); | |||
| fEngine->Process(fBeginDateUst, fEndDateUst); | |||
| fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); // Signal all clients | |||
| int res = 0; | |||
| jack_log("JackFreewheelDriver::Process master %lld", fEngineControl->fTimeOutUsecs); | |||
| JackDriver::CycleTakeBeginTime(); | |||
| if (fEngine->Process(fBeginDateUst, fEndDateUst)) { | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable)) { // Signal all clients | |||
| jack_error("JackFreewheelDriver::Process: ResumeRefNum error"); | |||
| res = -1; | |||
| } | |||
| if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, FREEWHEEL_DRIVER_TIMEOUT * 1000000) < 0) { // Wait for all clients to finish for 10 sec | |||
| jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); | |||
| jack_error("JackFreewheelDriver::ProcessSync: SuspendRefNum error"); | |||
| /* We have a client time-out error, but still continue to process, until a better recovery strategy is chosen */ | |||
| return 0; | |||
| } | |||
| } else { | |||
| fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); // Signal all clients | |||
| if (fEngineControl->fSyncMode) { | |||
| if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { | |||
| jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); | |||
| return -1; | |||
| } | |||
| } | |||
| } else { // Graph not finished: do not activate it | |||
| jack_error("JackFreewheelDriver::Process: Process error"); | |||
| res = -1; | |||
| } | |||
| return res; | |||
| } | |||
| int JackFreewheelDriver::ProcessRead() | |||
| { | |||
| return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync(); | |||
| } | |||
| int JackFreewheelDriver::ProcessWrite() | |||
| { | |||
| return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync(); | |||
| } | |||
| int JackFreewheelDriver::ProcessReadSync() | |||
| { | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { // Signal all clients | |||
| jack_error("JackFreewheelDriver::ProcessReadSync: ResumeRefNum error"); | |||
| return -1; | |||
| } | |||
| return 0; | |||
| } | |||
| int JackFreewheelDriver::ProcessWriteSync() | |||
| { | |||
| if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, DRIVER_TIMEOUT_FACTOR * fEngineControl->fTimeOutUsecs) < 0) { | |||
| jack_error("JackFreewheelDriver::ProcessSync SuspendRefNum error"); | |||
| return -1; | |||
| } | |||
| return 0; | |||
| } | |||
| int JackFreewheelDriver::ProcessReadAsync() | |||
| { | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { // Signal all clients | |||
| jack_error("JackFreewheelDriver::ProcessReadAsync: ResumeRefNum error"); | |||
| return -1; | |||
| } | |||
| return 0; | |||
| } | |||
| int JackFreewheelDriver::ProcessWriteAsync() | |||
| { | |||
| return 0; | |||
| } | |||
| } // end of namespace | |||
| @@ -46,6 +46,16 @@ class JackFreewheelDriver : public JackDriver | |||
| } | |||
| int Process(); | |||
| int ProcessRead(); | |||
| int ProcessWrite(); | |||
| int ProcessReadSync(); | |||
| int ProcessWriteSync(); | |||
| int ProcessReadAsync(); | |||
| int ProcessWriteAsync(); | |||
| }; | |||
| } // end of namespace | |||
| @@ -148,56 +148,24 @@ int JackMidiDriver::ProcessNull() | |||
| return 0; | |||
| } | |||
| /* | |||
| int JackMidiDriver::Process() | |||
| int JackMidiDriver::ProcessRead() | |||
| { | |||
| if (Read() < 0) { | |||
| jack_error("JackMidiDriver::Process: read error, skip cycle"); | |||
| return 0; // Skip cycle, but continue processing... | |||
| } | |||
| if (fEngineControl->fSyncMode) { | |||
| int res = 0; | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { | |||
| jack_error("JackMidiDriver::Process - ResumeRefNum error"); | |||
| res = -1; | |||
| } | |||
| if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, | |||
| DRIVER_TIMEOUT_FACTOR * | |||
| fEngineControl->fTimeOutUsecs) < 0) { | |||
| jack_error("JackMidiDriver::Process - SuspendRefNum error"); | |||
| res = -1; | |||
| } | |||
| if (Write() < 0) { | |||
| jack_error("JackMidiDriver::Process - Write error"); | |||
| } | |||
| return res; | |||
| } | |||
| // Not in sync mode | |||
| if (Write() < 0) { | |||
| jack_error("JackMidiDriver::Process - Write error"); | |||
| } else { | |||
| fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable); | |||
| } | |||
| return 0; | |||
| return (fEngineControl->fSyncMode) ? ProcessReadSync() : ProcessReadAsync(); | |||
| } | |||
| */ | |||
| int JackMidiDriver::Process() | |||
| int JackMidiDriver::ProcessWrite() | |||
| { | |||
| return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync(); | |||
| return (fEngineControl->fSyncMode) ? ProcessWriteSync() : ProcessWriteAsync(); | |||
| } | |||
| int JackMidiDriver::ProcessSync() | |||
| int JackMidiDriver::ProcessReadSync() | |||
| { | |||
| int res = 0; | |||
| // Read input buffers for the current cycle | |||
| if (Read() < 0) { | |||
| jack_error("JackMidiDriver::ProcessSync: read error, skip cycle"); | |||
| return 0; // Skip cycle, but continue processing... | |||
| res = -1; | |||
| } | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { | |||
| @@ -205,6 +173,13 @@ int JackMidiDriver::ProcessSync() | |||
| res = -1; | |||
| } | |||
| return res; | |||
| } | |||
| int JackMidiDriver::ProcessWriteSync() | |||
| { | |||
| int res = 0; | |||
| if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, | |||
| DRIVER_TIMEOUT_FACTOR * | |||
| fEngineControl->fTimeOutUsecs) < 0) { | |||
| @@ -215,24 +190,26 @@ int JackMidiDriver::ProcessSync() | |||
| // Write output buffers from the current cycle | |||
| if (Write() < 0) { | |||
| jack_error("JackMidiDriver::ProcessSync - Write error"); | |||
| res = -1; | |||
| } | |||
| return res; | |||
| } | |||
| int JackMidiDriver::ProcessAsync() | |||
| int JackMidiDriver::ProcessReadAsync() | |||
| { | |||
| int res = 0; | |||
| // Read input buffers for the current cycle | |||
| if (Read() < 0) { | |||
| jack_error("JackMidiDriver::ProcessAsync: read error, skip cycle"); | |||
| return 0; // Skip cycle, but continue processing... | |||
| res = -1; | |||
| } | |||
| // Write output buffers from the previous cycle | |||
| if (Write() < 0) { | |||
| jack_error("JackMidiDriver::ProcessAsync - Write error"); | |||
| res = -1; | |||
| } | |||
| if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { | |||
| @@ -243,6 +220,11 @@ int JackMidiDriver::ProcessAsync() | |||
| return res; | |||
| } | |||
| int JackMidiDriver::ProcessWriteAsync() | |||
| { | |||
| return 0; | |||
| } | |||
| JackMidiBuffer* JackMidiDriver::GetInputBuffer(int port_index) | |||
| { | |||
| assert(fCapturePortList[port_index]); | |||
| @@ -48,6 +48,12 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver | |||
| JackMidiBuffer* GetInputBuffer(int port_index); | |||
| JackMidiBuffer* GetOutputBuffer(int port_index); | |||
| virtual int ProcessReadSync(); | |||
| virtual int ProcessWriteSync(); | |||
| virtual int ProcessReadAsync(); | |||
| virtual int ProcessWriteAsync(); | |||
| public: | |||
| JackMidiDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table); | |||
| @@ -63,9 +69,9 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver | |||
| jack_nframes_t capture_latency, | |||
| jack_nframes_t playback_latency); | |||
| virtual int Process(); | |||
| virtual int ProcessSync(); | |||
| virtual int ProcessAsync(); | |||
| virtual int ProcessRead(); | |||
| virtual int ProcessWrite(); | |||
| virtual int ProcessNull(); | |||
| virtual int Attach(); | |||
| @@ -127,9 +127,24 @@ void JackThreadedDriver::RemoveSlave(JackDriverInterface* slave) | |||
| fDriver->RemoveSlave(slave); | |||
| } | |||
| int JackThreadedDriver::ProcessSlaves() | |||
| int JackThreadedDriver::ProcessReadSlaves() | |||
| { | |||
| return fDriver->ProcessSlaves(); | |||
| return fDriver->ProcessReadSlaves(); | |||
| } | |||
| int JackThreadedDriver::ProcessWriteSlaves() | |||
| { | |||
| return fDriver->ProcessWriteSlaves(); | |||
| } | |||
| int JackThreadedDriver::ProcessRead() | |||
| { | |||
| return fDriver->ProcessRead(); | |||
| } | |||
| int JackThreadedDriver::ProcessWrite() | |||
| { | |||
| return fDriver->ProcessWrite(); | |||
| } | |||
| std::list<JackDriverInterface*> JackThreadedDriver::GetSlaves() | |||
| @@ -89,10 +89,17 @@ class SERVER_EXPORT JackThreadedDriver : public JackDriverClientInterface, publi | |||
| virtual void SetMaster(bool onoff); | |||
| virtual bool GetMaster(); | |||
| virtual void AddSlave(JackDriverInterface* slave); | |||
| virtual void RemoveSlave(JackDriverInterface* slave); | |||
| virtual std::list<JackDriverInterface*> GetSlaves(); | |||
| virtual int ProcessSlaves(); | |||
| virtual int ProcessReadSlaves(); | |||
| virtual int ProcessWriteSlaves(); | |||
| virtual int ProcessRead(); | |||
| virtual int ProcessWrite(); | |||
| virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2); | |||
| virtual JackClientControl* GetClientControl() const; | |||