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 struct SERVER_EXPORT JackEngineControl : public JackShmMem
00049 {
00050
00051 jack_nframes_t fBufferSize;
00052 jack_nframes_t fSampleRate;
00053 bool fSyncMode;
00054 bool fTemporary;
00055 jack_time_t fPeriodUsecs;
00056 jack_time_t fTimeOutUsecs;
00057 float fMaxDelayedUsecs;
00058 float fXrunDelayedUsecs;
00059 bool fTimeOut;
00060 bool fRealTime;
00061 int fServerPriority;
00062 int fClientPriority;
00063 int fMaxClientPriority;
00064 char fServerName[64];
00065 JackTransportEngine fTransport;
00066 bool fVerbose;
00067
00068
00069 jack_time_t fPrevCycleTime;
00070 jack_time_t fCurCycleTime;
00071 jack_time_t fSpareUsecs;
00072 jack_time_t fMaxUsecs;
00073 jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
00074 int fRollingClientUsecsCnt;
00075 int fRollingClientUsecsIndex;
00076 int fRollingInterval;
00077 float fCPULoad;
00078
00079
00080 UInt64 fPeriod;
00081 UInt64 fComputation;
00082 UInt64 fConstraint;
00083
00084
00085 JackFrameTimer fFrameTimer;
00086
00087 #ifdef JACK_MONITOR
00088 JackEngineProfiling fProfiler;
00089 #endif
00090
00091 JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name)
00092 {
00093 fBufferSize = 512;
00094 fSampleRate = 48000;
00095 fPeriodUsecs = jack_time_t(1000000.f / fSampleRate * fBufferSize);
00096 fSyncMode = sync;
00097 fTemporary = temporary;
00098 fTimeOut = (timeout > 0);
00099 fTimeOutUsecs = timeout * 1000;
00100 fRealTime = rt;
00101 fServerPriority = priority;
00102 fClientPriority = (rt) ? priority - 5 : 0;
00103 fMaxClientPriority = (rt) ? priority - 1 : 0;
00104 fVerbose = verbose;
00105 fPrevCycleTime = 0;
00106 fCurCycleTime = 0;
00107 fSpareUsecs = 0;
00108 fMaxUsecs = 0;
00109 ResetRollingUsecs();
00110 strncpy(fServerName, server_name, sizeof(fServerName));
00111 fPeriod = 0;
00112 fComputation = 0;
00113 fConstraint = 0;
00114 fMaxDelayedUsecs = 0.f;
00115 fXrunDelayedUsecs = 0.f;
00116 }
00117
00118 ~JackEngineControl()
00119 {}
00120
00121
00122 void CycleIncTime(jack_time_t callback_usecs)
00123 {
00124
00125 fFrameTimer.IncFrameTime(fBufferSize, callback_usecs, fPeriodUsecs);
00126 }
00127
00128 void CycleBegin(JackClientInterface** table, JackGraphManager* manager, jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end)
00129 {
00130 fTransport.CycleBegin(fSampleRate, cur_cycle_begin);
00131 CalcCPULoad(table, manager, cur_cycle_begin, prev_cycle_end);
00132 #ifdef JACK_MONITOR
00133 fProfiler.Profile(table, manager, fPeriodUsecs, cur_cycle_begin, prev_cycle_end);
00134 #endif
00135 }
00136
00137 void CycleEnd(JackClientInterface** table)
00138 {
00139 fTransport.CycleEnd(table, fSampleRate, fBufferSize);
00140 }
00141
00142
00143 void InitFrameTime()
00144 {
00145 fFrameTimer.InitFrameTime();
00146 }
00147
00148 void ResetFrameTime(jack_time_t callback_usecs)
00149 {
00150 fFrameTimer.ResetFrameTime(fSampleRate, callback_usecs, fPeriodUsecs);
00151 }
00152
00153 void ReadFrameTime(JackTimer* timer)
00154 {
00155 fFrameTimer.ReadFrameTime(timer);
00156 }
00157
00158
00159 void NotifyXRun(float delayed_usecs);
00160 void ResetXRun()
00161 {
00162 fMaxDelayedUsecs = 0.f;
00163 }
00164
00165
00166 void CalcCPULoad(JackClientInterface** table, JackGraphManager* manager, jack_time_t cur_cycle_begin, jack_time_t prev_cycle_end);
00167 void ResetRollingUsecs();
00168
00169 };
00170
00171 }
00172
00173 #endif