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.

301 lines
7.1KB

  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:%Lu %s:%s:%d: " format "\n", getpid(), get_cycles(), __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 jack_client_id_t 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 awake_at;
  142. volatile unsigned long long finished_at;
  143. /* callbacks */
  144. JackProcessCallback process;
  145. void *process_arg;
  146. JackBufferSizeCallback bufsize;
  147. void *bufsize_arg;
  148. JackSampleRateCallback srate;
  149. void *srate_arg;
  150. JackPortRegistrationCallback port_register;
  151. void *port_register_arg;
  152. JackGraphOrderCallback graph_order;
  153. void *graph_order_arg;
  154. JackXRunCallback xrun;
  155. void *xrun_arg;
  156. /* for engine use only */
  157. void *private_internal_client;
  158. } jack_client_control_t;
  159. typedef struct {
  160. ClientType type;
  161. char name[JACK_CLIENT_NAME_SIZE+1];
  162. char object_path[PATH_MAX+1];
  163. } jack_client_connect_request_t;
  164. typedef struct {
  165. int status;
  166. int client_key;
  167. int control_key;
  168. char fifo_prefix[PATH_MAX+1];
  169. int realtime;
  170. int realtime_priority;
  171. /* these two are valid only if the connect request
  172. was for type == ClientDriver.
  173. */
  174. jack_client_control_t *client_control;
  175. jack_control_t *engine_control;
  176. /* XXX need to be able to use more than one port segment key */
  177. key_t port_segment_key;
  178. } jack_client_connect_result_t;
  179. typedef struct {
  180. jack_client_id_t client_id;
  181. } jack_client_connect_ack_request_t;
  182. typedef struct {
  183. char status;
  184. } jack_client_connect_ack_result_t;
  185. typedef enum {
  186. RegisterPort = 1,
  187. UnRegisterPort = 2,
  188. ConnectPorts = 3,
  189. DisconnectPorts = 4,
  190. SetTimeBaseClient = 5,
  191. ActivateClient = 6,
  192. DeactivateClient = 7,
  193. DisconnectPort = 8,
  194. SetClientCapabilities = 9,
  195. GetPortConnections = 10,
  196. GetPortNConnections = 11,
  197. AddAlias = 12,
  198. RemoveAlias = 13
  199. } RequestType;
  200. typedef struct {
  201. RequestType type;
  202. union {
  203. struct {
  204. char name[JACK_PORT_NAME_SIZE+1];
  205. char type[JACK_PORT_TYPE_SIZE+1];
  206. unsigned long flags;
  207. unsigned long buffer_size;
  208. jack_port_id_t port_id;
  209. jack_client_id_t client_id;
  210. } port_info;
  211. struct {
  212. char source_port[JACK_PORT_NAME_SIZE+1];
  213. char destination_port[JACK_PORT_NAME_SIZE+1];
  214. } connect;
  215. struct {
  216. char port[JACK_PORT_NAME_SIZE+1];
  217. char alias[JACK_PORT_NAME_SIZE+1];
  218. } alias;
  219. jack_client_id_t client_id;
  220. jack_nframes_t nframes;
  221. unsigned int nports;
  222. } x;
  223. int status;
  224. } jack_request_t;
  225. typedef struct _jack_port_alias {
  226. char port[JACK_PORT_NAME_SIZE+1];
  227. char alias[JACK_PORT_NAME_SIZE+1];
  228. } jack_port_alias_t;
  229. extern void jack_cleanup_shm ();
  230. extern void jack_cleanup_files ();
  231. extern int jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event);
  232. jack_client_t *jack_driver_become_client (const char *client_name);
  233. extern char *jack_server_dir;
  234. extern int jack_get_mhz (void);
  235. extern void jack_error (const char *fmt, ...);
  236. #endif /* __jack_internal_h__ */