1
/* -*- mode: c; c-file-style: "bsd"; -*- */
3
Internal shared data and functions.
5
If you edit this file, you should carefully consider changing the
6
JACK_PROTOCOL_VERSION in configure.in.
8
Copyright (C) 2001-2003 Paul Davis
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.
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.
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.
26
#ifndef __jack_internal_h__
27
#define __jack_internal_h__
34
#include <sys/types.h>
37
#ifndef POST_PACKED_STRUCTURE
39
/* POST_PACKED_STRUCTURE needs to be a macro which
40
expands into a compiler directive. The directive must
41
tell the compiler to arrange the preceding structure
42
declaration so that it is packed on byte-boundaries rather
43
than use the natural alignment of the processor and/or
46
#define POST_PACKED_STRUCTURE __attribute__((__packed__))
48
/* Add other things here for non-gcc platforms */
52
/* Needed by <sysdeps/time.h> */
53
extern void jack_error (const char *fmt, ...);
55
extern void jack_info (const char *fmt, ...);
57
#include <jack/jack.h>
58
#include <jack/types.h>
59
#include <jack/port.h>
60
#include <jack/transport.h>
63
JACK_TIMER_SYSTEM_CLOCK,
64
JACK_TIMER_CYCLE_COUNTER,
68
void jack_init_time ();
69
void jack_set_clock_source (jack_timer_type_t);
70
const char* jack_clock_source_name (jack_timer_type_t);
72
#include <sysdeps/time.h>
73
#include <sysdeps/atomicity.h>
75
#ifdef JACK_USE_MACH_THREADS
76
#include <sysdeps/mach_port.h>
79
#include <jack/messagebuffer.h>
83
/* grab thread id instead of PID on linux */
84
#if defined(__gnu_linux__)
85
#ifdef gettid /* glibc has a version */
86
#define GETTID() gettid()
87
#else /* use our own version */
88
#include <sys/syscall.h>
89
#define GETTID() syscall(__NR_gettid)
92
#define GETTID() getpid()
95
#define DEBUG(format,args...) \
96
MESSAGE("jack:%5d:%" PRIu64 " %s:%s:%d: " format "", GETTID(), jack_get_microseconds(), __FILE__, __FUNCTION__, __LINE__ , ## args)
99
#if JACK_CPP_VARARGS_BROKEN
100
#define DEBUG(format...)
102
#define DEBUG(format,args...)
106
/* Enable preemption checking for Linux Realtime Preemption kernels.
108
* This checks if any RT-safe code section does anything to cause CPU
109
* preemption. Examples are sleep() or other system calls that block.
110
* If a problem is detected, the kernel writes a syslog entry, and
111
* sends SIGUSR2 to the client.
113
#ifdef DO_PREEMPTION_CHECKING
114
#define CHECK_PREEMPTION(engine, onoff) \
115
if ((engine)->real_time) gettimeofday (1, (onoff))
117
#define CHECK_PREEMPTION(engine, onoff)
128
typedef struct _jack_engine jack_engine_t;
129
typedef struct _jack_request jack_request_t;
131
typedef void * dlhandle;
134
TransportCommandNone = 0,
135
TransportCommandStart = 1,
136
TransportCommandStop = 2,
137
} transport_command_t;
141
volatile uint32_t guard1;
142
volatile jack_nframes_t frames;
143
volatile jack_time_t current_wakeup;
144
volatile jack_time_t next_wakeup;
145
volatile float second_order_integrator;
146
volatile int32_t initialized;
147
volatile uint32_t guard2;
149
/* not accessed by clients */
151
int32_t reset_pending; /* xrun happened, deal with it */
152
float filter_coefficient; /* set once, never altered */
154
} POST_PACKED_STRUCTURE jack_frame_timer_t;
156
/* JACK engine shared memory data structure. */
159
jack_transport_state_t transport_state;
160
volatile transport_command_t transport_cmd;
161
transport_command_t previous_cmd; /* previous transport_cmd */
162
jack_position_t current_time; /* position for current cycle */
163
jack_position_t pending_time; /* position for next cycle */
164
jack_position_t request_time; /* latest requested position */
165
jack_unique_t prev_request; /* previous request unique ID */
166
volatile _Atomic_word seq_number; /* unique ID sequence number */
167
int8_t new_pos; /* new position this cycle */
168
int8_t pending_pos; /* new position request pending */
169
jack_nframes_t pending_frame; /* pending frame number */
170
int32_t sync_clients; /* number of active_slowsync clients */
171
int32_t sync_remain; /* number of them with sync_poll */
172
jack_time_t sync_timeout;
173
jack_time_t sync_time_left;
174
jack_frame_timer_t frame_timer;
176
jack_timer_type_t clock_source;
178
jack_nframes_t buffer_size;
182
int32_t client_priority;
183
int32_t max_client_priority;
184
int32_t has_capabilities;
186
float xrun_delayed_usecs;
187
float max_delayed_usecs;
190
jack_port_type_id_t n_port_types;
191
jack_port_type_info_t port_types[JACK_MAX_PORT_TYPES];
192
jack_port_shared_t ports[0];
194
} POST_PACKED_STRUCTURE jack_control_t;
216
char name[JACK_CLIENT_NAME_SIZE];
217
jack_port_id_t port_id;
218
jack_port_id_t self_id;
222
jack_port_type_id_t ptid;
223
jack_port_id_t other_id;
225
} POST_PACKED_STRUCTURE jack_event_t;
228
ClientInternal, /* connect request just names .so */
229
ClientDriver, /* code is loaded along with driver */
230
ClientExternal /* client is in another process */
238
} jack_client_state_t;
240
/* JACK client shared memory data structure. */
241
typedef volatile struct {
243
volatile jack_client_id_t id; /* w: engine r: engine and client */
244
volatile jack_nframes_t nframes; /* w: engine r: client */
245
volatile jack_client_state_t state; /* w: engine and client r: engine */
246
volatile char name[JACK_CLIENT_NAME_SIZE];
247
volatile ClientType type; /* w: engine r: engine and client */
248
volatile int8_t active; /* w: engine r: engine and client */
249
volatile int8_t dead; /* r/w: engine */
250
volatile int8_t timed_out; /* r/w: engine */
251
volatile int8_t is_timebase; /* w: engine, r: engine and client */
252
volatile int8_t timebase_new; /* w: engine and client, r: engine */
253
volatile int8_t is_slowsync; /* w: engine, r: engine and client */
254
volatile int8_t active_slowsync; /* w: engine, r: engine and client */
255
volatile int8_t sync_poll; /* w: engine and client, r: engine */
256
volatile int8_t sync_new; /* w: engine and client, r: engine */
257
volatile pid_t pid; /* w: client r: engine; client pid */
258
volatile pid_t pgrp; /* w: client r: engine; client pgrp */
259
volatile uint64_t signalled_at;
260
volatile uint64_t awake_at;
261
volatile uint64_t finished_at;
262
volatile int32_t last_status; /* w: client, r: engine and client */
264
/* indicators for whether callbacks have been set for this client.
265
We do not include ptrs to the callbacks here (or their arguments)
266
so that we can avoid 32/64 bit pointer size mismatches between
267
the jack server and a client. The pointers are in the client-
268
local structure which is part of the libjack compiled for
269
either 32 bit or 64 bit clients.
271
volatile uint8_t process_cbset;
272
volatile uint8_t thread_init_cbset;
273
volatile uint8_t bufsize_cbset;
274
volatile uint8_t srate_cbset;
275
volatile uint8_t port_register_cbset;
276
volatile uint8_t port_connect_cbset;
277
volatile uint8_t graph_order_cbset;
278
volatile uint8_t xrun_cbset;
279
volatile uint8_t sync_cb_cbset;
280
volatile uint8_t timebase_cb_cbset;
281
volatile uint8_t freewheel_cb_cbset;
282
volatile uint8_t client_register_cbset;
283
volatile uint8_t thread_cb_cbset;
285
} POST_PACKED_STRUCTURE jack_client_control_t;
289
uint32_t protocol_v; /* protocol version, must go first */
292
jack_options_t options;
294
char name[JACK_CLIENT_NAME_SIZE];
295
char object_path[PATH_MAX+1];
296
char object_data[1024];
298
} POST_PACKED_STRUCTURE jack_client_connect_request_t;
302
jack_status_t status;
304
jack_shm_registry_index_t client_shm_index;
305
jack_shm_registry_index_t engine_shm_index;
307
char fifo_prefix[PATH_MAX+1];
310
int32_t realtime_priority;
312
char name[JACK_CLIENT_NAME_SIZE]; /* unique name, if assigned */
314
/* these two are valid only for internal clients, and thus
315
are exempt from the requirement that we not export
316
pointers back to clients. an internal client must
317
necessarily match the host, so 32/64 bit issues
318
do not apply to these pointers.
320
jack_client_control_t* client_control;
321
jack_control_t* engine_control;
323
#ifdef JACK_USE_MACH_THREADS
324
/* specific resources for server/client real-time thread communication */
328
} POST_PACKED_STRUCTURE jack_client_connect_result_t;
331
jack_client_id_t client_id;
332
} POST_PACKED_STRUCTURE jack_client_connect_ack_request_t;
336
} POST_PACKED_STRUCTURE jack_client_connect_ack_result_t;
343
SetTimeBaseClient = 5,
345
DeactivateClient = 7,
347
SetClientCapabilities = 9,
348
GetPortConnections = 10,
349
GetPortNConnections = 11,
350
ResetTimeBaseClient = 12,
352
ResetSyncClient = 14,
357
IntClientHandle = 19,
360
IntClientUnload = 22,
361
RecomputeTotalLatencies = 23,
362
RecomputeTotalLatency = 24
365
struct _jack_request {
371
char name[JACK_PORT_NAME_SIZE];
372
char type[JACK_PORT_TYPE_SIZE];
374
jack_shmsize_t buffer_size;
375
jack_port_id_t port_id;
376
jack_client_id_t client_id;
377
} POST_PACKED_STRUCTURE port_info;
379
char source_port[JACK_PORT_NAME_SIZE];
380
char destination_port[JACK_PORT_NAME_SIZE];
381
} POST_PACKED_STRUCTURE connect;
384
const char **ports; /* this is only exposed to internal clients, so there
385
is no 64/32 issue. external clients read the ports
386
one by one from the server, and allocate their
387
own "ports" array in their own address space.
389
} POST_PACKED_STRUCTURE port_connections;
391
jack_client_id_t client_id;
393
} POST_PACKED_STRUCTURE timebase;
395
//jack_options_t options;
398
char name[JACK_CLIENT_NAME_SIZE];
399
char path[PATH_MAX+1];
400
char init[JACK_LOAD_INIT_LIMIT];
401
} POST_PACKED_STRUCTURE intclient;
402
jack_client_id_t client_id;
403
jack_nframes_t nframes;
406
} POST_PACKED_STRUCTURE x;
408
} POST_PACKED_STRUCTURE;
410
/* Per-client structure allocated in the server's address space.
411
* It's here because its not part of the engine structure.
414
typedef struct _jack_client_internal {
416
jack_client_control_t *control;
420
int subgraph_start_fd;
421
int subgraph_wait_fd;
422
JSList *ports; /* protected by engine->client_lock */
423
JSList *truefeeds; /* protected by engine->client_lock */
424
JSList *sortfeeds; /* protected by engine->client_lock */
427
jack_shm_info_t control_shm;
428
unsigned long execution_order;
429
struct _jack_client_internal *next_client; /* not a linked list! */
431
int (*initialize)(jack_client_t*, const char*); /* int. clients only */
432
void (*finish)(void *); /* internal clients only */
435
#ifdef JACK_USE_MACH_THREADS
436
/* specific resources for server/client real-time thread communication */
437
mach_port_t serverport;
438
trivial_message message;
441
#endif /* JACK_USE_MACH_THREADS */
446
JackProcessCallback process;
448
JackThreadInitCallback thread_init;
449
void *thread_init_arg;
450
JackBufferSizeCallback bufsize;
452
JackSampleRateCallback srate;
454
JackPortRegistrationCallback port_register;
455
void *port_register_arg;
456
JackPortConnectCallback port_connect;
457
void *port_connect_arg;
458
JackGraphOrderCallback graph_order;
459
void *graph_order_arg;
460
JackXRunCallback xrun;
462
JackSyncCallback sync_cb;
464
JackTimebaseCallback timebase_cb;
466
JackFreewheelCallback freewheel_cb;
468
JackClientRegistrationCallback client_register;
469
void *client_register_arg;
470
JackThreadCallback thread_cb;
473
/* external clients: set by libjack
474
* internal clients: set by engine */
475
//int (*deliver_request)(void*, jack_request_t*); /* JOQ: 64/32 bug! */
477
jack_client_t *private_client;
478
} jack_client_internal_t;
480
typedef struct _jack_thread_arg {
481
jack_client_t* client;
482
void* (*work_function)(void*);
489
extern int jack_client_handle_port_connection (jack_client_t *client,
490
jack_event_t *event);
491
extern jack_client_t *jack_driver_client_new (jack_engine_t *,
492
const char *client_name);
493
extern jack_client_t *jack_client_alloc_internal (jack_client_control_t*,
496
/* internal clients call this. it's defined in jack/engine.c */
497
void handle_internal_client_request (jack_control_t*, jack_request_t*);
499
extern char *jack_tmpdir;
501
extern char *jack_user_dir (void);
503
extern char *jack_server_dir (const char *server_name, char *server_dir);
505
extern void *jack_zero_filled_buffer;
507
extern jack_port_functions_t jack_builtin_audio_functions;
509
extern jack_port_type_info_t jack_builtin_port_types[];
511
extern void jack_client_invalidate_port_buffers (jack_client_t *client);
513
extern void jack_transport_copy_position (jack_position_t *from,
514
jack_position_t *to);
515
extern void jack_call_sync_client (jack_client_t *client);
517
extern void jack_call_timebase_master (jack_client_t *client);
519
extern char *jack_default_server_name (void);
521
void silent_jack_error_callback (const char *desc);
523
/* needed for port management */
524
jack_port_t *jack_port_by_id_int (const jack_client_t *client,
525
jack_port_id_t id, int* free);
527
jack_port_t *jack_port_by_name_int (jack_client_t *client,
528
const char *port_name);
529
int jack_port_name_equals (jack_port_shared_t* port, const char* target);
532
# define likely(x) __builtin_expect((x),1)
533
# define unlikely(x) __builtin_expect((x),0)
535
# define likely(x) (x)
536
# define unlikely(x) (x)
539
#endif /* __jack_internal_h__ */