File: module.h

package info (click to toggle)
satdump 1.2.2%2Bgb79af48-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 81,648 kB
  • sloc: cpp: 276,768; ansic: 164,598; lisp: 1,219; sh: 283; xml: 106; makefile: 7
file content (91 lines) | stat: -rw-r--r-- 2,919 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once

#include <string>
#include <vector>
#include <map>
#include <functional>
#include <memory>
#include <atomic>
#include "imgui/imgui_flags.h"
#include "dll_export.h"
#include "core/style.h"
#include "common/dsp/complex.h"
#include "common/dsp/buffer.h"
#include "nlohmann/json.hpp"
#include "plugin.h"

// Utils
#define UITO_C_STR(input) "%s", std::to_string(input).c_str()

#define REGISTER_MODULE(module) modules_registry.emplace(module::getID(), module::getInstance)
#define REGISTER_MODULE_EXTERNAL(registry, module) registry.emplace(module::getID(), module::getInstance)

enum ModuleDataType
{
    DATA_STREAM,     // Generic data, for which a circular buffer will be used
    DATA_DSP_STREAM, // DSP Data using the specialized buffer and complex floats
    DATA_FILE,       // Just generic data from a file
};

class ProcessingModule
{
protected:
    const std::string d_input_file;
    const std::string d_output_file_hint;
    std::vector<std::string> d_output_files;
    nlohmann::json d_parameters;
    ModuleDataType input_data_type, output_data_type;

    bool streamingInput; // Used to know if we should treat the input as a stream or file

public:
    ProcessingModule(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
    virtual std::vector<ModuleDataType> getInputTypes() { return {DATA_FILE}; }
    virtual std::vector<ModuleDataType> getOutputTypes() { return {DATA_FILE}; }
    void setInputType(ModuleDataType type);
    void setOutputType(ModuleDataType type);
    ModuleDataType getInputType();
    ModuleDataType getOutputType();
    virtual void init();
    virtual void stop();
    virtual void process() = 0;
    virtual void drawUI(bool window) = 0;
    std::vector<std::string> getOutputs();

public:
    std::shared_ptr<dsp::RingBuffer<uint8_t>> input_fifo;
    std::shared_ptr<dsp::RingBuffer<uint8_t>> output_fifo;
    std::shared_ptr<dsp::stream<complex_t>> input_stream;
    std::shared_ptr<dsp::stream<complex_t>> output_stream;
    std::atomic<bool> input_active;

public:
    nlohmann::json module_stats;

public:
    static std::string getID();
    virtual std::string getIDM() = 0;
    static std::vector<std::string> getParameters();
    static std::shared_ptr<ProcessingModule> getInstance(std::string input_file, std::string output_file_hint, nlohmann::json parameters);
};

SATDUMP_DLL extern std::map<std::string, std::function<std::shared_ptr<ProcessingModule>(std::string, std::string, nlohmann::json)>> modules_registry;

// Event where modules are registered, so plugins can load theirs
struct RegisterModulesEvent
{
    std::map<std::string, std::function<std::shared_ptr<ProcessingModule>(std::string, std::string, nlohmann::json)>> &modules_registry;
};

void registerModules();

// Status stuff
enum instrument_status_t
{
    DECODING,
    PROCESSING,
    SAVING,
    DONE,
};

void drawStatus(instrument_status_t status);