[xiph-cvs] cvs commit: vorbis-tools/ogg123 buffer.c buffer.h ogg123.c ogg123.h
Kenneth C. Arnold
kcarnold at xiph.org
Wed Aug 22 18:15:48 PDT 2001
kcarnold 01/08/22 18:15:48
Modified: ogg123 Tag: kcarnold_work buffer.c buffer.h ogg123.c
ogg123.h
Log:
A few more buffer things, and some commented code for closing devices
on SIGTSTP that won't work with buffering, at least never reliably
enough to be worth including. Hardened OutBufferWrite; rechunks output
into BUFFER_CHUNK_SIZE chunks before writing. It's another memmove of
the entire decoded data by the time we're done, but it's much more
solid for keeping channels in the right order. This was originally
done to try to get the closing devices code to work right, but even
when that was removed it still seems a good deal more robust.
Revision Changes Path
No revision
No revision
1.7.2.18 +14 -3 vorbis-tools/ogg123/buffer.c
Index: buffer.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/buffer.c,v
retrieving revision 1.7.2.17
retrieving revision 1.7.2.18
diff -u -r1.7.2.17 -r1.7.2.18
--- buffer.c 2001/08/22 16:42:30 1.7.2.17
+++ buffer.c 2001/08/23 01:15:46 1.7.2.18
@@ -11,7 +11,7 @@
* *
********************************************************************
- last mod: $Id: buffer.c,v 1.7.2.17 2001/08/22 16:42:30 kcarnold Exp $
+ last mod: $Id: buffer.c,v 1.7.2.18 2001/08/23 01:15:46 kcarnold Exp $
********************************************************************/
@@ -85,7 +85,7 @@
void PthreadCleanup (void *arg)
{
-#if 0
+#ifdef DEBUG_BUFFER
buf_t *buf = (buf_t*) arg;
#endif
@@ -133,6 +133,7 @@
while (!(buf->Playing) ||
(buf->StatMask & STAT_PREBUFFERING)) {
DEBUG1 ("waiting on !playing || prebuffering (stat=%d)", buf->StatMask);
+ pthread_cond_signal (&buf->UnderflowCondition);
TIMEDWAIT (buf->DataReadyCondition, buf->SizeMutex, 1, 0);
}
@@ -223,12 +224,13 @@
DEBUG0("writing chunk to output");
/* unlock while playing sample */
+ buf->bufferWriting = 1;
UNLOCK_MUTEX (buf->SizeMutex);
DEBUG1("WriteThisTime=%d", WriteThisTime);
buf->write_func (buf->writer, WriteThisTime, 1, buf->data, tmpEOS);
- DEBUG0("incrementing pointer");
LOCK_MUTEX (buf->SizeMutex);
+ buf->bufferWriting = 0;
if (vbuf->curfill == 0)
{
/* buffer was flushed while we were writing (and had the mutex unlocked)
@@ -423,6 +425,15 @@
void buffer_Pause (buf_t *buf)
{
buf->Playing = 0;
+}
+
+void buffer_WaitForPaused (buf_t *buf)
+{
+ buf->Playing = 0;
+ LOCK_MUTEX (buf->SizeMutex);
+ while (buf->bufferWriting)
+ TIMEDWAIT(buf->UnderflowCondition, buf->SizeMutex, 1, 0);
+ UNLOCK_MUTEX (buf->SizeMutex);
}
void buffer_Unpause (buf_t *buf)
1.2.2.16 +3 -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.15
retrieving revision 1.2.2.16
diff -u -r1.2.2.15 -r1.2.2.16
--- buffer.h 2001/08/22 16:42:31 1.2.2.15
+++ buffer.h 2001/08/23 01:15:46 1.2.2.16
@@ -11,7 +11,7 @@
* *
********************************************************************
- last mod: $Id: buffer.h,v 1.2.2.15 2001/08/22 16:42:31 kcarnold Exp $
+ last mod: $Id: buffer.h,v 1.2.2.16 2001/08/23 01:15:46 kcarnold Exp $
********************************************************************/
@@ -55,6 +55,7 @@
long curfill; /* how much the buffer is currently filled */
long prebuffer; /* number of chunks to prebuffer */
char eos; /* set if reader is at end of stream */
+ char bufferWriting; /* set if buffer is busy writing data to output */
chunk *reader; /* Chunk the reader is busy with */
chunk *writer; /* Chunk the writer is busy with */
chunk *end; /* Last chunk in the buffer (for convenience) */
@@ -78,6 +79,7 @@
long buffer_full (buf_t *buf);
void buffer_Pause (buf_t *buf);
+void buffer_WaitForPaused (buf_t *buf);
void buffer_Unpause (buf_t *buf);
char buffer_Paused (buf_t *buf);
void buffer_KillBuffer (buf_t *buf, int signo);
1.39.2.23 +52 -15 vorbis-tools/ogg123/ogg123.c
Index: ogg123.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.c,v
retrieving revision 1.39.2.22
retrieving revision 1.39.2.23
diff -u -r1.39.2.22 -r1.39.2.23
--- ogg123.c 2001/08/22 16:42:31 1.39.2.22
+++ ogg123.c 2001/08/23 01:15:46 1.39.2.23
@@ -14,7 +14,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.c,v 1.39.2.22 2001/08/22 16:42:31 kcarnold Exp $
+ last mod: $Id: ogg123.c,v 1.39.2.23 2001/08/23 01:15:46 kcarnold Exp $
********************************************************************/
@@ -245,15 +245,37 @@
size_t OutBufferWrite(void *ptr, size_t size, size_t nmemb, void *arg, char iseos)
{
static ogg_int64_t cursample = 0;
+ static unsigned char RechunkBuffer[BUFFER_CHUNK_SIZE];
+ static int curBuffered = 0;
+ size_t origSize;
+ unsigned char *data = ptr;
+
+ size *= nmemb;
+ origSize = size;
SetTime (Options.statOpts.stats, cursample);
SetBuffersStats ();
UpdateStats (Options.statOpts.stats);
cursample += Options.playOpts.nth * size * nmemb / Options.outputOpts.channels / 2 / Options.playOpts.ntimes; /* locked to 16-bit */
- if (iseos)
+ /* don't actually write until we have a full chunk, or of course EOS */
+ while (size) {
+ int toChunkNow = BUFFER_CHUNK_SIZE - curBuffered <= size ? BUFFER_CHUNK_SIZE - curBuffered : size;
+ memmove (RechunkBuffer + curBuffered, data, toChunkNow);
+ size -= toChunkNow;
+ data += toChunkNow;
+ curBuffered += toChunkNow;
+ if (curBuffered == BUFFER_CHUNK_SIZE) {
+ devices_write (RechunkBuffer, curBuffered, 1, Options.outputOpts.devices);
+ curBuffered = 0;
+ }
+ }
+ if (iseos) {
cursample = 0;
- return devices_write (ptr, size, nmemb, Options.outputOpts.devices);
+ devices_write (RechunkBuffer, curBuffered, 1, Options.outputOpts.devices);
+ curBuffered = 0;
+ }
+ return origSize;
}
/* /buffer interface */
@@ -568,15 +590,27 @@
buffer_flush (Options.outputOpts.buffer);
break;
case SIGTSTP:
- if (Options.outputOpts.buffer)
+ if (Options.outputOpts.buffer) {
buffer_KillBuffer (Options.outputOpts.buffer, SIGSTOP);
- /* buffer_Pause (Options.outputOpts.buffer); */
+ }
kill (getpid(), SIGSTOP);
+ /* buffer_Pause (Options.outputOpts.buffer);
+ buffer_WaitForPaused (Options.outputOpts.buffer);
+ }
+ if (Options.outputOpts.devicesOpen == 0) {
+ close_audio_devices (Options.outputOpts.devices);
+ Options.outputOpts.devicesOpen = 0;
+ }
+ */
+ /* open_audio_devices();
+ if (Options.outputOpts.buffer) {
+ buffer_Unpause (Options.outputOpts.buffer);
+ }
+ */
break;
case SIGCONT:
if (Options.outputOpts.buffer)
buffer_KillBuffer (Options.outputOpts.buffer, SIGCONT);
- /* buffer_Unpause (Options.outputOpts.buffer); */
break;
default:
psignal (signo, "Unknown signal caught");
@@ -732,7 +766,7 @@
buffer_flush (Options.outputOpts.buffer);
break;
}
-
+
old_section = current_section;
ret =
ov_read(&vf, convbuffer, sizeof(convbuffer), is_big_endian,
@@ -833,16 +867,17 @@
devices_t *current;
ao_sample_format format;
- if(prevrate == Options.outputOpts.rate && prevchan == Options.outputOpts.channels)
+ if(prevrate == Options.outputOpts.rate && prevchan == Options.outputOpts.channels && Options.outputOpts.devicesOpen)
return 0;
- if(prevrate !=0 && prevchan!=0)
- {
- if (Options.outputOpts.buffer)
- buffer_WaitForEmpty (Options.outputOpts.buffer);
-
- close_audio_devices (Options.outputOpts.devices);
- }
+ if(prevrate !=0 && prevchan!=0 && Options.outputOpts.devicesOpen)
+ {
+ if (Options.outputOpts.buffer)
+ buffer_WaitForEmpty (Options.outputOpts.buffer);
+
+ close_audio_devices (Options.outputOpts.devices);
+ Options.outputOpts.devicesOpen = 0;
+ }
format.rate = prevrate = Options.outputOpts.rate;
format.channels = prevchan = Options.outputOpts.channels;
@@ -905,6 +940,7 @@
current = current->next_device;
}
+ Options.outputOpts.devicesOpen = 1;
return 0;
}
@@ -921,4 +957,5 @@
}
ao_onexit (exitcode, Options.outputOpts.devices);
+ Options.outputOpts.devicesOpen = 0;
}
1.7.2.12 +2 -1 vorbis-tools/ogg123/ogg123.h
Index: ogg123.h
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/ogg123/ogg123.h,v
retrieving revision 1.7.2.11
retrieving revision 1.7.2.12
diff -u -r1.7.2.11 -r1.7.2.12
--- ogg123.h 2001/08/22 16:42:31 1.7.2.11
+++ ogg123.h 2001/08/23 01:15:46 1.7.2.12
@@ -11,7 +11,7 @@
* *
********************************************************************
- last mod: $Id: ogg123.h,v 1.7.2.11 2001/08/22 16:42:31 kcarnold Exp $
+ last mod: $Id: ogg123.h,v 1.7.2.12 2001/08/23 01:15:46 kcarnold Exp $
********************************************************************/
@@ -64,6 +64,7 @@
long BufferSize;
float Prebuffer;
int rate, channels; /* playback params for opening audio devices */
+ char devicesOpen;
devices_t *devices;
char *default_device;
} outputOpts;
--- >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