decode: fix unsigned comparision and add some paranoid assertions
git-svn-id: https://svn.musicpd.org/mpd/trunk@7301 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
f275a1a1ab
commit
e566c4c64c
17
src/decode.c
17
src/decode.c
@ -79,24 +79,25 @@ static void quitDecode(PlayerControl * pc, DecoderControl * dc)
|
|||||||
static unsigned calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af,
|
static unsigned calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af,
|
||||||
float totalTime)
|
float totalTime)
|
||||||
{
|
{
|
||||||
long chunks;
|
unsigned chunks;
|
||||||
|
|
||||||
if (pc->crossFade <= 0 || pc->crossFade >= totalTime ||
|
if (pc->crossFade == 0 || pc->crossFade >= totalTime ||
|
||||||
!isCurrentAudioFormat(af))
|
!isCurrentAudioFormat(af))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
assert(pc->crossFade > 0);
|
||||||
|
assert(af->bits > 0);
|
||||||
|
assert(af->channels > 0);
|
||||||
|
assert(af->sampleRate > 0);
|
||||||
|
|
||||||
chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE);
|
chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE);
|
||||||
chunks = (chunks * pc->crossFade + 0.5);
|
chunks = (chunks * pc->crossFade + 0.5);
|
||||||
|
|
||||||
assert(buffered_chunks >= buffered_before_play);
|
assert(buffered_chunks >= buffered_before_play);
|
||||||
if (chunks > (buffered_chunks - buffered_before_play)) {
|
if (chunks > (buffered_chunks - buffered_before_play))
|
||||||
chunks = buffered_chunks - buffered_before_play;
|
chunks = buffered_chunks - buffered_before_play;
|
||||||
}
|
|
||||||
|
|
||||||
if (chunks < 0)
|
return chunks;
|
||||||
chunks = 0;
|
|
||||||
|
|
||||||
return (unsigned)chunks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int waitOnDecode(PlayerControl * pc, DecoderControl * dc,
|
static int waitOnDecode(PlayerControl * pc, DecoderControl * dc,
|
||||||
|
Loading…
Reference in New Issue
Block a user