mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 07:43:57 +02:00
remove audio injectors that are starved and not added
This commit is contained in:
parent
fbb097accb
commit
00446076b5
6 changed files with 35 additions and 22 deletions
|
@ -59,7 +59,7 @@ int AudioMixerClientData::parseData(unsigned char* packetData, int numBytes) {
|
|||
for (int i = 0; i < _ringBuffers.size(); i++) {
|
||||
if (_ringBuffers[i]->getType() == PositionalAudioRingBuffer::Injector
|
||||
&& ((InjectedAudioRingBuffer*) _ringBuffers[i])->getStreamIdentifier() == streamIdentifier) {
|
||||
|
||||
matchingInjectedRingBuffer = (InjectedAudioRingBuffer*) _ringBuffers[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,10 +87,10 @@ void AudioMixerClientData::checkBuffersBeforeFrameSend(int jitterBufferLengthSam
|
|||
|
||||
void AudioMixerClientData::pushBuffersAfterFrameSend() {
|
||||
for (int i = 0; i < _ringBuffers.size(); i++) {
|
||||
if (_ringBuffers[i]->willBeAddedToMix()) {
|
||||
// this was a used buffer, push the output pointer forwards
|
||||
PositionalAudioRingBuffer* audioBuffer = _ringBuffers[i];
|
||||
|
||||
// this was a used buffer, push the output pointer forwards
|
||||
PositionalAudioRingBuffer* audioBuffer = _ringBuffers[i];
|
||||
|
||||
if (audioBuffer->willBeAddedToMix()) {
|
||||
audioBuffer->setNextOutput(audioBuffer->getNextOutput() + BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||
|
||||
if (audioBuffer->getNextOutput() >= audioBuffer->getBuffer() + RING_BUFFER_LENGTH_SAMPLES) {
|
||||
|
@ -98,6 +98,9 @@ void AudioMixerClientData::pushBuffersAfterFrameSend() {
|
|||
}
|
||||
|
||||
audioBuffer->setWillBeAddedToMix(false);
|
||||
} else if (audioBuffer->hasStarted() && audioBuffer->isStarved()) {
|
||||
delete audioBuffer;
|
||||
_ringBuffers.erase(_ringBuffers.begin() + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ 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 (ringBuffer->getEndOfLastWrite()) {
|
||||
if (!ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() <
|
||||
if (ringBuffer->isStarved() && ringBuffer->diffLastWriteNextOutput() <
|
||||
(PACKET_LENGTH_SAMPLES + _jitterBufferSamples * (ringBuffer->isStereo() ? 2 : 1))) {
|
||||
//
|
||||
// If not enough audio has arrived to start playback, keep waiting
|
||||
|
@ -172,12 +172,12 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
PACKET_LENGTH_SAMPLES,
|
||||
_jitterBufferSamples);
|
||||
#endif
|
||||
} else if (ringBuffer->isStarted() && ringBuffer->diffLastWriteNextOutput() == 0) {
|
||||
} else if (!ringBuffer->isStarved() && ringBuffer->diffLastWriteNextOutput() == 0) {
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
ringBuffer->setStarted(false);
|
||||
ringBuffer->setIsStarved(true);
|
||||
|
||||
_numStarves++;
|
||||
_packetsReceivedThisPlayback = 0;
|
||||
|
@ -191,8 +191,9 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
|||
//
|
||||
// We are either already playing back, or we have enough audio to start playing back.
|
||||
//
|
||||
if (!ringBuffer->isStarted()) {
|
||||
ringBuffer->setStarted(true);
|
||||
if (ringBuffer->isStarved()) {
|
||||
ringBuffer->setIsStarved(false);
|
||||
ringBuffer->setHasStarted(true);
|
||||
#ifdef SHOW_AUDIO_DEBUG
|
||||
qDebug("starting playback %0.1f msecs delayed, jitter = %d, pkts recvd: %d \n",
|
||||
(usecTimestampNow() - usecTimestamp(&_firstPacketReceivedTime))/1000.0,
|
||||
|
@ -459,7 +460,7 @@ void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBy
|
|||
}
|
||||
}
|
||||
|
||||
if (!_ringBuffer.isStarted()) {
|
||||
if (_ringBuffer.isStarved()) {
|
||||
_packetsReceivedThisPlayback++;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
AudioRingBuffer::AudioRingBuffer(bool isStereo) :
|
||||
NodeData(NULL),
|
||||
_endOfLastWrite(NULL),
|
||||
_isStarted(false),
|
||||
_isStarved(true),
|
||||
_hasStarted(false),
|
||||
_isStereo(isStereo)
|
||||
{
|
||||
_buffer = new int16_t[RING_BUFFER_LENGTH_SAMPLES];
|
||||
|
@ -30,7 +31,8 @@ AudioRingBuffer::~AudioRingBuffer() {
|
|||
void AudioRingBuffer::reset() {
|
||||
_endOfLastWrite = _buffer;
|
||||
_nextOutput = _buffer;
|
||||
_isStarted = false;
|
||||
_isStarved = true;
|
||||
_hasStarted = false;
|
||||
}
|
||||
|
||||
int AudioRingBuffer::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||
|
@ -50,7 +52,7 @@ int AudioRingBuffer::parseAudioSamples(unsigned char* sourceBuffer, int numBytes
|
|||
} else if (diffLastWriteNextOutput() > RING_BUFFER_LENGTH_SAMPLES - samplesToCopy) {
|
||||
_endOfLastWrite = _buffer;
|
||||
_nextOutput = _buffer;
|
||||
_isStarted = false;
|
||||
_isStarved = true;
|
||||
}
|
||||
|
||||
memcpy(_endOfLastWrite, sourceBuffer, numBytes);
|
||||
|
|
|
@ -43,8 +43,11 @@ public:
|
|||
|
||||
int16_t* getBuffer() const { return _buffer; }
|
||||
|
||||
bool isStarted() const { return _isStarted; }
|
||||
void setStarted(bool isStarted) { _isStarted = isStarted; }
|
||||
bool isStarved() const { return _isStarved; }
|
||||
void setIsStarved(bool isStarved) { _isStarved = isStarved; }
|
||||
|
||||
bool hasStarted() const { return _hasStarted; }
|
||||
void setHasStarted(bool hasStarted) { _hasStarted = hasStarted; }
|
||||
|
||||
int diffLastWriteNextOutput() const;
|
||||
|
||||
|
@ -58,7 +61,8 @@ protected:
|
|||
int16_t* _nextOutput;
|
||||
int16_t* _endOfLastWrite;
|
||||
int16_t* _buffer;
|
||||
bool _isStarted;
|
||||
bool _isStarved;
|
||||
bool _hasStarted;
|
||||
bool _isStereo;
|
||||
};
|
||||
|
||||
|
|
|
@ -8,13 +8,15 @@
|
|||
|
||||
#include <cstring>
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
#include <PacketHeaders.h>
|
||||
#include <UUID.h>
|
||||
|
||||
#include "InjectedAudioRingBuffer.h"
|
||||
|
||||
InjectedAudioRingBuffer::InjectedAudioRingBuffer(const QUuid& streamIdentifier) :
|
||||
PositionalAudioRingBuffer(PositionalAudioRingBuffer::Microphone),
|
||||
PositionalAudioRingBuffer(PositionalAudioRingBuffer::Injector),
|
||||
_streamIdentifier(streamIdentifier),
|
||||
_radius(0.0f),
|
||||
_attenuationRatio(0)
|
||||
|
|
|
@ -48,7 +48,7 @@ int PositionalAudioRingBuffer::parsePositionalData(unsigned char* sourceBuffer,
|
|||
// if this node sent us a NaN for first float in orientation then don't consider this good audio and bail
|
||||
if (std::isnan(_orientation.x)) {
|
||||
_endOfLastWrite = _nextOutput = _buffer;
|
||||
_isStarted = false;
|
||||
_isStarved = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -57,16 +57,17 @@ int PositionalAudioRingBuffer::parsePositionalData(unsigned char* sourceBuffer,
|
|||
|
||||
bool PositionalAudioRingBuffer::shouldBeAddedToMix(int numJitterBufferSamples) {
|
||||
if (_endOfLastWrite) {
|
||||
if (!_isStarted && diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + numJitterBufferSamples) {
|
||||
if (_isStarved && diffLastWriteNextOutput() <= BUFFER_LENGTH_SAMPLES_PER_CHANNEL + numJitterBufferSamples) {
|
||||
printf("Buffer held back\n");
|
||||
return false;
|
||||
} else if (diffLastWriteNextOutput() < BUFFER_LENGTH_SAMPLES_PER_CHANNEL) {
|
||||
printf("Buffer starved.\n");
|
||||
_isStarted = false;
|
||||
_isStarved = true;
|
||||
return false;
|
||||
} else {
|
||||
// good buffer, add this to the mix
|
||||
_isStarted = true;
|
||||
_isStarved = false;
|
||||
_hasStarted = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue