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.

278 lines
7.1KB

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