** Warning: Cannot open xref database.
1 /* -*- mode: c; c-file-style: "bsd"; -*- */
2 /*
3 Internal shared data and functions.
4
5 If you edit this file, you should carefully consider changing the
6 JACK_PROTOCOL_VERSION in configure.in.
7
8 Copyright (C) 2001-2003 Paul Davis
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 $Id: internal.h,v 1.59 2003/12/16 06:08:38 joq Exp $
25 */
26
27 #ifndef __jack_internal_h__
28 #define __jack_internal_h__
29
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <limits.h>
33 #include <dlfcn.h>
34 #include <sys/types.h>
35 #include <sys/time.h>
36 #include <pthread.h>
37
38 #if defined(__APPLE__) && defined(__POWERPC__)
39 #include "mach_port.h"
40 #endif
41
42 #include <jack/jack.h>
43 #include <jack/types.h>
44 #include <jack/port.h>
45 #include <jack/transport.h>
46 #include <jack/time.h>
47
48 #ifdef DEBUG_ENABLED
49 #define DEBUG(format,args...) \
50 fprintf (stderr, "jack:%5d:%" PRIu64 " %s:%s:%d: " format "\n", getpid(), jack_get_microseconds(), __FILE__, __FUNCTION__, __LINE__ , ## args)
51 #else
52 #if defined(__APPLE__) && defined(__POWERPC__)
53 #define DEBUG(format...)
54 #else
55 #define DEBUG(format,args...)
56 #endif
57 #endif
58
59 #ifndef FALSE
60 #define FALSE (0)
61 #endif
62
63 #ifndef TRUE
64 #define TRUE (1)
65 #endif
66
67 typedef struct _jack_engine jack_engine_t;
68 typedef struct _jack_request jack_request_t;
69
70 typedef void * dlhandle;
71
72 typedef enum {
73 TransportCommandNone = 0,
74 TransportCommandStart = 1,
75 TransportCommandStop = 2,
76 } transport_command_t;
77
78 typedef struct {
79 volatile jack_time_t guard1;
80 volatile jack_nframes_t frames;
81 volatile jack_time_t stamp;
82 volatile jack_time_t guard2;
83 } jack_frame_timer_t;
84
85 /* JACK engine shared memory data structure. */
86 typedef struct {
87
88 jack_transport_state_t transport_state;
89 volatile transport_command_t transport_cmd;
90 transport_command_t previous_cmd; /* previous transport_cmd */
91 jack_position_t current_time; /* position for current cycle */
92 jack_position_t pending_time; /* position for next cycle */
93 jack_position_t request_time; /* latest requested position */
94 jack_unique_t prev_request; /* previous request unique ID */
95 volatile uint32_t seq_number; /* unique ID sequence number */
96 int8_t new_pos; /* new position this cycle */
97 int8_t pending_pos; /* new position request pending */
98 jack_nframes_t pending_frame; /* pending frame number */
99 int32_t sync_clients; /* number of active_slowsync clients */
100 int32_t sync_remain; /* number of them with sync_poll */
101 jack_time_t sync_timeout;
102 jack_time_t sync_time_left;
103 jack_frame_timer_t frame_timer;
104 int32_t internal;
105 jack_nframes_t frames_at_cycle_start;
106 pid_t engine_pid;
107 jack_nframes_t buffer_size;
108 int8_t real_time;
109 int32_t client_priority;
110 int32_t has_capabilities;
111 float cpu_load;
112 uint32_t port_max;
113 int32_t engine_ok;
114 uint32_t n_port_types;
115 jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
116 jack_port_shared_t ports[0];
117
118 } jack_control_t;
119
120 typedef enum {
121 BufferSizeChange,
122 SampleRateChange,
123 AttachPortSegment,
124 PortConnected,
125 PortDisconnected,
126 GraphReordered,
127 PortRegistered,
128 PortUnregistered,
129 XRun,
130 StartFreewheel,
131 StopFreewheel
132 } EventType;
133
134 typedef struct {
135 EventType type;
136 union {
137 uint32_t n;
138 jack_port_id_t port_id;
139 jack_port_id_t self_id;
140 } x;
141 union {
142 uint32_t n;
143 jack_port_type_id_t ptid;
144 jack_port_id_t other_id;
145 } y;
146 } jack_event_t;
147
148 typedef enum {
149 ClientInternal, /* connect request just names .so */
150 ClientDriver, /* code is loaded along with driver */
151 ClientExternal /* client is in another process */
152 } ClientType;
153
154 typedef enum {
155 NotTriggered,
156 Triggered,
157 Running,
158 Finished
159 } jack_client_state_t;
160
161 /* JACK client shared memory data structure. */
162 typedef volatile struct {
163
164 volatile jack_client_id_t id; /* w: engine r: engine and client */
165 volatile jack_nframes_t nframes; /* w: engine r: client */
166 volatile jack_client_state_t state; /* w: engine and client r: engine */
167 volatile int8_t name[JACK_CLIENT_NAME_SIZE+1];
168 volatile ClientType type; /* w: engine r: engine and client */
169 volatile int8_t active; /* w: engine r: engine and client */
170 volatile int8_t dead; /* r/w: engine */
171 volatile int8_t timed_out; /* r/w: engine */
172 volatile int8_t is_timebase; /* w: engine, r: engine and client */
173 volatile int8_t timebase_new; /* w: engine and client, r: engine */
174 volatile int8_t is_slowsync; /* w: engine, r: engine and client */
175 volatile int8_t active_slowsync; /* w: engine, r: engine and client */
176 volatile int8_t sync_poll; /* w: engine and client, r: engine */
177 volatile int8_t sync_new; /* w: engine and client, r: engine */
178 volatile pid_t pid; /* w: client r: engine; client pid */
179 volatile pid_t pgrp; /* w: client r: engine; client pgrp */
180 volatile uint64_t signalled_at;
181 volatile uint64_t awake_at;
182 volatile uint64_t finished_at;
183
184 /* JOQ: all these pointers are trouble for 32/64 compatibility,
185 * they should move to non-shared memory.
186 */
187
188 /* callbacks
189 */
190 JackProcessCallback process;
191 void *process_arg;
192 JackBufferSizeCallback bufsize;
193 void *bufsize_arg;
194 JackSampleRateCallback srate;
195 void *srate_arg;
196 JackPortRegistrationCallback port_register;
197 void *port_register_arg;
198 JackGraphOrderCallback graph_order;
199 void *graph_order_arg;
200 JackXRunCallback xrun;
201 void *xrun_arg;
202 JackSyncCallback sync_cb;
203 void *sync_arg;
204 JackTimebaseCallback timebase_cb;
205 void *timebase_arg;
206 JackFreewheelCallback freewheel_cb;
207 void *freewheel_arg;
208
209 /* external clients: set by libjack
210 * internal clients: set by engine */
211 int (*deliver_request)(void*, jack_request_t*);
212 void *deliver_arg;
213
214 /* for engine use only */
215 void *private_client;
216
217 } jack_client_control_t;
218
219 typedef struct {
220
221 int32_t load;
222 ClientType type;
223
224 char name[JACK_CLIENT_NAME_SIZE+1];
225 char object_path[PATH_MAX+1];
226 char object_data[1024];
227
228 } jack_client_connect_request_t;
229
230 typedef struct {
231
232 int32_t status;
233
234 uint32_t protocol_v;
235
236 jack_shm_info_t client_shm;
237 jack_shm_info_t engine_shm;
238
239 char fifo_prefix[PATH_MAX+1];
240
241 int32_t realtime;
242 int32_t realtime_priority;
243
244 /* these two are valid only if the connect request
245 was for type == ClientDriver.
246 */
247
248 jack_client_control_t *client_control; /* JOQ: 64/32 problem */
249 jack_control_t *engine_control; /* JOQ: 64/32 problem */
250
251 #if defined(__APPLE__) && defined(__POWERPC__)
252 /* specific resources for server/client real-time thread communication */
253 int32_t portnum;
254 #endif
255
256 } jack_client_connect_result_t;
257
258 typedef struct {
259 jack_client_id_t client_id;
260 } jack_client_connect_ack_request_t;
261
262 typedef struct {
263 int8_t status;
264 } jack_client_connect_ack_result_t;
265
266 typedef enum {
267 RegisterPort = 1,
268 UnRegisterPort = 2,
269 ConnectPorts = 3,
270 DisconnectPorts = 4,
271 SetTimeBaseClient = 5,
272 ActivateClient = 6,
273 DeactivateClient = 7,
274 DisconnectPort = 8,
275 SetClientCapabilities = 9,
276 GetPortConnections = 10,
277 GetPortNConnections = 11,
278 ResetTimeBaseClient = 12,
279 SetSyncClient = 13,
280 ResetSyncClient = 14,
281 SetSyncTimeout = 15,
282 SetBufferSize = 16,
283 FreeWheel = 17,
284 StopFreeWheel = 18,
285 } RequestType;
286
287 struct _jack_request {
288
289 RequestType type;
290 union {
291 struct {
292 char name[JACK_PORT_NAME_SIZE+1];
293 char type[JACK_PORT_TYPE_SIZE+1];
294 uint32_t flags;
295 jack_shmsize_t buffer_size;
296 jack_port_id_t port_id;
297 jack_client_id_t client_id;
298 } port_info;
299 struct {
300 char source_port[JACK_PORT_NAME_SIZE+1];
301 char destination_port[JACK_PORT_NAME_SIZE+1];
302 } connect;
303 struct {
304 int32_t nports;
305 const char **ports; /* JOQ: 32/64 problem? */
306 } port_connections;
307 struct {
308 jack_client_id_t client_id;
309 int32_t conditional;
310 } timebase;
311 jack_client_id_t client_id;
312 jack_nframes_t nframes;
313 jack_time_t timeout;
314 } x;
315 int32_t status;
316 };
317
318 /* per-client structure allocated in the server's address space
319 * its here because its not part of the engine structure.
320 */
321
322 typedef struct _jack_client_internal {
323
324 jack_client_control_t *control;
325
326 int request_fd;
327 int event_fd;
328 int subgraph_start_fd;
329 int subgraph_wait_fd;
330 JSList *ports; /* protected by engine->client_lock */
331 JSList *fed_by; /* protected by engine->client_lock */
332 jack_shm_info_t control_shm;
333 unsigned long execution_order;
334 struct _jack_client_internal *next_client; /* not a linked list! */
335 dlhandle handle;
336 int (*initialize)(jack_client_t*, const char*); /* int. clients only */
337 void (*finish)(void *); /* internal clients only */
338 int error;
339
340 #if defined(__APPLE__) && defined(__POWERPC__)
341 /* specific resources for server/client real-time thread communication */
342 mach_port_t serverport;
343 trivial_message message;
344 int running;
345 int portnum;
346 #endif
347
348 } jack_client_internal_t;
349
350 extern void jack_cleanup_files ();
351
352 extern int jack_client_handle_port_connection (jack_client_t *client,
353 jack_event_t *event);
354 extern jack_client_t *jack_driver_client_new (jack_engine_t *,
355 const char *client_name);
356 extern jack_client_t *jack_client_alloc_internal (jack_client_control_t*,
357 jack_engine_t*);
358
359 /* internal clients call this. it's defined in jack/engine.c */
360 void handle_internal_client_request (jack_control_t*, jack_request_t*);
361
362 extern char *jack_server_dir;
363
364 extern void *jack_zero_filled_buffer;
365
366 extern void jack_error (const char *fmt, ...);
367
368 extern jack_port_functions_t jack_builtin_audio_functions;
369
370 extern jack_port_type_info_t jack_builtin_port_types[];
371
372 extern void jack_client_invalidate_port_buffers (jack_client_t *client);
373
374 extern void jack_transport_copy_position (jack_position_t *from,
375 jack_position_t *to);
376 extern void jack_call_sync_client (jack_client_t *client);
377
378 extern void jack_call_timebase_master (jack_client_t *client);
379
380 extern int jack_acquire_real_time_scheduling (pthread_t, int priority);
381 extern int jack_drop_real_time_scheduling (pthread_t);
382
383 void silent_jack_error_callback (const char *desc);
384
385 #endif /* __jack_internal_h__ */
386
387
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.