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.

275 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 time;
  77. jack_frame_timer_t frame_timer;
  78. int in_process;
  79. jack_nframes_t frames_at_cycle_start;
  80. pid_t engine_pid;
  81. unsigned long buffer_size;
  82. char real_time;
  83. int client_priority;
  84. int has_capabilities;
  85. float cpu_load;
  86. unsigned long port_max;
  87. jack_port_shared_t ports[0];
  88. int engine_ok;
  89. } jack_control_t;
  90. typedef enum {
  91. BufferSizeChange,
  92. SampleRateChange,
  93. NewPortBufferSegment,
  94. PortConnected,
  95. PortDisconnected,
  96. GraphReordered,
  97. PortRegistered,
  98. PortUnregistered,
  99. XRun,
  100. } EventType;
  101. typedef struct {
  102. EventType type;
  103. union {
  104. unsigned long n;
  105. jack_port_id_t port_id;
  106. jack_port_id_t self_id;
  107. } x;
  108. union {
  109. unsigned long n;
  110. jack_port_id_t other_id;
  111. } y;
  112. } jack_event_t;
  113. typedef enum {
  114. ClientDynamic, /* connect request just names .so */
  115. ClientDriver, /* code is loaded along with driver */
  116. ClientOutOfProcess /* client is in another process */
  117. } ClientType;
  118. typedef enum {
  119. NotTriggered,
  120. Triggered,
  121. Running,
  122. Finished
  123. } jack_client_state_t;
  124. typedef volatile struct {
  125. volatile int id; /* w: engine r: engine and client */
  126. volatile jack_nframes_t nframes; /* w: engine r: client */
  127. volatile jack_client_state_t state; /* w: engine and client r: engine */
  128. volatile char name[JACK_CLIENT_NAME_SIZE+1];
  129. volatile ClientType type; /* w: engine r: engine and client */
  130. volatile char active : 1; /* w: engine r: engine and client */
  131. volatile char dead : 1; /* r/w: engine */
  132. volatile char timed_out : 1; /* r/w: engine */
  133. volatile pid_t pid; /* w: client r: engine; pid of client */
  134. volatile unsigned long long signalled_at;
  135. volatile unsigned long long finished_at;
  136. /* callbacks */
  137. JackProcessCallback process;
  138. void *process_arg;
  139. JackBufferSizeCallback bufsize;
  140. void *bufsize_arg;
  141. JackSampleRateCallback srate;
  142. void *srate_arg;
  143. JackPortRegistrationCallback port_register;
  144. void *port_register_arg;
  145. JackGraphOrderCallback graph_order;
  146. void *graph_order_arg;
  147. JackXRunCallback xrun;
  148. void *xrun_arg;
  149. /* for engine use only */
  150. void *private_internal_client;
  151. } jack_client_control_t;
  152. typedef struct {
  153. ClientType type;
  154. char name[JACK_CLIENT_NAME_SIZE+1];
  155. char object_path[PATH_MAX+1];
  156. } jack_client_connect_request_t;
  157. typedef struct {
  158. int status;
  159. int client_key;
  160. int control_key;
  161. char fifo_prefix[PATH_MAX+1];
  162. int realtime;
  163. int realtime_priority;
  164. /* these two are valid only if the connect request
  165. was for type == ClientDriver.
  166. */
  167. jack_client_control_t *client_control;
  168. jack_control_t *engine_control;
  169. /* XXX need to be able to use more than one port segment key */
  170. key_t port_segment_key;
  171. } jack_client_connect_result_t;
  172. typedef struct {
  173. jack_client_id_t client_id;
  174. } jack_client_connect_ack_request_t;
  175. typedef struct {
  176. char status;
  177. } jack_client_connect_ack_result_t;
  178. typedef enum {
  179. RegisterPort = 1,
  180. UnRegisterPort = 2,
  181. ConnectPorts = 3,
  182. DisconnectPorts = 4,
  183. SetTimeBaseClient = 5,
  184. ActivateClient = 6,
  185. DeactivateClient = 7,
  186. DisconnectPort = 8,
  187. SetClientCapabilities = 9
  188. } RequestType;
  189. typedef struct {
  190. RequestType type;
  191. union {
  192. struct {
  193. char name[JACK_PORT_NAME_SIZE+1];
  194. char type[JACK_PORT_TYPE_SIZE+1];
  195. unsigned long flags;
  196. unsigned long buffer_size;
  197. jack_port_id_t port_id;
  198. jack_client_id_t client_id;
  199. } port_info;
  200. struct {
  201. char source_port[JACK_PORT_NAME_SIZE+1];
  202. char destination_port[JACK_PORT_NAME_SIZE+1];
  203. } connect;
  204. jack_client_id_t client_id;
  205. jack_nframes_t nframes;
  206. } x;
  207. int status;
  208. } jack_request_t;
  209. extern void jack_cleanup_shm ();
  210. extern void jack_cleanup_files ();
  211. extern int jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event);
  212. jack_client_t *jack_driver_become_client (const char *client_name);
  213. extern char *jack_temp_dir;
  214. extern int jack_get_mhz (void);
  215. #endif /* __jack_internal_h__ */