Skip to content

Commit

Permalink
fix SDR++ server crash at high samplerates AlexandreRouma#1326
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRouma committed Feb 13, 2024
1 parent 61ffb3e commit 650a619
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions core/src/dsp/compression/sample_stream_compressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace dsp::compression {

void init(stream<complex_t>* in, PCMType pcmType) {
_pcmType = pcmType;

// Set the output buffer size to the max size of a complex buffer + 8 bytes for the header
out.setBufferSize(STREAM_BUFFER_SIZE*sizeof(complex_t) + 8);

base_type::init(in);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace server {
// Compress data if needed and fill out header fields
if (compression) {
bb_pkt_hdr->type = PACKET_TYPE_BASEBAND_COMPRESSED;
bb_pkt_hdr->size = sizeof(PacketHeader) + (uint32_t)ZSTD_compressCCtx(cctx, &bbuf[sizeof(PacketHeader)], SERVER_MAX_PACKET_SIZE, data, count, 1);
bb_pkt_hdr->size = sizeof(PacketHeader) + (uint32_t)ZSTD_compressCCtx(cctx, &bbuf[sizeof(PacketHeader)], SERVER_MAX_PACKET_SIZE-sizeof(PacketHeader), data, count, 1);
}
else {
bb_pkt_hdr->type = PACKET_TYPE_BASEBAND;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace server {
dctx = ZSTD_createDCtx();

// Initialize DSP
decompIn.setBufferSize((sizeof(dsp::complex_t) * STREAM_BUFFER_SIZE) + 8);
decompIn.setBufferSize(STREAM_BUFFER_SIZE*sizeof(dsp::complex_t) + 8);
decompIn.clearWriteStop();
decomp.init(&decompIn);
link.init(&decomp.out, output);
Expand Down Expand Up @@ -209,7 +209,7 @@ namespace server {
if (!decompIn.swap(r_pkt_hdr->size - sizeof(PacketHeader))) { break; }
}
else if (r_pkt_hdr->type == PACKET_TYPE_BASEBAND_COMPRESSED) {
size_t outCount = ZSTD_decompressDCtx(dctx, decompIn.writeBuf, STREAM_BUFFER_SIZE, r_pkt_data, r_pkt_hdr->size - sizeof(PacketHeader));
size_t outCount = ZSTD_decompressDCtx(dctx, decompIn.writeBuf, STREAM_BUFFER_SIZE*sizeof(dsp::complex_t)+8, r_pkt_data, r_pkt_hdr->size - sizeof(PacketHeader));
if (outCount) {
if (!decompIn.swap(outCount)) { break; }
};
Expand Down

0 comments on commit 650a619

Please sign in to comment.