Commit 264d7a71 authored by Stan Seibert's avatar Stan Seibert

Finally a fix to the Ctrl-C handling. The old semantics were incorrect.

Now 1 ^C means "skip to next song" and 2 ^C's within a certain time period
means (500 ms right now) exit the program.  We use gettimeofday() so we
don't need alarm() anymore.  Thanks to Segher for working out most of this
patch.

svn path=/trunk/vorbis-tools/; revision=2902
parent e1705965
......@@ -11,7 +11,7 @@
* *
********************************************************************
last mod: $Id: cmdline_options.c,v 1.3 2001/12/19 04:59:16 volsung Exp $
last mod: $Id: cmdline_options.c,v 1.4 2001/12/24 15:58:03 volsung Exp $
********************************************************************/
......@@ -134,7 +134,7 @@ int parse_cmdline_options (int argc, char **argv,
break;
case 'l':
ogg123_opts->delay = atoi(optarg);
ogg123_opts->delay = 1000 * atoi(optarg);
break;
case 'o':
......@@ -277,7 +277,7 @@ void cmdline_usage (void)
" -y n, --ntimes repeat every played block 'n' times\n"
" -z, --shuffle shuffle play\n"
"\n"
"ogg123 will skip to the next song on SIGINT (Ctrl-C) after s seconds after\n"
"song start.\n"
" -l, --delay=s set s (default 1). If s=-1, disable song skip.\n");
"ogg123 will skip to the next song on SIGINT (Ctrl-C); two SIGINTs within\n"
"s seconds make ogg123 terinate.\n"
" -l, --delay=s set s [milliseconds] (default 250).\n");
}
......@@ -14,7 +14,7 @@
* *
********************************************************************
last mod: $Id: ogg123.c,v 1.55 2001/12/20 02:51:22 volsung Exp $
last mod: $Id: ogg123.c,v 1.56 2001/12/24 15:58:03 volsung Exp $
********************************************************************/
......@@ -27,6 +27,7 @@
#include <getopt.h>
#include <signal.h>
#include <unistd.h>
#include <sys/time.h>
#include "audio.h"
#include "buffer.h"
......@@ -82,20 +83,22 @@ signal_request_t sig_request = {0, 0, 0, 0};
void signal_handler (int signo)
{
struct timeval tv;
ogg_int64_t now;
switch (signo) {
case SIGALRM:
sig_request.ticks++;
if (sig_request.ticks < options.delay) {
signal (SIGALRM, signal_handler);
alarm(1);
}
break;
case SIGINT:
if (sig_request.ticks < options.delay)
gettimeofday(&tv, 0);
/* Units of milliseconds (need the cast to force 64 arithmetics) */
now = (ogg_int64_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
if ( (now - sig_request.last_ctrl_c) <= options.delay)
sig_request.exit = 1;
else
sig_request.skipfile = 1;
sig_request.last_ctrl_c = now;
break;
case SIGTSTP:
......@@ -126,7 +129,7 @@ void options_init (ogg123_options_t *opts)
{
opts->verbosity = 2;
opts->shuffle = 0;
opts->delay = 2;
opts->delay = 500;
opts->nth = 1;
opts->ntimes = 1;
opts->seekpos = 0.0;
......@@ -324,7 +327,7 @@ int main(int argc, char **argv)
/* Play the files/streams */
while (optind < argc) {
while (optind < argc && !sig_request.exit) {
play(argv[optind]);
optind++;
}
......@@ -403,13 +406,10 @@ void play (char *source_string)
select_stats(stat_format, &options, source, decoder, audio_buffer);
/* Reset all of the signal flags and setup the timer */
/* Reset all of the signal flags */
sig_request.skipfile = 0;
sig_request.exit = 0;
sig_request.pause = 0;
sig_request.ticks = 0;
alarm(1); /* Count seconds */
/* Start the audio playback thread before we begin sending data */
if (audio_buffer != NULL) {
......@@ -533,7 +533,6 @@ void play (char *source_string)
display_statistics_quick(stat_format, audio_buffer, source, decoder);
alarm(0);
format->cleanup(decoder);
transport->close(source);
status_reset_output_lock(); /* In case we were killed mid-output */
......
......@@ -11,7 +11,7 @@
* *
********************************************************************
last mod: $Id: ogg123.h,v 1.11 2001/12/19 04:59:17 volsung Exp $
last mod: $Id: ogg123.h,v 1.12 2001/12/24 15:58:03 volsung Exp $
********************************************************************/
......@@ -24,8 +24,8 @@
typedef struct ogg123_options_t {
long int verbosity; /* Verbose output if > 1, quiet if 0 */
int shuffle; /* Should we shuffle playing? */
int delay; /* delay for skip to next song */
int shuffle; /* Should we shuffle playing? */
ogg_int64_t delay; /* delay (in millisecs) for skip to next song */
int nth; /* Play every nth chunk */
int ntimes; /* Play every chunk n times */
double seekpos; /* Position in file to seek to */
......@@ -46,7 +46,7 @@ typedef struct signal_request_t {
int skipfile;
int exit;
int pause;
ogg_int64_t ticks;
ogg_int64_t last_ctrl_c;
} signal_request_t;
#endif /* __OGG123_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment