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.

230 lines
5.8KB

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