mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 16:34:15 +02:00
make compression optional
This commit is contained in:
parent
a590f384a6
commit
6c640752cd
6 changed files with 67 additions and 36 deletions
|
@ -59,16 +59,19 @@ void VoxelPacketProcessor::processPacket(sockaddr& senderAddress, unsigned char*
|
|||
} else {
|
||||
app->_voxels.setDataSourceUUID(voxelServer->getUUID());
|
||||
|
||||
// thse packets are commpressed...
|
||||
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||
QByteArray compressedData((const char*)packetData + numBytesPacketHeader,
|
||||
messageLength - numBytesPacketHeader);
|
||||
QByteArray uncompressedData = qUncompress(compressedData);
|
||||
QByteArray uncompressedPacket((const char*)packetData, numBytesPacketHeader);
|
||||
uncompressedPacket.append(uncompressedData);
|
||||
// these packets are commpressed...
|
||||
if (VOXEL_PACKETS_COMPRESSED) {
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||
QByteArray compressedData((const char*)packetData + numBytesPacketHeader,
|
||||
messageLength - numBytesPacketHeader);
|
||||
QByteArray uncompressedData = qUncompress(compressedData);
|
||||
QByteArray uncompressedPacket((const char*)packetData, numBytesPacketHeader);
|
||||
uncompressedPacket.append(uncompressedData);
|
||||
|
||||
app->_voxels.parseData((unsigned char*)uncompressedPacket.data(), uncompressedPacket.size());
|
||||
app->_voxels.parseData((unsigned char*)uncompressedPacket.data(), uncompressedPacket.size());
|
||||
} else {
|
||||
app->_voxels.parseData(packetData, messageLength);
|
||||
}
|
||||
app->_voxels.setDataSourceUUID(QUuid());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -595,7 +595,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||
"readBitstreamToTree()");
|
||||
// ask the VoxelTree to read the bitstream into the tree
|
||||
ReadBitstreamToTreeParams args(WANT_COLOR, NO_EXISTS_BITS /*WANT_EXISTS_BITS*/, NULL, getDataSourceUUID());
|
||||
ReadBitstreamToTreeParams args(WANT_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID());
|
||||
lockTree();
|
||||
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
|
||||
unlockTree();
|
||||
|
@ -605,7 +605,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||
"readBitstreamToTree()");
|
||||
// ask the VoxelTree to read the MONOCHROME bitstream into the tree
|
||||
ReadBitstreamToTreeParams args(NO_COLOR, NO_EXISTS_BITS /*WANT_EXISTS_BITS*/, NULL, getDataSourceUUID());
|
||||
ReadBitstreamToTreeParams args(NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID());
|
||||
lockTree();
|
||||
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
|
||||
unlockTree();
|
||||
|
|
|
@ -102,38 +102,48 @@ void VoxelNodeData::resetVoxelPacket() {
|
|||
|
||||
int numBytesPacketHeader = populateTypeAndVersion(_voxelPacket, voxelPacketType);
|
||||
_voxelPacketAt = _voxelPacket + numBytesPacketHeader;
|
||||
_voxelPacketAvailableBytes = (MAX_VOXEL_PACKET_SIZE * UNCOMPRESSED_SIZE_MULTIPLE) - numBytesPacketHeader;
|
||||
compressPacket();
|
||||
|
||||
if (VOXEL_PACKETS_COMPRESSED) {
|
||||
_voxelPacketAvailableBytes = (MAX_VOXEL_PACKET_SIZE * UNCOMPRESSED_SIZE_MULTIPLE) - numBytesPacketHeader;
|
||||
compressPacket();
|
||||
} else {
|
||||
_voxelPacketAvailableBytes = MAX_VOXEL_PACKET_SIZE - numBytesPacketHeader;
|
||||
}
|
||||
_voxelPacketWaiting = false;
|
||||
}
|
||||
|
||||
bool VoxelNodeData::willFit(unsigned char* buffer, int bytes) {
|
||||
int uncompressedLength = getPacketLengthUncompressed();
|
||||
const int MAX_COMPRESSION = 9;
|
||||
// we only want to compress the data payload, not the message header
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(_voxelPacket);
|
||||
bool wouldFit = false;
|
||||
if (VOXEL_PACKETS_COMPRESSED) {
|
||||
int uncompressedLength = getPacketLengthUncompressed();
|
||||
const int MAX_COMPRESSION = 9;
|
||||
// we only want to compress the data payload, not the message header
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(_voxelPacket);
|
||||
|
||||
// start with the current uncompressed data
|
||||
QByteArray uncompressedTestData((const char*)_voxelPacket + numBytesPacketHeader,
|
||||
uncompressedLength - numBytesPacketHeader);
|
||||
// start with the current uncompressed data
|
||||
QByteArray uncompressedTestData((const char*)_voxelPacket + numBytesPacketHeader,
|
||||
uncompressedLength - numBytesPacketHeader);
|
||||
|
||||
// append this next buffer...
|
||||
uncompressedTestData.append((const char*)buffer, bytes);
|
||||
// append this next buffer...
|
||||
uncompressedTestData.append((const char*)buffer, bytes);
|
||||
|
||||
// test compress it
|
||||
QByteArray compressedData = qCompress(uncompressedTestData, MAX_COMPRESSION);
|
||||
// test compress it
|
||||
QByteArray compressedData = qCompress(uncompressedTestData, MAX_COMPRESSION);
|
||||
|
||||
bool wouldFit = (compressedData.size() + numBytesPacketHeader) <= MAX_VOXEL_PACKET_SIZE;
|
||||
wouldFit = (compressedData.size() + numBytesPacketHeader) <= MAX_VOXEL_PACKET_SIZE;
|
||||
|
||||
/*
|
||||
if (!wouldFit) {
|
||||
printf("would not fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
||||
getPacketLength(), bytes, (compressedData.size() + numBytesPacketHeader), MAX_VOXEL_PACKET_SIZE);
|
||||
/*
|
||||
if (!wouldFit) {
|
||||
printf("would not fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
||||
getPacketLength(), bytes, (compressedData.size() + numBytesPacketHeader), MAX_VOXEL_PACKET_SIZE);
|
||||
} else {
|
||||
printf("would fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
||||
getPacketLength(), bytes, (compressedData.size() + numBytesPacketHeader), MAX_VOXEL_PACKET_SIZE);
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
printf("would fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
||||
getPacketLength(), bytes, (compressedData.size() + numBytesPacketHeader), MAX_VOXEL_PACKET_SIZE);
|
||||
wouldFit = bytes <= _voxelPacketAvailableBytes;
|
||||
}
|
||||
*/
|
||||
return wouldFit;
|
||||
}
|
||||
|
||||
|
@ -145,8 +155,25 @@ void VoxelNodeData::writeToPacket(unsigned char* buffer, int bytes) {
|
|||
compressPacket();
|
||||
}
|
||||
|
||||
const unsigned char* VoxelNodeData::getPacket() const {
|
||||
if (VOXEL_PACKETS_COMPRESSED) {
|
||||
return (const unsigned char*)_compressedPacket.constData();
|
||||
}
|
||||
return _voxelPacket;
|
||||
}
|
||||
|
||||
int VoxelNodeData::getPacketLength() const {
|
||||
if (VOXEL_PACKETS_COMPRESSED) {
|
||||
return _compressedPacket.size();
|
||||
}
|
||||
return getPacketLengthUncompressed();
|
||||
}
|
||||
|
||||
int VoxelNodeData::getPacketLengthUncompressed() const {
|
||||
return (MAX_VOXEL_PACKET_SIZE * UNCOMPRESSED_SIZE_MULTIPLE) - _voxelPacketAvailableBytes;
|
||||
if (VOXEL_PACKETS_COMPRESSED) {
|
||||
return (MAX_VOXEL_PACKET_SIZE * UNCOMPRESSED_SIZE_MULTIPLE) - _voxelPacketAvailableBytes;
|
||||
}
|
||||
return MAX_VOXEL_PACKET_SIZE - _voxelPacketAvailableBytes;
|
||||
}
|
||||
|
||||
void VoxelNodeData::compressPacket() {
|
||||
|
|
|
@ -31,8 +31,8 @@ public:
|
|||
void writeToPacket(unsigned char* buffer, int bytes); // writes to end of packet
|
||||
bool willFit(unsigned char* buffer, int bytes); // tests to see if the bytes will fit
|
||||
|
||||
const unsigned char* getPacket() const { return (const unsigned char*)_compressedPacket.constData(); }
|
||||
int getPacketLength() const { return _compressedPacket.size(); }
|
||||
const unsigned char* getPacket() const;
|
||||
int getPacketLength() const;
|
||||
int getPacketLengthUncompressed() const;
|
||||
|
||||
bool isPacketWaiting() const { return _voxelPacketWaiting; }
|
||||
|
|
|
@ -335,7 +335,7 @@ int VoxelSendThread::deepestLevelVoxelDistributor(Node* node, VoxelNodeData* nod
|
|||
nodeData->getViewFrustumJustStoppedChanging()) || nodeData->hasLodChanged();
|
||||
|
||||
EncodeBitstreamParams params(INT_MAX, &nodeData->getCurrentViewFrustum(), wantColor,
|
||||
NO_EXISTS_BITS /*WANT_EXISTS_BITS*/, DONT_CHOP, wantDelta, lastViewFrustum,
|
||||
WANT_EXISTS_BITS, DONT_CHOP, wantDelta, lastViewFrustum,
|
||||
wantOcclusionCulling, coverageMap, boundaryLevelAdjust, voxelSizeScale,
|
||||
nodeData->getLastTimeBagEmpty(),
|
||||
isFullScene, &nodeData->stats, _myServer->getJurisdiction());
|
||||
|
|
|
@ -62,4 +62,5 @@ const int DANGEROUSLY_DEEP_RECURSION = 200; // use this for something that needs
|
|||
|
||||
const int DEFAULT_MAX_VOXEL_PPS = 600; // the default maximum PPS we think a voxel server should send to a client
|
||||
|
||||
const bool VOXEL_PACKETS_COMPRESSED = false;
|
||||
#endif
|
Loading…
Reference in a new issue