jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.2KB

  1. /*
  2. Copyright (C) 2003 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackEngineControl__
  17. #define __JackEngineControl__
  18. #include "JackShmMem.h"
  19. #include "JackFrameTimer.h"
  20. #include "JackTransportEngine.h"
  21. #include "types.h"
  22. #include <stdio.h>
  23. namespace Jack
  24. {
  25. class JackClientInterface;
  26. class JackGraphManager;
  27. #define TIME_POINTS 1000
  28. #define JACK_ENGINE_ROLLING_COUNT 32
  29. #define JACK_ENGINE_ROLLING_INTERVAL 1024
  30. /*!
  31. \brief Timing stucture for a client.
  32. */
  33. struct JackTimingMeasureClient
  34. {
  35. int fRefNum;
  36. jack_time_t fSignaledAt;
  37. jack_time_t fAwakeAt;
  38. jack_time_t fFinishedAt;
  39. jack_client_state_t fStatus;
  40. };
  41. /*!
  42. \brief Timing stucture for a table of clients.
  43. */
  44. struct JackTimingMeasure
  45. {
  46. unsigned int fAudioCycle;
  47. jack_time_t fEngineTime;
  48. JackTimingMeasureClient fClientTable[CLIENT_NUM];
  49. };
  50. /*!
  51. \brief Engine control in shared memory.
  52. */
  53. struct JackEngineControl : public JackShmMem
  54. {
  55. // Shared state
  56. jack_nframes_t fBufferSize;
  57. jack_nframes_t fSampleRate;
  58. bool fSyncMode;
  59. bool fTemporary;
  60. jack_time_t fPeriodUsecs;
  61. jack_time_t fTimeOutUsecs;
  62. float fMaxDelayedUsecs;
  63. float fXrunDelayedUsecs;
  64. bool fTimeOut;
  65. bool fRealTime;
  66. int fPriority;
  67. char fServerName[64];
  68. JackTransportEngine fTransport;
  69. bool fVerbose;
  70. // Timing
  71. JackTimingMeasure fMeasure[TIME_POINTS];
  72. jack_time_t fLastTime;
  73. jack_time_t fCurTime;
  74. jack_time_t fProcessTime;
  75. jack_time_t fLastProcessTime;
  76. jack_time_t fSpareUsecs;
  77. jack_time_t fMaxUsecs;
  78. unsigned int fAudioCycle;
  79. jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
  80. int fRollingClientUsecsCnt;
  81. int fRollingClientUsecsIndex;
  82. int fRollingInterval;
  83. float fCPULoad;
  84. // For OSX thread
  85. UInt64 fPeriod;
  86. UInt64 fComputation;
  87. UInt64 fConstraint;
  88. // Timer
  89. JackFrameTimer fFrameTimer;
  90. JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name)
  91. {
  92. fBufferSize = 512;
  93. fSampleRate = 48000;
  94. fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize);
  95. fSyncMode = sync;
  96. fTemporary = temporary;
  97. fTimeOut = (timeout > 0);
  98. fTimeOutUsecs = timeout * 1000;
  99. fRealTime = rt;
  100. fPriority = priority;
  101. fVerbose = verbose;
  102. fLastTime = 0;
  103. fCurTime = 0;
  104. fProcessTime = 0;
  105. fLastProcessTime = 0;
  106. fSpareUsecs = 0;
  107. fMaxUsecs = 0;
  108. fAudioCycle = 0;
  109. ClearTimeMeasures();
  110. ResetRollingUsecs();
  111. snprintf(fServerName, sizeof(fServerName), server_name);
  112. fPeriod = 0;
  113. fComputation = 0;
  114. fConstraint = 0;
  115. fMaxDelayedUsecs = 0.f;
  116. fXrunDelayedUsecs = 0.f;
  117. }
  118. ~JackEngineControl()
  119. {}
  120. // Cycle
  121. void CycleIncTime(jack_time_t callback_usecs);
  122. void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
  123. void CycleEnd(JackClientInterface** table);
  124. // Timer
  125. void InitFrameTime();
  126. void ResetFrameTime(jack_time_t callback_usecs);
  127. void ReadFrameTime(JackTimer* timer);
  128. // XRun
  129. void NotifyXRun(float delayed_usecs);
  130. void ResetXRun();
  131. // Private
  132. void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager);
  133. void GetTimeMeasure(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
  134. void ClearTimeMeasures();
  135. void ResetRollingUsecs();
  136. };
  137. } // end of namespace
  138. #endif