migrate node hash calls from AudioMixer to new tbb format

This commit is contained in:
Stephen Birarda 2014-11-06 13:53:10 -08:00
parent 38f2b2ac6a
commit 1a953b5906
2 changed files with 22 additions and 42 deletions

View file

@ -438,16 +438,12 @@ int AudioMixer::prepareMixForListeningNode(Node* node) {
// loop through all other nodes that have sufficient audio to mix // loop through all other nodes that have sufficient audio to mix
int streamsMixed = 0; int streamsMixed = 0;
NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); NodeList::getInstance()->eachNode([&](const SharedNodePointer& otherNode){
for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
SharedNodePointer otherNode = it->second;
if (otherNode->getLinkedData()) { if (otherNode->getLinkedData()) {
AudioMixerClientData* otherNodeClientData = (AudioMixerClientData*) otherNode->getLinkedData(); AudioMixerClientData* otherNodeClientData = (AudioMixerClientData*) otherNode->getLinkedData();
// enumerate the ARBs attached to the otherNode and add all that should be added to mix // enumerate the ARBs attached to the otherNode and add all that should be added to mix
const QHash<QUuid, PositionalAudioStream*>& otherNodeAudioStreams = otherNodeClientData->getAudioStreams(); const QHash<QUuid, PositionalAudioStream*>& otherNodeAudioStreams = otherNodeClientData->getAudioStreams();
QHash<QUuid, PositionalAudioStream*>::ConstIterator i; QHash<QUuid, PositionalAudioStream*>::ConstIterator i;
for (i = otherNodeAudioStreams.constBegin(); i != otherNodeAudioStreams.constEnd(); i++) { for (i = otherNodeAudioStreams.constBegin(); i != otherNodeAudioStreams.constEnd(); i++) {
@ -457,14 +453,15 @@ int AudioMixer::prepareMixForListeningNode(Node* node) {
if (otherNodeStream->getType() == PositionalAudioStream::Microphone) { if (otherNodeStream->getType() == PositionalAudioStream::Microphone) {
streamUUID = otherNode->getUUID(); streamUUID = otherNode->getUUID();
} }
if (*otherNode != *node || otherNodeStream->shouldLoopbackForNode()) { if (*otherNode != *node || otherNodeStream->shouldLoopbackForNode()) {
streamsMixed += addStreamToMixForListeningNodeWithStream(listenerNodeData, streamUUID, streamsMixed += addStreamToMixForListeningNodeWithStream(listenerNodeData, streamUUID,
otherNodeStream, nodeAudioStream); otherNodeStream, nodeAudioStream);
} }
} }
} }
} });
return streamsMixed; return streamsMixed;
} }
@ -485,16 +482,11 @@ void AudioMixer::readPendingDatagram(const QByteArray& receivedPacket, const Hif
QByteArray packet = receivedPacket; QByteArray packet = receivedPacket;
populatePacketHeader(packet, PacketTypeMuteEnvironment); populatePacketHeader(packet, PacketTypeMuteEnvironment);
NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); nodeList->eachNode([&](const SharedNodePointer& node){
for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
SharedNodePointer node = it->second;
if (node->getType() == NodeType::Agent && node->getActiveSocket() && node->getLinkedData() && node != nodeList->sendingNodeForPacket(receivedPacket)) { if (node->getType() == NodeType::Agent && node->getActiveSocket() && node->getLinkedData() && node != nodeList->sendingNodeForPacket(receivedPacket)) {
nodeList->writeDatagram(packet, packet.size(), node); nodeList->writeDatagram(packet, packet.size(), node);
} }
} });
} else { } else {
// let processNodeData handle it. // let processNodeData handle it.
nodeList->processNodeData(senderSockAddr, receivedPacket); nodeList->processNodeData(senderSockAddr, receivedPacket);
@ -558,9 +550,8 @@ void AudioMixer::sendStatsPacket() {
NodeList* nodeList = NodeList::getInstance(); NodeList* nodeList = NodeList::getInstance();
int clientNumber = 0; int clientNumber = 0;
NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table();
for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) { nodeList->eachNode([&](const SharedNodePointer& node) {
// if we're too large, send the packet // if we're too large, send the packet
if (sizeOfStats > TOO_BIG_FOR_MTU) { if (sizeOfStats > TOO_BIG_FOR_MTU) {
nodeList->sendStatsToDomainServer(statsObject2); nodeList->sendStatsToDomainServer(statsObject2);
@ -570,15 +561,15 @@ void AudioMixer::sendStatsPacket() {
} }
clientNumber++; clientNumber++;
AudioMixerClientData* clientData = static_cast<AudioMixerClientData*>(it->second->getLinkedData()); AudioMixerClientData* clientData = static_cast<AudioMixerClientData*>(node->getLinkedData());
if (clientData) { if (clientData) {
QString property = "jitterStats." + it->first.toString(); QString property = "jitterStats." + node->getUUID().toString();
QString value = clientData->getAudioStreamStatsString(); QString value = clientData->getAudioStreamStatsString();
statsObject2[qPrintable(property)] = value; statsObject2[qPrintable(property)] = value;
somethingToSend = true; somethingToSend = true;
sizeOfStats += property.size() + value.size(); sizeOfStats += property.size() + value.size();
} }
} });
if (somethingToSend) { if (somethingToSend) {
nodeList->sendStatsToDomainServer(statsObject2); nodeList->sendStatsToDomainServer(statsObject2);
@ -717,10 +708,7 @@ void AudioMixer::run() {
_lastPerSecondCallbackTime = now; _lastPerSecondCallbackTime = now;
} }
NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); nodeList->eachNode([&](const SharedNodePointer& node) {
for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
SharedNodePointer node = it->second;
if (node->getLinkedData()) { if (node->getLinkedData()) {
AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData(); AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData();
@ -830,7 +818,7 @@ void AudioMixer::run() {
++_sumListeners; ++_sumListeners;
} }
} }
} });
++_numStatFrames; ++_numStatFrames;
@ -888,11 +876,7 @@ void AudioMixer::perSecondActions() {
_timeSpentPerHashMatchCallStats.getWindowSum() / WINDOW_LENGTH_USECS * 100.0, _timeSpentPerHashMatchCallStats.getWindowSum() / WINDOW_LENGTH_USECS * 100.0,
_timeSpentPerHashMatchCallStats.getCurrentIntervalSum() / USECS_PER_SECOND * 100.0); _timeSpentPerHashMatchCallStats.getCurrentIntervalSum() / USECS_PER_SECOND * 100.0);
NodeHashSnapshot snapshotHash = NodeList::getInstance()->getNodeHash().snapshot_table(); NodeList::getInstance()->eachNode([](const SharedNodePointer& node) {
for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
SharedNodePointer node = it->second;
if (node->getLinkedData()) { if (node->getLinkedData()) {
AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData(); AudioMixerClientData* nodeData = (AudioMixerClientData*)node->getLinkedData();
@ -902,7 +886,7 @@ void AudioMixer::perSecondActions() {
nodeData->printUpstreamDownstreamStats(); nodeData->printUpstreamDownstreamStats();
} }
} }
} });
} }
_datagramsReadPerCallStats.currentIntervalComplete(); _datagramsReadPerCallStats.currentIntervalComplete();

