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.

299 lines
7.3KB

  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. #include <jack/jack.h>
  26. #include <jack/types.h>
  27. #include <jack/port.h>
  28. #include <jack/transport.h>
  29. #include <jack/time.h>
  30. #ifdef DEBUG_ENABLED
  31. #define DEBUG(format,args...) \
  32. printf ("jack:%5d:%Lu %s:%s:%d: " format "\n", getpid(), jack_get_microseconds(), __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 struct _jack_request jack_request_t;
  44. typedef void * dlhandle;
  45. typedef struct {
  46. const char *shm_name;
  47. size_t offset;
  48. } jack_port_buffer_info_t;
  49. typedef struct {
  50. volatile unsigned long long guard1;
  51. volatile jack_nframes_t frames;
  52. volatile jack_time_t stamp;
  53. volatile unsigned long long guard2;
  54. } jack_frame_timer_t;
  55. /* the relatively low value of this constant
  56. * reflects the fact that JACK currently only
  57. * knows about *1* port type. (March 2003)
  58. */
  59. #define JACK_MAX_PORT_TYPES 4
  60. typedef struct {
  61. jack_transport_info_t current_time;
  62. jack_transport_info_t pending_time;
  63. jack_frame_timer_t frame_timer;
  64. int internal;
  65. jack_nframes_t frames_at_cycle_start;
  66. pid_t engine_pid;
  67. unsigned long buffer_size;
  68. char real_time;
  69. int client_priority;
  70. int has_capabilities;
  71. float cpu_load;
  72. unsigned long port_max;
  73. int engine_ok;
  74. jack_engine_t *engine;
  75. unsigned long n_port_types;
  76. jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
  77. jack_port_shared_t ports[0];
  78. } jack_control_t;
  79. typedef enum {
  80. BufferSizeChange,
  81. SampleRateChange,
  82. NewPortType,
  83. PortConnected,
  84. PortDisconnected,
  85. GraphReordered,
  86. PortRegistered,
  87. PortUnregistered,
  88. XRun,
  89. } EventType;
  90. typedef struct {
  91. EventType type;
  92. union {
  93. unsigned long n;
  94. jack_port_id_t port_id;
  95. jack_port_id_t self_id;
  96. shm_name_t shm_name;
  97. } x;
  98. union {
  99. unsigned long n;
  100. jack_port_id_t other_id;
  101. void* addr;
  102. } y;
  103. union {
  104. size_t size;
  105. } z;
  106. } jack_event_t;
  107. typedef enum {
  108. ClientInternal, /* connect request just names .so */
  109. ClientDriver, /* code is loaded along with driver */
  110. ClientExternal /* client is in another process */
  111. } ClientType;
  112. typedef enum {
  113. NotTriggered,
  114. Triggered,
  115. Running,
  116. Finished
  117. } jack_client_state_t;
  118. typedef volatile struct {
  119. volatile jack_client_id_t id; /* w: engine r: engine and client */
  120. volatile jack_nframes_t nframes; /* w: engine r: client */
  121. volatile jack_client_state_t state; /* w: engine and client r: engine */
  122. volatile char name[JACK_CLIENT_NAME_SIZE+1];
  123. volatile ClientType type; /* w: engine r: engine and client */
  124. volatile char active : 1; /* w: engine r: engine and client */
  125. volatile char dead : 1; /* r/w: engine */
  126. volatile char timed_out : 1; /* r/w: engine */
  127. volatile pid_t pid; /* w: client r: engine; pid of client */
  128. volatile unsigned long long signalled_at;
  129. volatile unsigned long long awake_at;
  130. volatile unsigned long long finished_at;
  131. /* callbacks */
  132. JackProcessCallback process;
  133. void *process_arg;
  134. JackBufferSizeCallback bufsize;
  135. void *bufsize_arg;
  136. JackSampleRateCallback srate;
  137. void *srate_arg;
  138. JackPortRegistrationCallback port_register;
  139. void *port_register_arg;
  140. JackGraphOrderCallback graph_order;
  141. void *graph_order_arg;
  142. JackXRunCallback xrun;
  143. void *xrun_arg;
  144. /* OOP clients: set by libjack
  145. IP clients: set by engine
  146. */
  147. int (*deliver_request)(void*, jack_request_t*);
  148. void *deliver_arg;
  149. /* for engine use only */
  150. void *private_client;
  151. } jack_client_control_t;
  152. typedef struct {
  153. int load;
  154. ClientType type;
  155. char name[JACK_CLIENT_NAME_SIZE+1];
  156. char object_path[PATH_MAX+1];
  157. char object_data[1024];
  158. } jack_client_connect_request_t;
  159. typedef struct {
  160. int status;
  161. unsigned int protocol_v;
  162. shm_name_t client_shm_name;
  163. shm_name_t control_shm_name;
  164. char fifo_prefix[PATH_MAX+1];
  165. int realtime;
  166. int realtime_priority;
  167. /* these two are valid only if the connect request
  168. was for type == ClientDriver.
  169. */
  170. jack_client_control_t *client_control;
  171. jack_control_t *engine_control;
  172. size_t control_size;
  173. /* when we write this response, we deliver n_port_types
  174. of jack_port_type_info_t after it.
  175. */
  176. unsigned long n_port_types;
  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. GetPortConnections = 10,
  195. GetPortNConnections = 11,
  196. } RequestType;
  197. struct _jack_request {
  198. RequestType type;
  199. union {
  200. struct {
  201. char name[JACK_PORT_NAME_SIZE+1];
  202. char type[JACK_PORT_TYPE_SIZE+1];
  203. unsigned long flags;
  204. unsigned long buffer_size;
  205. jack_port_id_t port_id;
  206. jack_client_id_t client_id;
  207. } port_info;
  208. struct {
  209. char source_port[JACK_PORT_NAME_SIZE+1];
  210. char destination_port[JACK_PORT_NAME_SIZE+1];
  211. } connect;
  212. struct {
  213. unsigned int nports;
  214. const char **ports;
  215. } port_connections;
  216. jack_client_id_t client_id;
  217. jack_nframes_t nframes;
  218. } x;
  219. int status;
  220. };
  221. extern void jack_cleanup_files ();
  222. extern int jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event);
  223. extern void jack_client_handle_new_port_type (jack_client_t *client, shm_name_t, size_t, void* addr);
  224. extern jack_client_t *jack_driver_client_new (jack_engine_t *, const char *client_name);
  225. jack_client_t *jack_client_alloc_internal (jack_client_control_t*, jack_control_t*);
  226. /* internal clients call this. its defined in jack/engine.c */
  227. void handle_internal_client_request (jack_control_t*, jack_request_t*);
  228. extern char *jack_server_dir;
  229. extern void jack_error (const char *fmt, ...);
  230. extern jack_port_type_info_t jack_builtin_port_types[];
  231. extern void jack_client_invalidate_port_buffers (jack_client_t *client);
  232. #endif /* __jack_internal_h__ */