send extra stats from audio-mixer to domain-server

This commit is contained in:
Stephen Birarda 2014-03-24 13:14:19 -07:00
parent 5f93e44ff7
commit 1fffda674a
2 changed files with 33 additions and 13 deletions

View file

@ -67,7 +67,11 @@ void attachNewBufferToNode(Node *newNode) {
AudioMixer::AudioMixer(const QByteArray& packet) : AudioMixer::AudioMixer(const QByteArray& packet) :
ThreadedAssignment(packet), ThreadedAssignment(packet),
_trailingSleepRatio(1.0f), _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; return;
} }
++_sumMixes;
glm::quat inverseOrientation = glm::inverse(listeningNodeBuffer->getOrientation()); glm::quat inverseOrientation = glm::inverse(listeningNodeBuffer->getOrientation());
float distanceSquareToSource = glm::dot(relativePosition, relativePosition); float distanceSquareToSource = glm::dot(relativePosition, relativePosition);
@ -352,8 +358,15 @@ void AudioMixer::readPendingDatagrams() {
void AudioMixer::sendStatsPacket() { void AudioMixer::sendStatsPacket() {
static QJsonObject statsObject; static QJsonObject statsObject;
statsObject["trailing_sleep"] = _trailingSleepRatio; statsObject["trailing_sleep_time"] = _trailingSleepRatio;
statsObject["min_audability_threshold"] = _minAudibilityThreshold; 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); NodeList::getInstance()->sendStatsToDomainServer(statsObject);
} }
@ -382,7 +395,6 @@ void AudioMixer::run() {
+ numBytesForPacketHeaderGivenPacketType(PacketTypeMixedAudio)]; + numBytesForPacketHeaderGivenPacketType(PacketTypeMixedAudio)];
int usecToSleep = BUFFER_SEND_INTERVAL_USECS; int usecToSleep = BUFFER_SEND_INTERVAL_USECS;
float audabilityCutoffRatio = 0;
const int TRAILING_AVERAGE_FRAMES = 100; const int TRAILING_AVERAGE_FRAMES = 100;
int framesSinceCutoffEvent = TRAILING_AVERAGE_FRAMES; int framesSinceCutoffEvent = TRAILING_AVERAGE_FRAMES;
@ -410,7 +422,7 @@ void AudioMixer::run() {
_trailingSleepRatio = (PREVIOUS_FRAMES_RATIO * _trailingSleepRatio) _trailingSleepRatio = (PREVIOUS_FRAMES_RATIO * _trailingSleepRatio)
+ (usecToSleep * CURRENT_FRAME_RATIO / (float) BUFFER_SEND_INTERVAL_USECS); + (usecToSleep * CURRENT_FRAME_RATIO / (float) BUFFER_SEND_INTERVAL_USECS);
float lastCutoffRatio = audabilityCutoffRatio; float lastCutoffRatio = _performanceThrottling;
bool hasRatioChanged = false; bool hasRatioChanged = false;
if (framesSinceCutoffEvent >= TRAILING_AVERAGE_FRAMES) { if (framesSinceCutoffEvent >= TRAILING_AVERAGE_FRAMES) {
@ -420,27 +432,27 @@ void AudioMixer::run() {
if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) { if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) {
// we're struggling - change our min required loudness to reduce some load // 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" 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; 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 // we've recovered and can back off the required loudness
audabilityCutoffRatio = audabilityCutoffRatio - RATIO_BACK_OFF; _performanceThrottling = _performanceThrottling - RATIO_BACK_OFF;
if (audabilityCutoffRatio < 0) { if (_performanceThrottling < 0) {
audabilityCutoffRatio = 0; _performanceThrottling = 0;
} }
qDebug() << "Mixer is recovering, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was" 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; hasRatioChanged = true;
} }
if (hasRatioChanged) { if (hasRatioChanged) {
// set out min audability threshold from the new ratio // 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; qDebug() << "Minimum audability required to be mixed is now" << _minAudibilityThreshold;
framesSinceCutoffEvent = 0; framesSinceCutoffEvent = 0;
@ -460,6 +472,8 @@ void AudioMixer::run() {
memcpy(clientMixBuffer + numBytesPacketHeader, _clientSamples, NETWORK_BUFFER_LENGTH_BYTES_STEREO); memcpy(clientMixBuffer + numBytesPacketHeader, _clientSamples, NETWORK_BUFFER_LENGTH_BYTES_STEREO);
nodeList->writeDatagram(clientMixBuffer, NETWORK_BUFFER_LENGTH_BYTES_STEREO + numBytesPacketHeader, node); nodeList->writeDatagram(clientMixBuffer, NETWORK_BUFFER_LENGTH_BYTES_STEREO + numBytesPacketHeader, node);
++_sumListeners;
} }
} }
@ -470,6 +484,8 @@ void AudioMixer::run() {
} }
} }
++_numStatFrames;
QCoreApplication::processEvents(); QCoreApplication::processEvents();
if (_isFinished) { if (_isFinished) {

View file

@ -44,6 +44,10 @@ private:
float _trailingSleepRatio; float _trailingSleepRatio;
float _minAudibilityThreshold; float _minAudibilityThreshold;
float _performanceThrottling;
int _numStatFrames;
int _sumListeners;
int _sumMixes;
}; };
#endif /* defined(__hifi__AudioMixer__) */ #endif /* defined(__hifi__AudioMixer__) */