summaryrefslogtreecommitdiff
path: root/src/outputBuffer.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-05-07 19:11:43 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-05-07 19:11:43 +0000
commitc9f0d22f0ac19dcee7d1991020c75c8a3691b1b7 (patch)
tree9a7a1f0877821c01c808b6e65420e833fa31f263 /src/outputBuffer.c
parent3794126e5609112d68a2e0c9cbae5a923da301b6 (diff)
rewrite outputBuffer'ing abstraction a bit to be more effecient and easier
to interface. Also, use outputBuffer abstraction for ogg git-svn-id: https://svn.musicpd.org/mpd/trunk@941 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/outputBuffer.c')
-rw-r--r--src/outputBuffer.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 191ea7556..1861fe45a 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -24,39 +24,57 @@
#include <string.h>
-long sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
- int flushAllData, char * data, long datalen, float time,
- mpd_uint16 bitRate)
+static mpd_sint16 currentChunk = -1;
+
+void flushOutputBuffer(OutputBuffer * cb) {
+ if(currentChunk == cb->end) {
+ cb->end++;
+ if(cb->end>=buffered_chunks) {
+ cb->end = 0;
+ cb->wrap = 1;
+ }
+ currentChunk = -1;
+ }
+}
+
+int sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
+ char * data, long datalen, float time, mpd_uint16 bitRate)
{
- long dataSent = 0;
- long dataToSend;
+ mpd_uint16 dataToSend;
+ mpd_uint16 chunkLeft;
- while(datalen >= CHUNK_SIZE || (flushAllData && datalen)) {
- dataToSend = datalen > CHUNK_SIZE ? CHUNK_SIZE : datalen;
+ while(datalen) {
+ if(currentChunk != cb->end) {
+ while(cb->begin==cb->end && cb->wrap && !dc->stop &&
+ !dc->seek)
+ {
+ my_usleep(10000);
+ }
+ if(dc->stop) return OUTPUT_BUFFER_DC_STOP;
+ if(dc->seek) return OUTPUT_BUFFER_DC_SEEK;
- while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek)
- my_usleep(10000);
- if(dc->stop) return OUTPUT_BUFFER_DC_STOP;
- /* just for now, so it doesn't hang */
- if(dc->seek) return OUTPUT_BUFFER_DC_SEEK;
- /* be sure to remove this! */
+ currentChunk = cb->end;
+ cb->chunkSize[currentChunk] = 0;
+ }
- memcpy(cb->chunks+cb->end*CHUNK_SIZE,data,dataToSend);
- cb->chunkSize[cb->end] = dataToSend;
- cb->bitRate[cb->end] = bitRate;
- cb->times[cb->end] = time;
+ chunkLeft = CHUNK_SIZE-cb->chunkSize[currentChunk];
+ dataToSend = datalen > chunkLeft ? chunkLeft : datalen;
- cb->end++;
- if(cb->end>=buffered_chunks) {
- cb->end = 0;
- cb->wrap = 1;
- }
+ memcpy(cb->chunks+currentChunk*CHUNK_SIZE+
+ cb->chunkSize[currentChunk],
+ data, dataToSend);
+ cb->chunkSize[currentChunk]+= dataToSend;
+ cb->bitRate[currentChunk] = bitRate;
+ cb->times[currentChunk] = time;
datalen-= dataToSend;
- dataSent+= dataToSend;
data+= dataToSend;
+
+ if(cb->chunkSize[currentChunk] == CHUNK_SIZE) {
+ flushOutputBuffer(cb);
+ }
}
- return dataSent;
+ return 0;
}
/* vim:set shiftwidth=4 tabstop=8 expandtab: */