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.

389 lines
11KB

  1. /*
  2. Internal shared data and functions.
  3. If you edit this file, you should carefully consider changing the
  4. JACK_PROTOCOL_VERSION in configure.in.
  5. Copyright (C) 2001-2003 Paul Davis
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. $Id$
  18. */
  19. #ifndef __jack_internal_h__
  20. #define __jack_internal_h__
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <limits.h>
  24. #include <dlfcn.h>
  25. #include <sys/types.h>
  26. #include <sys/time.h>
  27. #include <pthread.h>
  28. #if defined(__APPLE__) && defined(__POWERPC__)
  29. #include "mach_port.h"
  30. #endif
  31. #include <jack/jack.h>
  32. #include <jack/types.h>
  33. #include <jack/port.h>
  34. #include <jack/transport.h>
  35. #include <jack/time.h>
  36. #ifdef DEBUG_ENABLED
  37. #define DEBUG(format,args...) \
  38. printf ("jack:%5d:%" PRIu64 " %s:%s:%d: " format "\n", getpid(), jack_get_microseconds(), __FILE__, __FUNCTION__, __LINE__ , ## args)
  39. #else
  40. #if defined(__APPLE__) && defined(__POWERPC__)
  41. #define DEBUG(format...)
  42. #else
  43. #define DEBUG(format,args...)
  44. #endif
  45. #endif
  46. #ifndef FALSE
  47. #define FALSE (0)
  48. #endif
  49. #ifndef TRUE
  50. #define TRUE (!FALSE)
  51. #endif
  52. typedef struct _jack_engine jack_engine_t;
  53. typedef struct _jack_request jack_request_t;
  54. typedef void * dlhandle;
  55. typedef struct {
  56. const char *shm_name;
  57. size_t offset; /* JOQ: 32/64 problem? */
  58. } jack_port_buffer_info_t;
  59. typedef enum {
  60. TransportCommandNone = 0,
  61. TransportCommandStart = 1,
  62. TransportCommandStop = 2,
  63. } transport_command_t;
  64. typedef struct {
  65. volatile jack_time_t guard1;
  66. volatile jack_nframes_t frames;
  67. volatile jack_time_t stamp;
  68. volatile jack_time_t guard2;
  69. } jack_frame_timer_t;
  70. /* the relatively low value of this constant
  71. * reflects the fact that JACK currently only
  72. * knows about *1* port type. (March 2003)
  73. */
  74. #define JACK_MAX_PORT_TYPES 4
  75. /* JACK engine shared memory data structure. */
  76. typedef struct {
  77. jack_transport_state_t transport_state;
  78. volatile transport_command_t transport_cmd;
  79. transport_command_t previous_cmd; /* previous transport_cmd */
  80. jack_position_t current_time; /* position for current cycle */
  81. jack_position_t pending_time; /* position for next cycle */
  82. jack_position_t request_time; /* latest requested position */
  83. jack_unique_t prev_request; /* previous request unique ID */
  84. volatile uint32_t seq_number; /* unique ID sequence number */
  85. int8_t new_pos; /* new position this cycle */
  86. int8_t pending_pos; /* new position request pending */
  87. jack_nframes_t pending_frame; /* pending frame number */
  88. uint32_t sync_clients; /* number of is_slowsync clients */
  89. uint32_t sync_remain; /* number of them with sync_poll */
  90. jack_time_t sync_timeout;
  91. jack_time_t sync_time_left;
  92. jack_frame_timer_t frame_timer;
  93. int32_t internal;
  94. jack_nframes_t frames_at_cycle_start;
  95. pid_t engine_pid;
  96. uint32_t buffer_size;
  97. int8_t real_time;
  98. int32_t client_priority;
  99. int32_t has_capabilities;
  100. float cpu_load;
  101. uint32_t port_max;
  102. int32_t engine_ok;
  103. uint32_t n_port_types;
  104. jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
  105. jack_port_shared_t ports[0];
  106. } jack_control_t;
  107. typedef enum {
  108. BufferSizeChange,
  109. SampleRateChange,
  110. NewPortType,
  111. PortConnected,
  112. PortDisconnected,
  113. GraphReordered,
  114. PortRegistered,
  115. PortUnregistered,
  116. XRun,
  117. } EventType;
  118. typedef struct {
  119. EventType type;
  120. union {
  121. uint32_t n;
  122. jack_port_id_t port_id;
  123. jack_port_id_t self_id;
  124. shm_name_t shm_name;
  125. } x;
  126. union {
  127. uint32_t n;
  128. jack_port_id_t other_id;
  129. void* addr; /* JOQ: 32/64 problem? */
  130. } y;
  131. union {
  132. size_t size; /* JOQ: 32/64 problem? */
  133. } z;
  134. } jack_event_t;
  135. typedef enum {
  136. ClientInternal, /* connect request just names .so */
  137. ClientDriver, /* code is loaded along with driver */
  138. ClientExternal /* client is in another process */
  139. } ClientType;
  140. typedef enum {
  141. NotTriggered,
  142. Triggered,
  143. Running,
  144. Finished
  145. } jack_client_state_t;
  146. /* JACK client shared memory data structure. */
  147. typedef volatile struct {
  148. volatile jack_client_id_t id; /* w: engine r: engine and client */
  149. volatile jack_nframes_t nframes; /* w: engine r: client */
  150. volatile jack_client_state_t state; /* w: engine and client r: engine */
  151. volatile int8_t name[JACK_CLIENT_NAME_SIZE+1];
  152. volatile ClientType type; /* w: engine r: engine and client */
  153. volatile int8_t active : 1; /* w: engine r: engine and client */
  154. volatile int8_t dead : 1; /* r/w: engine */
  155. volatile int8_t timed_out : 1; /* r/w: engine */
  156. volatile int8_t is_timebase : 1; /* w: engine, r: engine and client */
  157. volatile int8_t is_slowsync : 1; /* w: engine, r: engine and client */
  158. volatile int8_t sync_poll : 1; /* w: engine and client, r: engine */
  159. volatile int8_t sync_new : 1; /* w: engine and client, r: engine */
  160. volatile pid_t pid; /* w: client r: engine; client pid */
  161. volatile uint64_t signalled_at;
  162. volatile uint64_t awake_at;
  163. volatile uint64_t finished_at;
  164. /* JOQ: all these pointers are trouble for 32/64 compatibility,
  165. * they should move to non-shared memory. */
  166. /* callbacks */
  167. JackProcessCallback process;
  168. void *process_arg;
  169. JackBufferSizeCallback bufsize;
  170. void *bufsize_arg;
  171. JackSampleRateCallback srate;
  172. void *srate_arg;
  173. JackPortRegistrationCallback port_register;
  174. void *port_register_arg;
  175. JackGraphOrderCallback graph_order;
  176. void *graph_order_arg;
  177. JackXRunCallback xrun;
  178. void *xrun_arg;
  179. JackSyncCallback sync_cb;
  180. void *sync_arg;
  181. JackTimebaseCallback timebase_cb;
  182. void *timebase_arg;
  183. /* external clients: set by libjack
  184. * internal clients: set by engine */
  185. int (*deliver_request)(void*, jack_request_t*);
  186. void *deliver_arg;
  187. /* for engine use only */
  188. void *private_client;
  189. } jack_client_control_t;
  190. typedef struct {
  191. int32_t load;
  192. ClientType type;
  193. char name[JACK_CLIENT_NAME_SIZE+1];
  194. char object_path[PATH_MAX+1];
  195. char object_data[1024];
  196. } jack_client_connect_request_t;
  197. typedef struct {
  198. int32_t status;
  199. uint32_t protocol_v;
  200. shm_name_t client_shm_name;
  201. shm_name_t control_shm_name;
  202. int8_t fifo_prefix[PATH_MAX+1];
  203. int32_t realtime;
  204. int32_t realtime_priority;
  205. /* these two are valid only if the connect request
  206. was for type == ClientDriver.
  207. */
  208. jack_client_control_t *client_control;
  209. jack_control_t *engine_control;
  210. size_t control_size; /* JOQ: 32/64 problem? */
  211. /* when we write this response, we deliver n_port_types
  212. of jack_port_type_info_t after it.
  213. */
  214. uint32_t n_port_types;
  215. #if defined(__APPLE__) && defined(__POWERPC__)
  216. /* specific resources for server/client real-time thread communication */
  217. int32_t portnum;
  218. #endif
  219. } jack_client_connect_result_t;
  220. typedef struct {
  221. jack_client_id_t client_id;
  222. } jack_client_connect_ack_request_t;
  223. typedef struct {
  224. int8_t status;
  225. } jack_client_connect_ack_result_t;
  226. typedef enum {
  227. RegisterPort = 1,
  228. UnRegisterPort = 2,
  229. ConnectPorts = 3,
  230. DisconnectPorts = 4,
  231. SetTimeBaseClient = 5,
  232. ActivateClient = 6,
  233. DeactivateClient = 7,
  234. DisconnectPort = 8,
  235. SetClientCapabilities = 9,
  236. GetPortConnections = 10,
  237. GetPortNConnections = 11,
  238. ResetTimeBaseClient = 12,
  239. SetSyncClient = 13,
  240. ResetSyncClient = 14,
  241. SetSyncTimeout = 15,
  242. } RequestType;
  243. struct _jack_request {
  244. RequestType type;
  245. union {
  246. struct {
  247. char name[JACK_PORT_NAME_SIZE+1];
  248. char type[JACK_PORT_TYPE_SIZE+1];
  249. uint32_t flags;
  250. uint32_t buffer_size;
  251. jack_port_id_t port_id;
  252. jack_client_id_t client_id;
  253. } port_info;
  254. struct {
  255. char source_port[JACK_PORT_NAME_SIZE+1];
  256. char destination_port[JACK_PORT_NAME_SIZE+1];
  257. } connect;
  258. struct {
  259. int32_t nports;
  260. const char **ports; /* JOQ: 32/64 problem? */
  261. } port_connections;
  262. struct {
  263. jack_client_id_t client_id;
  264. int32_t conditional;
  265. } timebase;
  266. jack_client_id_t client_id;
  267. jack_nframes_t nframes;
  268. jack_time_t timeout;
  269. } x;
  270. int32_t status;
  271. };
  272. /* per-client structure allocated in the server's address space
  273. * JOQ: then why isn't this in engine.h? */
  274. typedef struct _jack_client_internal {
  275. jack_client_control_t *control;
  276. int request_fd;
  277. int event_fd;
  278. int subgraph_start_fd;
  279. int subgraph_wait_fd;
  280. JSList *ports; /* protected by engine->client_lock */
  281. JSList *fed_by; /* protected by engine->client_lock */
  282. shm_name_t shm_name;
  283. unsigned long execution_order;
  284. struct _jack_client_internal *next_client; /* not a linked list! */
  285. dlhandle handle;
  286. int (*initialize)(jack_client_t*, const char*); /* int. clients only */
  287. void (*finish)(void *); /* internal clients only */
  288. int error;
  289. #if defined(__APPLE__) && defined(__POWERPC__)
  290. /* specific resources for server/client real-time thread communication */
  291. mach_port_t serverport;
  292. trivial_message message;
  293. int running;
  294. int portnum;
  295. #endif
  296. } jack_client_internal_t;
  297. extern void jack_cleanup_files ();
  298. extern int jack_client_handle_port_connection (jack_client_t *client,
  299. jack_event_t *event);
  300. extern void jack_client_handle_new_port_type (jack_client_t *client,
  301. shm_name_t, size_t, void* addr);
  302. extern jack_client_t *jack_driver_client_new (jack_engine_t *,
  303. const char *client_name);
  304. jack_client_t *jack_client_alloc_internal (jack_client_control_t*,
  305. jack_control_t*);
  306. /* internal clients call this. it's defined in jack/engine.c */
  307. void handle_internal_client_request (jack_control_t*, jack_request_t*);
  308. extern char *jack_server_dir;
  309. extern void jack_error (const char *fmt, ...);
  310. extern jack_port_type_info_t jack_builtin_port_types[];
  311. extern void jack_client_invalidate_port_buffers (jack_client_t *client);
  312. extern void jack_transport_copy_position (jack_position_t *from,
  313. jack_position_t *to);
  314. extern void jack_call_sync_client (jack_client_t *client);
  315. extern void jack_call_timebase_master (jack_client_t *client);
  316. #endif /* __jack_internal_h__ */