View file

@ -122,9 +122,7 @@ void AvatarMixer::broadcastAvatarData() {
AvatarMixerClientData* nodeData = NULL; AvatarMixerClientData* nodeData = NULL;
AvatarMixerClientData* otherNodeData = NULL; AvatarMixerClientData* otherNodeData = NULL;
NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); nodeList->eachNode([&](const SharedNodePointer& node) {
for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
SharedNodePointer node = it->second;
if (node->getLinkedData() && node->getType() == NodeType::Agent && node->getActiveSocket() if (node->getLinkedData() && node->getType() == NodeType::Agent && node->getActiveSocket()
&& (nodeData = reinterpret_cast<AvatarMixerClientData*>(node->getLinkedData()))->getMutex().tryLock()) { && (nodeData = reinterpret_cast<AvatarMixerClientData*>(node->getLinkedData()))->getMutex().tryLock()) {
++_sumListeners; ++_sumListeners;
@ -137,9 +135,7 @@ void AvatarMixer::broadcastAvatarData() {
// this is an AGENT we have received head data from // this is an AGENT we have received head data from
// send back a packet with other active node data to this node // send back a packet with other active node data to this node
NodeHashSnapshot snapshotHash = nodeList->getNodeHash().snapshot_table(); nodeList->eachNode([&](const SharedNodePointer& otherNode) {
for (auto it = snapshotHash.begin(); it != snapshotHash.end(); it++) {
SharedNodePointer otherNode = it->second;
if (otherNode->getLinkedData() && otherNode->getUUID() != node->getUUID() if (otherNode->getLinkedData() && otherNode->getUUID() != node->getUUID()
&& (otherNodeData = reinterpret_cast<AvatarMixerClientData*>(otherNode->getLinkedData()))->getMutex().tryLock()) { && (otherNodeData = reinterpret_cast<AvatarMixerClientData*>(otherNode->getLinkedData()))->getMutex().tryLock()) {
@ -207,13 +203,13 @@ void AvatarMixer::broadcastAvatarData() {
otherNodeData->getMutex().unlock(); otherNodeData->getMutex().unlock();
} }
} });
nodeList->writeDatagram(mixedAvatarByteArray, node); nodeList->writeDatagram(mixedAvatarByteArray, node);
nodeData->getMutex().unlock(); nodeData->getMutex().unlock();
} }
} });
_lastFrameTimestamp = QDateTime::currentMSecsSinceEpoch(); _lastFrameTimestamp = QDateTime::currentMSecsSinceEpoch();
} }