diff --git a/common/JackClient.h b/common/JackClient.h index 26c50d78..17ec12e4 100644 --- a/common/JackClient.h +++ b/common/JackClient.h @@ -50,7 +50,8 @@ typedef void (*JackShutdownCallback)(void *arg); class JackClient : public JackClientInterface, public JackRunnableInterface { - + friend class JackDebugClient; + protected: JackProcessCallback fProcess; diff --git a/common/JackDebugClient.cpp b/common/JackDebugClient.cpp index ec3cbae8..c9f1749c 100644 --- a/common/JackDebugClient.cpp +++ b/common/JackDebugClient.cpp @@ -18,7 +18,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "JackDebugClient.h" +#include "JackEngineControl.h" #include "JackError.h" +#include "JackTime.h" #include #include #include @@ -438,10 +440,24 @@ void JackDebugClient::OnShutdown(JackShutdownCallback callback, void *arg) fClient->OnShutdown(callback, arg); } +int JackDebugClient::TimeCallback(jack_nframes_t nframes, void *arg) +{ + JackDebugClient* client = (JackDebugClient*)arg; + jack_time_t t1 = GetMicroSeconds(); + int res = client->fProcessTimeCallback(nframes, client->fProcessTimeCallbackArg); + jack_time_t t2 = GetMicroSeconds(); + long delta = long((t2 - t1) - client->GetEngineControl()->fPeriodUsecs); + if (delta > 0) + *client->fStream << "!!! ERROR !!! : XRun of " << delta << " us" << endl; + return res; +} + int JackDebugClient::SetProcessCallback(JackProcessCallback callback, void *arg) { CheckClient(); - return fClient->SetProcessCallback(callback, arg); + fProcessTimeCallback = callback; + fProcessTimeCallbackArg = arg; + return fClient->SetProcessCallback(TimeCallback, this); } int JackDebugClient::SetXRunCallback(JackXRunCallback callback, void *arg) diff --git a/common/JackDebugClient.h b/common/JackDebugClient.h index ab08d1e9..bde079f8 100644 --- a/common/JackDebugClient.h +++ b/common/JackDebugClient.h @@ -45,23 +45,22 @@ PortFollower; /*! \brief A "decorator" debug client to validate API use. */ - + class JackDebugClient : public JackClient { - private: - - JackClient* fClient; - std::ofstream* fStream; - protected: - PortFollower fPortList[MAX_PORT_HISTORY]; // Arbitrary value... To be tuned... + JackClient* fClient; + std::ofstream* fStream; + PortFollower fPortList[MAX_PORT_HISTORY]; // Arbitrary value... To be tuned... int fTotalPortNumber; // The total number of port opened and maybe closed. Historical view. int fOpenPortNumber; // The current number of opened port. int fIsActivated; int fIsDeactivated; int fIsClosed; char fClientName[JACK_CLIENT_NAME_SIZE]; + JackProcessCallback fProcessTimeCallback; + void* fProcessTimeCallbackArg; public: @@ -131,9 +130,9 @@ class JackDebugClient : public JackClient jack_nframes_t Wait(int status); JackClientControl* GetClientControl() const; - void CheckClient() const; - + + static int JackDebugClient::TimeCallback(jack_nframes_t nframes, void *arg); };