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.

647 lines
22KB

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