only replicate packets for agents being replicated

This commit is contained in:
Stephen Birarda 2017-06-12 14:56:28 -07:00
parent 1868971cfc
commit 03a8d7b8c8
2 changed files with 45 additions and 34 deletions

View file

@ -81,7 +81,7 @@ void AudioMixerClientData::processPackets() {
QMutexLocker lock(&getMutex());
parseData(*packet);
replicatePacket(*packet);
optionallyReplicatePacket(*packet, *node);
break;
}
@ -109,9 +109,13 @@ void AudioMixerClientData::processPackets() {
assert(_packetQueue.empty());
}
void AudioMixerClientData::replicatePacket(ReceivedMessage& message) {
void AudioMixerClientData::optionallyReplicatePacket(ReceivedMessage& message, const Node& node) {
// first, make sure that this is a packet from a node we are supposed to replicate
if (node.isReplicated()) {
auto nodeList = DependencyManager::get<NodeList>();
// now make sure it's a packet type that we want to replicate
PacketType mirroredType;
if (message.getType() == PacketType::MicrophoneAudioNoEcho) {
@ -126,8 +130,16 @@ void AudioMixerClientData::replicatePacket(ReceivedMessage& message) {
return;
}
std::unique_ptr<NLPacket> packet;
// enumerate the replicant audio mixers and send them the replicated version of this packet
nodeList->eachMatchingNode([&](const SharedNodePointer& node)->bool {
return node->getType() == NodeType::DownstreamAudioMixer;
}, [&](const SharedNodePointer& node) {
// construct the packet only once, if we have any downstream audio mixers to send to
if (!packet) {
// construct an NLPacket to send to the replicant that has the contents of the received packet
auto packet = NLPacket::create(mirroredType);
packet = NLPacket::create(mirroredType);
// since this packet will be non-sourced, we add the replicated node's ID here
packet->write(message.getSourceID().toRfc4122());
@ -137,15 +149,14 @@ void AudioMixerClientData::replicatePacket(ReceivedMessage& message) {
packet->writeString(_selectedCodecName);
packet->write(message.getMessage());
}
// enumerate the replicant audio mixers and send them the replicated version of this packet
nodeList->eachMatchingNode([&](const SharedNodePointer& node)->bool {
return node->getType() == NodeType::DownstreamAudioMixer;
}, [&](const SharedNodePointer& node) {
nodeList->sendUnreliablePacket(*packet, node->getPublicSocket());
});
}
}
void AudioMixerClientData::negotiateAudioFormat(ReceivedMessage& message, const SharedNodePointer& node) {
quint8 numberOfCodecs;
message.readPrimitive(&numberOfCodecs);

View file

@ -126,7 +126,7 @@ private:
QReadWriteLock _streamsLock;
AudioStreamMap _audioStreams; // microphone stream from avatar is stored under key of null UUID
void replicatePacket(ReceivedMessage& packet);
void optionallyReplicatePacket(ReceivedMessage& packet, const Node& node);
using IgnoreZone = AABox;
class IgnoreZoneMemo {