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.

277 lines
6.6KB

  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 <glib.h>
  26. #include <jack/jack.h>
  27. #include <jack/types.h>
  28. #include <jack/port.h>
  29. #include <jack/transport.h>
  30. #include <jack/cycles.h>
  31. #ifdef DEBUG_ENABLED
  32. #define DEBUG(format,args...) \
  33. printf ("jack:%5d %s:%s:%d: " format "\n", getpid(), __FILE__, __FUNCTION__, __LINE__ , ## args)
  34. #else
  35. #define DEBUG(format,args...)
  36. #endif
  37. typedef struct _jack_engine jack_engine_t;
  38. typedef void * dlhandle;
  39. typedef struct {
  40. int shm_key;
  41. size_t offset;
  42. } jack_port_buffer_info_t;
  43. typedef struct {
  44. int shm_key;
  45. char *address;
  46. } jack_port_segment_info_t;
  47. typedef struct _time_info
  48. {
  49. jack_nframes_t frame;
  50. jack_nframes_t frame_rate;
  51. cycles_t cycles;
  52. jack_transport_state_t transport_state;
  53. jack_nframes_t loop_start;
  54. jack_nframes_t loop_end;
  55. #if 0
  56. double ppqPos; // 1 ppq
  57. double tempo; // in bpm
  58. double barStartPos; // last bar start, in 1 ppq
  59. double cycleStartPos; // 1 ppq
  60. double cycleEndPos; // 1 ppq
  61. float timeSigNumerator; // time signature
  62. float timeSigDenominator;
  63. long smpteOffset;
  64. long smpteFrameRate; // 0:24, 1:25, 2:29.97, 3:30, 4:29.97 df, 5:30 df
  65. long samplesToNextClock; // midi clock resolution (24 ppq), can be negative
  66. long flags; // see below
  67. #endif
  68. } jack_time_info_t;
  69. typedef struct {
  70. volatile unsigned long long guard1;
  71. volatile jack_nframes_t frames;
  72. volatile cycles_t stamp;
  73. volatile unsigned long long guard2;
  74. } jack_frame_timer_t;
  75. typedef struct {
  76. jack_time_info_t current_time;
  77. jack_time_info_t pending_time;
  78. jack_frame_timer_t frame_timer;
  79. int in_process;
  80. jack_nframes_t frames_at_cycle_start;
  81. pid_t engine_pid;
  82. unsigned long buffer_size;
  83. char real_time;
  84. int client_priority;
  85. int has_capabilities;
  86. float cpu_load;
  87. unsigned long port_max;
  88. int engine_ok;
  89. jack_port_shared_t ports[0];
  90. } jack_control_t;
  91. typedef enum {
  92. BufferSizeChange,
  93. SampleRateChange,
  94. NewPortBufferSegment,
  95. PortConnected,
  96. PortDisconnected,
  97. GraphReordered,
  98. PortRegistered,
  99. PortUnregistered,
  100. XRun,
  101. } EventType;
  102. typedef struct {
  103. EventType type;
  104. union {
  105. unsigned long n;
  106. jack_port_id_t port_id;
  107. jack_port_id_t self_id;
  108. } x;
  109. union {
  110. unsigned long n;
  111. jack_port_id_t other_id;
  112. } y;
  113. } jack_event_t;
  114. typedef enum {
  115. ClientDynamic, /* connect request just names .so */
  116. ClientDriver, /* code is loaded along with driver */
  117. ClientOutOfProcess /* 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 int 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 finished_at;
  137. /* callbacks */
  138. JackProcessCallback process;
  139. void *process_arg;
  140. JackBufferSizeCallback bufsize;
  141. void *bufsize_arg;
  142. JackSampleRateCallback srate;
  143. void *srate_arg;
  144. JackPortRegistrationCallback port_register;
  145. void *port_register_arg;
  146. JackGraphOrderCallback graph_order;
  147. void *graph_order_arg;
  148. JackXRunCallback xrun;
  149. void *xrun_arg;
  150. /* for engine use only */
  151. void *private_internal_client;
  152. } jack_client_control_t;
  153. typedef struct {
  154. ClientType type;
  155. char name[JACK_CLIENT_NAME_SIZE+1];
  156. char object_path[PATH_MAX+1];
  157. } jack_client_connect_request_t;
  158. typedef struct {
  159. int status;
  160. int client_key;
  161. int control_key;
  162. char fifo_prefix[PATH_MAX+1];
  163. int realtime;
  164. int realtime_priority;
  165. /* these two are valid only if the connect request
  166. was for type == ClientDriver.
  167. */
  168. jack_client_control_t *client_control;
  169. jack_control_t *engine_control;
  170. /* XXX need to be able to use more than one port segment key */
  171. key_t port_segment_key;
  172. } jack_client_connect_result_t;
  173. typedef struct {
  174. jack_client_id_t client_id;
  175. } jack_client_connect_ack_request_t;
  176. typedef struct {
  177. char status;
  178. } jack_client_connect_ack_result_t;
  179. typedef enum {
  180. RegisterPort = 1,
  181. UnRegisterPort = 2,
  182. ConnectPorts = 3,
  183. DisconnectPorts = 4,
  184. SetTimeBaseClient = 5,
  185. ActivateClient = 6,
  186. DeactivateClient = 7,
  187. DisconnectPort = 8,
  188. SetClientCapabilities = 9
  189. } RequestType;
  190. typedef struct {
  191. RequestType type;
  192. union {
  193. struct {
  194. char name[JACK_PORT_NAME_SIZE+1];
  195. char type[JACK_PORT_TYPE_SIZE+1];
  196. unsigned long flags;
  197. unsigned long buffer_size;
  198. jack_port_id_t port_id;
  199. jack_client_id_t client_id;
  200. } port_info;
  201. struct {
  202. char source_port[JACK_PORT_NAME_SIZE+1];
  203. char destination_port[JACK_PORT_NAME_SIZE+1];
  204. } connect;
  205. jack_client_id_t client_id;
  206. jack_nframes_t nframes;
  207. } x;
  208. int status;
  209. } jack_request_t;
  210. extern void jack_cleanup_shm ();
  211. extern void jack_cleanup_files ();
  212. extern int jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event);
  213. jack_client_t *jack_driver_become_client (const char *client_name);
  214. extern char *jack_temp_dir;
  215. extern int jack_get_mhz (void);
  216. #endif /* __jack_internal_h__ */