summaryrefslogtreecommitdiff
path: root/libjack
diff options
context:
space:
mode:
Diffstat (limited to 'libjack')
-rw-r--r--libjack/client.c1457
-rw-r--r--libjack/driver.c113
-rw-r--r--libjack/intclient.c110
-rw-r--r--libjack/local.h156
-rw-r--r--libjack/messagebuffer.c106
-rw-r--r--libjack/metadata.c1172
-rw-r--r--libjack/midiport.c220
-rw-r--r--libjack/pool.c16
-rw-r--r--libjack/port.c343
-rw-r--r--libjack/ringbuffer.c66
-rw-r--r--libjack/sanitycheck.c12
-rw-r--r--libjack/shm.c205
-rw-r--r--libjack/simd.c195
-rw-r--r--libjack/systemtest.c12
-rw-r--r--libjack/thread.c163
-rw-r--r--libjack/time.c28
-rw-r--r--libjack/transclient.c211
-rw-r--r--libjack/unlock.c30
-rw-r--r--libjack/uuid.c72
19 files changed, 2414 insertions, 2273 deletions
diff --git a/libjack/client.c b/libjack/client.c
index 32e97d8..34e8b09 100644
--- a/libjack/client.c
+++ b/libjack/client.c
@@ -2,22 +2,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2005 Jussi Laako
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <config.h>
@@ -67,10 +67,10 @@
#endif
static pthread_mutex_t client_lock;
-static pthread_cond_t client_ready;
+static pthread_cond_t client_ready;
static int
-jack_client_close_aux (jack_client_t *client);
+jack_client_close_aux(jack_client_t *client);
#define EVENT_POLL_INDEX 0
#define WAIT_POLL_INDEX 1
@@ -78,9 +78,9 @@ jack_client_close_aux (jack_client_t *client);
#define graph_wait_fd pollfd[WAIT_POLL_INDEX].fd
typedef struct {
- int status;
- struct _jack_client *client;
- const char *client_name;
+ int status;
+ struct _jack_client *client;
+ const char *client_name;
} client_info;
#ifdef USE_DYNSIMD
@@ -92,16 +92,19 @@ int cpu_type = 0;
static void
init_cpu ()
{
- cpu_type = ((have_3dnow() << 8) | have_sse());
+ cpu_type = ((have_3dnow () << 8) | have_sse ());
#if 0
- if (ARCH_X86_HAVE_3DNOW(cpu_type))
- jack_debug("Enhanced3DNow! detected");
- if (ARCH_X86_HAVE_SSE2(cpu_type))
- jack_debug("SSE2 detected");
- if ((!ARCH_X86_HAVE_3DNOW(cpu_type)) && (!ARCH_X86_HAVE_SSE2(cpu_type)))
- jack_debug("No supported SIMD instruction sets detected");
+ if (ARCH_X86_HAVE_3DNOW (cpu_type)) {
+ jack_debug ("Enhanced3DNow! detected");
+ }
+ if (ARCH_X86_HAVE_SSE2 (cpu_type)) {
+ jack_debug ("SSE2 detected");
+ }
+ if ((!ARCH_X86_HAVE_3DNOW (cpu_type)) && (!ARCH_X86_HAVE_SSE2 (cpu_type))) {
+ jack_debug ("No supported SIMD instruction sets detected");
+ }
#endif
- jack_port_set_funcs();
+ jack_port_set_funcs ();
}
#else /* ARCH_X86 */
@@ -109,12 +112,12 @@ init_cpu ()
static void
init_cpu ()
{
- jack_port_set_funcs();
+ jack_port_set_funcs ();
}
-#endif /* ARCH_X86 */
+#endif /* ARCH_X86 */
-#endif /* USE_DYNSIMD */
+#endif /* USE_DYNSIMD */
char *jack_tmpdir = DEFAULT_TMP_DIR;
@@ -123,7 +126,7 @@ jack_get_tmpdir ()
{
FILE* in;
size_t len;
- char buf[PATH_MAX+2]; /* allow tmpdir to live anywhere, plus newline, plus null */
+ char buf[PATH_MAX + 2]; /* allow tmpdir to live anywhere, plus newline, plus null */
char *pathenv;
char *pathcopy;
char *p;
@@ -132,7 +135,7 @@ jack_get_tmpdir ()
resetting PATH for the exec'd command. since we *want* to
use the user's PATH setting to locate jackd, we have to
do it ourselves.
- */
+ */
if ((pathenv = getenv ("PATH")) == 0) {
return -1;
@@ -146,14 +149,14 @@ jack_get_tmpdir ()
p = strtok (pathcopy, ":");
while (p) {
- char jackd[PATH_MAX+1];
- char command[PATH_MAX+4];
+ char jackd[PATH_MAX + 1];
+ char command[PATH_MAX + 4];
+
+ snprintf (jackd, sizeof(jackd), "%s/jackd", p);
- snprintf (jackd, sizeof (jackd), "%s/jackd", p);
-
if (access (jackd, X_OK) == 0) {
-
- snprintf (command, sizeof (command), "%s -l", jackd);
+
+ snprintf (command, sizeof(command), "%s -l", jackd);
if ((in = popen (command, "r")) != NULL) {
break;
@@ -169,7 +172,7 @@ jack_get_tmpdir ()
return -1;
}
- if (fgets (buf, sizeof (buf), in) == NULL) {
+ if (fgets (buf, sizeof(buf), in) == NULL) {
pclose (in);
free (pathcopy);
return -1;
@@ -177,28 +180,28 @@ jack_get_tmpdir ()
len = strlen (buf);
- if (buf[len-1] != '\n') {
+ if (buf[len - 1] != '\n') {
/* didn't get a whole line */
pclose (in);
free (pathcopy);
return -1;
}
- if ((jack_tmpdir = (char *) malloc (len)) == NULL) {
+ if ((jack_tmpdir = (char*)malloc (len)) == NULL) {
free (pathcopy);
return -1;
}
- memcpy (jack_tmpdir, buf, len-1);
- jack_tmpdir[len-1] = '\0';
-
+ memcpy (jack_tmpdir, buf, len - 1);
+ jack_tmpdir[len - 1] = '\0';
+
pclose (in);
free (pathcopy);
return 0;
}
-void
+void
jack_error (const char *fmt, ...)
{
va_list ap;
@@ -210,21 +213,21 @@ jack_error (const char *fmt, ...)
va_end (ap);
}
-void
+void
default_jack_error_callback (const char *desc)
{
- fprintf(stderr, "%s\n", desc);
- fflush(stderr);
+ fprintf (stderr, "%s\n", desc);
+ fflush (stderr);
}
-void
+void
default_jack_info_callback (const char *desc)
{
- fprintf(stdout, "%s\n", desc);
- fflush(stdout);
+ fprintf (stdout, "%s\n", desc);
+ fflush (stdout);
}
-void
+void
silent_jack_error_callback (const char *desc)
{
}
@@ -232,7 +235,7 @@ silent_jack_error_callback (const char *desc)
void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
void (*jack_info_callback)(const char *desc) = &default_jack_info_callback;
-void
+void
jack_info (const char *fmt, ...)
{
va_list ap;
@@ -248,45 +251,48 @@ static int
oop_client_deliver_request (void *ptr, jack_request_t *req)
{
int wok, rok;
- jack_client_t *client = (jack_client_t*) ptr;
-
- wok = (write (client->request_fd, req, sizeof (*req))
- == sizeof (*req));
-
- /* if necessary, add variable length key data after a PropertyChange request
- */
-
- if (req->type == PropertyChangeNotify) {
- if (req->x.property.keylen) {
- if (write (client->request_fd, req->x.property.key, req->x.property.keylen) != req->x.property.keylen) {
- jack_error ("cannot send property key of length %d to server",
- req->x.property.keylen);
- req->status = -1;
- return req->status;
- }
- }
- }
-
- rok = (read (client->request_fd, req, sizeof (*req))
- == sizeof (*req));
-
- if (wok && rok) { /* everything OK? */
+ jack_client_t *client = (jack_client_t*)ptr;
+
+ wok = (write (client->request_fd, req, sizeof(*req))
+ == sizeof(*req));
+
+ /* if necessary, add variable length key data after a PropertyChange request
+ */
+
+ if (req->type == PropertyChangeNotify) {
+ if (req->x.property.keylen) {
+ if (write (client->request_fd, req->x.property.key, req->x.property.keylen) != req->x.property.keylen) {
+ jack_error ("cannot send property key of length %d to server",
+ req->x.property.keylen);
+ req->status = -1;
+ return req->status;
+ }
+ }
+ }
+
+ rok = (read (client->request_fd, req, sizeof(*req))
+ == sizeof(*req));
+
+ if (wok && rok) { /* everything OK? */
return req->status;
}
- req->status = -1; /* request failed */
+ req->status = -1; /* request failed */
/* check for server shutdown */
- if (client->engine->engine_ok == 0)
+ if (client->engine->engine_ok == 0) {
return req->status;
+ }
/* otherwise report errors */
- if (!wok)
+ if (!wok) {
jack_error ("cannot send request type %d to server",
- req->type);
- if (!rok)
+ req->type);
+ }
+ if (!rok) {
jack_error ("cannot read result for request type %d from"
" server (%s)", req->type, strerror (errno));
+ }
return req->status;
}
@@ -301,18 +307,18 @@ jack_client_deliver_request (const jack_client_t *client, jack_request_t *req)
return client->deliver_request (client->deliver_arg, req);
}
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
jack_client_t *
jack_client_alloc ()
{
jack_client_t *client;
- if ((client = (jack_client_t *) calloc (1, sizeof (jack_client_t))) == NULL) {
+ if ((client = (jack_client_t*)calloc (1, sizeof(jack_client_t))) == NULL) {
return NULL;
}
- if ((client->pollfd = (struct pollfd *) malloc (sizeof (struct pollfd) * 1)) == NULL) {
+ if ((client->pollfd = (struct pollfd*)malloc (sizeof(struct pollfd) * 1)) == NULL) {
free (client);
return NULL;
}
@@ -335,8 +341,8 @@ jack_client_alloc ()
client->port_segment = NULL;
#ifdef USE_DYNSIMD
- init_cpu();
-#endif /* USE_DYNSIMD */
+ init_cpu ();
+#endif /* USE_DYNSIMD */
return client;
}
@@ -348,10 +354,10 @@ jack_client_alloc ()
{
jack_client_t *client;
- if ((client = (jack_client_t *) calloc (1, sizeof (jack_client_t))) == NULL) {
+ if ((client = (jack_client_t*)calloc (1, sizeof(jack_client_t))) == NULL) {
return NULL;
}
- if ((client->pollfd = (struct pollfd *) malloc (sizeof (struct pollfd) * 2)) == NULL) {
+ if ((client->pollfd = (struct pollfd*)malloc (sizeof(struct pollfd) * 2)) == NULL) {
free (client);
return NULL;
}
@@ -374,8 +380,8 @@ jack_client_alloc ()
client->port_segment = NULL;
#ifdef USE_DYNSIMD
- init_cpu();
-#endif /* USE_DYNSIMD */
+ init_cpu ();
+#endif /* USE_DYNSIMD */
return client;
}
@@ -394,7 +400,7 @@ jack_client_alloc_internal (jack_client_control_t *cc, jack_engine_t* engine)
client->control = cc;
client->engine = engine->control;
-
+
client->n_port_types = client->engine->n_port_types;
client->port_segment = &engine->port_segment[0];
@@ -421,23 +427,23 @@ jack_client_fix_port_buffers (jack_client_t *client)
and sets the buffer pointer to NULL. This will cause
jack_port_get_buffer() to reallocate space for the
buffer on the next call (if there is one).
- */
+ */
for (node = client->ports; node; node = jack_slist_next (node)) {
- port = (jack_port_t *) node->data;
+ port = (jack_port_t*)node->data;
if (port->shared->flags & JackPortIsInput) {
if (port->mix_buffer) {
- size_t buffer_size =
- jack_port_type_buffer_size( port->type_info,
- client->engine->buffer_size );
+ size_t buffer_size =
+ jack_port_type_buffer_size ( port->type_info,
+ client->engine->buffer_size );
jack_pool_release (port->mix_buffer);
port->mix_buffer = NULL;
pthread_mutex_lock (&port->connection_lock);
if (jack_slist_length (port->connections) > 1) {
port->mix_buffer = jack_pool_alloc (buffer_size);
- port->fptr.buffer_init (port->mix_buffer,
- buffer_size,
+ port->fptr.buffer_init (port->mix_buffer,
+ buffer_size,
client->engine->buffer_size);
}
pthread_mutex_unlock (&port->connection_lock);
@@ -453,7 +459,7 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
jack_port_t *other = 0;
JSList *node;
int need_free = FALSE;
-
+
if (jack_uuid_compare (client->engine->ports[event->x.self_id].client_id, client->control->uuid) == 0 ||
jack_uuid_compare (client->engine->ports[event->y.other_id].client_id, client->control->uuid) == 0) {
@@ -464,42 +470,42 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
other = jack_port_new (client, event->y.other_id,
client->engine);
/* jack_port_by_id_int() always returns an internal
- * port that does not need to be deallocated
+ * port that does not need to be deallocated
*/
control_port = jack_port_by_id_int (client, event->x.self_id,
&need_free);
pthread_mutex_lock (&control_port->connection_lock);
if ((control_port->shared->flags & JackPortIsInput)
- && (control_port->connections != NULL)
- && (control_port->mix_buffer == NULL) ) {
- size_t buffer_size =
- jack_port_type_buffer_size( control_port->type_info,
- client->engine->buffer_size );
+ && (control_port->connections != NULL)
+ && (control_port->mix_buffer == NULL) ) {
+ size_t buffer_size =
+ jack_port_type_buffer_size ( control_port->type_info,
+ client->engine->buffer_size );
control_port->mix_buffer = jack_pool_alloc (buffer_size);
- control_port->fptr.buffer_init (control_port->mix_buffer,
- buffer_size,
+ control_port->fptr.buffer_init (control_port->mix_buffer,
+ buffer_size,
client->engine->buffer_size);
}
control_port->connections =
jack_slist_prepend (control_port->connections,
- (void *) other);
+ (void*)other);
pthread_mutex_unlock (&control_port->connection_lock);
break;
-
+
case PortDisconnected:
/* jack_port_by_id_int() always returns an internal
- * port that does not need to be deallocated
+ * port that does not need to be deallocated
*/
control_port = jack_port_by_id_int (client, event->x.self_id,
&need_free);
pthread_mutex_lock (&control_port->connection_lock);
-
+
for (node = control_port->connections; node;
node = jack_slist_next (node)) {
-
- other = (jack_port_t *) node->data;
+
+ other = (jack_port_t*)node->data;
if (other->shared->id == event->y.other_id) {
control_port->connections =
@@ -511,10 +517,10 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
break;
}
}
-
+
pthread_mutex_unlock (&control_port->connection_lock);
break;
-
+
default:
/* impossible */
break;
@@ -523,8 +529,8 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
if (client->control->port_connect_cbset) {
client->port_connect (event->x.self_id, event->y.other_id,
- (event->type == PortConnected ? 1 : 0),
- client->port_connect_arg);
+ (event->type == PortConnected ? 1 : 0),
+ client->port_connect_arg);
}
return 0;
@@ -533,16 +539,16 @@ jack_client_handle_port_connection (jack_client_t *client, jack_event_t *event)
int
jack_client_handle_session_callback (jack_client_t *client, jack_event_t *event)
{
- char uuidstr[37];
+ char uuidstr[37];
jack_session_event_t *s_event;
- if (! client->control->session_cbset) {
+ if (!client->control->session_cbset) {
return -1;
}
- jack_uuid_unparse (client->control->uuid, uuidstr);
+ jack_uuid_unparse (client->control->uuid, uuidstr);
- s_event = malloc( sizeof(jack_session_event_t) );
+ s_event = malloc ( sizeof(jack_session_event_t) );
s_event->type = event->y.n;
s_event->session_dir = strdup (event->x.name);
s_event->client_uuid = strdup (uuidstr);
@@ -571,16 +577,19 @@ jack_port_recalculate_latency (jack_port_t *port, jack_latency_callback_mode_t m
jack_port_get_latency_range (other, mode, &other_latency);
- if (other_latency.max > latency.max)
+ if (other_latency.max > latency.max) {
latency.max = other_latency.max;
- if (other_latency.min < latency.min)
+ }
+ if (other_latency.min < latency.min) {
latency.min = other_latency.min;
+ }
}
pthread_mutex_unlock (&port->connection_lock);
- if (latency.min == UINT32_MAX)
+ if (latency.min == UINT32_MAX) {
latency.min = 0;
+ }
jack_port_set_latency_range (port, mode, &latency);
}
@@ -588,7 +597,7 @@ jack_port_recalculate_latency (jack_port_t *port, jack_latency_callback_mode_t m
int
jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event, int is_driver)
{
- jack_latency_callback_mode_t mode = (event->x.n==0) ? JackCaptureLatency : JackPlaybackLatency;
+ jack_latency_callback_mode_t mode = (event->x.n == 0) ? JackCaptureLatency : JackPlaybackLatency;
JSList *node;
jack_latency_range_t latency = { UINT32_MAX, 0 };
@@ -611,7 +620,7 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
*/
if (is_driver && !client->control->latency_cbset) {
return 0;
- }
+ }
if (!client->control->latency_cbset) {
/*
@@ -629,15 +638,18 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
jack_latency_range_t other_latency;
jack_port_get_latency_range (port, mode, &other_latency);
- if (other_latency.max > latency.max)
+ if (other_latency.max > latency.max) {
latency.max = other_latency.max;
- if (other_latency.min < latency.min)
+ }
+ if (other_latency.min < latency.min) {
latency.min = other_latency.min;
+ }
}
}
- if (latency.min == UINT32_MAX)
+ if (latency.min == UINT32_MAX) {
latency.min = 0;
+ }
/* now set the found latency on all input ports
*/
@@ -659,15 +671,18 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
jack_latency_range_t other_latency;
jack_port_get_latency_range (port, mode, &other_latency);
- if (other_latency.max > latency.max)
+ if (other_latency.max > latency.max) {
latency.max = other_latency.max;
- if (other_latency.min < latency.min)
+ }
+ if (other_latency.min < latency.min) {
latency.min = other_latency.min;
+ }
}
}
- if (latency.min == UINT32_MAX)
+ if (latency.min == UINT32_MAX) {
latency.min = 0;
+ }
/* now set the found latency on all output ports
*/
@@ -691,14 +706,14 @@ jack_client_handle_latency_callback (jack_client_t *client, jack_event_t *event,
#if JACK_USE_MACH_THREADS
-static int
+static int
jack_handle_reorder (jack_client_t *client, jack_event_t *event)
-{
+{
client->pollmax = 1;
/* If the client registered its own callback for graph order events,
execute it now.
- */
+ */
if (client->control->graph_order_cbset) {
client->graph_order (client->graph_order_arg);
@@ -709,10 +724,10 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
#else
-static int
+static int
jack_handle_reorder (jack_client_t *client, jack_event_t *event)
-{
- char path[PATH_MAX+1];
+{
+ char path[PATH_MAX + 1];
DEBUG ("graph reorder\n");
@@ -720,7 +735,7 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
DEBUG ("closing graph_wait_fd==%d", client->graph_wait_fd);
close (client->graph_wait_fd);
client->graph_wait_fd = -1;
- }
+ }
if (client->graph_next_fd >= 0) {
DEBUG ("closing graph_next_fd==%d", client->graph_next_fd);
@@ -729,17 +744,17 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
}
sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n);
-
- if ((client->graph_wait_fd = open (path, O_RDONLY|O_NONBLOCK)) < 0) {
+
+ if ((client->graph_wait_fd = open (path, O_RDONLY | O_NONBLOCK)) < 0) {
jack_error ("cannot open specified fifo [%s] for reading (%s)",
path, strerror (errno));
return -1;
}
DEBUG ("opened new graph_wait_fd %d (%s)", client->graph_wait_fd, path);
- sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n+1);
-
- if ((client->graph_next_fd = open (path, O_WRONLY|O_NONBLOCK)) < 0) {
+ sprintf (path, "%s-%" PRIu32, client->fifo_prefix, event->x.n + 1);
+
+ if ((client->graph_next_fd = open (path, O_WRONLY | O_NONBLOCK)) < 0) {
jack_error ("cannot open specified fifo [%s] for writing (%s)",
path, strerror (errno));
return -1;
@@ -749,12 +764,12 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
client->pollmax = 2;
DEBUG ("opened new graph_next_fd %d (%s) (upstream is jackd? %d)",
- client->graph_next_fd, path,
+ client->graph_next_fd, path,
client->upstream_is_jackd);
/* If the client registered its own callback for graph order events,
execute it now.
- */
+ */
if (client->control->graph_order_cbset) {
client->graph_order (client->graph_order_arg);
@@ -764,7 +779,7 @@ jack_handle_reorder (jack_client_t *client, jack_event_t *event)
}
#endif
-
+
static int
server_connect (const char *server_name)
{
@@ -772,7 +787,7 @@ server_connect (const char *server_name)
struct sockaddr_un addr;
int which = 0;
- char server_dir[PATH_MAX+1] = "";
+ char server_dir[PATH_MAX + 1] = "";
if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
jack_error ("cannot create client socket (%s)",
@@ -784,12 +799,12 @@ server_connect (const char *server_name)
//jack_info ("DEBUG: connecting to `%s' server", server_name);
addr.sun_family = AF_UNIX;
- snprintf (addr.sun_path, sizeof (addr.sun_path) - 1, "%s/jack_%d",
- jack_server_dir (server_name, server_dir) , which);
+ snprintf (addr.sun_path, sizeof(addr.sun_path) - 1, "%s/jack_%d",
+ jack_server_dir (server_name, server_dir), which);
- if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
+ if (connect (fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
close (fd);
- jack_error ("connect(2) call to %s failed (err=%s)", addr.sun_path, strerror (errno));
+ jack_error ("connect(2) call to %s failed (err=%s)", addr.sun_path, strerror (errno));
return -1;
}
return fd;
@@ -803,7 +818,7 @@ server_event_connect (jack_client_t *client, const char *server_name)
jack_client_connect_ack_request_t req;
jack_client_connect_ack_result_t res;
- char server_dir[PATH_MAX+1] = "";
+ char server_dir[PATH_MAX + 1] = "";
if ((fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
jack_error ("cannot create client event socket (%s)",
@@ -812,10 +827,10 @@ server_event_connect (jack_client_t *client, const char *server_name)
}
addr.sun_family = AF_UNIX;
- snprintf (addr.sun_path, sizeof (addr.sun_path) - 1, "%s/jack_ack_0",
- jack_server_dir (server_name,server_dir));
+ snprintf (addr.sun_path, sizeof(addr.sun_path) - 1, "%s/jack_ack_0",
+ jack_server_dir (server_name, server_dir));
- if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) < 0) {
+ if (connect (fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
jack_error ("cannot connect to jack server for events",
strerror (errno));
close (fd);
@@ -824,14 +839,14 @@ server_event_connect (jack_client_t *client, const char *server_name)
jack_uuid_copy (&req.client_id, client->control->uuid);
- if (write (fd, &req, sizeof (req)) != sizeof (req)) {
+ if (write (fd, &req, sizeof(req)) != sizeof(req)) {
jack_error ("cannot write event connect request to server (%s)",
strerror (errno));
close (fd);
return -1;
}
- if (read (fd, &res, sizeof (res)) != sizeof (res)) {
+ if (read (fd, &res, sizeof(res)) != sizeof(res)) {
jack_error ("cannot read event connect result from server (%s)",
strerror (errno));
close (fd);
@@ -863,32 +878,32 @@ _start_server (const char *server_name)
int i = 0;
int good = 0;
int ret;
- char *startup_file;
+ char *startup_file;
- if ((startup_file = getenv ("JACK_RC_FILE")) == NULL) {
- snprintf(filename, 255, "%s/.jackdrc", getenv("HOME"));
- startup_file = filename;
- }
+ if ((startup_file = getenv ("JACK_RC_FILE")) == NULL) {
+ snprintf (filename, 255, "%s/.jackdrc", getenv ("HOME"));
+ startup_file = filename;
+ }
- fp = fopen(startup_file, "r");
+ fp = fopen (startup_file, "r");
if (!fp) {
- fp = fopen("/etc/jackdrc", "r");
+ fp = fopen ("/etc/jackdrc", "r");
}
/* if still not found, check old config name for backwards compatability */
if (!fp) {
- fp = fopen("/etc/jackd.conf", "r");
+ fp = fopen ("/etc/jackd.conf", "r");
}
if (fp) {
arguments[0] = '\0';
- ret = fscanf(fp, "%s", buffer);
- while(ret != 0 && ret != EOF) {
- strcat(arguments, buffer);
- strcat(arguments, " ");
- ret = fscanf(fp, "%s", buffer);
+ ret = fscanf (fp, "%s", buffer);
+ while (ret != 0 && ret != EOF) {
+ strcat (arguments, buffer);
+ strcat (arguments, " ");
+ ret = fscanf (fp, "%s", buffer);
}
- if (strlen(arguments) > 0) {
+ if (strlen (arguments) > 0) {
good = 1;
}
}
@@ -896,64 +911,63 @@ _start_server (const char *server_name)
if (!good) {
#if defined(USE_CAPABILITIES)
command = JACK_LOCATION "/jackstart";
- strncpy(arguments, JACK_LOCATION "/jackstart -T -R -d "
- JACK_DEFAULT_DRIVER " -p 512", 255);
-#else /* !USE_CAPABILITIES */
+ strncpy (arguments, JACK_LOCATION "/jackstart -T -R -d "
+ JACK_DEFAULT_DRIVER " -p 512", 255);
+#else /* !USE_CAPABILITIES */
command = JACK_LOCATION "/jackd";
- strncpy(arguments, JACK_LOCATION "/jackd -T -d "
- JACK_DEFAULT_DRIVER, 255);
-#endif /* USE_CAPABILITIES */
+ strncpy (arguments, JACK_LOCATION "/jackd -T -d "
+ JACK_DEFAULT_DRIVER, 255);
+#endif /* USE_CAPABILITIES */
} else {
- result = strcspn(arguments, " ");
- if ((command = (char *) malloc(result+1)) == NULL) {
+ result = strcspn (arguments, " ");
+ if ((command = (char*)malloc (result + 1)) == NULL) {
goto failure;
}
- strncpy(command, arguments, result);
+ strncpy (command, arguments, result);
command[result] = '\0';
}
- if ((argv = (char **) malloc (255)) == NULL) {
+ if ((argv = (char**)malloc (255)) == NULL) {
goto failure;
}
-
- while(1) {
+
+ while (1) {
/* insert -T and -nserver_name in front of arguments */
if (i == 1) {
- argv[i] = (char *) malloc(strlen ("-T") + 1);
- strcpy (argv[i++], "-T");
+ argv[i] = (char*)malloc (strlen ("-T") + 1);
+ strcpy (argv[i++], "-T");
if (server_name) {
size_t optlen = strlen ("-n");
char *buf =
malloc (optlen
+ strlen (server_name) + 1);
strcpy (buf, "-n");
- strcpy (buf+optlen, server_name);
+ strcpy (buf + optlen, server_name);
argv[i++] = buf;
}
}
/* skip whitespace */
- while (pos < strlen(arguments) && arguments[pos] && arguments[pos] == ' ') {
+ while (pos < strlen (arguments) && arguments[pos] && arguments[pos] == ' ')
++pos;
- }
- if (pos >= strlen(arguments)) {
+ if (pos >= strlen (arguments)) {
break;
}
if (arguments[pos] == '\"') {
++pos;
- result = strcspn(arguments + pos, "\"");
+ result = strcspn (arguments + pos, "\"");
} else {
- result = strcspn(arguments + pos, " ");
+ result = strcspn (arguments + pos, " ");
}
if (0 == result) {
break;
}
- argv[i] = (char*)malloc(result + 1);
- strncpy(argv[i], arguments + pos, result);
+ argv[i] = (char*)malloc (result + 1);
+ strncpy (argv[i], arguments + pos, result);
argv[i][result] = '\0';
pos += result + 1;
if (++i > 253) {
@@ -964,9 +978,9 @@ _start_server (const char *server_name)
#if 0
fprintf (stderr, "execing JACK using %s\n", command);
- for (_xx = 0; argv[_xx]; ++_xx) {
+ for (_xx = 0; argv[_xx]; ++_xx)
fprintf (stderr, "\targv[%d] = %s\n", _xx, argv[_xx]);
- }
+
#endif
execv (command, argv);
@@ -980,11 +994,11 @@ failure:
int
start_server (const char *server_name, jack_options_t options)
{
- int status;
- pid_t first_child_pid;
+ int status;
+ pid_t first_child_pid;
if ((options & JackNoStartServer)
- || getenv("JACK_NO_START_SERVER")) {
+ || getenv ("JACK_NO_START_SERVER")) {
return 1;
}
@@ -998,28 +1012,28 @@ start_server (const char *server_name, jack_options_t options)
* probably relatively small.
*/
- first_child_pid = fork();
+ first_child_pid = fork ();
switch (first_child_pid) {
- case 0: /* child process */
- switch (fork()) {
- case 0: /* grandchild process */
- _start_server(server_name);
- _exit (99); /* exec failed */
+ case 0: /* child process */
+ switch (fork ()) {
+ case 0: /* grandchild process */
+ _start_server (server_name);
+ _exit (99); /* exec failed */
case -1:
_exit (98);
default:
_exit (0);
}
- case -1: /* fork() error */
- return 1; /* failed to start server */
+ case -1: /* fork() error */
+ return 1; /* failed to start server */
}
- /* reap the initaial child */
- waitpid (first_child_pid, &status, 0);
+ /* reap the initaial child */
+ waitpid (first_child_pid, &status, 0);
/* only the original parent process goes here */
- return 0; /* (probably) successful */
+ return 0; /* (probably) successful */
}
static int
@@ -1031,46 +1045,46 @@ jack_request_client (ClientType type,
jack_client_connect_request_t req;
*req_fd = -1;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.options = options;
- if (strlen (client_name) >= sizeof (req.name)) {
+ if (strlen (client_name) >= sizeof(req.name)) {
jack_error ("\"%s\" is too long to be used as a JACK client"
" name.\n"
"Please use %lu characters or less.",
- client_name, sizeof (req.name));
+ client_name, sizeof(req.name));
return -1;
}
if (va->load_name
- && (strlen (va->load_name) > sizeof (req.object_path) - 1)) {
+ && (strlen (va->load_name) > sizeof(req.object_path) - 1)) {
jack_error ("\"%s\" is too long to be used as a JACK shared"
" object name.\n"
- "Please use %lu characters or less.",
- va->load_name, sizeof (req.object_path) - 1);
+ "Please use %lu characters or less.",
+ va->load_name, sizeof(req.object_path) - 1);
return -1;
}
if (va->load_init
- && (strlen (va->load_init) > sizeof (req.object_data) - 1)) {
+ && (strlen (va->load_init) > sizeof(req.object_data) - 1)) {
jack_error ("\"%s\" is too long to be used as a JACK shared"
" object data string.\n"
- "Please use %lu characters or less.",
- va->load_init, sizeof (req.object_data) - 1);
+ "Please use %lu characters or less.",
+ va->load_init, sizeof(req.object_data) - 1);
return -1;
}
-
+
if ((*req_fd = server_connect (va->server_name)) < 0) {
int trys;
- if (start_server(va->server_name, options)) {
- *status |= (JackFailure|JackServerFailed);
+ if (start_server (va->server_name, options)) {
+ *status |= (JackFailure | JackServerFailed);
goto fail;
}
trys = 5;
do {
- sleep(1);
+ sleep (1);
if (--trys < 0) {
- *status |= (JackFailure|JackServerFailed);
+ *status |= (JackFailure | JackServerFailed);
goto fail;
}
} while ((*req_fd = server_connect (va->server_name)) < 0);
@@ -1081,52 +1095,52 @@ jack_request_client (ClientType type,
if (va->sess_uuid && strlen (va->sess_uuid)) {
if (jack_uuid_parse (va->sess_uuid, &req.uuid) != 0) {
- jack_error ("Given UUID [%s] is not parseable", va->sess_uuid);
- goto fail;
- }
- } else {
+ jack_error ("Given UUID [%s] is not parseable", va->sess_uuid);
+ goto fail;
+ }
+ } else {
jack_uuid_clear (&req.uuid);
- }
+ }
req.protocol_v = jack_protocol_version;
req.load = TRUE;
req.type = type;
- snprintf (req.name, sizeof (req.name),
+ snprintf (req.name, sizeof(req.name),
"%s", client_name);
- snprintf (req.object_path, sizeof (req.object_path),
+ snprintf (req.object_path, sizeof(req.object_path),
"%s", va->load_name);
- snprintf (req.object_data, sizeof (req.object_data),
+ snprintf (req.object_data, sizeof(req.object_data),
"%s", va->load_init);
- if (write (*req_fd, &req, sizeof (req)) != sizeof (req)) {
+ if (write (*req_fd, &req, sizeof(req)) != sizeof(req)) {
jack_error ("cannot send request to jack server (%s)",
strerror (errno));
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
- if (read (*req_fd, res, sizeof (*res)) != sizeof (*res)) {
+ if (read (*req_fd, res, sizeof(*res)) != sizeof(*res)) {
if (errno == 0) {
/* server shut the socket */
jack_error ("could not attach as client");
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
-
+
if (errno == ECONNRESET) {
jack_error ("could not attach as JACK client "
"(server has exited)");
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
-
+
jack_error ("cannot read response from jack server (%s)",
strerror (errno));
- *status |= (JackFailure|JackServerError);
+ *status |= (JackFailure | JackServerError);
goto fail;
}
- *status |= res->status; /* return server status bits */
+ *status |= res->status; /* return server status bits */
if (*status & JackFailure) {
if (*status & JackVersionError) {
@@ -1151,8 +1165,8 @@ jack_request_client (ClientType type,
return 0;
- fail:
- jack_error ("attempt to connect to server failed");
+fail:
+ jack_error ("attempt to connect to server failed");
if (*req_fd >= 0) {
close (*req_fd);
*req_fd = -1;
@@ -1164,29 +1178,29 @@ int
jack_attach_port_segment (jack_client_t *client, jack_port_type_id_t ptid)
{
/* Lookup, attach and register the port/buffer segments in use
- * right now.
+ * right now.
*/
if (client->control->type != ClientExternal) {
- jack_error("Only external clients need attach port segments");
- abort();
+ jack_error ("Only external clients need attach port segments");
+ abort ();
}
/* make sure we have space to store the port
segment information.
- */
+ */
if (ptid >= client->n_port_types) {
-
+
client->port_segment = (jack_shm_info_t*)
- realloc (client->port_segment,
- sizeof (jack_shm_info_t) * (ptid+1));
+ realloc (client->port_segment,
+ sizeof(jack_shm_info_t) * (ptid + 1));
memset (&client->port_segment[client->n_port_types],
0,
- sizeof (jack_shm_info_t) *
+ sizeof(jack_shm_info_t) *
(ptid - client->n_port_types));
-
+
client->n_port_types = ptid + 1;
} else {
@@ -1213,38 +1227,39 @@ jack_attach_port_segment (jack_client_t *client, jack_port_type_id_t ptid)
jack_client_t *
jack_client_open_aux (const char *client_name,
- jack_options_t options,
- jack_status_t *status, va_list ap)
+ jack_options_t options,
+ jack_status_t *status, va_list ap)
{
/* optional arguments: */
- jack_varargs_t va; /* variable arguments */
+ jack_varargs_t va; /* variable arguments */
int req_fd = -1;
int ev_fd = -1;
- jack_client_connect_result_t res;
+ jack_client_connect_result_t res;
jack_client_t *client;
jack_port_type_id_t ptid;
jack_status_t my_status;
jack_messagebuffer_init ();
-
- if (status == NULL) /* no status from caller? */
- status = &my_status; /* use local status word */
+
+ if (status == NULL) { /* no status from caller? */
+ status = &my_status; /* use local status word */
+ }
*status = 0;
/* validate parameters */
if ((options & ~JackOpenOptions)) {
- *status |= (JackFailure|JackInvalidOption);
+ *status |= (JackFailure | JackInvalidOption);
jack_messagebuffer_exit ();
return NULL;
}
/* parse variable arguments */
- jack_varargs_parse(options, ap, &va);
+ jack_varargs_parse (options, ap, &va);
/* External clients need to know where the tmpdir used for
communication with the server lives
- */
+ */
if (jack_get_tmpdir ()) {
*status |= JackFailure;
jack_messagebuffer_exit ();
@@ -1269,16 +1284,16 @@ jack_client_open_aux (const char *client_name,
strcpy (client->fifo_prefix, res.fifo_prefix);
client->request_fd = req_fd;
client->pollfd[EVENT_POLL_INDEX].events =
- POLLIN|POLLERR|POLLHUP|POLLNVAL;
+ POLLIN | POLLERR | POLLHUP | POLLNVAL;
#ifndef JACK_USE_MACH_THREADS
client->pollfd[WAIT_POLL_INDEX].events =
- POLLIN|POLLERR|POLLHUP|POLLNVAL;
+ POLLIN | POLLERR | POLLHUP | POLLNVAL;
#endif
/* Don't access shared memory until server connected. */
if (jack_initialize_shm (va.server_name)) {
jack_error ("Unable to initialize shared memory.");
- *status |= (JackFailure|JackShmFailure);
+ *status |= (JackFailure | JackShmFailure);
goto fail;
}
@@ -1289,8 +1304,8 @@ jack_client_open_aux (const char *client_name,
" segment");
goto fail;
}
-
- client->engine = (jack_control_t *) jack_shm_addr (&client->engine_shm);
+
+ client->engine = (jack_control_t*)jack_shm_addr (&client->engine_shm);
/* initialize clock source as early as possible */
jack_set_clock_source (client->engine->clock_source);
@@ -1302,9 +1317,9 @@ jack_client_open_aux (const char *client_name,
" segment");
goto fail;
}
-
- client->control = (jack_client_control_t *)
- jack_shm_addr (&client->control_shm);
+
+ client->control = (jack_client_control_t*)
+ jack_shm_addr (&client->control_shm);
/* Nobody else needs to access this shared memory any more, so
* destroy it. Because we have it attached, it won't vanish
@@ -1313,10 +1328,10 @@ jack_client_open_aux (const char *client_name,
jack_destroy_shm (&client->control_shm);
client->n_port_types = client->engine->n_port_types;
- if ((client->port_segment = (jack_shm_info_t *) malloc (sizeof (jack_shm_info_t) * client->n_port_types)) == NULL) {
+ if ((client->port_segment = (jack_shm_info_t*)malloc (sizeof(jack_shm_info_t) * client->n_port_types)) == NULL) {
goto fail;
}
-
+
for (ptid = 0; ptid < client->n_port_types; ++ptid) {
client->port_segment[ptid].index =
client->engine->port_types[ptid].shm_registry_index;
@@ -1327,7 +1342,7 @@ jack_client_open_aux (const char *client_name,
}
/* set up the client so that it does the right thing for an
- * external client
+ * external client
*/
client->deliver_request = oop_client_deliver_request;
client->deliver_arg = client;
@@ -1337,25 +1352,26 @@ jack_client_open_aux (const char *client_name,
}
client->event_fd = ev_fd;
-
+
#ifdef JACK_USE_MACH_THREADS
- /* specific resources for server/client real-time thread
+ /* specific resources for server/client real-time thread
* communication */
- client->clienttask = mach_task_self();
-
- if (task_get_bootstrap_port(client->clienttask, &client->bp)){
- jack_error ("Can't find bootstrap port");
- goto fail;
- }
-
- if (allocate_mach_clientport(client, res.portnum) < 0) {
- jack_error("Can't allocate mach port");
- goto fail;
- };
-#endif /* JACK_USE_MACH_THREADS */
- return client;
-
- fail:
+ client->clienttask = mach_task_self ();
+
+ if (task_get_bootstrap_port (client->clienttask, &client->bp)) {
+ jack_error ("Can't find bootstrap port");
+ goto fail;
+ }
+
+ if (allocate_mach_clientport (client, res.portnum) < 0) {
+ jack_error ("Can't allocate mach port");
+ goto fail;
+ }
+ ;
+#endif /* JACK_USE_MACH_THREADS */
+ return client;
+
+fail:
jack_messagebuffer_exit ();
if (client->engine) {
@@ -1377,12 +1393,13 @@ jack_client_open_aux (const char *client_name,
return NULL;
}
-jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
+jack_client_t* jack_client_open (const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
{
va_list ap;
- va_start(ap, status);
- jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
- va_end(ap);
+
+ va_start (ap, status);
+ jack_client_t* res = jack_client_open_aux (ext_client_name, options, status, ap);
+ va_end (ap);
return res;
}
@@ -1390,8 +1407,10 @@ jack_client_t *
jack_client_new (const char *client_name)
{
jack_options_t options = JackUseExactName;
- if (getenv("JACK_START_SERVER") == NULL)
+
+ if (getenv ("JACK_START_SERVER") == NULL) {
options |= JackNoStartServer;
+ }
return jack_client_open (client_name, options, NULL);
}
@@ -1411,12 +1430,13 @@ jack_internal_client_new (const char *client_name,
jack_status_t status;
jack_options_t options = JackUseExactName;
- if (getenv("JACK_START_SERVER") == NULL)
+ if (getenv ("JACK_START_SERVER") == NULL) {
options |= JackNoStartServer;
+ }
jack_varargs_init (&va);
- va.load_name = (char *) so_name;
- va.load_init = (char *) so_data;
+ va.load_name = (char*)so_name;
+ va.load_init = (char*)so_data;
return jack_request_client (ClientInternal, client_name,
options, &status, &va, &res, &req_fd);
@@ -1426,8 +1446,10 @@ char *
jack_default_server_name (void)
{
char *server_name;
- if ((server_name = getenv("JACK_DEFAULT_SERVER")) == NULL)
+
+ if ((server_name = getenv ("JACK_DEFAULT_SERVER")) == NULL) {
server_name = "default";
+ }
return server_name;
}
@@ -1435,15 +1457,15 @@ jack_default_server_name (void)
char *
jack_user_dir (void)
{
- static char user_dir[PATH_MAX+1] = "";
+ static char user_dir[PATH_MAX + 1] = "";
/* format the path name on the first call */
if (user_dir[0] == '\0') {
if (getenv ("JACK_PROMISCUOUS_SERVER")) {
- snprintf (user_dir, sizeof (user_dir), "%s/jack",
+ snprintf (user_dir, sizeof(user_dir), "%s/jack",
jack_tmpdir);
} else {
- snprintf (user_dir, sizeof (user_dir), "%s/jack-%d",
+ snprintf (user_dir, sizeof(user_dir), "%s/jack-%d",
jack_tmpdir, getuid ());
}
}
@@ -1458,13 +1480,13 @@ jack_server_dir (const char *server_name, char *server_dir)
/* format the path name into the suppled server_dir char array,
* assuming that server_dir is at least as large as PATH_MAX+1 */
- if (server_name == NULL || server_name[0] == '\0') {
- snprintf (server_dir, PATH_MAX+1, "%s/%s",
- jack_user_dir (), jack_default_server_name());
- } else {
- snprintf (server_dir, PATH_MAX+1, "%s/%s",
- jack_user_dir (), server_name);
- }
+ if (server_name == NULL || server_name[0] == '\0') {
+ snprintf (server_dir, PATH_MAX + 1, "%s/%s",
+ jack_user_dir (), jack_default_server_name ());
+ } else {
+ snprintf (server_dir, PATH_MAX + 1, "%s/%s",
+ jack_user_dir (), server_name);
+ }
return server_dir;
}
@@ -1477,19 +1499,19 @@ jack_internal_client_close (const char *client_name)
char *server_name = jack_default_server_name ();
req.load = FALSE;
- snprintf (req.name, sizeof (req.name), "%s", client_name);
-
+ snprintf (req.name, sizeof(req.name), "%s", client_name);
+
if ((fd = server_connect (server_name)) < 0) {
return;
}
- if (write (fd, &req, sizeof (req)) != sizeof(req)) {
+ if (write (fd, &req, sizeof(req)) != sizeof(req)) {
jack_error ("cannot deliver ClientUnload request to JACK "
"server.");
}
/* no response to this request */
-
+
close (fd);
return;
}
@@ -1498,7 +1520,8 @@ int
jack_recompute_total_latencies (jack_client_t* client)
{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = RecomputeTotalLatencies;
return jack_client_deliver_request (client, &request);
@@ -1508,7 +1531,8 @@ int
jack_recompute_total_latency (jack_client_t* client, jack_port_t* port)
{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = RecomputeTotalLatency;
request.x.port_info.port_id = port->shared->id;
@@ -1519,7 +1543,8 @@ int
jack_set_freewheel (jack_client_t* client, int onoff)
{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = onoff ? FreeWheel : StopFreeWheel;
jack_uuid_copy (&request.x.client_id, client->control->uuid);
@@ -1532,25 +1557,25 @@ jack_session_reply (jack_client_t *client, jack_session_event_t *event )
int retval = 0;
if (event->command_line) {
- snprintf ((char *)client->control->session_command,
- sizeof(client->control->session_command),
- "%s", event->command_line);
+ snprintf ((char*)client->control->session_command,
+ sizeof(client->control->session_command),
+ "%s", event->command_line);
client->control->session_flags = event->flags;
} else {
retval = -1;
}
- if (pthread_self() == client->thread_id) {
+ if (pthread_self () == client->thread_id) {
client->session_cb_immediate_reply = 1;
} else {
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = SessionReply;
jack_uuid_copy (&request.x.client_id, client->control->uuid);
- retval = jack_client_deliver_request(client, &request);
+ retval = jack_client_deliver_request (client, &request);
}
return retval;
@@ -1559,32 +1584,37 @@ jack_session_reply (jack_client_t *client, jack_session_event_t *event )
void
jack_session_event_free (jack_session_event_t *event)
{
- if (event->command_line)
+ if (event->command_line) {
free (event->command_line);
+ }
- free ((char *)event->session_dir);
- free ((char *)event->client_uuid);
+ free ((char*)event->session_dir);
+ free ((char*)event->client_uuid);
free (event);
}
void
jack_session_commands_free (jack_session_command_t *cmds)
{
- int i=0;
- while(1) {
- if (cmds[i].client_name)
- free ((char *)cmds[i].client_name);
- if (cmds[i].command)
- free ((char *)cmds[i].command);
- if (cmds[i].uuid)
- free ((char *)cmds[i].uuid);
- else
+ int i = 0;
+
+ while (1) {
+ if (cmds[i].client_name) {
+ free ((char*)cmds[i].client_name);
+ }
+ if (cmds[i].command) {
+ free ((char*)cmds[i].command);
+ }
+ if (cmds[i].uuid) {
+ free ((char*)cmds[i].uuid);
+ } else {
break;
+ }
i += 1;
}
- free(cmds);
+ free (cmds);
}
jack_session_command_t *
@@ -1594,80 +1624,84 @@ jack_session_notify (jack_client_t* client, const char *target, jack_session_eve
jack_session_command_t *retval = NULL;
int num_replies = 0;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = SessionNotify;
- if( path )
- snprintf( request.x.session.path, sizeof( request.x.session.path ), "%s", path );
- else
+ if ( path ) {
+ snprintf ( request.x.session.path, sizeof( request.x.session.path ), "%s", path );
+ } else {
request.x.session.path[0] = '\0';
+ }
- if( target )
- snprintf( request.x.session.target, sizeof( request.x.session.target ), "%s", target );
- else
+ if ( target ) {
+ snprintf ( request.x.session.target, sizeof( request.x.session.target ), "%s", target );
+ } else {
request.x.session.target[0] = '\0';
+ }
request.x.session.type = code;
-
- if( (write (client->request_fd, &request, sizeof (request))
- != sizeof (request)) ) {
+
+ if ( (write (client->request_fd, &request, sizeof(request))
+ != sizeof(request)) ) {
jack_error ("cannot send request type %d to server",
- request.type);
+ request.type);
goto out;
}
- while( 1 ) {
+ while ( 1 ) {
jack_uuid_t uid;
- if (read (client->request_fd, &uid, sizeof (uid)) != sizeof (uid)) {
+ if (read (client->request_fd, &uid, sizeof(uid)) != sizeof(uid)) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
num_replies += 1;
- retval = realloc( retval, (num_replies)*sizeof(jack_session_command_t) );
- retval[num_replies-1].client_name = malloc (JACK_CLIENT_NAME_SIZE);
- retval[num_replies-1].command = malloc (JACK_PORT_NAME_SIZE);
- retval[num_replies-1].uuid = malloc (JACK_UUID_STRING_SIZE);
-
- if ( (retval[num_replies-1].client_name == NULL)
- ||(retval[num_replies-1].command == NULL)
- ||(retval[num_replies-1].uuid == NULL) )
- goto out;
+ retval = realloc ( retval, (num_replies) * sizeof(jack_session_command_t) );
+ retval[num_replies - 1].client_name = malloc (JACK_CLIENT_NAME_SIZE);
+ retval[num_replies - 1].command = malloc (JACK_PORT_NAME_SIZE);
+ retval[num_replies - 1].uuid = malloc (JACK_UUID_STRING_SIZE);
+
+ if ( (retval[num_replies - 1].client_name == NULL)
+ || (retval[num_replies - 1].command == NULL)
+ || (retval[num_replies - 1].uuid == NULL) ) {
+ goto out;
+ }
if (jack_uuid_empty (uid)) {
break;
- }
+ }
- if (read (client->request_fd, (char *)retval[num_replies-1].client_name, JACK_CLIENT_NAME_SIZE)
- != JACK_CLIENT_NAME_SIZE) {
+ if (read (client->request_fd, (char*)retval[num_replies - 1].client_name, JACK_CLIENT_NAME_SIZE)
+ != JACK_CLIENT_NAME_SIZE) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
- if (read (client->request_fd, (char *)retval[num_replies-1].command, JACK_PORT_NAME_SIZE)
- != JACK_PORT_NAME_SIZE) {
+ if (read (client->request_fd, (char*)retval[num_replies - 1].command, JACK_PORT_NAME_SIZE)
+ != JACK_PORT_NAME_SIZE) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
- if (read (client->request_fd, & retval[num_replies-1].flags, sizeof(retval[num_replies-1].flags) )
- != sizeof(retval[num_replies-1].flags) ) {
+ if (read (client->request_fd, &retval[num_replies - 1].flags, sizeof(retval[num_replies - 1].flags) )
+ != sizeof(retval[num_replies - 1].flags) ) {
jack_error ("cannot read result for request type %d from"
- " server (%s)", request.type, strerror (errno));
+ " server (%s)", request.type, strerror (errno));
goto out;
}
- jack_uuid_unparse (uid, (char *)retval[num_replies-1].uuid);
+ jack_uuid_unparse (uid, (char*)retval[num_replies - 1].uuid);
}
- free((char *)retval[num_replies-1].uuid);
- retval[num_replies-1].uuid = NULL;
- retval[num_replies-1].client_name = NULL;
- retval[num_replies-1].command = NULL;
+ free ((char*)retval[num_replies - 1].uuid);
+ retval[num_replies - 1].uuid = NULL;
+ retval[num_replies - 1].client_name = NULL;
+ retval[num_replies - 1].command = NULL;
return retval;
out:
- if( retval )
- jack_session_commands_free(retval);
+ if ( retval ) {
+ jack_session_commands_free (retval);
+ }
return NULL;
}
@@ -1676,12 +1710,13 @@ jack_client_has_session_callback (jack_client_t *client, const char *client_name
{
jack_request_t request;
int retval;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = SessionHasCallback;
strncpy (request.x.name, client_name, JACK_CLIENT_NAME_SIZE);
- retval = jack_client_deliver_request(client, &request);
+ retval = jack_client_deliver_request (client, &request);
return retval;
}
@@ -1692,7 +1727,7 @@ jack_start_freewheel (jack_client_t* client)
jack_client_control_t *control = client->control;
if (client->engine->real_time) {
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
jack_drop_real_time_scheduling (client->process_thread);
#else
jack_drop_real_time_scheduling (client->thread);
@@ -1710,12 +1745,12 @@ jack_stop_freewheel (jack_client_t* client)
jack_client_control_t *control = client->control;
if (client->engine->real_time) {
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
jack_acquire_real_time_scheduling (client->process_thread,
- client->engine->client_priority);
+ client->engine->client_priority);
#else
- jack_acquire_real_time_scheduling (client->thread,
- client->engine->client_priority);
+ jack_acquire_real_time_scheduling (client->thread,
+ client->engine->client_priority);
#endif
}
@@ -1728,7 +1763,7 @@ static void
jack_client_thread_suicide (jack_client_t* client, const char* reason)
{
#ifdef JACK_USE_MACH_THREADS
- client->rt_thread_ok = FALSE;
+ client->rt_thread_ok = FALSE;
#endif
if (client->on_info_shutdown) {
@@ -1741,7 +1776,7 @@ jack_client_thread_suicide (jack_client_t* client, const char* reason)
jack_error ("jack_client_thread: %s - exiting from JACK", reason);
jack_client_close_aux (client);
/* Need a fix : possibly make client crash if
- * zombified without shutdown handler
+ * zombified without shutdown handler
*/
}
@@ -1757,39 +1792,39 @@ jack_client_process_events (jack_client_t* client)
jack_client_control_t *control = client->control;
JSList *node;
jack_port_t* port;
- char* key = 0;
+ char* key = 0;
DEBUG ("process events");
if (client->pollfd[EVENT_POLL_INDEX].revents & POLLIN) {
-
+
DEBUG ("client receives an event, "
"now reading on event fd");
-
+
/* server has sent us an event. process the
* event and reply */
-
- if (read (client->event_fd, &event, sizeof (event))
- != sizeof (event)) {
+
+ if (read (client->event_fd, &event, sizeof(event))
+ != sizeof(event)) {
jack_error ("cannot read server event (%s)",
strerror (errno));
return -1;
}
- if (event.type == PropertyChange) {
- if (event.y.key_size) {
- key = (char *) malloc (event.y.key_size);
- if (read (client->event_fd, key, event.y.key_size) !=
- event.y.key_size) {
- jack_error ("cannot read property change key (%s)",
- strerror (errno));
- return -1;
- }
- }
- }
+ if (event.type == PropertyChange) {
+ if (event.y.key_size) {
+ key = (char*)malloc (event.y.key_size);
+ if (read (client->event_fd, key, event.y.key_size) !=
+ event.y.key_size) {
+ jack_error ("cannot read property change key (%s)",
+ strerror (errno));
+ return -1;
+ }
+ }
+ }
status = 0;
-
+
switch (event.type) {
case PortRegistered:
for (node = client->ports_ext; node; node = jack_slist_next (node)) {
@@ -1801,76 +1836,76 @@ jack_client_process_events (jack_client_t* client)
if (control->port_register_cbset) {
client->port_register
(event.x.port_id, TRUE,
- client->port_register_arg);
- }
+ client->port_register_arg);
+ }
break;
-
+
case PortUnregistered:
if (control->port_register_cbset) {
client->port_register
(event.x.port_id, FALSE,
- client->port_register_arg);
+ client->port_register_arg);
}
break;
-
+
case ClientRegistered:
if (control->client_register_cbset) {
client->client_register
(event.x.name, TRUE,
- client->client_register_arg);
- }
+ client->client_register_arg);
+ }
break;
-
+
case ClientUnregistered:
if (control->client_register_cbset) {
client->client_register
(event.x.name, FALSE,
- client->client_register_arg);
+ client->client_register_arg);
}
break;
-
+
case GraphReordered:
status = jack_handle_reorder (client, &event);
break;
-
+
case PortConnected:
case PortDisconnected:
status = jack_client_handle_port_connection
- (client, &event);
+ (client, &event);
break;
-
+
case BufferSizeChange:
jack_client_fix_port_buffers (client);
if (control->bufsize_cbset) {
status = client->bufsize
- (client->engine->buffer_size,
- client->bufsize_arg);
- }
+ (client->engine->buffer_size,
+ client->bufsize_arg);
+ }
break;
-
+
case SampleRateChange:
if (control->srate_cbset) {
status = client->srate
- (client->engine->current_time.frame_rate,
- client->srate_arg);
+ (client->engine->current_time.frame_rate,
+ client->srate_arg);
}
break;
-
+
case XRun:
if (control->xrun_cbset) {
status = client->xrun
- (client->xrun_arg);
+ (client->xrun_arg);
}
break;
-
+
case AttachPortSegment:
jack_attach_port_segment (client, event.y.ptid);
break;
-
+
case StartFreewheel:
jack_start_freewheel (client);
break;
-
+
case StopFreewheel:
jack_stop_freewheel (client);
break;
@@ -1880,31 +1915,31 @@ jack_client_process_events (jack_client_t* client)
case LatencyCallback:
status = jack_client_handle_latency_callback (client, &event, 0 );
break;
- case PropertyChange:
- if (control->property_cbset) {
- client->property_cb (event.x.uuid, key, event.z.property_change, client->property_cb_arg);
- }
- if (key) {
- free (key);
- }
- break;
- case PortRename:
- if (control->port_rename_cbset) {
- client->port_rename_cb (event.y.other_id, event.x.name, event.z.other_name, client->port_rename_arg);
- }
- break;
- }
-
+ case PropertyChange:
+ if (control->property_cbset) {
+ client->property_cb (event.x.uuid, key, event.z.property_change, client->property_cb_arg);
+ }
+ if (key) {
+ free (key);
+ }
+ break;
+ case PortRename:
+ if (control->port_rename_cbset) {
+ client->port_rename_cb (event.y.other_id, event.x.name, event.z.other_name, client->port_rename_arg);
+ }
+ break;
+ }
+
DEBUG ("client has dealt with the event, writing "
"response on event fd");
-
- if (write (client->event_fd, &status, sizeof (status))
- != sizeof (status)) {
+
+ if (write (client->event_fd, &status, sizeof(status))
+ != sizeof(status)) {
jack_error ("cannot send event response to "
"engine (%s)", strerror (errno));
return -1;
}
- }
+ }
return 0;
}
@@ -1918,19 +1953,19 @@ jack_wake_next_client (jack_client_t* client)
int pret = 0;
char c = 0;
- if (write (client->graph_next_fd, &c, sizeof (c))
- != sizeof (c)) {
- DEBUG("cannot write byte to fd %d", client->graph_next_fd);
+ if (write (client->graph_next_fd, &c, sizeof(c))
+ != sizeof(c)) {
+ DEBUG ("cannot write byte to fd %d", client->graph_next_fd);
jack_error ("cannot continue execution of the "
"processing graph (%s)",
- strerror(errno));
+ strerror (errno));
return -1;
}
-
+
DEBUG ("client sent message to next stage by %" PRIu64 "",
- jack_get_microseconds());
-
- DEBUG("reading cleanup byte from pipe %d\n", client->graph_wait_fd);
+ jack_get_microseconds ());
+
+ DEBUG ("reading cleanup byte from pipe %d\n", client->graph_wait_fd);
/* "upstream client went away? readability is checked in
* jack_client_core_wait(), but that's almost a whole cycle
@@ -1942,21 +1977,21 @@ jack_wake_next_client (jack_client_t* client)
pfds[0].events = POLLIN;
/* 0 timeout, don't actually wait */
- pret = poll(pfds, 1, 0);
+ pret = poll (pfds, 1, 0);
}
if (pret > 0 && (pfds[0].revents & POLLIN)) {
- if (read (client->graph_wait_fd, &c, sizeof (c))
- != sizeof (c)) {
+ if (read (client->graph_wait_fd, &c, sizeof(c))
+ != sizeof(c)) {
jack_error ("cannot complete execution of the "
- "processing graph (%s)", strerror(errno));
+ "processing graph (%s)", strerror (errno));
return -1;
}
} else {
- DEBUG("cleanup byte from pipe %d not available?\n",
- client->graph_wait_fd);
+ DEBUG ("cleanup byte from pipe %d not available?\n",
+ client->graph_wait_fd);
}
-#endif
+#endif
return 0;
}
@@ -1970,10 +2005,10 @@ jack_osx_event_thread_work (void* arg)
All we do here is to poll() for callbacks from the server,
and then process any callbacks that arrive.
- */
+ */
- jack_client_t* client = (jack_client_t*) arg;
+ jack_client_t* client = (jack_client_t*)arg;
jack_client_control_t *control = client->control;
if (control->thread_init_cbset) {
@@ -1981,14 +2016,14 @@ jack_osx_event_thread_work (void* arg)
client->thread_init (client->thread_init_arg);
}
- while (1) {
+ while (1) {
/* this is OS X - we're only waiting on events */
-
+
DEBUG ("client polling on %s", client->pollmax == 2 ?
"event_fd and graph_wait_fd..." :
"event_fd only");
-
+
while (1) {
if (poll (client->pollfd, client->pollmax, 1000) < 0) {
if (errno == EINTR) {
@@ -1998,15 +2033,15 @@ jack_osx_event_thread_work (void* arg)
strerror (errno));
break;
}
-
- pthread_testcancel();
-
+
+ pthread_testcancel ();
+
if (jack_client_process_events (client)) {
DEBUG ("event processing failed\n");
break;
}
}
-
+
if (control->dead || client->pollfd[EVENT_POLL_INDEX].revents & ~POLLIN) {
DEBUG ("client appears dead or event pollfd has error status\n");
break;
@@ -2027,12 +2062,12 @@ jack_client_core_wait (jack_client_t* client)
{
jack_client_control_t *control = client->control;
- /* this is not OS X - we're waiting on events & process wakeups */
+ /* this is not OS X - we're waiting on events & process wakeups */
DEBUG ("client polling on %s", client->pollmax == 2 ?
"event_fd and graph_wait_fd..." :
"event_fd only");
-
+
while (1) {
if (poll (client->pollfd, client->pollmax, 1000) < 0) {
if (errno == EINTR) {
@@ -2043,30 +2078,30 @@ jack_client_core_wait (jack_client_t* client)
return -1;
}
- pthread_testcancel();
+ pthread_testcancel ();
/* get an accurate timestamp on waking from poll for a
- * process() cycle.
+ * process() cycle.
*/
-
+
if (client->graph_wait_fd >= 0
&& client->pollfd[WAIT_POLL_INDEX].revents & POLLIN) {
- control->awake_at = jack_get_microseconds();
+ control->awake_at = jack_get_microseconds ();
}
-
+
DEBUG ("pfd[EVENT].revents = 0x%x pfd[WAIT].revents = 0x%x",
client->pollfd[EVENT_POLL_INDEX].revents,
client->pollfd[WAIT_POLL_INDEX].revents);
-
+
if (client->graph_wait_fd >= 0 &&
(client->pollfd[WAIT_POLL_INDEX].revents & ~POLLIN)) {
-
+
/* our upstream "wait" connection
closed, which either means that
an intermediate client exited, or
jackd exited, or jackd zombified
us.
-
+
we can discover the zombification
via client->control->dead, but
the other two possibilities are
@@ -2074,8 +2109,8 @@ jack_client_core_wait (jack_client_t* client)
this situation. so we have to
check what we are connected to,
and act accordingly.
- */
-
+ */
+
if (client->upstream_is_jackd) {
DEBUG ("WE (%s) DIE\n", client->name);
return 0;
@@ -2085,12 +2120,12 @@ jack_client_core_wait (jack_client_t* client)
* again until we get a
* GraphReordered event.
*/
-
+
client->graph_wait_fd = -1;
client->pollmax = 1;
}
}
-
+
if (jack_client_process_events (client)) {
DEBUG ("event processing failed\n");
return 0;
@@ -2113,39 +2148,39 @@ jack_client_core_wait (jack_client_t* client)
#endif
-static void*
+static void*
jack_process_thread_work (void* arg)
{
/* this is the RT process thread used to handle process()
callbacks, and on non-OSX systems, server events/callbacks
as well.
- */
+ */
- jack_client_t* client = (jack_client_t*) arg;
+ jack_client_t* client = (jack_client_t*)arg;
jack_client_control_t *control = client->control;
/* notify the waiting client that this thread
is up and running.
- */
+ */
pthread_mutex_lock (&client_lock);
client->thread_ok = TRUE;
- client->thread_id = pthread_self();
+ client->thread_id = pthread_self ();
pthread_cond_signal (&client_ready);
pthread_mutex_unlock (&client_lock);
- control->pid = getpid();
- control->pgrp = getpgrp();
+ control->pid = getpid ();
+ control->pgrp = getpgrp ();
#ifdef JACK_USE_MACH_THREADS
client->rt_thread_ok = TRUE;
-#endif
+#endif
if (control->thread_cb_cbset) {
- /* client provided a thread function to run,
+ /* client provided a thread function to run,
so just do that.
- */
+ */
client->thread_cb (client->thread_cb_arg);
@@ -2155,29 +2190,29 @@ jack_process_thread_work (void* arg)
DEBUG ("calling process thread init callback");
client->thread_init (client->thread_init_arg);
}
-
+
while (1) {
int status;
-
+
if (jack_cycle_wait (client) != client->engine->buffer_size) {
break;
}
-
+
if (control->process_cbset) {
-
+
/* run process callback, then wait... ad-infinitum */
-
- DEBUG("client calls process()");
+
+ DEBUG ("client calls process()");
status = client->process (client->engine->buffer_size, client->process_arg);
control->state = Finished;
} else {
status = 0;
}
-
- /* if status was non-zero, this will not return (it will call
+
+ /* if status was non-zero, this will not return (it will call
jack_client_thread_suicide()
- */
-
+ */
+
jack_cycle_signal (client, status);
}
}
@@ -2190,12 +2225,13 @@ jack_process_thread_work (void* arg)
jack_nframes_t
jack_thread_wait (jack_client_t* client, int status)
{
- static int msg_delivered = 0;
- if (!msg_delivered) {
- jack_error("jack_thread_wait(): deprecated, use jack_cycle_wait/jack_cycle_signal");
- msg_delivered = 1;
- }
- return 0;
+ static int msg_delivered = 0;
+
+ if (!msg_delivered) {
+ jack_error ("jack_thread_wait(): deprecated, use jack_cycle_wait/jack_cycle_signal");
+ msg_delivered = 1;
+ }
+ return 0;
}
jack_nframes_t jack_cycle_wait (jack_client_t* client)
@@ -2203,38 +2239,38 @@ jack_nframes_t jack_cycle_wait (jack_client_t* client)
jack_client_control_t *control = client->control;
/* SECTION TWO: WAIT FOR NEXT DATA PROCESSING TIME */
-
+
#ifdef JACK_USE_MACH_THREADS
- /* on OS X systems, this thread is running a callback provided
- by the client that has called this function in order to wait
- for the next process callback. This is how we do that ...
- */
- jack_client_suspend (client);
+ /* on OS X systems, this thread is running a callback provided
+ by the client that has called this function in order to wait
+ for the next process callback. This is how we do that ...
+ */
+ jack_client_suspend (client);
#else
- /* on non-OSX systems, this thread is running a callback provided
- by the client that has called this function in order to wait
- for the next process() callback or the next event from the
- server.
- */
+ /* on non-OSX systems, this thread is running a callback provided
+ by the client that has called this function in order to wait
+ for the next process() callback or the next event from the
+ server.
+ */
if (jack_client_core_wait (client)) {
return 0;
}
#endif
-
- /* SECTION THREE: START NEXT DATA PROCESSING TIME */
-
+
+ /* SECTION THREE: START NEXT DATA PROCESSING TIME */
+
/* Time to do data processing */
-
- control->awake_at = jack_get_microseconds();
+
+ control->awake_at = jack_get_microseconds ();
client->control->state = Running;
-
+
/* begin preemption checking */
CHECK_PREEMPTION (client->engine, TRUE);
-
+
if (client->control->sync_cb_cbset) {
jack_call_sync_client (client);
- }
-
+ }
+
return client->engine->buffer_size;
}
@@ -2242,69 +2278,69 @@ void jack_cycle_signal (jack_client_t* client, int status)
{
client->control->last_status = status;
- /* SECTION ONE: HOUSEKEEPING/CLEANUP FROM LAST DATA PROCESSING */
-
+ /* SECTION ONE: HOUSEKEEPING/CLEANUP FROM LAST DATA PROCESSING */
+
/* housekeeping/cleanup after data processing */
-
+
if (status == 0 && client->control->timebase_cb_cbset) {
jack_call_timebase_master (client);
}
-
+
/* end preemption checking */
CHECK_PREEMPTION (client->engine, FALSE);
-
- client->control->finished_at = jack_get_microseconds();
- client->control->state = Finished;
-
- /* wake the next client in the chain (could be the server),
+
+ client->control->finished_at = jack_get_microseconds ();
+ client->control->state = Finished;
+
+ /* wake the next client in the chain (could be the server),
and check if we were killed during the process
cycle.
- */
-
+ */
+
if (jack_wake_next_client (client)) {
- DEBUG("client cannot wake next, or is dead\n");
+ DEBUG ("client cannot wake next, or is dead\n");
jack_client_thread_suicide (client, "graph error");
/*NOTREACHED*/
}
-
- if (client->control->dead) {
+
+ if (client->control->dead) {
jack_client_thread_suicide (client, "zombified");
/*NOTREACHED*/
- }
+ }
if (status) {
jack_client_thread_suicide (client, "process error");
/*NOTREACHED*/
}
- if (!client->engine->engine_ok) {
+ if (!client->engine->engine_ok) {
jack_client_thread_suicide (client, "JACK died");
/*NOTREACHED*/
- }
+ }
}
static int
jack_start_thread (jack_client_t *client)
{
#ifdef USE_MLOCK
- if (client->engine->real_time) {
+ if (client->engine->real_time) {
if (client->engine->do_mlock
&& (mlockall (MCL_CURRENT | MCL_FUTURE) != 0)) {
jack_error ("cannot lock down memory for RT thread "
"(%s)", strerror (errno));
- }
-
- if (client->engine->do_munlock) {
- cleanup_mlock ();
- }
+ }
+
+ if (client->engine->do_munlock) {
+ cleanup_mlock ();
+ }
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
#ifdef JACK_USE_MACH_THREADS
/* Stephane Letz : letz@grame.fr
On MacOSX, the event/callback-handling thread does not need to be real-time.
-*/
- if (jack_client_create_thread (client,
+ */
+ if (jack_client_create_thread (client,
&client->thread,
client->engine->client_priority,
FALSE,
@@ -2313,10 +2349,10 @@ jack_start_thread (jack_client_t *client)
}
#else
if (jack_client_create_thread (client,
- &client->thread,
- client->engine->client_priority,
- client->engine->real_time,
- jack_process_thread_work, client)) {
+ &client->thread,
+ client->engine->client_priority,
+ client->engine->real_time,
+ jack_process_thread_work, client)) {
return -1;
}
@@ -2332,21 +2368,21 @@ jack_start_thread (jack_client_t *client)
methods that encapsulated the underlying mechanism
used.
- */
+ */
- if (jack_client_create_thread(client,
- &client->process_thread,
- client->engine->client_priority,
- client->engine->real_time,
- jack_process_thread_work, client)) {
+ if (jack_client_create_thread (client,
+ &client->process_thread,
+ client->engine->client_priority,
+ client->engine->real_time,
+ jack_process_thread_work, client)) {
return -1;
}
-#endif /* JACK_USE_MACH_THREADS */
+#endif /* JACK_USE_MACH_THREADS */
return 0;
}
-int
+int
jack_activate (jack_client_t *client)
{
jack_request_t req;
@@ -2368,9 +2404,9 @@ jack_activate (jack_client_t *client)
/* we need to ask the engine for realtime capabilities
before trying to start the realtime thread
- */
+ */
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = SetClientCapabilities;
req.x.client_id = client->control->id;
@@ -2387,19 +2423,19 @@ jack_activate (jack_client_t *client)
give the client the required capabilities.
For now, leave the client so that it
still runs, albeit non-realtime.
- */
-
+ */
+
jack_error ("could not receive realtime capabilities, "
"client will run non-realtime");
- }
+ }
}
-#endif /* USE_CAPABILITIES */
+#endif /* USE_CAPABILITIES */
if (client->first_active) {
pthread_mutex_init (&client_lock, NULL);
pthread_cond_init (&client_ready, NULL);
-
+
pthread_mutex_lock (&client_lock);
if (jack_start_thread (client)) {
@@ -2418,7 +2454,7 @@ jack_activate (jack_client_t *client)
client->first_active = FALSE;
}
- startit:
+startit:
req.type = ActivateClient;
jack_uuid_copy (&req.x.client_id, client->control->uuid);
@@ -2426,16 +2462,16 @@ jack_activate (jack_client_t *client)
return jack_client_deliver_request (client, &req);
}
-static int
+static int
jack_deactivate_aux (jack_client_t *client)
{
jack_request_t req;
- int rc = ESRCH; /* already shut down */
-
- if (client && client->control) { /* not shut down? */
+ int rc = ESRCH; /* already shut down */
+
+ if (client && client->control) { /* not shut down? */
rc = 0;
- if (client->control->active) { /* still active? */
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ if (client->control->active) { /* still active? */
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = DeactivateClient;
jack_uuid_copy (&req.x.client_id, client->control->uuid);
rc = jack_client_deliver_request (client, &req);
@@ -2444,10 +2480,10 @@ jack_deactivate_aux (jack_client_t *client)
return rc;
}
-int
+int
jack_deactivate (jack_client_t *client)
{
- return jack_deactivate_aux(client);
+ return jack_deactivate_aux (client);
}
static int
@@ -2458,13 +2494,13 @@ jack_client_close_aux (jack_client_t *client)
int rc;
rc = jack_deactivate_aux (client);
- if (rc == ESRCH) { /* already shut down? */
+ if (rc == ESRCH) { /* already shut down? */
return rc;
}
if (client->control->type == ClientExternal) {
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
if (client->rt_thread_ok) {
// MacOSX pthread_cancel not implemented in
// Darwin 5.5, 6.4
@@ -2473,12 +2509,12 @@ jack_client_close_aux (jack_client_t *client)
thread_terminate (machThread);
}
#endif
-
+
/* stop the thread that communicates with the jack
- * server, only if it was actually running
+ * server, only if it was actually running
*/
-
- if (client->thread_ok){
+
+ if (client->thread_ok) {
pthread_cancel (client->thread);
pthread_join (client->thread, &status);
}
@@ -2494,9 +2530,8 @@ jack_client_close_aux (jack_client_t *client)
if (client->port_segment) {
jack_port_type_id_t ptid;
- for (ptid = 0; ptid < client->n_port_types; ++ptid) {
+ for (ptid = 0; ptid < client->n_port_types; ++ptid)
jack_release_shm (&client->port_segment[ptid]);
- }
free (client->port_segment);
client->port_segment = NULL;
}
@@ -2505,12 +2540,12 @@ jack_client_close_aux (jack_client_t *client)
if (client->graph_wait_fd >= 0) {
close (client->graph_wait_fd);
}
-
+
if (client->graph_next_fd >= 0) {
close (client->graph_next_fd);
}
-#endif
-
+#endif
+
close (client->event_fd);
if (shutdown (client->request_fd, SHUT_RDWR)) {
@@ -2521,13 +2556,11 @@ jack_client_close_aux (jack_client_t *client)
}
- for (node = client->ports; node; node = jack_slist_next (node)) {
+ for (node = client->ports; node; node = jack_slist_next (node))
free (node->data);
- }
jack_slist_free (client->ports);
- for (node = client->ports_ext; node; node = jack_slist_next (node)) {
+ for (node = client->ports_ext; node; node = jack_slist_next (node))
free (node->data);
- }
jack_slist_free (client->ports_ext);
jack_client_free (client);
jack_messagebuffer_exit ();
@@ -2538,16 +2571,16 @@ jack_client_close_aux (jack_client_t *client)
int
jack_client_close (jack_client_t *client)
{
- return jack_client_close_aux(client);
-}
+ return jack_client_close_aux (client);
+}
-int
+int
jack_is_realtime (jack_client_t *client)
{
return client->engine->real_time;
}
-jack_nframes_t
+jack_nframes_t
jack_get_buffer_size (jack_client_t *client)
{
return client->engine->buffer_size;
@@ -2559,11 +2592,11 @@ jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes)
#ifdef DO_BUFFER_RESIZE
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
- if (nframes < 1 || nframes > 16384) {
- return ERANGE;
- }
+ if (nframes < 1 || nframes > 16384) {
+ return ERANGE;
+ }
req.type = SetBufferSize;
req.x.nframes = nframes;
@@ -2572,23 +2605,23 @@ jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes)
#else
return ENOSYS;
-#endif /* DO_BUFFER_RESIZE */
+#endif /* DO_BUFFER_RESIZE */
}
-int
+int
jack_connect (jack_client_t *client, const char *source_port,
const char *destination_port)
{
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = ConnectPorts;
snprintf (req.x.connect.source_port,
- sizeof (req.x.connect.source_port), "%s", source_port);
+ sizeof(req.x.connect.source_port), "%s", source_port);
snprintf (req.x.connect.destination_port,
- sizeof (req.x.connect.destination_port),
+ sizeof(req.x.connect.destination_port),
"%s", destination_port);
return jack_client_deliver_request (client, &req);
@@ -2608,7 +2641,7 @@ jack_port_disconnect (jack_client_t *client, jack_port_t *port)
pthread_mutex_unlock (&port->connection_lock);
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = DisconnectPort;
req.x.port_info.port_id = port->shared->id;
@@ -2616,38 +2649,38 @@ jack_port_disconnect (jack_client_t *client, jack_port_t *port)
return jack_client_deliver_request (client, &req);
}
-int
+int
jack_disconnect (jack_client_t *client, const char *source_port,
const char *destination_port)
{
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = DisconnectPorts;
snprintf (req.x.connect.source_port,
- sizeof (req.x.connect.source_port), "%s", source_port);
+ sizeof(req.x.connect.source_port), "%s", source_port);
snprintf (req.x.connect.destination_port,
- sizeof (req.x.connect.destination_port),
+ sizeof(req.x.connect.destination_port),
"%s", destination_port);
-
+
return jack_client_deliver_request (client, &req);
}
void
-jack_set_error_function (void (*func) (const char *))
+jack_set_error_function (void (*func)(const char *))
{
jack_error_callback = func;
}
void
-jack_set_info_function (void (*func) (const char *))
+jack_set_info_function (void (*func)(const char *))
{
jack_info_callback = func;
}
-int
+int
jack_set_graph_order_callback (jack_client_t *client,
JackGraphOrderCallback callback, void *arg)
{
@@ -2661,9 +2694,9 @@ jack_set_graph_order_callback (jack_client_t *client,
return 0;
}
-int
+int
jack_set_latency_callback (jack_client_t *client,
- JackLatencyCallback callback, void *arg)
+ JackLatencyCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2686,7 +2719,7 @@ int jack_set_xrun_callback (jack_client_t *client,
client->xrun = callback;
client->xrun_arg = arg;
client->control->xrun_cbset = (callback != NULL);
- return 0;
+ return 0;
}
int
@@ -2698,12 +2731,12 @@ jack_set_process_callback (jack_client_t *client,
jack_error ("You cannot set callbacks on an active client.");
return -1;
}
-
+
if (client->control->thread_cb_cbset) {
jack_error ("A thread callback has already been setup, both models cannot be used at the same time!");
return -1;
}
-
+
client->process_arg = arg;
client->process = callback;
client->control->process_cbset = (callback != NULL);
@@ -2756,8 +2789,8 @@ jack_set_buffer_size_callback (jack_client_t *client,
int
jack_set_port_rename_callback (jack_client_t *client,
- JackPortRenameCallback callback,
- void *arg)
+ JackPortRenameCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2770,9 +2803,9 @@ jack_set_port_rename_callback (jack_client_t *client,
}
int
-jack_set_port_registration_callback(jack_client_t *client,
- JackPortRegistrationCallback callback,
- void *arg)
+jack_set_port_registration_callback (jack_client_t *client,
+ JackPortRegistrationCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2785,9 +2818,9 @@ jack_set_port_registration_callback(jack_client_t *client,
}
int
-jack_set_port_connect_callback(jack_client_t *client,
- JackPortConnectCallback callback,
- void *arg)
+jack_set_port_connect_callback (jack_client_t *client,
+ JackPortConnectCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2800,9 +2833,9 @@ jack_set_port_connect_callback(jack_client_t *client,
}
int
-jack_set_client_registration_callback(jack_client_t *client,
- JackClientRegistrationCallback callback,
- void *arg)
+jack_set_client_registration_callback (jack_client_t *client,
+ JackClientRegistrationCallback callback,
+ void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2815,13 +2848,13 @@ jack_set_client_registration_callback(jack_client_t *client,
}
int
-jack_set_process_thread(jack_client_t* client, JackThreadCallback callback, void *arg)
+jack_set_process_thread (jack_client_t* client, JackThreadCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
return -1;
}
-
+
if (client->control->process_cbset) {
jack_error ("A process callback has already been setup, both models cannot be used at the same time!");
return -1;
@@ -2834,7 +2867,7 @@ jack_set_process_thread(jack_client_t* client, JackThreadCallback callback, void
}
int
-jack_set_session_callback(jack_client_t* client, JackSessionCallback callback, void *arg)
+jack_set_session_callback (jack_client_t* client, JackSessionCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -2869,64 +2902,68 @@ jack_on_info_shutdown (jack_client_t *client, void (*function)(jack_status_t, co
char *
jack_get_client_name_by_uuid (jack_client_t *client, const char *uuid_str)
-{
+{
jack_request_t request;
-
- VALGRIND_MEMSET (&request, 0, sizeof (request));
- if (jack_uuid_parse (uuid_str, &request.x.client_id) != 0) {
- return NULL;
- }
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
+
+ if (jack_uuid_parse (uuid_str, &request.x.client_id) != 0) {
+ return NULL;
+ }
request.type = GetClientByUUID;
- if( jack_client_deliver_request (client, &request))
+ if ( jack_client_deliver_request (client, &request)) {
return NULL;
+ }
- return strdup (request.x.port_info.name);
+ return strdup (request.x.port_info.name);
}
char*
jack_get_uuid_for_client_name (jack_client_t *client, const char *client_name)
{
jack_request_t request;
- size_t len = strlen(client_name) + 1;
- if ( len > sizeof(request.x.name) )
+ size_t len = strlen (client_name) + 1;
+
+ if ( len > sizeof(request.x.name) ) {
return NULL;
+ }
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = GetUUIDByClientName;
- memcpy(request.x.name, client_name, len);
+ memcpy (request.x.name, client_name, len);
- if (jack_client_deliver_request( client, &request)) {
+ if (jack_client_deliver_request ( client, &request)) {
return NULL;
- }
+ }
- char buf[37];
- jack_uuid_unparse (request.x.client_id, buf);
- return strdup (buf);
+ char buf[37];
+ jack_uuid_unparse (request.x.client_id, buf);
+ return strdup (buf);
}
char *
jack_client_get_uuid (jack_client_t *client)
-{
+{
char retval[37];
- jack_uuid_unparse (client->control->uuid, retval);
+
+ jack_uuid_unparse (client->control->uuid, retval);
return strdup (retval);
}
int
jack_reserve_client_name (jack_client_t *client, const char *name, const char *uuid_str)
-{
+{
jack_request_t request;
- VALGRIND_MEMSET (&request, 0, sizeof (request));
+ VALGRIND_MEMSET (&request, 0, sizeof(request));
request.type = ReserveName;
- snprintf( request.x.reservename.name, sizeof( request.x.reservename.name ), "%s", name );
- if (jack_uuid_parse (uuid_str, &request.x.reservename.uuid) != 0) {
- return -1;
- }
+ snprintf ( request.x.reservename.name, sizeof( request.x.reservename.name ), "%s", name );
+ if (jack_uuid_parse (uuid_str, &request.x.reservename.uuid) != 0) {
+ return -1;
+ }
return jack_client_deliver_request (client, &request);
}
@@ -2950,17 +2987,17 @@ jack_get_ports (jack_client_t *client,
if (port_name_pattern && port_name_pattern[0]) {
regcomp (&port_regex, port_name_pattern,
- REG_EXTENDED|REG_NOSUB);
+ REG_EXTENDED | REG_NOSUB);
}
if (type_name_pattern && type_name_pattern[0]) {
regcomp (&type_regex, type_name_pattern,
- REG_EXTENDED|REG_NOSUB);
+ REG_EXTENDED | REG_NOSUB);
}
psp = engine->ports;
match_cnt = 0;
- if ((matching_ports = (const char **) malloc (sizeof (char *) * (engine->port_max + 1))) == NULL) {
+ if ((matching_ports = (const char**)malloc (sizeof(char *) * (engine->port_max + 1))) == NULL) {
return NULL;
}
@@ -2981,7 +3018,7 @@ jack_get_ports (jack_client_t *client,
if (regexec (&port_regex, psp[i].name, 0, NULL, 0)) {
matching = 0;
}
- }
+ }
if (matching && type_name_pattern && type_name_pattern[0]) {
jack_port_type_id_t ptid = psp[i].ptype_id;
@@ -2990,8 +3027,8 @@ jack_get_ports (jack_client_t *client,
0, NULL, 0)) {
matching = 0;
}
- }
-
+ }
+
if (matching) {
matching_ports[match_cnt++] = psp[i].name;
}
@@ -3007,8 +3044,8 @@ jack_get_ports (jack_client_t *client,
free (matching_ports);
matching_ports = 0;
} else {
- matching_ports[match_cnt] = 0;
- }
+ matching_ports[match_cnt] = 0;
+ }
return matching_ports;
}
@@ -3040,28 +3077,28 @@ jack_reset_max_delayed_usecs (jack_client_t *client)
pthread_t
jack_client_thread_id (jack_client_t *client)
{
- if (client->control->type != ClientExternal) {
- /* Internal and driver clients run in ... ??? */
- return 0;
- }
+ if (client->control->type != ClientExternal) {
+ /* Internal and driver clients run in ... ??? */
+ return 0;
+ }
return client->thread_id;
}
int
-jack_client_name_size(void)
+jack_client_name_size (void)
{
return JACK_CLIENT_NAME_SIZE;
}
int
-jack_port_name_size(void)
+jack_port_name_size (void)
{
return JACK_PORT_NAME_SIZE;
}
int
-jack_port_type_size(void)
+jack_port_type_size (void)
{
return JACK_PORT_TYPE_SIZE;
}
@@ -3075,44 +3112,44 @@ jack_free (void* ptr)
const char*
jack_event_type_name (JackEventType type)
{
- switch (type) {
- case BufferSizeChange:
- return "buffer size change";
- case SampleRateChange:
- return "sample rate change";
- case AttachPortSegment:
- return "port segment attached";
- case PortConnected:
- return "ports connected";
- case PortDisconnected:
- return "ports disconnected";
- case GraphReordered:
- return "graph reordered";
- case PortRegistered:
- return "port registered";
- case PortUnregistered:
- return "port unregistered";
- case XRun:
- return "xrun";
- case StartFreewheel:
- return "freewheel started";
- case StopFreewheel:
- return "freewheel stopped";
- case ClientRegistered:
- return "client registered";
- case ClientUnregistered:
- return "client unregistered";
- case SaveSession:
- return "save session";
- case LatencyCallback:
- return "latency callback";
- case PropertyChange:
- return "property change callback";
- case PortRename:
- return "port rename";
- default:
- break;
- }
-
- return "unknown";
+ switch (type) {
+ case BufferSizeChange:
+ return "buffer size change";
+ case SampleRateChange:
+ return "sample rate change";
+ case AttachPortSegment:
+ return "port segment attached";
+ case PortConnected:
+ return "ports connected";
+ case PortDisconnected:
+ return "ports disconnected";
+ case GraphReordered:
+ return "graph reordered";
+ case PortRegistered:
+ return "port registered";
+ case PortUnregistered:
+ return "port unregistered";
+ case XRun:
+ return "xrun";
+ case StartFreewheel:
+ return "freewheel started";
+ case StopFreewheel:
+ return "freewheel stopped";
+ case ClientRegistered:
+ return "client registered";
+ case ClientUnregistered:
+ return "client unregistered";
+ case SaveSession:
+ return "save session";
+ case LatencyCallback:
+ return "latency callback";
+ case PropertyChange:
+ return "property change callback";
+ case PortRename:
+ return "port rename";
+ default:
+ break;
+ }
+
+ return "unknown";
}
diff --git a/libjack/driver.c b/libjack/driver.c
index f5093af..cbffed9 100644
--- a/libjack/driver.c
+++ b/libjack/driver.c
@@ -1,22 +1,22 @@
/* -*- mode: c; c-file-style: "linux"; -*- */
/*
Copyright (C) 2001-2003 Paul Davis
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <config.h>
#include <stdio.h>
@@ -36,22 +36,46 @@
#include <sys/mman.h>
#endif /* USE_MLOCK */
-static int dummy_attach (jack_driver_t *drv, jack_engine_t *eng) { return 0; }
-static int dummy_detach (jack_driver_t *drv, jack_engine_t *eng) { return 0; }
+static int dummy_attach (jack_driver_t *drv, jack_engine_t *eng)
+{
+ return 0;
+}
+static int dummy_detach (jack_driver_t *drv, jack_engine_t *eng)
+{
+ return 0;
+}
static int dummy_write (jack_driver_t *drv,
- jack_nframes_t nframes) { return 0; }
-static int dummy_read (jack_driver_t *drv, jack_nframes_t nframes) { return 0; }
+ jack_nframes_t nframes)
+{
+ return 0;
+}
+static int dummy_read (jack_driver_t *drv, jack_nframes_t nframes)
+{
+ return 0;
+}
static int dummy_null_cycle (jack_driver_t *drv,
- jack_nframes_t nframes) { return 0; }
+ jack_nframes_t nframes)
+{
+ return 0;
+}
static int dummy_bufsize (jack_driver_t *drv,
- jack_nframes_t nframes) {return 0;}
-static int dummy_stop (jack_driver_t *drv) { return 0; }
-static int dummy_start (jack_driver_t *drv) { return 0; }
+ jack_nframes_t nframes)
+{
+ return 0;
+}
+static int dummy_stop (jack_driver_t *drv)
+{
+ return 0;
+}
+static int dummy_start (jack_driver_t *drv)
+{
+ return 0;
+}
void
jack_driver_init (jack_driver_t *driver)
{
- memset (driver, 0, sizeof (*driver));
+ memset (driver, 0, sizeof(*driver));
driver->attach = dummy_attach;
driver->detach = dummy_detach;
@@ -66,12 +90,21 @@ jack_driver_init (jack_driver_t *driver)
/****************************
- *** Non-Threaded Drivers ***
- ****************************/
+*** Non-Threaded Drivers ***
+****************************/
-static int dummy_nt_run_cycle (jack_driver_nt_t *drv) { return 0; }
-static int dummy_nt_attach (jack_driver_nt_t *drv) { return 0; }
-static int dummy_nt_detach (jack_driver_nt_t *drv) { return 0; }
+static int dummy_nt_run_cycle (jack_driver_nt_t *drv)
+{
+ return 0;
+}
+static int dummy_nt_attach (jack_driver_nt_t *drv)
+{
+ return 0;
+}
+static int dummy_nt_detach (jack_driver_nt_t *drv)
+{
+ return 0;
+}
/*
@@ -104,16 +137,16 @@ jack_driver_nt_detach (jack_driver_nt_t * driver, jack_engine_t * engine)
static void *
jack_driver_nt_thread (void * arg)
{
- jack_driver_nt_t * driver = (jack_driver_nt_t *) arg;
+ jack_driver_nt_t * driver = (jack_driver_nt_t*)arg;
int rc = 0;
int run;
/* This thread may start running before pthread_create()
* actually stores the driver->nt_thread value. It's safer to
- * store it here as well.
+ * store it here as well.
*/
- driver->nt_thread = pthread_self();
+ driver->nt_thread = pthread_self ();
pthread_mutex_lock (&driver->nt_run_lock);
@@ -130,7 +163,7 @@ jack_driver_nt_thread (void * arg)
pthread_mutex_unlock (&driver->nt_run_lock);
- out:
+out:
if (rc) {
driver->nt_run = DRIVER_NT_DYING;
driver->engine->driver_exit (driver->engine);
@@ -145,13 +178,13 @@ jack_driver_nt_start (jack_driver_nt_t * driver)
/* stop the new thread from really starting until the driver has
been started.
- */
-
+ */
+
pthread_mutex_lock (&driver->nt_run_lock);
driver->nt_run = DRIVER_NT_RUN;
if ((err = jack_client_create_thread (NULL,
- &driver->nt_thread,
+ &driver->nt_thread,
driver->engine->rtpriority,
driver->engine->control->real_time,
jack_driver_nt_thread, driver)) != 0) {
@@ -180,7 +213,7 @@ jack_driver_nt_do_stop (jack_driver_nt_t * driver, int run)
int err;
pthread_mutex_lock (&driver->nt_run_lock);
- if(driver->nt_run != DRIVER_NT_DYING) {
+ if (driver->nt_run != DRIVER_NT_DYING) {
driver->nt_run = run;
}
pthread_mutex_unlock (&driver->nt_run_lock);
@@ -189,7 +222,7 @@ jack_driver_nt_do_stop (jack_driver_nt_t * driver, int run)
if (driver->nt_thread && driver->nt_run != DRIVER_NT_DYING
&& (err = pthread_join (driver->nt_thread, NULL)) != 0) {
jack_error ("DRIVER NT: error waiting for driver thread: %s",
- strerror (err));
+ strerror (err));
return err;
}
@@ -235,19 +268,19 @@ jack_driver_nt_bufsize (jack_driver_nt_t * driver, jack_nframes_t nframes)
void
jack_driver_nt_init (jack_driver_nt_t * driver)
{
- memset (driver, 0, sizeof (*driver));
+ memset (driver, 0, sizeof(*driver));
- jack_driver_init ((jack_driver_t *) driver);
+ jack_driver_init ((jack_driver_t*)driver);
- driver->attach = (JackDriverAttachFunction) jack_driver_nt_attach;
- driver->detach = (JackDriverDetachFunction) jack_driver_nt_detach;
- driver->bufsize = (JackDriverBufSizeFunction) jack_driver_nt_bufsize;
- driver->stop = (JackDriverStopFunction) jack_driver_nt_stop;
- driver->start = (JackDriverStartFunction) jack_driver_nt_start;
+ driver->attach = (JackDriverAttachFunction)jack_driver_nt_attach;
+ driver->detach = (JackDriverDetachFunction)jack_driver_nt_detach;
+ driver->bufsize = (JackDriverBufSizeFunction)jack_driver_nt_bufsize;
+ driver->stop = (JackDriverStopFunction)jack_driver_nt_stop;
+ driver->start = (JackDriverStartFunction)jack_driver_nt_start;
- driver->nt_bufsize = (JackDriverNTBufSizeFunction) dummy_bufsize;
- driver->nt_start = (JackDriverNTStartFunction) dummy_start;
- driver->nt_stop = (JackDriverNTStopFunction) dummy_stop;
+ driver->nt_bufsize = (JackDriverNTBufSizeFunction)dummy_bufsize;
+ driver->nt_start = (JackDriverNTStartFunction)dummy_start;
+ driver->nt_stop = (JackDriverNTStopFunction)dummy_stop;
driver->nt_attach = dummy_nt_attach;
driver->nt_detach = dummy_nt_detach;
driver->nt_run_cycle = dummy_nt_run_cycle;
@@ -257,7 +290,7 @@ jack_driver_nt_init (jack_driver_nt_t * driver)
}
void
-jack_driver_nt_finish (jack_driver_nt_t * driver)
+jack_driver_nt_finish (jack_driver_nt_t * driver)
{
pthread_mutex_destroy (&driver->nt_run_lock);
}
diff --git a/libjack/intclient.c b/libjack/intclient.c
index e06722b..cc8d1e3 100644
--- a/libjack/intclient.c
+++ b/libjack/intclient.c
@@ -1,19 +1,19 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
* Copyright (C) 2004 Jack O'Quin
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
@@ -34,59 +34,62 @@
#include "local.h"
static int
-jack_intclient_request(RequestType type, jack_client_t *client,
- const char* client_name, jack_options_t options,
- jack_status_t *status, jack_intclient_t uuid, jack_varargs_t *va)
+jack_intclient_request (RequestType type, jack_client_t *client,
+ const char* client_name, jack_options_t options,
+ jack_status_t *status, jack_intclient_t uuid, jack_varargs_t *va)
{
jack_request_t req;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
- if (strlen (client_name) >= sizeof (req.x.intclient.name)) {
+ if (strlen (client_name) >= sizeof(req.x.intclient.name)) {
jack_error ("\"%s\" is too long for a JACK client name.\n"
"Please use %lu characters or less.",
- client_name, sizeof (req.x.intclient.name));
+ client_name, sizeof(req.x.intclient.name));
return -1;
}
if (va->load_name
- && (strlen (va->load_name) > sizeof (req.x.intclient.path) - 1)) {
+ && (strlen (va->load_name) > sizeof(req.x.intclient.path) - 1)) {
jack_error ("\"%s\" is too long for a shared object name.\n"
- "Please use %lu characters or less.",
- va->load_name, sizeof (req.x.intclient.path) - 1);
- *status |= (JackFailure|JackInvalidOption);
+ "Please use %lu characters or less.",
+ va->load_name, sizeof(req.x.intclient.path) - 1);
+ *status |= (JackFailure | JackInvalidOption);
return -1;
}
if (va->load_init
- && (strlen (va->load_init) > sizeof (req.x.intclient.init) - 1)) {
+ && (strlen (va->load_init) > sizeof(req.x.intclient.init) - 1)) {
jack_error ("\"%s\" is too long for internal client init "
"string.\nPlease use %lu characters or less.",
- va->load_init, sizeof (req.x.intclient.init) - 1);
- *status |= (JackFailure|JackInvalidOption);
+ va->load_init, sizeof(req.x.intclient.init) - 1);
+ *status |= (JackFailure | JackInvalidOption);
return -1;
}
req.type = type;
req.x.intclient.options = options;
strncpy (req.x.intclient.name, client_name,
- sizeof (req.x.intclient.name));
- if (va->load_name)
+ sizeof(req.x.intclient.name));
+ if (va->load_name) {
strncpy (req.x.intclient.path, va->load_name,
- sizeof (req.x.intclient.path));
- if (va->load_init)
+ sizeof(req.x.intclient.path));
+ }
+ if (va->load_init) {
strncpy (req.x.intclient.init, va->load_init,
- sizeof (req.x.intclient.init));
+ sizeof(req.x.intclient.init));
+ }
jack_client_deliver_request (client, &req);
*status |= req.status;
- if (*status & JackFailure)
+ if (*status & JackFailure) {
return -1;
+ }
jack_uuid_copy (&uuid, req.x.intclient.uuid);
- return 0;
+ return 0;
}
char *
@@ -96,7 +99,7 @@ jack_get_internal_client_name (jack_client_t *client,
jack_request_t req;
char *name;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.type = IntClientName;
req.x.intclient.options = JackNullOption;
jack_uuid_copy (&req.x.intclient.uuid, intclient);
@@ -119,48 +122,50 @@ int
jack_internal_client_handle (jack_client_t *client,
const char *client_name,
jack_status_t *status,
- jack_intclient_t *handle)
+ jack_intclient_t *handle)
{
jack_request_t req;
jack_status_t my_status;
- if (status == NULL) /* no status from caller? */
- status = &my_status; /* use local status word */
+ if (status == NULL) { /* no status from caller? */
+ status = &my_status; /* use local status word */
+ }
*status = 0;
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.type = IntClientHandle;
req.x.intclient.options = JackNullOption;
strncpy (req.x.intclient.name, client_name,
- sizeof (req.x.intclient.name));
+ sizeof(req.x.intclient.name));
*status = jack_client_deliver_request (client, &req);
- if (!jack_uuid_empty (req.x.intclient.uuid)) {
- jack_uuid_copy (handle, req.x.intclient.uuid);
- return 0;
- }
+ if (!jack_uuid_empty (req.x.intclient.uuid)) {
+ jack_uuid_copy (handle, req.x.intclient.uuid);
+ return 0;
+ }
- return -1;
+ return -1;
}
int
jack_internal_client_load_aux (jack_client_t *client,
- const char *client_name,
- jack_options_t options,
- jack_status_t *status,
- jack_intclient_t handle, va_list ap)
+ const char *client_name,
+ jack_options_t options,
+ jack_status_t *status,
+ jack_intclient_t handle, va_list ap)
{
jack_varargs_t va;
jack_status_t my_status;
- if (status == NULL) /* no status from caller? */
- status = &my_status; /* use local status word */
+ if (status == NULL) { /* no status from caller? */
+ status = &my_status; /* use local status word */
+ }
*status = 0;
/* validate parameters */
if ((options & ~JackLoadOptions)) {
- *status |= (JackFailure|JackInvalidOption);
+ *status |= (JackFailure | JackInvalidOption);
return -1;
}
@@ -175,14 +180,15 @@ int
jack_internal_client_load (jack_client_t *client,
const char *client_name,
jack_options_t options,
- jack_status_t *status,
- jack_intclient_t handle, ...)
+ jack_status_t *status,
+ jack_intclient_t handle, ...)
{
- va_list ap;
- va_start(ap, handle);
- int res = jack_internal_client_load_aux(client, client_name, options, status, handle, ap);
- va_end(ap);
- return res;
+ va_list ap;
+
+ va_start (ap, handle);
+ int res = jack_internal_client_load_aux (client, client_name, options, status, handle, ap);
+ va_end (ap);
+ return res;
}
jack_status_t
@@ -194,15 +200,15 @@ jack_internal_client_unload (jack_client_t *client,
if (intclient) {
- memset (&req, 0, sizeof (req));
+ memset (&req, 0, sizeof(req));
req.type = IntClientUnload;
req.x.intclient.options = JackNullOption;
jack_uuid_copy (&req.x.intclient.uuid, intclient);
jack_client_deliver_request (client, &req);
status = req.status;
- } else { /* intclient is null */
- status = (JackNoSuchClient|JackFailure);
+ } else { /* intclient is null */
+ status = (JackNoSuchClient | JackFailure);
}
return status;
diff --git a/libjack/local.h b/libjack/local.h
index 3f7f074..c90d7b0 100644
--- a/libjack/local.h
+++ b/libjack/local.h
@@ -4,100 +4,100 @@
/* Client data structure, in the client address space. */
struct _jack_client {
- jack_control_t *engine;
- jack_client_control_t *control;
- jack_shm_info_t engine_shm;
- jack_shm_info_t control_shm;
+ jack_control_t *engine;
+ jack_client_control_t *control;
+ jack_shm_info_t engine_shm;
+ jack_shm_info_t control_shm;
- struct pollfd* pollfd;
- int pollmax;
- int graph_next_fd;
- int request_fd;
- int upstream_is_jackd;
+ struct pollfd* pollfd;
+ int pollmax;
+ int graph_next_fd;
+ int request_fd;
+ int upstream_is_jackd;
- /* these two are copied from the engine when the
- * client is created.
- */
+ /* these two are copied from the engine when the
+ * client is created.
+ */
- jack_port_type_id_t n_port_types;
- jack_shm_info_t* port_segment;
+ jack_port_type_id_t n_port_types;
+ jack_shm_info_t* port_segment;
- JSList *ports;
- JSList *ports_ext;
+ JSList *ports;
+ JSList *ports_ext;
- pthread_t thread;
- char fifo_prefix[PATH_MAX+1];
- void (*on_shutdown)(void *arg);
- void *on_shutdown_arg;
- void (*on_info_shutdown)(jack_status_t, const char*, void *arg);
- void *on_info_shutdown_arg;
- char thread_ok : 1;
- char first_active : 1;
- pthread_t thread_id;
- char name[JACK_CLIENT_NAME_SIZE];
- int session_cb_immediate_reply;
+ pthread_t thread;
+ char fifo_prefix[PATH_MAX + 1];
+ void (*on_shutdown)(void *arg);
+ void *on_shutdown_arg;
+ void (*on_info_shutdown)(jack_status_t, const char*, void *arg);
+ void *on_info_shutdown_arg;
+ char thread_ok : 1;
+ char first_active : 1;
+ pthread_t thread_id;
+ char name[JACK_CLIENT_NAME_SIZE];
+ int session_cb_immediate_reply;
#ifdef JACK_USE_MACH_THREADS
- /* specific ressources for server/client real-time thread communication */
- mach_port_t clienttask, bp, serverport, replyport;
- trivial_message message;
- pthread_t process_thread;
- char rt_thread_ok : 1;
+ /* specific ressources for server/client real-time thread communication */
+ mach_port_t clienttask, bp, serverport, replyport;
+ trivial_message message;
+ pthread_t process_thread;
+ char rt_thread_ok : 1;
#endif
- /* callbacks
- */
- JackProcessCallback process;
- void *process_arg;
- JackThreadInitCallback thread_init;
- void *thread_init_arg;
- JackBufferSizeCallback bufsize;
- void *bufsize_arg;
- JackSampleRateCallback srate;
- void *srate_arg;
- JackPortRegistrationCallback port_register;
- void *port_register_arg;
- JackPortConnectCallback port_connect;
- void *port_connect_arg;
- JackGraphOrderCallback graph_order;
- void *graph_order_arg;
- JackXRunCallback xrun;
- void *xrun_arg;
- JackSyncCallback sync_cb;
- void *sync_arg;
- JackTimebaseCallback timebase_cb;
- void *timebase_arg;
- JackFreewheelCallback freewheel_cb;
- void *freewheel_arg;
- JackClientRegistrationCallback client_register;
- void *client_register_arg;
- JackThreadCallback thread_cb;
- void *thread_cb_arg;
- JackSessionCallback session_cb;
- void *session_cb_arg;
- JackLatencyCallback latency_cb;
- void *latency_cb_arg;
- JackPropertyChangeCallback property_cb;
- void *property_cb_arg;
- JackPortRenameCallback port_rename_cb;
- void *port_rename_arg;
+ /* callbacks
+ */
+ JackProcessCallback process;
+ void *process_arg;
+ JackThreadInitCallback thread_init;
+ void *thread_init_arg;
+ JackBufferSizeCallback bufsize;
+ void *bufsize_arg;
+ JackSampleRateCallback srate;
+ void *srate_arg;
+ JackPortRegistrationCallback port_register;
+ void *port_register_arg;
+ JackPortConnectCallback port_connect;
+ void *port_connect_arg;
+ JackGraphOrderCallback graph_order;
+ void *graph_order_arg;
+ JackXRunCallback xrun;
+ void *xrun_arg;
+ JackSyncCallback sync_cb;
+ void *sync_arg;
+ JackTimebaseCallback timebase_cb;
+ void *timebase_arg;
+ JackFreewheelCallback freewheel_cb;
+ void *freewheel_arg;
+ JackClientRegistrationCallback client_register;
+ void *client_register_arg;
+ JackThreadCallback thread_cb;
+ void *thread_cb_arg;
+ JackSessionCallback session_cb;
+ void *session_cb_arg;
+ JackLatencyCallback latency_cb;
+ void *latency_cb_arg;
+ JackPropertyChangeCallback property_cb;
+ void *property_cb_arg;
+ JackPortRenameCallback port_rename_cb;
+ void *port_rename_arg;
- /* external clients: set by libjack
- * internal clients: set by engine */
- int (*deliver_request)(void*, jack_request_t*); /* JOQ: 64/32 bug! */
- void *deliver_arg;
+ /* external clients: set by libjack
+ * internal clients: set by engine */
+ int (*deliver_request)(void*, jack_request_t*); /* JOQ: 64/32 bug! */
+ void *deliver_arg;
};
-extern int jack_client_deliver_request (const jack_client_t *client,
- jack_request_t *req);
-extern jack_port_t *jack_port_new (const jack_client_t *client,
- jack_port_id_t port_id,
- jack_control_t *control);
+extern int jack_client_deliver_request(const jack_client_t *client,
+ jack_request_t *req);
+extern jack_port_t *jack_port_new(const jack_client_t *client,
+ jack_port_id_t port_id,
+ jack_control_t *control);
extern void *jack_zero_filled_buffer;
extern void jack_set_clock_source (jack_timer_type_t);
-extern char* jack_server_dir (const char* server_name, char* server_dir);
+extern char* jack_server_dir(const char* server_name, char* server_dir);
#endif /* __jack_libjack_local_h__ */
diff --git a/libjack/messagebuffer.c b/libjack/messagebuffer.c
index f0fc4fb..5f9541a 100644
--- a/libjack/messagebuffer.c
+++ b/libjack/messagebuffer.c
@@ -13,14 +13,14 @@
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
@@ -36,9 +36,9 @@
#include "internal.h"
/* MB_NEXT() relies on the fact that MB_BUFFERS is a power of two */
-#define MB_BUFFERS 128
-#define MB_NEXT(index) ((index+1) & (MB_BUFFERS-1))
-#define MB_BUFFERSIZE 256 /* message length limit */
+#define MB_BUFFERS 128
+#define MB_NEXT(index) ((index + 1) & (MB_BUFFERS - 1))
+#define MB_BUFFERSIZE 256 /* message length limit */
static char mb_buffers[MB_BUFFERS][MB_BUFFERSIZE];
static volatile unsigned int mb_initialized = 0;
@@ -52,112 +52,116 @@ static void (*mb_thread_init_callback)(void*) = 0;
static void* mb_thread_init_callback_arg = 0;
static void
-mb_flush()
+mb_flush ()
{
/* called WITHOUT the mb_write_lock */
while (mb_outbuffer != mb_inbuffer) {
- jack_info(mb_buffers[mb_outbuffer]);
- mb_outbuffer = MB_NEXT(mb_outbuffer);
+ jack_info (mb_buffers[mb_outbuffer]);
+ mb_outbuffer = MB_NEXT (mb_outbuffer);
}
}
static void *
-mb_thread_func(void *arg)
+mb_thread_func (void *arg)
{
/* The mutex is only to eliminate collisions between multiple
* writer threads and protect the condition variable. */
- pthread_mutex_lock(&mb_write_lock);
+ pthread_mutex_lock (&mb_write_lock);
while (mb_initialized) {
- pthread_cond_wait(&mb_ready_cond, &mb_write_lock);
+ pthread_cond_wait (&mb_ready_cond, &mb_write_lock);
if (mb_thread_init_callback) {
/* the client asked for all threads to run a thread
initialization callback, which includes us.
- */
+ */
mb_thread_init_callback (mb_thread_init_callback_arg);
mb_thread_init_callback = 0;
/* note that we've done it */
- pthread_cond_signal(&mb_ready_cond);
+ pthread_cond_signal (&mb_ready_cond);
}
/* releasing the mutex reduces contention */
- pthread_mutex_unlock(&mb_write_lock);
- mb_flush();
- pthread_mutex_lock(&mb_write_lock);
+ pthread_mutex_unlock (&mb_write_lock);
+ mb_flush ();
+ pthread_mutex_lock (&mb_write_lock);
}
- pthread_mutex_unlock(&mb_write_lock);
+ pthread_mutex_unlock (&mb_write_lock);
return NULL;
}
-void
+void
jack_messagebuffer_init ()
{
- if (mb_initialized)
+ if (mb_initialized) {
return;
+ }
- pthread_mutex_init(&mb_write_lock, NULL);
- pthread_cond_init(&mb_ready_cond, NULL);
+ pthread_mutex_init (&mb_write_lock, NULL);
+ pthread_cond_init (&mb_ready_cond, NULL);
mb_overruns = 0;
mb_initialized = 1;
- if (jack_thread_creator (&mb_writer_thread, NULL, &mb_thread_func, NULL) != 0)
+ if (jack_thread_creator (&mb_writer_thread, NULL, &mb_thread_func, NULL) != 0) {
mb_initialized = 0;
+ }
}
-void
+void
jack_messagebuffer_exit ()
{
- if (!mb_initialized)
+ if (!mb_initialized) {
return;
+ }
- pthread_mutex_lock(&mb_write_lock);
+ pthread_mutex_lock (&mb_write_lock);
mb_initialized = 0;
- pthread_cond_signal(&mb_ready_cond);
- pthread_mutex_unlock(&mb_write_lock);
+ pthread_cond_signal (&mb_ready_cond);
+ pthread_mutex_unlock (&mb_write_lock);
- pthread_join(mb_writer_thread, NULL);
- mb_flush();
+ pthread_join (mb_writer_thread, NULL);
+ mb_flush ();
- if (mb_overruns)
- jack_error("WARNING: %d message buffer overruns!",
- mb_overruns);
+ if (mb_overruns) {
+ jack_error ("WARNING: %d message buffer overruns!",
+ mb_overruns);
+ }
- pthread_mutex_destroy(&mb_write_lock);
- pthread_cond_destroy(&mb_ready_cond);
+ pthread_mutex_destroy (&mb_write_lock);
+ pthread_cond_destroy (&mb_ready_cond);
}
-void
+void
jack_messagebuffer_add (const char *fmt, ...)
{
char msg[MB_BUFFERSIZE];
va_list ap;
/* format the message first, to reduce lock contention */
- va_start(ap, fmt);
- vsnprintf(msg, MB_BUFFERSIZE, fmt, ap);
- va_end(ap);
+ va_start (ap, fmt);
+ vsnprintf (msg, MB_BUFFERSIZE, fmt, ap);
+ va_end (ap);
if (!mb_initialized) {
/* Unable to print message with realtime safety.
* Complain and print it anyway. */
- fprintf(stderr, "ERROR: messagebuffer not initialized: %s",
- msg);
+ fprintf (stderr, "ERROR: messagebuffer not initialized: %s",
+ msg);
return;
}
- if (pthread_mutex_trylock(&mb_write_lock) == 0) {
- strncpy(mb_buffers[mb_inbuffer], msg, MB_BUFFERSIZE);
- mb_inbuffer = MB_NEXT(mb_inbuffer);
- pthread_cond_signal(&mb_ready_cond);
- pthread_mutex_unlock(&mb_write_lock);
- } else { /* lock collision */
- atomic_add(&mb_overruns, 1);
+ if (pthread_mutex_trylock (&mb_write_lock) == 0) {
+ strncpy (mb_buffers[mb_inbuffer], msg, MB_BUFFERSIZE);
+ mb_inbuffer = MB_NEXT (mb_inbuffer);
+ pthread_cond_signal (&mb_ready_cond);
+ pthread_mutex_unlock (&mb_write_lock);
+ } else { /* lock collision */
+ atomic_add (&mb_overruns, 1);
}
}
@@ -171,11 +175,11 @@ jack_messagebuffer_thread_init (void (*cb)(void*), void* arg)
mb_thread_init_callback = cb;
/* wake msg buffer thread */
- pthread_cond_signal(&mb_ready_cond);
+ pthread_cond_signal (&mb_ready_cond);
/* wait for it to be done */
- pthread_cond_wait(&mb_ready_cond, &mb_write_lock);
+ pthread_cond_wait (&mb_ready_cond, &mb_write_lock);
/* and we're done */
pthread_mutex_unlock (&mb_write_lock);
-}
+}
diff --git a/libjack/metadata.c b/libjack/metadata.c
index a12778f..226ac1d 100644
--- a/libjack/metadata.c
+++ b/libjack/metadata.c
@@ -1,20 +1,20 @@
/*
- Copyright (C) 2013 Paul Davis
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or (at
- your option) any later version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ Copyright (C) 2013 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include <string.h>
#include <db.h>
@@ -39,519 +39,551 @@ static DB_ENV* db_env = NULL;
static int
jack_property_init (const char* server_name)
{
- int ret;
- char dbpath[PATH_MAX+1];
- char server_dir[PATH_MAX+1];
-
- /* idempotent */
-
- if (db_env) {
- return 0;
- }
-
- if ((ret = db_env_create(&db_env, 0)) != 0) {
- jack_error ("cannot initialize DB environment: %s\n", db_strerror(ret));
- return -1;
- }
-
- if ((ret = db_env->open(db_env, jack_server_dir (server_name, server_dir), DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_THREAD, 0)) != 0) {
- jack_error ("cannot open DB environment: %s", db_strerror (ret));
- return -1;
- }
-
- if ((ret = db_create (&db, db_env, 0)) != 0) {
- jack_error ("Cannot initialize metadata DB (%s)", db_strerror (ret));
- return -1;
- }
-
- snprintf (dbpath, sizeof (dbpath), "%s/%s", jack_server_dir (server_name, server_dir), "metadata.db");
-
- if ((ret = db->open (db, NULL, dbpath, NULL, DB_HASH, DB_CREATE|DB_THREAD, 0666)) != 0) {
- jack_error ("Cannot open metadata DB at %s: %s", dbpath, db_strerror (ret));
- db->close (db, 0);
- db = NULL;
- return -1;
- }
-
- return 0;
+ int ret;
+ char dbpath[PATH_MAX + 1];
+ char server_dir[PATH_MAX + 1];
+
+ /* idempotent */
+
+ if (db_env) {
+ return 0;
+ }
+
+ if ((ret = db_env_create (&db_env, 0)) != 0) {
+ jack_error ("cannot initialize DB environment: %s\n", db_strerror (ret));
+ return -1;
+ }
+
+ if ((ret = db_env->open (db_env, jack_server_dir (server_name, server_dir), DB_CREATE | DB_INIT_LOCK | DB_INIT_MPOOL | DB_THREAD, 0)) != 0) {
+ jack_error ("cannot open DB environment: %s", db_strerror (ret));
+ return -1;
+ }
+
+ if ((ret = db_create (&db, db_env, 0)) != 0) {
+ jack_error ("Cannot initialize metadata DB (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ snprintf (dbpath, sizeof(dbpath), "%s/%s", jack_server_dir (server_name, server_dir), "metadata.db");
+
+ if ((ret = db->open (db, NULL, dbpath, NULL, DB_HASH, DB_CREATE | DB_THREAD, 0666)) != 0) {
+ jack_error ("Cannot open metadata DB at %s: %s", dbpath, db_strerror (ret));
+ db->close (db, 0);
+ db = NULL;
+ return -1;
+ }
+
+ return 0;
}
-static void jack_properties_uninit () __attribute__ ((destructor));
+static void jack_properties_uninit() __attribute__ ((destructor));
void
jack_properties_uninit ()
{
- if (db) {
- db->close (db, 0);
- db = NULL;
- }
- if (db_env) {
- db_env->close (db_env, 0);
- db_env = 0;
- }
+ if (db) {
+ db->close (db, 0);
+ db = NULL;
+ }
+ if (db_env) {
+ db_env->close (db_env, 0);
+ db_env = 0;
+ }
}
void
-jack_free_description(jack_description_t* desc, int free_actual_description_too)
+jack_free_description (jack_description_t* desc, int free_actual_description_too)
{
- uint32_t n;
-
- for (n = 0; n < desc->property_cnt; ++n) {
- free ((char*) desc->properties[n].key);
- free ((char*) desc->properties[n].data);
- if (desc->properties[n].type) {
- free ((char*) desc->properties[n].type);
- }
- }
+ uint32_t n;
+
+ for (n = 0; n < desc->property_cnt; ++n) {
+ free ((char*)desc->properties[n].key);
+ free ((char*)desc->properties[n].data);
+ if (desc->properties[n].type) {
+ free ((char*)desc->properties[n].type);
+ }
+ }
- free (desc->properties);
+ free (desc->properties);
- if (free_actual_description_too) {
- free (desc);
- }
+ if (free_actual_description_too) {
+ free (desc);
+ }
}
static int
jack_property_change_notify (jack_client_t* client, jack_uuid_t uuid, const char* key, jack_property_change_t change)
{
- jack_request_t req;
+ jack_request_t req;
- /* the engine passes in a NULL client when it removes metadata during port or client removal
- */
+ /* the engine passes in a NULL client when it removes metadata during port or client removal
+ */
- if (client == NULL) {
- return 0;
- }
+ if (client == NULL) {
+ return 0;
+ }
- req.type = PropertyChangeNotify;
- req.x.property.change = change;
- jack_uuid_copy (&req.x.property.uuid, uuid);
- req.x.property.keylen = key ? strlen (key) + 1 : 0;
- req.x.property.key = key;
- return jack_client_deliver_request (client, &req);
+ req.type = PropertyChangeNotify;
+ req.x.property.change = change;
+ jack_uuid_copy (&req.x.property.uuid, uuid);
+ req.x.property.keylen = key ? strlen (key) + 1 : 0;
+ req.x.property.key = key;
+ return jack_client_deliver_request (client, &req);
}
static void
make_key_dbt (DBT* dbt, jack_uuid_t subject, const char* key)
{
- char ustr[JACK_UUID_STRING_SIZE];
- size_t len1, len2;
-
- memset(dbt, 0, sizeof(DBT));
- memset(ustr, 0, JACK_UUID_STRING_SIZE);
- jack_uuid_unparse (subject, ustr);
- len1 = JACK_UUID_STRING_SIZE;
- len2 = strlen (key) + 1;
- dbt->size = len1 + len2;
- dbt->data = malloc (dbt->size);
- memcpy (dbt->data, ustr, len1); // copy subject+null
- memcpy (dbt->data + len1, key, len2); // copy key+null
+ char ustr[JACK_UUID_STRING_SIZE];
+ size_t len1, len2;
+
+ memset (dbt, 0, sizeof(DBT));
+ memset (ustr, 0, JACK_UUID_STRING_SIZE);
+ jack_uuid_unparse (subject, ustr);
+ len1 = JACK_UUID_STRING_SIZE;
+ len2 = strlen (key) + 1;
+ dbt->size = len1 + len2;
+ dbt->data = malloc (dbt->size);
+ memcpy (dbt->data, ustr, len1); // copy subject+null
+ memcpy (dbt->data + len1, key, len2); // copy key+null
}
int
jack_set_property (jack_client_t* client,
- jack_uuid_t subject,
- const char* key,
- const char* value,
- const char* type)
+ jack_uuid_t subject,
+ const char* key,
+ const char* value,
+ const char* type)
{
- DBT d_key;
- DBT data;
- int ret;
- size_t len1, len2;
- jack_property_change_t change;
-
- if (!key || key[0] == '\0') {
- jack_error ("empty key string for metadata not allowed");
- return -1;
- }
-
- if (!value || value[0] == '\0') {
- jack_error ("empty value string for metadata not allowed");
- return -1;
- }
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- /* build a key */
-
- make_key_dbt (&d_key, subject, key);
-
- /* build data */
-
- memset(&data, 0, sizeof(data));
-
- len1 = strlen(value) + 1;
- if (type && type[0] != '\0') {
- len2 = strlen(type) + 1;
- } else {
- len2 = 0;
- }
-
- data.size = len1 + len2;
- data.data = malloc (data.size);
- memcpy (data.data, value, len1);
-
- if (len2) {
- memcpy (data.data + len1, type, len2);
- }
-
- if (db->exists (db, NULL, &d_key, 0) == DB_NOTFOUND) {
- change = PropertyCreated;
- } else {
- change = PropertyChanged;
- }
-
- if ((ret = db->put (db, NULL, &d_key, &data, 0)) != 0) {
- char ustr[JACK_UUID_STRING_SIZE];
- jack_uuid_unparse (subject, ustr);
- jack_error ("Cannot store metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
- return -1;
- }
-
- jack_property_change_notify (client, subject, key, change);
-
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
-
- return 0;
+ DBT d_key;
+ DBT data;
+ int ret;
+ size_t len1, len2;
+ jack_property_change_t change;
+
+ if (!key || key[0] == '\0') {
+ jack_error ("empty key string for metadata not allowed");
+ return -1;
+ }
+
+ if (!value || value[0] == '\0') {
+ jack_error ("empty value string for metadata not allowed");
+ return -1;
+ }
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ /* build a key */
+
+ make_key_dbt (&d_key, subject, key);
+
+ /* build data */
+
+ memset (&data, 0, sizeof(data));
+
+ len1 = strlen (value) + 1;
+ if (type && type[0] != '\0') {
+ len2 = strlen (type) + 1;
+ } else {
+ len2 = 0;
+ }
+
+ data.size = len1 + len2;
+ data.data = malloc (data.size);
+ memcpy (data.data, value, len1);
+
+ if (len2) {
+ memcpy (data.data + len1, type, len2);
+ }
+
+ if (db->exists (db, NULL, &d_key, 0) == DB_NOTFOUND) {
+ change = PropertyCreated;
+ } else {
+ change = PropertyChanged;
+ }
+
+ if ((ret = db->put (db, NULL, &d_key, &data, 0)) != 0) {
+ char ustr[JACK_UUID_STRING_SIZE];
+ jack_uuid_unparse (subject, ustr);
+ jack_error ("Cannot store metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+ return -1;
+ }
+
+ jack_property_change_notify (client, subject, key, change);
+
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+
+ return 0;
}
int
jack_get_property (jack_uuid_t subject,
- const char* key,
- char** value,
- char** type)
+ const char* key,
+ char** value,
+ char** type)
{
- DBT d_key;
- DBT data;
- int ret;
- size_t len1, len2;
-
- if (key == NULL || key[0] == '\0') {
- return -1;
- }
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- /* build a key */
-
- make_key_dbt (&d_key, subject, key);
-
- /* setup data DBT */
-
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- if ((ret = db->get (db, NULL, &d_key, &data, 0)) != 0) {
- if (ret != DB_NOTFOUND) {
- char ustr[JACK_UUID_STRING_SIZE];
- jack_uuid_unparse (subject, ustr);
- jack_error ("Cannot metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
- }
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
- return -1;
- }
-
- /* result must have at least 2 chars plus 2 nulls to be valid
- */
-
- if (data.size < 4) {
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
- return -1;
- }
-
- len1 = strlen (data.data) + 1;
- (*value) = (char *) malloc (len1);
- memcpy (*value, data.data, len1);
-
- if (len1 < data.size) {
- len2 = strlen (data.data+len1) + 1;
-
- (*type) = (char *) malloc (len2);
- memcpy (*type, data.data+len1, len2);
- } else {
- /* no type specified, assume default */
- *type = NULL;
- }
-
- if (d_key.size > 0) free(d_key.data);
- if (data.size > 0) free(data.data);
-
- return 0;
+ DBT d_key;
+ DBT data;
+ int ret;
+ size_t len1, len2;
+
+ if (key == NULL || key[0] == '\0') {
+ return -1;
+ }
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ /* build a key */
+
+ make_key_dbt (&d_key, subject, key);
+
+ /* setup data DBT */
+
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ if ((ret = db->get (db, NULL, &d_key, &data, 0)) != 0) {
+ if (ret != DB_NOTFOUND) {
+ char ustr[JACK_UUID_STRING_SIZE];
+ jack_uuid_unparse (subject, ustr);
+ jack_error ("Cannot metadata for %s/%s (%s)", ustr, key, db_strerror (ret));
+ }
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+ return -1;
+ }
+
+ /* result must have at least 2 chars plus 2 nulls to be valid
+ */
+
+ if (data.size < 4) {
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+ return -1;
+ }
+
+ len1 = strlen (data.data) + 1;
+ (*value) = (char*)malloc (len1);
+ memcpy (*value, data.data, len1);
+
+ if (len1 < data.size) {
+ len2 = strlen (data.data + len1) + 1;
+
+ (*type) = (char*)malloc (len2);
+ memcpy (*type, data.data + len1, len2);
+ } else {
+ /* no type specified, assume default */
+ *type = NULL;
+ }
+
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ if (data.size > 0) {
+ free (data.data);
+ }
+
+ return 0;
}
int
jack_get_properties (jack_uuid_t subject,
- jack_description_t* desc)
+ jack_description_t* desc)
{
- DBT key;
- DBT data;
- DBC* cursor;
- int ret;
- size_t len1, len2;
- size_t cnt = 0;
- char ustr[JACK_UUID_STRING_SIZE];
- size_t props_size = 0;
- jack_property_t* prop;
-
- desc->properties = NULL;
- desc->property_cnt = 0;
-
- memset(ustr, 0, JACK_UUID_STRING_SIZE);
- jack_uuid_unparse (subject, ustr);
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
-
- if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
- jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- while ((ret = cursor->get(cursor, &key, &data, DB_NEXT)) == 0) {
-
- /* require 2 extra chars (data+null) for key,
- which is composed of UUID str plus a key name
- */
-
- if (key.size < JACK_UUID_STRING_SIZE + 2) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
- /* not relevant */
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- /* result must have at least 2 chars plus 2 nulls to be valid
- */
-
- if (data.size < 4) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- /* realloc array if necessary */
-
- if (cnt == props_size) {
- if (props_size == 0) {
- props_size = 8; /* a rough guess at a likely upper bound for the number of properties */
- } else {
- props_size *= 2;
- }
-
- desc->properties = (jack_property_t*) realloc (desc->properties, sizeof (jack_property_t) * props_size);
- }
-
- prop = &desc->properties[cnt];
-
- /* store UUID/subject */
-
- jack_uuid_copy (&desc->subject, subject);
-
- /* copy key (without leading UUID as subject */
-
- len1 = key.size - JACK_UUID_STRING_SIZE;
- prop->key = malloc (len1);
- memcpy ((char*) prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
-
- /* copy data (which contains 1 or 2 null terminated strings, the value
- and optionally a MIME type.
- */
-
- len1 = strlen (data.data) + 1;
- prop->data = (char *) malloc (len1);
- memcpy ((char*) prop->data, data.data, len1);
-
- if (len1 < data.size) {
- len2 = strlen (data.data+len1) + 1;
-
- prop->type= (char *) malloc (len2);
- memcpy ((char*) prop->type, data.data+len1, len2);
- } else {
- /* no type specified, assume default */
- prop->type = NULL;
- }
-
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
-
- ++cnt;
- }
-
- cursor->close (cursor);
- desc->property_cnt = cnt;
-
- return cnt;
+ DBT key;
+ DBT data;
+ DBC* cursor;
+ int ret;
+ size_t len1, len2;
+ size_t cnt = 0;
+ char ustr[JACK_UUID_STRING_SIZE];
+ size_t props_size = 0;
+ jack_property_t* prop;
+
+ desc->properties = NULL;
+ desc->property_cnt = 0;
+
+ memset (ustr, 0, JACK_UUID_STRING_SIZE);
+ jack_uuid_unparse (subject, ustr);
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+
+ if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
+ jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ memset (&key, 0, sizeof(key));
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ while ((ret = cursor->get (cursor, &key, &data, DB_NEXT)) == 0) {
+
+ /* require 2 extra chars (data+null) for key,
+ which is composed of UUID str plus a key name
+ */
+
+ if (key.size < JACK_UUID_STRING_SIZE + 2) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
+ /* not relevant */
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ /* result must have at least 2 chars plus 2 nulls to be valid
+ */
+
+ if (data.size < 4) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ /* realloc array if necessary */
+
+ if (cnt == props_size) {
+ if (props_size == 0) {
+ props_size = 8; /* a rough guess at a likely upper bound for the number of properties */
+ } else {
+ props_size *= 2;
+ }
+
+ desc->properties = (jack_property_t*)realloc (desc->properties, sizeof(jack_property_t) * props_size);
+ }
+
+ prop = &desc->properties[cnt];
+
+ /* store UUID/subject */
+
+ jack_uuid_copy (&desc->subject, subject);
+
+ /* copy key (without leading UUID as subject */
+
+ len1 = key.size - JACK_UUID_STRING_SIZE;
+ prop->key = malloc (len1);
+ memcpy ((char*)prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
+
+ /* copy data (which contains 1 or 2 null terminated strings, the value
+ and optionally a MIME type.
+ */
+
+ len1 = strlen (data.data) + 1;
+ prop->data = (char*)malloc (len1);
+ memcpy ((char*)prop->data, data.data, len1);
+
+ if (len1 < data.size) {
+ len2 = strlen (data.data + len1) + 1;
+
+ prop->type = (char*)malloc (len2);
+ memcpy ((char*)prop->type, data.data + len1, len2);
+ } else {
+ /* no type specified, assume default */
+ prop->type = NULL;
+ }
+
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+
+ ++cnt;
+ }
+
+ cursor->close (cursor);
+ desc->property_cnt = cnt;
+
+ return cnt;
}
int
jack_get_all_properties (jack_description_t** descriptions)
{
- DBT key;
- DBT data;
- DBC* cursor;
- int ret;
- size_t dcnt = 0;
- size_t dsize = 0;
- size_t n = 0;
- jack_description_t* desc = NULL;
- jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER;
- jack_description_t* current_desc = NULL;
- jack_property_t* current_prop = NULL;
- size_t len1, len2;
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
- jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- dsize = 8; /* initial guess at number of descriptions we need */
- dcnt = 0;
- desc = (jack_description_t*) malloc (dsize * sizeof (jack_description_t));
-
- while ((ret = cursor->get(cursor, &key, &data, DB_NEXT)) == 0) {
-
- /* require 2 extra chars (data+null) for key,
- which is composed of UUID str plus a key name
- */
-
- if (key.size < JACK_UUID_STRING_SIZE + 2) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if (jack_uuid_parse (key.data, &uuid) != 0) {
- continue;
- }
-
- /* do we have an existing description for this UUID */
-
- for (n = 0; n < dcnt ; ++n) {
- if (jack_uuid_compare (uuid, desc[n].subject) == 0) {
- break;
- }
- }
-
- if (n == dcnt) {
- /* we do not have an existing description, so grow the array */
-
- if (dcnt == dsize) {
- dsize *= 2;
- desc = (jack_description_t*) realloc (desc, sizeof (jack_description_t) * dsize);
- }
-
- /* initialize */
-
- desc[n].property_size = 0;
- desc[n].property_cnt = 0;
- desc[n].properties = NULL;
-
- /* set up UUID */
-
- jack_uuid_copy (&desc[n].subject, uuid);
- dcnt++;
- }
-
- current_desc = &desc[n];
-
- /* see if there is room for the new property or if we need to realloc
- */
-
- if (current_desc->property_cnt == current_desc->property_size) {
- if (current_desc->property_size == 0) {
- current_desc->property_size = 8;
- } else {
- current_desc->property_size *= 2;
- }
-
- current_desc->properties = (jack_property_t*) realloc (current_desc->properties, sizeof (jack_property_t) * current_desc->property_size);
- }
-
- current_prop = &current_desc->properties[current_desc->property_cnt++];
-
- /* copy key (without leading UUID) */
-
- len1 = key.size - JACK_UUID_STRING_SIZE;
- current_prop->key = malloc (len1);
- memcpy ((char*) current_prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
-
- /* copy data (which contains 1 or 2 null terminated strings, the value
- and optionally a MIME type.
- */
-
- len1 = strlen (data.data) + 1;
- current_prop->data = (char *) malloc (len1);
- memcpy ((char*) current_prop->data, data.data, len1);
-
- if (len1 < data.size) {
- len2 = strlen (data.data+len1) + 1;
-
- current_prop->type= (char *) malloc (len2);
- memcpy ((char*) current_prop->type, data.data+len1, len2);
- } else {
- /* no type specified, assume default */
- current_prop->type = NULL;
- }
-
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- }
-
- cursor->close (cursor);
-
- (*descriptions) = desc;
-
- return dcnt;
+ DBT key;
+ DBT data;
+ DBC* cursor;
+ int ret;
+ size_t dcnt = 0;
+ size_t dsize = 0;
+ size_t n = 0;
+ jack_description_t* desc = NULL;
+ jack_uuid_t uuid = JACK_UUID_EMPTY_INITIALIZER;
+ jack_description_t* current_desc = NULL;
+ jack_property_t* current_prop = NULL;
+ size_t len1, len2;
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
+ jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ memset (&key, 0, sizeof(key));
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ dsize = 8; /* initial guess at number of descriptions we need */
+ dcnt = 0;
+ desc = (jack_description_t*)malloc (dsize * sizeof(jack_description_t));
+
+ while ((ret = cursor->get (cursor, &key, &data, DB_NEXT)) == 0) {
+
+ /* require 2 extra chars (data+null) for key,
+ which is composed of UUID str plus a key name
+ */
+
+ if (key.size < JACK_UUID_STRING_SIZE + 2) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if (jack_uuid_parse (key.data, &uuid) != 0) {
+ continue;
+ }
+
+ /* do we have an existing description for this UUID */
+
+ for (n = 0; n < dcnt; ++n) {
+ if (jack_uuid_compare (uuid, desc[n].subject) == 0) {
+ break;
+ }
+ }
+
+ if (n == dcnt) {
+ /* we do not have an existing description, so grow the array */
+
+ if (dcnt == dsize) {
+ dsize *= 2;
+ desc = (jack_description_t*)realloc (desc, sizeof(jack_description_t) * dsize);
+ }
+
+ /* initialize */
+
+ desc[n].property_size = 0;
+ desc[n].property_cnt = 0;
+ desc[n].properties = NULL;
+
+ /* set up UUID */
+
+ jack_uuid_copy (&desc[n].subject, uuid);
+ dcnt++;
+ }
+
+ current_desc = &desc[n];
+
+ /* see if there is room for the new property or if we need to realloc
+ */
+
+ if (current_desc->property_cnt == current_desc->property_size) {
+ if (current_desc->property_size == 0) {
+ current_desc->property_size = 8;
+ } else {
+ current_desc->property_size *= 2;
+ }
+
+ current_desc->properties = (jack_property_t*)realloc (current_desc->properties, sizeof(jack_property_t) * current_desc->property_size);
+ }
+
+ current_prop = &current_desc->properties[current_desc->property_cnt++];
+
+ /* copy key (without leading UUID) */
+
+ len1 = key.size - JACK_UUID_STRING_SIZE;
+ current_prop->key = malloc (len1);
+ memcpy ((char*)current_prop->key, key.data + JACK_UUID_STRING_SIZE, len1);
+
+ /* copy data (which contains 1 or 2 null terminated strings, the value
+ and optionally a MIME type.
+ */
+
+ len1 = strlen (data.data) + 1;
+ current_prop->data = (char*)malloc (len1);
+ memcpy ((char*)current_prop->data, data.data, len1);
+
+ if (len1 < data.size) {
+ len2 = strlen (data.data + len1) + 1;
+
+ current_prop->type = (char*)malloc (len2);
+ memcpy ((char*)current_prop->type, data.data + len1, len2);
+ } else {
+ /* no type specified, assume default */
+ current_prop->type = NULL;
+ }
+
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ }
+
+ cursor->close (cursor);
+
+ (*descriptions) = desc;
+
+ return dcnt;
}
int
-jack_get_description (jack_uuid_t subject,
- jack_description_t* desc)
+jack_get_description (jack_uuid_t subject,
+ jack_description_t* desc)
{
- return 0;
+ return 0;
}
int
jack_get_all_descriptions (jack_description_t** descs)
{
- return 0;
+ return 0;
}
-int
+int
jack_set_property_change_callback (jack_client_t *client,
- JackPropertyChangeCallback callback, void *arg)
+ JackPropertyChangeCallback callback, void *arg)
{
if (client->control->active) {
jack_error ("You cannot set callbacks on an active client.");
@@ -563,118 +595,128 @@ jack_set_property_change_callback (jack_client_t *client,
return 0;
}
-int
+int
jack_remove_property (jack_client_t* client, jack_uuid_t subject, const char* key)
{
- DBT d_key;
- int ret;
+ DBT d_key;
+ int ret;
- if (jack_property_init (NULL)) {
- return -1;
- }
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
- make_key_dbt (&d_key, subject, key);
- if ((ret = db->del (db, NULL, &d_key, 0)) != 0) {
- jack_error ("Cannot delete key %s (%s)", key, db_strerror (ret));
- if (d_key.size > 0) free(d_key.data);
- return -1;
- }
+ make_key_dbt (&d_key, subject, key);
+ if ((ret = db->del (db, NULL, &d_key, 0)) != 0) {
+ jack_error ("Cannot delete key %s (%s)", key, db_strerror (ret));
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
+ return -1;
+ }
- jack_property_change_notify (client, subject, key, PropertyDeleted);
+ jack_property_change_notify (client, subject, key, PropertyDeleted);
- if (d_key.size > 0) free(d_key.data);
+ if (d_key.size > 0) {
+ free (d_key.data);
+ }
- return 0;
+ return 0;
}
-int
+int
jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
{
- DBT key;
- DBT data;
- DBC* cursor;
- int ret;
- char ustr[JACK_UUID_STRING_SIZE];
- int retval = 0;
- uint32_t cnt = 0;
-
- memset(ustr, 0, JACK_UUID_STRING_SIZE);
- jack_uuid_unparse (subject, ustr);
-
- if (jack_property_init (NULL)) {
- return -1;
- }
-
- if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
- jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
- return -1;
- }
-
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- data.flags = DB_DBT_MALLOC;
-
- while ((ret = cursor->get(cursor, &key, &data, DB_NEXT)) == 0) {
-
- /* require 2 extra chars (data+null) for key,
- which is composed of UUID str plus a key name
- */
-
- if (key.size < JACK_UUID_STRING_SIZE + 2) {
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
- /* not relevant */
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- continue;
- }
-
- if ((ret = cursor->del (cursor, 0)) != 0) {
- jack_error ("cannot delete property (%s)", db_strerror (ret));
- /* don't return -1 here since this would leave things
- even more inconsistent. wait till the cursor is finished
- */
- retval = -1;
- }
- cnt++;
-
- /* if (key.size > 0) free(key.data); */
- if (data.size > 0) free(data.data);
- }
-
- cursor->close (cursor);
-
- if (cnt) {
- jack_property_change_notify (client, subject, NULL, PropertyDeleted);
- }
-
- if (retval) {
- return -1;
- }
-
- return cnt;
+ DBT key;
+ DBT data;
+ DBC* cursor;
+ int ret;
+ char ustr[JACK_UUID_STRING_SIZE];
+ int retval = 0;
+ uint32_t cnt = 0;
+
+ memset (ustr, 0, JACK_UUID_STRING_SIZE);
+ jack_uuid_unparse (subject, ustr);
+
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
+
+ if ((ret = db->cursor (db, NULL, &cursor, 0)) != 0) {
+ jack_error ("Cannot create cursor for metadata search (%s)", db_strerror (ret));
+ return -1;
+ }
+
+ memset (&key, 0, sizeof(key));
+ memset (&data, 0, sizeof(data));
+ data.flags = DB_DBT_MALLOC;
+
+ while ((ret = cursor->get (cursor, &key, &data, DB_NEXT)) == 0) {
+
+ /* require 2 extra chars (data+null) for key,
+ which is composed of UUID str plus a key name
+ */
+
+ if (key.size < JACK_UUID_STRING_SIZE + 2) {
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if (memcmp (ustr, key.data, JACK_UUID_STRING_SIZE) != 0) {
+ /* not relevant */
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ continue;
+ }
+
+ if ((ret = cursor->del (cursor, 0)) != 0) {
+ jack_error ("cannot delete property (%s)", db_strerror (ret));
+ /* don't return -1 here since this would leave things
+ even more inconsistent. wait till the cursor is finished
+ */
+ retval = -1;
+ }
+ cnt++;
+
+ /* if (key.size > 0) free(key.data); */
+ if (data.size > 0) {
+ free (data.data);
+ }
+ }
+
+ cursor->close (cursor);
+
+ if (cnt) {
+ jack_property_change_notify (client, subject, NULL, PropertyDeleted);
+ }
+
+ if (retval) {
+ return -1;
+ }
+
+ return cnt;
}
-int
+int
jack_remove_all_properties (jack_client_t* client)
{
- int ret;
- jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
+ int ret;
+ jack_uuid_t empty_uuid = JACK_UUID_EMPTY_INITIALIZER;
- if (jack_property_init (NULL)) {
- return -1;
- }
+ if (jack_property_init (NULL)) {
+ return -1;
+ }
- if ((ret = db->truncate (db, NULL, NULL, 0)) != 0) {
- jack_error ("Cannot clear properties (%s)", db_strerror (ret));
- return -1;
- }
+ if ((ret = db->truncate (db, NULL, NULL, 0)) != 0) {
+ jack_error ("Cannot clear properties (%s)", db_strerror (ret));
+ return -1;
+ }
- jack_property_change_notify (client, empty_uuid, NULL, PropertyDeleted);
+ jack_property_change_notify (client, empty_uuid, NULL, PropertyDeleted);
- return 0;
+ return 0;
}
diff --git a/libjack/midiport.c b/libjack/midiport.c
index b673972..d5e607d 100644
--- a/libjack/midiport.c
+++ b/libjack/midiport.c
@@ -1,21 +1,21 @@
/*
Copyright (C) 2004-2006 Ian Esten
Copyright (C) 2006 Dave Robillard
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <assert.h>
#include <stdio.h>
@@ -30,47 +30,49 @@
enum { MIDI_INLINE_MAX = 4 }; /* 4 bytes for default event size */
typedef struct _jack_midi_port_info_private {
- jack_nframes_t nframes; /**< Number of frames in buffer */
- uint32_t buffer_size; /**< Size of buffer in bytes */
- uint32_t event_count; /**< Number of events stored in this buffer */
- jack_nframes_t last_write_loc; /**< Used for both writing and mixdown */
- uint32_t events_lost; /**< Number of events lost in this buffer */
+ jack_nframes_t nframes; /**< Number of frames in buffer */
+ uint32_t buffer_size; /**< Size of buffer in bytes */
+ uint32_t event_count; /**< Number of events stored in this buffer */
+ jack_nframes_t last_write_loc; /**< Used for both writing and mixdown */
+ uint32_t events_lost; /**< Number of events lost in this buffer */
} POST_PACKED_STRUCTURE jack_midi_port_info_private_t;
typedef struct _jack_midi_port_internal_event {
- uint16_t time; /* offset within buffer limit to 64k */
- uint16_t size; /* event size limited to 64k */
- union {
- jack_shmsize_t byte_offset;
- jack_midi_data_t inline_data[MIDI_INLINE_MAX];
+ uint16_t time; /* offset within buffer limit to 64k */
+ uint16_t size; /* event size limited to 64k */
+ union {
+ jack_shmsize_t byte_offset;
+ jack_midi_data_t inline_data[MIDI_INLINE_MAX];
} POST_PACKED_STRUCTURE;
} POST_PACKED_STRUCTURE jack_midi_port_internal_event_t;
size_t
jack_midi_internal_event_size ()
{
- return sizeof (jack_midi_port_internal_event_t);
+ return sizeof(jack_midi_port_internal_event_t);
}
static inline jack_midi_data_t*
-jack_midi_event_data(void* port_buffer,
- const jack_midi_port_internal_event_t* event)
+jack_midi_event_data (void* port_buffer,
+ const jack_midi_port_internal_event_t* event)
{
- if (event->size <= MIDI_INLINE_MAX)
- return (jack_midi_data_t*) event->inline_data;
- else
- return ((jack_midi_data_t *)port_buffer) + event->byte_offset;
+ if (event->size <= MIDI_INLINE_MAX) {
+ return (jack_midi_data_t*)event->inline_data;
+ } else {
+ return ((jack_midi_data_t*)port_buffer) + event->byte_offset;
+ }
}
/* jack_midi_port_functions.buffer_init */
static void
-jack_midi_buffer_init(void *port_buffer,
- size_t buffer_size,
+jack_midi_buffer_init (void *port_buffer,
+ size_t buffer_size,
jack_nframes_t nframes)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
+
/* We can also add some magic field to midi buffer to validate client calls */
info->nframes = nframes;
info->buffer_size = buffer_size;
@@ -81,86 +83,90 @@ jack_midi_buffer_init(void *port_buffer,
uint32_t
-jack_midi_get_event_count(void *port_buffer)
+jack_midi_get_event_count (void *port_buffer)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
+
return info->event_count;
}
int
-jack_midi_event_get(jack_midi_event_t *event,
- void *port_buffer,
- uint32_t event_idx)
+jack_midi_event_get (jack_midi_event_t *event,
+ void *port_buffer,
+ uint32_t event_idx)
{
jack_midi_port_internal_event_t *port_event;
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
-
+ (jack_midi_port_info_private_t*)port_buffer;
+
if (event_idx >= info->event_count)
#ifdef ENODATA
- return ENODATA;
+ { return ENODATA; }
#else
- return ENOMSG;
+ { return ENOMSG; }
#endif
-
- port_event = (jack_midi_port_internal_event_t *) (info + 1);
+
+ port_event = (jack_midi_port_internal_event_t*)(info + 1);
port_event += event_idx;
event->time = port_event->time;
event->size = port_event->size;
- event->buffer = jack_midi_event_data(port_buffer, port_event);
-
+ event->buffer = jack_midi_event_data (port_buffer, port_event);
+
return 0;
}
size_t
-jack_midi_max_event_size(void *port_buffer)
+jack_midi_max_event_size (void *port_buffer)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
size_t buffer_size =
info->buffer_size;
-
+
/* (event_count + 1) below accounts for jack_midi_port_internal_event_t
* which would be needed to store the next event */
size_t used_size = sizeof(jack_midi_port_info_private_t)
- + info->last_write_loc
- + ((info->event_count + 1)
- * sizeof(jack_midi_port_internal_event_t));
-
- if (used_size > buffer_size)
+ + info->last_write_loc
+ + ((info->event_count + 1)
+ * sizeof(jack_midi_port_internal_event_t));
+
+ if (used_size > buffer_size) {
return 0;
- else if ((buffer_size - used_size) < MIDI_INLINE_MAX)
+ } else if ((buffer_size - used_size) < MIDI_INLINE_MAX) {
return MIDI_INLINE_MAX;
- else
- return (buffer_size - used_size);
+ } else {
+ return buffer_size - used_size;
+ }
}
jack_midi_data_t*
-jack_midi_event_reserve(void *port_buffer,
- jack_nframes_t time,
- size_t data_size)
+jack_midi_event_reserve (void *port_buffer,
+ jack_nframes_t time,
+ size_t data_size)
{
- jack_midi_data_t *retbuf = (jack_midi_data_t *) port_buffer;
+ jack_midi_data_t *retbuf = (jack_midi_data_t*)port_buffer;
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
jack_midi_port_internal_event_t *event_buffer =
- (jack_midi_port_internal_event_t *) (info + 1);
+ (jack_midi_port_internal_event_t*)(info + 1);
size_t buffer_size =
info->buffer_size;
-
- if (time < 0 || time >= info->nframes)
- goto failed;
-
- if (info->event_count > 0 && time < event_buffer[info->event_count-1].time)
- goto failed;
+
+ if (time < 0 || time >= info->nframes) {
+ goto failed;
+ }
+
+ if (info->event_count > 0 && time < event_buffer[info->event_count - 1].time) {
+ goto failed;
+ }
/* Check if data_size is >0 and there is enough space in the buffer for the event. */
- if (data_size <=0) {
+ if (data_size <= 0) {
goto failed; // return NULL?
} else if (jack_midi_max_event_size (port_buffer) < data_size) {
goto failed;
@@ -180,23 +186,23 @@ jack_midi_event_reserve(void *port_buffer,
info->event_count += 1;
return retbuf;
}
- failed:
- info->events_lost++;
+failed:
+ info->events_lost++;
return NULL;
}
int
-jack_midi_event_write(void *port_buffer,
- jack_nframes_t time,
- const jack_midi_data_t *data,
- size_t data_size)
+jack_midi_event_write (void *port_buffer,
+ jack_nframes_t time,
+ const jack_midi_data_t *data,
+ size_t data_size)
{
jack_midi_data_t *retbuf =
- jack_midi_event_reserve(port_buffer, time, data_size);
+ jack_midi_event_reserve (port_buffer, time, data_size);
if (retbuf) {
- memcpy(retbuf, data, data_size);
+ memcpy (retbuf, data, data_size);
return 0;
} else {
return ENOBUFS;
@@ -210,10 +216,10 @@ jack_midi_event_write(void *port_buffer,
* been reset.
*/
void
-jack_midi_clear_buffer(void *port_buffer)
+jack_midi_clear_buffer (void *port_buffer)
{
jack_midi_port_info_private_t *info =
- (jack_midi_port_info_private_t *) port_buffer;
+ (jack_midi_port_info_private_t*)port_buffer;
info->event_count = 0;
info->last_write_loc = 0;
@@ -223,40 +229,40 @@ jack_midi_clear_buffer(void *port_buffer)
/* jack_midi_port_functions.mixdown */
static void
-jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
+jack_midi_port_mixdown (jack_port_t *port, jack_nframes_t nframes)
{
JSList *node;
jack_port_t *input;
- jack_nframes_t num_events = 0;
- jack_nframes_t i = 0;
- int err = 0;
- jack_nframes_t lost_events = 0;
+ jack_nframes_t num_events = 0;
+ jack_nframes_t i = 0;
+ int err = 0;
+ jack_nframes_t lost_events = 0;
/* The next (single) event to mix in to the buffer */
jack_midi_port_info_private_t *earliest_info;
jack_midi_port_internal_event_t *earliest_event;
jack_midi_data_t *earliest_buffer;
-
- jack_midi_port_info_private_t *in_info; /* For finding next event */
- jack_midi_port_internal_event_t *in_events; /* Corresponds to in_info */
- jack_midi_port_info_private_t *out_info; /* Output 'buffer' */
- jack_midi_clear_buffer(port->mix_buffer);
-
- out_info = (jack_midi_port_info_private_t *) port->mix_buffer;
+ jack_midi_port_info_private_t *in_info; /* For finding next event */
+ jack_midi_port_internal_event_t *in_events; /* Corresponds to in_info */
+ jack_midi_port_info_private_t *out_info; /* Output 'buffer' */
+
+ jack_midi_clear_buffer (port->mix_buffer);
+
+ out_info = (jack_midi_port_info_private_t*)port->mix_buffer;
/* This function uses jack_midi_port_info_private_t.last_write_loc of the
* source ports to store indices of the last event read from that buffer
* so far. This is OK because last_write_loc is used when writing events
* to a buffer, which at this stage is already complete so the value
* can be safely smashed. */
-
+
/* Iterate through all connections to see how many events we need to mix,
* and initialise their 'last event read' (last_write_loc) to 0 */
- for (node = port->connections; node; node = jack_slist_next(node)) {
- input = (jack_port_t *) node->data;
+ for (node = port->connections; node; node = jack_slist_next (node)) {
+ input = (jack_port_t*)node->data;
in_info =
- (jack_midi_port_info_private_t *) jack_output_port_buffer(input);
+ (jack_midi_port_info_private_t*)jack_output_port_buffer (input);
num_events += in_info->event_count;
lost_events += in_info->events_lost;
in_info->last_write_loc = 0;
@@ -270,36 +276,36 @@ jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
/* Find the earliest unread event, to mix next
* (search for an event earlier than earliest_event) */
- for (node = port->connections; node; node = jack_slist_next(node)) {
- in_info = (jack_midi_port_info_private_t *)
- jack_output_port_buffer(((jack_port_t *) node->data));
- in_events = (jack_midi_port_internal_event_t *) (in_info + 1);
+ for (node = port->connections; node; node = jack_slist_next (node)) {
+ in_info = (jack_midi_port_info_private_t*)
+ jack_output_port_buffer (((jack_port_t*)node->data));
+ in_events = (jack_midi_port_internal_event_t*)(in_info + 1);
/* If there are unread events left in this port.. */
if (in_info->event_count > in_info->last_write_loc) {
/* .. and this event is the new earliest .. */
/* NOTE: that's why we compare time with <, not <= */
if (earliest_info == NULL
- || in_events[in_info->last_write_loc].time
- < earliest_event->time) {
+ || in_events[in_info->last_write_loc].time
+ < earliest_event->time) {
/* .. then set this event as the next earliest */
earliest_info = in_info;
- earliest_event = (jack_midi_port_internal_event_t *)
- (&in_events[in_info->last_write_loc]);
+ earliest_event = (jack_midi_port_internal_event_t*)
+ (&in_events[in_info->last_write_loc]);
}
}
}
if (earliest_info && earliest_event) {
- earliest_buffer = (jack_midi_data_t *) earliest_info;
-
+ earliest_buffer = (jack_midi_data_t*)earliest_info;
+
/* Write event to output */
- err = jack_midi_event_write(
- jack_port_buffer(port),
+ err = jack_midi_event_write (
+ jack_port_buffer (port),
earliest_event->time,
- jack_midi_event_data(earliest_buffer, earliest_event),
+ jack_midi_event_data (earliest_buffer, earliest_event),
earliest_event->size);
-
+
earliest_info->last_write_loc++;
if (err) {
@@ -308,7 +314,7 @@ jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
}
}
}
- assert(out_info->event_count == num_events - out_info->events_lost);
+ assert (out_info->event_count == num_events - out_info->events_lost);
// inherit total lost events count from all connected ports.
out_info->events_lost += lost_events;
@@ -316,12 +322,12 @@ jack_midi_port_mixdown(jack_port_t *port, jack_nframes_t nframes)
uint32_t
-jack_midi_get_lost_event_count(void *port_buffer)
+jack_midi_get_lost_event_count (void *port_buffer)
{
- return ((jack_midi_port_info_private_t *) port_buffer)->events_lost;
+ return ((jack_midi_port_info_private_t*)port_buffer)->events_lost;
}
jack_port_functions_t jack_builtin_midi_functions = {
- .buffer_init = jack_midi_buffer_init,
- .mixdown = jack_midi_port_mixdown,
+ .buffer_init = jack_midi_buffer_init,
+ .mixdown = jack_midi_port_mixdown,
};
diff --git a/libjack/pool.c b/libjack/pool.c
index f329cd5..4b7ecf3 100644
--- a/libjack/pool.c
+++ b/libjack/pool.c
@@ -1,21 +1,21 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <config.h>
@@ -33,11 +33,11 @@ jack_pool_alloc (size_t bytes)
{
#ifdef HAVE_POSIX_MEMALIGN
void* m;
- int err = posix_memalign (&m, 64, bytes);
+ int err = posix_memalign (&m, 64, bytes);
return (!err) ? m : 0;
#else
return malloc (bytes);
-#endif /* HAVE_POSIX_MEMALIGN */
+#endif /* HAVE_POSIX_MEMALIGN */
}
void
diff --git a/libjack/port.c b/libjack/port.c
index 5d42b9f..ae67cbb 100644
--- a/libjack/port.c
+++ b/libjack/port.c
@@ -1,22 +1,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2005 Jussi Laako
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <string.h>
#include <stdio.h>
@@ -41,36 +41,34 @@
#include "local.h"
static void jack_generic_buffer_init(void *port_buffer,
- size_t buffer_size,
- jack_nframes_t nframes);
-
-static void jack_audio_port_mixdown (jack_port_t *port,
+ size_t buffer_size,
jack_nframes_t nframes);
+static void jack_audio_port_mixdown(jack_port_t *port,
+ jack_nframes_t nframes);
+
/* These function pointers are local to each address space. For
* internal clients they reside within jackd; for external clients in
* the application process. */
jack_port_functions_t jack_builtin_audio_functions = {
- .buffer_init = jack_generic_buffer_init,
- .mixdown = jack_audio_port_mixdown,
+ .buffer_init = jack_generic_buffer_init,
+ .mixdown = jack_audio_port_mixdown,
};
extern jack_port_functions_t jack_builtin_midi_functions;
jack_port_functions_t jack_builtin_NULL_functions = {
- .buffer_init = jack_generic_buffer_init,
- .mixdown = NULL,
+ .buffer_init = jack_generic_buffer_init,
+ .mixdown = NULL,
};
/* Only the Audio and MIDI port types are currently built in. */
jack_port_type_info_t jack_builtin_port_types[] = {
- { .type_name = JACK_DEFAULT_AUDIO_TYPE,
- .buffer_scale_factor = 1,
- },
- { .type_name = JACK_DEFAULT_MIDI_TYPE,
+ { .type_name = JACK_DEFAULT_AUDIO_TYPE,
+ .buffer_scale_factor = 1, },
+ { .type_name = JACK_DEFAULT_MIDI_TYPE,
.buffer_scale_factor = -1,
- .buffer_size = 2048
- },
+ .buffer_size = 2048 },
{ .type_name = "", }
};
@@ -78,13 +76,13 @@ jack_port_type_info_t jack_builtin_port_types[] = {
#ifdef USE_DYNSIMD
-static void (*opt_copy) (float *, const float *, int);
-static void (*opt_mix) (float *, const float *, int);
+static void (*opt_copy)(float *, const float *, int);
+static void (*opt_mix)(float *, const float *, int);
static void
gen_copyf (float *dest, const float *src, int length)
{
- memcpy(dest, src, length * sizeof(float));
+ memcpy (dest, src, length * sizeof(float));
}
static void
@@ -96,22 +94,20 @@ gen_mixf (float *dest, const float *src, int length)
while (n--)
*dest++ += *src++;
/*for (iSample = 0; iSample < iDataLength; iSample++)
- fpDest[iSample] += fpSrc[iSample];*/
+ fpDest[iSample] += fpSrc[iSample];*/
}
#ifdef ARCH_X86
void jack_port_set_funcs ()
{
- if (ARCH_X86_HAVE_SSE2(cpu_type)) {
+ if (ARCH_X86_HAVE_SSE2 (cpu_type)) {
opt_copy = x86_sse_copyf;
opt_mix = x86_sse_add2f;
- }
- else if (ARCH_X86_HAVE_3DNOW(cpu_type)) {
+ } else if (ARCH_X86_HAVE_3DNOW (cpu_type)) {
opt_copy = x86_3dnow_copyf;
opt_mix = x86_3dnow_add2f;
- }
- else {
+ } else {
opt_copy = gen_copyf;
opt_mix = gen_mixf;
}
@@ -125,34 +121,34 @@ void jack_port_set_funcs ()
opt_mix = gen_mixf;
}
-#endif /* ARCH_X86 */
+#endif /* ARCH_X86 */
-#endif /* USE_DYNSIMD */
+#endif /* USE_DYNSIMD */
int
jack_port_name_equals (jack_port_shared_t* port, const char* target)
{
- char buf[JACK_PORT_NAME_SIZE+1];
+ char buf[JACK_PORT_NAME_SIZE + 1];
/* this nasty, nasty kludge is here because between 0.109.0 and 0.109.1,
the ALSA audio backend had the name "ALSA", whereas as before and
after it, it was called "alsa_pcm". this stops breakage for
any setups that have saved "alsa_pcm" or "ALSA" in their connection
state.
- */
+ */
if (strncmp (target, "ALSA:capture", 12) == 0 || strncmp (target, "ALSA:playback", 13) == 0) {
- snprintf (buf, sizeof (buf), "alsa_pcm%s", target+4);
+ snprintf (buf, sizeof(buf), "alsa_pcm%s", target + 4);
target = buf;
}
- return (strcmp (port->name, target) == 0 ||
- strcmp (port->alias1, target) == 0 ||
- strcmp (port->alias2, target) == 0);
+ return strcmp (port->name, target) == 0 ||
+ strcmp (port->alias1, target) == 0 ||
+ strcmp (port->alias2, target) == 0;
}
jack_port_functions_t *
-jack_get_port_functions(jack_port_type_id_t ptid)
+jack_get_port_functions (jack_port_type_id_t ptid)
{
switch (ptid) {
case JACK_AUDIO_PORT_TYPE:
@@ -169,9 +165,9 @@ jack_get_port_functions(jack_port_type_id_t ptid)
* Fills buffer with zeroes. For audio ports, engine->silent_buffer relies on it.
*/
static void
-jack_generic_buffer_init(void *buffer, size_t size, jack_nframes_t nframes)
-{
- memset(buffer, 0, size);
+jack_generic_buffer_init (void *buffer, size_t size, jack_nframes_t nframes)
+{
+ memset (buffer, 0, size);
}
@@ -183,10 +179,10 @@ jack_port_new (const jack_client_t *client, jack_port_id_t port_id,
jack_port_type_id_t ptid = shared->ptype_id;
jack_port_t *port;
- if ((port = (jack_port_t *) malloc (sizeof (jack_port_t))) == NULL) {
+ if ((port = (jack_port_t*)malloc (sizeof(jack_port_t))) == NULL) {
return NULL;
}
-
+
port->mix_buffer = NULL;
port->client_segment_base = NULL;
port->shared = shared;
@@ -196,14 +192,15 @@ jack_port_new (const jack_client_t *client, jack_port_id_t port_id,
port->tied = NULL;
if (jack_uuid_compare (client->control->uuid, port->shared->client_id) == 0) {
-
+
/* It's our port, so initialize the pointers to port
* functions within this address space. These builtin
- * definitions can be overridden by the client.
+ * definitions can be overridden by the client.
*/
- jack_port_functions_t *port_functions = jack_get_port_functions(ptid);
- if (port_functions == NULL)
+ jack_port_functions_t *port_functions = jack_get_port_functions (ptid);
+ if (port_functions == NULL) {
port_functions = &jack_builtin_NULL_functions;
+ }
port->fptr = *port_functions;
port->shared->has_mixdown = (port->fptr.mixdown ? TRUE : FALSE);
}
@@ -213,32 +210,33 @@ jack_port_new (const jack_client_t *client, jack_port_id_t port_id,
directly, because port->client_segment_base and/or
port->offset can change if the buffer size or port counts
are changed.
- */
+ */
port->client_segment_base =
- (void **) &client->port_segment[ptid].attached_at;
+ (void**)&client->port_segment[ptid].attached_at;
return port;
}
-size_t
+size_t
jack_port_type_get_buffer_size (jack_client_t *client, const char *port_type)
{
int i;
- for (i=0; i<client->engine->n_port_types; i++) {
- if (!strcmp(port_type, client->engine->port_types[i].type_name))
+ for (i = 0; i < client->engine->n_port_types; i++)
+ if (!strcmp (port_type, client->engine->port_types[i].type_name)) {
break;
- }
+ }
- if (i==client->engine->n_port_types)
+ if (i == client->engine->n_port_types) {
return 0;
+ }
return jack_port_type_buffer_size (&(client->engine->port_types[i]), client->engine->buffer_size);
}
jack_port_t *
-jack_port_register (jack_client_t *client,
+jack_port_register (jack_client_t *client,
const char *port_name,
const char *port_type,
unsigned long flags,
@@ -246,29 +244,29 @@ jack_port_register (jack_client_t *client,
{
jack_request_t req;
jack_port_t *port = 0;
- int length ;
+ int length;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = RegisterPort;
- length = strlen ((const char *) client->control->name)
- + 1 + strlen (port_name);
- if ( length >= sizeof (req.x.port_info.name) ) {
- jack_error ("\"%s:%s\" is too long to be used as a JACK port name.\n"
- "Please use %lu characters or less.",
- client->control->name ,
- port_name,
- sizeof (req.x.port_info.name) - 1);
- return NULL ;
+ length = strlen ((const char*)client->control->name)
+ + 1 + strlen (port_name);
+ if ( length >= sizeof(req.x.port_info.name) ) {
+ jack_error ("\"%s:%s\" is too long to be used as a JACK port name.\n"
+ "Please use %lu characters or less.",
+ client->control->name,
+ port_name,
+ sizeof(req.x.port_info.name) - 1);
+ return NULL;
}
- strcpy ((char *) req.x.port_info.name,
- (const char *) client->control->name);
- strcat ((char *) req.x.port_info.name, ":");
- strcat ((char *) req.x.port_info.name, port_name);
+ strcpy ((char*)req.x.port_info.name,
+ (const char*)client->control->name);
+ strcat ((char*)req.x.port_info.name, ":");
+ strcat ((char*)req.x.port_info.name, port_name);
- snprintf (req.x.port_info.type, sizeof (req.x.port_info.type),
+ snprintf (req.x.port_info.type, sizeof(req.x.port_info.type),
"%s", port_type);
req.x.port_info.flags = flags;
req.x.port_info.buffer_size = buffer_size;
@@ -290,12 +288,12 @@ jack_port_register (jack_client_t *client,
return port;
}
-int
+int
jack_port_unregister (jack_client_t *client, jack_port_t *port)
{
jack_request_t req;
-
- VALGRIND_MEMSET (&req, 0, sizeof (req));
+
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
req.type = UnRegisterPort;
@@ -324,20 +322,20 @@ jack_port_connected_to (const jack_port_t *port, const char *portname)
while we are checking for them. that's hard,
and has a non-trivial performance impact
for jackd.
- */
+ */
- pthread_mutex_lock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_lock (&((jack_port_t*)port)->connection_lock);
for (node = port->connections; node; node = jack_slist_next (node)) {
- jack_port_t *other_port = (jack_port_t *) node->data;
-
+ jack_port_t *other_port = (jack_port_t*)node->data;
+
if (jack_port_name_equals (other_port->shared, portname)) {
ret = TRUE;
break;
}
}
- pthread_mutex_unlock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_unlock (&((jack_port_t*)port)->connection_lock);
return ret;
}
@@ -353,29 +351,29 @@ jack_port_get_connections (const jack_port_t *port)
while we are checking for them. that's hard,
and has a non-trivial performance impact
for jackd.
- */
+ */
- pthread_mutex_lock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_lock (&((jack_port_t*)port)->connection_lock);
if (port->connections != NULL) {
- ret = (const char **)
- malloc (sizeof (char *)
- * (jack_slist_length (port->connections) + 1));
+ ret = (const char**)
+ malloc (sizeof(char *)
+ * (jack_slist_length (port->connections) + 1));
if (ret == NULL) {
- pthread_mutex_unlock (&((jack_port_t *)port)->connection_lock);
+ pthread_mutex_unlock (&((jack_port_t*)port)->connection_lock);
return NULL;
}
for (n = 0, node = port->connections; node;
node = jack_slist_next (node), ++n) {
- jack_port_t* other =(jack_port_t *) node->data;
+ jack_port_t* other = (jack_port_t*)node->data;
ret[n] = other->shared->name;
}
ret[n] = NULL;
}
- pthread_mutex_unlock (&((jack_port_t *) port)->connection_lock);
+ pthread_mutex_unlock (&((jack_port_t*)port)->connection_lock);
return ret;
}
@@ -395,8 +393,8 @@ jack_port_get_all_connections (const jack_client_t *client,
return NULL;
}
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = GetPortConnections;
req.x.port_info.name[0] = '\0';
@@ -417,15 +415,15 @@ jack_port_get_all_connections (const jack_client_t *client,
return req.x.port_connections.ports;
}
- if ((ret = (const char **) malloc (sizeof (char *) * (req.x.port_connections.nports + 1))) == NULL) {
+ if ((ret = (const char**)malloc (sizeof(char *) * (req.x.port_connections.nports + 1))) == NULL) {
return NULL;
}
for (i = 0; i < req.x.port_connections.nports; ++i ) {
jack_port_id_t port_id;
-
- if (read (client->request_fd, &port_id, sizeof (port_id))
- != sizeof (port_id)) {
+
+ if (read (client->request_fd, &port_id, sizeof(port_id))
+ != sizeof(port_id)) {
jack_error ("cannot read port id from server");
return 0;
}
@@ -448,14 +446,15 @@ jack_port_by_id_int (const jack_client_t *client, jack_port_id_t id, int* free)
JSList *node;
for (node = client->ports; node; node = jack_slist_next (node)) {
- if (((jack_port_t *) node->data)->shared->id == id) {
+ if (((jack_port_t*)node->data)->shared->id == id) {
*free = FALSE;
- return (jack_port_t *) node->data;
+ return (jack_port_t*)node->data;
}
}
- if (id >= client->engine->port_max)
+ if (id >= client->engine->port_max) {
return NULL;
+ }
if (client->engine->ports[id].in_use) {
*free = TRUE;
@@ -471,18 +470,20 @@ jack_port_by_id (jack_client_t *client, jack_port_id_t id)
JSList *node;
jack_port_t* port;
int need_free = FALSE;
+
for (node = client->ports_ext; node; node = jack_slist_next (node)) {
port = node->data;
if (port->shared->id == id) { // Found port, return the cached structure
return port;
}
}
-
+
// Otherwise possibly allocate a new port structure, keep it in the ports_ext list for later use
- port = jack_port_by_id_int (client,id,&need_free);
- if (port != NULL && need_free)
+ port = jack_port_by_id_int (client, id, &need_free);
+ if (port != NULL && need_free) {
client->ports_ext =
jack_slist_prepend (client->ports_ext, port);
+ }
return port;
}
@@ -491,10 +492,10 @@ jack_port_by_name_int (jack_client_t *client, const char *port_name)
{
unsigned long i, limit;
jack_port_shared_t *port;
-
+
limit = client->engine->port_max;
port = &client->engine->ports[0];
-
+
for (i = 0; i < limit; i++) {
if (port[i].in_use && jack_port_name_equals (&port[i], port_name)) {
return jack_port_new (client, port[i].id,
@@ -510,6 +511,7 @@ jack_port_by_name (jack_client_t *client, const char *port_name)
{
JSList *node;
jack_port_t* port;
+
for (node = client->ports_ext; node; node = jack_slist_next (node)) {
port = node->data;
if (jack_port_name_equals (port->shared, port_name)) {
@@ -517,13 +519,14 @@ jack_port_by_name (jack_client_t *client, const char *port_name)
return port;
}
}
-
+
/* Otherwise allocate a new port structure, keep it in the
* ports_ext list for later use. */
port = jack_port_by_name_int (client, port_name);
- if (port != NULL)
+ if (port != NULL) {
client->ports_ext =
jack_slist_prepend (client->ports_ext, port);
+ }
return port;
}
@@ -543,7 +546,7 @@ void
jack_port_set_latency (jack_port_t *port, jack_nframes_t nframes)
{
port->shared->latency = nframes;
-
+
/* setup the new latency values here,
* so we dont need to change the backend codes.
*/
@@ -564,15 +567,15 @@ jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
/* Output port. The buffer was assigned by the engine
when the port was registered.
- */
+ */
if (port->shared->flags & JackPortIsOutput) {
if (port->tied) {
return jack_port_get_buffer (port->tied, nframes);
}
-
- if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
- return NULL;
- }
+
+ if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
+ return NULL;
+ }
return jack_output_port_buffer (port);
}
@@ -581,23 +584,23 @@ jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
process() callback, and since no connections can be
made/broken during this phase (enforced by the jack
server), there is no need to take the connection lock here
- */
+ */
if ((node = port->connections) == NULL) {
-
- if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
- return NULL;
- }
+
+ if (port->client_segment_base == NULL || *port->client_segment_base == MAP_FAILED) {
+ return NULL;
+ }
/* no connections; return a zero-filled buffer */
- return (void *) (*(port->client_segment_base) + port->type_info->zero_buffer_offset);
+ return (void*)(*(port->client_segment_base) + port->type_info->zero_buffer_offset);
}
if ((next = jack_slist_next (node)) == NULL) {
/* one connection: use zero-copy mode - just pass
the buffer of the connected (output) port.
- */
- return jack_port_get_buffer (((jack_port_t *) node->data),
+ */
+ return jack_port_get_buffer (((jack_port_t*)node->data),
nframes);
}
@@ -605,25 +608,25 @@ jack_port_get_buffer (jack_port_t *port, jack_nframes_t nframes)
incoming data into that buffer. We have already
established the existence of a mixdown function during the
connection process.
- */
+ */
if (port->mix_buffer == NULL) {
- jack_error( "internal jack error: mix_buffer not allocated" );
+ jack_error ( "internal jack error: mix_buffer not allocated" );
return NULL;
}
port->fptr.mixdown (port, nframes);
- return (void *) port->mix_buffer;
+ return (void*)port->mix_buffer;
}
size_t
jack_port_type_buffer_size (jack_port_type_info_t* port_type_info, jack_nframes_t nframes)
{
- if( port_type_info->buffer_scale_factor < 0 ) {
+ if ( port_type_info->buffer_scale_factor < 0 ) {
return port_type_info->buffer_size;
- }
+ }
return port_type_info->buffer_scale_factor
- * sizeof (jack_default_audio_sample_t)
- * nframes;
+ * sizeof(jack_default_audio_sample_t)
+ * nframes;
}
int
@@ -655,7 +658,7 @@ jack_port_untie (jack_port_t *port)
return 0;
}
-int
+int
jack_port_request_monitor (jack_port_t *port, int onoff)
{
@@ -669,21 +672,21 @@ jack_port_request_monitor (jack_port_t *port, int onoff)
JSList *node;
- /* this port is for input, so recurse over each of the
+ /* this port is for input, so recurse over each of the
connected ports.
*/
pthread_mutex_lock (&port->connection_lock);
for (node = port->connections; node;
node = jack_slist_next (node)) {
-
+
/* drop the lock because if there is a feedback loop,
we will deadlock. XXX much worse things will
happen if there is a feedback loop !!!
- */
+ */
pthread_mutex_unlock (&port->connection_lock);
- jack_port_request_monitor ((jack_port_t *) node->data,
+ jack_port_request_monitor ((jack_port_t*)node->data,
onoff);
pthread_mutex_lock (&port->connection_lock);
}
@@ -692,8 +695,8 @@ jack_port_request_monitor (jack_port_t *port, int onoff)
return 0;
}
-
-int
+
+int
jack_port_request_monitor_by_name (jack_client_t *client,
const char *port_name, int onoff)
@@ -704,7 +707,7 @@ jack_port_request_monitor_by_name (jack_client_t *client,
limit = client->engine->port_max;
ports = &client->engine->ports[0];
-
+
for (i = 0; i < limit; i++) {
if (ports[i].in_use &&
strcmp (ports[i].name, port_name) == 0) {
@@ -757,14 +760,14 @@ int
jack_port_get_aliases (const jack_port_t *port, char* const aliases[2])
{
int cnt = 0;
-
+
if (port->shared->alias1[0] != '\0') {
- snprintf (aliases[0], JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE, "%s", port->shared->alias1);
+ snprintf (aliases[0], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", port->shared->alias1);
cnt++;
}
if (port->shared->alias2[0] != '\0') {
- snprintf (aliases[1], JACK_CLIENT_NAME_SIZE+JACK_PORT_NAME_SIZE, "%s", port->shared->alias2);
+ snprintf (aliases[1], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", port->shared->alias2);
cnt++;
}
@@ -776,12 +779,12 @@ jack_port_short_name (const jack_port_t *port)
{
/* we know there is always a colon, because we put
it there ...
- */
+ */
return strchr (port->shared->name, ':') + 1;
}
-int
+int
jack_port_is_mine (const jack_client_t *client, const jack_port_t *port)
{
return jack_uuid_compare (port->shared->client_id, client->control->uuid) == 0;
@@ -813,16 +816,16 @@ jack_port_rename (jack_client_t* client, jack_port_t *port, const char *new_name
req.type = PortNameChanged;
/* re-purpose an appropriate part of the request union to convey the names */
- snprintf ((char *) req.x.connect.source_port, JACK_PORT_NAME_SIZE-1, "%s", old_name);
- snprintf ((char *) req.x.connect.destination_port, JACK_PORT_NAME_SIZE-1, "%s", new_name);
-
- (void) jack_client_deliver_request (client, &req);
+ snprintf ((char*)req.x.connect.source_port, JACK_PORT_NAME_SIZE - 1, "%s", old_name);
+ snprintf ((char*)req.x.connect.destination_port, JACK_PORT_NAME_SIZE - 1, "%s", new_name);
+
+ (void)jack_client_deliver_request (client, &req);
}
free (old_name);
return ret;
-}
+}
int
jack_port_set_name (jack_port_t *port, const char *new_name)
{
@@ -832,13 +835,13 @@ jack_port_set_name (jack_port_t *port, const char *new_name)
if (strcmp (new_name, port->shared->name) == 0) {
return 0;
}
-
+
colon = strchr (port->shared->name, ':');
- len = sizeof (port->shared->name) -
- ((int) (colon - port->shared->name)) - 2;
- snprintf (colon+1, len, "%s", new_name);
+ len = sizeof(port->shared->name) -
+ ((int)(colon - port->shared->name)) - 2;
+ snprintf (colon + 1, len, "%s", new_name);
+
-
return 0;
}
@@ -846,9 +849,9 @@ int
jack_port_set_alias (jack_port_t *port, const char *alias)
{
if (port->shared->alias1[0] == '\0') {
- snprintf (port->shared->alias1, sizeof (port->shared->alias1), "%s", alias);
+ snprintf (port->shared->alias1, sizeof(port->shared->alias1), "%s", alias);
} else if (port->shared->alias2[0] == '\0') {
- snprintf (port->shared->alias2, sizeof (port->shared->alias2), "%s", alias);
+ snprintf (port->shared->alias2, sizeof(port->shared->alias2), "%s", alias);
} else {
return -1;
}
@@ -870,55 +873,59 @@ jack_port_unset_alias (jack_port_t *port, const char *alias)
return 0;
}
-void
+void
jack_port_set_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
{
if (mode == JackCaptureLatency) {
port->shared->capture_latency = *range;
- /* hack to set port->shared->latency up for
+ /* hack to set port->shared->latency up for
* backend ports
*/
- if ((port->shared->flags & JackPortIsOutput) && (port->shared->flags & JackPortIsPhysical))
+ if ((port->shared->flags & JackPortIsOutput) && (port->shared->flags & JackPortIsPhysical)) {
port->shared->latency = (range->min + range->max) / 2;
+ }
} else {
port->shared->playback_latency = *range;
- /* hack to set port->shared->latency up for
+ /* hack to set port->shared->latency up for
* backend ports
*/
- if ((port->shared->flags & JackPortIsInput) && (port->shared->flags & JackPortIsPhysical))
+ if ((port->shared->flags & JackPortIsInput) && (port->shared->flags & JackPortIsPhysical)) {
port->shared->latency = (range->min + range->max) / 2;
+ }
}
}
-void
+void
jack_port_get_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
{
- if (mode == JackCaptureLatency)
+ if (mode == JackCaptureLatency) {
*range = port->shared->capture_latency;
- else
+ } else {
*range = port->shared->playback_latency;
+ }
}
/* AUDIO PORT SUPPORT */
-static inline float f_max(float x, float a)
+static inline float f_max (float x, float a)
{
x -= a;
x += fabs (x);
x *= 0.5;
x += a;
- return (x);
+ return x;
}
-static void
+static void
jack_audio_port_mixdown (jack_port_t *port, jack_nframes_t nframes)
{
JSList *node;
jack_port_t *input;
+
#ifndef ARCH_X86
jack_nframes_t n;
jack_default_audio_sample_t *dst, *src;
@@ -928,39 +935,39 @@ jack_audio_port_mixdown (jack_port_t *port, jack_nframes_t nframes)
/* by the time we've called this, we've already established
the existence of more than one connection to this input
port and allocated a mix_buffer.
- */
+ */
/* no need to take connection lock, since this is called
from the process() callback, and the jack server
ensures that no changes to connections happen
during this time.
- */
+ */
node = port->connections;
- input = (jack_port_t *) node->data;
+ input = (jack_port_t*)node->data;
buffer = port->mix_buffer;
#ifndef USE_DYNSIMD
memcpy (buffer, jack_output_port_buffer (input),
- sizeof (jack_default_audio_sample_t) * nframes);
-#else /* USE_DYNSIMD */
+ sizeof(jack_default_audio_sample_t) * nframes);
+#else /* USE_DYNSIMD */
opt_copy (buffer, jack_output_port_buffer (input), nframes);
#endif /* USE_DYNSIMD */
for (node = jack_slist_next (node); node;
node = jack_slist_next (node)) {
- input = (jack_port_t *) node->data;
+ input = (jack_port_t*)node->data;
#ifndef USE_DYNSIMD
n = nframes;
dst = buffer;
src = jack_output_port_buffer (input);
- while (n--) {
+ while (n--)
*dst++ += *src++;
- }
-#else /* USE_DYNSIMD */
+
+#else /* USE_DYNSIMD */
opt_mix (buffer, jack_output_port_buffer (input), nframes);
#endif /* USE_DYNSIMD */
}
diff --git a/libjack/ringbuffer.c b/libjack/ringbuffer.c
index c06a1b2..b8cf3e6 100644
--- a/libjack/ringbuffer.c
+++ b/libjack/ringbuffer.c
@@ -1,24 +1,24 @@
/*
- Copyright (C) 2000 Paul Davis
- Copyright (C) 2003 Rohan Drape
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- ISO/POSIX C version of Paul Davis's lock free ringbuffer C++ code.
- This is safe for the case of one read thread and one write thread.
-*/
+ Copyright (C) 2000 Paul Davis
+ Copyright (C) 2003 Rohan Drape
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ ISO/POSIX C version of Paul Davis's lock free ringbuffer C++ code.
+ This is safe for the case of one read thread and one write thread.
+ */
#include <config.h>
@@ -37,13 +37,13 @@ jack_ringbuffer_create (size_t sz)
{
int power_of_two;
jack_ringbuffer_t *rb;
-
- if ((rb = malloc (sizeof (jack_ringbuffer_t))) == NULL) {
+
+ if ((rb = malloc (sizeof(jack_ringbuffer_t))) == NULL) {
return NULL;
}
-
- for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++);
-
+
+ for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++) ;
+
rb->size = 1 << power_of_two;
rb->size_mask = rb->size;
rb->size_mask -= 1;
@@ -54,7 +54,7 @@ jack_ringbuffer_create (size_t sz)
return NULL;
}
rb->mlocked = 0;
-
+
return rb;
}
@@ -67,7 +67,7 @@ jack_ringbuffer_free (jack_ringbuffer_t * rb)
if (rb->mlocked) {
munlock (rb->buf, rb->size);
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
free (rb->buf);
free (rb);
}
@@ -81,7 +81,7 @@ jack_ringbuffer_mlock (jack_ringbuffer_t * rb)
if (mlock (rb->buf, rb->size)) {
return -1;
}
-#endif /* USE_MLOCK */
+#endif /* USE_MLOCK */
rb->mlocked = 1;
return 0;
}
@@ -104,10 +104,10 @@ size_t
jack_ringbuffer_read_space (const jack_ringbuffer_t * rb)
{
size_t w, r;
-
+
w = rb->write_ptr;
r = rb->read_ptr;
-
+
if (w > r) {
return w - r;
} else {
@@ -174,8 +174,8 @@ jack_ringbuffer_read (jack_ringbuffer_t * rb, char *dest, size_t cnt)
return to_read;
}
-/* The copying data reader w/o read pointer advance. Copy at most
- `cnt' bytes from `rb' to `dest'. Returns the actual number of bytes
+/* The copying data reader w/o read pointer advance. Copy at most
+ `cnt' bytes from `rb' to `dest'. Returns the actual number of bytes
copied. */
size_t
@@ -260,6 +260,7 @@ void
jack_ringbuffer_read_advance (jack_ringbuffer_t * rb, size_t cnt)
{
size_t tmp = (rb->read_ptr + cnt) & rb->size_mask;
+
rb->read_ptr = tmp;
}
@@ -269,6 +270,7 @@ void
jack_ringbuffer_write_advance (jack_ringbuffer_t * rb, size_t cnt)
{
size_t tmp = (rb->write_ptr + cnt) & rb->size_mask;
+
rb->write_ptr = tmp;
}
diff --git a/libjack/sanitycheck.c b/libjack/sanitycheck.c
index 257b7ee..b77e254 100644
--- a/libjack/sanitycheck.c
+++ b/libjack/sanitycheck.c
@@ -1,20 +1,20 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <sysdeps/sanitycheck.c>
diff --git a/libjack/shm.c b/libjack/shm.c
index f3401c7..c5e24f2 100644
--- a/libjack/shm.c
+++ b/libjack/shm.c
@@ -12,22 +12,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <config.h>
@@ -58,13 +58,13 @@ static jack_shmtype_t jack_shmtype = shm_SYSV;
#endif
/* interface-dependent forward declarations */
-static int jack_access_registry (jack_shm_info_t *ri);
-static int jack_create_registry (jack_shm_info_t *ri);
-static void jack_remove_shm (jack_shm_id_t *id);
+static int jack_access_registry(jack_shm_info_t *ri);
+static int jack_create_registry(jack_shm_info_t *ri);
+static void jack_remove_shm(jack_shm_id_t *id);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * common interface-independent section
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* common interface-independent section
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* The JACK SHM registry is a chunk of memory for keeping track of the
* shared memory used by each active JACK server. This allows the
@@ -74,10 +74,10 @@ static void jack_remove_shm (jack_shm_id_t *id);
*/
/* per-process global data for the SHM interfaces */
-static jack_shm_id_t registry_id; /* SHM id for the registry */
-static jack_shm_info_t registry_info = { /* SHM info for the registry */
- .index = JACK_SHM_NULL_INDEX,
- .attached_at = MAP_FAILED
+static jack_shm_id_t registry_id; /* SHM id for the registry */
+static jack_shm_info_t registry_info = { /* SHM info for the registry */
+ .index = JACK_SHM_NULL_INDEX,
+ .attached_at = MAP_FAILED
};
/* pointers to registry header and array */
@@ -121,29 +121,29 @@ semaphore_init ()
key_t semkey = JACK_SEMAPHORE_KEY;
struct sembuf sbuf;
int create_flags = IPC_CREAT | IPC_EXCL
- | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
+ | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
/* Get semaphore ID associated with this key. */
- if ((semid = semget(semkey, 0, 0)) == -1) {
+ if ((semid = semget (semkey, 0, 0)) == -1) {
/* Semaphore does not exist - Create. */
- if ((semid = semget(semkey, 1, create_flags)) != -1) {
+ if ((semid = semget (semkey, 1, create_flags)) != -1) {
/* Initialize the semaphore, allow one owner. */
sbuf.sem_num = 0;
sbuf.sem_op = 1;
sbuf.sem_flg = 0;
- if (semop(semid, &sbuf, 1) == -1) {
+ if (semop (semid, &sbuf, 1) == -1) {
semaphore_error ("semop");
}
} else if (errno == EEXIST) {
- if ((semid = semget(semkey, 0, 0)) == -1) {
+ if ((semid = semget (semkey, 0, 0)) == -1) {
semaphore_error ("semget");
}
} else {
- semaphore_error ("semget creation");
+ semaphore_error ("semget creation");
}
}
}
@@ -156,21 +156,22 @@ semaphore_add (int value)
sbuf.sem_num = 0;
sbuf.sem_op = value;
sbuf.sem_flg = SEM_UNDO;
- if (semop(semid, &sbuf, 1) == -1) {
+ if (semop (semid, &sbuf, 1) == -1) {
semaphore_error ("semop");
}
}
-static void
+static void
jack_shm_lock_registry (void)
{
- if (semid == -1)
+ if (semid == -1) {
semaphore_init ();
+ }
semaphore_add (-1);
}
-static void
+static void
jack_shm_unlock_registry (void)
{
semaphore_add (1);
@@ -188,12 +189,11 @@ jack_shm_init_registry ()
jack_shm_header->protocol = jack_protocol_version;
jack_shm_header->type = jack_shmtype;
jack_shm_header->size = JACK_SHM_REGISTRY_SIZE;
- jack_shm_header->hdr_len = sizeof (jack_shm_header_t);
- jack_shm_header->entry_len = sizeof (jack_shm_registry_t);
+ jack_shm_header->hdr_len = sizeof(jack_shm_header_t);
+ jack_shm_header->entry_len = sizeof(jack_shm_registry_t);
- for (i = 0; i < MAX_SHM_ID; ++i) {
+ for (i = 0; i < MAX_SHM_ID; ++i)
jack_shm_registry[i].index = i;
- }
}
static int
@@ -205,10 +205,10 @@ jack_shm_validate_registry ()
&& (jack_shm_header->protocol == jack_protocol_version)
&& (jack_shm_header->type == jack_shmtype)
&& (jack_shm_header->size == JACK_SHM_REGISTRY_SIZE)
- && (jack_shm_header->hdr_len == sizeof (jack_shm_header_t))
- && (jack_shm_header->entry_len == sizeof (jack_shm_registry_t))) {
+ && (jack_shm_header->hdr_len == sizeof(jack_shm_header_t))
+ && (jack_shm_header->entry_len == sizeof(jack_shm_registry_t))) {
- return 0; /* registry OK */
+ return 0; /* registry OK */
}
return -1;
@@ -233,7 +233,7 @@ jack_shm_validate_registry ()
static void
jack_set_server_prefix (const char *server_name)
{
- snprintf (jack_shm_server_prefix, sizeof (jack_shm_server_prefix),
+ snprintf (jack_shm_server_prefix, sizeof(jack_shm_server_prefix),
"/jack-%d:%s:", getuid (), server_name);
}
@@ -246,9 +246,10 @@ jack_server_initialize_shm (int new_registry)
{
int rc;
- if (jack_shm_header)
- return 0; /* already initialized */
+ if (jack_shm_header) {
+ return 0; /* already initialized */
+ }
jack_shm_lock_registry ();
rc = jack_access_registry (&registry_info);
@@ -259,14 +260,15 @@ jack_server_initialize_shm (int new_registry)
}
switch (rc) {
- case ENOENT: /* registry does not exist */
+ case ENOENT: /* registry does not exist */
rc = jack_create_registry (&registry_info);
break;
- case 0: /* existing registry */
- if (jack_shm_validate_registry () == 0)
+ case 0: /* existing registry */
+ if (jack_shm_validate_registry () == 0) {
break;
- /* else it was invalid, so fall through */
- case EINVAL: /* bad registry */
+ }
+ /* else it was invalid, so fall through */
+ case EINVAL: /* bad registry */
/* Apparently, this registry was created by an older
* JACK version. Delete it so we can try again. */
jack_release_shm (&registry_info);
@@ -280,7 +282,7 @@ jack_server_initialize_shm (int new_registry)
#endif
}
break;
- default: /* failure return code */
+ default: /* failure return code */
break;
}
@@ -300,9 +302,10 @@ jack_initialize_shm (const char *server_name)
{
int rc;
- if (jack_shm_header)
- return 0; /* already initialized */
+ if (jack_shm_header) {
+ return 0; /* already initialized */
+ }
jack_set_server_prefix (server_name);
jack_shm_lock_registry ();
@@ -322,9 +325,10 @@ void
jack_destroy_shm (jack_shm_info_t* si)
{
/* must NOT have the registry locked */
- if (si->index == JACK_SHM_NULL_INDEX)
- return; /* segment not allocated */
+ if (si->index == JACK_SHM_NULL_INDEX) {
+ return; /* segment not allocated */
+ }
jack_remove_shm (&jack_shm_registry[si->index].id);
jack_release_shm_info (si->index);
}
@@ -341,7 +345,7 @@ jack_get_free_shm_info ()
break;
}
}
-
+
if (i < MAX_SHM_ID) {
si = &jack_shm_registry[i];
}
@@ -356,21 +360,21 @@ jack_release_shm_entry (jack_shm_registry_index_t index)
jack_shm_registry[index].size = 0;
jack_shm_registry[index].allocator = 0;
memset (&jack_shm_registry[index].id, 0,
- sizeof (jack_shm_registry[index].id));
+ sizeof(jack_shm_registry[index].id));
}
void
jack_release_shm_info (jack_shm_registry_index_t index)
{
/* must NOT have the registry locked */
- if (jack_shm_registry[index].allocator == getpid()) {
+ if (jack_shm_registry[index].allocator == getpid ()) {
jack_shm_lock_registry ();
jack_release_shm_entry (index);
jack_shm_unlock_registry ();
}
}
-/* Claim server_name for this process.
+/* Claim server_name for this process.
*
* returns 0 if successful
* EEXIST if server_name was already active for this user
@@ -387,8 +391,9 @@ jack_register_server (const char *server_name, int new_registry)
jack_info ("JACK compiled with %s SHM support.", JACK_SHM_TYPE);
- if (jack_server_initialize_shm (new_registry))
+ if (jack_server_initialize_shm (new_registry)) {
return ENOMEM;
+ }
jack_shm_lock_registry ();
@@ -399,34 +404,35 @@ jack_register_server (const char *server_name, int new_registry)
if (strncmp (jack_shm_header->server[i].name,
jack_shm_server_prefix,
- JACK_SERVER_NAME_SIZE) != 0)
- continue; /* no match */
+ JACK_SERVER_NAME_SIZE) != 0) {
+ continue; /* no match */
+ }
if (jack_shm_header->server[i].pid == my_pid) {
jack_shm_unlock_registry ();
- return 0; /* it's me */
+ return 0; /* it's me */
}
/* see if server still exists */
if (kill (jack_shm_header->server[i].pid, 0) == 0) {
jack_shm_unlock_registry ();
- return EEXIST; /* other server running */
+ return EEXIST; /* other server running */
}
/* it's gone, reclaim this entry */
memset (&jack_shm_header->server[i], 0,
- sizeof (jack_shm_server_t));
+ sizeof(jack_shm_server_t));
}
/* find a free entry */
- for (i = 0; i < MAX_SERVERS; i++) {
- if (jack_shm_header->server[i].pid == 0)
+ for (i = 0; i < MAX_SERVERS; i++)
+ if (jack_shm_header->server[i].pid == 0) {
break;
- }
+ }
if (i >= MAX_SERVERS) {
jack_shm_unlock_registry ();
- return ENOSPC; /* out of space */
+ return ENOSPC; /* out of space */
}
/* claim it */
@@ -452,7 +458,7 @@ jack_unregister_server (const char *server_name /* unused */)
for (i = 0; i < MAX_SERVERS; i++) {
if (jack_shm_header->server[i].pid == my_pid) {
memset (&jack_shm_header->server[i], 0,
- sizeof (jack_shm_server_t));
+ sizeof(jack_shm_server_t));
}
}
@@ -469,22 +475,23 @@ jack_cleanup_shm ()
pid_t my_pid = getpid ();
jack_shm_lock_registry ();
-
+
for (i = 0; i < MAX_SHM_ID; i++) {
jack_shm_registry_t* r;
r = &jack_shm_registry[i];
- memcpy (&copy, r, sizeof (jack_shm_info_t));
+ memcpy (&copy, r, sizeof(jack_shm_info_t));
destroy = FALSE;
/* ignore unused entries */
- if (r->allocator == 0)
+ if (r->allocator == 0) {
continue;
+ }
/* is this my shm segment? */
if (r->allocator == my_pid) {
- /* allocated by this process, so unattach
+ /* allocated by this process, so unattach
and destroy. */
jack_release_shm (&copy);
destroy = TRUE;
@@ -552,8 +559,8 @@ jack_resize_shm (jack_shm_info_t* si, jack_shmsize_t size)
#ifdef USE_POSIX_SHM
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * POSIX interface-dependent functions
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* POSIX interface-dependent functions
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* gain addressability to existing SHM registry segment
*
@@ -569,7 +576,7 @@ jack_access_registry (jack_shm_info_t *ri)
/* registry must be locked */
int shm_fd;
- strncpy (registry_id, "/jack-shm-registry", sizeof (registry_id));
+ strncpy (registry_id, "/jack-shm-registry", sizeof(registry_id));
/* try to open an existing segment */
if ((shm_fd = shm_open (registry_id, O_RDWR, 0666)) < 0) {
@@ -583,7 +590,7 @@ jack_access_registry (jack_shm_info_t *ri)
}
if ((ri->attached_at = mmap (0, JACK_SHM_REGISTRY_SIZE,
- PROT_READ|PROT_WRITE,
+ PROT_READ | PROT_WRITE,
MAP_SHARED, shm_fd, 0)) == MAP_FAILED) {
jack_error ("cannot mmap shm registry segment (%s)",
strerror (errno));
@@ -594,7 +601,7 @@ jack_access_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
return 0;
}
@@ -612,9 +619,9 @@ jack_create_registry (jack_shm_info_t *ri)
/* registry must be locked */
int shm_fd;
- strncpy (registry_id, "/jack-shm-registry", sizeof (registry_id));
+ strncpy (registry_id, "/jack-shm-registry", sizeof(registry_id));
- if ((shm_fd = shm_open (registry_id, O_RDWR|O_CREAT, 0666)) < 0) {
+ if ((shm_fd = shm_open (registry_id, O_RDWR | O_CREAT, 0666)) < 0) {
int rc = errno;
jack_error ("cannot create shm registry segment (%s)",
strerror (errno));
@@ -633,7 +640,7 @@ jack_create_registry (jack_shm_info_t *ri)
}
if ((ri->attached_at = mmap (0, JACK_SHM_REGISTRY_SIZE,
- PROT_READ|PROT_WRITE,
+ PROT_READ | PROT_WRITE,
MAP_SHARED, shm_fd, 0)) == MAP_FAILED) {
jack_error ("cannot mmap shm registry segment (%s)",
strerror (errno));
@@ -645,7 +652,7 @@ jack_create_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
/* initialize registry contents */
jack_shm_init_registry ();
@@ -661,8 +668,8 @@ jack_remove_shm (jack_shm_id_t *id)
the shm segment, so this failing is not an error.
XXX it would be good to differentiate between these
two conditions.
- */
- shm_unlink ((char *) id);
+ */
+ shm_unlink ((char*)id);
}
void
@@ -681,7 +688,7 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
jack_shm_registry_t* registry;
int shm_fd;
int rc = -1;
- char name[SHM_NAME_MAX+1];
+ char name[SHM_NAME_MAX + 1];
jack_shm_lock_registry ();
@@ -697,14 +704,14 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
* actual names. So, we construct a short name from the
* registry index for uniqueness.
*/
- snprintf (name, sizeof (name), "/jack-%d", registry->index);
+ snprintf (name, sizeof(name), "/jack-%d", registry->index);
- if (strlen (name) >= sizeof (registry->id)) {
+ if (strlen (name) >= sizeof(registry->id)) {
jack_error ("shm segment name too long %s", name);
goto unlock;
}
- if ((shm_fd = shm_open (name, O_RDWR|O_CREAT, 0666)) < 0) {
+ if ((shm_fd = shm_open (name, O_RDWR | O_CREAT, 0666)) < 0) {
jack_error ("cannot create shm segment %s (%s)",
name, strerror (errno));
goto unlock;
@@ -720,13 +727,13 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
close (shm_fd);
registry->size = size;
- strncpy (registry->id, name, sizeof (registry->id));
- registry->allocator = getpid();
+ strncpy (registry->id, name, sizeof(registry->id));
+ registry->allocator = getpid ();
si->index = registry->index;
- si->attached_at = MAP_FAILED; /* not attached */
- rc = 0; /* success */
+ si->attached_at = MAP_FAILED; /* not attached */
+ rc = 0; /* success */
- unlock:
+unlock:
jack_shm_unlock_registry ();
return rc;
}
@@ -744,9 +751,9 @@ jack_attach_shm (jack_shm_info_t* si)
return -1;
}
- if ((si->attached_at = mmap (0, registry->size, PROT_READ|PROT_WRITE,
+ if ((si->attached_at = mmap (0, registry->size, PROT_READ | PROT_WRITE,
MAP_SHARED, shm_fd, 0)) == MAP_FAILED) {
- jack_error ("cannot mmap shm segment %s (%s)",
+ jack_error ("cannot mmap shm segment %s (%s)",
registry->id,
strerror (errno));
close (shm_fd);
@@ -761,8 +768,8 @@ jack_attach_shm (jack_shm_info_t* si)
#else
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * System V interface-dependent functions
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+* System V interface-dependent functions
+* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* gain addressability to existing SHM registry segment
*
@@ -784,15 +791,15 @@ jack_access_registry (jack_shm_info_t *ri)
switch (errno) {
- case ENOENT: /* segment does not exist */
+ case ENOENT: /* segment does not exist */
return ENOENT;
- case EINVAL: /* segment exists, but too small */
+ case EINVAL: /* segment exists, but too small */
/* attempt minimum size access */
registry_id = shmget (JACK_SHM_REGISTRY_KEY, 1, 0666);
return EINVAL;
- default: /* or other error */
+ default: /* or other error */
jack_error ("unable to access shm registry (%s)",
strerror (errno));
return errno;
@@ -808,7 +815,7 @@ jack_access_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
return 0;
}
@@ -826,7 +833,7 @@ jack_create_registry (jack_shm_info_t *ri)
/* registry must be locked */
if ((registry_id = shmget (JACK_SHM_REGISTRY_KEY,
JACK_SHM_REGISTRY_SIZE,
- 0666|IPC_CREAT)) < 0) {
+ 0666 | IPC_CREAT)) < 0) {
jack_error ("cannot create shm registry segment (%s)",
strerror (errno));
return errno;
@@ -841,7 +848,7 @@ jack_create_registry (jack_shm_info_t *ri)
/* set up global pointers */
ri->index = JACK_SHM_REGISTRY_INDEX;
jack_shm_header = ri->attached_at;
- jack_shm_registry = (jack_shm_registry_t *) (jack_shm_header + 1);
+ jack_shm_registry = (jack_shm_registry_t*)(jack_shm_header + 1);
/* initialize registry contents */
jack_shm_init_registry ();
@@ -853,11 +860,11 @@ static void
jack_remove_shm (jack_shm_id_t *id)
{
/* registry may or may not be locked */
- /* this call can fail if we are attempting to
+ /* this call can fail if we are attempting to
remove a segment that was already deleted
- by the client. XXX i suppose the
+ by the client. XXX i suppose the
function should take a "canfail" argument.
- */
+ */
shmctl (*id, IPC_RMID, NULL);
}
@@ -871,7 +878,7 @@ jack_release_shm (jack_shm_info_t* si)
}
int
-jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
+jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
{
int shmflags;
int shmid;
@@ -888,7 +895,7 @@ jack_shmalloc (jack_shmsize_t size, jack_shm_info_t* si)
registry->size = size;
registry->id = shmid;
- registry->allocator = getpid();
+ registry->allocator = getpid ();
si->index = registry->index;
si->attached_at = MAP_FAILED; /* not attached */
rc = 0;
diff --git a/libjack/simd.c b/libjack/simd.c
index 0c2c558..139ba2c 100644
--- a/libjack/simd.c
+++ b/libjack/simd.c
@@ -1,22 +1,22 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
Copyright (C) 2005-2008 Jussi Laako
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <config.h>
@@ -45,23 +45,23 @@ have_3dnow ()
"movl $0x80000001, %%eax\n\t" \
"cpuid\n\t" \
\
- "xorl %%eax, %%eax\n\t" \
+ "xorl %%eax, %%eax\n\t" \
\
"movl $1, %%ecx\n\t" \
"shll $31, %%ecx\n\t" \
"testl %%ecx, %%edx\n\t" \
- "jz tdnow_testexit\n\t" \
+ "jz tdnow_testexit\n\t" \
"movl $1, %%eax\n\t" \
\
"movl $1, %%ecx\n\t" \
"shll $30, %%ecx\n\t" \
"testl %%ecx, %%edx\n\t" \
- "jz tdnow_testexit\n\t" \
+ "jz tdnow_testexit\n\t" \
"movl $2, %%eax\n\t" \
"jmp tdnow_testexit\n\t" \
\
"tdnow_prexit:\n\t" \
- "xorl %%eax, %%eax\n\t" \
+ "xorl %%eax, %%eax\n\t" \
"tdnow_testexit:\n\t"
: "=a" (res)
:
@@ -88,7 +88,7 @@ have_sse ()
"movl $1, %%eax\n\t" \
"cpuid\n\t" \
\
- "xorl %%eax, %%eax\n\t" \
+ "xorl %%eax, %%eax\n\t" \
\
"movl $1, %%ebx\n\t" \
"shll $25, %%ebx\n\t" \
@@ -123,49 +123,47 @@ void
x86_3dnow_copyf (float *dest, const float *src, int length)
{
int i, n1, n2;
- pv2sf m64p_src = (pv2sf) src;
- pv2sf m64p_dest = (pv2sf) dest;
+ pv2sf m64p_src = (pv2sf)src;
+ pv2sf m64p_dest = (pv2sf)dest;
n1 = (length >> 4);
n2 = ((length & 0xf) >> 1);
- for (i = 0; i < n1; i++)
- {
+ for (i = 0; i < n1; i++) {
asm volatile ("movq %0, %%mm0\n\t"
- : : "m" (*m64p_src++) : "mm0", "memory");
+ : : "m" (*m64p_src++) : "mm0", "memory");
asm volatile ("movq %0, %%mm1\n\t"
- : : "m" (*m64p_src++) : "mm1", "memory");
+ : : "m" (*m64p_src++) : "mm1", "memory");
asm volatile ("movq %0, %%mm2\n\t"
- : : "m" (*m64p_src++) : "mm2", "memory");
+ : : "m" (*m64p_src++) : "mm2", "memory");
asm volatile ("movq %0, %%mm3\n\t"
- : : "m" (*m64p_src++) : "mm3", "memory");
+ : : "m" (*m64p_src++) : "mm3", "memory");
asm volatile ("movq %0, %%mm4\n\t"
- : : "m" (*m64p_src++) : "mm4", "memory");
+ : : "m" (*m64p_src++) : "mm4", "memory");
asm volatile ("movq %0, %%mm5\n\t"
- : : "m" (*m64p_src++) : "mm5", "memory");
+ : : "m" (*m64p_src++) : "mm5", "memory");
asm volatile ("movq %0, %%mm6\n\t"
- : : "m" (*m64p_src++) : "mm6", "memory");
+ : : "m" (*m64p_src++) : "mm6", "memory");
asm volatile ("movq %0, %%mm7\n\t"
- : : "m" (*m64p_src++) : "mm7", "memory");
+ : : "m" (*m64p_src++) : "mm7", "memory");
asm volatile ("movq %%mm0, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm0", "memory");
+ : "=m" (*m64p_dest++) : : "mm0", "memory");
asm volatile ("movq %%mm1, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm1", "memory");
+ : "=m" (*m64p_dest++) : : "mm1", "memory");
asm volatile ("movq %%mm2, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm2", "memory");
+ : "=m" (*m64p_dest++) : : "mm2", "memory");
asm volatile ("movq %%mm3, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm3", "memory");
+ : "=m" (*m64p_dest++) : : "mm3", "memory");
asm volatile ("movq %%mm4, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm4", "memory");
+ : "=m" (*m64p_dest++) : : "mm4", "memory");
asm volatile ("movq %%mm5, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm5", "memory");
+ : "=m" (*m64p_dest++) : : "mm5", "memory");
asm volatile ("movq %%mm6, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm6", "memory");
+ : "=m" (*m64p_dest++) : : "mm6", "memory");
asm volatile ("movq %%mm7, %0\n\t"
- : "=m" (*m64p_dest++) : : "mm7", "memory");
+ : "=m" (*m64p_dest++) : : "mm7", "memory");
}
- for (i = 0; i < n2; i++)
- {
+ for (i = 0; i < n2; i++) {
asm volatile (
"movq %1, %%mm0\n\t" \
"movq %%mm0, %0\n\t"
@@ -173,8 +171,7 @@ x86_3dnow_copyf (float *dest, const float *src, int length)
: "m" (*m64p_src++)
: "mm0", "memory");
}
- if (length & 0x1)
- {
+ if (length & 0x1) {
asm volatile (
"movd %1, %%mm0\n\t" \
"movd %%mm0, %0\n\t"
@@ -191,23 +188,21 @@ void
x86_3dnow_add2f (float *dest, const float *src, int length)
{
int i, n;
- pv2sf m64p_dest = (pv2sf) dest;
- pv2sf m64p_src = (pv2sf) src;
+ pv2sf m64p_dest = (pv2sf)dest;
+ pv2sf m64p_src = (pv2sf)src;
n = (length >> 1);
- for (i = 0; i < n; i++)
- {
+ for (i = 0; i < n; i++) {
asm volatile (
"movq %1, %%mm0\n\t" \
"pfadd %2, %%mm0\n\t" \
"movq %%mm0, %0\n\t"
: "=m" (m64p_dest[i])
: "m0" (m64p_dest[i]),
- "m" (m64p_src[i])
+ "m" (m64p_src[i])
: "mm0", "memory");
}
- if (n & 0x1)
- {
+ if (n & 0x1) {
asm volatile (
"movd %1, %%mm0\n\t" \
"movd %2, %%mm1\n\t" \
@@ -215,7 +210,7 @@ x86_3dnow_add2f (float *dest, const float *src, int length)
"movd %%mm0, %0\n\t"
: "=m" (dest[length - 1])
: "m0" (dest[length - 1]),
- "m" (src[length - 1])
+ "m" (src[length - 1])
: "mm0", "mm1", "memory");
}
asm volatile (
@@ -227,59 +222,56 @@ void
x86_sse_copyf (float *dest, const float *src, int length)
{
int i, n1, n2, si3;
- pv4sf m128p_src = (pv4sf) src;
- pv4sf m128p_dest = (pv4sf) dest;
+ pv4sf m128p_src = (pv4sf)src;
+ pv4sf m128p_dest = (pv4sf)dest;
n1 = (length >> 5);
n2 = ((length & 0x1f) >> 2);
si3 = (length & ~0x3);
- for (i = 0; i < n1; i++)
- {
+ for (i = 0; i < n1; i++) {
asm volatile ("movaps %0, %%xmm0\n\t"
- : : "m" (*m128p_src++) : "xmm0", "memory");
+ : : "m" (*m128p_src++) : "xmm0", "memory");
asm volatile ("movaps %0, %%xmm1\n\t"
- : : "m" (*m128p_src++) : "xmm1", "memory");
+ : : "m" (*m128p_src++) : "xmm1", "memory");
asm volatile ("movaps %0, %%xmm2\n\t"
- : : "m" (*m128p_src++) : "xmm2", "memory");
+ : : "m" (*m128p_src++) : "xmm2", "memory");
asm volatile ("movaps %0, %%xmm3\n\t"
- : : "m" (*m128p_src++) : "xmm3", "memory");
+ : : "m" (*m128p_src++) : "xmm3", "memory");
asm volatile ("movaps %0, %%xmm4\n\t"
- : : "m" (*m128p_src++) : "xmm4", "memory");
+ : : "m" (*m128p_src++) : "xmm4", "memory");
asm volatile ("movaps %0, %%xmm5\n\t"
- : : "m" (*m128p_src++) : "xmm5", "memory");
+ : : "m" (*m128p_src++) : "xmm5", "memory");
asm volatile ("movaps %0, %%xmm6\n\t"
- : : "m" (*m128p_src++) : "xmm6", "memory");
+ : : "m" (*m128p_src++) : "xmm6", "memory");
asm volatile ("movaps %0, %%xmm7\n\t"
- : : "m" (*m128p_src++) : "xmm7", "memory");
+ : : "m" (*m128p_src++) : "xmm7", "memory");
asm volatile ("movaps %%xmm0, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm0", "memory");
+ : "=m" (*m128p_dest++) : : "xmm0", "memory");
asm volatile ("movaps %%xmm1, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm1", "memory");
+ : "=m" (*m128p_dest++) : : "xmm1", "memory");
asm volatile ("movaps %%xmm2, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm2", "memory");
+ : "=m" (*m128p_dest++) : : "xmm2", "memory");
asm volatile ("movaps %%xmm3, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm3", "memory");
+ : "=m" (*m128p_dest++) : : "xmm3", "memory");
asm volatile ("movaps %%xmm4, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm4", "memory");
+ : "=m" (*m128p_dest++) : : "xmm4", "memory");
asm volatile ("movaps %%xmm5, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm5", "memory");
+ : "=m" (*m128p_dest++) : : "xmm5", "memory");
asm volatile ("movaps %%xmm6, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm6", "memory");
+ : "=m" (*m128p_dest++) : : "xmm6", "memory");
asm volatile ("movaps %%xmm7, %0\n\t"
- : "=m" (*m128p_dest++) : : "xmm7", "memory");
+ : "=m" (*m128p_dest++) : : "xmm7", "memory");
}
- for (i = 0; i < n2; i++)
- {
+ for (i = 0; i < n2; i++) {
asm volatile (
- "movaps %1, %%xmm0\n\t" \
+ "movaps %1, %%xmm0\n\t" \
"movaps %%xmm0, %0\n\t"
: "=m" (*m128p_dest++)
: "m" (*m128p_src++)
: "xmm0", "memory");
}
- for (i = si3; i < length; i++)
- {
+ for (i = si3; i < length; i++) {
asm volatile (
"movss %1, %%xmm0\n\t" \
"movss %%xmm0, %0\n\t"
@@ -293,38 +285,35 @@ void
x86_sse_add2f (float *dest, const float *src, int length)
{
int i, n, si2;
- pv4sf m128p_src = (pv4sf) src;
- pv4sf m128p_dest = (pv4sf) dest;
+ pv4sf m128p_src = (pv4sf)src;
+ pv4sf m128p_dest = (pv4sf)dest;
- if (__builtin_expect(((long) src & 0xf) || ((long) dest & 0xf), 0))
- {
+ if (__builtin_expect (((long)src & 0xf) || ((long)dest & 0xf), 0)) {
/*jack_error("x86_sse_add2f(): non aligned pointers!");*/
si2 = 0;
goto sse_nonalign;
}
si2 = (length & ~0x3);
n = (length >> 2);
- for (i = 0; i < n; i++)
- {
+ for (i = 0; i < n; i++) {
asm volatile (
- "movaps %1, %%xmm0\n\t" \
+ "movaps %1, %%xmm0\n\t" \
"addps %2, %%xmm0\n\t" \
"movaps %%xmm0, %0\n\t"
: "=m" (m128p_dest[i])
: "m0" (m128p_dest[i]),
- "m" (m128p_src[i])
+ "m" (m128p_src[i])
: "xmm0", "memory");
}
sse_nonalign:
- for (i = si2; i < length; i++)
- {
+ for (i = si2; i < length; i++) {
asm volatile (
"movss %1, %%xmm0\n\t" \
"addss %2, %%xmm0\n\t" \
"movss %%xmm0, %0\n\t"
: "=m" (dest[i])
: "m0" (dest[i]),
- "m" (src[i])
+ "m" (src[i])
: "xmm0", "memory");
}
}
@@ -332,29 +321,29 @@ sse_nonalign:
void x86_sse_f2i (int *dest, const float *src, int length, float scale)
{
int i;
- static const float max[4] __attribute__((aligned(16))) =
- { -1.0F, -1.0F, -1.0F, -1.0F };
- static const float min[4] __attribute__((aligned(16))) =
- { 1.0F, 1.0F, 1.0F, 1.0F };
- float s[4] __attribute__((aligned(16)));
+ static const float max[4] __attribute__((aligned (16))) =
+ { -1.0F, -1.0F, -1.0F, -1.0F };
+ static const float min[4] __attribute__((aligned (16))) =
+ { 1.0F, 1.0F, 1.0F, 1.0F };
+ float s[4] __attribute__((aligned (16)));
s[0] = s[1] = s[2] = s[3] = scale;
asm volatile (
- "movaps %0, %%xmm4\n\t" \
- "movaps %1, %%xmm5\n\t" \
+ "movaps %0, %%xmm4\n\t" \
+ "movaps %1, %%xmm5\n\t" \
"movaps %2, %%xmm6\n\t"
:
: "m" (*max),
- "m" (*min),
- "m" (*s)
+ "m" (*min),
+ "m" (*s)
: "xmm4", "xmm5", "xmm6");
- if (__builtin_expect((((long) dest & 0xf) || ((long) src & 0xf)), 0))
+ if (__builtin_expect ((((long)dest & 0xf) || ((long)src & 0xf)), 0)) {
goto sse_nonalign;
- for (i = 0; i < length; i += 4)
- {
+ }
+ for (i = 0; i < length; i += 4) {
asm volatile (
- "movaps %1, %%xmm1\n\t" \
+ "movaps %1, %%xmm1\n\t" \
"maxps %%xmm4, %%xmm1\n\t" \
"minps %%xmm5, %%xmm1\n\t" \
"mulps %%xmm6, %%xmm1\n\t" \
@@ -367,10 +356,9 @@ void x86_sse_f2i (int *dest, const float *src, int length, float scale)
return;
sse_nonalign:
- for (i = 0; i < length; i += 4)
- {
+ for (i = 0; i < length; i += 4) {
asm volatile (
- "movups %1, %%xmm1\n\t" \
+ "movups %1, %%xmm1\n\t" \
"maxps %%xmm4, %%xmm1\n\t" \
"minps %%xmm5, %%xmm1\n\t" \
"mulps %%xmm6, %%xmm1\n\t" \
@@ -386,7 +374,7 @@ sse_nonalign:
void x86_sse_i2f (float *dest, const int *src, int length, float scale)
{
int i;
- float s[4] __attribute__((aligned(16)));
+ float s[4] __attribute__((aligned (16)));
s[0] = s[1] = s[2] = s[3] = scale;
asm volatile (
@@ -395,10 +383,10 @@ void x86_sse_i2f (float *dest, const int *src, int length, float scale)
: "m" (*s)
: "xmm4" );
- if (__builtin_expect((((long) dest & 0xf) || ((long) src & 0xf)), 0))
- goto sse_nonalign;
- for (i = 0; i < length; i += 4)
- {
+ if (__builtin_expect ((((long)dest & 0xf) || ((long)src & 0xf)), 0)) {
+ goto sse_nonalign;
+ }
+ for (i = 0; i < length; i += 4) {
asm volatile (
"cvtdq2ps %1, %%xmm0\n\t" \
"mulps %%xmm4, %%xmm0\n\t" \
@@ -410,10 +398,9 @@ void x86_sse_i2f (float *dest, const int *src, int length, float scale)
return;
sse_nonalign:
- for (i = 0; i < length; i += 4)
- {
+ for (i = 0; i < length; i += 4) {
asm volatile (
- "movdqu %1, %%xmm1\n\t" \
+ "movdqu %1, %%xmm1\n\t" \
"cvtdq2ps %%xmm1, %%xmm0\n\t" \
"mulps %%xmm4, %%xmm0\n\t" \
"movups %%xmm0, %0\n\t"
@@ -423,7 +410,7 @@ sse_nonalign:
}
}
-#endif /* ARCH_X86 */
+#endif /* ARCH_X86 */
-#endif /* USE_DYNSIMD */
+#endif /* USE_DYNSIMD */
diff --git a/libjack/systemtest.c b/libjack/systemtest.c
index adf464a..2ccb431 100644
--- a/libjack/systemtest.c
+++ b/libjack/systemtest.c
@@ -1,20 +1,20 @@
/*
Copyright (C) 2001-2003 Paul Davis
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
+
+ */
#include <sysdeps/systemtest.c>
diff --git a/libjack/thread.c b/libjack/thread.c
index 70cd03e..d17e7d8 100644
--- a/libjack/thread.c
+++ b/libjack/thread.c
@@ -1,25 +1,25 @@
/*
- Copyright (C) 2004 Paul Davis
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
+ Copyright (C) 2004 Paul Davis
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
- You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
- Thread creation function including workarounds for real-time scheduling
- behaviour on different glibc versions.
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ Thread creation function including workarounds for real-time scheduling
+ behaviour on different glibc versions.
-*/
+
+ */
#include <config.h>
@@ -43,7 +43,7 @@
jack_thread_creator_t jack_thread_creator = pthread_create;
void
-jack_set_thread_creator (jack_thread_creator_t jtc)
+jack_set_thread_creator (jack_thread_creator_t jtc)
{
jack_thread_creator = jtc;
}
@@ -52,10 +52,11 @@ static inline void
log_result (char *msg, int res)
{
char outbuf[500];
- snprintf(outbuf, sizeof(outbuf),
- "jack_client_create_thread: error %d %s: %s",
- res, msg, strerror(res));
- jack_error(outbuf);
+
+ snprintf (outbuf, sizeof(outbuf),
+ "jack_client_create_thread: error %d %s: %s",
+ res, msg, strerror (res));
+ jack_error (outbuf);
}
static void
@@ -64,24 +65,24 @@ maybe_get_capabilities (jack_client_t* client)
#ifdef USE_CAPABILITIES
if (client != 0) {
-
+
jack_request_t req;
if (client->engine->has_capabilities != 0) {
-
+
/* we need to ask the engine for realtime capabilities
before trying to run the thread work function
- */
-
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ */
+
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = SetClientCapabilities;
- req.x.cap_pid = getpid();
-
+ req.x.cap_pid = getpid ();
+
jack_client_deliver_request (client, &req);
-
+
if (req.status) {
-
+
/* what to do? engine is running realtime, it
is using capabilities and has them
(otherwise we would not get an error
@@ -89,51 +90,51 @@ maybe_get_capabilities (jack_client_t* client)
give the client the required capabilities.
for now, allow the client to run, albeit
non-realtime.
- */
-
+ */
+
jack_error ("could not receive realtime capabilities, "
"client will run non-realtime");
-
+
}
}
}
-#endif /* USE_CAPABILITIES */
-}
+#endif /* USE_CAPABILITIES */
+}
static void
-jack_thread_touch_stack()
+jack_thread_touch_stack ()
{
char buf[JACK_THREAD_STACK_TOUCH];
int i;
volatile char *buf_ptr = buf;
- for (i = 0; i < JACK_THREAD_STACK_TOUCH; i++) {
- buf_ptr[i] = (char) (i & 0xff);
- }
+ for (i = 0; i < JACK_THREAD_STACK_TOUCH; i++)
+ buf_ptr[i] = (char)(i & 0xff);
}
-typedef void (* stack_touch_t)();
+typedef void (*stack_touch_t)();
static volatile stack_touch_t ptr_jack_thread_touch_stack = jack_thread_touch_stack;
static void*
jack_thread_proxy (void* varg)
{
- jack_thread_arg_t* arg = (jack_thread_arg_t*) varg;
+ jack_thread_arg_t* arg = (jack_thread_arg_t*)varg;
+
void* (*work)(void*);
void* warg;
jack_client_t* client = arg->client;
if (arg->realtime) {
- ptr_jack_thread_touch_stack();
+ ptr_jack_thread_touch_stack ();
maybe_get_capabilities (client);
- jack_acquire_real_time_scheduling (pthread_self(), arg->priority);
+ jack_acquire_real_time_scheduling (pthread_self (), arg->priority);
}
warg = arg->arg;
work = arg->work_function;
free (arg);
-
+
return work (warg);
}
@@ -148,15 +149,15 @@ jack_client_create_thread (jack_client_t* client,
#ifndef JACK_USE_MACH_THREADS
pthread_attr_t attr;
jack_thread_arg_t* thread_args;
-#endif /* !JACK_USE_MACH_THREADS */
+#endif /* !JACK_USE_MACH_THREADS */
int result = 0;
if (!realtime) {
result = jack_thread_creator (thread, 0, start_routine, arg);
if (result) {
- log_result("creating thread with default parameters",
- result);
+ log_result ("creating thread with default parameters",
+ result);
}
return result;
}
@@ -168,34 +169,34 @@ jack_client_create_thread (jack_client_t* client,
#ifndef JACK_USE_MACH_THREADS
- pthread_attr_init(&attr);
- result = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+ pthread_attr_init (&attr);
+ result = pthread_attr_setinheritsched (&attr, PTHREAD_EXPLICIT_SCHED);
if (result) {
- log_result("requesting explicit scheduling", result);
+ log_result ("requesting explicit scheduling", result);
return result;
}
- result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+ result = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE);
if (result) {
- log_result("requesting joinable thread creation", result);
+ log_result ("requesting joinable thread creation", result);
return result;
}
#ifdef __OpenBSD__
- result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS);
+ result = pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
#else
- result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
+ result = pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
#endif
if (result) {
- log_result("requesting system scheduling scope", result);
+ log_result ("requesting system scheduling scope", result);
return result;
}
- result = pthread_attr_setstacksize(&attr, THREAD_STACK);
- if (result) {
- log_result("setting thread stack size", result);
- return result;
- }
+ result = pthread_attr_setstacksize (&attr, THREAD_STACK);
+ if (result) {
+ log_result ("setting thread stack size", result);
+ return result;
+ }
- if ((thread_args = (jack_thread_arg_t *) malloc (sizeof (jack_thread_arg_t))) == NULL) {
+ if ((thread_args = (jack_thread_arg_t*)malloc (sizeof(jack_thread_arg_t))) == NULL) {
return -1;
}
@@ -211,7 +212,7 @@ jack_client_create_thread (jack_client_t* client,
return result;
}
-#else /* JACK_USE_MACH_THREADS */
+#else /* JACK_USE_MACH_THREADS */
result = jack_thread_creator (thread, 0, start_routine, arg);
if (result) {
@@ -221,8 +222,8 @@ jack_client_create_thread (jack_client_t* client,
/* time constraint thread */
setThreadToPriority (*thread, 96, TRUE, 10000000);
-
-#endif /* JACK_USE_MACH_THREADS */
+
+#endif /* JACK_USE_MACH_THREADS */
return 0;
}
@@ -233,7 +234,7 @@ jack_client_real_time_priority (jack_client_t* client)
if (!client->engine->real_time) {
return -1;
}
-
+
return client->engine->client_priority;
}
@@ -247,20 +248,20 @@ jack_client_max_real_time_priority (jack_client_t* client)
return client->engine->max_client_priority;
}
-#if JACK_USE_MACH_THREADS
+#if JACK_USE_MACH_THREADS
int
jack_drop_real_time_scheduling (pthread_t thread)
{
- setThreadToPriority(thread, 31, FALSE, 10000000);
- return 0;
+ setThreadToPriority (thread, 31, FALSE, 10000000);
+ return 0;
}
int
jack_acquire_real_time_scheduling (pthread_t thread, int priority)
- //priority is unused
+//priority is unused
{
- setThreadToPriority(thread, 96, TRUE, 10000000);
+ setThreadToPriority (thread, 96, TRUE, 10000000);
return 0;
}
@@ -271,8 +272,8 @@ jack_drop_real_time_scheduling (pthread_t thread)
{
struct sched_param rtparam;
int x;
-
- memset (&rtparam, 0, sizeof (rtparam));
+
+ memset (&rtparam, 0, sizeof(rtparam));
rtparam.sched_priority = 0;
if ((x = pthread_setschedparam (thread, SCHED_OTHER, &rtparam)) != 0) {
@@ -280,7 +281,7 @@ jack_drop_real_time_scheduling (pthread_t thread)
strerror (errno));
return -1;
}
- return 0;
+ return 0;
}
int
@@ -288,20 +289,20 @@ jack_acquire_real_time_scheduling (pthread_t thread, int priority)
{
struct sched_param rtparam;
int x;
-
- memset (&rtparam, 0, sizeof (rtparam));
+
+ memset (&rtparam, 0, sizeof(rtparam));
rtparam.sched_priority = priority;
-
+
if ((x = pthread_setschedparam (thread, SCHED_FIFO, &rtparam)) != 0) {
jack_error ("cannot use real-time scheduling (FIFO at priority %d) "
- "[for thread %d, from thread %d] (%d: %s)",
- rtparam.sched_priority,
- thread, pthread_self(),
+ "[for thread %d, from thread %d] (%d: %s)",
+ rtparam.sched_priority,
+ thread, pthread_self (),
x, strerror (x));
return -1;
}
- return 0;
+ return 0;
}
#endif /* JACK_USE_MACH_THREADS */
diff --git a/libjack/time.c b/libjack/time.c
index d450aa6..f476ebf 100644
--- a/libjack/time.c
+++ b/libjack/time.c
@@ -2,22 +2,22 @@
/*
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2005 Jussi Laako
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <config.h>
@@ -62,26 +62,28 @@ jack_clock_source_name (jack_timer_type_t src)
#ifndef HAVE_CLOCK_GETTIME
-jack_time_t
-jack_get_microseconds_from_system (void) {
+jack_time_t
+jack_get_microseconds_from_system (void)
+{
jack_time_t jackTime;
struct timeval tv;
gettimeofday (&tv, NULL);
- jackTime = (jack_time_t) tv.tv_sec * 1000000 + (jack_time_t) tv.tv_usec;
+ jackTime = (jack_time_t)tv.tv_sec * 1000000 + (jack_time_t)tv.tv_usec;
return jackTime;
}
#else
-jack_time_t
-jack_get_microseconds_from_system (void) {
+jack_time_t
+jack_get_microseconds_from_system (void)
+{
jack_time_t jackTime;
struct timespec time;
- clock_gettime(CLOCK_MONOTONIC, &time);
- jackTime = (jack_time_t) time.tv_sec * 1e6 +
- (jack_time_t) time.tv_nsec / 1e3;
+ clock_gettime (CLOCK_MONOTONIC, &time);
+ jackTime = (jack_time_t)time.tv_sec * 1e6 +
+ (jack_time_t)time.tv_nsec / 1e3;
return jackTime;
}
diff --git a/libjack/transclient.c b/libjack/transclient.c
index 5a6fd08..9d92c36 100644
--- a/libjack/transclient.c
+++ b/libjack/transclient.c
@@ -3,22 +3,22 @@
Copyright (C) 2001-2003 Paul Davis
Copyright (C) 2003 Jack O'Quin
-
+
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1
of the License, or (at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
-*/
+ */
#include <config.h>
#include <errno.h>
@@ -39,7 +39,7 @@ jack_unique_t
jack_generate_unique_id (jack_control_t *ectl)
{
/* The jack_unique_t is an opaque type. */
- return exchange_and_add(&ectl->seq_number, 1);
+ return exchange_and_add (&ectl->seq_number, 1);
}
static inline void
@@ -49,7 +49,7 @@ jack_read_frame_time (const jack_client_t *client, jack_frame_timer_t *copy)
long timeout = 1000;
do {
- /* throttle the busy wait if we don't get
+ /* throttle the busy wait if we don't get
the answer very quickly.
XXX This is disgusting. on a UP
@@ -58,7 +58,7 @@ jack_read_frame_time (const jack_client_t *client, jack_frame_timer_t *copy)
system, it should wait for half of
the context switch time before
sleeping.
- */
+ */
if (tries > 10) {
usleep (20);
@@ -67,7 +67,7 @@ jack_read_frame_time (const jack_client_t *client, jack_frame_timer_t *copy)
/* debug code to avoid system hangs... */
if (--timeout == 0) {
jack_error ("hung in loop copying position A");
- abort();
+ abort ();
}
}
@@ -97,7 +97,7 @@ jack_transport_copy_position (jack_position_t *from, jack_position_t *to)
/* debug code to avoid system hangs... */
if (--timeout == 0) {
jack_error ("hung in loop copying position B");
- abort();
+ abort ();
}
}
*to = *from;
@@ -112,7 +112,7 @@ jack_transport_request_new_pos (jack_client_t *client, jack_position_t *pos)
jack_control_t *ectl = client->engine;
/* distinguish this request from all others */
- pos->unique_1 = pos->unique_2 = jack_generate_unique_id(ectl);
+ pos->unique_1 = pos->unique_2 = jack_generate_unique_id (ectl);
/* clients may not set these fields */
pos->usecs = ectl->current_time.usecs;
@@ -120,7 +120,7 @@ jack_transport_request_new_pos (jack_client_t *client, jack_position_t *pos)
/* carefully copy requested postion into shared memory */
jack_transport_copy_position (pos, &ectl->request_time);
-
+
return 0;
}
@@ -139,8 +139,8 @@ jack_call_sync_client (jack_client_t *client)
control->active_slowsync) {
if (client->sync_cb (ectl->transport_state,
- &ectl->current_time,
- client->sync_arg)) {
+ &ectl->current_time,
+ client->sync_arg)) {
if (control->sync_poll) {
control->sync_poll = 0;
@@ -156,14 +156,14 @@ jack_call_timebase_master (jack_client_t *client)
{
jack_client_control_t *control = client->control;
jack_control_t *ectl = client->engine;
- int new_pos = (int) ectl->pending_pos;
+ int new_pos = (int)ectl->pending_pos;
+
-
/* Make sure this is still the master; is_timebase is set in a
* critical section; timebase_cb is not. */
- if (control->is_timebase) {
+ if (control->is_timebase) {
- if (control->timebase_new) { /* first callback? */
+ if (control->timebase_new) { /* first callback? */
control->timebase_new = 0;
new_pos = 1;
}
@@ -173,10 +173,10 @@ jack_call_timebase_master (jack_client_t *client)
new_pos) {
client->timebase_cb (ectl->transport_state,
- ectl->buffer_size,
- &ectl->pending_time,
- new_pos,
- client->timebase_arg);
+ ectl->buffer_size,
+ &ectl->pending_time,
+ new_pos,
+ client->timebase_arg);
}
} else {
@@ -194,35 +194,35 @@ jack_call_timebase_master (jack_client_t *client)
jack_nframes_t
jack_get_current_transport_frame (const jack_client_t *client)
{
- jack_position_t position;
+ jack_position_t position;
float usecs;
jack_nframes_t elapsed;
jack_transport_state_t tstate;
- /* get the current transport position information.
+ /* get the current transport position information.
this is thread-safe and atomic with respect
to the structure contents.
- */
+ */
tstate = jack_transport_query (client, &position);
-
+
if (tstate != JackTransportRolling) {
return position.frame;
}
-
+
/* compute the elapsed usecs then audio frames since
the transport info was last updated
- */
-
- usecs = jack_get_microseconds() - position.usecs;
- elapsed = (jack_nframes_t) floor ((((float) position.frame_rate)
- / 1000000.0f) * usecs);
+ */
+
+ usecs = jack_get_microseconds () - position.usecs;
+ elapsed = (jack_nframes_t)floor ((((float)position.frame_rate)
+ / 1000000.0f) * usecs);
/* return the estimated transport frame position
*/
-
+
return position.frame + elapsed;
-}
+}
jack_nframes_t
jack_frames_since_cycle_start (const jack_client_t *client)
@@ -230,59 +230,59 @@ jack_frames_since_cycle_start (const jack_client_t *client)
float usecs;
jack_control_t *ectl = client->engine;
- usecs = jack_get_microseconds() - ectl->current_time.usecs;
- return (jack_nframes_t) floor ((((float) ectl->current_time.frame_rate)
- / 1000000.0f) * usecs);
+ usecs = jack_get_microseconds () - ectl->current_time.usecs;
+ return (jack_nframes_t)floor ((((float)ectl->current_time.frame_rate)
+ / 1000000.0f) * usecs);
}
int
jack_get_cycle_times (const jack_client_t *client,
jack_nframes_t *current_frames,
- jack_time_t *current_usecs,
- jack_time_t *next_usecs,
+ jack_time_t *current_usecs,
+ jack_time_t *next_usecs,
float *period_usecs)
{
jack_frame_timer_t time;
jack_read_frame_time (client, &time);
if (time.initialized) {
- *current_frames = time.frames;
- *current_usecs = time.current_wakeup;
- *next_usecs = time.next_wakeup;
- *period_usecs = time.period_usecs;
- return 0;
+ *current_frames = time.frames;
+ *current_usecs = time.current_wakeup;
+ *next_usecs = time.next_wakeup;
+ *period_usecs = time.period_usecs;
+ return 0;
}
return 1;
}
jack_time_t
-jack_get_time()
+jack_get_time ()
{
- return jack_get_microseconds();
+ return jack_get_microseconds ();
}
jack_nframes_t
-jack_time_to_frames(const jack_client_t *client, jack_time_t usecs)
+jack_time_to_frames (const jack_client_t *client, jack_time_t usecs)
{
jack_frame_timer_t time;
jack_control_t *ectl = client->engine;
jack_read_frame_time (client, &time);
if (time.initialized) {
- /*
- Make sure we have signed differences. It would make a lot of sense
- to use the standard signed intNN_t types everywhere instead of e.g.
- jack_nframes_t and jack_time_t. This would at least ensure that the
- types used below are the correct ones. There is no way to get a type
- that would be 'a signed version of jack_time_t' for example - the
- types below are inherently fragile and there is no automatic way to
- check they are the correct ones. The only way is to check manually
- against jack/types.h. FA - 16/02/2012
- */
- int64_t du = usecs - time.current_wakeup;
- int64_t dp = time.next_wakeup - time.current_wakeup;
- return time.frames + (int32_t) floor (((double) du / (double) dp
- * ectl->buffer_size) + 0.5);
+ /*
+ Make sure we have signed differences. It would make a lot of sense
+ to use the standard signed intNN_t types everywhere instead of e.g.
+ jack_nframes_t and jack_time_t. This would at least ensure that the
+ types used below are the correct ones. There is no way to get a type
+ that would be 'a signed version of jack_time_t' for example - the
+ types below are inherently fragile and there is no automatic way to
+ check they are the correct ones. The only way is to check manually
+ against jack/types.h. FA - 16/02/2012
+ */
+ int64_t du = usecs - time.current_wakeup;
+ int64_t dp = time.next_wakeup - time.current_wakeup;
+ return time.frames + (int32_t)floor (((double)du / (double)dp
+ * ectl->buffer_size) + 0.5);
}
return 0;
}
@@ -290,8 +290,9 @@ jack_time_to_frames(const jack_client_t *client, jack_time_t usecs)
jack_nframes_t
jack_frame_time (const jack_client_t *client)
{
- jack_time_t now = jack_get_microseconds();
- return jack_time_to_frames(client, now);
+ jack_time_t now = jack_get_microseconds ();
+
+ return jack_time_to_frames (client, now);
}
jack_nframes_t
@@ -301,28 +302,28 @@ jack_last_frame_time (const jack_client_t *client)
}
jack_time_t
-jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames)
+jack_frames_to_time (const jack_client_t *client, jack_nframes_t frames)
{
jack_frame_timer_t time;
jack_control_t *ectl = client->engine;
jack_read_frame_time (client, &time);
if (time.initialized) {
- /*
- Make sure we have signed differences. It would make a lot of sense
- to use the standard signed intNN_t types everywhere instead of e.g.
- jack_nframes_t and jack_time_t. This would at least ensure that the
- types used below are the correct ones. There is no way to get a type
- that would be 'a signed version of jack_time_t' for example - the
- types below are inherently fragile and there is no automatic way to
- check they are the correct ones. The only way is to check manually
- against jack/types.h. FA - 16/02/2012
- */
- int32_t df = frames - time.frames;
- int64_t dp = time.next_wakeup - time.current_wakeup;
- return time.current_wakeup + (int64_t) floor (((double) df * (double) dp
- / ectl->buffer_size) + 0.5);
- }
+ /*
+ Make sure we have signed differences. It would make a lot of sense
+ to use the standard signed intNN_t types everywhere instead of e.g.
+ jack_nframes_t and jack_time_t. This would at least ensure that the
+ types used below are the correct ones. There is no way to get a type
+ that would be 'a signed version of jack_time_t' for example - the
+ types below are inherently fragile and there is no automatic way to
+ check they are the correct ones. The only way is to check manually
+ against jack/types.h. FA - 16/02/2012
+ */
+ int32_t df = frames - time.frames;
+ int64_t dp = time.next_wakeup - time.current_wakeup;
+ return time.current_wakeup + (int64_t)floor (((double)df * (double)dp
+ / ectl->buffer_size) + 0.5);
+ }
return 0;
}
@@ -351,15 +352,15 @@ jack_set_sample_rate_callback (jack_client_t *client,
return 0;
}
-int
+int
jack_release_timebase (jack_client_t *client)
{
int rc;
jack_request_t req;
jack_client_control_t *ctl = client->control;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = ResetTimeBaseClient;
jack_uuid_copy (&req.x.client_id, ctl->uuid);
@@ -373,7 +374,7 @@ jack_release_timebase (jack_client_t *client)
return rc;
}
-int
+int
jack_set_sync_callback (jack_client_t *client,
JackSyncCallback sync_callback, void *arg)
{
@@ -381,12 +382,13 @@ jack_set_sync_callback (jack_client_t *client,
jack_request_t req;
int rc;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
- if (sync_callback)
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
+ if (sync_callback) {
req.type = SetSyncClient;
- else
+ } else {
req.type = ResetSyncClient;
+ }
jack_uuid_copy (&req.x.client_id, ctl->uuid);
rc = jack_client_deliver_request (client, &req);
@@ -398,20 +400,20 @@ jack_set_sync_callback (jack_client_t *client,
return rc;
}
-int
+int
jack_set_sync_timeout (jack_client_t *client, jack_time_t usecs)
{
jack_request_t req;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = SetSyncTimeout;
req.x.timeout = usecs;
return jack_client_deliver_request (client, &req);
}
-int
+int
jack_set_timebase_callback (jack_client_t *client, int conditional,
JackTimebaseCallback timebase_cb, void *arg)
{
@@ -419,8 +421,8 @@ jack_set_timebase_callback (jack_client_t *client, int conditional,
jack_request_t req;
jack_client_control_t *ctl = client->control;
- VALGRIND_MEMSET (&req, 0, sizeof (req));
-
+ VALGRIND_MEMSET (&req, 0, sizeof(req));
+
req.type = SetTimeBaseClient;
jack_uuid_copy (&req.x.timebase.client_id, ctl->uuid);
req.x.timebase.conditional = conditional;
@@ -444,14 +446,14 @@ jack_transport_locate (jack_client_t *client, jack_nframes_t frame)
return jack_transport_request_new_pos (client, &pos);
}
-jack_transport_state_t
+jack_transport_state_t
jack_transport_query (const jack_client_t *client, jack_position_t *pos)
{
jack_control_t *ectl = client->engine;
if (pos) {
/* the guarded copy makes this function work in any
- * thread
+ * thread
*/
jack_transport_copy_position (&ectl->current_time, pos);
}
@@ -466,13 +468,14 @@ jack_transport_reposition (jack_client_t *client, const jack_position_t *pos)
jack_position_t tmp = *pos;
/* validate input */
- if (tmp.valid & ~JACK_POSITION_MASK) /* unknown field present? */
+ if (tmp.valid & ~JACK_POSITION_MASK) { /* unknown field present? */
return EINVAL;
+ }
return jack_transport_request_new_pos (client, &tmp);
}
-void
+void
jack_transport_start (jack_client_t *client)
{
client->engine->transport_cmd = TransportCommandStart;
@@ -494,7 +497,7 @@ jack_engine_takeover_timebase (jack_client_t *client)
{
jack_error ("jack_engine_takeover_timebase() is no longer supported.");
return ENOSYS;
-}
+}
void
jack_get_transport_info (jack_client_t *client,
@@ -503,14 +506,15 @@ jack_get_transport_info (jack_client_t *client,
jack_control_t *ectl = client->engine;
static int first_time = 1;
- if (first_time)
+ if (first_time) {
jack_error ("jack_get_transport_info() is deprecated.");
+ }
first_time = 0;
/* check that this is the process thread */
- if (!pthread_equal(client->thread_id, pthread_self())) {
- jack_error("Invalid thread for jack_get_transport_info().");
- abort(); /* kill this client */
+ if (!pthread_equal (client->thread_id, pthread_self ())) {
+ jack_error ("Invalid thread for jack_get_transport_info().");
+ abort (); /* kill this client */
}
info->usecs = ectl->current_time.usecs;
@@ -538,9 +542,10 @@ jack_set_transport_info (jack_client_t *client,
{
static int first_time = 1;
- if (first_time)
+ if (first_time) {
jack_error ("jack_set_transport_info() no longer supported.");
+ }
first_time = 0;
-}
+}
#endif /* OLD_TRANSPORT */
diff --git a/libjack/unlock.c b/libjack/unlock.c
index fc04278..9c1a37e 100644
--- a/libjack/unlock.c
+++ b/libjack/unlock.c
@@ -1,22 +1,22 @@
/* -*- mode: c; c-file-style: "bsd"; -*- */
/*
Copyright (C) 2004 Paul Davis
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <stdio.h>
#include <unistd.h>
@@ -46,8 +46,8 @@ static char* library_roots[] = {
"/usr/lib",
"/usr/local/lib",
"/usr/X11R6/lib",
- "/opt/lib", /* solaris-y */
- "/opt/local/lib", /* common on OS X */
+ "/opt/lib", /* solaris-y */
+ "/opt/local/lib", /* common on OS X */
NULL
};
@@ -57,13 +57,13 @@ cleanup_mlock ()
FILE* map;
size_t start;
size_t end;
- char path[PATH_MAX+1];
+ char path[PATH_MAX + 1];
int unlock;
int i;
int whoknows;
int looks_like_library;
- snprintf (path, sizeof(path), "/proc/%d/maps", getpid());
+ snprintf (path, sizeof(path), "/proc/%d/maps", getpid ());
if ((map = fopen (path, "r")) == NULL) {
jack_error ("can't open map file");
@@ -98,7 +98,7 @@ cleanup_mlock ()
if (!looks_like_library) {
continue;
}
-
+
for (i = 0; blacklist[i]; ++i) {
if (strstr (path, blacklist[i])) {
unlock = 1;
@@ -109,21 +109,21 @@ cleanup_mlock ()
if (end - start > 1048576) {
unlock = 1;
}
-
+
for (i = 0; whitelist[i]; ++i) {
if (strstr (path, whitelist[i])) {
unlock = 0;
break;
}
}
-
+
if (unlock) {
jack_info ("unlocking %s", path);
- munlock ((char *) start, end - start);
+ munlock ((char*)start, end - start);
}
}
fclose (map);
}
-
-
+
+
diff --git a/libjack/uuid.c b/libjack/uuid.c
index 9a3894d..9b86f5f 100644
--- a/libjack/uuid.c
+++ b/libjack/uuid.c
@@ -5,17 +5,17 @@
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public License
- along with this program; if not, write to the Free Software
+ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ */
#include <stdio.h>
#include <stdint.h>
@@ -26,87 +26,89 @@
#include "internal.h"
static pthread_mutex_t uuid_lock = PTHREAD_MUTEX_INITIALIZER;
-static uint32_t uuid_cnt = 0;
+static uint32_t uuid_cnt = 0;
enum JackUUIDType {
- JackUUIDPort = 0x1,
- JackUUIDClient = 0x2
+ JackUUIDPort = 0x1,
+ JackUUIDClient = 0x2
};
jack_uuid_t
jack_client_uuid_generate ()
{
- jack_uuid_t uuid = JackUUIDClient;
- pthread_mutex_lock (&uuid_lock);
- uuid = (uuid << 32) | ++uuid_cnt;
- pthread_mutex_unlock (&uuid_lock);
- return uuid;
+ jack_uuid_t uuid = JackUUIDClient;
+
+ pthread_mutex_lock (&uuid_lock);
+ uuid = (uuid << 32) | ++uuid_cnt;
+ pthread_mutex_unlock (&uuid_lock);
+ return uuid;
}
jack_uuid_t
jack_port_uuid_generate (uint32_t port_id)
{
- jack_uuid_t uuid = JackUUIDPort;
- uuid = (uuid << 32) | (port_id + 1);
- return uuid;
+ jack_uuid_t uuid = JackUUIDPort;
+
+ uuid = (uuid << 32) | (port_id + 1);
+ return uuid;
}
uint32_t
jack_uuid_to_index (jack_uuid_t u)
{
- return (u & 0xffff) - 1;
+ return (u & 0xffff) - 1;
}
int
jack_uuid_empty (jack_uuid_t u)
{
- return (u == 0);
+ return u == 0;
}
int
jack_uuid_compare (jack_uuid_t a, jack_uuid_t b)
{
- if (a == b) {
- return 0;
- }
+ if (a == b) {
+ return 0;
+ }
- if (a < b) {
- return -1;
- }
+ if (a < b) {
+ return -1;
+ }
- return 1;
+ return 1;
}
void
jack_uuid_copy (jack_uuid_t* dst, jack_uuid_t src)
{
- *dst = src;
+ *dst = src;
}
void
jack_uuid_clear (jack_uuid_t* u)
{
- *u = 0;
+ *u = 0;
}
void
jack_uuid_unparse (jack_uuid_t u, char b[JACK_UUID_STRING_SIZE])
{
- snprintf (b, JACK_UUID_STRING_SIZE, "%" PRIu64, u);
+ snprintf (b, JACK_UUID_STRING_SIZE, "%" PRIu64, u);
}
int
jack_uuid_parse (const char *b, jack_uuid_t* u)
{
- if (sscanf (b, "%" PRIu64, u) == 1) {
+ if (sscanf (b, "%" PRIu64, u) == 1) {
- if (*u < (0x1LL << 32)) {
- /* has not type bits set - not legal */
- return -1;
- }
+ if (*u < (0x1LL << 32)) {
+ /* has not type bits set - not legal */
+ return -1;
+ }
- return 0;
- }
+ return 0;
+ }
- return -1;
+ return -1;
}