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
This commit is contained in:
parent
5cfb1cf46e
commit
3105280f26
@ -54,21 +54,30 @@ static inline unsigned successor(const OutputBuffer * cb, unsigned i)
|
|||||||
return i == cb->size ? 0 : 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)
|
void flushOutputBuffer(OutputBuffer * cb)
|
||||||
{
|
{
|
||||||
if (cb->currentChunk == (int)cb->end) {
|
if (cb->currentChunk == (int)cb->end)
|
||||||
int was_empty = outputBufferEmpty(cb);
|
output_buffer_expand(cb, successor(cb, cb->end));
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int outputBufferEmpty(const OutputBuffer * cb)
|
int outputBufferEmpty(const OutputBuffer * cb)
|
||||||
|
Loading…
Reference in New Issue
Block a user