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.

322 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 JackNetMode {
  29. JackFastMode = 'f',
  30. JackNormalMode = 'n',
  31. JackSlowMode = 's',
  32. };
  33. enum JackNetEncoder {
  34. JackFloatEncoder = 0, // Samples are transmitted as float
  35. JackIntEncoder = 1, // Samples are transmitted as 16 bits integer
  36. JackCeltEncoder = 2, // Samples are transmitted using CELT codec (http://www.celt-codec.org/)
  37. };
  38. typedef struct {
  39. int audio_input; // from master or to slave
  40. int audio_output; // to master or from slave
  41. int midi_input; // from master or to slave
  42. int midi_output; // to master or from slave
  43. int mtu; // network Maximum Transmission Unit
  44. int time_out; // in second, -1 means in infinite
  45. int encoder; // Encoder type (one of JackNetEncoder)
  46. int kbps; // KB per second for CELT encoder
  47. char mode;
  48. } jack_slave_t;
  49. typedef struct {
  50. jack_nframes_t buffer_size;
  51. jack_nframes_t sample_rate;
  52. char master_name[MASTER_NAME_SIZE];
  53. } jack_master_t;
  54. /**
  55. * jack_net_t is an opaque type. You may only access it using the
  56. * API provided.
  57. */
  58. typedef struct _jack_net_slave jack_net_slave_t;
  59. /**
  60. * Open a network connection with the master machine.
  61. * @param ip the multicast address of the master
  62. * @param port the connection port
  63. * @param request a connection request structure
  64. * @param result a connection result structure
  65. *
  66. * @return Opaque net handle if successful or NULL in case of error.
  67. */
  68. jack_net_slave_t* jack_net_slave_open(const char* ip, int port, const char* name, jack_slave_t* request, jack_master_t* result);
  69. /**
  70. * Close the network connection with the master machine.
  71. * @param net the network connection to be closed
  72. *
  73. * @return 0 on success, otherwise a non-zero error code
  74. */
  75. int jack_net_slave_close(jack_net_slave_t* net);
  76. /**
  77. * Prototype for Process callback.
  78. * @param nframes buffer size
  79. * @param audio_input number of audio inputs
  80. * @param audio_input_buffer an array of audio input buffers (from master)
  81. * @param midi_input number of MIDI inputs
  82. * @param midi_input_buffer an array of MIDI input buffers (from master)
  83. * @param audio_output number of audio outputs
  84. * @param audio_output_buffer an array of audio output buffers (to master)
  85. * @param midi_output number of MIDI outputs
  86. * @param midi_output_buffer an array of MIDI output buffers (to master)
  87. * @param arg pointer to a client supplied structure supplied by jack_set_net_process_callback().
  88. *
  89. * @return zero on success, non-zero on error
  90. */
  91. typedef int (* JackNetSlaveProcessCallback) (jack_nframes_t buffer_size,
  92. int audio_input,
  93. float** audio_input_buffer,
  94. int midi_input,
  95. void** midi_input_buffer,
  96. int audio_output,
  97. float** audio_output_buffer,
  98. int midi_output,
  99. void** midi_output_buffer,
  100. void* data);
  101. /**
  102. * Set network process callback.
  103. * @param net the network connection
  104. * @param net_callback the process callback
  105. * @param arg pointer to a client supplied structure
  106. *
  107. * @return 0 on success, otherwise a non-zero error code
  108. */
  109. int jack_set_net_slave_process_callback(jack_net_slave_t * net, JackNetSlaveProcessCallback net_callback, void *arg);
  110. /**
  111. * Start processing thread, the net_callback will start to be called.
  112. * @param net the network connection
  113. *
  114. * @return 0 on success, otherwise a non-zero error code
  115. */
  116. int jack_net_slave_activate(jack_net_slave_t* net);
  117. /**
  118. * Stop processing thread.
  119. * @param net the network connection
  120. *
  121. * @return 0 on success, otherwise a non-zero error code
  122. */
  123. int jack_net_slave_deactivate(jack_net_slave_t* net);
  124. /**
  125. * Prototype for BufferSize callback.
  126. * @param nframes buffer size
  127. * @param arg pointer to a client supplied structure supplied by jack_set_net_buffer_size_callback().
  128. *
  129. * @return zero on success, non-zero on error
  130. */
  131. typedef int (*JackNetSlaveBufferSizeCallback)(jack_nframes_t nframes, void *arg);
  132. /**
  133. * Prototype for SampleRate callback
  134. * @param nframes sample rate
  135. * @param arg pointer to a client supplied structure supplied by jack_set_net_sample_rate_callback().
  136. *
  137. * @return zero on success, non-zero on error
  138. */
  139. typedef int (*JackNetSlaveSampleRateCallback)(jack_nframes_t nframes, void *arg);
  140. /**
  141. * Set network buffer size callback.
  142. * @param net the network connection
  143. * @param bufsize_callback the buffer size callback
  144. * @param arg pointer to a client supplied structure
  145. *
  146. * @return 0 on success, otherwise a non-zero error code
  147. */
  148. int jack_set_net_slave_buffer_size_callback(jack_net_slave_t *net, JackNetSlaveBufferSizeCallback bufsize_callback, void *arg);
  149. /**
  150. * Set network sample rate callback.
  151. * @param net the network connection
  152. * @param samplerate_callback the sample rate callback
  153. * @param arg pointer to a client supplied structure
  154. *
  155. * @return 0 on success, otherwise a non-zero error code
  156. */
  157. int jack_set_net_slave_sample_rate_callback(jack_net_slave_t *net, JackNetSlaveSampleRateCallback samplerate_callback, void *arg);
  158. /**
  159. * Prototype for server Shutdown callback (if not set, the client will just restart, waiting for an available master again.)
  160. * @param arg pointer to a client supplied structure supplied by jack_set_net_shutdown_callback().
  161. */
  162. typedef void (*JackNetSlaveShutdownCallback)(void* data);
  163. /**
  164. * Set network shutdown callback.
  165. * @param net the network connection
  166. * @param shutdown_callback the shutdown callback
  167. * @param arg pointer to a client supplied structure
  168. *
  169. * @return 0 on success, otherwise a non-zero error code
  170. */
  171. int jack_set_net_slave_shutdown_callback(jack_net_slave_t *net, JackNetSlaveShutdownCallback shutdown_callback, void *arg);
  172. /**
  173. * jack_net_t is an opaque type. You may only access it using the
  174. * API provided.
  175. */
  176. typedef struct _jack_net_master jack_net_master_t;
  177. /**
  178. * Open a network connection with the slave machine.
  179. * @param ip the multicast address of the master
  180. * @param port the connection port
  181. * @param request a connection request structure
  182. * @param result a connection result structure
  183. *
  184. * @return Opaque net handle if successful or NULL in case of error.
  185. */
  186. jack_net_master_t* jack_net_master_open(const char* ip, int port, const char* name, jack_master_t* request, jack_slave_t* result);
  187. /**
  188. * Close the network connection with the master machine.
  189. * @param net the network connection to be closed
  190. *
  191. * @return 0 on success, otherwise a non-zero error code
  192. */
  193. int jack_net_master_close(jack_net_master_t* net);
  194. /**
  195. * Receive sync and data from the network
  196. * @param net the network connection
  197. * @param audio_input number of audio inputs
  198. * @param audio_input_buffer an array of audio input buffers
  199. * @param midi_input number of MIDI inputs
  200. * @param midi_input_buffer an array of MIDI input buffers
  201. *
  202. * @return zero on success, non-zero on error
  203. */
  204. int jack_net_master_recv(jack_net_master_t* net, int audio_input, float** audio_input_buffer, int midi_input, void** midi_input_buffer);
  205. /**
  206. * Send sync and data to the network
  207. * @param net the network connection
  208. * @param audio_output number of audio outputs
  209. * @param audio_output_buffer an array of audio output buffers
  210. * @param midi_output number of MIDI ouputs
  211. * @param midi_output_buffer an array of MIDI output buffers
  212. *
  213. * @return zero on success, non-zero on error
  214. */
  215. int jack_net_master_send(jack_net_master_t* net, int audio_output, float** audio_output_buffer, int midi_output, void** midi_output_buffer);
  216. // Experimental Adapter API
  217. /**
  218. * jack_adapter_t is an opaque type. You may only access it using the
  219. * API provided.
  220. */
  221. typedef struct _jack_adapter jack_adapter_t;
  222. /**
  223. * Create an adapter.
  224. * @param input number of audio inputs
  225. * @param output of audio outputs
  226. * @param host_buffer_size the host buffer size in frames
  227. * @param host_sample_rate the host buffer sample rate
  228. * @param adapted_buffer_size the adapted buffer size in frames
  229. * @param adapted_sample_rate the adapted buffer sample rate
  230. *
  231. * @return 0 on success, otherwise a non-zero error code
  232. */
  233. jack_adapter_t* jack_create_adapter(int input, int output,
  234. jack_nframes_t host_buffer_size,
  235. jack_nframes_t host_sample_rate,
  236. jack_nframes_t adapted_buffer_size,
  237. jack_nframes_t adapted_sample_rate);
  238. /**
  239. * Destroy an adapter.
  240. * @param adapter the adapter to be destroyed
  241. *
  242. * @return 0 on success, otherwise a non-zero error code
  243. */
  244. int jack_destroy_adapter(jack_adapter_t* adapter);
  245. /**
  246. * Flush internal state of an adapter.
  247. * @param adapter the adapter to be flushed
  248. *
  249. * @return 0 on success, otherwise a non-zero error code
  250. */
  251. void jack_flush_adapter(jack_adapter_t* adapter);
  252. /**
  253. * Push input to and pull output from adapter ringbuffer
  254. * @param adapter the adapter
  255. * @param input an array of audio input buffers
  256. * @param output an array of audio ouput buffers
  257. * @param frames number of frames
  258. *
  259. * @return 0 on success, otherwise a non-zero error code
  260. */
  261. int jack_adapter_push_and_pull(jack_adapter_t* adapter, float** input, float** output, unsigned int frames);
  262. /**
  263. * Pull input to and push output from adapter ringbuffer
  264. * @param adapter the adapter
  265. * @param input an array of audio input buffers
  266. * @param output an array of audio ouput buffers
  267. * @param frames number of frames
  268. *
  269. * @return 0 on success, otherwise a non-zero error code
  270. */
  271. int jack_adapter_pull_and_push(jack_adapter_t* adapter, float** input, float** output, unsigned int frames);
  272. #ifdef __cplusplus
  273. }
  274. #endif
  275. #endif /* __net_h__ */