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.

337 lines
8.5KB

  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_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. #if defined(__APPLE__) && defined(__POWERPC__)
  26. #include "mach_port.h"
  27. #endif
  28. #include <jack/jack.h>
  29. #include <jack/types.h>
  30. #include <jack/port.h>
  31. #include <jack/transport.h>
  32. #include <jack/time.h>
  33. #ifdef DEBUG_ENABLED
  34. #define DEBUG(format,args...) \
  35. printf ("jack:%5d:%Lu %s:%s:%d: " format "\n", getpid(), jack_get_microseconds(), __FILE__, __FUNCTION__, __LINE__ , ## args)
  36. #else
  37. #if defined(linux)
  38. #define DEBUG(format,args...)
  39. #elif defined(__APPLE__) && defined(__POWERPC__)
  40. #define DEBUG(format...)
  41. #endif
  42. #endif
  43. #ifndef FALSE
  44. #define FALSE (0)
  45. #endif
  46. #ifndef TRUE
  47. #define TRUE (!FALSE)
  48. #endif
  49. typedef struct _jack_engine jack_engine_t;
  50. typedef struct _jack_request jack_request_t;
  51. typedef void * dlhandle;
  52. typedef struct {
  53. const char *shm_name;
  54. size_t offset;
  55. } jack_port_buffer_info_t;
  56. typedef struct {
  57. volatile jack_time_t guard1;
  58. volatile jack_nframes_t frames;
  59. volatile jack_time_t stamp;
  60. volatile jack_time_t guard2;
  61. } jack_frame_timer_t;
  62. /* the relatively low value of this constant
  63. * reflects the fact that JACK currently only
  64. * knows about *1* port type. (March 2003)
  65. */
  66. #define JACK_MAX_PORT_TYPES 4
  67. typedef struct {
  68. jack_transport_info_t current_time;
  69. jack_transport_info_t pending_time;
  70. jack_frame_timer_t frame_timer;
  71. int internal;
  72. jack_nframes_t frames_at_cycle_start;
  73. pid_t engine_pid;
  74. unsigned long buffer_size;
  75. char real_time;
  76. int client_priority;
  77. int has_capabilities;
  78. float cpu_load;
  79. unsigned long port_max;
  80. int engine_ok;
  81. jack_engine_t *engine;
  82. unsigned long n_port_types;
  83. jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
  84. jack_port_shared_t ports[0];
  85. } jack_control_t;
  86. typedef enum {
  87. BufferSizeChange,
  88. SampleRateChange,
  89. NewPortType,
  90. PortConnected,
  91. PortDisconnected,
  92. GraphReordered,
  93. PortRegistered,
  94. PortUnregistered,
  95. XRun,
  96. } EventType;
  97. typedef struct {
  98. EventType type;
  99. union {
  100. unsigned long n;
  101. jack_port_id_t port_id;
  102. jack_port_id_t self_id;
  103. shm_name_t shm_name;
  104. } x;
  105. union {
  106. unsigned long n;
  107. jack_port_id_t other_id;
  108. void* addr;
  109. } y;
  110. union {
  111. size_t size;
  112. } z;
  113. } jack_event_t;
  114. typedef enum {
  115. ClientInternal, /* connect request just names .so */
  116. ClientDriver, /* code is loaded along with driver */
  117. ClientExternal /* client is in another process */
  118. } ClientType;
  119. typedef enum {
  120. NotTriggered,
  121. Triggered,
  122. Running,
  123. Finished
  124. } jack_client_state_t;
  125. typedef volatile struct {
  126. volatile jack_client_id_t id; /* w: engine r: engine and client */
  127. volatile jack_nframes_t nframes; /* w: engine r: client */
  128. volatile jack_client_state_t state; /* w: engine and client r: engine */
  129. volatile char name[JACK_CLIENT_NAME_SIZE+1];
  130. volatile ClientType type; /* w: engine r: engine and client */
  131. volatile char active : 1; /* w: engine r: engine and client */
  132. volatile char dead : 1; /* r/w: engine */
  133. volatile char timed_out : 1; /* r/w: engine */
  134. volatile pid_t pid; /* w: client r: engine; pid of client */
  135. volatile unsigned long long signalled_at;
  136. volatile unsigned long long awake_at;
  137. volatile unsigned long long finished_at;
  138. /* callbacks */
  139. JackProcessCallback process;
  140. void *process_arg;
  141. JackBufferSizeCallback bufsize;
  142. void *bufsize_arg;
  143. JackSampleRateCallback srate;
  144. void *srate_arg;
  145. JackPortRegistrationCallback port_register;
  146. void *port_register_arg;
  147. JackGraphOrderCallback graph_order;
  148. void *graph_order_arg;
  149. JackXRunCallback xrun;
  150. void *xrun_arg;
  151. /* OOP clients: set by libjack
  152. IP clients: set by engine
  153. */
  154. int (*deliver_request)(void*, jack_request_t*);
  155. void *deliver_arg;
  156. /* for engine use only */
  157. void *private_client;
  158. } jack_client_control_t;
  159. typedef struct {
  160. int load;
  161. ClientType type;
  162. char name[JACK_CLIENT_NAME_SIZE+1];
  163. char object_path[PATH_MAX+1];
  164. char object_data[1024];
  165. } jack_client_connect_request_t;
  166. typedef struct {
  167. int status;
  168. unsigned int protocol_v;
  169. shm_name_t client_shm_name;
  170. shm_name_t control_shm_name;
  171. char fifo_prefix[PATH_MAX+1];
  172. int realtime;
  173. int realtime_priority;
  174. /* these two are valid only if the connect request
  175. was for type == ClientDriver.
  176. */
  177. jack_client_control_t *client_control;
  178. jack_control_t *engine_control;
  179. size_t control_size;
  180. /* when we write this response, we deliver n_port_types
  181. of jack_port_type_info_t after it.
  182. */
  183. unsigned long n_port_types;
  184. #if defined(__APPLE__) && defined(__POWERPC__)
  185. /* specific ressources for server/client real-time thread communication */
  186. int portnum;
  187. #endif
  188. } jack_client_connect_result_t;
  189. typedef struct {
  190. jack_client_id_t client_id;
  191. } jack_client_connect_ack_request_t;
  192. typedef struct {
  193. char status;
  194. } jack_client_connect_ack_result_t;
  195. typedef enum {
  196. RegisterPort = 1,
  197. UnRegisterPort = 2,
  198. ConnectPorts = 3,
  199. DisconnectPorts = 4,
  200. SetTimeBaseClient = 5,
  201. ActivateClient = 6,
  202. DeactivateClient = 7,
  203. DisconnectPort = 8,
  204. SetClientCapabilities = 9,
  205. GetPortConnections = 10,
  206. GetPortNConnections = 11,
  207. } RequestType;
  208. struct _jack_request {
  209. RequestType type;
  210. union {
  211. struct {
  212. char name[JACK_PORT_NAME_SIZE+1];
  213. char type[JACK_PORT_TYPE_SIZE+1];
  214. unsigned long flags;
  215. unsigned long buffer_size;
  216. jack_port_id_t port_id;
  217. jack_client_id_t client_id;
  218. } port_info;
  219. struct {
  220. char source_port[JACK_PORT_NAME_SIZE+1];
  221. char destination_port[JACK_PORT_NAME_SIZE+1];
  222. } connect;
  223. struct {
  224. unsigned int nports;
  225. const char **ports;
  226. } port_connections;
  227. jack_client_id_t client_id;
  228. jack_nframes_t nframes;
  229. } x;
  230. int status;
  231. };
  232. typedef struct _jack_client_internal {
  233. jack_client_control_t *control;
  234. int request_fd;
  235. int event_fd;
  236. int subgraph_start_fd;
  237. int subgraph_wait_fd;
  238. JSList *ports; /* protected by engine->client_lock */
  239. JSList *fed_by; /* protected by engine->client_lock */
  240. shm_name_t shm_name;
  241. unsigned long execution_order;
  242. struct _jack_client_internal *next_client; /* not a linked list! */
  243. dlhandle handle;
  244. int (*initialize)(jack_client_t*, const char*); /* for internal clients only */
  245. void (*finish)(void); /* for internal clients only */
  246. int error;
  247. #if defined(__APPLE__) && defined(__POWERPC__)
  248. /* specific ressources for server/client real-time thread communication */
  249. mach_port_t serverport;
  250. trivial_message message;
  251. int running;
  252. int portnum;
  253. #endif
  254. } jack_client_internal_t;
  255. extern void jack_cleanup_files ();
  256. extern int jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event);
  257. extern void jack_client_handle_new_port_type (jack_client_t *client, shm_name_t, size_t, void* addr);
  258. extern jack_client_t *jack_driver_client_new (jack_engine_t *, const char *client_name);
  259. jack_client_t *jack_client_alloc_internal (jack_client_control_t*, jack_control_t*);
  260. /* internal clients call this. its defined in jack/engine.c */
  261. void handle_internal_client_request (jack_control_t*, jack_request_t*);
  262. extern char *jack_server_dir;
  263. extern void jack_error (const char *fmt, ...);
  264. extern jack_port_type_info_t jack_builtin_port_types[];
  265. extern void jack_client_invalidate_port_buffers (jack_client_t *client);
  266. #endif /* __jack_internal_h__ */