00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __JackEngineControl__
00022 #define __JackEngineControl__
00023
00024 #include "JackShmMem.h"
00025 #include "JackFrameTimer.h"
00026 #include "JackTransportEngine.h"
00027 #include "JackConstants.h"
00028 #include "types.h"
00029 #include <stdio.h>
00030
00031 #ifdef JACK_MONITOR
00032 #include "JackEngineProfiling.h"
00033 #endif
00034
00035 namespace Jack
00036 {
00037
00038 class JackClientInterface;
00039 class JackGraphManager;
00040
00041 #define JACK_ENGINE_ROLLING_COUNT 32
00042 #define JACK_ENGINE_ROLLING_INTERVAL 1024
00043
00048 PRE_PACKED_STRUCTURE
00049 struct SERVER_EXPORT JackEngineControl : public JackShmMem
00050 {
00051
00052 jack_nframes_t fBufferSize;
00053 jack_nframes_t fSampleRate;
00054 bool fSyncMode;
00055 bool fTemporary;
00056 jack_time_t fPeriodUsecs;
00057 jack_time_t fTimeOutUsecs;
00058 float fMaxDelayedUsecs;
00059 float fXrunDelayedUsecs;
00060 bool fTimeOut;
00061 bool fRealTime;
00062 bool fSavedRealTime;
00063 int fServerPriority;
00064 int fClientPriority;
00065 int fMaxClientPriority;
00066 char fServerName[JACK_SERVER_NAME_SIZE];
00067 JackTransportEngine fTransport;
00068 jack_timer_type_t fClockSource;
00069 int fDriverNum;
00070 bool fVerbose;
00071
00072
00073 jack_time_t fPrevCycleTime;
00074 jack_time_t fCurCycleTime;
00075 jack_time_t fSpareUsecs;
00076 jack_time_t fMaxUsecs;
00077 jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
00078 unsigned int fRollingClientUsecsCnt;
00079 int fRollingClientUsecsIndex;
00080 int fRollingInterval;
00081 float fCPULoad;
00082
00083
00084 UInt64 fPeriod;
00085 UInt64 fComputation;
00086 UInt64 fConstraint;
00087
00088
00089 JackFrameTimer fFrameTimer;
00090
00091 #ifdef JACK_MONITOR
00092 JackEngineProfiling fProfiler;
00093 #endif
00094
00095 JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name)
00096 {
00097 fBufferSize = 512;
00098 fSampleRate = 48000;
00099 fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize);
00100 fSyncMode = sync;
00101 fTemporary = temporary;
00102 fTimeOut = (timeout > 0);
00103 fTimeOutUsecs = timeout * 1000;
00104 fRealTime = rt;
00105 fSavedRealTime = false;
00106 fServerPriority = priority;
00107 fClientPriority = (rt) ? priority - 5 : 0;
00108 fMaxClientPriority = (rt) ? priority - 1 : 0;
00109 fVerbose = verbose;
00110 fPrevCycleTime = 0;
00111 fCurCycleTime = 0;
00112 fSpareUsecs = 0;
00113 fMaxUsecs = 0;
00114 ResetRollingUsecs();
00115 strncpy(fServerName, server_name, sizeof(fServerName));
00116 fCPULoad = 0.f;
00117 fPeriod = 0;
00118 fComputation = 0;
00119 fConstraint = 0;
00120 fMaxDelayedUsecs = 0.f;
00121 fXrunDelayedUsecs = 0.f;
00122 fClockSource = clock;
00123 fDriverNum = 0;
00124 }
00125
00126 ~JackEngineControl()
00127 {}
00128
00129 void UpdateTimeOut()
00130 {
00131 fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize);
00132 if (!(fTimeOut && fTimeOutUsecs > 2 * fPeriodUsecs)) {
00133 fTimeOutUsecs = 2 * fPeriodUsecs;
00134 }
00135 }
00136
00137
00138 void CycleIncTime(jack_time_t callback_usecs)
00139 {
00140
00141 fFrameTimer.IncFrameTime(fBufferSize, callback_usecs, fPeriodUsecs);
00142 }
00143
00144 void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
00145 {
00146 fTransport.CycleBegin(fSampleRate, cur_cycle_begin);
00147 CalcCPULoad(table, manager, cur_cycle_begin, prev_cycle_end);
00148 #ifdef JACK_MONITOR
00149 fProfiler.Profile(table, manager, fPeriodUsecs, cur_cycle_begin, prev_cycle_end);
00150 #endif
00151 }
00152
00153 void CycleEnd(JackClientInterface** table)
00154 {
00155 fTransport.CycleEnd(table, fSampleRate, fBufferSize);
00156 }
00157
00158
00159 void InitFrameTime()
00160 {
00161 fFrameTimer.InitFrameTime();
00162 }
00163
00164 void ResetFrameTime(jack_time_t callback_usecs)
00165 {
00166 fFrameTimer.ResetFrameTime(callback_usecs);
00167 }
00168
00169 void ReadFrameTime(JackTimer* timer)
00170 {
00171 fFrameTimer.ReadFrameTime(timer);
00172 }
00173
00174
00175 void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs);
00176 void ResetXRun()
00177 {
00178 fMaxDelayedUsecs = 0.f;
00179 }
00180
00181
00182 void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager, jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
00183 void ResetRollingUsecs();
00184
00185 } POST_PACKED_STRUCTURE;
00186
00187 }
00188
00189 #endif