From bc2e278e915e8fa4d7ebbf50a76e8a207c468b04 Mon Sep 17 00:00:00 2001 From: Devin Anderson Date: Mon, 2 May 2011 17:25:14 -0700 Subject: [PATCH 1/4] Add jack_error() calls to 'jack_midi_event_reserve'. --- common/JackMidiAPI.cpp | 18 ++++++++++++++++-- common/JackMidiPort.cpp | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/JackMidiAPI.cpp b/common/JackMidiAPI.cpp index b06a93a2..1a651493 100644 --- a/common/JackMidiAPI.cpp +++ b/common/JackMidiAPI.cpp @@ -98,10 +98,24 @@ EXPORT jack_midi_data_t* jack_midi_event_reserve(void* port_buffer, jack_nframes_t time, size_t data_size) { JackMidiBuffer *buf = (JackMidiBuffer*)port_buffer; - if (!buf && !buf->IsValid()) + if (! buf) { + jack_error("jack_midi_event_reserve: port buffer is set to NULL"); return 0; - if (time >= buf->nframes || (buf->event_count && buf->events[buf->event_count - 1].time > time)) + } + if (! buf->IsValid()) { + jack_error("jack_midi_event_reserve: port buffer is invalid"); + return 0; + } + if (time >= buf->nframes) { + jack_error("jack_midi_event_reserve: time parameter is out of range " + "(%lu >= %lu)", time, buf->nframes); + return 0; + } + if (buf->event_count && (buf->events[buf->event_count - 1].time > time)) { + jack_error("jack_midi_event_reserve: time parameter is earlier than " + "last reserved event"); return 0; + } return buf->ReserveEvent(time, data_size); } diff --git a/common/JackMidiPort.cpp b/common/JackMidiPort.cpp index 5bd82341..2426cb72 100644 --- a/common/JackMidiPort.cpp +++ b/common/JackMidiPort.cpp @@ -52,6 +52,8 @@ SERVER_EXPORT jack_midi_data_t* JackMidiBuffer::ReserveEvent(jack_nframes_t time { jack_shmsize_t space = MaxEventSize(); if (space == 0 || size > space) { + jack_error("JackMidiBuffer::ReserveEvent - the buffer does not have " + "enough room to enqueue a %lu byte event", size); lost_events++; return 0; } From 60b5a763105fc0c90e7699c887c613b9fba947aa Mon Sep 17 00:00:00 2001 From: Devin Anderson Date: Mon, 2 May 2011 17:25:55 -0700 Subject: [PATCH 2/4] Make 'jack_midi_latency_test' aware of port aliases as well as port names. --- example-clients/midi_latency_test.c | 48 +++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/example-clients/midi_latency_test.c b/example-clients/midi_latency_test.c index 1806946f..6937b677 100644 --- a/example-clients/midi_latency_test.c +++ b/example-clients/midi_latency_test.c @@ -47,6 +47,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * implementations for semaphores and command-line argument handling. */ +#include #include #include #include @@ -84,6 +85,8 @@ const char *SOURCE_SHUTDOWN = "handle_shutdown"; const char *SOURCE_SIGNAL_SEMAPHORE = "signal_semaphore"; const char *SOURCE_WAIT_SEMAPHORE = "wait_semaphore"; +char *alias1; +char *alias2; jack_client_t *client; semaphore_t connect_semaphore; volatile int connections_established; @@ -517,9 +520,31 @@ update_connection(jack_port_t *remote_port, int connected, return current_port; } if (target_name) { - if (strcmp(target_name, jack_port_name(remote_port))) { + char *aliases[2]; + if (! strcmp(target_name, jack_port_name(remote_port))) { + return remote_port; + } + aliases[0] = alias1; + aliases[1] = alias2; + switch (jack_port_get_aliases(remote_port, aliases)) { + case -1: + /* Sigh ... */ + die("jack_port_get_aliases", "Failed to get port aliases"); + case 2: + if (! strcmp(target_name, alias2)) { + return remote_port; + } + /* Fallthrough on purpose */ + case 1: + if (! strcmp(target_name, alias1)) { + return remote_port; + } + /* Fallthrough on purpose */ + case 0: return NULL; } + /* This shouldn't happen. */ + assert(0); } return remote_port; } @@ -537,7 +562,6 @@ update_connection(jack_port_t *remote_port, int connected, connected, then we take the first port name in the array and use it as our remote port. It's a dumb implementation. */ current_port = jack_port_by_name(client, port_names[0]); - jack_free(port_names); if (current_port == NULL) { /* Sigh */ @@ -597,6 +621,7 @@ main(int argc, char **argv) {"timeout", 1, NULL, 't'} }; size_t name_arg_count; + size_t name_size; char *option_string = "hm:s:t:"; int show_usage = 0; connections_established = 0; @@ -656,11 +681,24 @@ main(int argc, char **argv) output_usage(); return EXIT_FAILURE; } + name_size = jack_port_name_size(); + alias1 = malloc(name_size * sizeof(char)); + if (alias1 == NULL) { + error_message = strerror(errno); + error_source = "malloc"; + goto show_error; + } + alias2 = malloc(name_size * sizeof(char)); + if (alias2 == NULL) { + error_message = strerror(errno); + error_source = "malloc"; + goto free_alias1; + } latency_values = malloc(sizeof(jack_nframes_t) * samples); if (latency_values == NULL) { error_message = strerror(errno); error_source = "malloc"; - goto show_error; + goto free_alias2; } latency_time_values = malloc(sizeof(jack_time_t) * samples); if (latency_time_values == NULL) { @@ -917,6 +955,10 @@ main(int argc, char **argv) free(latency_time_values); free_latency_values: free(latency_values); + free_alias2: + free(alias2); + free_alias1: + free(alias1); if (error_message != NULL) { show_error: output_error(error_source, error_message); From 264aead30254a755a58cff99b513fd2636f451e8 Mon Sep 17 00:00:00 2001 From: Devin Anderson Date: Mon, 2 May 2011 17:28:14 -0700 Subject: [PATCH 3/4] JackEngine::PortRegister - set buffer size argument to engine buffer size when buffer size is 0. --- common/JackEngine.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index 998cb651..6a511f3f 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -804,6 +804,9 @@ int JackEngine::PortRegister(int refnum, const char* name, const char *type, uns return -1; } + if (! buffer_size) { + buffer_size = fEngineControl->fBufferSize; + } *port_index = fGraphManager->AllocatePort(refnum, name, type, (JackPortFlags)flags, buffer_size); if (*port_index != NO_PORT) { if (client->GetClientControl()->fActive) From 68e4756a9e5149475efa21939b05b12eb5b7e8cd Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Tue, 3 May 2011 11:38:22 +0200 Subject: [PATCH 4/4] Correct JackEngine::PortRegister. --- common/JackEngine.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index 6a511f3f..dfc3f9af 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -804,10 +804,8 @@ int JackEngine::PortRegister(int refnum, const char* name, const char *type, uns return -1; } - if (! buffer_size) { - buffer_size = fEngineControl->fBufferSize; - } - *port_index = fGraphManager->AllocatePort(refnum, name, type, (JackPortFlags)flags, buffer_size); + // buffer_size is actually ignored... + *port_index = fGraphManager->AllocatePort(refnum, name, type, (JackPortFlags)flags, fEngineControl->fBufferSize); if (*port_index != NO_PORT) { if (client->GetClientControl()->fActive) NotifyPortRegistation(*port_index, true);