JACK tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
7.7KB

  1. /*
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #ifndef WIN32
  17. #include <unistd.h>
  18. #endif
  19. #include <string.h>
  20. #include <getopt.h>
  21. #include <inttypes.h>
  22. #include <config.h>
  23. #include <jack/jack.h>
  24. #include <jack/session.h>
  25. #include <jack/uuid.h>
  26. char * my_name;
  27. static void
  28. show_version (void)
  29. {
  30. fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
  31. }
  32. static void
  33. printf_name2uuid (jack_client_t* client, const char* pname)
  34. {
  35. char *port_component = strchr( pname, ':' );
  36. size_t csize = port_component - pname + 1;
  37. char client_component[csize];
  38. snprintf(client_component, csize, "%s", pname);
  39. char *uuid = jack_get_uuid_for_client_name(client, client_component);
  40. if (uuid) {
  41. printf("%s%s\n", uuid, port_component );
  42. } else {
  43. printf("%s\n",pname);
  44. }
  45. jack_free(uuid);
  46. }
  47. static void
  48. show_usage (void)
  49. {
  50. show_version ();
  51. fprintf (stderr, "\nUsage: %s [options] [filter string]\n", my_name);
  52. fprintf (stderr, "List active Jack ports, and optionally display extra information.\n");
  53. fprintf (stderr, "Optionally filter ports which match ALL strings provided after any options.\n\n");
  54. fprintf (stderr, "Display options:\n");
  55. fprintf (stderr, " -s, --server <name> Connect to the jack server named <name>\n");
  56. fprintf (stderr, " -A, --aliases List aliases for each port\n");
  57. fprintf (stderr, " -c, --connections List connections to/from each port\n");
  58. fprintf (stderr, " -l, --port-latency Display per-port latency in frames at each port\n");
  59. fprintf (stderr, " -L, --total-latency Display total latency in frames at each port\n");
  60. fprintf (stderr, " -p, --properties Display port properties. Output may include:\n"
  61. " input|output, can-monitor, physical, terminal\n\n");
  62. fprintf (stderr, " -t, --type Display port type\n");
  63. fprintf (stderr, " -u, --uuid Display uuid instead of client name (if available)\n");
  64. fprintf (stderr, " -U, --port-uuid Display port uuid\n");
  65. fprintf (stderr, " -h, --help Display this help message\n");
  66. fprintf (stderr, " --version Output version information and exit\n\n");
  67. fprintf (stderr, "For more information see http://jackaudio.org/\n");
  68. }
  69. int
  70. main (int argc, char *argv[])
  71. {
  72. jack_client_t *client;
  73. jack_status_t status;
  74. jack_options_t options = JackNoStartServer;
  75. const char **ports, **connections;
  76. unsigned int i, j, k;
  77. int skip_port;
  78. int show_aliases = 0;
  79. int show_con = 0;
  80. int show_port_latency = 0;
  81. int show_total_latency = 0;
  82. int show_properties = 0;
  83. int show_type = 0;
  84. int show_uuid = 0;
  85. int show_port_uuid = 0;
  86. int c;
  87. int option_index;
  88. char* aliases[2];
  89. char *server_name = NULL;
  90. struct option long_options[] = {
  91. { "server", 1, 0, 's' },
  92. { "aliases", 0, 0, 'A' },
  93. { "connections", 0, 0, 'c' },
  94. { "port-latency", 0, 0, 'l' },
  95. { "total-latency", 0, 0, 'L' },
  96. { "properties", 0, 0, 'p' },
  97. { "type", 0, 0, 't' },
  98. { "uuid", 0, 0, 'u' },
  99. { "port-uuid", 0, 0, 'U' },
  100. { "help", 0, 0, 'h' },
  101. { "version", 0, 0, 'v' },
  102. { 0, 0, 0, 0 }
  103. };
  104. my_name = strrchr(argv[0], '/');
  105. if (my_name == 0) {
  106. my_name = argv[0];
  107. } else {
  108. my_name ++;
  109. }
  110. while ((c = getopt_long (argc, argv, "s:AclLphvtuU", long_options, &option_index)) >= 0) {
  111. switch (c) {
  112. case 's':
  113. server_name = (char *) malloc (sizeof (char) * strlen(optarg));
  114. strcpy (server_name, optarg);
  115. options |= JackServerName;
  116. break;
  117. case 'A':
  118. aliases[0] = (char *) malloc (jack_port_name_size());
  119. aliases[1] = (char *) malloc (jack_port_name_size());
  120. show_aliases = 1;
  121. break;
  122. case 'c':
  123. show_con = 1;
  124. break;
  125. case 'l':
  126. show_port_latency = 1;
  127. break;
  128. case 'L':
  129. show_total_latency = 1;
  130. break;
  131. case 'p':
  132. show_properties = 1;
  133. break;
  134. case 't':
  135. show_type = 1;
  136. break;
  137. case 'u':
  138. show_uuid = 1;
  139. break;
  140. case 'U':
  141. show_port_uuid = 1;
  142. break;
  143. case 'h':
  144. show_usage ();
  145. return 1;
  146. break;
  147. case 'v':
  148. show_version ();
  149. return 1;
  150. break;
  151. default:
  152. show_usage ();
  153. return 1;
  154. break;
  155. }
  156. }
  157. /* Open a client connection to the JACK server. Starting a
  158. * new server only to list its ports seems pointless, so we
  159. * specify JackNoStartServer. */
  160. if ((client = jack_client_open ("lsp", options, &status, server_name)) == 0) {
  161. fprintf (stderr, "Error: cannot connect to JACK, ");
  162. if (status & JackServerFailed) {
  163. fprintf (stderr, "server is not running.\n");
  164. } else {
  165. fprintf (stderr, "jack_client_open() failed, status = 0x%2.0x\n", status);
  166. }
  167. return 1;
  168. }
  169. ports = jack_get_ports (client, NULL, NULL, 0);
  170. for (i = 0; ports && ports[i]; ++i) {
  171. // skip over any that don't match ALL of the strings presented at command line
  172. skip_port = 0;
  173. for (k = optind; k < argc; k++){
  174. if (strstr(ports[i], argv[k]) == NULL ){
  175. skip_port = 1;
  176. }
  177. }
  178. if (skip_port) continue;
  179. if (show_uuid) {
  180. printf_name2uuid(client, ports[i]);
  181. } else {
  182. printf ("%s\n", ports[i]);
  183. }
  184. jack_port_t *port = jack_port_by_name (client, ports[i]);
  185. if (show_port_uuid) {
  186. char buf[JACK_UUID_STRING_SIZE];
  187. jack_uuid_t uuid = jack_port_uuid (port);
  188. jack_uuid_unparse (uuid, buf);
  189. printf (" uuid: %s\n", buf);
  190. }
  191. if (show_aliases) {
  192. int cnt;
  193. int i;
  194. cnt = jack_port_get_aliases (port, aliases);
  195. for (i = 0; i < cnt; ++i) {
  196. printf (" %s\n", aliases[i]);
  197. }
  198. }
  199. if (show_con) {
  200. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  201. for (j = 0; connections[j]; j++) {
  202. printf(" ");
  203. if (show_uuid) {
  204. printf_name2uuid(client, connections[j]);
  205. } else {
  206. printf("%s\n", connections[j]);
  207. }
  208. }
  209. jack_free (connections);
  210. }
  211. }
  212. if (show_port_latency) {
  213. if (port) {
  214. jack_latency_range_t range;
  215. jack_port_get_latency_range (port, JackPlaybackLatency, &range);
  216. printf (" port playback latency = [ %" PRIu32 " %" PRIu32 " ] frames\n",
  217. range.min, range.max);
  218. jack_port_get_latency_range (port, JackCaptureLatency, &range);
  219. printf (" port capture latency = [ %" PRIu32 " %" PRIu32 " ] frames\n",
  220. range.min, range.max);
  221. }
  222. }
  223. if (show_total_latency) {
  224. if (port) {
  225. printf (" total latency = %d frames\n",
  226. jack_port_get_total_latency (client, port));
  227. }
  228. }
  229. if (show_properties) {
  230. if (port) {
  231. int flags = jack_port_flags (port);
  232. printf (" properties: ");
  233. if (flags & JackPortIsInput) {
  234. fputs ("input,", stdout);
  235. }
  236. if (flags & JackPortIsOutput) {
  237. fputs ("output,", stdout);
  238. }
  239. if (flags & JackPortCanMonitor) {
  240. fputs ("can-monitor,", stdout);
  241. }
  242. if (flags & JackPortIsPhysical) {
  243. fputs ("physical,", stdout);
  244. }
  245. if (flags & JackPortIsTerminal) {
  246. fputs ("terminal,", stdout);
  247. }
  248. putc ('\n', stdout);
  249. }
  250. }
  251. if (show_type) {
  252. if (port) {
  253. putc ('\t', stdout);
  254. fputs (jack_port_type (port), stdout);
  255. putc ('\n', stdout);
  256. }
  257. }
  258. }
  259. if (show_aliases) {
  260. free(aliases[0]);
  261. free(aliases[1]);
  262. }
  263. if (ports)
  264. jack_free (ports);
  265. jack_client_close (client);
  266. exit (0);
  267. }