mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 17:41:12 +02:00
tighten audio latency by clearing the network stack after starves
This commit is contained in:
parent
1c0b256f92
commit
14718980e5
1 changed files with 17 additions and 4 deletions
|
@ -136,7 +136,8 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
// if there is anything in the ring buffer, decide what to do:
|
// if there is anything in the ring buffer, decide what to do:
|
||||||
|
|
||||||
if (ringBuffer->getEndOfLastWrite()) {
|
if (ringBuffer->getEndOfLastWrite()) {
|
||||||
if (!ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() < (PACKET_LENGTH_SAMPLES + _jitterBufferSamples * (ringBuffer->isStereo() ? 2 : 1))) {
|
if (!ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() <
|
||||||
|
(PACKET_LENGTH_SAMPLES + _jitterBufferSamples * (ringBuffer->isStereo() ? 2 : 1))) {
|
||||||
//
|
//
|
||||||
// If not enough audio has arrived to start playback, keep waiting
|
// If not enough audio has arrived to start playback, keep waiting
|
||||||
//
|
//
|
||||||
|
@ -147,8 +148,7 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
PACKET_LENGTH_SAMPLES,
|
PACKET_LENGTH_SAMPLES,
|
||||||
_jitterBufferSamples);
|
_jitterBufferSamples);
|
||||||
#endif
|
#endif
|
||||||
} else if (ringBuffer->isStarted() && (ringBuffer->diffLastWriteNextOutput()
|
} else if (ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() == 0) {
|
||||||
< PACKET_LENGTH_SAMPLES * (ringBuffer->isStereo() ? 2 : 1))) {
|
|
||||||
//
|
//
|
||||||
// If we have started and now have run out of audio to send to the audio device,
|
// If we have started and now have run out of audio to send to the audio device,
|
||||||
// this means we've starved and should restart.
|
// this means we've starved and should restart.
|
||||||
|
@ -159,7 +159,7 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
_packetsReceivedThisPlayback = 0;
|
_packetsReceivedThisPlayback = 0;
|
||||||
_wasStarved = 10; // Frames for which to render the indication that the system was starved.
|
_wasStarved = 10; // Frames for which to render the indication that the system was starved.
|
||||||
#ifdef SHOW_AUDIO_DEBUG
|
#ifdef SHOW_AUDIO_DEBUG
|
||||||
printLog("Starved, remaining samples = %.0f\n",
|
printLog("Starved, remaining samples = %d\n",
|
||||||
ringBuffer->diffLastWriteNextOutput());
|
ringBuffer->diffLastWriteNextOutput());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -423,7 +423,20 @@ void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBy
|
||||||
gettimeofday(&_firstPacketReceivedTime, NULL);
|
gettimeofday(&_firstPacketReceivedTime, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_ringBuffer.diffLastWriteNextOutput() + PACKET_LENGTH_SAMPLES >
|
||||||
|
PACKET_LENGTH_SAMPLES + (ceilf((float) (_jitterBufferSamples * 2) / PACKET_LENGTH_SAMPLES) * PACKET_LENGTH_SAMPLES)) {
|
||||||
|
// this packet would give us more than the required amount for play out
|
||||||
|
// discard the first packet in the buffer
|
||||||
|
|
||||||
|
_ringBuffer.setNextOutput(_ringBuffer.getNextOutput() + PACKET_LENGTH_SAMPLES);
|
||||||
|
|
||||||
|
if (_ringBuffer.getNextOutput() == _ringBuffer.getBuffer() + RING_BUFFER_LENGTH_SAMPLES) {
|
||||||
|
_ringBuffer.setNextOutput(_ringBuffer.getBuffer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//printf("Got audio packet %d\n", _packetsReceivedThisPlayback);
|
//printf("Got audio packet %d\n", _packetsReceivedThisPlayback);
|
||||||
|
|
||||||
_ringBuffer.parseData((unsigned char*) receivedData, PACKET_LENGTH_BYTES + sizeof(PACKET_HEADER));
|
_ringBuffer.parseData((unsigned char*) receivedData, PACKET_LENGTH_BYTES + sizeof(PACKET_HEADER));
|
||||||
|
|
||||||
_lastReceiveTime = currentReceiveTime;
|
_lastReceiveTime = currentReceiveTime;
|
||||||
|
|
Loading…
Reference in a new issue