diff --git a/code/Decoder/Decoder.h b/code/Decoder/Decoder.h index f1d9612..e3b79b4 100644 --- a/code/Decoder/Decoder.h +++ b/code/Decoder/Decoder.h @@ -63,12 +63,12 @@ class Decoder // RTTY public: - typedef TReal TValue; - typedef std::complex TComplex; - typedef std::vector TRVector; - typedef habdec::IQVector TIQVector; - typedef habdec::Decimator< std::complex, TReal > TDecimator; - typedef habdec::FirFilter< std::complex, TReal> TFIR; + using TValue = TReal; + using TComplex = std::complex; + using TRVector = std::vector; + using TIQVector = habdec::IQVector; + using TDecimator = habdec::Decimator< std::complex, TReal >; + using TFIR = habdec::FirFilter< std::complex, 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 sentence_callback_; @@ -137,9 +140,6 @@ public: // callback on each decoded ssdv packet. callsign, image_id, jpeg_bytes std::function)> 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 diff --git a/code/Decoder/ssdv_wrapper.cpp b/code/Decoder/ssdv_wrapper.cpp index 9254bb2..5ce2667 100644 --- a/code/Decoder/ssdv_wrapper.cpp +++ b/code/Decoder/ssdv_wrapper.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #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); } diff --git a/code/websocketServer/main.cpp b/code/websocketServer/main.cpp index f449458..da38681 100755 --- a/code/websocketServer/main.cpp +++ b/code/websocketServer/main.cpp @@ -239,8 +239,6 @@ void DECODER_THREAD() ////// // - typedef std::chrono::nanoseconds TDur; - auto& DECODER = GLOBALS::get().decoder_; habdec::IQVector 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(std::chrono::high_resolution_clock::now() - _start); - // accumulate demod samples to display more { std::lock_guard _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);