compression

This commit is contained in:
AlexandreRouma
2022-01-26 13:23:55 +01:00
parent 75da59833a
commit 4c0220a228
9 changed files with 79 additions and 13 deletions

View File

@@ -26,7 +26,11 @@ namespace server {
s_cmd_hdr = (CommandHeader*)s_pkt_data;
s_cmd_data = &sbuffer[sizeof(PacketHeader) + sizeof(CommandHeader)];
// Initialize decompressor
dctx = ZSTD_createDCtx();
// Initialize DSP
decompIn.setBufferSize((sizeof(dsp::complex_t) * STREAM_BUFFER_SIZE) + 8);
decomp.init(&decompIn);
link.init(&decomp.out, output);
decomp.start();
@@ -43,6 +47,7 @@ namespace server {
ClientClass::~ClientClass() {
close();
ZSTD_freeDCtx(dctx);
delete[] rbuffer;
delete[] sbuffer;
}
@@ -108,6 +113,11 @@ namespace server {
sendCommand(COMMAND_SET_SAMPLE_TYPE, 1);
}
void ClientClass::setCompression(bool enabled) {
s_cmd_data[0] = enabled;
sendCommand(COMMAND_SET_COMPRESSION, 1);
}
void ClientClass::start() {
if (!client || !client->isOpen()) { return; }
sendCommand(COMMAND_START, 0);
@@ -189,6 +199,10 @@ namespace server {
memcpy(_this->decompIn.writeBuf, &buf[sizeof(PacketHeader)], _this->r_pkt_hdr->size - sizeof(PacketHeader));
_this->decompIn.swap(_this->r_pkt_hdr->size - sizeof(PacketHeader));
}
else if (_this->r_pkt_hdr->type == PACKET_TYPE_BASEBAND_COMPRESSED) {
size_t outCount = ZSTD_decompressDCtx(_this->dctx, _this->decompIn.writeBuf, STREAM_BUFFER_SIZE, _this->r_pkt_data, _this->r_pkt_hdr->size - sizeof(PacketHeader));
if (outCount) { _this->decompIn.swap(outCount); };
}
else if (_this->r_pkt_hdr->type == PACKET_TYPE_ERROR) {
spdlog::error("SDR++ Server Error: {0}", buf[sizeof(PacketHeader)]);
}