jack1 codebase
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.

636 lines
21KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. $Id$
  15. */
  16. #ifndef __jack_h__
  17. #define __jack_h__
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include <pthread.h>
  22. #include <jack/types.h>
  23. #include <jack/transport.h>
  24. /**
  25. * Note: More documentation can be found in jack/types.h.
  26. */
  27. /**
  28. * Attemps to become an external client of the Jack server.
  29. */
  30. jack_client_t *jack_client_new (const char *client_name);
  31. /**
  32. * Disconnects an external client from a JACK server.
  33. *
  34. * @return 0 on success, otherwise a non-zero error code
  35. */
  36. int jack_client_close (jack_client_t *client);
  37. /**
  38. * @param client_name The name for the new client
  39. * @param so_name A path to a shared object file containing the code for the new client
  40. * @param so_data An arbitary string containing information to be passed to the init() routine of the new client
  41. *
  42. * Attemps to load an internal client into the Jack server.
  43. */
  44. int jack_internal_client_new (const char *client_name, const char *so_name, const char *so_data);
  45. /**
  46. * Removes an internal client from a JACK server.
  47. *
  48. * @return 0 on success, otherwise a non-zero error code
  49. */
  50. void jack_internal_client_close (const char *client_name);
  51. /**
  52. * @param client The Jack client structure.
  53. *
  54. * Check if the JACK subsystem is running with -R (--realtime).
  55. *
  56. * @return 1 if JACK is running realtime, 0 otherwise
  57. */
  58. int jack_is_realtime (jack_client_t *client);
  59. /**
  60. * @param client The Jack client structure.
  61. * @param function The jack_shutdown function pointer.
  62. * @param arg The arguments for the jack_shutdown function.
  63. *
  64. * Register a function (and argument) to be called if and when the
  65. * JACK server shuts down the client thread. The function must
  66. * be written as if it were an asynchonrous POSIX signal
  67. * handler --- use only async-safe functions, and remember that it
  68. * is executed from another thread. A typical function might
  69. * set a flag or write to a pipe so that the rest of the
  70. * application knows that the JACK client thread has shut
  71. * down.
  72. *
  73. * NOTE: clients do not need to call this. It exists only
  74. * to help more complex clients understand what is going
  75. * on. It should be called before jack_client_activate().
  76. */
  77. void jack_on_shutdown (jack_client_t *client, void (*function)(void *arg), void *arg);
  78. /**
  79. * Tell the Jack server to call @a process_callback whenever there is
  80. * work be done, passing @a arg as the second argument.
  81. *
  82. * The code in the supplied function must be suitable for real-time
  83. * execution. That means that it cannot call functions that might
  84. * block for a long time.  This includes malloc, free, printf,
  85. * pthread_mutex_lock, sleep, wait, poll, select, pthread_join,
  86. * pthread_cond_wait, etc, etc.  See
  87. * http://jackit.sourceforge.net/docs/design/design.html#SECTION00411000000000000000
  88. * for more information.
  89. *
  90. * @return 0 on success, otherwise a non-zero error code, causing JACK
  91. * to remove that client from the process() graph.
  92. */
  93. int jack_set_process_callback (jack_client_t *client,
  94. JackProcessCallback process_callback,
  95. void *arg);
  96. /**
  97. * Start/Stop JACK's "freewheel" mode.
  98. *
  99. * When in "freewheel" mode, JACK no longer waits for
  100. * any external event to begin the start of the next process
  101. * cycle.
  102. *
  103. * As a result, freewheel mode causes "faster than realtime"
  104. * execution of a JACK graph. If possessed, real-time
  105. * scheduling is dropped when entering freewheel mode, and
  106. * if appropriate it is reacquired when stopping.
  107. *
  108. * @param client pointer to JACK client structure
  109. * @param onoff if non-zero, freewheel mode starts. Otherwise
  110. * freewheel mode ends.
  111. *
  112. * @return 0 on success, otherwise a non-zero error code.
  113. */
  114. int jack_set_freewheel(jack_client_t* client, int onoff);
  115. /**
  116. * Change the buffer size passed to the @a process_callback.
  117. *
  118. * This operation stops the JACK engine process cycle, then calls all
  119. * registered @a bufsize_callback functions before restarting the
  120. * process cycle. This will cause a gap in the audio flow, so it
  121. * should only be done at appropriate stopping points.
  122. *
  123. * @see jack_set_buffer_size_callback()
  124. *
  125. * @param client pointer to JACK client structure.
  126. * @param nframes new buffer size. Must be a power of two.
  127. *
  128. * @return 0 on success, otherwise a non-zero error code
  129. */
  130. int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  131. /**
  132. * Tell JACK to call @a bufsize_callback whenever the size of the the
  133. * buffer that will be passed to the @a process_callback is about to
  134. * change. Clients that depend on knowing the buffer size must supply
  135. * a @a bufsize_callback before activating themselves.
  136. *
  137. * @param client pointer to JACK client structure.
  138. * @param bufsize_callback function to call when the buffer size changes.
  139. * @param arg argument for @a bufsize_callback.
  140. *
  141. * @return 0 on success, otherwise a non-zero error code
  142. */
  143. int jack_set_buffer_size_callback (jack_client_t *client,
  144. JackBufferSizeCallback bufsize_callback,
  145. void *arg);
  146. /**
  147. * Tell the Jack server to call @a srate_callback whenever the system
  148. * sample rate changes.
  149. *
  150. * @return 0 on success, otherwise a non-zero error code
  151. */
  152. int jack_set_sample_rate_callback (jack_client_t *client,
  153. JackSampleRateCallback srate_callback,
  154. void *arg);
  155. /**
  156. * Tell the Jack server to call 'registration_callback' whenever a port is registered
  157. * or unregistered, passing 'arg' as a second argument.
  158. *
  159. * @return 0 on success, otherwise a non-zero error code
  160. */
  161. int jack_set_port_registration_callback (jack_client_t *, JackPortRegistrationCallback registration_callback, void *arg);
  162. /**
  163. * Tell the Jack server to call 'registration_callback' whenever the processing
  164. * graph is reordered, passing 'arg' as an argument.
  165. *
  166. * @return 0 on success, otherwise a non-zero error code
  167. */
  168. int jack_set_graph_order_callback (jack_client_t *, JackGraphOrderCallback graph_callback, void *);
  169. /**
  170. * Tell the Jack server to call 'xrun_callback' whenever there is a xrun, passing
  171. * 'arg' as an argument.
  172. *
  173. * @return 0 on success, otherwise a non-zero error code
  174. */
  175. int jack_set_xrun_callback (jack_client_t *, JackXRunCallback xrun_callback, void *arg);
  176. /**
  177. * Tell the Jack server that the program is ready to start processing
  178. * audio.
  179. *
  180. * @return 0 on success, otherwise a non-zero error code
  181. */
  182. int jack_activate (jack_client_t *client);
  183. /**
  184. * Tells the Jack server that the program should be removed from the
  185. * processing graph. As a side effect, this will disconnect any
  186. * and all ports belonging to the client, since inactive clients
  187. * are not allowed to be connected to any other ports.
  188. *
  189. * @return 0 on success, otherwise a non-zero error code
  190. */
  191. int jack_deactivate (jack_client_t *client);
  192. /**
  193. * This creates a new port for the client.
  194. *
  195. * A port is an object used for moving data in or out of the client.
  196. * the data may be of any type. Ports may be connected to each other
  197. * in various ways.
  198. *
  199. * A port has a short name, a non-NULL and non-zero length string, and
  200. * is passed as the first argument. A port's full name is the name of
  201. * the client concatenated with a colon (:) and then its short
  202. * name. There are limits to the length of the name, and exceeding
  203. * them will cause registration of the port to fail and the function
  204. * to return NULL. The limit is derived from the size of a full port
  205. * name, which also has to include the client name and a separator
  206. * character.
  207. *
  208. * A port has a type, which may be any non-NULL and non-zero length
  209. * string, and is passed as the second argument. Some port types are
  210. * built into the JACK API (currently only JACK_DEFAULT_AUDIO_TYPE).
  211. * For other types, the client must supply a non-zero @a buffer_size.
  212. * For builtin types, @a buffer_size is ignored.
  213. *
  214. * The @a flags argument is formed from a bitmask of JackPortFlags values.
  215. *
  216. * @return a valid jack_port_t* on success, NULL otherwise.
  217. */
  218. jack_port_t *jack_port_register (jack_client_t *,
  219. const char *port_name,
  220. const char *port_type,
  221. unsigned long flags,
  222. unsigned long buffer_size);
  223. /**
  224. * This removes the port from the client, disconnecting
  225. * any existing connections at the same time.
  226. *
  227. * @return 0 on success, otherwise a non-zero error code
  228. */
  229. int jack_port_unregister (jack_client_t *, jack_port_t *);
  230. /**
  231. * This returns a pointer to the memory area associated with the
  232. * specified port. For an output port, it will be a memory area
  233. * that can be written to; for an input port, it will be an area
  234. * containing the data from the port's connection(s), or
  235. * zero-filled. if there are multiple inbound connections, the data
  236. * will be mixed appropriately.
  237. *
  238. * FOR OUTPUT PORTS ONLY
  239. * ---------------------
  240. * You may cache the value returned, but only between calls to
  241. * your "blocksize" callback. For this reason alone, you should
  242. * either never cache the return value or ensure you have
  243. * a "blocksize" callback and be sure to invalidate the cached
  244. * address from there.
  245. */
  246. void *jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  247. /**
  248. * Returns the name of the jack_port_t.
  249. */
  250. const char * jack_port_name (const jack_port_t *port);
  251. /**
  252. * Returns the short name of the jack_port_t.
  253. */
  254. const char * jack_port_short_name (const jack_port_t *port);
  255. /**
  256. * Returns the flags of the jack_port_t.
  257. */
  258. int jack_port_flags (const jack_port_t *port);
  259. /**
  260. * Returns the type of the jack_port_t.
  261. */
  262. const char * jack_port_type (const jack_port_t *port);
  263. /**
  264. * Returns 1 if the jack_port_t belongs to the jack_client_t.
  265. */
  266. int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  267. /**
  268. * This returns a positive integer indicating the number
  269. * of connections to or from 'port'.
  270. *
  271. * ®pre The calling client must own 'port'.
  272. */
  273. int jack_port_connected (const jack_port_t *port);
  274. /**
  275. * This returns TRUE or FALSE if the port argument is
  276. * DIRECTLY connected to the port with the name given in 'portname'
  277. *
  278. * @pre The calling client must own 'port'.
  279. */
  280. int jack_port_connected_to (const jack_port_t *port, const char *portname);
  281. /**
  282. * This returns a null-terminated array of port names to which
  283. * the argument port is connected. if there are no connections, it
  284. * returns NULL.
  285. *
  286. * The caller is responsible for calling free(3) on any
  287. * non-NULL returned value.
  288. *
  289. * @pre The calling client must own 'port'.
  290. *
  291. * See jack_port_get_all_connections() for an alternative.
  292. */
  293. const char ** jack_port_get_connections (const jack_port_t *port);
  294. /**
  295. * This returns a null-terminated array of port names to which
  296. * the argument port is connected. if there are no connections, it
  297. * returns NULL.
  298. *
  299. * The caller is responsible for calling free(3) on any
  300. * non-NULL returned value.
  301. *
  302. * It differs from jack_port_get_connections() in two important
  303. * respects:
  304. *
  305. * 1) You may not call this function from code that is
  306. * executed in response to a JACK event. For example,
  307. * you cannot use it in a GraphReordered handler.
  308. *
  309. * 2) You need not be the owner of the port to get information
  310. * about its connections.
  311. */
  312. const char ** jack_port_get_all_connections (const jack_client_t *client, const jack_port_t *port);
  313. /**
  314. * A client may call this on a pair of its own ports to
  315. * semi-permanently wire them together. This means that
  316. * a client that wants to direct-wire an input port to
  317. * an output port can call this and then no longer
  318. * have to worry about moving data between them. Any data
  319. * arriving at the input port will appear automatically
  320. * at the output port.
  321. *
  322. * The 'destination' port must be an output port. The 'source'
  323. * port must be an input port. Both ports must belong to
  324. * the same client. You cannot use this to tie ports between
  325. * clients. That is what a connection is for.
  326. *
  327. * @return 0 on success, otherwise a non-zero error code
  328. */
  329. int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  330. /**
  331. * This undoes the effect of jack_port_tie(). The port
  332. * should be same as the 'destination' port passed to
  333. * jack_port_tie().
  334. *
  335. * @return 0 on success, otherwise a non-zero error code
  336. */
  337. int jack_port_untie (jack_port_t *port);
  338. /**
  339. * A client may call this function to prevent other objects
  340. * from changing the connection status of a port. The port
  341. * must be owned by the calling client.
  342. *
  343. * @return 0 on success, otherwise a non-zero error code
  344. */
  345. int jack_port_lock (jack_client_t *, jack_port_t *);
  346. /**
  347. * This allows other objects to change the connection status of a port.
  348. *
  349. * @return 0 on success, otherwise a non-zero error code
  350. */
  351. int jack_port_unlock (jack_client_t *, jack_port_t *);
  352. /**
  353. * Returns the time (in frames) between data being
  354. * available or delivered at/to a port, and the time at
  355. * which it arrived at or is delivered to the "other side"
  356. * of the port. E.g. for a physical audio output port, this
  357. * is the time between writing to the port and when the
  358. * signal will leave the connector. For a physical audio
  359. * input port, this is the time between the sound arriving
  360. * at the connector and the corresponding frames being
  361. * readable from the port.
  362. */
  363. jack_nframes_t jack_port_get_latency (jack_port_t *port);
  364. /**
  365. * The maximum of the sum of the latencies in every
  366. * connection path that can be drawn between the port and other
  367. * ports with the JackPortIsTerminal flag set.
  368. */
  369. jack_nframes_t jack_port_get_total_latency (jack_client_t *, jack_port_t *port);
  370. /**
  371. * The port latency is zero by default. Clients that control
  372. * physical hardware with non-zero latency should call this
  373. * to set the latency to its correct value. Note that the value
  374. * should include any systemic latency present "outside" the
  375. * physical hardware controlled by the client. For example,
  376. * for a client controlling a digital audio interface connected
  377. * to an external digital converter, the latency setting should
  378. * include both buffering by the audio interface *and* the converter.
  379. */
  380. void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  381. /**
  382. * This modifies a port's name, and may be called at any time.
  383. *
  384. * @return 0 on success, otherwise a non-zero error code
  385. */
  386. int jack_port_set_name (jack_port_t *port, const char *name);
  387. /**
  388. * If JackPortCanMonitor is set for a port, then these 2 functions will
  389. * turn on/off input monitoring for the port. If JackPortCanMonitor
  390. * is not set, then these functions will have no effect.
  391. */
  392. int jack_port_request_monitor (jack_port_t *port, int onoff);
  393. /**
  394. * If JackPortCanMonitor is set for a port, then these 2 functions will
  395. * turn on/off input monitoring for the port. If JackPortCanMonitor
  396. * is not set, then these functions will have no effect.
  397. *
  398. * @return 0 on success, otherwise a non-zero error code
  399. */
  400. int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff);
  401. /**
  402. * If JackPortCanMonitor is set for a port, then this function will
  403. * turn on input monitoring if it was off, and will turn it off it
  404. * only one request has been made to turn it on. If JackPortCanMonitor
  405. * is not set, then this function will do nothing.
  406. *
  407. * @return 0 on success, otherwise a non-zero error code
  408. */
  409. int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  410. /**
  411. * Returns a true or false value depending on whether or not
  412. * input monitoring has been requested for 'port'.
  413. */
  414. int jack_port_monitoring_input (jack_port_t *port);
  415. /**
  416. * Establishes a connection between two ports.
  417. *
  418. * When a connection exists, data written to the source port will
  419. * be available to be read at the destination port.
  420. *
  421. * @pre The types of both ports must be identical to establish a connection.
  422. * @pre The flags of the source port must include PortIsOutput.
  423. * @pre The flags of the destination port must include PortIsInput.
  424. *
  425. * @return 0 on success, EEXIST if the connection is allready made, otherwise
  426. * a non-zero error code
  427. */
  428. int jack_connect (jack_client_t *,
  429. const char *source_port,
  430. const char *destination_port);
  431. /**
  432. * Removes a connection between two ports.
  433. *
  434. * @pre The types of both ports must be identical to establish a connection.
  435. * @pre The flags of the source port must include PortIsOutput.
  436. * @pre The flags of the destination port must include PortIsInput.
  437. *
  438. * @return 0 on success, otherwise a non-zero error code
  439. */
  440. int jack_disconnect (jack_client_t *,
  441. const char *source_port,
  442. const char *destination_port);
  443. /**
  444. * Performs the exact same function as jack_connect(), but it uses
  445. * port handles rather than names, which avoids the name lookup inherent
  446. * in the name-based version.
  447. *
  448. * It is envisaged that clients connecting their own ports will use these
  449. * two, whereas generic connection clients (e.g. patchbays) will use the
  450. * name-based versions.
  451. *
  452. * @return 0 on success, otherwise a non-zero error code
  453. */
  454. int jack_port_connect (jack_client_t *, jack_port_t *src, jack_port_t *dst);
  455. /**
  456. * Performs the exact same function as jack_disconnect(), but it uses
  457. * port handles rather than names, which avoids the name lookup inherent
  458. * in the name-based version.
  459. *
  460. * It is envisaged that clients disconnecting their own ports will use these
  461. * two, whereas generic connection clients (e.g. patchbays) will use the
  462. * name-based versions.
  463. */
  464. int jack_port_disconnect (jack_client_t *, jack_port_t *);
  465. /**
  466. * This returns the sample rate of the jack system, as set by the user when
  467. * jackd was started.
  468. */
  469. jack_nframes_t jack_get_sample_rate (jack_client_t *);
  470. /**
  471. * This returns the current maximum size that will ever be passed to
  472. * the @a process_callback. It should only be used *before* the
  473. * client has been activated. This size may change, clients that
  474. * depend on it must register a @a bufsize_callback so they will be
  475. * notified if it does.
  476. *
  477. * @see jack_set_buffer_size_callback()
  478. */
  479. jack_nframes_t jack_get_buffer_size (jack_client_t *);
  480. /**
  481. * @param port_name_pattern A regular expression used to select
  482. * ports by name. If NULL or of zero length, no selection based
  483. * on name will be carried out.
  484. * @param type_name_pattern A regular expression used to select
  485. * ports by type. If NULL or of zero length, no selection based
  486. * on type will be carried out.
  487. * @param flags A value used to select ports by their flags.
  488. * If zero, no selection based on flags will be carried out.
  489. *
  490. * This function returns a NULL-terminated array of ports that match
  491. * the specified arguments.
  492. * The caller is responsible for calling free(3) any non-NULL returned value.
  493. */
  494. const char ** jack_get_ports (jack_client_t *,
  495. const char *port_name_pattern,
  496. const char *type_name_pattern,
  497. unsigned long flags);
  498. /**
  499. * Searchs for and returns the jack_port_t with the name value
  500. * from portname.
  501. */
  502. jack_port_t *jack_port_by_name (jack_client_t *, const char *portname);
  503. /**
  504. * Searchs for and returns the jack_port_t of id 'id'.
  505. */
  506. jack_port_t *jack_port_by_id (const jack_client_t *client, jack_port_id_t id);
  507. /**
  508. * Old-style interface to become the timebase for the entire JACK
  509. * subsystem.
  510. *
  511. * @deprecated This function still exists for compatibility with the
  512. * earlier transport interface, but it does nothing. Instead, see
  513. * <jack/transport.h> and use jack_set_timebase_callback().
  514. *
  515. * @return ENOSYS, function not implemented.
  516. */
  517. int jack_engine_takeover_timebase (jack_client_t *);
  518. /**
  519. * undocumented
  520. */
  521. void jack_update_time (jack_client_t *, jack_nframes_t);
  522. /**
  523. * This estimates the time that has passed since the JACK server
  524. * started calling the process callbacks of all its clients.
  525. */
  526. jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  527. /**
  528. * Return an estimate of the current time in frames. It is a running
  529. * counter - no significance should be attached to the return
  530. * value. it should be used to compute the difference between
  531. * a previously returned value.
  532. */
  533. jack_nframes_t jack_frame_time (const jack_client_t *);
  534. /**
  535. * This returns the current CPU load estimated by JACK
  536. * as a percentage. The load is computed by measuring
  537. * the amount of time it took to execute all clients
  538. * as a fraction of the total amount of time
  539. * represented by the data that was processed.
  540. */
  541. float jack_cpu_load (jack_client_t *client);
  542. /**
  543. * Set the directory in which the server is expected
  544. * to have put its communication FIFOs. A client
  545. * will need to call this before calling
  546. * jack_client_new() if the server was started
  547. * with arguments telling it to use a non-standard
  548. * directory.
  549. */
  550. void jack_set_server_dir (const char *path);
  551. /**
  552. * Return the pthread ID of the thread running the JACK client
  553. * side code.
  554. */
  555. pthread_t jack_client_thread_id (jack_client_t *);
  556. extern void (*jack_error_callback)(const char *desc);
  557. /**
  558. * Sets callback to be called to print error messages.
  559. */
  560. void jack_set_error_function (void (*func)(const char *));
  561. #ifdef __cplusplus
  562. }
  563. #endif
  564. #endif /* __jack_h__ */