From 3105280f26e07108ba979be11e398ff2155c1ceb Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 12 Apr 2008 04:21:09 +0000 Subject: 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 --- src/outputBuffer.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/outputBuffer.c b/src/outputBuffer.c index 37b0e2f20..cf4be8f1b 100644 --- a/src/outputBuffer.c +++ b/src/outputBuffer.c @@ -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) -- cgit v1.2.3