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.

121 lines
2.3KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <getopt.h>
  6. #include <signal.h>
  7. #include <time.h>
  8. #include <config.h>
  9. #include <jack/jack.h>
  10. char * my_name;
  11. jack_client_t *client;
  12. unsigned int wait_timeout = 1000;
  13. void
  14. show_version (void)
  15. {
  16. fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n",
  17. my_name);
  18. }
  19. void
  20. show_usage (void)
  21. {
  22. show_version ();
  23. fprintf (stderr, "\nUsage: %s [options]\n", my_name);
  24. fprintf (stderr, "this is a test client, which just sleeps in its process_cb to simulate cpu load\n");
  25. fprintf (stderr, "options:\n");
  26. fprintf (stderr, " -t, --timeout Wait timeout in seconds\n");
  27. fprintf (stderr, " -h, --help Display this help message\n");
  28. fprintf (stderr, " --version Output version information and exit\n\n");
  29. fprintf (stderr, "For more information see http://jackaudio.org/\n");
  30. }
  31. void jack_shutdown(void *arg)
  32. {
  33. fprintf(stderr, "JACK shut down, exiting ...\n");
  34. exit(1);
  35. }
  36. void signal_handler(int sig)
  37. {
  38. jack_client_close(client);
  39. fprintf(stderr, "signal received, exiting ...\n");
  40. exit(0);
  41. }
  42. int
  43. process_cb (jack_nframes_t nframes, void *arg)
  44. {
  45. jack_time_t now = jack_get_time();
  46. jack_time_t wait = now + wait_timeout;
  47. while (jack_get_time() < wait) ;
  48. return 0;
  49. }
  50. int
  51. main (int argc, char *argv[])
  52. {
  53. int c;
  54. int option_index;
  55. struct option long_options[] = {
  56. { "timeout", 1, 0, 't' },
  57. { "help", 0, 0, 'h' },
  58. { "version", 0, 0, 'v' },
  59. { 0, 0, 0, 0 }
  60. };
  61. my_name = strrchr(argv[0], '/');
  62. if (my_name == 0) {
  63. my_name = argv[0];
  64. } else {
  65. my_name ++;
  66. }
  67. while ((c = getopt_long (argc, argv, "t:hv", long_options, &option_index)) >= 0) {
  68. switch (c) {
  69. case 't':
  70. wait_timeout = atoi(optarg);
  71. break;
  72. case 'h':
  73. show_usage ();
  74. return 1;
  75. break;
  76. case 'v':
  77. show_version ();
  78. return 1;
  79. break;
  80. default:
  81. show_usage ();
  82. return 1;
  83. break;
  84. }
  85. }
  86. /* try to open server in a loop. breaking under certein conditions */
  87. client = jack_client_open( "load_test", JackNullOption, NULL );
  88. signal(SIGQUIT, signal_handler);
  89. signal(SIGTERM, signal_handler);
  90. signal(SIGHUP, signal_handler);
  91. signal(SIGINT, signal_handler);
  92. jack_on_shutdown(client, jack_shutdown, 0);
  93. jack_set_process_callback( client, process_cb, NULL );
  94. jack_activate (client);
  95. sleep( -1 );
  96. exit (0);
  97. }