[xiph-cvs] cvs commit: vorbis-tools/ogg123 cmdline_options.c ogg123.c ogg123.h

Stan Seibert volsung at xiph.org
Mon Dec 24 07:58:05 PST 2001



volsung     01/12/24 07:58:04

  Modified:    ogg123   cmdline_options.c ogg123.c ogg123.h
  Log:
  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.

Revision  Changes    Path
1.4       +5 -5      vorbis-tools/ogg123/cmdline_options.c

Index: cmdline_options.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/cmdline_options.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- cmdline_options.c	2001/12/19 04:59:16	1.3
+++ cmdline_options.c	2001/12/24 15:58:03	1.4
@@ -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 @@
           break;
           
         case 'l':
-	  ogg123_opts->delay = atoi(optarg);
+	  ogg123_opts->delay = 1000 * atoi(optarg);
           break;
           
         case 'o':
@@ -277,7 +277,7 @@
          "  -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");
 }

1.56      +16 -17    vorbis-tools/ogg123/ogg123.c

Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- ogg123.c	2001/12/20 02:51:22	1.55
+++ ogg123.c	2001/12/24 15:58:03	1.56
@@ -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 @@
 
 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 @@
 {
   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 @@
 
   /* Play the files/streams */
 
-  while (optind < argc) {
+  while (optind < argc && !sig_request.exit) {
     play(argv[optind]);
     optind++;
   }
@@ -403,13 +406,10 @@
   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 @@
   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 */

1.12      +4 -4      vorbis-tools/ogg123/ogg123.h

Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ogg123.h	2001/12/19 04:59:17	1.11
+++ ogg123.h	2001/12/24 15:58:03	1.12
@@ -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 @@
   int skipfile;
   int exit;
   int pause;
-  ogg_int64_t ticks;
+  ogg_int64_t last_ctrl_c;
 } signal_request_t;
 
 #endif /* __OGG123_H__ */

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list