mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 05:37:34 +02:00
Merge pull request #11602 from kencooke/audio-startup-fix
Fix loud screeching sound when certain users join a domain
This commit is contained in:
commit
c1ce84b060
2 changed files with 29 additions and 10 deletions
|
@ -46,6 +46,10 @@ static const int STATS_FOR_STATS_PACKET_WINDOW_SECONDS = 30;
|
||||||
// _currentJitterBufferFrames is updated with the time-weighted avg and the running time-weighted avg is reset.
|
// _currentJitterBufferFrames is updated with the time-weighted avg and the running time-weighted avg is reset.
|
||||||
static const quint64 FRAMES_AVAILABLE_STAT_WINDOW_USECS = 10 * USECS_PER_SECOND;
|
static const quint64 FRAMES_AVAILABLE_STAT_WINDOW_USECS = 10 * USECS_PER_SECOND;
|
||||||
|
|
||||||
|
// When the audio codec is switched, temporary codec mismatch is expected due to packets in-flight.
|
||||||
|
// A SelectedAudioFormat packet is not sent until this threshold is exceeded.
|
||||||
|
static const int MAX_MISMATCHED_AUDIO_CODEC_COUNT = 10;
|
||||||
|
|
||||||
InboundAudioStream::InboundAudioStream(int numChannels, int numFrames, int numBlocks, int numStaticJitterBlocks) :
|
InboundAudioStream::InboundAudioStream(int numChannels, int numFrames, int numBlocks, int numStaticJitterBlocks) :
|
||||||
_ringBuffer(numChannels * numFrames, numBlocks),
|
_ringBuffer(numChannels * numFrames, numBlocks),
|
||||||
_numChannels(numChannels),
|
_numChannels(numChannels),
|
||||||
|
@ -153,6 +157,7 @@ int InboundAudioStream::parseData(ReceivedMessage& message) {
|
||||||
// If we recieved a SilentAudioFrame from our sender, we might want to drop
|
// If we recieved a SilentAudioFrame from our sender, we might want to drop
|
||||||
// some of the samples in order to catch up to our desired jitter buffer size.
|
// some of the samples in order to catch up to our desired jitter buffer size.
|
||||||
writeDroppableSilentFrames(networkFrames);
|
writeDroppableSilentFrames(networkFrames);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// note: PCM and no codec are identical
|
// note: PCM and no codec are identical
|
||||||
bool selectedPCM = _selectedCodecName == "pcm" || _selectedCodecName == "";
|
bool selectedPCM = _selectedCodecName == "pcm" || _selectedCodecName == "";
|
||||||
|
@ -160,20 +165,33 @@ int InboundAudioStream::parseData(ReceivedMessage& message) {
|
||||||
if (codecInPacket == _selectedCodecName || (packetPCM && selectedPCM)) {
|
if (codecInPacket == _selectedCodecName || (packetPCM && selectedPCM)) {
|
||||||
auto afterProperties = message.readWithoutCopy(message.getBytesLeftToRead());
|
auto afterProperties = message.readWithoutCopy(message.getBytesLeftToRead());
|
||||||
parseAudioData(message.getType(), afterProperties);
|
parseAudioData(message.getType(), afterProperties);
|
||||||
|
_mismatchedAudioCodecCount = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug(audio) << "Codec mismatch: expected" << _selectedCodecName << "got" << codecInPacket << "writing silence";
|
_mismatchedAudioCodecCount++;
|
||||||
|
qDebug(audio) << "Codec mismatch: expected" << _selectedCodecName << "got" << codecInPacket;
|
||||||
|
|
||||||
// Since the data in the stream is using a codec that we aren't prepared for,
|
if (packetPCM) {
|
||||||
// we need to let the codec know that we don't have data for it, this will
|
// If there are PCM packets in-flight after the codec is changed, use them.
|
||||||
// allow the codec to interpolate missing data and produce a fade to silence.
|
auto afterProperties = message.readWithoutCopy(message.getBytesLeftToRead());
|
||||||
lostAudioData(1);
|
_ringBuffer.writeData(afterProperties.data(), afterProperties.size());
|
||||||
|
} else {
|
||||||
// inform others of the mismatch
|
// Since the data in the stream is using a codec that we aren't prepared for,
|
||||||
auto sendingNode = DependencyManager::get<NodeList>()->nodeWithUUID(message.getSourceID());
|
// we need to let the codec know that we don't have data for it, this will
|
||||||
if (sendingNode) {
|
// allow the codec to interpolate missing data and produce a fade to silence.
|
||||||
emit mismatchedAudioCodec(sendingNode, _selectedCodecName, codecInPacket);
|
lostAudioData(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_mismatchedAudioCodecCount > MAX_MISMATCHED_AUDIO_CODEC_COUNT) {
|
||||||
|
_mismatchedAudioCodecCount = 0;
|
||||||
|
|
||||||
|
// inform others of the mismatch
|
||||||
|
auto sendingNode = DependencyManager::get<NodeList>()->nodeWithUUID(message.getSourceID());
|
||||||
|
if (sendingNode) {
|
||||||
|
emit mismatchedAudioCodec(sendingNode, _selectedCodecName, codecInPacket);
|
||||||
|
qDebug(audio) << "Codec mismatch threshold exceeded, SelectedAudioFormat(" << _selectedCodecName << " ) sent";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -186,6 +186,7 @@ protected:
|
||||||
CodecPluginPointer _codec;
|
CodecPluginPointer _codec;
|
||||||
QString _selectedCodecName;
|
QString _selectedCodecName;
|
||||||
Decoder* _decoder { nullptr };
|
Decoder* _decoder { nullptr };
|
||||||
|
int _mismatchedAudioCodecCount { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
float calculateRepeatedFrameFadeFactor(int indexOfRepeat);
|
float calculateRepeatedFrameFadeFactor(int indexOfRepeat);
|
||||||
|
|
Loading…
Reference in a new issue