jack1 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.

127 lines
2.4KB

  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. void silent_function( const char *ignore )
  43. {
  44. }
  45. int
  46. process_cb (jack_nframes_t nframes, void *arg)
  47. {
  48. jack_time_t now = jack_get_time();
  49. jack_time_t wait = now + wait_timeout;
  50. while (jack_get_time() < wait) ;
  51. return 0;
  52. }
  53. int
  54. main (int argc, char *argv[])
  55. {
  56. int c;
  57. int option_index;
  58. struct option long_options[] = {
  59. { "timeout", 1, 0, 't' },
  60. { "help", 0, 0, 'h' },
  61. { "version", 0, 0, 'v' },
  62. { 0, 0, 0, 0 }
  63. };
  64. my_name = strrchr(argv[0], '/');
  65. if (my_name == 0) {
  66. my_name = argv[0];
  67. } else {
  68. my_name ++;
  69. }
  70. while ((c = getopt_long (argc, argv, "t:hv", long_options, &option_index)) >= 0) {
  71. switch (c) {
  72. case 't':
  73. wait_timeout = atoi(optarg);
  74. break;
  75. case 'h':
  76. show_usage ();
  77. return 1;
  78. break;
  79. case 'v':
  80. show_version ();
  81. return 1;
  82. break;
  83. default:
  84. show_usage ();
  85. return 1;
  86. break;
  87. }
  88. }
  89. /* try to open server in a loop. breaking under certein conditions */
  90. jack_set_info_function( silent_function );
  91. client = jack_client_open( "load_test", JackNullOption, NULL );
  92. signal(SIGQUIT, signal_handler);
  93. signal(SIGTERM, signal_handler);
  94. signal(SIGHUP, signal_handler);
  95. signal(SIGINT, signal_handler);
  96. jack_on_shutdown(client, jack_shutdown, 0);
  97. jack_set_process_callback( client, process_cb, NULL );
  98. jack_activate (client);
  99. sleep( -1 );
  100. exit (0);
  101. }