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.

152 lines
3.8KB

  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. 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. unsigned int 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 fTimeOut;
  62. bool fRealTime;
  63. int fPriority;
  64. char fServerName[64];
  65. JackTransportEngine fTransport;
  66. bool fVerbose;
  67. // Timing
  68. JackTimingMeasure fMeasure[TIME_POINTS];
  69. jack_time_t fLastTime;
  70. jack_time_t fCurTime;
  71. jack_time_t fProcessTime;
  72. jack_time_t fLastProcessTime;
  73. jack_time_t fSpareUsecs;
  74. jack_time_t fMaxUsecs;
  75. unsigned int fAudioCycle;
  76. jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
  77. int fRollingClientUsecsCnt;
  78. int fRollingClientUsecsIndex;
  79. int fRollingInterval;
  80. float fCPULoad;
  81. // For OSX thread
  82. UInt64 fPeriod;
  83. UInt64 fComputation;
  84. UInt64 fConstraint;
  85. // Timer
  86. JackFrameTimer fFrameTimer;
  87. JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name)
  88. {
  89. fSyncMode = sync;
  90. fTemporary = temporary;
  91. fTimeOut = (timeout > 0);
  92. fTimeOutUsecs = timeout * 1000;
  93. fRealTime = rt;
  94. fPriority = priority;
  95. fVerbose = verbose;
  96. fLastTime = 0;
  97. fCurTime = 0;
  98. fProcessTime = 0;
  99. fLastProcessTime = 0;
  100. fSpareUsecs = 0;
  101. fMaxUsecs = 0;
  102. fAudioCycle = 0;
  103. ClearTimeMeasures();
  104. ResetRollingUsecs();
  105. snprintf(fServerName, sizeof(fServerName), server_name);
  106. fPeriod = 0;
  107. fComputation = 0;
  108. fConstraint = 0;
  109. }
  110. ~JackEngineControl()
  111. {}
  112. // Cycle
  113. void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
  114. void CycleEnd(JackClientInterface** table);
  115. // Timer
  116. void InitFrameTime();
  117. void ResetFrameTime(jack_time_t callback_usecs);
  118. void ReadFrameTime(JackTimer* timer);
  119. // Private
  120. void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager);
  121. void GetTimeMeasure(JackClientInterface** table, JackGraphManager* manager, jack_time_t callback_usecs);
  122. void ClearTimeMeasures();
  123. void ResetRollingUsecs();
  124. };
  125. } // end of namespace
  126. #endif