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__
25 #include "JackClientInterface.h"
26 #include "JackConstants.h"
27 #include "JackPlatformPlug.h"
28 #include "JackClientControl.h"
34 class JackLockedEngine
;
35 class JackGraphManager
;
36 struct JackEngineControl
;
37 class JackSlaveDriverInterface
;
40 \brief The base interface for drivers.
43 class SERVER_EXPORT JackDriverInterface
50 virtual ~JackDriverInterface()
53 virtual int Open() = 0;
55 virtual int Open(jack_nframes_t buffer_size
,
56 jack_nframes_t samplerate
,
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;
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
132 char fCaptureDriverName
[JACK_CLIENT_NAME_SIZE
+ 1];
133 char fPlaybackDriverName
[JACK_CLIENT_NAME_SIZE
+ 1];
135 char fAliasName
[JACK_CLIENT_NAME_SIZE
+ 1];
137 jack_nframes_t fCaptureLatency
;
138 jack_nframes_t fPlaybackLatency
;
140 int fCaptureChannels
;
141 int fPlaybackChannels
;
143 jack_time_t fBeginDateUst
;
144 jack_time_t fEndDateUst
;
147 // Pointers to engine state
148 JackLockedEngine
* fEngine
;
149 JackGraphManager
* fGraphManager
;
150 JackSynchro
* fSynchroTable
;
151 JackEngineControl
* fEngineControl
;
152 JackClientControl fClientControl
;
154 std::list
<JackDriverInterface
*> fSlaveList
;
158 bool fWithMonitorPorts
;
160 // Static tables since the actual number of ports may be changed by the real driver
161 // thus dynamic allocation is more difficult to handle
162 jack_port_id_t fCapturePortList
[DRIVER_PORT_NUM
];
163 jack_port_id_t fPlaybackPortList
[DRIVER_PORT_NUM
];
164 jack_port_id_t fMonitorPortList
[DRIVER_PORT_NUM
];
166 driver_connections_list_t fConnections
; // Connections list
169 void CycleTakeBeginTime();
170 void CycleTakeEndTime();
172 void SetupDriverSync(int ref
, bool freewheel
);
174 void NotifyXRun(jack_time_t callback_usecs
, float delayed_usecs
); // XRun notification sent by the driver
175 void NotifyBufferSize(jack_nframes_t buffer_size
); // BufferSize notification sent by the driver
176 void NotifySampleRate(jack_nframes_t sample_rate
); // SampleRate notification sent by the driver
177 void NotifyFailure(int code
, const char* reason
); // Failure notification sent by the driver
179 virtual void SaveConnections(int alias
);
180 virtual void LoadConnections(int alias
, bool full_name
= true);
181 std::string
MatchPortName(const char* name
, const char** ports
, int alias
, const std::string
& type
);
183 virtual int StartSlaves();
184 virtual int StopSlaves();
186 virtual int ResumeRefNum();
187 virtual int SuspendRefNum();
191 JackDriver(const char* name
, const char* alias
, JackLockedEngine
* engine
, JackSynchro
* table
);
192 virtual ~JackDriver();
194 void SetMaster(bool onoff
);
197 void AddSlave(JackDriverInterface
* slave
);
198 void RemoveSlave(JackDriverInterface
* slave
);
200 std::list
<JackDriverInterface
*> GetSlaves()
207 virtual int Open(jack_nframes_t buffer_size
,
208 jack_nframes_t samplerate
,
214 const char* capture_driver_name
,
215 const char* playback_driver_name
,
216 jack_nframes_t capture_latency
,
217 jack_nframes_t playback_latency
);
221 virtual int Process();
223 virtual int Attach();
224 virtual int Detach();
232 // For "master" driver
233 int ProcessReadSlaves();
234 int ProcessWriteSlaves();
236 // For "slave" driver with typically decompose a given cycle in separated Read and Write parts.
237 virtual int ProcessRead();
238 virtual int ProcessWrite();
240 // For "slave" driver in "synchronous" mode
241 virtual int ProcessReadSync();
242 virtual int ProcessWriteSync();
244 // For "slave" driver in "asynchronous" mode
245 virtual int ProcessReadAsync();
246 virtual int ProcessWriteAsync();
248 virtual bool IsFixedBufferSize();
249 virtual int SetBufferSize(jack_nframes_t buffer_size
);
250 virtual int SetSampleRate(jack_nframes_t sample_rate
);
252 virtual int ClientNotify(int refnum
, const char* name
, int notify
, int sync
, const char* message
, int value1
, int value2
);
253 virtual JackClientControl
* GetClientControl() const;
255 virtual bool IsRealTime() const;
256 virtual bool IsRunning() const { return fIsRunning
; }
257 virtual bool Initialize(); // To be called by the wrapping thread Init method when the driver is a "blocking" one
261 } // end of namespace