** Warning: Cannot open xref database.
1 /* -*- mode: c; c-file-style: "bsd"; -*- */
2 /*
3 Copyright (C) 2001-2003 Paul Davis
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 $Id: engine.h,v 1.36 2003/11/02 04:18:06 joq Exp $
20 */
21
22 #ifndef __jack_engine_h__
23 #define __jack_engine_h__
24
25 #include <jack/jack.h>
26 #include <jack/internal.h>
27 #include <jack/driver_interface.h>
28
29 #define VERBOSE(engine,format,args...) \
30 if ((engine)->verbose) fprintf (stderr, format, ## args)
31
32 struct _jack_driver;
33 struct _jack_client_internal;
34 struct _jack_port_internal;
35
36 /* Structures is allocated by the engine in local memory to keep track
37 * of port buffers and connections.
38 */
39 typedef struct {
40 jack_shm_info_t* shm_info;
41 jack_shmsize_t offset;
42 } jack_port_buffer_info_t;
43
44 /* The engine keeps an array of these in its local memory. */
45 typedef struct _jack_port_internal {
46 struct _jack_port_shared *shared;
47 JSList *connections;
48 jack_port_buffer_info_t *buffer_info;
49 } jack_port_internal_t;
50
51 /* The engine's internal port type structure. */
52 typedef struct _jack_port_buffer_list {
53 pthread_mutex_t lock; /* only lock within server */
54 JSList *freelist; /* list of free buffers */
55 jack_port_buffer_info_t *info; /* jack_buffer_info_t array */
56 } jack_port_buffer_list_t;
57
58 /* The main engine structure in local memory. */
59 struct _jack_engine {
60 jack_control_t *control;
61
62 JSList *drivers;
63 struct _jack_driver *driver;
64 jack_driver_desc_t *driver_desc;
65 JSList *driver_params;
66
67 /* these are "callbacks" made by the driver */
68 int (*set_buffer_size) (struct _jack_engine *, jack_nframes_t frames);
69 int (*set_sample_rate) (struct _jack_engine *, jack_nframes_t frames);
70 int (*run_cycle) (struct _jack_engine *, jack_nframes_t nframes,
71 float delayed_usecs);
72 void (*delay) (struct _jack_engine *);
73 void (*transport_cycle_start) (struct _jack_engine *, jack_time_t time);
74 void (*driver_exit) (struct _jack_engine *);
75
76 /* "private" sections starts here */
77
78 /* engine serialization -- use precedence for deadlock avoidance */
79 pthread_mutex_t request_lock; /* precedes client_lock */
80 pthread_mutex_t client_lock;
81 pthread_mutex_t port_lock;
82 int process_errors;
83 int period_msecs;
84
85 /* Time to wait for clients in msecs. Used when jackd is run
86 * without realtime priority enabled. */
87 int client_timeout_msecs;
88
89 /* info on the shm segment containing this->control */
90
91 jack_shm_info_t control_shm;
92
93 /* address-space local port buffer and segment info,
94 indexed by the port type_id
95 */
96 jack_port_buffer_list_t port_buffers[JACK_MAX_PORT_TYPES];
97 jack_shm_info_t port_segment[JACK_MAX_PORT_TYPES];
98
99 unsigned int port_max;
100 pthread_t server_thread;
101 pthread_t watchdog_thread;
102
103 int fds[2];
104 jack_client_id_t next_client_id;
105 size_t pfd_size;
106 size_t pfd_max;
107 struct pollfd *pfd;
108 char fifo_prefix[PATH_MAX+1];
109 int *fifo;
110 unsigned long fifo_size;
111 unsigned long external_client_cnt;
112 int rtpriority;
113 char freewheeling;
114 char verbose;
115 int reordered;
116 int watchdog_check;
117 pid_t wait_pid;
118 pthread_t freewheel_thread;
119
120 /* these lists are protected by `client_lock' */
121 JSList *clients;
122 JSList *clients_waiting;
123
124 jack_port_internal_t *internal_ports;
125 jack_client_internal_t *timebase_client;
126 jack_port_buffer_info_t *silent_buffer;
127 jack_client_internal_t *current_client;
128
129 #define JACK_ENGINE_ROLLING_COUNT 32
130 #define JACK_ENGINE_ROLLING_INTERVAL 1024
131
132 jack_time_t rolling_client_usecs[JACK_ENGINE_ROLLING_COUNT];
133 int rolling_client_usecs_cnt;
134 int rolling_client_usecs_index;
135 int rolling_interval;
136 float spare_usecs;
137 float usecs_per_cycle;
138
139 #if defined(__APPLE__) && defined(__POWERPC__)
140 /* specific resources for server/client real-time thread communication */
141 mach_port_t servertask, bp;
142 int portnum;
143 #endif
144
145 };
146
147 /* public functions */
148
149 jack_engine_t *jack_engine_new (int real_time, int real_time_priority,
150 int verbose, int client_timeout,
151 pid_t waitpid, JSList * drivers);
152 int jack_engine_delete (jack_engine_t *);
153 int jack_run (jack_engine_t *engine);
154 int jack_wait (jack_engine_t *engine);
155 int jack_engine_load_driver (jack_engine_t *engine,
156 jack_driver_desc_t * driver_desc,
157 JSList * driver_params);
158 void jack_dump_configuration(jack_engine_t *engine, int take_lock);
159
160 extern jack_client_internal_t *
161 jack_client_internal_by_id (jack_engine_t *engine, jack_client_id_t id);
162
163 static inline void jack_lock_graph (jack_engine_t* engine) {
164 DEBUG ("acquiring graph lock");
165 pthread_mutex_lock (&engine->client_lock);
166 }
167
168 static inline int jack_try_lock_graph (jack_engine_t *engine)
169 {
170 DEBUG ("TRYING to acquiring graph lock");
171 return pthread_mutex_trylock (&engine->client_lock);
172 }
173
174 static inline void jack_unlock_graph (jack_engine_t* engine)
175 {
176 DEBUG ("releasing graph lock");
177 pthread_mutex_unlock (&engine->client_lock);
178 }
179
180 static inline unsigned int jack_power_of_two (unsigned int n)
181 {
182 return !(n & (n - 1));
183 }
184
185 #endif /* __jack_engine_h__ */
186
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.