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.

203 lines
6.5KB

  1. /* -*- mode: c; c-file-style: "bsd"; -*- */
  2. /*
  3. Copyright (C) 2001-2003 Paul Davis
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. $Id$
  16. */
  17. #ifndef __jack_engine_h__
  18. #define __jack_engine_h__
  19. #include <jack/jack.h>
  20. #include <jack/internal.h>
  21. #include <jack/driver_interface.h>
  22. struct _jack_driver;
  23. struct _jack_client_internal;
  24. struct _jack_port_internal;
  25. /* Structures is allocated by the engine in local memory to keep track
  26. * of port buffers and connections.
  27. */
  28. typedef struct {
  29. jack_shm_info_t* shm_info;
  30. jack_shmsize_t offset;
  31. } jack_port_buffer_info_t;
  32. /* The engine keeps an array of these in its local memory. */
  33. typedef struct _jack_port_internal {
  34. struct _jack_port_shared *shared;
  35. JSList *connections;
  36. jack_port_buffer_info_t *buffer_info;
  37. } jack_port_internal_t;
  38. /* The engine's internal port type structure. */
  39. typedef struct _jack_port_buffer_list {
  40. pthread_mutex_t lock; /* only lock within server */
  41. JSList *freelist; /* list of free buffers */
  42. jack_port_buffer_info_t *info; /* jack_buffer_info_t array */
  43. } jack_port_buffer_list_t;
  44. /* The main engine structure in local memory. */
  45. struct _jack_engine {
  46. jack_control_t *control;
  47. JSList *drivers;
  48. struct _jack_driver *driver;
  49. jack_driver_desc_t *driver_desc;
  50. JSList *driver_params;
  51. /* these are "callbacks" made by the driver backend */
  52. int (*set_buffer_size) (struct _jack_engine *, jack_nframes_t frames);
  53. int (*set_sample_rate) (struct _jack_engine *, jack_nframes_t frames);
  54. int (*run_cycle) (struct _jack_engine *, jack_nframes_t nframes,
  55. float delayed_usecs);
  56. void (*delay) (struct _jack_engine *, float delayed_usecs);
  57. void (*transport_cycle_start) (struct _jack_engine *, jack_time_t time);
  58. void (*driver_exit) (struct _jack_engine *);
  59. /* "private" sections starts here */
  60. /* engine serialization -- use precedence for deadlock avoidance */
  61. pthread_mutex_t request_lock; /* precedes client_lock */
  62. pthread_mutex_t client_lock;
  63. pthread_mutex_t port_lock;
  64. int process_errors;
  65. int period_msecs;
  66. /* Time to wait for clients in msecs. Used when jackd is run
  67. * without realtime priority enabled. */
  68. int client_timeout_msecs;
  69. /* info on the shm segment containing this->control */
  70. jack_shm_info_t control_shm;
  71. /* address-space local port buffer and segment info,
  72. indexed by the port type_id
  73. */
  74. jack_port_buffer_list_t port_buffers[JACK_MAX_PORT_TYPES];
  75. jack_shm_info_t port_segment[JACK_MAX_PORT_TYPES];
  76. unsigned int port_max;
  77. pthread_t server_thread;
  78. pthread_t watchdog_thread;
  79. int fds[2];
  80. jack_client_id_t next_client_id;
  81. size_t pfd_size;
  82. size_t pfd_max;
  83. struct pollfd *pfd;
  84. char fifo_prefix[PATH_MAX+1];
  85. int *fifo;
  86. unsigned long fifo_size;
  87. unsigned long external_client_cnt;
  88. int rtpriority;
  89. char freewheeling;
  90. char verbose;
  91. char do_munlock;
  92. const char *server_name;
  93. char temporary;
  94. int reordered;
  95. int watchdog_check;
  96. pid_t wait_pid;
  97. pthread_t freewheel_thread;
  98. /* these lists are protected by `client_lock' */
  99. JSList *clients;
  100. JSList *clients_waiting;
  101. jack_port_internal_t *internal_ports;
  102. jack_client_internal_t *timebase_client;
  103. jack_port_buffer_info_t *silent_buffer;
  104. jack_client_internal_t *current_client;
  105. #define JACK_ENGINE_ROLLING_COUNT 32
  106. #define JACK_ENGINE_ROLLING_INTERVAL 1024
  107. jack_time_t rolling_client_usecs[JACK_ENGINE_ROLLING_COUNT];
  108. int rolling_client_usecs_cnt;
  109. int rolling_client_usecs_index;
  110. int rolling_interval;
  111. float max_usecs;
  112. float spare_usecs;
  113. float usecs_per_cycle;
  114. #ifdef JACK_USE_MACH_THREADS
  115. /* specific resources for server/client real-time thread communication */
  116. mach_port_t servertask, bp;
  117. int portnum;
  118. #endif
  119. };
  120. /* public functions */
  121. jack_engine_t *jack_engine_new (int real_time, int real_time_priority,
  122. int do_mlock, int do_unlock,
  123. const char *server_name, int temporary,
  124. int verbose, int client_timeout,
  125. unsigned int port_max,
  126. pid_t waitpid, JSList *drivers);
  127. void jack_engine_delete (jack_engine_t *);
  128. int jack_run (jack_engine_t *engine);
  129. int jack_wait (jack_engine_t *engine);
  130. int jack_engine_load_driver (jack_engine_t *engine,
  131. jack_driver_desc_t * driver_desc,
  132. JSList * driver_params);
  133. void jack_dump_configuration(jack_engine_t *engine, int take_lock);
  134. /* private engine functions */
  135. void jack_engine_reset_rolling_usecs (jack_engine_t *engine);
  136. int internal_client_request (void* ptr, jack_request_t *request);
  137. int jack_get_fifo_fd (jack_engine_t *engine,
  138. unsigned int which_fifo);
  139. extern jack_client_internal_t *
  140. jack_client_internal_by_id (jack_engine_t *engine, jack_client_id_t id);
  141. static inline void jack_lock_graph (jack_engine_t* engine) {
  142. DEBUG ("acquiring graph lock");
  143. pthread_mutex_lock (&engine->client_lock);
  144. }
  145. static inline int jack_try_lock_graph (jack_engine_t *engine)
  146. {
  147. DEBUG ("TRYING to acquiring graph lock");
  148. return pthread_mutex_trylock (&engine->client_lock);
  149. }
  150. static inline void jack_unlock_graph (jack_engine_t* engine)
  151. {
  152. DEBUG ("releasing graph lock");
  153. pthread_mutex_unlock (&engine->client_lock);
  154. }
  155. static inline unsigned int jack_power_of_two (unsigned int n)
  156. {
  157. return !(n & (n - 1));
  158. }
  159. /* Internal port handling interfaces for JACK engine. */
  160. void jack_port_clear_connections (jack_engine_t *engine,
  161. jack_port_internal_t *port);
  162. void jack_port_registration_notify (jack_engine_t *, jack_port_id_t, int);
  163. void jack_port_release (jack_engine_t *engine, jack_port_internal_t *);
  164. void jack_sort_graph (jack_engine_t *engine);
  165. #endif /* __jack_engine_h__ */