From fa4929efd64ab6a9bf490f10f0eec8f0cb515faa Mon Sep 17 00:00:00 2001 From: Aang23 Date: Tue, 31 Jan 2023 20:40:37 +0100 Subject: [PATCH] Make DSP buffer size editable, to lower RAM usable drastically on SBCs --- .../stdc/module_stdc_parser.cpp | 41 ++++++++++++------- .../stdc/module_stdc_parser.h | 2 + .../rtlsdr_sdr_support/rtlsdr_sdr.h | 2 +- satdump_cfg.json | 12 ++++++ src-cli/live.cpp | 2 +- src-core/common/dsp/buffer.cpp | 8 ++++ src-core/common/dsp/buffer.h | 6 +-- .../common/dsp_source_sink/file_source.cpp | 2 +- src-core/init.cpp | 14 +++++++ src-core/modules/demod/module_demod_base.cpp | 2 +- src-interface/recorder/recorder_proc.cpp | 2 +- 11 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 src-core/common/dsp/buffer.cpp diff --git a/plugins/inmarsat_support/stdc/module_stdc_parser.cpp b/plugins/inmarsat_support/stdc/module_stdc_parser.cpp index ad6cfc163..d75e5c471 100644 --- a/plugins/inmarsat_support/stdc/module_stdc_parser.cpp +++ b/plugins/inmarsat_support/stdc/module_stdc_parser.cpp @@ -152,11 +152,14 @@ namespace inmarsat else logger->info("Packet : " + get_id_name(id)); - pkt_history_mtx.lock(); - pkt_history.push_back(msg); - if (pkt_history.size() > 500) - pkt_history.erase(pkt_history.begin()); - pkt_history_mtx.unlock(); + if (is_gui) + { + pkt_history_mtx.lock(); + pkt_history.push_back(msg); + if (pkt_history.size() > 500) + pkt_history.erase(pkt_history.begin()); + pkt_history_mtx.unlock(); + } // logger->info("Packet IDK : \n" + msg.dump(4)); }; @@ -169,11 +172,14 @@ namespace inmarsat logger->info("Full Message : \n" + msg["message"].get()); - pkt_history_mtx.lock(); - pkt_history_msg.push_back(msg); - if (pkt_history_msg.size() > 100) - pkt_history_msg.erase(pkt_history_msg.begin()); - pkt_history_mtx.unlock(); + if (is_gui) + { + pkt_history_mtx.lock(); + pkt_history_msg.push_back(msg); + if (pkt_history_msg.size() > 100) + pkt_history_msg.erase(pkt_history_msg.begin()); + pkt_history_mtx.unlock(); + } }; egc_parser.on_message = [&](nlohmann::json msg) @@ -184,11 +190,14 @@ namespace inmarsat logger->info("Full EGC Message : \n" + msg["message"].get()); - pkt_history_mtx.lock(); - pkt_history_egc.push_back(msg); - if (pkt_history_egc.size() > 100) - pkt_history_egc.erase(pkt_history_egc.begin()); - pkt_history_mtx.unlock(); + if (is_gui) + { + pkt_history_mtx.lock(); + pkt_history_egc.push_back(msg); + if (pkt_history_egc.size() > 100) + pkt_history_egc.erase(pkt_history_egc.begin()); + pkt_history_mtx.unlock(); + } }; time_t lastTime = 0; @@ -230,6 +239,8 @@ namespace inmarsat void STDCParserModule::drawUI(bool window) { + is_gui = true; + ImGui::Begin("Inmarsat STD-C Parser", NULL, window ? 0 : NOWINDOW_FLAGS); ImGui::Text("Decoded packets can be seen in a floating window."); diff --git a/plugins/inmarsat_support/stdc/module_stdc_parser.h b/plugins/inmarsat_support/stdc/module_stdc_parser.h index 33a9e89e5..9e9f3a42c 100644 --- a/plugins/inmarsat_support/stdc/module_stdc_parser.h +++ b/plugins/inmarsat_support/stdc/module_stdc_parser.h @@ -30,6 +30,8 @@ namespace inmarsat bool do_save_files; std::vector> udp_clients; + bool is_gui = false; + public: STDCParserModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters); ~STDCParserModule(); diff --git a/plugins/sdr_sources/rtlsdr_sdr_support/rtlsdr_sdr.h b/plugins/sdr_sources/rtlsdr_sdr_support/rtlsdr_sdr.h index 8d13a46a4..83c984442 100644 --- a/plugins/sdr_sources/rtlsdr_sdr_support/rtlsdr_sdr.h +++ b/plugins/sdr_sources/rtlsdr_sdr_support/rtlsdr_sdr.h @@ -36,7 +36,7 @@ protected: void mainThread() { - int buffer_size = std::min(roundf(current_samplerate / (250 * 512)) * 512, STREAM_BUFFER_SIZE); + int buffer_size = std::min(roundf(current_samplerate / (250 * 512)) * 512, dsp::STREAM_BUFFER_SIZE); while (thread_should_run) { diff --git a/satdump_cfg.json b/satdump_cfg.json index e8e66cfcb..2800f67b8 100644 --- a/satdump_cfg.json +++ b/satdump_cfg.json @@ -181,6 +181,18 @@ 43065 // GCOM-C1 ] }, + // Advanced user settings + // Should NOT be touched by the average user + "advanced_settings": { + // DSP Buffer size. The default 1MB uses + // too much RAM for operation on some SBCs + // with only 256MB or such. + // Changing this will drastically reduce + // RAM utilization, but be careful to NOT go + // too low or things will break! + // ------------------------------------------------------ + // "default_buffer_size": 100e3 + }, // Settings for the Viewer. Those also are default settings when generating viewer-less "viewer": { "instruments": { diff --git a/src-cli/live.cpp b/src-cli/live.cpp index e5ce8b694..4b93c1641 100644 --- a/src-cli/live.cpp +++ b/src-cli/live.cpp @@ -173,7 +173,7 @@ int main_live(int argc, char *argv[]) // Init pipeline parameters["baseband_format"] = "f32"; - parameters["buffer_size"] = STREAM_BUFFER_SIZE; // This is required, as we WILL go over the (usually) default 8192 size + parameters["buffer_size"] = dsp::STREAM_BUFFER_SIZE; // This is required, as we WILL go over the (usually) default 8192 size parameters["start_timestamp"] = (double)time(0); // Some pipelines need this std::unique_ptr live_pipeline = std::make_unique(pipeline.value(), parameters, output_file); diff --git a/src-core/common/dsp/buffer.cpp b/src-core/common/dsp/buffer.cpp new file mode 100644 index 000000000..c505b59eb --- /dev/null +++ b/src-core/common/dsp/buffer.cpp @@ -0,0 +1,8 @@ +#include "buffer.h" + +namespace dsp +{ + // 1MB buffers + int STREAM_BUFFER_SIZE = 1000000; + int RING_BUF_SZ = 1000000; +}; \ No newline at end of file diff --git a/src-core/common/dsp/buffer.h b/src-core/common/dsp/buffer.h index e1ce720f3..74ef79d6f 100644 --- a/src-core/common/dsp/buffer.h +++ b/src-core/common/dsp/buffer.h @@ -7,9 +7,9 @@ namespace dsp { -// 1MB buffers -#define STREAM_BUFFER_SIZE 1000000 -#define RING_BUF_SZ 1000000 + // Default buffer sizes + extern int STREAM_BUFFER_SIZE; + extern int RING_BUF_SZ; /* Util function to create a volk aligned buffer diff --git a/src-core/common/dsp_source_sink/file_source.cpp b/src-core/common/dsp_source_sink/file_source.cpp index 3c14bdce7..18225ef09 100644 --- a/src-core/common/dsp_source_sink/file_source.cpp +++ b/src-core/common/dsp_source_sink/file_source.cpp @@ -57,7 +57,7 @@ void FileSource::start() if (is_ui) file_path = file_input.getPath(); - buffer_size = std::min(STREAM_BUFFER_SIZE, std::max(8192 + 1, current_samplerate / 200)); + buffer_size = std::min(dsp::STREAM_BUFFER_SIZE, std::max(8192 + 1, current_samplerate / 200)); DSPSampleSource::start(); ns_to_wait = (1e9 / current_samplerate) * float(buffer_size); diff --git a/src-core/init.cpp b/src-core/init.cpp index 1fc8fd09e..75c6ef331 100644 --- a/src-core/init.cpp +++ b/src-core/init.cpp @@ -14,6 +14,8 @@ #include "core/opencl.h" +#include "common/dsp/buffer.h" + namespace satdump { SATDUMP_DLL std::string user_path; @@ -111,6 +113,18 @@ namespace satdump // Products registerProducts(); + // Set DSP buffer sizes if they have been changed + if (config::main_cfg.contains("advanced_settings")) + { + if (config::main_cfg["advanced_settings"].contains("default_buffer_size")) + { + int new_sz = config::main_cfg["advanced_settings"]["default_buffer_size"].get(); + dsp::STREAM_BUFFER_SIZE = new_sz; + dsp::RING_BUF_SZ = new_sz; + logger->warn("DSP Buffer size was changed to {:d}", new_sz); + } + } + // Let plugins know we started eventBus->fire_event({}); diff --git a/src-core/modules/demod/module_demod_base.cpp b/src-core/modules/demod/module_demod_base.cpp index f27e1ccb1..91fcd521e 100644 --- a/src-core/modules/demod/module_demod_base.cpp +++ b/src-core/modules/demod/module_demod_base.cpp @@ -17,7 +17,7 @@ namespace demod if (parameters.count("buffer_size") > 0) d_buffer_size = parameters["buffer_size"].get(); else - d_buffer_size = std::min(STREAM_BUFFER_SIZE, std::max(8192 + 1, d_samplerate / 200)); + d_buffer_size = std::min(dsp::STREAM_BUFFER_SIZE, std::max(8192 + 1, d_samplerate / 200)); if (parameters.count("symbolrate") > 0) d_symbolrate = parameters["symbolrate"].get(); diff --git a/src-interface/recorder/recorder_proc.cpp b/src-interface/recorder/recorder_proc.cpp index acb5ab8c2..24a0fbaf5 100644 --- a/src-interface/recorder/recorder_proc.cpp +++ b/src-interface/recorder/recorder_proc.cpp @@ -134,7 +134,7 @@ namespace satdump pipeline_params = pipeline_selector.getParameters(); pipeline_params["samplerate"] = get_samplerate(); pipeline_params["baseband_format"] = "f32"; - pipeline_params["buffer_size"] = STREAM_BUFFER_SIZE; // This is required, as we WILL go over the (usually) default 8192 size + pipeline_params["buffer_size"] = dsp::STREAM_BUFFER_SIZE; // This is required, as we WILL go over the (usually) default 8192 size pipeline_params["start_timestamp"] = (double)time(0); // Some pipelines need this if (automated_live_output_dir)