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.

538 lines
16KB

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