mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-15 17:46:47 +02:00
send extra stats from audio-mixer to domain-server
This commit is contained in:
parent
5f93e44ff7
commit
1fffda674a
2 changed files with 33 additions and 13 deletions
|
@ -67,7 +67,11 @@ void attachNewBufferToNode(Node *newNode) {
|
|||
AudioMixer::AudioMixer(const QByteArray& packet) :
|
||||
ThreadedAssignment(packet),
|
||||
_trailingSleepRatio(1.0f),
|
||||
_minAudibilityThreshold(LOUDNESS_TO_DISTANCE_RATIO / 2.0f)
|
||||
_minAudibilityThreshold(LOUDNESS_TO_DISTANCE_RATIO / 2.0f),
|
||||
_performanceThrottling(0.0f),
|
||||
_numStatFrames(0),
|
||||
_sumListeners(0),
|
||||
_sumMixes(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -95,6 +99,8 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
|
|||
return;
|
||||
}
|
||||
|
||||
++_sumMixes;
|
||||
|
||||
glm::quat inverseOrientation = glm::inverse(listeningNodeBuffer->getOrientation());
|
||||
|
||||
float distanceSquareToSource = glm::dot(relativePosition, relativePosition);
|
||||
|
@ -352,8 +358,15 @@ void AudioMixer::readPendingDatagrams() {
|
|||
|
||||
void AudioMixer::sendStatsPacket() {
|
||||
static QJsonObject statsObject;
|
||||
statsObject["trailing_sleep"] = _trailingSleepRatio;
|
||||
statsObject["min_audability_threshold"] = _minAudibilityThreshold;
|
||||
statsObject["trailing_sleep_time"] = _trailingSleepRatio;
|
||||
statsObject["performance_cutoff"] = _minAudibilityThreshold;
|
||||
|
||||
statsObject["average_listeners_per_frame"] = _sumListeners / (float) _numStatFrames;
|
||||
statsObject["average_mixes_per_listeners"] = _sumMixes / _sumListeners / _numStatFrames;
|
||||
|
||||
_sumListeners = 0;
|
||||
_sumMixes = 0;
|
||||
_numStatFrames = 0;
|
||||
|
||||
NodeList::getInstance()->sendStatsToDomainServer(statsObject);
|
||||
}
|
||||
|
@ -382,7 +395,6 @@ void AudioMixer::run() {
|
|||
+ numBytesForPacketHeaderGivenPacketType(PacketTypeMixedAudio)];
|
||||
|
||||
int usecToSleep = BUFFER_SEND_INTERVAL_USECS;
|
||||
float audabilityCutoffRatio = 0;
|
||||
|
||||
const int TRAILING_AVERAGE_FRAMES = 100;
|
||||
int framesSinceCutoffEvent = TRAILING_AVERAGE_FRAMES;
|
||||
|
@ -410,7 +422,7 @@ void AudioMixer::run() {
|
|||
_trailingSleepRatio = (PREVIOUS_FRAMES_RATIO * _trailingSleepRatio)
|
||||
+ (usecToSleep * CURRENT_FRAME_RATIO / (float) BUFFER_SEND_INTERVAL_USECS);
|
||||
|
||||
float lastCutoffRatio = audabilityCutoffRatio;
|
||||
float lastCutoffRatio = _performanceThrottling;
|
||||
bool hasRatioChanged = false;
|
||||
|
||||
if (framesSinceCutoffEvent >= TRAILING_AVERAGE_FRAMES) {
|
||||
|
@ -420,27 +432,27 @@ void AudioMixer::run() {
|
|||
|
||||
if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) {
|
||||
// we're struggling - change our min required loudness to reduce some load
|
||||
audabilityCutoffRatio = audabilityCutoffRatio + (0.5f * (1.0f - audabilityCutoffRatio));
|
||||
_performanceThrottling = _performanceThrottling + (0.5f * (1.0f - _performanceThrottling));
|
||||
|
||||
qDebug() << "Mixer is struggling, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
||||
<< lastCutoffRatio << "and is now" << audabilityCutoffRatio;
|
||||
<< lastCutoffRatio << "and is now" << _performanceThrottling;
|
||||
hasRatioChanged = true;
|
||||
} else if (_trailingSleepRatio >= BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD && audabilityCutoffRatio != 0) {
|
||||
} else if (_trailingSleepRatio >= BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD && _performanceThrottling != 0) {
|
||||
// we've recovered and can back off the required loudness
|
||||
audabilityCutoffRatio = audabilityCutoffRatio - RATIO_BACK_OFF;
|
||||
_performanceThrottling = _performanceThrottling - RATIO_BACK_OFF;
|
||||
|
||||
if (audabilityCutoffRatio < 0) {
|
||||
audabilityCutoffRatio = 0;
|
||||
if (_performanceThrottling < 0) {
|
||||
_performanceThrottling = 0;
|
||||
}
|
||||
|
||||
qDebug() << "Mixer is recovering, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
||||
<< lastCutoffRatio << "and is now" << audabilityCutoffRatio;
|
||||
<< lastCutoffRatio << "and is now" << _performanceThrottling;
|
||||
hasRatioChanged = true;
|
||||
}
|
||||
|
||||
if (hasRatioChanged) {
|
||||
// set out min audability threshold from the new ratio
|
||||
_minAudibilityThreshold = LOUDNESS_TO_DISTANCE_RATIO / (2.0f * (1.0f - audabilityCutoffRatio));
|
||||
_minAudibilityThreshold = LOUDNESS_TO_DISTANCE_RATIO / (2.0f * (1.0f - _performanceThrottling));
|
||||
qDebug() << "Minimum audability required to be mixed is now" << _minAudibilityThreshold;
|
||||
|
||||
framesSinceCutoffEvent = 0;
|
||||
|
@ -460,6 +472,8 @@ void AudioMixer::run() {
|
|||
|
||||
memcpy(clientMixBuffer + numBytesPacketHeader, _clientSamples, NETWORK_BUFFER_LENGTH_BYTES_STEREO);
|
||||
nodeList->writeDatagram(clientMixBuffer, NETWORK_BUFFER_LENGTH_BYTES_STEREO + numBytesPacketHeader, node);
|
||||
|
||||
++_sumListeners;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -470,6 +484,8 @@ void AudioMixer::run() {
|
|||
}
|
||||
}
|
||||
|
||||
++_numStatFrames;
|
||||
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
if (_isFinished) {
|
||||
|
|
|
@ -44,6 +44,10 @@ private:
|
|||
|
||||
float _trailingSleepRatio;
|
||||
float _minAudibilityThreshold;
|
||||
float _performanceThrottling;
|
||||
int _numStatFrames;
|
||||
int _sumListeners;
|
||||
int _sumMixes;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__AudioMixer__) */
|
||||
|
|
Loading…
Reference in a new issue