JACK API headers
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.

507 lines
15KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004 Jack O'Quin
  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. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __jack_types_h__
  17. #define __jack_types_h__
  18. #include <inttypes.h>
  19. #include <pthread.h>
  20. typedef int32_t jack_shmsize_t;
  21. /**
  22. * Type used to represent sample frame counts.
  23. */
  24. typedef uint32_t jack_nframes_t;
  25. /**
  26. * Maximum value that can be stored in jack_nframes_t
  27. */
  28. #define JACK_MAX_FRAMES (4294967295U) /* This should be UINT32_MAX, but
  29. C++ has a problem with that. */
  30. /**
  31. * Type used to represent the value of free running
  32. * monotonic clock with units of microseconds.
  33. */
  34. typedef uint64_t jack_time_t;
  35. /**
  36. * Maximum size of @a load_init string passed to an internal client
  37. * jack_initialize() function via jack_internal_client_load().
  38. */
  39. #define JACK_LOAD_INIT_LIMIT 1024
  40. /**
  41. * jack_intclient_t is an opaque type representing a loaded internal
  42. * client. You may only access it using the API provided in @ref
  43. * intclient.h "<jack/intclient.h>".
  44. */
  45. typedef uint64_t jack_intclient_t;
  46. /**
  47. * jack_port_t is an opaque type. You may only access it using the
  48. * API provided.
  49. */
  50. typedef struct _jack_port jack_port_t;
  51. /**
  52. * jack_client_t is an opaque type. You may only access it using the
  53. * API provided.
  54. */
  55. typedef struct _jack_client jack_client_t;
  56. /**
  57. * Ports have unique ids. A port registration callback is the only
  58. * place you ever need to know their value.
  59. */
  60. typedef uint32_t jack_port_id_t;
  61. /**
  62. * to make jack API independent of different thread implementations,
  63. * we define jack_native_thread_t to pthread_t here.
  64. * (all platforms that jack1 runs on, have pthread)
  65. */
  66. typedef pthread_t jack_native_thread_t;
  67. /**
  68. * @ref jack_options_t bits
  69. */
  70. enum JackOptions {
  71. /**
  72. * Null value to use when no option bits are needed.
  73. */
  74. JackNullOption = 0x00,
  75. /**
  76. * Do not automatically start the JACK server when it is not
  77. * already running. This option is always selected if
  78. * \$JACK_NO_START_SERVER is defined in the calling process
  79. * environment.
  80. */
  81. JackNoStartServer = 0x01,
  82. /**
  83. * Use the exact client name requested. Otherwise, JACK
  84. * automatically generates a unique one, if needed.
  85. */
  86. JackUseExactName = 0x02,
  87. /**
  88. * Open with optional <em>(char *) server_name</em> parameter.
  89. */
  90. JackServerName = 0x04,
  91. /**
  92. * Load internal client from optional <em>(char *)
  93. * load_name</em>. Otherwise use the @a client_name.
  94. */
  95. JackLoadName = 0x08,
  96. /**
  97. * Pass optional <em>(char *) load_init</em> string to the
  98. * jack_initialize() entry point of an internal client.
  99. */
  100. JackLoadInit = 0x10,
  101. /**
  102. * pass a SessionID Token this allows the sessionmanager to identify the client again.
  103. */
  104. JackSessionID = 0x20
  105. };
  106. /** Valid options for opening an external client. */
  107. #define JackOpenOptions (JackSessionID|JackServerName|JackNoStartServer|JackUseExactName)
  108. /** Valid options for loading an internal client. */
  109. #define JackLoadOptions (JackLoadInit|JackLoadName|JackUseExactName)
  110. /**
  111. * Options for several JACK operations, formed by OR-ing together the
  112. * relevant @ref JackOptions bits.
  113. */
  114. typedef enum JackOptions jack_options_t;
  115. /**
  116. * @ref jack_status_t bits
  117. */
  118. enum JackStatus {
  119. /**
  120. * Overall operation failed.
  121. */
  122. JackFailure = 0x01,
  123. /**
  124. * The operation contained an invalid or unsupported option.
  125. */
  126. JackInvalidOption = 0x02,
  127. /**
  128. * The desired client name was not unique. With the @ref
  129. * JackUseExactName option this situation is fatal. Otherwise,
  130. * the name was modified by appending a dash and a two-digit
  131. * number in the range "-01" to "-99". The
  132. * jack_get_client_name() function will return the exact string
  133. * that was used. If the specified @a client_name plus these
  134. * extra characters would be too long, the open fails instead.
  135. */
  136. JackNameNotUnique = 0x04,
  137. /**
  138. * The JACK server was started as a result of this operation.
  139. * Otherwise, it was running already. In either case the caller
  140. * is now connected to jackd, so there is no race condition.
  141. * When the server shuts down, the client will find out.
  142. */
  143. JackServerStarted = 0x08,
  144. /**
  145. * Unable to connect to the JACK server.
  146. */
  147. JackServerFailed = 0x10,
  148. /**
  149. * Communication error with the JACK server.
  150. */
  151. JackServerError = 0x20,
  152. /**
  153. * Requested client does not exist.
  154. */
  155. JackNoSuchClient = 0x40,
  156. /**
  157. * Unable to load internal client
  158. */
  159. JackLoadFailure = 0x80,
  160. /**
  161. * Unable to initialize client
  162. */
  163. JackInitFailure = 0x100,
  164. /**
  165. * Unable to access shared memory
  166. */
  167. JackShmFailure = 0x200,
  168. /**
  169. * Client's protocol version does not match
  170. */
  171. JackVersionError = 0x400,
  172. /*
  173. * BackendError
  174. */
  175. JackBackendError = 0x800,
  176. /*
  177. * Client is being shutdown against its will
  178. */
  179. JackClientZombie = 0x1000
  180. };
  181. /**
  182. * Status word returned from several JACK operations, formed by
  183. * OR-ing together the relevant @ref JackStatus bits.
  184. */
  185. typedef enum JackStatus jack_status_t;
  186. /**
  187. * @ref jack_latency_callback_mode_t
  188. */
  189. enum JackLatencyCallbackMode {
  190. /**
  191. * Latency Callback for Capture Latency.
  192. * Input Ports have their latency value setup.
  193. * In the Callback the client needs to set the latency of the output ports
  194. */
  195. JackCaptureLatency,
  196. /**
  197. * Latency Callback for Playback Latency.
  198. * Output Ports have their latency value setup.
  199. * In the Callback the client needs to set the latency of the input ports
  200. */
  201. JackPlaybackLatency
  202. };
  203. /**
  204. * Type of Latency Callback (Capture or Playback)
  205. */
  206. typedef enum JackLatencyCallbackMode jack_latency_callback_mode_t;
  207. /**
  208. * Prototype for the client supplied function that is called
  209. * by the engine when port latencies need to be recalculated
  210. *
  211. * @param mode playback or capture latency
  212. * @param arg pointer to a client supplied data
  213. *
  214. * @return zero on success, non-zero on error
  215. */
  216. typedef void (*JackLatencyCallback)(jack_latency_callback_mode_t mode, void *arg);
  217. /**
  218. * the new latency API operates on Ranges.
  219. */
  220. struct _jack_latency_range
  221. {
  222. /**
  223. * minimum latency
  224. */
  225. jack_nframes_t min;
  226. /**
  227. * maximum latency
  228. */
  229. jack_nframes_t max;
  230. };
  231. typedef struct _jack_latency_range jack_latency_range_t;
  232. /**
  233. * Prototype for the client supplied function that is called
  234. * by the engine anytime there is work to be done.
  235. *
  236. * @pre nframes == jack_get_buffer_size()
  237. * @pre nframes == pow(2,x)
  238. *
  239. * @param nframes number of frames to process
  240. * @param arg pointer to a client supplied data
  241. *
  242. * @return zero on success, non-zero on error
  243. */
  244. typedef int (*JackProcessCallback)(jack_nframes_t nframes, void *arg);
  245. /**
  246. * Prototype for the client supplied function that is called
  247. * once after the creation of the thread in which other
  248. * callbacks will be made. Special thread characteristics
  249. * can be set from this callback, for example. This is a
  250. * highly specialized callback and most clients will not
  251. * and should not use it.
  252. *
  253. * @param arg pointer to a client supplied structure
  254. *
  255. * @return void
  256. */
  257. typedef void (*JackThreadInitCallback)(void *arg);
  258. /**
  259. * Prototype for the client supplied function that is called
  260. * whenever the processing graph is reordered.
  261. *
  262. * @param arg pointer to a client supplied data
  263. *
  264. * @return zero on success, non-zero on error
  265. */
  266. typedef int (*JackGraphOrderCallback)(void *arg);
  267. /**
  268. * Prototype for the client-supplied function that is called whenever
  269. * an xrun has occured.
  270. *
  271. * @see jack_get_xrun_delayed_usecs()
  272. *
  273. * @param arg pointer to a client supplied data
  274. *
  275. * @return zero on success, non-zero on error
  276. */
  277. typedef int (*JackXRunCallback)(void *arg);
  278. /**
  279. * Prototype for the @a bufsize_callback that is invoked whenever the
  280. * JACK engine buffer size changes. Although this function is called
  281. * in the JACK process thread, the normal process cycle is suspended
  282. * during its operation, causing a gap in the audio flow. So, the @a
  283. * bufsize_callback can allocate storage, touch memory not previously
  284. * referenced, and perform other operations that are not realtime
  285. * safe.
  286. *
  287. * @param nframes buffer size
  288. * @param arg pointer supplied by jack_set_buffer_size_callback().
  289. *
  290. * @return zero on success, non-zero on error
  291. */
  292. typedef int (*JackBufferSizeCallback)(jack_nframes_t nframes, void *arg);
  293. /**
  294. * Prototype for the client supplied function that is called
  295. * when the engine sample rate changes.
  296. *
  297. * @param nframes new engine sample rate
  298. * @param arg pointer to a client supplied data
  299. *
  300. * @return zero on success, non-zero on error
  301. */
  302. typedef int (*JackSampleRateCallback)(jack_nframes_t nframes, void *arg);
  303. /**
  304. * Prototype for the client supplied function that is called
  305. * whenever a port is registered or unregistered.
  306. *
  307. * @param port the ID of the port
  308. * @param arg pointer to a client supplied data
  309. * @param register non-zero if the port is being registered,
  310. * zero if the port is being unregistered
  311. */
  312. typedef void (*JackPortRegistrationCallback)(jack_port_id_t port, int register, void *arg);
  313. /**
  314. * Prototype for the client supplied function that is called
  315. * whenever a client is registered or unregistered.
  316. *
  317. * @param name a null-terminated string containing the client name
  318. * @param register non-zero if the client is being registered,
  319. * zero if the client is being unregistered
  320. * @param arg pointer to a client supplied data
  321. */
  322. typedef void (*JackClientRegistrationCallback)(const char* name, int register, void *arg);
  323. /**
  324. * Prototype for the client supplied function that is called
  325. * whenever a client is registered or unregistered.
  326. *
  327. * @param a one of two ports connected or disconnected
  328. * @param b one of two ports connected or disconnected
  329. * @param connect non-zero if ports were connected
  330. * zero if ports were disconnected
  331. * @param arg pointer to a client supplied data
  332. */
  333. typedef void (*JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
  334. /**
  335. * Prototype for the client supplied function that is called
  336. * whenever jackd starts or stops freewheeling.
  337. *
  338. * @param starting non-zero if we start starting to freewheel, zero otherwise
  339. * @param arg pointer to a client supplied structure
  340. */
  341. typedef void (*JackFreewheelCallback)(int starting, void *arg);
  342. typedef void *(*JackThreadCallback)(void* arg);
  343. /**
  344. * Prototype for the client supplied function that is called
  345. * whenever jackd is shutdown. Note that after server shutdown,
  346. * the client pointer is *not* deallocated by libjack,
  347. * the application is responsible to properly use jack_client_close()
  348. * to release client ressources. Warning: jack_client_close() cannot be
  349. * safely used inside the shutdown callback and has to be called outside of
  350. * the callback context.
  351. *
  352. * @param arg pointer to a client supplied structure
  353. */
  354. typedef void (*JackShutdownCallback)(void *arg);
  355. /**
  356. * Prototype for the client supplied function that is called
  357. * whenever jackd is shutdown. Note that after server shutdown,
  358. * the client pointer is *not* deallocated by libjack,
  359. * the application is responsible to properly use jack_client_close()
  360. * to release client ressources. Warning: jack_client_close() cannot be
  361. * safely used inside the shutdown callback and has to be called outside of
  362. * the callback context.
  363. *
  364. * @param code a shutdown code
  365. * @param reason a string describing the shutdown reason (backend failure, server crash... etc...)
  366. * @param arg pointer to a client supplied structure
  367. */
  368. typedef void (*JackInfoShutdownCallback)(jack_status_t code, const char* reason, void *arg);
  369. /**
  370. * Used for the type argument of jack_port_register() for default
  371. * audio and midi ports.
  372. */
  373. #define JACK_DEFAULT_AUDIO_TYPE "32 bit float mono audio"
  374. #define JACK_DEFAULT_MIDI_TYPE "8 bit raw midi"
  375. /**
  376. * For convenience, use this typedef if you want to be able to change
  377. * between float and double. You may want to typedef sample_t to
  378. * jack_default_audio_sample_t in your application.
  379. */
  380. typedef float jack_default_audio_sample_t;
  381. /**
  382. * A port has a set of flags that are formed by OR-ing together the
  383. * desired values from the list below. The flags "JackPortIsInput" and
  384. * "JackPortIsOutput" are mutually exclusive and it is an error to use
  385. * them both.
  386. */
  387. enum JackPortFlags {
  388. /**
  389. * if JackPortIsInput is set, then the port can receive
  390. * data.
  391. */
  392. JackPortIsInput = 0x1,
  393. /**
  394. * if JackPortIsOutput is set, then data can be read from
  395. * the port.
  396. */
  397. JackPortIsOutput = 0x2,
  398. /**
  399. * if JackPortIsPhysical is set, then the port corresponds
  400. * to some kind of physical I/O connector.
  401. */
  402. JackPortIsPhysical = 0x4,
  403. /**
  404. * if JackPortCanMonitor is set, then a call to
  405. * jack_port_request_monitor() makes sense.
  406. *
  407. * Precisely what this means is dependent on the client. A typical
  408. * result of it being called with TRUE as the second argument is
  409. * that data that would be available from an output port (with
  410. * JackPortIsPhysical set) is sent to a physical output connector
  411. * as well, so that it can be heard/seen/whatever.
  412. *
  413. * Clients that do not control physical interfaces
  414. * should never create ports with this bit set.
  415. */
  416. JackPortCanMonitor = 0x8,
  417. /**
  418. * JackPortIsTerminal means:
  419. *
  420. * for an input port: the data received by the port
  421. * will not be passed on or made
  422. * available at any other port
  423. *
  424. * for an output port: the data available at the port
  425. * does not originate from any other port
  426. *
  427. * Audio synthesizers, I/O hardware interface clients, HDR
  428. * systems are examples of clients that would set this flag for
  429. * their ports.
  430. */
  431. JackPortIsTerminal = 0x10
  432. };
  433. #endif /* __jack_types_h__ */