[xiph-cvs] cvs commit: vorbis-tools/ogg123 buffer.c buffer.h ogg123.c ogg123.h
Kenneth C. Arnold
kcarnold at xiph.org
Sat Jun 23 18:24:58 PDT 2001
kcarnold 01/06/23 18:24:57
Modified: ogg123 Tag: kcarnold_work buffer.c buffer.h ogg123.c
ogg123.h
Log:
Prebuffering. And a bit of underflow handling code, but not fully there yet.
-p/--prebuffer.
And more signals...
Revision Changes Path
No revision
No revision
1.7.2.4 +25 -4 vorbis-tools/ogg123/buffer.c
Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.3
retrieving revision 1.7.2.4
diff -u -r1.7.2.3 -r1.7.2.4
--- buffer.c 2001/06/24 01:03:12 1.7.2.3
+++ buffer.c 2001/06/24 01:24:56 1.7.2.4
@@ -37,7 +37,7 @@
}
/* Initialize the buffer structure. */
-void buffer_init (buf_t *buf, long size)
+void buffer_init (buf_t *buf, long size, long prebuffer)
{
DEBUG0("buffer init");
memset (buf, 0, sizeof(*buf));
@@ -45,6 +45,9 @@
buf->reader = buf->writer = buf->buffer;
buf->end = buf->buffer + (size - 1);
buf->size = size;
+ buf->prebuffer = prebuffer;
+ if (prebuffer > 0)
+ buf->status |= STAT_PREBUFFER;
}
/* Main write loop. No semaphores. No deadlock. No problem. I hope. */
@@ -52,15 +55,22 @@
{
devices_t *d1;
signal (SIGINT, SIG_IGN);
+ signal (SIGUSR1, signal_handler);
DEBUG0("r: writer_main");
while (! (buf->status & STAT_SHUTDOWN && buf->reader == buf->writer))
{
- /* Writer just waits on reader to be done with buf_write.
+ /* Writer just waits on reader to be done with submit_chunk
* Reader must ensure that we don't deadlock. */
+ /* prebuffering */
+ while (buf->status & STAT_PREBUFFER)
+ pause();
+
if (buf->reader == buf->writer) {
/* this won't deadlock, right...? */
+ if (! (buf->status & STAT_FLUSH)) /* likely unnecessary */
+ buf->status |= STAT_UNDERFLOW;
DEBUG0("alerting writer");
write (buf->fds[1], "1", sizeof(int)); /* This identifier could hold a lot
* more detail in the future. */
@@ -114,7 +124,7 @@
* to the buffer structure that is shared. Just pass this straight to
* submit_chunk and all will be happy. */
-buf_t *fork_writer (long size, devices_t *d)
+buf_t *fork_writer (long size, devices_t *d, long prebuffer)
{
int childpid;
buf_t *buf;
@@ -164,7 +174,7 @@
setvbuf (debugfile, NULL, _IONBF, 0);
#endif
- buffer_init (buf, size);
+ buffer_init (buf, size, prebuffer);
/* Create a pipe for communication between the two processes. Unlike
* the first incarnation of an ogg123 buffer, the data is not transferred
@@ -238,6 +248,16 @@
buf->reader = buf->buffer;
else
buf->reader++;
+
+ if (buf->status & STAT_PREBUFFER && buffer_full(buf) >= buf->prebuffer) {
+ buf->status &= ~STAT_PREBUFFER;
+ kill (buf->readerpid, SIGUSR1);
+ }
+ else if (buf->status & STAT_UNDERFLOW) {
+ buf->status |= STAT_PREBUFFER;
+ buf->status &= ~STAT_UNDERFLOW;
+ kill (buf->readerpid, SIGUSR1);
+ }
DEBUG0("submit_chunk exit");
}
@@ -253,6 +273,7 @@
DEBUG0("shutdown buffer");
buf->status |= STAT_SHUTDOWN;
+ buf->status &= ~STAT_PREBUFFER;
while (buf->status != 0)
{
DEBUG0("waiting on reader to quit");
1.2.2.3 +4 -1 vorbis-tools/ogg123/buffer.h
Index: buffer.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.h,v
retrieving revision 1.2.2.2
retrieving revision 1.2.2.3
diff -u -r1.2.2.2 -r1.2.2.3
--- buffer.h 2001/06/24 01:03:12 1.2.2.2
+++ buffer.h 2001/06/24 01:24:56 1.2.2.3
@@ -18,6 +18,7 @@
char status; /* Status. See STAT_* below. */
int fds[2]; /* Pipe file descriptors. */
long size; /* buffer size, for reference */
+ long prebuffer; /* number of chunks to prebuffer */
pid_t readerpid; /* PID of reader process */
pid_t writerpid; /* PID of writer process */
chunk_t *reader; /* Chunk the reader is busy with */
@@ -26,7 +27,7 @@
chunk_t buffer[1]; /* The buffer itself. It's more than one chunk. */
} buf_t;
-buf_t *fork_writer (long size, devices_t *d);
+buf_t *fork_writer (long size, devices_t *d, long prebuffer);
void submit_chunk (buf_t *buf, chunk_t chunk);
void buffer_shutdown (buf_t *buf);
void buffer_cleanup (buf_t *buf);
@@ -35,6 +36,8 @@
#define STAT_FLUSH 1
#define STAT_SHUTDOWN 2
+#define STAT_PREBUFFER 4
+#define STAT_UNDERFLOW 8
#endif /* !defined (__BUFFER_H) */
1.39.2.5 +10 -3 vorbis-tools/ogg123/ogg123.c
Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.4
retrieving revision 1.39.2.5
diff -u -r1.39.2.4 -r1.39.2.5
--- ogg123.c 2001/06/24 01:03:12 1.39.2.4
+++ ogg123.c 2001/06/24 01:24:56 1.39.2.5
@@ -14,7 +14,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.c,v 1.39.2.4 2001/06/24 01:03:12 kcarnold Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.5 2001/06/24 01:24:56 kcarnold Exp $
********************************************************************/
@@ -69,6 +69,7 @@
{"quiet", no_argument, 0, 'q'},
{"shuffle", no_argument, 0, 'z'},
{"buffer", required_argument, 0, 'b'},
+ {"prebuffer", required_argument, 0, 'p'},
{"delay", required_argument, 0, 'l'},
{"nth", required_argument, 0, 'x'},
{"ntimes", required_argument, 0, 'y'},
@@ -123,7 +124,7 @@
signal (SIGINT, signal_quit);
ao_initialize();
- while (-1 != (ret = getopt_long(argc, argv, "b:d:hl:k:o:qvVxyz",
+ while (-1 != (ret = getopt_long(argc, argv, "b:d:hl:k:o:p:qvVx:y:z",
long_options, &option_index))) {
switch (ret) {
case 0:
@@ -159,6 +160,9 @@
case 'h':
usage();
exit(0);
+ case 'p':
+ opt.prebuffer = atoi (optarg);
+ break;
case 'q':
opt.quiet++;
break;
@@ -185,6 +189,9 @@
}
}
+ if (opt.buffer_size > 1 && opt.prebuffer == 0)
+ opt.prebuffer = 1; /* for good measure */
+
/* Add last device to device list or use the default device */
if (temp_driver_id < 0) {
temp_driver_id = get_default_device();
@@ -620,7 +627,7 @@
}
if (opt->buffer_size)
- *buffer = fork_writer (opt->buffer_size, opt->outdevices);
+ *buffer = fork_writer (opt->buffer_size, opt->outdevices, opt->prebuffer);
return 0;
}
1.7.2.5 +1 -0 vorbis-tools/ogg123/ogg123.h
Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.7.2.4
retrieving revision 1.7.2.5
diff -u -r1.7.2.4 -r1.7.2.5
--- ogg123.h 2001/06/24 01:03:12 1.7.2.4
+++ ogg123.h 2001/06/24 01:24:56 1.7.2.5
@@ -31,6 +31,7 @@
char *default_device; /* default device for playback */
devices_t *outdevices; /* Streams to write to. */
int buffer_size; /* Size of the buffer in chunks. */
+ int prebuffer; /* number of chunks to prebuffer */
int rate, channels; /* playback params for opening audio devices */
int delay; /* delay for skip to next song */
int nth; /* Play every nth chunk */
--- >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