Commit 3105280f authored by Max Kellermann's avatar Max Kellermann Committed by Eric Wong

added output_buffer_expand()

output_buffer_expand() moves the cb->end to the new position (only its current successor is allowed) and wakes up the player if is waiting for the decoder. This simplifies flushOutputBuffer(). git-svn-id: https://svn.musicpd.org/mpd/trunk@7338 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 5cfb1cf4
......@@ -54,21 +54,30 @@ static inline unsigned successor(const OutputBuffer * cb, unsigned i)
return i == cb->size ? 0 : i;
}
/**
* Mark the tail chunk as "full" and wake up the player if is waiting
* for the decoder.
*/
static void output_buffer_expand(OutputBuffer * cb, unsigned i)
{
int was_empty = outputBufferEmpty(cb);
assert(i == (cb->end + 1) % cb->size);
assert(i != cb->end);
cb->end = i;
cb->currentChunk = -1;
if (was_empty)
/* if the buffer was empty, the player thread might be
waiting for us; wake it up now that another decoded
buffer has become available. */
decoder_wakeup_player();
}
void flushOutputBuffer(OutputBuffer * cb)
{
if (cb->currentChunk == (int)cb->end) {
int was_empty = outputBufferEmpty(cb);
cb->end = successor(cb, cb->end);
cb->currentChunk = -1;
if (was_empty)
/* if the buffer was empty, the player thread
might be waiting for us; wake it up now
that another decoded buffer has become
available. */
decoder_wakeup_player();
}
if (cb->currentChunk == (int)cb->end)
output_buffer_expand(cb, successor(cb, cb->end));
}
int outputBufferEmpty(const 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