Merge branch 'master' into develop
[jack2.git] / common / JackDriver.h
blobc66e2500e2f9bdf919118cdd6fcab1427e67ad59
1 /*
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 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.
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.
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.
21 #ifndef __JackDriver__
22 #define __JackDriver__
24 #include "types.h"
25 #include "JackClientInterface.h"
26 #include "JackConstants.h"
27 #include "JackPlatformPlug.h"
28 #include "JackClientControl.h"
29 #include <list>
31 namespace Jack
34 class JackLockedEngine;
35 class JackGraphManager;
36 struct JackEngineControl;
37 class JackSlaveDriverInterface;
39 /*!
40 \brief The base interface for drivers.
43 class SERVER_EXPORT JackDriverInterface
46 public:
48 JackDriverInterface()
50 virtual ~JackDriverInterface()
53 virtual int Open() = 0;
55 virtual int Open(jack_nframes_t buffer_size,
56 jack_nframes_t samplerate,
57 bool capturing,
58 bool playing,
59 int inchannels,
60 int outchannels,
61 bool monitor,
62 const char* capture_driver_name,
63 const char* playback_driver_name,
64 jack_nframes_t capture_latency,
65 jack_nframes_t playback_latency) = 0;
67 virtual int Attach() = 0;
68 virtual int Detach() = 0;
70 virtual int Read() = 0;
71 virtual int Write() = 0;
73 virtual int Start() = 0;
74 virtual int Stop() = 0;
76 virtual bool IsFixedBufferSize() = 0;
77 virtual int SetBufferSize(jack_nframes_t buffer_size) = 0;
78 virtual int SetSampleRate(jack_nframes_t sample_rate) = 0;
80 virtual int Process() = 0;
82 virtual void SetMaster(bool onoff) = 0;
83 virtual bool GetMaster() = 0;
85 virtual void AddSlave(JackDriverInterface* slave) = 0;
86 virtual void RemoveSlave(JackDriverInterface* slave) = 0;
88 virtual std::list<JackDriverInterface*> GetSlaves() = 0;
90 // For "master" driver
91 virtual int ProcessReadSlaves() = 0;
92 virtual int ProcessWriteSlaves() = 0;
94 // For "slave" driver
95 virtual int ProcessRead() = 0;
96 virtual int ProcessWrite() = 0;
98 // For "slave" driver in "synchronous" mode
99 virtual int ProcessReadSync() = 0;
100 virtual int ProcessWriteSync() = 0;
102 // For "slave" driver in "asynchronous" mode
103 virtual int ProcessReadAsync() = 0;
104 virtual int ProcessWriteAsync() = 0;
106 virtual bool IsRealTime() const = 0;
107 virtual bool IsRunning() const = 0;
111 \brief The base interface for drivers clients.
114 class SERVER_EXPORT JackDriverClientInterface : public JackDriverInterface, public JackClientInterface
118 \brief The base class for drivers.
121 #define CaptureDriverFlags static_cast<JackPortFlags>(JackPortIsOutput | JackPortIsPhysical | JackPortIsTerminal)
122 #define PlaybackDriverFlags static_cast<JackPortFlags>(JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal)
123 #define MonitorDriverFlags static_cast<JackPortFlags>(JackPortIsOutput)
125 typedef std::list<std::pair<std::string, std::pair<std::string, std::string> > > driver_connections_list_t; // [type : (src, dst)]
127 class SERVER_EXPORT JackDriver : public JackDriverClientInterface
130 protected:
132 char fCaptureDriverName[JACK_CLIENT_NAME_SIZE+1];
133 char fPlaybackDriverName[JACK_CLIENT_NAME_SIZE+1];
134 char fAliasName[JACK_CLIENT_NAME_SIZE+1];
136 jack_nframes_t fCaptureLatency;
137 jack_nframes_t fPlaybackLatency;
139 int fCaptureChannels;
140 int fPlaybackChannels;
142 jack_time_t fBeginDateUst;
143 jack_time_t fEndDateUst;
144 float fDelayedUsecs;
146 // Pointers to engine state
147 JackLockedEngine* fEngine;
148 JackGraphManager* fGraphManager;
149 JackSynchro* fSynchroTable;
150 JackEngineControl* fEngineControl;
151 JackClientControl fClientControl;
153 std::list<JackDriverInterface*> fSlaveList;
155 bool fIsMaster;
156 bool fIsRunning;
157 bool fWithMonitorPorts;
159 // Static tables since the actual number of ports may be changed by the real driver
160 // thus dynamic allocation is more difficult to handle
161 jack_port_id_t fCapturePortList[DRIVER_PORT_NUM];
162 jack_port_id_t fPlaybackPortList[DRIVER_PORT_NUM];
163 jack_port_id_t fMonitorPortList[DRIVER_PORT_NUM];
165 driver_connections_list_t fConnections; // Connections list
167 void CycleIncTime();
168 void CycleTakeBeginTime();
169 void CycleTakeEndTime();
171 void SetupDriverSync(int ref, bool freewheel);
173 void NotifyXRun(jack_time_t callback_usecs, float delayed_usecs); // XRun notification sent by the driver
174 void NotifyBufferSize(jack_nframes_t buffer_size); // BufferSize notification sent by the driver
175 void NotifySampleRate(jack_nframes_t sample_rate); // SampleRate notification sent by the driver
176 void NotifyFailure(int code, const char* reason); // Failure notification sent by the driver
178 virtual void SaveConnections(int alias);
179 virtual void LoadConnections(int alias, bool full_name = true);
180 std::string MatchPortName(const char* name, const char** ports, int alias, const std::string& type);
182 virtual int StartSlaves();
183 virtual int StopSlaves();
185 virtual int ResumeRefNum();
186 virtual int SuspendRefNum();
188 public:
190 JackDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table);
191 virtual ~JackDriver();
193 void SetMaster(bool onoff);
194 bool GetMaster();
196 void AddSlave(JackDriverInterface* slave);
197 void RemoveSlave(JackDriverInterface* slave);
199 std::list<JackDriverInterface*> GetSlaves()
201 return fSlaveList;
204 virtual int Open();
206 virtual int Open(jack_nframes_t buffer_size,
207 jack_nframes_t samplerate,
208 bool capturing,
209 bool playing,
210 int inchannels,
211 int outchannels,
212 bool monitor,
213 const char* capture_driver_name,
214 const char* playback_driver_name,
215 jack_nframes_t capture_latency,
216 jack_nframes_t playback_latency);
218 virtual int Close();
220 virtual int Process();
222 virtual int Attach();
223 virtual int Detach();
225 virtual int Read();
226 virtual int Write();
228 virtual int Start();
229 virtual int Stop();
231 // For "master" driver
232 int ProcessReadSlaves();
233 int ProcessWriteSlaves();
235 // For "slave" driver with typically decompose a given cycle in separated Read and Write parts.
236 virtual int ProcessRead();
237 virtual int ProcessWrite();
239 // For "slave" driver in "synchronous" mode
240 virtual int ProcessReadSync();
241 virtual int ProcessWriteSync();
243 // For "slave" driver in "asynchronous" mode
244 virtual int ProcessReadAsync();
245 virtual int ProcessWriteAsync();
247 virtual bool IsFixedBufferSize();
248 virtual int SetBufferSize(jack_nframes_t buffer_size);
249 virtual int SetSampleRate(jack_nframes_t sample_rate);
251 virtual int ClientNotify(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2);
252 virtual JackClientControl* GetClientControl() const;
254 virtual bool IsRealTime() const;
255 virtual bool IsRunning() const { return fIsRunning; }
256 virtual bool Initialize(); // To be called by the wrapping thread Init method when the driver is a "blocking" one
260 } // end of namespace
262 #endif