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