aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:11:23 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:11:23 +0000
commit1ecebd4686e815773928ee89fd4dc09d2e1dfdfc (patch)
tree34b4de765a6b8bc0020b1b9a5238005fa7515fcc
parent63b55b9a48bfa59f541adab8629d9927e040c714 (diff)
downloadmpd-1ecebd4686e815773928ee89fd4dc09d2e1dfdfc.tar.gz
mpd-1ecebd4686e815773928ee89fd4dc09d2e1dfdfc.tar.xz
mpd-1ecebd4686e815773928ee89fd4dc09d2e1dfdfc.zip
moved code to function tailChunk()
This patch removes some clutter from decodeParent() by moving some code out. git-svn-id: https://svn.musicpd.org/mpd/trunk@7247 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/outputBuffer.c91
1 files changed, 58 insertions, 33 deletions
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 04641faa3..d15a947e3 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -57,6 +57,54 @@ void flushOutputBuffer(OutputBuffer * cb)
}
}
+/**
+ * Return the tail chunk has room for additional data. If there is no
+ * room in the queue, this function blocks until the player thread has
+ * finished playing its current chunk.
+ *
+ * @return the positive index of the new chunk; OUTPUT_BUFFER_DC_SEEK
+ * if another thread requested seeking; OUTPUT_BUFFER_DC_STOP if
+ * another thread requested stopping the decoder.
+ */
+static int tailChunk(OutputBuffer * cb, InputStream * inStream,
+ DecoderControl * dc, int seekable,
+ float data_time, mpd_uint16 bitRate)
+{
+ unsigned int next;
+
+ if (currentChunk == cb->end)
+ return currentChunk;
+
+ next = cb->end + 1;
+ if (next >= buffered_chunks) {
+ next = 0;
+ }
+ while (cb->begin == next && !dc->stop) {
+ if (dc->seek) {
+ if (seekable) {
+ return OUTPUT_BUFFER_DC_SEEK;
+ } else {
+ dc->seekError = 1;
+ dc->seek = 0;
+ decoder_wakeup_player();
+ }
+ }
+ if (!inStream ||
+ bufferInputStream(inStream) <= 0) {
+ decoder_sleep();
+ }
+ }
+ if (dc->stop)
+ return OUTPUT_BUFFER_DC_STOP;
+
+ currentChunk = cb->end;
+ cb->chunkSize[currentChunk] = 0;
+ cb->bitRate[currentChunk] = bitRate;
+ cb->times[currentChunk] = data_time;
+
+ return currentChunk;
+}
+
int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream,
DecoderControl * dc, int seekable, void *dataIn,
size_t dataInLen, float data_time, mpd_uint16 bitRate,
@@ -93,45 +141,22 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream,
normalizeData(data, datalen, &cb->audioFormat);
while (datalen) {
- if (currentChunk != cb->end) {
- unsigned int next = cb->end + 1;
- if (next >= buffered_chunks) {
- next = 0;
- }
- while (cb->begin == next && !dc->stop) {
- if (dc->seek) {
- if (seekable) {
- return OUTPUT_BUFFER_DC_SEEK;
- } else {
- dc->seekError = 1;
- dc->seek = 0;
- decoder_wakeup_player();
- }
- }
- if (!inStream ||
- bufferInputStream(inStream) <= 0) {
- decoder_sleep();
- }
- }
- if (dc->stop)
- return OUTPUT_BUFFER_DC_STOP;
-
- currentChunk = cb->end;
- cb->chunkSize[currentChunk] = 0;
- cb->bitRate[currentChunk] = bitRate;
- cb->times[currentChunk] = data_time;
- }
+ int chunk_index = tailChunk(cb, inStream,
+ dc, seekable,
+ data_time, bitRate);
+ if (chunk_index < 0)
+ return chunk_index;
- chunkLeft = CHUNK_SIZE - cb->chunkSize[currentChunk];
+ chunkLeft = CHUNK_SIZE - cb->chunkSize[chunk_index];
dataToSend = datalen > chunkLeft ? chunkLeft : datalen;
- memcpy(cb->chunks + currentChunk * CHUNK_SIZE +
- cb->chunkSize[currentChunk], data, dataToSend);
- cb->chunkSize[currentChunk] += dataToSend;
+ memcpy(cb->chunks + chunk_index * CHUNK_SIZE +
+ cb->chunkSize[chunk_index], data, dataToSend);
+ cb->chunkSize[chunk_index] += dataToSend;
datalen -= dataToSend;
data += dataToSend;
- if (cb->chunkSize[currentChunk] == CHUNK_SIZE) {
+ if (cb->chunkSize[chunk_index] == CHUNK_SIZE) {
flushOutputBuffer(cb);
}
}