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.

264 lines
6.7KB

  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 && strcmp(uuid, "-1") != 0) {
  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, " -h, --help Display this help message\n");
  49. fprintf (stderr, " --version Output version information and exit\n\n");
  50. fprintf (stderr, "For more information see http://jackaudio.org/\n");
  51. }
  52. int
  53. main (int argc, char *argv[])
  54. {
  55. jack_client_t *client;
  56. jack_status_t status;
  57. jack_options_t options = JackNoStartServer;
  58. const char **ports, **connections;
  59. unsigned int i, j, k;
  60. int skip_port;
  61. int show_aliases = 0;
  62. int show_con = 0;
  63. int show_port_latency = 0;
  64. int show_total_latency = 0;
  65. int show_properties = 0;
  66. int show_type = 0;
  67. int show_uuid = 0;
  68. int c;
  69. int option_index;
  70. char* aliases[2];
  71. char *server_name = NULL;
  72. struct option long_options[] = {
  73. { "server", 1, 0, 's' },
  74. { "aliases", 0, 0, 'A' },
  75. { "connections", 0, 0, 'c' },
  76. { "port-latency", 0, 0, 'l' },
  77. { "total-latency", 0, 0, 'L' },
  78. { "properties", 0, 0, 'p' },
  79. { "type", 0, 0, 't' },
  80. { "uuid", 0, 0, 'u' },
  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:AclLphvtu", 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 'u':
  119. show_uuid = 1;
  120. break;
  121. case 'h':
  122. show_usage ();
  123. return 1;
  124. break;
  125. case 'v':
  126. show_version ();
  127. return 1;
  128. break;
  129. default:
  130. show_usage ();
  131. return 1;
  132. break;
  133. }
  134. }
  135. /* Open a client connection to the JACK server. Starting a
  136. * new server only to list its ports seems pointless, so we
  137. * specify JackNoStartServer. */
  138. client = jack_client_open ("lsp", options, &status, server_name);
  139. if (client == NULL) {
  140. if (status & JackServerFailed) {
  141. fprintf (stderr, "JACK server not running\n");
  142. } else {
  143. fprintf (stderr, "jack_client_open() failed, "
  144. "status = 0x%2.0x\n", status);
  145. }
  146. return 1;
  147. }
  148. ports = jack_get_ports (client, NULL, NULL, 0);
  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. if (show_uuid) {
  159. printf_name2uuid(client, ports[i]);
  160. } else {
  161. printf ("%s\n", ports[i]);
  162. }
  163. jack_port_t *port = jack_port_by_name (client, ports[i]);
  164. if (show_aliases) {
  165. int cnt;
  166. int i;
  167. cnt = jack_port_get_aliases (port, aliases);
  168. for (i = 0; i < cnt; ++i) {
  169. printf (" %s\n", aliases[i]);
  170. }
  171. }
  172. if (show_con) {
  173. if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
  174. for (j = 0; connections[j]; j++) {
  175. printf(" ");
  176. if (show_uuid) {
  177. printf_name2uuid(client, connections[j]);
  178. } else {
  179. printf("%s\n", connections[j]);
  180. }
  181. }
  182. jack_free (connections);
  183. }
  184. }
  185. if (show_port_latency) {
  186. if (port) {
  187. jack_latency_range_t range;
  188. printf (" port latency = %" PRIu32 " frames\n",
  189. jack_port_get_latency (port));
  190. jack_port_get_latency_range (port, JackPlaybackLatency, &range);
  191. printf (" port playback latency = [ %" PRIu32 " %" PRIu32 " ] frames\n",
  192. range.min, range.max);
  193. jack_port_get_latency_range (port, JackCaptureLatency, &range);
  194. printf (" port capture latency = [ %" PRIu32 " %" PRIu32 " ] frames\n",
  195. range.min, range.max);
  196. }
  197. }
  198. if (show_total_latency) {
  199. if (port) {
  200. printf (" total latency = %" PRIu32 " frames\n",
  201. jack_port_get_total_latency (client, port));
  202. }
  203. }
  204. if (show_properties) {
  205. if (port) {
  206. int flags = jack_port_flags (port);
  207. printf (" properties: ");
  208. if (flags & JackPortIsInput) {
  209. fputs ("input,", stdout);
  210. }
  211. if (flags & JackPortIsOutput) {
  212. fputs ("output,", stdout);
  213. }
  214. if (flags & JackPortCanMonitor) {
  215. fputs ("can-monitor,", stdout);
  216. }
  217. if (flags & JackPortIsPhysical) {
  218. fputs ("physical,", stdout);
  219. }
  220. if (flags & JackPortIsTerminal) {
  221. fputs ("terminal,", stdout);
  222. }
  223. putc ('\n', stdout);
  224. }
  225. }
  226. if (show_type) {
  227. if (port) {
  228. putc ('\t', stdout);
  229. fputs (jack_port_type (port), stdout);
  230. putc ('\n', stdout);
  231. }
  232. }
  233. }
  234. if (ports)
  235. jack_free (ports);
  236. jack_client_close (client);
  237. exit (0);
  238. }