| @@ -1,8 +1,27 @@ | |||
| /* | |||
| This program is free software; you can redistribute it and/or modify | |||
| it under the terms of the GNU General Public License as published by | |||
| the Free Software Foundation; either version 2 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 General Public License for more details. | |||
| You should have received a copy of the GNU General Public License | |||
| along with this program; if not, write to the Free Software | |||
| Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| */ | |||
| #include <stdio.h> | |||
| #include <stdlib.h> | |||
| #ifndef WIN32 | |||
| #include <unistd.h> | |||
| #endif | |||
| #include <string.h> | |||
| #include <getopt.h> | |||
| #include <inttypes.h> | |||
| #include <config.h> | |||
| @@ -12,14 +31,13 @@ | |||
| char * my_name; | |||
| void | |||
| static void | |||
| show_version (void) | |||
| { | |||
| fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", | |||
| my_name); | |||
| fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name); | |||
| } | |||
| void | |||
| static void | |||
| printf_name2uuid (jack_client_t* client, const char* pname) | |||
| { | |||
| char *port_component = strchr( pname, ':' ); | |||
| @@ -36,7 +54,7 @@ printf_name2uuid (jack_client_t* client, const char* pname) | |||
| jack_free(uuid); | |||
| } | |||
| void | |||
| static void | |||
| show_usage (void) | |||
| { | |||
| show_version (); | |||
| @@ -47,7 +65,8 @@ show_usage (void) | |||
| fprintf (stderr, " -s, --server <name> Connect to the jack server named <name>\n"); | |||
| fprintf (stderr, " -A, --aliases List aliases for each port\n"); | |||
| fprintf (stderr, " -c, --connections List connections to/from each port\n"); | |||
| fprintf (stderr, " -l, --latency Display per-port latency in frames at each port\n"); | |||
| fprintf (stderr, " -l, --port-latency Display per-port latency in frames at each port\n"); | |||
| fprintf (stderr, " -L, --total-latency Display total latency in frames at each port\n"); | |||
| fprintf (stderr, " -p, --properties Display port properties. Output may include:\n" | |||
| " input|output, can-monitor, physical, terminal\n\n"); | |||
| fprintf (stderr, " -t, --type Display port type\n"); | |||
| @@ -70,6 +89,7 @@ main (int argc, char *argv[]) | |||
| int show_aliases = 0; | |||
| int show_con = 0; | |||
| int show_port_latency = 0; | |||
| int show_total_latency = 0; | |||
| int show_properties = 0; | |||
| int show_type = 0; | |||
| int show_uuid = 0; | |||
| @@ -79,12 +99,12 @@ main (int argc, char *argv[]) | |||
| char* aliases[2]; | |||
| char *server_name = NULL; | |||
| struct option long_options[] = { | |||
| { "server", 1, 0, 's' }, | |||
| { "server", 1, 0, 's' }, | |||
| { "aliases", 0, 0, 'A' }, | |||
| { "connections", 0, 0, 'c' }, | |||
| { "port-latency", 0, 0, 'l' }, | |||
| { "total-latency", 0, 0, 'L' }, | |||
| { "properties", 0, 0, 'p' }, | |||
| { "type", 0, 0, 't' }, | |||
| { "uuid", 0, 0, 'u' }, | |||
| @@ -104,10 +124,10 @@ main (int argc, char *argv[]) | |||
| while ((c = getopt_long (argc, argv, "s:AclLphvtuU", long_options, &option_index)) >= 0) { | |||
| switch (c) { | |||
| case 's': | |||
| server_name = (char *) malloc (sizeof (char) * strlen(optarg)); | |||
| strcpy (server_name, optarg); | |||
| options |= JackServerName; | |||
| break; | |||
| server_name = (char *) malloc (sizeof (char) * strlen(optarg)); | |||
| strcpy (server_name, optarg); | |||
| options |= JackServerName; | |||
| break; | |||
| case 'A': | |||
| aliases[0] = (char *) malloc (jack_port_name_size()); | |||
| aliases[1] = (char *) malloc (jack_port_name_size()); | |||
| @@ -119,6 +139,9 @@ main (int argc, char *argv[]) | |||
| case 'l': | |||
| show_port_latency = 1; | |||
| break; | |||
| case 'L': | |||
| show_total_latency = 1; | |||
| break; | |||
| case 'p': | |||
| show_properties = 1; | |||
| break; | |||
| @@ -149,13 +172,12 @@ main (int argc, char *argv[]) | |||
| /* Open a client connection to the JACK server. Starting a | |||
| * new server only to list its ports seems pointless, so we | |||
| * specify JackNoStartServer. */ | |||
| client = jack_client_open ("lsp", options, &status, server_name); | |||
| if (client == NULL) { | |||
| if ((client = jack_client_open ("lsp", options, &status, server_name)) == 0) { | |||
| fprintf (stderr, "Error: cannot connect to JACK, "); | |||
| if (status & JackServerFailed) { | |||
| fprintf (stderr, "JACK server not running\n"); | |||
| fprintf (stderr, "server is not running.\n"); | |||
| } else { | |||
| fprintf (stderr, "jack_client_open() failed, " | |||
| "status = 0x%2.0x\n", status); | |||
| fprintf (stderr, "jack_client_open() failed, status = 0x%2.0x\n", status); | |||
| } | |||
| return 1; | |||
| } | |||
| @@ -165,12 +187,12 @@ main (int argc, char *argv[]) | |||
| for (i = 0; ports && ports[i]; ++i) { | |||
| // skip over any that don't match ALL of the strings presented at command line | |||
| skip_port = 0; | |||
| for(k=optind; k < argc; k++){ | |||
| if(strstr(ports[i], argv[k]) == NULL ){ | |||
| for (k = optind; k < argc; k++){ | |||
| if (strstr(ports[i], argv[k]) == NULL ){ | |||
| skip_port = 1; | |||
| } | |||
| } | |||
| if(skip_port) continue; | |||
| if (skip_port) continue; | |||
| if (show_uuid) { | |||
| printf_name2uuid(client, ports[i]); | |||
| @@ -179,15 +201,15 @@ main (int argc, char *argv[]) | |||
| } | |||
| jack_port_t *port = jack_port_by_name (client, ports[i]); | |||
| if (show_port_uuid) { | |||
| char buf[64]; | |||
| jack_uuid_t uuid = jack_port_uuid (port); | |||
| jack_uuid_unparse (uuid, buf); | |||
| printf (" uuid: %s\n", buf); | |||
| } | |||
| if (show_aliases) { | |||
| if (show_port_uuid) { | |||
| char buf[JACK_UUID_STRING_SIZE]; | |||
| jack_uuid_t uuid = jack_port_uuid (port); | |||
| jack_uuid_unparse (uuid, buf); | |||
| printf (" uuid: %s\n", buf); | |||
| } | |||
| if (show_aliases) { | |||
| int cnt; | |||
| int i; | |||
| @@ -196,7 +218,7 @@ main (int argc, char *argv[]) | |||
| printf (" %s\n", aliases[i]); | |||
| } | |||
| } | |||
| if (show_con) { | |||
| if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) { | |||
| for (j = 0; connections[j]; j++) { | |||
| @@ -206,10 +228,9 @@ main (int argc, char *argv[]) | |||
| } else { | |||
| printf("%s\n", connections[j]); | |||
| } | |||
| } | |||
| jack_free (connections); | |||
| } | |||
| } | |||
| } | |||
| if (show_port_latency) { | |||
| if (port) { | |||
| @@ -224,7 +245,12 @@ main (int argc, char *argv[]) | |||
| range.min, range.max); | |||
| } | |||
| } | |||
| if (show_total_latency) { | |||
| if (port) { | |||
| printf (" total latency = %d frames\n", | |||
| jack_port_get_total_latency (client, port)); | |||
| } | |||
| } | |||
| if (show_properties) { | |||
| if (port) { | |||
| int flags = jack_port_flags (port); | |||
| @@ -256,9 +282,12 @@ main (int argc, char *argv[]) | |||
| } | |||
| } | |||
| if (show_aliases) { | |||
| free(aliases[0]); | |||
| free(aliases[1]); | |||
| } | |||
| if (ports) | |||
| jack_free (ports); | |||
| jack_client_close (client); | |||
| exit (0); | |||
| } | |||