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.

260 lines
6.8KB

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