Exemple #1
0
int InboundAudioStream::popFrames(int maxFrames, bool allOrNothing, bool starveIfNoFramesPopped) {
    int framesPopped = 0;
    int framesAvailable = _ringBuffer.framesAvailable();
    if (_isStarved) {
        // we're still refilling; don't pop
        _consecutiveNotMixedCount++;
        _lastPopSucceeded = false;
    } else {
        if (framesAvailable >= maxFrames) {
            // we have enough frames to pop, so we're good to pop
            popSamplesNoCheck(maxFrames * _ringBuffer.getNumFrameSamples());
            framesPopped = maxFrames;
        } else if (!allOrNothing && framesAvailable > 0) {
            // we don't have the requested number of frames, but we do have some
            // frames available, so pop all those (except in all-or-nothing mode)
            popSamplesNoCheck(framesAvailable * _ringBuffer.getNumFrameSamples());
            framesPopped = framesAvailable;
        } else {
            // we can't pop any frames. set this stream to starved if needed
            if (starveIfNoFramesPopped) {
                setToStarved();
                _consecutiveNotMixedCount = 1;
            }
            _lastPopSucceeded = false;
        }
    }
    return framesPopped;
}
Exemple #2
0
int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing) {
    int samplesPopped = 0;
    int samplesAvailable = _ringBuffer.samplesAvailable();
    if (_isStarved) {
        // we're still refilling; don't pop
        _consecutiveNotMixedCount++;
        _lastPopSucceeded = false;
    } else {
        if (samplesAvailable >= maxSamples) {
            // we have enough samples to pop, so we're good to pop
            popSamplesNoCheck(maxSamples);
            samplesPopped = maxSamples;
        } else if (!allOrNothing && samplesAvailable > 0) {
            // we don't have the requested number of samples, but we do have some
            // samples available, so pop all those (except in all-or-nothing mode)
            popSamplesNoCheck(samplesAvailable);
            samplesPopped = samplesAvailable;
        } else {
            // we can't pop any samples, set this stream to starved
            setToStarved();
            _consecutiveNotMixedCount++;
            _lastPopSucceeded = false;
        }
    }
    return samplesPopped;
}