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.

147 lines
3.4KB

  1. /*
  2. Copyright (C) 2003 Paul Davis
  3. Copyright (C) 2004-2006 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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. namespace Jack
  23. {
  24. class JackClientInterface;
  25. class JackGraphManager;
  26. #define TIME_POINTS 1000
  27. #define JACK_ENGINE_ROLLING_COUNT 32
  28. #define JACK_ENGINE_ROLLING_INTERVAL 1024
  29. /*!
  30. \brief Timing stucture for a client.
  31. */
  32. struct JackTimingMeasureClient
  33. {
  34. int fRefNum;
  35. jack_time_t fSignaledAt;
  36. jack_time_t fAwakeAt;
  37. jack_time_t fFinishedAt;
  38. jack_client_state_t fStatus;
  39. };
  40. /*!
  41. \brief Timing stucture for a table of clients.
  42. */
  43. struct JackTimingMeasure
  44. {
  45. long fAudioCycle;
  46. jack_time_t fEngineTime;
  47. JackTimingMeasureClient fClientTable[CLIENT_NUM];
  48. };
  49. /*!
  50. \brief Engine control in shared memory.
  51. */
  52. struct JackEngineControl : public JackShmMem
  53. {
  54. // Shared state
  55. jack_nframes_t fBufferSize;
  56. jack_nframes_t fSampleRate;
  57. bool fSyncMode;
  58. bool fTemporary;
  59. jack_time_t fPeriodUsecs;
  60. jack_time_t fTimeOutUsecs;
  61. bool fRealTime;
  62. int32_t fPriority;
  63. char fServerName[64];
  64. JackTransportEngine fTransport;
  65. bool fVerbose;
  66. // Timing
  67. JackTimingMeasure fMeasure[TIME_POINTS];
  68. jack_time_t fLastTime;
  69. jack_time_t fCurTime;
  70. jack_time_t fProcessTime;
  71. jack_time_t fLastProcessTime;
  72. jack_time_t fSpareUsecs;
  73. jack_time_t fMaxUsecs;
  74. uint32_t fAudioCycle;
  75. jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
  76. int fRollingClientUsecsCnt;
  77. int fRollingClientUsecsIndex;
  78. int fRollingInterval;
  79. float fCPULoad;
  80. // Fos OSX thread
  81. UInt64 fPeriod;
  82. UInt64 fComputation;
  83. UInt64 fConstraint;
  84. // Timer
  85. JackFrameTimer fFrameTimer;
  86. JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name)
  87. {
  88. fSyncMode = sync;
  89. fTemporary = temporary;
  90. fTimeOutUsecs = timeout * 1000;
  91. fRealTime = rt;
  92. fPriority = priority;
  93. fVerbose = verbose;
  94. fLastTime = 0;
  95. fCurTime = 0;
  96. fProcessTime = 0;
  97. fLastProcessTime = 0;
  98. fSpareUsecs = 0;
  99. fMaxUsecs = 0;
  100. fAudioCycle = 0;
  101. ClearTimeMeasures();
  102. ResetRollingUsecs();
  103. snprintf(fServerName, sizeof(fServerName), server_name);
  104. }
  105. ~JackEngineControl()
  106. {}
  107. // Cycle
  108. void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
  109. void CycleEnd(JackClientInterface** table);
  110. // Timer
  111. void InitFrameTime();
  112. void ResetFrameTime(jack_time_t callback_usecs);
  113. void ReadFrameTime(JackTimer* timer);
  114. // Private
  115. void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager);
  116. void GetTimeMeasure(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
  117. void ClearTimeMeasures();
  118. void ResetRollingUsecs();
  119. };
  120. } // end of namespace
  121. #endif