History

Merge pull request #3094 from wangyix/seqNumberStats

Fixed bugs and improved overflow handling in AudioRingBuffer; Added audio stream stats packets; Added seq numbers and tracking to audio packets;

Brad Hefta-Gaub committed 12 years ago

Commit df51d262 parents a88c92e 99fd1c736 files · +1304 −343Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 36 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+22−2
@@ -460,13 +460,17 @@ void ScriptEngine::run() { · 459 unmodified lines
460460 _numAvatarSoundSentBytes = 0;
461461 }
462462 }
463−
463+
464464 QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame
465465 ? PacketTypeSilentAudioFrame
466466 : PacketTypeMicrophoneAudioNoEcho);
467467
468468 QDataStream packetStream(&audioPacket, QIODevice::Append);
469469
470+ // pack a placeholder value for sequence number for now, will be packed when destination node is known
471+ int numPreSequenceNumberBytes = audioPacket.size();
472+ packetStream << (quint16)0;
473+
470474 // use the orientation and position of this avatar for the source of this audio
471475 packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3));
472476 glm::quat headOrientation = _avatarData->getHeadOrientation();
@@ -486,7 +490,19 @@ void ScriptEngine::run() { · 13 unmodified lines
486490 numAvailableSamples * sizeof(int16_t));
487491 }
488492
489− nodeList->broadcastToNodes(audioPacket, NodeSet() << NodeType::AudioMixer);
493+ // write audio packet to AudioMixer nodes
494+ NodeList* nodeList = NodeList::getInstance();
495+ foreach(const SharedNodePointer& node, nodeList->getNodeHash()) {
496+ // only send to nodes of type AudioMixer
497+ if (node->getType() == NodeType::AudioMixer) {
498+ // pack sequence number
499+ quint16 sequence = _outgoingScriptAudioSequenceNumbers[node->getUUID()]++;
500+ memcpy(audioPacket.data() + numPreSequenceNumberBytes, &sequence, sizeof(quint16));
501+
502+ // send audio packet
503+ nodeList->writeDatagram(audioPacket, node);
504+ }
505+ }
490506 }
491507 }
492508
@@ -662,3 +678,7 @@ void ScriptEngine::include(const QString& includeFile) { · 169 unmodified lines
662678 _engine.clearExceptions();
663679 }
664680 }
681+
682+void ScriptEngine::nodeKilled(SharedNodePointer node) {
683+ _outgoingScriptAudioSequenceNumbers.remove(node->getUUID());
684+}