Commit a7b19012 authored by Max Kellermann's avatar Max Kellermann Committed by Eric Wong

add method availableOutputBuffer()

The method availableOutputBuffer() calculates how many chunks are in use. This simplifies code which needs this information, and it can run without knowing OutputBuffer internals. The function knows how to calculate this when begin>end; this might have been a bug in decodeParent(), which does not. git-svn-id: https://svn.musicpd.org/mpd/trunk@7250 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 0defe87d
......@@ -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();
......
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment