satdump/src-core/module.h

81 lines
2.8 KiB
C
Raw Normal View History

2021-02-14 12:05:44 +01:00
#pragma once
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <memory>
2021-02-18 00:37:12 +01:00
#include <atomic>
2021-02-19 00:03:52 +01:00
#include "imgui/imgui_flags.h"
2021-03-11 19:28:50 +01:00
#include "dll_export.h"
2021-10-22 15:26:17 +02:00
#include "common/dsp/complex.h"
#include "common/dsp/buffer.h"
2021-07-21 00:54:48 +02:00
#include "nlohmann/json.hpp"
#include "plugin.h"
2021-02-14 12:05:44 +01:00
2021-07-13 15:52:15 +02:00
// Utils
2021-02-15 19:52:38 +01:00
#define WRITE_IMAGE(image, path) \
image.save_png(std::string(path).c_str()); \
d_output_files.push_back(path);
#define UITO_C_STR(input) "%s", std::to_string(input).c_str()
2021-02-15 19:52:38 +01:00
2021-07-13 15:52:15 +02:00
// Colors
#define IMCOLOR_NOSYNC ImColor::HSV(0 / 360.0, 1, 1, 1.0)
#define IMCOLOR_SYNCING ImColor::HSV(39.0 / 360.0, 0.93, 1, 1.0)
#define IMCOLOR_SYNCED ImColor::HSV(113.0 / 360.0, 1, 1, 1.0)
2021-02-20 00:36:44 +01:00
enum ModuleDataType
{
2021-03-22 22:26:21 +01:00
DATA_STREAM, // Generic data, for which a circular buffer will be used
DATA_DSP_STREAM, // DSP Data using the specialized buffer and complex floats
2021-03-22 22:26:21 +01:00
DATA_FILE, // Just generic data from a file
2021-02-20 00:36:44 +01:00
};
2021-02-14 12:05:44 +01:00
class ProcessingModule
{
protected:
const std::string d_input_file;
const std::string d_output_file_hint;
std::vector<std::string> d_output_files;
2021-03-22 22:26:21 +01:00
std::map<std::string, std::string> d_parameters;
2021-02-20 00:36:44 +01:00
ModuleDataType input_data_type, output_data_type;
2021-02-14 12:05:44 +01:00
bool streamingInput; // Used to know if we should treat the input as a stream or file
2021-02-14 12:05:44 +01:00
public:
ProcessingModule(std::string input_file, std::string output_file_hint, std::map<std::string, std::string> parameters);
2021-02-20 00:36:44 +01:00
virtual std::vector<ModuleDataType> getInputTypes() { return {DATA_FILE}; }
virtual std::vector<ModuleDataType> getOutputTypes() { return {DATA_FILE}; }
void setInputType(ModuleDataType type);
void setOutputType(ModuleDataType type);
2021-05-22 16:36:09 +02:00
ModuleDataType getInputType();
ModuleDataType getOutputType();
2021-03-22 22:26:21 +01:00
virtual void init();
2021-05-22 16:36:09 +02:00
virtual void stop();
2021-02-14 12:05:44 +01:00
virtual void process() = 0;
2021-03-31 18:15:26 +02:00
virtual void drawUI(bool window) = 0;
2021-02-14 12:05:44 +01:00
std::vector<std::string> getOutputs();
2021-02-20 00:36:44 +01:00
public:
std::shared_ptr<dsp::RingBuffer<uint8_t>> input_fifo;
std::shared_ptr<dsp::RingBuffer<uint8_t>> output_fifo;
2021-10-22 15:26:17 +02:00
std::shared_ptr<dsp::stream<complex_t>> input_stream;
std::shared_ptr<dsp::stream<complex_t>> output_stream;
2021-02-22 18:23:31 +01:00
std::atomic<bool> input_active;
2021-02-20 00:36:44 +01:00
2021-07-21 00:54:48 +02:00
public:
nlohmann::json module_stats;
2021-02-14 12:05:44 +01:00
public:
static std::string getID();
2021-07-21 00:54:48 +02:00
virtual std::string getIDM() = 0;
2021-02-14 12:05:44 +01:00
static std::vector<std::string> getParameters();
static std::shared_ptr<ProcessingModule> getInstance(std::string input_file, std::string output_file_hint, std::map<std::string, std::string> parameters);
};
2021-03-11 19:28:50 +01:00
SATDUMP_DLL extern std::map<std::string, std::function<std::shared_ptr<ProcessingModule>(std::string, std::string, std::map<std::string, std::string>)>> modules_registry;
2021-02-14 12:05:44 +01:00
void registerModules();
SATDUMP_DLL extern float ui_scale; // UI Scaling factor, for DPI scaling
SATDUMP_DLL extern int demod_constellation_size; // Demodulator constellation size