| 1 |
/* |
|---|
| 2 |
Copyright (C) 2009 Grame |
|---|
| 3 |
|
|---|
| 4 |
This program is free software; you can redistribute it and/or modify |
|---|
| 5 |
it under the terms of the GNU Lesser General Public License as published by |
|---|
| 6 |
the Free Software Foundation; either version 2.1 of the License, or |
|---|
| 7 |
(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 Lesser General Public License for more details. |
|---|
| 13 |
|
|---|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
|---|
| 15 |
along with this program; if not, write to the Free Software |
|---|
| 16 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 17 |
|
|---|
| 18 |
*/ |
|---|
| 19 |
|
|---|
| 20 |
#ifndef __net_h__ |
|---|
| 21 |
#define __net_h__ |
|---|
| 22 |
|
|---|
| 23 |
#ifdef __cplusplus |
|---|
| 24 |
extern "C" |
|---|
| 25 |
{ |
|---|
| 26 |
#endif |
|---|
| 27 |
|
|---|
| 28 |
#include <jack/systemdeps.h> |
|---|
| 29 |
#include <jack/types.h> |
|---|
| 30 |
|
|---|
| 31 |
#define DEFAULT_MULTICAST_IP "225.3.19.154" |
|---|
| 32 |
#define DEFAULT_PORT 19000 |
|---|
| 33 |
#define DEFAULT_MTU 1500 |
|---|
| 34 |
#define MASTER_NAME_SIZE 256 |
|---|
| 35 |
|
|---|
| 36 |
#define SOCKET_ERROR -1 |
|---|
| 37 |
|
|---|
| 38 |
enum JackNetMode { |
|---|
| 39 |
|
|---|
| 40 |
JackFastMode = 'f', |
|---|
| 41 |
JackNormalMode = 'n', |
|---|
| 42 |
JackSlowMode = 's', |
|---|
| 43 |
}; |
|---|
| 44 |
|
|---|
| 45 |
typedef struct { |
|---|
| 46 |
|
|---|
| 47 |
int audio_input; // from master or to slave |
|---|
| 48 |
int audio_output; // to master or from slave |
|---|
| 49 |
int midi_input; // from master or to slave |
|---|
| 50 |
int midi_output; // to master or from slave |
|---|
| 51 |
int mtu; |
|---|
| 52 |
int time_out; // in second, -1 means in infinite |
|---|
| 53 |
char mode; |
|---|
| 54 |
|
|---|
| 55 |
} jack_slave_t; |
|---|
| 56 |
|
|---|
| 57 |
typedef struct { |
|---|
| 58 |
|
|---|
| 59 |
jack_nframes_t buffer_size; |
|---|
| 60 |
jack_nframes_t sample_rate; |
|---|
| 61 |
char master_name[MASTER_NAME_SIZE]; |
|---|
| 62 |
|
|---|
| 63 |
} jack_master_t; |
|---|
| 64 |
|
|---|
| 65 |
/** |
|---|
| 66 |
* jack_net_t is an opaque type. You may only access it using the |
|---|
| 67 |
* API provided. |
|---|
| 68 |
*/ |
|---|
| 69 |
typedef struct _jack_net_slave jack_net_slave_t; |
|---|
| 70 |
|
|---|
| 71 |
/** |
|---|
| 72 |
* Open a network connection with the master machine. |
|---|
| 73 |
* @param ip the multicast address of the master |
|---|
| 74 |
* @param port the connection port |
|---|
| 75 |
* @param request a connection request structure |
|---|
| 76 |
* @param result a connection result structure |
|---|
| 77 |
* |
|---|
| 78 |
* @return Opaque net handle if successful or NULL in case of error. |
|---|
| 79 |
*/ |
|---|
| 80 |
jack_net_slave_t* jack_net_slave_open(const char* ip, int port, const char* name, jack_slave_t* request, jack_master_t* result); |
|---|
| 81 |
|
|---|
| 82 |
/** |
|---|
| 83 |
* Close the network connection with the master machine. |
|---|
| 84 |
* @param net the network connection to be closed |
|---|
| 85 |
* |
|---|
| 86 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 87 |
*/ |
|---|
| 88 |
int jack_net_slave_close(jack_net_slave_t* net); |
|---|
| 89 |
|
|---|
| 90 |
/** |
|---|
| 91 |
* Prototype for Process callback. |
|---|
| 92 |
* @param nframes buffer size |
|---|
| 93 |
* @param audio_input number of audio inputs |
|---|
| 94 |
* @param audio_input_buffer an array of audio input buffers |
|---|
| 95 |
* @param midi_input number of MIDI inputs |
|---|
| 96 |
* @param midi_input_buffer an array of MIDI input buffers |
|---|
| 97 |
* @param audio_output number of audio outputs |
|---|
| 98 |
* @param audio_output_buffer an array of audio output buffers |
|---|
| 99 |
* @param midi_output number of MIDI outputs |
|---|
| 100 |
* @param midi_output_buffer an array of MIDI output buffers |
|---|
| 101 |
* @param arg pointer to a client supplied structure supplied by jack_set_net_process_callback(). |
|---|
| 102 |
* |
|---|
| 103 |
* @return zero on success, non-zero on error |
|---|
| 104 |
*/ |
|---|
| 105 |
typedef int (* JackNetSlaveProcessCallback) (jack_nframes_t buffer_size, |
|---|
| 106 |
int audio_input, |
|---|
| 107 |
float** audio_input_buffer, |
|---|
| 108 |
int midi_input, |
|---|
| 109 |
void** midi_input_buffer, |
|---|
| 110 |
int audio_output, |
|---|
| 111 |
float** audio_output_buffer, |
|---|
| 112 |
int midi_output, |
|---|
| 113 |
void** midi_output_buffer, |
|---|
| 114 |
void* data); |
|---|
| 115 |
|
|---|
| 116 |
/** |
|---|
| 117 |
* Set network process callback. |
|---|
| 118 |
* @param net the network connection |
|---|
| 119 |
* @param net_callback the process callback |
|---|
| 120 |
* @param arg pointer to a client supplied structure |
|---|
| 121 |
* |
|---|
| 122 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 123 |
*/ |
|---|
| 124 |
int jack_set_net_slave_process_callback(jack_net_slave_t * net, JackNetSlaveProcessCallback net_callback, void *arg); |
|---|
| 125 |
|
|---|
| 126 |
/** |
|---|
| 127 |
* Start processing thread, the net_callback will start to be called. |
|---|
| 128 |
* @param net the network connection |
|---|
| 129 |
* |
|---|
| 130 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 131 |
*/ |
|---|
| 132 |
int jack_net_slave_activate(jack_net_slave_t* net); |
|---|
| 133 |
|
|---|
| 134 |
/** |
|---|
| 135 |
* Stop processing thread. |
|---|
| 136 |
* @param net the network connection |
|---|
| 137 |
* |
|---|
| 138 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 139 |
*/ |
|---|
| 140 |
int jack_net_slave_deactivate(jack_net_slave_t* net); |
|---|
| 141 |
|
|---|
| 142 |
/** |
|---|
| 143 |
* Prototype for BufferSize callback. |
|---|
| 144 |
* @param nframes buffer size |
|---|
| 145 |
* @param arg pointer to a client supplied structure supplied by jack_set_net_buffer_size_callback(). |
|---|
| 146 |
* |
|---|
| 147 |
* @return zero on success, non-zero on error |
|---|
| 148 |
*/ |
|---|
| 149 |
typedef int (*JackNetSlaveBufferSizeCallback)(jack_nframes_t nframes, void *arg); |
|---|
| 150 |
|
|---|
| 151 |
/** |
|---|
| 152 |
* Prototype for SampleRate callback |
|---|
| 153 |
* @param nframes sample rate |
|---|
| 154 |
* @param arg pointer to a client supplied structure supplied by jack_set_net_sample_rate_callback(). |
|---|
| 155 |
* |
|---|
| 156 |
* @return zero on success, non-zero on error |
|---|
| 157 |
*/ |
|---|
| 158 |
typedef int (*JackNetSlaveSampleRateCallback)(jack_nframes_t nframes, void *arg); |
|---|
| 159 |
|
|---|
| 160 |
/** |
|---|
| 161 |
* Set network buffer size callback. |
|---|
| 162 |
* @param net the network connection |
|---|
| 163 |
* @param bufsize_callback the buffer size callback |
|---|
| 164 |
* @param arg pointer to a client supplied structure |
|---|
| 165 |
* |
|---|
| 166 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 167 |
*/ |
|---|
| 168 |
int jack_set_net_slave_buffer_size_callback(jack_net_slave_t *net, JackNetSlaveBufferSizeCallback bufsize_callback, void *arg); |
|---|
| 169 |
|
|---|
| 170 |
/** |
|---|
| 171 |
* Set network sample rate callback. |
|---|
| 172 |
* @param net the network connection |
|---|
| 173 |
* @param samplerate_callback the sample rate callback |
|---|
| 174 |
* @param arg pointer to a client supplied structure |
|---|
| 175 |
* |
|---|
| 176 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 177 |
*/ |
|---|
| 178 |
int jack_set_net_slave_sample_rate_callback(jack_net_slave_t *net, JackNetSlaveSampleRateCallback samplerate_callback, void *arg); |
|---|
| 179 |
|
|---|
| 180 |
/** |
|---|
| 181 |
* Prototype for server Shutdown callback (if not set, the client will just restart, waiting for an available master again.) |
|---|
| 182 |
* @param arg pointer to a client supplied structure supplied by jack_set_net_shutdown_callback(). |
|---|
| 183 |
*/ |
|---|
| 184 |
typedef void (*JackNetSlaveShutdownCallback)(void* data); |
|---|
| 185 |
|
|---|
| 186 |
/** |
|---|
| 187 |
* Set network shutdown callback. |
|---|
| 188 |
* @param net the network connection |
|---|
| 189 |
* @param shutdown_callback the shutdown callback |
|---|
| 190 |
* @param arg pointer to a client supplied structure |
|---|
| 191 |
* |
|---|
| 192 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 193 |
*/ |
|---|
| 194 |
int jack_set_net_slave_shutdown_callback(jack_net_slave_t *net, JackNetSlaveShutdownCallback shutdown_callback, void *arg); |
|---|
| 195 |
|
|---|
| 196 |
/** |
|---|
| 197 |
* jack_net_t is an opaque type. You may only access it using the |
|---|
| 198 |
* API provided. |
|---|
| 199 |
*/ |
|---|
| 200 |
typedef struct _jack_net_master jack_net_master_t; |
|---|
| 201 |
|
|---|
| 202 |
/** |
|---|
| 203 |
* Open a network connection with the slave machine. |
|---|
| 204 |
* @param ip the multicast address of the master |
|---|
| 205 |
* @param port the connection port |
|---|
| 206 |
* @param request a connection request structure |
|---|
| 207 |
* @param result a connection result structure |
|---|
| 208 |
* |
|---|
| 209 |
* @return Opaque net handle if successful or NULL in case of error. |
|---|
| 210 |
*/ |
|---|
| 211 |
jack_net_master_t* jack_net_master_open(const char* ip, int port, const char* name, jack_master_t* request, jack_slave_t* result); |
|---|
| 212 |
|
|---|
| 213 |
/** |
|---|
| 214 |
* Close the network connection with the master machine. |
|---|
| 215 |
* @param net the network connection to be closed |
|---|
| 216 |
* |
|---|
| 217 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 218 |
*/ |
|---|
| 219 |
int jack_net_master_close(jack_net_master_t* net); |
|---|
| 220 |
|
|---|
| 221 |
/** |
|---|
| 222 |
* Receive sync and data from the network |
|---|
| 223 |
* @param net the network connection |
|---|
| 224 |
* @param audio_input number of audio inputs |
|---|
| 225 |
* @param audio_input_buffer an array of audio input buffers |
|---|
| 226 |
* @param midi_input number of MIDI inputs |
|---|
| 227 |
* @param midi_input_buffer an array of MIDI input buffers |
|---|
| 228 |
* |
|---|
| 229 |
* @return zero on success, non-zero on error |
|---|
| 230 |
*/ |
|---|
| 231 |
int jack_net_master_recv(jack_net_master_t* net, int audio_input, float** audio_input_buffer, int midi_input, void** midi_input_buffer); |
|---|
| 232 |
|
|---|
| 233 |
/** |
|---|
| 234 |
* Send sync and data to the network |
|---|
| 235 |
* @param net the network connection |
|---|
| 236 |
* @param audio_output number of audio ouputs |
|---|
| 237 |
* @param audio_output_buffer an array of audio output buffers |
|---|
| 238 |
* @param midi_output number of MIDI ouputs |
|---|
| 239 |
* @param midi_output_buffer an array of MIDI output buffers |
|---|
| 240 |
* |
|---|
| 241 |
* @return zero on success, non-zero on error |
|---|
| 242 |
*/ |
|---|
| 243 |
int jack_net_master_send(jack_net_master_t* net, int audio_output, float** audio_output_buffer, int midi_output, void** midi_output_buffer); |
|---|
| 244 |
|
|---|
| 245 |
// Experimental Adapter API |
|---|
| 246 |
|
|---|
| 247 |
/** |
|---|
| 248 |
* jack_adapter_t is an opaque type. You may only access it using the |
|---|
| 249 |
* API provided. |
|---|
| 250 |
*/ |
|---|
| 251 |
typedef struct _jack_adapter jack_adapter_t; |
|---|
| 252 |
|
|---|
| 253 |
/** |
|---|
| 254 |
* Create an adapter. |
|---|
| 255 |
* |
|---|
| 256 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 257 |
*/ |
|---|
| 258 |
jack_adapter_t* jack_create_adapter(int input, int output, |
|---|
| 259 |
jack_nframes_t host_buffer_size, |
|---|
| 260 |
jack_nframes_t host_sample_rate, |
|---|
| 261 |
jack_nframes_t adapted_buffer_size, |
|---|
| 262 |
jack_nframes_t adapted_sample_rate); |
|---|
| 263 |
|
|---|
| 264 |
/** |
|---|
| 265 |
* Destroy an adapter. |
|---|
| 266 |
* |
|---|
| 267 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 268 |
*/ |
|---|
| 269 |
int jack_destroy_adapter(jack_adapter_t* adapter); |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
void jack_flush_adapter(jack_adapter_t* adapter); |
|---|
| 273 |
|
|---|
| 274 |
/** |
|---|
| 275 |
* Push input to and pull output from ringbuffer |
|---|
| 276 |
* |
|---|
| 277 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 278 |
*/ |
|---|
| 279 |
int jack_adapter_push_and_pull(jack_adapter_t* adapter, float** input, float** output, unsigned int frames); |
|---|
| 280 |
|
|---|
| 281 |
/** |
|---|
| 282 |
* Pull input to and push output from ringbuffer |
|---|
| 283 |
* |
|---|
| 284 |
* @return 0 on success, otherwise a non-zero error code |
|---|
| 285 |
*/ |
|---|
| 286 |
int jack_adapter_pull_and_push(jack_adapter_t* adapter, float** input, float** output, unsigned int frames); |
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
#ifdef __cplusplus |
|---|
| 290 |
} |
|---|
| 291 |
#endif |
|---|
| 292 |
|
|---|
| 293 |
#endif /* __net_h__ */ |
|---|