From d73f093dab44b90e28166220c97f611f797dbbc0 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sat, 13 Mar 2021 00:13:00 +0100 Subject: [PATCH] DATV: various fixes and enhancements to ldpc_tool handling. Implements #804 --- plugins/channelrx/demoddatv/datvdemodsink.cpp | 532 ++++++++---------- plugins/channelrx/demoddatv/datvdemodsink.h | 4 +- .../demoddatv/datvdvbs2constellation.h | 12 +- .../channelrx/demoddatv/datvideorender.cpp | 2 +- plugins/channelrx/demoddatv/datvvideoplayer.h | 8 +- .../demoddatv/ldpctool/ldpc_tool.cpp | 4 +- plugins/channelrx/demoddatv/leansdr/dvb.h | 267 +++++---- plugins/channelrx/demoddatv/leansdr/dvbs2.h | 300 +++++----- .../channelrx/demoddatv/leansdr/framework.h | 50 +- plugins/channelrx/demoddatv/leansdr/sdr.h | 369 +++++++----- plugins/channelrx/demoddatv/leansdr/viterbi.h | 1 + 11 files changed, 856 insertions(+), 693 deletions(-) diff --git a/plugins/channelrx/demoddatv/datvdemodsink.cpp b/plugins/channelrx/demoddatv/datvdemodsink.cpp index 1877b2465..1d4fb306d 100644 --- a/plugins/channelrx/demoddatv/datvdemodsink.cpp +++ b/plugins/channelrx/demoddatv/datvdemodsink.cpp @@ -54,7 +54,7 @@ DATVDemodSink::DATVDemodSink() : { //*************** DATV PARAMETERS *************** m_blnInitialized=false; - CleanUpDATVFramework(false); + ResetDATVFrameworkPointers(); m_objVideoStream = new DATVideostream(); m_objRFFilter = new fftfilt(-256000.0 / 1024000.0, 256000.0 / 1024000.0, m_rfFilterFftLength); } @@ -81,7 +81,7 @@ DATVDemodSink::~DATVDemodSink() m_objRenderThread->wait(2000); } - CleanUpDATVFramework(true); + CleanUpDATVFramework(); delete m_objRFFilter; } @@ -154,7 +154,6 @@ bool DATVDemodSink::videoDecodeOK() bool DATVDemodSink::PlayVideo(bool blnStartStop) { - if (m_objVideoStream == nullptr) { return false; } @@ -195,262 +194,248 @@ bool DATVDemodSink::PlayVideo(bool blnStartStop) return true; } -void DATVDemodSink::CleanUpDATVFramework(bool blnRelease) +void DATVDemodSink::CleanUpDATVFramework() { - if (blnRelease == true) + if (m_objScheduler != nullptr) { - if (m_objScheduler != nullptr) - { - m_objScheduler->shutdown(); - delete m_objScheduler; - } + m_objScheduler->shutdown(); + delete m_objScheduler; + } - // NOTCH FILTER + // NOTCH FILTER - if (r_auto_notch != nullptr) { - delete r_auto_notch; - } - if (p_autonotched != nullptr) { - delete p_autonotched; - } + if (r_auto_notch != nullptr) { + delete r_auto_notch; + } + if (p_autonotched != nullptr) { + delete p_autonotched; + } - // FREQUENCY CORRECTION : DEROTATOR - if (p_derot != nullptr) { - delete p_derot; - } - if (r_derot != nullptr) { - delete r_derot; - } + // FREQUENCY CORRECTION : DEROTATOR + if (p_derot != nullptr) { + delete p_derot; + } + if (r_derot != nullptr) { + delete r_derot; + } - // CNR ESTIMATION - if (p_cnr != nullptr) { - delete p_cnr; - } - if (r_cnr != nullptr) { - delete r_cnr; - } + // CNR ESTIMATION + if (p_cnr != nullptr) { + delete p_cnr; + } + if (r_cnr != nullptr) { + delete r_cnr; + } + if (r_cnrGauge != nullptr) { + delete r_cnrGauge; + } - //FILTERING - if (r_resample != nullptr) { - delete r_resample; - } - if (p_resampled != nullptr) { - delete p_resampled; - } - if (coeffs != nullptr) { - delete coeffs; - } + //FILTERING + if (r_resample != nullptr) { + delete r_resample; + } + if (p_resampled != nullptr) { + delete p_resampled; + } + if (coeffs != nullptr) { + delete coeffs; + } - // OUTPUT PREPROCESSED DATA - if (sampler != nullptr) { - delete sampler; - } - if (coeffs_sampler != nullptr) { - delete coeffs_sampler; - } - if (p_symbols != nullptr) { - delete p_symbols; - } - if (p_freq != nullptr) { - delete p_freq; - } - if (p_ss != nullptr) { - delete p_ss; - } - if (p_mer != nullptr) { - delete p_mer; - } - if (p_sampled != nullptr) { - delete p_sampled; - } + // OUTPUT PREPROCESSED DATA + if (sampler != nullptr) { + delete sampler; + } + if (coeffs_sampler != nullptr) { + delete coeffs_sampler; + } + if (p_symbols != nullptr) { + delete p_symbols; + } + if (p_freq != nullptr) { + delete p_freq; + } + if (p_ss != nullptr) { + delete p_ss; + } + if (p_mer != nullptr) { + delete p_mer; + } + if (r_merGauge != nullptr) { + delete r_merGauge; + } + if (p_sampled != nullptr) { + delete p_sampled; + } - //DECIMATION - if (p_decimated != nullptr) { - delete p_decimated; - } - if (p_decim != nullptr) { - delete p_decim; - } - if (r_ppout != nullptr) { - delete r_ppout; - } + //DECIMATION + if (p_decimated != nullptr) { + delete p_decimated; + } + if (p_decim != nullptr) { + delete p_decim; + } + if (r_ppout != nullptr) { + delete r_ppout; + } - //GENERIC CONSTELLATION RECEIVER - if (m_objDemodulator != nullptr) { - delete m_objDemodulator; - } + //GENERIC CONSTELLATION RECEIVER + if (m_objDemodulator != nullptr) { + delete m_objDemodulator; + } - //DECONVOLUTION AND SYNCHRONIZATION - if (p_bytes != nullptr) { - delete p_bytes; - } - if (r_deconv != nullptr) { - delete r_deconv; - } - if (r != nullptr) { - delete r; - } - if (p_descrambled != nullptr) { - delete p_descrambled; - } - if (p_frames != nullptr) { - delete p_frames; - } - if (r_etr192_descrambler != nullptr) { - delete r_etr192_descrambler; - } - if (r_sync != nullptr) { - delete r_sync; - } - if (p_mpegbytes != nullptr) { - delete p_mpegbytes; - } - if (p_lock != nullptr) { - delete p_lock; - } - if (p_locktime != nullptr) { - delete p_locktime; - } - if (r_sync_mpeg != nullptr) { - delete r_sync_mpeg; - } + //DECONVOLUTION AND SYNCHRONIZATION + if (p_bytes != nullptr) { + delete p_bytes; + } + if (r_deconv != nullptr) { + delete r_deconv; + } + if (r != nullptr) { + delete r; + } + if (p_descrambled != nullptr) { + delete p_descrambled; + } + if (p_frames != nullptr) { + delete p_frames; + } + if (r_etr192_descrambler != nullptr) { + delete r_etr192_descrambler; + } + if (r_sync != nullptr) { + delete r_sync; + } + if (p_mpegbytes != nullptr) { + delete p_mpegbytes; + } + if (p_lock != nullptr) { + delete p_lock; + } + if (p_locktime != nullptr) { + delete p_locktime; + } + if (r_sync_mpeg != nullptr) { + delete r_sync_mpeg; + } - // DEINTERLEAVING - if (p_rspackets != nullptr) { - delete p_rspackets; - } - if (r_deinter != nullptr) { - delete r_deinter; - } - if (p_vbitcount != nullptr) { - delete p_vbitcount; - } - if (p_verrcount != nullptr) { - delete p_verrcount; - } - if (p_rtspackets != nullptr) { - delete p_rtspackets; - } - if (r_rsdec != nullptr) { - delete r_rsdec; - } + // DEINTERLEAVING + if (p_rspackets != nullptr) { + delete p_rspackets; + } + if (r_deinter != nullptr) { + delete r_deinter; + } + if (p_vbitcount != nullptr) { + delete p_vbitcount; + } + if (p_verrcount != nullptr) { + delete p_verrcount; + } + if (p_rtspackets != nullptr) { + delete p_rtspackets; + } + if (r_rsdec != nullptr) { + delete r_rsdec; + } - //BER ESTIMATION - if (p_vber != nullptr) { - delete p_vber; - } - if (r_vber != nullptr) { - delete r_vber; - } + //BER ESTIMATION + if (p_vber != nullptr) { + delete p_vber; + } + if (r_vber != nullptr) { + delete r_vber; + } - // DERANDOMIZATION - if (p_tspackets != nullptr) { - delete p_tspackets; - } - if (r_derand != nullptr) { - delete r_derand; - } + // DERANDOMIZATION + if (p_tspackets != nullptr) { + delete p_tspackets; + } + if (r_derand != nullptr) { + delete r_derand; + } - //OUTPUT : To remove - if (r_stdout != nullptr) { - delete r_stdout; - } - if (r_videoplayer != nullptr) { - delete r_videoplayer; - } + //OUTPUT + if (r_videoplayer != nullptr) { + delete r_videoplayer; + } - //CONSTELLATION - if (r_scope_symbols != nullptr) { - delete r_scope_symbols; - } - if (r_merGauge != nullptr) { - delete r_merGauge; - } - if (r_cnrGauge != nullptr) { - delete r_cnrGauge; - } - - // INPUT - if (p_rawiq != nullptr) { - delete p_rawiq; - } - if (p_rawiq_writer != nullptr) { - delete p_rawiq_writer; - } - //if(p_preprocessed!=nullptr) delete p_preprocessed; - - //DVB-S2 - - if(p_slots_dvbs2 != nullptr) - { - delete (leansdr::pipebuf< leansdr::plslot >*) p_slots_dvbs2; - } - - if(p_cstln != nullptr) - { - delete p_cstln; - } - - if(p_cstln_pls != nullptr) - { - delete p_cstln_pls; - } - - if(p_framelock != nullptr) - { - delete p_framelock; - } - - if(m_objDemodulatorDVBS2 != nullptr) - { - delete (leansdr::s2_frame_receiver*) m_objDemodulatorDVBS2; - } - - if(p_fecframes != nullptr) - { - delete (leansdr::pipebuf< leansdr::fecframe >*) p_fecframes; - } - - if(p_bbframes != nullptr) - { - delete (leansdr::pipebuf*) p_bbframes; - } - - if(p_s2_deinterleaver != nullptr) - { - delete (leansdr::s2_deinterleaver*) p_s2_deinterleaver; - } - - if(r_fecdec != nullptr) - { - delete (leansdr::s2_fecdec*) r_fecdec; - } - -#ifdef LINUX - if(r_fecdecsoft != nullptr) - { - delete (leansdr::s2_fecdec_soft*) r_fecdecsoft; - } - if(r_fecdechelper != nullptr) - { - delete (leansdr::s2_fecdec_helper*) r_fecdechelper; - } -#endif - - if(p_deframer != nullptr) - { - delete (leansdr::s2_deframer*) p_deframer; - } - - if(r_scope_symbols_dvbs2 != nullptr) - { - delete r_scope_symbols_dvbs2; - } - } // blnRelease - - m_objScheduler=nullptr; + //CONSTELLATION + if (r_scope_symbols != nullptr) { + delete r_scope_symbols; + } // INPUT + if (p_rawiq != nullptr) { + delete p_rawiq; + } + if (p_rawiq_writer != nullptr) { + delete p_rawiq_writer; + } + //if(p_preprocessed!=nullptr) delete p_preprocessed; + + //DVB-S2 + + if (p_slots_dvbs2 != nullptr) { + delete (leansdr::pipebuf< leansdr::plslot >*) p_slots_dvbs2; + } + + if (p_cstln != nullptr) { + delete p_cstln; + } + + if (p_cstln_pls != nullptr) { + delete p_cstln_pls; + } + + if (p_framelock != nullptr) { + delete p_framelock; + } + + if (m_objDemodulatorDVBS2 != nullptr) { + delete (leansdr::s2_frame_receiver*) m_objDemodulatorDVBS2; + } + + if (p_fecframes != nullptr) { + delete (leansdr::pipebuf< leansdr::fecframe >*) p_fecframes; + } + + if (p_bbframes != nullptr) { + delete (leansdr::pipebuf*) p_bbframes; + } + + if (p_s2_deinterleaver != nullptr) { + delete (leansdr::s2_deinterleaver*) p_s2_deinterleaver; + } + + if (r_fecdec != nullptr) { + delete (leansdr::s2_fecdec*) r_fecdec; + } + +#ifdef LINUX + if (r_fecdecsoft != nullptr) { + delete (leansdr::s2_fecdec_soft*) r_fecdecsoft; + } + + if (r_fecdechelper != nullptr) { + delete (leansdr::s2_fecdec_helper*) r_fecdechelper; + } +#endif + + if (p_deframer != nullptr) { + delete (leansdr::s2_deframer*) p_deframer; + } + + if (r_scope_symbols_dvbs2 != nullptr) { + delete r_scope_symbols_dvbs2; + } + + ResetDATVFrameworkPointers(); +} + +void DATVDemodSink::ResetDATVFrameworkPointers() +{ + // INPUT + m_objScheduler = nullptr; p_rawiq = nullptr; p_rawiq_writer = nullptr; @@ -468,6 +453,7 @@ void DATVDemodSink::CleanUpDATVFramework(bool blnRelease) // CNR ESTIMATION p_cnr = nullptr; r_cnr = nullptr; + r_cnrGauge = nullptr; //FILTERING r_resample = nullptr; @@ -484,6 +470,7 @@ void DATVDemodSink::CleanUpDATVFramework(bool blnRelease) p_freq = nullptr; p_ss = nullptr; p_mer = nullptr; + r_merGauge = nullptr; p_sampled = nullptr; //DECIMATION @@ -509,7 +496,6 @@ void DATVDemodSink::CleanUpDATVFramework(bool blnRelease) p_locktime = nullptr; r_sync_mpeg = nullptr; - // DEINTERLEAVING p_rspackets = nullptr; r_deinter = nullptr; @@ -519,26 +505,19 @@ void DATVDemodSink::CleanUpDATVFramework(bool blnRelease) p_rtspackets = nullptr; r_rsdec = nullptr; - //BER ESTIMATION p_vber = nullptr; r_vber = nullptr; - // DERANDOMIZATION p_tspackets = nullptr; r_derand = nullptr; - //OUTPUT : To remove void * - r_stdout = nullptr; r_videoplayer = nullptr; - //CONSTELLATION r_scope_symbols = nullptr; - r_merGauge = nullptr; - r_cnrGauge = nullptr; //DVB-S2 p_slots_dvbs2 = nullptr; @@ -550,8 +529,10 @@ void DATVDemodSink::CleanUpDATVFramework(bool blnRelease) p_bbframes = nullptr; p_s2_deinterleaver = nullptr; r_fecdec = nullptr; +#ifdef LINUX r_fecdecsoft = nullptr; r_fecdechelper = nullptr; +#endif p_deframer = nullptr; r_scope_symbols_dvbs2 = nullptr; } @@ -560,7 +541,7 @@ void DATVDemodSink::InitDATVFramework() { m_blnDVBInitialized = false; m_lngReadIQ = 0; - CleanUpDATVFramework(false); + CleanUpDATVFramework(); qDebug() << "DATVDemodSink::InitDATVFramework:" << " Standard: " << m_settings.m_standard @@ -675,7 +656,6 @@ void DATVDemodSink::InitDATVFramework() p_preprocessed = p_autonotched; } - // FREQUENCY CORRECTION //******** -> if ( m_objCfg.Fderot>0 ) @@ -696,7 +676,6 @@ void DATVDemodSink::InitDATVFramework() //******** -> if ( m_objCfg.resample ) - // DECIMATION // (Unless already done in resampler) @@ -704,7 +683,6 @@ void DATVDemodSink::InitDATVFramework() //Resampling FS - // Generic constellation receiver p_symbols = new leansdr::pipebuf(m_objScheduler, "PSK soft-symbols", BUF_SYMBOLS); @@ -898,7 +876,7 @@ void DATVDemodSink::InitDATVS2Framework() m_blnDVBInitialized = false; m_lngReadIQ = 0; - CleanUpDATVFramework(true); + CleanUpDATVFramework(); qDebug() << "DATVDemodSink::InitDATVS2Framework:" << " Standard: " << m_settings.m_standard @@ -1026,7 +1004,6 @@ void DATVDemodSink::InitDATVS2Framework() //******** -> if ( m_objCfg.resample ) - // DECIMATION // (Unless already done in resampler) @@ -1034,7 +1011,6 @@ void DATVDemodSink::InitDATVS2Framework() //Resampling FS - // Generic constellation receiver p_freq = new leansdr::pipebuf (m_objScheduler, "freq", BUF_SLOW); @@ -1076,24 +1052,22 @@ void DATVDemodSink::InitDATVS2Framework() p_framelock = new leansdr::pipebuf(m_objScheduler, "frame lock", BUF_SLOW); m_objDemodulatorDVBS2 = new leansdr::s2_frame_receiver( - m_objScheduler, - sampler, - *p_preprocessed, - *(leansdr::pipebuf< leansdr::plslot > *) p_slots_dvbs2, - /* p_freq */ nullptr, - /* p_ss */ nullptr, - p_mer, - p_cstln, - /* p_cstln_pls */ nullptr, - /*p_iqsymbols*/ nullptr, - /* p_framelock */nullptr); + m_objScheduler, + sampler, + *p_preprocessed, + *(leansdr::pipebuf< leansdr::plslot > *) p_slots_dvbs2, + /* p_freq */ nullptr, + /* p_ss */ nullptr, + p_mer, + p_cstln, + /* p_cstln_pls */ nullptr, + /*p_iqsymbols*/ nullptr, + /* p_framelock */nullptr + ); objDemodulatorDVBS2 = (leansdr::s2_frame_receiver *) m_objDemodulatorDVBS2; - - objDemodulatorDVBS2->omega0 = m_objCfg.Fs/m_objCfg.Fm; -//objDemodulatorDVBS2->mu=1; - + //objDemodulatorDVBS2->mu=1; m_objCfg.Ftune=0.0f; objDemodulatorDVBS2->Ftune = m_objCfg.Ftune / m_objCfg.Fm; @@ -1102,12 +1076,8 @@ void DATVDemodSink::InitDATVS2Framework() demod.strongpls = cfg.strongpls; */ - //objDemodulatorDVBS2->Fm = m_objCfg.Fm; deprecated objDemodulatorDVBS2->meas_decimation = decimation(m_objCfg.Fs, m_objCfg.Finfo); - objDemodulatorDVBS2->strongpls = false; - - objDemodulatorDVBS2->cstln = make_dvbs2_constellation(m_objCfg.constellation, m_objCfg.fec); m_cstlnSetByModcod = false; @@ -1116,7 +1086,6 @@ void DATVDemodSink::InitDATVS2Framework() if (m_objRegisteredTVScreen) { qDebug("DATVDemodSink::InitDATVS2Framework: Register DVBS 2 TVSCREEN"); - m_objRegisteredTVScreen->resizeTVScreen(256,256); r_scope_symbols_dvbs2 = new leansdr::datvdvbs2constellation(m_objScheduler, *p_cstln /* *p_sampled */ /* *p_cstln */, -128,128, nullptr, m_objRegisteredTVScreen); r_scope_symbols_dvbs2->decimation = 1; @@ -1249,13 +1218,11 @@ void DATVDemodSink::InitDATVS2Framework() p_lock = new leansdr::pipebuf (m_objScheduler, "lock", BUF_SLOW); p_locktime = new leansdr::pipebuf (m_objScheduler, "locktime", BUF_S2PACKETS); p_tspackets = new leansdr::pipebuf(m_objScheduler, "TS packets", BUF_S2PACKETS); - p_deframer = new leansdr::s2_deframer(m_objScheduler,*(leansdr::pipebuf *) p_bbframes, *p_tspackets, p_lock, p_locktime); /* if ( cfg.fd_gse >= 0 ) deframer.fd_gse = cfg.fd_gse; */ - //********************************************** // OUTPUT r_videoplayer = new leansdr::datvvideoplayer(m_objScheduler, *p_tspackets, m_objVideoStream, &m_udpStream); @@ -1268,7 +1235,6 @@ void DATVDemodSink::feed(const SampleVector::const_iterator& begin, const Sample float fltI; float fltQ; leansdr::cf32 objIQ; - //Complex objC; fftfilt::cmplx *objRF; int intRFOut; double magSq; @@ -1276,7 +1242,6 @@ void DATVDemodSink::feed(const SampleVector::const_iterator& begin, const Sample int lngWritable=0; //********** Bis repetita : Let's rock and roll buddy ! ********** - #ifdef EXTENDED_DIRECT_SAMPLE qint16 * ptrBuffer; @@ -1306,10 +1271,7 @@ void DATVDemodSink::feed(const SampleVector::const_iterator& begin, const Sample fltQ = it->imag(); #endif - //********** demodulation ********** - - if (m_blnNeedConfigUpdate) { qDebug("DATVDemodSink::feed: Settings applied. Standard : %d...", m_settings.m_standard); @@ -1327,13 +1289,9 @@ void DATVDemodSink::feed(const SampleVector::const_iterator& begin, const Sample } } - //********** iq stream **************** - Complex objC(fltI,fltQ); - objC *= m_objNCO.nextIQ(); - intRFOut = m_objRFFilter->runFilt(objC, &objRF); // filter RF before demod for (int intI = 0 ; intI < intRFOut; intI++) diff --git a/plugins/channelrx/demoddatv/datvdemodsink.h b/plugins/channelrx/demoddatv/datvdemodsink.h index be81bc909..0dd03ec17 100644 --- a/plugins/channelrx/demoddatv/datvdemodsink.h +++ b/plugins/channelrx/demoddatv/datvdemodsink.h @@ -142,7 +142,8 @@ private: inline int decimation(float Fin, float Fout) { int d = Fin / Fout; return std::max(d, 1); } - void CleanUpDATVFramework(bool blnRelease); + void CleanUpDATVFramework(); + void ResetDATVFrameworkPointers(); void InitDATVFramework(); void InitDATVS2Framework(); @@ -274,7 +275,6 @@ private: //OUTPUT - leansdr::file_writer *r_stdout; leansdr::datvvideoplayer *r_videoplayer; //CONSTELLATION diff --git a/plugins/channelrx/demoddatv/datvdvbs2constellation.h b/plugins/channelrx/demoddatv/datvdvbs2constellation.h index 27fe08202..0d9b2bd1c 100644 --- a/plugins/channelrx/demoddatv/datvdvbs2constellation.h +++ b/plugins/channelrx/demoddatv/datvdvbs2constellation.h @@ -123,12 +123,12 @@ template struct datvdvbs2constellation: runnable std::vector cstln_cols; datvdvbs2constellation( - scheduler *sch, - pipebuf > &_in, - T _xymin, - T _xymax, - const char *_name = nullptr, - TVScreen *objDATVScreen = nullptr) : + scheduler *sch, + pipebuf > &_in, + T _xymin, + T _xymax, + const char *_name = nullptr, + TVScreen *objDATVScreen = nullptr) : runnable(sch, _name ? _name : _in.name), xymin(_xymin), xymax(_xymax), diff --git a/plugins/channelrx/demoddatv/datvideorender.cpp b/plugins/channelrx/demoddatv/datvideorender.cpp index f1798db57..bbe76ac2a 100644 --- a/plugins/channelrx/demoddatv/datvideorender.cpp +++ b/plugins/channelrx/demoddatv/datvideorender.cpp @@ -255,7 +255,7 @@ bool DATVideoRender::PreprocessStream() MetaData.Program = ""; MetaData.Stream = ""; - if (m_formatCtx->programs) + if (m_formatCtx->programs && m_formatCtx->programs[m_videoStreamIndex]) { buffer = nullptr; av_dict_get_string(m_formatCtx->programs[m_videoStreamIndex]->metadata, &buffer, ':', '\n'); diff --git a/plugins/channelrx/demoddatv/datvvideoplayer.h b/plugins/channelrx/demoddatv/datvvideoplayer.h index 2509d7aba..48c259ee1 100644 --- a/plugins/channelrx/demoddatv/datvvideoplayer.h +++ b/plugins/channelrx/demoddatv/datvvideoplayer.h @@ -29,10 +29,10 @@ namespace leansdr template struct datvvideoplayer: runnable { datvvideoplayer( - scheduler *sch, - pipebuf &_in, - DATVideostream *objVideoStream, - DATVUDPStream *udpStream) : + scheduler *sch, + pipebuf &_in, + DATVideostream *objVideoStream, + DATVUDPStream *udpStream) : runnable(sch, _in.name), in(_in), m_objVideoStream(objVideoStream), diff --git a/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp b/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp index ef4b2a8ea..7fd7cc10c 100644 --- a/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp +++ b/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp @@ -181,8 +181,8 @@ int main(int argc, char **argv) if (num_decodes == 20) { - fprintf(stderr, "ldpc_tool: trials: %d%% max: %d%% at converging to a code word\n", - (trials_count*100)/(num_decodes*max_trials), (max_count*100)/num_decodes); + fprintf(stderr, "ldpc_tool: trials: %d%% max: %d%% at converging to a code word (max trials: %d)\n", + (trials_count*100)/(num_decodes*max_trials), (max_count*100)/num_decodes, max_trials); trials_count = 0; max_count = 0; num_decodes = 0; diff --git a/plugins/channelrx/demoddatv/leansdr/dvb.h b/plugins/channelrx/demoddatv/leansdr/dvb.h index cedb8463c..d1160a871 100644 --- a/plugins/channelrx/demoddatv/leansdr/dvb.h +++ b/plugins/channelrx/demoddatv/leansdr/dvb.h @@ -111,17 +111,20 @@ static const int DVBS_G2 = 0133; template struct deconvol_sync : runnable { - deconvol_sync(scheduler *sch, - pipebuf &_in, - pipebuf &_out, - uint32_t gX, - uint32_t gY, - uint32_t pX, - uint32_t pY) : runnable(sch, "deconvol_sync"), - fastlock(false), - in(_in), - out(_out, SIZE_RSPACKET), - skip(0) + deconvol_sync( + scheduler *sch, + pipebuf &_in, + pipebuf &_out, + uint32_t gX, + uint32_t gY, + uint32_t pX, + uint32_t pY + ) : + runnable(sch, "deconvol_sync"), + fastlock(false), + in(_in), + out(_out, SIZE_RSPACKET), + skip(0) { conv = new uint32_t[2]; conv[0] = gX; @@ -151,6 +154,14 @@ struct deconvol_sync : runnable locked = &syncs[0]; } + ~deconvol_sync() + { + delete[] deconv2; + delete[] deconv; + delete[] punct; + delete[] conv; + } + typedef uint64_t signal_t; typedef uint64_t iq_t; @@ -582,10 +593,11 @@ struct deconvol_sync : runnable typedef deconvol_sync deconvol_sync_simple; -deconvol_sync_simple *make_deconvol_sync_simple(scheduler *sch, - pipebuf &_in, - pipebuf &_out, - enum code_rate rate); +deconvol_sync_simple *make_deconvol_sync_simple( + scheduler *sch, + pipebuf &_in, + pipebuf &_out, + enum code_rate rate); // CONVOLUTIONAL ENCODER @@ -665,13 +677,16 @@ struct dvb_convol : runnable typedef u8 uncoded_byte; typedef u8 hardsymbol; - dvb_convol(scheduler *sch, - pipebuf &_in, - pipebuf &_out, - code_rate fec, - int bits_per_symbol) : runnable(sch, "dvb_convol"), - in(_in), - out(_out, 64) // BPSK 7/8: 7 bytes in, 64 symbols out + dvb_convol( + scheduler *sch, + pipebuf &_in, + pipebuf &_out, + code_rate fec, + int bits_per_symbol + ) : + runnable(sch, "dvb_convol"), + in(_in), + out(_out, 64) // BPSK 7/8: 7 bytes in, 64 symbols out { fec_spec *fs = &fec_specs[fec]; @@ -719,13 +734,16 @@ struct dvb_deconvol_sync : runnable int resync_period; static const int chunk_size = 64; // At least 2*sizeof(Thist)/8 - dvb_deconvol_sync(scheduler *sch, - pipebuf &_in, - pipebuf &_out) : runnable(sch, "deconvol_sync_multipoly"), - resync_period(32), - in(_in), - out(_out, chunk_size), - resync_phase(0) + dvb_deconvol_sync( + scheduler *sch, + pipebuf &_in, + pipebuf &_out + ) : + runnable(sch, "deconvol_sync_multipoly"), + resync_period(32), + in(_in), + out(_out, chunk_size), + resync_phase(0) { init_syncs(); locked = &syncs[0]; @@ -736,7 +754,7 @@ struct dvb_deconvol_sync : runnable while (in.readable() >= chunk_size * 8 && out.writable() >= chunk_size) { int errors_best = 1 << 30; - sync_t *best = NULL; + sync_t *best = nullptr; for (sync_t *s = syncs; s < syncs + NSYNCS; ++s) { @@ -833,29 +851,42 @@ struct mpeg_sync : runnable bool fastlock; int resync_period; - mpeg_sync(scheduler *sch, - pipebuf &_in, - pipebuf &_out, - deconvol_sync *_deconv, - pipebuf *_state_out = NULL, - pipebuf *_locktime_out = NULL) : runnable(sch, "sync_detect"), - scan_syncs(8), - want_syncs(4), - lock_timeout(4), - fastlock(false), - resync_period(1), - in(_in), - out(_out, SIZE_RSPACKET * (scan_syncs + 1)), - deconv(_deconv), - polarity(0), - resync_phase(0), - bitphase(0), - synchronized(false), - next_sync_count(0), - report_state(true) + mpeg_sync( + scheduler *sch, + pipebuf &_in, + pipebuf &_out, + deconvol_sync *_deconv, + pipebuf *_state_out = nullptr, + pipebuf *_locktime_out = nullptr + ) : + runnable(sch, "sync_detect"), + scan_syncs(8), + want_syncs(4), + lock_timeout(4), + fastlock(false), + resync_period(1), + in(_in), + out(_out, SIZE_RSPACKET * (scan_syncs + 1)), + deconv(_deconv), + polarity(0), + resync_phase(0), + bitphase(0), + synchronized(false), + next_sync_count(0), + report_state(true) { - state_out = _state_out ? new pipewriter(*_state_out) : NULL; - locktime_out = _locktime_out ? new pipewriter(*_locktime_out) : NULL; + state_out = _state_out ? new pipewriter(*_state_out) : nullptr; + locktime_out = _locktime_out ? new pipewriter(*_locktime_out) : nullptr; + } + + ~mpeg_sync() + { + if (state_out) { + delete state_out; + } + if (locktime_out) { + delete locktime_out; + } } void run() @@ -1096,11 +1127,14 @@ struct rspacket struct interleaver : runnable { - interleaver(scheduler *sch, - pipebuf> &_in, - pipebuf &_out) : runnable(sch, "interleaver"), - in(_in), - out(_out, SIZE_RSPACKET) + interleaver( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out + ) : + runnable(sch, "interleaver"), + in(_in), + out(_out, SIZE_RSPACKET) { } @@ -1112,8 +1146,7 @@ struct interleaver : runnable u8 *pout = out.wr(); int delay = 0; - for (int i = 0; i < SIZE_RSPACKET; ++i, ++pout, delay = (delay + 1) % 12) - { + for (int i = 0; i < SIZE_RSPACKET; ++i, ++pout, delay = (delay + 1) % 12) { *pout = pin[11 - delay].data[i]; } @@ -1133,11 +1166,14 @@ struct interleaver : runnable template struct deinterleaver : runnable { - deinterleaver(scheduler *sch, - pipebuf &_in, - pipebuf> &_out) : runnable(sch, "deinterleaver"), - in(_in), - out(_out) + deinterleaver( + scheduler *sch, + pipebuf &_in, + pipebuf> &_out + ) : + runnable(sch, "deinterleaver"), + in(_in), + out(_out) { } @@ -1148,8 +1184,7 @@ struct deinterleaver : runnable Tbyte *pin = in.rd() + 17 * 11 * 12, *pend = pin + SIZE_RSPACKET; Tbyte *pout = out.wr()->data; - for (int delay = 17 * 11; pin < pend; ++pin, ++pout, delay = (delay - 17 + 17 * 12) % (17 * 12)) - { + for (int delay = 17 * 11; pin < pend; ++pin, ++pout, delay = (delay - 17 + 17 * 12) % (17 * 12)) { *pout = pin[-delay * 12]; } @@ -1175,11 +1210,14 @@ struct tspacket struct rs_encoder : runnable { - rs_encoder(scheduler *sch, - pipebuf &_in, - pipebuf> &_out) : runnable(sch, "RS encoder"), - in(_in), - out(_out) + rs_encoder( + scheduler *sch, + pipebuf &_in, + pipebuf> &_out + ) : + runnable(sch, "RS encoder"), + in(_in), + out(_out) { } @@ -1213,16 +1251,29 @@ struct rs_decoder : runnable { rs_engine rs; - rs_decoder(scheduler *sch, - pipebuf> &_in, - pipebuf &_out, - pipebuf *_bitcount = NULL, - pipebuf *_errcount = NULL) : runnable(sch, "RS decoder"), - in(_in), - out(_out) + rs_decoder( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out, + pipebuf *_bitcount = nullptr, + pipebuf *_errcount = nullptr + ) : + runnable(sch, "RS decoder"), + in(_in), + out(_out) { - bitcount = _bitcount ? new pipewriter(*_bitcount) : NULL; - errcount = _errcount ? new pipewriter(*_errcount) : NULL; + bitcount = _bitcount ? new pipewriter(*_bitcount) : nullptr; + errcount = _errcount ? new pipewriter(*_errcount) : nullptr; + } + + ~rs_decoder() + { + if (bitcount) { + delete bitcount; + } + if (errcount) { + delete errcount; + } } void run() @@ -1307,11 +1358,14 @@ struct rs_decoder : runnable struct randomizer : runnable { - randomizer(scheduler *sch, - pipebuf &_in, - pipebuf &_out) : runnable(sch, "derandomizer"), - in(_in), - out(_out) + randomizer( + scheduler *sch, + pipebuf &_in, + pipebuf &_out + ) : + runnable(sch, "derandomizer"), + in(_in), + out(_out) { precompute_pattern(); pos = pattern; @@ -1367,11 +1421,14 @@ struct randomizer : runnable struct derandomizer : runnable { - derandomizer(scheduler *sch, - pipebuf &_in, - pipebuf &_out) : runnable(sch, "derandomizer"), - in(_in), - out(_out) + derandomizer( + scheduler *sch, + pipebuf &_in, + pipebuf &_out + ) : + runnable(sch, "derandomizer"), + in(_in), + out(_out) { precompute_pattern(); pos = pattern; @@ -1525,17 +1582,20 @@ struct viterbi_sync : runnable public: int resync_period; - viterbi_sync(scheduler *sch, - pipebuf &_in, - pipebuf &_out, - cstln_lut *_cstln, - code_rate cr) : runnable(sch, "viterbi_sync"), - in(_in), - out(_out, chunk_size), - cstln(_cstln), - current_sync(0), - resync_phase(0), - resync_period(32) // 1/32 = 9% synchronization overhead TBD + viterbi_sync( + scheduler *sch, + pipebuf &_in, + pipebuf &_out, + cstln_lut *_cstln, + code_rate cr + ) : + runnable(sch, "viterbi_sync"), + in(_in), + out(_out, chunk_size), + cstln(_cstln), + current_sync(0), + resync_phase(0), + resync_period(32) // 1/32 = 9% synchronization overhead TBD { bits_per_symbol = log2i(cstln->nsymbols); fec = &fec_specs[cr]; @@ -1659,6 +1719,11 @@ struct viterbi_sync : runnable } } + ~viterbi_sync() + { + delete syncs; + } + TCS *init_map(bool conj, float angle) { // Each constellation has its own pattern for labels. diff --git a/plugins/channelrx/demoddatv/leansdr/dvbs2.h b/plugins/channelrx/demoddatv/leansdr/dvbs2.h index ef8642dd1..cb45a4587 100644 --- a/plugins/channelrx/demoddatv/leansdr/dvbs2.h +++ b/plugins/channelrx/demoddatv/leansdr/dvbs2.h @@ -299,11 +299,14 @@ const modcod_info *check_modcod(int m) template struct s2_frame_transmitter : runnable { - s2_frame_transmitter(scheduler *sch, - pipebuf> &_in, - pipebuf> &_out) - : runnable(sch, "S2 frame transmitter"), - in(_in), out(_out, modcod_info::MAX_SYMBOLS_PER_FRAME) + s2_frame_transmitter( + scheduler *sch, + pipebuf> &_in, + pipebuf> &_out + ) : + runnable(sch, "S2 frame transmitter"), + in(_in), + out(_out, modcod_info::MAX_SYMBOLS_PER_FRAME) { float amp = cstln_amp / sqrtf(2); qsymbols[0].re = +amp; @@ -437,65 +440,17 @@ static int pl_errors = 0, pl_symbols = 0; template struct s2_frame_receiver : runnable { - sampler_interface *sampler; - int meas_decimation; - float Ftune; // Tuning bias in cycles per symbol - float Fm; // Baud rate in Hz, for debug messages only. TBD remove. - bool strongpls; - static const int MAX_SYMBOLS_PER_FRAME = - (1 + modcod_info::MAX_SLOTS_PER_FRAME) * plslot::LENGTH + - ((modcod_info::MAX_SLOTS_PER_FRAME - 1) / 16) * pilot_length; - s2_frame_receiver(scheduler *sch, - sampler_interface *_sampler, - pipebuf> &_in, - pipebuf> &_out, - pipebuf *_freq_out = nullptr, - pipebuf *_ss_out = nullptr, - pipebuf *_mer_out = nullptr, - pipebuf> *_cstln_out = nullptr, - pipebuf> *_cstln_pls_out = nullptr, - pipebuf> *_symbols_out = nullptr, - pipebuf *_state_out = nullptr) - : runnable(sch, "S2 frame receiver"), - sampler(_sampler), - meas_decimation(1048576), - Ftune(0), Fm(0), - strongpls(false), - in_power(0), ev_power(0), agc_gain(1), agc_bw(1e-3), - nsyncs(0), - cstln(nullptr), - in(_in), out(_out, 1 + modcod_info::MAX_SLOTS_PER_FRAME), - meas_count(0), - freq_out(opt_writer(_freq_out)), - ss_out(opt_writer(_ss_out)), - mer_out(opt_writer(_mer_out)), - cstln_out(opt_writer(_cstln_out, 1024)), - cstln_pls_out(opt_writer(_cstln_pls_out, 1024)), - symbols_out(opt_writer(_symbols_out, MAX_SYMBOLS_PER_FRAME)), - state_out(opt_writer(_state_out)), - report_state(false), - scrambling(0), - m_modcodType(-1), - m_modcodRate(-1) - { - // Constellation for PLS - qpsk = new cstln_lut(cstln_base::QPSK); - add_syncs(qpsk); - - init_coarse_freq(); - -#if TEST_DIVERSITY - fprintf(stderr, "** DEBUG: Diversity test mode (slower)\n"); -#endif - } - - enum - { + enum { COARSE_FREQ, FRAME_SEARCH, FRAME_LOCKED, } state; + sampler_interface *sampler; + int meas_decimation; + float Ftune; // Tuning bias in cycles per symbol + float Fm; // Baud rate in Hz, for debug messages only. TBD remove. + bool strongpls; float min_freqw16, max_freqw16; // State during COARSE_FREQ @@ -509,6 +464,61 @@ struct s2_frame_receiver : runnable float mu; // Time to next symbol, in samples float omega0; // Samples per symbol + static const int MAX_SYMBOLS_PER_FRAME = + (1 + modcod_info::MAX_SLOTS_PER_FRAME) * plslot::LENGTH + + ((modcod_info::MAX_SLOTS_PER_FRAME - 1) / 16) * pilot_length; + + s2_frame_receiver( + scheduler *sch, + sampler_interface *_sampler, + pipebuf> &_in, + pipebuf> &_out, + pipebuf *_freq_out = nullptr, + pipebuf *_ss_out = nullptr, + pipebuf *_mer_out = nullptr, + pipebuf> *_cstln_out = nullptr, + pipebuf> *_cstln_pls_out = nullptr, + pipebuf> *_symbols_out = nullptr, + pipebuf *_state_out = nullptr + ) : + runnable(sch, "S2 frame receiver"), + sampler(_sampler), + meas_decimation(1048576), + Ftune(0), Fm(0), + strongpls(false), + in_power(0), ev_power(0), agc_gain(1), agc_bw(1e-3), + nsyncs(0), + cstln(nullptr), + in(_in), out(_out, 1 + modcod_info::MAX_SLOTS_PER_FRAME), + meas_count(0), + freq_out(opt_writer(_freq_out)), + ss_out(opt_writer(_ss_out)), + mer_out(opt_writer(_mer_out)), + cstln_out(opt_writer(_cstln_out, 1024)), + cstln_pls_out(opt_writer(_cstln_pls_out, 1024)), + symbols_out(opt_writer(_symbols_out, MAX_SYMBOLS_PER_FRAME)), + state_out(opt_writer(_state_out)), + report_state(false), + scrambling(0), + m_modcodType(-1), + m_modcodRate(-1) + { + // Constellation for PLS + qpsk = new cstln_lut(cstln_base::QPSK); + add_syncs(qpsk); + + init_coarse_freq(); + +#if TEST_DIVERSITY + fprintf(stderr, "** DEBUG: Diversity test mode (slower)\n"); +#endif + } + + ~s2_frame_receiver() + { + delete qpsk; + } + void run() { // Require enough samples to detect one plheader, @@ -1237,11 +1247,14 @@ struct fecframe struct s2_interleaver : runnable { - s2_interleaver(scheduler *sch, - pipebuf> &_in, - pipebuf> &_out) - : runnable(sch, "S2 interleaver"), - in(_in), out(_out, 1 + 360) + s2_interleaver( + scheduler *sch, + pipebuf> &_in, + pipebuf> &_out + ) : + runnable(sch, "S2 interleaver"), + in(_in), + out(_out, 1 + 360) { } void run() @@ -1566,13 +1579,17 @@ struct s2_interleaver : runnable template struct s2_deinterleaver : runnable { - s2_deinterleaver(scheduler *sch, - pipebuf> &_in, - pipebuf> &_out) - : runnable(sch, "S2 deinterleaver"), - in(_in), out(_out) + s2_deinterleaver( + scheduler *sch, + pipebuf> &_in, + pipebuf> &_out + ) : + runnable(sch, "S2 deinterleaver"), + in(_in), + out(_out) { } + void run() { while (in.readable() >= 1 && out.writable() >= 1) @@ -2044,10 +2061,14 @@ struct s2_bch_engines struct s2_fecenc : runnable { typedef ldpc_engine s2_ldpc_engine; - s2_fecenc(scheduler *sch, - pipebuf &_in, pipebuf> &_out) - : runnable(sch, "S2 fecenc"), - in(_in), out(_out) + s2_fecenc( + scheduler *sch, + pipebuf &_in, + pipebuf> &_out + ) : + runnable(sch, "S2 fecenc"), + in(_in), + out(_out) { if (sch->debug) s2ldpc.print_node_stats(); @@ -2097,15 +2118,18 @@ template struct s2_fecdec : runnable { int bitflips; - s2_fecdec(scheduler *sch, - pipebuf> &_in, pipebuf &_out, - pipebuf *_bitcount = nullptr, - pipebuf *_errcount = nullptr) - : runnable(sch, "S2 fecdec"), - bitflips(0), - in(_in), out(_out), - bitcount(opt_writer(_bitcount, 1)), - errcount(opt_writer(_errcount, 1)) + s2_fecdec( + scheduler *sch, + pipebuf> &_in, pipebuf &_out, + pipebuf *_bitcount = nullptr, + pipebuf *_errcount = nullptr + ) : + runnable(sch, "S2 fecdec"), + bitflips(0), + in(_in), + out(_out), + bitcount(opt_writer(_bitcount, 1)), + errcount(opt_writer(_errcount, 1)) { if (sch->debug) s2ldpc.print_node_stats(); @@ -2186,21 +2210,24 @@ struct s2_fecdec : runnable template struct s2_fecdec_soft : runnable { - s2_fecdec_soft(scheduler *sch, - pipebuf> &_in, - pipebuf &_out, - int _modcod, - bool _shortframes = true, - int _max_trials = 25, - pipebuf *_bitcount = nullptr, - pipebuf *_errcount = nullptr) - : runnable(sch, "S2 fecdec soft"), - in(_in), out(_out), - modcod(_modcod < 0 ? 0 : _modcod > 31 ? 31 : _modcod), - shortframes(_shortframes ? 1 : 0), - max_trials(_max_trials), - bitcount(opt_writer(_bitcount, 1)), - errcount(opt_writer(_errcount, 1)) + s2_fecdec_soft( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out, + int _modcod, + bool _shortframes = true, + int _max_trials = 25, + pipebuf *_bitcount = nullptr, + pipebuf *_errcount = nullptr + ) : + runnable(sch, "S2 fecdec soft"), + in(_in), + out(_out), + modcod(_modcod < 0 ? 0 : _modcod > 31 ? 31 : _modcod), + shortframes(_shortframes ? 1 : 0), + max_trials(_max_trials), + bitcount(opt_writer(_bitcount, 1)), + errcount(opt_writer(_errcount, 1)) { const char *tabname = ldpctool::LDPCInterface::mc_tabnames[shortframes][modcod]; fprintf(stderr, "s2_fecdec_soft::s2_fecdec_soft: tabname: %s\n", tabname); @@ -2357,20 +2384,23 @@ struct s2_fecdec_helper : runnable bool must_buffer; int max_trials; - s2_fecdec_helper(scheduler *sch, - pipebuf> &_in, - pipebuf &_out, - const char *_command, - pipebuf *_bitcount = nullptr, - pipebuf *_errcount = nullptr) - : runnable(sch, "S2 fecdec io"), - batch_size(16), - nhelpers(1), - must_buffer(false), - max_trials(8), - in(_in), out(_out), - bitcount(opt_writer(_bitcount, 1)), - errcount(opt_writer(_errcount, 1)) + s2_fecdec_helper( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out, + const char *_command, + pipebuf *_bitcount = nullptr, + pipebuf *_errcount = nullptr + ) : + runnable(sch, "S2 fecdec io"), + batch_size(16), + nhelpers(1), + must_buffer(false), + max_trials(8), + in(_in), + out(_out), + bitcount(opt_writer(_bitcount, 1)), + errcount(opt_writer(_errcount, 1)) { command = strdup(_command); for (int mc = 0; mc < 32; ++mc) @@ -2459,6 +2489,7 @@ struct s2_fecdec_helper : runnable lseek(h->fd_tx, 0, SEEK_SET); // allow new writes on this worker continue; // next worker } + if (nw < 0) fatal("write(LDPC helper"); else if (nw != iosize) @@ -2524,9 +2555,9 @@ struct s2_fecdec_helper : runnable int cs; waitpid(h->pid, &cs, 0); } - // reset pipes - lseek(h->fd_tx, 0, SEEK_SET); - lseek(h->fd_rx, 0, SEEK_SET); + // close pipes + close(h->fd_tx); + close(h->fd_rx); } delete p->procs; @@ -2638,7 +2669,7 @@ struct s2_fecdec_helper : runnable } else if (nr != iosize) { - fprintf(stderr, "s2_fecdec_helper::receive_frame: %d bytes read vs %d", nr, iosize); + fprintf(stderr, "s2_fecdec_helper::receive_frame: %d bytes read vs %d\n", nr, iosize); } --job->h->b_out; @@ -2700,9 +2731,15 @@ struct s2_framer : runnable { uint8_t rolloff_code; // 0=0.35, 1=0.25, 2=0.20, 3=reserved s2_pls pls; - s2_framer(scheduler *sch, pipebuf &_in, pipebuf &_out) - : runnable(sch, "S2 framer"), - in(_in), out(_out) + + s2_framer( + scheduler *sch, + pipebuf &_in, + pipebuf &_out + ) : + runnable(sch, "S2 framer"), + in(_in), + out(_out) { pls.modcod = 4; pls.sf = false; @@ -2782,17 +2819,22 @@ struct s2_framer : runnable struct s2_deframer : runnable { - s2_deframer(scheduler *sch, pipebuf &_in, pipebuf &_out, - pipebuf *_state_out = nullptr, - pipebuf *_locktime_out = nullptr) - : runnable(sch, "S2 deframer"), - missing(-1), - in(_in), out(_out, MAX_TS_PER_BBFRAME), - current_state(false), - state_out(opt_writer(_state_out, 2)), - report_state(true), - locktime(0), - locktime_out(opt_writer(_locktime_out, MAX_TS_PER_BBFRAME)) + s2_deframer( + scheduler *sch, + pipebuf &_in, + pipebuf &_out, + pipebuf *_state_out = nullptr, + pipebuf *_locktime_out = nullptr + ) : + runnable(sch, "S2 deframer"), + missing(-1), + in(_in), + out(_out, MAX_TS_PER_BBFRAME), + current_state(false), + state_out(opt_writer(_state_out, 2)), + report_state(true), + locktime(0), + locktime_out(opt_writer(_locktime_out, MAX_TS_PER_BBFRAME)) { } void run() diff --git a/plugins/channelrx/demoddatv/leansdr/framework.h b/plugins/channelrx/demoddatv/leansdr/framework.h index cdb380ebe..3a0a3caec 100644 --- a/plugins/channelrx/demoddatv/leansdr/framework.h +++ b/plugins/channelrx/demoddatv/leansdr/framework.h @@ -107,7 +107,7 @@ struct runnable_common struct window_placement { - const char *name; // NULL to terminate + const char *name; // nullptr to terminate int x, y, w, h; }; @@ -120,12 +120,13 @@ struct scheduler window_placement *windows; bool verbose, debug, debug2; - scheduler() : npipes(0), - nrunnables(0), - windows(NULL), - verbose(false), - debug(false), - debug2(false) + scheduler() : + npipes(0), + nrunnables(0), + windows(nullptr), + verbose(false), + debug(false), + debug2(false) { } @@ -208,20 +209,26 @@ struct pipebuf : pipebuf_common T *wr; T *end; - int sizeofT() + pipebuf(scheduler *sch, const char *name, unsigned long size) : + pipebuf_common(name), + nrd(0), + min_write(1), + total_written(0), + total_read(0) { - return sizeof(T); + buf = new T[size]; + wr = buf; + end = buf + size; + sch->add_pipe(this); } - pipebuf(scheduler *sch, const char *name, unsigned long size) : pipebuf_common(name), - buf(new T[size]), - nrd(0), wr(buf), - end(buf + size), - min_write(1), - total_written(0), - total_read(0) + ~pipebuf() { - sch->add_pipe(this); + delete[] buf; + } + + int sizeofT() { + return sizeof(T); } int add_reader() @@ -307,9 +314,8 @@ struct pipewriter void written(unsigned long n) { - if (buf.wr + n > buf.end) - { - fprintf(stderr, "Bug: overflow to %s\n", buf.name); + if (buf.wr + n > buf.end) { + fprintf(stderr, "pipewriter::written: bug: overflow to %s\n", buf.name); } buf.wr += n; @@ -328,13 +334,13 @@ struct pipewriter template pipewriter *opt_writer(pipebuf *buf, unsigned long min_write = 1) { - return buf ? new pipewriter(*buf, min_write) : NULL; + return buf ? new pipewriter(*buf, min_write) : nullptr; } template bool opt_writable(pipewriter *p, int n = 1) { - return (p == NULL) || p->writable() >= n; + return (p == nullptr) || p->writable() >= n; } template diff --git a/plugins/channelrx/demoddatv/leansdr/sdr.h b/plugins/channelrx/demoddatv/leansdr/sdr.h index b341b3f1d..848d3d037 100644 --- a/plugins/channelrx/demoddatv/leansdr/sdr.h +++ b/plugins/channelrx/demoddatv/leansdr/sdr.h @@ -48,20 +48,23 @@ struct auto_notch : runnable int decimation; float k; - auto_notch(scheduler *sch, - pipebuf> &_in, - pipebuf> &_out, - int _nslots, - T _agc_rms_setpoint) : runnable(sch, "auto_notch"), - decimation(1024 * 4096), - k(0.002), // k(0.01) - fft(4096), - in(_in), - out(_out, fft.n), - nslots(_nslots), - phase(0), - gain(1), - agc_rms_setpoint(_agc_rms_setpoint) + auto_notch( + scheduler *sch, + pipebuf> &_in, + pipebuf> &_out, + int _nslots, + T _agc_rms_setpoint + ) : + runnable(sch, "auto_notch"), + decimation(1024 * 4096), + k(0.002), // k(0.01) + fft(4096), + in(_in), + out(_out, fft.n), + nslots(_nslots), + phase(0), + gain(1), + agc_rms_setpoint(_agc_rms_setpoint) { __slots = new slot[nslots]; @@ -74,6 +77,10 @@ struct auto_notch : runnable ~auto_notch() { + for (int s = 0; s < nslots; ++s) { + delete[] __slots[s].expj; + } + delete[] __slots; } @@ -226,12 +233,16 @@ struct ss_estimator : runnable unsigned long window_size; // Samples per estimation unsigned long decimation; // Output rate - ss_estimator(scheduler *sch, pipebuf> &_in, pipebuf &_out) : runnable(sch, "SS estimator"), - window_size(1024), - decimation(1024), - in(_in), - out(_out), - phase(0) + ss_estimator( + scheduler *sch, + pipebuf> &_in, pipebuf &_out + ) : + runnable(sch, "SS estimator"), + window_size(1024), + decimation(1024), + in(_in), + out(_out), + phase(0) { } @@ -268,18 +279,21 @@ struct ss_amp_estimator : runnable unsigned long window_size; // Samples per estimation unsigned long decimation; // Output rate - ss_amp_estimator(scheduler *sch, - pipebuf> &_in, - pipebuf &_out_ss, - pipebuf &_out_ampmin, - pipebuf &_out_ampmax) : runnable(sch, "SS estimator"), - window_size(1024), - decimation(1024), - in(_in), - out_ss(_out_ss), - out_ampmin(_out_ampmin), - out_ampmax(_out_ampmax), - phase(0) + ss_amp_estimator( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out_ss, + pipebuf &_out_ampmin, + pipebuf &_out_ampmax + ) : + runnable(sch, "SS estimator"), + window_size(1024), + decimation(1024), + in(_in), + out_ss(_out_ss), + out_ampmin(_out_ampmin), + out_ampmax(_out_ampmax), + phase(0) { } @@ -332,14 +346,17 @@ struct simple_agc : runnable float estimated; // Input power static const int chunk_size = 128; - simple_agc(scheduler *sch, - pipebuf> &_in, - pipebuf> &_out) : runnable(sch, "AGC"), - out_rms(1), - bw(0.001), - estimated(0), - in(_in), - out(_out, chunk_size) + simple_agc( + scheduler *sch, + pipebuf> &_in, + pipebuf> &_out + ) : + runnable(sch, "AGC"), + out_rms(1), + bw(0.001), + estimated(0), + in(_in), + out(_out, chunk_size) { } @@ -484,12 +501,16 @@ struct cstln_base template struct cstln_lut : cstln_base { - cstln_lut(cstln_base::predef type, - float mer = 10, - float gamma1 = 0, - float gamma2 = 0, - float gamma3 = 0) + cstln_lut( + cstln_base::predef type, + float mer = 10, + float gamma1 = 0, + float gamma2 = 0, + float gamma3 = 0 + ) { + symbols = nullptr; + switch (type) { case BPSK: @@ -679,6 +700,13 @@ struct cstln_lut : cstln_base } } + ~cstln_lut() + { + if (symbols) { + delete[] symbols; + } + } + struct result { SOFTSYMB ss; @@ -958,15 +986,21 @@ struct linear_sampler : sampler_interface template struct fir_sampler : sampler_interface { - fir_sampler(int _ncoeffs, Tc *_coeffs, int _subsampling = 1) : ncoeffs(_ncoeffs), - coeffs(_coeffs), - subsampling(_subsampling), - shifted_coeffs(new complex[ncoeffs]), - update_freq_phase(0) + fir_sampler(int _ncoeffs, Tc *_coeffs, int _subsampling = 1) : + ncoeffs(_ncoeffs), + coeffs(_coeffs), + subsampling(_subsampling), + update_freq_phase(0) { + shifted_coeffs = new complex[ncoeffs]; do_update_freq(0); // In case application never calls update_freq() } + ~fir_sampler() + { + delete[] shifted_coeffs; + } + int readahead() { return ncoeffs - 1; @@ -1050,36 +1084,39 @@ struct cstln_receiver : runnable static const unsigned int chunk_size = 128; float kest; - cstln_receiver(scheduler *sch, - sampler_interface *_sampler, - pipebuf> &_in, - pipebuf &_out, - pipebuf *_freq_out = NULL, - pipebuf *_ss_out = NULL, - pipebuf *_mer_out = NULL, - pipebuf *_cstln_out = NULL) : runnable(sch, "Constellation receiver"), - sampler(_sampler), - cstln(NULL), - meas_decimation(1048576), - pll_adjustment(1.0), - allow_drift(false), - kest(0.01), - in(_in), - out(_out, chunk_size), - est_insp(cstln_amp * cstln_amp), - agc_gain(1), - mu(0), - phase(0), - est_sp(0), - est_ep(0), - meas_count(0) + cstln_receiver( + scheduler *sch, + sampler_interface *_sampler, + pipebuf> &_in, + pipebuf &_out, + pipebuf *_freq_out = nullptr, + pipebuf *_ss_out = nullptr, + pipebuf *_mer_out = nullptr, + pipebuf *_cstln_out = nullptr + ) : + runnable(sch, "Constellation receiver"), + sampler(_sampler), + cstln(nullptr), + meas_decimation(1048576), + pll_adjustment(1.0), + allow_drift(false), + kest(0.01), + in(_in), + out(_out, chunk_size), + est_insp(cstln_amp * cstln_amp), + agc_gain(1), + mu(0), + phase(0), + est_sp(0), + est_ep(0), + meas_count(0) { set_omega(1); set_freq(0); - freq_out = _freq_out ? new pipewriter(*_freq_out) : NULL; - ss_out = _ss_out ? new pipewriter(*_ss_out) : NULL; - mer_out = _mer_out ? new pipewriter(*_mer_out) : NULL; - cstln_out = _cstln_out ? new pipewriter(*_cstln_out) : NULL; + freq_out = _freq_out ? new pipewriter(*_freq_out) : nullptr; + ss_out = _ss_out ? new pipewriter(*_ss_out) : nullptr; + mer_out = _mer_out ? new pipewriter(*_mer_out) : nullptr; + cstln_out = _cstln_out ? new pipewriter(*_cstln_out) : nullptr; for (int i = 0; i < 3; i++) { @@ -1088,6 +1125,22 @@ struct cstln_receiver : runnable } } + ~cstln_receiver() + { + if (freq_out) { + delete freq_out; + } + if (ss_out) { + delete ss_out; + } + if (mer_out) { + delete mer_out; + } + if (cstln_out) { + delete cstln_out; + } + } + void set_omega(float _omega, float tol = 10e-6) { omega = _omega; @@ -1170,7 +1223,7 @@ struct cstln_receiver : runnable // These are scoped outside the loop for SS and MER estimation. complex sg{0.0f, 0.0f}; // Symbol before AGC; complex s; // For MER estimation and constellation viewer - complex *cstln_point = NULL; + complex *cstln_point = nullptr; while (pin < pend) { @@ -1292,8 +1345,7 @@ struct cstln_receiver : runnable if (ss_out) ss_out->write(sqrtf(est_insp)); if (mer_out) - mer_out->write( - est_ep ? 10 * logf(est_sp / est_ep) / logf(10) : 0); + mer_out->write(est_ep ? 10 * log10f(est_sp / est_ep) : 0); } } // Work to do @@ -1342,28 +1394,41 @@ struct fast_qpsk_receiver : runnable bool allow_drift; // Follow carrier beyond safe limits static const unsigned int chunk_size = 128; - fast_qpsk_receiver(scheduler *sch, - pipebuf> &_in, - pipebuf &_out, - pipebuf *_freq_out = NULL, - pipebuf> *_cstln_out = NULL) : runnable(sch, "Fast QPSK receiver"), - meas_decimation(1048576), - pll_adjustment(1.0), - allow_drift(false), - in(_in), - out(_out, chunk_size), - mu(0), - phase(0), - meas_count(0) + fast_qpsk_receiver( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out, + pipebuf *_freq_out = nullptr, + pipebuf> *_cstln_out = nullptr + ) : + runnable(sch, "Fast QPSK receiver"), + meas_decimation(1048576), + pll_adjustment(1.0), + allow_drift(false), + in(_in), + out(_out, chunk_size), + mu(0), + phase(0), + meas_count(0) { set_omega(1); set_freq(0); - freq_out = _freq_out ? new pipewriter(*_freq_out) : NULL; - cstln_out = _cstln_out ? new pipewriter>(*_cstln_out) : NULL; + freq_out = _freq_out ? new pipewriter(*_freq_out) : nullptr; + cstln_out = _cstln_out ? new pipewriter>(*_cstln_out) : nullptr; memset(hist, 0, sizeof(hist)); init_lookup_tables(); } + ~fast_qpsk_receiver() + { + if (freq_out) { + delete freq_out; + } + if (cstln_out) { + delete cstln_out; + } + } + void set_omega(float _omega, float tol = 10e-6) { omega = _omega; @@ -1621,12 +1686,15 @@ struct cstln_transmitter : runnable { cstln_lut *cstln; - cstln_transmitter(scheduler *sch, - pipebuf &_in, - pipebuf> &_out) : runnable(sch, "cstln_transmitter"), - in(_in), - out(_out), - cstln(0) + cstln_transmitter( + scheduler *sch, + pipebuf &_in, + pipebuf> &_out + ) : + runnable(sch, "cstln_transmitter"), + in(_in), + out(_out), + cstln(nullptr) { } @@ -1663,13 +1731,16 @@ struct cstln_transmitter : runnable template struct rotator : runnable { - rotator(scheduler *sch, - pipebuf> &_in, - pipebuf> &_out, - float freq) : runnable(sch, "rotator"), - in(_in), - out(_out), - index(0) + rotator( + scheduler *sch, + pipebuf> &_in, + pipebuf> &_out, + float freq + ) : + runnable(sch, "rotator"), + in(_in), + out(_out), + index(0) { int ifreq = freq * 65536; if (sch->debug) @@ -1721,29 +1792,34 @@ struct rotator : runnable template struct cnr_fft : runnable { - cnr_fft(scheduler *sch, - pipebuf> &_in, - pipebuf &_out, - float _bandwidth, int nfft = 4096) : runnable(sch, "cnr_fft"), - bandwidth(_bandwidth), - freq_tap(NULL), - tap_multiplier(1), - decimation(1048576), - kavg(0.1), - in(_in), - out(_out), - fft(nfft), - avgpower(NULL), - phase(0) + cnr_fft( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out, + float _bandwidth, int nfft = 4096 + ) : + runnable(sch, "cnr_fft"), + bandwidth(_bandwidth), + freq_tap(nullptr), + tap_multiplier(1), + decimation(1048576), + kavg(0.1), + in(_in), + out(_out), + fft(nfft), + avgpower(nullptr), + phase(0) { if (bandwidth > 0.25) fail("CNR estimator requires Fsampling > 4x Fsignal"); } - float bandwidth; - float *freq_tap, tap_multiplier; - int decimation; - float kavg; + ~cnr_fft() + { + if (avgpower) { + delete[] avgpower; + } + } void run() { @@ -1761,6 +1837,11 @@ struct cnr_fft : runnable } } + float bandwidth; + float *freq_tap, tap_multiplier; + int decimation; + float kavg; + private: void do_cnr() { @@ -1826,23 +1907,33 @@ struct cnr_fft : runnable template struct spectrum : runnable { - spectrum(scheduler *sch, - pipebuf> &_in, - pipebuf &_out) : runnable(sch, "spectrum"), - decimation(1048576), - kavg(0.1), - decim(1), in(_in), - out(_out), - fft(NFFT), - avgpower(NULL), - phase(0) - { - } - int decimation; float kavg; int decim; + spectrum( + scheduler *sch, + pipebuf> &_in, + pipebuf &_out + ) : + runnable(sch, "spectrum"), + decimation(1048576), + kavg(0.1), + decim(1), in(_in), + out(_out), + fft(NFFT), + avgpower(nullptr), + phase(0) + { + } + + ~spectrum() + { + if (avgpower) { + delete avgpower; + } + } + void run() { while (in.readable() >= fft.n * decim && out.writable() >= 1) diff --git a/plugins/channelrx/demoddatv/leansdr/viterbi.h b/plugins/channelrx/demoddatv/leansdr/viterbi.h index 79798b4ab..4e3e50699 100644 --- a/plugins/channelrx/demoddatv/leansdr/viterbi.h +++ b/plugins/channelrx/demoddatv/leansdr/viterbi.h @@ -124,6 +124,7 @@ template struct viterbi_dec_interface { + virtual ~viterbi_dec_interface() {} virtual TUS update(TBM *costs, TPM *quality = NULL) = 0; virtual TUS update(TCS s, TBM cost, TPM *quality = NULL) = 0; };