ssdv jpeg save is async now.

ssdv
Michal Fratczak 2020-04-26 18:12:13 +02:00
rodzic b79dfae8b3
commit 4e67a34b7b
3 zmienionych plików z 31 dodań i 29 usunięć

Wyświetl plik

@ -63,12 +63,12 @@ class Decoder
// RTTY
public:
typedef TReal TValue;
typedef std::complex<TReal> TComplex;
typedef std::vector<TReal> TRVector;
typedef habdec::IQVector<TReal> TIQVector;
typedef habdec::Decimator< std::complex<TReal>, TReal > TDecimator;
typedef habdec::FirFilter< std::complex<TReal>, TReal> TFIR;
using TValue = TReal;
using TComplex = std::complex<TReal>;
using TRVector = std::vector<TReal>;
using TIQVector = habdec::IQVector<TReal>;
using TDecimator = habdec::Decimator< std::complex<TReal>, TReal >;
using TFIR = habdec::FirFilter< std::complex<TReal>, TReal>;
// feed decoder
bool pushSamples(const TIQVector& i_stream);
@ -128,6 +128,9 @@ public:
bool livePrint() const { return live_print_; }
void livePrint(bool i_live) { live_print_ = i_live; }
std::string ssdvBaseFile() const { return ssdv_.base_file(); }
void ssdvBaseFile(const std::string& _f) { ssdv_.base_file(_f); }
// callback on each successfull sentence decode. callsign, sentence_data, CRC
std::function<void(std::string, std::string, std::string)> sentence_callback_;
@ -137,9 +140,6 @@ public:
// callback on each decoded ssdv packet. callsign, image_id, jpeg_bytes
std::function<void(std::string, int, std::vector<uint8_t>)> ssdv_callback_;
// SSDV
SSDV_wraper_t ssdv_;
private:
// IQ buffers
TIQVector iq_in_buffer_; // input IQ buffer
@ -189,6 +189,9 @@ private:
std::string last_sentence_; // result of rtty
// size_t last_sentence_len_ = 0; // optimization for regexp run
// SSDV
SSDV_wraper_t ssdv_;
// threading
mutable std::mutex process_mutex_; // mutex for main processing

Wyświetl plik

@ -23,6 +23,7 @@
#include <cstring>
#include <iostream>
#include <iomanip>
#include <future>
#include <ctime>
#include <stdio.h>
#include "../ssdv/ssdv.h"
@ -151,21 +152,26 @@ void SSDV_wraper_t::save_jpeg( const image_key_t& image_key )
if( jpegs_.find(image_key) == jpegs_.end() )
return;
const auto& jpeg = jpegs_[image_key];
const auto jpeg = jpegs_[image_key];
const auto base_file = base_file_;
auto t = std::time(nullptr);
char timestamp[200];
strftime(timestamp, 200, "%Y-%m-%d", std::localtime(&t) );
async(launch::async, [&jpeg, &base_file, image_key](){
// timestamp
auto t = std::time(nullptr);
char timestamp[200];
strftime(timestamp, 200, "%Y-%m-%d", std::localtime(&t) );
// filename 0 padding
string img_id_pad = std::to_string(image_key.second);
img_id_pad = string(4 - img_id_pad.length(), '0') + img_id_pad;
string fname = base_file + string(timestamp)
+ "_" + image_key.first
+ "_" + img_id_pad + ".jpeg";
string img_id_pad = std::to_string(image_key.second);
img_id_pad = string(4 - img_id_pad.length(), '0') + img_id_pad;
FILE* fh = fopen( fname.c_str(), "wb" );
fwrite(jpeg.data(), 1, jpeg.size(), fh);
fclose(fh);
});
string fname = base_file_ + string(timestamp)
+ "_" + image_key.first
+ "_" + img_id_pad + ".jpeg";
FILE* fh = fopen( fname.c_str(), "wb" );
fwrite(jpeg.data(), 1, jpeg.size(), fh);
fclose(fh);
}

Wyświetl plik

@ -239,8 +239,6 @@ void DECODER_THREAD()
//////
//
typedef std::chrono::nanoseconds TDur;
auto& DECODER = GLOBALS::get().decoder_;
habdec::IQVector<TReal> samples;
@ -249,8 +247,6 @@ void DECODER_THREAD()
while(1)
{
auto _start = std::chrono::high_resolution_clock::now();
size_t count = p_iq_src->get( samples.data(), samples.size() );
if(count)
samples.resize(count);
@ -278,9 +274,6 @@ void DECODER_THREAD()
}
}
TDur _duration = std::chrono::duration_cast<TDur>(std::chrono::high_resolution_clock::now() - _start);
// accumulate demod samples to display more
{
std::lock_guard<std::mutex> _lock(GLOBALS::get().demod_accumulated_mtx_);
@ -470,7 +463,7 @@ int main(int argc, char** argv)
DECODER.lowpass_trans( G.par_.lowpass_tr_ );
int _decim = G.par_.decimation_;
DECODER.setupDecimationStagesFactor( pow(2,_decim) );
DECODER.ssdv_.base_file( G.par_.ssdv_dir_ + "/ssdv_" );
DECODER.ssdvBaseFile( G.par_.ssdv_dir_ + "/ssdv_" );
double freq = G.par_.frequency_;
G.p_iq_source_->setOption("frequency_double", &freq);