Jack2: JackProxyDriver.h Source File

Jack2 1.9.12

JackProxyDriver.h
1 /*
2 Copyright (C) 2014 Cédric Schieli
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 */
19
20 #ifndef __JackProxyDriver__
21 #define __JackProxyDriver__
22
23 #include "JackTimedDriver.h"
24
25 #define DEFAULT_UPSTREAM "default"
26 #define DEFAULT_CLIENT_NAME "proxy"
28 #ifdef __APPLE__
29 #define JACK_PROXY_CLIENT_LIB "libjack.0.dylib"
30 #elif defined(WIN32)
31 #ifdef _WIN64
32 #define JACK_PROXY_CLIENT_LIB "libjack64.dll"
33 #else
34 #define JACK_PROXY_CLIENT_LIB "libjack.dll"
35 #endif
36 #else
37 #define JACK_PROXY_CLIENT_LIB "libjack.so.0"
38 #endif
39
40 #define PROXY_DEF_SYMBOL(ret,name,...) ret (*name) (__VA_ARGS__)
41 #define PROXY_LOAD_SYMBOL(ret,name,...) name = (ret (*) (__VA_ARGS__)) GetJackProc(fHandle, #name); assert(name)
42
43 namespace Jack
44 {
60 class JackProxyDriver : public JackRestarterDriver
61 {
62
63 private:
64
65 char fUpstream[JACK_CLIENT_NAME_SIZE+1]; /*<! the upstream server name */
66 char fClientName[JACK_CLIENT_NAME_SIZE+1]; /*<! client name to use when connecting */
67 const char* fPromiscuous; /*<! if not null, group or gid to use for promiscuous mode */
68
69 //jack data
70 jack_client_t* fClient; /*<! client handle */
71 jack_port_t** fUpstreamCapturePorts; /*<! ports registered for capture in the upstream server */
72 jack_port_t** fUpstreamPlaybackPorts; /*<! ports registered for playback in the upstream server */
73 int* fUpstreamCapturePortConnected; /*<! map of capture ports connected upstream, for optimization purpose */
74 int* fUpstreamPlaybackPortConnected; /*<! map of playback ports connected upstream, for optimization purpose */
75
76 bool fAutoSave; /*<! wether the local connections should be saved/restored when upstream connection is restarted */
77 bool fAutoConnect; /*<! wether the upstream ports should be automatically connected to upstream physical ports */
78 bool fDetectPlaybackChannels; /*<! wether the number of playback ports registered should match the number of upstream physical playback ports */
79 bool fDetectCaptureChannels; /*<! wether the number of capture ports registered should match the number of upstream physical capture ports */
80
81 bool Initialize(); /*<! establish upstream connection and register the client callbacks */
82
83 int AllocPorts(); /*<! register local and upstream ports */
84 int FreePorts(); /*<! unregister local ports */
85 void ConnectPorts(); /*<! connect upstream ports to physical ones */
86
87 int CountIO(const char*, int); /*<! get the number of upstream ports of a specific type */
88
89 // client callbacks
90 static int process_callback(jack_nframes_t, void*);
91 static int bufsize_callback(jack_nframes_t, void*);
92 static int srate_callback(jack_nframes_t, void*);
93 static void connect_callback(jack_port_id_t, jack_port_id_t, int, void*);
94 static void shutdown_callback(void*);
95
96 // indirect member callbacks
97 int bufsize_callback(jack_nframes_t);
98 int srate_callback(jack_nframes_t);
99 void connect_callback(jack_port_id_t, jack_port_id_t, int);
100
101 JACK_HANDLE fHandle; /*<! handle to the jack client library */
102
103 // map needed client library symbols as members to override those from the jackserver library
104 PROXY_DEF_SYMBOL(jack_client_t*, jack_client_open, const char*, jack_options_t, jack_status_t*, ...);
105 PROXY_DEF_SYMBOL(int, jack_set_process_callback, jack_client_t*, JackProcessCallback, void*);
106 PROXY_DEF_SYMBOL(int, jack_set_buffer_size_callback, jack_client_t*, JackBufferSizeCallback, void*);
107 PROXY_DEF_SYMBOL(int, jack_set_sample_rate_callback, jack_client_t*, JackSampleRateCallback, void*);
108 PROXY_DEF_SYMBOL(int, jack_set_port_connect_callback, jack_client_t*, JackPortConnectCallback, void*);
109 PROXY_DEF_SYMBOL(void, jack_on_shutdown, jack_client_t*, JackShutdownCallback, void*);
110 PROXY_DEF_SYMBOL(jack_nframes_t, jack_get_buffer_size, jack_client_t*);
111 PROXY_DEF_SYMBOL(jack_nframes_t, jack_get_sample_rate, jack_client_t*);
112 PROXY_DEF_SYMBOL(int, jack_activate, jack_client_t*);
113 PROXY_DEF_SYMBOL(int, jack_deactivate, jack_client_t*);
114 PROXY_DEF_SYMBOL(jack_port_t*, jack_port_by_id, jack_client_t*, jack_port_id_t);
115 PROXY_DEF_SYMBOL(int, jack_port_is_mine, const jack_client_t*, const jack_port_t*);
116 PROXY_DEF_SYMBOL(const char**, jack_get_ports, jack_client_t*, const char*, const char*, unsigned long);
117 PROXY_DEF_SYMBOL(void, jack_free, void*);
118 PROXY_DEF_SYMBOL(jack_port_t*, jack_port_register, jack_client_t*, const char*, const char*, unsigned long, unsigned long);
119 PROXY_DEF_SYMBOL(int, jack_port_unregister, jack_client_t*, jack_port_t*);
120 PROXY_DEF_SYMBOL(void*, jack_port_get_buffer, jack_port_t*, jack_nframes_t);
121 PROXY_DEF_SYMBOL(int, jack_connect, jack_client_t*, const char*, const char*);
122 PROXY_DEF_SYMBOL(const char*, jack_port_name, const jack_port_t*);
123 PROXY_DEF_SYMBOL(int, jack_client_close, jack_client_t*);
124
126 void LoadSymbols()
127 {
128 PROXY_LOAD_SYMBOL(jack_client_t*, jack_client_open, const char*, jack_options_t, jack_status_t*, ...);
129 PROXY_LOAD_SYMBOL(int, jack_set_process_callback, jack_client_t*, JackProcessCallback, void*);
130 PROXY_LOAD_SYMBOL(int, jack_set_buffer_size_callback, jack_client_t*, JackBufferSizeCallback, void*);
131 PROXY_LOAD_SYMBOL(int, jack_set_sample_rate_callback, jack_client_t*, JackSampleRateCallback, void*);
132 PROXY_LOAD_SYMBOL(int, jack_set_port_connect_callback, jack_client_t*, JackPortConnectCallback, void*);
133 PROXY_LOAD_SYMBOL(void, jack_on_shutdown, jack_client_t*, JackShutdownCallback, void*);
134 PROXY_LOAD_SYMBOL(jack_nframes_t, jack_get_buffer_size, jack_client_t*);
135 PROXY_LOAD_SYMBOL(jack_nframes_t, jack_get_sample_rate, jack_client_t*);
136 PROXY_LOAD_SYMBOL(int, jack_activate, jack_client_t*);
137 PROXY_LOAD_SYMBOL(int, jack_deactivate, jack_client_t*);
138 PROXY_LOAD_SYMBOL(jack_port_t*, jack_port_by_id, jack_client_t*, jack_port_id_t);
139 PROXY_LOAD_SYMBOL(int, jack_port_is_mine, const jack_client_t*, const jack_port_t*);
140 PROXY_LOAD_SYMBOL(const char**, jack_get_ports, jack_client_t*, const char*, const char*, unsigned long);
141 PROXY_LOAD_SYMBOL(void, jack_free, void*);
142 PROXY_LOAD_SYMBOL(jack_port_t*, jack_port_register, jack_client_t*, const char*, const char*, unsigned long, unsigned long);
143 PROXY_LOAD_SYMBOL(int, jack_port_unregister, jack_client_t*, jack_port_t*);
144 PROXY_LOAD_SYMBOL(void*, jack_port_get_buffer, jack_port_t*, jack_nframes_t);
145 PROXY_LOAD_SYMBOL(int, jack_connect, jack_client_t*, const char*, const char*);
146 PROXY_LOAD_SYMBOL(const char*, jack_port_name, const jack_port_t*);
147 PROXY_LOAD_SYMBOL(int, jack_client_close, jack_client_t*);
148 }
149 int LoadClientLib();
151 public:
152
153 JackProxyDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table,
154 const char* upstream, const char* promiscuous, char* client_name, bool auto_connect, bool auto_save);
155 virtual ~JackProxyDriver();
156
157 int Open(jack_nframes_t buffer_size,
158 jack_nframes_t samplerate,
159 bool capturing,
160 bool playing,
161 int inchannels,
162 int outchannels,
163 bool monitor,
164 const char* capture_driver_name,
165 const char* playback_driver_name,
166 jack_nframes_t capture_latency,
167 jack_nframes_t playback_latency);
168 int Close();
169
170 int Stop();
171
172 int Attach();
173 int Detach();
174
175 int Read();
176 int Write();
177
178 };
179 }
180
181 #endif
jack_port_unregister
LIB_EXPORT int jack_port_unregister(jack_client_t *, jack_port_t *)
Definition: JackAPI.cpp:1109
Jack
Definition: JackAC3Encoder.cpp:30
Jack::JackLockedEngine
Locked Engine, access to methods is serialized using a mutex.
Definition: JackLockedEngine.h:78
jack_port_by_id
LIB_EXPORT jack_port_t * jack_port_by_id(jack_client_t *client, jack_port_id_t port_id)
Definition: JackAPI.cpp:1326
Jack::JackPosixSemaphore
Inter process synchronization using POSIX semaphore.
Definition: JackPosixSemaphore.h:36
jack_set_process_callback
LIB_EXPORT int jack_set_process_callback(jack_client_t *client, JackProcessCallback process_callback, void *arg)
Definition: JackAPI.cpp:829
jack_activate
LIB_EXPORT int jack_activate(jack_client_t *client)
Definition: JackAPI.cpp:1067
Jack::JackProxyDriver
Definition: JackProxyDriver.h:60
jack_connect
LIB_EXPORT int jack_connect(jack_client_t *, const char *source_port, const char *destination_port)
Definition: JackAPI.cpp:1211
jack_port_register
LIB_EXPORT jack_port_t * jack_port_register(jack_client_t *client, const char *port_name, const char *port_type, unsigned long flags, unsigned long buffer_size)
Definition: JackAPI.cpp:1093
jack_on_shutdown
LIB_EXPORT void jack_on_shutdown(jack_client_t *client, JackShutdownCallback shutdown_callback, void *arg)
Definition: JackAPI.cpp:805
jack_set_port_connect_callback
LIB_EXPORT int jack_set_port_connect_callback(jack_client_t *, JackPortConnectCallback connect_callback, void *arg)
Definition: JackAPI.cpp:987
jack_client_open
LIB_EXPORT jack_client_t * jack_client_open(const char *client_name, jack_options_t options, jack_status_t *status,...)
Definition: JackLibAPI.cpp:167
jack_get_buffer_size
LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t *)
Definition: JackAPI.cpp:1275
jack_set_sample_rate_callback
LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t *client, JackSampleRateCallback srate_callback, void *arg)
Definition: JackAPI.cpp:948
jack_port_get_buffer
LIB_EXPORT void * jack_port_get_buffer(jack_port_t *, jack_nframes_t)
Definition: JackAPI.cpp:363
jack_port_is_mine
LIB_EXPORT int jack_port_is_mine(const jack_client_t *, const jack_port_t *port)
Definition: JackAPI.cpp:1127
jack_get_sample_rate
LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t *)
Definition: JackAPI.cpp:1261
jack_set_buffer_size_callback
LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t *client, JackBufferSizeCallback bufsize_callback, void *arg)
Definition: JackAPI.cpp:935
Jack::JackRestarterDriver
A restartable driver.
Definition: JackTimedDriver.h:84
jack_port_name
LIB_EXPORT const char * jack_port_name(const jack_port_t *port)
Definition: JackAPI.cpp:383
jack_get_ports
LIB_EXPORT const char ** jack_get_ports(jack_client_t *, const char *port_name_pattern, const char *type_name_pattern, unsigned long flags)
Definition: JackAPI.cpp:1289
jack_deactivate
LIB_EXPORT int jack_deactivate(jack_client_t *client)
Definition: JackAPI.cpp:1080
jack_client_close
LIB_EXPORT int jack_client_close(jack_client_t *client)
Definition: JackLibAPI.cpp:189