mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-10 22:58:45 +02:00
Merge branch 'master' of git://github.com/highfidelity/hifi into fade
This commit is contained in:
commit
b68ec4f933
17 changed files with 363 additions and 367 deletions
|
@ -81,7 +81,6 @@ bool OctreeSendThread::process() {
|
||||||
// don't do any send processing until the initial load of the octree is complete...
|
// don't do any send processing until the initial load of the octree is complete...
|
||||||
if (_myServer->isInitialLoadComplete()) {
|
if (_myServer->isInitialLoadComplete()) {
|
||||||
if (auto node = _node.lock()) {
|
if (auto node = _node.lock()) {
|
||||||
_nodeMissingCount = 0;
|
|
||||||
OctreeQueryNode* nodeData = static_cast<OctreeQueryNode*>(node->getLinkedData());
|
OctreeQueryNode* nodeData = static_cast<OctreeQueryNode*>(node->getLinkedData());
|
||||||
|
|
||||||
// Sometimes the node data has not yet been linked, in which case we can't really do anything
|
// Sometimes the node data has not yet been linked, in which case we can't really do anything
|
||||||
|
@ -129,8 +128,7 @@ AtomicUIntStat OctreeSendThread::_totalSpecialBytes { 0 };
|
||||||
AtomicUIntStat OctreeSendThread::_totalSpecialPackets { 0 };
|
AtomicUIntStat OctreeSendThread::_totalSpecialPackets { 0 };
|
||||||
|
|
||||||
|
|
||||||
int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode* nodeData, int& trueBytesSent,
|
int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode* nodeData, bool dontSuppressDuplicate) {
|
||||||
int& truePacketsSent, bool dontSuppressDuplicate) {
|
|
||||||
OctreeServer::didHandlePacketSend(this);
|
OctreeServer::didHandlePacketSend(this);
|
||||||
|
|
||||||
// if we're shutting down, then exit early
|
// if we're shutting down, then exit early
|
||||||
|
@ -141,15 +139,14 @@ int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode*
|
||||||
bool debug = _myServer->wantsDebugSending();
|
bool debug = _myServer->wantsDebugSending();
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
|
|
||||||
bool packetSent = false; // did we send a packet?
|
int numPackets = 0;
|
||||||
int packetsSent = 0;
|
|
||||||
|
|
||||||
// Here's where we check to see if this packet is a duplicate of the last packet. If it is, we will silently
|
// Here's where we check to see if this packet is a duplicate of the last packet. If it is, we will silently
|
||||||
// obscure the packet and not send it. This allows the callers and upper level logic to not need to know about
|
// obscure the packet and not send it. This allows the callers and upper level logic to not need to know about
|
||||||
// this rate control savings.
|
// this rate control savings.
|
||||||
if (!dontSuppressDuplicate && nodeData->shouldSuppressDuplicatePacket()) {
|
if (!dontSuppressDuplicate && nodeData->shouldSuppressDuplicatePacket()) {
|
||||||
nodeData->resetOctreePacket(); // we still need to reset it though!
|
nodeData->resetOctreePacket(); // we still need to reset it though!
|
||||||
return packetsSent; // without sending...
|
return numPackets; // without sending...
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we've got a stats message ready to send, then see if we can piggyback them together
|
// If we've got a stats message ready to send, then see if we can piggyback them together
|
||||||
|
@ -163,12 +160,15 @@ int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode*
|
||||||
// copy octree message to back of stats message
|
// copy octree message to back of stats message
|
||||||
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getDataSize());
|
statsPacket.write(nodeData->getPacket().getData(), nodeData->getPacket().getDataSize());
|
||||||
|
|
||||||
// since a stats message is only included on end of scene, don't consider any of these bytes "wasted", since
|
int numBytes = statsPacket.getDataSize();
|
||||||
|
_totalBytes += numBytes;
|
||||||
|
_totalPackets++;
|
||||||
|
// since a stats message is only included on end of scene, don't consider any of these bytes "wasted"
|
||||||
// there was nothing else to send.
|
// there was nothing else to send.
|
||||||
int thisWastedBytes = 0;
|
int thisWastedBytes = 0;
|
||||||
_totalWastedBytes += thisWastedBytes;
|
//_totalWastedBytes += 0;
|
||||||
_totalBytes += statsPacket.getDataSize();
|
_trueBytesSent += numBytes;
|
||||||
_totalPackets++;
|
numPackets++;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
NLPacket& sentPacket = nodeData->getPacket();
|
NLPacket& sentPacket = nodeData->getPacket();
|
||||||
|
@ -191,18 +191,22 @@ int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode*
|
||||||
// actually send it
|
// actually send it
|
||||||
OctreeServer::didCallWriteDatagram(this);
|
OctreeServer::didCallWriteDatagram(this);
|
||||||
DependencyManager::get<NodeList>()->sendUnreliablePacket(statsPacket, *node);
|
DependencyManager::get<NodeList>()->sendUnreliablePacket(statsPacket, *node);
|
||||||
packetSent = true;
|
|
||||||
} else {
|
} else {
|
||||||
// not enough room in the packet, send two packets
|
// not enough room in the packet, send two packets
|
||||||
|
|
||||||
|
// first packet
|
||||||
OctreeServer::didCallWriteDatagram(this);
|
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
|
int numBytes = statsPacket.getDataSize();
|
||||||
|
_totalBytes += numBytes;
|
||||||
|
_totalPackets++;
|
||||||
|
// since a stats message is only included on end of scene, don't consider any of these bytes "wasted"
|
||||||
// there was nothing else to send.
|
// there was nothing else to send.
|
||||||
int thisWastedBytes = 0;
|
int thisWastedBytes = 0;
|
||||||
_totalWastedBytes += thisWastedBytes;
|
//_totalWastedBytes += 0;
|
||||||
_totalBytes += statsPacket.getDataSize();
|
_trueBytesSent += numBytes;
|
||||||
_totalPackets++;
|
numPackets++;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
NLPacket& sentPacket = nodeData->getPacket();
|
NLPacket& sentPacket = nodeData->getPacket();
|
||||||
|
@ -221,19 +225,18 @@ int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode*
|
||||||
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
|
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
trueBytesSent += statsPacket.getDataSize();
|
// second packet
|
||||||
truePacketsSent++;
|
|
||||||
packetsSent++;
|
|
||||||
|
|
||||||
OctreeServer::didCallWriteDatagram(this);
|
OctreeServer::didCallWriteDatagram(this);
|
||||||
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *node);
|
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *node);
|
||||||
packetSent = true;
|
|
||||||
|
|
||||||
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
|
numBytes = nodeData->getPacket().getDataSize();
|
||||||
thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader;
|
_totalBytes += numBytes;
|
||||||
_totalWastedBytes += thisWastedBytes;
|
|
||||||
_totalBytes += nodeData->getPacket().getDataSize();
|
|
||||||
_totalPackets++;
|
_totalPackets++;
|
||||||
|
// we count wasted bytes here because we were unable to fit the stats packet
|
||||||
|
thisWastedBytes = udt::MAX_PACKET_SIZE - numBytes;
|
||||||
|
_totalWastedBytes += thisWastedBytes;
|
||||||
|
_trueBytesSent += numBytes;
|
||||||
|
numPackets++;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
NLPacket& sentPacket = nodeData->getPacket();
|
NLPacket& sentPacket = nodeData->getPacket();
|
||||||
|
@ -259,13 +262,14 @@ int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode*
|
||||||
// just send the octree packet
|
// just send the octree packet
|
||||||
OctreeServer::didCallWriteDatagram(this);
|
OctreeServer::didCallWriteDatagram(this);
|
||||||
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *node);
|
DependencyManager::get<NodeList>()->sendUnreliablePacket(nodeData->getPacket(), *node);
|
||||||
packetSent = true;
|
|
||||||
|
|
||||||
int packetSizeWithHeader = nodeData->getPacket().getDataSize();
|
int numBytes = nodeData->getPacket().getDataSize();
|
||||||
int thisWastedBytes = udt::MAX_PACKET_SIZE - packetSizeWithHeader;
|
_totalBytes += numBytes;
|
||||||
_totalWastedBytes += thisWastedBytes;
|
|
||||||
_totalBytes += packetSizeWithHeader;
|
|
||||||
_totalPackets++;
|
_totalPackets++;
|
||||||
|
int thisWastedBytes = udt::MAX_PACKET_SIZE - numBytes;
|
||||||
|
_totalWastedBytes += thisWastedBytes;
|
||||||
|
numPackets++;
|
||||||
|
_trueBytesSent += numBytes;
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
NLPacket& sentPacket = nodeData->getPacket();
|
NLPacket& sentPacket = nodeData->getPacket();
|
||||||
|
@ -280,23 +284,21 @@ int OctreeSendThread::handlePacketSend(SharedNodePointer node, OctreeQueryNode*
|
||||||
|
|
||||||
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
|
qDebug() << "Sending packet at " << now << " [" << _totalPackets <<"]: sequence: " << sequence <<
|
||||||
" timestamp: " << timestamp <<
|
" timestamp: " << timestamp <<
|
||||||
" size: " << packetSizeWithHeader << " [" << _totalBytes <<
|
" size: " << numBytes << " [" << _totalBytes <<
|
||||||
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
|
"] wasted bytes:" << thisWastedBytes << " [" << _totalWastedBytes << "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remember to track our stats
|
// remember to track our stats
|
||||||
if (packetSent) {
|
if (numPackets > 0) {
|
||||||
nodeData->stats.packetSent(nodeData->getPacket().getPayloadSize());
|
nodeData->stats.packetSent(nodeData->getPacket().getPayloadSize());
|
||||||
trueBytesSent += nodeData->getPacket().getPayloadSize();
|
|
||||||
truePacketsSent++;
|
|
||||||
packetsSent++;
|
|
||||||
nodeData->octreePacketSent();
|
nodeData->octreePacketSent();
|
||||||
nodeData->resetOctreePacket();
|
nodeData->resetOctreePacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
return packetsSent;
|
_truePacketsSent += numPackets;
|
||||||
|
return numPackets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Version of octree element distributor that sends the deepest LOD level at once
|
/// Version of octree element distributor that sends the deepest LOD level at once
|
||||||
|
@ -315,13 +317,9 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
preDistributionProcessing();
|
preDistributionProcessing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate max number of packets that can be sent during this interval
|
_truePacketsSent = 0;
|
||||||
int clientMaxPacketsPerInterval = std::max(1, (nodeData->getMaxQueryPacketsPerSecond() / INTERVALS_PER_SECOND));
|
_trueBytesSent = 0;
|
||||||
int maxPacketsPerInterval = std::min(clientMaxPacketsPerInterval, _myServer->getPacketsPerClientPerInterval());
|
_packetsSentThisInterval = 0;
|
||||||
|
|
||||||
int truePacketsSent = 0;
|
|
||||||
int trueBytesSent = 0;
|
|
||||||
int packetsSentThisInterval = 0;
|
|
||||||
|
|
||||||
bool isFullScene = nodeData->shouldForceFullScene();
|
bool isFullScene = nodeData->shouldForceFullScene();
|
||||||
if (isFullScene) {
|
if (isFullScene) {
|
||||||
|
@ -334,17 +332,9 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
&& ((!viewFrustumChanged && nodeData->getViewFrustumJustStoppedChanging()) || nodeData->hasLodChanged()));
|
&& ((!viewFrustumChanged && nodeData->getViewFrustumJustStoppedChanging()) || nodeData->hasLodChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool somethingToSend = true; // assume we have something
|
|
||||||
|
|
||||||
// If our packet already has content in it, then we must use the color choice of the waiting packet.
|
|
||||||
// If we're starting a fresh packet, then...
|
|
||||||
// If we're moving, and the client asked for low res, then we force monochrome, otherwise, use
|
|
||||||
// the clients requested color state.
|
|
||||||
|
|
||||||
// If we have a packet waiting, and our desired want color, doesn't match the current waiting packets color
|
|
||||||
// then let's just send that waiting packet.
|
|
||||||
if (nodeData->isPacketWaiting()) {
|
if (nodeData->isPacketWaiting()) {
|
||||||
packetsSentThisInterval += handlePacketSend(node, nodeData, trueBytesSent, truePacketsSent);
|
// send the waiting packet
|
||||||
|
_packetsSentThisInterval += handlePacketSend(node, nodeData);
|
||||||
} else {
|
} else {
|
||||||
nodeData->resetOctreePacket();
|
nodeData->resetOctreePacket();
|
||||||
}
|
}
|
||||||
|
@ -375,8 +365,7 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
//unsigned long encodeTime = nodeData->stats.getTotalEncodeTime();
|
//unsigned long encodeTime = nodeData->stats.getTotalEncodeTime();
|
||||||
//unsigned long elapsedTime = nodeData->stats.getElapsedTime();
|
//unsigned long elapsedTime = nodeData->stats.getElapsedTime();
|
||||||
|
|
||||||
int packetsJustSent = handlePacketSend(node, nodeData, trueBytesSent, truePacketsSent, isFullScene);
|
_packetsSentThisInterval += handlePacketSend(node, nodeData, isFullScene);
|
||||||
packetsSentThisInterval += packetsJustSent;
|
|
||||||
|
|
||||||
// If we're starting a full scene, then definitely we want to empty the elementBag
|
// If we're starting a full scene, then definitely we want to empty the elementBag
|
||||||
if (isFullScene) {
|
if (isFullScene) {
|
||||||
|
@ -404,17 +393,81 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
|
|
||||||
// If we have something in our elementBag, then turn them into packets and send them out...
|
// If we have something in our elementBag, then turn them into packets and send them out...
|
||||||
if (!nodeData->elementBag.isEmpty()) {
|
if (!nodeData->elementBag.isEmpty()) {
|
||||||
int bytesWritten = 0;
|
|
||||||
quint64 start = usecTimestampNow();
|
quint64 start = usecTimestampNow();
|
||||||
|
|
||||||
// TODO: add these to stats page
|
traverseTreeAndSendContents(node, nodeData, viewFrustumChanged, isFullScene);
|
||||||
//quint64 startCompressTimeMsecs = OctreePacketData::getCompressContentTime() / 1000;
|
|
||||||
//quint64 startCompressCalls = OctreePacketData::getCompressContentCalls();
|
// Here's where we can/should allow the server to send other data...
|
||||||
|
// send the environment packet
|
||||||
|
// TODO: should we turn this into a while loop to better handle sending multiple special packets
|
||||||
|
if (_myServer->hasSpecialPacketsToSend(node) && !nodeData->isShuttingDown()) {
|
||||||
|
int specialPacketsSent = 0;
|
||||||
|
int specialBytesSent = _myServer->sendSpecialPackets(node, nodeData, specialPacketsSent);
|
||||||
|
nodeData->resetOctreePacket(); // because nodeData's _sequenceNumber has changed
|
||||||
|
_truePacketsSent += specialPacketsSent;
|
||||||
|
_trueBytesSent += specialBytesSent;
|
||||||
|
_packetsSentThisInterval += specialPacketsSent;
|
||||||
|
|
||||||
|
_totalPackets += specialPacketsSent;
|
||||||
|
_totalBytes += specialBytesSent;
|
||||||
|
|
||||||
|
_totalSpecialPackets += specialPacketsSent;
|
||||||
|
_totalSpecialBytes += specialBytesSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate max number of packets that can be sent during this interval
|
||||||
|
int clientMaxPacketsPerInterval = std::max(1, (nodeData->getMaxQueryPacketsPerSecond() / INTERVALS_PER_SECOND));
|
||||||
|
int maxPacketsPerInterval = std::min(clientMaxPacketsPerInterval, _myServer->getPacketsPerClientPerInterval());
|
||||||
|
|
||||||
|
// Re-send packets that were nacked by the client
|
||||||
|
while (nodeData->hasNextNackedPacket() && _packetsSentThisInterval < maxPacketsPerInterval) {
|
||||||
|
const NLPacket* packet = nodeData->getNextNackedPacket();
|
||||||
|
if (packet) {
|
||||||
|
DependencyManager::get<NodeList>()->sendUnreliablePacket(*packet, *node);
|
||||||
|
int numBytes = packet->getDataSize();
|
||||||
|
_truePacketsSent++;
|
||||||
|
_trueBytesSent += numBytes;
|
||||||
|
_packetsSentThisInterval++;
|
||||||
|
|
||||||
|
_totalPackets++;
|
||||||
|
_totalBytes += numBytes;
|
||||||
|
_totalWastedBytes += udt::MAX_PACKET_SIZE - packet->getDataSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
quint64 end = usecTimestampNow();
|
||||||
|
int elapsedmsec = (end - start) / USECS_PER_MSEC;
|
||||||
|
OctreeServer::trackLoopTime(elapsedmsec);
|
||||||
|
|
||||||
|
// if after sending packets we've emptied our bag, then we want to remember that we've sent all
|
||||||
|
// the octree elements from the current view frustum
|
||||||
|
if (nodeData->elementBag.isEmpty()) {
|
||||||
|
nodeData->updateLastKnownViewFrustum();
|
||||||
|
nodeData->setViewSent(true);
|
||||||
|
|
||||||
|
// If this was a full scene then make sure we really send out a stats packet at this point so that
|
||||||
|
// the clients will know the scene is stable
|
||||||
|
if (isFullScene) {
|
||||||
|
nodeData->stats.sceneCompleted();
|
||||||
|
handlePacketSend(node, nodeData, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end if bag wasn't empty, and so we sent stuff...
|
||||||
|
|
||||||
|
return _truePacketsSent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OctreeSendThread::traverseTreeAndSendContents(SharedNodePointer node, OctreeQueryNode* nodeData, bool viewFrustumChanged, bool isFullScene) {
|
||||||
|
// calculate max number of packets that can be sent during this interval
|
||||||
|
int clientMaxPacketsPerInterval = std::max(1, (nodeData->getMaxQueryPacketsPerSecond() / INTERVALS_PER_SECOND));
|
||||||
|
int maxPacketsPerInterval = std::min(clientMaxPacketsPerInterval, _myServer->getPacketsPerClientPerInterval());
|
||||||
|
|
||||||
int extraPackingAttempts = 0;
|
int extraPackingAttempts = 0;
|
||||||
bool completedScene = false;
|
bool completedScene = false;
|
||||||
|
|
||||||
while (somethingToSend && packetsSentThisInterval < maxPacketsPerInterval && !nodeData->isShuttingDown()) {
|
bool somethingToSend = true; // assume we have something
|
||||||
|
while (somethingToSend && _packetsSentThisInterval < maxPacketsPerInterval && !nodeData->isShuttingDown()) {
|
||||||
float lockWaitElapsedUsec = OctreeServer::SKIP_TIME;
|
float lockWaitElapsedUsec = OctreeServer::SKIP_TIME;
|
||||||
float encodeElapsedUsec = OctreeServer::SKIP_TIME;
|
float encodeElapsedUsec = OctreeServer::SKIP_TIME;
|
||||||
float compressAndWriteElapsedUsec = OctreeServer::SKIP_TIME;
|
float compressAndWriteElapsedUsec = OctreeServer::SKIP_TIME;
|
||||||
|
@ -452,8 +505,8 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
|
|
||||||
// Our trackSend() function is implemented by the server subclass, and will be called back
|
// Our trackSend() function is implemented by the server subclass, and will be called back
|
||||||
// during the encodeTreeBitstream() as new entities/data elements are sent
|
// during the encodeTreeBitstream() as new entities/data elements are sent
|
||||||
params.trackSend = [this, node](const QUuid& dataID, quint64 dataEdited) {
|
params.trackSend = [this](const QUuid& dataID, quint64 dataEdited) {
|
||||||
_myServer->trackSend(dataID, dataEdited, node->getUUID());
|
_myServer->trackSend(dataID, dataEdited, _nodeUuid);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: should this include the lock time or not? This stat is sent down to the client,
|
// TODO: should this include the lock time or not? This stat is sent down to the client,
|
||||||
|
@ -461,7 +514,8 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
// are reported to client. Since you can encode without the lock
|
// are reported to client. Since you can encode without the lock
|
||||||
nodeData->stats.encodeStarted();
|
nodeData->stats.encodeStarted();
|
||||||
|
|
||||||
bytesWritten = _myServer->getOctree()->encodeTreeBitstream(subTree, &_packetData, nodeData->elementBag, params);
|
// NOTE: this is where the tree "contents" are actaully packed
|
||||||
|
_myServer->getOctree()->encodeTreeBitstream(subTree, &_packetData, nodeData->elementBag, params);
|
||||||
|
|
||||||
quint64 encodeEnd = usecTimestampNow();
|
quint64 encodeEnd = usecTimestampNow();
|
||||||
encodeElapsedUsec = (float)(encodeEnd - encodeStart);
|
encodeElapsedUsec = (float)(encodeEnd - encodeStart);
|
||||||
|
@ -479,66 +533,48 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
nodeData->stats.encodeStopped();
|
nodeData->stats.encodeStopped();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// If the bag was empty then we didn't even attempt to encode, and so we know the bytesWritten were 0
|
|
||||||
bytesWritten = 0;
|
|
||||||
somethingToSend = false; // this will cause us to drop out of the loop...
|
somethingToSend = false; // this will cause us to drop out of the loop...
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the last node didn't fit, but we're in compressed mode, then we actually want to see if we can fit a
|
|
||||||
// little bit more in this packet. To do this we write into the packet, but don't send it yet, we'll
|
|
||||||
// keep attempting to write in compressed mode to add more compressed segments
|
|
||||||
|
|
||||||
// We only consider sending anything if there is something in the _packetData to send... But
|
|
||||||
// if bytesWritten == 0 it means either the subTree couldn't fit or we had an empty bag... Both cases
|
|
||||||
// mean we should send the previous packet contents and reset it.
|
|
||||||
if (completedScene || lastNodeDidntFit) {
|
if (completedScene || lastNodeDidntFit) {
|
||||||
|
// we probably want to flush what has accumulated in nodeData but:
|
||||||
|
// do we have more data to send? and is there room?
|
||||||
if (_packetData.hasContent()) {
|
if (_packetData.hasContent()) {
|
||||||
|
// yes, more data to send
|
||||||
quint64 compressAndWriteStart = usecTimestampNow();
|
quint64 compressAndWriteStart = usecTimestampNow();
|
||||||
|
unsigned int additionalSize = _packetData.getFinalizedSize() + sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE);
|
||||||
// if for some reason the finalized size is greater than our available size, then probably the "compressed"
|
if (additionalSize > nodeData->getAvailable()) {
|
||||||
// form actually inflated beyond our padding, and in this case we will send the current packet, then
|
// no room --> flush what we've got
|
||||||
// write to out new packet...
|
_packetsSentThisInterval += handlePacketSend(node, nodeData);
|
||||||
unsigned int writtenSize = _packetData.getFinalizedSize() + sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE);
|
|
||||||
|
|
||||||
if (writtenSize > nodeData->getAvailable()) {
|
|
||||||
packetsSentThisInterval += handlePacketSend(node, nodeData, trueBytesSent, truePacketsSent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// either there is room, or we've flushed and reset nodeData's data buffer
|
||||||
|
// so we can transfer whatever is in _packetData to nodeData
|
||||||
nodeData->writeToPacket(_packetData.getFinalizedData(), _packetData.getFinalizedSize());
|
nodeData->writeToPacket(_packetData.getFinalizedData(), _packetData.getFinalizedSize());
|
||||||
quint64 compressAndWriteEnd = usecTimestampNow();
|
compressAndWriteElapsedUsec = (float)(usecTimestampNow()- compressAndWriteStart);
|
||||||
compressAndWriteElapsedUsec = (float)(compressAndWriteEnd - compressAndWriteStart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're not running compressed, then we know we can just send now. Or if we're running compressed, but
|
bool sendNow = completedScene ||
|
||||||
// the packet doesn't have enough space to bother attempting to pack more...
|
nodeData->getAvailable() < MINIMUM_ATTEMPT_MORE_PACKING ||
|
||||||
bool sendNow = true;
|
extraPackingAttempts > REASONABLE_NUMBER_OF_PACKING_ATTEMPTS;
|
||||||
|
|
||||||
if (!completedScene && (nodeData->getAvailable() >= MINIMUM_ATTEMPT_MORE_PACKING &&
|
|
||||||
extraPackingAttempts <= REASONABLE_NUMBER_OF_PACKING_ATTEMPTS)) {
|
|
||||||
sendNow = false; // try to pack more
|
|
||||||
}
|
|
||||||
|
|
||||||
int targetSize = MAX_OCTREE_PACKET_DATA_SIZE;
|
int targetSize = MAX_OCTREE_PACKET_DATA_SIZE;
|
||||||
if (sendNow) {
|
if (sendNow) {
|
||||||
quint64 packetSendingStart = usecTimestampNow();
|
quint64 packetSendingStart = usecTimestampNow();
|
||||||
packetsSentThisInterval += handlePacketSend(node, nodeData, trueBytesSent, truePacketsSent);
|
_packetsSentThisInterval += handlePacketSend(node, nodeData);
|
||||||
quint64 packetSendingEnd = usecTimestampNow();
|
quint64 packetSendingEnd = usecTimestampNow();
|
||||||
packetSendingElapsedUsec = (float)(packetSendingEnd - packetSendingStart);
|
packetSendingElapsedUsec = (float)(packetSendingEnd - packetSendingStart);
|
||||||
|
|
||||||
targetSize = nodeData->getAvailable() - sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE);
|
targetSize = nodeData->getAvailable() - sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE);
|
||||||
extraPackingAttempts = 0;
|
extraPackingAttempts = 0;
|
||||||
} else {
|
} else {
|
||||||
// If we're in compressed mode, then we want to see if we have room for more in this wire packet.
|
// We want to see if we have room for more in this wire packet but we've copied the _packetData,
|
||||||
// but we've finalized the _packetData, so we want to start a new section, we will do that by
|
// so we want to start a new section. We will do that by resetting the packet settings with the max
|
||||||
// resetting the packet settings with the max uncompressed size of our current available space
|
// size of our current available space in the wire packet plus room for our section header and a
|
||||||
// in the wire packet. We also include room for our section header, and a little bit of padding
|
// little bit of padding.
|
||||||
// to account for the fact that whenc compressing small amounts of data, we sometimes end up with
|
|
||||||
// a larger compressed size then uncompressed size
|
|
||||||
targetSize = nodeData->getAvailable() - sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE) - COMPRESS_PADDING;
|
targetSize = nodeData->getAvailable() - sizeof(OCTREE_PACKET_INTERNAL_SECTION_SIZE) - COMPRESS_PADDING;
|
||||||
}
|
}
|
||||||
_packetData.changeSettings(true, targetSize); // will do reset - NOTE: Always compressed
|
_packetData.changeSettings(true, targetSize); // will do reset - NOTE: Always compressed
|
||||||
|
|
||||||
}
|
}
|
||||||
OctreeServer::trackTreeWaitTime(lockWaitElapsedUsec);
|
OctreeServer::trackTreeWaitTime(lockWaitElapsedUsec);
|
||||||
OctreeServer::trackEncodeTime(encodeElapsedUsec);
|
OctreeServer::trackEncodeTime(encodeElapsedUsec);
|
||||||
|
@ -551,72 +587,8 @@ int OctreeSendThread::packetDistributor(SharedNodePointer node, OctreeQueryNode*
|
||||||
}
|
}
|
||||||
|
|
||||||
if (somethingToSend && _myServer->wantsVerboseDebug()) {
|
if (somethingToSend && _myServer->wantsVerboseDebug()) {
|
||||||
qCDebug(octree) << "Hit PPS Limit, packetsSentThisInterval =" << packetsSentThisInterval
|
qCDebug(octree) << "Hit PPS Limit, packetsSentThisInterval =" << _packetsSentThisInterval
|
||||||
<< " maxPacketsPerInterval = " << maxPacketsPerInterval
|
<< " maxPacketsPerInterval = " << maxPacketsPerInterval
|
||||||
<< " clientMaxPacketsPerInterval = " << clientMaxPacketsPerInterval;
|
<< " clientMaxPacketsPerInterval = " << clientMaxPacketsPerInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here's where we can/should allow the server to send other data...
|
|
||||||
// send the environment packet
|
|
||||||
// TODO: should we turn this into a while loop to better handle sending multiple special packets
|
|
||||||
if (_myServer->hasSpecialPacketsToSend(node) && !nodeData->isShuttingDown()) {
|
|
||||||
int specialPacketsSent = 0;
|
|
||||||
trueBytesSent += _myServer->sendSpecialPackets(node, nodeData, specialPacketsSent);
|
|
||||||
nodeData->resetOctreePacket(); // because nodeData's _sequenceNumber has changed
|
|
||||||
truePacketsSent += specialPacketsSent;
|
|
||||||
packetsSentThisInterval += specialPacketsSent;
|
|
||||||
|
|
||||||
_totalPackets += specialPacketsSent;
|
|
||||||
_totalBytes += trueBytesSent;
|
|
||||||
|
|
||||||
_totalSpecialPackets += specialPacketsSent;
|
|
||||||
_totalSpecialBytes += trueBytesSent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-send packets that were nacked by the client
|
|
||||||
while (nodeData->hasNextNackedPacket() && packetsSentThisInterval < maxPacketsPerInterval) {
|
|
||||||
const NLPacket* packet = nodeData->getNextNackedPacket();
|
|
||||||
if (packet) {
|
|
||||||
DependencyManager::get<NodeList>()->sendUnreliablePacket(*packet, *node);
|
|
||||||
truePacketsSent++;
|
|
||||||
packetsSentThisInterval++;
|
|
||||||
|
|
||||||
_totalBytes += packet->getDataSize();
|
|
||||||
_totalPackets++;
|
|
||||||
_totalWastedBytes += udt::MAX_PACKET_SIZE - packet->getDataSize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
quint64 end = usecTimestampNow();
|
|
||||||
int elapsedmsec = (end - start) / USECS_PER_MSEC;
|
|
||||||
OctreeServer::trackLoopTime(elapsedmsec);
|
|
||||||
|
|
||||||
// TODO: add these to stats page
|
|
||||||
//quint64 endCompressCalls = OctreePacketData::getCompressContentCalls();
|
|
||||||
//int elapsedCompressCalls = endCompressCalls - startCompressCalls;
|
|
||||||
//quint64 endCompressTimeMsecs = OctreePacketData::getCompressContentTime() / 1000;
|
|
||||||
//int elapsedCompressTimeMsecs = endCompressTimeMsecs - startCompressTimeMsecs;
|
|
||||||
|
|
||||||
// if after sending packets we've emptied our bag, then we want to remember that we've sent all
|
|
||||||
// the octree elements from the current view frustum
|
|
||||||
if (nodeData->elementBag.isEmpty()) {
|
|
||||||
nodeData->updateLastKnownViewFrustum();
|
|
||||||
nodeData->setViewSent(true);
|
|
||||||
|
|
||||||
// If this was a full scene then make sure we really send out a stats packet at this point so that
|
|
||||||
// the clients will know the scene is stable
|
|
||||||
if (isFullScene) {
|
|
||||||
int thisTrueBytesSent = 0;
|
|
||||||
int thisTruePacketsSent = 0;
|
|
||||||
nodeData->stats.sceneCompleted();
|
|
||||||
int packetsJustSent = handlePacketSend(node, nodeData, thisTrueBytesSent, thisTruePacketsSent, true);
|
|
||||||
_totalBytes += thisTrueBytesSent;
|
|
||||||
_totalPackets += thisTruePacketsSent;
|
|
||||||
truePacketsSent += packetsJustSent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end if bag wasn't empty, and so we sent stuff...
|
|
||||||
|
|
||||||
return truePacketsSent;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,12 +53,13 @@ protected:
|
||||||
|
|
||||||
/// Called before a packetDistributor pass to allow for pre-distribution processing
|
/// Called before a packetDistributor pass to allow for pre-distribution processing
|
||||||
virtual void preDistributionProcessing() {};
|
virtual void preDistributionProcessing() {};
|
||||||
|
virtual void traverseTreeAndSendContents(SharedNodePointer node, OctreeQueryNode* nodeData, bool viewFrustumChanged, bool isFullScene);
|
||||||
|
|
||||||
OctreeServer* _myServer { nullptr };
|
OctreeServer* _myServer { nullptr };
|
||||||
QWeakPointer<Node> _node;
|
QWeakPointer<Node> _node;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int handlePacketSend(SharedNodePointer node, OctreeQueryNode* nodeData, int& trueBytesSent, int& truePacketsSent, bool dontSuppressDuplicate = false);
|
int handlePacketSend(SharedNodePointer node, OctreeQueryNode* nodeData, bool dontSuppressDuplicate = false);
|
||||||
int packetDistributor(SharedNodePointer node, OctreeQueryNode* nodeData, bool viewFrustumChanged);
|
int packetDistributor(SharedNodePointer node, OctreeQueryNode* nodeData, bool viewFrustumChanged);
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +67,9 @@ private:
|
||||||
|
|
||||||
OctreePacketData _packetData;
|
OctreePacketData _packetData;
|
||||||
|
|
||||||
int _nodeMissingCount { 0 };
|
int _truePacketsSent { 0 }; // available for debug stats
|
||||||
|
int _trueBytesSent { 0 }; // available for debug stats
|
||||||
|
int _packetsSentThisInterval { 0 }; // used for bandwidth throttle condition
|
||||||
bool _isShuttingDown { false };
|
bool _isShuttingDown { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -678,7 +678,7 @@ private:
|
||||||
QTimer _addAssetToWorldErrorTimer;
|
QTimer _addAssetToWorldErrorTimer;
|
||||||
|
|
||||||
FileScriptingInterface* _fileDownload;
|
FileScriptingInterface* _fileDownload;
|
||||||
AudioInjector* _snapshotSoundInjector { nullptr };
|
AudioInjectorPointer _snapshotSoundInjector;
|
||||||
SharedSoundPointer _snapshotSound;
|
SharedSoundPointer _snapshotSound;
|
||||||
|
|
||||||
DisplayPluginPointer _autoSwitchDisplayModeSupportedHMDPlugin;
|
DisplayPluginPointer _autoSwitchDisplayModeSupportedHMDPlugin;
|
||||||
|
|
|
@ -680,7 +680,7 @@ Menu::Menu() {
|
||||||
// Developer > Physics >>>
|
// Developer > Physics >>>
|
||||||
MenuWrapper* physicsOptionsMenu = developerMenu->addMenu("Physics");
|
MenuWrapper* physicsOptionsMenu = developerMenu->addMenu("Physics");
|
||||||
{
|
{
|
||||||
auto drawStatusConfig = qApp->getRenderEngine()->getConfiguration()->getConfig<render::DrawStatus>();
|
auto drawStatusConfig = qApp->getRenderEngine()->getConfiguration()->getConfig<render::DrawStatus>("RenderMainView.DrawStatus");
|
||||||
addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowOwned,
|
addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowOwned,
|
||||||
0, false, drawStatusConfig, SLOT(setShowNetwork(bool)));
|
0, false, drawStatusConfig, SLOT(setShowNetwork(bool)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -433,8 +433,7 @@ void AvatarManager::handleCollisionEvents(const CollisionEvents& collisionEvents
|
||||||
// but most avatars are roughly the same size, so let's not be so fancy yet.
|
// but most avatars are roughly the same size, so let's not be so fancy yet.
|
||||||
const float AVATAR_STRETCH_FACTOR = 1.0f;
|
const float AVATAR_STRETCH_FACTOR = 1.0f;
|
||||||
|
|
||||||
|
_collisionInjectors.remove_if([](const AudioInjectorPointer& injector) {
|
||||||
_collisionInjectors.remove_if([](QPointer<AudioInjector>& injector) {
|
|
||||||
return !injector || injector->isFinished();
|
return !injector || injector->isFinished();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@
|
||||||
#include <SimpleMovingAverage.h>
|
#include <SimpleMovingAverage.h>
|
||||||
#include <shared/RateCounter.h>
|
#include <shared/RateCounter.h>
|
||||||
#include <avatars-renderer/ScriptAvatar.h>
|
#include <avatars-renderer/ScriptAvatar.h>
|
||||||
|
#include <AudioInjector.h>
|
||||||
|
|
||||||
#include "AvatarMotionState.h"
|
#include "AvatarMotionState.h"
|
||||||
#include "MyAvatar.h"
|
#include "MyAvatar.h"
|
||||||
|
|
||||||
class AudioInjector;
|
|
||||||
|
|
||||||
class AvatarManager : public AvatarHashMap {
|
class AvatarManager : public AvatarHashMap {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -104,7 +104,7 @@ private:
|
||||||
std::shared_ptr<MyAvatar> _myAvatar;
|
std::shared_ptr<MyAvatar> _myAvatar;
|
||||||
quint64 _lastSendAvatarDataTime = 0; // Controls MyAvatar send data rate.
|
quint64 _lastSendAvatarDataTime = 0; // Controls MyAvatar send data rate.
|
||||||
|
|
||||||
std::list<QPointer<AudioInjector>> _collisionInjectors;
|
std::list<AudioInjectorPointer> _collisionInjectors;
|
||||||
|
|
||||||
RateCounter<> _myAvatarSendRate;
|
RateCounter<> _myAvatarSendRate;
|
||||||
int _numAvatarsUpdated { 0 };
|
int _numAvatarsUpdated { 0 };
|
||||||
|
|
|
@ -1203,11 +1203,11 @@ bool AudioClient::mixLocalAudioInjectors(float* mixBuffer) {
|
||||||
// lock the injectors
|
// lock the injectors
|
||||||
Lock lock(_injectorsMutex);
|
Lock lock(_injectorsMutex);
|
||||||
|
|
||||||
QVector<AudioInjector*> injectorsToRemove;
|
QVector<AudioInjectorPointer> injectorsToRemove;
|
||||||
|
|
||||||
memset(mixBuffer, 0, AudioConstants::NETWORK_FRAME_SAMPLES_STEREO * sizeof(float));
|
memset(mixBuffer, 0, AudioConstants::NETWORK_FRAME_SAMPLES_STEREO * sizeof(float));
|
||||||
|
|
||||||
for (AudioInjector* injector : _activeLocalAudioInjectors) {
|
for (const AudioInjectorPointer& injector : _activeLocalAudioInjectors) {
|
||||||
// the lock guarantees that injectorBuffer, if found, is invariant
|
// the lock guarantees that injectorBuffer, if found, is invariant
|
||||||
AudioInjectorLocalBuffer* injectorBuffer = injector->getLocalBuffer();
|
AudioInjectorLocalBuffer* injectorBuffer = injector->getLocalBuffer();
|
||||||
if (injectorBuffer) {
|
if (injectorBuffer) {
|
||||||
|
@ -1278,7 +1278,7 @@ bool AudioClient::mixLocalAudioInjectors(float* mixBuffer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (AudioInjector* injector : injectorsToRemove) {
|
for (const AudioInjectorPointer& injector : injectorsToRemove) {
|
||||||
qCDebug(audioclient) << "removing injector";
|
qCDebug(audioclient) << "removing injector";
|
||||||
_activeLocalAudioInjectors.removeOne(injector);
|
_activeLocalAudioInjectors.removeOne(injector);
|
||||||
}
|
}
|
||||||
|
@ -1369,7 +1369,7 @@ void AudioClient::setIsStereoInput(bool isStereoInput) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioClient::outputLocalInjector(AudioInjector* injector) {
|
bool AudioClient::outputLocalInjector(const AudioInjectorPointer& injector) {
|
||||||
AudioInjectorLocalBuffer* injectorBuffer = injector->getLocalBuffer();
|
AudioInjectorLocalBuffer* injectorBuffer = injector->getLocalBuffer();
|
||||||
if (injectorBuffer) {
|
if (injectorBuffer) {
|
||||||
// local injectors are on the AudioInjectorsThread, so we must guard access
|
// local injectors are on the AudioInjectorsThread, so we must guard access
|
||||||
|
|
|
@ -143,7 +143,7 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void setAvatarBoundingBoxParameters(glm::vec3 corner, glm::vec3 scale);
|
Q_INVOKABLE void setAvatarBoundingBoxParameters(glm::vec3 corner, glm::vec3 scale);
|
||||||
|
|
||||||
bool outputLocalInjector(AudioInjector* injector) override;
|
bool outputLocalInjector(const AudioInjectorPointer& injector) override;
|
||||||
|
|
||||||
QAudioDeviceInfo getActiveAudioDevice(QAudio::Mode mode) const;
|
QAudioDeviceInfo getActiveAudioDevice(QAudio::Mode mode) const;
|
||||||
QList<QAudioDeviceInfo> getAudioDevices(QAudio::Mode mode) const;
|
QList<QAudioDeviceInfo> getAudioDevices(QAudio::Mode mode) const;
|
||||||
|
@ -380,7 +380,7 @@ private:
|
||||||
|
|
||||||
bool _hasReceivedFirstPacket { false };
|
bool _hasReceivedFirstPacket { false };
|
||||||
|
|
||||||
QVector<AudioInjector*> _activeLocalAudioInjectors;
|
QVector<AudioInjectorPointer> _activeLocalAudioInjectors;
|
||||||
|
|
||||||
bool _isPlayingBackRecording { false };
|
bool _isPlayingBackRecording { false };
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <udt/PacketHeaders.h>
|
#include <udt/PacketHeaders.h>
|
||||||
|
|
||||||
#include "AudioInjectorOptions.h"
|
#include "AudioInjectorOptions.h"
|
||||||
|
#include "AudioInjector.h"
|
||||||
|
|
||||||
class AudioInjector;
|
class AudioInjector;
|
||||||
class AudioInjectorLocalBuffer;
|
class AudioInjectorLocalBuffer;
|
||||||
|
@ -35,7 +36,7 @@ public:
|
||||||
// threadsafe
|
// threadsafe
|
||||||
// moves injector->getLocalBuffer() to another thread (so removes its parent)
|
// moves injector->getLocalBuffer() to another thread (so removes its parent)
|
||||||
// take care to delete it when ~AudioInjector, as parenting Qt semantics will not work
|
// take care to delete it when ~AudioInjector, as parenting Qt semantics will not work
|
||||||
virtual bool outputLocalInjector(AudioInjector* injector) = 0;
|
virtual bool outputLocalInjector(const AudioInjectorPointer& injector) = 0;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual bool shouldLoopbackInjectors() { return false; }
|
virtual bool shouldLoopbackInjectors() { return false; }
|
||||||
|
|
|
@ -92,11 +92,6 @@ void AudioInjector::finish() {
|
||||||
emit finished();
|
emit finished();
|
||||||
|
|
||||||
deleteLocalBuffer();
|
deleteLocalBuffer();
|
||||||
|
|
||||||
if (stateHas(AudioInjectorState::PendingDelete)) {
|
|
||||||
// we've been asked to delete after finishing, trigger a deleteLater here
|
|
||||||
deleteLater();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::restart() {
|
void AudioInjector::restart() {
|
||||||
|
@ -132,7 +127,7 @@ void AudioInjector::restart() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioInjector::inject(bool(AudioInjectorManager::*injection)(AudioInjector*)) {
|
bool AudioInjector::inject(bool(AudioInjectorManager::*injection)(const AudioInjectorPointer&)) {
|
||||||
_state = AudioInjectorState::NotFinished;
|
_state = AudioInjectorState::NotFinished;
|
||||||
|
|
||||||
int byteOffset = 0;
|
int byteOffset = 0;
|
||||||
|
@ -150,7 +145,7 @@ bool AudioInjector::inject(bool(AudioInjectorManager::*injection)(AudioInjector*
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if (!_options.localOnly) {
|
if (!_options.localOnly) {
|
||||||
auto injectorManager = DependencyManager::get<AudioInjectorManager>();
|
auto injectorManager = DependencyManager::get<AudioInjectorManager>();
|
||||||
if (!(*injectorManager.*injection)(this)) {
|
if (!(*injectorManager.*injection)(sharedFromThis())) {
|
||||||
success = false;
|
success = false;
|
||||||
finishNetworkInjection();
|
finishNetworkInjection();
|
||||||
}
|
}
|
||||||
|
@ -173,7 +168,7 @@ bool AudioInjector::injectLocally() {
|
||||||
|
|
||||||
// call this function on the AudioClient's thread
|
// call this function on the AudioClient's thread
|
||||||
// this will move the local buffer's thread to the LocalInjectorThread
|
// this will move the local buffer's thread to the LocalInjectorThread
|
||||||
success = _localAudioInterface->outputLocalInjector(this);
|
success = _localAudioInterface->outputLocalInjector(sharedFromThis());
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
qCDebug(audio) << "AudioInjector::injectLocally could not output locally via _localAudioInterface";
|
qCDebug(audio) << "AudioInjector::injectLocally could not output locally via _localAudioInterface";
|
||||||
|
@ -418,20 +413,16 @@ void AudioInjector::triggerDeleteAfterFinish() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stateHas(AudioInjectorState::Finished)) {
|
if (stateHas(AudioInjectorState::Finished)) {
|
||||||
stopAndDeleteLater();
|
stop();
|
||||||
} else {
|
} else {
|
||||||
_state |= AudioInjectorState::PendingDelete;
|
_state |= AudioInjectorState::PendingDelete;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInjector::stopAndDeleteLater() {
|
AudioInjectorPointer AudioInjector::playSound(SharedSoundPointer sound, const float volume,
|
||||||
stop();
|
const float stretchFactor, const glm::vec3 position) {
|
||||||
QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioInjector* AudioInjector::playSound(SharedSoundPointer sound, const float volume, const float stretchFactor, const glm::vec3 position) {
|
|
||||||
if (!sound || !sound->isReady()) {
|
if (!sound || !sound->isReady()) {
|
||||||
return nullptr;
|
return AudioInjectorPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjectorOptions options;
|
AudioInjectorOptions options;
|
||||||
|
@ -462,8 +453,8 @@ AudioInjector* AudioInjector::playSound(SharedSoundPointer sound, const float vo
|
||||||
return playSoundAndDelete(resampled, options);
|
return playSoundAndDelete(resampled, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioInjector* AudioInjector::playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options) {
|
AudioInjectorPointer AudioInjector::playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options) {
|
||||||
AudioInjector* sound = playSound(buffer, options);
|
AudioInjectorPointer sound = playSound(buffer, options);
|
||||||
|
|
||||||
if (sound) {
|
if (sound) {
|
||||||
sound->_state |= AudioInjectorState::PendingDelete;
|
sound->_state |= AudioInjectorState::PendingDelete;
|
||||||
|
@ -473,8 +464,9 @@ AudioInjector* AudioInjector::playSoundAndDelete(const QByteArray& buffer, const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options) {
|
AudioInjectorPointer AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options) {
|
||||||
AudioInjector* injector = new AudioInjector(buffer, options);
|
AudioInjectorPointer injector = AudioInjectorPointer::create(buffer, options);
|
||||||
|
|
||||||
if (!injector->inject(&AudioInjectorManager::threadInjector)) {
|
if (!injector->inject(&AudioInjectorManager::threadInjector)) {
|
||||||
qWarning() << "AudioInjector::playSound failed to thread injector";
|
qWarning() << "AudioInjector::playSound failed to thread injector";
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
class AbstractAudioInterface;
|
class AbstractAudioInterface;
|
||||||
class AudioInjectorManager;
|
class AudioInjectorManager;
|
||||||
|
class AudioInjector;
|
||||||
|
using AudioInjectorPointer = QSharedPointer<AudioInjector>;
|
||||||
|
|
||||||
|
|
||||||
enum class AudioInjectorState : uint8_t {
|
enum class AudioInjectorState : uint8_t {
|
||||||
|
@ -47,7 +49,7 @@ AudioInjectorState& operator|= (AudioInjectorState& lhs, AudioInjectorState rhs)
|
||||||
|
|
||||||
// In order to make scripting cleaner for the AudioInjector, the script now holds on to the AudioInjector object
|
// In order to make scripting cleaner for the AudioInjector, the script now holds on to the AudioInjector object
|
||||||
// until it dies.
|
// until it dies.
|
||||||
class AudioInjector : public QObject {
|
class AudioInjector : public QObject, public QEnableSharedFromThis<AudioInjector> {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AudioInjector(const Sound& sound, const AudioInjectorOptions& injectorOptions);
|
AudioInjector(const Sound& sound, const AudioInjectorOptions& injectorOptions);
|
||||||
|
@ -72,16 +74,16 @@ public:
|
||||||
|
|
||||||
bool stateHas(AudioInjectorState state) const ;
|
bool stateHas(AudioInjectorState state) const ;
|
||||||
static void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
|
static void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
|
||||||
static AudioInjector* playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options);
|
static AudioInjectorPointer playSoundAndDelete(const QByteArray& buffer, const AudioInjectorOptions options);
|
||||||
static AudioInjector* playSound(const QByteArray& buffer, const AudioInjectorOptions options);
|
static AudioInjectorPointer playSound(const QByteArray& buffer, const AudioInjectorOptions options);
|
||||||
static AudioInjector* playSound(SharedSoundPointer sound, const float volume, const float stretchFactor, const glm::vec3 position);
|
static AudioInjectorPointer playSound(SharedSoundPointer sound, const float volume,
|
||||||
|
const float stretchFactor, const glm::vec3 position);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void restart();
|
void restart();
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
void triggerDeleteAfterFinish();
|
void triggerDeleteAfterFinish();
|
||||||
void stopAndDeleteLater();
|
|
||||||
|
|
||||||
const AudioInjectorOptions& getOptions() const { return _options; }
|
const AudioInjectorOptions& getOptions() const { return _options; }
|
||||||
void setOptions(const AudioInjectorOptions& options);
|
void setOptions(const AudioInjectorOptions& options);
|
||||||
|
@ -98,7 +100,7 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int64_t injectNextFrame();
|
int64_t injectNextFrame();
|
||||||
bool inject(bool(AudioInjectorManager::*injection)(AudioInjector*));
|
bool inject(bool(AudioInjectorManager::*injection)(const AudioInjectorPointer&));
|
||||||
bool injectLocally();
|
bool injectLocally();
|
||||||
void deleteLocalBuffer();
|
void deleteLocalBuffer();
|
||||||
|
|
||||||
|
@ -123,6 +125,6 @@ private:
|
||||||
friend class AudioInjectorManager;
|
friend class AudioInjectorManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(AudioInjector*)
|
Q_DECLARE_METATYPE(AudioInjectorPointer)
|
||||||
|
|
||||||
#endif // hifi_AudioInjector_h
|
#endif // hifi_AudioInjector_h
|
||||||
|
|
|
@ -30,7 +30,7 @@ AudioInjectorManager::~AudioInjectorManager() {
|
||||||
auto& timePointerPair = _injectors.top();
|
auto& timePointerPair = _injectors.top();
|
||||||
|
|
||||||
// ask it to stop and be deleted
|
// ask it to stop and be deleted
|
||||||
timePointerPair.second->stopAndDeleteLater();
|
timePointerPair.second->stop();
|
||||||
|
|
||||||
_injectors.pop();
|
_injectors.pop();
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ bool AudioInjectorManager::wouldExceedLimits() { // Should be called inside of a
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
bool AudioInjectorManager::threadInjector(const AudioInjectorPointer& injector) {
|
||||||
if (_shouldStop) {
|
if (_shouldStop) {
|
||||||
qCDebug(audio) << "AudioInjectorManager::threadInjector asked to thread injector but is shutting down.";
|
qCDebug(audio) << "AudioInjectorManager::threadInjector asked to thread injector but is shutting down.";
|
||||||
return false;
|
return false;
|
||||||
|
@ -159,7 +159,7 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
||||||
injector->moveToThread(_thread);
|
injector->moveToThread(_thread);
|
||||||
|
|
||||||
// add the injector to the queue with a send timestamp of now
|
// add the injector to the queue with a send timestamp of now
|
||||||
_injectors.emplace(usecTimestampNow(), InjectorQPointer { injector });
|
_injectors.emplace(usecTimestampNow(), injector);
|
||||||
|
|
||||||
// notify our wait condition so we can inject two frames for this injector immediately
|
// notify our wait condition so we can inject two frames for this injector immediately
|
||||||
_injectorReady.notify_one();
|
_injectorReady.notify_one();
|
||||||
|
@ -168,7 +168,7 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) {
|
bool AudioInjectorManager::restartFinishedInjector(const AudioInjectorPointer& injector) {
|
||||||
if (_shouldStop) {
|
if (_shouldStop) {
|
||||||
qCDebug(audio) << "AudioInjectorManager::threadInjector asked to thread injector but is shutting down.";
|
qCDebug(audio) << "AudioInjectorManager::threadInjector asked to thread injector but is shutting down.";
|
||||||
return false;
|
return false;
|
||||||
|
@ -181,7 +181,7 @@ bool AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// add the injector to the queue with a send timestamp of now
|
// add the injector to the queue with a send timestamp of now
|
||||||
_injectors.emplace(usecTimestampNow(), InjectorQPointer { injector });
|
_injectors.emplace(usecTimestampNow(), injector);
|
||||||
|
|
||||||
// notify our wait condition so we can inject two frames for this injector immediately
|
// notify our wait condition so we can inject two frames for this injector immediately
|
||||||
_injectorReady.notify_one();
|
_injectorReady.notify_one();
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
|
|
||||||
class AudioInjector;
|
#include "AudioInjector.h"
|
||||||
|
|
||||||
class AudioInjectorManager : public QObject, public Dependency {
|
class AudioInjectorManager : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -34,8 +34,7 @@ private slots:
|
||||||
void run();
|
void run();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
using InjectorQPointer = QPointer<AudioInjector>;
|
using TimeInjectorPointerPair = std::pair<uint64_t, AudioInjectorPointer>;
|
||||||
using TimeInjectorPointerPair = std::pair<uint64_t, InjectorQPointer>;
|
|
||||||
|
|
||||||
struct greaterTime {
|
struct greaterTime {
|
||||||
bool operator() (const TimeInjectorPointerPair& x, const TimeInjectorPointerPair& y) const {
|
bool operator() (const TimeInjectorPointerPair& x, const TimeInjectorPointerPair& y) const {
|
||||||
|
@ -49,8 +48,8 @@ private:
|
||||||
using Mutex = std::mutex;
|
using Mutex = std::mutex;
|
||||||
using Lock = std::unique_lock<Mutex>;
|
using Lock = std::unique_lock<Mutex>;
|
||||||
|
|
||||||
bool threadInjector(AudioInjector* injector);
|
bool threadInjector(const AudioInjectorPointer& injector);
|
||||||
bool restartFinishedInjector(AudioInjector* injector);
|
bool restartFinishedInjector(const AudioInjectorPointer& injector);
|
||||||
void notifyInjectorReadyCondition() { _injectorReady.notify_one(); }
|
void notifyInjectorReadyCondition() { _injectorReady.notify_one(); }
|
||||||
bool wouldExceedLimits();
|
bool wouldExceedLimits();
|
||||||
|
|
||||||
|
|
|
@ -1102,7 +1102,34 @@ int Avatar::getJointIndex(const QString& name) const {
|
||||||
QStringList Avatar::getJointNames() const {
|
QStringList Avatar::getJointNames() const {
|
||||||
QStringList result;
|
QStringList result;
|
||||||
withValidJointIndicesCache([&]() {
|
withValidJointIndicesCache([&]() {
|
||||||
result = _modelJointIndicesCache.keys();
|
// find out how large the vector needs to be
|
||||||
|
int maxJointIndex = -1;
|
||||||
|
QHashIterator<QString, int> k(_modelJointIndicesCache);
|
||||||
|
while (k.hasNext()) {
|
||||||
|
k.next();
|
||||||
|
int index = k.value();
|
||||||
|
if (index > maxJointIndex) {
|
||||||
|
maxJointIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// iterate through the hash and put joint names
|
||||||
|
// into the vector at their indices
|
||||||
|
QVector<QString> resultVector(maxJointIndex+1);
|
||||||
|
QHashIterator<QString, int> i(_modelJointIndicesCache);
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
int index = i.value();
|
||||||
|
resultVector[index] = i.key();
|
||||||
|
}
|
||||||
|
// convert to QList and drop out blanks
|
||||||
|
result = resultVector.toList();
|
||||||
|
QMutableListIterator<QString> j(result);
|
||||||
|
while (j.hasNext()) {
|
||||||
|
QString jointName = j.next();
|
||||||
|
if (jointName.isEmpty()) {
|
||||||
|
j.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,10 @@ void injectorFromScriptValue(const QScriptValue& object, ScriptAudioInjector*& o
|
||||||
out = qobject_cast<ScriptAudioInjector*>(object.toQObject());
|
out = qobject_cast<ScriptAudioInjector*>(object.toQObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptAudioInjector::ScriptAudioInjector(AudioInjector* injector) :
|
ScriptAudioInjector::ScriptAudioInjector(const AudioInjectorPointer& injector) :
|
||||||
_injector(injector)
|
_injector(injector)
|
||||||
{
|
{
|
||||||
QObject::connect(injector, &AudioInjector::finished, this, &ScriptAudioInjector::finished);
|
QObject::connect(injector.data(), &AudioInjector::finished, this, &ScriptAudioInjector::finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptAudioInjector::~ScriptAudioInjector() {
|
ScriptAudioInjector::~ScriptAudioInjector() {
|
||||||
|
@ -44,5 +44,5 @@ ScriptAudioInjector::~ScriptAudioInjector() {
|
||||||
|
|
||||||
void ScriptAudioInjector::stopInjectorImmediately() {
|
void ScriptAudioInjector::stopInjectorImmediately() {
|
||||||
qCDebug(scriptengine) << "ScriptAudioInjector::stopInjectorImmediately called to stop audio injector immediately.";
|
qCDebug(scriptengine) << "ScriptAudioInjector::stopInjectorImmediately called to stop audio injector immediately.";
|
||||||
_injector->stopAndDeleteLater();
|
_injector->stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ScriptAudioInjector : public QObject {
|
||||||
Q_PROPERTY(float loudness READ getLoudness)
|
Q_PROPERTY(float loudness READ getLoudness)
|
||||||
Q_PROPERTY(AudioInjectorOptions options WRITE setOptions READ getOptions)
|
Q_PROPERTY(AudioInjectorOptions options WRITE setOptions READ getOptions)
|
||||||
public:
|
public:
|
||||||
ScriptAudioInjector(AudioInjector* injector);
|
ScriptAudioInjector(const AudioInjectorPointer& injector);
|
||||||
~ScriptAudioInjector();
|
~ScriptAudioInjector();
|
||||||
public slots:
|
public slots:
|
||||||
void restart() { _injector->restart(); }
|
void restart() { _injector->restart(); }
|
||||||
|
@ -41,7 +41,7 @@ signals:
|
||||||
protected slots:
|
protected slots:
|
||||||
void stopInjectorImmediately();
|
void stopInjectorImmediately();
|
||||||
private:
|
private:
|
||||||
QPointer<AudioInjector> _injector;
|
AudioInjectorPointer _injector;
|
||||||
|
|
||||||
friend QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in);
|
friend QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in);
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <SoundCache.h>
|
#include <SoundCache.h>
|
||||||
|
|
||||||
class AudioInjector;
|
class AudioInjector;
|
||||||
|
using AudioInjectorPointer = QSharedPointer<AudioInjector>;
|
||||||
|
|
||||||
// SoundEffect object, exposed to qml only, not interface JavaScript.
|
// SoundEffect object, exposed to qml only, not interface JavaScript.
|
||||||
// This is used to play spatial sound effects on tablets/web entities from within QML.
|
// This is used to play spatial sound effects on tablets/web entities from within QML.
|
||||||
|
@ -38,7 +39,7 @@ protected:
|
||||||
QUrl _url;
|
QUrl _url;
|
||||||
float _volume { 1.0f };
|
float _volume { 1.0f };
|
||||||
SharedSoundPointer _sound;
|
SharedSoundPointer _sound;
|
||||||
AudioInjector* _injector { nullptr };
|
AudioInjectorPointer _injector;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_SoundEffect_h
|
#endif // hifi_SoundEffect_h
|
||||||
|
|
Loading…
Reference in a new issue