Fixed bugs and improved overflow handling in AudioRingBuffer; Added audio stream stats packets; Added seq numbers and tracking to audio packets;
Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 36 files). Show all
Unified · Split
| @@ -460,13 +460,17 @@ void ScriptEngine::run() { · 459 unmodified lines | ||
| 460 | 460 | _numAvatarSoundSentBytes = 0; |
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | − | |
| 463 | + | |
| 464 | 464 | QByteArray audioPacket = byteArrayWithPopulatedHeader(silentFrame |
| 465 | 465 | ? PacketTypeSilentAudioFrame |
| 466 | 466 | : PacketTypeMicrophoneAudioNoEcho); |
| 467 | 467 | |
| 468 | 468 | QDataStream packetStream(&audioPacket, QIODevice::Append); |
| 469 | 469 | |
| 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 | + | |
| 470 | 474 | // use the orientation and position of this avatar for the source of this audio |
| 471 | 475 | packetStream.writeRawData(reinterpret_cast<const char*>(&_avatarData->getPosition()), sizeof(glm::vec3)); |
| 472 | 476 | glm::quat headOrientation = _avatarData->getHeadOrientation(); |
| @@ -486,7 +490,19 @@ void ScriptEngine::run() { · 13 unmodified lines | ||
| 486 | 490 | numAvailableSamples * sizeof(int16_t)); |
| 487 | 491 | } |
| 488 | 492 | |
| 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 | + } | |
| 490 | 506 | } |
| 491 | 507 | } |
| 492 | 508 | |
| @@ -662,3 +678,7 @@ void ScriptEngine::include(const QString& includeFile) { · 169 unmodified lines | ||
| 662 | 678 | _engine.clearExceptions(); |
| 663 | 679 | } |
| 664 | 680 | } |
| 681 | + | |
| 682 | +void ScriptEngine::nodeKilled(SharedNodePointer node) { | |
| 683 | + _outgoingScriptAudioSequenceNumbers.remove(node->getUUID()); | |
| 684 | +} | |