mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-06 20:13:10 +02:00
prevent overflow of local injectors buffer
This commit is contained in:
parent
e882e7b648
commit
cdf6c332a6
1 changed files with 16 additions and 16 deletions
|
@ -1097,6 +1097,12 @@ void AudioClient::handleRecordedAudioInput(const QByteArray& audio) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::prepareLocalAudioInjectors() {
|
void AudioClient::prepareLocalAudioInjectors() {
|
||||||
|
int samplesNeeded = std::numeric_limits<int>::max();
|
||||||
|
while (samplesNeeded > 0) {
|
||||||
|
// unlock between every write to allow device switching
|
||||||
|
Lock lock(_localAudioMutex);
|
||||||
|
|
||||||
|
// in case of a device switch, consider bufferCapacity volatile across iterations
|
||||||
if (_outputPeriod == 0) {
|
if (_outputPeriod == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1111,12 +1117,6 @@ void AudioClient::prepareLocalAudioInjectors() {
|
||||||
bufferCapacity += 1;
|
bufferCapacity += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int samplesNeeded = std::numeric_limits<int>::max();
|
|
||||||
while (samplesNeeded > 0) {
|
|
||||||
// lock for every write to avoid locking out the device callback
|
|
||||||
// this lock is intentional - the buffer is only lock-free in its use in the device callback
|
|
||||||
Lock lock(_localAudioMutex);
|
|
||||||
|
|
||||||
samplesNeeded = bufferCapacity - _localSamplesAvailable.load(std::memory_order_relaxed);
|
samplesNeeded = bufferCapacity - _localSamplesAvailable.load(std::memory_order_relaxed);
|
||||||
if (samplesNeeded <= 0) {
|
if (samplesNeeded <= 0) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue