Jack2  1.9.9
JackDriver.h
1 /*
2  Copyright (C) 2001 Paul Davis
3  Copyright (C) 2004-2008 Grame
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
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 General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19  */
20 
21 #ifndef __JackDriver__
22 #define __JackDriver__
23 
24 #include "types.h"
25 #include "JackClientInterface.h"
26 #include "JackConstants.h"
27 #include "JackPlatformPlug.h"
28 #include "JackClientControl.h"
29 #include <list>
30 
31 namespace Jack
32 {
33 
34 class JackLockedEngine;
35 class JackGraphManager;
36 struct JackEngineControl;
37 class JackSlaveDriverInterface;
38 
43 class SERVER_EXPORT JackDriverInterface
44 {
45 
46  public:
47 
49  {}
50  virtual ~JackDriverInterface()
51  {}
52 
53  virtual int Open() = 0;
54 
55  virtual int Open (bool capturing,
56  bool playing,
57  int inchannels,
58  int outchannels,
59  bool monitor,
60  const char* capture_driver_name,
61  const char* playback_driver_name,
62  jack_nframes_t capture_latency,
63  jack_nframes_t playback_latency) = 0;
64 
65  virtual int Open(jack_nframes_t buffer_size,
66  jack_nframes_t samplerate,
67  bool capturing,
68  bool playing,
69  int inchannels,
70  int outchannels,
71  bool monitor,
72  const char* capture_driver_name,
73  const char* playback_driver_name,
74  jack_nframes_t capture_latency,
75  jack_nframes_t playback_latency) = 0;
76 
77  virtual int Attach() = 0;
78  virtual int Detach() = 0;
79 
80  virtual int Read() = 0;
81  virtual int Write() = 0;
82 
83  virtual int Start() = 0;
84  virtual int Stop() = 0;
85 
86  virtual bool IsFixedBufferSize() = 0;
87  virtual int SetBufferSize(jack_nframes_t buffer_size) = 0;
88  virtual int SetSampleRate(jack_nframes_t sample_rate) = 0;
89 
90  virtual int Process() = 0;
91 
92  virtual void SetMaster(bool onoff) = 0;
93  virtual bool GetMaster() = 0;
94 
95  virtual void AddSlave(JackDriverInterface* slave) = 0;
96  virtual void RemoveSlave(JackDriverInterface* slave) = 0;
97 
98  virtual std::list<JackDriverInterface*> GetSlaves() = 0;
99 
100  // For "master" driver
101  virtual int ProcessReadSlaves() = 0;
102  virtual int ProcessWriteSlaves() = 0;
103 
104  // For "slave" driver
105  virtual int ProcessRead() = 0;
106  virtual int ProcessWrite() = 0;
107 
108  virtual int ProcessReadSync() = 0;
109  virtual int ProcessWriteSync() = 0;
110 
111  virtual int ProcessReadAsync() = 0;
112  virtual int ProcessWriteAsync() = 0;
113 
114  virtual bool IsRealTime() const = 0;
115  virtual bool IsRunning() const = 0;
116 };
117 
123 {};
124 
129 #define CaptureDriverFlags static_cast<JackPortFlags>(JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal)
130 #define PlaybackDriverFlags static_cast<JackPortFlags>(JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal)
131 #define MonitorDriverFlags static_cast<JackPortFlags>(JackPortIsOutput)
132 
133 class SERVER_EXPORT JackDriver : public JackDriverClientInterface
134 {
135 
136  protected:
137 
138  char fCaptureDriverName[JACK_CLIENT_NAME_SIZE + 1];
139  char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE + 1];
140 
141  char fAliasName[JACK_CLIENT_NAME_SIZE + 1];
142 
143  jack_nframes_t fCaptureLatency;
144  jack_nframes_t fPlaybackLatency;
145 
146  int fCaptureChannels;
147  int fPlaybackChannels;
148 
149  jack_time_t fBeginDateUst;
150  jack_time_t fEndDateUst;
151  float fDelayedUsecs;
152 
153  // Pointers to engine state
154  JackLockedEngine* fEngine;
155  JackGraphManager* fGraphManager;
156  JackSynchro* fSynchroTable;
157  JackEngineControl* fEngineControl;
158  JackClientControl fClientControl;
159 
160  std::list<JackDriverInterface*> fSlaveList;
161 
162  bool fIsMaster;
163  bool fIsRunning;
164  bool fWithMonitorPorts;
165 
166  // Static tables since the actual number of ports may be changed by the real driver
167  // thus dynamic allocation is more difficult to handle
168  jack_port_id_t fCapturePortList[DRIVER_PORT_NUM];
169  jack_port_id_t fPlaybackPortList[DRIVER_PORT_NUM];
170  jack_port_id_t fMonitorPortList[DRIVER_PORT_NUM];
171 
172  std::list<std::pair<std::string, std::string> > fConnections; // Connections list
173 
174  void CycleIncTime();
175  void CycleTakeBeginTime();
176  void CycleTakeEndTime();
177 
178  void SetupDriverSync(int ref, bool freewheel);
179 
180  void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
181  void NotifyBufferSize(jack_nframes_t buffer_size); // BufferSize notification sent by the driver
182  void NotifySampleRate(jack_nframes_t sample_rate); // SampleRate notification sent by the driver
183  void NotifyFailure(int code, const char* reason); // Failure notification sent by the driver
184 
185  virtual void SaveConnections();
186  virtual void RestoreConnections();
187 
188  virtual int StartSlaves();
189  virtual int StopSlaves();
190 
191  virtual int ResumeRefNum();
192  virtual int SuspendRefNum();
193 
194  public:
195 
196  JackDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
197  JackDriver();
198  virtual ~JackDriver();
199 
200  void SetMaster(bool onoff);
201  bool GetMaster();
202 
203  void AddSlave(JackDriverInterface* slave);
204  void RemoveSlave(JackDriverInterface* slave);
205 
206  std::list<JackDriverInterface*> GetSlaves()
207  {
208  return fSlaveList;
209  }
210 
211  virtual int Open();
212 
213  virtual int Open(bool capturing,
214  bool playing,
215  int inchannels,
216  int outchannels,
217  bool monitor,
218  const char* capture_driver_name,
219  const char* playback_driver_name,
220  jack_nframes_t capture_latency,
221  jack_nframes_t playback_latency);
222 
223  virtual int Open(jack_nframes_t buffer_size,
224  jack_nframes_t samplerate,
225  bool capturing,
226  bool playing,
227  int inchannels,
228  int outchannels,
229  bool monitor,
230  const char* capture_driver_name,
231  const char* playback_driver_name,
232  jack_nframes_t capture_latency,
233  jack_nframes_t playback_latency);
234 
235  virtual int Close();
236 
237  virtual int Process();
238 
239  virtual int Attach();
240  virtual int Detach();
241 
242  virtual int Read();
243  virtual int Write();
244 
245  virtual int Start();
246  virtual int Stop();
247 
248  // For "master" driver
249  int ProcessReadSlaves();
250  int ProcessWriteSlaves();
251 
252  // For "slave" driver
253  int ProcessRead();
254  int ProcessWrite();
255 
256  int ProcessReadSync();
257  int ProcessWriteSync();
258 
259  int ProcessReadAsync();
260  int ProcessWriteAsync();
261 
262  virtual bool IsFixedBufferSize();
263  virtual int SetBufferSize(jack_nframes_t buffer_size);
264  virtual int SetSampleRate(jack_nframes_t sample_rate);
265 
266  virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
267  virtual JackClientControl* GetClientControl() const;
268 
269  virtual bool IsRealTime() const;
270  virtual bool IsRunning() const { return fIsRunning; }
271  virtual bool Initialize(); // To be called by the wrapping thread Init method when the driver is a "blocking" one
272 
273 };
274 
275 } // end of namespace
276 
277 #endif
The base interface for drivers.
Definition: JackDriver.h:43
Inter process synchronization using using Mach semaphore.
Locked Engine, access to methods is serialized using a mutex.
Graph manager: contains the connection manager and the port array.
The base interface for drivers clients.
Definition: JackDriver.h:122
Engine control in shared memory.
Client control possibly in shared memory.