Merge pull request #10740 from birarda/feat/replicants

some cleanup for audio/avatar replicated packet checking
This commit is contained in:
Stephen Birarda 2017-06-19 15:13:28 -07:00 committed by GitHub
commit b3824c6a25
6 changed files with 39 additions and 34 deletions

View file

@ -132,18 +132,10 @@ void AudioMixer::queueReplicatedAudioPacket(QSharedPointer<ReceivedMessage> mess
// construct a "fake" audio received message from the byte array and packet list information
auto audioData = message->getMessage().mid(NUM_BYTES_RFC4122_UUID);
PacketType rewrittenType;
PacketType rewrittenType = REPLICATED_PACKET_MAPPING.key(message->getType());
if (message->getType() == PacketType::ReplicatedMicrophoneAudioNoEcho) {
rewrittenType = PacketType::MicrophoneAudioNoEcho;
} else if (message->getType() == PacketType::ReplicatedMicrophoneAudioWithEcho) {
rewrittenType = PacketType::MicrophoneAudioWithEcho;
} else if (message->getType() == PacketType::ReplicatedInjectAudio) {
rewrittenType = PacketType::InjectAudio;
} else if (message->getType() == PacketType::ReplicatedSilentAudioFrame) {
rewrittenType = PacketType::SilentAudioFrame;
} else {
return;
if (rewrittenType == PacketType::Unknown) {
qDebug() << "Cannot unwrap replicated packet type not present in REPLICATED_PACKET_WRAPPING";
}
auto replicatedMessage = QSharedPointer<ReceivedMessage>::create(audioData, rewrittenType,

View file

@ -124,27 +124,18 @@ void AudioMixerClientData::optionallyReplicatePacket(ReceivedMessage& message, c
auto nodeList = DependencyManager::get<NodeList>();
// now make sure it's a packet type that we want to replicate
PacketType mirroredType;
switch (message.getType()) {
case PacketType::MicrophoneAudioNoEcho:
case PacketType::ReplicatedMicrophoneAudioNoEcho:
mirroredType = PacketType::ReplicatedMicrophoneAudioNoEcho;
break;
case PacketType::MicrophoneAudioWithEcho:
case PacketType::ReplicatedMicrophoneAudioWithEcho:
mirroredType = PacketType::ReplicatedMicrophoneAudioWithEcho;
break;
case PacketType::InjectAudio:
case PacketType::ReplicatedInjectAudio:
mirroredType = PacketType::ReplicatedInjectAudio;
break;
case PacketType::SilentAudioFrame:
case PacketType::ReplicatedSilentAudioFrame:
mirroredType = PacketType::ReplicatedSilentAudioFrame;
break;
default:
// first check if it is an original type that we should replicate
PacketType mirroredType = REPLICATED_PACKET_MAPPING.value(message.getType());
if (mirroredType == PacketType::Unknown) {
// if it wasn't check if it is a replicated type that we should re-replicate
if (REPLICATED_PACKET_MAPPING.key(message.getType()) != PacketType::Unknown) {
mirroredType = message.getType();
} else {
qDebug() << "Packet passed to optionallyReplicatePacket was not a replicatable type - returning";
return;
}
}
std::unique_ptr<NLPacket> packet;

View file

@ -26,7 +26,6 @@
#include "PositionalAudioStream.h"
#include "AvatarAudioStream.h"
class AudioMixerClientData : public NodeData {
Q_OBJECT
public:

View file

@ -127,9 +127,21 @@ void AvatarMixer::handleReplicatedBulkAvatarPacket(QSharedPointer<ReceivedMessag
void AvatarMixer::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()
&& (message.getType() == PacketType::KillAvatar || message.getType() == PacketType::ReplicatedKillAvatar)) {
PacketType replicatedType = PacketType::ReplicatedKillAvatar;
if (node.isReplicated()) {
// check if this is a packet type we replicate
// which means it must be a packet type present in REPLICATED_PACKET_MAPPING or must be the
// replicated version of one of those packet types
PacketType replicatedType = REPLICATED_PACKET_MAPPING.value(message.getType());
if (replicatedType == PacketType::Unknown) {
if (REPLICATED_PACKET_MAPPING.key(message.getType()) != PacketType::Unknown) {
replicatedType = message.getType();
} else {
qDebug() << __FUNCTION__ << "called without replicatable packet type - returning";
return;
}
}
std::unique_ptr<NLPacket> packet;

View file

@ -44,6 +44,15 @@ const QSet<PacketType> NON_SOURCED_PACKETS = QSet<PacketType>()
<< PacketType::ReplicatedInjectAudio << PacketType::ReplicatedSilentAudioFrame
<< PacketType::ReplicatedAvatarIdentity << PacketType::ReplicatedKillAvatar << PacketType::ReplicatedBulkAvatarData;
const QHash<PacketType, PacketType> REPLICATED_PACKET_MAPPING {
{ PacketType::MicrophoneAudioNoEcho, PacketType::ReplicatedMicrophoneAudioNoEcho },
{ PacketType::MicrophoneAudioWithEcho, PacketType::ReplicatedMicrophoneAudioWithEcho },
{ PacketType::InjectAudio, PacketType::ReplicatedInjectAudio },
{ PacketType::SilentAudioFrame, PacketType::ReplicatedSilentAudioFrame },
{ PacketType::AvatarIdentity, PacketType::ReplicatedAvatarIdentity },
{ PacketType::KillAvatar, PacketType::ReplicatedKillAvatar },
};
PacketVersion versionForPacketType(PacketType packetType) {
switch (packetType) {
case PacketType::DomainList:

View file

@ -128,6 +128,8 @@ public:
using PacketType = PacketTypeEnum::Value;
extern const QHash<PacketType, PacketType> REPLICATED_PACKET_MAPPING;
const int NUM_BYTES_MD5_HASH = 16;
typedef char PacketVersion;