jack2 codebase
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.

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