Skip to content

Commit 650a619

Browse files
fix SDR++ server crash at high samplerates AlexandreRouma#1326
1 parent 61ffb3e commit 650a619

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

core/src/dsp/compression/sample_stream_compressor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace dsp::compression {
1212

1313
void init(stream<complex_t>* in, PCMType pcmType) {
1414
_pcmType = pcmType;
15+
16+
// Set the output buffer size to the max size of a complex buffer + 8 bytes for the header
17+
out.setBufferSize(STREAM_BUFFER_SIZE*sizeof(complex_t) + 8);
18+
1519
base_type::init(in);
1620
}
1721

core/src/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ namespace server {
230230
// Compress data if needed and fill out header fields
231231
if (compression) {
232232
bb_pkt_hdr->type = PACKET_TYPE_BASEBAND_COMPRESSED;
233-
bb_pkt_hdr->size = sizeof(PacketHeader) + (uint32_t)ZSTD_compressCCtx(cctx, &bbuf[sizeof(PacketHeader)], SERVER_MAX_PACKET_SIZE, data, count, 1);
233+
bb_pkt_hdr->size = sizeof(PacketHeader) + (uint32_t)ZSTD_compressCCtx(cctx, &bbuf[sizeof(PacketHeader)], SERVER_MAX_PACKET_SIZE-sizeof(PacketHeader), data, count, 1);
234234
}
235235
else {
236236
bb_pkt_hdr->type = PACKET_TYPE_BASEBAND;

source_modules/sdrpp_server_source/src/sdrpp_server_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace server {
3030
dctx = ZSTD_createDCtx();
3131

3232
// Initialize DSP
33-
decompIn.setBufferSize((sizeof(dsp::complex_t) * STREAM_BUFFER_SIZE) + 8);
33+
decompIn.setBufferSize(STREAM_BUFFER_SIZE*sizeof(dsp::complex_t) + 8);
3434
decompIn.clearWriteStop();
3535
decomp.init(&decompIn);
3636
link.init(&decomp.out, output);
@@ -209,7 +209,7 @@ namespace server {
209209
if (!decompIn.swap(r_pkt_hdr->size - sizeof(PacketHeader))) { break; }
210210
}
211211
else if (r_pkt_hdr->type == PACKET_TYPE_BASEBAND_COMPRESSED) {
212-
size_t outCount = ZSTD_decompressDCtx(dctx, decompIn.writeBuf, STREAM_BUFFER_SIZE, r_pkt_data, r_pkt_hdr->size - sizeof(PacketHeader));
212+
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));
213213
if (outCount) {
214214
if (!decompIn.swap(outCount)) { break; }
215215
};

0 commit comments

Comments
 (0)