mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 03:06:39 +02:00
Merge pull request #8 from birarda/atp
final fixes for new networking API
This commit is contained in:
commit
6ba89a1c99
13 changed files with 51 additions and 45 deletions
|
@ -204,8 +204,7 @@ void AssignmentClientMonitor::checkSpares() {
|
|||
|
||||
void AssignmentClientMonitor::handleChildStatusPacket(QSharedPointer<NLPacket> packet) {
|
||||
// read out the sender ID
|
||||
QUuid senderID = QUuid::fromRfc4122(QByteArray::fromRawData(packet->getPayload(), NUM_BYTES_RFC4122_UUID));
|
||||
packet->seek(NUM_BYTES_RFC4122_UUID);
|
||||
QUuid senderID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
|
||||
|
|
|
@ -15,9 +15,7 @@
|
|||
|
||||
int AvatarMixerClientData::parseData(NLPacket& packet) {
|
||||
// compute the offset to the data payload
|
||||
QByteArray byteArray = QByteArray::fromRawData(packet.getPayload() + packet.pos(),
|
||||
packet.bytesLeftToRead());
|
||||
return _avatar.parseDataFromBuffer(byteArray);
|
||||
return _avatar.parseDataFromBuffer(packet.read(packet.bytesLeftToRead()));
|
||||
}
|
||||
|
||||
bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {
|
||||
|
|
|
@ -965,26 +965,24 @@ int DomainServer::parseNodeData(QDataStream& packetStream, NodeType_t& nodeType,
|
|||
|
||||
void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const HifiSockAddr &senderSockAddr,
|
||||
const NodeSet& nodeInterestSet) {
|
||||
auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
NLPacketList domainListPackets(PacketType::DomainList);
|
||||
|
||||
// always send the node their own UUID back
|
||||
QDataStream domainListStream(&domainListPackets);
|
||||
|
||||
const int NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES = NUM_BYTES_RFC4122_UUID + NUM_BYTES_RFC4122_UUID + 2;
|
||||
|
||||
|
||||
// setup the extended header for the domain list packets
|
||||
// this data is at the beginning of each of the domain list packets
|
||||
QByteArray extendedHeader(NUM_DOMAIN_LIST_EXTENDED_HEADER_BYTES, 0);
|
||||
QDataStream extendedHeaderStream(&extendedHeader, QIODevice::WriteOnly);
|
||||
|
||||
|
||||
auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
|
||||
|
||||
extendedHeaderStream << limitedNodeList->getSessionUUID();
|
||||
extendedHeaderStream << node->getUUID();
|
||||
extendedHeaderStream << (quint8) node->getCanAdjustLocks();
|
||||
extendedHeaderStream << (quint8) node->getCanRez();
|
||||
|
||||
domainListPackets.setExtendedHeader(extendedHeader);
|
||||
NLPacketList domainListPackets(PacketType::DomainList, extendedHeader);
|
||||
|
||||
// always send the node their own UUID back
|
||||
QDataStream domainListStream(&domainListPackets);
|
||||
|
||||
DomainServerNodeData* nodeData = reinterpret_cast<DomainServerNodeData*>(node->getLinkedData());
|
||||
|
||||
|
|
|
@ -4113,8 +4113,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
connect(workerThread, &QThread::started, scriptEngine, &ScriptEngine::run);
|
||||
|
||||
// when the thread is terminated, add both scriptEngine and thread to the deleteLater queue
|
||||
connect(scriptEngine, &ScriptEngine::doneRunning, scriptEngine, &ScriptEngine::deleteLater());
|
||||
connect(workerThread, &QThread::finished, workerThread, &Qthread::deleteLater);
|
||||
connect(scriptEngine, &ScriptEngine::doneRunning, scriptEngine, &ScriptEngine::deleteLater);
|
||||
connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
|
||||
|
||||
// tell the thread to stop when the script engine is done
|
||||
connect(scriptEngine, &ScriptEngine::destroyed, workerThread, &QThread::quit);
|
||||
|
|
|
@ -270,12 +270,12 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) {
|
|||
}
|
||||
|
||||
void SkeletonModel::updateJointState(int index) {
|
||||
if (index > _jointStates.size()) {
|
||||
if (index < 0 && index >= _jointStates.size()) {
|
||||
return; // bail
|
||||
}
|
||||
JointState& state = _jointStates[index];
|
||||
const FBXJoint& joint = state.getFBXJoint();
|
||||
if (joint.parentIndex != -1 && joint.parentIndex <= _jointStates.size()) {
|
||||
if (joint.parentIndex >= 0 && joint.parentIndex < _jointStates.size()) {
|
||||
const JointState& parentState = _jointStates.at(joint.parentIndex);
|
||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||
if (index == geometry.leanJointIndex) {
|
||||
|
|
|
@ -112,11 +112,10 @@ int InboundAudioStream::parseData(NLPacket& packet) {
|
|||
int networkSamples;
|
||||
|
||||
// parse the info after the seq number and before the audio data (the stream properties)
|
||||
int propertyBytes = parseStreamProperties(packet.getType(),
|
||||
QByteArray::fromRawData(packet.getPayload() + packet.pos(), packet.bytesLeftToRead()),
|
||||
networkSamples);
|
||||
packet.seek(packet.pos() + propertyBytes);
|
||||
|
||||
int prePropertyPosition = packet.pos();
|
||||
int propertyBytes = parseStreamProperties(packet.getType(), packet.read(packet.bytesLeftToRead()), networkSamples);
|
||||
packet.seek(prePropertyPosition + propertyBytes);
|
||||
|
||||
// handle this packet based on its arrival status.
|
||||
switch (arrivalInfo._status) {
|
||||
case SequenceNumberStats::Early: {
|
||||
|
@ -133,11 +132,7 @@ int InboundAudioStream::parseData(NLPacket& packet) {
|
|||
if (packet.getType() == PacketType::SilentAudioFrame) {
|
||||
writeDroppableSilentSamples(networkSamples);
|
||||
} else {
|
||||
int audioBytes = parseAudioData(packet.getType(),
|
||||
QByteArray::fromRawData(packet.getPayload() + packet.pos(),
|
||||
packet.bytesLeftToRead()),
|
||||
networkSamples);
|
||||
packet.seek(packet.pos() + audioBytes);
|
||||
parseAudioData(packet.getType(), packet.read(packet.bytesLeftToRead()), networkSamples);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -54,23 +54,25 @@ void AvatarHashMap::processAvatarDataPacket(QSharedPointer<NLPacket> packet, Sha
|
|||
// only add them if mixerWeakPointer points to something (meaning that mixer is still around)
|
||||
while (packet->bytesLeftToRead()) {
|
||||
QUuid sessionUUID = QUuid::fromRfc4122(packet->read(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
int positionBeforeRead = packet->pos();
|
||||
|
||||
QByteArray byteArray = QByteArray::fromRawData(packet->getPayload() + packet->pos(),
|
||||
packet->bytesLeftToRead());
|
||||
QByteArray byteArray = packet->read(packet->bytesLeftToRead());
|
||||
|
||||
if (sessionUUID != _lastOwnerSessionUUID) {
|
||||
AvatarSharedPointer avatar = _avatarHash.value(sessionUUID);
|
||||
if (!avatar) {
|
||||
avatar = addAvatar(sessionUUID, sendingNode);
|
||||
}
|
||||
|
||||
|
||||
// have the matching (or new) avatar parse the data from the packet
|
||||
int bytesRead = avatar->parseDataFromBuffer(byteArray);
|
||||
packet->seek(packet->pos() + bytesRead);
|
||||
packet->seek(positionBeforeRead + bytesRead);
|
||||
} else {
|
||||
// create a dummy AvatarData class to throw this data on the ground
|
||||
AvatarData dummyData;
|
||||
int bytesRead = dummyData.parseDataFromBuffer(byteArray);
|
||||
packet->seek(packet->pos() + bytesRead);
|
||||
packet->seek(positionBeforeRead + bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,10 @@
|
|||
|
||||
#include "NLPacket.h"
|
||||
|
||||
NLPacketList::NLPacketList(PacketType::Value packetType) : PacketList(packetType) {
|
||||
NLPacketList::NLPacketList(PacketType::Value packetType, QByteArray extendedHeader) :
|
||||
PacketList(packetType, extendedHeader)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<Packet> NLPacketList::createPacket() {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
class NLPacketList : public PacketList {
|
||||
public:
|
||||
NLPacketList(PacketType::Value packetType);
|
||||
NLPacketList(PacketType::Value packetType, QByteArray extendedHeader = QByteArray());
|
||||
|
||||
private:
|
||||
NLPacketList(const NLPacketList& other) = delete;
|
||||
|
|
|
@ -210,6 +210,13 @@ void Packet::writeSequenceNumber(SequenceNumber seqNum) {
|
|||
&seqNum, sizeof(seqNum));
|
||||
}
|
||||
|
||||
QByteArray Packet::read(qint64 maxSize) {
|
||||
qint64 sizeToRead = std::min(size() - pos(), maxSize);
|
||||
QByteArray data { QByteArray::fromRawData(getPayload() + pos(), sizeToRead) };
|
||||
seek(pos() + sizeToRead);
|
||||
return data;
|
||||
}
|
||||
|
||||
qint64 Packet::writeData(const char* data, qint64 maxSize) {
|
||||
|
||||
// make sure we have the space required to write this block
|
||||
|
|
|
@ -79,6 +79,9 @@ public:
|
|||
virtual bool reset();
|
||||
virtual qint64 size() const { return _payloadCapacity; }
|
||||
|
||||
using QIODevice::read;
|
||||
QByteArray read(qint64 maxSize);
|
||||
|
||||
template<typename T> qint64 peekPrimitive(T* data);
|
||||
template<typename T> qint64 readPrimitive(T* data);
|
||||
template<typename T> qint64 writePrimitive(const T& data);
|
||||
|
|
|
@ -15,14 +15,15 @@
|
|||
|
||||
#include "Packet.h"
|
||||
|
||||
PacketList::PacketList(PacketType::Value packetType) :
|
||||
_packetType(packetType)
|
||||
PacketList::PacketList(PacketType::Value packetType, QByteArray extendedHeader) :
|
||||
_packetType(packetType),
|
||||
_extendedHeader(extendedHeader)
|
||||
{
|
||||
QIODevice::open(WriteOnly);
|
||||
}
|
||||
|
||||
void PacketList::startSegment() {
|
||||
_segmentStartIndex = _currentPacket ? _currentPacket->pos() : 0;
|
||||
_segmentStartIndex = _currentPacket ? _currentPacket->pos() : _extendedHeader.size();
|
||||
}
|
||||
|
||||
void PacketList::endSegment() {
|
||||
|
@ -83,11 +84,13 @@ qint64 PacketList::writeData(const char* data, qint64 maxSize) {
|
|||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
int segmentSize = _currentPacket->pos() - _segmentStartIndex;
|
||||
|
||||
// copy from currentPacket where the segment started to the beginning of the newPacket
|
||||
newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, numBytesToEnd);
|
||||
newPacket->write(_currentPacket->getPayload() + _segmentStartIndex, segmentSize);
|
||||
|
||||
// the current segment now starts at the beginning of the new packet
|
||||
_segmentStartIndex = 0;
|
||||
_segmentStartIndex = _extendedHeader.size();
|
||||
|
||||
// shrink the current payload to the actual size of the packet
|
||||
_currentPacket->setPayloadSize(_segmentStartIndex);
|
||||
|
|
|
@ -21,7 +21,7 @@ class Packet;
|
|||
class PacketList : public QIODevice {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PacketList(PacketType::Value packetType);
|
||||
PacketList(PacketType::Value packetType, QByteArray extendedHeader = QByteArray());
|
||||
|
||||
virtual bool isSequential() const { return true; }
|
||||
|
||||
|
@ -33,8 +33,6 @@ public:
|
|||
|
||||
void closeCurrentPacket(bool shouldSendEmpty = false);
|
||||
|
||||
void setExtendedHeader(const QByteArray& extendedHeader) { _extendedHeader = extendedHeader; }
|
||||
|
||||
template<typename T> qint64 readPrimitive(T* data);
|
||||
template<typename T> qint64 writePrimitive(const T& data);
|
||||
protected:
|
||||
|
@ -83,4 +81,4 @@ template<typename T> std::unique_ptr<T> PacketList::takeFront() {
|
|||
return std::unique_ptr<T>(dynamic_cast<T*>(packet.release()));
|
||||
}
|
||||
|
||||
#endif // hifi_PacketList_h
|
||||
#endif // hifi_PacketList_h
|
||||
|
|
Loading…
Reference in a new issue