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.

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