[xiph-cvs] cvs commit: vorbis-tools/ogg123 ogg123.1 ogg123.c
Chris Cheney
calc at xiph.org
Sun Jun 17 20:01:52 PDT 2001
calc 01/06/17 20:01:51
Modified: ogg123 ogg123.1 ogg123.c
Log:
James Atwill's patch to support SIGINT song changes
Revision Changes Path
1.5 +15 -0 vorbis-tools/ogg123/ogg123.1
Index: ogg123.1
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.1,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ogg123.1 2001/06/17 23:52:51 1.4
+++ ogg123.1 2001/06/18 03:01:51 1.5
@@ -195,6 +195,21 @@
.RE
.PP
+.SH INTERRUPT
+You can abort
+.B ogg123
+at any time by pressing Ctrl-C. If you are playing multiple
+files, this will stop the current file and begin playing the
+next one. If you want to abort playing immediately instead
+of skipping to the next file, press Ctrl-C within the first
+second of the playback of a new file.
+.P
+Note that the result of pressing Ctrl-C might not be audible
+immediately, due to audio data buffering in the audio device.
+This delay is system dependent, but it is usually not more
+than one or two seconds.
+
+
.SH FILES
.TP
1.34 +56 -1 vorbis-tools/ogg123/ogg123.c
Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- ogg123.c 2001/06/17 23:52:51 1.33
+++ ogg123.c 2001/06/18 03:01:51 1.34
@@ -14,7 +14,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.c,v 1.33 2001/06/17 23:52:51 calc Exp $
+ last mod: $Id: ogg123.c,v 1.34 2001/06/18 03:01:51 calc Exp $
********************************************************************/
@@ -30,12 +30,17 @@
#include <time.h>
#include <getopt.h>
+#include <signal.h>
+
#include "ogg123.h"
char convbuffer[4096]; /* take 8k out of the data segment, not the stack */
int convsize = 4096;
buf_t * buffer = NULL;
+static char skipfile_requested;
+static void (*old_sig)(int);
+
struct {
char *key; /* includes the '=' for programming convenience */
char *formatstr; /* formatted output */
@@ -220,6 +225,36 @@
return (0);
}
+/* Two signal handlers, one for SIGINT, and the second for
+ * SIGALRM. They are de/activated on an as-needed basis by the
+ * player to allow the user to stop ogg123 or skip songs.
+ */
+
+void signal_skipfile(int which_signal)
+{
+ skipfile_requested = 1;
+
+ /* libao, when writing wav's, traps SIGINT so it correctly
+ * closes things down in the event of an interrupt. We
+ * honour this. libao will re-raise SIGINT once it cleans
+ * up properly, causing the application to exit. This is
+ * desired since we would otherwise re-open output.wav
+ * and blow away existing "output.wav" file.
+ */
+
+ if (old_sig != NULL) {
+ signal(which_signal,old_sig);
+ raise(which_signal);
+ }
+
+}
+
+void signal_activate_skipfile(int ignored)
+{
+ old_sig = signal(SIGINT,signal_skipfile);
+}
+
+
void play_file(ogg123_options_t opt)
{
/* Oh my gosh this is disgusting. Big cleanups here will include an
@@ -327,6 +362,15 @@
/* Throw the comments plus a few lines about the bitstream we're
* decoding */
+
+ /* Setup so that pressing ^C in the first second of playback
+ * interrupts the program, but after the first second, skips
+ * the song. This functionality is similar to mpg123's abilities. */
+
+ skipfile_requested = 0;
+ signal(SIGALRM,signal_activate_skipfile);
+ alarm(1);
+
while (!eof) {
int i;
vorbis_comment *vc = ov_comment(&vf, -1);
@@ -373,7 +417,14 @@
ov_time_seek(&vf, realseekpos);
eos = 0;
+
while (!eos) {
+
+ if (skipfile_requested) {
+ eof = eos = 1;
+ break;
+ }
+
old_section = current_section;
ret =
ov_read(&vf, convbuffer, sizeof(convbuffer), is_big_endian,
@@ -419,6 +470,10 @@
}
}
}
+
+ alarm(0);
+ signal(SIGALRM,SIG_DFL);
+ signal(SIGINT,old_sig);
ov_clear(&vf);
--- >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