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.

284 lines
6.7KB

  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 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_internal_h__
  17. #define __jack_internal_h__
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <limits.h>
  21. #include <dlfcn.h>
  22. #include <sys/types.h>
  23. #include <sys/time.h>
  24. #include <pthread.h>
  25. #include <jack/jack.h>
  26. #include <jack/types.h>
  27. #include <jack/port.h>
  28. #include <jack/transport.h>
  29. #include <jack/cycles.h>
  30. #ifdef DEBUG_ENABLED
  31. #define DEBUG(format,args...) \
  32. printf ("jack:%5d %s:%s:%d: " format "\n", getpid(), __FILE__, __FUNCTION__, __LINE__ , ## args)
  33. #else
  34. #define DEBUG(format,args...)
  35. #endif
  36. #ifndef FALSE
  37. #define FALSE (0)
  38. #endif
  39. #ifndef TRUE
  40. #define TRUE (!FALSE)
  41. #endif
  42. typedef struct _jack_engine jack_engine_t;
  43. typedef void * dlhandle;
  44. typedef struct {
  45. int shm_key;
  46. size_t offset;
  47. } jack_port_buffer_info_t;
  48. typedef struct {
  49. int shm_key;
  50. char *address;
  51. } jack_port_segment_info_t;
  52. typedef struct _time_info
  53. {
  54. jack_nframes_t frame;
  55. jack_nframes_t frame_rate;
  56. cycles_t cycles;
  57. jack_transport_state_t transport_state;
  58. jack_nframes_t loop_start;
  59. jack_nframes_t loop_end;
  60. #if 0
  61. double ppqPos; // 1 ppq
  62. double tempo; // in bpm
  63. double barStartPos; // last bar start, in 1 ppq
  64. double cycleStartPos; // 1 ppq
  65. double cycleEndPos; // 1 ppq
  66. float timeSigNumerator; // time signature
  67. float timeSigDenominator;
  68. long smpteOffset;
  69. long smpteFrameRate; // 0:24, 1:25, 2:29.97, 3:30, 4:29.97 df, 5:30 df
  70. long samplesToNextClock; // midi clock resolution (24 ppq), can be negative
  71. long flags; // see below
  72. #endif
  73. } jack_time_info_t;
  74. typedef struct {
  75. volatile unsigned long long guard1;
  76. volatile jack_nframes_t frames;
  77. volatile cycles_t stamp;
  78. volatile unsigned long long guard2;
  79. } jack_frame_timer_t;
  80. typedef struct {
  81. jack_time_info_t current_time;
  82. jack_time_info_t pending_time;
  83. jack_frame_timer_t frame_timer;
  84. int in_process;
  85. jack_nframes_t frames_at_cycle_start;
  86. pid_t engine_pid;
  87. unsigned long buffer_size;
  88. char real_time;
  89. int client_priority;
  90. int has_capabilities;
  91. float cpu_load;
  92. unsigned long port_max;
  93. int engine_ok;
  94. jack_port_shared_t ports[0];
  95. } jack_control_t;
  96. typedef enum {
  97. BufferSizeChange,
  98. SampleRateChange,
  99. NewPortBufferSegment,
  100. PortConnected,
  101. PortDisconnected,
  102. GraphReordered,
  103. PortRegistered,
  104. PortUnregistered,
  105. XRun,
  106. } EventType;
  107. typedef struct {
  108. EventType type;
  109. union {
  110. unsigned long n;
  111. jack_port_id_t port_id;
  112. jack_port_id_t self_id;
  113. } x;
  114. union {
  115. unsigned long n;
  116. jack_port_id_t other_id;
  117. } y;
  118. } jack_event_t;
  119. typedef enum {
  120. ClientDynamic, /* connect request just names .so */
  121. ClientDriver, /* code is loaded along with driver */
  122. ClientOutOfProcess /* client is in another process */
  123. } ClientType;
  124. typedef enum {
  125. NotTriggered,
  126. Triggered,
  127. Running,
  128. Finished
  129. } jack_client_state_t;
  130. typedef volatile struct {
  131. volatile int id; /* w: engine r: engine and client */
  132. volatile jack_nframes_t nframes; /* w: engine r: client */
  133. volatile jack_client_state_t state; /* w: engine and client r: engine */
  134. volatile char name[JACK_CLIENT_NAME_SIZE+1];
  135. volatile ClientType type; /* w: engine r: engine and client */
  136. volatile char active : 1; /* w: engine r: engine and client */
  137. volatile char dead : 1; /* r/w: engine */
  138. volatile char timed_out : 1; /* r/w: engine */
  139. volatile pid_t pid; /* w: client r: engine; pid of client */
  140. volatile unsigned long long signalled_at;
  141. volatile unsigned long long finished_at;
  142. /* callbacks */
  143. JackProcessCallback process;
  144. void *process_arg;
  145. JackBufferSizeCallback bufsize;
  146. void *bufsize_arg;
  147. JackSampleRateCallback srate;
  148. void *srate_arg;
  149. JackPortRegistrationCallback port_register;
  150. void *port_register_arg;
  151. JackGraphOrderCallback graph_order;
  152. void *graph_order_arg;
  153. JackXRunCallback xrun;
  154. void *xrun_arg;
  155. /* for engine use only */
  156. void *private_internal_client;
  157. } jack_client_control_t;
  158. typedef struct {
  159. ClientType type;
  160. char name[JACK_CLIENT_NAME_SIZE+1];
  161. char object_path[PATH_MAX+1];
  162. } jack_client_connect_request_t;
  163. typedef struct {
  164. int status;
  165. int client_key;
  166. int control_key;
  167. char fifo_prefix[PATH_MAX+1];
  168. int realtime;
  169. int realtime_priority;
  170. /* these two are valid only if the connect request
  171. was for type == ClientDriver.
  172. */
  173. jack_client_control_t *client_control;
  174. jack_control_t *engine_control;
  175. /* XXX need to be able to use more than one port segment key */
  176. key_t port_segment_key;
  177. } jack_client_connect_result_t;
  178. typedef struct {
  179. jack_client_id_t client_id;
  180. } jack_client_connect_ack_request_t;
  181. typedef struct {
  182. char status;
  183. } jack_client_connect_ack_result_t;
  184. typedef enum {
  185. RegisterPort = 1,
  186. UnRegisterPort = 2,
  187. ConnectPorts = 3,
  188. DisconnectPorts = 4,
  189. SetTimeBaseClient = 5,
  190. ActivateClient = 6,
  191. DeactivateClient = 7,
  192. DisconnectPort = 8,
  193. SetClientCapabilities = 9
  194. } RequestType;
  195. typedef struct {
  196. RequestType type;
  197. union {
  198. struct {
  199. char name[JACK_PORT_NAME_SIZE+1];
  200. char type[JACK_PORT_TYPE_SIZE+1];
  201. unsigned long flags;
  202. unsigned long buffer_size;
  203. jack_port_id_t port_id;
  204. jack_client_id_t client_id;
  205. } port_info;
  206. struct {
  207. char source_port[JACK_PORT_NAME_SIZE+1];
  208. char destination_port[JACK_PORT_NAME_SIZE+1];
  209. } connect;
  210. jack_client_id_t client_id;
  211. jack_nframes_t nframes;
  212. } x;
  213. int status;
  214. } jack_request_t;
  215. extern void jack_cleanup_shm ();
  216. extern void jack_cleanup_files ();
  217. extern int jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event);
  218. jack_client_t *jack_driver_become_client (const char *client_name);
  219. extern char *jack_temp_dir;
  220. extern int jack_get_mhz (void);
  221. #endif /* __jack_internal_h__ */