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.

176 lines
5.5KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 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 General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. $Id$
  15. */
  16. #ifndef __jack_engine_h__
  17. #define __jack_engine_h__
  18. #include <jack/jack.h>
  19. #include <jack/internal.h>
  20. #define VERBOSE(engine,format,args...) \
  21. if ((engine)->verbose) fprintf (stderr, format, ## args)
  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. typedef struct {
  28. const char *shm_name;
  29. jack_shmsize_t offset;
  30. } jack_port_buffer_info_t;
  31. /* The engine keeps an array of these in its local memory. */
  32. typedef struct _jack_port_internal {
  33. struct _jack_port_shared *shared;
  34. JSList *connections;
  35. jack_port_buffer_info_t *buffer_info;
  36. } jack_port_internal_t;
  37. /* The engine's internal port type structure. */
  38. typedef struct _jack_port_type_internal {
  39. pthread_mutex_t buffer_lock; /* only lock within server */
  40. JSList *buffer_freelist; /* list of free buffers */
  41. void *buffer_info; /* jack_buffer_info_t array */
  42. void *seg_addr; /* buffer segment address */
  43. } jack_port_type_internal_t;
  44. /* The main engine structure in local memory. */
  45. struct _jack_engine {
  46. jack_control_t *control;
  47. struct _jack_driver *driver;
  48. /* these are "callbacks" made by the driver */
  49. int (*set_buffer_size)(struct _jack_engine *, jack_nframes_t frames);
  50. int (*set_sample_rate)(struct _jack_engine *, jack_nframes_t frames);
  51. int (*run_cycle)(struct _jack_engine *, jack_nframes_t nframes,
  52. float delayed_usecs);
  53. void (*transport_cycle_start)(struct _jack_engine *, jack_time_t time);
  54. /* "private" sections starts here */
  55. /* engine serialization -- use precedence for deadlock avoidance */
  56. pthread_mutex_t port_lock;
  57. pthread_mutex_t request_lock; /* precedes driver_lock */
  58. pthread_mutex_t driver_lock; /* precedes client_lock */
  59. pthread_mutex_t client_lock;
  60. int process_errors;
  61. int period_msecs;
  62. int client_timeout_msecs; /* Time to wait for clients in
  63. * msecs. Used when jackd is run in
  64. * non-ASIO mode and without realtime
  65. * priority enabled. */
  66. /* internal port type info, indexed by the port type_id */
  67. jack_port_type_internal_t port_type[JACK_MAX_PORT_TYPES];
  68. unsigned int port_max;
  69. shm_name_t control_shm_name;
  70. size_t control_size;
  71. shm_name_t port_segment_name; /* XXX fix me */
  72. size_t port_segment_size; /* XXX fix me */
  73. void *port_segment_address; /* XXX fix me */
  74. pthread_t main_thread;
  75. pthread_t server_thread;
  76. /* these lists are all protected by `client_lock' */
  77. JSList *clients;
  78. JSList *clients_waiting;
  79. struct _jack_port_internal *internal_ports;
  80. int fds[2];
  81. jack_client_id_t next_client_id;
  82. size_t pfd_size;
  83. size_t pfd_max;
  84. struct pollfd *pfd;
  85. struct _jack_client_internal *timebase_client;
  86. jack_port_buffer_info_t *silent_buffer;
  87. char fifo_prefix[PATH_MAX+1];
  88. int *fifo;
  89. unsigned long fifo_size;
  90. unsigned long external_client_cnt;
  91. int rtpriority;
  92. char verbose;
  93. char asio_mode;
  94. int reordered;
  95. int watchdog_check;
  96. struct _jack_client_internal *current_client;
  97. #define JACK_ENGINE_ROLLING_COUNT 32
  98. #define JACK_ENGINE_ROLLING_INTERVAL 1024
  99. jack_time_t rolling_client_usecs[JACK_ENGINE_ROLLING_COUNT];
  100. int rolling_client_usecs_cnt;
  101. int rolling_client_usecs_index;
  102. int rolling_interval;
  103. float spare_usecs;
  104. float usecs_per_cycle;
  105. #if defined(__APPLE__) && defined(__POWERPC__)
  106. /* specific ressources for server/client real-time thread communication */
  107. mach_port_t servertask, bp;
  108. int portnum;
  109. #endif
  110. };
  111. /* public functions */
  112. jack_engine_t *jack_engine_new (int real_time, int real_time_priority, int verbose, int client_timeout);
  113. int jack_engine_delete (jack_engine_t *);
  114. int jack_run (jack_engine_t *engine);
  115. int jack_wait (jack_engine_t *engine);
  116. int jack_engine_load_driver (jack_engine_t *, int, char **);
  117. void jack_set_asio_mode (jack_engine_t *, int yn);
  118. void jack_dump_configuration(jack_engine_t *engine, int take_lock);
  119. extern jack_client_internal_t *
  120. jack_client_internal_by_id (jack_engine_t *engine, jack_client_id_t id);
  121. static inline void jack_lock_graph (jack_engine_t* engine) {
  122. DEBUG ("acquiring graph lock");
  123. pthread_mutex_lock (&engine->client_lock);
  124. }
  125. static inline int jack_try_lock_graph (jack_engine_t *engine)
  126. {
  127. DEBUG ("TRYING to acquiring graph lock");
  128. return pthread_mutex_trylock (&engine->client_lock);
  129. }
  130. static inline void jack_unlock_graph (jack_engine_t* engine)
  131. {
  132. DEBUG ("releasing graph lock");
  133. pthread_mutex_unlock (&engine->client_lock);
  134. }
  135. static inline unsigned int jack_power_of_two (unsigned int n)
  136. {
  137. return !(n & (n - 1));
  138. }
  139. #endif /* __jack_engine_h__ */