2 Copyright (C) 2003 Paul Davis
3 Copyright (C) 2004-2008 Grame
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #ifndef __JackEngineControl__
22 #define __JackEngineControl__
24 #include "JackShmMem.h"
25 #include "JackFrameTimer.h"
26 #include "JackTransportEngine.h"
27 #include "JackConstants.h"
32 #include "JackEngineProfiling.h"
38 class JackClientInterface
;
39 class JackGraphManager
;
41 #define JACK_ENGINE_ROLLING_COUNT 32
42 #define JACK_ENGINE_ROLLING_INTERVAL 1024
45 \brief Engine control in shared memory.
49 struct SERVER_EXPORT JackEngineControl
: public JackShmMem
52 jack_nframes_t fBufferSize
;
53 jack_nframes_t fSampleRate
;
56 jack_time_t fPeriodUsecs
;
57 jack_time_t fTimeOutUsecs
;
58 float fMaxDelayedUsecs
;
59 float fXrunDelayedUsecs
;
62 bool fSavedRealTime
; // RT state saved and restored during Freewheel mode
65 int fMaxClientPriority
;
66 char fServerName
[JACK_SERVER_NAME_SIZE
+1];
67 alignas(UInt32
) alignas(JackTransportEngine
) JackTransportEngine fTransport
;
68 jack_timer_type_t fClockSource
;
73 jack_time_t fPrevCycleTime
;
74 jack_time_t fCurCycleTime
;
75 jack_time_t fSpareUsecs
;
76 jack_time_t fMaxUsecs
;
77 jack_time_t fRollingClientUsecs
[JACK_ENGINE_ROLLING_COUNT
];
78 unsigned int fRollingClientUsecsCnt
;
79 int fRollingClientUsecsIndex
;
89 alignas(UInt32
) alignas(JackFrameTimer
) JackFrameTimer fFrameTimer
;
92 JackEngineProfiling fProfiler
;
95 JackEngineControl(bool sync
, bool temporary
, long timeout
, bool rt
, long priority
, bool verbose
, jack_timer_type_t clock
, const char* server_name
)
97 static_assert(offsetof(JackEngineControl
, fTransport
) % sizeof(UInt32
) == 0,
98 "fTransport must be aligned within JackEngineControl");
99 static_assert(offsetof(JackEngineControl
, fFrameTimer
) % sizeof(UInt32
) == 0,
100 "fFrameTimer must be aligned within JackEngineControl");
103 fPeriodUsecs
= jack_time_t(1000000.f
/ fSampleRate
* fBufferSize
);
105 fTemporary
= temporary
;
106 fTimeOut
= (timeout
> 0);
107 fTimeOutUsecs
= timeout
* 1000;
109 fSavedRealTime
= false;
110 fServerPriority
= priority
;
113 fClientPriority
= (rt
) ? priority
- 3 : 0;
115 fClientPriority
= (rt
) ? priority
- 5 : 0;
117 fMaxClientPriority
= (rt
) ? priority
- 1 : 0;
124 strncpy(fServerName
, server_name
, sizeof(fServerName
));
125 fServerName
[sizeof(fServerName
) - 1] = 0;
130 fMaxDelayedUsecs
= 0.f
;
131 fXrunDelayedUsecs
= 0.f
;
132 fClockSource
= clock
;
141 fPeriodUsecs
= jack_time_t(1000000.f
/ fSampleRate
* fBufferSize
); // In microsec
142 if (!(fTimeOut
&& fTimeOutUsecs
> 2 * fPeriodUsecs
)) {
143 fTimeOutUsecs
= 2 * fPeriodUsecs
;
148 void CycleIncTime(jack_time_t callback_usecs
)
151 fFrameTimer
.IncFrameTime(fBufferSize
, callback_usecs
, fPeriodUsecs
);
154 void CycleBegin(JackClientInterface
** table
, JackGraphManager
* manager
, jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
)
156 fTransport
.CycleBegin(fSampleRate
, cur_cycle_begin
);
157 CalcCPULoad(table
, manager
, cur_cycle_begin
, prev_cycle_end
);
159 fProfiler
.Profile(table
, manager
, fPeriodUsecs
, cur_cycle_begin
, prev_cycle_end
);
163 void CycleEnd(JackClientInterface
** table
)
165 fTransport
.CycleEnd(table
, fSampleRate
, fBufferSize
);
171 fFrameTimer
.InitFrameTime();
174 void ResetFrameTime(jack_time_t callback_usecs
)
176 fFrameTimer
.ResetFrameTime(callback_usecs
);
179 void ReadFrameTime(JackTimer
* timer
)
181 fFrameTimer
.ReadFrameTime(timer
);
185 void NotifyXRun(jack_time_t callback_usecs
, float delayed_usecs
);
188 fMaxDelayedUsecs
= 0.f
;
192 void CalcCPULoad(JackClientInterface
** table
, JackGraphManager
* manager
, jack_time_t cur_cycle_begin
, jack_time_t prev_cycle_end
);
193 void ResetRollingUsecs();
195 } POST_PACKED_STRUCTURE
;
197 } // end of namespace