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.

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