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.

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