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.

249 lines
6.6KB

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