mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-11 02:58:03 +02:00
Merge pull request #15619 from kencooke/audio-mac-callback-crashfix
BUGZ-158: Crash when switching audio devices on Mac
This commit is contained in:
commit
cc2e5af34d
2 changed files with 15 additions and 5 deletions
|
@ -2162,6 +2162,8 @@ qint64 AudioClient::AudioOutputIODevice::readData(char * data, qint64 maxSize) {
|
|||
}
|
||||
|
||||
bytesWritten = framesPopped * AudioConstants::SAMPLE_SIZE * deviceChannelCount;
|
||||
assert(bytesWritten <= maxSize);
|
||||
|
||||
} else {
|
||||
// nothing on network, don't grab anything from injectors, and just return 0s
|
||||
memset(data, 0, maxSize);
|
||||
|
@ -2174,7 +2176,6 @@ qint64 AudioClient::AudioOutputIODevice::readData(char * data, qint64 maxSize) {
|
|||
_audio->_audioFileWav.addRawAudioChunk(reinterpret_cast<char*>(scratchBuffer), bytesWritten);
|
||||
}
|
||||
|
||||
|
||||
int bytesAudioOutputUnplayed = _audio->_audioOutput->bufferSize() - _audio->_audioOutput->bytesFree();
|
||||
float msecsAudioOutputUnplayed = bytesAudioOutputUnplayed / (float)_audio->_outputFormat.bytesForDuration(USECS_PER_MSEC);
|
||||
_audio->_stats.updateOutputMsUnplayed(msecsAudioOutputUnplayed);
|
||||
|
|
|
@ -364,10 +364,19 @@ int InboundAudioStream::popSamples(int maxSamples, bool allOrNothing) {
|
|||
// buffer calculations.
|
||||
setToStarved();
|
||||
_consecutiveNotMixedCount++;
|
||||
//Kick PLC to generate a filler frame, reducing 'click'
|
||||
lostAudioData(allOrNothing ? (maxSamples - samplesAvailable) / _ringBuffer.getNumFrameSamples() : 1);
|
||||
samplesPopped = _ringBuffer.samplesAvailable();
|
||||
if (samplesPopped) {
|
||||
|
||||
// use PLC to generate extrapolated audio data, to reduce clicking
|
||||
if (allOrNothing) {
|
||||
int samplesNeeded = maxSamples - samplesAvailable;
|
||||
int packetsNeeded = (samplesNeeded + _ringBuffer.getNumFrameSamples() - 1) / _ringBuffer.getNumFrameSamples();
|
||||
lostAudioData(packetsNeeded);
|
||||
} else {
|
||||
lostAudioData(1);
|
||||
}
|
||||
samplesAvailable = _ringBuffer.samplesAvailable();
|
||||
|
||||
if (samplesAvailable > 0) {
|
||||
samplesPopped = std::min(samplesAvailable, maxSamples);
|
||||
popSamplesNoCheck(samplesPopped);
|
||||
} else {
|
||||
// No samples available means a packet is currently being
|
||||
|
|
Loading…
Reference in a new issue