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

moved check to outputBufferAbsolute()

decoderParent() uses a lot of OutputBuffer internals to see whether cross-fading should be started. Move these checks to outputBuffer.c, which also simplifies decoderParent(). git-svn-id: https://svn.musicpd.org/mpd/trunk@7262 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent a5464282
...@@ -503,7 +503,6 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer * ...@@ -503,7 +503,6 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
(fadePosition = next - cb->begin + (fadePosition = next - cb->begin +
buffered_chunks) <= crossFadeChunks))) { buffered_chunks) <= crossFadeChunks))) {
/* perform cross fade */ /* perform cross fade */
unsigned int test = end;
if (nextChunk < 0) { if (nextChunk < 0) {
/* beginning of the cross fade /* beginning of the cross fade
- adjust crossFadeChunks - adjust crossFadeChunks
...@@ -512,13 +511,8 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer * ...@@ -512,13 +511,8 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
chunks in the old song */ chunks in the old song */
crossFadeChunks = fadePosition; crossFadeChunks = fadePosition;
} }
if (end < cb->begin) nextChunk = outputBufferAbsolute(cb, crossFadeChunks);
test += buffered_chunks; if (nextChunk >= 0) {
nextChunk = cb->begin + crossFadeChunks;
if ((unsigned)nextChunk < test) {
if ((unsigned)nextChunk >= buffered_chunks) {
nextChunk -= buffered_chunks;
}
pcm_mix(cb->chunks + pcm_mix(cb->chunks +
cb->begin * CHUNK_SIZE, cb->begin * CHUNK_SIZE,
cb->chunks + cb->chunks +
...@@ -575,16 +569,9 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer * ...@@ -575,16 +569,9 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
/* the cross-fade is finished; skip /* the cross-fade is finished; skip
the section which was cross-faded the section which was cross-faded
(and thus already played) */ (and thus already played) */
unsigned int test = end; nextChunk = outputBufferAbsolute(cb, crossFadeChunks);
nextChunk = cb->begin + crossFadeChunks; if (nextChunk >= 0)
if (end < cb->begin)
test += buffered_chunks;
if ((unsigned)nextChunk < test) {
if ((unsigned)nextChunk >= buffered_chunks) {
nextChunk -= buffered_chunks;
}
advanceOutputBufferTo(cb, nextChunk); advanceOutputBufferTo(cb, nextChunk);
}
} }
/* wait for the decoder to work on the new song */ /* wait for the decoder to work on the new song */
......
...@@ -65,6 +65,23 @@ unsigned availableOutputBuffer(const OutputBuffer * cb) ...@@ -65,6 +65,23 @@ unsigned availableOutputBuffer(const OutputBuffer * cb)
return cb->end + buffered_chunks - cb->begin; return cb->end + buffered_chunks - cb->begin;
} }
int outputBufferAbsolute(const OutputBuffer * cb, unsigned relative)
{
unsigned i, max;
max = cb->end;
if (max < cb->begin)
max += buffered_chunks;
i = (unsigned)cb->begin + relative;
if (i >= max)
return -1;
if (i >= buffered_chunks)
i -= buffered_chunks;
return (int)i;
}
/** /**
* Return the tail chunk has room for additional data. If there is no * 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 * room in the queue, this function blocks until the player thread has
......
...@@ -58,6 +58,12 @@ void flushOutputBuffer(OutputBuffer * cb); ...@@ -58,6 +58,12 @@ void flushOutputBuffer(OutputBuffer * cb);
/** determine the number of decoded chunks */ /** determine the number of decoded chunks */
unsigned availableOutputBuffer(const OutputBuffer * cb); unsigned availableOutputBuffer(const OutputBuffer * cb);
/**
* Get the absolute index of the nth used chunk after the first one.
* Returns -1 if there is no such chunk.
*/
int outputBufferAbsolute(const OutputBuffer * cb, unsigned relative);
/* we send inStream for buffering the inputStream while waiting to /* we send inStream for buffering the inputStream while waiting to
send the next chunk */ send the next chunk */
int sendDataToOutputBuffer(OutputBuffer * cb, 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