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.

130 lines
3.5KB

  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 JACK_ENGINE_ROLLING_COUNT 32
  28. #define JACK_ENGINE_ROLLING_INTERVAL 1024
  29. /*!
  30. \brief Engine control in shared memory.
  31. */
  32. struct EXPORT JackEngineControl : public JackShmMem
  33. {
  34. // Shared state
  35. jack_nframes_t fBufferSize;
  36. jack_nframes_t fSampleRate;
  37. bool fSyncMode;
  38. bool fTemporary;
  39. jack_time_t fPeriodUsecs;
  40. jack_time_t fTimeOutUsecs;
  41. float fMaxDelayedUsecs;
  42. float fXrunDelayedUsecs;
  43. bool fTimeOut;
  44. bool fRealTime;
  45. int fPriority;
  46. char fServerName[64];
  47. JackTransportEngine fTransport;
  48. bool fVerbose;
  49. // CPU Load
  50. jack_time_t fPrevCycleTime;
  51. jack_time_t fCurCycleTime;
  52. jack_time_t fSpareUsecs;
  53. jack_time_t fMaxUsecs;
  54. jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
  55. int fRollingClientUsecsCnt;
  56. int fRollingClientUsecsIndex;
  57. int fRollingInterval;
  58. float fCPULoad;
  59. // For OSX thread
  60. UInt64 fPeriod;
  61. UInt64 fComputation;
  62. UInt64 fConstraint;
  63. // Timer
  64. JackFrameTimer fFrameTimer;
  65. JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name)
  66. {
  67. fBufferSize = 512;
  68. fSampleRate = 48000;
  69. fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize);
  70. fSyncMode = sync;
  71. fTemporary = temporary;
  72. fTimeOut = (timeout > 0);
  73. fTimeOutUsecs = timeout * 1000;
  74. fRealTime = rt;
  75. fPriority = priority;
  76. fVerbose = verbose;
  77. fPrevCycleTime = 0;
  78. fCurCycleTime = 0;
  79. fSpareUsecs = 0;
  80. fMaxUsecs = 0;
  81. ResetRollingUsecs();
  82. snprintf(fServerName, sizeof(fServerName), server_name);
  83. fPeriod = 0;
  84. fComputation = 0;
  85. fConstraint = 0;
  86. fMaxDelayedUsecs = 0.f;
  87. fXrunDelayedUsecs = 0.f;
  88. }
  89. ~JackEngineControl()
  90. {}
  91. // Cycle
  92. void CycleIncTime(jack_time_t callback_usecs);
  93. void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
  94. void CycleEnd(JackClientInterface** table);
  95. // Timer
  96. void InitFrameTime();
  97. void ResetFrameTime(jack_time_t callback_usecs);
  98. void ReadFrameTime(JackTimer* timer);
  99. // XRun
  100. void NotifyXRun(float delayed_usecs);
  101. void ResetXRun();
  102. // Private
  103. void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager, jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
  104. void ResetRollingUsecs();
  105. };
  106. } // end of namespace
  107. #endif