[xiph-cvs] cvs commit: vorbis-tools/ogg123 buffer.c buffer.h ogg123.c
Kenneth C. Arnold
kcarnold at xiph.org
Wed Aug 8 18:56:56 PDT 2001
kcarnold 01/08/08 18:56:56
Modified: ogg123 Tag: kcarnold_work buffer.c buffer.h ogg123.c
Log:
Last commit to my branch minus pthreads. This is all the buffer cleanups without it.
Revision Changes Path
No revision
No revision
1.7.2.5 +33 -36 vorbis-tools/ogg123/buffer.c
Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.4
retrieving revision 1.7.2.5
diff -u -r1.7.2.4 -r1.7.2.5
--- buffer.c 2001/06/24 01:24:56 1.7.2.4
+++ buffer.c 2001/08/09 01:56:54 1.7.2.5
@@ -5,8 +5,6 @@
* that program is used in this buffer.
*/
-/* #define DEBUG_BUFFER */
-
#include <sys/types.h>
#if HAVE_SMMAP
#include <sys/mman.h>
@@ -23,6 +21,8 @@
#include "ogg123.h"
#include "buffer.h"
+#undef DEBUG_BUFFER
+
#ifdef DEBUG_BUFFER
FILE *debugfile;
#define DEBUG0(x) do { fprintf (debugfile, x "\n" ); } while (0)
@@ -46,6 +46,7 @@
buf->end = buf->buffer + (size - 1);
buf->size = size;
buf->prebuffer = prebuffer;
+ buf->curfill = 0;
if (prebuffer > 0)
buf->status |= STAT_PREBUFFER;
}
@@ -58,39 +59,42 @@
signal (SIGUSR1, signal_handler);
DEBUG0("r: writer_main");
- while (! (buf->status & STAT_SHUTDOWN && buf->reader == buf->writer))
+ while (! (buf->status & STAT_SHUTDOWN && buf->curfill == 0))
{
/* Writer just waits on reader to be done with submit_chunk
* Reader must ensure that we don't deadlock. */
/* prebuffering */
+ prebuffer:
while (buf->status & STAT_PREBUFFER)
pause();
- if (buf->reader == buf->writer) {
- /* this won't deadlock, right...? */
+ if (buf->curfill == 0) {
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. */
+ kill (buf->readerpid, SIGUSR1);
}
if (buf->status & STAT_FLUSH) {
flush:
DEBUG0("r: buffer flush");
+ buf->curfill = 0;
buf->reader = buf->writer;
buf->status &= ~STAT_FLUSH;
DEBUG1("buf->status = %d", buf->status);
- write (buf->fds[1], "F", sizeof(int));
+ kill (buf->readerpid, SIGUSR1);
}
- while (buf->reader == buf->writer && !(buf->status & STAT_SHUTDOWN)
- && !(buf->status & STAT_FLUSH))
- DEBUG1("looping on buffer underflow, status is %d", buf->status);
+ if (buf->curfill == 0 && !(buf->status & STAT_SHUTDOWN)
+ && !(buf->status & STAT_FLUSH)) {
+ buf->status |= STAT_PREBUFFER;
+ goto prebuffer;
+ }
+ /* DEBUG1("looping on buffer underflow, status is %d", buf->status);*/
if (buf->status & STAT_FLUSH)
- goto flush; /* eeew... */
+ goto flush;
if (buf->reader == buf->writer)
break;
@@ -110,11 +114,14 @@
buf->writer = buf->buffer;
else
buf->writer++;
+ buf->curfill--;
+ if (buf->curfill + 1 == buf->size)
+ kill (buf->readerpid, SIGUSR1);
}
DEBUG0("r: shutting down buffer");
buf->status = 0;
write (buf->fds[1], "2", sizeof(int));
- kill (buf->writerpid, SIGHUP);
+ kill (buf->writerpid, SIGUSR1);
DEBUG0("r: exiting");
_exit(0);
}
@@ -190,9 +197,10 @@
fcntl (buf->fds[1], F_SETFL, O_NONBLOCK);
fflush (stdout);
- /* buffer flushes stderr, but stderr is unbuffered (*duh*!) */
+
+ signal (SIGUSR1, signal_handler);
- signal (SIGHUP, signal_handler);
+ buf->readerpid = getpid();
childpid = fork();
@@ -204,12 +212,12 @@
if (childpid == 0)
{
+ buf->writerpid = getpid();
writer_main (buf, d);
return NULL;
}
else {
- buf->writerpid = getpid();
- buf->readerpid = childpid;
+ buf->writerpid = childpid;
return buf;
}
}
@@ -224,8 +232,7 @@
DEBUG0("submit_chunk");
/* Wait wait, don't step on my sample! */
- while (!((buf->reader != buf->end && buf->reader + 1 != buf->writer) ||
- (buf->reader == buf->end && buf->writer != buf->buffer)))
+ while (buf->curfill == buf->size)
{
/* buffer overflow (yikes! no actually it's a GOOD thing) */
int ret;
@@ -248,15 +255,16 @@
buf->reader = buf->buffer;
else
buf->reader++;
+ buf->curfill++;
if (buf->status & STAT_PREBUFFER && buffer_full(buf) >= buf->prebuffer) {
buf->status &= ~STAT_PREBUFFER;
- kill (buf->readerpid, SIGUSR1);
+ kill (buf->writerpid, SIGUSR1);
}
else if (buf->status & STAT_UNDERFLOW) {
buf->status |= STAT_PREBUFFER;
buf->status &= ~STAT_UNDERFLOW;
- kill (buf->readerpid, SIGUSR1);
+ kill (buf->writerpid, SIGUSR1);
}
DEBUG0("submit_chunk exit");
}
@@ -269,18 +277,12 @@
void buffer_shutdown (buf_t *buf)
{
- /* struct timeval tv;*/
-
DEBUG0("shutdown buffer");
buf->status |= STAT_SHUTDOWN;
buf->status &= ~STAT_PREBUFFER;
while (buf->status != 0)
{
DEBUG0("waiting on reader to quit");
- /* tv.tv_sec = 1;
- tv.tv_usec = 0;
- select (0, NULL, NULL, NULL, &tv);*/
-
pause();
}
#ifndef HAVE_SMMAP
@@ -291,20 +293,15 @@
}
long buffer_full (buf_t* buf) {
- chunk_t *reader = buf->reader; /* thread safety... */
-
- if (reader > buf->writer)
- return (reader - buf->writer + 1);
- else
- return (buf->end - reader) + (buf->writer - buf->buffer) + 2;
+ return buf->curfill;
}
void buffer_cleanup (buf_t *buf) {
if (buf) {
- if (buf->readerpid)
- kill (buf->readerpid, SIGTERM);
+ if (buf->writerpid)
+ kill (buf->writerpid, SIGTERM);
wait (0);
- buf->readerpid = 0;
+ buf->writerpid = 0;
#ifndef HAVE_SMMAP
shmdt(buf);
#endif
1.2.2.5 +2 -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.4
retrieving revision 1.2.2.5
diff -u -r1.2.2.4 -r1.2.2.5
--- buffer.h 2001/08/06 21:35:40 1.2.2.4
+++ buffer.h 2001/08/09 01:56:55 1.2.2.5
@@ -12,7 +12,7 @@
typedef struct chunk_s
{
long len; /* Length of the chunk (for if we only got partial data) */
- char data[BUFFER_CHUNK_SIZE];
+ unsigned char data[BUFFER_CHUNK_SIZE];
} chunk_t;
typedef struct buf_s
@@ -20,6 +20,7 @@
char status; /* Status. See STAT_* below. */
int fds[2]; /* Pipe file descriptors. */
long size; /* buffer size, for reference */
+ long curfill; /* how much the buffer is currently filled */
long prebuffer; /* number of chunks to prebuffer */
pid_t readerpid; /* PID of reader process */
pid_t writerpid; /* PID of writer process */
1.39.2.7 +10 -7 vorbis-tools/ogg123/ogg123.c
Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.6
retrieving revision 1.39.2.7
diff -u -r1.39.2.6 -r1.39.2.7
--- ogg123.c 2001/08/06 21:35:40 1.39.2.6
+++ ogg123.c 2001/08/09 01:56:55 1.39.2.7
@@ -14,7 +14,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.c,v 1.39.2.6 2001/08/06 21:35:40 volsung Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.7 2001/08/09 01:56:55 kcarnold Exp $
********************************************************************/
@@ -41,7 +41,7 @@
buf_t * buffer = NULL;
static char skipfile_requested;
-static void (*old_sig)(int);
+/*static void (*old_sig)(int);*/
struct {
char *key; /* includes the '=' for programming convenience */
@@ -244,7 +244,7 @@
srand(time(NULL));
for (i = optind; i < argc; i++) {
- int j = optind + rand() % (argc - i);
+ int j = optind + (int) ((double)(argc - i)*(double)rand()/(RAND_MAX+1.0));
char *temp = argv[i];
argv[i] = argv[j];
argv[j] = temp;
@@ -292,18 +292,23 @@
* and blow away existing "output.wav" file.
*/
+ fprintf (stderr, "skipfile\n");
+
+#if 0
if (old_sig != NULL) {
signal(which_signal,old_sig);
raise(which_signal);
}
else
+#endif
signal (SIGINT, signal_quit);
/* should that be unconditional? man pages are not clear on this */
}
void signal_activate_skipfile(int ignored)
{
- old_sig = signal(SIGINT,signal_skipfile);
+ fprintf (stderr, "activate skipfile.\n");
+ /*old_sig = */signal(SIGINT,signal_skipfile);
}
void signal_quit(int ignored)
@@ -311,8 +316,6 @@
exit(0);
}
-
-
void play_file(ogg123_options_t opt)
{
/* Oh my gosh this is disgusting. Big cleanups here will include an
@@ -569,7 +572,7 @@
alarm(0);
signal(SIGALRM,SIG_DFL);
- signal(SIGINT,old_sig);
+ signal(SIGINT,signal_quit);
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