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.

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