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.

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