2 Copyright (C) 2001 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 __JackTransportEngine__
22 #define __JackTransportEngine__
24 #include "JackAtomicArrayState.h"
25 #include "JackCompilerDeps.h"
32 TransportCommandNone
= 0,
33 TransportCommandStart
= 1,
34 TransportCommandStop
= 2,
35 } transport_command_t
;
38 \brief The client transport structure.
42 - a "current" position
43 - a "pending" position prepared by the server at each cycle
44 - a "request" position wanted by a client
46 At the beginning of a cycle the server needs to select a new current position. When a request and a pending position are available,
47 the resquest takes precedence on the pending one. The server atomically switches to the new position.
48 The current position can be read by clients.
50 We use a JackAtomicArrayState pattern that allows to manage several "next" states independantly.
52 In jack1 implementation, transport code (jack_transport_cycle_end) was not called if the graph could not be locked (see jack_run_one_cycle).
53 Here transport cycle (CycleBegin, CycleEnd) has to run in the RT thread concurrently with code executed from the "command" thread.
55 Each client maintains a state in it's shared memory area defined by:
57 - it's current transport state
58 - a boolean that is "true" when slow-sync cb has to be called
59 - a boolean that is "true" when timebase cb is called with new_pos on
61 Several operations set the "slow-sync cb" flag to true:
63 - setting a new cb (client)
65 - transport start (server)
68 Slow-sync cb calls stops when:
70 - the cb return true (client)
71 - desactivate (client)
72 - transport stop (server)
74 Several operations set the "timebase cb" flag to true:
76 - setting a new cb (client)
78 - transport start (server) ??
81 Timebase cb "new_pos" argument calls stops when:
83 - after one cb call with "new_pos" argument true (client)
84 - desactivate (client)
86 - transport stop (server)
90 class JackClientInterface
;
92 class SERVER_EXPORT JackTransportEngine
: public JackAtomicArrayState
<jack_position_t
>
97 jack_transport_state_t fTransportState
;
98 volatile transport_command_t fTransportCmd
;
99 transport_command_t fPreviousCmd
; /* previous transport_cmd */
100 jack_time_t fSyncTimeout
;
106 SInt32 fWriteCounter
;
108 bool CheckAllRolling(JackClientInterface
** table
);
109 void MakeAllStartingLocating(JackClientInterface
** table
);
110 void MakeAllStopping(JackClientInterface
** table
);
111 void MakeAllLocating(JackClientInterface
** table
);
113 void SyncTimeout(jack_nframes_t frame_rate
, jack_nframes_t buffer_size
);
117 JackTransportEngine();
119 ~JackTransportEngine()
122 void SetCommand(transport_command_t state
)
124 fTransportCmd
= state
;
127 jack_transport_state_t
GetState() const
129 return fTransportState
;
132 void SetState(jack_transport_state_t state
)
134 fTransportState
= state
;
140 int ResetTimebase(int refnum
);
145 int SetTimebaseMaster(int refnum
, bool conditionnal
);
147 void GetTimebaseMaster(int& refnum
, bool& conditionnal
);
152 void CycleBegin(jack_nframes_t frame_rate
, jack_time_t time
);
157 void CycleEnd(JackClientInterface
** table
, jack_nframes_t frame_rate
, jack_nframes_t buffer_size
);
162 void SetSyncTimeout(jack_time_t timeout
)
164 fSyncTimeout
= timeout
;
167 void ReadCurrentPos(jack_position_t
* pos
);
169 jack_unique_t
GenerateUniqueID()
171 return (jack_unique_t
)INC_ATOMIC(&fWriteCounter
);
174 void RequestNewPos(jack_position_t
* pos
);
176 jack_transport_state_t
Query(jack_position_t
* pos
);
178 jack_nframes_t
GetCurrentFrame();
180 static void CopyPosition(jack_position_t
* from
, jack_position_t
* to
);
182 bool GetNetworkSync() const
187 void SetNetworkSync(bool sync
)
195 } // end of namespace