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.

187 lines
5.9KB

  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. #define VERBOSE(engine,format,args...) \
  23. if ((engine)->verbose) fprintf (stderr, format, ## args)
  24. struct _jack_driver;
  25. struct _jack_client_internal;
  26. struct _jack_port_internal;
  27. /* Structures is allocated by the engine in local memory to keep track
  28. * of port buffers and connections.
  29. */
  30. typedef struct {
  31. jack_shm_info_t* shm_info;
  32. jack_shmsize_t offset;
  33. } jack_port_buffer_info_t;
  34. /* The engine keeps an array of these in its local memory. */
  35. typedef struct _jack_port_internal {
  36. struct _jack_port_shared *shared;
  37. JSList *connections;
  38. jack_port_buffer_info_t *buffer_info;
  39. } jack_port_internal_t;
  40. /* The engine's internal port type structure. */
  41. typedef struct _jack_port_buffer_list {
  42. pthread_mutex_t lock; /* only lock within server */
  43. JSList *freelist; /* list of free buffers */
  44. jack_port_buffer_info_t *info; /* jack_buffer_info_t array */
  45. } jack_port_buffer_list_t;
  46. /* The main engine structure in local memory. */
  47. struct _jack_engine {
  48. jack_control_t *control;
  49. JSList *drivers;
  50. struct _jack_driver *driver;
  51. jack_driver_desc_t *driver_desc;
  52. JSList *driver_params;
  53. /* these are "callbacks" made by the driver */
  54. int (*set_buffer_size) (struct _jack_engine *, jack_nframes_t frames);
  55. int (*set_sample_rate) (struct _jack_engine *, jack_nframes_t frames);
  56. int (*run_cycle) (struct _jack_engine *, jack_nframes_t nframes,
  57. float delayed_usecs);
  58. void (*delay) (struct _jack_engine *);
  59. void (*transport_cycle_start) (struct _jack_engine *, jack_time_t time);
  60. void (*driver_exit) (struct _jack_engine *);
  61. /* "private" sections starts here */
  62. /* engine serialization -- use precedence for deadlock avoidance */
  63. pthread_mutex_t request_lock; /* precedes client_lock */
  64. pthread_mutex_t client_lock;
  65. pthread_mutex_t port_lock;
  66. int process_errors;
  67. int period_msecs;
  68. /* Time to wait for clients in msecs. Used when jackd is run
  69. * without realtime priority enabled. */
  70. int client_timeout_msecs;
  71. /* info on the shm segment containing this->control */
  72. jack_shm_info_t control_shm;
  73. /* address-space local port buffer and segment info,
  74. indexed by the port type_id
  75. */
  76. jack_port_buffer_list_t port_buffers[JACK_MAX_PORT_TYPES];
  77. jack_shm_info_t port_segment[JACK_MAX_PORT_TYPES];
  78. unsigned int port_max;
  79. pthread_t server_thread;
  80. pthread_t watchdog_thread;
  81. int fds[2];
  82. jack_client_id_t next_client_id;
  83. size_t pfd_size;
  84. size_t pfd_max;
  85. struct pollfd *pfd;
  86. char fifo_prefix[PATH_MAX+1];
  87. int *fifo;
  88. unsigned long fifo_size;
  89. unsigned long external_client_cnt;
  90. int rtpriority;
  91. char freewheeling;
  92. char verbose;
  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 spare_usecs;
  112. float usecs_per_cycle;
  113. #if defined(__APPLE__) && defined(__POWERPC__)
  114. /* specific resources for server/client real-time thread communication */
  115. mach_port_t servertask, bp;
  116. int portnum;
  117. #endif
  118. };
  119. /* public functions */
  120. jack_engine_t *jack_engine_new (int real_time, int real_time_priority,
  121. int temporary, int verbose, int client_timeout,
  122. pid_t waitpid, JSList * drivers);
  123. int jack_engine_delete (jack_engine_t *);
  124. int jack_run (jack_engine_t *engine);
  125. int jack_wait (jack_engine_t *engine);
  126. int jack_engine_load_driver (jack_engine_t *engine,
  127. jack_driver_desc_t * driver_desc,
  128. JSList * driver_params);
  129. void jack_dump_configuration(jack_engine_t *engine, int take_lock);
  130. extern jack_client_internal_t *
  131. jack_client_internal_by_id (jack_engine_t *engine, jack_client_id_t id);
  132. static inline void jack_lock_graph (jack_engine_t* engine) {
  133. DEBUG ("acquiring graph lock");
  134. pthread_mutex_lock (&engine->client_lock);
  135. }
  136. static inline int jack_try_lock_graph (jack_engine_t *engine)
  137. {
  138. DEBUG ("TRYING to acquiring graph lock");
  139. return pthread_mutex_trylock (&engine->client_lock);
  140. }
  141. static inline void jack_unlock_graph (jack_engine_t* engine)
  142. {
  143. DEBUG ("releasing graph lock");
  144. pthread_mutex_unlock (&engine->client_lock);
  145. }
  146. static inline unsigned int jack_power_of_two (unsigned int n)
  147. {
  148. return !(n & (n - 1));
  149. }
  150. #endif /* __jack_engine_h__ */