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.

137 lines
4.2KB

  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. struct _jack_driver;
  21. struct _jack_client_internal;
  22. struct _jack_port_internal;
  23. struct _jack_engine {
  24. jack_control_t *control;
  25. struct _jack_driver *driver;
  26. /* these are "callbacks" made by the driver */
  27. int (*set_buffer_size)(struct _jack_engine *, jack_nframes_t frames);
  28. int (*set_sample_rate)(struct _jack_engine *, jack_nframes_t frames);
  29. int (*run_cycle)(struct _jack_engine *, jack_nframes_t nframes,
  30. float delayed_usecs);
  31. void (*transport_cycle_start)(struct _jack_engine *, jack_time_t time);
  32. /* "private" sections starts here */
  33. pthread_mutex_t client_lock;
  34. pthread_mutex_t port_lock;
  35. pthread_mutex_t request_lock;
  36. int process_errors;
  37. int period_msecs;
  38. int client_timeout_msecs; /* Time to wait for clients in msecs. Used when jackd is
  39. * run in non-ASIO mode and without realtime priority enabled.
  40. */
  41. unsigned int port_max;
  42. shm_name_t control_shm_name;
  43. size_t control_size;
  44. shm_name_t port_segment_name; /* XXX fix me */
  45. size_t port_segment_size; /* XXX fix me */
  46. void *port_segment_address; /* XXX fix me */
  47. pthread_t main_thread;
  48. pthread_t server_thread;
  49. /* these lists are all protected by `client_lock' */
  50. JSList *clients;
  51. JSList *clients_waiting;
  52. struct _jack_port_internal *internal_ports;
  53. int fds[2];
  54. jack_client_id_t next_client_id;
  55. size_t pfd_size;
  56. size_t pfd_max;
  57. struct pollfd *pfd;
  58. struct _jack_client_internal *timebase_client;
  59. jack_port_buffer_info_t *silent_buffer;
  60. char fifo_prefix[PATH_MAX+1];
  61. int *fifo;
  62. unsigned long fifo_size;
  63. unsigned long external_client_cnt;
  64. int rtpriority;
  65. char verbose;
  66. char asio_mode;
  67. int reordered;
  68. int watchdog_check;
  69. struct _jack_client_internal *current_client;
  70. #define JACK_ENGINE_ROLLING_COUNT 32
  71. #define JACK_ENGINE_ROLLING_INTERVAL 1024
  72. jack_time_t rolling_client_usecs[JACK_ENGINE_ROLLING_COUNT];
  73. int rolling_client_usecs_cnt;
  74. int rolling_client_usecs_index;
  75. int rolling_interval;
  76. float spare_usecs;
  77. float usecs_per_cycle;
  78. #if defined(__APPLE__) && defined(__POWERPC__)
  79. /* specific ressources for server/client real-time thread communication */
  80. mach_port_t servertask, bp;
  81. int portnum;
  82. #endif
  83. };
  84. /* public functions */
  85. jack_engine_t *jack_engine_new (int real_time, int real_time_priority, int verbose, int client_timeout);
  86. int jack_engine_delete (jack_engine_t *);
  87. int jack_run (jack_engine_t *engine);
  88. int jack_wait (jack_engine_t *engine);
  89. int jack_engine_load_driver (jack_engine_t *, int, char **);
  90. void jack_set_asio_mode (jack_engine_t *, int yn);
  91. void jack_dump_configuration(jack_engine_t *engine, int take_lock);
  92. extern jack_client_internal_t *
  93. jack_client_internal_by_id (jack_engine_t *engine, jack_client_id_t id);
  94. static inline void jack_lock_graph (jack_engine_t* engine) {
  95. DEBUG ("acquiring graph lock");
  96. pthread_mutex_lock (&engine->client_lock);
  97. }
  98. static inline int jack_try_lock_graph (jack_engine_t *engine)
  99. {
  100. DEBUG ("TRYING to acquiring graph lock");
  101. return pthread_mutex_trylock (&engine->client_lock);
  102. }
  103. static inline void jack_unlock_graph (jack_engine_t* engine)
  104. {
  105. DEBUG ("releasing graph lock");
  106. pthread_mutex_unlock (&engine->client_lock);
  107. }
  108. #endif /* __jack_engine_h__ */