Merge branch 'protocol' of https://github.com/Atlante45/hifi into atp

This commit is contained in:
Stephen Birarda 2015-07-09 11:21:36 -07:00
commit 659f6742c6
8 changed files with 66 additions and 60 deletions

View file

@ -230,8 +230,8 @@ void AssignmentClientMonitor::readPendingDatagrams() {
// tell unknown assignment-client child to exit.
qDebug() << "asking unknown child to exit.";
auto diePacket = NL::create(PacketType::StopNode, 0);
nodeList->sendPacket(std::move(diePacket), childNode);
auto diePacket = NLPacket::create(PacketType::StopNode, 0);
nodeList->sendPacket(std::move(diePacket), senderSockAddr);
}
}
}

View file

@ -524,11 +524,11 @@ void AudioMixer::sendAudioEnvironmentPacket(SharedNodePointer node) {
setAtBit(bitset, HAS_REVERB_BIT);
}
envPacket.write(&bitset, sizeof(bitset));
envPacket->writePrimitive(bitset);
if (hasReverb) {
envPacket.write(&reverbTime, sizeof(reverb));
envPacket.write(&wetLevel, sizeof(wetLevel));
envPacket->writePrimitive(reverbTime);
envPacket->writePrimitive(wetLevel);
}
nodeList->sendPacket(std::move(envPacket), node);
}
@ -550,13 +550,14 @@ void AudioMixer::readPendingDatagram(const QByteArray& receivedPacket, const Hif
} else if (mixerPacketType == PacketType::MuteEnvironment) {
SharedNodePointer sendingNode = nodeList->sendingNodeForPacket(receivedPacket);
if (sendingNode->getCanAdjustLocks()) {
QByteArray packet = receivedPacket;
nodeList->populatePacketHeader(packet, PacketType::MuteEnvironment);
auto packet = NLPacket::create(PacketType::MuteEnvironment);
// Copy payload
packet->write(receivedPacket.mid(numBytesForPacketHeader(receivedPacket)));
nodeList->eachNode([&](const SharedNodePointer& node){
if (node->getType() == NodeType::Agent && node->getActiveSocket() &&
node->getLinkedData() && node != sendingNode) {
nodeList->writeDatagram(packet, packet.size(), node);
nodeList->sendPacket(std::move(packet), node);
}
});
}
@ -805,26 +806,27 @@ void AudioMixer::run() {
std::unique_ptr<NLPacket> mixPacket;
if (streamsMixed > 0) {
int mixPacketBytes = sizeof(quint16) + AudioConstants::NETWORK_FRAME_BYTES_STEREO;
int mixPacketBytes = sizeof(quint16) + AudioConstants::NETWORK_FRAME_BYTES_STEREO * sizeof(int16_t);
mixPacket = NLPacket::create(PacketType::MixedAudio, mixPacketBytes);
// pack sequence number
quint16 sequence = nodeData->getOutgoingSequenceNumber();
mixPacket.write(&sequence, sizeof(quint16));
mixPacket->writePrimitive(sequence);
// pack mixed audio samples
mixPacket.write(mixSamples, AudioConstants::NETWORK_FRAME_BYTES_STEREO);
mixPacket->write(reinterpret_cast<char*>(_mixSamples),
AudioConstants::NETWORK_FRAME_BYTES_STEREO * sizeof(int16_t));
} else {
int silentPacketBytes = sizeof(quint16) + sizeof(quint16);
mixPacket = NLPacket::create(PacketType::SilentAudioFrame, silentPacketBytes);
// pack sequence number
quint16 sequence = nodeData->getOutgoingSequenceNumber();
mixPacket.write(&sequence, sizeof(quint16));
mixPacket->writePrimitive(sequence);
// pack number of silent audio samples
quint16 numSilentSamples = AudioConstants::NETWORK_FRAME_SAMPLES_STEREO;
mixPacket.write(&numSilentSamples, sizeof(quint16));
mixPacket->writePrimitive(numSilentSamples);
}
// Send audio environment

View file

@ -159,21 +159,21 @@ void AudioMixerClientData::sendAudioStreamStatsPackets(const SharedNodePointer&
int numStreamStatsRemaining = _audioStreams.size();
QHash<QUuid, PositionalAudioStream*>::ConstIterator audioStreamsIterator = _audioStreams.constBegin();
PacketList statsPacketList(PacketType::AudioStreamStats);
NLPacketList statsPacketList(PacketType::AudioStreamStats);
while (numStreamStatsRemaining > 0) {
auto statsPacket = NLPacket::create(PacketType::AudioStreamStats);
// pack the append flag in this packet
statsPacket->write(&appendFlag, sizeof(quint8));
statsPacket->writePrimitive(appendFlag);
appendFlag = 1;
int numStreamStatsRoomFor = (statsPacket.size() - sizeof(quint8) - sizeof(quint16)) / sizeof(AudioStreamStats);
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);
statsPacket->write(&numStreamStatsToPack, sizeof(quint16));
statsPacket->writePrimitive(numStreamStatsToPack);
// pack the calculated number of stream stats
for (int i = 0; i < numStreamStatsToPack; i++) {
@ -182,7 +182,7 @@ void AudioMixerClientData::sendAudioStreamStatsPackets(const SharedNodePointer&
stream->perSecondCallbackForUpdatingStats();
AudioStreamStats streamStats = stream->getAudioStreamStats();
statsPacket->write(&streamStats, sizeof(AudioStreamStats));
statsPacket->writePrimitive(streamStats);
audioStreamsIterator++;
}

View file

@ -368,7 +368,7 @@ void AvatarMixer::nodeKilled(SharedNodePointer killedNode) {
auto killPacket = NLPacket::create(PacketType::KillAvatar, NUM_BYTES_RFC4122_UUID);
killPacket->write(killedNode->getUUID().toRfc4122());
nodeList->broadcastToNodes(killPacket, NodeSet() << NodeType::Agent);
nodeList->broadcastToNodes(std::move(killPacket), NodeSet() << NodeType::Agent);
// we also want to remove sequence number data for this avatar on our other avatars
// so invoke the appropriate method on the AvatarMixerClientData for other avatars

View file

@ -42,7 +42,7 @@ OctreeQueryNode::OctreeQueryNode() :
_lodInitialized(false),
_sequenceNumber(0),
_lastRootTimestamp(0),
_myPacketType(PacketTypeUnknown),
_myPacketType(PacketType::Unknown),
_isShuttingDown(false),
_sentPacketHistory()
{
@ -194,14 +194,14 @@ void OctreeQueryNode::resetOctreePacket() {
_octreePacket->reset();
// pack in flags
_octreePacket->write(&flags, sizeof(flags));
_octreePacket->writePrimitive(flags);
// pack in sequence number
_octreePacket->write(&_sequenceNumber, sizeof(_sequenceNumber));
_octreePacket->writePrimitive(_sequenceNumber);
// pack in timestamp
OCTREE_PACKET_SENT_TIME now = usecTimestampNow();
_octreePacket->write(&now, sizeof(now));
_octreePacket->writePrimitive(now);
_octreePacketWaiting = false;
}
@ -216,10 +216,10 @@ void OctreeQueryNode::writeToPacket(const unsigned char* buffer, unsigned int by
// multiple compressed portions together
if (_currentPacketIsCompressed) {
OCTREE_PACKET_INTERNAL_SECTION_SIZE sectionSize = bytes;
_octreePacket->write(&sectionSize, sizeof(sectionSize));
_octreePacket->writePrimitive(sectionSize);
}
if (bytes <= _octreePacket->bytesAvailable()) {
_octreePacket->write(buffer, bytes);
_octreePacket->write(reinterpret_cast<const char*>(buffer), bytes);
_octreePacketWaiting = true;
}
}
@ -368,7 +368,7 @@ bool OctreeQueryNode::hasNextNackedPacket() const {
const NLPacket* OctreeQueryNode::getNextNackedPacket() {
if (!_nackedSequenceNumbers.isEmpty()) {
// could return null if packet is not in the history
return _sentPacketHistory.getPacket(_nackedSequenceNumbers.dequeue());
return _sentPacketHistory.getPacket(_nackedSequenceNumbers.dequeue()).get();
}
return nullptr;

View file

@ -41,13 +41,12 @@ public:
void writeToPacket(const unsigned char* buffer, unsigned int bytes); // writes to end of packet
NLPacket& getPacket() const { return _octreePacket; }
NLPacket& getPacket() const { return *_octreePacket; }
bool isPacketWaiting() const { return _octreePacketWaiting; }
bool packetIsDuplicate() const;
bool shouldSuppressDuplicatePacket();
unsigned int getAvailable() const { return _octreePacketAvailableBytes; }
int getMaxSearchLevel() const { return _maxSearchLevel; }
void resetMaxSearchLevel() { _maxSearchLevel = 1; }
void incrementMaxSearchLevel() { _maxSearchLevel++; }

View file

@ -147,33 +147,33 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
NLPacket& statsPacket = nodeData->stats.getStatsMessage();
// If the size of the stats message and the octree message will fit in a packet, then piggyback them
if (nodeData->getPacket()->getSizeWithHeader() <= statsPacket->bytesAvailable()) {
if (nodeData->getPacket().getSizeWithHeader() <= statsPacket.bytesAvailable()) {
// copy octree message to back of stats message
statsPacket->write(nodeData->getPacket()->getData(), nodeData->getPacket()->getSizeWithHeader());
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getSizeWithHeader());
// since a stats message is only included on end of scene, don't consider any of these bytes "wasted", since
// there was nothing else to send.
int thisWastedBytes = 0;
_totalWastedBytes += thisWastedBytes;
_totalBytes += statsPacket->getSizeWithHeader();
_totalBytes += statsPacket.getSizeWithHeader();
_totalPackets++;
if (debug) {
NLPacket& sentPacket = nodeData->getPacket();
sentPacket->seek(sizeof(OCTREE_PACKET_FLAGS));
sentPacket.seek(sizeof(OCTREE_PACKET_FLAGS));
OCTREE_PACKET_SEQUENCE sequence;
sentPacket->read(&sequence, sizeof(sequence));
sentPacket.readPrimitive(&sequence);
OCTREE_PACKET_SENT_TIME timestamp;
sentPacket->read(&timestamp, sizeof(timestamp));
sentPacket.readPrimitive(&timestamp);
qDebug() << "Adding stats to packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" statsMessageLength: " << statsPacket->getSizeWithHeader() <<
" original size: " << nodeData->getPacket()->getSizeWithHeader() << " [" << _totalBytes <<
" statsMessageLength: " << statsPacket.getSizeWithHeader() <<
" original size: " << nodeData->getPacket().getSizeWithHeader() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
@ -184,33 +184,33 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
} else {
// not enough room in the packet, send two packets
OctreeServer::didCallWriteDatagram(this);
DependencyManager::get<NodeList>()-sendUnreliablePacket(statsPacket, _node);
DependencyManager::get<NodeList>()->sendUnreliablePacket(statsPacket, _node);
// since a stats message is only included on end of scene, don't consider any of these bytes "wasted", since
// there was nothing else to send.
int thisWastedBytes = 0;
_totalWastedBytes += thisWastedBytes;
_totalBytes += statsPacket->getSizeWithHeader();
_totalBytes += statsPacket.getSizeWithHeader();
_totalPackets++;
if (debug) {
NLPacket& sentPacket = nodeData->getPacket();
sentPacket->seek(sizeof(OCTREE_PACKET_FLAGS));
sentPacket.seek(sizeof(OCTREE_PACKET_FLAGS));
OCTREE_PACKET_SEQUENCE sequence;
sentPacket->read(&sequence, sizeof(sequence));
sentPacket.readPrimitive(&sequence);
OCTREE_PACKET_SENT_TIME timestamp;
sentPacket->read(&timestamp, sizeof(timestamp));
sentPacket.readPrimitive(&timestamp);
qDebug() << "Sending separate stats packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" size: " << statsPacket->getSizeWithHeader() << " [" << _totalBytes <<
" size: " << statsPacket.getSizeWithHeader() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
trueBytesSent += statsPacket->getSizeWithHeader();
trueBytesSent += statsPacket.getSizeWithHeader();
truePacketsSent++;
packetsSent++;
@ -218,26 +218,26 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), _node);
packetSent = true;
int packetSizeWithHeader = nodeData->getPacket()->getSizeWithHeader();
int packetSizeWithHeader = nodeData->getPacket().getSizeWithHeader();
thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes;
_totalBytes += nodeData->getPacket()->getSizeWithHeader();
_totalBytes += nodeData->getPacket().getSizeWithHeader();
_totalPackets++;
if (debug) {
NLPacket& sentPacket = nodeData->getPacket();
sentPacket->seek(sizeof(OCTREE_PACKET_FLAGS));
sentPacket.seek(sizeof(OCTREE_PACKET_FLAGS));
OCTREE_PACKET_SEQUENCE sequence;
sentPacket->read(&sequence, sizeof(sequence));
sentPacket.readPrimitive(&sequence);
OCTREE_PACKET_SENT_TIME timestamp;
sentPacket->read(&timestamp, sizeof(timestamp));
sentPacket.readPrimitive(&timestamp);
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
" size: " << nodeData->getPacket()->getSizeWithHeader() << " [" << _totalBytes <<
" size: " << nodeData->getPacket().getSizeWithHeader() << " [" << _totalBytes <<
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
}
}
@ -250,8 +250,8 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), _node);
packetSent = true;
int packetSizeWithHeader = nodeData->getPacket()->getSizeWithHeader();
int thisWastedBytes = MAX_PACKET_SIZE -;
int packetSizeWithHeader = nodeData->getPacket().getSizeWithHeader();
int thisWastedBytes = MAX_PACKET_SIZE - packetSizeWithHeader;
_totalWastedBytes += thisWastedBytes;
_totalBytes += packetSizeWithHeader;
_totalPackets++;
@ -259,13 +259,13 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
if (debug) {
NLPacket& sentPacket = nodeData->getPacket();
sentPacket->seek(sizeof(OCTREE_PACKET_FLAGS));
sentPacket.seek(sizeof(OCTREE_PACKET_FLAGS));
OCTREE_PACKET_SEQUENCE sequence;
sentPacket->read(&sequence, sizeof(sequence));
sentPacket.readPrimitive(&sequence);
OCTREE_PACKET_SENT_TIME timestamp;
sentPacket->read(&timestamp, sizeof(timestamp));
sentPacket.readPrimitive(&timestamp);
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
" timestamp: " << timestamp <<
@ -277,8 +277,8 @@ int OctreeSendThread::handlePacketSend(OctreeQueryNode* nodeData, int& trueBytes
// remember to track our stats
if (packetSent) {
nodeData->stats.packetSent(nodeData->getPacket()->getSizeUsed());
trueBytesSent += nodeData->getPacket()->getSizeUsed();
nodeData->stats.packetSent(nodeData->getPacket().getSizeUsed());
trueBytesSent += nodeData->getPacket().getSizeUsed();
truePacketsSent++;
packetsSent++;
nodeData->octreePacketSent();
@ -528,7 +528,7 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus
}
// If we're not running compressed, then we know we can just send now. Or if we're running compressed, but
// the packet doesn't have enough space to bother attempting to pack more...
// the packet doesn't have enough space to bother attempting to pack more...packet
bool sendNow = true;
if (nodeData->getCurrentPacketIsCompressed() &&

View file

@ -144,11 +144,16 @@ public:
// qint64 writeUnverifiedDatagram(const char* data, qint64 size, const SharedNodePointer& destinationNode,
// const HifiSockAddr& overridenSockAddr = HifiSockAddr());
//
qint64 sendUnreliablePacket(const NLPacket& packet, const SharedNodePointer& destinationNode)
{ assert(false); return 0; }
qint64 sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr)
{ assert(false); return 0; }
// TODO remove those
qint64 sendUnreliablePacket(std::unique_ptr<NLPacket>& packet, const SharedNodePointer& destinationNode)
{ assert(false); return 0; }
{ assert(false); return 0; }
qint64 sendUnreliablePacket(std::unique_ptr<NLPacket>& packet, const HifiSockAddr& sockAddr)
{ assert(false); return 0; }
{ assert(false); return 0; }
qint64 sendPacket(std::unique_ptr<NLPacket> packet, const SharedNodePointer& destinationNode)
{ assert(false); return 0; }