jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
11KB

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