mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-10 01:36:26 +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 {
|
} else {
|
||||||
app->_voxels.setDataSourceUUID(voxelServer->getUUID());
|
app->_voxels.setDataSourceUUID(voxelServer->getUUID());
|
||||||
|
|
||||||
// thse packets are commpressed...
|
// these packets are commpressed...
|
||||||
|
if (VOXEL_PACKETS_COMPRESSED) {
|
||||||
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
int numBytesPacketHeader = numBytesForPacketHeader(packetData);
|
||||||
QByteArray compressedData((const char*)packetData + numBytesPacketHeader,
|
QByteArray compressedData((const char*)packetData + numBytesPacketHeader,
|
||||||
messageLength - numBytesPacketHeader);
|
messageLength - numBytesPacketHeader);
|
||||||
QByteArray uncompressedData = qUncompress(compressedData);
|
QByteArray uncompressedData = qUncompress(compressedData);
|
||||||
QByteArray uncompressedPacket((const char*)packetData, numBytesPacketHeader);
|
QByteArray uncompressedPacket((const char*)packetData, numBytesPacketHeader);
|
||||||
uncompressedPacket.append(uncompressedData);
|
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());
|
app->_voxels.setDataSourceUUID(QUuid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -595,7 +595,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||||
"readBitstreamToTree()");
|
"readBitstreamToTree()");
|
||||||
// ask the VoxelTree to read the bitstream into the tree
|
// 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();
|
lockTree();
|
||||||
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
|
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
|
||||||
unlockTree();
|
unlockTree();
|
||||||
|
@ -605,7 +605,7 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) {
|
||||||
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
|
||||||
"readBitstreamToTree()");
|
"readBitstreamToTree()");
|
||||||
// ask the VoxelTree to read the MONOCHROME bitstream into the tree
|
// 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();
|
lockTree();
|
||||||
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
|
_tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args);
|
||||||
unlockTree();
|
unlockTree();
|
||||||
|
|
|
@ -102,38 +102,48 @@ void VoxelNodeData::resetVoxelPacket() {
|
||||||
|
|
||||||
int numBytesPacketHeader = populateTypeAndVersion(_voxelPacket, voxelPacketType);
|
int numBytesPacketHeader = populateTypeAndVersion(_voxelPacket, voxelPacketType);
|
||||||
_voxelPacketAt = _voxelPacket + numBytesPacketHeader;
|
_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;
|
_voxelPacketWaiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VoxelNodeData::willFit(unsigned char* buffer, int bytes) {
|
bool VoxelNodeData::willFit(unsigned char* buffer, int bytes) {
|
||||||
int uncompressedLength = getPacketLengthUncompressed();
|
bool wouldFit = false;
|
||||||
const int MAX_COMPRESSION = 9;
|
if (VOXEL_PACKETS_COMPRESSED) {
|
||||||
// we only want to compress the data payload, not the message header
|
int uncompressedLength = getPacketLengthUncompressed();
|
||||||
int numBytesPacketHeader = numBytesForPacketHeader(_voxelPacket);
|
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
|
// start with the current uncompressed data
|
||||||
QByteArray uncompressedTestData((const char*)_voxelPacket + numBytesPacketHeader,
|
QByteArray uncompressedTestData((const char*)_voxelPacket + numBytesPacketHeader,
|
||||||
uncompressedLength - numBytesPacketHeader);
|
uncompressedLength - numBytesPacketHeader);
|
||||||
|
|
||||||
// append this next buffer...
|
// append this next buffer...
|
||||||
uncompressedTestData.append((const char*)buffer, bytes);
|
uncompressedTestData.append((const char*)buffer, bytes);
|
||||||
|
|
||||||
// test compress it
|
// test compress it
|
||||||
QByteArray compressedData = qCompress(uncompressedTestData, MAX_COMPRESSION);
|
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) {
|
if (!wouldFit) {
|
||||||
printf("would not fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
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);
|
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 {
|
} else {
|
||||||
printf("would fit... previous size: %d, buffer size: %d, would be:%d MAX_VOXEL_PACKET_SIZE: %d\n",
|
wouldFit = bytes <= _voxelPacketAvailableBytes;
|
||||||
getPacketLength(), bytes, (compressedData.size() + numBytesPacketHeader), MAX_VOXEL_PACKET_SIZE);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return wouldFit;
|
return wouldFit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +155,25 @@ void VoxelNodeData::writeToPacket(unsigned char* buffer, int bytes) {
|
||||||
compressPacket();
|
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 {
|
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() {
|
void VoxelNodeData::compressPacket() {
|
||||||
|
|
|
@ -31,8 +31,8 @@ public:
|
||||||
void writeToPacket(unsigned char* buffer, int bytes); // writes to end of packet
|
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
|
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(); }
|
const unsigned char* getPacket() const;
|
||||||
int getPacketLength() const { return _compressedPacket.size(); }
|
int getPacketLength() const;
|
||||||
int getPacketLengthUncompressed() const;
|
int getPacketLengthUncompressed() const;
|
||||||
|
|
||||||
bool isPacketWaiting() const { return _voxelPacketWaiting; }
|
bool isPacketWaiting() const { return _voxelPacketWaiting; }
|
||||||
|
|
|
@ -335,7 +335,7 @@ int VoxelSendThread::deepestLevelVoxelDistributor(Node* node, VoxelNodeData* nod
|
||||||
nodeData->getViewFrustumJustStoppedChanging()) || nodeData->hasLodChanged();
|
nodeData->getViewFrustumJustStoppedChanging()) || nodeData->hasLodChanged();
|
||||||
|
|
||||||
EncodeBitstreamParams params(INT_MAX, &nodeData->getCurrentViewFrustum(), wantColor,
|
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,
|
wantOcclusionCulling, coverageMap, boundaryLevelAdjust, voxelSizeScale,
|
||||||
nodeData->getLastTimeBagEmpty(),
|
nodeData->getLastTimeBagEmpty(),
|
||||||
isFullScene, &nodeData->stats, _myServer->getJurisdiction());
|
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 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
|
#endif
|
Loading…
Reference in a new issue