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.

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