aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/decode.c3
-rw-r--r--src/outputBuffer.c8
-rw-r--r--src/outputBuffer.h3
3 files changed, 12 insertions, 2 deletions
diff --git a/src/decode.c b/src/decode.c
index a07d61843..520485383 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -425,8 +425,7 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
pc->play = 0;
wakeup_main_task();
- while ((unsigned)cb->end - cb->begin < bbp &&
- cb->end != buffered_chunks - 1 &&
+ while (availableOutputBuffer(cb) < bbp &&
dc->state != DECODE_STATE_STOP) {
processDecodeInput();
player_sleep();
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index d15a947e3..f5a6dbf51 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -57,6 +57,14 @@ void flushOutputBuffer(OutputBuffer * cb)
}
}
+unsigned availableOutputBuffer(const OutputBuffer * cb)
+{
+ if (cb->end >= cb->begin)
+ return cb->end - cb->begin;
+ else
+ return cb->end + buffered_chunks - cb->begin;
+}
+
/**
* 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
diff --git a/src/outputBuffer.h b/src/outputBuffer.h
index 4d480e08a..08124dffa 100644
--- a/src/outputBuffer.h
+++ b/src/outputBuffer.h
@@ -55,6 +55,9 @@ void clearOutputBuffer(OutputBuffer * cb);
void flushOutputBuffer(OutputBuffer * cb);
+/** determine the number of decoded chunks */
+unsigned availableOutputBuffer(const OutputBuffer * cb);
+
/* we send inStream for buffering the inputStream while waiting to
send the next chunk */
int sendDataToOutputBuffer(OutputBuffer * cb,