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.

368 lines
9.7KB

  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:%Lu %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;
  58. } jack_port_buffer_info_t;
  59. typedef enum {
  60. TransportCommandNone = 0,
  61. TransportCommandPlay = 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. jack_position_t current_time; /* position for current cycle */
  80. jack_position_t pending_time; /* position for next cycle */
  81. jack_position_t request_time; /* latest requested position */
  82. int new_pos; /* new position this cycle */
  83. unsigned long sync_remain; /* remaining sync count */
  84. unsigned long sync_cycle; /* number ready this cycle */
  85. unsigned long sync_clients; /* number of slow-sync clients */
  86. jack_frame_timer_t frame_timer;
  87. int internal;
  88. jack_nframes_t frames_at_cycle_start;
  89. pid_t engine_pid;
  90. unsigned long buffer_size;
  91. char real_time;
  92. int client_priority;
  93. int has_capabilities;
  94. float cpu_load;
  95. unsigned long port_max;
  96. int engine_ok;
  97. jack_engine_t *engine;
  98. unsigned long n_port_types;
  99. jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
  100. jack_port_shared_t ports[0];
  101. } jack_control_t;
  102. typedef enum {
  103. BufferSizeChange,
  104. SampleRateChange,
  105. NewPortType,
  106. PortConnected,
  107. PortDisconnected,
  108. GraphReordered,
  109. PortRegistered,
  110. PortUnregistered,
  111. XRun,
  112. } EventType;
  113. typedef struct {
  114. EventType type;
  115. union {
  116. unsigned long n;
  117. jack_port_id_t port_id;
  118. jack_port_id_t self_id;
  119. shm_name_t shm_name;
  120. } x;
  121. union {
  122. unsigned long n;
  123. jack_port_id_t other_id;
  124. void* addr;
  125. } y;
  126. union {
  127. size_t size;
  128. } z;
  129. } jack_event_t;
  130. typedef enum {
  131. ClientInternal, /* connect request just names .so */
  132. ClientDriver, /* code is loaded along with driver */
  133. ClientExternal /* client is in another process */
  134. } ClientType;
  135. typedef enum {
  136. NotTriggered,
  137. Triggered,
  138. Running,
  139. Finished
  140. } jack_client_state_t;
  141. /* JACK client shared memory data structure. */
  142. typedef volatile struct {
  143. volatile jack_client_id_t id; /* w: engine r: engine and client */
  144. volatile jack_nframes_t nframes; /* w: engine r: client */
  145. volatile jack_client_state_t state; /* w: engine and client r: engine */
  146. volatile char name[JACK_CLIENT_NAME_SIZE+1];
  147. volatile ClientType type; /* w: engine r: engine and client */
  148. volatile char active : 1; /* w: engine r: engine and client */
  149. volatile char dead : 1; /* r/w: engine */
  150. volatile char timed_out : 1; /* r/w: engine */
  151. volatile char sync_ready : 1; /* w: engine and client, r: engine */
  152. volatile pid_t pid; /* w: client r: engine; client pid */
  153. volatile unsigned long long signalled_at;
  154. volatile unsigned long long awake_at;
  155. volatile unsigned long long finished_at;
  156. /* callbacks */
  157. JackProcessCallback process;
  158. void *process_arg;
  159. JackBufferSizeCallback bufsize;
  160. void *bufsize_arg;
  161. JackSampleRateCallback srate;
  162. void *srate_arg;
  163. JackPortRegistrationCallback port_register;
  164. void *port_register_arg;
  165. JackGraphOrderCallback graph_order;
  166. void *graph_order_arg;
  167. JackXRunCallback xrun;
  168. void *xrun_arg;
  169. JackSyncCallback sync_cb;
  170. void *sync_arg;
  171. JackTimebaseCallback timebase_cb;
  172. void *timebase_arg;
  173. /* external clients: set by libjack
  174. * internal clients: set by engine */
  175. int (*deliver_request)(void*, jack_request_t*);
  176. void *deliver_arg;
  177. /* for engine use only */
  178. void *private_client;
  179. } jack_client_control_t;
  180. typedef struct {
  181. int load;
  182. ClientType type;
  183. char name[JACK_CLIENT_NAME_SIZE+1];
  184. char object_path[PATH_MAX+1];
  185. char object_data[1024];
  186. } jack_client_connect_request_t;
  187. typedef struct {
  188. int status;
  189. unsigned int protocol_v;
  190. shm_name_t client_shm_name;
  191. shm_name_t control_shm_name;
  192. char fifo_prefix[PATH_MAX+1];
  193. int realtime;
  194. int realtime_priority;
  195. /* these two are valid only if the connect request
  196. was for type == ClientDriver.
  197. */
  198. jack_client_control_t *client_control;
  199. jack_control_t *engine_control;
  200. size_t control_size;
  201. /* when we write this response, we deliver n_port_types
  202. of jack_port_type_info_t after it.
  203. */
  204. unsigned long n_port_types;
  205. #if defined(__APPLE__) && defined(__POWERPC__)
  206. /* specific ressources for server/client real-time thread communication */
  207. int portnum;
  208. #endif
  209. } jack_client_connect_result_t;
  210. typedef struct {
  211. jack_client_id_t client_id;
  212. } jack_client_connect_ack_request_t;
  213. typedef struct {
  214. char status;
  215. } jack_client_connect_ack_result_t;
  216. typedef enum {
  217. RegisterPort = 1,
  218. UnRegisterPort = 2,
  219. ConnectPorts = 3,
  220. DisconnectPorts = 4,
  221. SetTimeBaseClient = 5,
  222. ActivateClient = 6,
  223. DeactivateClient = 7,
  224. DisconnectPort = 8,
  225. SetClientCapabilities = 9,
  226. GetPortConnections = 10,
  227. GetPortNConnections = 11,
  228. ResetTimeBaseClient = 12,
  229. SetSyncClient = 13,
  230. } RequestType;
  231. struct _jack_request {
  232. RequestType type;
  233. union {
  234. struct {
  235. char name[JACK_PORT_NAME_SIZE+1];
  236. char type[JACK_PORT_TYPE_SIZE+1];
  237. unsigned long flags;
  238. unsigned long buffer_size;
  239. jack_port_id_t port_id;
  240. jack_client_id_t client_id;
  241. } port_info;
  242. struct {
  243. char source_port[JACK_PORT_NAME_SIZE+1];
  244. char destination_port[JACK_PORT_NAME_SIZE+1];
  245. } connect;
  246. struct {
  247. unsigned int nports;
  248. const char **ports;
  249. } port_connections;
  250. struct {
  251. jack_client_id_t client_id;
  252. int conditional;
  253. } timebase;
  254. jack_client_id_t client_id;
  255. jack_nframes_t nframes;
  256. } x;
  257. int status;
  258. };
  259. typedef struct _jack_client_internal {
  260. jack_client_control_t *control;
  261. int request_fd;
  262. int event_fd;
  263. int subgraph_start_fd;
  264. int subgraph_wait_fd;
  265. JSList *ports; /* protected by engine->client_lock */
  266. JSList *fed_by; /* protected by engine->client_lock */
  267. shm_name_t shm_name;
  268. unsigned long execution_order;
  269. struct _jack_client_internal *next_client; /* not a linked list! */
  270. dlhandle handle;
  271. int (*initialize)(jack_client_t*, const char*); /* for internal clients only */
  272. void (*finish)(void); /* for internal clients only */
  273. int error;
  274. #if defined(__APPLE__) && defined(__POWERPC__)
  275. /* specific ressources for server/client real-time thread communication */
  276. mach_port_t serverport;
  277. trivial_message message;
  278. int running;
  279. int portnum;
  280. #endif
  281. } jack_client_internal_t;
  282. extern void jack_cleanup_files ();
  283. extern int jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event);
  284. extern void jack_client_handle_new_port_type (jack_client_t *client, shm_name_t, size_t, void* addr);
  285. extern jack_client_t *jack_driver_client_new (jack_engine_t *, const char *client_name);
  286. jack_client_t *jack_client_alloc_internal (jack_client_control_t*, jack_control_t*);
  287. /* internal clients call this. its defined in jack/engine.c */
  288. void handle_internal_client_request (jack_control_t*, jack_request_t*);
  289. extern char *jack_server_dir;
  290. extern void jack_error (const char *fmt, ...);
  291. extern jack_port_type_info_t jack_builtin_port_types[];
  292. extern void jack_client_invalidate_port_buffers (jack_client_t *client);
  293. extern void jack_transport_copy_position (jack_position_t *from,
  294. jack_position_t *to);
  295. #endif /* __jack_internal_h__ */