AudioTransportSource::hasStreamFinished() resets


#1

I'm trying to check an AudioTransportSource to see if it has stopped because it reached the end of the stream. hasStreamFinished() pretty much always returns false regardless. Looking at the code, it seems that the inputStreamEOF flag is only set to true for a very brief period and gets reset when getNextAudioBlock gets called again.

void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
{
    const ScopedLock sl (callbackLock);
    inputStreamEOF = false;   ----------> GETS RESET HERE ALMOST IMMEDIATELY AFTER SET TO TRUE (SEE BELOW)

    if (masterSource != nullptr && ! stopped)
    {
        masterSource->getNextAudioBlock (info);
        if (! playing)
        {
            // just stopped playing, so fade out the last block..
            for (int i = info.buffer->getNumChannels(); --i >= 0;)
                info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
            if (info.numSamples > 256)
                info.buffer->clear (info.startSample + 256, info.numSamples - 256);
        }
        if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
             && ! positionableSource->isLooping())
        {
            playing = false;
            inputStreamEOF = true;  ----------> GETS SET TRUE HERE, ONLY VALID FOR THE CHANGE MESSAGE
            sendChangeMessage();
        }
        stopped = ! playing;
        for (int i = info.buffer->getNumChannels(); --i >= 0;)
        {
            info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
                                        lastGain, gain);
        }
    }
    else
    {
        info.clearActiveBufferRegion();
        stopped = true;
    }
    lastGain = gain;
}

Is this the intended behaviour?


#2

Ah, good catch, thanks! I've tweaked this now - it should now keep reporting the correct value until it gets restarted.