From 8d20c369656f3d7eaafb7c7161eba57eb53eab61 Mon Sep 17 00:00:00 2001 From: torben Date: Sat, 7 Mar 2009 21:09:42 +0000 Subject: [PATCH] [alsa-io] fix signal termination git-svn-id: svn+ssh://jackaudio.org/trunk/jack@3414 0c269be4-1314-0410-8aa9-9f06e86f4224 --- tools/alsa_in.c | 18 +++++++++++++----- tools/alsa_out.c | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tools/alsa_in.c b/tools/alsa_in.c index 25340e8..58e59c5 100644 --- a/tools/alsa_in.c +++ b/tools/alsa_in.c @@ -36,6 +36,7 @@ snd_pcm_t *alsa_handle; int jack_sample_rate; int jack_buffer_size; +int quit = 0; double resample_mean = 1.0; double static_resample_factor = 1.0; @@ -557,8 +558,7 @@ fprintf(stderr, "usage: alsa_out [options]\n" void sigterm_handler( int signal ) { - jack_deactivate( client ); - jack_client_close( client ); + quit = 1; } @@ -721,9 +721,10 @@ int main (int argc, char *argv[]) { } signal( SIGTERM, sigterm_handler ); + signal( SIGINT, sigterm_handler ); if( verbose ) { - while(1) { + while(!quit) { usleep(500000); if( output_new_delay ) { printf( "delay = %d\n", output_new_delay ); @@ -734,12 +735,19 @@ int main (int argc, char *argv[]) { } else if( instrument ) { printf( "# n\tresamp\tdiff\toffseti\tintegral\n"); int n=0; - while(1) { + while(!quit) { usleep(1000); printf( "%d\t%f\t%f\t%f\t%f\n", n++, output_resampling_factor, output_diff, output_offset, output_integral ); } } else { - while(1) sleep(10); + while(!quit) + { + usleep(500000); + if( output_new_delay ) { + printf( "delay = %d\n", output_new_delay ); + output_new_delay = 0; + } + } } jack_deactivate( client ); diff --git a/tools/alsa_out.c b/tools/alsa_out.c index 8c27011..7727666 100644 --- a/tools/alsa_out.c +++ b/tools/alsa_out.c @@ -44,6 +44,7 @@ double *window_array; int offset_differential_index = 0; double offset_integral = 0; +int quit = 0; // ------------------------------------------------------ commandline parameters @@ -555,8 +556,7 @@ fprintf(stderr, "usage: alsa_out [options]\n" void sigterm_handler( int signal ) { - jack_deactivate( client ); - jack_client_close( client ); + quit = 1; } @@ -719,9 +719,10 @@ int main (int argc, char *argv[]) { } signal( SIGTERM, sigterm_handler ); + signal( SIGINT, sigterm_handler ); if( verbose ) { - while(1) { + while(!quit) { usleep(500000); if( output_new_delay ) { printf( "delay = %d\n", output_new_delay ); @@ -732,12 +733,19 @@ int main (int argc, char *argv[]) { } else if( instrument ) { printf( "# n\tresamp\tdiff\toffseti\tintegral\n"); int n=0; - while(1) { + while(!quit) { usleep(1000); printf( "%d\t%f\t%f\t%f\t%f\n", n++, output_resampling_factor, output_diff, output_offset, output_integral ); } } else { - while(1) sleep(10); + while(!quit) + { + usleep(500000); + if( output_new_delay ) { + printf( "delay = %d\n", output_new_delay ); + output_new_delay = 0; + } + } } jack_deactivate( client );