mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 07:34:20 +02:00
Merge branch 'atp' of https://github.com/birarda/hifi into protocol
This commit is contained in:
commit
8e7580d58d
12 changed files with 261 additions and 340 deletions
|
@ -195,8 +195,8 @@ void AssignmentClientMonitor::checkSpares() {
|
|||
SharedNodePointer childNode = nodeList->nodeWithUUID(aSpareId);
|
||||
childNode->activateLocalSocket();
|
||||
|
||||
QByteArray diePacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeStopNode);
|
||||
nodeList->writeUnverifiedDatagram(diePacket, childNode);
|
||||
auto diePacket { NLPacket::create(PacketType::StopNode); }
|
||||
nodeList->sendPacket(diePacket, childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -229,8 +229,9 @@ void AssignmentClientMonitor::readPendingDatagrams() {
|
|||
} else {
|
||||
// tell unknown assignment-client child to exit.
|
||||
qDebug() << "asking unknown child to exit.";
|
||||
QByteArray diePacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeStopNode);
|
||||
nodeList->writeUnverifiedDatagram(diePacket, senderSockAddr);
|
||||
|
||||
auto diePacket { NL::create(PacketType::StopNode); }
|
||||
nodeList->sendPacket(diePacket, childNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -509,24 +509,20 @@ void AudioMixer::sendAudioEnvironmentPacket(SharedNodePointer node) {
|
|||
|
||||
if (sendData) {
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
int numBytesEnvPacketHeader = nodeList->populatePacketHeader(clientEnvBuffer, PacketTypeAudioEnvironment);
|
||||
char* envDataAt = clientEnvBuffer + numBytesEnvPacketHeader;
|
||||
auto envPacket = NLPacket::create(PacketType::AudioEnvironment);
|
||||
|
||||
unsigned char bitset = 0;
|
||||
if (hasReverb) {
|
||||
setAtBit(bitset, HAS_REVERB_BIT);
|
||||
}
|
||||
|
||||
memcpy(envDataAt, &bitset, sizeof(unsigned char));
|
||||
envDataAt += sizeof(unsigned char);
|
||||
envPacket.write(&bitset, sizeof(unsigned char));
|
||||
|
||||
if (hasReverb) {
|
||||
memcpy(envDataAt, &reverbTime, sizeof(float));
|
||||
envDataAt += sizeof(float);
|
||||
memcpy(envDataAt, &wetLevel, sizeof(float));
|
||||
envDataAt += sizeof(float);
|
||||
envPacket.write(&reverbTime, sizeof(float));
|
||||
envPacket.write(&wetLevel, sizeof(float));
|
||||
}
|
||||
nodeList->writeDatagram(clientEnvBuffer, envDataAt - clientEnvBuffer, node);
|
||||
nodeList->sendPacket(envPacket, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -712,8 +708,6 @@ void AudioMixer::run() {
|
|||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
|
||||
char clientMixBuffer[MAX_PACKET_SIZE];
|
||||
|
||||
int usecToSleep = AudioConstants::NETWORK_FRAME_USECS;
|
||||
|
||||
const int TRAILING_AVERAGE_FRAMES = 100;
|
||||
|
@ -791,8 +785,8 @@ void AudioMixer::run() {
|
|||
// if the stream should be muted, send mute packet
|
||||
if (nodeData->getAvatarAudioStream()
|
||||
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
||||
QByteArray packet = nodeList->byteArrayWithPopulatedHeader(PacketTypeNoisyMute);
|
||||
nodeList->writeDatagram(packet, node);
|
||||
auto mutePacket { NLPacket::create(PacketType::NoisyMute); }
|
||||
nodeList->sendPacket(mutePacket, node);
|
||||
}
|
||||
|
||||
if (node->getType() == NodeType::Agent && node->getActiveSocket()
|
||||
|
@ -800,41 +794,36 @@ void AudioMixer::run() {
|
|||
|
||||
int streamsMixed = prepareMixForListeningNode(node.data());
|
||||
|
||||
char* mixDataAt;
|
||||
std::unique_ptr<NLPacket> mixPacket;
|
||||
|
||||
if (streamsMixed > 0) {
|
||||
// pack header
|
||||
int numBytesMixPacketHeader = nodeList->populatePacketHeader(clientMixBuffer, PacketTypeMixedAudio);
|
||||
mixDataAt = clientMixBuffer + numBytesMixPacketHeader;
|
||||
int mixPacketBytes = sizeof(quint16) + AudioConstants::NETWORK_FRAME_BYTES_STEREO;
|
||||
mixPacket = NLPacket::create(PacketType::MixedAudio);
|
||||
|
||||
// pack sequence number
|
||||
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
||||
memcpy(mixDataAt, &sequence, sizeof(quint16));
|
||||
mixDataAt += sizeof(quint16);
|
||||
mixPacket.write(&sequence, sizeof(quint16));
|
||||
|
||||
// pack mixed audio samples
|
||||
memcpy(mixDataAt, _mixSamples, AudioConstants::NETWORK_FRAME_BYTES_STEREO);
|
||||
mixDataAt += AudioConstants::NETWORK_FRAME_BYTES_STEREO;
|
||||
mixPacket.write(mixSamples, AudioConstants::NETWORK_FRAME_BYTES_STEREO);
|
||||
} else {
|
||||
// pack header
|
||||
int numBytesPacketHeader = nodeList->populatePacketHeader(clientMixBuffer, PacketTypeSilentAudioFrame);
|
||||
mixDataAt = clientMixBuffer + numBytesPacketHeader;
|
||||
int silentPacketBytes = sizeof(quint16) + sizeof(quint16);
|
||||
mixPacket = NLPacket::create(PacketType::SilentAudioFrame);
|
||||
|
||||
// pack sequence number
|
||||
quint16 sequence = nodeData->getOutgoingSequenceNumber();
|
||||
memcpy(mixDataAt, &sequence, sizeof(quint16));
|
||||
mixDataAt += sizeof(quint16);
|
||||
mixPacket.write(&sequence, sizeof(quint16));
|
||||
|
||||
// pack number of silent audio samples
|
||||
quint16 numSilentSamples = AudioConstants::NETWORK_FRAME_SAMPLES_STEREO;
|
||||
memcpy(mixDataAt, &numSilentSamples, sizeof(quint16));
|
||||
mixDataAt += sizeof(quint16);
|
||||
mixPacket.write(&numSilentSamples, sizeof(quint16));
|
||||
}
|
||||
|
||||
// Send audio environment
|
||||
sendAudioEnvironmentPacket(node);
|
||||
|
||||
// send mixed audio packet
|
||||
nodeList->writeDatagram(clientMixBuffer, mixDataAt - clientMixBuffer, node);
|
||||
nodeList->sendPacket(mixPacket, node);
|
||||
nodeData->incrementOutgoingMixedAudioSequenceNumber();
|
||||
|
||||
// send an audio stream stats packet if it's time
|
||||
|
|
|
@ -147,7 +147,6 @@ void AudioMixerClientData::sendAudioStreamStatsPackets(const SharedNodePointer&
|
|||
// since audio stream stats packets are sent periodically, this is a good place to remove our dead injected streams.
|
||||
removeDeadInjectedStreams();
|
||||
|
||||
char packet[MAX_PACKET_SIZE];
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
// The append flag is a boolean value that will be packed right after the header. The first packet sent
|
||||
|
@ -156,44 +155,38 @@ void AudioMixerClientData::sendAudioStreamStatsPackets(const SharedNodePointer&
|
|||
// it receives a packet with an appendFlag of 0. This prevents the buildup of dead audio stream stats in the client.
|
||||
quint8 appendFlag = 0;
|
||||
|
||||
// pack header
|
||||
int numBytesPacketHeader = nodeList->populatePacketHeader(packet, PacketTypeAudioStreamStats);
|
||||
char* headerEndAt = packet + numBytesPacketHeader;
|
||||
|
||||
// calculate how many stream stat structs we can fit in each packet
|
||||
const int numStreamStatsRoomFor = (MAX_PACKET_SIZE - numBytesPacketHeader - sizeof(quint8) - sizeof(quint16)) / sizeof(AudioStreamStats);
|
||||
|
||||
// pack and send stream stats packets until all audio streams' stats are sent
|
||||
int numStreamStatsRemaining = _audioStreams.size();
|
||||
QHash<QUuid, PositionalAudioStream*>::ConstIterator audioStreamsIterator = _audioStreams.constBegin();
|
||||
while (numStreamStatsRemaining > 0) {
|
||||
|
||||
char* dataAt = headerEndAt;
|
||||
auto statsPacket { NLPacket::create(PacketType::AudioStreamStats); }
|
||||
|
||||
// pack the append flag
|
||||
memcpy(dataAt, &appendFlag, sizeof(quint8));
|
||||
// pack the append flag in this packet
|
||||
statsPacket.write(&appendFlag, sizeof(quint8));
|
||||
appendFlag = 1;
|
||||
dataAt += sizeof(quint8);
|
||||
|
||||
int numStreamStatsRoomFor = (statsPacket.size() - sizeof(quint8) - sizeof(quint16)) / sizeof(AudioStreamStats);
|
||||
|
||||
// calculate and pack the number of stream stats to follow
|
||||
quint16 numStreamStatsToPack = std::min(numStreamStatsRemaining, numStreamStatsRoomFor);
|
||||
memcpy(dataAt, &numStreamStatsToPack, sizeof(quint16));
|
||||
dataAt += sizeof(quint16);
|
||||
statsPacket.write(&numStreamStatsToPack, sizeof(quint16));
|
||||
|
||||
// pack the calculated number of stream stats
|
||||
for (int i = 0; i < numStreamStatsToPack; i++) {
|
||||
PositionalAudioStream* stream = audioStreamsIterator.value();
|
||||
|
||||
stream->perSecondCallbackForUpdatingStats();
|
||||
|
||||
AudioStreamStats streamStats = stream->getAudioStreamStats();
|
||||
memcpy(dataAt, &streamStats, sizeof(AudioStreamStats));
|
||||
dataAt += sizeof(AudioStreamStats);
|
||||
statsPacket.write(&streamStats, sizeof(AudioStreamStats));
|
||||
|
||||
audioStreamsIterator++;
|
||||
}
|
||||
numStreamStatsRemaining -= numStreamStatsToPack;
|
||||
|
||||
// send the current packet
|
||||
nodeList->writeDatagram(packet, dataAt - packet, destinationNode);
|
||||
nodeList->sendPacket(statsPacket, destinationNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,10 +120,7 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
++framesSinceCutoffEvent;
|
||||
}
|
||||
|
||||
static QByteArray mixedAvatarByteArray;
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
int numPacketHeaderBytes = nodeList->populatePacketHeader(mixedAvatarByteArray, PacketTypeBulkAvatarData);
|
||||
|
||||
// setup for distributed random floating point values
|
||||
std::random_device randomDevice;
|
||||
|
@ -151,9 +148,6 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
}
|
||||
++_sumListeners;
|
||||
|
||||
// reset packet pointers for this node
|
||||
mixedAvatarByteArray.resize(numPacketHeaderBytes);
|
||||
|
||||
AvatarData& avatar = nodeData->getAvatar();
|
||||
glm::vec3 myPosition = avatar.getPosition();
|
||||
|
||||
|
@ -218,6 +212,9 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
nodeData->incrementNumFramesSinceFRDAdjustment();
|
||||
}
|
||||
|
||||
// setup a PacketList for the avatarPackets
|
||||
PacketList avatarPacketList(PacketType::AvatarData);
|
||||
|
||||
// this is an AGENT we have received head data from
|
||||
// send back a packet with other active node data to this node
|
||||
nodeList->eachMatchingNode(
|
||||
|
@ -257,7 +254,7 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
}
|
||||
|
||||
PacketSequenceNumber lastSeqToReceiver = nodeData->getLastBroadcastSequenceNumber(otherNode->getUUID());
|
||||
PacketSequenceNumber lastSeqFromSender = otherNode->getLastSequenceNumberForPacketType(PacketTypeAvatarData);
|
||||
PacketSequenceNumber lastSeqFromSender = otherNode->getLastSequenceNumberForPacketType(PacketType::AvatarData);
|
||||
|
||||
if (lastSeqToReceiver > lastSeqFromSender) {
|
||||
// Did we somehow get out of order packets from the sender?
|
||||
|
@ -286,23 +283,15 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
|
||||
// set the last sent sequence number for this sender on the receiver
|
||||
nodeData->setLastBroadcastSequenceNumber(otherNode->getUUID(),
|
||||
otherNode->getLastSequenceNumberForPacketType(PacketTypeAvatarData));
|
||||
otherNode->getLastSequenceNumberForPacketType(PacketType::AvatarData));
|
||||
|
||||
QByteArray avatarByteArray;
|
||||
avatarByteArray.append(otherNode->getUUID().toRfc4122());
|
||||
avatarByteArray.append(otherAvatar.toByteArray());
|
||||
// start a new segment in the PacketList for this avatar
|
||||
avatarPacketList.startSegment();
|
||||
|
||||
if (avatarByteArray.size() + mixedAvatarByteArray.size() > MAX_PACKET_SIZE) {
|
||||
nodeList->writeDatagram(mixedAvatarByteArray, node);
|
||||
numAvatarDataBytes += avatarPacketList.write(otherNode->getUUID().toRfc4122());
|
||||
numAvatarDataBytes += avatarPacketList.write(otherAvatar.toByteArray());
|
||||
|
||||
numAvatarDataBytes += mixedAvatarByteArray.size();
|
||||
|
||||
// reset the packet
|
||||
mixedAvatarByteArray.resize(numPacketHeaderBytes);
|
||||
}
|
||||
|
||||
// copy the avatar into the mixedAvatarByteArray packet
|
||||
mixedAvatarByteArray.append(avatarByteArray);
|
||||
avatarPacketList.endSegment();
|
||||
|
||||
// if the receiving avatar has just connected make sure we send out the mesh and billboard
|
||||
// for this avatar (assuming they exist)
|
||||
|
@ -315,11 +304,12 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
&& (forceSend
|
||||
|| otherNodeData->getBillboardChangeTimestamp() > _lastFrameTimestamp
|
||||
|| randFloat() < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
|
||||
QByteArray billboardPacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeAvatarBillboard);
|
||||
billboardPacket.append(otherNode->getUUID().toRfc4122());
|
||||
billboardPacket.append(otherNodeData->getAvatar().getBillboard());
|
||||
|
||||
nodeList->writeDatagram(billboardPacket, node);
|
||||
auto billboardPacket { NLPacket::create(PacketType::AvatarBillboard); }
|
||||
billboardPacket.write(otherNode->getUUID().toRfc4122());
|
||||
billboardPacket.write(otherNodeData->getAvatar().getBillboard());
|
||||
|
||||
nodeList->sendPacket(billboardPacket, node);
|
||||
|
||||
++_sumBillboardPackets;
|
||||
}
|
||||
|
@ -329,23 +319,24 @@ void AvatarMixer::broadcastAvatarData() {
|
|||
|| otherNodeData->getIdentityChangeTimestamp() > _lastFrameTimestamp
|
||||
|| randFloat() < BILLBOARD_AND_IDENTITY_SEND_PROBABILITY)) {
|
||||
|
||||
QByteArray identityPacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeAvatarIdentity);
|
||||
auto identityPacket { NLPacket::create(PacketType::AvatarIdentity); }
|
||||
|
||||
QByteArray individualData = otherNodeData->getAvatar().identityByteArray();
|
||||
individualData.replace(0, NUM_BYTES_RFC4122_UUID, otherNode->getUUID().toRfc4122());
|
||||
identityPacket.append(individualData);
|
||||
|
||||
nodeList->writeDatagram(identityPacket, node);
|
||||
identityPacket.write(individualData);
|
||||
|
||||
nodeList->sendPacket(identityPacket, node);
|
||||
|
||||
++_sumIdentityPackets;
|
||||
}
|
||||
});
|
||||
|
||||
// send the last packet
|
||||
nodeList->writeDatagram(mixedAvatarByteArray, node);
|
||||
// send the avatar data PacketList
|
||||
nodeList->sendPacketList(avatarPacketList, node);
|
||||
|
||||
// record the bytes sent for other avatar data in the AvatarMixerClientData
|
||||
nodeData->recordSentAvatarData(numAvatarDataBytes + mixedAvatarByteArray.size());
|
||||
nodeData->recordSentAvatarData(numAvatarDataBytes);
|
||||
|
||||
// record the number of avatars held back this frame
|
||||
nodeData->recordNumOtherAvatarStarves(numAvatarsHeldBack);
|
||||
|
@ -370,8 +361,8 @@ void AvatarMixer::nodeKilled(SharedNodePointer killedNode) {
|
|||
|
||||
// this was an avatar we were sending to other people
|
||||
// send a kill packet for it to our other nodes
|
||||
QByteArray killPacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeKillAvatar);
|
||||
killPacket += killedNode->getUUID().toRfc4122();
|
||||
auto killPacket { NLPacket::create(PacketType::KillAvatar); }
|
||||
killPacket.write(killedNode->getUUID().toRfc4122());
|
||||
|
||||
nodeList->broadcastToNodes(killPacket, NodeSet() << NodeType::Agent);
|
||||
|
||||
|
|
|
@ -573,33 +573,34 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
|
|||
QDataStream packetStream(packet);
|
||||
packetStream.skipRawData(numBytesForPacketHeader(packet));
|
||||
|
||||
QUuid connectUUID;
|
||||
packetStream >> connectUUID;
|
||||
|
||||
parseNodeDataFromByteArray(packetStream, nodeType, publicSockAddr, localSockAddr, senderSockAddr);
|
||||
|
||||
QUuid packetUUID = uuidFromPacketHeader(packet);
|
||||
|
||||
// check if this connect request matches an assignment in the queue
|
||||
bool isAssignment = _pendingAssignedNodes.contains(packetUUID);
|
||||
bool isAssignment = _pendingAssignedNodes.contains(connectUUID);
|
||||
SharedAssignmentPointer matchingQueuedAssignment = SharedAssignmentPointer();
|
||||
PendingAssignedNodeData* pendingAssigneeData = NULL;
|
||||
|
||||
if (isAssignment) {
|
||||
pendingAssigneeData = _pendingAssignedNodes.value(packetUUID);
|
||||
pendingAssigneeData = _pendingAssignedNodes.value(connectUUID);
|
||||
|
||||
if (pendingAssigneeData) {
|
||||
matchingQueuedAssignment = matchingQueuedAssignmentForCheckIn(pendingAssigneeData->getAssignmentUUID(), nodeType);
|
||||
|
||||
if (matchingQueuedAssignment) {
|
||||
qDebug() << "Assignment deployed with" << uuidStringWithoutCurlyBraces(packetUUID)
|
||||
qDebug() << "Assignment deployed with" << uuidStringWithoutCurlyBraces(connectUUID)
|
||||
<< "matches unfulfilled assignment"
|
||||
<< uuidStringWithoutCurlyBraces(matchingQueuedAssignment->getUUID());
|
||||
|
||||
// remove this unique assignment deployment from the hash of pending assigned nodes
|
||||
// cleanup of the PendingAssignedNodeData happens below after the node has been added to the LimitedNodeList
|
||||
_pendingAssignedNodes.remove(packetUUID);
|
||||
_pendingAssignedNodes.remove(connectUUID);
|
||||
} else {
|
||||
// this is a node connecting to fulfill an assignment that doesn't exist
|
||||
// don't reply back to them so they cycle back and re-request an assignment
|
||||
qDebug() << "No match for assignment deployed with" << uuidStringWithoutCurlyBraces(packetUUID);
|
||||
qDebug() << "No match for assignment deployed with" << uuidStringWithoutCurlyBraces(connectUUID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -621,9 +622,8 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
|
|||
QByteArray utfString = reason.toUtf8();
|
||||
int payloadSize = utfString.size();
|
||||
|
||||
auto connectionDeniedPacket = NodeListPacket::make(PacketType::DomainConnectionDenied, payloadSize);
|
||||
|
||||
memcpy(connectionDeniedPacket.payload().data(), utfString.data(), utfString.size());
|
||||
auto connectionDeniedPacket = NLPacket::make(PacketType::DomainConnectionDenied, payloadSize);
|
||||
connectionDeniedPacket.write(utfString);
|
||||
|
||||
// tell client it has been refused.
|
||||
limitedNodeList->sendPacket(std::move(connectionDeniedPacket, senderSockAddr);
|
||||
|
@ -638,18 +638,18 @@ void DomainServer::handleConnectRequest(const QByteArray& packet, const HifiSock
|
|||
QUuid nodeUUID;
|
||||
|
||||
HifiSockAddr discoveredSocket = senderSockAddr;
|
||||
SharedNetworkPeer connectedPeer = _icePeers.value(packetUUID);
|
||||
SharedNetworkPeer connectedPeer = _icePeers.value(connectUUID);
|
||||
|
||||
if (connectedPeer) {
|
||||
// this user negotiated a connection with us via ICE, so re-use their ICE client ID
|
||||
nodeUUID = packetUUID;
|
||||
nodeUUID = connectUUID;
|
||||
|
||||
if (connectedPeer->getActiveSocket()) {
|
||||
// set their discovered socket to whatever the activated socket on the network peer object was
|
||||
discoveredSocket = *connectedPeer->getActiveSocket();
|
||||
}
|
||||
} else {
|
||||
// we got a packetUUID we didn't recognize, just add the node
|
||||
// we got a connectUUID we didn't recognize, just add the node with a new UUID
|
||||
nodeUUID = QUuid::createUuid();
|
||||
}
|
||||
|
||||
|
|
|
@ -153,54 +153,56 @@ void AudioInjector::injectToMixer() {
|
|||
// make sure we actually have samples downloaded to inject
|
||||
if (_audioData.size()) {
|
||||
|
||||
auto audioPacket { NLPacket::create(PacketType::InjectAudio); }
|
||||
|
||||
// setup the packet for injected audio
|
||||
QByteArray injectAudioPacket = nodeList->byteArrayWithPopulatedHeader(PacketTypeInjectAudio);
|
||||
QDataStream packetStream(&injectAudioPacket, QIODevice::Append);
|
||||
QDataStream audioPacketStream(&audioPacket);
|
||||
|
||||
// pack some placeholder sequence number for now
|
||||
int numPreSequenceNumberBytes = injectAudioPacket.size();
|
||||
packetStream << (quint16)0;
|
||||
audioPacketStream << (quint16) 0;
|
||||
|
||||
// pack stream identifier (a generated UUID)
|
||||
packetStream << QUuid::createUuid();
|
||||
audioPacketStream << QUuid::createUuid();
|
||||
|
||||
// pack the stereo/mono type of the stream
|
||||
packetStream << _options.stereo;
|
||||
audioPacketStream << _options.stereo;
|
||||
|
||||
// pack the flag for loopback
|
||||
uchar loopbackFlag = (uchar) true;
|
||||
packetStream << loopbackFlag;
|
||||
audioPacketStream << loopbackFlag;
|
||||
|
||||
// pack the position for injected audio
|
||||
int positionOptionOffset = injectAudioPacket.size();
|
||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.position),
|
||||
int positionOptionOffset = audioPacket.pos();
|
||||
audioPacketStream.writeRawData(reinterpret_cast<const char*>(&_options.position),
|
||||
sizeof(_options.position));
|
||||
|
||||
// pack our orientation for injected audio
|
||||
int orientationOptionOffset = injectAudioPacket.size();
|
||||
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation),
|
||||
int orientationOptionOffset = audioPacket.pos();
|
||||
audioPacketStream.writeRawData(reinterpret_cast<const char*>(&_options.orientation),
|
||||
sizeof(_options.orientation));
|
||||
|
||||
// pack zero for radius
|
||||
float radius = 0;
|
||||
packetStream << radius;
|
||||
audioPacketStream << radius;
|
||||
|
||||
// pack 255 for attenuation byte
|
||||
int volumeOptionOffset = injectAudioPacket.size();
|
||||
int volumeOptionOffset = audioPacket.pos();
|
||||
quint8 volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||
packetStream << volume;
|
||||
audioPacketStream << volume;
|
||||
|
||||
packetStream << _options.ignorePenumbra;
|
||||
audioPacketStream << _options.ignorePenumbra;
|
||||
|
||||
int audioDataOffset = audioPacket.pos();
|
||||
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
int nextFrame = 0;
|
||||
|
||||
int numPreAudioDataBytes = injectAudioPacket.size();
|
||||
bool shouldLoop = _options.loop;
|
||||
|
||||
// loop to send off our audio in NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL byte chunks
|
||||
quint16 outgoingInjectedAudioSequenceNumber = 0;
|
||||
|
||||
while (_currentSendPosition < _audioData.size() && !_shouldStop) {
|
||||
|
||||
int bytesToCopy = std::min(((_options.stereo) ? 2 : 1) * AudioConstants::NETWORK_FRAME_BYTES_PER_CHANNEL,
|
||||
|
@ -214,31 +216,29 @@ void AudioInjector::injectToMixer() {
|
|||
}
|
||||
_loudness /= (float)(bytesToCopy / sizeof(int16_t));
|
||||
|
||||
memcpy(injectAudioPacket.data() + positionOptionOffset,
|
||||
&_options.position,
|
||||
sizeof(_options.position));
|
||||
memcpy(injectAudioPacket.data() + orientationOptionOffset,
|
||||
&_options.orientation,
|
||||
sizeof(_options.orientation));
|
||||
volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||
memcpy(injectAudioPacket.data() + volumeOptionOffset, &volume, sizeof(volume));
|
||||
audioPacket.seek(positionOptionOffset);
|
||||
audioPacket.write(&_options.position, sizeof(_options.position));
|
||||
|
||||
// resize the QByteArray to the right size
|
||||
injectAudioPacket.resize(numPreAudioDataBytes + bytesToCopy);
|
||||
audioPacket.seek(orientationOptionOffset);
|
||||
audioPacket.write(&_options.orientation, sizeof(_options.orientation));
|
||||
|
||||
volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||
audioPacket.seek(volumeOptionOffset);
|
||||
audioPacket.write(&volume, sizeof(volume));
|
||||
|
||||
audioPacket.seek(audioDataOffset);
|
||||
|
||||
// pack the sequence number
|
||||
memcpy(injectAudioPacket.data() + numPreSequenceNumberBytes,
|
||||
&outgoingInjectedAudioSequenceNumber, sizeof(quint16));
|
||||
audioPacket.write(&outgoingInjectedAudioSequenceNumber, sizeof(quint16));
|
||||
|
||||
// copy the next NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL bytes to the packet
|
||||
memcpy(injectAudioPacket.data() + numPreAudioDataBytes,
|
||||
_audioData.data() + _currentSendPosition, bytesToCopy);
|
||||
audioPacket.write(_audioData.data() + _currentSendPosition, bytesToCopy);
|
||||
|
||||
// grab our audio mixer from the NodeList, if it exists
|
||||
SharedNodePointer audioMixer = nodeList->soloNodeOfType(NodeType::AudioMixer);
|
||||
|
||||
// send off this audio packet
|
||||
nodeList->writeDatagram(injectAudioPacket, audioMixer);
|
||||
nodeList->sendUnreliablePacket(audioPacket, audioMixer);
|
||||
outgoingInjectedAudioSequenceNumber++;
|
||||
|
||||
_currentSendPosition += bytesToCopy;
|
||||
|
|
|
@ -508,22 +508,22 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t
|
|||
}
|
||||
}
|
||||
|
||||
unsigned LimitedNodeList::broadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) {
|
||||
unsigned n = 0;
|
||||
// unsigned LimitedNodeList::broadcastToNodes(PacketList& packetList, const NodeSet& destinationNodeTypes) {
|
||||
// unsigned n = 0;
|
||||
//
|
||||
// eachNode([&](const SharedNodePointer& node){
|
||||
// if (destinationNodeTypes.contains(node->getType())) {
|
||||
// writeDatagram(packet, node);
|
||||
// ++n;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return n;
|
||||
// }
|
||||
|
||||
eachNode([&](const SharedNodePointer& node){
|
||||
if (destinationNodeTypes.contains(node->getType())) {
|
||||
writeDatagram(packet, node);
|
||||
++n;
|
||||
}
|
||||
});
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
NodeListPacket&& LimitedNodeList::constructPingPacket(PingType_t pingType) {
|
||||
NLPacket&& LimitedNodeList::constructPingPacket(PingType_t pingType) {
|
||||
int packetSize = sizeof(PingType_t) + sizeof(quint64);
|
||||
NodeListPacket pingPacket = NodeListPacket::create(PacketType::Ping, packetSize);
|
||||
auto pingPacket { NLPacket::create(PacketType::Ping, packetSize); }
|
||||
|
||||
QDataStream packetStream(&pingPacket.payload(), QIODevice::Append);
|
||||
|
||||
|
@ -533,7 +533,7 @@ NodeListPacket&& LimitedNodeList::constructPingPacket(PingType_t pingType) {
|
|||
return pingPacket;
|
||||
}
|
||||
|
||||
NodeListPacket&& LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacket) {
|
||||
NLPacket&& LimitedNodeList::constructPingReplyPacket(const QByteArray& pingPacket) {
|
||||
QDataStream pingPacketStream(pingPacket);
|
||||
pingPacketStream.skipRawData(numBytesForPacketHeader(pingPacket));
|
||||
|
||||
|
@ -545,7 +545,7 @@ NodeListPacket&& LimitedNodeList::constructPingReplyPacket(const QByteArray& pin
|
|||
|
||||
int packetSize = sizeof(PingType_t) + sizeof(quint64) + sizeof(quint64);
|
||||
|
||||
NodeListPacket replyPacket = NodeListPacket::create(PacketType::Ping, packetSize);
|
||||
auto replyPacket { NLPacket::create(PacketType::Ping, packetSize); }
|
||||
|
||||
QDataStream packetStream(&replyPacket, QIODevice::Append);
|
||||
packetStream << typeFromOriginalPing << timeFromOriginalPing << usecTimestampNow();
|
||||
|
@ -553,10 +553,10 @@ NodeListPacket&& LimitedNodeList::constructPingReplyPacket(const QByteArray& pin
|
|||
return replyPacket;
|
||||
}
|
||||
|
||||
NodeListPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID) {
|
||||
NLPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID) {
|
||||
int packetSize = NUM_BYTES_RFC4122_UUID + sizeof(PingType_t);
|
||||
|
||||
NodeListPacket icePingPacket = NodeListPacket::create(PacketType::ICEPing, packetSize);
|
||||
auto icePingPacket { NLPacket::create(PacketType::ICEPing, packetSize); }
|
||||
|
||||
icePingPacket.payload().replace(0, NUM_BYTES_RFC4122_UUID, iceID.toRfc4122().data());
|
||||
memcpy(icePingPacket.payload() + NUM_BYTES_RFC4122_UUID, &pingType, sizeof(PingType_t));
|
||||
|
@ -564,14 +564,14 @@ NodeListPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID)
|
|||
return icePingPacket;
|
||||
}
|
||||
|
||||
NodeListPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID) {
|
||||
NLPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID) {
|
||||
// pull out the ping type so we can reply back with that
|
||||
PingType_t pingType;
|
||||
|
||||
memcpy(&pingType, pingPacket.data() + NUM_BYTES_RFC4122_UUID, sizeof(PingType_t));
|
||||
|
||||
int packetSize = NUM_BYTES_RFC4122_UUID + sizeof(PingType_t);
|
||||
NodeListPacket icePingReplyPacket = NodeListPacket::create(PacketType::ICEPingReply, packetSize);
|
||||
auto icePingReplyPacket { NLPacket::create(PacketType::ICEPingReply, packetSize); }
|
||||
|
||||
// pack the ICE ID and then the ping type
|
||||
memcpy(icePingReplyPacket.payload(), iceID.toRfc4122().data(), NUM_BYTES_RFC4122_UUID);
|
||||
|
|
|
@ -141,6 +141,14 @@ public:
|
|||
//
|
||||
// qint64 writeUnverifiedDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
|
||||
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
|
||||
//
|
||||
|
||||
qint64 sendUnreliablePacket(NLPacket& packet, const SharedNodePointer& destinationNode) {};
|
||||
qint64 sendUnreliablePacket(NLPacket& packet, const HifiSockAddr& sockAddr) {};
|
||||
qint64 sendPacket(NLPacket&& packet, const SharedNodePointer& destinationNode) {};
|
||||
qint64 sendPacket(NLPacket&& packet, const HifiSockAddr& sockAddr) {};
|
||||
qint64 sendPacketList(PacketList& packetList, const SharedNodePointer& destinationNode) {};
|
||||
qint64 sendPacketList(PacketList& packetList, const HifiSockAddr& sockAddr) {};
|
||||
|
||||
void (*linkedDataCreateCallback)(Node *);
|
||||
|
||||
|
@ -165,17 +173,17 @@ public:
|
|||
int updateNodeWithDataFromPacket(const SharedNodePointer& matchingNode, const QByteArray& packet);
|
||||
int findNodeAndUpdateWithDataFromPacket(const QByteArray& packet);
|
||||
|
||||
unsigned broadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes);
|
||||
unsigned broadcastToNodes(PacketList& packetList, const NodeSet& destinationNodeTypes) {};
|
||||
SharedNodePointer soloNodeOfType(char nodeType);
|
||||
|
||||
void getPacketStats(float &packetsPerSecond, float &bytesPerSecond);
|
||||
void resetPacketStats();
|
||||
|
||||
NodeListPacket&& constructPingPacket(PingType_t pingType = PingType::Agnostic);
|
||||
NodeListPacket&& constructPingReplyPacket(const QByteArray& pingPacket);
|
||||
NLPacket&& constructPingPacket(PingType_t pingType = PingType::Agnostic);
|
||||
NLPacket&& constructPingReplyPacket(const QByteArray& pingPacket);
|
||||
|
||||
NodeListPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID);
|
||||
NodeListPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID);
|
||||
NLPacket&& constructICEPingPacket(PingType_t pingType, const QUuid& iceID);
|
||||
NLPacket&& constructICEPingReplyPacket(const QByteArray& pingPacket, const QUuid& iceID);
|
||||
|
||||
virtual bool processSTUNResponse(const QByteArray& packet);
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
bool isUsingDTLS = false;
|
||||
|
||||
PacketType::Value domainPacketType = !_domainHandler.isConnected()
|
||||
? PacketTypeDomainConnectRequest : PacketTypeDomainListRequest;
|
||||
? PacketType::DomainConnectRequest : PacketType::DomainListRequest;
|
||||
|
||||
if (!_domainHandler.isConnected()) {
|
||||
qCDebug(networking) << "Sending connect request to domain-server at" << _domainHandler.getHostname();
|
||||
|
@ -329,24 +329,26 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
|
||||
}
|
||||
|
||||
// construct the DS check in packet
|
||||
QUuid packetUUID = _sessionUUID;
|
||||
auto domainPacket { NLPacket::create(domainPacketType); }
|
||||
QDataStream packetStream(&domainPacket->getPayload);
|
||||
|
||||
if (domainPacketType == PacketType::DomainConnectRequest) {
|
||||
QUuid connectUUID;
|
||||
|
||||
if (domainPacketType == PacketTypeDomainConnectRequest) {
|
||||
if (!_domainHandler.getAssignmentUUID().isNull()) {
|
||||
// this is a connect request and we're an assigned node
|
||||
// so set our packetUUID as the assignment UUID
|
||||
packetUUID = _domainHandler.getAssignmentUUID();
|
||||
connectUUID = _domainHandler.getAssignmentUUID();
|
||||
} else if (_domainHandler.requiresICE()) {
|
||||
// this is a connect request and we're an interface client
|
||||
// that used ice to discover the DS
|
||||
// so send our ICE client UUID with the connect request
|
||||
packetUUID = _domainHandler.getICEClientID();
|
||||
}
|
||||
connectUUID = _domainHandler.getICEClientID();
|
||||
}
|
||||
|
||||
QByteArray domainServerPacket = byteArrayWithUUIDPopulatedHeader(domainPacketType, packetUUID);
|
||||
QDataStream packetStream(&domainServerPacket, QIODevice::Append);
|
||||
// pack the connect UUID for this connect request
|
||||
packetStream << connectUUID;
|
||||
}
|
||||
|
||||
// pack our data to send to the domain-server
|
||||
packetStream << _ownerType << _publicSockAddr << _localSockAddr << _nodeTypesOfInterest.toList();
|
||||
|
@ -367,7 +369,7 @@ void NodeList::sendDomainServerCheckIn() {
|
|||
flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::SendDSCheckIn);
|
||||
|
||||
if (!isUsingDTLS) {
|
||||
writeUnverifiedDatagram(domainServerPacket, _domainHandler.getSockAddr());
|
||||
sendPacket(domainPacket, _domainHandler.getSockAddr());
|
||||
}
|
||||
|
||||
if (_numNoReplyDomainCheckIns >= MAX_SILENT_DOMAIN_SERVER_CHECK_INS) {
|
||||
|
@ -410,7 +412,7 @@ void NodeList::sendDSPathQuery(const QString& newPath) {
|
|||
// only send a path query if we know who our DS is or is going to be
|
||||
if (_domainHandler.isSocketKnown()) {
|
||||
// construct the path query packet
|
||||
QByteArray pathQueryPacket = byteArrayWithPopulatedHeader(PacketTypeDomainServerPathQuery);
|
||||
auto pathQueryPacket = NLPacket::create(PacketType::DomainServerPathQuery);
|
||||
|
||||
// get the UTF8 representation of path query
|
||||
QByteArray pathQueryUTF8 = newPath.toUtf8();
|
||||
|
@ -418,18 +420,18 @@ void NodeList::sendDSPathQuery(const QString& newPath) {
|
|||
// get the size of the UTF8 representation of the desired path
|
||||
quint16 numPathBytes = pathQueryUTF8.size();
|
||||
|
||||
if (pathQueryPacket.size() + numPathBytes + sizeof(numPathBytes) < MAX_PACKET_SIZE) {
|
||||
if (numPathBytes + sizeof(numPathBytes) < pathQueryPacket.size() ) {
|
||||
// append the size of the path to the query packet
|
||||
pathQueryPacket.append(reinterpret_cast<char*>(&numPathBytes), sizeof(numPathBytes));
|
||||
pathQueryPacket.write(&numPathBytes, sizeof(numPathBytes));
|
||||
|
||||
// append the path itself to the query packet
|
||||
pathQueryPacket.append(pathQueryUTF8);
|
||||
pathQueryPacket.write(pathQueryUTF8);
|
||||
|
||||
qCDebug(networking) << "Sending a path query packet for path" << newPath << "to domain-server at"
|
||||
<< _domainHandler.getSockAddr();
|
||||
|
||||
// send off the path query
|
||||
writeUnverifiedDatagram(pathQueryPacket, _domainHandler.getSockAddr());
|
||||
sendPacket(pathQueryPacket, _domainHandler.getSockAddr());
|
||||
} else {
|
||||
qCDebug(networking) << "Path" << newPath << "would make PacketTypeDomainServerPathQuery packet > MAX_PACKET_SIZE." <<
|
||||
"Will not send query.";
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
//
|
||||
// PacketPayload.cpp
|
||||
// libraries/networking/src
|
||||
//
|
||||
// Created by Stephen Birarda on 07/06/15.
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "PacketPayload.h"
|
||||
|
||||
PacketPayload::PacketPayload(char* data, int maxBytes) :
|
||||
_data(data)
|
||||
_maxBytes(maxBytes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int PacketPayload::append(const char* src, int srcBytes) {
|
||||
// this is a call to write at the current index
|
||||
int numWrittenBytes = write(src, srcBytes, _index);
|
||||
|
||||
if (numWrittenBytes > 0) {
|
||||
// we wrote some bytes, push the index
|
||||
_index += numWrittenBytes;
|
||||
return numWrittenBytes;
|
||||
} else {
|
||||
return numWrittenBytes;
|
||||
}
|
||||
}
|
||||
|
||||
const int PACKET_WRITE_ERROR = -1;
|
||||
|
||||
int PacketPayload::write(const char* src, int srcBytes, int index) {
|
||||
if (index >= _maxBytes) {
|
||||
// we were passed a bad index, return -1
|
||||
return PACKET_WRITE_ERROR;
|
||||
}
|
||||
|
||||
// make sure we have the space required to write this block
|
||||
int bytesAvailable = _maxBytes - index;
|
||||
|
||||
if (bytesAvailable < srcBytes) {
|
||||
// good to go - write the data
|
||||
memcpy(_data + index, src, srcBytes);
|
||||
|
||||
// should this cause us to push our index (is this the farthest we've written in data)?
|
||||
_index = std::max(_data + index + srcBytes, _index);
|
||||
|
||||
// return the number of bytes written
|
||||
return srcBytes;
|
||||
} else {
|
||||
// not enough space left for this write - return an error
|
||||
return PACKET_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +31,8 @@ const QSet<PacketType::Value> NON_VERIFIED_PACKETS = QSet<PacketType::Value>()
|
|||
|
||||
const QSet<PacketType::Value> SEQUENCE_NUMBERED_PACKETS = QSet<PacketType::Value>() << AvatarData;
|
||||
|
||||
const QSet<PacketType::Value> NON_SOURCED_PACKETS = QSet<PacketType::Value>() << ICEPing << ICEPingReply;
|
||||
const QSet<PacketType::Value> NON_SOURCED_PACKETS = QSet<PacketType::Value>()
|
||||
<< ICEPing << ICEPingReply << DomainConnectRequest;
|
||||
|
||||
int arithmeticCodingValueFromBuffer(const char* checkValue) {
|
||||
if (((uchar) *checkValue) < 255) {
|
||||
|
|
|
@ -47,18 +47,15 @@ qint64 writeData(const char* data, qint64 maxSize) {
|
|||
|
||||
if (!_isOrdered) {
|
||||
auto newPacket = T::create(_packetType);
|
||||
PacketPayload& newPayload = newPacket.getPayload();
|
||||
|
||||
if (_segmentStartIndex >= 0) {
|
||||
// We in the process of writing a segment for an unordered PacketList.
|
||||
// We need to try and pull the first part of the segment out to our new packet
|
||||
|
||||
PacketPayload& currentPayload = _currentPacket->getPayload();
|
||||
|
||||
// check now to see if this is an unsupported write
|
||||
int numBytesToEnd = currentPayload.size() - _segmentStartIndex;
|
||||
int numBytesToEnd = _currentPacket.size() - _segmentStartIndex;
|
||||
|
||||
if ((newPayload.size() - numBytesToEnd) < maxSize) {
|
||||
if ((newPacket.size() - numBytesToEnd) < maxSize) {
|
||||
// this is an unsupported case - the segment is bigger than the size of an individual packet
|
||||
// but the PacketList is not going to be sent ordered
|
||||
qDebug() << "Error in PacketList::writeData - attempted to write a segment to an unordered packet that is"
|
||||
|
@ -67,20 +64,20 @@ qint64 writeData(const char* data, qint64 maxSize) {
|
|||
}
|
||||
|
||||
// copy from currentPacket where the segment started to the beginning of the newPacket
|
||||
newPayload.write(currentPacket.constData() + _segmentStartIndex, numBytesToEnd);
|
||||
newPacket.write(currentPacket.constData() + _segmentStartIndex, numBytesToEnd);
|
||||
|
||||
// the current segment now starts at the beginning of the new packet
|
||||
_segmentStartIndex = 0;
|
||||
|
||||
// shrink the current payload to the actual size of the packet
|
||||
currentPayload.setSizeUsed(_segmentStartIndex);
|
||||
currentPacket.setSizeUsed(_segmentStartIndex);
|
||||
}
|
||||
|
||||
// move the current packet to our list of packets
|
||||
_packets.insert(std::move(_currentPacket));
|
||||
|
||||
// write the data to the newPacket
|
||||
newPayload.write(data, maxSize);
|
||||
newPacket.write(data, maxSize);
|
||||
|
||||
// set our current packet to the new packet
|
||||
_currentPacket = newPacket;
|
||||
|
@ -90,9 +87,8 @@ qint64 writeData(const char* data, qint64 maxSize) {
|
|||
} else {
|
||||
// we're an ordered PacketList - let's fit what we can into the current packet and then put the leftover
|
||||
// into a new packet
|
||||
PacketPayload& currentPayload = _currentPacket.getPayload();
|
||||
|
||||
int numBytesToEnd = _currentPayload.size() - _currentPayload.pos();
|
||||
int numBytesToEnd = _currentPacket.size() - _currentPacket.sizeUsed();
|
||||
_currentPacket.write(data, numBytesToEnd);
|
||||
|
||||
// move the current packet to our list of packets
|
||||
|
|
Loading…
Reference in a new issue