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.

294 lines
9.4KB

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