File: autotrack_proc.cpp

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 (88 lines) | stat: -rw-r--r-- 3,172 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
#include "autotrack.h"
#include "logger.h"
#include "common/utils.h"
#include "common/thread_priority.h"

void AutoTrackApp::start_processing()
{
    if (is_processing)
        return;

    live_pipeline_mtx.lock();
    logger->trace("Start pipeline...");
    pipeline_params["samplerate"] = get_samplerate();
    pipeline_params["baseband_format"] = "cf32";
    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

    try
    {
        pipeline_output_dir = prepareAutomatedPipelineFolder(time(0), source_ptr->d_frequency, selected_pipeline.name, d_output_folder);
        live_pipeline = std::make_unique<satdump::LivePipeline>(selected_pipeline, pipeline_params, pipeline_output_dir);
        splitter->reset_output("live");
        live_pipeline->start(splitter->get_output("live"), main_thread_pool);
        splitter->set_enabled("live", true);

        is_processing = true;
    }
    catch (std::runtime_error &e)
    {
        logger->error(e.what());
    }

    live_pipeline_mtx.unlock();
}

void AutoTrackApp::stop_processing()
{
    if (is_processing)
    {
        live_pipeline_mtx.lock();
        logger->trace("Stop pipeline...");
        is_processing = false;
        splitter->set_enabled("live", false);
        live_pipeline->stop();

        if (d_settings.contains("finish_processing") && d_settings["finish_processing"].get<bool>() && live_pipeline->getOutputFiles().size() > 0)
        {
            std::string input_file = live_pipeline->getOutputFiles()[0];
            satdump::Pipeline selected_pipeline_ = selected_pipeline;
            std::string pipeline_output_dir_ = pipeline_output_dir;
            nlohmann::json pipeline_params_ = pipeline_params;
            auto fun = [selected_pipeline_, pipeline_output_dir_, input_file, pipeline_params_](int)
            {
                setLowestThreadPriority();
                satdump::Pipeline pipeline = selected_pipeline_;
                int start_level = pipeline.live_cfg.normal_live[pipeline.live_cfg.normal_live.size() - 1].first;
                std::string input_level = pipeline.steps[start_level].level_name;
                pipeline.run(input_file, pipeline_output_dir_, pipeline_params_, input_level);
                logger->info("Pipeline Processing Done!");
            };
            main_thread_pool.push(fun);
        }

        live_pipeline.reset();
        live_pipeline_mtx.unlock();
    }
}

void AutoTrackApp::start_recording()
{
    splitter->set_enabled("record", true);

    std::string filename = d_output_folder + "/" + prepareBasebandFileName(getTime(), get_samplerate(), frequency_hz);
    std::string recorder_filename = file_sink->start_recording(filename, get_samplerate());
    logger->info("Recording to " + recorder_filename);
    is_recording = true;
}

void AutoTrackApp::stop_recording()
{
    if (is_recording)
    {
        file_sink->stop_recording();
        splitter->set_enabled("record", false);
        //  recorder_filename = "";
        is_recording = false;
    }
}