mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-18 08:58:59 +02:00
use received message faking for cleaner replication in audio
This commit is contained in:
parent
a476a5b82e
commit
29842c67cc
3 changed files with 37 additions and 20 deletions
assignment-client/src/audio
libraries/audio/src
|
@ -125,7 +125,26 @@ void AudioMixer::queueReplicatedAudioPacket(QSharedPointer<ReceivedMessage> mess
|
|||
replicatedNode->setLastHeardMicrostamp(usecTimestampNow());
|
||||
replicatedNode->setIsUpstream(true);
|
||||
|
||||
getOrCreateClientData(replicatedNode.data())->queuePacket(message, replicatedNode);
|
||||
// construct a "fake" avatar data received message from the byte array and packet list information
|
||||
auto audioData = message->getMessage().mid(NUM_BYTES_RFC4122_UUID);
|
||||
|
||||
PacketType rewrittenType;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
auto replicatedMessage = QSharedPointer<ReceivedMessage>::create(audioData, rewrittenType,
|
||||
versionForPacketType(rewrittenType),
|
||||
message->getSenderSockAddr(), nodeID);
|
||||
|
||||
getOrCreateClientData(replicatedNode.data())->queuePacket(replicatedMessage, replicatedNode);
|
||||
}
|
||||
|
||||
void AudioMixer::handleMuteEnvironmentPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode) {
|
||||
|
|
|
@ -160,10 +160,6 @@ void AudioMixerClientData::optionallyReplicatePacket(ReceivedMessage& message, c
|
|||
if (!isReplicatedPacket(message.getType())) {
|
||||
// since this packet will be non-sourced, we add the replicated node's ID here
|
||||
packet->write(node.getUUID().toRfc4122());
|
||||
|
||||
// we won't negotiate an audio format with the replicant, because we aren't a listener
|
||||
// so pack the codec string here so that it can statelessly setup a decoder for this string when it needs
|
||||
packet->writeString(_selectedCodecName);
|
||||
}
|
||||
|
||||
packet->write(message.getMessage());
|
||||
|
@ -312,6 +308,7 @@ int AudioMixerClientData::parseData(ReceivedMessage& message) {
|
|||
// this is injected audio
|
||||
// grab the stream identifier for this injected audio
|
||||
message.seek(sizeof(quint16));
|
||||
|
||||
QUuid streamIdentifier = QUuid::fromRfc4122(message.readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
bool isStereo;
|
||||
|
@ -346,18 +343,6 @@ int AudioMixerClientData::parseData(ReceivedMessage& message) {
|
|||
// seek to the beginning of the packet so that the next reader is in the right spot
|
||||
message.seek(0);
|
||||
|
||||
if (packetType == PacketType::ReplicatedMicrophoneAudioWithEcho
|
||||
|| packetType == PacketType::ReplicatedMicrophoneAudioNoEcho
|
||||
|| packetType == PacketType::ReplicatedSilentAudioFrame
|
||||
|| packetType == PacketType::ReplicatedInjectAudio) {
|
||||
|
||||
// skip past source ID for the replicated packet
|
||||
message.seek(NUM_BYTES_RFC4122_UUID);
|
||||
|
||||
// skip past the codec string
|
||||
message.readString();
|
||||
}
|
||||
|
||||
// check the overflow count before we parse data
|
||||
auto overflowBefore = matchingStream->getOverflowCount();
|
||||
auto parseResult = matchingStream->parseData(message);
|
||||
|
@ -706,9 +691,9 @@ bool AudioMixerClientData::shouldIgnore(const SharedNodePointer self, const Shar
|
|||
}
|
||||
|
||||
void AudioMixerClientData::setupCodecForReplicatedAgent(QSharedPointer<ReceivedMessage> message) {
|
||||
// first pull the codec string from the packet
|
||||
// pull the codec string from the packet
|
||||
message->seek(sizeof(quint16));
|
||||
|
||||
// read the string for the codec
|
||||
auto codecString = message->readString();
|
||||
|
||||
qDebug() << "Manually setting codec for replicated agent" << uuidStringWithoutCurlyBraces(getNodeID())
|
||||
|
@ -718,4 +703,7 @@ void AudioMixerClientData::setupCodecForReplicatedAgent(QSharedPointer<ReceivedM
|
|||
setupCodec(codec.second, codec.first);
|
||||
|
||||
_hasSetupCodecForUpstreamNode = true;
|
||||
|
||||
// seek back to the beginning of the message so other readers are in the right place
|
||||
message->seek(0);
|
||||
}
|
||||
|
|
|
@ -127,7 +127,17 @@ int InboundAudioStream::parseData(ReceivedMessage& message) {
|
|||
// parse the info after the seq number and before the audio data (the stream properties)
|
||||
int prePropertyPosition = message.getPosition();
|
||||
int propertyBytes = parseStreamProperties(message.getType(), message.readWithoutCopy(message.getBytesLeftToRead()), networkFrames);
|
||||
message.seek(prePropertyPosition + propertyBytes);
|
||||
|
||||
if (message.getType() == PacketType::ReplicatedMicrophoneAudioNoEcho
|
||||
|| message.getType() == PacketType::ReplicatedMicrophoneAudioWithEcho
|
||||
|| message.getType() == PacketType::ReplicatedInjectAudio
|
||||
|| message.getType() == PacketType::ReplicatedSilentAudioFrame) {
|
||||
message.seek(NUM_BYTES_RFC4122_UUID);
|
||||
message.readString();
|
||||
message.read(sizeof(quint16) + prePropertyPosition + propertyBytes);
|
||||
} else {
|
||||
message.seek(prePropertyPosition + propertyBytes);
|
||||
}
|
||||
|
||||
// handle this packet based on its arrival status.
|
||||
switch (arrivalInfo._status) {
|
||||
|
|
Loading…
Reference in a new issue