diff options
author | Max Kellermann <max@duempel.org> | 2008-04-12 04:21:09 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:21:09 +0000 |
commit | 3105280f26e07108ba979be11e398ff2155c1ceb (patch) | |
tree | 77026a5ee2d68afe613257510afdb586190d9d50 /src | |
parent | 5cfb1cf46e9bbc87a6a8ebfea294be6cebf0f4a5 (diff) | |
download | mpd-3105280f26e07108ba979be11e398ff2155c1ceb.tar.gz mpd-3105280f26e07108ba979be11e398ff2155c1ceb.tar.xz mpd-3105280f26e07108ba979be11e398ff2155c1ceb.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/outputBuffer.c | 35 |
1 files 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) |